Skip to contentSkip to conversation

drm/xe: Unify fault injection hooks for CSC, GT reset

PATCH Superseded Mallesh Koujalagi 3 participants 5 messages May 15 – May 18

Subsystems (2)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 drm/xe: Unify fault injection hooks for CSC, GT reset

The fault injection code was scattered: the GT reset hook lived in xe_gt.h as an inline function with its own global variable, the CSC hook had a separate global in xe_hw_error.c with an extern declaration, and each was individually registered in xe_debugfs.c. Adding a new error type meant editing many files and copy-pasting the same boilerplate.

Create a single, centralized fault injection module (xe_fault_inject.c/h) that manages all fault types through one table. Each type is just an entry in an enum and a one-line row in a descriptor array -- no more scattered globals, externs, or per-type inline helpers.

Debugfs interface (under /sys/kernel/debug/dri/0/):
- fail_gt_reset - GT reset failure
- inject_csc_hw_error - CSC firmware error

---
v2:
- Add multiple platform support. (Vinay)
- Handle VF properly.
- Rename to XE_FAULT_GT_RESET/XE_FAULT_CSC_HW_ERROR and create xe_fault_inject_types.h file including those name.

v3:
- Solved patch apply issue on tip.

v4:
- Add proper header file.

---
 drivers/gpu/drm/xe/Makefile                |  1 +
 drivers/gpu/drm/xe/xe_debugfs.c            |  9 +--
 drivers/gpu/drm/xe/xe_fault_inject.c       | 68 ++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_fault_inject.h       | 31 ++++++++++
 drivers/gpu/drm/xe/xe_fault_inject_types.h | 21 +++++++
 drivers/gpu/drm/xe/xe_gt.c                 |  5 +-
 drivers/gpu/drm/xe/xe_gt.h                 |  8 ---
 drivers/gpu/drm/xe/xe_hw_error.c           | 11 +---
 8 files changed, 128 insertions(+), 26 deletions(-)
 create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.c
 create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.h
 create mode 100644 drivers/gpu/drm/xe/xe_fault_inject_types.h
drivers/gpu/drm/xe/Makefile +1 -0
index 09661f079d03..b36cf511a537 100644
@@ -351,6 +351,7 @@ endif
 
 ifeq ($(CONFIG_DEBUG_FS),y)
 	xe-y += xe_debugfs.o \
+		xe_fault_inject.o \
 		xe_gt_debugfs.o \
 		xe_gt_sriov_vf_debugfs.o \
 		xe_gt_stats.o \
drivers/gpu/drm/xe/xe_debugfs.c +2 -7
index 22b471303984..8402189b24ef 100644
@@ -6,7 +6,6 @@
 #include "xe_debugfs.h"
 
 #include <linux/debugfs.h>
-#include <linux/fault-inject.h>
 #include <linux/string_helpers.h>
 
 #include <drm/drm_debugfs.h>
@@ -14,6 +13,7 @@
 #include "regs/xe_pmt.h"
 #include "xe_bo.h"
 #include "xe_device.h"
+#include "xe_fault_inject.h"
 #include "xe_force_wake.h"
 #include "xe_gt.h"
 #include "xe_gt_debugfs.h"
@@ -38,9 +38,6 @@
 #include "xe_vm.h"
 #endif
 
