Skip to contentSkip to conversation

Fix amdgpu detection of pci=realloc

PATCH Superseded Mario Limonciello 4 participants 10 messages Oct 20 – Oct 26

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 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 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_dev 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                      |  9 +++++++++
 include/linux/pci.h                      |  3 +++
 4 files changed, 18 insertions(+), 28 deletions(-)

---
base-commit: c03c1a14507dfaf8b856c2608f9ac216021fc222
change-id: 20261019-vfct-regression-2142fc52852a

Best regards,

Signature · 1 line
Mario Limonciello <[email protected]>
#1 lore raw

PATCH v2 1/3 PCI: Preserve the initial bus number in pci_dev

Bridges that need bus reassignment are scanned in two passes. Save the firmware secondary bus number during the first pass, before the bridge is disabled, and carry it to the bus created in the second pass. Initialize pci_dev from this preserved bus number so drivers can match firmware records after PCI bus renumbering.

Handle pci_alloc_dev(NULL) as well; some in-tree callers use it to allocate a standalone pci_dev.

---
 drivers/pci/probe.c | 9 +++++++++
 include/linux/pci.h | 3 +++
 2 files changed, 12 insertions(+)
drivers/pci/probe.c +9 -0
index 27008e2ea5afc..4ece4b70cdc15 100644
@@ -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->initial_bus_number = 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,7 @@ 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->initial_bus_number = busnr;
 	child->primary = parent->busn_res.start;
 	child->busn_res.end = 0xff;
 
@@ -1470,6 +1472,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->initial_bus_number = secondary;
 			child->primary = primary;
 			pci_bus_insert_busn_res(child, secondary, subordinate);
 			child->bridge_ctl = bctl;
