All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baoli Zhang <baoli.zhang@linux.intel.com>
To: intel-xe@lists.freedesktop.org, intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	jani.nikula@linux.intel.com, rodrigo.vivi@intel.com,
	joonas.lahtinen@linux.intel.com, tursulin@ursulin.net,
	matthew.brost@intel.com, thomas.hellstrom@linux.intel.com,
	matthew.auld@intel.com, airlied@gmail.com, simona@ffwll.ch,
	andriy.shevchenko@linux.intel.com,
	Baoli Zhang <baoli.zhang@linux.intel.com>,
	Yanx L Liu <yanx.l.liu@intel.com>
Subject: [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release
Date: Mon, 16 Nov 2026 09:15:04 +0800	[thread overview]
Message-ID: <20261116011504.3910139-4-baoli.zhang@linux.intel.com> (raw)
In-Reply-To: <20261116011504.3910139-1-baoli.zhang@linux.intel.com>

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@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
 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


  parent reply	other threads:[~2026-11-16  1:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  1:15 [PATCH 0/3] drm/xe/display: Free the KMS objects on DRM device release, not on unbind Baoli Zhang
2026-11-16  1:15 ` [PATCH 1/3] drm/i915/display: Tear down encoder hardware state in a separate hook Baoli Zhang
2026-11-16  1:38   ` sashiko-bot
2026-11-16  1:15 ` [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects Baoli Zhang
2026-11-16  1:53   ` sashiko-bot
2026-11-16  8:39   ` Jani Nikula
2026-11-17  1:41     ` Zhang, Baoli
2026-11-16  1:15 ` Baoli Zhang [this message]
2026-11-16  1:54   ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release sashiko-bot
2026-11-16  1:35 ` ✓ CI.KUnit: success for drm/xe/display: Free the KMS objects on DRM device release, not on unbind Patchwork
2026-11-16  2:08 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-16  2:39 ` ✗ i915.CI.BAT: failure " Patchwork
2026-11-16  3:20 ` ✗ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261116011504.3910139-4-baoli.zhang@linux.intel.com \
    --to=baoli.zhang@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew.auld@intel.com \
    --cc=matthew.brost@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tursulin@ursulin.net \
    --cc=yanx.l.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.