Skip to contentSkip to conversation

drm/xe: Expose retired VRAM pages via drm-ras

PATCH Superseded Rodrigo Vivi 2 participants 5 messages Nov 23

Subsystems (6)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Rodrigo Vivi

author maintainer
#0 lore raw

v3 cover drm/xe: Expose retired VRAM pages via drm-ras

This is v3 of:

https://lore.kernel.org/dri-devel/[email protected]/

It addresses all the netlink review-prompts and reduces the unused layer to solve Jacob's anti-pattern concern.

The IGT test and tools are also done:
https://lore.kernel.org/igt-dev/[email protected]/T/#t

Thanks,
Rodrigo.

Aravind Iddamsetty (2):
drm/ras: Add retired-pages node type
drm/xe: Expose retired VRAM pages via drm-ras

 Documentation/netlink/specs/drm_ras.yaml   |  75 ++++++++-
 drivers/gpu/drm/drm_ras.c                  | 179 ++++++++++++++++++++-
 drivers/gpu/drm/drm_ras_nl.c               |  24 +++
 drivers/gpu/drm/drm_ras_nl.h               |   4 +
 drivers/gpu/drm/xe/xe_drm_ras.c            |  56 +++++++
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c       |  72 ++++++++-
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.h       |   3 +
 drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h |   5 +
 include/drm/drm_ras.h                      |  48 ++++++
 include/uapi/drm/drm_ras.h                 |  31 +++-
 10 files changed, 482 insertions(+), 15 deletions(-)
Signature · 1 line
2.56.0
author maintainer
#1 lore raw

PATCH v3 1/2 drm/ras: Add retired-pages node type

From: Aravind Iddamsetty <[email protected]>

Add a retired-pages node type to drm-ras so drivers can report the memory pages they have taken out of service, with two operations:

- get-retired-pages: dump one entry per page with its address, size and status (retired, pending or failed). The dump is flagged with NLM_F_DUMP_INTR if the list changes while it is read.
- get-retired-pages-info: return the maximum number of pages that can be retired.

v3 (Rodrigo+LLM):
- Split the drm-ras core from the xe user.
- Flatten the page attributes and name the node type retired-pages instead of retired-resources, avoiding the over-wrapping anti-pattern pointed out by Jakub: the type-specific nest and the resource-type enum are gone.
- Use uint for address, size and max-pages, no pad (Jakub).
- Start the status enum at 1.
- Move max-pages to its own do operation instead of a leading dump entry.
- Set NLM_F_DUMP_INTR from a driver generation counter.
- Report unknown node IDs with NL_SET_BAD_ATTR.
- Removed deprecated Assisted-by tag.

---
 Documentation/netlink/specs/drm_ras.yaml |  75 +++++++++-
 drivers/gpu/drm/drm_ras.c                | 179 ++++++++++++++++++++++-
 drivers/gpu/drm/drm_ras_nl.c             |  24 +++
 drivers/gpu/drm/drm_ras_nl.h             |   4 +
 include/drm/drm_ras.h                    |  48 ++++++
 include/uapi/drm/drm_ras.h               |  31 +++-
 6 files changed, 347 insertions(+), 14 deletions(-)
Documentation/netlink/specs/drm_ras.yaml +71 -4
index 4c2ac9a1ba3f..448d22dbf1b4 100644
@@ -16,11 +16,22 @@ definitions:
     type: enum
     name: node-type
     value-start: 1
-    entries: [error-counter]
+    entries: [error-counter, retired-pages]
     doc: >-
-         Type of the node. Currently, only error-counter nodes are
-         supported, which expose reliability counters for a hardware/software
-         component.
+         Type of the node.
+         error-counter nodes expose reliability counters for a
+         hardware/software component. retired-pages nodes list the memory
+         pages that have been taken out of service.
+  -
+    type: enum
+    name: retired-page-status
+    value-start: 1
+    entries: [retired, pending, failed]
+    doc: >-
+         Status of a retired page. retired means the page is reserved and out
+         of service; pending means the retirement is queued but the
+         reservation is not complete yet; failed means the reservation failed
+         and the page may still be in use.
 
 attribute-sets:
   -
@@ -100,6 +111,30 @@ attribute-sets:
         name: error-value
         type: u32
         doc: Current value of the error counter.
+  -
+    name: retired-page-attrs
+    attributes:
+      -
+        name: node-id
+        type: u32
+        doc: Node ID targeted by this retired pages operation.
+      -
+        name: address
+        type: uint
+        doc: Device address of the retired page.
+      -
+        name: size
+        type: uint
+        doc: Size of the retired page in bytes.
+      -
+        name: status
+        type: u32
+        doc: Retirement status of the page.
+        enum: retired-page-status
+      -
+        name: max-pages
+        type: uint
+        doc: Maximum number of pages that can be retired on this node.
 
 operations:
   list:
@@ -199,6 +234,38 @@ operations:
             - node-id
             - error-id
             - error-threshold
+    -
+      name: get-retired-pages
+      doc: >-
+           Retrieve the pages retired on a retired-pages node, one entry per
+           page. The dump is flagged as interrupted if the list changes while
+           it is being read.
+      attribute-set: retired-page-attrs
+      flags: [admin-perm]
+      dump:
+        request:
+          attributes:
+            - node-id
+        reply:
+          attributes:
+            - node-id
+            - address
+            - size
+            - status
+    -
+      name: get-retired-pages-info
+      doc: >-
+           Retrieve the retired page limits of a retired-pages node.
+      attribute-set: retired-page-attrs
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - node-id
+        reply:
+          attributes:
+            - node-id
+            - max-pages
 
 mcast-groups:
   list:
drivers/gpu/drm/drm_ras.c +171 -8

222 lines not on this page · raw message

drivers/gpu/drm/drm_ras_nl.c +24 -0
index c9f5e0ceb3b5..a301b2b3a194 100644
@@ -41,6 +41,16 @@ static const struct nla_policy drm_ras_set_error_threshold_nl_policy[DRM_RAS_A_E
 	[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD] = { .type = NLA_U32, },
 };
 
+/* DRM_RAS_CMD_GET_RETIRED_PAGES - dump */
+static const struct nla_policy drm_ras_get_retired_pages_nl_policy[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID + 1] = {
+	[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID] = { .type = NLA_U32, },
+};
+
+/* DRM_RAS_CMD_GET_RETIRED_PAGES_INFO - do */
+static const struct nla_policy drm_ras_get_retired_pages_info_nl_policy[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID + 1] = {
+	[DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID] = { .type = NLA_U32, },
+};
+
 /* Ops table for drm_ras */
 static const struct genl_split_ops drm_ras_nl_ops[] = {
 	{
@@ -83,6 +93,20 @@ static const struct genl_split_ops drm_ras_nl_ops[] = {
 		.maxattr	= DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD,
 		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
 	},
+	{
+		.cmd		= DRM_RAS_CMD_GET_RETIRED_PAGES,
+		.dumpit		= drm_ras_nl_get_retired_pages_dumpit,
+		.policy		= drm_ras_get_retired_pages_nl_policy,
+		.maxattr	= DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID,
+		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
+	},
+	{
+		.cmd		= DRM_RAS_CMD_GET_RETIRED_PAGES_INFO,
+		.doit		= drm_ras_nl_get_retired_pages_info_doit,
+		.policy		= drm_ras_get_retired_pages_info_nl_policy,
+		.maxattr	= DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID,
+		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
+	},
 };
 
 static const struct genl_multicast_group drm_ras_nl_mcgrps[] = {
drivers/gpu/drm/drm_ras_nl.h +4 -0
index 9aef097ea10f..9ea26c04d330 100644
@@ -24,6 +24,10 @@ int drm_ras_nl_get_error_threshold_doit(struct sk_buff *skb,
 					struct genl_info *info);
 int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb,
 					struct genl_info *info);
+int drm_ras_nl_get_retired_pages_dumpit(struct sk_buff *skb,
+					struct netlink_callback *cb);
+int drm_ras_nl_get_retired_pages_info_doit(struct sk_buff *skb,
+					   struct genl_info *info);
 
 enum {
 	DRM_RAS_NLGRP_ERROR_REPORT,
include/drm/drm_ras.h +48 -0

60 lines not on this page · raw message

include/uapi/drm/drm_ras.h +29 -2
index 2f832275ee6e..efbc45aca506 100644
@@ -11,11 +11,25 @@
 #define DRM_RAS_FAMILY_VERSION	1
 
 /*
- * Type of the node. Currently, only error-counter nodes are supported, which
- * expose reliability counters for a hardware/software component.
+ * Type of the node. error-counter nodes expose reliability counters for a
+ * hardware/software component. retired-pages nodes list the memory pages that
+ * have been taken out of service.
  */
 enum drm_ras_node_type {
 	DRM_RAS_NODE_TYPE_ERROR_COUNTER = 1,
+	DRM_RAS_NODE_TYPE_RETIRED_PAGES,
+};
+
+/*
+ * Status of a retired page. retired means the page is reserved and out of
+ * service; pending means the retirement is queued but the reservation is not
+ * complete yet; failed means the reservation failed and the page may still be
+ * in use.
+ */
+enum drm_ras_retired_page_status {
+	DRM_RAS_RETIRED_PAGE_STATUS_RETIRED = 1,
+	DRM_RAS_RETIRED_PAGE_STATUS_PENDING,
+	DRM_RAS_RETIRED_PAGE_STATUS_FAILED,
 };
 
 enum {
@@ -51,6 +65,17 @@ enum {
 	DRM_RAS_A_ERROR_EVENT_ATTRS_MAX = (__DRM_RAS_A_ERROR_EVENT_ATTRS_MAX - 1)
 };
 
+enum {
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_NODE_ID = 1,
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_ADDRESS,
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_SIZE,
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_STATUS,
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX_PAGES,
+
+	__DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX,
+	DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX = (__DRM_RAS_A_RETIRED_PAGE_ATTRS_MAX - 1)
+};
+
 enum {
 	DRM_RAS_CMD_LIST_NODES = 1,
 	DRM_RAS_CMD_GET_ERROR_COUNTER,
@@ -58,6 +83,8 @@ enum {
 	DRM_RAS_CMD_ERROR_EVENT,
 	DRM_RAS_CMD_GET_ERROR_THRESHOLD,
 	DRM_RAS_CMD_SET_ERROR_THRESHOLD,
+	DRM_RAS_CMD_GET_RETIRED_PAGES,
+	DRM_RAS_CMD_GET_RETIRED_PAGES_INFO,
 
 	__DRM_RAS_CMD_MAX,
 	DRM_RAS_CMD_MAX = (__DRM_RAS_CMD_MAX - 1)
Signature · 1 line
2.56.0
#2 lore raw

Re: [PATCH 1/2] drm/ras: Add retired-pages node type

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…

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 <[email protected]>

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.

Quoted 4 lines
drivers/gpu/drm/drm_ras.c +0 -0
index b099eb67836e7..34e5dab997440 100644

[ ... ]

Quoted 76 lines
drivers/gpu/drm/drm_ras.c +72 -0
@@ -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);
+

drivers/gpu/drm/drm_ras.c int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i · line 721

Quoted 10 lines
drivers/gpu/drm/drm_ras.c +10 -0
+		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.

[ ... ]

Quoted 16 lines
drivers/gpu/drm/drm_ras.c +5 -7
@@ -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;

drivers/gpu/drm/drm_ras.c int drm_ras_node_register(struct drm_ras_node *node) · line 807

Quoted 10 lines
drivers/gpu/drm/drm_ras.c +6 -0
+	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++) {
    ...
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

Re: [PATCH 1/2] drm/ras: Add retired-pages node type

Quoted 6 lines · On Mon, Nov 23, 2026 at 03:28:53PM +0000, [email protected] wrote:

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

I have a v4 on the pipeline that solves all of these, but to get that right, I first need to quickly land these fixes that I found during this exercise:

https://lore.kernel.org/dri-devel/[email protected]/T/#t

Please help with review of those and I'll send the v4 soon...

Quoted 190 lines

--

commit 27c9afd08cd19612592b285ef905e2efcbf77cec
Author: Aravind Iddamsetty <[email protected]>

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.

Quoted 4 lines
drivers/gpu/drm/drm_ras.c +0 -0
index b099eb67836e7..34e5dab997440 100644

[ ... ]

Quoted 76 lines
drivers/gpu/drm/drm_ras.c +72 -0
@@ -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);
+

drivers/gpu/drm/drm_ras.c int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i · line 721

Quoted 10 lines
drivers/gpu/drm/drm_ras.c +10 -0
+		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.

[ ... ]

Quoted 16 lines
drivers/gpu/drm/drm_ras.c +5 -7
@@ -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;

drivers/gpu/drm/drm_ras.c int drm_ras_node_register(struct drm_ras_node *node) · line 807

Quoted 10 lines
drivers/gpu/drm/drm_ras.c +6 -0
+	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++) {
    ...
}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#4 lore raw

PATCH v3 2/2 drm/xe: Expose retired VRAM pages via drm-ras

In reply to Rodrigo Vivi

From: Aravind Iddamsetty <[email protected]>

Retired VRAM pages are only visible through the vram_bad_pages debugfs file today. Register a drm-ras retired-pages node so userspace gets them, and the maximum number of pages that can be retired, through a stable interface.

The page lists are walked under the VRAM manager lock, and a generation counter on each manager lets drm-ras flag dumps that raced with a page being added, retired or failing its reservation.

v3 (Rodrigo+LLM):
- Use the drm-ras retired-pages node type, which replaces the nested retired-resources layout (Jakub).
- Walk the lists under mgr->lock instead of RCU, which they are not protected by, and stop reading the buddy blocks (Sashiko).
- Add a generation counter for interrupted dumps.
- Keep the vram_bad_pages debugfs file for now.
- Remove deprecated Assisted-by tag.

Cc Tejas Upadhyay <[email protected]>
Cc Himal Prasad Ghimiray <[email protected]>
Cc Riana Tauro <[email protected]>
---
 drivers/gpu/drm/xe/xe_drm_ras.c            | 56 +++++++++++++++++
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.c       | 72 +++++++++++++++++++++-
 drivers/gpu/drm/xe/xe_ttm_vram_mgr.h       |  3 +
 drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h |  5 ++
 4 files changed, 135 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/xe_drm_ras.c +56 -0
index 7554803aae11..b4ace09f9772 100644
@@ -12,6 +12,7 @@
 #include "xe_device_types.h"
 #include "xe_drm_ras.h"
 #include "xe_ras.h"
+#include "xe_ttm_vram_mgr.h"
 
 static const char * const error_components[] = DRM_XE_RAS_ERROR_COMPONENT_NAMES;
 static const char * const error_severity[] = DRM_XE_RAS_ERROR_SEVERITY_NAMES;
@@ -230,6 +231,54 @@ static int register_nodes(struct xe_device *xe)
 	return ret;
 }
 
+static int query_retired_page(struct drm_ras_node *node, u64 cursor,
+			      struct drm_ras_retired_page *page)
+{
+	return xe_ttm_vram_get_retired_page(node->priv, cursor, page);
+}
+
+static int query_retired_pages_info(struct drm_ras_node *node, u64 *max_pages)
+{
+	*max_pages = xe_ras_get_max_pages(node->priv);
+
+	return 0;
+}
+
+static int register_retired_pages_node(struct xe_device *xe)
+{
+	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
+	struct drm_ras_node *node;
+	int ret;
+
+	/* Retired VRAM pages are only tracked on platforms with page offline */
+	if (xe->info.platform != XE_CRESCENTISLAND)
+		return 0;
+
+	node = drmm_kzalloc(&xe->drm, sizeof(*node), GFP_KERNEL);
+	if (!node)
+		return -ENOMEM;
+
+	node->device_name = kasprintf(GFP_KERNEL, "%04x:%02x:%02x.%d",
+				      pci_domain_nr(pdev->bus), pdev->bus->number,
+				      PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
+	if (!node->device_name)
+		return -ENOMEM;
+
+	node->node_name = "vram-retired-pages";
+	node->type = DRM_RAS_NODE_TYPE_RETIRED_PAGES;
+	node->query_retired_page = query_retired_page;
+	node->query_retired_pages_info = query_retired_pages_info;
+	node->priv = xe;
+
+	ret = drm_ras_node_register(node);
+	if (ret) {
+		cleanup_node_param(node);
+		return ret;
+	}
+
+	return drmm_add_action_or_reset(&xe->drm, cleanup_node, node);
+}
+
 /**
  * xe_drm_ras_event() - Report drm-ras error event to userspace
  * @xe: xe device structure
@@ -294,5 +343,12 @@ int xe_drm_ras_init(struct xe_device *xe)
 		return err;
 	}
 
+	err = register_retired_pages_node(xe);
+	if (err) {
+		drm_err(&xe->drm, "Failed to register DRM RAS retired pages node (%pe)\n",
+			ERR_PTR(err));
+		return err;
+	}
+
 	return 0;
 }
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +71 -1

112 lines not on this page · raw message

drivers/gpu/drm/xe/xe_ttm_vram_mgr.h +3 -0
index d77f067d197b..91147385718c 100644
@@ -9,6 +9,7 @@
 #include "xe_ttm_vram_mgr_types.h"
 
 enum dma_data_direction;
+struct drm_ras_retired_page;
 struct xe_device;
 struct xe_tile;
 struct xe_vram_region;
@@ -33,6 +34,8 @@ void xe_ttm_vram_get_used(struct ttm_resource_manager *man,
 			  u64 *used, u64 *used_visible);
 int xe_ttm_vram_handle_addr_fault(struct xe_device *xe, u64 addr);
 int xe_ttm_vram_inject_fault(struct xe_device *xe);
+int xe_ttm_vram_get_retired_page(struct xe_device *xe, u64 cursor,
+				 struct drm_ras_retired_page *page);
 
 static inline struct xe_ttm_vram_mgr_resource *
 to_xe_ttm_vram_mgr_resource(struct ttm_resource *res)
drivers/gpu/drm/xe/xe_ttm_vram_mgr_types.h +5 -0
index 4a2cd27a5b61..6a49ee8b09ef 100644
@@ -27,6 +27,11 @@ struct xe_ttm_vram_mgr {
 	struct list_head queued_pages;
 	/** @n_queued_pages: Number of queued pages */
 	u16 n_queued_pages;
+	/**
+	 * @retired_gen: Changed whenever @offlined_pages or @queued_pages
+	 * change. Protected by @lock.
+	 */
+	u32 retired_gen;
 	/** @visible_size: Probed size of the CPU visible portion */
 	u64 visible_size;
 	/** @visible_avail: CPU visible portion still unallocated */
Signature · 1 line
2.56.0