Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] drm/xe/drm_ras: Protect against unplugged or wedged device
@ 2026-11-16  8:53 Raag Jadav
  2026-11-16  9:07 ` sashiko-bot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Raag Jadav @ 2026-11-16  8:53 UTC (permalink / raw)
  To: intel-xe; +Cc: riana.tauro, Raag Jadav

Xe driver exposes drm_ras counters to userspace through netlink interface,
which the user can access during the device lifetime. But this should not
be done in case of unplugged or wedged device. Protect against such cases.

Fixes: b40db12b542f ("drm/xe/xe_drm_ras: Add support for XE DRM RAS")
Signed-off-by: Raag Jadav <raag.jadav@intel.com>
---
 drivers/gpu/drm/xe/xe_drm_ras.c | 93 ++++++++++++++++++++++++---------
 1 file changed, 69 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_drm_ras.c b/drivers/gpu/drm/xe/xe_drm_ras.c
index 7554803aae11..c0c1acb84e89 100644
--- a/drivers/gpu/drm/xe/xe_drm_ras.c
+++ b/drivers/gpu/drm/xe/xe_drm_ras.c
@@ -5,6 +5,7 @@
 
 #include <linux/bitmap.h>
 
+#include <drm/drm_drv.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_print.h>
 #include <drm/drm_ras.h>
@@ -12,10 +13,33 @@
 #include "xe_device_types.h"
 #include "xe_drm_ras.h"
 #include "xe_ras.h"
+#include "xe_wedge.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;
 
+static int drm_ras_counter_get(struct xe_device *xe, struct xe_drm_ras_counter *info,
+			       u32 error_id, int *idx)
+{
+	if (xe_wedged(xe))
+		return -ECANCELED;
+
+	if (!info || !info[error_id].name)
+		return -ENOENT;
+
+	/* Must be last */
+	if (!drm_dev_enter(&xe->drm, idx))
+		return -ENODEV;
+
+	return 0;
+}
+
+static void drm_ras_counter_put(int idx)
+{
+	/* Pair with drm_ras_counter_get() */
+	drm_dev_exit(idx);
+}
+
 static bool drm_ras_counter_is_valid(u32 severity, u32 component)
 {
 	if (!in_range(severity, DRM_XE_RAS_ERR_SEV_CORRECTABLE, DRM_XE_RAS_ERR_SEV_MAX))
@@ -33,19 +57,23 @@ static int query_error_counter(struct xe_device *xe,
 {
 	struct xe_drm_ras *ras = &xe->ras.nl_data;
 	struct xe_drm_ras_counter *info = ras->info[severity];
+	int idx, ret;
 
-	if (!info || !info[error_id].name)
-		return -ENOENT;
-
-	*name = info[error_id].name;
+	ret = drm_ras_counter_get(xe, info, error_id, &idx);
+	if (ret)
+		return ret;
 
 	/* Fetch counter from system controller if supported */
 	if (xe->info.has_sysctrl)
-		return xe_ras_get_counter(xe, severity, error_id, val);
+		ret = xe_ras_get_counter(xe, severity, error_id, val);
+	else
+		*val = atomic_read(&info[error_id].counter);
 
-	*val = atomic_read(&info[error_id].counter);
+	if (!ret)
+		*name = info[error_id].name;
 
-	return 0;
+	drm_ras_counter_put(idx);
+	return ret;
 }
 
 static int clear_error_counter(struct xe_device *xe,
@@ -54,17 +82,20 @@ static int clear_error_counter(struct xe_device *xe,
 {
 	struct xe_drm_ras *ras = &xe->ras.nl_data;
 	struct xe_drm_ras_counter *info = ras->info[severity];
+	int idx, ret;
 
-	if (!info || !info[error_id].name)
-		return -ENOENT;
+	ret = drm_ras_counter_get(xe, info, error_id, &idx);
+	if (ret)
+		return ret;
 
 	/* Clear counter from system controller if supported */
 	if (xe->info.has_sysctrl)
-		return xe_ras_clear_counter(xe, severity, error_id);
+		ret = xe_ras_clear_counter(xe, severity, error_id);
+	else
+		atomic_set(&info[error_id].counter, 0);
 
-	atomic_set(&info[error_id].counter, 0);
-
-	return 0;
+	drm_ras_counter_put(idx);
+	return ret;
 }
 
 static int query_uncorrectable_error_counter(struct drm_ras_node *ep, u32 error_id,
@@ -103,15 +134,21 @@ static int query_correctable_error_threshold(struct drm_ras_node *ep, u32 error_
 	struct xe_device *xe = ep->priv;
 	struct xe_drm_ras *ras = &xe->ras.nl_data;
 	struct xe_drm_ras_counter *info = ras->info[DRM_XE_RAS_ERR_SEV_CORRECTABLE];
-
-	if (!info || !info[error_id].name)
-		return -ENOENT;
+	int idx, ret;
 
 	if (!xe->info.has_sysctrl)
 		return -EOPNOTSUPP;
 
-	*name = info[error_id].name;
-	return xe_ras_get_threshold(xe, DRM_XE_RAS_ERR_SEV_CORRECTABLE, error_id, threshold);
+	ret = drm_ras_counter_get(xe, info, error_id, &idx);
+	if (ret)
+		return ret;
+
+	ret = xe_ras_get_threshold(xe, DRM_XE_RAS_ERR_SEV_CORRECTABLE, error_id, threshold);
+	if (!ret)
+		*name = info[error_id].name;
+
+	drm_ras_counter_put(idx);
+	return ret;
 }
 
 static int set_correctable_error_threshold(struct drm_ras_node *ep, u32 error_id, u32 threshold)
@@ -119,14 +156,19 @@ static int set_correctable_error_threshold(struct drm_ras_node *ep, u32 error_id
 	struct xe_device *xe = ep->priv;
 	struct xe_drm_ras *ras = &xe->ras.nl_data;
 	struct xe_drm_ras_counter *info = ras->info[DRM_XE_RAS_ERR_SEV_CORRECTABLE];
-
-	if (!info || !info[error_id].name)
-		return -ENOENT;
+	int idx, ret;
 
 	if (!xe->info.has_sysctrl)
 		return -EOPNOTSUPP;
 
-	return xe_ras_set_threshold(xe, DRM_XE_RAS_ERR_SEV_CORRECTABLE, error_id, threshold);
+	ret = drm_ras_counter_get(xe, info, error_id, &idx);
+	if (ret)
+		return ret;
+
+	ret = xe_ras_set_threshold(xe, DRM_XE_RAS_ERR_SEV_CORRECTABLE, error_id, threshold);
+
+	drm_ras_counter_put(idx);
+	return ret;
 }
 
 static struct xe_drm_ras_counter *allocate_and_copy_counters(struct xe_device *xe)
@@ -244,7 +286,7 @@ void xe_drm_ras_event(struct xe_device *xe, u32 component, u32 severity, u32 val
 	struct xe_drm_ras *ras = &xe->ras.nl_data;
 	struct xe_drm_ras_counter *info;
 	struct drm_ras_node *node;
-	int ret;
+	int idx, ret;
 
 	/* Event is supported only if drm-ras is enabled */
 	if (!xe->info.has_drm_ras)
@@ -256,13 +298,16 @@ void xe_drm_ras_event(struct xe_device *xe, u32 component, u32 severity, u32 val
 	node = &ras->node[severity];
 	info = ras->info[severity];
 
-	if (!info || !info[component].name)
+	ret = drm_ras_counter_get(xe, info, component, &idx);
+	if (ret)
 		return;
 
 	ret = drm_ras_nl_error_event(node, component, info[component].name, value);
 	if (ret)
 		drm_err_ratelimited(&xe->drm, "drm-ras error-event failed: %d for %s %s\n", ret,
 				    info[component].name, error_severity[severity]);
+
+	drm_ras_counter_put(idx);
 }
 
 /**
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-16 13:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  8:53 [PATCH v1] drm/xe/drm_ras: Protect against unplugged or wedged device Raag Jadav
2026-11-16  9:07 ` sashiko-bot
2026-11-16  9:25 ` ✓ CI.KUnit: success for " Patchwork
2026-11-16  9:57 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-16 13:55 ` ✓ Xe.CI.FULL: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox