Skip to contentSkip to conversation

Allow matching devices with different bus numbers

PATCH In review Mario Limonciello 4 participants 12 messages Jul 8 – Jul 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Allow matching devices with different bus numbers

If a user has specified pci=realloc,assign-busses on kernel command line then it's plausible that the bus number in the ACPI VFCT won't match the bus number the kernel assigned.

In this case the device will fail to probe because of the mismatch.

Loosen the requirements on VFCT bus number matching to allow this case but log it with dev_notice().

Cc: Oz Tiram <[email protected]>
Mario Limonciello (5):
drm/amdgpu: Fix VFCT bus number matching with soft filter drm/amdgpu: Release VFCT ACPI table reference drm/radeon: Modernize VFCT error handling drm/radeon: Fix VFCT bus number matching with soft filter drm/radeon: Validate VBIOS signature in VFCT path

 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 62 +++++++++++++++++++----
 drivers/gpu/drm/radeon/radeon_bios.c     | 64 +++++++++++++++++++-----
 2 files changed, 103 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/5 drm/amdgpu: Fix VFCT bus number matching with soft filter

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes amdgpu_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce amdgpu_acpi_vfct_match() which treats the bus number as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 45 +++++++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +40 -5
index 3ebdd792feec1..d8fd047295d9d 100644
@@ -377,6 +377,45 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev)
 		false : amdgpu_asic_read_disabled_bios(adev);
 }
 
+/**
+ * amdgpu_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @adev: AMDGPU device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int amdgpu_acpi_vfct_match(struct amdgpu_device *adev,
+				  VFCT_IMAGE_HEADER *vhdr)
+{
+	/* Vendor and device IDs must always match */
+	if (vhdr->VendorID != adev->pdev->vendor ||
+	    vhdr->DeviceID != adev->pdev->device)
+		return -ENODEV;
+
+	if (vhdr->PCIDevice != PCI_SLOT(adev->pdev->devfn) ||
+	    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;
+}
+
 #ifdef CONFIG_ACPI
 static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 {
@@ -413,11 +452,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 		}
 
 		if (vhdr->ImageLength &&
-		    vhdr->PCIBus == adev->pdev->bus->number &&
-		    vhdr->PCIDevice == PCI_SLOT(adev->pdev->devfn) &&
-		    vhdr->PCIFunction == PCI_FUNC(adev->pdev->devfn) &&
-		    vhdr->VendorID == adev->pdev->vendor &&
-		    vhdr->DeviceID == adev->pdev->device) {
+		    !amdgpu_acpi_vfct_match(adev, vhdr)) {
 			adev->bios = kmemdup(&vbios->VbiosContent,
 					     vhdr->ImageLength,
 					     GFP_KERNEL);
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/5] drm/amdgpu: Fix VFCT bus number matching with soft filter

Hello,

Quoted 72 lines · Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes amdgpu_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce amdgpu_acpi_vfct_match() which treats the bus number as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 45 +++++++++++++++++++++---
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +39 -0
index 3ebdd792feec1..d8fd047295d9d 100644
@@ -377,6 +377,45 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev)
 		false : amdgpu_asic_read_disabled_bios(adev);
 }
 
