Skip to contentSkip to conversation

drm/cma-helper: Release non-coherent memory with dma_free_noncoherent()

PATCH In review Thomas Zimmermann 2 participants 4 messages Jul 8, 2021 – Nov 12, 2021

Subsystems (2)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/cma-helper: Release non-coherent memory with dma_free_noncoherent()

The GEM CMA helpers allocate non-coherent (i.e., cached) backing storage with dma_alloc_noncoherent(), but release it with dma_free_wc(). Fix this with a call to dma_free_noncoherent(). Writecombining storage is still released with dma_free_wc().

Fixes cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory")
Cc Paul Cercueil <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_gem_cma_helper.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +7 -2
index d53388199f34..9d05674550a4 100644
@@ -210,8 +210,13 @@ void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
 			dma_buf_vunmap(gem_obj->import_attach->dmabuf, &map);
 		drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
 	} else if (cma_obj->vaddr) {
-		dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
-			    cma_obj->vaddr, cma_obj->paddr);
+		if (cma_obj->map_noncoherent)
+			dma_free_noncoherent(gem_obj->dev->dev, cma_obj->base.size,
+					     cma_obj->vaddr, cma_obj->paddr,
+					     DMA_TO_DEVICE);
+		else
+			dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
+				    cma_obj->vaddr, cma_obj->paddr);
 	}
 
 	drm_gem_object_release(gem_obj);
Signature · 1 line
2.32.0
author maintainer
#1 lore raw

Ping for review.

Am 08.07.21 um 19:51 schrieb Thomas Zimmermann:

Quoted 38 lines

The GEM CMA helpers allocate non-coherent (i.e., cached) backing storage with dma_alloc_noncoherent(), but release it with dma_free_wc(). Fix this with a call to dma_free_noncoherent(). Writecombining storage is still released with dma_free_wc().

Fixes cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory")
Cc Paul Cercueil <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_gem_cma_helper.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +7 -2
index d53388199f34..9d05674550a4 100644
@@ -210,8 +210,13 @@ void drm_gem_cma_free_object(struct drm_gem_object *gem_obj)
  			dma_buf_vunmap(gem_obj->import_attach->dmabuf, &map);
  		drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
  	} else if (cma_obj->vaddr) {
-		dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
-			    cma_obj->vaddr, cma_obj->paddr);
+		if (cma_obj->map_noncoherent)
+			dma_free_noncoherent(gem_obj->dev->dev, cma_obj->base.size,
+					     cma_obj->vaddr, cma_obj->paddr,
+					     DMA_TO_DEVICE);
+		else
+			dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
+				    cma_obj->vaddr, cma_obj->paddr);
  	}
 
  	drm_gem_object_release(gem_obj);
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Acked-by
#2 lore raw

Hi Thomas,

I never received the original patch and I can't find it online either?

Anyway:

Cheers,
-Paul

Quoted 50 lines · Thomas Zimmermann

Ping for review.

Am 08.07.21 um 19:51 schrieb Thomas Zimmermann:

Quoted 37 lines

The GEM CMA helpers allocate non-coherent (i.e., cached) backing storage with dma_alloc_noncoherent(), but release it with dma_free_wc(). Fix this with a call to dma_free_noncoherent(). Writecombining storage is still released with dma_free_wc().

Fixes cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory")
Cc Paul Cercueil <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
  drivers/gpu/drm/drm_gem_cma_helper.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +7 -2
index d53388199f34..9d05674550a4 100644
@@ -210,8 +210,13 @@ void drm_gem_cma_free_object(struct 
 drm_gem_object *gem_obj)
  			dma_buf_vunmap(gem_obj->import_attach->dmabuf, &map);
  		drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
  	} else if (cma_obj->vaddr) {
-		dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
-			    cma_obj->vaddr, cma_obj->paddr);
+		if (cma_obj->map_noncoherent)
+			dma_free_noncoherent(gem_obj->dev->dev, cma_obj->base.size,
+					     cma_obj->vaddr, cma_obj->paddr,
+					     DMA_TO_DEVICE);
+		else
+			dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
+				    cma_obj->vaddr, cma_obj->paddr);
  	}
 
Quoted 2 lines
  	drm_gem_object_release(gem_obj);

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

author maintainer
#3 lore raw

Hi Paul

Am 12.11.21 um 16:26 schrieb Paul Cercueil:

Quoted 3 lines

Hi Thomas,

I never received the original patch and I can't find it online either?

It was posted a while ago [1] and got lost. I remember that you had a problem with your email setup. Maybe that's why you didn't see it.

Quoted 3 lines

Anyway:

Thanks a lot.

Best regards
Thomas

[1] https://lore.kernel.org/dri-devel/[email protected]/

Quoted 58 lines

Cheers,
-Paul

Quoted 50 lines · Thomas Zimmermann

Ping for review.

Am 08.07.21 um 19:51 schrieb Thomas Zimmermann:

Quoted 39 lines

The GEM CMA helpers allocate non-coherent (i.e., cached) backing storage with dma_alloc_noncoherent(), but release it with dma_free_wc(). Fix this with a call to dma_free_noncoherent(). Writecombining storage is still released with dma_free_wc().

Fixes cf8ccbc72d61 ("drm: Add support for GEM buffers backed by non-coherent memory")
Cc Paul Cercueil <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>

---
  drivers/gpu/drm/drm_gem_cma_helper.c | 9 +++++++--

  1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_gem_cma_helper.c +7 -2
index d53388199f34..9d05674550a4 100644
@@ -210,8 +210,13 @@ void drm_gem_cma_free_object(struct 
 drm_gem_object *gem_obj)
               dma_buf_vunmap(gem_obj->import_attach->dmabuf, &map);
           drm_prime_gem_destroy(gem_obj, cma_obj->sgt);
       } else if (cma_obj->vaddr) {
-        dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
-                cma_obj->vaddr, cma_obj->paddr);
+        if (cma_obj->map_noncoherent)
+            dma_free_noncoherent(gem_obj->dev->dev, cma_obj->base.size,
+                         cma_obj->vaddr, cma_obj->paddr,
+                         DMA_TO_DEVICE);
+        else
+            dma_free_wc(gem_obj->dev->dev, cma_obj->base.size,
+                    cma_obj->vaddr, cma_obj->paddr);
       }
 

      drm_gem_object_release(gem_obj);

Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev