Fix amdgpu detection of pci=realloc
Subsystems (3)
v4 cover Fix amdgpu detection of pci=realloc
amdgpu needs to know the bus number the platform assigned a device to be able to match firmware images against the right device.
This was previously adjusted to be a soft filter due to
commit 11c141672045f ("drm/amdgpu: Fix VFCT bus number matching with soft filter") where if everything but the number matched to take a device.
This however fails when there are two identical devices. Instead save the initial bus number to the PCI device structure and then match that.
---
Changes in v4:
- Retain secondary bus bus number for a bridge across rescans, and the child bus is initialized from it during allocation, before registration callbacks run. (Sashiko)
- Rename variable to clarify it's for bridges (Lijo)
- Link to v3: https://patch.msgid.link/[email protected]
Changes in v3:
- Preserve the firmware bus number across bridge renumbering, capturing the secondary bus number before pci_scan_bridge_extend() clears it.
- Adjust member name in all patches
- Add tags
- Link to v2: https://patch.msgid.link/[email protected]
Changes in v2:
- pci_alloc_dev(NULL) remains safe.
- For buses behind a reassigned bridge, the PCI core now saves the firmware secondary bus number before clearing the bridge configuration and carries it into the newly allocated bus. Devices discovered there inherit that original number.
- Add changes for radeon too.
- Link to v1: https://patch.msgid.link/[email protected]
---
Mario Limonciello (3):
PCI: Preserve the initial bus number in pci_bus drm/amdgpu: Match VFCT using initial PCI bus number drm/radeon: Match VFCT using initial PCI bus number
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 17 +++-------------- drivers/gpu/drm/radeon/radeon_bios.c | 17 +++-------------- drivers/pci/probe.c | 6 ++++++ include/linux/pci.h | 3 +++ 4 files changed, 15 insertions(+), 28 deletions(-)
---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261019-vfct-regression-2142fc52852a
Best regards,
Signature · 1 line
Mario Limonciello <[email protected]>
PATCH v4 1/3 PCI: Preserve the initial bus number in pci_bus
Bridge scans are split into two passes when bus numbers need reassigning. Save the firmware secondary bus number on the bridge in pass 0, before it is disabled. Use it to initialize number_initial when the child bus is created in pass 1, before bus registration callbacks run.
Keep the saved secondary number on the bridge so a later rescan does not replace the child's initial number with its reassigned runtime number.
--- drivers/pci/probe.c | 6 ++++++ include/linux/pci.h | 3 +++ 2 files changed, 9 insertions(+)
drivers/pci/probe.c +6 -0
@@ -1012,6 +1012,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) bus->sysdata = bridge->sysdata; bus->ops = bridge->ops; bus->number = bus->busn_res.start = bridge->busnr; + bus->number_initial = bus->number;#ifdef CONFIG_PCI_DOMAINS_GENERIC if (bridge->domain_nr ==PCI_DOMAIN_NR_NOT_SET ) bus->domain_nr =pci_bus_find_domain_nr (bus, parent);
@@ -1232,6 +1233,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,/* Set up the primary, secondary and subordinate bus numbers */ child->number = child->busn_res.start = busnr; + child->number_initial = bridge && bridge->bridge_secondary_busnr ? + bridge->bridge_secondary_busnr : busnr; child->primary = parent->busn_res.start; child->busn_res.end =0xff ;
@@ -1418,6 +1421,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,pci_dbg (dev,"scanning [bus %02x-%02x] behind bridge, pass %d\n" , secondary, subordinate, pass); +if (!pass && !dev->bridge_secondary_busnr) + dev->bridge_secondary_busnr = secondary;if (!primary && (primary != bus->number) && secondary && subordinate) {pci_warn (dev,"Primary bus is hard wired to 0\n" );
@@ -1470,6 +1475,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, child =pci_add_new_bus (bus, dev, secondary);if (!child) goto out; + child->number_initial = secondary; child->primary = primary;pci_bus_insert_busn_res (child, secondary, subordinate); child->bridge_ctl = bctl;
include/linux/pci.h +3 -0
@@ -363,6 +363,8 @@ struct pci_dev {struct pci_slot *slot;/* Physical slot this device is in */ unsigned int devfn;/* Encoded device & function index */ +/* Firmware secondary bus number saved across bridge scan passes */ +u8 bridge_secondary_busnr;unsigned short vendor;unsigned short device;unsigned short subsystem_vendor;
@@ -724,6 +726,7 @@ struct pci_bus {struct proc_dir_entry *procdir;/* Directory entry in /proc/bus/pci */ unsigned char number;/* Bus number */ +unsigned char number_initial;/* Bus number before reassignment */ unsigned char primary;/* Number of primary bridge */ unsigned char max_bus_speed;/* enum pci_bus_speed */ unsigned char cur_bus_speed;/* enum pci_bus_speed */
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 1/3] PCI: Preserve the initial bus number in pci_bus
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Bridge scans are split into two passes when bus numbers need reassigning. Save the firmware secondary bus number on the bridge in pass 0, before it is disabled. Use it to initialize
number_initialwhen the child bus is created in pass 1, before bus registration callbacks run.Keep the saved secondary number on the bridge so a later rescan does not replace the child's initial number with its reassigned runtime number.
Signed-off-by Mario Limonciello <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v4 1/3] PCI: Preserve the initial bus number in pci_bus
In reply to Mario Limonciello[+cc Lijo]
Quoted 36 lines · Mario Limonciello
Bridge scans are split into two passes when bus numbers need reassigning. Save the firmware secondary bus number on the bridge in pass 0, before it is disabled. Use it to initialize
number_initialwhen the child bus is created in pass 1, before bus registration callbacks run.Keep the saved secondary number on the bridge so a later rescan does not replace the child's initial number with its reassigned runtime number.
Signed-off-by Mario Limonciello <[email protected]>--- drivers/pci/probe.c | 6 ++++++ include/linux/pci.h | 3 +++ 2 files changed, 9 insertions(+)drivers/pci/probe.c +3
-0@@ -1012,6 +1012,7 @@ static int pci_register_host_bridge(struct pci_host_bridge *bridge) bus->sysdata = bridge->sysdata; bus->ops = bridge->ops; bus->number = bus->busn_res.start = bridge->busnr; + bus->number_initial = bus->number;#ifdef CONFIG_PCI_DOMAINS_GENERIC if (bridge->domain_nr ==PCI_DOMAIN_NR_NOT_SET ) bus->domain_nr =pci_bus_find_domain_nr (bus, parent);@@ -1232,6 +1233,8 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,/* Set up the primary, secondary and subordinate bus numbers */ child->number = child->busn_res.start = busnr; + child->number_initial = bridge && bridge->bridge_secondary_busnr ? + bridge->bridge_secondary_busnr : busnr; child->primary = parent->busn_res.start; child->busn_res.end =0xff ;
drivers/pci/probe.c static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, · line 1425
Quoted 5 lines
drivers/pci/probe.c +2
-0@@ -1418,6 +1421,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,pci_dbg (dev,"scanning [bus %02x-%02x] behind bridge, pass %d\n" , secondary, subordinate, pass); +if (!pass && !dev->bridge_secondary_busnr) + dev->bridge_secondary_busnr = secondary;
I think I was mistaken to suggest that pci_bus was the right place to store this.
It seems like we definitely need something in the pci_dev because we may clear the initial bus numbers in the first pass, so we need to stash the secondary bus number somewhere until the second pass allocates the pci_bus and we can save it here.
Since we have to have it in the pci_dev, I suspect maybe it would be enough to have it *only* there. Maybe it could be set in pci_read_bridge_windows(), and drivers could find it via pdev->bus->self?
Quoted 15 lines
drivers/pci/probe.c +1
-0if (!primary && (primary != bus->number) && secondary && subordinate) {pci_warn (dev,"Primary bus is hard wired to 0\n" );@@ -1470,6 +1475,7 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev, child =pci_add_new_bus (bus, dev, secondary);if (!child) goto out; + child->number_initial = secondary; child->primary = primary;pci_bus_insert_busn_res (child, secondary, subordinate); child->bridge_ctl = bctl;include/linux/pci.h +0
-0
include/linux/pci.h struct pci_dev { · line 367
Quoted 5 lines
include/linux/pci.h +2
-0@@ -363,6 +363,8 @@ struct pci_dev {struct pci_slot *slot;/* Physical slot this device is in */ unsigned int devfn;/* Encoded device & function index */ +/* Firmware secondary bus number saved across bridge scan passes */ +u8 bridge_secondary_busnr;
I think you're right to use "secondary" here so we don't perpetuate the "subordinate" misuse. Maybe also include "initial" and make it "unsigned char" so it's the same as pci_bus.number?
Quoted 15 lines
include/linux/pci.h +1
-0unsigned short vendor;unsigned short device;unsigned short subsystem_vendor;@@ -724,6 +726,7 @@ struct pci_bus {struct proc_dir_entry *procdir;/* Directory entry in /proc/bus/pci */ unsigned char number;/* Bus number */ +unsigned char number_initial;/* Bus number before reassignment */ unsigned char primary;/* Number of primary bridge */ unsigned char max_bus_speed;/* enum pci_bus_speed */ unsigned char cur_bus_speed;/* enum pci_bus_speed */ Signature · 2 lines
-- 2.43.0
PATCH v4 2/3 drm/amdgpu: Match VFCT using initial PCI bus number
In reply to Mario LimoncielloVFCT records the PCI bus number from BIOS POST. The current bus number can change after PCI core renumbers the bus, while accepting a mismatch based only on device identity can select the wrong VFCT image when matching devices are present. Compare against the bus number captured from the firmware bus assignment before bridge renumbering.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +3 -14
@@ -386,10 +386,8 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev)* VFCT entries contain the PCI bus number as recorded during BIOS POST. * On systems where the kernel renumbers PCI buses (e.g. pci=realloc or * resource conflicts), the runtime bus number may differ from the POST -* value. Match by device identity (vendor + device + function) and use -* the bus number as a preference: exact bus match is preferred, but when -* the bus numbers disagree we accept the entry if the device identity -* matches. +* value. Match using the bus number captured when the device was +* discovered, before any bus renumbering. * * Returns: 0 on match, -ENODEV on no match */
@@ -405,16 +403,7 @@ static int amdgpu_acpi_vfct_match(struct amdgpu_device *adev, vhdr->PCIFunction != PCI_FUNC(adev->pdev->devfn)) return -ENODEV; -/* Exact bus number match - preferred */ -if (vhdr->PCIBus == adev->pdev->bus->number) -return 0 ; - -/* Bus mismatch but device identity matches (PCI renumbering case) */ -dev_notice (adev->dev, -"VFCT bus number mismatch: table %u != runtime %u, matching by device identity (vendor 0x%04x device 0x%04x)\n" , - vhdr->PCIBus, adev->pdev->bus->number, - adev->pdev->vendor, adev->pdev->device); -return 0 ; +return vhdr->PCIBus == adev->pdev->bus->number_initial ?0 : -ENODEV ; }static bool amdgpu_acpi_vfct_bios (struct amdgpu_device *adev)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 2/3] drm/amdgpu: Match VFCT using initial PCI bus number
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
VFCT records the PCI bus number from BIOS POST. The current bus number can change after PCI core renumbers the bus, while accepting a mismatch based only on device identity can select the wrong VFCT image when matching devices are present. Compare against the bus number captured from the firmware bus assignment before bridge renumbering.
Reported-by Reza Nikzad Chaleshori <[email protected]>Fixes 11c141672045f ("drm/amdgpu: Fix VFCT bus number matching with soft filter")Signed-off-by Mario Limonciello <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v4 3/3 drm/radeon: Match VFCT using initial PCI bus number
In reply to Mario LimoncielloVFCT records the PCI bus number from BIOS POST. The current bus number can change after PCI core renumbers the bus, while accepting a mismatch based only on device identity can select the wrong VFCT image when matching devices are present. Compare against the bus number captured from the firmware bus assignment before bridge renumbering.
--- drivers/gpu/drm/radeon/radeon_bios.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +3 -14
@@ -609,10 +609,8 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev)* VFCT entries contain the PCI bus number as recorded during BIOS POST. * On systems where the kernel renumbers PCI buses (e.g. pci=realloc or * resource conflicts), the runtime bus number may differ from the POST -* value. Match by device identity (vendor + device + function) and use -* the bus number as a preference: exact bus match is preferred, but when -* the bus numbers disagree we accept the entry if the device identity -* matches. +* value. Match using the bus number captured when the device was +* discovered, before any bus renumbering. * * Returns: 0 on match, -ENODEV on no match */
@@ -628,16 +626,7 @@ static int radeon_acpi_vfct_match(struct radeon_device *rdev, vhdr->PCIFunction != PCI_FUNC(rdev->pdev->devfn)) return -ENODEV; -/* Exact bus number match - preferred */ -if (vhdr->PCIBus == rdev->pdev->bus->number) -return 0 ; - -/* Bus mismatch but device identity matches (PCI renumbering case) */ -dev_notice (&rdev->pdev->dev, -"VFCT bus number mismatch: table %u != runtime %u, matching by device identity (vendor 0x%04x device 0x%04x)\n" , - vhdr->PCIBus, rdev->pdev->bus->number, - rdev->pdev->vendor, rdev->pdev->device); -return 0 ; +return vhdr->PCIBus == rdev->pdev->bus->number_initial ?0 : -ENODEV ; }static bool radeon_acpi_vfct_bios (struct radeon_device *rdev)
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v4 3/3] drm/radeon: Match VFCT using initial PCI bus number
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
VFCT records the PCI bus number from BIOS POST. The current bus number can change after PCI core renumbers the bus, while accepting a mismatch based only on device identity can select the wrong VFCT image when matching devices are present. Compare against the bus number captured from the firmware bus assignment before bridge renumbering.
Fixes 4059e2f02c8a ("drm/radeon: Fix VFCT bus number matching with soft filter")Signed-off-by Mario Limonciello <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3