{"id":2229275,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2229275/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260428020935.2049617-1-dayou5941@163.com/","project":{"id":13,"url":"http://patchwork.ozlabs.org/api/1.1/projects/13/?format=json","name":"Linux IDE development","link_name":"linux-ide","list_id":"linux-ide.vger.kernel.org","list_email":"linux-ide@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<20260428020935.2049617-1-dayou5941@163.com>","date":"2026-04-28T02:09:35","name":"[v5] ata: ahci: fail probe if BAR too small for claimed ports","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"10b97c806423c827bd9e31f918ea1487bb61ab37","submitter":{"id":93214,"url":"http://patchwork.ozlabs.org/api/1.1/people/93214/?format=json","name":"李佑鸿","email":"dayou5941@163.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-ide/patch/20260428020935.2049617-1-dayou5941@163.com/mbox/","series":[{"id":501750,"url":"http://patchwork.ozlabs.org/api/1.1/series/501750/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ide/list/?series=501750","date":"2026-04-28T02:09:35","name":"[v5] ata: ahci: fail probe if BAR too small for claimed ports","version":5,"mbox":"http://patchwork.ozlabs.org/series/501750/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2229275/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2229275/checks/","tags":{},"headers":{"Return-Path":"\n <linux-ide+bounces-5569-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-ide@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256\n header.s=s110527 header.b=a602enSk;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c09:e001:a7::12fc:5321; helo=sto.lore.kernel.org;\n envelope-from=linux-ide+bounces-5569-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=\"a602enSk\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=117.135.210.4","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=163.com"],"Received":["from sto.lore.kernel.org (sto.lore.kernel.org\n [IPv6:2600:3c09:e001:a7::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4P5r5Pwgz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 12:10:08 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sto.lore.kernel.org (Postfix) with ESMTP id 382AD30066A5\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 02:10:05 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 129C82D9797;\n\tTue, 28 Apr 2026 02:10:04 +0000 (UTC)","from m16.mail.163.com (m16.mail.163.com [117.135.210.4])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 54FB72D5C8E\n\tfor <linux-ide@vger.kernel.org>; Tue, 28 Apr 2026 02:09:58 +0000 (UTC)","from localhost.localdomain (unknown [])\n\tby gzga-smtp-mtada-g0-4 (Coremail) with SMTP id\n _____wD3d1jhFvBp44XFCA--.27144S2;\n\tTue, 28 Apr 2026 10:09:37 +0800 (CST)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777342204; cv=none;\n b=p/b4doZpKjATBd9Vxz93P08v1zQMhOEAP/mUYp82EQZXXHAn6iRdeJvIttI235eclLSnitXB155CXdNGTYwr+BBWMk4SUE/8i0ENg80av8xidThNwGRG+sMScC2Kna/aKEEACAVKNk9qCm5ix8gCRH8gijYJRPuiudDa5O5/k5E=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777342204; c=relaxed/simple;\n\tbh=+0l37V+xusQpwt0Vx5kF+e4tMleGYK7y88Bk4YbZ4jM=;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version;\n b=oXZt47esKD6OahpBH5VjuDGWoYWT8KwmCybNgYuwL+p/JpRR1BfU7QzdzdQZrLYFhyaBCz6h5G8cs2ibg1lNentJbyzFbUGIrivghg8/NpCuzlAqcNrRRpZOv2cuQ0VBGcdVvT5NqU1v1SX8hSeH5GXTkNSme/HtPnkYnXOT0Ow=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=163.com;\n spf=pass smtp.mailfrom=163.com;\n dkim=pass (1024-bit key) header.d=163.com header.i=@163.com\n header.b=a602enSk; arc=none smtp.client-ip=117.135.210.4","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com;\n\ts=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=60\n\tg8PUvRpsOCkXClbZjQeBO2lU1sq8Zq+H84NrQdzM4=; b=a602enSkVlS6LRXRb9\n\tYbl3enhsyGhWRHWsZ0ZxMUqvXtBjZsDd0mNeZ9CLm7bEYNjNXsQn1euJiIpII7Qp\n\tmsMql+4SPUPYRokKNvtY7lgG+G/TOPkr7aR5x5q5Ti4xgLkG7ddsG+n8ag3eEdre\n\t/badoNzs2bafeTgW18rWlYG1I=","From":"dayou5941@163.com","To":"linux-ide@vger.kernel.org","Cc":"dlemoal@kernel.org,\n\tcassel@kernel.org,\n\tliyouhong@kylinos.cn","Subject":"[PATCH v5] ata: ahci: fail probe if BAR too small for claimed ports","Date":"Tue, 28 Apr 2026 10:09:35 +0800","Message-Id":"<20260428020935.2049617-1-dayou5941@163.com>","X-Mailer":"git-send-email 2.25.1","Precedence":"bulk","X-Mailing-List":"linux-ide@vger.kernel.org","List-Id":"<linux-ide.vger.kernel.org>","List-Subscribe":"<mailto:linux-ide+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-ide+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-CM-TRANSID":"_____wD3d1jhFvBp44XFCA--.27144S2","X-Coremail-Antispam":"1Uf129KBjvJXoWxJF4DCryfZF1fKFWDZF18Krg_yoW5uF1xpF\n\tWxGa9YkrWUWry7Xay8Aan7Z343Cws5JFW7t343J3ZayFs0kry8WF1Ska47Ca98J34qka42\n\tqr1qqr18ur1UAFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2\n\t9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j1rWrUUUUU=","X-CM-SenderInfo":"5gd103ivzuiqqrwthudrp/xtbC3gNUA2nwFuOj8AAA31"},"content":"From: liyouhong <liyouhong@kylinos.cn>\n\nWhen an AHCI controller is disabled in BIOS, its HOST_CAP register may\ncontain invalid values (e.g., 0xFFFFFFFF) indicating an impossibly large\nnumber of ports. If CAP.NP claims more ports than can physically fit\nwithin the mapped BAR region, accessing port registers beyond the BAR\nboundary causes a kernel panic.\n\nAdd validation in ahci_init_one() to check that the BAR size is\nsufficient for the number of ports claimed in CAP.NP. The check\ncalculates the required MMIO size as:\n\n  required_size = 0x100 (global registers) + max_ports * 0x80\n\nIf required_size exceeds the actual BAR size, the probe fails with\n-ENODEV, preventing the panic and providing a clear error message.\n\nThis solution follows the suggestion by Damien Le Moal and Niklas Cassel\nto detect and reject obviously broken controller configurations early.\n\nReported-by: liyouhong <liyouhong@kylinos.cn>\nCloses: https://lore.kernel.org/all/20260422080322.1006592-1-dayou5941@163.com/\nSuggested-by: Damien Le Moal <dlemoal@kernel.org>\nSuggested-by: Niklas Cassel <cassel@kernel.org>\nReviewed-by: Damien Le Moal <dlemoal@kernel.org>\nSigned-off-by: liyouhong <liyouhong@kylinos.cn>\n---\nv2:\n- Complete rewrite based on community feedback\n- Move check from libahci.c to ahci.c\n- Fail probe early instead of attempting to work around invalid state\n- Implement BAR size validation as suggested\n\nv3:\n- Fix patch format: add \"---\" separator and move changelog to correct location\n- Change dev_err to dev_warn as suggested\n\nv4:\n- Break long lines as suggested by Damien\n- Keep complete changelog history\n\nv5:\n- Update function signature to match ahci_remap_check() pattern\n- Use hpriv->mmio instead of separate mmio parameter\n- Use %pa format specifier for resource_size_t\n- Use %#x for hexadecimal port offset\n- Dynamically show BAR number in error message\n- Add Closes: tag as suggested by checkpatch.pl\n\n---\n drivers/ata/ahci.c | 22 ++++++++++++++++++++++\n 1 file changed, 22 insertions(+)","diff":"diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c\nindex 1d73a53370cf..b4e5d347151a 100644\n--- a/drivers/ata/ahci.c\n+++ b/drivers/ata/ahci.c\n@@ -1888,6 +1888,24 @@ static ssize_t remapped_nvme_show(struct device *dev,\n \n static DEVICE_ATTR_RO(remapped_nvme);\n \n+static int ahci_validate_bar_size(struct pci_dev *pdev, int bar,\n+\t\t\t\t  struct ahci_host_priv *hpriv)\n+{\n+\tu32 cap = readl(hpriv->mmio + HOST_CAP);\n+\tunsigned int max_ports = ahci_nr_ports(cap);\n+\tu32 last_port_end = 0x100 + (max_ports * 0x80);\n+\tresource_size_t bar_size = pci_resource_len(pdev, bar);\n+\n+\tif (last_port_end > bar_size) {\n+\t\tdev_warn(&pdev->dev,\n+\t\t\t \"BAR%d too small for %u ports (last port ends at %#x, BAR %pa)\\n\",\n+\t\t\t bar, max_ports, last_port_end, &bar_size);\n+\t\treturn -ENODEV;\n+\t}\n+\n+\treturn 0;\n+}\n+\n static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)\n {\n \tunsigned int board_id = ent->driver_data;\n@@ -1988,6 +2006,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)\n \tif (!hpriv->mmio)\n \t\treturn -ENOMEM;\n \n+\trc = ahci_validate_bar_size(pdev, ahci_pci_bar, hpriv);\n+\tif (rc)\n+\t\treturn rc;\n+\n \t/* detect remapped nvme devices */\n \tahci_remap_check(pdev, ahci_pci_bar, hpriv);\n \n","prefixes":["v5"]}