]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/xe/lrc: Allow to add user commands on context switch
authorLucas De Marchi <lucas.demarchi@intel.com>
Tue, 16 Sep 2025 21:15:40 +0000 (14:15 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Thu, 18 Sep 2025 21:20:39 +0000 (14:20 -0700)
During validation it's useful to allows additional commands to be
executed on context switch. Fetch the commands from configfs (to be
added) and add them to the WA BB.

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/20250916-wa-bb-cmds-v5-3-306bddbc15da@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_configfs.c
drivers/gpu/drm/xe/xe_configfs.h
drivers/gpu/drm/xe/xe_lrc.c

index 45fdb6cf26b5d6be0c8550b18fe11ca3f9b1611f..d86c75af032781810eb67434b534380f2f8f5193 100644 (file)
@@ -633,6 +633,19 @@ bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev)
        return ret;
 }
 
+/**
+ * xe_configfs_get_ctx_restore_post_bb - get configfs ctx_restore_post_bb setting
+ * @pdev: pci device
+ *
+ * Return: post_ctx_restore setting in configfs
+ */
+u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev,
+                                       enum xe_engine_class class,
+                                       const u32 **cs)
+{
+       return 0;
+}
+
 int __init xe_configfs_init(void)
 {
        int ret;
index 1402e863b71c0d8d0013c885ec6ac19699d37cfe..eff2645b5f59313c6ca31d1a3cf34bea40e408c0 100644 (file)
@@ -8,6 +8,8 @@
 #include <linux/limits.h>
 #include <linux/types.h>
 
+#include <xe_hw_engine_types.h>
+
 struct pci_dev;
 
 #if IS_ENABLED(CONFIG_CONFIGFS_FS)
@@ -17,6 +19,8 @@ void xe_configfs_check_device(struct pci_dev *pdev);
 bool xe_configfs_get_survivability_mode(struct pci_dev *pdev);
 u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev);
 bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev);
+u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
+                                       const u32 **cs);
 #else
 static inline int xe_configfs_init(void) { return 0; }
 static inline void xe_configfs_exit(void) { }
@@ -24,6 +28,8 @@ static inline void xe_configfs_check_device(struct pci_dev *pdev) { }
 static inline bool xe_configfs_get_survivability_mode(struct pci_dev *pdev) { return false; }
 static inline u64 xe_configfs_get_engines_allowed(struct pci_dev *pdev) { return U64_MAX; }
 static inline bool xe_configfs_get_psmi_enabled(struct pci_dev *pdev) { return false; }
+static inline u32 xe_configfs_get_ctx_restore_post_bb(struct pci_dev *pdev, enum xe_engine_class,
+                                                     const u32 **cs) { return 0; }
 #endif
 
 #endif
index 6d52e0eb97f54f2110998776d47b7dc7a624bf03..c706585611d55197a891ec436580b0a98020e31c 100644 (file)
@@ -8,6 +8,7 @@
 #include <generated/xe_wa_oob.h>
 
 #include <linux/ascii85.h>
+#include <linux/panic.h>
 
 #include "instructions/xe_mi_commands.h"
 #include "instructions/xe_gfxpipe_commands.h"
@@ -16,6 +17,7 @@
 #include "regs/xe_lrc_layout.h"
 #include "xe_bb.h"
 #include "xe_bo.h"
+#include "xe_configfs.h"
 #include "xe_device.h"
 #include "xe_drm_client.h"
 #include "xe_exec_queue_types.h"
@@ -1102,6 +1104,35 @@ static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
        return cmd - batch;
 }
 
+static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc,
+                                                 struct xe_hw_engine *hwe,
+                                                 u32 *batch, size_t max_len)
+{
+       struct xe_device *xe = gt_to_xe(lrc->gt);
+       const u32 *user_batch;
+       u32 *cmd = batch;
+       u32 count;
+
+       count = xe_configfs_get_ctx_restore_post_bb(to_pci_dev(xe->drm.dev),
+                                                   hwe->class, &user_batch);
+       if (!count)
+               return 0;
+
+       if (count > max_len)
+               return -ENOSPC;
+
+       /*
+        * This should be used only for tests and validation. Taint the kernel
+        * as anything could be submitted directly in context switches
+        */
+       add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
+
+       memcpy(cmd, user_batch, count * sizeof(u32));
+       cmd += count;
+
+       return cmd - batch;
+}
+
 static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc,
                                               struct xe_hw_engine *hwe,
                                               u32 *batch, size_t max_len)
@@ -1203,6 +1234,7 @@ int xe_lrc_setup_wa_bb_with_scratch(struct xe_lrc *lrc, struct xe_hw_engine *hwe
                { .setup = setup_timestamp_wa },
                { .setup = setup_invalidate_state_cache_wa },
                { .setup = setup_utilization_wa },
+               { .setup = setup_configfs_post_ctx_restore_bb },
        };
        struct bo_setup_state state = {
                .lrc = lrc,