Skip to contentSkip to conversation

drm: Support DMA per allocation kernel mappings

PATCH In review Chen-Yu Tsai 3 participants 13 messages Mar 26 – Mar 30

Subsystems (19)
lore
Share & tools
lore
#0 lore raw

v3 cover drm: Support DMA per allocation kernel mappings

Hi everyone,

This is v3 of the "DMA per allocation kernel mappings" series.

Changes since v2:
- Dropped rcar-du patch in favor of just using dma_get_sgtable_attrs() in patch 2
- Patch 1
- Switched to drm_warn_once()
- Moved flag definition from include/uapi/ to include/drm/drm_dumb_buffers.h
- Reworded commit message
- Patch 2
- Added change for rcar-du: s/dma_get_sgtable()/dma_get_sgtable_attrs()/
- Patch 3
- Added back DRM_MODE_DUMB_KERNEL_MAP flag to all drivers calling drm_gem_dma_dumb_create_internal()
- Expanded commit message to cover display drivers needing the kernel mapping to do scan out

This is an attempt to revive Rob Herring's "DMA per allocation kernel mappings" [1] series from 2019. This series stacks on top of my recent "drm/gem-dma: Support dedicated DMA device for allocation" series [2]. Many of the allocation paths are touched by both.

The 3 driver conversions from the original series are not included, as the changes have landed in some other form.

Patch 1 adds the kernel internal DRM_MODE_DUMB_KERNEL_MAP flag.

Patch 2 adds the dma_attr field to drm_gem_dma_object, and converts the GEM DMA helpers to use the dma_*_attrs() variant of the DMA API.

Patch 3 adds support for DRM_MODE_DUMB_KERNEL_MAP to the GEM DMA helpers by setting the DMA_ATTR_NO_KERNEL_MAPING attribute for requests without the DRM_MODE_DUMB_KERNEL_MAP flag.

All existing callers of drm_gem_dma_dumb_create_internal() will have DRM_MODE_DUMB_KERNEL_MAP set to maintain existing behavior.

I have also started to convert the exynos driver to use the GEM DMA helpers. I also plan on looking into the rockchip driver, but that one has a separate IOMMU path that needs to be handled. I might copy the approach used in the exynos driver to deal with it.

Changes compared to the original version from Rob (v1):
- Link to original v1:
https://lore.kernel.org/dri-devel/[email protected]/
- Rebased onto renamed GEM DMA helpers
- New patch for rcar-du
- Patch 2
- Make drm_mode_create_dumb_ioctl() emit warning if args->flags is not zero
- Patch 3
- Made vc4_bo_purge() use dma_free_attrs(); this is the other location of DMA API used with drm_gem_dma_object outside the helpers
- Expanded commit message
- Patch 4
- Added kernal mapping check in drm_fb_dma_get_scanout_buffer() and

    drm_gem_dma_vmap().

- Made drm_gem_dma_print_info() show "vaddr=(no mapping)" for objects allocated without kernel mapping
- Dropped existing DRM_MODE_DUMB_KERNEL_MAP flag addition in various drivers
- Added DRM_MODE_DUMB_KERNEL_MAP flag to adp_drm_gem_dumb_create()
- Added flags field kerneldoc for drm_gem_dma_create_with_handle()

I dropped all the original Reviewed-by tags, as it's been 5 years since the changes were first posted, and also because the code has changed a lot.

Please have a look.

Thanks
ChenYu

Original cover letter from Rob:

This series adds support for CMA/DMA users to skip kernel mappings for GEM allocations. The DMA API only guarantees a kernel mapping at allocation time. Creating mappings with vmap() after allocation may or may not work as not all allocations have a struct page. As virtual memory space is limited on 32-bit systems some drivers will skip kernel mappings when possible. This prevents those drivers from using CMA helpers and the generic fbdev emulation which results in a lot of duplicated code.

In order to distinguish between kernel and userspace allocations, a new flag, DRM_MODE_DUMB_KERNEL_MAP, for drm_mode_create_dumb() is introduced. This allows drivers to override the default behavior for CMA helpers of always creating a kernel mapping.

Mediatek is converted to CMA helpers and Rockchip is converted to generic fbdev support. I also have patches to convert Rockchip to CMA and shmem helpers, but they need a bit more work. Exynos can also probably be converted to use CMA helpers.

Compile tested only. I did test fbdev on Rockchip, but the h/w I have has an IOMMU, so the CMA code path doesn't get tested.

- end quote -

[1] https://lore.kernel.org/dri-devel/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Rob Herring (3):
drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag drm/gem-dma: Use the dma_*_attr API variant drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag

 drivers/gpu/drm/adp/adp_drv.c                 |  1 +
 .../gpu/drm/arm/display/komeda/komeda_kms.c   |  1 +
 drivers/gpu/drm/arm/malidp_drv.c              |  1 +
 drivers/gpu/drm/drm_client.c                  |  2 +
 drivers/gpu/drm/drm_dumb_buffers.c            |  4 +
 drivers/gpu/drm/drm_fb_dma_helper.c           |  4 +
 drivers/gpu/drm/drm_gem_dma_helper.c          | 93 ++++++++++++-------
 drivers/gpu/drm/logicvc/logicvc_drm.c         |  1 +
 drivers/gpu/drm/meson/meson_drv.c             |  1 +
 drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c |  2 +
 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c |  5 +-
 drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c  |  1 +
 drivers/gpu/drm/stm/drv.c                     |  3 +-
 drivers/gpu/drm/sun4i/sun4i_drv.c             |  1 +
 drivers/gpu/drm/vc4/vc4_bo.c                  |  2 +-
 drivers/gpu/drm/vc4/vc4_drv.c                 |  2 +
 drivers/gpu/drm/verisilicon/vs_drm.c          |  2 +
 drivers/gpu/drm/xlnx/zynqmp_kms.c             |  2 +
 include/drm/drm_dumb_buffers.h                |  3 +
 include/drm/drm_gem_dma_helper.h              |  3 +
 20 files changed, 94 insertions(+), 40 deletions(-)
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
#1 lore raw

PATCH v3 1/3 drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag

From: Rob Herring <[email protected]>

Introduce a new flag, DRM_MODE_DUMB_KERNEL_MAP, for struct drm_mode_create_dumb. This flag is for internal kernel use to indicate if dumb buffer allocation needs a kernel mapping. This is needed only for GEM DMA where creating a kernel mapping or not has to be decided at allocation time because creating a mapping on demand (with vmap()) is not guaranteed to work.

Several drivers are using reimplementing the GEM DMA helpers because they distinguish between kernel and userspace allocations to create a kernel mapping or not. Adding a flag allows migrating these drivers to the helpers while preserving their existing behavior. These include exynos, rockchip, and previously mediatek.

Update the callers of drm_mode_dumb_create() to set drm_mode_dumb_create.flags to appropriate defaults. Currently, flags can be set to anything by userspace, but is unused within the kernel. Let's force flags to zero (no kernel mapping) for userspace callers by default. For in kernel clients, set DRM_MODE_DUMB_KERNEL_MAP by default. Drivers can override this as needed.

[[email protected]: Emit warning (once) if args->flags is not zero]
[[email protected]: Moved flag def. to include/drm/drm_dumb_buffers.h]

---
Changes since v2:
- Switched to drm_warn_once()
- Moved flag definition from include/uapi/ to include/drm/drm_dumb_buffers.h
- Reworded commit message

Changes since v1:
- Emit warning if args->flags is not zero

---
 drivers/gpu/drm/drm_client.c       | 2 ++
 drivers/gpu/drm/drm_dumb_buffers.c | 4 ++++
 include/drm/drm_dumb_buffers.h     | 3 +++
 3 files changed, 9 insertions(+)
drivers/gpu/drm/drm_client.c +2 -0
index 46c465bce98c..3d3e61823cc1 100644
@@ -14,6 +14,7 @@
 #include <drm/drm_client_event.h>
 #include <drm/drm_device.h>
 #include <drm/drm_drv.h>
