* [PATCH v4 0/4] Extend drm_ras for qaic telemetry
@ 2026-11-17 23:34 Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 1/4] drm/drm_ras: Reference-count nodes across netlink handlers Zack McKevitt
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Zack McKevitt @ 2026-11-17 23:34 UTC (permalink / raw)
To: dri-devel, netdev, riana.tauro, aravind.iddamsetty, rodrigo.vivi,
raag.jadav, simona.vetter, airlied, kuba, ogabbay, lizhi.hou,
karol.wachowski
Cc: jeff.hugo, carl.vanderlip, troy.hanson, youssef.abdulrahman,
Zack McKevitt
This patch series extends the drm_ras netlink interface to include a new
node type for telemetry nodes. Telemetry nodes support three operations:
getting, setting (optional), and listing telemetry fields. Drivers may
specify an optional predoit function to validate get and set operations.
Telemetry get operations take the drm_ras node id and telemetry field to
be read and return the field's value and any status reported by the driver.
Telemetry set operations take the node id, telemetry field, and value,
and return only the status reported by the driver.
Before adding telemetry nodes, a new patch is introduced to add refcounts
to drm_ras nodes stored in the xarray. This protects the nodes, which are
owned by the device, from being unregistered and freed in the middle of
a netlink doit such as getting an error counter.
This extension also removes the admin requirement on the list-nodes
operation. This allows drm_ras nodes to be discovered by userspace programs
for drivers that do not necessarily require admin privileges, like qaic.
The new drm_ras telemetry interface is implemented by the qaic driver,
which exposes the telemetry fields to userspace and enforces filesystem-
esque permission checks on telemetry operations in its telemetry_pre
callback.
Claude Opus 5.5 was used to assist in the development of these patches and
to address Sashiko feedback.
Changes in v4:
- Add refcounts to track drm_ras node lifetimes.
- Address Sashiko comments:
- Fix status field population when HW returns an error.
- Add refcounts for telemetry nodes.
- Update outdated commit messages.
- Add static to private functions in qaic_telemetry.c, and remove them
from qaic_telemetry.h.
- Stop returning remaining jiffies when device status is nonzero in
telemetry_request().
- Add mhi_unprepare_from_transfer if drm_ras node registration fails
in qaic_telemetry_mhi_probe().
- Consolidate get/set dumpits into a single dump operation.
- Pin telemetry node to context in pre-doit and unpin in post-doit.
This ensures the same node is used between pre-doit and doit calls.
- Change field attribute to uint and status to sint.
- Added NL_SET_BAD_ATTR calls to telemetry netlink functions.
- Reject non-telemetry nodes in telemetry get/set/list-fields.
- Updated qaic Kconfig to depend on DRM_RAS.
Link to v3: https://lore.kernel.org/all/20261106181225.3333260-1-zachary.mckevitt@oss.qualcomm.com/#t
Changes in v3:
- Address Sashiko comments:
- Properly return status when telemetry request is successful but a
hardware error occurs.
- Validate telemetry fields against their gettable/settable fields
lists when invoking the predoit.
- Update documentation in include/drm/drm_ras.h.
- Moved calls to qaic_drm_ras_register/unregister to mhi_probe/remove
instead of pci_probe/remove.
- Added srcu read locks around calls to telemetry_request() in get
and set callbacks in qaic_telemetry.c.
- Added a tele_ch check to telemetry_request().
- Properly handle a -ERESTARTSYS return from
wait_for_completion_interrputable in telemetry_request().
- Ensure field can be truncated to a u8 in qaic's telemetry get and
set callbacks.
- Minor code cleanups (typos, header ordering, etc).
Link to v2: https://lore.kernel.org/all/20261029203000.1763447-1-zachary.mckevitt@oss.qualcomm.com/
Changes in v2:
- Address Sashiko comments:
- Initialize certain stack variables in drm_ras.c.
- Added attribute guards (GENL_REQ_ATTR_CHECK) in telemetry doits.
- Added a valid node check in drm_ras_nl_pre_telemetry.
- Fixed improper node callback in telemetry_set.
- Now registering drm_ras node after MHI initialization.
- Now removing drm_ras node before freeing MHI controller.
- Added scoped_with_init_fs guard to qaic_telemetry_pre's inode check.
- Fixed improper kfree in qaic_drm_ras_register_node.
- Changed telemetry value attribute to sint and dropped padding attribute.
- Updated documentation in drm_ras.yaml.
- Renamed telemetry read/write to get/set.
- Added dumpit for gettable and settable telemetry values.
- Made telemetry_set optional and added admin-perm for it.
- Specified ynl file regeneration in commit message for patch 2.
Link to v1: https://lore.kernel.org/all/20261009173152.2436195-1-zachary.mckevitt@oss.qualcomm.com/
Zack McKevitt (4):
drm/drm_ras: Reference-count nodes across netlink handlers
drm/drm_ras: Remove admin-perm flag from list-nodes operation
drm/drm_ras: Extend DRM RAS interface to include telemetry nodes
accel/qaic: Add callbacks for DRM RAS netlink telemetry
Documentation/netlink/specs/drm_ras.yaml | 98 +++-
drivers/accel/qaic/Kconfig | 1 +
drivers/accel/qaic/Makefile | 1 +
drivers/accel/qaic/qaic.h | 19 +
drivers/accel/qaic/qaic_drv.c | 15 +
drivers/accel/qaic/qaic_telemetry.c | 563 +++++++++++++++++++++
drivers/accel/qaic/qaic_telemetry.h | 14 +
drivers/gpu/drm/drm_ras.c | 611 ++++++++++++++++++++---
drivers/gpu/drm/drm_ras_nl.c | 45 +-
drivers/gpu/drm/drm_ras_nl.h | 10 +
include/drm/drm_ras.h | 98 ++++
include/uapi/drm/drm_ras.h | 29 +-
include/uapi/drm/qaic_accel.h | 28 ++
13 files changed, 1461 insertions(+), 71 deletions(-)
create mode 100644 drivers/accel/qaic/qaic_telemetry.c
create mode 100644 drivers/accel/qaic/qaic_telemetry.h
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 1/4] drm/drm_ras: Reference-count nodes across netlink handlers
2026-11-17 23:34 [PATCH v4 0/4] Extend drm_ras for qaic telemetry Zack McKevitt
@ 2026-11-17 23:34 ` Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 2/4] drm/drm_ras: Remove admin-perm flag from list-nodes operation Zack McKevitt
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Zack McKevitt @ 2026-11-17 23:34 UTC (permalink / raw)
To: dri-devel, netdev, riana.tauro, aravind.iddamsetty, rodrigo.vivi,
raag.jadav, simona.vetter, airlied, kuba, ogabbay, lizhi.hou,
karol.wachowski
Cc: jeff.hugo, carl.vanderlip, troy.hanson, youssef.abdulrahman,
Zack McKevitt, Sashiko
The drm_ras generic netlink family sets .parallel_ops = true, so its
handlers can run concurrently with each other and with
drm_ras_node_unregister(). Every handler looks a node up with a bare
xa_load() and then dereferences the returned pointer across GFP_KERNEL
allocations and sleeping driver callbacks, while drm_ras_node_unregister()
only calls xa_erase() and the driver frees the node immediately afterwards.
xa_load() only holds the RCU read lock for the duration of the walk, so the
node can be unregistered and freed while a handler is still using it.
Give each node a reference count. A node holds one reference for being
registered; drm_ras_node_get()/drm_ras_node_get_next() take an additional
reference under the xarray lock, which serialises them against the
xa_erase() in drm_ras_node_unregister() so the bump can never race with the
free. Handlers drop their reference with drm_ras_node_put() once they are
done touching the node. drm_ras_node_unregister() removes the node from
the xarray, drops the registration reference and waits for any in-flight
handler to drop theirs before returning, so the driver can still free the
node as soon as unregister() returns.
drm_ras_nl_error_event() is left unchanged: it is called by the driver with
its own node, whose lifetime the caller already guarantees.
Fixes: c36218dc49f5 ("drm/ras: Introduce the DRM RAS infrastructure over generic netlink")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/patchset/20261106181225.3333260-1-zachary.mckevitt@oss.qualcomm.com
Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
---
drivers/gpu/drm/drm_ras.c | 239 +++++++++++++++++++++++++++++---------
include/drm/drm_ras.h | 16 +++
2 files changed, 201 insertions(+), 54 deletions(-)
diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
index b099eb67836e..75e3403ca71b 100644
--- a/drivers/gpu/drm/drm_ras.c
+++ b/drivers/gpu/drm/drm_ras.c
@@ -3,9 +3,11 @@
* Copyright © 2026 Intel Corporation
*/
+#include <linux/completion.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
+#include <linux/refcount.h>
#include <linux/xarray.h>
#include <net/genetlink.h>
@@ -60,6 +62,21 @@
* - drm_ras_node_unregister(): Removes a previously registered
* node from the xarray.
*
+ * Node lifetime:
+ *
+ * The &drm_ras_nl_family uses &genl_family.parallel_ops, so netlink
+ * handlers may run concurrently with each other and with
+ * drm_ras_node_unregister(). Node memory is owned by the driver, which
+ * typically frees it right after drm_ras_node_unregister() returns. To make
+ * this safe, every handler looks a node up with drm_ras_node_get(), which
+ * takes a reference under the xarray lock, and drops it with
+ * drm_ras_node_put() once it is done touching the node. A node holds one
+ * reference for being registered; drm_ras_node_unregister() removes the node
+ * from the xarray (so no new lookups can find it), drops that registration
+ * reference, and then waits for any in-flight handlers to drop theirs before
+ * returning. The driver may therefore free the node as soon as
+ * drm_ras_node_unregister() returns.
+ *
* Node type:
*
* - ERROR_COUNTER:
@@ -107,6 +124,75 @@ struct drm_ras_ctx {
unsigned long restart;
};
+/**
+ * drm_ras_node_get() - Look up a RAS node by ID and take a reference
+ * @node_id: ID of the node to look up
+ *
+ * Looks the node up in the global xarray and, if found, takes a reference to
+ * it so that it cannot be freed while the caller is using it. The lookup and
+ * the reference bump happen under the xarray lock, which serialises them
+ * against the xa_erase() in drm_ras_node_unregister(): a node that is still
+ * present in the xarray is guaranteed to still hold its registration
+ * reference, so the bump can never operate on freed memory.
+ *
+ * The caller must drop the returned reference with drm_ras_node_put().
+ *
+ * Return: the referenced node, or NULL if no node with @node_id is registered.
+ */
+static struct drm_ras_node *drm_ras_node_get(u32 node_id)
+{
+ struct drm_ras_node *node;
+
+ xa_lock(&drm_ras_xa);
+ node = xa_load(&drm_ras_xa, node_id);
+ if (node)
+ refcount_inc(&node->ref);
+ xa_unlock(&drm_ras_xa);
+
+ return node;
+}
+
+/**
+ * drm_ras_node_get_next() - Take a reference on the next registered RAS node
+ * @next: in/out cursor; on entry the first ID to consider, on return the ID of
+ * the node whose reference was taken
+ *
+ * Iterator counterpart of drm_ras_node_get() used by the LIST_NODES dump.
+ * Finds the first node with an ID at or above *@next, takes a reference to it
+ * under the xarray lock and reports its ID back in *@next.
+ *
+ * The caller must drop the returned reference with drm_ras_node_put().
+ *
+ * Return: the referenced node, or NULL if no further node is registered.
+ */
+static struct drm_ras_node *drm_ras_node_get_next(unsigned long *next)
+{
+ struct drm_ras_node *node;
+
+ xa_lock(&drm_ras_xa);
+ node = xa_find(&drm_ras_xa, next, ULONG_MAX, XA_PRESENT);
+ if (node)
+ refcount_inc(&node->ref);
+ xa_unlock(&drm_ras_xa);
+
+ return node;
+}
+
+/**
+ * drm_ras_node_put() - Drop a reference taken on a RAS node
+ * @node: node to drop a reference on, may be NULL
+ *
+ * Drops a reference previously taken by drm_ras_node_get() or
+ * drm_ras_node_get_next(). When the last reference (including the registration
+ * reference dropped by drm_ras_node_unregister()) goes away, the waiter in
+ * drm_ras_node_unregister() is woken so the driver can free the node.
+ */
+static void drm_ras_node_put(struct drm_ras_node *node)
+{
+ if (node && refcount_dec_and_test(&node->ref))
+ complete(&node->unregistered);
+}
+
/**
* drm_ras_nl_list_nodes_dumpit() - Dump all registered RAS nodes
* @skb: Netlink message buffer
@@ -129,44 +215,45 @@ int drm_ras_nl_list_nodes_dumpit(struct sk_buff *skb,
struct drm_ras_ctx *ctx = (void *)cb->ctx;
struct drm_ras_node *node;
struct nlattr *hdr;
- unsigned long id;
- int ret;
+ unsigned long id = ctx->restart;
+ int ret = 0;
- xa_for_each_start(&drm_ras_xa, id, node, ctx->restart) {
+ while ((node = drm_ras_node_get_next(&id))) {
hdr = genlmsg_iput(skb, info);
if (!hdr) {
ret = -EMSGSIZE;
+ drm_ras_node_put(node);
break;
}
ret = nla_put_u32(skb, DRM_RAS_A_NODE_ATTRS_NODE_ID, node->id);
- if (ret) {
- genlmsg_cancel(skb, hdr);
- break;
- }
+ if (ret)
+ goto cancel;
ret = nla_put_string(skb, DRM_RAS_A_NODE_ATTRS_DEVICE_NAME,
node->device_name);
- if (ret) {
- genlmsg_cancel(skb, hdr);
- break;
- }
+ if (ret)
+ goto cancel;
ret = nla_put_string(skb, DRM_RAS_A_NODE_ATTRS_NODE_NAME,
node->node_name);
- if (ret) {
- genlmsg_cancel(skb, hdr);
- break;
- }
+ if (ret)
+ goto cancel;
ret = nla_put_u32(skb, DRM_RAS_A_NODE_ATTRS_NODE_TYPE,
node->type);
- if (ret) {
- genlmsg_cancel(skb, hdr);
- break;
- }
+ if (ret)
+ goto cancel;
genlmsg_end(skb, hdr);
+ drm_ras_node_put(node);
+ id++;
+ continue;
+
+cancel:
+ genlmsg_cancel(skb, hdr);
+ drm_ras_node_put(node);
+ break;
}
if (ret == -EMSGSIZE)
@@ -175,13 +262,10 @@ int drm_ras_nl_list_nodes_dumpit(struct sk_buff *skb,
return ret;
}
-static int get_node_error_counter(u32 node_id, u32 error_id,
+static int get_node_error_counter(struct drm_ras_node *node, u32 error_id,
const char **name, u32 *value)
{
- struct drm_ras_node *node;
-
- node = xa_load(&drm_ras_xa, node_id);
- if (!node || !node->query_error_counter)
+ if (!node->query_error_counter)
return -ENOENT;
if (error_id < node->error_counter_range.first ||
@@ -191,14 +275,9 @@ static int get_node_error_counter(u32 node_id, u32 error_id,
return node->query_error_counter(node, error_id, name, value);
}
-static int get_node_error_threshold(u32 node_id, u32 error_id, const char **name, u32 *threshold)
+static int get_node_error_threshold(struct drm_ras_node *node, u32 error_id,
+ const char **name, u32 *threshold)
{
- struct drm_ras_node *node;
-
- node = xa_load(&drm_ras_xa, node_id);
- if (!node)
- return -ENOENT;
-
if (!node->query_error_threshold)
return -EOPNOTSUPP;
@@ -208,14 +287,8 @@ static int get_node_error_threshold(u32 node_id, u32 error_id, const char **name
return node->query_error_threshold(node, error_id, name, threshold);
}
-static int set_node_error_threshold(u32 node_id, u32 error_id, u32 threshold)
+static int set_node_error_threshold(struct drm_ras_node *node, u32 error_id, u32 threshold)
{
- struct drm_ras_node *node;
-
- node = xa_load(&drm_ras_xa, node_id);
- if (!node)
- return -ENOENT;
-
if (!node->set_error_threshold)
return -EOPNOTSUPP;
@@ -290,15 +363,22 @@ static int msg_reply_threshold(struct sk_buff *msg, u32 error_id, const char *er
static int doit_reply_value(struct genl_info *info, u32 node_id,
u32 error_id)
{
+ struct drm_ras_node *node;
struct sk_buff *msg;
struct nlattr *hdr;
const char *error_name;
u32 value;
int ret;
+ node = drm_ras_node_get(node_id);
+ if (!node)
+ return -ENOENT;
+
msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
+ if (!msg) {
+ ret = -ENOMEM;
+ goto put_node;
+ }
hdr = genlmsg_iput(msg, info);
if (!hdr) {
@@ -306,7 +386,7 @@ static int doit_reply_value(struct genl_info *info, u32 node_id,
goto free_msg;
}
- ret = get_node_error_counter(node_id, error_id,
+ ret = get_node_error_counter(node, error_id,
&error_name, &value);
if (ret)
goto cancel_msg;
@@ -317,26 +397,37 @@ static int doit_reply_value(struct genl_info *info, u32 node_id,
genlmsg_end(msg, hdr);
+ drm_ras_node_put(node);
+
return genlmsg_reply(msg, info);
cancel_msg:
genlmsg_cancel(msg, hdr);
free_msg:
nlmsg_free(msg);
+put_node:
+ drm_ras_node_put(node);
return ret;
}
static int doit_reply_threshold(struct genl_info *info, u32 node_id, u32 error_id)
{
const char *error_name;
+ struct drm_ras_node *node;
struct sk_buff *msg;
struct nlattr *hdr;
u32 threshold;
int ret;
+ node = drm_ras_node_get(node_id);
+ if (!node)
+ return -ENOENT;
+
msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
- if (!msg)
- return -ENOMEM;
+ if (!msg) {
+ ret = -ENOMEM;
+ goto put_node;
+ }
hdr = genlmsg_iput(msg, info);
if (!hdr) {
@@ -344,7 +435,7 @@ static int doit_reply_threshold(struct genl_info *info, u32 node_id, u32 error_i
goto free_msg;
}
- ret = get_node_error_threshold(node_id, error_id, &error_name, &threshold);
+ ret = get_node_error_threshold(node, error_id, &error_name, &threshold);
if (ret)
goto cancel_msg;
@@ -354,12 +445,16 @@ static int doit_reply_threshold(struct genl_info *info, u32 node_id, u32 error_i
genlmsg_end(msg, hdr);
+ drm_ras_node_put(node);
+
return genlmsg_reply(msg, info);
cancel_msg:
genlmsg_cancel(msg, hdr);
free_msg:
nlmsg_free(msg);
+put_node:
+ drm_ras_node_put(node);
return ret;
}
@@ -372,6 +467,10 @@ static int doit_reply_threshold(struct genl_info *info, u32 node_id, u32 error_i
*
* Report an error-event to userspace using the error-report multicast group.
*
+ * The caller owns @node and must guarantee it stays alive for the duration of
+ * this call (it is the driver's own node), so no additional reference is taken
+ * here.
+ *
* Context: Process context only. Uses %GFP_KERNEL and multicasts to all
* netns, which is unbounded work; callers in interrupt handlers
* or other atomic context must defer event.
@@ -455,21 +554,21 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
struct nlattr *hdr;
const char *error_name;
u32 node_id, error_id, value;
- int ret;
+ int ret = 0;
if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID))
return -EINVAL;
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;
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,
+ ret = get_node_error_counter(node, error_id,
&error_name, &value);
/*
* For non-contiguous range, driver return -ENOENT as indication
@@ -478,7 +577,7 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
if (ret == -ENOENT)
continue;
if (ret)
- return ret;
+ break;
hdr = genlmsg_iput(skb, info);
@@ -499,6 +598,8 @@ int drm_ras_nl_get_error_counter_dumpit(struct sk_buff *skb,
if (ret == -EMSGSIZE)
ctx->restart = error_id;
+ drm_ras_node_put(node);
+
return ret;
}
@@ -544,6 +645,7 @@ int drm_ras_nl_clear_error_counter_doit(struct sk_buff *skb,
{
struct drm_ras_node *node;
u32 node_id, error_id;
+ int ret;
if (!info->attrs ||
GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID) ||
@@ -553,15 +655,23 @@ int drm_ras_nl_clear_error_counter_doit(struct sk_buff *skb,
node_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID]);
error_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]);
- node = xa_load(&drm_ras_xa, node_id);
- if (!node || !node->clear_error_counter)
+ node = drm_ras_node_get(node_id);
+ if (!node || !node->clear_error_counter) {
+ drm_ras_node_put(node);
return -ENOENT;
+ }
if (error_id < node->error_counter_range.first ||
- error_id > node->error_counter_range.last)
+ error_id > node->error_counter_range.last) {
+ drm_ras_node_put(node);
return -EINVAL;
+ }
- return node->clear_error_counter(node, error_id);
+ ret = node->clear_error_counter(node, error_id);
+
+ drm_ras_node_put(node);
+
+ return ret;
}
/**
@@ -602,7 +712,9 @@ int drm_ras_nl_get_error_threshold_doit(struct sk_buff *skb, struct genl_info *i
*/
int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *info)
{
+ struct drm_ras_node *node;
u32 node_id, error_id, threshold;
+ int ret;
if (!info->attrs ||
GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID) ||
@@ -614,7 +726,15 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i
error_id = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_ID]);
threshold = nla_get_u32(info->attrs[DRM_RAS_A_ERROR_COUNTER_ATTRS_ERROR_THRESHOLD]);
- return set_node_error_threshold(node_id, error_id, threshold);
+ node = drm_ras_node_get(node_id);
+ if (!node)
+ return -ENOENT;
+
+ ret = set_node_error_threshold(node, error_id, threshold);
+
+ drm_ras_node_put(node);
+
+ return ret;
}
/**
@@ -640,6 +760,10 @@ int drm_ras_node_register(struct drm_ras_node *node)
(!node->error_counter_range.last || !node->query_error_counter))
return -EINVAL;
+ /* One reference is held for being registered in the xarray */
+ refcount_set(&node->ref, 1);
+ init_completion(&node->unregistered);
+
return xa_alloc(&drm_ras_xa, &node->id, node, xa_limit_32b, GFP_KERNEL);
}
EXPORT_SYMBOL(drm_ras_node_register);
@@ -648,10 +772,17 @@ EXPORT_SYMBOL(drm_ras_node_register);
* drm_ras_node_unregister() - Unregister a previously registered node
* @node: Node structure to unregister
*
- * Removes the given node from the global node xarray using its ID.
+ * Removes the given node from the global node xarray using its ID and waits
+ * for any netlink handler that may still be using it to finish. Once this
+ * returns, no handler holds a reference to @node and the caller may free it.
*/
void drm_ras_node_unregister(struct drm_ras_node *node)
{
+ /* Remove from the xarray so no new lookup can find the node */
xa_erase(&drm_ras_xa, node->id);
+
+ /* Drop the registration reference and wait for in-flight handlers */
+ drm_ras_node_put(node);
+ wait_for_completion(&node->unregistered);
}
EXPORT_SYMBOL(drm_ras_node_unregister);
diff --git a/include/drm/drm_ras.h b/include/drm/drm_ras.h
index 1765a3130b09..449509c36355 100644
--- a/include/drm/drm_ras.h
+++ b/include/drm/drm_ras.h
@@ -6,6 +6,8 @@
#ifndef __DRM_RAS_H__
#define __DRM_RAS_H__
+#include <linux/completion.h>
+#include <linux/refcount.h>
#include <linux/types.h>
#include <uapi/drm/drm_ras.h>
@@ -102,6 +104,20 @@ struct drm_ras_node {
/** @priv: Driver private data */
void *priv;
+
+ /* private: Internal drm_ras bookkeeping, drivers must not touch. */
+
+ /*
+ * @ref: One reference is held while the node is registered in the
+ * xarray; netlink handlers take an additional reference across their
+ * use of the node. See drm_ras_node_get()/drm_ras_node_put().
+ */
+ refcount_t ref;
+ /*
+ * @unregistered: Completed when the last reference is dropped, so
+ * drm_ras_node_unregister() can wait for in-flight handlers.
+ */
+ struct completion unregistered;
};
struct drm_device;
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 2/4] drm/drm_ras: Remove admin-perm flag from list-nodes operation
2026-11-17 23:34 [PATCH v4 0/4] Extend drm_ras for qaic telemetry Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 1/4] drm/drm_ras: Reference-count nodes across netlink handlers Zack McKevitt
@ 2026-11-17 23:34 ` Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry Zack McKevitt
3 siblings, 0 replies; 7+ messages in thread
From: Zack McKevitt @ 2026-11-17 23:34 UTC (permalink / raw)
To: dri-devel, netdev, riana.tauro, aravind.iddamsetty, rodrigo.vivi,
raag.jadav, simona.vetter, airlied, kuba, ogabbay, lizhi.hou,
karol.wachowski
Cc: jeff.hugo, carl.vanderlip, troy.hanson, youssef.abdulrahman,
Zack McKevitt
Drivers may want to avoid requiring CAP_NET_ADMIN for subsequent
drm-ras operations. However, userspace must still be able to access
the list of RAS nodes to determine the node IDs. So, drop the
CAP_NET_ADMIN requirement for dumping RAS nodes so that drivers
with different permission requirements are still able to use the
interface.
This prepares the interface to be used for telemetry by the qaic
driver.
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
---
Documentation/netlink/specs/drm_ras.yaml | 1 -
drivers/gpu/drm/drm_ras_nl.c | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/Documentation/netlink/specs/drm_ras.yaml b/Documentation/netlink/specs/drm_ras.yaml
index 4c2ac9a1ba3f..a88fdab7a1c7 100644
--- a/Documentation/netlink/specs/drm_ras.yaml
+++ b/Documentation/netlink/specs/drm_ras.yaml
@@ -112,7 +112,6 @@ operations:
the node IDs. These IDs are required for all subsequent
operations on nodes, such as querying error counters.
attribute-set: node-attrs
- flags: [admin-perm]
dump:
reply:
attributes:
diff --git a/drivers/gpu/drm/drm_ras_nl.c b/drivers/gpu/drm/drm_ras_nl.c
index c9f5e0ceb3b5..ff0dc406c27c 100644
--- a/drivers/gpu/drm/drm_ras_nl.c
+++ b/drivers/gpu/drm/drm_ras_nl.c
@@ -46,7 +46,7 @@ static const struct genl_split_ops drm_ras_nl_ops[] = {
{
.cmd = DRM_RAS_CMD_LIST_NODES,
.dumpit = drm_ras_nl_list_nodes_dumpit,
- .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
+ .flags = GENL_CMD_CAP_DUMP,
},
{
.cmd = DRM_RAS_CMD_GET_ERROR_COUNTER,
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes
2026-11-17 23:34 [PATCH v4 0/4] Extend drm_ras for qaic telemetry Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 1/4] drm/drm_ras: Reference-count nodes across netlink handlers Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 2/4] drm/drm_ras: Remove admin-perm flag from list-nodes operation Zack McKevitt
@ 2026-11-17 23:34 ` Zack McKevitt
2026-11-18 23:35 ` sashiko-bot
2026-11-17 23:34 ` [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry Zack McKevitt
3 siblings, 1 reply; 7+ messages in thread
From: Zack McKevitt @ 2026-11-17 23:34 UTC (permalink / raw)
To: dri-devel, netdev, riana.tauro, aravind.iddamsetty, rodrigo.vivi,
raag.jadav, simona.vetter, airlied, kuba, ogabbay, lizhi.hou,
karol.wachowski
Cc: jeff.hugo, carl.vanderlip, troy.hanson, youssef.abdulrahman,
Zack McKevitt
Add a new node type, attribute set, and doit/dump functions for
performing telemetry operations using the DRM RAS interface.
Introduce telemetry_get and telemetry_set operations for reading and
writing telemetry values. The telemetry_list_fields dump operation
reports the telemetry fields that the driver defines, listing the enum
string, enum value, and read/write mode of each field.
Telemetry get and set operations have associated pre and post doit
functions. The pre-doit will retrieve the specified node from the xarray,
increase its refcount, and store a handle to the node in the request
context. This function will also check for an optional node-specified
telemetry_pre function, which can be used to enforce permission checks,
and ensure that the specified node is a telemetry node type.
This node handle is retrieved from the context in the doit, which ensures
the same node remains pinned across the pre-doit and doit functions. The
post-doit will decrease the refcount for the stashed node.
The telemetry_list_fields callback does not have associated pre and post
doit functions. Instead, it takes and drops the node reference within
each call. This ensures an unfinished dump can't block the wait in
drm_ras_node_unregister().
ynl-regen.sh was used to regenerate drm_ras_nl.c, drm_ras_nl.h, and
include/uapi/drm/drm_ras.h from the drm_ras.yaml spec.
Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
---
Documentation/netlink/specs/drm_ras.yaml | 97 +++++-
drivers/gpu/drm/drm_ras.c | 374 ++++++++++++++++++++++-
drivers/gpu/drm/drm_ras_nl.c | 43 +++
drivers/gpu/drm/drm_ras_nl.h | 10 +
include/drm/drm_ras.h | 82 +++++
include/uapi/drm/drm_ras.h | 29 +-
6 files changed, 619 insertions(+), 16 deletions(-)
diff --git a/Documentation/netlink/specs/drm_ras.yaml b/Documentation/netlink/specs/drm_ras.yaml
index a88fdab7a1c7..28a89aef1e01 100644
--- a/Documentation/netlink/specs/drm_ras.yaml
+++ b/Documentation/netlink/specs/drm_ras.yaml
@@ -16,11 +16,16 @@ definitions:
type: enum
name: node-type
value-start: 1
- entries: [error-counter]
+ entries: [error-counter, telemetry]
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. The error-counter nodes expose reliability counters
+ for a hardware/software component, and telemetry nodes expose an
+ interface for reading and writing telemetry values to a device.
+ -
+ type: flags
+ name: telemetry-field-mode
+ entries: [read, write]
+ doc: Bitmask of access modes supported by a telemetry field.
attribute-sets:
-
@@ -100,6 +105,41 @@ attribute-sets:
name: error-value
type: u32
doc: Current value of the error counter.
+ -
+ name: telemetry-attrs
+ attributes:
+ -
+ name: node-id
+ type: u32
+ doc: >-
+ Unique identifier for the node.
+ Assigned dynamically by the DRM RAS core upon registration.
+ -
+ name: field
+ type: uint
+ doc: Telemetry field to be read/written, e.g., SoC temp.
+ -
+ name: field-name
+ type: string
+ doc: Name of the telemetry field defined by the device's uAPI.
+ -
+ name: value
+ type: sint
+ doc: Value of telemetry field that was read/written.
+ -
+ name: status
+ type: sint
+ doc: >-
+ Status of the telemetry operation.
+ Populated by the device in response to the performed
+ telemetry operation. Errors may be hardware specific.
+ -
+ name: mode
+ type: u8
+ enum: telemetry-field-mode
+ doc: >-
+ Bitmask of access modes (read/write) supported by the
+ telemetry field.
operations:
list:
@@ -198,6 +238,55 @@ operations:
- node-id
- error-id
- error-threshold
+ -
+ name: telemetry-get
+ doc: Perform a read of the specified telemetry field.
+ attribute-set: telemetry-attrs
+ do:
+ pre: drm-ras-nl-pre-telemetry
+ post: drm-ras-nl-post-telemetry
+ request:
+ attributes:
+ - node-id
+ - field
+ reply:
+ attributes:
+ - value
+ - status
+ -
+ name: telemetry-set
+ doc: >-
+ Perform a write of the specified telemetry field.
+ Telemetry writes are device specific, and may be used to set
+ device limits or other capacities, for example.
+ attribute-set: telemetry-attrs
+ flags: [admin-perm]
+ do:
+ pre: drm-ras-nl-pre-telemetry
+ post: drm-ras-nl-post-telemetry
+ request:
+ attributes:
+ - node-id
+ - field
+ - value
+ reply:
+ attributes:
+ - status
+ -
+ name: telemetry-list-fields
+ doc: >-
+ Enumerate the telemetry fields exposed by a node, reporting each
+ field's value, name, and supported access modes (read/write).
+ attribute-set: telemetry-attrs
+ dump:
+ request:
+ attributes:
+ - node-id
+ reply:
+ attributes:
+ - field
+ - field-name
+ - mode
mcast-groups:
list:
diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
index 75e3403ca71b..08d3d0e43eb8 100644
--- a/drivers/gpu/drm/drm_ras.c
+++ b/drivers/gpu/drm/drm_ras.c
@@ -7,6 +7,7 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
+#include <linux/netlink.h>
#include <linux/refcount.h>
#include <linux/xarray.h>
#include <net/genetlink.h>
@@ -55,6 +56,19 @@
* 7. SET_ERROR_THRESHOLD: Set error threshold of a given counter.
* Userspace must provide Node ID, Error ID and threshold to be set.
*
+ * 8. TELEMETRY_GET: Read a telemetry value.
+ * Userspace must provide Node ID and telemetry field to be read.
+ * Returns the status of the read and the value read (if valid).
+ *
+ * 9. TELEMETRY_SET: Write a telemetry value.
+ * Userspace must provide Node ID, the telemetry field to write, and the value
+ * to be written.
+ * Returns the status of the write.
+ *
+ * 10. TELEMETRY_LIST_FIELDS: List the telemetry fields provided by the device.
+ * Each field contains the uAPI defined enum string, its numerical value,
+ * and its mode bitmask, which encodes read/write capabilities.
+ *
* Node registration:
*
* - drm_ras_node_register(): Registers a new node and assigns
@@ -80,7 +94,6 @@
* Node type:
*
* - ERROR_COUNTER:
- * + Currently, only error counters are supported.
* + The driver must implement the query_error_counter() callback to provide
* the name and the value of the error counter.
* + The driver must provide a error_counter_range.last value informing the
@@ -98,6 +111,16 @@
* that are raised by the hardware.
* + The driver is responsible for error threshold bounds checking.
*
+ * - TELEMETRY:
+ * + The driver must implement the telemetry_get() callbacks, telemetry_set()
+ * is optional.
+ * + The driver must provide a list of telemetry fields corresponding to
+ * their uAPI definitions and values, with each field's supported access
+ * modes (read/write) encoded in its mode bitmask. Fields writable via
+ * telemetry_set() must have the write mode bit set.
+ * + The driver can optionally provide a pre_doit callback, telemetry_pre(),
+ * to enforce permissions checks on telemetry operations.
+ *
* Netlink handlers:
*
* - drm_ras_nl_list_nodes_dumpit(): Implements the LIST_NODES
@@ -112,18 +135,37 @@
* operation, fetching the error threshold of a specific counter.
* - drm_ras_nl_set_error_threshold_doit(): Implements the SET_ERROR_THRESHOLD doit
* operation, setting the error threshold of a specific counter.
+ * - drm_ras_nl_pre_telemetry(): TELEMETRY_GET and TELEMETRY_SET pre_doit
+ * operation. Looks the node up, takes a reference on it and stashes it in
+ * info->ctx, and enforces the node's optional permission check.
+ * - drm_ras_nl_post_telemetry(): TELEMETRY_GET and TELEMETRY_SET post_doit
+ * operation, dropping the reference taken by drm_ras_nl_pre_telemetry().
+ * - drm_ras_nl_telemetry_get_doit(): Implements the TELEMETRY_GET doit operation,
+ * invoking the driver's telemetry_get callback and returning the results.
+ * - drm_ras_nl_telemetry_set_doit(): Implements the TELEMETRY_SET doit operation,
+ * invoking the driver's telemetry_set callback and returning the results.
+ * - drm_ras_nl_telemetry_list_fields_dumpit(): Implements the TELEMETRY_LIST_FIELDS
+ * dumpit operation, enumerating all telemetry fields and their supported
+ * access modes for a telemetry node.
*/
static DEFINE_XARRAY_ALLOC(drm_ras_xa);
/*
- * The netlink callback context carries dump state across multiple dumpit calls
+ * Per-command netlink context. Overlaid on the callback storage (cb->ctx) for
+ * dumps and on genl_info (info->ctx) for doits. @node pins the node targeted by
+ * a telemetry get/set doit between its pre_doit and post_doit. Dumps never
+ * hold a node reference across dumpit() calls.
*/
struct drm_ras_ctx {
- /* Which xarray id to restart the dump from */
+ /* Which xarray id, error id, or field id to restart the dump from */
unsigned long restart;
+ /* Node targeted by a telemetry get/set doit */
+ struct drm_ras_node *node;
};
+static_assert(sizeof(struct drm_ras_ctx) <= NETLINK_CTX_SIZE);
+
/**
* drm_ras_node_get() - Look up a RAS node by ID and take a reference
* @node_id: ID of the node to look up
@@ -737,6 +779,311 @@ int drm_ras_nl_set_error_threshold_doit(struct sk_buff *skb, struct genl_info *i
return ret;
}
+/**
+ * drm_ras_nl_pre_telemetry - Look up the telemetry node and enforce permissions
+ * @ops: Generic netlink operations
+ * @skb: Netlink message buffer
+ * @info: Generic Netlink info containing attributes of the request
+ *
+ * Looks up the telemetry node, takes a reference on it with drm_ras_node_get()
+ * and stashes it in @info->ctx so the doit handler can use it without a second
+ * lookup. The reference is dropped by drm_ras_nl_post_telemetry(), which
+ * genetlink only calls when this pre_doit succeeds; every error path here must
+ * therefore drop the reference itself. Also enforces the node's optional
+ * permission check via the telemetry_pre() callback.
+ *
+ * Return: 0 on success, or negative errno on failure.
+ */
+int drm_ras_nl_pre_telemetry(const struct genl_split_ops *ops, struct sk_buff *skb,
+ struct genl_info *info)
+{
+ struct drm_ras_ctx *ctx = (void *)info->ctx;
+ struct drm_ras_node *node;
+ u32 node_id;
+ int ret;
+
+ if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID))
+ return -EINVAL;
+
+ node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+ node = drm_ras_node_get(node_id);
+ if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+ drm_ras_node_put(node);
+ return -ENOENT;
+ }
+
+ if (node->telemetry_pre) {
+ ret = node->telemetry_pre(node);
+ if (ret) {
+ drm_ras_node_put(node);
+ return ret;
+ }
+ }
+
+ ctx->node = node;
+
+ return 0;
+}
+
+/**
+ * drm_ras_nl_post_telemetry - Release the telemetry node after a doit handler
+ * @ops: Generic netlink operations
+ * @skb: Netlink message buffer
+ * @info: Generic Netlink info containing attributes of the request
+ *
+ * Drops the reference that drm_ras_nl_pre_telemetry() took and stashed in
+ * @info->ctx. genetlink only invokes this post_doit when the matching pre_doit
+ * succeeded, so ctx->node is always the referenced node here.
+ */
+void drm_ras_nl_post_telemetry(const struct genl_split_ops *ops, struct sk_buff *skb,
+ struct genl_info *info)
+{
+ struct drm_ras_ctx *ctx = (void *)info->ctx;
+
+ drm_ras_node_put(ctx->node);
+}
+
+static bool telemetry_fields_contains(const struct drm_ras_telemetry_field *fields, u64 value,
+ u8 mode)
+{
+ unsigned long idx;
+
+ if (!fields)
+ return false;
+
+ for (idx = 0; fields[idx].name; idx++) {
+ if (fields[idx].value == value && (fields[idx].mode & mode))
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * drm_ras_nl_telemetry_list_fields_dumpit() - Dump a node's telemetry fields.
+ * @skb: Netlink message buffer
+ * @cb: Callback context for multi-part dumps
+ *
+ * Displays every telemetry field exposed by the given node, along with
+ * each field's supported access modes (read/write).
+ *
+ * The node reference is taken and dropped within each dumpit() call rather
+ * than held across the whole dump, so a userspace dump that is never
+ * completed cannot block drm_ras_node_unregister().
+ *
+ * Return: 0 on success, or negative errno on failure.
+ */
+int drm_ras_nl_telemetry_list_fields_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;
+ const struct drm_ras_telemetry_field *field;
+ struct drm_ras_node *node;
+ struct nlattr *hdr;
+ unsigned long idx;
+ u32 node_id;
+ int ret = 0;
+
+ if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID))
+ return -EINVAL;
+
+ node_id = nla_get_u32(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+
+ node = drm_ras_node_get(node_id);
+ if (!node || node->type != DRM_RAS_NODE_TYPE_TELEMETRY) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+ drm_ras_node_put(node);
+ return -ENOENT;
+ }
+
+ /*
+ * Node IDs may be reused, so the node found here is not necessarily the
+ * one seen by a previous dumpit() call of this dump. Walk the field list
+ * from the start rather than indexing at ctx->restart directly, so a
+ * shorter list can never be read past its terminator.
+ */
+ for (idx = 0; node->telemetry_fields[idx].name; idx++) {
+ if (idx < ctx->restart)
+ continue;
+
+ field = &node->telemetry_fields[idx];
+
+ hdr = genlmsg_iput(skb, info);
+ if (!hdr) {
+ ret = -EMSGSIZE;
+ break;
+ }
+
+ ret = nla_put_uint(skb, DRM_RAS_A_TELEMETRY_ATTRS_FIELD, field->value);
+ if (ret) {
+ genlmsg_cancel(skb, hdr);
+ break;
+ }
+
+ ret = nla_put_string(skb, DRM_RAS_A_TELEMETRY_ATTRS_FIELD_NAME, field->name);
+ if (ret) {
+ genlmsg_cancel(skb, hdr);
+ break;
+ }
+
+ ret = nla_put_u8(skb, DRM_RAS_A_TELEMETRY_ATTRS_MODE, field->mode);
+ if (ret) {
+ genlmsg_cancel(skb, hdr);
+ break;
+ }
+
+ genlmsg_end(skb, hdr);
+ }
+
+ if (ret == -EMSGSIZE)
+ ctx->restart = idx;
+
+ drm_ras_node_put(node);
+
+ return ret;
+}
+
+/**
+ * drm_ras_nl_telemetry_get_doit() - Query a telemetry value
+ * @skb: Netlink message buffer
+ * @info: Generic Netlink info containing attributes of the request
+ *
+ * Extracts the telemetry field from the netlink attributes and
+ * reads that value from the device.
+ *
+ * Return: 0 on success, or negative errno on failure.
+ */
+int drm_ras_nl_telemetry_get_doit(struct sk_buff *skb, struct genl_info *info)
+{
+ struct drm_ras_ctx *ctx = (void *)info->ctx;
+ struct drm_ras_node *node = ctx->node;
+ struct sk_buff *msg;
+ struct nlattr *hdr;
+ u64 field;
+ s64 status = 0;
+ s64 value = 0;
+ int ret = 0;
+
+ if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_TELEMETRY_ATTRS_FIELD))
+ return -EINVAL;
+
+ field = nla_get_uint(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_FIELD]);
+
+ if (!node->telemetry_get) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+ return -ENOENT;
+ }
+
+ if (!telemetry_fields_contains(node->telemetry_fields, field,
+ DRM_RAS_TELEMETRY_FIELD_MODE_READ)) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_FIELD]);
+ return -EINVAL;
+ }
+
+ msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+ if (!msg)
+ return -ENOMEM;
+
+ hdr = genlmsg_iput(msg, info);
+ if (!hdr) {
+ nlmsg_free(msg);
+ return -EMSGSIZE;
+ }
+
+ ret = node->telemetry_get(node, &field, &value, &status);
+ if (ret) {
+ nlmsg_free(msg);
+ return ret;
+ }
+
+ ret = nla_put_sint(msg, DRM_RAS_A_TELEMETRY_ATTRS_STATUS, status);
+ if (ret) {
+ genlmsg_cancel(msg, hdr);
+ nlmsg_free(msg);
+ return ret;
+ }
+
+ ret = nla_put_sint(msg, DRM_RAS_A_TELEMETRY_ATTRS_VALUE, value);
+ if (ret) {
+ genlmsg_cancel(msg, hdr);
+ nlmsg_free(msg);
+ return ret;
+ }
+
+ genlmsg_end(msg, hdr);
+
+ return genlmsg_reply(msg, info);
+}
+
+/**
+ * drm_ras_nl_telemetry_set_doit() - Write a telemetry value
+ * @skb: Netlink message buffer
+ * @info: Generic Netlink info containing attributes of the request
+ *
+ * Extracts the telemetry field and value to be written from the netlink
+ * attributes and writes that value to the specified field on the device.
+ *
+ * Return: 0 on success, or negative errno on failure.
+ */
+int drm_ras_nl_telemetry_set_doit(struct sk_buff *skb, struct genl_info *info)
+{
+ struct drm_ras_ctx *ctx = (void *)info->ctx;
+ struct drm_ras_node *node = ctx->node;
+ struct sk_buff *msg;
+ struct nlattr *hdr;
+ u64 field;
+ s64 status = 0;
+ s64 value = 0;
+ int ret = 0;
+
+ if (!info->attrs ||
+ GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_TELEMETRY_ATTRS_VALUE) ||
+ GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_TELEMETRY_ATTRS_FIELD))
+ return -EINVAL;
+
+ value = nla_get_sint(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_VALUE]);
+ field = nla_get_uint(info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_FIELD]);
+
+ if (!node->telemetry_set) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID]);
+ return -ENOENT;
+ }
+
+ if (!telemetry_fields_contains(node->telemetry_fields, field,
+ DRM_RAS_TELEMETRY_FIELD_MODE_WRITE)) {
+ NL_SET_BAD_ATTR(info->extack, info->attrs[DRM_RAS_A_TELEMETRY_ATTRS_FIELD]);
+ return -EINVAL;
+ }
+
+ msg = genlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+ if (!msg)
+ return -ENOMEM;
+
+ hdr = genlmsg_iput(msg, info);
+ if (!hdr) {
+ nlmsg_free(msg);
+ return -EMSGSIZE;
+ }
+
+ ret = node->telemetry_set(node, &field, &value, &status);
+ if (ret) {
+ nlmsg_free(msg);
+ return ret;
+ }
+
+ ret = nla_put_sint(msg, DRM_RAS_A_TELEMETRY_ATTRS_STATUS, status);
+ if (ret) {
+ genlmsg_cancel(msg, hdr);
+ nlmsg_free(msg);
+ return ret;
+ }
+
+ genlmsg_end(msg, hdr);
+
+ return genlmsg_reply(msg, info);
+}
+
/**
* drm_ras_node_register() - Register a new RAS node
* @node: Node structure to register
@@ -751,14 +1098,21 @@ 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))
+ /* Currently, only Error Counter and Telemetry endpoints are supported */
+ switch (node->type) {
+ case DRM_RAS_NODE_TYPE_ERROR_COUNTER:
+ /* Mandatory entries for Error Counter Node */
+ if (!node->error_counter_range.last || !node->query_error_counter)
+ return -EINVAL;
+ break;
+ case DRM_RAS_NODE_TYPE_TELEMETRY:
+ /* Must provide telemetry_get, telemetry_set is optional */
+ if (!node->telemetry_get || !node->telemetry_fields)
+ return -EINVAL;
+ break;
+ default:
return -EINVAL;
+ }
/* One reference is held for being registered in the xarray */
refcount_set(&node->ref, 1);
diff --git a/drivers/gpu/drm/drm_ras_nl.c b/drivers/gpu/drm/drm_ras_nl.c
index ff0dc406c27c..589c6445eff7 100644
--- a/drivers/gpu/drm/drm_ras_nl.c
+++ b/drivers/gpu/drm/drm_ras_nl.c
@@ -41,6 +41,24 @@ 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_TELEMETRY_GET - do */
+static const struct nla_policy drm_ras_telemetry_get_nl_policy[DRM_RAS_A_TELEMETRY_ATTRS_FIELD + 1] = {
+ [DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID] = { .type = NLA_U32, },
+ [DRM_RAS_A_TELEMETRY_ATTRS_FIELD] = { .type = NLA_UINT, },
+};
+
+/* DRM_RAS_CMD_TELEMETRY_SET - do */
+static const struct nla_policy drm_ras_telemetry_set_nl_policy[DRM_RAS_A_TELEMETRY_ATTRS_VALUE + 1] = {
+ [DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID] = { .type = NLA_U32, },
+ [DRM_RAS_A_TELEMETRY_ATTRS_FIELD] = { .type = NLA_UINT, },
+ [DRM_RAS_A_TELEMETRY_ATTRS_VALUE] = { .type = NLA_SINT, },
+};
+
+/* DRM_RAS_CMD_TELEMETRY_LIST_FIELDS - dump */
+static const struct nla_policy drm_ras_telemetry_list_fields_nl_policy[DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID + 1] = {
+ [DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID] = { .type = NLA_U32, },
+};
+
/* Ops table for drm_ras */
static const struct genl_split_ops drm_ras_nl_ops[] = {
{
@@ -83,6 +101,31 @@ 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_TELEMETRY_GET,
+ .pre_doit = drm_ras_nl_pre_telemetry,
+ .doit = drm_ras_nl_telemetry_get_doit,
+ .post_doit = drm_ras_nl_post_telemetry,
+ .policy = drm_ras_telemetry_get_nl_policy,
+ .maxattr = DRM_RAS_A_TELEMETRY_ATTRS_FIELD,
+ .flags = GENL_CMD_CAP_DO,
+ },
+ {
+ .cmd = DRM_RAS_CMD_TELEMETRY_SET,
+ .pre_doit = drm_ras_nl_pre_telemetry,
+ .doit = drm_ras_nl_telemetry_set_doit,
+ .post_doit = drm_ras_nl_post_telemetry,
+ .policy = drm_ras_telemetry_set_nl_policy,
+ .maxattr = DRM_RAS_A_TELEMETRY_ATTRS_VALUE,
+ .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
+ },
+ {
+ .cmd = DRM_RAS_CMD_TELEMETRY_LIST_FIELDS,
+ .dumpit = drm_ras_nl_telemetry_list_fields_dumpit,
+ .policy = drm_ras_telemetry_list_fields_nl_policy,
+ .maxattr = DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID,
+ .flags = GENL_CMD_CAP_DUMP,
+ },
};
static const struct genl_multicast_group drm_ras_nl_mcgrps[] = {
diff --git a/drivers/gpu/drm/drm_ras_nl.h b/drivers/gpu/drm/drm_ras_nl.h
index 9aef097ea10f..7a1cba70fd50 100644
--- a/drivers/gpu/drm/drm_ras_nl.h
+++ b/drivers/gpu/drm/drm_ras_nl.h
@@ -12,6 +12,12 @@
#include <uapi/drm/drm_ras.h>
+int drm_ras_nl_pre_telemetry(const struct genl_split_ops *ops,
+ struct sk_buff *skb, struct genl_info *info);
+void
+drm_ras_nl_post_telemetry(const struct genl_split_ops *ops,
+ struct sk_buff *skb, struct genl_info *info);
+
int drm_ras_nl_list_nodes_dumpit(struct sk_buff *skb,
struct netlink_callback *cb);
int drm_ras_nl_get_error_counter_doit(struct sk_buff *skb,
@@ -24,6 +30,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_telemetry_get_doit(struct sk_buff *skb, struct genl_info *info);
+int drm_ras_nl_telemetry_set_doit(struct sk_buff *skb, struct genl_info *info);
+int drm_ras_nl_telemetry_list_fields_dumpit(struct sk_buff *skb,
+ struct netlink_callback *cb);
enum {
DRM_RAS_NLGRP_ERROR_REPORT,
diff --git a/include/drm/drm_ras.h b/include/drm/drm_ras.h
index 449509c36355..b45b11d6a77d 100644
--- a/include/drm/drm_ras.h
+++ b/include/drm/drm_ras.h
@@ -12,6 +12,22 @@
#include <uapi/drm/drm_ras.h>
+/**
+ * struct drm_ras_telemetry_field - A descriptor of a telemetry field.
+ */
+struct drm_ras_telemetry_field {
+ /** @name: The enum or macro name defined by the device uAPI. */
+ const char *name;
+ /** @value: The numerical value of the field. */
+ u64 value;
+ /**
+ * @mode: Bitmask of supported access modes for this field, built
+ * from enum drm_ras_telemetry_field_mode (DRM_RAS_TELEMETRY_FIELD_MODE_READ,
+ * DRM_RAS_TELEMETRY_FIELD_MODE_WRITE).
+ */
+ u8 mode;
+};
+
/**
* struct drm_ras_node - A DRM RAS Node
*/
@@ -102,6 +118,72 @@ struct drm_ras_node {
*/
int (*set_error_threshold)(struct drm_ras_node *node, u32 error_id, u32 threshold);
+ /* Telemetry Related Callback and Variables */
+
+ /**
+ * @telemetry_fields:
+ *
+ * A list of telemetry fields for a device, each with its supported
+ * access modes encoded in its &drm_ras_telemetry_field.mode.
+ * The list must be terminated by a NULL .name entry.
+ */
+ const struct drm_ras_telemetry_field *telemetry_fields;
+
+ /**
+ * @telemetry_pre:
+ *
+ * This callback is used to enforce any pre_doit conditions necessary
+ * for telemetry. This is an optional callback for telemetry_node.
+ *
+ * Returns 0 on success, negative error code on failure.
+ */
+ int (*telemetry_pre)(struct drm_ras_node *ep);
+
+ /**
+ * @telemetry_get:
+ *
+ * This callback is used for a drm-ras telemetry node to read a
+ * telemetry value. This is a mandatory callback for telemetry_node.
+ *
+ * The callback will read the desired device-specific field into
+ * @value and update @status to a device-specific error code.
+ *
+ * The return value and @status report failures at two different
+ * levels. The return value indicates whether the read could be
+ * performed at all, e.g. an unsupported field or a driver/communication
+ * failure talking to the device. @status instead reports an error the
+ * device itself returned in response to an otherwise successfully
+ * performed read. @value is only meaningful when this returns 0 and
+ * @status is 0.
+ *
+ * Returns 0 if the read was performed, regardless of @status.
+ * Returns a negative error code if the read could not be performed.
+ */
+ int (*telemetry_get)(struct drm_ras_node *ep, u64 *field, s64 *value,
+ s64 *status);
+
+ /**
+ * @telemetry_set:
+ *
+ * This callback is used for a drm-ras telemetry node to write a
+ * telemetry value. This is an optional callback for telemetry_node.
+ *
+ * The callback will write @value to the desired device-specific field
+ * and update @status to a device-specific error code.
+ *
+ * The return value and @status report failures at two different
+ * levels. The return value indicates whether the write could be
+ * performed at all, e.g. an unsupported field or a driver/communication
+ * failure talking to the device. @status instead reports an error the
+ * device itself returned in response to an otherwise successfully
+ * performed write.
+ *
+ * Returns 0 if the write was performed, regardless of @status.
+ * Returns a negative error code if the write could not be performed.
+ */
+ int (*telemetry_set)(struct drm_ras_node *ep, u64 *field, s64 *value,
+ s64 *status);
+
/** @priv: Driver private data */
void *priv;
diff --git a/include/uapi/drm/drm_ras.h b/include/uapi/drm/drm_ras.h
index 2f832275ee6e..56e0588af5d5 100644
--- a/include/uapi/drm/drm_ras.h
+++ b/include/uapi/drm/drm_ras.h
@@ -11,11 +11,21 @@
#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. The error-counter nodes expose reliability counters for a
+ * hardware/software component, and telemetry nodes expose an interface for
+ * reading and writing telemetry values to a device.
*/
enum drm_ras_node_type {
DRM_RAS_NODE_TYPE_ERROR_COUNTER = 1,
+ DRM_RAS_NODE_TYPE_TELEMETRY,
+};
+
+/*
+ * Bitmask of access modes supported by a telemetry field.
+ */
+enum drm_ras_telemetry_field_mode {
+ DRM_RAS_TELEMETRY_FIELD_MODE_READ = 1,
+ DRM_RAS_TELEMETRY_FIELD_MODE_WRITE = 2,
};
enum {
@@ -51,6 +61,18 @@ enum {
DRM_RAS_A_ERROR_EVENT_ATTRS_MAX = (__DRM_RAS_A_ERROR_EVENT_ATTRS_MAX - 1)
};
+enum {
+ DRM_RAS_A_TELEMETRY_ATTRS_NODE_ID = 1,
+ DRM_RAS_A_TELEMETRY_ATTRS_FIELD,
+ DRM_RAS_A_TELEMETRY_ATTRS_FIELD_NAME,
+ DRM_RAS_A_TELEMETRY_ATTRS_VALUE,
+ DRM_RAS_A_TELEMETRY_ATTRS_STATUS,
+ DRM_RAS_A_TELEMETRY_ATTRS_MODE,
+
+ __DRM_RAS_A_TELEMETRY_ATTRS_MAX,
+ DRM_RAS_A_TELEMETRY_ATTRS_MAX = (__DRM_RAS_A_TELEMETRY_ATTRS_MAX - 1)
+};
+
enum {
DRM_RAS_CMD_LIST_NODES = 1,
DRM_RAS_CMD_GET_ERROR_COUNTER,
@@ -58,6 +80,9 @@ enum {
DRM_RAS_CMD_ERROR_EVENT,
DRM_RAS_CMD_GET_ERROR_THRESHOLD,
DRM_RAS_CMD_SET_ERROR_THRESHOLD,
+ DRM_RAS_CMD_TELEMETRY_GET,
+ DRM_RAS_CMD_TELEMETRY_SET,
+ DRM_RAS_CMD_TELEMETRY_LIST_FIELDS,
__DRM_RAS_CMD_MAX,
DRM_RAS_CMD_MAX = (__DRM_RAS_CMD_MAX - 1)
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry
2026-11-17 23:34 [PATCH v4 0/4] Extend drm_ras for qaic telemetry Zack McKevitt
` (2 preceding siblings ...)
2026-11-17 23:34 ` [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes Zack McKevitt
@ 2026-11-17 23:34 ` Zack McKevitt
2026-11-18 23:35 ` sashiko-bot
3 siblings, 1 reply; 7+ messages in thread
From: Zack McKevitt @ 2026-11-17 23:34 UTC (permalink / raw)
To: dri-devel, netdev, riana.tauro, aravind.iddamsetty, rodrigo.vivi,
raag.jadav, simona.vetter, airlied, kuba, ogabbay, lizhi.hou,
karol.wachowski
Cc: jeff.hugo, carl.vanderlip, troy.hanson, youssef.abdulrahman,
Zack McKevitt
Use the DRM RAS netlink infrastructure to perform device telemetry.
During MHI probe, create a DRM RAS node with DRM_RAS_NODE_TYPE_TELEMETRY
type and add callbacks to telemetry_request for read and write operations.
Co-developed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Signed-off-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Reviewed-by: Jeff Hugo <jeff.hugo@oss.qualcomm.com>
Signed-off-by: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
---
drivers/accel/qaic/Kconfig | 1 +
drivers/accel/qaic/Makefile | 1 +
drivers/accel/qaic/qaic.h | 19 +
drivers/accel/qaic/qaic_drv.c | 15 +
drivers/accel/qaic/qaic_telemetry.c | 563 ++++++++++++++++++++++++++++
drivers/accel/qaic/qaic_telemetry.h | 14 +
include/uapi/drm/qaic_accel.h | 28 ++
7 files changed, 641 insertions(+)
create mode 100644 drivers/accel/qaic/qaic_telemetry.c
create mode 100644 drivers/accel/qaic/qaic_telemetry.h
diff --git a/drivers/accel/qaic/Kconfig b/drivers/accel/qaic/Kconfig
index 116e42d152ca..6a07db0c402e 100644
--- a/drivers/accel/qaic/Kconfig
+++ b/drivers/accel/qaic/Kconfig
@@ -8,6 +8,7 @@ config DRM_ACCEL_QAIC
depends on DRM_ACCEL
depends on PCI && HAS_IOMEM
depends on MHI_BUS
+ depends on DRM_RAS
select CRC32
select WANT_DEV_COREDUMP
help
diff --git a/drivers/accel/qaic/Makefile b/drivers/accel/qaic/Makefile
index 71f727b74da3..b2bbe9b3e077 100644
--- a/drivers/accel/qaic/Makefile
+++ b/drivers/accel/qaic/Makefile
@@ -13,6 +13,7 @@ qaic-y := \
qaic_ras.o \
qaic_ssr.o \
qaic_sysfs.o \
+ qaic_telemetry.o \
qaic_timesync.o \
sahara.o
diff --git a/drivers/accel/qaic/qaic.h b/drivers/accel/qaic/qaic.h
index 889fa51da7da..fa19c758f504 100644
--- a/drivers/accel/qaic/qaic.h
+++ b/drivers/accel/qaic/qaic.h
@@ -17,6 +17,7 @@
#include <linux/workqueue.h>
#include <drm/drm_device.h>
#include <drm/drm_gem.h>
+#include <drm/drm_ras.h>
#define QAIC_DBC_BASE SZ_128K
#define QAIC_DBC_SIZE SZ_4K
@@ -204,6 +205,24 @@ struct qaic_device {
void *ssr_mhi_buf;
/* DBC which is under SSR. Sentinel U32_MAX would mean that no SSR in progress */
u32 ssr_dbc;
+ /* MHI telemetry channel device */
+ struct mhi_device *tele_ch;
+ /* Head in list of requests queued in MHI telemetry device */
+ struct list_head tele_xfer_list;
+ /* Req. ID of request that will be queued next in MHI telemetry device */
+ u32 tele_next_seq_num;
+ /* Synchronizes MHI telemetry device transactions and its xfer list */
+ struct mutex tele_mutex;
+ /*
+ * TRUE: A tx MHI transaction has failed and a rx buffer is still queued
+ * in telemetry device. Such a buffer is considered lost rx buffer
+ * FALSE: No rx buffer is lost in telemetry device
+ */
+ bool tele_lost_buf;
+ /* Work queue for tasks related to MHI telemetry device */
+ struct workqueue_struct *tele_wq;
+ /* Netlink telemetry node */
+ struct drm_ras_node *ras_node;
/* Array of DBC struct of this device */
struct dma_bridge_chan dbc[] __counted_by(num_dbc);
};
diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c
index 90c0d31e414a..6d185151a0a6 100644
--- a/drivers/accel/qaic/qaic_drv.c
+++ b/drivers/accel/qaic/qaic_drv.c
@@ -32,6 +32,7 @@
#include "qaic_debugfs.h"
#include "qaic_ras.h"
#include "qaic_ssr.h"
+#include "qaic_telemetry.h"
#include "qaic_timesync.h"
#include "sahara.h"
@@ -389,6 +390,7 @@ static void qaic_notify_reset(struct qaic_device *qdev)
qdev->dev_state = QAIC_OFFLINE;
/* wake up any waiters to avoid waiting for timeouts at sync */
wake_all_cntl(qdev);
+ wake_all_telemetry(qdev);
for (i = 0; i < qdev->num_dbc; ++i)
wakeup_dbc(qdev, i);
synchronize_srcu(&qdev->dev_lock);
@@ -439,6 +441,9 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev,
if (ret)
return NULL;
ret = drmm_mutex_init(drm, &qdev->bootlog_mutex);
+ if (ret)
+ return NULL;
+ ret = drmm_mutex_init(drm, &qdev->tele_mutex);
if (ret)
return NULL;
@@ -451,6 +456,9 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev,
qdev->ssr_wq = qaicm_wq_init(drm, "qaic_ssr");
if (IS_ERR(qdev->ssr_wq))
return NULL;
+ qdev->tele_wq = qaicm_wq_init(drm, "qaic_tele");
+ if (IS_ERR(qdev->tele_wq))
+ return NULL;
ret = qaicm_srcu_init(drm, &qdev->dev_lock);
if (ret)
@@ -466,6 +474,7 @@ static struct qaic_device *create_qdev(struct pci_dev *pdev,
INIT_LIST_HEAD(&qdev->cntl_xfer_list);
INIT_LIST_HEAD(&qdev->bootlog);
+ INIT_LIST_HEAD(&qdev->tele_xfer_list);
INIT_LIST_HEAD(&qddev->users);
for (i = 0; i < qdev->num_dbc; ++i) {
@@ -854,12 +863,17 @@ static int __init qaic_init(void)
ret = qaic_ras_register();
if (ret)
pr_debug("qaic: qaic_ras_register failed %d\n", ret);
+
ret = qaic_ssr_register();
if (ret) {
pr_debug("qaic: qaic_ssr_register failed %d\n", ret);
goto free_bootlog;
}
+ ret = qaic_telemetry_register();
+ if (ret)
+ pr_debug("qaic: qaic_telemetry_register failed %d\n", ret);
+
return 0;
free_bootlog:
@@ -889,6 +903,7 @@ static void __exit qaic_exit(void)
* reinitializing the link_up state after the cleanup is done.
*/
link_up = true;
+ qaic_telemetry_unregister();
qaic_ssr_unregister();
qaic_ras_unregister();
qaic_bootlog_unregister();
diff --git a/drivers/accel/qaic/qaic_telemetry.c b/drivers/accel/qaic/qaic_telemetry.c
new file mode 100644
index 000000000000..bcf9842f4ec9
--- /dev/null
+++ b/drivers/accel/qaic/qaic_telemetry.c
@@ -0,0 +1,563 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/* Copyright (c) 2020-2021, The Linux Foundation. All rights reserved. */
+/* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */
+
+#include <asm/byteorder.h>
+#include <drm/drm_file.h>
+#include <drm/drm_ras.h>
+#include <linux/completion.h>
+#include <linux/fs.h>
+#include <linux/fs_struct.h>
+#include <linux/kernel.h>
+#include <linux/kref.h>
+#include <linux/limits.h>
+#include <linux/list.h>
+#include <linux/mhi.h>
+#include <linux/mutex.h>
+#include <linux/namei.h>
+#include <linux/path.h>
+#include <linux/sprintf.h>
+#include <linux/srcu.h>
+#include <linux/types.h>
+#include <linux/workqueue.h>
+#include <uapi/drm/qaic_accel.h>
+
+#include "qaic.h"
+#include "qaic_telemetry.h"
+
+#define MAGIC 0x55AA
+#define VERSION 0x1
+
+/*
+ * Telemetry fields defined by the uAPI.
+ * This table will be used by drm_ras's dumpit to display
+ * each field to userspace.
+ */
+#define QAIC_FIELD_RO(_name) \
+ {#_name, _name, DRM_RAS_TELEMETRY_FIELD_MODE_READ}
+#define QAIC_FIELD_RW(_name) \
+ {#_name, _name, DRM_RAS_TELEMETRY_FIELD_MODE_READ | DRM_RAS_TELEMETRY_FIELD_MODE_WRITE}
+
+static const struct drm_ras_telemetry_field qaic_telemetry_fields[] = {
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_SOC_MAX_TEMP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_BOARD_TEMP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_BOARD_MAX_TEMP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_DDR_TEMP),
+ QAIC_FIELD_RW(QAIC_DEVINFO_THERMAL_WARNING_TEMP),
+ QAIC_FIELD_RW(QAIC_DEVINFO_THERMAL_SHUTDOWN_TEMP),
+ QAIC_FIELD_RW(QAIC_DEVINFO_BOARD_TDP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_BOARD_POWER),
+ QAIC_FIELD_RW(QAIC_DEVINFO_POWER_STATE),
+ QAIC_FIELD_RO(QAIC_DEVINFO_POWER_MAX),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THROTTLE_PERCENT),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THROTTLE_TIME),
+ QAIC_FIELD_RO(QAIC_DEVINFO_UPTIME),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_SOC_FLOOR_TEMP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_SOC_CEILING_TEMP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_VOLTAGE_CX),
+ QAIC_FIELD_RO(QAIC_DEVINFO_VOLTAGE_MX),
+ QAIC_FIELD_RO(QAIC_DEVINFO_VOLTAGE_NSP_CX),
+ QAIC_FIELD_RO(QAIC_DEVINFO_VOLTAGE_NSP_MX),
+ QAIC_FIELD_RW(QAIC_DEVINFO_CFG_TOPS),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_PMIC_TEMP_A),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_PMIC_TEMP_C),
+ QAIC_FIELD_RO(QAIC_DEVINFO_THERMAL_PMIC_TEMP_E),
+ QAIC_FIELD_RW(QAIC_DEVINFO_POWER_ACTION),
+ QAIC_FIELD_RW(QAIC_DEVINFO_SOC_TDP),
+ QAIC_FIELD_RO(QAIC_DEVINFO_SOC_POWER),
+ {},
+};
+
+#undef QAIC_FIELD_RO
+#undef QAIC_FIELD_RW
+
+enum fw_errno {
+ ERR_READ_ONLY = -1,
+ ERR_NOT_SUPPORTED = -2,
+ ERR_WHILE_PROCESSING = -3,
+ ERR_INVALID_VALUE = -4,
+ ERR_INVALID_HEADER = -5,
+};
+
+enum cmd_type {
+ TYPE_READ, /* read value from device */
+ TYPE_WRITE, /* write value to device */
+};
+
+enum msg_type {
+ MSG_PUSH, /* async push from device */
+ MSG_REQ, /* sync request to device */
+ MSG_RESP, /* sync response from device */
+};
+
+struct telemetry_data {
+ u8 cmd;
+ u8 cmd_type;
+ u8 status;
+ __le64 val; /* signed */
+} __packed;
+
+struct telemetry_header {
+ __le16 magic;
+ __le16 ver;
+ __le32 seq_num;
+ u8 type;
+ u8 id;
+ __le16 len;
+} __packed;
+
+struct telemetry_msg { /* little endian encoded */
+ struct telemetry_header hdr;
+ struct telemetry_data data;
+} __packed;
+
+struct wrapper_msg {
+ struct kref ref_count;
+ struct telemetry_msg msg;
+};
+
+struct xfer_queue_elem {
+ /*
+ * Node in list of ongoing transfer request on telemetry channel.
+ * Maintained by root device struct
+ */
+ struct list_head list;
+ /* Sequence number of this transfer request */
+ u32 seq_num;
+ /* This is used to wait on until completion of transfer request */
+ struct completion xfer_done;
+ /* Received data from device */
+ void *buf;
+};
+
+struct resp_work {
+ /* Work struct to schedule work coming on QAIC_TELEMETRY channel */
+ struct work_struct work;
+ /* Root struct of device, used to access device resources */
+ struct qaic_device *qdev;
+ /* Buffer used by MHI for transfer requests */
+ void *buf;
+};
+
+static void free_wrapper(struct kref *ref)
+{
+ struct wrapper_msg *wrapper = container_of(ref, struct wrapper_msg, ref_count);
+
+ kfree(wrapper);
+}
+
+static int telemetry_request(struct qaic_device *qdev, u8 cmd, u8 cmd_type, s64 *val, s64 *status)
+{
+ struct wrapper_msg *wrapper;
+ struct xfer_queue_elem elem;
+ struct telemetry_msg *resp;
+ struct telemetry_msg *req;
+ long ret = 0;
+
+ wrapper = kzalloc_obj(*wrapper);
+ if (!wrapper)
+ return -ENOMEM;
+
+ kref_init(&wrapper->ref_count);
+ req = &wrapper->msg;
+
+ ret = mutex_lock_interruptible(&qdev->tele_mutex);
+ if (ret)
+ goto free_req;
+
+ if (!qdev->tele_ch) {
+ mutex_unlock(&qdev->tele_mutex);
+ ret = -ENODEV;
+ goto free_req;
+ }
+
+ req->hdr.magic = cpu_to_le16(MAGIC);
+ req->hdr.ver = cpu_to_le16(VERSION);
+ req->hdr.seq_num = cpu_to_le32(qdev->tele_next_seq_num++);
+ req->hdr.type = MSG_REQ;
+ req->hdr.id = 0;
+ req->hdr.len = cpu_to_le16(sizeof(req->data));
+
+ req->data.cmd = cmd;
+ req->data.cmd_type = cmd_type;
+ req->data.status = 0;
+ if (cmd_type == TYPE_READ)
+ req->data.val = cpu_to_le64(0);
+ else
+ req->data.val = cpu_to_le64(*val);
+
+ elem.seq_num = qdev->tele_next_seq_num - 1;
+ elem.buf = NULL;
+ init_completion(&elem.xfer_done);
+ if (likely(!qdev->tele_lost_buf)) {
+ resp = kzalloc_obj(*resp);
+ if (!resp) {
+ mutex_unlock(&qdev->tele_mutex);
+ ret = -ENOMEM;
+ goto free_req;
+ }
+
+ ret = mhi_queue_buf(qdev->tele_ch, DMA_FROM_DEVICE, resp, sizeof(*resp), MHI_EOT);
+ if (ret) {
+ mutex_unlock(&qdev->tele_mutex);
+ goto free_resp;
+ }
+ } else {
+ /*
+ * we lost a buffer because we queued a recv buf, but then
+ * queuing the corresponding tx buf failed. To try to avoid
+ * a memory leak, lets reclaim it and use it for this
+ * transaction.
+ */
+ qdev->tele_lost_buf = false;
+ }
+
+ kref_get(&wrapper->ref_count);
+ ret = mhi_queue_buf(qdev->tele_ch, DMA_TO_DEVICE, req, sizeof(*req), MHI_EOT);
+ if (ret) {
+ qdev->tele_lost_buf = true;
+ kref_put(&wrapper->ref_count, free_wrapper);
+ mutex_unlock(&qdev->tele_mutex);
+ goto free_req;
+ }
+
+ list_add_tail(&elem.list, &qdev->tele_xfer_list);
+ mutex_unlock(&qdev->tele_mutex);
+
+ ret = wait_for_completion_interruptible_timeout(&elem.xfer_done, HZ);
+ /*
+ * not using _interruptable because we have to cleanup or we'll
+ * likely cause memory corruption
+ */
+ mutex_lock(&qdev->tele_mutex);
+ if (!list_empty(&elem.list))
+ list_del(&elem.list);
+ /* resp_worker() processed the response but the wait was interrupted */
+ else if (ret == -ERESTARTSYS)
+ ret = 0;
+ if (!ret && !elem.buf)
+ ret = -ETIMEDOUT;
+ else if (ret > 0 && !elem.buf)
+ ret = -EIO;
+ mutex_unlock(&qdev->tele_mutex);
+
+ resp = elem.buf;
+
+ /*
+ * telemetry_request() is called from Generic Netlink .doit callbacks
+ * rather than a syscall boundary, so -ERESTARTSYS is never translated
+ * to -EINTR before it would otherwise be serialized as-is into the
+ * netlink error ack.
+ */
+ if (ret == -ERESTARTSYS)
+ ret = -EINTR;
+
+ if (ret < 0)
+ goto free_resp;
+
+ if (le16_to_cpu(resp->hdr.magic) != MAGIC || le16_to_cpu(resp->hdr.ver) != VERSION ||
+ resp->hdr.type != MSG_RESP || resp->hdr.id != 0 ||
+ le16_to_cpu(resp->hdr.len) != sizeof(resp->data) || resp->data.cmd != cmd ||
+ resp->data.cmd_type != cmd_type) {
+ ret = -EINVAL;
+ goto free_resp;
+ }
+
+ if (resp->data.status) {
+ switch ((s8)resp->data.status) {
+ case ERR_READ_ONLY:
+ *status = -EROFS;
+ break;
+ case ERR_NOT_SUPPORTED:
+ *status = -EOPNOTSUPP;
+ break;
+ case ERR_WHILE_PROCESSING:
+ *status = -EREMOTEIO;
+ break;
+ case ERR_INVALID_VALUE:
+ *status = -EINVAL;
+ break;
+ case ERR_INVALID_HEADER:
+ *status = -EBADR;
+ break;
+ default:
+ *status = -EPROTO;
+ }
+ ret = 0;
+ goto free_resp;
+ }
+
+ if (cmd_type == TYPE_READ)
+ *val = le64_to_cpu(resp->data.val);
+
+ ret = 0;
+
+free_resp:
+ kfree(resp);
+free_req:
+ kref_put(&wrapper->ref_count, free_wrapper);
+
+ return ret;
+}
+
+static void resp_worker(struct work_struct *work)
+{
+ struct resp_work *resp = container_of(work, struct resp_work, work);
+ struct qaic_device *qdev = resp->qdev;
+ struct telemetry_msg *msg = resp->buf;
+ struct xfer_queue_elem *elem;
+ struct xfer_queue_elem *i;
+ bool found = false;
+
+ if (le16_to_cpu(msg->hdr.magic) != MAGIC) {
+ kfree(msg);
+ kfree(resp);
+ return;
+ }
+
+ mutex_lock(&qdev->tele_mutex);
+ list_for_each_entry_safe(elem, i, &qdev->tele_xfer_list, list) {
+ if (elem->seq_num == le32_to_cpu(msg->hdr.seq_num)) {
+ found = true;
+ list_del_init(&elem->list);
+ elem->buf = msg;
+ complete_all(&elem->xfer_done);
+ break;
+ }
+ }
+ mutex_unlock(&qdev->tele_mutex);
+
+ if (!found)
+ /* request must have timed out, drop packet */
+ kfree(msg);
+
+ kfree(resp);
+}
+
+static void qaic_telemetry_mhi_ul_xfer_cb(struct mhi_device *mhi_dev,
+ struct mhi_result *mhi_result)
+{
+ struct telemetry_msg *msg = mhi_result->buf_addr;
+ struct wrapper_msg *wrapper;
+
+ wrapper = container_of(msg, struct wrapper_msg, msg);
+ kref_put(&wrapper->ref_count, free_wrapper);
+}
+
+static void qaic_telemetry_mhi_dl_xfer_cb(struct mhi_device *mhi_dev,
+ struct mhi_result *mhi_result)
+{
+ struct qaic_device *qdev = dev_get_drvdata(&mhi_dev->dev);
+ struct telemetry_msg *msg = mhi_result->buf_addr;
+ struct resp_work *resp;
+
+ if (mhi_result->transaction_status) {
+ kfree(msg);
+ return;
+ }
+
+ resp = kmalloc(sizeof(*resp), GFP_ATOMIC);
+ if (!resp) {
+ pci_err(qdev->pdev, "dl_xfer_cb alloc fail, dropping message\n");
+ kfree(msg);
+ return;
+ }
+
+ INIT_WORK(&resp->work, resp_worker);
+ resp->qdev = qdev;
+ resp->buf = msg;
+ queue_work(qdev->tele_wq, &resp->work);
+}
+
+static int qaic_telemetry_pre(struct drm_ras_node *ep)
+{
+ struct qaic_device *qdev = ep->priv;
+ struct inode *dev_inode;
+ struct path path;
+ char devpath[24];
+ int ret;
+
+ snprintf(devpath, sizeof(devpath), "/dev/accel/%s", to_accel_kdev(qdev->qddev)->kobj.name);
+ scoped_with_init_fs()
+ ret = kern_path(devpath, LOOKUP_FOLLOW, &path);
+ if (ret)
+ return -EINVAL;
+
+ dev_inode = d_inode(path.dentry);
+ ret = inode_permission(&nop_mnt_idmap, dev_inode, MAY_READ | MAY_WRITE);
+ path_put(&path);
+
+ return ret;
+}
+
+static int qaic_telemetry_get(struct drm_ras_node *ep, u64 *field, s64 *value, s64 *status)
+{
+ struct qaic_device *qdev = ep->priv;
+ int rcu_id;
+ int ret;
+
+ /* telemetry_request expects the field to be a u8 */
+ if (*field > U8_MAX)
+ return -EINVAL;
+
+ rcu_id = srcu_read_lock(&qdev->dev_lock);
+ if (qdev->dev_state != QAIC_ONLINE) {
+ srcu_read_unlock(&qdev->dev_lock, rcu_id);
+ return -ENODEV;
+ }
+
+ ret = telemetry_request(qdev, (u8)*field, TYPE_READ, value, status);
+ srcu_read_unlock(&qdev->dev_lock, rcu_id);
+
+ return ret;
+}
+
+static int qaic_telemetry_set(struct drm_ras_node *ep, u64 *field, s64 *value, s64 *status)
+{
+ struct qaic_device *qdev = ep->priv;
+ int rcu_id;
+ int ret;
+
+ /* telemetry_request expects the field to be a u8 */
+ if (*field > U8_MAX)
+ return -EINVAL;
+
+ rcu_id = srcu_read_lock(&qdev->dev_lock);
+ if (qdev->dev_state != QAIC_ONLINE) {
+ srcu_read_unlock(&qdev->dev_lock, rcu_id);
+ return -ENODEV;
+ }
+
+ ret = telemetry_request(qdev, (u8)*field, TYPE_WRITE, value, status);
+ srcu_read_unlock(&qdev->dev_lock, rcu_id);
+
+ return ret;
+}
+
+static int qaic_drm_ras_register_node(struct qaic_device *qdev)
+{
+ struct drm_ras_node *node;
+ struct pci_dev *pdev = qdev->pdev;
+ const char *device_name, *node_name;
+ int ret;
+
+ node = kzalloc_obj(struct drm_ras_node);
+ if (!node)
+ return -ENOMEM;
+
+ 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 (!device_name) {
+ kfree(node);
+ return -ENOMEM;
+ }
+
+ node_name = kasprintf(GFP_KERNEL, "qaic_telemetry");
+ if (!node_name) {
+ kfree(device_name);
+ kfree(node);
+ return -ENOMEM;
+ }
+
+ node->device_name = device_name;
+ node->node_name = node_name;
+ node->type = DRM_RAS_NODE_TYPE_TELEMETRY;
+ node->priv = qdev;
+ node->telemetry_get = qaic_telemetry_get;
+ node->telemetry_set = qaic_telemetry_set;
+ node->telemetry_pre = qaic_telemetry_pre;
+ node->telemetry_fields = qaic_telemetry_fields;
+
+ ret = drm_ras_node_register(node);
+ if (ret) {
+ kfree(device_name);
+ kfree(node_name);
+ kfree(node);
+ return ret;
+ }
+
+ qdev->ras_node = node;
+ return 0;
+}
+
+static void qaic_drm_ras_unregister_node(struct qaic_device *qdev)
+{
+ drm_ras_node_unregister(qdev->ras_node);
+ kfree(qdev->ras_node->node_name);
+ kfree(qdev->ras_node->device_name);
+ kfree(qdev->ras_node);
+}
+
+static int qaic_telemetry_mhi_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id)
+{
+ struct qaic_device *qdev = pci_get_drvdata(to_pci_dev(mhi_dev->mhi_cntrl->cntrl_dev));
+ int ret;
+
+ ret = mhi_prepare_for_transfer(mhi_dev);
+ if (ret)
+ return ret;
+
+ dev_set_drvdata(&mhi_dev->dev, qdev);
+ qdev->tele_ch = mhi_dev;
+ qdev->tele_lost_buf = false;
+
+ ret = qaic_drm_ras_register_node(qdev);
+ if (ret) {
+ mhi_unprepare_from_transfer(mhi_dev);
+ qdev->tele_ch = NULL;
+ return ret;
+ }
+
+ return 0;
+}
+
+static void qaic_telemetry_mhi_remove(struct mhi_device *mhi_dev)
+{
+ struct qaic_device *qdev = dev_get_drvdata(&mhi_dev->dev);
+
+ qaic_drm_ras_unregister_node(qdev);
+ mhi_unprepare_from_transfer(qdev->tele_ch);
+ qdev->tele_ch = NULL;
+}
+
+static const struct mhi_device_id qaic_telemetry_mhi_match_table[] = {
+ { .chan = "QAIC_TELEMETRY", },
+ {},
+};
+
+static struct mhi_driver qaic_telemetry_mhi_driver = {
+ .id_table = qaic_telemetry_mhi_match_table,
+ .remove = qaic_telemetry_mhi_remove,
+ .probe = qaic_telemetry_mhi_probe,
+ .ul_xfer_cb = qaic_telemetry_mhi_ul_xfer_cb,
+ .dl_xfer_cb = qaic_telemetry_mhi_dl_xfer_cb,
+ .driver = {
+ .name = "qaic_telemetry",
+ },
+};
+
+int qaic_telemetry_register(void)
+{
+ return mhi_driver_register(&qaic_telemetry_mhi_driver);
+}
+
+void qaic_telemetry_unregister(void)
+{
+ mhi_driver_unregister(&qaic_telemetry_mhi_driver);
+}
+
+void wake_all_telemetry(struct qaic_device *qdev)
+{
+ struct xfer_queue_elem *elem;
+ struct xfer_queue_elem *i;
+
+ mutex_lock(&qdev->tele_mutex);
+ list_for_each_entry_safe(elem, i, &qdev->tele_xfer_list, list) {
+ list_del_init(&elem->list);
+ complete_all(&elem->xfer_done);
+ }
+ qdev->tele_lost_buf = false;
+ mutex_unlock(&qdev->tele_mutex);
+}
diff --git a/drivers/accel/qaic/qaic_telemetry.h b/drivers/accel/qaic/qaic_telemetry.h
new file mode 100644
index 000000000000..07803e44ab66
--- /dev/null
+++ b/drivers/accel/qaic/qaic_telemetry.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+/* Copyright (c) 2020, The Linux Foundation. All rights reserved. */
+
+#ifndef __QAIC_TELEMETRY_H__
+#define __QAIC_TELEMETRY_H__
+
+#include "qaic.h"
+
+int qaic_telemetry_register(void);
+void qaic_telemetry_unregister(void);
+void wake_all_telemetry(struct qaic_device *qdev);
+
+#endif /* __QAIC_TELEMETRY_H__ */
diff --git a/include/uapi/drm/qaic_accel.h b/include/uapi/drm/qaic_accel.h
index c92d0309d583..5aac05101426 100644
--- a/include/uapi/drm/qaic_accel.h
+++ b/include/uapi/drm/qaic_accel.h
@@ -51,6 +51,34 @@ extern "C" {
#define QAIC_TRANS_VALIDATE_PARTITION_FROM_DEV 19
#define QAIC_TRANS_VALIDATE_PARTITION_TO_DEV 20
+/* Telemetry fields */
+#define QAIC_DEVINFO_THERMAL_SOC_MAX_TEMP 1
+#define QAIC_DEVINFO_THERMAL_BOARD_TEMP 2
+#define QAIC_DEVINFO_THERMAL_BOARD_MAX_TEMP 3
+#define QAIC_DEVINFO_THERMAL_DDR_TEMP 4
+#define QAIC_DEVINFO_THERMAL_WARNING_TEMP 5
+#define QAIC_DEVINFO_THERMAL_SHUTDOWN_TEMP 6
+#define QAIC_DEVINFO_BOARD_TDP 7
+#define QAIC_DEVINFO_BOARD_POWER 8
+#define QAIC_DEVINFO_POWER_STATE 9
+#define QAIC_DEVINFO_POWER_MAX 10
+#define QAIC_DEVINFO_THROTTLE_PERCENT 11
+#define QAIC_DEVINFO_THROTTLE_TIME 12
+#define QAIC_DEVINFO_UPTIME 13
+#define QAIC_DEVINFO_THERMAL_SOC_FLOOR_TEMP 14
+#define QAIC_DEVINFO_THERMAL_SOC_CEILING_TEMP 15
+#define QAIC_DEVINFO_VOLTAGE_CX 16
+#define QAIC_DEVINFO_VOLTAGE_MX 17
+#define QAIC_DEVINFO_VOLTAGE_NSP_CX 18
+#define QAIC_DEVINFO_VOLTAGE_NSP_MX 19
+#define QAIC_DEVINFO_CFG_TOPS 20
+#define QAIC_DEVINFO_THERMAL_PMIC_TEMP_A 21
+#define QAIC_DEVINFO_THERMAL_PMIC_TEMP_C 22
+#define QAIC_DEVINFO_THERMAL_PMIC_TEMP_E 23
+#define QAIC_DEVINFO_POWER_ACTION 24
+#define QAIC_DEVINFO_SOC_TDP 25
+#define QAIC_DEVINFO_SOC_POWER 26
+
/**
* struct qaic_manage_trans_hdr - Header for a transaction in a manage message.
* @type: In. Identifies this transaction. See QAIC_TRANS_* defines.
--
2.43.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes
2026-11-17 23:34 ` [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes Zack McKevitt
@ 2026-11-18 23:35 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-18 23:35 UTC (permalink / raw)
To: Zack McKevitt, dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/drm_ras: telemetry-attrs mode flags attribute uses u8
instead of u32/uint
--
commit fd2287347a17ff8e49c9be2dea7e5b0d3b353084
Author: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
drm/drm_ras: Extend DRM RAS interface to include telemetry nodes
This commit extends the DRM RAS netlink interface with a telemetry node
type and adds operations to list telemetry fields and read or write field
values.
> diff --git a/Documentation/netlink/specs/drm_ras.yaml b/Documentation/netlink/specs/drm_ras.yaml
> index a88fdab7a1c74..28a89aef1e016 100644
> --- a/Documentation/netlink/specs/drm_ras.yaml
> +++ b/Documentation/netlink/specs/drm_ras.yaml
[ ... ]
> @@ -100,6 +105,41 @@ attribute-sets:
> name: error-value
> type: u32
> doc: Current value of the error counter.
> + -
> + name: telemetry-attrs
> + attributes:
[ ... ]
> + -
> + name: mode
> + type: u8
> + enum: telemetry-field-mode
> + doc: >-
> + Bitmask of access modes (read/write) supported by the
> + telemetry field.
[Severity: Low]
Should the mode attribute in telemetry-attrs (and struct
drm_ras_telemetry_field.mode) use u32 or uint instead of u8?
Netlink attributes are padded to 4-byte alignment, so u8 saves no space on
the wire over a 32-bit attribute while permanently limiting the
telemetry-field-mode bitmask in the userspace interface to 8 flags.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117233442.407877-1-zachary.mckevitt@oss.qualcomm.com?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry
2026-11-17 23:34 ` [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry Zack McKevitt
@ 2026-11-18 23:35 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-11-18 23:35 UTC (permalink / raw)
To: Zack McKevitt, dri-devel
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] accel/qaic: missing tele_wq flush and drmm/devm mismatch in
create_qdev()
- [Medium] accel/qaic: missing dev_state check under tele_mutex in
telemetry_request()
- [Medium] accel/qaic: Kconfig depends on default-n DRM_RAS despite
stubbed API
- [Low] accel/qaic: ignored qaic_telemetry_register() failure in
qaic_init()
--
commit d01a133716244ea133490c85965bd2f525824839
Author: Zack McKevitt <zachary.mckevitt@oss.qualcomm.com>
accel/qaic: Add callbacks for DRM RAS netlink telemetry
This commit adds MHI telemetry channel support for QAIC devices and
registers a DRM RAS telemetry node to expose device telemetry fields over
Generic Netlink.
> diff --git a/drivers/accel/qaic/Kconfig b/drivers/accel/qaic/Kconfig
> index 116e42d152ca8..6a07db0c402e7 100644
> --- a/drivers/accel/qaic/Kconfig
> +++ b/drivers/accel/qaic/Kconfig
> @@ -8,6 +8,7 @@ config DRM_ACCEL_QAIC
> depends on DRM_ACCEL
> depends on PCI && HAS_IOMEM
> depends on MHI_BUS
> + depends on DRM_RAS
> select CRC32
> select WANT_DEV_COREDUMP
> help
[Severity: Medium]
Does adding "depends on DRM_RAS" disable DRM_ACCEL_QAIC in existing
configs? DRM_RAS defaults to n, so running olddefconfig on a kernel
configuration with DRM_ACCEL_QAIC enabled will silently drop the driver
unless DRM_RAS was explicitly selected.
include/drm/drm_ras.h already provides no-op inline stubs for
drm_ras_node_register() and drm_ras_node_unregister() when CONFIG_DRM_RAS
is disabled, so DRM_ACCEL_QAIC does not need a hard Kconfig dependency on
DRM_RAS.
[ ... ]
> diff --git a/drivers/accel/qaic/qaic_drv.c b/drivers/accel/qaic/qaic_drv.c
> index 90c0d31e414ae..6d185151a0a69 100644
> --- a/drivers/accel/qaic/qaic_drv.c
> +++ b/drivers/accel/qaic/qaic_drv.c
[ ... ]
> @@ -854,12 +863,17 @@ static int __init qaic_init(void)
> ret = qaic_ras_register();
> if (ret)
> pr_debug("qaic: qaic_ras_register failed %d\n", ret);
> +
> ret = qaic_ssr_register();
> if (ret) {
> pr_debug("qaic: qaic_ssr_register failed %d\n", ret);
> goto free_bootlog;
> }
>
> + ret = qaic_telemetry_register();
> + if (ret)
> + pr_debug("qaic: qaic_telemetry_register failed %d\n", ret);
> +
> return 0;
>
> free_bootlog:
> @@ -889,6 +903,7 @@ static void __exit qaic_exit(void)
> * reinitializing the link_up state after the cleanup is done.
> */
> link_up = true;
> + qaic_telemetry_unregister();
> qaic_ssr_unregister();
> qaic_ras_unregister();
> qaic_bootlog_unregister();
[Severity: Low]
If qaic_telemetry_register() fails in qaic_init(), module initialization
still succeeds with qaic_telemetry_mhi_driver left unregistered. When the
module is later unloaded, qaic_exit() unconditionally calls
qaic_telemetry_unregister() -> mhi_driver_unregister() ->
driver_unregister(), which hits WARN(1, "Unexpected driver unregister!\n")
because drv->p is NULL. Should qaic_init() unwind and propagate the error
when qaic_telemetry_register() fails, matching qaic_ssr_register()?
> diff --git a/drivers/accel/qaic/qaic_telemetry.c b/drivers/accel/qaic/qaic_telemetry.c
> new file mode 100644
> index 0000000000000..bcf9842f4ec91
> --- /dev/null
> +++ b/drivers/accel/qaic/qaic_telemetry.c
> @@ -0,0 +1,563 @@
[ ... ]
> +static int telemetry_request(struct qaic_device *qdev, u8 cmd, u8 cmd_type, s64 *val, s64 *status)
> +{
> + struct wrapper_msg *wrapper;
> + struct xfer_queue_elem elem;
> + struct telemetry_msg *resp;
> + struct telemetry_msg *req;
> + long ret = 0;
> +
> + wrapper = kzalloc_obj(*wrapper);
> + if (!wrapper)
> + return -ENOMEM;
> +
> + kref_init(&wrapper->ref_count);
> + req = &wrapper->msg;
> +
> + ret = mutex_lock_interruptible(&qdev->tele_mutex);
> + if (ret)
> + goto free_req;
> +
> + if (!qdev->tele_ch) {
> + mutex_unlock(&qdev->tele_mutex);
> + ret = -ENODEV;
> + goto free_req;
> + }
[Severity: Medium]
Can telemetry_request() queue a request onto qdev->tele_xfer_list after
wake_all_telemetry() has already drained it during a reset?
qaic_telemetry_get() and qaic_telemetry_set() check qdev->dev_state !=
QAIC_ONLINE before calling telemetry_request() and acquiring
qdev->tele_mutex. During qaic_notify_reset(), qdev->tele_ch remains
non-NULL until qaic_telemetry_mhi_remove() runs after
synchronize_srcu(&qdev->dev_lock):
CPU0 CPU1
qaic_telemetry_get()
srcu_read_lock(&qdev->dev_lock)
if (qdev->dev_state != QAIC_ONLINE)
telemetry_request()
qaic_notify_reset()
qdev->dev_state = QAIC_OFFLINE;
wake_all_telemetry(qdev)
mutex_lock(&qdev->tele_mutex)
/* drains tele_xfer_list */
mutex_unlock(&qdev->tele_mutex)
mutex_lock_interruptible(&qdev->tele_mutex)
/* qdev->tele_ch is still non-NULL */
mhi_queue_buf(...)
list_add_tail(&elem.list, &qdev->tele_xfer_list)
mutex_unlock(&qdev->tele_mutex)
wait_for_completion_interruptible_timeout(..., HZ)
synchronize_srcu(&qdev->dev_lock)
<-- stalls for HZ
CPU0 queues MHI buffers onto a resetting channel after wake_all_telemetry()
has already run, stalls synchronize_srcu(&qdev->dev_lock) for the full HZ
timeout, and returns -ETIMEDOUT instead of -ENODEV. Should
telemetry_request() recheck qdev->dev_state != QAIC_ONLINE under
qdev->tele_mutex, similar to how msg_xfer() checks qdev->dev_state under
qdev->cntl_mutex?
[ ... ]
> +static void qaic_telemetry_mhi_remove(struct mhi_device *mhi_dev)
> +{
> + struct qaic_device *qdev = dev_get_drvdata(&mhi_dev->dev);
> +
> + qaic_drm_ras_unregister_node(qdev);
> + mhi_unprepare_from_transfer(qdev->tele_ch);
> + qdev->tele_ch = NULL;
> +}
[Severity: High]
Can a pending resp_worker() item or drmm cleanup access qdev after it has
been freed?
In create_qdev(), qdev is allocated with devm_kzalloc_flex() on &pdev->dev,
whereas qdev->tele_mutex and qdev->tele_wq are managed by drmm on the
drm_device via drmm_mutex_init() and qaicm_wq_init(). Furthermore,
qaic_telemetry_mhi_remove() does not flush qdev->tele_wq after
mhi_unprepare_from_transfer(). If the PCI device is removed while
userspace holds an open file descriptor to /dev/accel/accelN, the open file
keeps a reference on drm_device, so devres frees qdev before
drm_managed_release() runs:
CPU0 kworker
qaic_pci_remove()
...
qaic_telemetry_mhi_remove()
mhi_unprepare_from_transfer(...)
/* tele_wq not flushed */
devres_release_all(&pdev->dev)
/* frees qdev while drm ref > 0 */
resp_worker()
mutex_lock(&qdev->tele_mutex)
<-- use-after-free
Even without a pending work item, when userspace later closes the DRM file
descriptor, the final drm_dev_put() runs __drmm_mutex_release() on
&qdev->tele_mutex in the already-freed qdev. Flushing qdev->tele_wq in
qaic_telemetry_mhi_remove() and tying tele_mutex and tele_wq to devm on
&pdev->dev (or matching qdev's lifetime) would avoid both use-after-frees.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117233442.407877-1-zachary.mckevitt@oss.qualcomm.com?part=4
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-18 23:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 23:34 [PATCH v4 0/4] Extend drm_ras for qaic telemetry Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 1/4] drm/drm_ras: Reference-count nodes across netlink handlers Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 2/4] drm/drm_ras: Remove admin-perm flag from list-nodes operation Zack McKevitt
2026-11-17 23:34 ` [PATCH v4 3/4] drm/drm_ras: Extend DRM RAS interface to include telemetry nodes Zack McKevitt
2026-11-18 23:35 ` sashiko-bot
2026-11-17 23:34 ` [PATCH v4 4/4] accel/qaic: Add callbacks for DRM RAS netlink telemetry Zack McKevitt
2026-11-18 23:35 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox