[PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release
From: Baoli Zhang
Date: Sun Nov 15 2026 - 20:26:05 EST
xe frees all the KMS objects on unbind, from the xe_display_fini_early()
devres action. If userspace still holds the DRM fd open at that point,
e.g. a display server with framebuffers created through ADDFB, those
framebuffers are freed while still linked on the file's list:
WARNING: drivers/gpu/drm/drm_mode_config.c:571 at drm_mode_config_cleanup+0x2e7/0x300
Call Trace:
intel_display_driver_remove_noirq+0x55/0xb0 [xe]
xe_display_fini_early+0x37/0x50 [xe]
devres_release_all+0x94/0xe0
device_release_driver_internal+0x1c3/0x200
unbind_store+0xa4/0xb0
xe 0000:00:02.0: [drm] drm_WARN_ON(!list_empty(&fb->filp_head))
WARNING: drivers/gpu/drm/drm_framebuffer.c:833 at drm_framebuffer_free+0x87/0xa0
and drm_fb_release() touches the freed framebuffers when the fd is
closed later, a use-after-free.
Resources visible to userspace must only be freed with the last
reference to the DRM device, see the DRM device instance documentation
in drm_drv.c. drm_mode_config_init() already registers
drm_mode_config_cleanup() as a drmm action, and the display device is
freed by a drmm action registered before it, so it is still around when
the KMS objects get destroyed.
Stop calling intel_display_driver_mode_config_cleanup() from xe and let
drmm free the KMS objects instead. The encoder hardware teardown still
happens on unbind, through intel_display_driver_remove_noirq().
Fixes: 5b6937b65e45 ("drm/xe/display: move display fini stuff to devm")
Tested-by: Yanx L Liu <yanx.l.liu@xxxxxxxxx>
Signed-off-by: Baoli Zhang <baoli.zhang@xxxxxxxxxxxxxxx>
---
drivers/gpu/drm/xe/display/xe_display.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
index d33052a98d942..1c7f08fb9d2ce 100644
--- a/drivers/gpu/drm/xe/display/xe_display.c
+++ b/drivers/gpu/drm/xe/display/xe_display.c
@@ -72,8 +72,11 @@ static void xe_display_fini_early(void *arg)
if (!xe->info.probe_display)
return;
+ /*
+ * The KMS objects are freed by drmm when the last reference to the DRM
+ * device is gone, as userspace may still hold the DRM fd open.
+ */
intel_display_driver_remove_noirq(display);
- intel_display_driver_mode_config_cleanup(display);
intel_display_driver_remove_nogem(display);
intel_display_power_cleanup(display);
}
@@ -111,7 +114,6 @@ int xe_display_init_early(struct xe_device *xe)
return devm_add_action_or_reset(xe->drm.dev, xe_display_fini_early, xe);
err_noirq:
intel_display_driver_remove_noirq(display);
- intel_display_driver_mode_config_cleanup(display);
intel_display_power_cleanup(display);
return err;
--
2.43.0