Skip to contentSkip to conversation

drm/shmem-helpers: vunmap: Don't put pages for dma-buf

PATCH In review Noralf Trønnes 4 participants 9 messages Feb 19, 2021 – Feb 25, 2021

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

PATCH 1/1 drm/shmem-helpers: vunmap: Don't put pages for dma-buf

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -3
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
 	if (--shmem->vmap_use_count > 0)
 		return;
 
-	if (obj->import_attach)
+	if (obj->import_attach) {
 		dma_buf_vunmap(obj->import_attach->dmabuf, map);
-	else
+	} else {
 		vunmap(shmem->vaddr);
+		drm_gem_shmem_put_pages(shmem);
+	}
 
 	shmem->vaddr = NULL;
-	drm_gem_shmem_put_pages(shmem);
 }
 
 /*
Signature · 6 lines
2.23.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by Tested-by on v1 1/1
#1 lore raw

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>

Just when I saw the error. Nice. :)

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 27 lines
---
  drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -3
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,
  	if (--shmem->vmap_use_count > 0)
  		return;
 
-	if (obj->import_attach)
+	if (obj->import_attach) {
  		dma_buf_vunmap(obj->import_attach->dmabuf, map);
-	else
+	} else {
  		vunmap(shmem->vaddr);
+		drm_gem_shmem_put_pages(shmem);
+	}
 
  	shmem->vaddr = NULL;
-	drm_gem_shmem_put_pages(shmem);
  }
 
  /*
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: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 15 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Quoted 5 lines

Just when I saw the error. Nice. :)

Should I apply this to drm-misc-fixes?

Noralf.

Quoted 27 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 18 lines

---
  drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---

  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -1
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
       if (--shmem->vmap_use_count > 0)
           return;
   -    if (obj->import_attach)
+    if (obj->import_attach) {
           dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
Quoted 9 lines

drivers/gpu/drm/drm_gem_shmem_helper.c static void drm_gem_shmem_vunmap_locked(struct drm_gem_shmem_object *shmem,

Quoted 8 lines
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -1
           vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
         shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
   }
     /*
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Hi

Am 24.02.21 um 18:14 schrieb Noralf Trønnes:

Quoted 18 lines

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 15 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Quoted 7 lines
Quoted 5 lines

Just when I saw the error. Nice. :)

Should I apply this to drm-misc-fixes?

I think so. Ping me if you want me to add it.

Best regards
Thomas

Quoted 39 lines

Noralf.

Quoted 36 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines
---
   drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
       if (--shmem->vmap_use_count > 0)
           return;
   -    if (obj->import_attach)
+    if (obj->import_attach) {
           dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
           vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
         shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
   }
     /*
 
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: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Den 25.02.2021 09.12, skrev Thomas Zimmermann:

Quoted 24 lines

Hi

Am 24.02.21 um 18:14 schrieb Noralf Trønnes:

Quoted 21 lines

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 18 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 8 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also
on dma-bufs. Fix this by only putting pages if it's not imported.

Quoted 4 lines
Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>

Just when I saw the error. Nice. :)

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Should I apply this to drm-misc-fixes?

I think so. Ping me if you want me to add it.

I'd appreciate if you could do it. I haven't applied a patch in almost a year now and need to dig out my notes on how I do it. -fixes stuff is for me a "hold my breath and hope I don't screw up anything" exercise. Stressful :/

One day in the future I hope there's a green button I can push that
says: Merge patch to -fixes and make sure everything is OK. That would be nice :)

Thanks,
Noralf.

Quoted 44 lines

Best regards
Thomas

Quoted 40 lines

Noralf.

Quoted 37 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines

---
   drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---

   1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
        if (--shmem->vmap_use_count > 0)
            return;
    -    if (obj->import_attach)
+    if (obj->import_attach) {
            dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
            vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
          shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
    }
      /*
 

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Am 25.02.21 um 10:25 schrieb Noralf Trønnes:

Quoted 33 lines

Den 25.02.2021 09.12, skrev Thomas Zimmermann:

Quoted 30 lines

Hi

Am 24.02.21 um 18:14 schrieb Noralf Trønnes:

Quoted 26 lines

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 16 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 8 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also
on dma-bufs. Fix this by only putting pages if it's not imported.

Quoted 4 lines
Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Quoted 5 lines

Just when I saw the error. Nice. :)

Should I apply this to drm-misc-fixes?

Quoted 7 lines
Quoted 2 lines

I think so. Ping me if you want me to add it.

I'd appreciate if you could do it. I haven't applied a patch in almost a year now and need to dig out my notes on how I do it. -fixes stuff is for me a "hold my breath and hope I don't screw up anything" exercise. Stressful :/

Applied now to drm-misc-next. If it breaks, I'll also take the blame. :) I took the liberty of moving your S-o-b line to the top of the tag. IIRC this is the preferred style. Thanks again for the fix.

Best regards
Thomas

Quoted 52 lines

One day in the future I hope there's a green button I can push that
says: Merge patch to -fixes and make sure everything is OK. That would be nice :)

Thanks,
Noralf.

Quoted 44 lines

Best regards
Thomas

Quoted 40 lines

Noralf.

Quoted 37 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines
---
    drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
    1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
        if (--shmem->vmap_use_count > 0)
            return;
    -    if (obj->import_attach)
+    if (obj->import_attach) {
            dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
            vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
          shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
    }
      /*
 
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: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw
In reply to Noralf Trønnes
Quoted 19 lines · Noralf Trønnes

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 15 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>
Quoted 7 lines
Quoted 5 lines

Just when I saw the error. Nice. :)

Should I apply this to drm-misc-fixes?

drm-misc-next-fixes because we're in the merge window. -Daniel

Quoted 39 lines

Noralf.

Quoted 36 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines
---
  drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
  1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
      if (--shmem->vmap_use_count > 0)
          return;
  -    if (obj->import_attach)
+    if (obj->import_attach) {
          dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
          vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
        shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
  }
    /*
 
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Hi

Am 25.02.21 um 10:43 schrieb Daniel Vetter:

Quoted 22 lines · Noralf Trønnes
Quoted 21 lines

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 17 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>

Just when I saw the error. Nice. :)

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Should I apply this to drm-misc-fixes?

drm-misc-next-fixes because we're in the merge window.

Too late. Can/should I cherry-pick the patch from drm-misc-next?

Best regards
Thomas

Quoted 44 lines

-Daniel

Quoted 39 lines

Noralf.

Quoted 36 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines
---
   drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
       if (--shmem->vmap_use_count > 0)
           return;
   -    if (obj->import_attach)
+    if (obj->import_attach) {
           dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
           vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
         shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
   }
     /*
 
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: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw
Quoted 29 lines · Thomas Zimmermann

Hi

Am 25.02.21 um 10:43 schrieb Daniel Vetter:

Quoted 26 lines · Noralf Trønnes
Quoted 25 lines

Den 19.02.2021 14.54, skrev Thomas Zimmermann:

Quoted 20 lines

Hi

Am 19.02.21 um 13:22 schrieb Noralf Trønnes:

Quoted 11 lines

dma-buf importing was reworked in commit 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing"). Before that commit drm_gem_shmem_prime_import_sg_table() did set ->pages_use_count=1 and drm_gem_shmem_vunmap_locked() could call drm_gem_shmem_put_pages() unconditionally. Now without the use count set, put pages is called also on dma-bufs. Fix this by only putting pages if it's not imported.

Fixes 7d2cd72a9aa3 ("drm/shmem-helpers: Simplify dma-buf importing")
Cc Daniel Vetter <[email protected]>
Cc Thomas Zimmermann <[email protected]>

Just when I saw the error. Nice. :)

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Should I apply this to drm-misc-fixes?

drm-misc-next-fixes because we're in the merge window.

Too late. Can/should I cherry-pick the patch from drm-misc-next?

Maarten just send the pull around, so pls coordinate with him. Maybe best if Maarten cherry-picks onto drm-misc-fixes after -rc1 is out. -Daniel

Quoted 57 lines

Best regards
Thomas

Quoted 44 lines

-Daniel

Quoted 39 lines

Noralf.

Quoted 36 lines

For testing the GUD driver, you may also want to keep an eye at [1]

Best regards
Thomas

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

Quoted 26 lines
---
   drivers/gpu/drm/drm_gem_shmem_helper.c | 7 ++++---
   1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +4 -2
index 9825c378dfa6..c8a6547a1757 100644
@@ -357,13 +357,14 @@ static void drm_gem_shmem_vunmap_locked(struct
 drm_gem_shmem_object *shmem,
       if (--shmem->vmap_use_count > 0)
           return;
   -    if (obj->import_attach)
+    if (obj->import_attach) {
           dma_buf_vunmap(obj->import_attach->dmabuf, map);
-    else
+    } else {
           vunmap(shmem->vaddr);
+        drm_gem_shmem_put_pages(shmem);
+    }
         shmem->vaddr = NULL;
-    drm_gem_shmem_put_pages(shmem);
   }
     /*
 
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: Felix Imendörffer
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel