From: sashiko-bot@kernel.org
To: "Rodrigo Vivi" <rodrigo.vivi@intel.com>, dri-devel@lists.freedesktop.org
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/ras: Keep nodes alive while netlink operations use them
Date: Mon, 23 Nov 2026 23:42:22 +0000 [thread overview]
Message-ID: <sashiko-outbox-230220@kernel.org> (raw)
In-Reply-To: <20261123233326.2882114-8-rodrigo.vivi@intel.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/ras: repeated node_id lookup in
drm_ras_nl_get_error_counter_dumpit()
- [Medium] drm/ras: premature node put in get_node_error_counter() and
threshold helper
- [Low] drm/ras: separate declaration and initialization of __free()
node variables
--
commit d22066c85bafafc21ec35b35656510aa805c320f
Author: Rodrigo Vivi <rodrigo.vivi@intel.com>
drm/ras: Keep nodes alive while netlink operations use them
This commit adds reference counting and a release completion to struct
drm_ras_node so that drm_ras_node_unregister() waits for active netlink
operations to finish using a node before returning.
> diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
> index f561604e7e967..550ca7d54cd12 100644
> --- a/drivers/gpu/drm/drm_ras.c
> +++ b/drivers/gpu/drm/drm_ras.c
[ ... ]
> @@ -178,9 +208,9 @@ int drm_ras_nl_list_nodes_dumpit(struct sk_buff *skb,
> static int get_node_error_counter(u32 node_id, u32 error_id,
> const char **name, u32 *value)
> {
> - struct drm_ras_node *node;
> + struct drm_ras_node *node __free(drm_ras_node_put) = NULL;
>
> - node = xa_load(&drm_ras_xa, node_id);
> + node = drm_ras_node_get(node_id);
> if (!node || !node->query_error_counter)
> return -ENOENT;
>
> @@ -193,9 +223,9 @@ static int get_node_error_counter(u32 node_id, u32 error_id,
>
> static int get_node_error_threshold(u32 node_id, u32 error_id, const char **name, u32 *threshold)
> {
> - struct drm_ras_node *node;
> + struct drm_ras_node *node __free(drm_ras_node_put) = NULL;
>
> - node = xa_load(&drm_ras_xa, node_id);
> + node = drm_ras_node_get(node_id);
> if (!node)
> return -ENOENT;
[Severity: Medium]
Does dropping the node reference on return from get_node_error_counter()
and get_node_error_threshold() leave *name unprotected in
doit_reply_value() and doit_reply_threshold()?
drivers/gpu/drm/drm_ras.c:doit_reply_value() {
...
ret = get_node_error_counter(node_id, error_id,
&error_name, &value);
if (ret)
goto cancel_msg;
ret = msg_reply_value(msg, error_id, error_name, value);
...
}
CPU0 CPU1
doit_reply_value()
get_node_error_counter()
node = drm_ras_node_get(...)
node->query_error_counter(...,
&error_name, ...)
drm_ras_node_put(node)
drm_ras_node_unregister(node)
xa_erase(&drm_ras_xa, node->id)
drm_ras_node_put(node)
wait_for_completion(&node->released)
/* driver frees counter names / unloads */
msg_reply_value(..., error_name, ...)
nla_put_string(..., error_name) <-- use-after-free
Because the __free(drm_ras_node_put) reference lives inside the helper,
drm_ras_node_unregister() can finish waiting before msg_reply_value() or
msg_reply_threshold() copies error_name into the skb.
> @@ -210,9 +240,9 @@ static int get_node_error_threshold(u32 node_id, u32 error_id, const char **name
>
> static int set_node_error_threshold(u32 node_id, u32 error_id, u32 threshold)
> {
> - struct drm_ras_node *node;
> + struct drm_ras_node *node __free(drm_ras_node_put) = NULL;
>
> - node = xa_load(&drm_ras_xa, node_id);
> + node = drm_ras_node_get(node_id);
> if (!node)
> return -ENOENT;
[Severity: Low]
This isn't a bug, but cleanup.h style prefers defining and initializing
__free() variables in one statement ("struct drm_ras_node *node
__free(drm_ras_node_put) = drm_ras_node_get(node_id);") rather than
initializing them to NULL and assigning later, here and in the other
functions touched by this patch.
[ ... ]
> @@ -451,7 +482,7 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
> {
> const struct genl_info *info = genl_info_dump(cb);
> struct drm_ras_ctx *ctx = (void *)cb->ctx;
> - struct drm_ras_node *node;
> + struct drm_ras_node *node __free(drm_ras_node_put) = NULL;
> struct nlattr *hdr;
> const char *error_name;
> u32 node_id, error_id, value;
> @@ -462,7 +493,7 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
>
> node_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]);
>
> - node = xa_load(&drm_ras_xa, node_id);
> + node = drm_ras_node_get(node_id);
> if (!node)
> return -ENOENT;
[Severity: Medium]
Can the dump loop in drm_ras_nl_get_error_counter_dumpit() silently
truncate the dump or switch to a different node if
drm_ras_node_unregister() runs mid-dump?
drivers/gpu/drm/drm_ras.c:drm_ras_nl_get_error_counter_dumpit() {
...
for (error_id = max(node->error_counter_range.first, ctx->restart);
error_id <= node->error_counter_range.last;
error_id++) {
ret = get_node_error_counter(node_id, error_id,
&error_name, &value);
/*
* For non-contiguous range, driver return -ENOENT as indication
* to skip this ID when listing all errors.
*/
if (ret == -ENOENT) {
ret = 0;
continue;
}
...
}
drm_ras_nl_get_error_counter_dumpit() already holds a reference on node,
but each loop iteration passes node_id to get_node_error_counter(), which
acquires xa_lock(&drm_ras_xa) and looks up node_id in drm_ras_xa again.
If drm_ras_node_unregister() runs concurrently, it calls xa_erase() before
waiting on node->released. Subsequent iterations of the loop then get
-ENOENT from drm_ras_node_get(node_id) and treat it as a non-contiguous
error ID to skip, returning a truncated dump with status 0 (or querying a
newly registered node if xa_alloc() reuses node_id while the old node is
still waiting in drm_ras_node_unregister()). Passing the already pinned
node pointer to a helper would avoid both the race and the repeated
xa_lock / kref cycles in the loop.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123233326.2882114-5-rodrigo.vivi@intel.com?part=3
next prev parent reply other threads:[~2026-11-23 23:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 23:33 [PATCH 0/3] drm/ras: core fixes Rodrigo Vivi
2026-11-23 23:33 ` [PATCH 1/3] drm/ras: Initialize ret in the list-nodes dump Rodrigo Vivi
2026-11-24 0:46 ` Ruhl, Michael J
2026-11-23 23:33 ` [PATCH 2/3] drm/ras: Do not fail an error-counter dump on a skipped last ID Rodrigo Vivi
2026-11-24 0:48 ` Ruhl, Michael J
2026-11-23 23:33 ` [PATCH 3/3] drm/ras: Keep nodes alive while netlink operations use them Rodrigo Vivi
2026-11-23 23:42 ` sashiko-bot [this message]
2026-11-23 23:41 ` ✗ CI.checkpatch: warning for drm/ras: core fixes Patchwork
2026-11-23 23:43 ` ✗ CI.KUnit: failure " Patchwork
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-230220@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=rodrigo.vivi@intel.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.