Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Rodrigo Vivi" <rodrigo.vivi@intel.com>, intel-xe@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/ras: Add retired-pages node type
Date: Mon, 23 Nov 2026 15:28:53 +0000	[thread overview]
Message-ID: <sashiko-outbox-229565@kernel.org> (raw)
In-Reply-To: <20261123150806.2266196-5-rodrigo.vivi@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/ras: lost NLM_F_DUMP_INTR in
  drm_ras_nl_get_retired_pages_dumpit()
- [Medium] drm/ras: missing node type checks in error-counter netlink
  handlers
--

commit 27c9afd08cd19612592b285ef905e2efcbf77cec
Author: Aravind Iddamsetty <aravind.iddamsetty@linux.intel.com>

drm/ras: Add retired-pages node type

This commit adds a retired-pages node type to drm-ras along with the
get-retired-pages dump operation and the get-retired-pages-info do
operation.

> diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
> index b099eb67836e7..34e5dab997440 100644
> --- a/drivers/gpu/drm/drm_ras.c
> +++ b/drivers/gpu/drm/drm_ras.c

[ ... ]

> @@ -617,6 +637,145 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i
>  	return set_node_error_threshold(node_id, error_id, threshold);
>  }
>  
> +static struct drm_ras_node *get_retired_pages_node(const struct genl_info *info)
> +{
> +	struct nlattr *attr = info->attrs[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID];
> +	struct drm_ras_node *node;
> +
> +	node = xa_load(&drm_ras_xa, nla_get_u32(attr));
> +	if (!node || node->type != DRM_RAS_NODE_TYPE_RETIRED_PAGES) {
> +		NL_SET_BAD_ATTR(info->extack, attr);
> +		return NULL;
> +	}
> +
> +	return node;
> +}
> +
> +static int msg_put_retired_page(struct sk_buff *msg, u32 node_id,
> +				const struct drm_ras_retired_page *page)
> +{
> +	if (nla_put_u32(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID, node_id) ||
> +	    nla_put_uint(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_ADDRESS, page->address) ||
> +	    nla_put_uint(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_SIZE, page->size) ||
> +	    nla_put_u32(msg, DRM_RAS_A_RETIRED_PAGE_ATTRS_STATUS, page->status))
> +		return -EMSGSIZE;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_ras_nl_get_retired_pages_dumpit() - Dump the retired pages of a node
> + * @skb: Netlink message buffer
> + * @cb: Callback context for multi-part dumps
> + *
> + * Appends one message per retired page, in increasing address order. The
> + * dump resumes from the next address after a buffer overflow, and is flagged
> + * with %NLM_F_DUMP_INTR if the list changed between messages.
> + *
> + * Return: 0 if all pages fit in @skb, -EMSGSIZE if the buffer filled up
> + *         (requires multi-part continuation), or a negative error code on
> + *         failure.
> + */
> +int drm_ras_nl_get_retired_pages_dumpit(struct sk_buff *skb,
> +					struct netlink_callback *cb)
> +{
> +	const struct genl_info *info = genl_info_dump(cb);
> +	struct drm_ras_ctx *ctx = (void *)cb->ctx;
> +	struct drm_ras_retired_page page;
> +	struct drm_ras_node *node;
> +	void *hdr;
> +	int ret;
> +
> +	if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID))
> +		return -EINVAL;
> +
> +	node = get_retired_pages_node(info);
> +	if (!node)
> +		return -ENOENT;
> +
> +	for (;;) {
> +		ret = node->query_retired_page(node, ctx->cursor, &page);
> +		if (ret == -ENOENT)
> +			return 0;
> +		if (ret)
> +			return ret;
> +
> +		/* Never zero, so the first message is checked as well */
> +		cb->seq = page.generation + 1;
> +
> +		hdr = genlmsg_iput(skb, info);
> +		if (!hdr)
> +			return -EMSGSIZE;
> +
> +		genl_dump_check_consistent(cb, hdr);
> +
> +		ret = msg_put_retired_page(skb, node->id, &page);
> +		if (ret) {
> +			genlmsg_cancel(skb, hdr);
> +			return ret;
> +		}
> +
> +		genlmsg_end(skb, hdr);
> +		ctx->cursor = page.address + 1;
> +	}
> +}

