dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset
@ 2026-11-05 13:15 saad
  2026-11-05 13:35 ` sashiko-bot
  0 siblings, 1 reply; 3+ messages in thread
From: saad @ 2026-11-05 13:15 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David Airlie, Simona Vetter
  Cc: amd-gfx, dri-devel, linux-kernel, saad

As part of the DRM TODO item "Remove custom dumb_map_offset
implementations", switch amdgpu's &drm_driver.dumb_map_offset callback
from the driver-specific amdgpu_mode_dumb_mmap() to the generic TTM
helper drm_gem_ttm_dumb_map_offset(), for both amdgpu_kms_driver and
amdgpu_partition_driver.

amdgpu_mode_dumb_mmap() additionally rejected userptr BOs and BOs
created with AMDGPU_GEM_CREATE_NO_CPU_ACCESS with -EPERM. Dropping
those checks from the dumb path does not allow such BOs to be mapped:
returning an offset does not create a mapping, and the actual mmap()
goes through drm_gem_mmap() -> amdgpu_gem_object_mmap(), which performs
the same two checks and still returns -EPERM. The only user-visible
difference is that DRM_IOCTL_MODE_MAP_DUMB on such a handle now succeeds
and the subsequent mmap() fails, instead of the ioctl failing. Dumb
buffers created by amdgpu_mode_dumb_create() are never userptr BOs and
always have AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED set, so they are not
affected.

amdgpu_mode_dumb_mmap() is kept, because it still backs the
driver-specific DRM_IOCTL_AMDGPU_GEM_MMAP via amdgpu_gem_mmap_ioctl(),
which is used by libdrm_amdgpu and Mesa. That path is unchanged.

Build-tested with CONFIG_DRM_AMDGPU=m (W=1 for amdgpu_drv.o and
amdgpu_gem.o), no new warnings. Not runtime tested.

The code change was written by hand and reviewed with the help of
Claude (AI coding assistant); the commit message was written by Claude.

Signed-off-by: saad <primecoder8@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 731fe8f9e..134d2fe4b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -27,6 +27,7 @@
 #include <drm/drm_drv.h>
 #include <drm/drm_fbdev_ttm.h>
 #include <drm/drm_gem.h>
+#include <drm/drm_gem_ttm_helper.h>
 #include <drm/drm_managed.h>
 #include <drm/drm_pciids.h>
 #include <drm/drm_probe_helper.h>
@@ -3151,7 +3152,7 @@ static const struct drm_driver amdgpu_kms_driver = {
 	.ioctls = amdgpu_ioctls_kms,
 	.num_ioctls = ARRAY_SIZE(amdgpu_ioctls_kms),
 	.dumb_create = amdgpu_mode_dumb_create,
-	.dumb_map_offset = amdgpu_mode_dumb_mmap,
+	.dumb_map_offset = drm_gem_ttm_dumb_map_offset,
 	DRM_FBDEV_TTM_DRIVER_OPS,
 	.fops = &amdgpu_driver_kms_fops,
 	.release = &amdgpu_driver_release_kms,
@@ -3177,7 +3178,7 @@ const struct drm_driver amdgpu_partition_driver = {
 	.ioctls = amdgpu_ioctls_kms,
 	.num_ioctls = ARRAY_SIZE(amdgpu_ioctls_kms),
 	.dumb_create = amdgpu_mode_dumb_create,
-	.dumb_map_offset = amdgpu_mode_dumb_mmap,
+	.dumb_map_offset = drm_gem_ttm_dumb_map_offset,
 	DRM_FBDEV_TTM_DRIVER_OPS,
 	.fops = &amdgpu_driver_kms_fops,
 	.release = &amdgpu_driver_release_kms,

---
base-commit: 279235273fc6c0a33df863b4a1cc52ec1e73aba5
change-id: 20261105-amdgpu-dumb-map-offset-6fa41e8d3fb5

Best regards,
-- 
saad <primecoder8@gmail.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset
  2026-11-05 13:15 [PATCH] drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset saad
@ 2026-11-05 13:35 ` sashiko-bot
  2026-11-06  7:35   ` primecoder 99
  0 siblings, 1 reply; 3+ messages in thread
From: sashiko-bot @ 2026-11-05 13:35 UTC (permalink / raw)
  To: saad; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] drm/amdgpu: amdgpu_mode_dumb_mmap() left non-static after callback removal
--

commit 20dcb7dcf18d16b07933bf4a8650d805f6e17934
Author: saad <primecoder8@gmail.com>

drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset

This commit switches amdgpu_kms_driver and amdgpu_partition_driver from the
custom amdgpu_mode_dumb_mmap() callback to the generic TTM helper
drm_gem_ttm_dumb_map_offset() for .dumb_map_offset.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> index 731fe8f9e9228..134d2fe4beae8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
[ ... ]
> @@ -3177,7 +3178,7 @@ const struct drm_driver amdgpu_partition_driver = {
>  	.ioctls = amdgpu_ioctls_kms,
>  	.num_ioctls = ARRAY_SIZE(amdgpu_ioctls_kms),
>  	.dumb_create = amdgpu_mode_dumb_create,
> -	.dumb_map_offset = amdgpu_mode_dumb_mmap,
> +	.dumb_map_offset = drm_gem_ttm_dumb_map_offset,

[Severity: Low]
This isn't a bug, but now that neither amdgpu_kms_driver nor
amdgpu_partition_driver in drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c uses
amdgpu_mode_dumb_mmap(), it has no callers outside
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:
int amdgpu_mode_dumb_mmap(struct drm_file *filp,
			  struct drm_device *dev,
			  uint32_t handle, uint64_t *offset_p)
{
...
}

int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
			  struct drm_file *filp)
{
	union drm_amdgpu_gem_mmap *args = data;
	uint32_t handle = args->in.handle;

	memset(args, 0, sizeof(*args));
	return amdgpu_mode_dumb_mmap(filp, dev, handle, &args->out.addr_ptr);
}

Since amdgpu_gem_mmap_ioctl() is now the sole caller of
amdgpu_mode_dumb_mmap(), and the unused dev parameter and mode_dumb name only
existed for the .dumb_map_offset callback signature, should
amdgpu_mode_dumb_mmap() be folded directly into amdgpu_gem_mmap_ioctl() (or at
least made static) and its prototype removed from
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261105-amdgpu-dumb-map-offset-v1-1-7299d94ede11@gmail.com?part=1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset
  2026-11-05 13:35 ` sashiko-bot
@ 2026-11-06  7:35   ` primecoder 99
  0 siblings, 0 replies; 3+ messages in thread
From: primecoder 99 @ 2026-11-06  7:35 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: dri-devel

> should amdgpu_mode_dumb_mmap() be folded directly into
> amdgpu_gem_mmap_ioctl() (or at least made static) and its prototype
> removed from drivers/gpu/drm/amd/amdgpu/amdgpu_gem.h?

Thanks, done in v2:
https://lore.kernel.org/r/20261106-amdgpu-dumb-map-offset-v2-1-0abfb77a84b8@gmail.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-06  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-05 13:15 [PATCH] drm/amdgpu: use drm_gem_ttm_dumb_map_offset() for dumb_map_offset saad
2026-11-05 13:35 ` sashiko-bot
2026-11-06  7:35   ` primecoder 99

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox