Skip to content

Commit 6091731

Browse files
committed
verbs: Introduce ibv_dm_export_dmabuf_fd() verb
This API exports a dmabuf fd that is associated with a given ibv_dm. Upon success the returned fd can be used for DMA and RDMA operations associated with it. Once the usage has been ended, close() should be called while supplying the fd. This call will release the resources that were earlier allocated using the ibv_dm_export_dmabuf_fd() API. A detailed man page was added as well. Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
1 parent c789919 commit 6091731

8 files changed

Lines changed: 69 additions & 0 deletions

File tree

debian/libibverbs1.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
5858
ibv_destroy_srq@IBVERBS_1.1 1.1.6
5959
ibv_detach_mcast@IBVERBS_1.0 1.1.6
6060
ibv_detach_mcast@IBVERBS_1.1 1.1.6
61+
ibv_dm_export_dmabuf_fd@IBVERBS_1.16 62
6162
ibv_dofork_range@IBVERBS_1.1 1.1.6
6263
ibv_dontfork_range@IBVERBS_1.1 1.1.6
6364
ibv_event_type_str@IBVERBS_1.1 1.1.6

libibverbs/driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ struct verbs_context_ops {
407407
int (*destroy_wq)(struct ibv_wq *wq);
408408
int (*detach_mcast)(struct ibv_qp *qp, const union ibv_gid *gid,
409409
uint16_t lid);
410+
int (*dm_export_dmabuf_fd)(struct ibv_dm *dm);
410411
void (*free_context)(struct ibv_context *context);
411412
int (*free_dm)(struct ibv_dm *dm);
412413
int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);

libibverbs/dummy_ops.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,12 @@ static int detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
285285
return EOPNOTSUPP;
286286
}
287287

288+
static int dm_export_dmabuf_fd(struct ibv_dm *dm)
289+
{
290+
errno = EOPNOTSUPP;
291+
return -1;
292+
}
293+
288294
static void free_context(struct ibv_context *ctx)
289295
{
290296
return;
@@ -569,6 +575,7 @@ const struct verbs_context_ops verbs_dummy_ops = {
569575
destroy_srq,
570576
destroy_wq,
571577
detach_mcast,
578+
dm_export_dmabuf_fd,
572579
free_context,
573580
free_dm,
574581
get_srq_num,
@@ -698,6 +705,7 @@ void verbs_set_ops(struct verbs_context *vctx,
698705
SET_PRIV_OP(ctx, destroy_srq);
699706
SET_OP(vctx, destroy_wq);
700707
SET_PRIV_OP(ctx, detach_mcast);
708+
SET_OP(vctx, dm_export_dmabuf_fd);
701709
SET_PRIV_OP_IC(ctx, free_context);
702710
SET_OP(vctx, free_dm);
703711
SET_OP(vctx, get_srq_num);

libibverbs/libibverbs.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ IBVERBS_1.15 {
173173

174174
IBVERBS_1.16 {
175175
global:
176+
ibv_dm_export_dmabuf_fd;
176177
ibv_query_port_speed;
177178
} IBVERBS_1.15;
178179

libibverbs/man/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ rdma_man_pages(
2828
ibv_create_wq.3
2929
ibv_devices.1
3030
ibv_devinfo.1
31+
ibv_dm_export_dmabuf_fd.3.md
3132
ibv_event_type_str.3.md
3233
ibv_fork_init.3.md
3334
ibv_get_async_event.3
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
date: 2025-12-7
3+
footer: libibverbs
4+
header: "Libibverbs Programmer's Manual"
5+
layout: page
6+
license: 'Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md'
7+
section: 3
8+
title: ibv_dm_export_dmabuf_fd
9+
---
10+
11+
# NAME
12+
13+
ibv_dm_export_dmabuf_fd - export dmabuf fd for a given ibv_dm.
14+
15+
# SYNOPSIS
16+
17+
```c
18+
#include <infiniband/verbs.h>
19+
20+
int ibv_dm_export_dmabuf_fd(struct ibv_dm *dm);
21+
```
22+
23+
# DESCRIPTION
24+
25+
**ibv_dm_export_dmabuf_fd()** exports a dmabuf fd that is associated with the given
26+
*dm*.
27+
28+
The returned fd can be later used for DMA and RDMA operations associated with it.
29+
30+
Once the usage has been ended close() should be called while supplying the fd.
31+
32+
This call will release resources that were earlier allocated using the **ibv_dm_export_dmabuf_fd()** API.
33+
34+
# ARGUMENTS
35+
36+
*dm*
37+
: An ibv_dm pointer to export the dmabuf fd for its memory.
38+
39+
# RETURN VALUE
40+
41+
**ibv_dm_export_dmabuf_fd()** returns an fd number >= 0 upon success, or -1 if the request fails and errno set to the error.
42+
43+
# SEE ALSO
44+
45+
**ibv_reg_mr_ex**(3)
46+
47+
# AUTHOR
48+
49+
Yishai Hadas <yishaih@nvidia.com>

libibverbs/verbs.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ int ibv_dealloc_dmah(struct ibv_dmah *dmah)
412412
return get_ops(dmah->context)->dealloc_dmah(dmah);
413413
}
414414

415+
int ibv_dm_export_dmabuf_fd(struct ibv_dm *dm)
416+
{
417+
return get_ops(dm->context)->dm_export_dmabuf_fd(dm);
418+
}
419+
415420
struct ibv_mr *ibv_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset,
416421
size_t length, uint64_t iova, int fd,
417422
int access)

libibverbs/verbs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,7 @@ struct ibv_values_ex {
21832183

21842184
struct verbs_context {
21852185
/* "grows up" - new fields go here */
2186+
int (*dm_export_dmabuf_fd)(struct ibv_dm *dm);
21862187
struct ibv_mr *(*reg_mr_ex)(struct ibv_pd *pd,
21872188
struct ibv_mr_init_attr *mr_init_attr);
21882189
int (*dealloc_dmah)(struct ibv_dmah *dmah);
@@ -2837,6 +2838,8 @@ int ibv_free_dm(struct ibv_dm *dm)
28372838
return vctx->free_dm(dm);
28382839
}
28392840

2841+
int ibv_dm_export_dmabuf_fd(struct ibv_dm *dm);
2842+
28402843
/**
28412844
* ibv_memcpy_to/from_dm - copy to/from device allocated memory
28422845
* @dm - The DM to copy to/from

0 commit comments

Comments
 (0)