Re:Re: Re: [PATCH] ata: libahci: fix panic when accessing ports beyond MMIO region
From: 李佑鸿
Date: Sat Apr 25 2026 - 02:15:53 EST
Hi Niklas, Damien,
At 2026-04-24 19:07:33, "Niklas Cassel" <cassel@xxxxxxxxxx> wrote:
>On Fri, Apr 24, 2026 at 03:16:56PM +0800, 李佑鸿 wrote:
>> At 2026-04-24 10:43:11, "Damien Le Moal" <dlemoal@xxxxxxxxxx> wrote:
>> >
>> >What I am surprised of here is that we even see that device on the PCI bus at
>> >all when it is disabled in the BIOs. If that device is disabled, why are we even
>> >seeing it by scanning the PCI ports ? The adapter should simply not be visible
>> >at all.
>
>I agree.
>E.g. both AMD and Intel make sure that the AHCI controller PCI device does
>not show up on the PCI bus if you disable it using the BIOS.
>
>It would have been nice if the Phytium BIOS also worked like that.
>
>
>> 3. **BAR Size Mismatch**: `CAP.NP` indicates more ports than physically fit in the BAR
>> - If CAP claims 32 ports but BAR is only 4KB, this is physically impossible
>> - 32 ports require at least 0x1100 bytes (0x100 + 32 * 0x80)
>
>The reason why I did not suggest failing the probe() originally, was because
>李佑鸿 sent a patch with a Fixes tag, so I assumed that he considered it a
>regression, and wanted the hardware to continue working, even though it was
>marked as disabled in BIOS, because that is how it was before the commit in
>the Fixes tag was introduced.
>
>That said, I fully agree that I think it is better to modify the AHCI driver
>to fail the probe() for this AHCI controller when it has not been properly
>initialized (because it is marked as disabled in BIOS).
>
>I prefer option 3.
>Look at CAP.NP and look at the BAR size, if it is too small, just fail the
>probe().
Thank you for the clear direction. I agree that checking BAR size against
CAP.NP is the cleanest solution.
I will prepare a v2 patch implementing this check:
1. In ahci_init_one(), after mapping MMIO but before any port access.
2. Calculate: required_size = 0x100 + (CAP.NP * 0x80).
3. Compare with pci_resource_len(pdev, 5).
4. If required_size > BAR size, fail probe with -ENODEV and clear error.
The patch will include:
- A new ahci_validate_bar_size() helper function
- Clear error message: "AHCI: BAR5 too small for %u ports..."
I'll send the v2 patch shortly.
Best regards,
liyouhong>
>
>Kind regards,
>Niklas