From: sashiko-bot@kernel.org
To: "Louis Chauvet" <louis.chauvet@bootlin.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v7 42/43] drm/vkms: Add connector parent configuration in vkms_config
Date: Thu, 26 Nov 2026 11:56:54 +0000 [thread overview]
Message-ID: <sashiko-outbox-235452@kernel.org> (raw)
In-Reply-To: <20261126-vkms-all-config-v7-42-21194cda2468@bootlin.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] drm/vkms: use-after-free on stale connector_cfg->connector
across device reset
- [Medium] drm/vkms: vkms_config_connector_get_parent() fails to detect
destroyed parent
- [Medium] drm/vkms: reference cycle leak when parent connector is
destroyed before config
- [Medium] drm/vkms: valid_connector_parents() mishandles static
connectors with enabled=0
- [Low] drm/vkms: vkms_connector_build_path_property() drops port_id at
16 nesting hops
--
commit ce654c82414edd96edaad21d3e70ad4c756954e2
Author: Louis Chauvet <louis.chauvet@bootlin.com>
drm/vkms: Add connector parent configuration in vkms_config
This commit adds parent connector and port_id configuration to
vkms_config_connector and populates the DRM connector PATH property to
emulate MST topologies.
> diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
> index 2c6a53d6f7783..fb6368e53c076 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.c
> +++ b/drivers/gpu/drm/vkms/vkms_config.c
[ ... ]
> @@ -498,6 +508,43 @@ static bool valid_connector_colorspaces(const struct vkms_config *config)
> return true;
> }
>
> +static bool valid_connector_parents(const struct vkms_config *config)
> +{
> + struct drm_device *dev = config->dev ? &config->dev->drm : NULL;
> +
> + struct vkms_config_connector *connector_cfg;
> + const struct vkms_config_connector *parent;
> + size_t num_connectors = 0;
> + size_t depth;
> +
> + vkms_config_for_each_connector(config, connector_cfg)
> + num_connectors++;
> +
> + vkms_config_for_each_connector(config, connector_cfg) {
> + bool expected_status = connector_cfg->enabled;
> +
> + parent = connector_cfg;
> + for (depth = 0; parent; depth++) {
> + /* A loop in the parent chain is walked more than
> + * num_connectors times.
> + */
> + if (depth > num_connectors) {
> + drm_info(dev, "Parents of connector should not form a loop\n");
> + return false;
> + }
> +
> + if (expected_status && parent->enabled != expected_status) {
> + drm_info(dev, "All parents of an enabled connector must be enabled\n");
> + return false;
> + }
> +
> + parent = vkms_config_connector_get_parent(parent);
> + }
> + }
> +
> + return true;
> +}
[Severity: Medium]
Does valid_connector_parents() mishandle static connectors whose enabled
field is false?
Static connectors (!connector_cfg->dynamic) are always created and
registered by vkms_output_init() regardless of connector_cfg->enabled, and
configfs allows writing 0 to enabled while the device is disabled. If a
static child connector has enabled == false and is attached to a disabled
dynamic parent, valid_connector_parents() skips the parent check and
vkms_output_init() registers the child with an unpopulated PATH property of
0 while its root parent is never created. Conversely, an enabled child
attached to a static parent with enabled == false is rejected.
[ ... ]
> @@ -1154,7 +1213,8 @@ int vkms_config_connector_set_edid(struct vkms_config_connector *connector_cfg,
> }
> EXPORT_SYMBOL_IF_KUNIT(vkms_config_connector_set_edid);
>
> -void vkms_config_destroy_connector(struct vkms_config_connector *connector_cfg)
> +void vkms_config_destroy_connector(struct vkms_config *config,
> + struct vkms_config_connector *connector_cfg)
> {
> /*
> * Pin the config, then unlink and drop the list's reference. If this
> @@ -1163,13 +1223,41 @@ void vkms_config_destroy_connector(struct vkms_config_connector *connector_cfg)
> * nor free the config (pinned). list_del_rcu() because a concurrent
> * dump may still be walking this connector.
> */
> - vkms_config_get(connector_cfg->config);
> + vkms_config_get(config);
> list_del_rcu(&connector_cfg->link);
> connector_cfg->unlinked = true;
> + /*
> + * The connector is logically destroyed but stays allocated
> + * while its children still hold a reference on it; detach it
> + * from its own parent now. Without this, a parent cycle
> + * (accepted at link time, rejected when enabling the device)
> + * would keep every member of the cycle alive forever, as
> + * plain krefs cannot be reclaimed in a loop.
> + */
> + if (connector_cfg->parent) {
> + struct vkms_config_connector *parent = connector_cfg->parent;
> +
> + connector_cfg->parent = NULL;
> + vkms_config_connector_put(parent);
> + }
> +
> vkms_config_connector_put(connector_cfg);
> }
[Severity: Medium]
Does destroying a parent connector before vkms_config_destroy() leak
config and its remaining objects via a reference cycle?
When vkms_config_destroy_connector(config, parent) runs while a child in
config->connectors still has child->parent == parent, it takes a reference
on config with vkms_config_get(config) that is only dropped in
vkms_config_connector_release() once parent->refcnt reaches 0. Because
child->parent keeps parent->refcnt > 0 and child->parent is only cleared
in vkms_config_release() when config->refcnt reaches 0, a subsequent
vkms_config_destroy(config) leaves config, child, and parent pinning each
other permanently.
> diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
> index e5352aaea85e6..83869e677f157 100644
> --- a/drivers/gpu/drm/vkms/vkms_config.h
> +++ b/drivers/gpu/drm/vkms/vkms_config.h
[ ... ]
> +static inline struct vkms_config_connector*
> +vkms_config_connector_get_parent(const struct vkms_config_connector *connector_cfg)
> +{
> + struct vkms_config_connector *parent = connector_cfg->parent;
> +
> + if (parent && list_empty(&parent->link))
> + return NULL;
> +
> + return parent;
> +}
[Severity: Medium]
Does list_empty(&parent->link) ever detect a parent destroyed by
vkms_config_destroy_connector()?
vkms_config_destroy_connector() removes the connector with list_del_rcu()
and sets parent->unlinked = true, while the child's reference keeps
parent->refcnt > 0. list_del_rcu() intentionally leaves parent->link.next
unchanged for RCU readers, so list_empty(&parent->link) evaluates to false
and vkms_config_connector_get_parent() keeps returning the destroyed
parent instead of NULL. Checking parent->unlinked avoids this.
> diff --git a/drivers/gpu/drm/vkms/vkms_connector.c b/drivers/gpu/drm/vkms/vkms_connector.c
> index 93bceba0a1ae6..5655f8b649c66 100644
> --- a/drivers/gpu/drm/vkms/vkms_connector.c
> +++ b/drivers/gpu/drm/vkms/vkms_connector.c
> @@ -8,6 +8,76 @@
> #include "vkms_config.h"
> #include "vkms_connector.h"
>
> +/**
> + * vkms_connector_build_path_property() - Build the PATH property string for MST connectors
> + * @connector: The connector to build the PATH property for
> + * @connector_cfg: The connector configuration
> + *
> + * The PATH property format is:
> + * mst:<drm object ID of root connector>-<dash-separated list of port_id>
> + * For nested MST connectors, this builds the full path like mst:45-2-3-4-2
> + */
> +static void vkms_connector_build_path_property(struct vkms_connector *connector,
> + const struct vkms_config_connector *connector_cfg)
> +{
> + const struct vkms_config_connector *current_cfg = connector_cfg;
> + const struct vkms_config_connector *root_cfg = NULL;
> + struct vkms_connector *root_connector = NULL;
> + char path[128]; /* Increased size for nested MST paths */
> + int len = 0;
> + u8 port_ids[16]; /* Max 16 levels of nesting */
> + int port_count = 0;
> + int i;
> +
> + if (!vkms_config_connector_get_parent(connector_cfg))
> + return;
> +
> + while (current_cfg) {
> + if (port_count < ARRAY_SIZE(port_ids))
> + port_ids[port_count++] = current_cfg->port_id;
> +
> + if (!vkms_config_connector_get_parent(current_cfg)) {
> + root_cfg = current_cfg;
> + break;
> + }
> +
> + current_cfg = vkms_config_connector_get_parent(current_cfg);
> + }
> +
> + if (!root_cfg || !root_cfg->connector)
> + return;
> +
> + root_connector = root_cfg->connector;
> +
> + len = snprintf(path, sizeof(path), "mst:%d", root_connector->base.base.id);
> +
> + for (i = port_count - 2; i >= 0; i--) {
> + int added = snprintf(path + len, sizeof(path) - len,
> + "-%u", port_ids[i]);
> + if (added < 0 || len + added >= sizeof(path))
> + return;
> + len += added;
> + }
> +
> + drm_connector_set_path_property(&connector->base, path);
> +}
[Severity: Low]
Does vkms_connector_build_path_property() drop the first child's port_id
when the chain reaches 16 levels of nesting?
The loop records current_cfg->port_id before checking whether current_cfg
is the root connector, and the formatting loop starts at port_count - 2 to
skip the root's entry. At 16 hops below the root, port_ids[0..15] fills
with the 16 child port IDs before reaching root_cfg, so starting at
port_count - 2 skips port_ids[15], which holds the first child's port_id
rather than the root's.
> +
> +/**
> + * vkms_connector_update_path_properties() - Update PATH properties for all connectors
> + * @vkmsdev: VKMS device
> + *
> + * This should be called after all connectors are created to ensure parent connectors
> + * have valid DRM object IDs.
> + */
> +void vkms_connector_update_path_properties(struct vkms_device *vkmsdev)
> +{
> + struct vkms_config_connector *connector_cfg;
> +
> + vkms_config_for_each_connector(vkmsdev->config, connector_cfg)
> + if (connector_cfg->connector)
> + vkms_connector_build_path_property(connector_cfg->connector, connector_cfg);
> +}
[ ... ]
> @@ -278,6 +352,8 @@ struct vkms_connector *vkms_connector_hot_add(struct vkms_device *vkmsdev,
> return ERR_PTR(ret);
> }
>
> + vkms_connector_build_path_property(connector, connector_cfg);
> +
> /*
> * Attach the configuration before registration and serialize the
> * registration with in-flight probes: drm_mode_getconnector() holds
[Severity: High]
Can vkms_connector_build_path_property() and
vkms_connector_update_path_properties() trigger a use-after-free on stale
connector_cfg->connector pointers when a device is disabled and
re-enabled?
When vkms_destroy() tears down a device, neither
vkms_connector_static_cfg_release() nor vkms_connector_dynamic_destroy()
clears connector_cfg->connector. On the next vkms_create() ->
vkms_output_init(), two paths dereference the freed struct vkms_connector
from the previous device instance:
1. If a dynamic child connector was enabled during the first instance and
is then disabled while the device is disabled, the next
vkms_output_init() skips it in the if (connector_cfg->enabled) loop,
leaving connector_cfg->connector pointing to the freed connector.
vkms_connector_update_path_properties() then checks only
if (connector_cfg->connector) and calls
drm_connector_set_path_property() on the freed connector.
2. If an enabled dynamic child precedes its enabled dynamic root in
config->connectors, vkms_output_init() calls vkms_connector_hot_add() on
the child before root_cfg->connector is updated for the new device, and
vkms_connector_build_path_property() reads root_connector->base.base.id
from the old freed root connector.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-vkms-all-config-v7-0-21194cda2468@bootlin.com?part=42
next prev parent reply other threads:[~2026-11-26 11:57 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
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 [this message]
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-235452@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.