libhsakmt: Implement dmabuf export for RDMA

Implement hsaKmtExportDMABufHandle, which can be used for a new
upstreamable RDMA solution. It exports a DMABuf handle for an arbitrary
virtual address along with the offset of the address within the
allocation. It also checks that the size of the intended export does
not exceed the allocation.

This uses the new AMDKFD_IOC_EXPORT_DMABUF, which requires KFD ioctl
API version 1.12.

Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Change-Id: Ie5fdb1f73ab3c7fa36c315ce326b1fb89eacc8b6
This commit is contained in:
Felix Kuehling
2021-11-16 23:13:11 -05:00
szülő e40ae8481e
commit 332f59eb2a
6 fájl változott, egészen pontosan 93 új sor hozzáadva és 2 régi sor törölve
+20
Fájl megtekintése
@@ -436,6 +436,26 @@ hsaKmtRegisterGraphicsHandleToNodes(
HSAuint32* NodeArray //IN
);
/**
* Export a dmabuf handle and offset for a given memory address
*
* Validates that @MemoryAddress belongs to a valid allocation and that the
* @MemorySizeInBytes doesn't exceed the end of that allocation. Returns a
* dmabuf fd of the allocation and the offset of MemoryAddress within that
* allocation. The memory will remain allocated even after the allocation is
* freed by hsaKmtFreeMemory for as long as a dmabuf fd remains open or any
* importer of that fd maintains an active reference to the memory.
*/
HSAKMT_STATUS
HSAKMTAPI
hsaKmtExportDMABufHandle(
void *MemoryAddress, //IN
HSAuint64 MemorySizeInBytes, //IN
int *DMABufFd, //OUT
HSAuint64 *Offset //OUT
);
/**
Export a memory buffer for sharing with other processes
+12 -2
Fájl megtekintése
@@ -37,9 +37,10 @@
* - 1.9 - Add available_memory ioctl
* - 1.10 - Add SMI profiler event log
* - 1.11 - Add unified memory for ctx save/restore area
* - 1.12 - Add DMA buf export ioctl
*/
#define KFD_IOCTL_MAJOR_VERSION 1
#define KFD_IOCTL_MINOR_VERSION 11
#define KFD_IOCTL_MINOR_VERSION 12
/*
* Debug revision change log
@@ -847,6 +848,12 @@ struct kfd_ioctl_import_dmabuf_args {
__u32 dmabuf_fd; /* to KFD */
};
struct kfd_ioctl_export_dmabuf_args {
__u64 handle; /* to KFD */
__u32 flags; /* to KFD */
__u32 dmabuf_fd; /* from KFD */
};
/*
* KFD SMI(System Management Interface) events
*/
@@ -1345,8 +1352,11 @@ struct kfd_ioctl_set_xnack_mode_args {
#define AMDKFD_IOC_AVAILABLE_MEMORY \
AMDKFD_IOWR(0x23, struct kfd_ioctl_get_available_memory_args)
#define AMDKFD_IOC_EXPORT_DMABUF \
AMDKFD_IOWR(0x24, struct kfd_ioctl_export_dmabuf_args)
#define AMDKFD_COMMAND_START 0x01
#define AMDKFD_COMMAND_END 0x24
#define AMDKFD_COMMAND_END 0x25
/* non-upstream ioctls */
#define AMDKFD_IOC_IPC_IMPORT_HANDLE \