]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Move GGTT lock init to alloc
authorMatthew Brost <matthew.brost@intel.com>
Wed, 8 Oct 2025 21:45:10 +0000 (14:45 -0700)
committerMatthew Brost <matthew.brost@intel.com>
Thu, 9 Oct 2025 10:22:30 +0000 (03:22 -0700)
The GGTT lock is needed very early during GT initialization for a VF;
move the GGTT lock initialization to the allocation phase.

v8:
 - Rework function structure (Michal)

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Link: https://lore.kernel.org/r/20251008214532.3442967-13-matthew.brost@intel.com
drivers/gpu/drm/xe/xe_ggtt.c

index 7fdd0a97a6281148e8e468d2f57f17e3c5a5be70..aca7ae5489b91b81f7c3ad4415a0533449c72e07 100644 (file)
@@ -159,6 +159,16 @@ static void xe_ggtt_clear(struct xe_ggtt *ggtt, u64 start, u64 size)
        }
 }
 
+static void primelockdep(struct xe_ggtt *ggtt)
+{
+       if (!IS_ENABLED(CONFIG_LOCKDEP))
+               return;
+
+       fs_reclaim_acquire(GFP_KERNEL);
+       might_lock(&ggtt->lock);
+       fs_reclaim_release(GFP_KERNEL);
+}
+
 /**
  * xe_ggtt_alloc - Allocate a GGTT for a given &xe_tile
  * @tile: &xe_tile
@@ -169,9 +179,19 @@ static void xe_ggtt_clear(struct xe_ggtt *ggtt, u64 start, u64 size)
  */
 struct xe_ggtt *xe_ggtt_alloc(struct xe_tile *tile)
 {
-       struct xe_ggtt *ggtt = drmm_kzalloc(&tile_to_xe(tile)->drm, sizeof(*ggtt), GFP_KERNEL);
-       if (ggtt)
-               ggtt->tile = tile;
+       struct xe_device *xe = tile_to_xe(tile);
+       struct xe_ggtt *ggtt;
+
+       ggtt = drmm_kzalloc(&xe->drm, sizeof(*ggtt), GFP_KERNEL);
+       if (!ggtt)
+               return NULL;
+
+       if (drmm_mutex_init(&xe->drm, &ggtt->lock))
+               return NULL;
+
+       primelockdep(ggtt);
+       ggtt->tile = tile;
+
        return ggtt;
 }
 
@@ -180,7 +200,6 @@ static void ggtt_fini_early(struct drm_device *drm, void *arg)
        struct xe_ggtt *ggtt = arg;
 
        destroy_workqueue(ggtt->wq);
-       mutex_destroy(&ggtt->lock);
        drm_mm_takedown(&ggtt->mm);
 }
 
@@ -198,16 +217,6 @@ void xe_ggtt_might_lock(struct xe_ggtt *ggtt)
 }
 #endif
 
-static void primelockdep(struct xe_ggtt *ggtt)
-{
-       if (!IS_ENABLED(CONFIG_LOCKDEP))
-               return;
-
-       fs_reclaim_acquire(GFP_KERNEL);
-       might_lock(&ggtt->lock);
-       fs_reclaim_release(GFP_KERNEL);
-}
-
 static const struct xe_ggtt_pt_ops xelp_pt_ops = {
        .pte_encode_flags = xelp_ggtt_pte_flags,
        .ggtt_set_pte = xe_ggtt_set_pte,
@@ -227,8 +236,6 @@ static void __xe_ggtt_init_early(struct xe_ggtt *ggtt, u32 reserved)
 {
        drm_mm_init(&ggtt->mm, reserved,
                    ggtt->size - reserved);
-       mutex_init(&ggtt->lock);
-       primelockdep(ggtt);
 }
 
 int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 reserved, u32 size)