* [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; 8+ 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] 8+ 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: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:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang
2 siblings, 1 reply; 8+ 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 related [flat|nested] 8+ 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 1:53 ` sashiko-bot
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, 2 replies; 8+ 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 related [flat|nested] 8+ 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
2026-11-16 1:54 ` sashiko-bot
2 siblings, 1 reply; 8+ 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 related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] drm/i915/display: Tear down encoder hardware state in a separate hook
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
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-16 1:38 UTC (permalink / raw)
To: Baoli Zhang, intel-xe, intel-gfx; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] drm/i915/ddi: uninitialized dedicated_external check in
intel_ddi_init() [1]
--
commit 29c999b99f6cbc9e2b633d5c497aefc1594c72cf
Author: Baoli Zhang <baoli.zhang@linux.intel.com>
drm/i915/display: Tear down encoder hardware state in a separate hook
This commit introduces an intel_encoder ->remove() callback to separate
hardware and userspace-visible encoder teardown on driver remove from
memory deallocation in ->destroy().
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi.c b/drivers/gpu/drm/i915/display/intel_ddi.c
> index a0aff087fafa8..01fbb5ab038fd 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi.c
[ ... ]
> @@ -5353,6 +5358,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;
[Severity: High]
This problem wasn't introduced by this patch, but doesn't intel_ddi_init()
call intel_encoder_is_tc() before dig_port->dedicated_external is
initialized [1]?
intel_encoder_is_tc() returns false when dig_port->dedicated_external is
set, yet intel_ddi_init() only populates dedicated_external from VBT after
querying intel_encoder_is_tc() to select encoder->get_config and check
need_aux_ch():
drivers/gpu/drm/i915/display/intel_ddi.c:intel_ddi_init() {
...
if (HAS_LT_PHY(display)) {
...
if (intel_encoder_is_tc(encoder))
encoder->get_config = mtl_ddi_tc_phy_get_config;
else
encoder->get_config = mtl_ddi_non_tc_phy_get_config;
} else if (DISPLAY_VER(display) >= 14) {
...
if (intel_encoder_is_tc(encoder))
encoder->get_config = mtl_ddi_tc_phy_get_config;
else
encoder->get_config = mtl_ddi_non_tc_phy_get_config;
}
...
if (intel_bios_encoder_is_dedicated_external(devdata))
dig_port->dedicated_external = true;
...
}
On DISPLAY_VER() >= 14 or HAS_LT_PHY() platforms where the VBT marks a
Type-C PHY port as a dedicated external port, encoder->get_config is
assigned mtl_ddi_tc_phy_get_config() instead of
mtl_ddi_non_tc_phy_get_config(). Once dedicated_external is set to true,
subsequent intel_encoder_is_tc() calls return false, so atomic DPLL
computation uses the non-TC path (ICL_PORT_DPLL_DEFAULT) while hardware
state readout via mtl_ddi_tc_phy_get_config() populates
ICL_PORT_DPLL_MG_PHY, causing DPLL state verification mismatches and
failing fastset checks.
[1] https://sashiko.dev/#/bug/linux-4f65a789-b335-4420-aca7-1aaf9a2f9779
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116011504.3910139-1-baoli.zhang@linux.intel.com?part=1
^ permalink raw reply [flat|nested] 8+ 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 1:53 ` sashiko-bot
2026-11-16 8:39 ` Jani Nikula
1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-16 1:53 UTC (permalink / raw)
To: Baoli Zhang, intel-xe, intel-gfx; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/i915/display: double intel_encoder_remove_all() on Xe
probe error
- [Medium] drm/i915/display: UAF of struct intel_display in
intel_crtc_destroy()
--
commit 4777f76b60cbdafe718dcc54b80e3edb4d081b1c
Author: Baoli Zhang <baoli.zhang@linux.intel.com>
drm/i915/display: Let the drivers free the KMS objects
This commit moves drm_mode_config_cleanup() out of
intel_mode_config_cleanup() into a new
intel_display_driver_mode_config_cleanup() helper and calls it from the
i915 and xe driver teardown paths after
intel_display_driver_remove_noirq().
> 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);
> }
[Severity: Medium]
Can this cause intel_encoder_remove_all() to run twice on the same
encoders if intel_display_driver_probe_nogem() fails during
xe_display_init_early()?
When intel_display_driver_probe_nogem() fails after intel_setup_outputs()
(for example, if intel_dp_tunnel_mgr_init() fails), its err_mode_config
path calls intel_mode_config_cleanup(), which now runs
intel_encoder_remove_all() without destroying the encoders via
drm_mode_config_cleanup(). xe_display_init_early() then jumps to
err_noirq and calls intel_display_driver_remove_noirq() ->
intel_mode_config_cleanup() a second time while those encoders are still
on mode_config.encoder_list.
Running encoder->remove() twice dereferences a NULL dig_port->tc pointer
in intel_tc_port_cleanup() (which frees and clears dig_port->tc on the
first call) and double frees intel_dp->aux.name in intel_dp_aux_fini().
> 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);
[Severity: Medium]
Does the out_cleanup_irq error path in i915_driver_probe() leave CRTCs
referencing a freed struct intel_display when
intel_display_driver_probe_nogem() fails?
If intel_display_driver_probe_nogem() fails after intel_crtc_init() has
linked a CRTC onto display->pipe_list, its err_mode_config path calls
intel_mode_config_cleanup(), which no longer calls
drm_mode_config_cleanup(). i915_driver_probe() then jumps to
out_cleanup_irq, bypassing intel_display_driver_mode_config_cleanup(),
and frees display in i915_driver_late_release() ->
intel_display_device_remove(). When drmm later runs
drm_mode_config_cleanup() -> intel_crtc_destroy(),
list_del(&crtc->pipe_head) writes to display->pipe_list inside the
already-freed struct intel_display.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116011504.3910139-1-baoli.zhang@linux.intel.com?part=2
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release
2026-11-16 1:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang
@ 2026-11-16 1:54 ` sashiko-bot
0 siblings, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-11-16 1:54 UTC (permalink / raw)
To: Baoli Zhang, intel-xe, intel-gfx; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/xe/display: double encoder->remove() on
xe_display_init_early() error
--
commit b715fa7a2b526531416f015bc7f326dd1dd557ca
Author: Baoli Zhang <baoli.zhang@linux.intel.com>
drm/xe/display: Free the KMS objects on DRM device release
This commit removes the calls to intel_display_driver_mode_config_cleanup()
from xe_display_fini_early() and the xe_display_init_early() error path so
that KMS objects are freed by drmm on DRM device release.
> diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
> index 8f02317a62120..639c2f5aeb66f 100644
> --- a/drivers/gpu/drm/xe/display/xe_display.c
> +++ b/drivers/gpu/drm/xe/display/xe_display.c
[ ... ]
> @@ -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;
[Severity: Medium]
Can the err_noirq path in xe_display_init_early() invoke encoder->remove()
twice on each encoder when intel_display_driver_probe_nogem() fails?
In intel_display_driver_probe_nogem(), if intel_dp_tunnel_mgr_init() fails
after intel_setup_outputs(), the err_mode_config path calls
intel_mode_config_cleanup() -> intel_encoder_remove_all(). Because
drm_mode_config_cleanup() is now deferred to drmm, the encoders remain
linked on display->drm->mode_config.encoder_list when
intel_display_driver_probe_nogem() returns an error.
The err_noirq path here then calls intel_display_driver_remove_noirq() ->
intel_mode_config_cleanup() -> intel_encoder_remove_all() a second time on
the still-populated encoder_list. On the first pass,
intel_ddi_encoder_remove() frees dig_port->tc and sets it to NULL in
intel_tc_port_cleanup() and frees intel_dp->aux.name in
intel_dp_aux_fini(), so the second pass causes a NULL pointer dereference
in intel_tc_port_suspend() and a double free of intel_dp->aux.name.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116011504.3910139-1-baoli.zhang@linux.intel.com?part=3
^ permalink raw reply [flat|nested] 8+ 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 1:53 ` sashiko-bot
@ 2026-11-16 8:39 ` Jani Nikula
1 sibling, 0 replies; 8+ 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] 8+ messages in thread
end of thread, other threads:[~2026-11-16 8:39 UTC | newest]
Thread overview: 8+ 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: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-16 1:15 ` [PATCH 3/3] drm/xe/display: Free the KMS objects on DRM device release Baoli Zhang
2026-11-16 1:54 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox