Skip to content

Commit 8b9cdb7

Browse files
authored
Merge pull request #1678 from yishaih/verbs_misc
verbs: Add support for exporting dma-buf file descriptors
2 parents 4969c01 + b685f21 commit 8b9cdb7

22 files changed

Lines changed: 218 additions & 2 deletions

debian/ibverbs-providers.symbols

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ libmlx5.so.1 ibverbs-providers #MINVER#
3333
MLX5_1.23@MLX5_1.23 40
3434
MLX5_1.24@MLX5_1.24 42
3535
MLX5_1.25@MLX5_1.25 54
36+
MLX5_1.26@MLX5_1.26 62
3637
mlx5dv_init_obj@MLX5_1.0 13
3738
mlx5dv_init_obj@MLX5_1.2 15
3839
mlx5dv_query_device@MLX5_1.0 13
@@ -55,6 +56,7 @@ libmlx5.so.1 ibverbs-providers #MINVER#
5556
mlx5dv_devx_obj_modify@MLX5_1.7 21
5657
mlx5dv_devx_obj_query@MLX5_1.7 21
5758
mlx5dv_devx_query_eqn@MLX5_1.7 21
59+
mlx5dv_devx_uar_export_dmabuf_fd@MLX5_1.26 62
5860
mlx5dv_devx_umem_dereg@MLX5_1.7 21
5961
mlx5dv_devx_umem_reg@MLX5_1.7 21
6062
mlx5dv_open_device@MLX5_1.7 21

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

kernel-headers/rdma/bnxt_re-abi.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum {
5656
BNXT_RE_UCNTX_CMASK_DBR_PACING_ENABLED = 0x08ULL,
5757
BNXT_RE_UCNTX_CMASK_POW2_DISABLED = 0x10ULL,
5858
BNXT_RE_UCNTX_CMASK_MSN_TABLE_ENABLED = 0x40,
59+
BNXT_RE_UCNTX_CMASK_QP_RATE_LIMIT_ENABLED = 0x80ULL,
5960
};
6061

6162
enum bnxt_re_wqe_mode {
@@ -215,4 +216,19 @@ enum bnxt_re_toggle_mem_methods {
215216
BNXT_RE_METHOD_GET_TOGGLE_MEM = (1U << UVERBS_ID_NS_SHIFT),
216217
BNXT_RE_METHOD_RELEASE_TOGGLE_MEM,
217218
};
219+
220+
struct bnxt_re_packet_pacing_caps {
221+
__u32 qp_rate_limit_min;
222+
__u32 qp_rate_limit_max; /* In kbps */
223+
/* Corresponding bit will be set if qp type from
224+
* 'enum ib_qp_type' is supported, e.g.
225+
* supported_qpts |= 1 << IB_QPT_RC
226+
*/
227+
__u32 supported_qpts;
228+
__u32 reserved;
229+
};
230+
231+
struct bnxt_re_query_device_ex_resp {
232+
struct bnxt_re_packet_pacing_caps packet_pacing_caps;
233+
};
218234
#endif /* __BNXT_RE_UVERBS_ABI_H__*/

kernel-headers/rdma/ib_user_ioctl_cmds.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum uverbs_default_objects {
5656
UVERBS_OBJECT_COUNTERS,
5757
UVERBS_OBJECT_ASYNC_EVENT,
5858
UVERBS_OBJECT_DMAH,
59+
UVERBS_OBJECT_DMABUF,
5960
};
6061

6162
enum {
@@ -263,6 +264,15 @@ enum uverbs_methods_dmah {
263264
UVERBS_METHOD_DMAH_FREE,
264265
};
265266

267+
enum uverbs_attrs_alloc_dmabuf_cmd_attr_ids {
268+
UVERBS_ATTR_ALLOC_DMABUF_HANDLE,
269+
UVERBS_ATTR_ALLOC_DMABUF_PGOFF,
270+
};
271+
272+
enum uverbs_methods_dmabuf {
273+
UVERBS_METHOD_DMABUF_ALLOC,
274+
};
275+
266276
enum uverbs_attrs_reg_dm_mr_cmd_attr_ids {
267277
UVERBS_ATTR_REG_DM_MR_HANDLE,
268278
UVERBS_ATTR_REG_DM_MR_OFFSET,

kernel-headers/rdma/mana-abi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define MANA_IB_UVERBS_ABI_VERSION 1
1818

1919
enum mana_ib_create_cq_flags {
20+
/* Reserved for backward compatibility. Legacy
21+
* kernel versions use it to create CQs in RNIC
22+
*/
2023
MANA_IB_CREATE_RNIC_CQ = 1 << 0,
2124
};
2225

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: 2 additions & 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);
@@ -743,6 +744,7 @@ int ibv_cmd_alloc_dm(struct ibv_context *ctx,
743744
struct verbs_dm *dm,
744745
struct ibv_command_buffer *link);
745746
int ibv_cmd_free_dm(struct verbs_dm *dm);
747+
int ibv_cmd_export_dmabuf_fd(struct ibv_context *ctx, off_t pg_off);
746748
int ibv_cmd_alloc_dmah(struct ibv_context *ctx, struct verbs_dmah *st,
747749
struct ibv_dmah_init_attr *attr);
748750
int ibv_cmd_free_dmah(struct verbs_dmah *dmah);

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: 2 additions & 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

@@ -220,6 +221,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ {
220221
ibv_cmd_destroy_srq;
221222
ibv_cmd_destroy_wq;
222223
ibv_cmd_detach_mcast;
224+
ibv_cmd_export_dmabuf_fd;
223225
ibv_cmd_free_dm;
224226
ibv_cmd_free_dmah;
225227
ibv_cmd_get_context;

0 commit comments

Comments
 (0)