-DECLARE_FAULT_ATTR(gt_reset_failure);
-DECLARE_FAULT_ATTR(inject_csc_hw_error);
-
 static void read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio,
 				   u32 offset, const char *name, struct drm_printer *p)
 {
@@ -563,8 +560,6 @@ void xe_debugfs_register(struct xe_device *xe)
 		drm_debugfs_create_files(debugfs_residencies,
 					 ARRAY_SIZE(debugfs_residencies),
 					 root, minor);
-		fault_create_debugfs_attr("inject_csc_hw_error", root,
-					  &inject_csc_hw_error);
 	}
 
 	debugfs_create_file("forcewake_all", 0400, root, xe,
@@ -610,7 +605,7 @@ void xe_debugfs_register(struct xe_device *xe)
 
 	xe_psmi_debugfs_register(xe);
 
-	fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
+	xe_fault_inject_debugfs_register(xe, root);
 
 	if (IS_SRIOV_PF(xe))
 		xe_sriov_pf_debugfs_register(xe, root);
drivers/gpu/drm/xe/xe_fault_inject.c new file +68 -0

68 lines not on this page · raw message

drivers/gpu/drm/xe/xe_fault_inject.h new file +31 -0
new file mode 100644
index 000000000000..bc4d856407e8
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_H_
+#define _XE_FAULT_INJECT_H_
+
+#include <linux/types.h>
+
+#include "xe_fault_inject_types.h"
+
+struct xe_device;
+struct dentry;
+
+#ifdef CONFIG_DEBUG_FS
+bool xe_fault_inject(enum xe_fault_type type);
+void xe_fault_inject_debugfs_register(struct xe_device *xe, struct dentry *root);
+#else
+static inline bool xe_fault_inject(enum xe_fault_type type)
+{
+	return false;
+}
+
+static inline void xe_fault_inject_debugfs_register(struct xe_device *xe,
+						    struct dentry *root)
+{
+}
+#endif
+
+#endif /* _XE_FAULT_INJECT_H_ */
drivers/gpu/drm/xe/xe_fault_inject_types.h new file +21 -0
new file mode 100644
index 000000000000..cf0cd0974be1
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_TYPES_H_
+#define _XE_FAULT_INJECT_TYPES_H_
+
+/**
+ * enum xe_fault_type - Fault injection types
+ * @XE_FAULT_GT_RESET: GT reset failure injection
+ * @XE_FAULT_CSC_HW_ERROR: CSC hardware error injection
+ * @XE_FAULT_MAX: Number of fault injection types
+ */
+enum xe_fault_type {
+	XE_FAULT_GT_RESET,
+	XE_FAULT_CSC_HW_ERROR,
+	XE_FAULT_MAX
+};
+
+#endif /* _XE_FAULT_INJECT_TYPES_H_ */
drivers/gpu/drm/xe/xe_gt.c +3 -2
index cdc678d1ae1f..f900c252a523 100644
@@ -23,6 +23,7 @@
 #include "xe_eu_stall.h"
 #include "xe_exec_queue.h"
 #include "xe_execlist.h"
+#include "xe_fault_inject.h"
 #include "xe_force_wake.h"
 #include "xe_ggtt.h"
 #include "xe_gsc.h"
@@ -923,7 +924,7 @@ static void gt_reset_worker(struct work_struct *w)
 
 	xe_gt_info(gt, "reset started\n");
 
-	if (xe_fault_inject_gt_reset()) {
+	if (xe_fault_inject(XE_FAULT_GT_RESET)) {
 		err = -ECANCELED;
 		goto err_fail;
 	}
@@ -980,7 +981,7 @@ void xe_gt_reset_async(struct xe_gt *gt)
 	xe_gt_info(gt, "trying reset from %ps\n", __builtin_return_address(0));
 
 	/* Don't do a reset while one is already in flight */
-	if (!xe_fault_inject_gt_reset() && xe_uc_reset_prepare(&gt->uc))
+	if (!xe_fault_inject(XE_FAULT_GT_RESET) && xe_uc_reset_prepare(&gt->uc))
 		return;
 
 	xe_gt_info(gt, "reset queued\n");
drivers/gpu/drm/xe/xe_gt.h +0 -8
index 4150aa594f05..f8e3ca63aabb 100644
@@ -6,8 +6,6 @@
 #ifndef _XE_GT_H_
 #define _XE_GT_H_
 
-#include <linux/fault-inject.h>
-
 #include <drm/drm_util.h>
 
 #include "xe_device.h"
@@ -38,12 +36,6 @@
 	xe_gt_is_media_type(gt_) ? MEDIA_VER(xe) : GRAPHICS_VER(xe); \
 })
 
-extern struct fault_attr gt_reset_failure;
-static inline bool xe_fault_inject_gt_reset(void)
-{
-	return IS_ENABLED(CONFIG_DEBUG_FS) && should_fail(&gt_reset_failure, 1);
-}
-
 struct xe_gt *xe_gt_alloc(struct xe_tile *tile);
 int xe_gt_init_early(struct xe_gt *gt);
 int xe_gt_init(struct xe_gt *gt);
drivers/gpu/drm/xe/xe_hw_error.c +2 -9
index 5135e8e4093f..192e68e847a5 100644
@@ -4,7 +4,6 @@
  */
 
 #include <linux/bitmap.h>
-#include <linux/fault-inject.h>
 
 #include "regs/xe_gsc_regs.h"
 #include "regs/xe_hw_error_regs.h"
@@ -12,6 +11,7 @@
 
 #include "xe_device.h"
 #include "xe_drm_ras.h"
+#include "xe_fault_inject.h"
 #include "xe_hw_error.h"
 #include "xe_mmio.h"
 #include "xe_survivability_mode.h"
@@ -25,8 +25,6 @@
 						 (PVC_COR_ERR_MASK & REG_BIT(err_bit)) : \
 						 (PVC_FAT_ERR_MASK & REG_BIT(err_bit)))
 
-extern struct fault_attr inject_csc_hw_error;
-
 static const char * const error_severity[] = DRM_XE_RAS_ERROR_SEVERITY_NAMES;
 
 static const char * const hec_uncorrected_fw_errors[] = {
@@ -167,11 +165,6 @@ static_assert(ARRAY_SIZE(pvc_master_local_nonfatal_err_reg) == XE_RAS_REG_SIZE);
 						 pvc_master_local_fatal_err_reg : \
 						 pvc_master_local_nonfatal_err_reg)
 
