]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
drm/shmem-helper: Use cached mappings by default
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 17 Nov 2020 13:31:55 +0000 (14:31 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Tue, 24 Nov 2020 08:10:21 +0000 (09:10 +0100)
SHMEM-buffer backing storage is allocated from system memory; which is
typically cachable. The default mode for SHMEM objects is writecombine
though.

Unify SHMEM semantics by defaulting to cached mappings. The exception
is pages imported via dma-buf. DMA memory is usually not cached.

DRM drivers that require write-combined mappings set the map_wc flag
in struct drm_gem_shmem_object to true. This currently affects lima,
panfrost and v3d.

The drivers mgag200, udl, virtio and vkms continue to use default
shmem mappings.

The drivers cirrus and gm12u320 change caching flags. Both used
writecombine and now switch over to shmem defaults. Both drivers use
SHMEM objects as shadow buffers for internal video memory, so cached
mappings will not affect them negatively.

v3:
* set value of shmem pointer before dereferencing it in
  __drm_gem_shmem_create() (Dan, kernel test robot)
v2:
* recreate patch on top of latest SHMEM helpers
* update lima, panfrost, v3d to select writecombine (Daniel, Rob)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Maxime Ripard <mripard@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20201117133156.26822-2-tzimmermann@suse.de
drivers/gpu/drm/drm_gem_shmem_helper.c
drivers/gpu/drm/lima/lima_gem.c
drivers/gpu/drm/panfrost/panfrost_gem.c
drivers/gpu/drm/v3d/v3d_bo.c
drivers/gpu/drm/virtio/virtgpu_object.c
include/drm/drm_gem_shmem_helper.h

index 499189c48f0bd95abcdb481ad010fdb8cd0b5adb..b1c7a316f2328f55fed2971c55450da69b4d7cd7 100644 (file)
@@ -51,13 +51,17 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
        if (!obj)
                return ERR_PTR(-ENOMEM);
 
+       shmem = to_drm_gem_shmem_obj(obj);
+
        if (!obj->funcs)
                obj->funcs = &drm_gem_shmem_funcs;
 
-       if (private)
+       if (private) {
                drm_gem_private_object_init(dev, obj, size);
-       else
+               shmem->map_wc = false; /* dma-buf mappings use always writecombine */
+       } else {
                ret = drm_gem_object_init(dev, obj, size);
+       }
        if (ret)
                goto err_free;
 
@@ -65,7 +69,6 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
        if (ret)
                goto err_release;
 
-       shmem = to_drm_gem_shmem_obj(obj);
        mutex_init(&shmem->pages_lock);
        mutex_init(&shmem->vmap_lock);
        INIT_LIST_HEAD(&shmem->madv_list);
@@ -284,7 +287,7 @@ static int drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem, struct
                if (ret)
                        goto err_zero_use;
 
-               if (!shmem->map_cached)
+               if (shmem->map_wc)
                        prot = pgprot_writecombine(prot);
                shmem->vaddr = vmap(shmem->pages, obj->size >> PAGE_SHIFT,
                                    VM_MAP, prot);
@@ -497,7 +500,6 @@ drm_gem_shmem_create_object_cached(struct drm_device *dev, size_t size)
        shmem = kzalloc(sizeof(*shmem), GFP_KERNEL);
        if (!shmem)
                return NULL;
-       shmem->map_cached = true;
 
        return &shmem->base;
 }
@@ -626,7 +628,7 @@ int drm_gem_shmem_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
 
        vma->vm_flags |= VM_MIXEDMAP | VM_DONTEXPAND;
        vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
-       if (!shmem->map_cached)
+       if (shmem->map_wc)
                vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
        vma->vm_ops = &drm_gem_shmem_vm_ops;
 
index 832e5280a6ed0af316a9886ed2efaa15b3a76e4c..de62966243cd53ee86a1efbf6bd3b2f1d3f95522 100644 (file)
@@ -225,7 +225,7 @@ struct drm_gem_object *lima_gem_create_object(struct drm_device *dev, size_t siz
 
        mutex_init(&bo->lock);
        INIT_LIST_HEAD(&bo->va);
-
+       bo->base.map_wc = true;
        bo->base.base.funcs = &lima_gem_funcs;
 
        return &bo->base.base;
index 57a31dd0ffed19ca284b5791ed07adf6da01bc5a..3e0723bc36bda98125650c00b0782e7ff5b73b0d 100644 (file)
@@ -228,7 +228,7 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t
        INIT_LIST_HEAD(&obj->mappings.list);
        mutex_init(&obj->mappings.lock);
        obj->base.base.funcs = &panfrost_gem_funcs;
-       obj->base.map_cached = pfdev->coherent;
+       obj->base.map_wc = !pfdev->coherent;
 
        return &obj->base.base;
 }
index 8b52cb25877c6f8b1d4eca05630187dfc18c9806..6a8731ab9d7d0cc7deac120665b7b59afabc16fb 100644 (file)
@@ -78,7 +78,7 @@ struct drm_gem_object *v3d_create_object(struct drm_device *dev, size_t size)
        obj = &bo->base.base;
 
        obj->funcs = &v3d_gem_funcs;
-
+       bo->base.map_wc = true;
        INIT_LIST_HEAD(&bo->unref_head);
 
        return &bo->base.base;
index d9ad27e00905da212412790c86bebead46b7bd3f..d69a5b6da55320c7e10ab88d6baa49f50c4c6e7d 100644 (file)
@@ -144,7 +144,6 @@ struct drm_gem_object *virtio_gpu_create_object(struct drm_device *dev,
 
        dshmem = &shmem->base.base;
        dshmem->base.funcs = &virtio_gpu_shmem_funcs;
-       dshmem->map_cached = true;
        return &dshmem->base;
 }
 
index 3449a0353fe0cbd5ec7e344e80c513ae13ae9922..f32801db3203ca3455681ad45160636f7ab2370b 100644 (file)
@@ -98,9 +98,9 @@ struct drm_gem_shmem_object {
        unsigned int vmap_use_count;
 
        /**
-        * @map_cached: map object cached (instead of using writecombine).
+        * @map_wc: map object write-combined (instead of using shmem defaults).
         */
-       bool map_cached;
+       bool map_wc;
 };
 
 #define to_drm_gem_shmem_obj(obj) \