* [PATCH v2 0/2] drm/vkms: Fix races on ConfigFS device removal @ 2026-12-05 0:16 Sebastian Wick 2026-12-05 0:17 ` [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths Sebastian Wick 2026-12-05 0:17 ` [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal Sebastian Wick 0 siblings, 2 replies; 5+ messages in thread From: Sebastian Wick @ 2026-12-05 0:16 UTC (permalink / raw) To: dri-devel Cc: louis.chauvet, hamohammed.sa, simona, melissa.srw, maarten.lankhorst, mripard, tzimmermann, airlied, Sebastian Wick VKMS devices created via ConfigFS can be removed while userspace still holds the device open. drm_dev_unregister() does not stop ioctls, so device removal can race with in-flight ioctls and deadlock against drm_atomic_helper_shutdown(). This series switches ConfigFS device removal to drm_dev_unplug(), which rejects ioctls with -ENODEV after removal, and adds the drm_dev_enter()/drm_dev_exit() guards in the vkms callbacks that drm_dev_unplug() relies on to wait for in-flight operations. Based on v7.4-rc5. v1: https://lists.freedesktop.org/archives/dri-devel/2026-October/609735.html Changes in v2: - Check drm_dev_enter() after vkms_crc_parse_source() in vkms_set_crc_source() so that the composer is also stopped when the CRC source is disabled on a device that is already gone, instead of failing the ioctl and leaving the composer running Sebastian Wick (2): drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths drm/vkms: Use drm_dev_unplug() for ConfigFS device removal drivers/gpu/drm/vkms/vkms_composer.c | 11 ++++++++++- drivers/gpu/drm/vkms/vkms_connector.c | 14 +++++++++++++- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_writeback.c | 13 +++++++++++-- 4 files changed, 35 insertions(+), 5 deletions(-) -- 2.55.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths 2026-12-05 0:16 [PATCH v2 0/2] drm/vkms: Fix races on ConfigFS device removal Sebastian Wick @ 2026-12-05 0:17 ` Sebastian Wick 2026-12-05 0:42 ` sashiko-bot 2026-12-05 0:17 ` [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal Sebastian Wick 1 sibling, 1 reply; 5+ messages in thread From: Sebastian Wick @ 2026-12-05 0:17 UTC (permalink / raw) To: dri-devel Cc: louis.chauvet, hamohammed.sa, simona, melissa.srw, maarten.lankhorst, mripard, tzimmermann, airlied, Sebastian Wick In preparation for switching to drm_dev_unplug() for ConfigFS device removal, add drm_dev_enter()/drm_dev_exit() guards to vkms callbacks that can be reached while the device is being torn down. drm_dev_unplug() relies on these SRCU guards to wait for in-flight operations before proceeding with teardown. Without them, synchronize_srcu() completes immediately and the teardown path can race with in-flight operations. Guard the following callbacks: - vkms_connector_detect() and vkms_conn_get_modes(): called from the MODE_GETCONNECTOR ioctl via fill_modes, which holds mode_config.mutex. Without the guard, an in-flight getconnector can hold locks that drm_atomic_helper_shutdown() needs. - vkms_wb_connector_get_modes(): same fill_modes path for the writeback connector. - vkms_set_crc_source(): called from the CRC debugfs release path. The debugfs proxy explicitly does not protect the release callback against removal races, so this needs its own guard. Atomic commit callbacks are intentionally not guarded: they are serialized against drm_atomic_helper_shutdown() via modeset ww_mutex locks, and must remain functional after unplug so shutdown can disable CRTCs. Changes in v2: - Check drm_dev_enter() after vkms_crc_parse_source() in vkms_set_crc_source() so that the composer is also stopped when the CRC source is disabled on a device that is already gone, instead of failing the ioctl and leaving the composer running Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com> --- drivers/gpu/drm/vkms/vkms_composer.c | 11 ++++++++++- drivers/gpu/drm/vkms/vkms_connector.c | 14 +++++++++++++- drivers/gpu/drm/vkms/vkms_writeback.c | 13 +++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 0fc915a954ba..23df0cb9eeb1 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -5,6 +5,7 @@ #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_blend.h> +#include <drm/drm_drv.h> #include <drm/drm_colorop.h> #include <drm/drm_fourcc.h> #include <drm/drm_fixed.h> @@ -731,11 +732,19 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) { struct vkms_output *out = drm_crtc_to_vkms_output(crtc); bool enabled = false; - int ret = 0; + int ret, idx; ret = vkms_crc_parse_source(src_name, &enabled); + if (!drm_dev_enter(crtc->dev, &idx)) { + if (!enabled) + vkms_set_composer(out, false); + return -ENODEV; + } + vkms_set_composer(out, enabled); + drm_dev_exit(idx); + return ret; } diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c index b0a6b212d3f4..81cd845cf84f 100644 --- a/drivers/gpu/drm/vkms/vkms_connector.c +++ b/drivers/gpu/drm/vkms/vkms_connector.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include <drm/drm_atomic_helper.h> +#include <drm/drm_drv.h> #include <drm/drm_edid.h> #include <drm/drm_managed.h> #include <drm/drm_probe_helper.h> @@ -16,6 +17,10 @@ static enum drm_connector_status vkms_connector_detect(struct drm_connector *con struct vkms_connector *vkms_connector; enum drm_connector_status status; struct vkms_config_connector *connector_cfg; + int idx; + + if (!drm_dev_enter(dev, &idx)) + return connector_status_disconnected; vkms_connector = drm_connector_to_vkms_connector(connector); @@ -31,6 +36,8 @@ static enum drm_connector_status vkms_connector_detect(struct drm_connector *con status = vkms_config_connector_get_status(connector_cfg); } + drm_dev_exit(idx); + return status; } @@ -44,12 +51,17 @@ static const struct drm_connector_funcs vkms_connector_funcs = { static int vkms_conn_get_modes(struct drm_connector *connector) { - int count; + int count, idx; + + if (!drm_dev_enter(connector->dev, &idx)) + return 0; /* Use the default modes list from DRM */ count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); + drm_dev_exit(idx); + return count; } diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index ecf29a2c0c8e..e779ace7b383 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -3,6 +3,7 @@ #include <linux/iosys-map.h> #include <drm/drm_atomic.h> +#include <drm/drm_drv.h> #include <drm/drm_edid.h> #include <drm/drm_fourcc.h> #include <drm/drm_writeback.h> @@ -67,9 +68,17 @@ static int vkms_wb_atomic_check(struct drm_connector *connector, static int vkms_wb_connector_get_modes(struct drm_connector *connector) { struct drm_device *dev = connector->dev; + int count, idx; - return drm_add_modes_noedid(connector, dev->mode_config.max_width, - dev->mode_config.max_height); + if (!drm_dev_enter(dev, &idx)) + return 0; + + count = drm_add_modes_noedid(connector, dev->mode_config.max_width, + dev->mode_config.max_height); + + drm_dev_exit(idx); + + return count; } static int vkms_wb_prepare_job(struct drm_writeback_connector *wb_connector, -- 2.55.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths 2026-12-05 0:17 ` [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths Sebastian Wick @ 2026-12-05 0:42 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-05 0:42 UTC (permalink / raw) To: Sebastian Wick, dri-devel Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/vkms: vkms_set_crc_source() bypasses drm_dev_enter() guard on disable - [Medium] drm/vkms: unguarded atomic_enable allows post-shutdown vblank timer UAF - [Low] drm/vkms: bypassed writeback get_modes guard and wrong lock rationale -- commit 61d2fd052426fe82a4c8e4ed09b2de7270308629 Author: Sebastian Wick <sebastian.wick@redhat.com> drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths This commit adds drm_dev_enter()/drm_dev_exit() guards to connector detect/get_modes callbacks and vkms_set_crc_source() in preparation for using drm_dev_unplug() on ConfigFS device removal. > Atomic commit callbacks are intentionally not guarded: they are > serialized against drm_atomic_helper_shutdown() via modeset ww_mutex > locks, and must remain functional after unplug so shutdown can disable > CRTCs. [Severity: Medium] Can an in-flight atomic commit still re-enable a CRTC and its vblank hrtimer after drm_atomic_helper_shutdown() finishes? drm_ioctl() checks drm_dev_is_unplugged() without taking drm_dev_enter(), so drm_dev_unplug() does not wait for atomic ioctls that have not yet acquired modeset locks. Modeset ww_mutex locks only serialize commits against each other; they do not stop an in-flight ioctl from running after shutdown drops the locks. update_connector_routing() rejects an unregistered connector only when crtc_state->active is true and the connector is in the request. One in-flight commit can attach it with ACTIVE=0, and a second can set ACTIVE=1 without listing the connector, calling drm_crtc_vblank_on(). CPU0 (ConfigFS remove) CPU1 (in-flight atomic ioctls) drm_dev_unplug() drm_ioctl() (passed unplugged check) drm_dev_unregister() synchronize_srcu() drm_atomic_helper_shutdown() drm_crtc_vblank_off() commit 1: attach connector, ACTIVE=0 commit 2: set CRTC ACTIVE=1 drm_crtc_vblank_atomic_enable() drm_crtc_vblank_on() close last fd -> drm_managed_release() destroy workq, zero crtc, free output <hrtimer> drm_vblank_timer_function() <-- NULL deref / use-after-free drm_vblank_init_release() hrtimer_cancel() Because vkms_create() calls drm_vblank_init() before vkms_modeset_init(), LIFO drm_managed_release() destroys composer_workq and frees crtc and vkms_output before drm_vblank_init_release() cancels the hrtimer. If the timer fires during teardown, it causes a NULL dereference or use-after-free. Unlike atomic_disable, atomic_enable is never needed by drm_atomic_helper_shutdown(), so guarding atomic_enable with drm_dev_enter()/drm_dev_exit() would prevent re-enabling the CRTC after unplug. [ ... ] > diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c > index 0fc915a954bad..23df0cb9eeb13 100644 > --- a/drivers/gpu/drm/vkms/vkms_composer.c > +++ b/drivers/gpu/drm/vkms/vkms_composer.c [ ... ] > @@ -731,11 +732,19 @@ int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) > { > struct vkms_output *out = drm_crtc_to_vkms_output(crtc); > bool enabled = false; > - int ret = 0; > + int ret, idx; > > ret = vkms_crc_parse_source(src_name, &enabled); > > + if (!drm_dev_enter(crtc->dev, &idx)) { > + if (!enabled) > + vkms_set_composer(out, false); > + return -ENODEV; > + } > + > vkms_set_composer(out, enabled); > > + drm_dev_exit(idx); > + > return ret; > } [Severity: Medium] Does calling vkms_set_composer(out, false) here bypass the drm_dev_enter() guard on the post-unplug debugfs release path? crtc_crc_release() always calls set_crc_source(crtc, NULL), which sets enabled to false. When drm_dev_enter() returns false it has already unlocked drm_unplug_srcu, so synchronize_srcu() in drm_dev_unplug() does not wait for vkms_set_composer(out, false). CPU0 (ConfigFS remove) CPU1 (close crc/data fd) drm_dev_unplug() dev->unplugged = true synchronize_srcu() crtc_crc_release() vkms_set_crc_source(crtc, NULL) drm_dev_enter() -> false (no SRCU) devres_release_group() drm_vblank_init_release() free dev->vblank, vkms_output vkms_set_composer(out, false) spin_lock_irq(&out->lock) drm_crtc_vblank_put() <-- use-after-free Because crtc_crc_open() does not hold a drm_dev_get() reference, closing crc/data without an open DRM chardev fd can race with teardown freeing vkms_output and dev->vblank, or arm vblank->disable_timer after unplug. Skipping vkms_set_composer(out, false) when !drm_dev_enter() will not leave the composer running, because vkms_destroy() runs drm_atomic_helper_shutdown() which calls drm_crtc_vblank_off() and flushes composer_work. Returning -ENODEV directly here avoids the unguarded call. [ ... ] > diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c > index ecf29a2c0c8e0..e779ace7b3837 100644 > --- a/drivers/gpu/drm/vkms/vkms_writeback.c > +++ b/drivers/gpu/drm/vkms/vkms_writeback.c [ ... ] > @@ -67,9 +68,17 @@ static int vkms_wb_atomic_check(struct drm_connector *connector, > static int vkms_wb_connector_get_modes(struct drm_connector *connector) > { > struct drm_device *dev = connector->dev; > + int count, idx; > > - return drm_add_modes_noedid(connector, dev->mode_config.max_width, > - dev->mode_config.max_height); > + if (!drm_dev_enter(dev, &idx)) > + return 0; > + > + count = drm_add_modes_noedid(connector, dev->mode_config.max_width, > + dev->mode_config.max_height); > + > + drm_dev_exit(idx); > + > + return count; > } [Severity: Low] Does returning 0 here actually prevent modes from being added on an unplugged writeback connector? vkms_wb_connector_funcs has no .detect callback, so the writeback connector still reports connector_status_connected after unplug. When get_modes() returns 0, drm_helper_probe_single_connector_modes() hits its fallback and calls drm_add_modes_noedid(connector, 1024, 768) anyway. Separately, the commit message says detect/get_modes need drm_dev_enter() because MODE_GETCONNECTOR holds mode_config.mutex needed by drm_atomic_helper_shutdown(). drm_atomic_helper_shutdown() does not acquire mode_config.mutex, and drm_mode_getconnector() holds it across fill_modes() regardless; vkms_connector_detect() needs the guard to protect vkmsdev->config. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261205001701.1125045-1-sebastian.wick@redhat.com?part=1 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal 2026-12-05 0:16 [PATCH v2 0/2] drm/vkms: Fix races on ConfigFS device removal Sebastian Wick 2026-12-05 0:17 ` [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths Sebastian Wick @ 2026-12-05 0:17 ` Sebastian Wick 2026-12-05 0:34 ` sashiko-bot 1 sibling, 1 reply; 5+ messages in thread From: Sebastian Wick @ 2026-12-05 0:17 UTC (permalink / raw) To: dri-devel Cc: louis.chauvet, hamohammed.sa, simona, melissa.srw, maarten.lankhorst, mripard, tzimmermann, airlied, Sebastian Wick, Oarora Etimis VKMS ConfigFS devices can be disabled while userspace still holds open file descriptors. Using drm_dev_unregister() leaves the device in a state where ioctls are still accepted but internal locks can contend with the teardown path. Specifically, drmModeGetConnector() triggers fill_modes which acquires mode_config locks that contend with drm_atomic_helper_shutdown(). Use drm_dev_unplug() instead, which marks the device as unplugged so the ioctl layer rejects subsequent calls with -ENODEV. The previous commit added drm_dev_enter()/drm_dev_exit() guards to vkms callbacks, so synchronize_srcu() in drm_dev_unplug() properly waits for any in-flight operations before the teardown proceeds. Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com> Acked-by: Maxime Ripard <mripard@kernel.org> Reviewed-by: Oarora Etimis <oaroraetimis@gmail.com> --- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 5a640b531d88..716f9c966c21 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -259,7 +259,7 @@ void vkms_destroy(struct vkms_config *config) fdev = config->dev->faux_dev; - drm_dev_unregister(&config->dev->drm); + drm_dev_unplug(&config->dev->drm); drm_atomic_helper_shutdown(&config->dev->drm); devres_release_group(&fdev->dev, NULL); faux_device_destroy(fdev); -- 2.55.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal 2026-12-05 0:17 ` [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal Sebastian Wick @ 2026-12-05 0:34 ` sashiko-bot 0 siblings, 0 replies; 5+ messages in thread From: sashiko-bot @ 2026-12-05 0:34 UTC (permalink / raw) To: Sebastian Wick, dri-devel Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/vkms: vkms_set_crc_source() calls vkms_set_composer() after unplug - [Low] drm/vkms: missing Fixes trailer for ConfigFS device removal -- commit 57a470b7f9cf80c97a20880e3587763a2408a3b5 Author: Sebastian Wick <sebastian.wick@redhat.com> > drm/vkms: Use drm_dev_unplug() for ConfigFS device removal > > VKMS ConfigFS devices can be disabled while userspace still holds open > file descriptors. Using drm_dev_unregister() leaves the device in a > state where ioctls are still accepted but internal locks can contend > with the teardown path. Specifically, drmModeGetConnector() triggers > fill_modes which acquires mode_config locks that contend with > drm_atomic_helper_shutdown(). > > Use drm_dev_unplug() instead, which marks the device as unplugged so > the ioctl layer rejects subsequent calls with -ENODEV. The previous > commit added drm_dev_enter()/drm_dev_exit() guards to vkms callbacks, > so synchronize_srcu() in drm_dev_unplug() properly waits for any > in-flight operations before the teardown proceeds. > > Signed-off-by: Sebastian Wick <sebastian.wick@redhat.com> > Acked-by: Maxime Ripard <mripard@kernel.org> > Reviewed-by: Oarora Etimis <oaroraetimis@gmail.com> [Severity: Low] This fixes a ConfigFS teardown issue introduced when dynamic instance removal was added. Should this include: Fixes: 13fc9b9745cc ("drm/vkms: Add and remove VKMS instances via configfs") > diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c > index 5a640b531d88f..716f9c966c211 100644 > --- a/drivers/gpu/drm/vkms/vkms_drv.c > +++ b/drivers/gpu/drm/vkms/vkms_drv.c > @@ -259,7 +259,7 @@ void vkms_destroy(struct vkms_config *config) > > fdev = config->dev->faux_dev; > > - drm_dev_unregister(&config->dev->drm); > + drm_dev_unplug(&config->dev->drm); > drm_atomic_helper_shutdown(&config->dev->drm); > devres_release_group(&fdev->dev, NULL); > faux_device_destroy(fdev); [Severity: Medium] Can switching to drm_dev_unplug() cause a use-after-free of vkms_output and dev->vblank when a debugfs CRC file is closed during teardown? Once drm_dev_unplug() sets dev->unplugged, vkms_set_crc_source() takes the !drm_dev_enter() path and still calls vkms_set_composer(out, false) after drm_dev_enter() has released drm_unplug_srcu: drivers/gpu/drm/vkms/vkms_composer.c:vkms_set_crc_source() { ... if (!drm_dev_enter(crtc->dev, &idx)) { if (!enabled) vkms_set_composer(out, false); return -ENODEV; } ... } Closing the debugfs crc/data file invokes crtc_crc_release() through full_proxy_release(), which does not acquire debugfs_file_get() or hold a drm_device reference. Neither debugfs removal nor synchronize_srcu() waits for vkms_set_composer(out, false): CPU0 (ConfigFS teardown) CPU1 (debugfs crc/data close) vkms_destroy() full_proxy_release() drm_dev_unplug() crtc_crc_release() dev->unplugged = true vkms_set_crc_source(crtc, NULL) synchronize_srcu() drm_dev_enter() -> false drm_atomic_helper_shutdown() devres_release_group() drm_dev_put() drm_managed_release() free vkms_output/vblank vkms_set_composer(out, false) &out->lock <-- use-after-free Once no /dev/dri/cardN fd remains open, drm_managed_release() frees vkms_output and dev->vblank while vkms_set_composer() still touches out->lock and calls drm_crtc_vblank_put(&out->crtc). Returning -ENODEV directly when drm_dev_enter() fails avoids running vkms_set_composer() outside SRCU protection. -- Sashiko AI review · https://sashiko.dev/#/patchset/20261205001701.1125045-1-sebastian.wick@redhat.com?part=2 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-05 0:42 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-12-05 0:16 [PATCH v2 0/2] drm/vkms: Fix races on ConfigFS device removal Sebastian Wick 2026-12-05 0:17 ` [PATCH v2 1/2] drm/vkms: Add drm_dev_enter/exit guards for hot-removable paths Sebastian Wick 2026-12-05 0:42 ` sashiko-bot 2026-12-05 0:17 ` [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal Sebastian Wick 2026-12-05 0:34 ` sashiko-bot
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.