[Severity: Medium]
Can calling genl_dump_check_consistent(cb, hdr) before
msg_put_retired_page() lose NLM_F_DUMP_INTR across a multi-part dump
boundary?

genlmsg_iput() only requires 20 bytes of tailroom, while
msg_put_retired_page() needs another 32 to 40 bytes.  If the remaining skb
space falls in between when page.generation changes,
genl_dump_check_consistent() sets NLM_F_DUMP_INTR on hdr and updates
cb->prev_seq = cb->seq, after which msg_put_retired_page() fails with
-EMSGSIZE and genlmsg_cancel() discards hdr.  When the dump resumes at the
same ctx->cursor in the next skb, cb->seq already matches cb->prev_seq, so
userspace never receives NLM_F_DUMP_INTR.

Also, page.generation + 1 wraps to 0 in cb->seq when page.generation is
U32_MAX, and if all remaining pages at or above ctx->cursor are removed
between dump batches, query_retired_page() returns -ENOENT before cb->seq
is updated.  Moving genl_dump_check_consistent() after
msg_put_retired_page() succeeds avoids consuming the sequence change on a
cancelled message.

[ ... ]

> @@ -631,14 +790,18 @@ int drm_ras_node_register(struct drm_ras_node *node)
>  	if (!node->device_name || !node->node_name)
>  		return -EINVAL;
>  
> -	/* Currently, only Error Counter Endpoints are supported */
> -	if (node->type != DRM_RAS_NODE_TYPE_ERROR_COUNTER)
> -		return -EINVAL;
> -
> -	/* Mandatory entries for Error Counter Node */
> -	if (node->type == DRM_RAS_NODE_TYPE_ERROR_COUNTER &&
> -	    (!node->error_counter_range.last || !node->query_error_counter))
> +	switch (node->type) {
> +	case DRM_RAS_NODE_TYPE_ERROR_COUNTER:
> +		if (!node->error_counter_range.last || !node->query_error_counter)
> +			return -EINVAL;
> +		break;
> +	case DRM_RAS_NODE_TYPE_RETIRED_PAGES:
> +		if (!node->query_retired_page)
> +			return -EINVAL;
> +		break;
> +	default:
>  		return -EINVAL;
> +	}
>  
>  	return xa_alloc(&drm_ras_xa, &node->id, node, xa_limit_32b, GFP_KERNEL);
>  }

[Severity: Medium]
Now that drm_ras_node_register() inserts DRM_RAS_NODE_TYPE_RETIRED_PAGES
nodes into drm_ras_xa, should the error-counter netlink handlers verify
that node->type == DRM_RAS_NODE_TYPE_ERROR_COUNTER?

Without that check, passing a retired-pages node ID to the error-counter
operations causes get_node_error_threshold() and set_node_error_threshold()
to return -EOPNOTSUPP instead of -ENOENT, and causes
drm_ras_nl_get_error_counter_dumpit() to iterate over
node->error_counter_range on a non-error-counter node:

drivers/gpu/drm/drm_ras.c:get_node_error_threshold() {
	node = xa_load(&drm_ras_xa, node_id);
	if (!node)
		return -ENOENT;

	if (!node->query_error_threshold)
		return -EOPNOTSUPP;
    ...
}

drivers/gpu/drm/drm_ras.c:drm_ras_nl_get_error_counter_dumpit() {
    ...
	node = xa_load(&drm_ras_xa, node_id);
	if (!node)
		return -ENOENT;

	for (error_id = max(node->error_counter_range.first, ctx->restart);
	     error_id <= node->error_counter_range.last;
	     error_id++) {
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123150806.2266196-4-rodrigo.vivi@intel.com?part=1

  reply	other threads:[~2026-11-23 15:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 15:08 [PATCH v3 0/2] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi
2026-11-23 15:08 ` [PATCH 1/2] drm/ras: Add retired-pages node type Rodrigo Vivi
2026-11-23 15:28   ` sashiko-bot [this message]
2026-11-23 15:08 ` [PATCH 2/2] drm/xe: Expose retired VRAM pages via drm-ras Rodrigo Vivi

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-229565@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox