Skip to contentSkip to conversation

drm/gem_shmem: Use a writecombine mapping for ->vaddr

PATCH In review Boris Brezillon 4 participants 7 messages May 29, 2019 – Jun 10, 2019

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

PATCH 1/1 drm/gem_shmem: Use a writecombine mapping for ->vaddr

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -1
index 1ee208c2c85e..472ea5d81f82 100644
@@ -255,7 +255,8 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
 	if (obj->import_attach)
 		shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf);
 	else
-		shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, VM_MAP, PAGE_KERNEL);
+		shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
+				    VM_MAP, pgprot_writecombine(PAGE_KERNEL));
 
 	if (!shmem->vaddr) {
 		DRM_DEBUG_KMS("Failed to vmap pages\n");
Signature · 6 lines
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 8 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

Quoted 8 lines

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

Uh, I guess shmem helpers (or gem helpers in general) need some concept about what kind of cpu mapping is desired. Since some cpus (like e.g. i915) do actually want cached mode for everything.

Same is needed for the userspace mmap, those should all agree.

Default probably best if we go with uncached.
-Daniel

Quoted 25 lines
---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +2 -1
index 1ee208c2c85e..472ea5d81f82 100644
@@ -255,7 +255,8 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
 	if (obj->import_attach)
 		shmem->vaddr = dma_buf_vmap(obj->import_attach->dmabuf);
 	else
-		shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT, VM_MAP, PAGE_KERNEL);
+		shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
+				    VM_MAP, pgprot_writecombine(PAGE_KERNEL));
 
 	if (!shmem->vaddr) {
 		DRM_DEBUG_KMS("Failed to vmap pages\n");
Signature · 6 lines
2.20.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
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
Reviewed-by on v1 1/1
#2 lore raw
In reply to Boris Brezillon
Quoted 8 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

Quoted 8 lines

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

writecombined was the intent, and this makes kernel vmap match the userspace mmap path.

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

#3 lore raw
Quoted 16 lines · Eric Anholt
Quoted 14 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

Quoted 5 lines
Quoted 2 lines

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

writecombined was the intent, and this makes kernel vmap match the userspace mmap path.

Since I missed that obviously: Where do the shmem helpers set write combined mode for userspace mmap?
-Daniel

Quoted 9 lines

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

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
#4 lore raw
Quoted 17 lines · Daniel Vetter
Quoted 16 lines · Eric Anholt
Quoted 14 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

writecombined was the intent, and this makes kernel vmap match the userspace mmap path.

Since I missed that obviously: Where do the shmem helpers set write combined mode for userspace mmap?

That was the trick when I asked the question, too. drm_gem.c is what sets WC by default.

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

Reviewed-by
#5 lore raw
Quoted 23 lines · Eric Anholt
Quoted 20 lines · Daniel Vetter
Quoted 19 lines · Eric Anholt
Quoted 16 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

writecombined was the intent, and this makes kernel vmap match the userspace mmap path.

Since I missed that obviously: Where do the shmem helpers set write combined mode for userspace mmap?

That was the trick when I asked the question, too. drm_gem.c is what sets WC by default.

TIL. And looks like this has been the case forever, it laned in

commit a2c0a97b784f837300f7b0869c82ab712c600952

Author: Jesse Barnes <[email protected]>
Date:   Wed Nov 5 10:31:53 2008 -0800

drm: GEM mmap support

I'll retract my concern, making this wc everywhere is the right thing to do.

Cheers, Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw
In reply to Boris Brezillon
Quoted 9 lines · Boris Brezillon

Right now, the BO is mapped as a cached region when ->vmap() is called and the underlying object is not a dmabuf.
Doing that makes cache management a bit more complicated (you'd need to call dma_map/unmap_sg() on the ->sgt field everytime the BO is about to be passed to the GPU/CPU), so let's map the BO with writecombine attributes instead (as done in most drivers).

Quoted 8 lines

---
Found this issue while working on panfrost perfcnt where the GPU dumps perf counter values in memory and the CPU reads them back in kernel-space. This patch seems to solve the unpredictable behavior I had.

I can also go for the other option (call dma_map/unmap/_sg() when needed) if you think that's more appropriate.

Using writecombine everywhere was the intention, but I missed this spot. I've applied this adding a Fixes tag.

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