+/**
+ * amdgpu_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @adev: AMDGPU device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int amdgpu_acpi_vfct_match(struct amdgpu_device *adev,
+				  VFCT_IMAGE_HEADER *vhdr)
+{
+	/* Vendor and device IDs must always match */
+	if (vhdr->VendorID != adev->pdev->vendor ||
+	    vhdr->DeviceID != adev->pdev->device)
+		return -ENODEV;
+
+	if (vhdr->PCIDevice != PCI_SLOT(adev->pdev->devfn) ||
+	    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;
+}
+
 #ifdef CONFIG_ACPI
 static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 {
@@ -413,11 +452,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 		}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) · line 458

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +1 -5
 		if (vhdr->ImageLength &&
-		    vhdr->PCIBus == adev->pdev->bus->number &&
-		    vhdr->PCIDevice == PCI_SLOT(adev->pdev->devfn) &&
-		    vhdr->PCIFunction == PCI_FUNC(adev->pdev->devfn) &&
-		    vhdr->VendorID == adev->pdev->vendor &&
-		    vhdr->DeviceID == adev->pdev->device) {
+		    !amdgpu_acpi_vfct_match(adev, vhdr)) {
 			adev->bios = kmemdup(&vbios->VbiosContent,
 					     vhdr->ImageLength,
 					     GFP_KERNEL);

For the record to hopefully make it easier for others to find the fix:

This patch became 33a18ecd2fbf in

https://gitlab.freedesktop.org/agd5f/linux.git drm-next

and thus next and it introduces a build failure for !CONFIG_ACPI builds:

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,
| ^~~~~~~~~~~~~~~~~~~~~~

Patch available at https://lore.kernel.org/all/[email protected]/

Best regards
Uwe

#3 lore raw

Re: [PATCH 1/5] drm/amdgpu: Fix VFCT bus number matching with soft filter

Quoted 94 lines · Uwe Kleine-König

Hello,

Quoted 72 lines · Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes amdgpu_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce amdgpu_acpi_vfct_match() which treats the bus number as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 45 +++++++++++++++++++++---
  1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +39 -0
index 3ebdd792feec1..d8fd047295d9d 100644
@@ -377,6 +377,45 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev)
  		false : amdgpu_asic_read_disabled_bios(adev);
  }
 
+/**
+ * amdgpu_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @adev: AMDGPU device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int amdgpu_acpi_vfct_match(struct amdgpu_device *adev,
+				  VFCT_IMAGE_HEADER *vhdr)
+{
+	/* Vendor and device IDs must always match */
+	if (vhdr->VendorID != adev->pdev->vendor ||
+	    vhdr->DeviceID != adev->pdev->device)
+		return -ENODEV;
+
+	if (vhdr->PCIDevice != PCI_SLOT(adev->pdev->devfn) ||
+	    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;
+}
+
  #ifdef CONFIG_ACPI
  static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
  {
@@ -413,11 +452,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
  		}
 

drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) · line 458

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +1 -5
  		if (vhdr->ImageLength &&
-		    vhdr->PCIBus == adev->pdev->bus->number &&
-		    vhdr->PCIDevice == PCI_SLOT(adev->pdev->devfn) &&
-		    vhdr->PCIFunction == PCI_FUNC(adev->pdev->devfn) &&
-		    vhdr->VendorID == adev->pdev->vendor &&
-		    vhdr->DeviceID == adev->pdev->device) {
+		    !amdgpu_acpi_vfct_match(adev, vhdr)) {
  			adev->bios = kmemdup(&vbios->VbiosContent,
  					     vhdr->ImageLength,
  					     GFP_KERNEL);

For the record to hopefully make it easier for others to find the fix:

This patch became 33a18ecd2fbf in

https://gitlab.freedesktop.org/agd5f/linux.git drm-next

and thus next and it introduces a build failure for !CONFIG_ACPI builds:

Quoted 8 lines

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,
| ^~~~~~~~~~~~~~~~~~~~~~

Patch available at https://lore.kernel.org/all/[email protected]/

Best regards
Uwe

Thanks. Alex can you squash that in, or has the merge request already gone out?

#4 lore raw

Re: [PATCH 1/5] drm/amdgpu: Fix VFCT bus number matching with soft filter

Quoted 102 lines · Mario Limonciello
Quoted 98 lines · Uwe Kleine-König

Hello,

Quoted 72 lines · Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes amdgpu_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce amdgpu_acpi_vfct_match() which treats the bus number as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 45 +++++++++++++++++++++---
  1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +39 -0
index 3ebdd792feec1..d8fd047295d9d 100644
@@ -377,6 +377,45 @@ static bool amdgpu_read_disabled_bios(struct amdgpu_device *adev)
             false : amdgpu_asic_read_disabled_bios(adev);
  }
 
+/**
+ * amdgpu_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @adev: AMDGPU device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int amdgpu_acpi_vfct_match(struct amdgpu_device *adev,
+                              VFCT_IMAGE_HEADER *vhdr)
+{
+    /* Vendor and device IDs must always match */
+    if (vhdr->VendorID != adev->pdev->vendor ||
+        vhdr->DeviceID != adev->pdev->device)
+            return -ENODEV;
+
+    if (vhdr->PCIDevice != PCI_SLOT(adev->pdev->devfn) ||
+        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;
+}
+
  #ifdef CONFIG_ACPI
  static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
  {
@@ -413,11 +452,7 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
             }
 

drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev) · line 458

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +1 -5
             if (vhdr->ImageLength &&
-                vhdr->PCIBus == adev->pdev->bus->number &&
-                vhdr->PCIDevice == PCI_SLOT(adev->pdev->devfn) &&
-                vhdr->PCIFunction == PCI_FUNC(adev->pdev->devfn) &&
-                vhdr->VendorID == adev->pdev->vendor &&
-                vhdr->DeviceID == adev->pdev->device) {
+                !amdgpu_acpi_vfct_match(adev, vhdr)) {
                     adev->bios = kmemdup(&vbios->VbiosContent,
                                          vhdr->ImageLength,
                                          GFP_KERNEL);

For the record to hopefully make it easier for others to find the fix:

This patch became 33a18ecd2fbf in

https://gitlab.freedesktop.org/agd5f/linux.git drm-next

and thus next and it introduces a build failure for !CONFIG_ACPI builds:

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,
| ^~~~~~~~~~~~~~~~~~~~~~

Quoted 7 lines
Quoted 4 lines

Patch available at https://lore.kernel.org/all/[email protected]/

Best regards
Uwe

Thanks. Alex can you squash that in, or has the merge request already gone out?

Already out. I've picked up Uwe's patch.

Alex

#5 lore raw

PATCH 2/5 drm/amdgpu: Release VFCT ACPI table reference

In reply to Mario Limonciello

amdgpu_acpi_vfct_bios() fetches the VFCT table with acpi_get_table() but never releases it. acpi_get_table() takes a reference on the table (incrementing its validation_count and mapping it on the 0->1 transition); without a paired acpi_put_table() the mapping is leaked on every call, whether or not a matching VBIOS image is found.

Route all exit paths after the table is acquired through a common acpi_put_table(). The VBIOS image is copied out with kmemdup() before the table is released, so it remains valid for the caller.

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c +11 -6
index d8fd047295d9d..bf6df87e0bafd 100644
@@ -423,13 +423,14 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 	acpi_size tbl_size;
 	UEFI_ACPI_VFCT *vfct;
 	unsigned int offset;
+	bool r = false;
 
 	if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr)))
 		return false;
 	tbl_size = hdr->length;
 	if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
 		dev_info(adev->dev, "ACPI VFCT table present but broken (too short #1),skipping\n");
-		return false;
+		goto out;
 	}
 
 	vfct = (UEFI_ACPI_VFCT *)hdr;
@@ -442,13 +443,13 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 		offset += sizeof(VFCT_IMAGE_HEADER);
 		if (offset > tbl_size) {
 			dev_info(adev->dev, "ACPI VFCT image header truncated,skipping\n");
-			return false;
+			goto out;
 		}
 
 		offset += vhdr->ImageLength;
 		if (offset > tbl_size) {
 			dev_info(adev->dev, "ACPI VFCT image truncated,skipping\n");
-			return false;
+			goto out;
 		}
 
 		if (vhdr->ImageLength &&
@@ -459,15 +460,19 @@ static bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
 
 			if (!check_atom_bios(adev, vhdr->ImageLength)) {
 				amdgpu_bios_release(adev);
-				return false;
+				goto out;
 			}
 			adev->bios_size = vhdr->ImageLength;
-			return true;
+			r = true;
+			goto out;
 		}
 	}
 
 	dev_info(adev->dev, "ACPI VFCT table present but broken (too short #2),skipping\n");
-	return false;
+
+out:
+	acpi_put_table(hdr);
+	return r;
 }
 #else
 static inline bool amdgpu_acpi_vfct_bios(struct amdgpu_device *adev)
Signature · 1 line
2.43.0
#6 lore raw

PATCH 3/5 drm/radeon: Modernize VFCT error handling

In reply to Mario Limonciello

Clean up radeon_acpi_vfct_bios() logging:

- Replace DRM_ERROR with dev_warn tied to the PCI device
- Use unsigned int rather than bare unsigned for the offset

