drm/virtio: fix mmap page attributes
Subsystems (4)
Gerd Hoffmann
maintainerPATCH 1/1 drm/virtio: fix mmap page attributes
virtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping drm_gem_shmem_mmap(), to tweak vm_page_prot accordingly.
--- drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/virtio/virtgpu_object.c +17 -1
@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj); } +static int virtio_gpu_gem_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +pgprot_t prot; +int ret; + + ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */ + prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +} +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .free = virtio_gpu_free_object, .open = virtio_gpu_gem_object_open,
@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap, }; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
Signature · 1 line
2.18.1
Thomas Zimmermann
maintainerHi
Am 10.12.19 um 09:57 schrieb Gerd Hoffmann:
Quoted 23 lines
virtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping
drm_gem_shmem_mmap(), to tweakvm_page_protaccordingly.Reported-by Gurchetan Singh <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_object.c +5
-0@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj); } +static int virtio_gpu_gem_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +pgprot_t prot; +int ret; +
drivers/gpu/drm/virtio/virtgpu_object.c static void virtio_gpu_free_object(struct drm_gem_object *obj) · line 92
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_object.c +10
-0+ ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */ + prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +}
There's similar code in udl, [1] which still uses writecombine for imported buffers. Virtio does not need this?
Aside from this, do you think we could handle all special cases within shmem?
Best regards
Thomas
Quoted 14 lines
drivers/gpu/drm/virtio/virtgpu_object.c +2
-1+static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .free = virtio_gpu_free_object, .open = virtio_gpu_gem_object_open,@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap, }; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
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
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Thomas Zimmermann
maintainerHi
Am 10.12.19 um 09:57 schrieb Gerd Hoffmann:
Quoted 23 lines
virtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping
drm_gem_shmem_mmap(), to tweakvm_page_protaccordingly.Reported-by Gurchetan Singh <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_object.c +5
-0@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj); } +static int virtio_gpu_gem_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +pgprot_t prot; +int ret; +
drivers/gpu/drm/virtio/virtgpu_object.c static void virtio_gpu_free_object(struct drm_gem_object *obj) · line 92
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_object.c +10
-0+ ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */ + prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +}
There's similar code in udl, [1] which still uses writecombine for imported buffers. Virtio does not need this?
Aside from this, do you think we could handle all special cases within shmem?
Best regards
Thomas
Quoted 14 lines
drivers/gpu/drm/virtio/virtgpu_object.c +2
-1+static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .free = virtio_gpu_free_object, .open = virtio_gpu_gem_object_open,@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap, }; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
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
Gerd Hoffmann
maintainerHi,
Quoted 2 lines
There's similar code in udl, [1] which still uses writecombine for imported buffers. Virtio does not need this?
virtio doesn't support dma-buf imports (yet).
So no worries for now.
Why pick writecombine for the imported buffer btw?
It'll probably be correct for the majority of imports, but it still looks like a educated guess to me. What if you import from vgem?
I guess we should either ...
(1) Ask the exporting driver to handle things, simliar to how it is done for vmaps already, probably by calling dma_buf_mmap(), or
(2) Refuse to mmap imported objects via drm api.
Quoted 2 lines
Aside from this, do you think we could handle all special cases within shmem?
Probably makes sense to teach shmem helpers about caching.
cheers,
Gerd
Gerd Hoffmann
maintainerHi,
Quoted 2 lines
There's similar code in udl, [1] which still uses writecombine for imported buffers. Virtio does not need this?
virtio doesn't support dma-buf imports (yet).
So no worries for now.
Why pick writecombine for the imported buffer btw?
It'll probably be correct for the majority of imports, but it still looks like a educated guess to me. What if you import from vgem?
I guess we should either ...
(1) Ask the exporting driver to handle things, simliar to how it is done for vmaps already, probably by calling dma_buf_mmap(), or
(2) Refuse to mmap imported objects via drm api.
Quoted 2 lines
Aside from this, do you think we could handle all special cases within shmem?
Probably makes sense to teach shmem helpers about caching.
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Gurchetan Singh
reviewerQuoted 39 lines · Gerd Hoffmann
virtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping
drm_gem_shmem_mmap(), to tweakvm_page_protaccordingly.Reported-by Gurchetan Singh <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_object.c +16
-0@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj); } +static int virtio_gpu_gem_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +pgprot_t prot; +int ret; + + ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */ + prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +} +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .free = virtio_gpu_free_object, .open = virtio_gpu_gem_object_open,
drivers/gpu/drm/virtio/virtgpu_object.c static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { · line 103
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_object.c +0
-0@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap,
Do we need vmap/vmunap? It seems optionable and also uses non-cacheable memory?
drivers/gpu/drm/virtio/virtgpu_object.c static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { · line 105
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_object.c +1
-1.vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap,
Why the &virtio_gpu_gem_mmap? Shouldn't just virtio_gpu_gem_mmap work?
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_object.c +0
-1}; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev, --2.18.1
Gurchetan Singh
reviewerQuoted 39 lines · Gerd Hoffmann
virtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping
drm_gem_shmem_mmap(), to tweakvm_page_protaccordingly.Reported-by Gurchetan Singh <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>--- drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_object.c +16
-0@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj); } +static int virtio_gpu_gem_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma) +{ +pgprot_t prot; +int ret; + + ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */ + prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +} +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .free = virtio_gpu_free_object, .open = virtio_gpu_gem_object_open,
drivers/gpu/drm/virtio/virtgpu_object.c static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { · line 103
Quoted 2 lines
drivers/gpu/drm/virtio/virtgpu_object.c +0
-0@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap,
Do we need vmap/vmunap? It seems optionable and also uses non-cacheable memory?
drivers/gpu/drm/virtio/virtgpu_object.c static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { · line 105
Quoted 3 lines
drivers/gpu/drm/virtio/virtgpu_object.c +1
-1.vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap,
Why the &virtio_gpu_gem_mmap? Shouldn't just virtio_gpu_gem_mmap work?
Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_object.c +0
-1}; struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev, --2.18.1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 32 lines
-----Original Message-----
From: dri-devel <[email protected]> On Behalf Of Gerd Hoffmann
Sent: Tuesday, December 10, 2019 3:58 AM
To: [email protected]
Cc: David Airlie <[email protected]>; open list <[email protected]>; open list:VIRTIO GPU DRIVER <[email protected]>; Gerd Hoffmann <[email protected]>; [email protected]
Subject: [PATCH] drm/virtio: fix mmap page attributesvirtio-gpu uses cached mappings. shmem helpers use writecombine though. So roll our own mmap function, wrapping
drm_gem_shmem_mmap(), to tweakvm_page_protaccordingly.Reported-by Gurchetan Singh <[email protected]>Signed-off-by Gerd Hoffmann <[email protected]>---
drivers/gpu/drm/virtio/virtgpu_object.c| 18 +++++++++++++++++-1 file changed, 17 insertions(+), 1 deletion(-)drivers/gpu/drm/virtio/virtgpu_object.c +1
-0@@ -75,6 +75,22 @@ static void virtio_gpu_free_object(struct drm_gem_object *obj)drm_gem_shmem_free_object (obj ); } +static int virtio_gpu_gem_mmap(struct drm_gem_object *obj, struct
drivers/gpu/drm/virtio/virtgpu_object.c static void virtio_gpu_free_object(struct · line 89
Quoted 10 lines
drivers/gpu/drm/virtio/virtgpu_object.c +9
-0vm_area_struct *vma) +{ +pgprot_t prot; +int ret; + + ret =drm_gem_shmem_mmap (obj, vma); +if (ret <0 ) +return ret; + +/* virtio-gpu needs normal caching, so clear writecombine */
A minor nit.
I was looking at this code, trying to see where you were clearing the writecombine bit.
Maybe a more clear comment would be:
virtio-gpu needs normal caching, re-do protection without writecombine
?
Mike
Quoted 22 lines
drivers/gpu/drm/virtio/virtgpu_object.c +6
-0+ prot =vm_get_page_prot (vma->vm_flags); + prot =pgprot_decrypted (prot); + vma->vm_page_prot = prot; +return 0 ; +} +static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = {.free =
virtio_gpu_free_object,
.open =virtio_gpu_gem_object_open,drivers/gpu/drm/virtio/virtgpu_object.c +1
-1@@ -86,7 +102,7 @@ static const struct drm_gem_object_funcs virtio_gpu_gem_funcs = { .get_sg_table = drm_gem_shmem_get_sg_table, .vmap = drm_gem_shmem_vmap, .vunmap = drm_gem_shmem_vunmap, - .mmap = &drm_gem_shmem_mmap, + .mmap = &virtio_gpu_gem_mmap, };struct
drm_gem_object*virtio_gpu_create_object(structdrm_device*dev, --
2.18.1
Quoted 4 lines
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel