Skip to contentSkip to conversation

drm/shmem-helper: Fix unsetting shmem vaddr while vmap refcount > 0

PATCH Applied Dmitry Osipenko 3 participants 4 messages Apr 3, 2025 – Apr 4, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/shmem-helper: Fix unsetting shmem vaddr while vmap refcount > 0

We switched to use refcount_t for vmaps and missed to change the vunmap code to properly unset the vmap pointer, which is now cleared while vmap's refcount > 0. Clear the cached vmap pointer only when refcounting drops to zero to fix the bug.

---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -2
index 2d924d547a51..aa43265f4f4f 100644
@@ -415,11 +415,11 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 
 		if (refcount_dec_and_test(&shmem->vmap_use_count)) {
 			vunmap(shmem->vaddr);
+			shmem->vaddr = NULL;
+
 			drm_gem_shmem_unpin_locked(shmem);
 		}
 	}
-
-	shmem->vaddr = NULL;
 }
 EXPORT_SYMBOL_GPL(drm_gem_shmem_vunmap_locked);
 
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · On Thu, 3 Apr 2025 17:26:33 +0300 Dmitry Osipenko…

We switched to use refcount_t for vmaps and missed to change the vunmap code to properly unset the vmap pointer, which is now cleared while vmap's refcount > 0. Clear the cached vmap pointer only when refcounting drops to zero to fix the bug.

Quoted 22 lines
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -2
index 2d924d547a51..aa43265f4f4f 100644
@@ -415,11 +415,11 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 
 		if (refcount_dec_and_test(&shmem->vmap_use_count)) {
 			vunmap(shmem->vaddr);
+			shmem->vaddr = NULL;
+
 			drm_gem_shmem_unpin_locked(shmem);
 		}
 	}
-
-	shmem->vaddr = NULL;
 }
 EXPORT_SYMBOL_GPL(drm_gem_shmem_vunmap_locked);
 
Tested-by on v1 1/1
#2 lore raw
In reply to Dmitry Osipenko
Quoted 9 lines · Dmitry Osipenko

We switched to use refcount_t for vmaps and missed to change the vunmap code to properly unset the vmap pointer, which is now cleared while vmap's refcount > 0. Clear the cached vmap pointer only when refcounting drops to zero to fix the bug.

this fixes it for me when using qemu ... -device cirrus-vga

thanks
Lucas De Marchi

author Applied
#3 lore raw
In reply to Dmitry Osipenko
Quoted 21 lines · Dmitry Osipenko

We switched to use refcount_t for vmaps and missed to change the vunmap code to properly unset the vmap pointer, which is now cleared while vmap's refcount > 0. Clear the cached vmap pointer only when refcounting drops to zero to fix the bug.

---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +0 -0
index 2d924d547a51..aa43265f4f4f 100644
@@ -415,11 +415,11 @@ void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 
 		if (refcount_dec_and_test(&shmem->vmap_use_count)) {
 			vunmap(shmem->vaddr);

drivers/gpu/drm/drm_gem_shmem_helper.c void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem, · line 425

Quoted 10 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -2
+			shmem->vaddr = NULL;
+
 			drm_gem_shmem_unpin_locked(shmem);
 		}
 	}
-
-	shmem->vaddr = NULL;
 }
 EXPORT_SYMBOL_GPL(drm_gem_shmem_vunmap_locked);
 

Applied to misc-next

Signature · 2 lines
Best regards,
Dmitry