On 9/3/2025 1:07 PM, Christian König wrote:
On 02.09.25 16:52, Srinivasan Shanmugam wrote:
Enable userspace to obtain a handle to the kernel-owned MMIO_REMAP
singleton when AMDGPU_GEM_DOMAIN_MMIO_REMAP is requested via
amdgpu_gem_create_ioctl().
Validate the fixed 4K constraint: if PAGE_SIZE > AMDGPU_GPU_PAGE_SIZE
return -EINVAL; when provided, size and alignment must equal
AMDGPU_GPU_PAGE_SIZE.
If the singleton BO is not available, return -ENODEV.
v2:
- Drop READ_ONCE() on adev->mmio_remap.bo (use a plain pointer load).
The pointer is set `bo = adev->mmio_remap.bo;` ie., The pointer is
written once during init and not changed while IOCTLs run. There’s no
concurrent writer in this execution path, so a normal read is safe.
(Alex)
v3:
- Drop early -EINVAL for AMDGPU_GEM_DOMAIN_MMIO_REMAP; let the
MMIO_REMAP fast-path (For MMIO_REMAP, if asked, we don’t allocate a
new BO — we just check size/alignment, grab the one pre-made BO,
return a handle) handle it and return the singleton handle.
v4:
- Return -EOPNOTSUPP if the singleton isn’t available; drop PAGE_SIZE
check from IOCTL; inline the MMIO_REMAP fast-path and keep
size/alignment validation there. (Christian)
v5:
- Reword comments (no “===”), explain why the singleton is returned.
- Pass &args->in to amdgpu_gem_get_mmio_remap_handle() (drop local
‘size’) (Christian)
Cc: Christian König<christian.koe...@amd.com>
Suggested-by: Alex Deucher<alexander.deuc...@amd.com>
Signed-off-by: Srinivasan Shanmugam<srinivasan.shanmu...@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 58 ++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index d3c369742124..7676eafbedbf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -424,6 +424,47 @@ const struct drm_gem_object_funcs amdgpu_gem_object_funcs
= {
.vm_ops = &amdgpu_gem_vm_ops,
};
+/**
+ * amdgpu_gem_get_mmio_remap_handle - Create a GEM handle for the MMIO_REMAP BO
+ * @file_priv: DRM file of the caller
+ * @adev: amdgpu device
+ * @in: GEM create input parameters from userspace (size/alignment fields may
be unset (0))
+ * @handle: returned GEM handle for userspace (output)
+ *
+ * Creates a GEM handle to the kernel-owned singleton MMIO_REMAP buffer object
+ * (adev->rmmio_remap.bo). The BO is expected to be allocated during TTM init
+ * when the hardware exposes a remap base and PAGE_SIZE <= 4K.
+ *
+ * Although @in can specify size or alignment, this BO is fixed and unique;
+ * those fields are only validated, not used for allocation.
+ *
+ * drm_gem_handle_create() acquires the handle reference, which will be dropped
+ * by GEM_CLOSE in userspace.
+ *
+ * Returns 0 on success,
+ * -EOPNOTSUPP if the singleton BO is not available on this system,
+ * or a negative errno from drm_gem_handle_create() / validation.
+ */
+static int amdgpu_gem_get_mmio_remap_handle(struct drm_file *file_priv,
+ struct amdgpu_device *adev,
+ const struct
drm_amdgpu_gem_create_in *in,
+ u32 *handle)
+{
+ struct amdgpu_bo *bo = adev->rmmio_remap.bo;
+
+ if (!bo)
+ return -EOPNOTSUPP;
+
+ /* MMIO_REMAP is a fixed 4K page; enforce only if userspace specified
them. */
+ if (in->bo_size != AMDGPU_GPU_PAGE_SIZE)
+ return -EINVAL;
+ if (in->alignment != AMDGPU_GPU_PAGE_SIZE)
+ return -EINVAL;
You misunderstood me on teams :(
Only the size must be exactly AMDGPU_GPU_PAGE_SIZE. The alignment can also be
smaller than that, just not larger.
In other words the check here is probably best written as "if (in->alignment <=
AMDGPU_GPU_PAGE_SIZE)".
Hi Christian,
Thanks a lot for all your quick reviews and feedback's onto this series.
Just to double check "if (in->alignment <= AMDGPU_GPU_PAGE_SIZE)".
"<="is rejecting for buffer alignment "#define BUFFER_ALIGN (4*1024)" in
IGT, so is that is that this check should be lesser than 4K
if (in->alignment < AMDGPU_GPU_PAGE_SIZE)atleast for this MMIO_REMAP BO case?
Best regards,
Srini