A malformed or missing VFCT table is not fatal: radeon falls back to the other BIOS fetch methods, so warn rather than error on these paths.

The goto out label is retained: acpi_get_table() takes a reference on the table (incrementing its validation_count and mapping it), which must be released with a paired acpi_put_table() on every exit path.

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/radeon/radeon_bios.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +5 -5
index 3a8c5199a0fe7..c6df799c3cf4a 100644
@@ -602,14 +602,14 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 	struct acpi_table_header *hdr;
 	acpi_size tbl_size;
 	UEFI_ACPI_VFCT *vfct;
-	unsigned offset;
+	unsigned int offset;
 	bool r = false;
 
 	if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr)))
 		return false;
 	tbl_size = hdr->length;
 	if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
-		DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
+		dev_warn(&rdev->pdev->dev, "ACPI VFCT table present but broken (too short #1),skipping\n");
 		goto out;
 	}
 
@@ -622,13 +622,13 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 
 		offset += sizeof(VFCT_IMAGE_HEADER);
 		if (offset > tbl_size) {
-			DRM_ERROR("ACPI VFCT image header truncated\n");
+			dev_warn(&rdev->pdev->dev, "ACPI VFCT image header truncated,skipping\n");
 			goto out;
 		}
 
 		offset += vhdr->ImageLength;
 		if (offset > tbl_size) {
-			DRM_ERROR("ACPI VFCT image truncated\n");
+			dev_warn(&rdev->pdev->dev, "ACPI VFCT image truncated,skipping\n");
 			goto out;
 		}
 
@@ -648,7 +648,7 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 		}
 	}
 
-	DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
+	dev_warn(&rdev->pdev->dev, "ACPI VFCT table present but broken (too short #2),skipping\n");
 
 out:
 	acpi_put_table(hdr);
Signature · 1 line
2.43.0
#7 lore raw

PATCH 4/5 drm/radeon: Fix VFCT bus number matching with soft filter

In reply to Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes radeon_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce radeon_acpi_vfct_match() which treats the bus number as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics. This mirrors the equivalent amdgpu change.

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/radeon/radeon_bios.c | 45 ++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +40 -5
index c6df799c3cf4a..cc10880af096b 100644
@@ -596,6 +596,45 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev)
 		return legacy_read_disabled_bios(rdev);
 }
 
+/**
+ * radeon_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @rdev: Radeon device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int radeon_acpi_vfct_match(struct radeon_device *rdev,
+				  VFCT_IMAGE_HEADER *vhdr)
+{
+	/* Vendor and device IDs must always match */
+	if (vhdr->VendorID != rdev->pdev->vendor ||
+	    vhdr->DeviceID != rdev->pdev->device)
+		return -ENODEV;
+
+	if (vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
+	    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;
+}
+
 #ifdef CONFIG_ACPI
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
@@ -633,11 +672,7 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 		}
 
 		if (vhdr->ImageLength &&
-		    vhdr->PCIBus == rdev->pdev->bus->number &&
-		    vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) &&
-		    vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) &&
-		    vhdr->VendorID == rdev->pdev->vendor &&
-		    vhdr->DeviceID == rdev->pdev->device) {
+		    !radeon_acpi_vfct_match(rdev, vhdr)) {
 			rdev->bios = kmemdup(&vbios->VbiosContent,
 					     vhdr->ImageLength,
 					     GFP_KERNEL);
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH 4/5] drm/radeon: Fix VFCT bus number matching with soft filter

Quoted 7 lines · Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes radeon_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce radeon_acpi_vfct_match()

This patch showed up in -next yesterday and from a very quick look seems likely to be the reason for a ppc64le build error I ran into:

"""drivers/gpu/drm/radeon/radeon_bios.c:614:12: error:
‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289:
drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228:
.] Error 2
make: *** [Makefile:256: __sub-make] Error 2
"""

Full log:
https://download.copr.fedorainfracloud.org/results/@kernel-vanilla/next/fedora-rawhide-ppc64le/10721545-next-next-all/builder-live.log.gz

Ciao, Thorsten

Quoted 1 line

drivers/gpu/drm/radeon/radeon_bios.c:6> drivers/gpu/drm/radeon/radeon_bios.c:614:12: error:

‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]

Quoted 11 lines

614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

14:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]

Quoted 130 lines

614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

which treats the bus number
as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics. This mirrors the equivalent amdgpu change.

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/radeon/radeon_bios.c | 45 ++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +40 -5
index c6df799c3cf4a..cc10880af096b 100644
@@ -596,6 +596,45 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev)
 		return legacy_read_disabled_bios(rdev);
 }
 
+/**
+ * radeon_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @rdev: Radeon device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int radeon_acpi_vfct_match(struct radeon_device *rdev,
+				  VFCT_IMAGE_HEADER *vhdr)
+{
+	/* Vendor and device IDs must always match */
+	if (vhdr->VendorID != rdev->pdev->vendor ||
+	    vhdr->DeviceID != rdev->pdev->device)
+		return -ENODEV;
+
+	if (vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
+	    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;
+}
+
 #ifdef CONFIG_ACPI
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
@@ -633,11 +672,7 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 		}
 
 		if (vhdr->ImageLength &&
-		    vhdr->PCIBus == rdev->pdev->bus->number &&
-		    vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) &&
-		    vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) &&
-		    vhdr->VendorID == rdev->pdev->vendor &&
-		    vhdr->DeviceID == rdev->pdev->device) {
+		    !radeon_acpi_vfct_match(rdev, vhdr)) {
 			rdev->bios = kmemdup(&vbios->VbiosContent,
 					     vhdr->ImageLength,
 					     GFP_KERNEL);
#9 lore raw

Re: [PATCH 4/5] drm/radeon: Fix VFCT bus number matching with soft filter

Quoted 31 lines · Thorsten Leemhuis
Quoted 7 lines · Mario Limonciello

On systems where PCI bus renumbering occurs (e.g. pci=realloc, resource conflicts), the runtime bus number may differ from the BIOS POST bus number recorded in the VFCT table. This causes radeon_acpi_vfct_bios() to fail finding the VBIOS even though the correct device entry exists.

Introduce radeon_acpi_vfct_match()

This patch showed up in -next yesterday and from a very quick look seems likely to be the reason for a ppc64le build error I ran into:

"""drivers/gpu/drm/radeon/radeon_bios.c:614:12: error:
‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289:
drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228:
.] Error 2
make: *** [Makefile:256: __sub-make] Error 2
"""

Quoted 3 lines

Full log:
https://download.copr.fedorainfracloud.org/results/@kernel-vanilla/next/fedora-rawhide-ppc64le/10721545-next-next-all/builder-live.log.gz

Fixed with this patch:
https://patchwork.freedesktop.org/patch/740649/?series=170572&rev=1

Alex

Quoted 149 lines

Ciao, Thorsten

Quoted 1 line

drivers/gpu/drm/radeon/radeon_bios.c:6> drivers/gpu/drm/radeon/radeon_bios.c:614:12: error:

‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]

Quoted 11 lines

614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

14:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]

Quoted 130 lines

614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

drivers/gpu/drm/radeon/radeon_bios.c:614:12: error: ‘radeon_acpi_vfct_match’ defined but not used [-Werror=unused-function]
614 | static int radeon_acpi_vfct_match(struct radeon_device *rdev,

      |            ^~~~~~~~~~~~~~~~~~~~~~

cc1: all warnings being treated as errors
make[6]: *** [scripts/Makefile.build:289: drivers/gpu/drm/radeon/radeon_bios.o] Error 1
make[5]: *** [scripts/Makefile.build:549: drivers/gpu/drm/radeon] Error 2
make[5]: *** Waiting for unfinished jobs....
make[4]: *** [scripts/Makefile.build:549: drivers/gpu/drm] Error 2
make[3]: *** [scripts/Makefile.build:549: drivers/gpu] Error 2
make[2]: *** [scripts/Makefile.build:549: drivers] Error 2
make[1]: *** [/builddir/build/BUILD/kernel-7.2.0-build/kernel-next-20260715/linux-7.2.0-0.0.next.20260715.427.vanilla.fc45.ppc64le/Makefile:2228: .] Error 2
make: *** [Makefile:256: __sub-make] Error 2

which treats the bus number
as a soft filter: vendor/device/function identity is the hard requirement, while exact bus match is the preferred path. When bus numbers disagree but device identity matches, accept the VFCT entry and log a dev_notice for diagnostics. This mirrors the equivalent amdgpu change.

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/radeon/radeon_bios.c | 45 ++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +40 -5
index c6df799c3cf4a..cc10880af096b 100644
@@ -596,6 +596,45 @@ static bool radeon_read_disabled_bios(struct radeon_device *rdev)
              return legacy_read_disabled_bios(rdev);
 }
 