+#include <drm/drm_dumb_buffers.h>
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
@@ -404,6 +405,7 @@ drm_client_buffer_create_dumb(struct drm_client_dev *client, u32 width, u32 heig
 	dumb_args.width = width;
 	dumb_args.height = height;
 	dumb_args.bpp = drm_format_info_bpp(info, 0);
+	dumb_args.flags = DRM_MODE_DUMB_KERNEL_MAP;
 	ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
 	if (ret)
 		return ERR_PTR(ret);
drivers/gpu/drm/drm_dumb_buffers.c +4 -0
index e2b62e5fb891..60f4c2d08641 100644
@@ -233,6 +233,10 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev,
 	struct drm_mode_create_dumb *args = data;
 	int err;
 
+	if (args->flags)
+		drm_warn_once(dev, "drm_mode_create_dumb.flags is not zero.\n");
+	args->flags = 0;
+
 	err = drm_mode_create_dumb(dev, args, file_priv);
 	if (err) {
 		args->handle = 0;
include/drm/drm_dumb_buffers.h +3 -0
index 1f3a8236fb3d..4657e44533f4 100644
@@ -6,6 +6,9 @@
 struct drm_device;
 struct drm_mode_create_dumb;
 
+/* drm_mode_create_dumb flags for internal use */
+#define DRM_MODE_DUMB_KERNEL_MAP	(1<<0)
+
 int drm_mode_size_dumb(struct drm_device *dev,
 		       struct drm_mode_create_dumb *args,
 		       unsigned long hw_pitch_align,
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
#2 lore raw

Re: [PATCH v3 1/3] drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag

Hi

Am 26.03.26 um 11:01 schrieb Chen-Yu Tsai:

Quoted 8 lines

From: Rob Herring <[email protected]>

Introduce a new flag, DRM_MODE_DUMB_KERNEL_MAP, for struct drm_mode_create_dumb. This flag is for internal kernel use to indicate if dumb buffer allocation needs a kernel mapping. This is needed only for GEM DMA where creating a kernel mapping or not has to be decided at allocation time because creating a mapping on demand (with vmap()) is not guaranteed to work.

I still don't understand what you're trying to achieve. As I pointed out, ever driver's memory manager potentially requires a vmap. Passing around flags will not solve that problem. If vmap is not possible, the driver should not provide the vmap callbacks in the first place.

Best regards
Thomas

Quoted 81 lines

Several drivers are using reimplementing the GEM DMA helpers because they distinguish between kernel and userspace allocations to create a kernel mapping or not. Adding a flag allows migrating these drivers to the helpers while preserving their existing behavior. These include exynos, rockchip, and previously mediatek.

Update the callers of drm_mode_dumb_create() to set drm_mode_dumb_create.flags to appropriate defaults. Currently, flags can be set to anything by userspace, but is unused within the kernel. Let's force flags to zero (no kernel mapping) for userspace callers by default. For in kernel clients, set DRM_MODE_DUMB_KERNEL_MAP by default. Drivers can override this as needed.

[[email protected]: Emit warning (once) if args->flags is not zero]
[[email protected]: Moved flag def. to include/drm/drm_dumb_buffers.h]

---
Changes since v2:
- Switched to drm_warn_once()
- Moved flag definition from include/uapi/ to include/drm/drm_dumb_buffers.h
- Reworded commit message

Changes since v1:
- Emit warning if args->flags is not zero

---
  drivers/gpu/drm/drm_client.c       | 2 ++
  drivers/gpu/drm/drm_dumb_buffers.c | 4 ++++
  include/drm/drm_dumb_buffers.h     | 3 +++
  3 files changed, 9 insertions(+)
drivers/gpu/drm/drm_client.c +2 -0
index 46c465bce98c..3d3e61823cc1 100644
@@ -14,6 +14,7 @@
  #include <drm/drm_client_event.h>
  #include <drm/drm_device.h>
  #include <drm/drm_drv.h>
+#include <drm/drm_dumb_buffers.h>
  #include <drm/drm_file.h>
  #include <drm/drm_fourcc.h>
  #include <drm/drm_framebuffer.h>
@@ -404,6 +405,7 @@ drm_client_buffer_create_dumb(struct drm_client_dev *client, u32 width, u32 heig
  	dumb_args.width = width;
  	dumb_args.height = height;
  	dumb_args.bpp = drm_format_info_bpp(info, 0);
+	dumb_args.flags = DRM_MODE_DUMB_KERNEL_MAP;
  	ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
  	if (ret)
  		return ERR_PTR(ret);
drivers/gpu/drm/drm_dumb_buffers.c +4 -0
index e2b62e5fb891..60f4c2d08641 100644
@@ -233,6 +233,10 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev,
  	struct drm_mode_create_dumb *args = data;
  	int err;
 
+	if (args->flags)
+		drm_warn_once(dev, "drm_mode_create_dumb.flags is not zero.\n");
+	args->flags = 0;
+
  	err = drm_mode_create_dumb(dev, args, file_priv);
  	if (err) {
  		args->handle = 0;
include/drm/drm_dumb_buffers.h +3 -0
index 1f3a8236fb3d..4657e44533f4 100644
@@ -6,6 +6,9 @@
  struct drm_device;
  struct drm_mode_create_dumb;
 
+/* drm_mode_create_dumb flags for internal use */
+#define DRM_MODE_DUMB_KERNEL_MAP	(1<<0)
+
  int drm_mode_size_dumb(struct drm_device *dev,
  		       struct drm_mode_create_dumb *args,
  		       unsigned long hw_pitch_align,
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#3 lore raw

Re: [PATCH v3 1/3] drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag

Quoted 13 lines · Thomas Zimmermann

Hi

Am 26.03.26 um 11:01 schrieb Chen-Yu Tsai:

Quoted 8 lines

From: Rob Herring <[email protected]>

Introduce a new flag, DRM_MODE_DUMB_KERNEL_MAP, for struct drm_mode_create_dumb. This flag is for internal kernel use to indicate if dumb buffer allocation needs a kernel mapping. This is needed only for GEM DMA where creating a kernel mapping or not has to be decided at allocation time because creating a mapping on demand (with vmap()) is not guaranteed to work.

Quoted 4 lines

I still don't understand what you're trying to achieve. As I pointed out, ever driver's memory manager potentially requires a vmap. Passing around flags will not solve that problem. If vmap is not possible, the driver should not provide the vmap callbacks in the first place.

I'm trying to convert the Rockchip and Exynos drivers to the GEM DMA helpers. Both have their reasons for not using the helpers, one of them being that the DRM device is not the DMA device. This is already fixed by my other series. Both drivers also set DMA_ATTR_NO_KERNEL_MAPPING for buffer allocations other than the one used by fb_helper.

Exynos's GEM implementation also sets extra DMA attributes at the allocation phase for their custom GEM create ioctl. But otherwise exynos is just reimplementing all the GEM DMA helpers in almost identical fashion. And to your point, exynos does not provide the vmap callback.

Rockchip's GEM implementation splits the code path between DMA and IOMMU usage as it needs to attach and detach the DMA device from the IOMMU domain on the fly. This predates the DMA IOMMU framework. This GEM implementation provides the vmap callback, which will fail for direct DMA allocations without the kernel mapping.

There's also something fishy about Rockchip's DRM driver. It's using fbdev-dma, even though it's not based on the GEM DMA helpers or even drm_gem_dma_object.

As you are against changing the existing *_dumb_create() interface, I will look into reusing drm_gem_dma_object with driver-specific functions. I believe I will need to keep patch 2 adding dma_attrs though. Would that be acceptable?

Once again, thank you for your patience.

ChenYu

Quoted 94 lines

Best regards
Thomas

Quoted 72 lines

Several drivers are using reimplementing the GEM DMA helpers because they distinguish between kernel and userspace allocations to create a kernel mapping or not. Adding a flag allows migrating these drivers to the helpers while preserving their existing behavior. These include exynos, rockchip, and previously mediatek.

Update the callers of drm_mode_dumb_create() to set drm_mode_dumb_create.flags to appropriate defaults. Currently, flags can be set to anything by userspace, but is unused within the kernel. Let's force flags to zero (no kernel mapping) for userspace callers by default. For in kernel clients, set DRM_MODE_DUMB_KERNEL_MAP by default. Drivers can override this as needed.

[[email protected]: Emit warning (once) if args->flags is not zero]
[[email protected]: Moved flag def. to include/drm/drm_dumb_buffers.h]

---
Changes since v2:
- Switched to drm_warn_once()
- Moved flag definition from include/uapi/ to include/drm/drm_dumb_buffers.h
- Reworded commit message

Changes since v1:
- Emit warning if args->flags is not zero

---
  drivers/gpu/drm/drm_client.c       | 2 ++
  drivers/gpu/drm/drm_dumb_buffers.c | 4 ++++
  include/drm/drm_dumb_buffers.h     | 3 +++
  3 files changed, 9 insertions(+)
drivers/gpu/drm/drm_client.c +2 -0
index 46c465bce98c..3d3e61823cc1 100644
@@ -14,6 +14,7 @@
  #include <drm/drm_client_event.h>
  #include <drm/drm_device.h>
  #include <drm/drm_drv.h>
+#include <drm/drm_dumb_buffers.h>
  #include <drm/drm_file.h>
  #include <drm/drm_fourcc.h>
  #include <drm/drm_framebuffer.h>
@@ -404,6 +405,7 @@ drm_client_buffer_create_dumb(struct drm_client_dev *client, u32 width, u32 heig
      dumb_args.width = width;
      dumb_args.height = height;
      dumb_args.bpp = drm_format_info_bpp(info, 0);
+     dumb_args.flags = DRM_MODE_DUMB_KERNEL_MAP;
      ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
      if (ret)
              return ERR_PTR(ret);
drivers/gpu/drm/drm_dumb_buffers.c +4 -0
index e2b62e5fb891..60f4c2d08641 100644
@@ -233,6 +233,10 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev,
      struct drm_mode_create_dumb *args = data;
      int err;
 
+     if (args->flags)
+             drm_warn_once(dev, "drm_mode_create_dumb.flags is not zero.\n");
+     args->flags = 0;
+
      err = drm_mode_create_dumb(dev, args, file_priv);
      if (err) {
              args->handle = 0;
include/drm/drm_dumb_buffers.h +0 -0
index 1f3a8236fb3d..4657e44533f4 100644

include/drm/drm_dumb_buffers.h line 14

Quoted 9 lines
include/drm/drm_dumb_buffers.h +3 -0
@@ -6,6 +6,9 @@
  struct drm_device;
  struct drm_mode_create_dumb;
 
+/* drm_mode_create_dumb flags for internal use */
+#define DRM_MODE_DUMB_KERNEL_MAP     (1<<0)
+
  int drm_mode_size_dumb(struct drm_device *dev,
                     struct drm_mode_create_dumb *args,
                     unsigned long hw_pitch_align,

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)

#4 lore raw

Re: [PATCH v3 1/3] drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag

Hi

Am 27.03.26 um 10:38 schrieb Chen-Yu Tsai:

Quoted 12 lines · Thomas Zimmermann
Quoted 11 lines

Hi

Am 26.03.26 um 11:01 schrieb Chen-Yu Tsai:

Quoted 8 lines

From: Rob Herring <[email protected]>

Introduce a new flag, DRM_MODE_DUMB_KERNEL_MAP, for struct drm_mode_create_dumb. This flag is for internal kernel use to indicate if dumb buffer allocation needs a kernel mapping. This is needed only for GEM DMA where creating a kernel mapping or not has to be decided at allocation time because creating a mapping on demand (with vmap()) is not guaranteed to work.

Quoted 5 lines
Quoted 4 lines

I still don't understand what you're trying to achieve. As I pointed out, ever driver's memory manager potentially requires a vmap. Passing around flags will not solve that problem. If vmap is not possible, the driver should not provide the vmap callbacks in the first place.

I'm trying to convert the Rockchip and Exynos drivers to the GEM DMA

Ok.

Quoted 17 lines

helpers. Both have their reasons for not using the helpers, one of them being that the DRM device is not the DMA device. This is already fixed by my other series. Both drivers also set DMA_ATTR_NO_KERNEL_MAPPING for buffer allocations other than the one used by fb_helper.

Exynos's GEM implementation also sets extra DMA attributes at the allocation phase for their custom GEM create ioctl. But otherwise exynos is just reimplementing all the GEM DMA helpers in almost identical fashion. And to your point, exynos does not provide the vmap callback.

Rockchip's GEM implementation splits the code path between DMA and IOMMU usage as it needs to attach and detach the DMA device from the IOMMU domain on the fly. This predates the DMA IOMMU framework. This GEM implementation provides the vmap callback, which will fail for direct DMA allocations without the kernel mapping.

Quoted 3 lines

There's also something fishy about Rockchip's DRM driver. It's using fbdev-dma, even though it's not based on the GEM DMA helpers or even drm_gem_dma_object.

Oh!

Quoted 5 lines

As you are against changing the existing *_dumb_create() interface, I will look into reusing drm_gem_dma_object with driver-specific functions. I believe I will need to keep patch 2 adding dma_attrs though. Would that be acceptable?

I think so. Sharing code is good, but I don't like these flags that change a function's overall behavior. I think that's the case here. Flags are OK when they extent or modify a little detail, but extensively used the affected code becomes unmaintainable. It's better to have a dedicated function for such special cases. What you could do is to provide a separate helper that allocates an object with the specific vmap behavior and use it for these drivers. The allocator function should also set dedicated gem-object funcs w/o vmap/vunmap where possible.  Drivers can then pick the helpers.

If you 're looking for an example, take a look at commit 660cd44659a0 ("drm/shmem-helper: Import dmabuf without mapping its sg_table")  and it's patch series.  With gem-shmem, many drivers don't work correctly with the sg-table imported.  The commit provides them with a separate import helper that takes care of this.

Best regards
Thomas

Quoted 99 lines

Once again, thank you for your patience.

ChenYu

Quoted 92 lines

Best regards
Thomas

Quoted 71 lines

Several drivers are using reimplementing the GEM DMA helpers because they distinguish between kernel and userspace allocations to create a kernel mapping or not. Adding a flag allows migrating these drivers to the helpers while preserving their existing behavior. These include exynos, rockchip, and previously mediatek.

Update the callers of drm_mode_dumb_create() to set drm_mode_dumb_create.flags to appropriate defaults. Currently, flags can be set to anything by userspace, but is unused within the kernel. Let's force flags to zero (no kernel mapping) for userspace callers by default. For in kernel clients, set DRM_MODE_DUMB_KERNEL_MAP by default. Drivers can override this as needed.

[[email protected]: Emit warning (once) if args->flags is not zero]
[[email protected]: Moved flag def. to include/drm/drm_dumb_buffers.h]

---
Changes since v2:
- Switched to drm_warn_once()
- Moved flag definition from include/uapi/ to include/drm/drm_dumb_buffers.h
- Reworded commit message

Changes since v1:
- Emit warning if args->flags is not zero

---
   drivers/gpu/drm/drm_client.c       | 2 ++
   drivers/gpu/drm/drm_dumb_buffers.c | 4 ++++
   include/drm/drm_dumb_buffers.h     | 3 +++
   3 files changed, 9 insertions(+)
drivers/gpu/drm/drm_client.c +2 -0
index 46c465bce98c..3d3e61823cc1 100644
@@ -14,6 +14,7 @@
   #include <drm/drm_client_event.h>
   #include <drm/drm_device.h>
   #include <drm/drm_drv.h>
+#include <drm/drm_dumb_buffers.h>
   #include <drm/drm_file.h>
   #include <drm/drm_fourcc.h>
   #include <drm/drm_framebuffer.h>
@@ -404,6 +405,7 @@ drm_client_buffer_create_dumb(struct drm_client_dev *client, u32 width, u32 heig
       dumb_args.width = width;
       dumb_args.height = height;
       dumb_args.bpp = drm_format_info_bpp(info, 0);
+     dumb_args.flags = DRM_MODE_DUMB_KERNEL_MAP;
       ret = drm_mode_create_dumb(dev, &dumb_args, client->file);
       if (ret)
               return ERR_PTR(ret);
drivers/gpu/drm/drm_dumb_buffers.c +4 -0
index e2b62e5fb891..60f4c2d08641 100644
@@ -233,6 +233,10 @@ int drm_mode_create_dumb_ioctl(struct drm_device *dev,
       struct drm_mode_create_dumb *args = data;
       int err;
 
+     if (args->flags)
+             drm_warn_once(dev, "drm_mode_create_dumb.flags is not zero.\n");
+     args->flags = 0;
+
       err = drm_mode_create_dumb(dev, args, file_priv);
       if (err) {
               args->handle = 0;
include/drm/drm_dumb_buffers.h +0 -0
index 1f3a8236fb3d..4657e44533f4 100644

include/drm/drm_dumb_buffers.h line 14

Quoted 9 lines
include/drm/drm_dumb_buffers.h +3 -0
@@ -6,6 +6,9 @@
   struct drm_device;
   struct drm_mode_create_dumb;
 
+/* drm_mode_create_dumb flags for internal use */
+#define DRM_MODE_DUMB_KERNEL_MAP     (1<<0)
+
   int drm_mode_size_dumb(struct drm_device *dev,
                      struct drm_mode_create_dumb *args,
                      unsigned long hw_pitch_align,

--
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)

Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#5 lore raw

PATCH v3 2/3 drm/gem-dma: Use the dma_*_attr API variant

In reply to Chen-Yu Tsai

From: Rob Herring <[email protected]>

In preparation to allow DRM DMA users to adjust the DMA_ATTR_* flags, convert the DMA helper code to use the dma_*_attr APIs instead of the dma_*_wc variants.

Only the DMA_ATTR_WRITE_COMBINE and DMA_ATTR_NO_WARN attributes are set in this commit, so there's no functional change.

Update rcar_du_vsp_map_fb() to use dma_get_sgtable_attrs() instead of dma_get_sgtable().

Also change the dma_free_wc() call in vc4_bo_purge() in the vc4 driver to use dma_free_attrs() to match. vc4_bo is a sub-class of drm_gem_dma_object.

Sub-classes of |struct drm_gem_dma_object| can also set additional DMA_ATTR_* flags if they choose so. For example a sub-class could set DMA_ATTR_FORCE_CONTIGUOUS in certain cases.

[[email protected]: Rebase onto renamed DMA helpers]
[[email protected]: Make vc4_bo_purge() use matching dma_free_attrs()]
[[email protected]: Make rcar_du_vsp_map_fb() use dma_get_sgtable_attrs()]

[[email protected]: Expand commit message to mention that sub-classes
can set extra DMA_ATTR_* flags]

---
Changes since v2:
- rcar-du: Change dma_get_sgtable() to dma_get_sgtable_attrs()

Changes since v1:
- Rebased onto renamed DMA helpers
- Made vc4_bo_purge() use matching dma_free_attrs()
- Expanded commit message to mention that sub-classes can set extra DMA_ATTR_* flags

---
 drivers/gpu/drm/drm_gem_dma_helper.c          | 26 +++++++++++--------
 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c |  5 ++--
 drivers/gpu/drm/vc4/vc4_bo.c                  |  2 +-
 include/drm/drm_gem_dma_helper.h              |  3 +++
 4 files changed, 22 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_gem_dma_helper.c +15 -11
index 1c00a71ab3c9..9722c9fc86f3 100644
@@ -108,6 +108,7 @@ __drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
 		goto error;
 	}
 
+	dma_obj->dma_attrs |= DMA_ATTR_NO_WARN | DMA_ATTR_WRITE_COMBINE;
 	return dma_obj;
 
 error:
@@ -152,9 +153,10 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
 						       DMA_TO_DEVICE,
 						       GFP_KERNEL | __GFP_NOWARN);
 	} else {
-		dma_obj->vaddr = dma_alloc_wc(drm_dev_dma_dev(drm), size,
-					      &dma_obj->dma_addr,
-					      GFP_KERNEL | __GFP_NOWARN);
+		dma_obj->vaddr = dma_alloc_attrs(drm_dev_dma_dev(drm), size,
+						 &dma_obj->dma_addr,
+						 GFP_KERNEL | __GFP_NOWARN,
+						 dma_obj->dma_attrs);
 	}
 	if (!dma_obj->vaddr) {
 		drm_dbg(drm, "failed to allocate buffer with size %zu\n",
@@ -242,9 +244,9 @@ void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)
 					     dma_obj->vaddr, dma_obj->dma_addr,
 					     DMA_TO_DEVICE);
 		else
-			dma_free_wc(drm_dev_dma_dev(gem_obj->dev),
-				    dma_obj->base.size, dma_obj->vaddr,
-				    dma_obj->dma_addr);
+			dma_free_attrs(drm_dev_dma_dev(gem_obj->dev),
+				       dma_obj->base.size, dma_obj->vaddr,
+				       dma_obj->dma_addr, dma_obj->dma_attrs);
 	}
 
 	drm_gem_object_release(gem_obj);
@@ -435,8 +437,9 @@ struct sg_table *drm_gem_dma_get_sg_table(struct drm_gem_dma_object *dma_obj)
 	if (!sgt)
 		return ERR_PTR(-ENOMEM);
 
-	ret = dma_get_sgtable(drm_dev_dma_dev(obj->dev), sgt, dma_obj->vaddr,
-			      dma_obj->dma_addr, obj->size);
+	ret = dma_get_sgtable_attrs(drm_dev_dma_dev(obj->dev), sgt,
+				    dma_obj->vaddr, dma_obj->dma_addr,
+				    obj->size, dma_obj->dma_attrs);
 	if (ret < 0)
 		goto out;
 
@@ -546,9 +549,10 @@ int drm_gem_dma_mmap(struct drm_gem_dma_object *dma_obj, struct vm_area_struct *
 				     vma, vma->vm_end - vma->vm_start,
 				     virt_to_page(dma_obj->vaddr));
 	} else {
-		ret = dma_mmap_wc(drm_dev_dma_dev(dma_obj->base.dev), vma,
-				  dma_obj->vaddr, dma_obj->dma_addr,
-				  vma->vm_end - vma->vm_start);
+		ret = dma_mmap_attrs(drm_dev_dma_dev(dma_obj->base.dev), vma,
+				     dma_obj->vaddr, dma_obj->dma_addr,
+				     vma->vm_end - vma->vm_start,
+				     dma_obj->dma_attrs);
 	}
 	if (ret)
 		drm_gem_vm_close(vma);
drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c +3 -2
index 94c22d2db197..a4896096e3bc 100644
@@ -291,8 +291,9 @@ int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb,
 				dst = sg_next(dst);
 			}
 		} else {
-			ret = dma_get_sgtable(rcdu->dev, sgt, gem->vaddr,
-					      gem->dma_addr, gem->base.size);
+			ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
+						    gem->dma_addr, gem->base.size
+						    gem->dma_attrs);
 			if (ret)
 				goto fail;
 		}
drivers/gpu/drm/vc4/vc4_bo.c +1 -1
index f45ba47b4ba8..981593739a0f 100644
@@ -304,7 +304,7 @@ static void vc4_bo_purge(struct drm_gem_object *obj)
 
 	drm_vma_node_unmap(&obj->vma_node, dev->anon_inode->i_mapping);
 
-	dma_free_wc(dev->dev, obj->size, bo->base.vaddr, bo->base.dma_addr);
+	dma_free_attrs(dev->dev, obj->size, bo->base.vaddr, bo->base.dma_addr, bo->base.dma_attrs);
 	bo->base.vaddr = NULL;
 	bo->madv = __VC4_MADV_PURGED;
 }
include/drm/drm_gem_dma_helper.h +3 -0
index f2678e7ecb98..e815ff121e23 100644
@@ -16,6 +16,8 @@ struct drm_mode_create_dumb;
  *       more than one entry but they are guaranteed to have contiguous
  *       DMA addresses.
  * @vaddr: kernel virtual address of the backing memory
+ * @dma_attrs: DMA attributes used when allocating backing memory.
+ *             Only applies to coherent memory.
  * @map_noncoherent: if true, the GEM object is backed by non-coherent memory
  */
 struct drm_gem_dma_object {
@@ -25,6 +27,7 @@ struct drm_gem_dma_object {
 
 	/* For objects with DMA memory allocated by GEM DMA */
 	void *vaddr;
+	unsigned long dma_attrs;
 
 	bool map_noncoherent;
 };
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
#6 lore raw

Re: [PATCH v3 2/3] drm/gem-dma: Use the dma_*_attr API variant

Quoted 44 lines · Chen-Yu Tsai

From: Rob Herring <[email protected]>

In preparation to allow DRM DMA users to adjust the DMA_ATTR_* flags, convert the DMA helper code to use the dma_*_attr APIs instead of the dma_*_wc variants.

Only the DMA_ATTR_WRITE_COMBINE and DMA_ATTR_NO_WARN attributes are set in this commit, so there's no functional change.

Update rcar_du_vsp_map_fb() to use dma_get_sgtable_attrs() instead of dma_get_sgtable().

Also change the dma_free_wc() call in vc4_bo_purge() in the vc4 driver to use dma_free_attrs() to match. vc4_bo is a sub-class of drm_gem_dma_object.

Sub-classes of |struct drm_gem_dma_object| can also set additional DMA_ATTR_* flags if they choose so. For example a sub-class could set DMA_ATTR_FORCE_CONTIGUOUS in certain cases.

[[email protected]: Rebase onto renamed DMA helpers]
[[email protected]: Make vc4_bo_purge() use matching dma_free_attrs()]
[[email protected]: Make rcar_du_vsp_map_fb() use dma_get_sgtable_attrs()]

[[email protected]: Expand commit message to mention that sub-classes
can set extra DMA_ATTR_* flags]

---
Changes since v2:
- rcar-du: Change dma_get_sgtable() to dma_get_sgtable_attrs()

Changes since v1:
- Rebased onto renamed DMA helpers
- Made vc4_bo_purge() use matching dma_free_attrs()
- Expanded commit message to mention that sub-classes can set extra DMA_ATTR_* flags

---
 drivers/gpu/drm/drm_gem_dma_helper.c          | 26 +++++++++++--------
 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c |  5 ++--
 drivers/gpu/drm/vc4/vc4_bo.c                  |  2 +-
 include/drm/drm_gem_dma_helper.h              |  3 +++
 4 files changed, 22 insertions(+), 14 deletions(-)

[...]

drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb, · line 296

Quoted 13 lines
drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c +3 -2
index 94c22d2db197..a4896096e3bc 100644
@@ -291,8 +291,9 @@ int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb,
                                dst = sg_next(dst);
                        }
                } else {
-                       ret = dma_get_sgtable(rcdu->dev, sgt, gem->vaddr,
-                                             gem->dma_addr, gem->base.size);
+                       ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
+                                                   gem->dma_addr, gem->base.size
+                                                   gem->dma_attrs);

This doesn't compile. Sorry for the noise.

#7 lore raw

Re: [PATCH v3 2/3] drm/gem-dma: Use the dma_*_attr API variant

In reply to Chen-Yu Tsai
kernel test robot noticed the following build errors:

Hi Chen-Yu,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260327]
[cannot apply to sunxi/sunxi/for-next linus/master v7.0-rc5] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Yu-Tsai/drm-Introduce-DRM_MODE_DUMB_KERNEL_MAP-flag/20260328-141115
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260326100248.1171828-3-wenst%40chromium.org
patch subject: [PATCH v3 2/3] drm/gem-dma: Use the dma_*_attr API variant
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20260328/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260328/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c: In function 'rcar_du_vsp_map_fb':

>> drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:296:82: error: expected ')' before 'gem'
     296 |                                                     gem->dma_addr, gem->base.size
         |                                                                                  ^
         |                                                                                  )
     297 |                                                     gem->dma_attrs);
         |                                                     ~~~                           
   drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:295:52: note: to match this '('
     295 |                         ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
         |                                                    ^
>> drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:295:31: error: too few arguments to function 'dma_get_sgtable_attrs'; expected 6, have 5
     295 |                         ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
         |                               ^~~~~~~~~~~~~~~~~~~~~
   In file included from include/linux/dma-buf.h:21,
                    from include/drm/drm_gem.h:38,
                    from include/drm/drm_gem_dma_helper.h:7,
                    from drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:18:

include/linux/dma-mapping.h:172:5: note: declared here
172 | int dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt,
| ^~~~~~~~~~~~~~~~~~~~~

vim +296 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c

258
259 int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb,
260 struct sg_table sg_tables[3])
261 {
262 struct rcar_du_device *rcdu = vsp->dev;
263 unsigned int i, j;
264 int ret;
265
266 for (i = 0; i < fb->format->num_planes; ++i) {
267 struct drm_gem_dma_object *gem = drm_fb_dma_get_gem_obj(fb, i);
268 struct sg_table *sgt = &sg_tables[i];
269
270 if (gem->sgt) {
271 struct scatterlist *src;
272 struct scatterlist *dst;
273
274 /*
275 * If the GEM buffer has a scatter gather table, it has
276 * been imported from a dma-buf and has no physical
277 * address as it might not be physically contiguous.
278 * Copy the original scatter gather table to map it to
279 * the VSP.
280 */
281 ret = sg_alloc_table(sgt, gem->sgt->orig_nents,
282 GFP_KERNEL);
283 if (ret)
284 goto fail;
285
286 src = gem->sgt->sgl;
287 dst = sgt->sgl;
288 for (j = 0; j < gem->sgt->orig_nents; ++j) {
289 sg_set_page(dst, sg_page(src), src->length,
290 src->offset);
291 src = sg_next(src);
292 dst = sg_next(dst);
293 }
294 } else {

 > 295				ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
 > 296							    gem->dma_addr, gem->base.size

297 gem->dma_attrs);
298 if (ret)
299 goto fail;
300 }
301
302 ret = vsp1_du_map_sg(vsp->vsp, sgt);
303 if (ret) {
304 sg_free_table(sgt);
305 goto fail;
306 }
307 }
308
309 return 0;
310
311 fail:
312 while (i--) {
313 struct sg_table *sgt = &sg_tables[i];
314
315 vsp1_du_unmap_sg(vsp->vsp, sgt);
316 sg_free_table(sgt);
317 }
318
319 return ret;
320 }
321

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

Re: [PATCH v3 2/3] drm/gem-dma: Use the dma_*_attr API variant

In reply to Chen-Yu Tsai
kernel test robot noticed the following build errors:

Hi Chen-Yu,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260327]
[cannot apply to sunxi/sunxi/for-next linus/master v7.0-rc5] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Yu-Tsai/drm-Introduce-DRM_MODE_DUMB_KERNEL_MAP-flag/20260328-141115
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260326100248.1171828-3-wenst%40chromium.org
patch subject: [PATCH v3 2/3] drm/gem-dma: Use the dma_*_attr API variant
config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20260329/[email protected]/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260329/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:297:11: error: expected ')'
     297 |                                                     gem->dma_attrs);
         |                                                     ^
   drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c:295:31: note: to match this '('
     295 |                         ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
         |                                                    ^

1 error generated.

vim +297 drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c

258
259 int rcar_du_vsp_map_fb(struct rcar_du_vsp *vsp, struct drm_framebuffer *fb,
260 struct sg_table sg_tables[3])
261 {
262 struct rcar_du_device *rcdu = vsp->dev;
263 unsigned int i, j;
264 int ret;
265
266 for (i = 0; i < fb->format->num_planes; ++i) {
267 struct drm_gem_dma_object *gem = drm_fb_dma_get_gem_obj(fb, i);
268 struct sg_table *sgt = &sg_tables[i];
269
270 if (gem->sgt) {
271 struct scatterlist *src;
272 struct scatterlist *dst;
273
274 /*
275 * If the GEM buffer has a scatter gather table, it has
276 * been imported from a dma-buf and has no physical
277 * address as it might not be physically contiguous.
278 * Copy the original scatter gather table to map it to
279 * the VSP.
280 */
281 ret = sg_alloc_table(sgt, gem->sgt->orig_nents,
282 GFP_KERNEL);
283 if (ret)
284 goto fail;
285
286 src = gem->sgt->sgl;
287 dst = sgt->sgl;
288 for (j = 0; j < gem->sgt->orig_nents; ++j) {
289 sg_set_page(dst, sg_page(src), src->length,
290 src->offset);
291 src = sg_next(src);
292 dst = sg_next(dst);
293 }
294 } else {
295 ret = dma_get_sgtable_attrs(rcdu->dev, sgt, gem->vaddr,
296 gem->dma_addr, gem->base.size

 > 297							    gem->dma_attrs);

298 if (ret)
299 goto fail;
300 }
301
302 ret = vsp1_du_map_sg(vsp->vsp, sgt);
303 if (ret) {
304 sg_free_table(sgt);
305 goto fail;
306 }
307 }
308
309 return 0;
310
311 fail:
312 while (i--) {
313 struct sg_table *sgt = &sg_tables[i];
314
315 vsp1_du_unmap_sg(vsp->vsp, sgt);
316 sg_free_table(sgt);
317 }
318
319 return ret;
320 }
321

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#9 lore raw

