Skip to contentSkip to conversation

drm/pagemap_util: Ensure proper cache lock management on free

PATCH Superseded Jonathan Cavitt 2 participants 3 messages Feb 24

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/pagemap_util: Ensure proper cache lock management on free

Static analysis issue:

Though probably unnecessary given the cache is being freed at this step, for the sake of consistency, ensure that the cache lock is always unlocked after drm_pagemap_cache_fini.

v2:
- Use requested code flow (Maarten)

Fixes 77f14f2f2d73f ("drm/pagemap: Add a drm_pagemap cache and shrinker")
Cc Thomas Hellstrom <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Maarten Lankhorst <[email protected]>
---
 drivers/gpu/drm/drm_pagemap_util.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_pagemap_util.c +4 -9
index 14ddb948a32e..66203a19f8f6 100644
@@ -65,18 +65,13 @@ static void drm_pagemap_cache_fini(void *arg)
 	drm_dbg(cache->shrinker->drm, "Destroying dpagemap cache.\n");
 	spin_lock(&cache->lock);
 	dpagemap = cache->dpagemap;
-	if (!dpagemap) {
-		spin_unlock(&cache->lock);
-		goto out;
-	}
+	if (dpagemap && !drm_pagemap_shrinker_cancel(dpagemap))
+		dpagemap = NULL;
+	spin_unlock(&cache->lock);
 
-	if (drm_pagemap_shrinker_cancel(dpagemap)) {
-		cache->dpagemap = NULL;
-		spin_unlock(&cache->lock);
+	if (dpagemap)
 		drm_pagemap_destroy(dpagemap, false);
-	}
 
-out:
 	mutex_destroy(&cache->lookup_mutex);
 	kfree(cache);
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 29 lines · Jonathan Cavitt

Static analysis issue:

Though probably unnecessary given the cache is being freed at this step, for the sake of consistency, ensure that the cache lock is always unlocked after drm_pagemap_cache_fini.

v2:
- Use requested code flow (Maarten)

Fixes 77f14f2f2d73f ("drm/pagemap: Add a drm_pagemap cache and shrinker")
Cc Thomas Hellstrom <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Maarten Lankhorst <[email protected]>
---
 drivers/gpu/drm/drm_pagemap_util.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_pagemap_util.c +0 -3
index 14ddb948a32e..66203a19f8f6 100644
@@ -65,18 +65,13 @@ static void drm_pagemap_cache_fini(void *arg)
 	drm_dbg(cache->shrinker->drm, "Destroying dpagemap cache.\n");
 	spin_lock(&cache->lock);
 	dpagemap = cache->dpagemap;
-	if (!dpagemap) {
-		spin_unlock(&cache->lock);
-		goto out;

drivers/gpu/drm/drm_pagemap_util.c static void drm_pagemap_cache_fini(void *arg) · line 73

Quoted 10 lines
drivers/gpu/drm/drm_pagemap_util.c +4 -4
-	}
+	if (dpagemap && !drm_pagemap_shrinker_cancel(dpagemap))
+		dpagemap = NULL;
+	spin_unlock(&cache->lock);
 
-	if (drm_pagemap_shrinker_cancel(dpagemap)) {
-		cache->dpagemap = NULL;
-		spin_unlock(&cache->lock);
+	if (dpagemap)
 		drm_pagemap_destroy(dpagemap, false);

The logic is different here as 'cache->dpagemap' never gets set to NULL under cache->lock when drm_pagemap_shrinker_cancel returns true.

Also be sure to include intel-xe list for CI too.

Matt

Quoted 9 lines
drivers/gpu/drm/drm_pagemap_util.c +0 -2
-	}
 
-out:
 	mutex_destroy(&cache->lookup_mutex);
 	kfree(cache);
 }
Signature · 1 line
2.43.0
#2 lore raw

-----Original Message-----
From: Brost, Matthew <[email protected]>
Sent: Tuesday, February 24, 2026 3:12 PM
To: Cavitt, Jonathan <[email protected]>
Cc: [email protected]; Gupta, Saurabhg <[email protected]>; Zuo, Alex <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2] drm/pagemap_util: Ensure proper cache lock management on free

Quoted 36 lines · Jonathan Cavitt
Quoted 34 lines

Static analysis issue:

Though probably unnecessary given the cache is being freed at this step, for the sake of consistency, ensure that the cache lock is always unlocked after drm_pagemap_cache_fini.

v2:
- Use requested code flow (Maarten)

Fixes 77f14f2f2d73f ("drm/pagemap: Add a drm_pagemap cache and shrinker")
Cc Thomas Hellstrom <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Maarten Lankhorst <[email protected]>
---
 drivers/gpu/drm/drm_pagemap_util.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/drm_pagemap_util.c +3 -4
index 14ddb948a32e..66203a19f8f6 100644
@@ -65,18 +65,13 @@ static void drm_pagemap_cache_fini(void *arg)
 	drm_dbg(cache->shrinker->drm, "Destroying dpagemap cache.\n");
 	spin_lock(&cache->lock);
 	dpagemap = cache->dpagemap;
-	if (!dpagemap) {
-		spin_unlock(&cache->lock);
-		goto out;
-	}
+	if (dpagemap && !drm_pagemap_shrinker_cancel(dpagemap))
+		dpagemap = NULL;
+	spin_unlock(&cache->lock);
 
Quoted 8 lines

drivers/gpu/drm/drm_pagemap_util.c static void drm_pagemap_cache_fini(void *arg) · line 73

Quoted 5 lines
drivers/gpu/drm/drm_pagemap_util.c +1 -3
-	if (drm_pagemap_shrinker_cancel(dpagemap)) {
-		cache->dpagemap = NULL;
-		spin_unlock(&cache->lock);
+	if (dpagemap)
 		drm_pagemap_destroy(dpagemap, false);

The logic is different here as 'cache->dpagemap' never gets set to NULL under cache->lock when drm_pagemap_shrinker_cancel returns true.

I forgot to add this back in as a part of the v2 request, although in this case, cache->dpagemap = NULL can just be assigned as such without checking the return of drm_pagemap_shrinker_cancel.
I'll fix this for V3 and add the intel-xe list at that time. Thank you.

-Jonathan Cavitt

Quoted 15 lines

Also be sure to include intel-xe list for CI too.

Matt

Quoted 9 lines
drivers/gpu/drm/drm_pagemap_util.c +0 -2
-	}
 
-out:
 	mutex_destroy(&cache->lookup_mutex);
 	kfree(cache);
 }
Signature · 1 line
2.43.0