+/**
+ * radeon_acpi_vfct_match() - Check if a VFCT entry matches the device
+ * @rdev: Radeon device
+ * @vhdr: VFCT image header to check
+ *
+ * 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.
+ *
+ * Returns: 0 on match, -ENODEV on no match
+ */
+static int radeon_acpi_vfct_match(struct radeon_device *rdev,
+                               VFCT_IMAGE_HEADER *vhdr)
+{
+     /* Vendor and device IDs must always match */
+     if (vhdr->VendorID != rdev->pdev->vendor ||
+         vhdr->DeviceID != rdev->pdev->device)
+             return -ENODEV;
+
+     if (vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
+         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;
+}
+
 #ifdef CONFIG_ACPI
 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 {
@@ -633,11 +672,7 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
              }
 
              if (vhdr->ImageLength &&
-                 vhdr->PCIBus == rdev->pdev->bus->number &&
-                 vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) &&
-                 vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) &&
-                 vhdr->VendorID == rdev->pdev->vendor &&
-                 vhdr->DeviceID == rdev->pdev->device) {
+                 !radeon_acpi_vfct_match(rdev, vhdr)) {
                      rdev->bios = kmemdup(&vbios->VbiosContent,
                                           vhdr->ImageLength,
                                           GFP_KERNEL);
#10 lore raw

PATCH 5/5 drm/radeon: Validate VBIOS signature in VFCT path

In reply to Mario Limonciello

The VFCT path accepted whatever kmemdup() returned without checking that the copied image is a valid VBIOS. Every other radeon BIOS fetch path verifies the 0x55 0xaa signature before trusting the image; the VFCT path is the odd one out.

Check the signature after copying the image and reject it (freeing the buffer) if it does not match, matching the amdgpu VFCT path which validates via check_atom_bios().

---
Cc: Oz Tiram <[email protected]>

 drivers/gpu/drm/radeon/radeon_bios.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_bios.c +7 -2
index cc10880af096b..215e47c94d29e 100644
@@ -676,9 +676,14 @@ static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
 			rdev->bios = kmemdup(&vbios->VbiosContent,
 					     vhdr->ImageLength,
 					     GFP_KERNEL);
-			if (rdev->bios)
-				r = true;
 
+			if (!rdev->bios ||
+			    rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
+				kfree(rdev->bios);
+				rdev->bios = NULL;
+				goto out;
+			}
+			r = true;
 			goto out;
 		}
 	}
Signature · 1 line
2.43.0
Reviewed-by on the v1 series
#11 lore raw
In reply to Mario Limonciello
Quoted 9 lines · Mario Limonciello

If a user has specified pci=realloc,assign-busses on kernel command line then it's plausible that the bus number in the ACPI VFCT won't match the bus number the kernel assigned.

In this case the device will fail to probe because of the mismatch.

Loosen the requirements on VFCT bus number matching to allow this case but log it with dev_notice().

Series is:

Quoted 16 lines

Cc: Oz Tiram <[email protected]>
Mario Limonciello (5):
drm/amdgpu: Fix VFCT bus number matching with soft filter drm/amdgpu: Release VFCT ACPI table reference drm/radeon: Modernize VFCT error handling drm/radeon: Fix VFCT bus number matching with soft filter drm/radeon: Validate VBIOS signature in VFCT path

 drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c | 62 +++++++++++++++++++----
 drivers/gpu/drm/radeon/radeon_bios.c     | 64 +++++++++++++++++++-----
 2 files changed, 103 insertions(+), 23 deletions(-)

--
2.43.0