Skip to content

Commit f824da4

Browse files
committed
verbs: Expose ibv_cmd_export_dmabuf_fd() to be used by drivers
Expose ibv_cmd_export_dmabuf_fd() to be used by drivers to call the kernel for executing the command. Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
1 parent 6091731 commit f824da4

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

libibverbs/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rdma_library(ibverbs "${CMAKE_CURRENT_BINARY_DIR}/libibverbs.map"
2929
cmd_cq.c
3030
cmd_device.c
3131
cmd_dm.c
32+
cmd_dmabuf.c
3233
cmd_dmah.c
3334
cmd_fallback.c
3435
cmd_flow.c

libibverbs/cmd_dmabuf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB
2+
/*
3+
* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved
4+
*/
5+
6+
#include <infiniband/cmd_write.h>
7+
8+
int ibv_cmd_export_dmabuf_fd(struct ibv_context *ctx, off_t pg_off)
9+
{
10+
DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_DMABUF,
11+
UVERBS_METHOD_DMABUF_ALLOC, 2);
12+
struct ib_uverbs_attr *handle;
13+
int ret;
14+
15+
handle = fill_attr_out_fd(cmd, UVERBS_ATTR_ALLOC_DMABUF_HANDLE, 0);
16+
fill_attr_in_uint64(cmd, UVERBS_ATTR_ALLOC_DMABUF_PGOFF, pg_off);
17+
18+
ret = execute_ioctl(ctx, cmd);
19+
if (ret)
20+
/* errno is set to a postive value internally */
21+
return -1;
22+
23+
return read_attr_fd(UVERBS_ATTR_ALLOC_DMABUF_HANDLE, handle);
24+
}

libibverbs/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ int ibv_cmd_alloc_dm(struct ibv_context *ctx,
744744
struct verbs_dm *dm,
745745
struct ibv_command_buffer *link);
746746
int ibv_cmd_free_dm(struct verbs_dm *dm);
747+
int ibv_cmd_export_dmabuf_fd(struct ibv_context *ctx, off_t pg_off);
747748
int ibv_cmd_alloc_dmah(struct ibv_context *ctx, struct verbs_dmah *st,
748749
struct ibv_dmah_init_attr *attr);
749750
int ibv_cmd_free_dmah(struct verbs_dmah *dmah);

libibverbs/libibverbs.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
221221
ibv_cmd_destroy_srq;
222222
ibv_cmd_destroy_wq;
223223
ibv_cmd_detach_mcast;
224+
ibv_cmd_export_dmabuf_fd;
224225
ibv_cmd_free_dm;
225226
ibv_cmd_free_dmah;
226227
ibv_cmd_get_context;

0 commit comments

Comments
 (0)