All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Louis Chauvet" <louis.chauvet@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 01/43] drm/vkms: Lock the config dump against concurrent configfs changes
Date: Thu, 26 Nov 2026 11:50:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-235426@kernel.org> (raw)
In-Reply-To: <20261126-vkms-all-config-v7-1-21194cda2468@bootlin.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] drm/vkms: const discarded locking config->lock in
  vkms_connector_detect()
- [High] drm/vkms: self-deadlock on config->lock in
  connector_status_store()
- [Medium] drm/vkms: unlocked RCU list walk and UAF in
  vkms_connector_detect()
- [Medium] drm/vkms: races from dropping config->lock in
  device_enabled_store()
- [Medium] drm/vkms: RCU lockdep warning in vkms_config_for_each_*
  during vkms_create()
- [Low] drm/vkms: commit message and vkms_config_show() comment mismatch
  with code
--

commit e3fcd80e0d55e7be8d3c20f129777ead0dbe15ab
Author: Louis Chauvet <louis.chauvet@bootlin.com>

drm/vkms: Lock the config dump against concurrent configfs changes

This commit moves the configuration lock into struct vkms_config, converts
the configuration lists to RCU-protected lists, and updates configfs,
debugfs, and connector detection to synchronize configuration access.

> diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
> index f9e30a4e5a3f8..6699ddae71260 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.c
> +++ b/drivers/gpu/drm/vkms/vkms_config.c
[ ... ]
> @@ -348,28 +350,38 @@ static int vkms_config_show(struct seq_file *m, void *data)
>  	struct vkms_config_encoder *encoder_cfg;
>  	struct vkms_config_connector *connector_cfg;
>  
> -	dev_name = vkms_config_get_device_name((struct vkms_config *)vkmsdev->config);
> -	seq_printf(m, "dev_name=%s\n", dev_name);
> -
> -	vkms_config_for_each_plane(vkmsdev->config, plane_cfg) {
> -		seq_puts(m, "plane:\n");
> -		seq_printf(m, "\ttype=%d\n",
> -			   vkms_config_plane_get_type(plane_cfg));
> -	}
> +	/*
> +	 * The configuration lists are mutated by the configfs under the
> +	 * configuration lock. Walk them under RCU instead: mutations use
> +	 * list_{add,del}_rcu and free the objects after a grace period,
> +	 * so this reader holds no lock and cannot block the configfs
> +	 * paths (the disable path removes this file while holding the
> +	 * lock, and the debugfs removal waits for this reader to drain).
> +	 */
> +	scoped_guard(rcu) {

[Severity: Low]
This isn't a bug, but both the commit message and this comment appear out of
sync with the code.  The commit message says "Move the configuration lock
into struct vkms_config and run the dump under it", whereas
vkms_config_show() uses scoped_guard(rcu).  In addition, this comment says
the disable path removes the debugfs file while holding the lock, but
device_enabled_store() drops dev->config->lock before calling vkms_destroy().

> diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
> index 56805b0c9b145..125273f67e7d7 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.h
> +++ b/drivers/gpu/drm/vkms/vkms_config.h
[ ... ]
> @@ -126,7 +139,9 @@ struct vkms_config_connector {
>   * @plane_cfg: &struct vkms_config_plane pointer used as cursor
>   */
>  #define vkms_config_for_each_plane(config, plane_cfg) \
> -	list_for_each_entry((plane_cfg), &(config)->planes, link)
> +	list_for_each_entry_rcu((plane_cfg), &(config)->planes, link, \
> +				      lockdep_is_held(&(config)->lock) || \
> +				      !(config)->dev)

[Severity: Medium]
Does this lockdep condition trigger an RCU_LOCKDEP_WARN splat during
vkms_create() when CONFIG_PROVE_RCU_LIST=y is enabled?

In vkms_create(), config->dev is assigned before calling vkms_modeset_init():

drivers/gpu/drm/vkms/vkms_drv.c:vkms_create() {
	...
	vkms_device->faux_dev = fdev;
	vkms_device->config = config;
	config->dev = vkms_device;
	...
	ret = vkms_modeset_init(vkms_device);
}

Neither vkms_init() nor device_enabled_store() holds config->lock or
rcu_read_lock() across vkms_create(), so config->dev is non-NULL when
vkms_modeset_init() -> vkms_output_init() and vkms_config_is_valid() iterate
the configuration lists with vkms_config_for_each_{plane,crtc,encoder,connector}().

> diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
> index af097967ca6fc..6bb24f5835db1 100644
> --- a/drivers/gpu/drm/vkms/vkms_configfs.c
> +++ b/drivers/gpu/drm/vkms/vkms_configfs.c
[ ... ]
> @@ -548,7 +546,7 @@ static ssize_t connector_status_store(struct config_item *item,
>  	    status != connector_status_unknown)
>  		return -EINVAL;
>  
> -	scoped_guard(mutex, &connector->dev->lock) {
> +	scoped_guard(mutex, &connector->dev->config->lock) {
>  		vkms_config_connector_set_status(connector->config, status);
>  
>  		if (connector->dev->enabled)
>  			vkms_trigger_connector_hotplug(connector->dev->config->dev);
>  	}

[Severity: High]
Does calling vkms_trigger_connector_hotplug() while holding
connector->dev->config->lock self-deadlock on config->lock when a connector's
configfs status is written on an enabled device?

connector_status_store()
  mutex_lock(&connector->dev->config->lock)
  vkms_trigger_connector_hotplug()
    drm_kms_helper_hotplug_event()
      ...
        drm_helper_probe_single_connector_modes()
          vkms_connector_detect()
            mutex_lock(&vkmsdev->config->lock)  <-- deadlocks

This also inverts the lock order against normal DRM connector probing (such
as drm_mode_getconnector()), which acquires dev->mode_config.mutex before
calling vkms_connector_detect() -> mutex_lock(&vkmsdev->config->lock).

[ ... ]

> @@ -711,21 +709,34 @@ static ssize_t device_enabled_store(struct config_item *item, const char *page,
>  	if (kstrtobool(page, &enabled))
>  		return -EINVAL;
>  
> -	scoped_guard(mutex, &dev->lock) {
> -		if (!dev->enabled && enabled) {
> -			if (!vkms_config_is_valid(dev->config))
> -				return -EINVAL;
> +	scoped_guard(mutex, &dev->config->lock) {
> +		if (dev->enabled == enabled)
> +			return (ssize_t)count;
>  
> -			ret = vkms_create(dev->config);
> -			if (ret)
> -				return ret;
> -		} else if (dev->enabled && !enabled) {
> -			vkms_destroy(dev->config);
> -		}
> +		if (!dev->enabled && !vkms_config_is_valid(dev->config))
> +			return -EINVAL;
>  
>  		dev->enabled = enabled;
>  	}
>  
> +	/*
> +	 * Do not hold config->lock while creating/destroying the device:
> +	 * vkms_destroy() unregisters the DRM device, which removes the
> +	 * vkms_config debugfs file and waits for its readers to drain, and
> +	 * vkms_connector_detect() takes config->lock to read the connector
> +	 * status.
> +	 */
> +	if (enabled) {
> +		ret = vkms_create(dev->config);
> +		if (ret) {
> +			scoped_guard(mutex, &dev->config->lock)
> +				dev->enabled = false;
> +			return ret;
> +		}
> +	} else {
> +		vkms_destroy(dev->config);
> +	}

[Severity: Medium]
Can dropping dev->config->lock after setting dev->enabled leave vkms_create()
and vkms_destroy() open to concurrent configfs operations?

CPU0                              CPU1
device_enabled_store(1)
  mutex_lock(&config->lock)
  dev->enabled = true
  mutex_unlock(&config->lock)
                                  connector_status_store()
                                    mutex_lock(&config->lock)
                                    if (connector->dev->enabled)
                                      vkms_trigger_connector_hotplug(
                                        config->dev)
                                        <-- NULL pointer dereference
  vkms_create(dev->config)
    config->dev = vkms_device

Because config->lock is released before vkms_create() or vkms_destroy() runs:
- a second write to enabled on another file descriptor can run vkms_destroy()
  concurrently with vkms_create() (or mutate the configuration after
  dev->enabled is cleared to false while vkms_destroy() is still running);
- configfs unlink (*_drop_link) and rmdir (*_release) callbacks do not check
  dev->enabled, so they can acquire config->lock after vkms_config_is_valid()
  returns and detach or free planes, CRTCs, encoders, or connectors while
  vkms_create() -> vkms_output_init() is initializing the device.

> diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
> index 57138027966f5..080a0240d5e92 100644
> --- a/drivers/gpu/drm/vkms/vkms_connector.c
> +++ b/drivers/gpu/drm/vkms/vkms_connector.c
> @@ -27,8 +27,10 @@ static enum drm_connector_status vkms_connector_detect(struct drm_connector *con
>  	status = connector->status;
>  
>  	vkms_config_for_each_connector(vkmsdev->config, connector_cfg) {
> -		if (connector_cfg->connector == vkms_connector)
> -			status = vkms_config_connector_get_status(connector_cfg);
> +		if (connector_cfg->connector == vkms_connector) {
> +			scoped_guard(mutex, &vkmsdev->config->lock)
> +				status = vkms_config_connector_get_status(connector_cfg);
> +		}
>  	}

[Severity: High]
Does passing &vkmsdev->config->lock to scoped_guard(mutex, ...) fail to build
under CONFIG_WERROR=y?  In struct vkms_device, config is declared as
const struct vkms_config *, so &vkmsdev->config->lock discards the const
qualifier (-Werror=discarded-qualifiers).  This is rewritten in a later patch
in the series, commit "drm/vkms: Introduce back pointer to connector", but
breaks bisection at this commit.

[Severity: Medium]
Can walking vkmsdev->config->connectors here without rcu_read_lock() or
holding config->lock across the loop trigger an RCU lockdep warning and race
with connector_release()?

CPU0                              CPU1
vkms_connector_detect()
  vkms_config_for_each_connector()
    if (connector_cfg->connector == ...)
                                  connector_release()
                                    mutex_lock(&config->lock)
                                    vkms_config_destroy_connector()
                                      list_del_rcu(&connector_cfg->link)
                                      kfree_rcu(connector_cfg, rcu)
                                    mutex_unlock(&config->lock)
                                  /* RCU grace period elapses */
      mutex_lock(&config->lock)
      vkms_config_connector_get_status(
        connector_cfg)            <-- use-after-free

Because vkmsdev->config->dev is non-NULL and neither rcu_read_lock() nor
config->lock is held across vkms_config_for_each_connector(), every call to
vkms_connector_detect() triggers RCU_LOCKDEP_WARN under
CONFIG_PROVE_RCU_LIST=y, and connector_cfg can be freed while CPU0 is
preempted or blocked on config->lock.  Later patches in the series (commit
"drm/vkms: Reference-count vkms_config and vkms_config_connector" and commit
"drm/vkms: Introduce back pointer to connector") replace this traversal with
a reference-counted back-pointer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-vkms-all-config-v7-0-21194cda2468@bootlin.com?part=1

  reply	other threads:[~2026-11-26 11:50 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 11:28 [PATCH v7 00/43] VKMS: Introduce multiple configFS attributes Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 01/43] drm/vkms: Lock the config dump against concurrent configfs changes Louis Chauvet
2026-11-26 11:50   ` sashiko-bot [this message]
2026-11-26 11:28 ` [PATCH v7 02/43] drm/drm_mode_config: Add helper to get plane type name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 03/43] drm/blend: Get a rotation name from its bitfield Louis Chauvet
2026-11-26 11:40   ` sashiko-bot
2026-11-26 11:28 ` [PATCH v7 04/43] drm/tests: Add test cases for DRM rotation name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 05/43] drm/drm_color_mgmt: Expose drm_get_color_encoding_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 06/43] drm/drm_color_mgmt: Expose drm_get_color_range_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 07/43] drm/connector: Export drm_get_colorspace_name Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 08/43] drm/drm_atomic_state_helper: Properly load default value for rotation Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 09/43] Documentation: ABI: vkms: Add current VKMS ABI documentation Louis Chauvet
2026-12-01 15:01   ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 10/43] drm/vkms: Reset config->dev when the device creation fails Louis Chauvet
2026-11-26 11:48   ` sashiko-bot
2026-11-27  7:21   ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 11/43] drm/vkms: Reference-count vkms_config and vkms_config_connector Louis Chauvet
2026-11-26 11:49   ` sashiko-bot
2026-11-26 11:28 ` [PATCH v7 12/43] drm/vkms: Add KUnit test for device lifecycle Louis Chauvet
2026-11-26 11:55   ` sashiko-bot
2026-11-27 10:24   ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 13/43] drm/vkms: Add error handling in plane config creation Louis Chauvet
2026-11-27 10:36   ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 14/43] drm/vkms: Simplify plane_release code Louis Chauvet
2026-11-26 11:28 ` [PATCH v7 15/43] drm/vkms: Explicitly display plane type Louis Chauvet
2026-11-27 10:40   ` Oarora Etimis
2026-11-26 11:28 ` [PATCH v7 16/43] drm/vkms: Use enabled/disabled instead of 1/0 for debug Louis Chauvet
2026-11-27 10:41   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 17/43] drm/vkms: Introduce config for plane name Louis Chauvet
2026-11-26 11:48   ` sashiko-bot
2026-11-27 11:39   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 18/43] drm/vkms: Use plane folder name as " Louis Chauvet
2026-11-27 11:40   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 19/43] drm/vkms: Introduce config for plane rotation Louis Chauvet
2026-11-26 11:46   ` sashiko-bot
2026-12-01 15:19   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 20/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-12-01 15:27   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 21/43] drm/vkms: Introduce config for plane color encoding Louis Chauvet
2026-11-26 11:48   ` sashiko-bot
2026-12-01 16:59   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 22/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:43   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 23/43] drm/vkms: Introduce config for plane color range Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 24/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:45   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 25/43] drm/vkms: Introduce config for plane format Louis Chauvet
2026-11-26 11:46   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 26/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:49   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 27/43] drm/vkms: Properly render plane using their zpos Louis Chauvet
2026-12-01 17:23   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 28/43] drm/vkms: Introduce config for plane zpos property Louis Chauvet
2026-11-26 11:46   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 29/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 30/43] drm/vkms: Introduce back pointer to connector Louis Chauvet
2026-11-26 11:55   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 31/43] drm/vkms: Introduce connector type Louis Chauvet
2026-11-27  7:15   ` Oarora Etimis
2026-11-26 11:29 ` [PATCH v7 32/43] drm/vkms: Introduce configfs for " Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 33/43] drm/vkms: Rename vkms_connector_init to vkms_connector_init_static Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 34/43] drm/vkms: Introduce config for connector supported colorspace Louis Chauvet
2026-11-26 11:48   ` sashiko-bot
2026-11-26 16:44   ` kernel test robot
2026-11-26 11:29 ` [PATCH v7 35/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:50   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 36/43] drm/vkms: Introduce config for connector EDID Louis Chauvet
2026-11-26 11:51   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 37/43] drm/vkms: Introduce configfs " Louis Chauvet
2026-11-26 11:59   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 38/43] drm/vkms: Store the enabled/disabled status for connector Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 39/43] drm/connector: Add a way to detach encoders Louis Chauvet
2026-11-26 11:29 ` [PATCH v7 40/43] drm/vkms: Allow to hot-add connectors Louis Chauvet
2026-11-26 12:05   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 41/43] drm/vkms: Introduce configfs for dynamic connector creation Louis Chauvet
2026-11-26 12:02   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 42/43] drm/vkms: Add connector parent configuration in vkms_config Louis Chauvet
2026-11-26 11:56   ` sashiko-bot
2026-11-26 11:29 ` [PATCH v7 43/43] drm/vkms: Add ConfigFS interface for connector parent and port_id Louis Chauvet
2026-11-26 11:52   ` sashiko-bot
2026-11-26 19:49   ` kernel test robot

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-235426@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=louis.chauvet@bootlin.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.