RE: [PATCH] drm/virtio: fix mmap page attributes

From: Ruhl, Michael J
Date: Thu Dec 12 2019 - 09:49:07 EST


>-----Original Message-----
>From: dri-devel <dri-devel-bounces@xxxxxxxxxxxxxxxxxxxxx> On Behalf Of
>Gerd Hoffmann
>Sent: Tuesday, December 10, 2019 3:58 AM
>To: dri-devel@xxxxxxxxxxxxxxxxxxxxx
>Cc: David Airlie <airlied@xxxxxxxx>; open list <linux-kernel@xxxxxxxxxxxxxxx>;
>open list:VIRTIO GPU DRIVER <virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx>;
>Gerd Hoffmann <kraxel@xxxxxxxxxx>; gurchetansingh@xxxxxxxxxxxx
>Subject: [PATCH] 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.
>
>Reported-by: Gurchetan Singh <gurchetansingh@xxxxxxxxxxxx>
>Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
>---
> drivers/gpu/drm/virtio/virtgpu_object.c | 18 +++++++++++++++++-
> 1 file changed, 17 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/gpu/drm/virtio/virtgpu_object.c
>b/drivers/gpu/drm/virtio/virtgpu_object.c
>index 017a9e0fc3bb..158610902054 100644
>--- a/drivers/gpu/drm/virtio/virtgpu_object.c
>+++ b/drivers/gpu/drm/virtio/virtgpu_object.c
>@@ -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 */

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

>+ 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,
>--
>2.18.1
>
>_______________________________________________
>dri-devel mailing list
>dri-devel@xxxxxxxxxxxxxxxxxxxxx
>https://lists.freedesktop.org/mailman/listinfo/dri-devel