Re: Re: Re: [PATCH] ata: libahci: fix panic when accessing ports beyond MMIO region

Niklas Cassel
2026-04-24T11:07:27Z

On Fri, Apr 24, 2026 at 02:32:59PM +0800, 李佑鸿 wrote:
> However, in the following code:
> cap = readl(mmio + HOST_CAP); /* When cap = 0xFFFFFFFF */
> if (hpriv->saved_cap)
> cap = (cap & ~(HOST_CAP_SSS | HOST_CAP_MPS)) | hpriv->saved_cap; /* When hpriv->saved_cap = 0xEF36FF81 */

Sorry for that. From the name hpriv->saved_cap, I assumed that it would
actually override hpriv->cap, but it seems that it only allows you to
set additional caps, not to override/clear caps that are broken...

I guess we could theoretically do:

diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 1d73a53370cf..94c3c740134a 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -2003,6 +2003,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)

if (pdev->vendor == 0x177d && pdev->device == 0xa01c)
hpriv->irq_handler = ahci_thunderx_irq_handler;
+
+ /* Phytium SATA controller has bogus CAP register */
+ if (pdev->vendor == 0x1db7 && pdev->device == 0xd001)
+ writel(0xEF36FF81, hpriv->mmio + HOST_CAP);
#endif

/* save initial config */

However, that said, I agree with Damien, I think a better solution is to
fail the probe(). Will reply to that mail with more details.

Kind regards,
Niklas