]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/exec, drm/xe: Avoid abusing the drm_exec retry pointer
authorThomas Hellström <thomas.hellstrom@linux.intel.com>
Wed, 20 May 2026 10:16:15 +0000 (12:16 +0200)
committerThomas Hellström <thomas.hellstrom@linux.intel.com>
Mon, 25 May 2026 08:45:38 +0000 (10:45 +0200)
The xe driver was using the drm_exec retry pointer directly to
restart the locking loop after out-of-memory errors. This is
relying on undocumented behaviour.

Instead add a drm_exec_retry() macro that can be used in this
situation, and that also warns if the struct drm_exec is
not newly (re-)initialized.

Use that macro in xe.

v2:
- Only allow if the drm_exec context is newly initialized.
  (Christian)

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patch.msgid.link/20260520101616.41284-4-thomas.hellstrom@linux.intel.com
drivers/gpu/drm/drm_exec.c
drivers/gpu/drm/xe/xe_validation.h
include/drm/drm_exec.h

index 746210f3f6c2829967b552485114bf8c8b49e654..7988f5e7d56a3e1c25528d468fe77cba737728d0 100644 (file)
@@ -48,9 +48,6 @@
  * See struct dma_exec for more details.
  */
 
-/* Dummy value used to initially enter the retry loop */
-#define DRM_EXEC_DUMMY ((void *)~0)
-
 /* Unlock all objects and drop references */
 static void drm_exec_unlock_all(struct drm_exec *exec)
 {
index a30e732c4d51e9aade219766254395e9e57aebe6..4cd955ce6cd2c80d8d5922ac16d7906266f5e2e2 100644 (file)
@@ -146,7 +146,7 @@ bool xe_validation_should_retry(struct xe_validation_ctx *ctx, int *ret);
 #define xe_validation_retry_on_oom(_ctx, _ret)                         \
        do {                                                            \
                if (xe_validation_should_retry(_ctx, _ret))             \
-                       goto *__drm_exec_retry_ptr;                     \
+                       drm_exec_retry((_ctx)->exec);                   \
        } while (0)
 
 /**
index 18f84faabbb9e181d54af61aec36bdf93221b074..99c7e1bb3c5b3d6f662682b962db232ec47a4d5c 100644 (file)
@@ -9,6 +9,12 @@
 #define DRM_EXEC_INTERRUPTIBLE_WAIT    BIT(0)
 #define DRM_EXEC_IGNORE_DUPLICATES     BIT(1)
 
+/*
+ * Dummy value used to initially enter the retry loop.
+ * internal use only.
+ */
+#define DRM_EXEC_DUMMY ((void *)~0)
+
 struct drm_gem_object;
 
 /**
@@ -142,6 +148,19 @@ static inline bool drm_exec_is_contended(struct drm_exec *exec)
        return !!exec->contended;
 }
 
+/**
+ * drm_exec_retry() - Unconditionally restart the loop to grab all locks.
+ * @exec: drm_exec object
+ *
+ * Unconditionally retry the loop to lock all objects. For consistency,
+ * the exec object needs to be newly initialized.
+ */
+#define drm_exec_retry(_exec)                                  \
+       do {                                                    \
+               WARN_ON((_exec)->contended != DRM_EXEC_DUMMY);  \
+               goto *__drm_exec_retry_ptr;                     \
+       } while (0)
+
 void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr);
 void drm_exec_fini(struct drm_exec *exec);
 bool drm_exec_cleanup(struct drm_exec *exec);