@@ -1491,6 +1494,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
 		 * do in the second pass.
 		 */
 		if (!pass) {
+			if (!dev->initial_secondary_bus_number)
+				dev->initial_secondary_bus_number = secondary;
 			if (pcibios_assign_all_busses() || broken)
 
 				/*
@@ -1526,6 +1531,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
 			child = pci_add_new_bus(bus, dev, next_busnr);
 			if (!child)
 				goto out;
+			if (dev->initial_secondary_bus_number)
+				child->initial_bus_number =
+					dev->initial_secondary_bus_number;
 			pci_bus_insert_busn_res(child, next_busnr,
 						bus->busn_res.end);
 		}
@@ -2508,6 +2516,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
 	INIT_LIST_HEAD(&dev->bus_list);
 	dev->dev.type = &pci_dev_type;
 	dev->bus = pci_bus_get(bus);
+	dev->initial_bus_number = bus ? bus->initial_bus_number : 0;
 	dev->driver_exclusive_resource = (struct resource) {
 		.name = "PCI Exclusive",
 		.start = 0,
include/linux/pci.h +3 -0
index 5ffcf5ce8c966..f6b377dcf7a14 100644
@@ -363,6 +363,8 @@ struct pci_dev {
 	struct pci_slot	*slot;		/* Physical slot this device is in */
 
 	unsigned int	devfn;		/* Encoded device & function index */
+	u8		initial_bus_number;	/* Bus number when device was discovered */
+	u8		initial_secondary_bus_number;	/* Bus number behind this bridge */
 	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	initial_bus_number;	/* 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
#2 lore raw

Re: [PATCH v2 1/3] PCI: Preserve the initial bus number in pci_dev

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

Bridges that need bus reassignment are scanned in two passes. Save the firmware secondary bus number during the first pass, before the bridge is disabled, and carry it to the bus created in the second pass. Initialize pci_dev from this preserved bus number so drivers can match firmware records after PCI bus renumbering.

Handle pci_alloc_dev(NULL) as well; some in-tree callers use it to allocate a standalone pci_dev.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by Reviewed-by on v2 1/3
#3 lore raw

RE: [PATCH v2 1/3] PCI: Preserve the initial bus number in pci_dev

In reply to Mario Limonciello

Public

Quoted 18 lines

-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Tuesday, October 20, 2026 10:05 AM
To: Bjorn Helgaas <[email protected]>; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Cc: Oz Tiram <[email protected]>; [email protected]; linux- [email protected]; [email protected]; dri- [email protected]; Limonciello, Mario <[email protected]>
Subject: [PATCH v2 1/3] PCI: Preserve the initial bus number in pci_dev

Bridges that need bus reassignment are scanned in two passes. Save the firmware secondary bus number during the first pass, before the bridge is disabled, and carry it to the bus created in the second pass. Initialize pci_dev from this preserved bus number so drivers can match firmware records after PCI bus renumbering.

Quoted 4 lines

Handle pci_alloc_dev(NULL) as well; some in-tree callers use it to allocate a standalone pci_dev.

Looks good to me. Patch 1 is:

Patches 2, 3:

I don't have a preference which tree these go through, assuming Bjorn is ok with the PCI change.

Alex

Quoted 94 lines
---
 drivers/pci/probe.c | 9 +++++++++
 include/linux/pci.h | 3 +++
 2 files changed, 12 insertions(+)
drivers/pci/probe.c index renamed from drivers/pci/probe.c +0 -0

27008e2ea5afc..4ece4b70cdc15 100644

drivers/pci/probe.c +1 -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->initial_bus_number = 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,7 @@ 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;
drivers/pci/probe.c +2 -0
+     child->initial_bus_number = busnr;
      child->primary = parent->busn_res.start;
      child->busn_res.end = 0xff;
@@ -1470,6 +1472,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->initial_bus_number = secondary;
                      child->primary = primary;
                      pci_bus_insert_busn_res(child, secondary,
subordinate);
                      child->bridge_ctl = bctl;
drivers/pci/probe.c +2 -0
@@ -1491,6 +1494,8 @@ static int pci_scan_bridge_extend(struct pci_bus
 *bus, struct pci_dev *dev,
               * do in the second pass.
               */
              if (!pass) {
+                     if (!dev->initial_secondary_bus_number)
+                             dev->initial_secondary_bus_number =
 secondary;
                      if (pcibios_assign_all_busses() || broken)
                              /*
drivers/pci/probe.c +3 -0
@@ -1526,6 +1531,9 @@ static int pci_scan_bridge_extend(struct pci_bus
 *bus, struct pci_dev *dev,
                      child = pci_add_new_bus(bus, dev, next_busnr);
                      if (!child)
                              goto out;
+                     if (dev->initial_secondary_bus_number)
+                             child->initial_bus_number =
+                                     dev->initial_secondary_bus_number;
                      pci_bus_insert_busn_res(child, next_busnr,
                                              bus->busn_res.end);
              }
drivers/pci/probe.c +1 -0
@@ -2508,6 +2516,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
      INIT_LIST_HEAD(&dev->bus_list);
      dev->dev.type = &pci_dev_type;
      dev->bus = pci_bus_get(bus);
+     dev->initial_bus_number = bus ? bus->initial_bus_number : 0;
      dev->driver_exclusive_resource = (struct resource) {
              .name = "PCI Exclusive",
              .start = 0,
include/linux/pci.h index renamed from include/linux/pci.h +0 -0

5ffcf5ce8c966..f6b377dcf7a14 100644

include/linux/pci.h +1 -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 */
+     u8              initial_bus_number;     /* Bus number when device

was discovered */
+ u8 initial_secondary_bus_number; /* Bus number behind
this bridge */

      unsigned short  vendor;
      unsigned short  device;
      unsigned short  subsystem_vendor;
include/linux/pci.h +1 -0
@@ -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   initial_bus_number;     /* 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 */

--
2.43.0

#4 lore raw

Re: [PATCH v2 1/3] PCI: Preserve the initial bus number in pci_dev

In reply to Mario Limonciello
Quoted 75 lines · Mario Limonciello

Bridges that need bus reassignment are scanned in two passes. Save the firmware secondary bus number during the first pass, before the bridge is disabled, and carry it to the bus created in the second pass. Initialize pci_dev from this preserved bus number so drivers can match firmware records after PCI bus renumbering.

Handle pci_alloc_dev(NULL) as well; some in-tree callers use it to allocate a standalone pci_dev.

---
 drivers/pci/probe.c | 9 +++++++++
 include/linux/pci.h | 3 +++
 2 files changed, 12 insertions(+)
drivers/pci/probe.c +9 -0
index 27008e2ea5afc..4ece4b70cdc15 100644
@@ -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->initial_bus_number = 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,7 @@ 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->initial_bus_number = busnr;
 	child->primary = parent->busn_res.start;
 	child->busn_res.end = 0xff;
 
@@ -1470,6 +1472,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->initial_bus_number = secondary;
 			child->primary = primary;
 			pci_bus_insert_busn_res(child, secondary, subordinate);
 			child->bridge_ctl = bctl;
@@ -1491,6 +1494,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
 		 * do in the second pass.
 		 */
 		if (!pass) {
+			if (!dev->initial_secondary_bus_number)
+				dev->initial_secondary_bus_number = secondary;
 			if (pcibios_assign_all_busses() || broken)
 
 				/*
@@ -1526,6 +1531,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
 			child = pci_add_new_bus(bus, dev, next_busnr);
 			if (!child)
 				goto out;
+			if (dev->initial_secondary_bus_number)
+				child->initial_bus_number =
+					dev->initial_secondary_bus_number;
 			pci_bus_insert_busn_res(child, next_busnr,
 						bus->busn_res.end);
 		}
@@ -2508,6 +2516,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
 	INIT_LIST_HEAD(&dev->bus_list);
 	dev->dev.type = &pci_dev_type;
 	dev->bus = pci_bus_get(bus);
+	dev->initial_bus_number = bus ? bus->initial_bus_number : 0;
 	dev->driver_exclusive_resource = (struct resource) {
 		.name = "PCI Exclusive",
 		.start = 0,
include/linux/pci.h +0 -0
index 5ffcf5ce8c966..f6b377dcf7a14 100644

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 */
+	u8		initial_bus_number;	/* Bus number when device was discovered */
+	u8		initial_secondary_bus_number;	/* Bus number behind this bridge */

Why do we need this in the pci_dev? Is there something about pci_scan_bridge_extend() that means it has to be in pci_dev as well as pci_bus? Multiple copies means possible inconsistencies.

include/linux/pci.h struct pci_bus { · line 729

Quoted 8 lines
include/linux/pci.h +1 -0
 	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	initial_bus_number;	/* Bus number before reassignment */

I think it should be stylistically similar to the existing "pci_bus.number"; adding "initial" before or after is ok, but adding both "initial" and "bus" makes them less connected.

Users would check "vhdr->PCIBus == rdev->pdev->bus->number_initial" or similar.

Quoted 7 lines
include/linux/pci.h +0 -0
 	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
#5 lore raw

Re: [PATCH v2 1/3] PCI: Preserve the initial bus number in pci_dev

Quoted 78 lines · Bjorn Helgaas
Quoted 77 lines · Mario Limonciello

Bridges that need bus reassignment are scanned in two passes. Save the firmware secondary bus number during the first pass, before the bridge is disabled, and carry it to the bus created in the second pass. Initialize pci_dev from this preserved bus number so drivers can match firmware records after PCI bus renumbering.

Handle pci_alloc_dev(NULL) as well; some in-tree callers use it to allocate a standalone pci_dev.

---
  drivers/pci/probe.c | 9 +++++++++
  include/linux/pci.h | 3 +++
  2 files changed, 12 insertions(+)
drivers/pci/probe.c +9 -0
index 27008e2ea5afc..4ece4b70cdc15 100644
@@ -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->initial_bus_number = 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,7 @@ 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->initial_bus_number = busnr;
  	child->primary = parent->busn_res.start;
  	child->busn_res.end = 0xff;
 
@@ -1470,6 +1472,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->initial_bus_number = secondary;
  			child->primary = primary;
  			pci_bus_insert_busn_res(child, secondary, subordinate);
  			child->bridge_ctl = bctl;
@@ -1491,6 +1494,8 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
  		 * do in the second pass.
  		 */
  		if (!pass) {
+			if (!dev->initial_secondary_bus_number)
+				dev->initial_secondary_bus_number = secondary;
  			if (pcibios_assign_all_busses() || broken)
 
  				/*
@@ -1526,6 +1531,9 @@ static int pci_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
  			child = pci_add_new_bus(bus, dev, next_busnr);
  			if (!child)
  				goto out;
+			if (dev->initial_secondary_bus_number)
+				child->initial_bus_number =
+					dev->initial_secondary_bus_number;
  			pci_bus_insert_busn_res(child, next_busnr,
  						bus->busn_res.end);
  		}
@@ -2508,6 +2516,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)
  	INIT_LIST_HEAD(&dev->bus_list);
  	dev->dev.type = &pci_dev_type;
  	dev->bus = pci_bus_get(bus);
+	dev->initial_bus_number = bus ? bus->initial_bus_number : 0;
  	dev->driver_exclusive_resource = (struct resource) {
  		.name = "PCI Exclusive",
  		.start = 0,
include/linux/pci.h +0 -0
index 5ffcf5ce8c966..f6b377dcf7a14 100644
@@ -363,6 +363,8 @@ struct pci_dev {
  	struct pci_slot	*slot;		/* Physical slot this device is in */
 
Quoted 7 lines

include/linux/pci.h struct pci_dev { · line 367

Quoted 3 lines
include/linux/pci.h +2 -0
  	unsigned int	devfn;		/* Encoded device & function index */
+	u8		initial_bus_number;	/* Bus number when device was discovered */
+	u8		initial_secondary_bus_number;	/* Bus number behind this bridge */

Why do we need this in the pci_dev? Is there something about pci_scan_bridge_extend() that means it has to be in pci_dev as well as pci_bus? Multiple copies means possible inconsistencies.

Agreed that the initial bus number should have one canonical home. I'll remove the copy from pci_dev; the drivers now read it from pdev->bus.

The separate initial_secondary_bus_number is temporary bridge state: pci_scan_bridge_extend() captures the firmware value in pass 0, before clearing the bridge, then transfers it to the child bus in pass 1 and clears it.

Quoted 14 lines

include/linux/pci.h struct pci_bus { · line 729

Quoted 9 lines
include/linux/pci.h +1 -0
  	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	initial_bus_number;	/* Bus number before reassignment */

I think it should be stylistically similar to the existing "pci_bus.number"; adding "initial" before or after is ok, but adding both "initial" and "bus" makes them less connected.

Quoted 2 lines

Users would check "vhdr->PCIBus == rdev->pdev->bus->number_initial" or similar.

OK, will adjust.

Quoted 8 lines
Quoted 8 lines
include/linux/pci.h +0 -0
  	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
#6 lore raw

PATCH v2 2/3 drm/amdgpu: Match VFCT using initial PCI bus number

In reply to Mario Limonciello

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 11c141672045f ("drm/amdgpu: Fix VFCT bus number matching with soft filter")
---
 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
index 08ed1eb695586..2b375e6b39d5f 100644
@@ -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->initial_bus_number ? 0 : -ENODEV;
 }
 
 static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH v2 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.

Fixes 11c141672045f ("drm/amdgpu: Fix VFCT bus number matching with soft filter")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#8 lore raw

PATCH v2 3/3 drm/radeon: Match VFCT using initial PCI bus number

In reply to Mario Limonciello

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")
---
 drivers/gpu/drm/radeon/radeon_bios.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +3 -14
index 1da6bf1c17ff3..88989c93757b1 100644
@@ -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->initial_bus_number ? 0 : -ENODEV;
 }
 
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
Signature · 1 line
2.43.0
#9 lore raw

Re: [PATCH v2 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")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3