From: "Summers, Stuart" <stuart.summers@intel.com>
To: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
"Jadav, Raag" <raag.jadav@intel.com>
Cc: "Tauro, Riana" <riana.tauro@intel.com>
Subject: Re: [PATCH v1] drm/xe/drm_ras: Protect against unplugged or wedged device
Date: Mon, 16 Nov 2026 23:28:23 +0000 [thread overview]
Message-ID: <85d0eb950789c3d413fb91dc02b9c53751207c57.camel@intel.com> (raw)
In-Reply-To: <20261116085343.1972825-1-raag.jadav@intel.com>
On Mon, 2026-11-16 at 14:23 +0530, Raag Jadav wrote:
> 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>
Hm.. I'm not fully convinced on the sashiko issue, particularly after
we have the get/put in this patch. I think we'll need some digging
there to see if that's really still a problem after this one gets
merged. Anyway as it called out, it's pre-existing.
I agree with the changes here. Functionally looks correct and makes
sense to include the wedge here too.
Should we have a test that injects an error after wedge with a netlink
hook enabled just to prove this works in CI?
Either way, for the kernel change:
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Thanks,
Stuart
> ---
> 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);
> }
>
> /**
next prev parent reply other threads:[~2026-11-16 23:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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
2026-11-16 23:28 ` Summers, Stuart [this message]
2026-11-17 8:50 ` [PATCH v1] " Raag Jadav
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=85d0eb950789c3d413fb91dc02b9c53751207c57.camel@intel.com \
--to=stuart.summers@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=raag.jadav@intel.com \
--cc=riana.tauro@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.