All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
@ 2019-05-29  6:51 Boris Brezillon
  2019-05-29  6:58 ` Daniel Vetter
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Boris Brezillon @ 2019-05-29  6:51 UTC (permalink / raw)
  To: Rob Herring, Tomeu Vizoso; +Cc: Boris Brezillon, dri-devel

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).

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
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(-)

diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index 1ee208c2c85e..472ea5d81f82 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -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");
-- 
2.20.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-05-29  6:51 [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr Boris Brezillon
@ 2019-05-29  6:58 ` Daniel Vetter
  2019-05-31 15:46 ` Eric Anholt
  2019-06-10 15:40 ` Rob Herring
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Vetter @ 2019-05-29  6:58 UTC (permalink / raw)
  To: Boris Brezillon; +Cc: Rob Herring, dri-devel

On Wed, May 29, 2019 at 08:51:21AM +0200, Boris Brezillon wrote:
> 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).
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> 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

> ---
>  drivers/gpu/drm/drm_gem_shmem_helper.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
> index 1ee208c2c85e..472ea5d81f82 100644
> --- a/drivers/gpu/drm/drm_gem_shmem_helper.c
> +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
> @@ -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");
> -- 
> 2.20.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-05-29  6:51 [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr Boris Brezillon
  2019-05-29  6:58 ` Daniel Vetter
@ 2019-05-31 15:46 ` Eric Anholt
  2019-06-03  7:21   ` Daniel Vetter
  2019-06-10 15:40 ` Rob Herring
  2 siblings, 1 reply; 7+ messages in thread
From: Eric Anholt @ 2019-05-31 15:46 UTC (permalink / raw)
  To: Rob Herring, Tomeu Vizoso; +Cc: Boris Brezillon, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 976 bytes --]

Boris Brezillon <boris.brezillon@collabora.com> writes:

> 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).
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> 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.

Reviewed-by: Eric Anholt <eric@anholt.net>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-05-31 15:46 ` Eric Anholt
@ 2019-06-03  7:21   ` Daniel Vetter
  2019-06-03 15:43     ` Eric Anholt
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Vetter @ 2019-06-03  7:21 UTC (permalink / raw)
  To: Eric Anholt; +Cc: dri-devel, Boris Brezillon, Rob Herring

On Fri, May 31, 2019 at 08:46:58AM -0700, Eric Anholt wrote:
> Boris Brezillon <boris.brezillon@collabora.com> writes:
> 
> > 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).
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> > ---
> > 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.

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

> 
> Reviewed-by: Eric Anholt <eric@anholt.net>



> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel


-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-06-03  7:21   ` Daniel Vetter
@ 2019-06-03 15:43     ` Eric Anholt
  2019-06-03 15:57       ` Daniel Vetter
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Anholt @ 2019-06-03 15:43 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: dri-devel, Boris Brezillon, Rob Herring


[-- Attachment #1.1: Type: text/plain, Size: 1328 bytes --]

Daniel Vetter <daniel@ffwll.ch> writes:

> On Fri, May 31, 2019 at 08:46:58AM -0700, Eric Anholt wrote:
>> Boris Brezillon <boris.brezillon@collabora.com> writes:
>> 
>> > 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).
>> >
>> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
>> > ---
>> > 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.
>
> 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.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-06-03 15:43     ` Eric Anholt
@ 2019-06-03 15:57       ` Daniel Vetter
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel Vetter @ 2019-06-03 15:57 UTC (permalink / raw)
  To: Eric Anholt; +Cc: dri-devel, Boris Brezillon, Rob Herring

On Mon, Jun 3, 2019 at 5:43 PM Eric Anholt <eric@anholt.net> wrote:
>
> Daniel Vetter <daniel@ffwll.ch> writes:
>
> > On Fri, May 31, 2019 at 08:46:58AM -0700, Eric Anholt wrote:
> >> Boris Brezillon <boris.brezillon@collabora.com> writes:
> >>
> >> > 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).
> >> >
> >> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> >> > ---
> >> > 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.
> >
> > 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 <jbarnes@virtuousgeek.org>
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.

Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Cheers, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr
  2019-05-29  6:51 [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr Boris Brezillon
  2019-05-29  6:58 ` Daniel Vetter
  2019-05-31 15:46 ` Eric Anholt
@ 2019-06-10 15:40 ` Rob Herring
  2 siblings, 0 replies; 7+ messages in thread
From: Rob Herring @ 2019-06-10 15:40 UTC (permalink / raw)
  To: Boris Brezillon; +Cc: dri-devel

On Wed, May 29, 2019 at 12:51 AM Boris Brezillon
<boris.brezillon@collabora.com> wrote:
>
> 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).
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> 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
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-10 15:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29  6:51 [PATCH] drm/gem_shmem: Use a writecombine mapping for ->vaddr Boris Brezillon
2019-05-29  6:58 ` Daniel Vetter
2019-05-31 15:46 ` Eric Anholt
2019-06-03  7:21   ` Daniel Vetter
2019-06-03 15:43     ` Eric Anholt
2019-06-03 15:57       ` Daniel Vetter
2019-06-10 15:40 ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.