PATCH v3 3/3 drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag

In reply to Chen-Yu Tsai

From: Rob Herring <[email protected]>

Add support in DMA helpers to handle callers specifying DRM_MODE_DUMB_KERNEL_MAP flag. Existing behavior is maintained with this change. drm_gem_dma_dumb_create() always creates a kernel mapping as before. drm_gem_dma_dumb_create_internal() lets the caller set the flags as desired.

drm_gem_dma_dumb_create_internal() users have DRM_MODE_DUMB_KERNEL_MAP added to preserve existing behavior.

A dumb buffer allocated from these devices can be shared (exported) to another device. The consuming device may require the kernel mapping to scan out the buffer to its own display. Such devices include DisplayLink and various MIPI DBI based displays. Therefore altering the behavior should be given much consideration.

[[email protected]: Rebase onto renamed GEM DMA helpers]
[[email protected]: show "vaddr=(no mapping)" in drm_gem_dma_print_info()]
[[email protected]: Add DRM_MODE_DUMB_KERNEL_MAP to new drivers]

[[email protected]: Add flags field to drm_gem_dma_create_with_handle()
kerneldoc]

---
Changes since v2:
- Added back DRM_MODE_DUMB_KERNEL_MAP flag to all drivers calling drm_gem_dma_dumb_create_internal()
- Expanded commit message to cover display drivers needing the kernel mapping to do scan out

Changes since v1:
- Rebased onto renamed GEM DMA helpers
- Added check in drm_fb_dma_get_scanout_buffer() and drm_gem_dma_vmap().
- Made drm_gem_dma_print_info() show "vaddr=(no mapping)" for objects allocated without kernel mapping
- Dropped existing DRM_MODE_DUMB_KERNEL_MAP flag addition in various drivers
- Added DRM_MODE_DUMB_KERNEL_MAP flag to adp_drm_gem_dumb_create()
- Added flags field kerneldoc for drm_gem_dma_create_with_handle()

Cc Sasha Finkelstein <[email protected]>
Cc Janne Grunau <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Kieran Bingham <[email protected]>
Cc Biju Das <[email protected]>
Cc Yannick Fertre <[email protected]>
Cc Raphael Gallais-Pou <[email protected]>
Cc Philippe Cornu <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Dave Stevenson <[email protected]>
Cc "Maíra Canal" <[email protected]>
Cc Raspberry Pi Kernel Maintenance <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
---
 drivers/gpu/drm/adp/adp_drv.c                 |  1 +
 .../gpu/drm/arm/display/komeda/komeda_kms.c   |  1 +
 drivers/gpu/drm/arm/malidp_drv.c              |  1 +
 drivers/gpu/drm/drm_fb_dma_helper.c           |  4 ++
 drivers/gpu/drm/drm_gem_dma_helper.c          | 67 ++++++++++++-------
 drivers/gpu/drm/logicvc/logicvc_drm.c         |  1 +
 drivers/gpu/drm/meson/meson_drv.c             |  1 +
 drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c |  2 +
 drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c  |  1 +
 drivers/gpu/drm/stm/drv.c                     |  3 +-
 drivers/gpu/drm/sun4i/sun4i_drv.c             |  1 +
 drivers/gpu/drm/vc4/vc4_drv.c                 |  2 +
 drivers/gpu/drm/verisilicon/vs_drm.c          |  2 +
 drivers/gpu/drm/xlnx/zynqmp_kms.c             |  2 +
 14 files changed, 63 insertions(+), 26 deletions(-)
drivers/gpu/drm/adp/adp_drv.c +1 -0
index 4554cf75565e..c549b44b3814 100644
@@ -95,6 +95,7 @@ static int adp_drm_gem_dumb_create(struct drm_file *file_priv,
 {
 	args->height = ALIGN(args->height, 64);
 	args->size = args->pitch * args->height;
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 
 	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
 }
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +1 -0
index 6ed504099188..2c096ebaea33 100644
@@ -29,6 +29,7 @@ static int komeda_gem_dma_dumb_create(struct drm_file *file,
 	struct komeda_dev *mdev = dev->dev_private;
 	u32 pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	args->pitch = ALIGN(pitch, mdev->chip.bus_width);
 
 	return drm_gem_dma_dumb_create_internal(file, dev, args);
drivers/gpu/drm/arm/malidp_drv.c +1 -0
index b765f6c9eea4..5519f48a27c0 100644
@@ -464,6 +464,7 @@ static int malidp_dumb_create(struct drm_file *file_priv,
 	/* allocate for the worst case scenario, i.e. rotated buffers */
 	u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), alignment);
 
 	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
drivers/gpu/drm/drm_fb_dma_helper.c +4 -0
index fd71969d2fb1..12a44accc48c 100644
@@ -187,6 +187,10 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane,
 	if (!dma_obj->vaddr)
 		return -ENODEV;
 
+	/* Buffer was allocated with NO_KERNEL_MAPPING */
+	if (dma_obj->dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+		return -ENODEV;
+
 	iosys_map_set_vaddr(&sb->map[0], dma_obj->vaddr);
 	sb->format = fb->format;
 	sb->height = fb->height;
drivers/gpu/drm/drm_gem_dma_helper.c +42 -25

132 lines not on this page · raw message

drivers/gpu/drm/logicvc/logicvc_drm.c +1 -0
index bbebf4fc7f51..595a71163cb5 100644
@@ -39,6 +39,7 @@ static int logicvc_drm_gem_dma_dumb_create(struct drm_file *file_priv,
 {
 	struct logicvc_drm *logicvc = logicvc_drm(drm_dev);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	/* Stride is always fixed to its configuration value. */
 	args->pitch = logicvc->config.row_stride * DIV_ROUND_UP(args->bpp, 8);
 
drivers/gpu/drm/meson/meson_drv.c +1 -0
index 49ff9f1f16d3..9fa339d6e273 100644
@@ -83,6 +83,7 @@ static irqreturn_t meson_irq(int irq, void *arg)
 static int meson_dumb_create(struct drm_file *file, struct drm_device *dev,
 			     struct drm_mode_create_dumb *args)
 {
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	/*
 	 * We need 64bytes aligned stride, and PAGE aligned size
 	 */
drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c +2 -0
index 60e6f43b8ab2..611fe3d4a4d8 100644
@@ -424,6 +424,8 @@ int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev,
 	if (ret)
 		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
 	return drm_gem_dma_dumb_create_internal(file, dev, args);
 }
 
drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c +1 -0
index 87f171145a23..359f85bd84eb 100644
@@ -184,6 +184,7 @@ int rzg2l_du_dumb_create(struct drm_file *file, struct drm_device *dev,
 	unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
 	unsigned int align = 16 * args->bpp / 8;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	args->pitch = roundup(min_pitch, align);
 
 	return drm_gem_dma_dumb_create_internal(file, dev, args);
drivers/gpu/drm/stm/drv.c +2 -1
index 56d53ac3082d..a0bc2e215adb 100644
@@ -51,8 +51,9 @@ static int stm_gem_dma_dumb_create(struct drm_file *file,
 	 * in order to optimize data transfer, pitch is aligned on
 	 * 128 bytes, height is aligned on 4 bytes
 	 */
-	args->pitch = roundup(min_pitch, 128);
 	args->height = roundup(args->height, 4);
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+	args->pitch = roundup(min_pitch, 128);
 
 	return drm_gem_dma_dumb_create_internal(file, dev, args);
 }
drivers/gpu/drm/sun4i/sun4i_drv.c +1 -0
index 8a409eee1dca..d3ff53ce2450 100644
@@ -36,6 +36,7 @@ static int drm_sun4i_gem_dumb_create(struct drm_file *file_priv,
 				     struct drm_device *drm,
 				     struct drm_mode_create_dumb *args)
 {
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 	/* The hardware only allows even pitches for YUV buffers. */
 	args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), 2);
 
drivers/gpu/drm/vc4/vc4_drv.c +2 -0
index a14ecb769461..7a04cf52f511 100644
@@ -87,6 +87,8 @@ static int vc5_dumb_create(struct drm_file *file_priv,
 	if (ret)
 		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
 	return drm_gem_dma_dumb_create_internal(file_priv, dev, args);
 }
 
drivers/gpu/drm/verisilicon/vs_drm.c +2 -0
index fd259d53f49f..fe3591244d02 100644
@@ -44,6 +44,8 @@ static int vs_gem_dumb_create(struct drm_file *file_priv,
 	if (ret)
 		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
 	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
 }
 
drivers/gpu/drm/xlnx/zynqmp_kms.c +2 -0
index 02f3a7d78cf8..aa3822b3cb08 100644
@@ -371,6 +371,8 @@ static int zynqmp_dpsub_dumb_create(struct drm_file *file_priv,
 	if (ret)
 		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
 	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
 }
 
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog
#10 lore raw

Re: [PATCH v3 3/3] drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag

Quoted 216 lines · Chen-Yu Tsai

From: Rob Herring <[email protected]>

Add support in DMA helpers to handle callers specifying DRM_MODE_DUMB_KERNEL_MAP flag. Existing behavior is maintained with this change. drm_gem_dma_dumb_create() always creates a kernel mapping as before. drm_gem_dma_dumb_create_internal() lets the caller set the flags as desired.

drm_gem_dma_dumb_create_internal() users have DRM_MODE_DUMB_KERNEL_MAP added to preserve existing behavior.

A dumb buffer allocated from these devices can be shared (exported) to another device. The consuming device may require the kernel mapping to scan out the buffer to its own display. Such devices include DisplayLink and various MIPI DBI based displays. Therefore altering the behavior should be given much consideration.

[[email protected]: Rebase onto renamed GEM DMA helpers]
[[email protected]: show "vaddr=(no mapping)" in drm_gem_dma_print_info()]
[[email protected]: Add DRM_MODE_DUMB_KERNEL_MAP to new drivers]

[[email protected]: Add flags field to drm_gem_dma_create_with_handle()
kerneldoc]

---
Changes since v2:
- Added back DRM_MODE_DUMB_KERNEL_MAP flag to all drivers calling drm_gem_dma_dumb_create_internal()
- Expanded commit message to cover display drivers needing the kernel mapping to do scan out

Changes since v1:
- Rebased onto renamed GEM DMA helpers
- Added check in drm_fb_dma_get_scanout_buffer() and drm_gem_dma_vmap().
- Made drm_gem_dma_print_info() show "vaddr=(no mapping)" for objects allocated without kernel mapping
- Dropped existing DRM_MODE_DUMB_KERNEL_MAP flag addition in various drivers
- Added DRM_MODE_DUMB_KERNEL_MAP flag to adp_drm_gem_dumb_create()
- Added flags field kerneldoc for drm_gem_dma_create_with_handle()

Cc Sasha Finkelstein <[email protected]>
Cc Janne Grunau <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Kieran Bingham <[email protected]>
Cc Biju Das <[email protected]>
Cc Yannick Fertre <[email protected]>
Cc Raphael Gallais-Pou <[email protected]>
Cc Philippe Cornu <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Dave Stevenson <[email protected]>
Cc "Maíra Canal" <[email protected]>
Cc Raspberry Pi Kernel Maintenance <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
---
 drivers/gpu/drm/adp/adp_drv.c                 |  1 +
 .../gpu/drm/arm/display/komeda/komeda_kms.c   |  1 +
 drivers/gpu/drm/arm/malidp_drv.c              |  1 +
 drivers/gpu/drm/drm_fb_dma_helper.c           |  4 ++
 drivers/gpu/drm/drm_gem_dma_helper.c          | 67 ++++++++++++-------
 drivers/gpu/drm/logicvc/logicvc_drm.c         |  1 +
 drivers/gpu/drm/meson/meson_drv.c             |  1 +
 drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c |  2 +
 drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c  |  1 +
 drivers/gpu/drm/stm/drv.c                     |  3 +-
 drivers/gpu/drm/sun4i/sun4i_drv.c             |  1 +
 drivers/gpu/drm/vc4/vc4_drv.c                 |  2 +
 drivers/gpu/drm/verisilicon/vs_drm.c          |  2 +
 drivers/gpu/drm/xlnx/zynqmp_kms.c             |  2 +
 14 files changed, 63 insertions(+), 26 deletions(-)
drivers/gpu/drm/adp/adp_drv.c +1 -0
index 4554cf75565e..c549b44b3814 100644
@@ -95,6 +95,7 @@ static int adp_drm_gem_dumb_create(struct drm_file *file_priv,
 {
        args->height = ALIGN(args->height, 64);
        args->size = args->pitch * args->height;
+       args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 
        return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
 }
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +1 -0
index 6ed504099188..2c096ebaea33 100644
@@ -29,6 +29,7 @@ static int komeda_gem_dma_dumb_create(struct drm_file *file,
        struct komeda_dev *mdev = dev->dev_private;
        u32 pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
 
+       args->flags = DRM_MODE_DUMB_KERNEL_MAP;
        args->pitch = ALIGN(pitch, mdev->chip.bus_width);
 
        return drm_gem_dma_dumb_create_internal(file, dev, args);
drivers/gpu/drm/arm/malidp_drv.c +1 -0
index b765f6c9eea4..5519f48a27c0 100644
@@ -464,6 +464,7 @@ static int malidp_dumb_create(struct drm_file *file_priv,
        /* allocate for the worst case scenario, i.e. rotated buffers */
        u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1);
 
+       args->flags = DRM_MODE_DUMB_KERNEL_MAP;
        args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), alignment);
 
        return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
drivers/gpu/drm/drm_fb_dma_helper.c +4 -0
index fd71969d2fb1..12a44accc48c 100644
@@ -187,6 +187,10 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane,
        if (!dma_obj->vaddr)
                return -ENODEV;
 
+       /* Buffer was allocated with NO_KERNEL_MAPPING */
+       if (dma_obj->dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+               return -ENODEV;
+
        iosys_map_set_vaddr(&sb->map[0], dma_obj->vaddr);
        sb->format = fb->format;
        sb->height = fb->height;
drivers/gpu/drm/drm_gem_dma_helper.c +30 -20
index 9722c9fc86f3..281fb563f061 100644
@@ -116,26 +116,8 @@ __drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
        return ERR_PTR(ret);
 }
 
-/**
- * drm_gem_dma_create - allocate an object with the given size
- * @drm: DRM device
- * @size: size of the object to allocate
- *
- * This function creates a DMA GEM object and allocates memory as backing store.
- * The allocated memory will occupy a contiguous chunk of bus address space.
- *
- * For devices that are directly connected to the memory bus then the allocated
- * memory will be physically contiguous. For devices that access through an
- * IOMMU, then the allocated memory is not expected to be physically contiguous
- * because having contiguous IOVAs is sufficient to meet a devices DMA
- * requirements.
- *
- * Returns:
- * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
- * error code on failure.
- */
-struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
-                                             size_t size)
+static struct drm_gem_dma_object *
+drm_gem_dma_create_flags(struct drm_device *drm, size_t size, u32 flags)
 {
        struct drm_gem_dma_object *dma_obj;
        int ret;
@@ -146,6 +128,9 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
        if (IS_ERR(dma_obj))
                return dma_obj;
 
+       if (!(flags & DRM_MODE_DUMB_KERNEL_MAP))
+               dma_obj->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
+
        if (dma_obj->map_noncoherent) {
                dma_obj->vaddr = dma_alloc_noncoherent(drm_dev_dma_dev(drm),
                                                       size,
@@ -171,6 +156,30 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
        drm_gem_object_put(&dma_obj->base);
        return ERR_PTR(ret);
 }
+
+/**
+ * drm_gem_dma_create - allocate an object with the given size
+ * @drm: DRM device
+ * @size: size of the object to allocate
+ *
+ * This function creates a DMA GEM object and allocates memory as backing store.
+ * The allocated memory will occupy a contiguous chunk of bus address space.
+ *
+ * For devices that are directly connected to the memory bus then the allocated
+ * memory will be physically contiguous. For devices that access through an
+ * IOMMU, then the allocated memory is not expected to be physically contiguous
+ * because having contiguous IOVAs is sufficient to meet a devices DMA
+ * requirements.
+ *
+ * Returns:
+ * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
+ * error code on failure.
+ */
+struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
+                                             size_t size)
+{
+       return drm_gem_dma_create_flags(drm, size, DRM_MODE_DUMB_KERNEL_MAP);
+}
 EXPORT_SYMBOL_GPL(drm_gem_dma_create);
 
 /**
@@ -179,6 +188,7 @@ EXPORT_SYMBOL_GPL(drm_gem_dma_create);
  * @file_priv: DRM file-private structure to register the handle for
  * @drm: DRM device
  * @size: size of the object to allocate
+ * @flags: DRM_MODE_DUMB_* flags if any
  * @handle: return location for the GEM handle
  *
  * This function creates a DMA GEM object, allocating a chunk of memory as
@@ -194,14 +204,14 @@ EXPORT_SYMBOL_GPL(drm_gem_dma_create);
  */
 static struct drm_gem_dma_object *
 drm_gem_dma_create_with_handle(struct drm_file *file_priv,

drivers/gpu/drm/drm_gem_dma_helper.c EXPORT_SYMBOL_GPL(drm_gem_dma_create); · line 214

Quoted 10 lines
drivers/gpu/drm/drm_gem_dma_helper.c +2 -2
-                              struct drm_device *drm, size_t size,
+                              struct drm_device *drm, size_t size, u32 flags,
                               uint32_t *handle)
 {
        struct drm_gem_dma_object *dma_obj;
        struct drm_gem_object *gem_obj;
        int ret;
 
-       dma_obj = drm_gem_dma_create(drm, size);
+       dma_obj = drm_gem_dma_create_flags(drm, size, DRM_MODE_DUMB_KERNEL_MAP);

Sashiko pointed out an obvious (to me now) error here: this should pass flags, not the flag directly.

ChenYu

#11 lore raw

Re: [PATCH v3 3/3] drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag

In reply to Chen-Yu Tsai

Hi

Am 26.03.26 um 11:01 schrieb Chen-Yu Tsai:

Quoted 8 lines

From: Rob Herring <[email protected]>

Add support in DMA helpers to handle callers specifying DRM_MODE_DUMB_KERNEL_MAP flag. Existing behavior is maintained with this change. drm_gem_dma_dumb_create() always creates a kernel mapping as before. drm_gem_dma_dumb_create_internal() lets the caller set the flags as desired.

Quoted 8 lines

drm_gem_dma_dumb_create_internal() users have DRM_MODE_DUMB_KERNEL_MAP added to preserve existing behavior.

A dumb buffer allocated from these devices can be shared (exported) to another device. The consuming device may require the kernel mapping to scan out the buffer to its own display. Such devices include DisplayLink and various MIPI DBI based displays. Therefore altering the behavior should be given much consideration.

NAK on this whole thing. Please do not clutter the sources with these flags and tests. If drivers cannot use the gem-cma helpers, they should not do so. Maybe these drivers _are_ different. Then give them different interfaces or even a different memory manager, if necessary.

Quoted 103 lines
[[email protected]: Rebase onto renamed GEM DMA helpers]
[[email protected]: show "vaddr=(no mapping)" in drm_gem_dma_print_info()]
[[email protected]: Add DRM_MODE_DUMB_KERNEL_MAP to new drivers]

[[email protected]: Add flags field to drm_gem_dma_create_with_handle()
kerneldoc]

---
Changes since v2:
- Added back DRM_MODE_DUMB_KERNEL_MAP flag to all drivers calling drm_gem_dma_dumb_create_internal()
- Expanded commit message to cover display drivers needing the kernel mapping to do scan out

Changes since v1:
- Rebased onto renamed GEM DMA helpers
- Added check in drm_fb_dma_get_scanout_buffer() and drm_gem_dma_vmap().
- Made drm_gem_dma_print_info() show "vaddr=(no mapping)" for objects allocated without kernel mapping
- Dropped existing DRM_MODE_DUMB_KERNEL_MAP flag addition in various drivers
- Added DRM_MODE_DUMB_KERNEL_MAP flag to adp_drm_gem_dumb_create()
- Added flags field kerneldoc for drm_gem_dma_create_with_handle()

Cc Sasha Finkelstein <[email protected]>
Cc Janne Grunau <[email protected]>
Cc Liviu Dudau <[email protected]>
Cc Paul Kocialkowski <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
Cc Kieran Bingham <[email protected]>
Cc Biju Das <[email protected]>
Cc Yannick Fertre <[email protected]>
Cc Raphael Gallais-Pou <[email protected]>
Cc Philippe Cornu <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc Dave Stevenson <[email protected]>
Cc "Maíra Canal" <[email protected]>
Cc Raspberry Pi Kernel Maintenance <[email protected]>
Cc Icenowy Zheng <[email protected]>
Cc Laurent Pinchart <[email protected]>
Cc Tomi Valkeinen <[email protected]>
---
  drivers/gpu/drm/adp/adp_drv.c                 |  1 +
  .../gpu/drm/arm/display/komeda/komeda_kms.c   |  1 +
  drivers/gpu/drm/arm/malidp_drv.c              |  1 +
  drivers/gpu/drm/drm_fb_dma_helper.c           |  4 ++
  drivers/gpu/drm/drm_gem_dma_helper.c          | 67 ++++++++++++-------
  drivers/gpu/drm/logicvc/logicvc_drm.c         |  1 +
  drivers/gpu/drm/meson/meson_drv.c             |  1 +
  drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c |  2 +
  drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c  |  1 +
  drivers/gpu/drm/stm/drv.c                     |  3 +-
  drivers/gpu/drm/sun4i/sun4i_drv.c             |  1 +
  drivers/gpu/drm/vc4/vc4_drv.c                 |  2 +
  drivers/gpu/drm/verisilicon/vs_drm.c          |  2 +
  drivers/gpu/drm/xlnx/zynqmp_kms.c             |  2 +
  14 files changed, 63 insertions(+), 26 deletions(-)
drivers/gpu/drm/adp/adp_drv.c +1 -0
index 4554cf75565e..c549b44b3814 100644
@@ -95,6 +95,7 @@ static int adp_drm_gem_dumb_create(struct drm_file *file_priv,
  {
  	args->height = ALIGN(args->height, 64);
  	args->size = args->pitch * args->height;
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
 
  	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
  }
drivers/gpu/drm/arm/display/komeda/komeda_kms.c +1 -0
index 6ed504099188..2c096ebaea33 100644
@@ -29,6 +29,7 @@ static int komeda_gem_dma_dumb_create(struct drm_file *file,
  	struct komeda_dev *mdev = dev->dev_private;
  	u32 pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	args->pitch = ALIGN(pitch, mdev->chip.bus_width);
 
  	return drm_gem_dma_dumb_create_internal(file, dev, args);
drivers/gpu/drm/arm/malidp_drv.c +1 -0
index b765f6c9eea4..5519f48a27c0 100644
@@ -464,6 +464,7 @@ static int malidp_dumb_create(struct drm_file *file_priv,
  	/* allocate for the worst case scenario, i.e. rotated buffers */
  	u8 alignment = malidp_hw_get_pitch_align(malidp->dev, 1);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), alignment);
 
  	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
drivers/gpu/drm/drm_fb_dma_helper.c +0 -0
index fd71969d2fb1..12a44accc48c 100644

drivers/gpu/drm/drm_fb_dma_helper.c int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane, · line 192

Quoted 6 lines
drivers/gpu/drm/drm_fb_dma_helper.c +3 -0
@@ -187,6 +187,10 @@ int drm_fb_dma_get_scanout_buffer(struct drm_plane *plane,
  	if (!dma_obj->vaddr)
  		return -ENODEV;
 
+	/* Buffer was allocated with NO_KERNEL_MAPPING */
+	if (dma_obj->dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+		return -ENODEV;

This is a good example of what I'm talking about. A driver that cannot provide a scanout buffer should not set the callback in the first place.

Best regards
Thomas

Quoted 264 lines
drivers/gpu/drm/drm_fb_dma_helper.c +1 -0
+
  	iosys_map_set_vaddr(&sb->map[0], dma_obj->vaddr);
  	sb->format = fb->format;
  	sb->height = fb->height;
drivers/gpu/drm/drm_gem_dma_helper.c +42 -25
index 9722c9fc86f3..281fb563f061 100644
@@ -116,26 +116,8 @@ __drm_gem_dma_create(struct drm_device *drm, size_t size, bool private)
  	return ERR_PTR(ret);
  }
 
-/**
- * drm_gem_dma_create - allocate an object with the given size
- * @drm: DRM device
- * @size: size of the object to allocate
- *
- * This function creates a DMA GEM object and allocates memory as backing store.
- * The allocated memory will occupy a contiguous chunk of bus address space.
- *
- * For devices that are directly connected to the memory bus then the allocated
- * memory will be physically contiguous. For devices that access through an
- * IOMMU, then the allocated memory is not expected to be physically contiguous
- * because having contiguous IOVAs is sufficient to meet a devices DMA
- * requirements.
- *
- * Returns:
- * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
- * error code on failure.
- */
-struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
-					      size_t size)
+static struct drm_gem_dma_object *
+drm_gem_dma_create_flags(struct drm_device *drm, size_t size, u32 flags)
  {
  	struct drm_gem_dma_object *dma_obj;
  	int ret;
@@ -146,6 +128,9 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
  	if (IS_ERR(dma_obj))
  		return dma_obj;
 
+	if (!(flags & DRM_MODE_DUMB_KERNEL_MAP))
+		dma_obj->dma_attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
+
  	if (dma_obj->map_noncoherent) {
  		dma_obj->vaddr = dma_alloc_noncoherent(drm_dev_dma_dev(drm),
  						       size,
@@ -171,6 +156,30 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
  	drm_gem_object_put(&dma_obj->base);
  	return ERR_PTR(ret);
  }
+
+/**
+ * drm_gem_dma_create - allocate an object with the given size
+ * @drm: DRM device
+ * @size: size of the object to allocate
+ *
+ * This function creates a DMA GEM object and allocates memory as backing store.
+ * The allocated memory will occupy a contiguous chunk of bus address space.
+ *
+ * For devices that are directly connected to the memory bus then the allocated
+ * memory will be physically contiguous. For devices that access through an
+ * IOMMU, then the allocated memory is not expected to be physically contiguous
+ * because having contiguous IOVAs is sufficient to meet a devices DMA
+ * requirements.
+ *
+ * Returns:
+ * A struct drm_gem_dma_object * on success or an ERR_PTR()-encoded negative
+ * error code on failure.
+ */
+struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
+					      size_t size)
+{
+	return drm_gem_dma_create_flags(drm, size, DRM_MODE_DUMB_KERNEL_MAP);
+}
  EXPORT_SYMBOL_GPL(drm_gem_dma_create);
 
  /**
@@ -179,6 +188,7 @@ EXPORT_SYMBOL_GPL(drm_gem_dma_create);
   * @file_priv: DRM file-private structure to register the handle for
   * @drm: DRM device
   * @size: size of the object to allocate
+ * @flags: DRM_MODE_DUMB_* flags if any
   * @handle: return location for the GEM handle
   *
   * This function creates a DMA GEM object, allocating a chunk of memory as
@@ -194,14 +204,14 @@ EXPORT_SYMBOL_GPL(drm_gem_dma_create);
   */
  static struct drm_gem_dma_object *
  drm_gem_dma_create_with_handle(struct drm_file *file_priv,
-			       struct drm_device *drm, size_t size,
+			       struct drm_device *drm, size_t size, u32 flags,
  			       uint32_t *handle)
  {
  	struct drm_gem_dma_object *dma_obj;
  	struct drm_gem_object *gem_obj;
  	int ret;
 
-	dma_obj = drm_gem_dma_create(drm, size);
+	dma_obj = drm_gem_dma_create_flags(drm, size, DRM_MODE_DUMB_KERNEL_MAP);
  	if (IS_ERR(dma_obj))
  		return dma_obj;
 
@@ -283,7 +293,7 @@ int drm_gem_dma_dumb_create_internal(struct drm_file *file_priv,
  		args->size = args->pitch * args->height;
 
  	dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size,
-						 &args->handle);
+						 args->flags, &args->handle);
  	return PTR_ERR_OR_ZERO(dma_obj);
  }
  EXPORT_SYMBOL_GPL(drm_gem_dma_dumb_create_internal);
@@ -313,12 +323,13 @@ int drm_gem_dma_dumb_create(struct drm_file *file_priv,
  	struct drm_gem_dma_object *dma_obj;
  	int ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	ret = drm_mode_size_dumb(drm, args, 0, 0);
  	if (ret)
  		return ret;
 
  	dma_obj = drm_gem_dma_create_with_handle(file_priv, drm, args->size,
-						 &args->handle);
+						 args->flags, &args->handle);
  	return PTR_ERR_OR_ZERO(dma_obj);
  }
  EXPORT_SYMBOL_GPL(drm_gem_dma_dumb_create);
@@ -412,7 +423,10 @@ void drm_gem_dma_print_info(const struct drm_gem_dma_object *dma_obj,
  			    struct drm_printer *p, unsigned int indent)
  {
  	drm_printf_indent(p, indent, "dma_addr=%pad\n", &dma_obj->dma_addr);
-	drm_printf_indent(p, indent, "vaddr=%p\n", dma_obj->vaddr);
+	if (dma_obj->dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+		drm_printf_indent(p, indent, "vaddr=(no mapping)\n");
+	else
+		drm_printf_indent(p, indent, "vaddr=%p\n", dma_obj->vaddr);
  }
  EXPORT_SYMBOL(drm_gem_dma_print_info);
 
@@ -511,6 +525,9 @@ EXPORT_SYMBOL_GPL(drm_gem_dma_prime_import_sg_table);
  int drm_gem_dma_vmap(struct drm_gem_dma_object *dma_obj,
  		     struct iosys_map *map)
  {
+	if (dma_obj->dma_attrs & DMA_ATTR_NO_KERNEL_MAPPING)
+		return -ENOMEM;
+
  	iosys_map_set_vaddr(map, dma_obj->vaddr);
 
  	return 0;
drivers/gpu/drm/logicvc/logicvc_drm.c +1 -0
index bbebf4fc7f51..595a71163cb5 100644
@@ -39,6 +39,7 @@ static int logicvc_drm_gem_dma_dumb_create(struct drm_file *file_priv,
  {
  	struct logicvc_drm *logicvc = logicvc_drm(drm_dev);
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	/* Stride is always fixed to its configuration value. */
  	args->pitch = logicvc->config.row_stride * DIV_ROUND_UP(args->bpp, 8);
 
drivers/gpu/drm/meson/meson_drv.c +1 -0
index 49ff9f1f16d3..9fa339d6e273 100644
@@ -83,6 +83,7 @@ static irqreturn_t meson_irq(int irq, void *arg)
  static int meson_dumb_create(struct drm_file *file, struct drm_device *dev,
  			     struct drm_mode_create_dumb *args)
  {
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	/*
  	 * We need 64bytes aligned stride, and PAGE aligned size
  	 */
drivers/gpu/drm/renesas/rcar-du/rcar_du_kms.c +2 -0
index 60e6f43b8ab2..611fe3d4a4d8 100644
@@ -424,6 +424,8 @@ int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev,
  	if (ret)
  		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
  	return drm_gem_dma_dumb_create_internal(file, dev, args);
  }
 
drivers/gpu/drm/renesas/rz-du/rzg2l_du_kms.c +1 -0
index 87f171145a23..359f85bd84eb 100644
@@ -184,6 +184,7 @@ int rzg2l_du_dumb_create(struct drm_file *file, struct drm_device *dev,
  	unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
  	unsigned int align = 16 * args->bpp / 8;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	args->pitch = roundup(min_pitch, align);
 
  	return drm_gem_dma_dumb_create_internal(file, dev, args);
drivers/gpu/drm/stm/drv.c +2 -1
index 56d53ac3082d..a0bc2e215adb 100644
@@ -51,8 +51,9 @@ static int stm_gem_dma_dumb_create(struct drm_file *file,
  	 * in order to optimize data transfer, pitch is aligned on
  	 * 128 bytes, height is aligned on 4 bytes
  	 */
-	args->pitch = roundup(min_pitch, 128);
  	args->height = roundup(args->height, 4);
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+	args->pitch = roundup(min_pitch, 128);
 
  	return drm_gem_dma_dumb_create_internal(file, dev, args);
  }
drivers/gpu/drm/sun4i/sun4i_drv.c +1 -0
index 8a409eee1dca..d3ff53ce2450 100644
@@ -36,6 +36,7 @@ static int drm_sun4i_gem_dumb_create(struct drm_file *file_priv,
  				     struct drm_device *drm,
  				     struct drm_mode_create_dumb *args)
  {
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
  	/* The hardware only allows even pitches for YUV buffers. */
  	args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), 2);
 
drivers/gpu/drm/vc4/vc4_drv.c +2 -0
index a14ecb769461..7a04cf52f511 100644
@@ -87,6 +87,8 @@ static int vc5_dumb_create(struct drm_file *file_priv,
  	if (ret)
  		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
  	return drm_gem_dma_dumb_create_internal(file_priv, dev, args);
  }
 
drivers/gpu/drm/verisilicon/vs_drm.c +2 -0
index fd259d53f49f..fe3591244d02 100644
@@ -44,6 +44,8 @@ static int vs_gem_dumb_create(struct drm_file *file_priv,
  	if (ret)
  		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
  	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
  }
 
drivers/gpu/drm/xlnx/zynqmp_kms.c +2 -0
index 02f3a7d78cf8..aa3822b3cb08 100644
@@ -371,6 +371,8 @@ static int zynqmp_dpsub_dumb_create(struct drm_file *file_priv,
  	if (ret)
  		return ret;
 
+	args->flags = DRM_MODE_DUMB_KERNEL_MAP;
+
  	return drm_gem_dma_dumb_create_internal(file_priv, drm, args);
  }
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
#12 lore raw

Re: [PATCH v3 3/3] drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag

In reply to Chen-Yu Tsai
kernel test robot noticed the following build errors:

Hi Chen-Yu,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260327]
[cannot apply to sunxi/sunxi/for-next linus/master v7.0-rc5] [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#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Chen-Yu-Tsai/drm-Introduce-DRM_MODE_DUMB_KERNEL_MAP-flag/20260328-141115
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260326100248.1171828-4-wenst%40chromium.org
patch subject: [PATCH v3 3/3] drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag
config: arm-randconfig-001-20260328 (https://download.01.org/0day-ci/archive/20260328/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260328/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpu/drm/stm/drv.c: In function 'stm_gem_dma_dumb_create':

>> drivers/gpu/drm/stm/drv.c:55:23: error: 'DRM_MODE_DUMB_KERNEL_MAP' undeclared (first use in this function)
      55 |         args->flags = DRM_MODE_DUMB_KERNEL_MAP;
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/stm/drv.c:55:23: note: each undeclared identifier is reported only once for each function it appears in
--
   drivers/gpu/drm/arm/malidp_drv.c: In function 'malidp_dumb_create':
>> drivers/gpu/drm/arm/malidp_drv.c:467:23: error: 'DRM_MODE_DUMB_KERNEL_MAP' undeclared (first use in this function)
     467 |         args->flags = DRM_MODE_DUMB_KERNEL_MAP;
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/gpu/drm/arm/malidp_drv.c:467:23: note: each undeclared identifier is reported only once for each function it appears in
--
   drivers/gpu/drm/arm/display/komeda/komeda_kms.c: In function 'komeda_gem_dma_dumb_create':
>> drivers/gpu/drm/arm/display/komeda/komeda_kms.c:32:23: error: 'DRM_MODE_DUMB_KERNEL_MAP' undeclared (first use in this function)
      32 |         args->flags = DRM_MODE_DUMB_KERNEL_MAP;
         |                       ^~~~~~~~~~~~~~~~~~~~~~~~

drivers/gpu/drm/arm/display/komeda/komeda_kms.c:32:23: note: each undeclared identifier is reported only once for each function it appears in

vim +/DRM_MODE_DUMB_KERNEL_MAP +55 drivers/gpu/drm/stm/drv.c

    43	
    44	static int stm_gem_dma_dumb_create(struct drm_file *file,
    45					   struct drm_device *dev,
    46					   struct drm_mode_create_dumb *args)
    47	{
    48		unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
    49	
    50		/*
    51		 * in order to optimize data transfer, pitch is aligned on
    52		 * 128 bytes, height is aligned on 4 bytes
    53		 */
    54		args->height = roundup(args->height, 4);
  > 55		args->flags = DRM_MODE_DUMB_KERNEL_MAP;
    56		args->pitch = roundup(min_pitch, 128);
    57	
    58		return drm_gem_dma_dumb_create_internal(file, dev, args);
    59	}
    60	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki