Skip to contentSkip to conversation

drm/amdgpu: only remove existing FBs for devices with displays

PATCH In review Alex Deucher 3 participants 3 messages Jan 16, 2024 – Jan 17, 2024

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: only remove existing FBs for devices with displays

Seems calling drm_aperture_remove_conflicting_pci_framebuffers() will take away the apertures for unrelated devices on some kernel versions. E.g., calling this on a PCIe accelerator with no display IP may take the apertures away from the actual PCIe display adapter on the system, breaking efifb, depending on the kernel version.

Just do this if there is display IP present.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -4
index 62772b58ef3d..353c38f008e8 100644
@@ -4056,10 +4056,12 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
 	amdgpu_device_set_mcbp(adev);
 
-	/* Get rid of things like offb */
-	r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
-	if (r)
-		return r;
+	if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_DCE)) {
+		/* Get rid of things like offb */
+		r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
+		if (r)
+			return r;
+	}
 
 	/* Enable TMZ based on IP_VERSION */
 	amdgpu_gmc_tmz_set(adev);
Signature · 1 line
2.42.0
#1 lore raw

Am 16.01.24 um 15:39 schrieb Alex Deucher:

Quoted 7 lines

Seems calling drm_aperture_remove_conflicting_pci_framebuffers() will take away the apertures for unrelated devices on some kernel versions. E.g., calling this on a PCIe accelerator with no display IP may take the apertures away from the actual PCIe display adapter on the system, breaking efifb, depending on the kernel version.

Just do this if there is display IP present.

I would have checked the PCI device type instead, because a system BIOS most likely has no idea that a VGA device doesn't has a connector.

Quoted 10 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 62772b58ef3d..353c38f008e8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev, · line 4059

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -4
@@ -4056,10 +4056,12 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
  	amdgpu_device_set_mcbp(adev);
 
-	/* Get rid of things like offb */
-	r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
-	if (r)
-		return r;
+	if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_DCE)) {

This certainly worth a comment why we do this.

Apart from that I'm not sure we should upstream this, the customer kernel is most likely just missing this fix here:

commit 5ae3716cfdcd286268133867f67d0803847acefc
Author: Daniel Vetter <[email protected]>
Date:   Thu Apr 6 15:21:07 2023 +0200

    video/aperture: Only remove sysfb on the default vga pci device

    Instead of calling aperture_remove_conflicting_devices() to remove the conflicting devices, just call to aperture_detach_devices() to detach the device that matches the same PCI BAR / aperture range. Since the former is just a wrapper of the latter plus a sysfb_disable() call, and now that's done in this function but only for the primary devices.

    This fixes a regression introduced by commit ee7a69aa38d8 ("fbdev:
    Disable sysfb device registration when removing conflicting FBs"), where we remove the sysfb when loading a driver for an unrelated pci device, resulting in the user losing their efifb console or similar.

    Note that in practice this only is a problem with the nvidia blob, because that's the only gpu driver people might install which does not come with an fbdev driver of it's own. For everyone else the real gpu driver will restore a working console.

    Also note that in the referenced bug there's confusion that this same bug also happens on amdgpu. But that was just another amdgpu specific regression, which just happened to happen at roughly the same time and with the same user-observable symptoms. That bug is fixed now, see
    https://bugzilla.kernel.org/show_bug.cgi?id=216331#c15

Regards,
Christian.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+		/* Get rid of things like offb */
+		r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
+		if (r)
+			return r;
+	}
 
  	/* Enable TMZ based on IP_VERSION */
  	amdgpu_gmc_tmz_set(adev);
#2 lore raw
Quoted 8 lines · Christian König

Am 16.01.24 um 15:39 schrieb Alex Deucher:

Quoted 6 lines

Seems calling drm_aperture_remove_conflicting_pci_framebuffers() will take away the apertures for unrelated devices on some kernel versions. E.g., calling this on a PCIe accelerator with no display IP may take the apertures away from the actual PCIe display adapter on the system, breaking efifb, depending on the kernel version.

Quoted 4 lines
Quoted 1 line

Just do this if there is display IP present.

I would have checked the PCI device type instead, because a system BIOS most likely has no idea that a VGA device doesn't has a connector.

True, but we have GPUs of PCI class PCI_CLASS_DISPLAY_OTHER that can have efifb bound to it. Unfortunately, the combinations of PCI classes and displays is complicated:

PCI_CLASS_DISPLAY_VGA - boards both with and without display hardware PCI_CLASS_DISPLAY_OTHER - boards both with and without display hardware PCI_CLASS_ACCELERATOR_PROCESSING - no display hardware

Quoted 47 lines
Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 62772b58ef3d..353c38f008e8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_init(struct amdgpu_device *adev, · line 4059

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -4
@@ -4056,10 +4056,12 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 
      amdgpu_device_set_mcbp(adev);
 
-     /* Get rid of things like offb */
-     r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
-     if (r)
-             return r;
+     if (amdgpu_device_ip_get_ip_block(adev, AMD_IP_BLOCK_TYPE_DCE)) {

This certainly worth a comment why we do this.

Apart from that I'm not sure we should upstream this, the customer kernel is most likely just missing this fix here:

commit 5ae3716cfdcd286268133867f67d0803847acefc

Author: Daniel Vetter <[email protected]>
Date:   Thu Apr 6 15:21:07 2023 +0200

video/aperture: Only remove sysfb on the default vga pci device

Instead of calling aperture_remove_conflicting_devices() to remove the conflicting devices, just call to aperture_detach_devices() to detach the device that matches the same PCI BAR / aperture range. Since the former is just a wrapper of the latter plus a sysfb_disable() call, and now that's done in this function but only for the primary devices.

This fixes a regression introduced by commit ee7a69aa38d8 ("fbdev:
Disable sysfb device registration when removing conflicting FBs"), where we remove the sysfb when loading a driver for an unrelated pci device, resulting in the user losing their efifb console or similar.

Note that in practice this only is a problem with the nvidia blob, because that's the only gpu driver people might install which does not come with an fbdev driver of it's own. For everyone else the real gpu driver will restore a working console.

Quoted 6 lines

Also note that in the referenced bug there's confusion that this same bug also happens on amdgpu. But that was just another amdgpu specific regression, which just happened to happen at roughly the same time and with the same user-observable symptoms. That bug is fixed now, see
https://bugzilla.kernel.org/show_bug.cgi?id=216331#c15

yeah, that looks like the right fix.

Alex

Quoted 12 lines

Regards,
Christian.

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5 -0
+             /* Get rid of things like offb */
+             r = drm_aperture_remove_conflicting_pci_framebuffers(adev->pdev, &amdgpu_kms_driver);
+             if (r)
+                     return r;
+     }
 
      /* Enable TMZ based on IP_VERSION */
      amdgpu_gmc_tmz_set(adev);