Skip to contentSkip to conversation

drm/aperture: Run fbdev removal before internal helpers

PATCH In review Thomas Zimmermann 4 participants 7 messages Jun 17, 2022 – Jun 21, 2022

Subsystems (2)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/aperture: Run fbdev removal before internal helpers

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Fixes 873eb3b11860 ("fbdev: Disable sysfb device registration when removing conflicting FBs")
Cc Javier Martinez Canillas <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Helge Deller <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Zhen Lei <[email protected]>
Cc Changcheng Deng <[email protected]>
---
 drivers/gpu/drm/drm_aperture.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_aperture.c +15 -11
index 74bd4a76b253..059fd71424f6 100644
@@ -329,7 +329,20 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 						     const struct drm_driver *req_driver)
 {
 	resource_size_t base, size;
-	int bar, ret = 0;
+	int bar, ret;
+
+	/*
+	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
+	 * otherwise the vga fbdev driver falls over.
+	 */
+#if IS_REACHABLE(CONFIG_FB)
+	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
+	if (ret)
+		return ret;
+#endif
+	ret = vga_remove_vgacon(pdev);
+	if (ret)
+		return ret;
 
 	for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
 		if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
@@ -339,15 +352,6 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 		drm_aperture_detach_drivers(base, size);
 	}
 
-	/*
-	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
-	 * otherwise the vga fbdev driver falls over.
-	 */
-#if IS_REACHABLE(CONFIG_FB)
-	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
-#endif
-	if (ret == 0)
-		ret = vga_remove_vgacon(pdev);
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers);
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

Quoted 58 lines
Fixes 873eb3b11860 ("fbdev: Disable sysfb device registration when removing conflicting FBs")
Cc Javier Martinez Canillas <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Helge Deller <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Zhen Lei <[email protected]>
Cc Changcheng Deng <[email protected]>
---
 drivers/gpu/drm/drm_aperture.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_aperture.c +15 -11
index 74bd4a76b253..059fd71424f6 100644
@@ -329,7 +329,20 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 						     const struct drm_driver *req_driver)
 {
 	resource_size_t base, size;
-	int bar, ret = 0;
+	int bar, ret;
+
+	/*
+	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
+	 * otherwise the vga fbdev driver falls over.
+	 */
+#if IS_REACHABLE(CONFIG_FB)
+	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
+	if (ret)
+		return ret;
+#endif
+	ret = vga_remove_vgacon(pdev);
+	if (ret)
+		return ret;
 
 	for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
 		if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
@@ -339,15 +352,6 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
 		drm_aperture_detach_drivers(base, size);
 	}
 
-	/*
-	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
-	 * otherwise the vga fbdev driver falls over.
-	 */
-#if IS_REACHABLE(CONFIG_FB)
-	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
-#endif
-	if (ret == 0)
-		ret = vga_remove_vgacon(pdev);
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers);
Signature · 5 lines
Best regards,

Javier Martinez Canillas
Linux Engineering
Red Hat
author maintainer
#2 lore raw

Hi

Am 17.06.22 um 14:29 schrieb Javier Martinez Canillas:

Quoted 47 lines

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Quoted 2 lines

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

I'll do.

Quoted 7 lines

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

Thanks!

Quoted 4 lines

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

If nothing else comes in, I'll merge this patch on Monday and send Alex an updated version of the vfio patch.

Best regards
Thomas

Quoted 60 lines
Quoted 59 lines
Fixes 873eb3b11860 ("fbdev: Disable sysfb device registration when removing conflicting FBs")
Cc Javier Martinez Canillas <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sam Ravnborg <[email protected]>
Cc Helge Deller <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Zhen Lei <[email protected]>
Cc Changcheng Deng <[email protected]>
---
  drivers/gpu/drm/drm_aperture.c | 26 +++++++++++++++-----------
  1 file changed, 15 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_aperture.c +15 -11
index 74bd4a76b253..059fd71424f6 100644
@@ -329,7 +329,20 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
  						     const struct drm_driver *req_driver)
  {
  	resource_size_t base, size;
-	int bar, ret = 0;
+	int bar, ret;
+
+	/*
+	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
+	 * otherwise the vga fbdev driver falls over.
+	 */
+#if IS_REACHABLE(CONFIG_FB)
+	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
+	if (ret)
+		return ret;
+#endif
+	ret = vga_remove_vgacon(pdev);
+	if (ret)
+		return ret;
 
  	for (bar = 0; bar < PCI_STD_NUM_BARS; ++bar) {
  		if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM))
@@ -339,15 +352,6 @@ int drm_aperture_remove_conflicting_pci_framebuffers(struct pci_dev *pdev,
  		drm_aperture_detach_drivers(base, size);
  	}
 
-	/*
-	 * WARNING: Apparently we must kick fbdev drivers before vgacon,
-	 * otherwise the vga fbdev driver falls over.
-	 */
-#if IS_REACHABLE(CONFIG_FB)
-	ret = remove_conflicting_pci_framebuffers(pdev, req_driver->name);
-#endif
-	if (ret == 0)
-		ret = vga_remove_vgacon(pdev);
-	return ret;
+	return 0;
  }
  EXPORT_SYMBOL(drm_aperture_remove_conflicting_pci_framebuffers);
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Reviewed-by
#3 lore raw
Quoted 66 lines · Thomas Zimmermann

Hi

Am 17.06.22 um 14:29 schrieb Javier Martinez Canillas:

Quoted 47 lines

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Quoted 2 lines

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

I'll do.

Quoted 7 lines

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

Thanks!

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

If nothing else comes in, I'll merge this patch on Monday and send Alex an updated version of the vfio patch.

Thanks Thomas. I just tested it on our arm64 configs and it fixes the crash on boot we've been seeing and gets them running again.

z

#4 lore raw
In reply to Thomas Zimmermann
Quoted 66 lines · On Fri, 17 Jun 2022 14:41:01 +0200 Thomas Zimmermann <[email protected]>…

Hi

Am 17.06.22 um 14:29 schrieb Javier Martinez Canillas:

Quoted 47 lines

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Quoted 2 lines

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

I'll do.

Quoted 7 lines

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

Thanks!

Quoted 1 line
Quoted 6 lines
Quoted 3 lines

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

If nothing else comes in, I'll merge this patch on Monday and send Alex an updated version of the vfio patch.

Please also publish a topic branch for the base of that patch if you're still looking for the non-drm aperture + vfio series to go in through my vfio tree. Thanks,

Alex

author maintainer
#5 lore raw

Hi

Am 17.06.22 um 16:12 schrieb Alex Williamson:

Quoted 73 lines
Quoted 70 lines · On Fri, 17 Jun 2022 14:41:01 +0200 Thomas Zimmermann <[email protected]>…

Hi

Am 17.06.22 um 14:29 schrieb Javier Martinez Canillas:

Quoted 47 lines

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Quoted 2 lines

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

I'll do.

Quoted 7 lines

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

Thanks!

Quoted 4 lines

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

Quoted 6 lines
Quoted 2 lines

If nothing else comes in, I'll merge this patch on Monday and send Alex an updated version of the vfio patch.

Please also publish a topic branch for the base of that patch if you're still looking for the non-drm aperture + vfio series to go in through my vfio tree. Thanks,

I have merge the aperture fix, but the vfio thing is getting complicated. Can we merge your vfio patches through drm-misc-next? As the vfio-side of the change already got an r-b from Javier, it should show up in v5.20 then.

Best regards
Thomas

Quoted 3 lines

Alex

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
#6 lore raw
Quoted 79 lines · On Tue, 21 Jun 2022 13:01:08 +0200 Thomas Zimmermann <[email protected]>…

Hi

Am 17.06.22 um 16:12 schrieb Alex Williamson:

Quoted 76 lines
Quoted 72 lines · On Fri, 17 Jun 2022 14:41:01 +0200 Thomas Zimmermann <[email protected]>…

Hi

Am 17.06.22 um 14:29 schrieb Javier Martinez Canillas:

Quoted 47 lines

[adding Zack and Alex to Cc list]

Hello Thomas,

Thanks a lot for tracking this down and figuring out the root cause!

Quoted 30 lines · Thomas Zimmermann

Always run fbdev removal first to remove simpledrm via sysfb_disable(). This clears the internal state. The later call to drm_aperture_detach_drivers() then does nothing. Otherwise, with drm_aperture_detach_drivers() running first, the call to sysfb_disable() uses inconsistent state.

Example backtrace show below:

[   11.663422] ==================================================================
[   11.663426] BUG: KASAN: use-after-free in device_del+0x79/0x5f0
[   11.663435] Read of size 8 at addr ffff888108185050 by task systemd-udevd/311
[   11.663440] CPU: 0 PID: 311 Comm: systemd-udevd Tainted: G            E     5
	.19.0-rc2-1-default+ #1689
[   11.663445] Hardware name: HP ProLiant DL120 G7, BIOS J01 04/21/2011
[   11.663447] Call Trace:
[   11.663449]  <TASK>
[   11.663451]  ? device_del+0x79/0x5f0
[   11.663456]  dump_stack_lvl+0x5b/0x73
[   11.663462]  print_address_description.constprop.0+0x1f/0x1b0
[   11.663468]  ? device_del+0x79/0x5f0
[   11.663471]  ? device_del+0x79/0x5f0
[   11.663475]  print_report.cold+0x3c/0x21c
[   11.663481]  ? lock_acquired+0x87/0x1e0
[   11.663484]  ? lock_acquired+0x87/0x1e0
[   11.663489]  ? device_del+0x79/0x5f0
[   11.663492]  kasan_report+0xbf/0xf0
[   11.663498]  ? device_del+0x79/0x5f0
[   11.663503]  device_del+0x79/0x5f0
[   11.663509]  ? device_remove_attrs+0x170/0x170
[   11.663514]  ? lock_is_held_type+0xe8/0x140
Quoted 9 lines
[   11.663523]  platform_device_del.part.0+0x19/0xe0
[   11.663530]  platform_device_unregister+0x1c/0x30
[   11.663535]  sysfb_disable+0x2d/0x70
[   11.663540]  remove_conflicting_framebuffers+0x1c/0xf0
[   11.663546]  remove_conflicting_pci_framebuffers+0x130/0x1a0
[   11.663554]  drm_aperture_remove_conflicting_pci_framebuffers+0x86/0xb0
[   11.663561]  ? mgag200_pci_remove+0x30/0x30 [mgag200]
[   11.663578]  mgag200_pci_probe+0x2d/0x140 [mgag200]
Quoted 2 lines

Maybe include a Reported-by: Zack Rusin <[email protected]> ? since this seems to be the exact same issue that he reported yesterday.

I'll do.

Quoted 7 lines

Patch looks good to me and this seems to be the correct fix IMO. That way we won't re-introduce the issue that was fixed by the sysfb_unregister() function, that is to remove a pdev even if wasn't bound to a driver to prevent a late simpledrm registration to match.

Thanks!

Quoted 4 lines

I wonder what's the best way to coordinate with Alex to merge this fix and your patch that moves the aperture code out of DRM, since as far as I can tell both should target the v5.20 release.

If nothing else comes in, I'll merge this patch on Monday and send Alex an updated version of the vfio patch.

Quoted 8 lines
Quoted 3 lines

Please also publish a topic branch for the base of that patch if you're still looking for the non-drm aperture + vfio series to go in through my vfio tree. Thanks,

I have merge the aperture fix, but the vfio thing is getting complicated. Can we merge your vfio patches through drm-misc-next? As the vfio-side of the change already got an r-b from Javier, it should show up in v5.20 then.

Sure, if you'd like to take 165541193265.1955826.8778757616438743090.stgit@omen via the drm tree, feel free, it's obviously the more trivial change of the series. Thanks,

Alex