Skip to contentSkip to conversation

Default to cachable mappings for GEM SHMEM

PATCH Superseded Thomas Zimmermann 3 participants 6 messages Nov 6, 2020 – Nov 12, 2020

Subsystems (10)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover Default to cachable mappings for GEM SHMEM

Shmem-allocated memory uses the system's default caching flags, usually involving cached mappings.

By default, SHMEM GEM helpers map pages using writecombine. Only a few drivers require this setting. Others revert it to default mappings flags. Some could benefit from caching, but don't care.

Unify the behaviour by switching the SHMEM GEM code to use cached mappings (i.e., PAGE_KERNEL actually); just like regular shmem memory does. The 3 drivers that require write combining explicitly select it during GEM object creation.

The exception is dma-buf imported pages, which are always mapped using writecombine mode.

v2:
* recreate patches on top of latest SHMEM helpers
* update lima, panfrost, v3d (Daniel, Rob)
* udl has been updated before separately.

Thomas Zimmermann (2):
drm/shmem-helper: Use cached mappings by default drm/shmem-helper: Removed drm_gem_shmem_create_object_cached()

 drivers/gpu/drm/drm_gem_shmem_helper.c  | 37 ++++---------------------
 drivers/gpu/drm/lima/lima_gem.c         |  2 +-
 drivers/gpu/drm/mgag200/mgag200_drv.c   |  1 -
 drivers/gpu/drm/panfrost/panfrost_gem.c |  2 +-
 drivers/gpu/drm/udl/udl_drv.c           |  2 --
 drivers/gpu/drm/v3d/v3d_bo.c            |  2 +-
 drivers/gpu/drm/virtio/virtgpu_object.c |  1 -
 drivers/gpu/drm/vkms/vkms_drv.c         |  1 -
 include/drm/drm_gem_shmem_helper.h      |  7 ++---
 9 files changed, 11 insertions(+), 44 deletions(-)

--
2.29.0

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author maintainer
#1 lore raw

PATCH v2 1/2 drm/shmem-helper: Use cached mappings by default

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.

v2:
* recreate patch on top of latest SHMEM helpers
* update lima, panfrost, v3d to select writecombine (Daniel, Rob)

---
 drivers/gpu/drm/drm_gem_shmem_helper.c  | 11 ++++++-----
 drivers/gpu/drm/lima/lima_gem.c         |  2 +-
 drivers/gpu/drm/panfrost/panfrost_gem.c |  2 +-
 drivers/gpu/drm/v3d/v3d_bo.c            |  2 +-
 drivers/gpu/drm/virtio/virtgpu_object.c |  1 -
 include/drm/drm_gem_shmem_helper.h      |  4 ++--
 6 files changed, 11 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +6 -5
index 8233bda4692f..ddec0e190f29 100644
@@ -54,10 +54,12 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
 	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;
 
@@ -278,7 +280,7 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
 		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);
@@ -487,7 +489,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;
 }
@@ -616,7 +617,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;
 
drivers/gpu/drm/lima/lima_gem.c +1 -1
index 11223fe348df..bbab1413eb0c 100644
@@ -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;
drivers/gpu/drm/panfrost/panfrost_gem.c +1 -1
index fb9f7334ce18..f77b72d995f9 100644
@@ -230,7 +230,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;
 }
drivers/gpu/drm/v3d/v3d_bo.c +1 -1
index 8b52cb25877c..6a8731ab9d7d 100644
@@ -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;
drivers/gpu/drm/virtio/virtgpu_object.c +0 -1
index 2d3aa7baffe4..47e3b69c3927 100644
@@ -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;
 }
 
include/drm/drm_gem_shmem_helper.h +2 -2
index 5381f0c8cf6f..268d0284ae02 100644
@@ -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) \
Signature · 6 lines
2.29.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#2 lore raw

Re: [PATCH v2 1/2] drm/shmem-helper: Use cached mappings by default

affects gm12u320; cc'ing Hans

Am 06.11.20 um 16:26 schrieb Thomas Zimmermann:

Quoted 146 lines

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.

v2:
* recreate patch on top of latest SHMEM helpers
* update lima, panfrost, v3d to select writecombine (Daniel, Rob)

---
 drivers/gpu/drm/drm_gem_shmem_helper.c  | 11 ++++++-----
 drivers/gpu/drm/lima/lima_gem.c         |  2 +-
 drivers/gpu/drm/panfrost/panfrost_gem.c |  2 +-
 drivers/gpu/drm/v3d/v3d_bo.c            |  2 +-
 drivers/gpu/drm/virtio/virtgpu_object.c |  1 -
 include/drm/drm_gem_shmem_helper.h      |  4 ++--
 6 files changed, 11 insertions(+), 11 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +6 -5
index 8233bda4692f..ddec0e190f29 100644
@@ -54,10 +54,12 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
 	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;
 
@@ -278,7 +280,7 @@ static void *drm_gem_shmem_vmap_locked(struct drm_gem_shmem_object *shmem)
 		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);
@@ -487,7 +489,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;
 }
@@ -616,7 +617,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;
 
drivers/gpu/drm/lima/lima_gem.c +1 -1
index 11223fe348df..bbab1413eb0c 100644
@@ -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;
drivers/gpu/drm/panfrost/panfrost_gem.c +1 -1
index fb9f7334ce18..f77b72d995f9 100644
@@ -230,7 +230,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;
 }
drivers/gpu/drm/v3d/v3d_bo.c +1 -1
index 8b52cb25877c..6a8731ab9d7d 100644
@@ -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;
drivers/gpu/drm/virtio/virtgpu_object.c +0 -1
index 2d3aa7baffe4..47e3b69c3927 100644
@@ -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;
 }
 
include/drm/drm_gem_shmem_helper.h +2 -2
index 5381f0c8cf6f..268d0284ae02 100644
@@ -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) \
Signature · 10 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
#3 lore raw

Re: [PATCH v2 1/2] drm/shmem-helper: Use cached mappings by default

In reply to Thomas Zimmermann
I love your patch! Perhaps something to improve:

Hi Thomas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on next-20201106]
[cannot apply to linus/master v5.10-rc2 v5.10-rc1 v5.9 v5.10-rc3] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Thomas-Zimmermann/Default-to-cachable-mappings-for-GEM-SHMEM/20201109-092124
base:    c34f157421f6905e6b4a79a312e9175dce2bc607
config: s390-randconfig-r021-20201109 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 09ec07827b1128504457a93dee80b2ceee1af600)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/6c0af452d25888d28cc6f16457d36a7c6e1c816a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Thomas-Zimmermann/Default-to-cachable-mappings-for-GEM-SHMEM/20201109-092124 git checkout 6c0af452d25888d28cc6f16457d36a7c6e1c816a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

include/uapi/linux/swab.h:19:12: note: expanded from macro '___constant_swab32'

           (((__u32)(x) & (__u32)0x000000ffUL) << 24) |            \
                     ^
   In file included from drivers/gpu/drm/drm_gem_shmem_helper.c:6:
   In file included from include/linux/dma-buf.h:16:
   In file included from include/linux/dma-buf-map.h:9:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:80:
   include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
           ___constant_swab32(x) :                 \
                              ^
   include/uapi/linux/swab.h:20:12: note: expanded from macro '___constant_swab32'
           (((__u32)(x) & (__u32)0x0000ff00UL) <<  8) |            \
                     ^
   In file included from drivers/gpu/drm/drm_gem_shmem_helper.c:6:
   In file included from include/linux/dma-buf.h:16:
   In file included from include/linux/dma-buf-map.h:9:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:80:
   include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
           ___constant_swab32(x) :                 \
                              ^
   include/uapi/linux/swab.h:21:12: note: expanded from macro '___constant_swab32'
           (((__u32)(x) & (__u32)0x00ff0000UL) >>  8) |            \
                     ^
   In file included from drivers/gpu/drm/drm_gem_shmem_helper.c:6:
   In file included from include/linux/dma-buf.h:16:
   In file included from include/linux/dma-buf-map.h:9:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:80:
   include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:119:21: note: expanded from macro '__swab32'
           ___constant_swab32(x) :                 \
                              ^
   include/uapi/linux/swab.h:22:12: note: expanded from macro '___constant_swab32'
           (((__u32)(x) & (__u32)0xff000000UL) >> 24)))
                     ^
   In file included from drivers/gpu/drm/drm_gem_shmem_helper.c:6:
   In file included from include/linux/dma-buf.h:16:
   In file included from include/linux/dma-buf-map.h:9:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:80:
   include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
                                                           ~~~~~~~~~~ ^
   include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
   #define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
                                                             ^
   include/uapi/linux/swab.h:120:12: note: expanded from macro '__swab32'
           __fswab32(x))
                     ^
   In file included from drivers/gpu/drm/drm_gem_shmem_helper.c:6:
   In file included from include/linux/dma-buf.h:16:
   In file included from include/linux/dma-buf-map.h:9:
   In file included from include/linux/io.h:13:
   In file included from arch/s390/include/asm/io.h:80:
   include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writeb(value, PCI_IOBASE + addr);
                               ~~~~~~~~~~ ^
   include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
                                                         ~~~~~~~~~~ ^
   include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsb(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsw(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           readsl(PCI_IOBASE + addr, buffer, count);
                  ~~~~~~~~~~ ^
   include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesb(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesw(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
   include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
           writesl(PCI_IOBASE + addr, buffer, count);
                   ~~~~~~~~~~ ^
>> drivers/gpu/drm/drm_gem_shmem_helper.c:59:3: warning: variable 'shmem' is uninitialized when used here [-Wuninitialized]
                   shmem->map_wc = false; /* dma-buf mappings use always writecombine */
                   ^~~~~
   drivers/gpu/drm/drm_gem_shmem_helper.c:41:36: note: initialize the variable 'shmem' to silence this warning
           struct drm_gem_shmem_object *shmem;
                                             ^
                                              = NULL

21 warnings generated.

vim +/shmem +59 drivers/gpu/drm/drm_gem_shmem_helper.c

    37	
    38	static struct drm_gem_shmem_object *
    39	__drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
    40	{
    41		struct drm_gem_shmem_object *shmem;
    42		struct drm_gem_object *obj;
    43		int ret = 0;
    44	
    45		size = PAGE_ALIGN(size);
    46	
    47		if (dev->driver->gem_create_object)
    48			obj = dev->driver->gem_create_object(dev, size);
    49		else
    50			obj = kzalloc(sizeof(*shmem), GFP_KERNEL);
    51		if (!obj)
    52			return ERR_PTR(-ENOMEM);
    53	
    54		if (!obj->funcs)
    55			obj->funcs = &drm_gem_shmem_funcs;
    56	
    57		if (private) {
    58			drm_gem_private_object_init(dev, obj, size);
  > 59			shmem->map_wc = false; /* dma-buf mappings use always writecombine */
    60		} else {
    61			ret = drm_gem_object_init(dev, obj, size);
    62		}
    63		if (ret)
    64			goto err_free;
    65	
    66		ret = drm_gem_create_mmap_offset(obj);
    67		if (ret)
    68			goto err_release;
    69	
    70		shmem = to_drm_gem_shmem_obj(obj);
    71		mutex_init(&shmem->pages_lock);
    72		mutex_init(&shmem->vmap_lock);
    73		INIT_LIST_HEAD(&shmem->madv_list);
    74	
    75		if (!private) {
    76			/*
    77			 * Our buffers are kept pinned, so allocating them
    78			 * from the MOVABLE zone is a really bad idea, and
    79			 * conflicts with CMA. See comments above new_inode()
    80			 * why this is required _and_ expected if you're
    81			 * going to pin these pages.
    82			 */
    83			mapping_set_gfp_mask(obj->filp->f_mapping, GFP_HIGHUSER |
    84					     __GFP_RETRY_MAYFAIL | __GFP_NOWARN);
    85		}
    86	
    87		return shmem;
    88	
    89	err_release:
    90		drm_gem_object_release(obj);
    91	err_free:
    92		kfree(obj);
    93	
    94		return ERR_PTR(ret);
    95	}
    96	/**
    97	 * drm_gem_shmem_create - Allocate an object with the given size
    98	 * @dev: DRM device
    99	 * @size: Size of the object to allocate

100 *
101 * This function creates a shmem GEM object.
102 *
103 * Returns:
104 * A struct drm_gem_shmem_object * on success or an ERR_PTR()-encoded negative
105 * error code on failure.
106 */
107 struct drm_gem_shmem_object *drm_gem_shmem_create(struct drm_device *dev, size_t size)
108 {
109 return __drm_gem_shmem_create(dev, size, false);
110 }
111 EXPORT_SYMBOL_GPL(drm_gem_shmem_create);
112

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw

Re: [PATCH v2 1/2] drm/shmem-helper: Use cached mappings by default

In reply to Thomas Zimmermann

Hi Thomas,

url:    https://github.com/0day-ci/linux/commits/Thomas-Zimmermann/Default-to-cachable-mappings-for-GEM-SHMEM/20201109-092124
base:    c34f157421f6905e6b4a79a312e9175dce2bc607
config: arm64-randconfig-m031-20201111 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

If you fix the issue, kindly add following tag as appropriate

smatch warnings:
drivers/gpu/drm/drm_gem_shmem_helper.c:59 __drm_gem_shmem_create() error: potentially dereferencing uninitialized 'shmem'.

vim +/shmem +59 drivers/gpu/drm/drm_gem_shmem_helper.c

7d2cd72a9aa3df3 Daniel Vetter     2020-05-29   38  static struct drm_gem_shmem_object *
7d2cd72a9aa3df3 Daniel Vetter     2020-05-29   39  __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private)
2194a63a818db71 Noralf Trønnes    2019-03-12   40  {
2194a63a818db71 Noralf Trønnes    2019-03-12   41  	struct drm_gem_shmem_object *shmem;
                                                                                     ^^^^^

2194a63a818db71 Noralf Trønnes 2019-03-12 42 struct drm_gem_object *obj;
7d2cd72a9aa3df3 Daniel Vetter 2020-05-29 43 int ret = 0;

2194a63a818db71 Noralf Trønnes    2019-03-12   44  
2194a63a818db71 Noralf Trønnes    2019-03-12   45  	size = PAGE_ALIGN(size);
2194a63a818db71 Noralf Trønnes    2019-03-12   46  
2194a63a818db71 Noralf Trønnes    2019-03-12   47  	if (dev->driver->gem_create_object)
2194a63a818db71 Noralf Trønnes    2019-03-12   48  		obj = dev->driver->gem_create_object(dev, size);
2194a63a818db71 Noralf Trønnes    2019-03-12   49  	else
2194a63a818db71 Noralf Trønnes    2019-03-12   50  		obj = kzalloc(sizeof(*shmem), GFP_KERNEL);
2194a63a818db71 Noralf Trønnes    2019-03-12   51  	if (!obj)
2194a63a818db71 Noralf Trønnes    2019-03-12   52  		return ERR_PTR(-ENOMEM);
2194a63a818db71 Noralf Trønnes    2019-03-12   53  
2194a63a818db71 Noralf Trønnes    2019-03-12   54  	if (!obj->funcs)
2194a63a818db71 Noralf Trønnes    2019-03-12   55  		obj->funcs = &drm_gem_shmem_funcs;
2194a63a818db71 Noralf Trønnes    2019-03-12   56  
6c0af452d25888d Thomas Zimmermann 2020-11-06   57  	if (private) {
7d2cd72a9aa3df3 Daniel Vetter     2020-05-29   58  		drm_gem_private_object_init(dev, obj, size);
6c0af452d25888d Thomas Zimmermann 2020-11-06  @59  		shmem->map_wc = false; /* dma-buf mappings use always writecombine */
                                                                ^^^^^^^^^^^^^^^^^^^^^

Not initialized until later

6c0af452d25888d Thomas Zimmermann 2020-11-06 60 } else {
2194a63a818db71 Noralf Trønnes 2019-03-12 61 ret = drm_gem_object_init(dev, obj, size);
6c0af452d25888d Thomas Zimmermann 2020-11-06 62 }

2194a63a818db71 Noralf Trønnes    2019-03-12   63  	if (ret)
2194a63a818db71 Noralf Trønnes    2019-03-12   64  		goto err_free;
2194a63a818db71 Noralf Trønnes    2019-03-12   65  
2194a63a818db71 Noralf Trønnes    2019-03-12   66  	ret = drm_gem_create_mmap_offset(obj);
2194a63a818db71 Noralf Trønnes    2019-03-12   67  	if (ret)
2194a63a818db71 Noralf Trønnes    2019-03-12   68  		goto err_release;
2194a63a818db71 Noralf Trønnes    2019-03-12   69  
2194a63a818db71 Noralf Trønnes    2019-03-12   70  	shmem = to_drm_gem_shmem_obj(obj);
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2194a63a818db71 Noralf Trønnes    2019-03-12   71  	mutex_init(&shmem->pages_lock);
2194a63a818db71 Noralf Trønnes    2019-03-12   72  	mutex_init(&shmem->vmap_lock);

17acb9f35ed736c Rob Herring 2019-08-05 73 INIT_LIST_HEAD(&shmem->madv_list);

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

author maintainer
#5 lore raw

PATCH v2 2/2 drm/shmem-helper: Removed drm_gem_shmem_create_object_cached()

In reply to Thomas Zimmermann

Cached page mappings are now the default for SHMEM GEM objects. Remove the obsolete create function for cached mappings.

---
 drivers/gpu/drm/drm_gem_shmem_helper.c | 26 --------------------------
 drivers/gpu/drm/mgag200/mgag200_drv.c  |  1 -
 drivers/gpu/drm/udl/udl_drv.c          |  2 --
 drivers/gpu/drm/vkms/vkms_drv.c        |  1 -
 include/drm/drm_gem_shmem_helper.h     |  3 ---
 5 files changed, 33 deletions(-)
drivers/gpu/drm/drm_gem_shmem_helper.c +0 -26
index ddec0e190f29..5b4240725e64 100644
@@ -468,32 +468,6 @@ bool drm_gem_shmem_purge(struct drm_gem_object *obj)
 }
 EXPORT_SYMBOL(drm_gem_shmem_purge);
 
-/**
- * drm_gem_shmem_create_object_cached - Create a shmem buffer object with
- *                                      cached mappings
- * @dev: DRM device
- * @size: Size of the object to allocate
- *
- * By default, shmem buffer objects use writecombine mappings. This
- * function implements struct drm_driver.gem_create_object for shmem
- * buffer objects with cached mappings.
- *
- * Returns:
- * A struct drm_gem_shmem_object * on success or NULL negative on failure.
- */
-struct drm_gem_object *
-drm_gem_shmem_create_object_cached(struct drm_device *dev, size_t size)
-{
-	struct drm_gem_shmem_object *shmem;
-
-	shmem = kzalloc(sizeof(*shmem), GFP_KERNEL);
-	if (!shmem)
-		return NULL;
-
-	return &shmem->base;
-}
-EXPORT_SYMBOL(drm_gem_shmem_create_object_cached);
-
 /**
  * drm_gem_shmem_dumb_create - Create a dumb shmem buffer object
  * @file: DRM file structure to create the dumb buffer for
drivers/gpu/drm/mgag200/mgag200_drv.c +0 -1
index 771b26aeee19..aaf50b6a7372 100644
@@ -37,7 +37,6 @@ static struct drm_driver mgag200_driver = {
 	.major = DRIVER_MAJOR,
 	.minor = DRIVER_MINOR,
 	.patchlevel = DRIVER_PATCHLEVEL,
-	.gem_create_object = drm_gem_shmem_create_object_cached,
 	DRM_GEM_SHMEM_DRIVER_OPS,
 };
 
drivers/gpu/drm/udl/udl_drv.c +0 -2
index 96d4317a2c1b..a29147799575 100644
@@ -38,8 +38,6 @@ static struct drm_driver driver = {
 	.driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
 
 	/* GEM hooks */
-	.gem_create_object = drm_gem_shmem_create_object_cached,
-
 	.fops = &udl_driver_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
 
drivers/gpu/drm/vkms/vkms_drv.c +0 -1
index 25faba5aac08..b6cd7f2d941c 100644
@@ -82,7 +82,6 @@ static struct drm_driver vkms_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
 	.release		= vkms_release,
 	.fops			= &vkms_driver_fops,
-	.gem_create_object = drm_gem_shmem_create_object_cached,
 	DRM_GEM_SHMEM_DRIVER_OPS,
 
 	.name			= DRIVER_NAME,
include/drm/drm_gem_shmem_helper.h +0 -3
index 268d0284ae02..6bcd2c4d6a51 100644
@@ -133,9 +133,6 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
 				 struct drm_device *dev, size_t size,
 				 uint32_t *handle);
 
-struct drm_gem_object *
-drm_gem_shmem_create_object_cached(struct drm_device *dev, size_t size);
-
 int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
 			      struct drm_mode_create_dumb *args);
 
Signature · 6 lines
2.29.0

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