-static bool fault_inject_csc_hw_error(void)
-{
-	return IS_ENABLED(CONFIG_DEBUG_FS) && should_fail(&inject_csc_hw_error, 1);
-}
-
 static void csc_hw_error_work(struct work_struct *work)
 {
 	struct xe_tile *tile = container_of(work, typeof(*tile), csc_hw_error_work);
@@ -507,7 +500,7 @@ void xe_hw_error_irq_handler(struct xe_tile *tile, const u32 master_ctl)
 {
 	enum hardware_error hw_err;
 
-	if (fault_inject_csc_hw_error())
+	if (xe_fault_inject(XE_FAULT_CSC_HW_ERROR))
 		schedule_work(&tile->csc_hw_error_work);
 
 	for (hw_err = 0; hw_err < HARDWARE_ERROR_MAX; hw_err++) {
Signature · 1 line
2.34.1
#1 lore raw

✗ CI.checkpatch: warning for drm/xe: Unify fault injection hooks for CSC, GT reset (rev5)

== Series Details ==

== Series Details ==

Series: drm/xe: Unify fault injection hooks for CSC, GT reset (rev5)
URL : https://patchwork.freedesktop.org/series/164761/
State : warning

== Summary ==

+ KERNEL=/kernel
+ git clone https://gitlab.freedesktop.org/drm/maintainer-tools mt Cloning into 'mt'...
warning: redirecting to https://gitlab.freedesktop.org/drm/maintainer-tools.git/
+ git -C mt rev-list -n1 origin/master 061140b9bc586ae7f40abc1249c97e1cc72d1b9d
+ cd /kernel
+ git config --global --add safe.directory /kernel
+ git log -n1
commit 3833cf7c1d6f280176a49ca6d5da9bde1a67f884

Author: Mallesh Koujalagi <[email protected]>
Date:   Fri May 15 15:49:50 2026 +0530

drm/xe: Unify fault injection hooks for CSC, GT reset

The fault injection code was scattered: the GT reset hook lived in xe_gt.h as an inline function with its own global variable, the CSC hook had a separate global in xe_hw_error.c with an extern declaration, and each was individually registered in xe_debugfs.c. Adding a new error type meant editing many files and copy-pasting the same boilerplate.

Create a single, centralized fault injection module (xe_fault_inject.c/h) that manages all fault types through one table. Each type is just an entry in an enum and a one-line row in a descriptor array -- no more scattered globals, externs, or per-type inline helpers.

Debugfs interface (under /sys/kernel/debug/dri/0/):
- fail_gt_reset - GT reset failure
- inject_csc_hw_error - CSC firmware error

+ /mt/dim checkpatch b9819223b7e92173091b674c2212252b99ea6c4b drm-intel 3833cf7c1d6f drm/xe: Unify fault injection hooks for CSC, GT reset
-:86: WARNING:FILE_PATH_CHANGES: added, moved or deleted file(s), does MAINTAINERS need updating? #86:
new file mode 100644

total: 0 errors, 1 warnings, 0 checks, 250 lines checked

#2 lore raw

✗ CI.KUnit: failure for drm/xe: Unify fault injection hooks for CSC, GT reset (rev5)

In reply to Mallesh Koujalagi
== Series Details ==

== Series Details ==

Series: drm/xe: Unify fault injection hooks for CSC, GT reset (rev5)
URL : https://patchwork.freedesktop.org/series/164761/
State : failure

== Summary ==

+ trap cleanup EXIT
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../drivers/gpu/drm/xe/xe_fault_inject.c:21:45: error: ‘FAULT_ATTR_INITIALIZER’ undeclared here (not in a function)
21 | .attr = FAULT_ATTR_INITIALIZER },

      |                                             ^~~~~~~~~~~~~~~~~~~~~~

make[7]: *** [../scripts/Makefile.build:289: drivers/gpu/drm/xe/xe_fault_inject.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:548: drivers/gpu/drm/xe] Error 2 make[5]: *** [../scripts/Makefile.build:548: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:548: drivers/gpu] Error 2
make[3]: *** [../scripts/Makefile.build:548: drivers] Error 2
make[2]: *** [/kernel/Makefile:2143: .] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2

[10:43:11] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:

$ make ARCH=um O=.kunit olddefconfig
[10:43:15] Building KUnit Kernel ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig
Building with:
$ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48
+ cleanup
++ stat -c %u:%g /kernel
+ chown -R 1003:1003 /kernel
Reviewed-by on v4 1/1
#3 lore raw
In reply to Mallesh Koujalagi
Quoted 110 lines · Mallesh Koujalagi

The fault injection code was scattered: the GT reset hook lived in xe_gt.h as an inline function with its own global variable, the CSC hook had a separate global in xe_hw_error.c with an extern declaration, and each was individually registered in xe_debugfs.c. Adding a new error type meant editing many files and copy-pasting the same boilerplate.

Create a single, centralized fault injection module (xe_fault_inject.c/h) that manages all fault types through one table. Each type is just an entry in an enum and a one-line row in a descriptor array -- no more scattered globals, externs, or per-type inline helpers.

Debugfs interface (under /sys/kernel/debug/dri/0/):
- fail_gt_reset - GT reset failure
- inject_csc_hw_error - CSC firmware error

---
v2:
- Add multiple platform support. (Vinay)
- Handle VF properly.
- Rename to XE_FAULT_GT_RESET/XE_FAULT_CSC_HW_ERROR and create xe_fault_inject_types.h file including those name.

v3:
- Solved patch apply issue on tip.

v4:
- Add proper header file.

---
  drivers/gpu/drm/xe/Makefile                |  1 +
  drivers/gpu/drm/xe/xe_debugfs.c            |  9 +--
  drivers/gpu/drm/xe/xe_fault_inject.c       | 68 ++++++++++++++++++++++
  drivers/gpu/drm/xe/xe_fault_inject.h       | 31 ++++++++++
  drivers/gpu/drm/xe/xe_fault_inject_types.h | 21 +++++++
  drivers/gpu/drm/xe/xe_gt.c                 |  5 +-
  drivers/gpu/drm/xe/xe_gt.h                 |  8 ---
  drivers/gpu/drm/xe/xe_hw_error.c           | 11 +---
  8 files changed, 128 insertions(+), 26 deletions(-)

create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.c create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.h create mode 100644 drivers/gpu/drm/xe/xe_fault_inject_types.h

drivers/gpu/drm/xe/Makefile +1 -0
index 09661f079d03..b36cf511a537 100644
@@ -351,6 +351,7 @@ endif
 
  ifeq ($(CONFIG_DEBUG_FS),y)
  	xe-y += xe_debugfs.o \
+		xe_fault_inject.o \
  		xe_gt_debugfs.o \
  		xe_gt_sriov_vf_debugfs.o \
  		xe_gt_stats.o \
drivers/gpu/drm/xe/xe_debugfs.c +2 -7
index 22b471303984..8402189b24ef 100644
@@ -6,7 +6,6 @@
  #include "xe_debugfs.h"
 
  #include <linux/debugfs.h>
-#include <linux/fault-inject.h>
  #include <linux/string_helpers.h>
 
  #include <drm/drm_debugfs.h>
@@ -14,6 +13,7 @@
  #include "regs/xe_pmt.h"
  #include "xe_bo.h"
  #include "xe_device.h"
+#include "xe_fault_inject.h"
  #include "xe_force_wake.h"
  #include "xe_gt.h"
  #include "xe_gt_debugfs.h"
@@ -38,9 +38,6 @@
  #include "xe_vm.h"
  #endif
 
-DECLARE_FAULT_ATTR(gt_reset_failure);
-DECLARE_FAULT_ATTR(inject_csc_hw_error);
-
  static void read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio,
  				   u32 offset, const char *name, struct drm_printer *p)
  {
@@ -563,8 +560,6 @@ void xe_debugfs_register(struct xe_device *xe)
  		drm_debugfs_create_files(debugfs_residencies,
  					 ARRAY_SIZE(debugfs_residencies),
  					 root, minor);
-		fault_create_debugfs_attr("inject_csc_hw_error", root,
-					  &inject_csc_hw_error);
  	}
 
  	debugfs_create_file("forcewake_all", 0400, root, xe,
@@ -610,7 +605,7 @@ void xe_debugfs_register(struct xe_device *xe)
 
  	xe_psmi_debugfs_register(xe);
 
-	fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
+	xe_fault_inject_debugfs_register(xe, root);
 
  	if (IS_SRIOV_PF(xe))
  		xe_sriov_pf_debugfs_register(xe, root);
drivers/gpu/drm/xe/xe_fault_inject.c new file +0 -0
new file mode 100644
index 000000000000..80811850a2ef

drivers/gpu/drm/xe/xe_fault_inject.c line 3

Quoted 3 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +3 -0
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2025 Intel Corporation

s/2025/2026 here and elsewhere.

Quoted 6 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +6 -0
+ */
+
+#include <linux/bits.h>
+#include <linux/fault-inject.h>
+
+#include "xe_device.h"

drivers/gpu/drm/xe/xe_fault_inject.c line 19

Quoted 10 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +10 -0
+#include "xe_fault_inject.h"
+#include "xe_platform_types.h"
+#include "xe_sriov.h"
+
+static struct {
+	const char *name;
+	u32 platforms;
+	bool skip_on_vf;
+	struct fault_attr attr;
+} xe_fault_inject_descs[XE_FAULT_MAX] = {

Nit: Descs are more for descriptors, maybe xe_fault_inject_entry?

drivers/gpu/drm/xe/xe_fault_inject.c line 21

Quoted 2 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +2 -0
+	[XE_FAULT_GT_RESET]	= { .name = "fail_gt_reset",
+				    .attr = FAULT_ATTR_INITIALIZER },

Should have some reference to the patch that introduces FAULT_ATTR_INITIALIZER. Can they both be in the same series?

With the nits addressed and copyright year fixed, this patch is-

Quoted 217 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +47 -0
+	[XE_FAULT_CSC_HW_ERROR]	= { .name = "inject_csc_hw_error",
+				    .platforms = BIT(XE_BATTLEMAGE),
+				    .skip_on_vf = true,
+				    .attr = FAULT_ATTR_INITIALIZER },
+};
+
+/**
+ * xe_fault_inject - Check if a fault should be injected
+ * @type: fault injection type to check
+ *
+ * Returns true if a fault should be injected for the given type.
+ * Controlled via debugfs fault injection attributes.
+ */
+bool xe_fault_inject(enum xe_fault_type type)
+{
+	if (type >= XE_FAULT_MAX)
+		return false;
+
+	return should_fail(&xe_fault_inject_descs[type].attr, 1);
+}
+
+/**
+ * xe_fault_inject_debugfs_register - Register fault injection debugfs entries
+ * @xe: xe device instance
+ * @root: debugfs root directory
+ *
+ * Creates debugfs fault injection attributes for all supported fault
+ * injection types. Platform-specific entries are only registered on
+ * matching platforms. Entries marked skip_on_vf are not registered for
+ * SR-IOV VF devices.
+ */
+void xe_fault_inject_debugfs_register(struct xe_device *xe, struct dentry *root)
+{
+	int i;
+
+	for (i = 0; i < XE_FAULT_MAX; i++) {
+		if (IS_SRIOV_VF(xe) && xe_fault_inject_descs[i].skip_on_vf)
+			continue;
+
+		if (xe_fault_inject_descs[i].platforms &&
+		    !(xe_fault_inject_descs[i].platforms & BIT(xe->info.platform)))
+			continue;
+
+		fault_create_debugfs_attr(xe_fault_inject_descs[i].name, root,
+					  &xe_fault_inject_descs[i].attr);
+	}
+}
drivers/gpu/drm/xe/xe_fault_inject.h new file +31 -0
new file mode 100644
index 000000000000..bc4d856407e8
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_H_
+#define _XE_FAULT_INJECT_H_
+
+#include <linux/types.h>
+
+#include "xe_fault_inject_types.h"
+
+struct xe_device;
+struct dentry;
+
+#ifdef CONFIG_DEBUG_FS
+bool xe_fault_inject(enum xe_fault_type type);
+void xe_fault_inject_debugfs_register(struct xe_device *xe, struct dentry *root);
+#else
+static inline bool xe_fault_inject(enum xe_fault_type type)
+{
+	return false;
+}
+
+static inline void xe_fault_inject_debugfs_register(struct xe_device *xe,
+						    struct dentry *root)
+{
+}
+#endif
+
+#endif /* _XE_FAULT_INJECT_H_ */
drivers/gpu/drm/xe/xe_fault_inject_types.h new file +21 -0
new file mode 100644
index 000000000000..cf0cd0974be1
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_TYPES_H_
+#define _XE_FAULT_INJECT_TYPES_H_
+
+/**
+ * enum xe_fault_type - Fault injection types
+ * @XE_FAULT_GT_RESET: GT reset failure injection
+ * @XE_FAULT_CSC_HW_ERROR: CSC hardware error injection
+ * @XE_FAULT_MAX: Number of fault injection types
+ */
+enum xe_fault_type {
+	XE_FAULT_GT_RESET,
+	XE_FAULT_CSC_HW_ERROR,
+	XE_FAULT_MAX
+};
+
+#endif /* _XE_FAULT_INJECT_TYPES_H_ */
drivers/gpu/drm/xe/xe_gt.c +3 -2
index cdc678d1ae1f..f900c252a523 100644
@@ -23,6 +23,7 @@
  #include "xe_eu_stall.h"
  #include "xe_exec_queue.h"
  #include "xe_execlist.h"
+#include "xe_fault_inject.h"
  #include "xe_force_wake.h"
  #include "xe_ggtt.h"
  #include "xe_gsc.h"
@@ -923,7 +924,7 @@ static void gt_reset_worker(struct work_struct *w)
 
  	xe_gt_info(gt, "reset started\n");
 
-	if (xe_fault_inject_gt_reset()) {
+	if (xe_fault_inject(XE_FAULT_GT_RESET)) {
  		err = -ECANCELED;
  		goto err_fail;
  	}
@@ -980,7 +981,7 @@ void xe_gt_reset_async(struct xe_gt *gt)
  	xe_gt_info(gt, "trying reset from %ps\n", __builtin_return_address(0));
 
  	/* Don't do a reset while one is already in flight */
-	if (!xe_fault_inject_gt_reset() && xe_uc_reset_prepare(&gt->uc))
+	if (!xe_fault_inject(XE_FAULT_GT_RESET) && xe_uc_reset_prepare(&gt->uc))
  		return;
 
  	xe_gt_info(gt, "reset queued\n");
drivers/gpu/drm/xe/xe_gt.h +0 -8
index 4150aa594f05..f8e3ca63aabb 100644
@@ -6,8 +6,6 @@
  #ifndef _XE_GT_H_
  #define _XE_GT_H_
 
-#include <linux/fault-inject.h>
-
  #include <drm/drm_util.h>
 
  #include "xe_device.h"
@@ -38,12 +36,6 @@
  	xe_gt_is_media_type(gt_) ? MEDIA_VER(xe) : GRAPHICS_VER(xe); \
  })
 
-extern struct fault_attr gt_reset_failure;
-static inline bool xe_fault_inject_gt_reset(void)
-{
-	return IS_ENABLED(CONFIG_DEBUG_FS) && should_fail(&gt_reset_failure, 1);
-}
-
  struct xe_gt *xe_gt_alloc(struct xe_tile *tile);
  int xe_gt_init_early(struct xe_gt *gt);
  int xe_gt_init(struct xe_gt *gt);
drivers/gpu/drm/xe/xe_hw_error.c +2 -9
index 5135e8e4093f..192e68e847a5 100644
@@ -4,7 +4,6 @@
   */
 
  #include <linux/bitmap.h>
-#include <linux/fault-inject.h>
 
  #include "regs/xe_gsc_regs.h"
  #include "regs/xe_hw_error_regs.h"
@@ -12,6 +11,7 @@
 
  #include "xe_device.h"
  #include "xe_drm_ras.h"
+#include "xe_fault_inject.h"
  #include "xe_hw_error.h"
  #include "xe_mmio.h"
  #include "xe_survivability_mode.h"
@@ -25,8 +25,6 @@
  						 (PVC_COR_ERR_MASK & REG_BIT(err_bit)) : \
  						 (PVC_FAT_ERR_MASK & REG_BIT(err_bit)))
 
-extern struct fault_attr inject_csc_hw_error;
-
  static const char * const error_severity[] = DRM_XE_RAS_ERROR_SEVERITY_NAMES;
 
  static const char * const hec_uncorrected_fw_errors[] = {
@@ -167,11 +165,6 @@ static_assert(ARRAY_SIZE(pvc_master_local_nonfatal_err_reg) == XE_RAS_REG_SIZE);
  						 pvc_master_local_fatal_err_reg : \
  						 pvc_master_local_nonfatal_err_reg)
 
-static bool fault_inject_csc_hw_error(void)
-{
-	return IS_ENABLED(CONFIG_DEBUG_FS) && should_fail(&inject_csc_hw_error, 1);
-}
-
  static void csc_hw_error_work(struct work_struct *work)
  {
  	struct xe_tile *tile = container_of(work, typeof(*tile), csc_hw_error_work);
@@ -507,7 +500,7 @@ void xe_hw_error_irq_handler(struct xe_tile *tile, const u32 master_ctl)
  {
  	enum hardware_error hw_err;
 
-	if (fault_inject_csc_hw_error())
+	if (xe_fault_inject(XE_FAULT_CSC_HW_ERROR))
  		schedule_work(&tile->csc_hw_error_work);
 
  	for (hw_err = 0; hw_err < HARDWARE_ERROR_MAX; hw_err++) {
#4 lore raw

Hi Vinay,

Quoted 100 lines · Vinay
Quoted 98 lines · Mallesh Koujalagi

The fault injection code was scattered: the GT reset hook lived in xe_gt.h as an inline function with its own global variable, the CSC hook had a separate global in xe_hw_error.c with an extern declaration, and each was individually registered in xe_debugfs.c. Adding a new error type meant editing many files and copy-pasting the same boilerplate.

Create a single, centralized fault injection module (xe_fault_inject.c/h) that manages all fault types through one table. Each type is just an entry in an enum and a one-line row in a descriptor array -- no more scattered globals, externs, or per-type inline helpers.

Debugfs interface (under /sys/kernel/debug/dri/0/):
  - fail_gt_reset         - GT reset failure
  - inject_csc_hw_error   - CSC firmware error

---
v2:
- Add multiple platform support. (Vinay)
- Handle VF properly.
- Rename to XE_FAULT_GT_RESET/XE_FAULT_CSC_HW_ERROR and create xe_fault_inject_types.h file including those name.

v3:
- Solved patch apply issue on tip.

v4:
- Add proper header file.
---
  drivers/gpu/drm/xe/Makefile                |  1 + drivers/gpu/drm/xe/xe_debugfs.c            |  9 +-- drivers/gpu/drm/xe/xe_fault_inject.c       | 68 ++++++++++++++++++++++ drivers/gpu/drm/xe/xe_fault_inject.h       | 31 ++++++++++ drivers/gpu/drm/xe/xe_fault_inject_types.h | 21 +++++++ drivers/gpu/drm/xe/xe_gt.c                 |  5 +- drivers/gpu/drm/xe/xe_gt.h                 |  8 --- drivers/gpu/drm/xe/xe_hw_error.c           | 11 +---

  8 files changed, 128 insertions(+), 26 deletions(-)

  create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.c create mode 100644 drivers/gpu/drm/xe/xe_fault_inject.h create mode 100644 drivers/gpu/drm/xe/xe_fault_inject_types.h

drivers/gpu/drm/xe/Makefile +1 -0
index 09661f079d03..b36cf511a537 100644
@@ -351,6 +351,7 @@ endif
     ifeq ($(CONFIG_DEBUG_FS),y)
       xe-y += xe_debugfs.o \
+        xe_fault_inject.o \
           xe_gt_debugfs.o \
           xe_gt_sriov_vf_debugfs.o \
           xe_gt_stats.o \
drivers/gpu/drm/xe/xe_debugfs.c +2 -5
index 22b471303984..8402189b24ef 100644
@@ -6,7 +6,6 @@
   #include "xe_debugfs.h"
     #include <linux/debugfs.h>
-#include <linux/fault-inject.h>
   #include <linux/string_helpers.h>
     #include <drm/drm_debugfs.h>
@@ -14,6 +13,7 @@
   #include "regs/xe_pmt.h"
   #include "xe_bo.h"
   #include "xe_device.h"
+#include "xe_fault_inject.h"
   #include "xe_force_wake.h"
   #include "xe_gt.h"
   #include "xe_gt_debugfs.h"
@@ -38,9 +38,6 @@
   #include "xe_vm.h"
   #endif
   -DECLARE_FAULT_ATTR(gt_reset_failure);
-DECLARE_FAULT_ATTR(inject_csc_hw_error);
-
   static void read_residency_counter(struct xe_device *xe, struct xe_mmio *mmio,
                      u32 offset, const char *name, struct drm_printer *p)
   {
@@ -563,8 +560,6 @@ void xe_debugfs_register(struct xe_device *xe)
           drm_debugfs_create_files(debugfs_residencies,
                        ARRAY_SIZE(debugfs_residencies),
                        root, minor);
-        fault_create_debugfs_attr("inject_csc_hw_error", root,
-                      &inject_csc_hw_error);
       }
         debugfs_create_file("forcewake_all", 0400, root, xe,
@@ -610,7 +605,7 @@ void xe_debugfs_register(struct xe_device *xe)
         xe_psmi_debugfs_register(xe);
   -    fault_create_debugfs_attr("fail_gt_reset", root, &gt_reset_failure);
+    xe_fault_inject_debugfs_register(xe, root);
         if (IS_SRIOV_PF(xe))
           xe_sriov_pf_debugfs_register(xe, root);
drivers/gpu/drm/xe/xe_fault_inject.c new file +0 -0
new file mode 100644
Quoted 8 lines

drivers/gpu/drm/xe/xe_fault_inject.c line 3

Quoted 7 lines

index 000000000000..80811850a2ef

drivers/gpu/drm/xe/xe_fault_inject.c new file +3 -0
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2025 Intel Corporation

s/2025/2026 here and elsewhere.

Sure, I will update it.

Quoted 9 lines
Quoted 9 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +9 -0
+ */
+
+#include <linux/bits.h>
+#include <linux/fault-inject.h>
+
+#include "xe_device.h"
+#include "xe_fault_inject.h"
+#include "xe_platform_types.h"
+#include "xe_sriov.h"
Quoted 8 lines

drivers/gpu/drm/xe/xe_fault_inject.c line 19

Quoted 7 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +7 -0
+
+static struct {
+    const char *name;
+    u32 platforms;
+    bool skip_on_vf;
+    struct fault_attr attr;
+} xe_fault_inject_descs[XE_FAULT_MAX] = {

Nit: Descs are more for descriptors, maybe xe_fault_inject_entry?

Thanks for feedback!, you are right.  I'll will rename it to xe_fault_inject_entry.

Quoted 4 lines

drivers/gpu/drm/xe/xe_fault_inject.c line 21

Quoted 2 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +2 -0
+    [XE_FAULT_GT_RESET]    = { .name = "fail_gt_reset",
+                    .attr = FAULT_ATTR_INITIALIZER },

Should have some reference to the patch that introduces FAULT_ATTR_INITIALIZER. Can they both be in the same series?

Found out alternative solution by checking CONFIG_FAULT_INJECTION in header and Makefile files.

Thanks,

-/Mallesh

Quoted 217 lines

With the nits addressed and copyright year fixed, this patch is-

Quoted 212 lines
drivers/gpu/drm/xe/xe_fault_inject.c new file +23 -0
+    [XE_FAULT_CSC_HW_ERROR]    = { .name = "inject_csc_hw_error",
+                    .platforms = BIT(XE_BATTLEMAGE),
+                    .skip_on_vf = true,
+                    .attr = FAULT_ATTR_INITIALIZER },
+};
+
+/**
+ * xe_fault_inject - Check if a fault should be injected
+ * @type: fault injection type to check
+ *
+ * Returns true if a fault should be injected for the given type.
+ * Controlled via debugfs fault injection attributes.
+ */
+bool xe_fault_inject(enum xe_fault_type type)
+{
+    if (type >= XE_FAULT_MAX)
+        return false;
+
+    return should_fail(&xe_fault_inject_descs[type].attr, 1);
+}
+
+/**
+ * xe_fault_inject_debugfs_register - Register fault injection 

debugfs entries
+ * @xe: xe device instance
+ * @root: debugfs root directory
+ *
+ * Creates debugfs fault injection attributes for all supported fault
+ * injection types. Platform-specific entries are only registered on
+ * matching platforms. Entries marked skip_on_vf are not registered for
+ * SR-IOV VF devices.
+ */
+void xe_fault_inject_debugfs_register(struct xe_device *xe, struct dentry *root)

drivers/gpu/drm/xe/xe_fault_inject.c new file +9 -0
+{
+    int i;
+
+    for (i = 0; i < XE_FAULT_MAX; i++) {
+        if (IS_SRIOV_VF(xe) && xe_fault_inject_descs[i].skip_on_vf)
+            continue;
+
+        if (xe_fault_inject_descs[i].platforms &&
+            !(xe_fault_inject_descs[i].platforms & 

BIT(xe->info.platform)))
+            continue;

drivers/gpu/drm/xe/xe_fault_inject.c new file +5 -0
+
+ fault_create_debugfs_attr(xe_fault_inject_descs[i].name, root,
+                      &xe_fault_inject_descs[i].attr);
+    }
+}
drivers/gpu/drm/xe/xe_fault_inject.h new file +18 -0
new file mode 100644
index 000000000000..bc4d856407e8
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_H_
+#define _XE_FAULT_INJECT_H_
+
+#include <linux/types.h>
+
+#include "xe_fault_inject_types.h"
+
+struct xe_device;
+struct dentry;
+
+#ifdef CONFIG_DEBUG_FS
+bool xe_fault_inject(enum xe_fault_type type);
+void xe_fault_inject_debugfs_register(struct xe_device *xe, struct 

dentry *root);

drivers/gpu/drm/xe/xe_fault_inject.h new file +7 -0
+#else
+static inline bool xe_fault_inject(enum xe_fault_type type)
+{
+    return false;
+}
+
+static inline void xe_fault_inject_debugfs_register(struct xe_device 

*xe,
+                            struct dentry *root)

drivers/gpu/drm/xe/xe_fault_inject.h new file +5 -0
+{
+}
+#endif
+
+#endif /* _XE_FAULT_INJECT_H_ */
drivers/gpu/drm/xe/xe_fault_inject_types.h new file +21 -0
new file mode 100644
index 000000000000..cf0cd0974be1
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2025 Intel Corporation
+ */
+
+#ifndef _XE_FAULT_INJECT_TYPES_H_
+#define _XE_FAULT_INJECT_TYPES_H_
+
+/**
+ * enum xe_fault_type - Fault injection types
+ * @XE_FAULT_GT_RESET: GT reset failure injection
+ * @XE_FAULT_CSC_HW_ERROR: CSC hardware error injection
+ * @XE_FAULT_MAX: Number of fault injection types
+ */
+enum xe_fault_type {
+    XE_FAULT_GT_RESET,
+    XE_FAULT_CSC_HW_ERROR,
+    XE_FAULT_MAX
+};
+
+#endif /* _XE_FAULT_INJECT_TYPES_H_ */
drivers/gpu/drm/xe/xe_gt.c +3 -1
index cdc678d1ae1f..f900c252a523 100644
@@ -23,6 +23,7 @@
   #include "xe_eu_stall.h"
   #include "xe_exec_queue.h"
   #include "xe_execlist.h"
+#include "xe_fault_inject.h"
   #include "xe_force_wake.h"
   #include "xe_ggtt.h"
   #include "xe_gsc.h"
@@ -923,7 +924,7 @@ static void gt_reset_worker(struct work_struct *w)
         xe_gt_info(gt, "reset started\n");
   -    if (xe_fault_inject_gt_reset()) {
+    if (xe_fault_inject(XE_FAULT_GT_RESET)) {
           err = -ECANCELED;
           goto err_fail;
       }
@@ -980,7 +981,7 @@ void xe_gt_reset_async(struct xe_gt *gt)
       xe_gt_info(gt, "trying reset from %ps\n", __builtin_return_address(0));
         /* Don't do a reset while one is already in flight */
-    if (!xe_fault_inject_gt_reset() && xe_uc_reset_prepare(&gt->uc))
+    if (!xe_fault_inject(XE_FAULT_GT_RESET) && 
 xe_uc_reset_prepare(&gt->uc))
           return;
         xe_gt_info(gt, "reset queued\n");
drivers/gpu/drm/xe/xe_gt.h +0 -0
index 4150aa594f05..f8e3ca63aabb 100644
@@ -6,8 +6,6 @@
   #ifndef _XE_GT_H_
   #define _XE_GT_H_

  -#include <linux/fault-inject.h>
-
  #include <drm/drm_util.h>
    #include "xe_device.h"

drivers/gpu/drm/xe/xe_gt.h +0 -5
@@ -38,12 +36,6 @@
       xe_gt_is_media_type(gt_) ? MEDIA_VER(xe) : GRAPHICS_VER(xe); \
   })
   -extern struct fault_attr gt_reset_failure;
-static inline bool xe_fault_inject_gt_reset(void)
-{
-    return IS_ENABLED(CONFIG_DEBUG_FS) && 
 should_fail(&gt_reset_failure, 1);
-}
-
   struct xe_gt *xe_gt_alloc(struct xe_tile *tile);
   int xe_gt_init_early(struct xe_gt *gt);

  int xe_gt_init(struct xe_gt *gt);

drivers/gpu/drm/xe/xe_hw_error.c +1 -6
index 5135e8e4093f..192e68e847a5 100644
@@ -4,7 +4,6 @@
    */
     #include <linux/bitmap.h>
-#include <linux/fault-inject.h>
     #include "regs/xe_gsc_regs.h"
   #include "regs/xe_hw_error_regs.h"
@@ -12,6 +11,7 @@
     #include "xe_device.h"
   #include "xe_drm_ras.h"
+#include "xe_fault_inject.h"
   #include "xe_hw_error.h"
   #include "xe_mmio.h"
   #include "xe_survivability_mode.h"
@@ -25,8 +25,6 @@
                            (PVC_COR_ERR_MASK & REG_BIT(err_bit)) : \
                            (PVC_FAT_ERR_MASK & REG_BIT(err_bit)))
   -extern struct fault_attr inject_csc_hw_error;
-
   static const char * const error_severity[] = DRM_XE_RAS_ERROR_SEVERITY_NAMES;
     static const char * const hec_uncorrected_fw_errors[] = {
@@ -167,11 +165,6 @@ 
 static_assert(ARRAY_SIZE(pvc_master_local_nonfatal_err_reg) == XE_RAS_REG_SIZE);
                            pvc_master_local_fatal_err_reg : \
                            pvc_master_local_nonfatal_err_reg)
   -static bool fault_inject_csc_hw_error(void)
-{
-    return IS_ENABLED(CONFIG_DEBUG_FS) && 
 should_fail(&inject_csc_hw_error, 1);
-}
-
   static void csc_hw_error_work(struct work_struct *work)

  {
      struct xe_tile *tile = container_of(work, typeof(*tile), csc_hw_error_work);

drivers/gpu/drm/xe/xe_hw_error.c +1 -0
@@ -507,7 +500,7 @@ void xe_hw_error_irq_handler(struct xe_tile 
 *tile, const u32 master_ctl)
   {
       enum hardware_error hw_err;
   -    if (fault_inject_csc_hw_error())
+    if (xe_fault_inject(XE_FAULT_CSC_HW_ERROR))
           schedule_work(&tile->csc_hw_error_work);
         for (hw_err = 0; hw_err < HARDWARE_ERROR_MAX; hw_err++) {