mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] drm/xe/display: Free the KMS objects on DRM device release, not on unbind
@ 2026-11-16  1:15 Baoli Zhang
  2026-11-16  1:15 ` [PATCH 1/3] drm/i915/display: Tear down encoder hardware state in a separate hook Baoli Zhang
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Baoli Zhang @ 2026-11-16  1:15 UTC (permalink / raw)
  To: intel-xe, intel-gfx
  Cc: dri-devel, linux-kernel, jani.nikula, rodrigo.vivi,
	joonas.lahtinen, tursulin, matthew.brost, thomas.hellstrom,
	matthew.auld, airlied, simona, andriy.shevchenko, Baoli Zhang

Unbinding xe while a display server still has the DRM fd open gives
these warnings, and drm_fb_release() later walks the freed framebuffers
when the fd is closed:

  WARNING: drivers/gpu/drm/drm_mode_config.c:571 at drm_mode_config_cleanup+0x2e7/0x300
  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

Since 5b6937b65e45 ("drm/xe/display: move display fini stuff to devm")
xe frees the KMS objects on unbind, but they should only be freed with
the last reference to the DRM device. drm_mode_config_init() already
registers drm_mode_config_cleanup() as a drmm action, so xe can simply
stop calling it. The first two patches prepare the shared display code
for that, with no change for i915:

1: move the hardware teardown out of the encoder ->destroy() callbacks
   into a new ->remove() hook, which still runs on unbind
2: move drm_mode_config_cleanup() out of
   intel_display_driver_remove_noirq() into the drivers
3: the actual fix, xe stops calling it

i915 keeps freeing the KMS objects on unbind for now. It frees the
display structure from its ->release() callback, before the drmm
actions run, so it can't rely on drmm without further changes.

We hit this with the LTP-DDT test TELEMETRY_XS_FUNC_TELEM_DRIVER, which
unbinds xe, on PTL with RHEL 10.3 and a v6.18.60 kernel (the trace above
is from there). It doesn't reproduce on Ubuntu, and only reproduces on
the first run after boot. My guess is that GDM holds the device on RHEL
and doesn't get it back after the first unbind/rebind.

Yanx tested the series backported to v6.18.60, the warnings are gone.
On mainline it is build-tested only.

Baoli Zhang (3):
  drm/i915/display: Tear down encoder hardware state in a separate hook
  drm/i915/display: Let the drivers free the KMS objects
  drm/xe/display: Free the KMS objects on DRM device release

 drivers/gpu/drm/i915/display/g4x_dp.c            |  8 ++++++--
 drivers/gpu/drm/i915/display/intel_ddi.c         | 16 +++++++++++-----
 .../gpu/drm/i915/display/intel_display_driver.c  | 15 ++++++++++++++-
 .../gpu/drm/i915/display/intel_display_driver.h  |  1 +
 .../gpu/drm/i915/display/intel_display_types.h   |  7 +++++++
 drivers/gpu/drm/i915/display/intel_encoder.c     |  9 +++++++++
 drivers/gpu/drm/i915/display/intel_encoder.h     |  1 +
 drivers/gpu/drm/i915/display/intel_sdvo.c        | 11 +++++++++--
 drivers/gpu/drm/i915/i915_driver.c               |  2 ++
 drivers/gpu/drm/xe/display/xe_display.c          |  4 ++++
 10 files changed, 64 insertions(+), 10 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] drm/i915/display: Tear down encoder hardware state in a separate hook
  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 ` Baoli Zhang
  2026-11-16  1:15 ` [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects Baoli Zhang
  2026-11-16  1:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang
  2 siblings, 0 replies; 5+ messages in thread
From: Baoli Zhang @ 2026-11-16  1:15 UTC (permalink / raw)
  To: intel-xe, intel-gfx
  Cc: dri-devel, linux-kernel, jani.nikula, rodrigo.vivi,
	joonas.lahtinen, tursulin, matthew.brost, thomas.hellstrom,
	matthew.auld, airlied, simona, andriy.shevchenko, Baoli Zhang,
	Yanx L Liu

Some encoder ->destroy() callbacks do more than freeing memory: the DDI
and g4x DP encoders tear down MST, DP tunnels, PPS and AUX and flush the
power work, and SDVO removes its I2C adapters. All of this needs the
hardware or is visible to userspace, so it has to happen on driver
remove, while the encoder memory should only be freed once the last
reference to the DRM device is gone.

Add an intel_encoder ->remove() hook for that part, move the hardware
teardown of those encoders there, and call it for all encoders from
intel_mode_config_cleanup() right before drm_mode_config_cleanup(). The
encoders are the first objects drm_mode_config_cleanup() destroys, and
->remove() walks them in the same order, the order they were registered
in, so the order of the teardown doesn't change. None of the ->remove()
callbacks depends on another encoder.

No functional change intended.

Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
 drivers/gpu/drm/i915/display/g4x_dp.c            |  8 ++++++--
 drivers/gpu/drm/i915/display/intel_ddi.c         | 16 +++++++++++-----
 .../gpu/drm/i915/display/intel_display_driver.c  |  3 ++-
 .../gpu/drm/i915/display/intel_display_types.h   |  7 +++++++
 drivers/gpu/drm/i915/display/intel_encoder.c     |  9 +++++++++
 drivers/gpu/drm/i915/display/intel_encoder.h     |  1 +
 drivers/gpu/drm/i915/display/intel_sdvo.c        | 11 +++++++++--
 7 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/g4x_dp.c b/drivers/gpu/drm/i915/display/g4x_dp.c
index b867443ff2272..184c5c1d8ede0 100644
--- a/drivers/gpu/drm/i915/display/g4x_dp.c
+++ b/drivers/gpu/drm/i915/display/g4x_dp.c
@@ -1251,12 +1251,15 @@ static void g4x_dp_suspend_complete(struct intel_encoder *encoder)
 	intel_encoder_link_check_flush_work(encoder);
 }
 
+static void intel_dp_encoder_remove(struct intel_encoder *encoder)
+{
+	intel_dp_encoder_flush_work(&encoder->base);
+}
+
 static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
 {
 	struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
 
-	intel_dp_encoder_flush_work(encoder);
-
 	drm_encoder_cleanup(encoder);
 	intel_dp_link_cleanup(&dig_port->dp);
 	kfree(dig_port);
@@ -1332,6 +1335,7 @@ bool g4x_dp_init(struct intel_display *display,
 	intel_encoder->suspend = intel_dp_encoder_suspend;
 	intel_encoder->suspend_complete = g4x_dp_suspend_complete;
 	intel_encoder->shutdown = intel_dp_encoder_shutdown;
+	intel_encoder->remove = intel_dp_encoder_remove;
 	if (display->platform.cherryview) {
 		intel_encoder->pre_pll_enable = chv_dp_pre_pll_enable;
 		intel_encoder->pre_enable = chv_pre_enable_dp;
diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
index d7c7ef22b73c5..2e7a68dc247e4 100644
--- a/drivers/gpu/drm/i915/display/intel_ddi.c
+++ b/drivers/gpu/drm/i915/display/intel_ddi.c
@@ -4699,15 +4699,20 @@ static int intel_ddi_compute_config_late(struct intel_atomic_state *state,
 	return 0;
 }
 
-static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
+static void intel_ddi_encoder_remove(struct intel_encoder *encoder)
 {
-	struct intel_display *display = to_intel_display(encoder->dev);
-	struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
+	struct intel_display *display = to_intel_display(encoder);
+	struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
 
-	intel_dp_encoder_flush_work(encoder);
-	if (intel_encoder_is_tc(&dig_port->base))
+	intel_dp_encoder_flush_work(&encoder->base);
+	if (intel_encoder_is_tc(encoder))
 		intel_tc_port_cleanup(dig_port);
 	intel_display_power_flush_work(display);
+}
+
+static void intel_ddi_encoder_destroy(struct drm_encoder *encoder)
+{
+	struct intel_digital_port *dig_port = enc_to_dig_port(to_intel_encoder(encoder));
 
 	drm_encoder_cleanup(encoder);
 	kfree(dig_port->hdcp.port_data.streams);
@@ -5355,6 +5360,7 @@ void intel_ddi_init(struct intel_display *display,
 	encoder->initial_fastset_check = intel_ddi_initial_fastset_check;
 	encoder->suspend = intel_ddi_encoder_suspend;
 	encoder->shutdown = intel_ddi_encoder_shutdown;
+	encoder->remove = intel_ddi_encoder_remove;
 	encoder->get_power_domains = intel_ddi_get_power_domains;
 
 	encoder->type = INTEL_OUTPUT_DDI;
diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/gpu/drm/i915/display/intel_display_driver.c
index 204810a11e463..d513cfc881069 100644
--- a/drivers/gpu/drm/i915/display/intel_display_driver.c
+++ b/drivers/gpu/drm/i915/display/intel_display_driver.c
@@ -159,6 +159,7 @@ static void intel_mode_config_init(struct intel_display *display)
 static void intel_mode_config_cleanup(struct intel_display *display)
 {
 	intel_atomic_global_obj_cleanup(display);
+	intel_encoder_remove_all(display);
 	drm_mode_config_cleanup(display->drm);
 }
 
@@ -612,7 +613,7 @@ void intel_display_driver_remove(struct intel_display *display)
 	/*
 	 * MST topology needs to be suspended so we don't have any calls to
 	 * fbdev after it's finalized. MST will be destroyed later as part of
-	 * drm_mode_config_cleanup()
+	 * intel_encoder_remove_all().
 	 */
 	intel_dp_mst_suspend(display);
 }
diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h
index 0e3083e852d5f..6293c53c93768 100644
--- a/drivers/gpu/drm/i915/display/intel_display_types.h
+++ b/drivers/gpu/drm/i915/display/intel_display_types.h
@@ -274,6 +274,13 @@ struct intel_encoder {
 	 * all encoders have been called.
 	 */
 	void (*shutdown_complete)(struct intel_encoder *encoder);
+	/*
+	 * Called on driver remove after interrupts are disabled, to release
+	 * everything needing the hardware or exposed to userspace. The encoder
+	 * itself may be destroyed later, once the last reference to the DRM
+	 * device is gone.
+	 */
+	void (*remove)(struct intel_encoder *encoder);
 	/*
 	 * Enable/disable the clock to the port.
 	 */
diff --git a/drivers/gpu/drm/i915/display/intel_encoder.c b/drivers/gpu/drm/i915/display/intel_encoder.c
index d01b081a60740..e3c303352a9cf 100644
--- a/drivers/gpu/drm/i915/display/intel_encoder.c
+++ b/drivers/gpu/drm/i915/display/intel_encoder.c
@@ -104,6 +104,15 @@ void intel_encoder_shutdown_all(struct intel_display *display)
 			encoder->shutdown_complete(encoder);
 }
 
+void intel_encoder_remove_all(struct intel_display *display)
+{
+	struct intel_encoder *encoder;
+
+	for_each_intel_encoder(display->drm, encoder)
+		if (encoder->remove)
+			encoder->remove(encoder);
+}
+
 struct intel_digital_port *intel_dig_port_alloc(void)
 {
 	struct intel_digital_port *dig_port;
diff --git a/drivers/gpu/drm/i915/display/intel_encoder.h b/drivers/gpu/drm/i915/display/intel_encoder.h
index ace0fe1a8f27a..a368c1bd4684c 100644
--- a/drivers/gpu/drm/i915/display/intel_encoder.h
+++ b/drivers/gpu/drm/i915/display/intel_encoder.h
@@ -17,6 +17,7 @@ void intel_encoder_link_check_flush_work(struct intel_encoder *encoder);
 
 void intel_encoder_suspend_all(struct intel_display *display);
 void intel_encoder_shutdown_all(struct intel_display *display);
+void intel_encoder_remove_all(struct intel_display *display);
 
 void intel_encoder_block_all_hpds(struct intel_display *display);
 void intel_encoder_unblock_all_hpds(struct intel_display *display);
diff --git a/drivers/gpu/drm/i915/display/intel_sdvo.c b/drivers/gpu/drm/i915/display/intel_sdvo.c
index 3075ef04df566..50e9387e18092 100644
--- a/drivers/gpu/drm/i915/display/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/display/intel_sdvo.c
@@ -2548,9 +2548,8 @@ static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs
 	.atomic_check = intel_sdvo_atomic_check,
 };
 
-static void intel_sdvo_encoder_destroy(struct drm_encoder *_encoder)
+static void intel_sdvo_encoder_remove(struct intel_encoder *encoder)
 {
-	struct intel_encoder *encoder = to_intel_encoder(_encoder);
 	struct intel_sdvo *sdvo = to_sdvo(encoder);
 	int i;
 
@@ -2558,6 +2557,12 @@ static void intel_sdvo_encoder_destroy(struct drm_encoder *_encoder)
 		if (sdvo->ddc[i].ddc_bus)
 			i2c_del_adapter(&sdvo->ddc[i].ddc);
 	}
+}
+
+static void intel_sdvo_encoder_destroy(struct drm_encoder *_encoder)
+{
+	struct intel_encoder *encoder = to_intel_encoder(_encoder);
+	struct intel_sdvo *sdvo = to_sdvo(encoder);
 
 	drm_encoder_cleanup(&encoder->base);
 	kfree(sdvo);
@@ -3439,6 +3444,7 @@ bool intel_sdvo_init(struct intel_display *display,
 	intel_encoder->audio_disable = intel_sdvo_disable_audio;
 	intel_encoder->get_hw_state = intel_sdvo_get_hw_state;
 	intel_encoder->get_config = intel_sdvo_get_config;
+	intel_encoder->remove = intel_sdvo_encoder_remove;
 
 	/* In default case sdvo lvds is false */
 	if (!intel_sdvo_get_capabilities(intel_sdvo, &intel_sdvo->caps))
@@ -3518,6 +3524,7 @@ bool intel_sdvo_init(struct intel_display *display,
 	intel_sdvo_output_cleanup(intel_sdvo);
 err:
 	intel_sdvo_unselect_i2c_bus(intel_sdvo);
+	intel_sdvo_encoder_remove(intel_encoder);
 	intel_sdvo_encoder_destroy(&intel_encoder->base);
 
 	return false;
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects
  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:15 ` Baoli Zhang
  2026-11-16  8:39   ` Jani Nikula
  2026-11-16  1:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang
  2 siblings, 1 reply; 5+ messages in thread
From: Baoli Zhang @ 2026-11-16  1:15 UTC (permalink / raw)
  To: intel-xe, intel-gfx
  Cc: dri-devel, linux-kernel, jani.nikula, rodrigo.vivi,
	joonas.lahtinen, tursulin, matthew.brost, thomas.hellstrom,
	matthew.auld, airlied, simona, andriy.shevchenko, Baoli Zhang,
	Yanx L Liu

intel_display_driver_remove_noirq() frees all the KMS objects through
drm_mode_config_cleanup(), while userspace may still hold the DRM fd
open with references to them, e.g. framebuffers it created. Such
objects must only be freed with the last reference to the DRM device.

As a first step, move drm_mode_config_cleanup() into the new
intel_display_driver_mode_config_cleanup() and call it from i915 and xe
right after intel_display_driver_remove_noirq(), so each driver can
then move it to the right place.

drm_mode_config_cleanup() now runs after the rest of the noirq teardown
(DP tunnel manager, overlay, GMBUS, workqueues and FBC). After the
previous patch the KMS object destroy callbacks no longer depend on any
of that.

No functional change intended.

Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>
---
 drivers/gpu/drm/i915/display/intel_display_driver.c | 12 ++++++++++++
 drivers/gpu/drm/i915/display/intel_display_driver.h |  1 +
 drivers/gpu/drm/i915/i915_driver.c                  |  2 ++
 drivers/gpu/drm/xe/display/xe_display.c             |  2 ++
 4 files changed, 17 insertions(+)

diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/gpu/drm/i915/display/intel_display_driver.c
index d513cfc881069..62a4d95d78b53 100644
--- a/drivers/gpu/drm/i915/display/intel_display_driver.c
+++ b/drivers/gpu/drm/i915/display/intel_display_driver.c
@@ -160,6 +160,18 @@ static void intel_mode_config_cleanup(struct intel_display *display)
 {
 	intel_atomic_global_obj_cleanup(display);
 	intel_encoder_remove_all(display);
+}
+
+/*
+ * Free the KMS objects, including the encoders torn down by
+ * intel_display_driver_remove_noirq(). Userspace can keep referring to them
+ * until the last reference to the DRM device is gone.
+ */
+void intel_display_driver_mode_config_cleanup(struct intel_display *display)
+{
+	if (!HAS_DISPLAY(display))
+		return;
+
 	drm_mode_config_cleanup(display->drm);
 }
 
diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.h b/drivers/gpu/drm/i915/display/intel_display_driver.h
index 1ae2ad7e95f6c..88d9028e86e4b 100644
--- a/drivers/gpu/drm/i915/display/intel_display_driver.h
+++ b/drivers/gpu/drm/i915/display/intel_display_driver.h
@@ -23,6 +23,7 @@ void intel_display_driver_register(struct intel_display *display);
 void intel_display_driver_remove(struct intel_display *display);
 void intel_display_driver_remove_noirq(struct intel_display *display);
 void intel_display_driver_remove_nogem(struct intel_display *display);
+void intel_display_driver_mode_config_cleanup(struct intel_display *display);
 void intel_display_driver_unregister(struct intel_display *display);
 void intel_display_driver_shutdown(struct intel_display *display);
 void intel_display_driver_shutdown_late(struct intel_display *display);
diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
index aeb7b24c81c8b..d29b37ab2833e 100644
--- a/drivers/gpu/drm/i915/i915_driver.c
+++ b/drivers/gpu/drm/i915/i915_driver.c
@@ -906,6 +906,7 @@ int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	intel_display_driver_remove(display);
 	intel_irq_uninstall(i915);
 	intel_display_driver_remove_noirq(display);
+	intel_display_driver_mode_config_cleanup(display);
 	goto out_cleanup_modeset;
 out_cleanup_irq:
 	intel_irq_uninstall(i915);
@@ -951,6 +952,7 @@ void i915_driver_remove(struct drm_i915_private *i915)
 	intel_irq_uninstall(i915);
 
 	intel_display_driver_remove_noirq(display);
+	intel_display_driver_mode_config_cleanup(display);
 
 	i915_reset_error_state(i915);
 	i915_gem_driver_remove(i915);
diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
index 506f26e9c59a8..d33052a98d942 100644
--- a/drivers/gpu/drm/xe/display/xe_display.c
+++ b/drivers/gpu/drm/xe/display/xe_display.c
@@ -73,6 +73,7 @@ static void xe_display_fini_early(void *arg)
 		return;
 
 	intel_display_driver_remove_noirq(display);
+	intel_display_driver_mode_config_cleanup(display);
 	intel_display_driver_remove_nogem(display);
 	intel_display_power_cleanup(display);
 }
@@ -110,6 +111,7 @@ 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release
  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:15 ` [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects Baoli Zhang
@ 2026-11-16  1:15 ` Baoli Zhang
  2 siblings, 0 replies; 5+ messages in thread
From: Baoli Zhang @ 2026-11-16  1:15 UTC (permalink / raw)
  To: intel-xe, intel-gfx
  Cc: dri-devel, linux-kernel, jani.nikula, rodrigo.vivi,
	joonas.lahtinen, tursulin, matthew.brost, thomas.hellstrom,
	matthew.auld, airlied, simona, andriy.shevchenko, Baoli Zhang,
	Yanx L Liu

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects
  2026-11-16  1:15 ` [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects Baoli Zhang
@ 2026-11-16  8:39   ` Jani Nikula
  0 siblings, 0 replies; 5+ messages in thread
From: Jani Nikula @ 2026-11-16  8:39 UTC (permalink / raw)
  To: Baoli Zhang, intel-xe, intel-gfx
  Cc: dri-devel, linux-kernel, rodrigo.vivi, joonas.lahtinen, tursulin,
	matthew.brost, thomas.hellstrom, matthew.auld, airlied, simona,
	andriy.shevchenko, Baoli Zhang, Yanx L Liu

On Mon, 16 Nov 2026, Baoli Zhang <baoli.zhang@linux.intel.com> wrote:
> intel_display_driver_remove_noirq() frees all the KMS objects through
> drm_mode_config_cleanup(), while userspace may still hold the DRM fd
> open with references to them, e.g. framebuffers it created. Such
> objects must only be freed with the last reference to the DRM device.
>
> As a first step, move drm_mode_config_cleanup() into the new
> intel_display_driver_mode_config_cleanup() and call it from i915 and xe
> right after intel_display_driver_remove_noirq(), so each driver can
> then move it to the right place.
>
> drm_mode_config_cleanup() now runs after the rest of the noirq teardown
> (DP tunnel manager, overlay, GMBUS, workqueues and FBC). After the
> previous patch the KMS object destroy callbacks no longer depend on any
> of that.
>
> No functional change intended.
>
> Tested-by: Yanx L Liu <yanx.l.liu@intel.com>
> Signed-off-by: Baoli Zhang <baoli.zhang@linux.intel.com>

Please don't add new display calls to i915 or xe core drivers. The
direction must be the opposite, there needs to be fewer calls. Move the
functionality in existing higher level display functions.

I see that patch 3/3 then changes i915 and xe to behave differently
here. That's also the wrong direction. We need to make the drivers
behave more similarly. Can't have one driver make some calls, and the
other not.

The approach here makes future changes harder.

BR,
Jani.

> ---
>  drivers/gpu/drm/i915/display/intel_display_driver.c | 12 ++++++++++++
>  drivers/gpu/drm/i915/display/intel_display_driver.h |  1 +
>  drivers/gpu/drm/i915/i915_driver.c                  |  2 ++
>  drivers/gpu/drm/xe/display/xe_display.c             |  2 ++
>  4 files changed, 17 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/gpu/drm/i915/display/intel_display_driver.c
> index d513cfc881069..62a4d95d78b53 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_driver.c
> +++ b/drivers/gpu/drm/i915/display/intel_display_driver.c
> @@ -160,6 +160,18 @@ static void intel_mode_config_cleanup(struct intel_display *display)
>  {
>  	intel_atomic_global_obj_cleanup(display);
>  	intel_encoder_remove_all(display);
> +}
> +
> +/*
> + * Free the KMS objects, including the encoders torn down by
> + * intel_display_driver_remove_noirq(). Userspace can keep referring to them
> + * until the last reference to the DRM device is gone.
> + */
> +void intel_display_driver_mode_config_cleanup(struct intel_display *display)
> +{
> +	if (!HAS_DISPLAY(display))
> +		return;
> +
>  	drm_mode_config_cleanup(display->drm);
>  }
>  
> diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.h b/drivers/gpu/drm/i915/display/intel_display_driver.h
> index 1ae2ad7e95f6c..88d9028e86e4b 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_driver.h
> +++ b/drivers/gpu/drm/i915/display/intel_display_driver.h
> @@ -23,6 +23,7 @@ void intel_display_driver_register(struct intel_display *display);
>  void intel_display_driver_remove(struct intel_display *display);
>  void intel_display_driver_remove_noirq(struct intel_display *display);
>  void intel_display_driver_remove_nogem(struct intel_display *display);
> +void intel_display_driver_mode_config_cleanup(struct intel_display *display);
>  void intel_display_driver_unregister(struct intel_display *display);
>  void intel_display_driver_shutdown(struct intel_display *display);
>  void intel_display_driver_shutdown_late(struct intel_display *display);
> diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c
> index aeb7b24c81c8b..d29b37ab2833e 100644
> --- a/drivers/gpu/drm/i915/i915_driver.c
> +++ b/drivers/gpu/drm/i915/i915_driver.c
> @@ -906,6 +906,7 @@ int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	intel_display_driver_remove(display);
>  	intel_irq_uninstall(i915);
>  	intel_display_driver_remove_noirq(display);
> +	intel_display_driver_mode_config_cleanup(display);
>  	goto out_cleanup_modeset;
>  out_cleanup_irq:
>  	intel_irq_uninstall(i915);
> @@ -951,6 +952,7 @@ void i915_driver_remove(struct drm_i915_private *i915)
>  	intel_irq_uninstall(i915);
>  
>  	intel_display_driver_remove_noirq(display);
> +	intel_display_driver_mode_config_cleanup(display);
>  
>  	i915_reset_error_state(i915);
>  	i915_gem_driver_remove(i915);
> diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
> index 506f26e9c59a8..d33052a98d942 100644
> --- a/drivers/gpu/drm/xe/display/xe_display.c
> +++ b/drivers/gpu/drm/xe/display/xe_display.c
> @@ -73,6 +73,7 @@ static void xe_display_fini_early(void *arg)
>  		return;
>  
>  	intel_display_driver_remove_noirq(display);
> +	intel_display_driver_mode_config_cleanup(display);
>  	intel_display_driver_remove_nogem(display);
>  	intel_display_power_cleanup(display);
>  }
> @@ -110,6 +111,7 @@ 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;

-- 
Jani Nikula, Intel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-16  8:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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:15 ` [PATCH 2/3] drm/i915/display: Let the drivers free the KMS objects Baoli Zhang
2026-11-16  8:39   ` Jani Nikula
2026-11-16  1:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®