]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: Fix lockdep false positive in amdgpu_lockdep_init
authorVitaly Prosyak <vitaly.prosyak@amd.com>
Sat, 1 Aug 2026 00:18:20 +0000 (20:18 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 6 Aug 2026 18:32:11 +0000 (14:32 -0400)
Move fs_reclaim_acquire() to before all lock acquisitions to eliminate
false positive circular locking dependency warning.

This is a 7.2-cycle regression fix suitable for stable backport.

v3: Address Mikhail Gavrilov technical review:
    - Clarify that fs_reclaim_acquire/release pair only REGISTERS the
      fs_reclaim lock class, does NOT create a static edge when called
      with no locks held
    - Explain that the actual fs_reclaim -> notifier_lock edge is
      established at runtime during memory reclaim -> MMU notifier path
    - Add Cc: Arunpravin PaneerSelvam

v2: Address Mikhail Gavrilov review feedback:
    - Fix author name: Michael -> Mikhail Gavrilov in all trailers
    - Add Fixes: tag to link regression to original commit
    - Add Tested-by: Mikhail Gavrilov (tested on RX 7900 XTX)

Fixes: 1d0f5838b126 ("drm/amdgpu: Add lockdep annotations for lock ordering validation")
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Analyzed-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Test-case-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Tested-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Suggested-by: Christian König <christian.koenig@amd.com>
Tested-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Cc: Arunpravin PaneerSelvam <Arunpravin.PaneerSelvam@amd.com>
Signed-off-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
Acked-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 70a1e9849e6ed12bb9f1c0faa24b0f1f9de601eb)
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/amdgpu_lockdep.c

index 61450af539a67d16c117d9010cfb527758c115e4..d5787d848d04407211e18ce583a4282ff0a2a31d 100644 (file)
@@ -135,6 +135,21 @@ int amdgpu_lockdep_init(void)
        lockdep_set_class(&locks->srbm_mutex, &amdgpu_srbm_lock_key);
        lockdep_set_class(&locks->grbm_idx_mutex, &amdgpu_grbm_lock_key);
        lockdep_set_class(&locks->mmio_idx_lock, &amdgpu_mmio_lock_key);
+
+       /*
+        * Register fs_reclaim lock class FIRST, before taking any locks.
+        *
+        * This acquire/release pair does NOT create a static lockdep edge
+        * (no locks are held between acquire and release). It only registers
+        * the fs_reclaim lock class with lockdep.
+        *
+        * The actual fs_reclaim -> notifier_lock dependency is established at
+        * RUNTIME when memory reclaim invokes MMU notifiers:
+        *   fs_reclaim (held by reclaim) -> notifier_lock (acquired in callback)
+        */
+       fs_reclaim_acquire(GFP_KERNEL);
+       fs_reclaim_release(GFP_KERNEL);
+
        /*
         * Take locks in the correct order to train lockdep.
         * This establishes the dependency chain.
@@ -154,11 +169,6 @@ int amdgpu_lockdep_init(void)
 
        /* Level 6: Reset control lock */
        mutex_lock(&locks->reset_lock);
-       /*
-        * Mark potential memory reclaim boundary.
-        * GPU operations might trigger memory allocation/reclaim.
-        */
-       fs_reclaim_acquire(GFP_KERNEL);
 
        /* Level 7: SRBM register access */
        mutex_lock(&locks->srbm_mutex);
@@ -176,7 +186,6 @@ int amdgpu_lockdep_init(void)
        spin_unlock_irqrestore(&locks->mmio_idx_lock, flags);
        mutex_unlock(&locks->grbm_idx_mutex);
        mutex_unlock(&locks->srbm_mutex);
-       fs_reclaim_release(GFP_KERNEL);
 
        mutex_unlock(&locks->reset_lock);
        up_read(&reset_domain->sem);