All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Wick" <sebastian.wick@redhat.com>,
	dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] drm/vkms: Use drm_dev_unplug() for ConfigFS device removal
Date: Sat, 05 Dec 2026 00:34:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-250839@kernel.org> (raw)
In-Reply-To: <20261205001701.1125045-3-sebastian.wick@redhat.com>

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

      reply	other threads:[~2026-12-05  0:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=sashiko-outbox-250839@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.wick@redhat.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.