From: Alex Deucher <alexander.deucher@amd.com>
To: <amd-gfx@lists.freedesktop.org>,
<dri-devel@lists.freedesktop.org>, <Felix.Kuehling@amd.com>
Cc: Mukul Joshi <mukul.joshi@amd.com>,
Horatio Zhang <hongkun.zhang@amd.com>,
Alex Deucher <alexander.deucher@amd.com>
Subject: [PATCH 2/3] drm/amdgpu: Add ioctl infra for exporting/importing UALink handles
Date: Mon, 24 Aug 2026 13:02:01 -0400 [thread overview]
Message-ID: <20260824170202.1764463-3-alexander.deucher@amd.com> (raw)
In-Reply-To: <20260824170202.1764463-1-alexander.deucher@amd.com>
From: Mukul Joshi <mukul.joshi@amd.com>
Add the ioctl infrastructure to support exporting and importing BOs
to facilitate NPA based memory sharing across GPUs in a rack scale
setup.
Proposed userspace:
https://github.com/ROCm/rocm-systems/blob/35959f8e1260c7cee3e51a740e320be3856ee4ff/projects/rocr-runtime/libhsakmt/src/memory.c#L971
https://github.com/ROCm/rocm-systems/blob/35959f8e1260c7cee3e51a740e320be3856ee4ff/projects/rocr-runtime/libhsakmt/src/memory.c#L1036
v2: Move the ioctl wire-up to the end of the series.
Signed-off-by: Mukul Joshi <mukul.joshi@amd.com>
Signed-off-by: Horatio Zhang <hongkun.zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 44 ++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h | 2 +
include/uapi/drm/amdgpu_drm.h | 30 +++++++++++++++
4 files changed, 78 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 04b21e456fbc0..25430ff39a6c0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -54,6 +54,7 @@
#include "amdgpu_userq.h"
#include "amdgpu_userq_fence.h"
#include "../amdxcp/amdgpu_xcp_drv.h"
+#include "amdgpu_ualink.h"
/*
* KMS wrapper.
@@ -3119,6 +3120,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_PROC_OPTIONS, amdgpu_proc_options_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+ DRM_IOCTL_DEF_DRV(AMDGPU_UALINK_HANDLE, amdgpu_gem_ualink_handle_ioctl, DRM_AUTH|DRM_RENDER_ALLOW)
};
static const struct drm_driver amdgpu_kms_driver = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index 402d8941fb045..63374c6b9ebd5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -3963,6 +3963,50 @@ int amdgpu_ualink_export_handle(struct drm_device *dev, struct drm_file *filp,
return r;
}
+int amdgpu_gem_ualink_handle_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp)
+{
+ union drm_amdgpu_ualink_handle *args = data;
+ struct amdgpu_device *adev = drm_to_adev(dev);
+ struct amdgpu_ualink_handle handle = {};
+ u32 gem_handle;
+ int r, fd = -1;
+
+ if (adev->ualink.info->accel_state !=
+ AMDGPU_UALINK_ACCEL_STATE_ACTIVE) {
+ dev_err(adev->dev,
+ "ualink device is not in active state in vpod\n");
+ return -EOPNOTSUPP;
+ }
+
+ /* The input and output members of the ioctl argument alias each other.
+ * Latch every input field before invoking the handlers, and only write
+ * the output fields afterwards.
+ */
+ switch (args->in.op) {
+ case DRM_AMDGPU_UALINK_HANDLE_OP_EXPORT:
+ gem_handle = args->in.gem_handle;
+ r = amdgpu_ualink_export_handle(dev, filp, gem_handle, &handle);
+ if (!r) {
+ args->out.export_ualink_handle[0] = handle.handle_lo;
+ args->out.export_ualink_handle[1] = handle.handle_hi;
+ }
+ break;
+ case DRM_AMDGPU_UALINK_HANDLE_OP_IMPORT:
+ handle.handle_lo = args->in.import_ualink_handle[0];
+ handle.handle_hi = args->in.import_ualink_handle[1];
+ r = amdgpu_ualink_import_handle(dev, &handle, &fd);
+ if (!r)
+ args->out.import_dmabuf_handle = fd;
+ break;
+ default:
+ r = -EINVAL;
+ break;
+ }
+
+ return r;
+}
+
int amdgpu_ualink_manager_start(struct amdgpu_device *adev)
{
int i, r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
index 63710b484c6a5..9908d3a277172 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
@@ -409,6 +409,8 @@ int amdgpu_ualink_export_handle(struct drm_device *dev, struct drm_file *filp,
int amdgpu_ualink_import_handle(struct drm_device *dev,
const struct amdgpu_ualink_handle *ualink_handle,
int *fd_out);
+int amdgpu_gem_ualink_handle_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp);
void amdgpu_ualink_revoke_exported_memory(struct amdgpu_bo *bo);
int ualink_ip_hw_init(struct amdgpu_ip_block *ip_block);
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index d6d5402a1e789..0e8115673d8d2 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -59,6 +59,7 @@ extern "C" {
#define DRM_AMDGPU_USERQ_WAIT 0x18
#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19
#define DRM_AMDGPU_PROC_OPTIONS 0x1A
+#define DRM_AMDGPU_UALINK_HANDLE 0x1B
#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -81,6 +82,7 @@ extern "C" {
#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)
#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)
#define DRM_IOCTL_AMDGPU_PROC_OPTIONS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_PROC_OPTIONS, struct drm_amdgpu_proc_options)
+#define DRM_IOCTL_AMDGPU_UALINK_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_UALINK_HANDLE, union drm_amdgpu_ualink_handle)
/**
* DOC: memory domains
@@ -1705,6 +1707,34 @@ struct drm_amdgpu_proc_options {
} kfd_sigbus_delay;
};
+#define DRM_AMDGPU_UALINK_HANDLE_OP_EXPORT 0
+#define DRM_AMDGPU_UALINK_HANDLE_OP_IMPORT 1
+
+struct drm_amdgpu_ualink_handle_in {
+ /* Export or import */
+ __u32 op;
+ /* For future use, no flags defined so far */
+ __u32 flags;
+ union {
+ /* GEM handle of the BO to export */
+ __u32 gem_handle;
+ /* UALink handle to import */
+ __u64 import_ualink_handle[2];
+ };
+};
+
+union drm_amdgpu_ualink_handle_out {
+ /* Exported UALink handle */
+ __u64 export_ualink_handle[2];
+ /** DMABuf representing the imported UALink handle */
+ __u32 import_dmabuf_handle;
+};
+
+union drm_amdgpu_ualink_handle {
+ struct drm_amdgpu_ualink_handle_in in;
+ union drm_amdgpu_ualink_handle_out out;
+};
+
#if defined(__cplusplus)
}
#endif
--
2.55.0
next prev parent reply other threads:[~2026-08-24 17:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 17:01 [PATCH V2 0/3] Add UALink infrastructure series 2 Alex Deucher
2026-08-24 17:02 ` [PATCH 1/3] drm/gem: Add callback for when handle count goes to 0 Alex Deucher
2026-08-24 17:02 ` Alex Deucher [this message]
2026-08-24 17:02 ` [PATCH 3/3] Documentation: add initial UALink Documentation Alex Deucher
-- strict thread matches above, loose matches on Subject: below --
2026-08-31 18:33 [PATCH V2 0/3] Add UALink infrastructure series 2 Alex Deucher
2026-08-31 18:33 ` [PATCH 2/3] drm/amdgpu: Add ioctl infra for exporting/importing UALink handles Alex Deucher
2026-08-21 19:52 [PATCH 0/3] Add UALink infrastructure series 2 Alex Deucher
2026-08-21 19:52 ` [PATCH 2/3] drm/amdgpu: Add ioctl infra for exporting/importing UALink handles Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260824170202.1764463-3-alexander.deucher@amd.com \
--to=alexander.deucher@amd.com \
--cc=Felix.Kuehling@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=hongkun.zhang@amd.com \
--cc=mukul.joshi@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.