Skip to content

Commit

Permalink
Merge pull request linux-rdma#968 from yishaih/verbs_dm
Browse files Browse the repository at this point in the history
verbs: Extend the device memory functionality
  • Loading branch information
yishaih authored Apr 19, 2021
2 parents d849f3d + fb558e9 commit 5b1e6d7
Show file tree
Hide file tree
Showing 29 changed files with 655 additions and 30 deletions.
1 change: 1 addition & 0 deletions debian/ibverbs-providers.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ libmlx5.so.1 ibverbs-providers #MINVER#
mlx5dv_reserved_qpn_alloc@MLX5_1.18 34
mlx5dv_reserved_qpn_dealloc@MLX5_1.18 34
mlx5dv_devx_umem_reg_ex@MLX5_1.19 35
mlx5dv_dm_map_op_addr@MLX5_1.19 35
libefa.so.1 ibverbs-providers #MINVER#
* Build-Depends-Package: libibverbs-dev
EFA_1.0@EFA_1.0 24
Expand Down
2 changes: 2 additions & 0 deletions debian/libibverbs1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
ibv_get_pkey_index@IBVERBS_1.5 20
ibv_get_sysfs_path@IBVERBS_1.0 1.1.6
ibv_import_device@IBVERBS_1.10 31
ibv_import_dm@IBVERBS_1.13 35
ibv_import_mr@IBVERBS_1.10 31
ibv_import_pd@IBVERBS_1.10 31
ibv_init_ah_from_wc@IBVERBS_1.1 1.1.6
Expand Down Expand Up @@ -113,6 +114,7 @@ libibverbs.so.1 libibverbs1 #MINVER#
ibv_resize_cq@IBVERBS_1.1 1.1.6
ibv_resolve_eth_l2_from_gid@IBVERBS_1.1 1.2.0
ibv_set_ece@IBVERBS_1.10 31
ibv_unimport_dm@IBVERBS_1.13 35
ibv_unimport_mr@IBVERBS_1.10 31
ibv_unimport_pd@IBVERBS_1.10 31
ibv_wc_status_str@IBVERBS_1.1 1.1.6
Expand Down
19 changes: 19 additions & 0 deletions kernel-headers/rdma/mlx5_user_ioctl_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ enum mlx5_ib_create_flow_action_attrs {
MLX5_IB_ATTR_CREATE_FLOW_ACTION_FLAGS = (1U << UVERBS_ID_NS_SHIFT),
};

enum mlx5_ib_dm_methods {
MLX5_IB_METHOD_DM_MAP_OP_ADDR = (1U << UVERBS_ID_NS_SHIFT),
MLX5_IB_METHOD_DM_QUERY,
};

enum mlx5_ib_dm_map_op_addr_attrs {
MLX5_IB_ATTR_DM_MAP_OP_ADDR_REQ_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
MLX5_IB_ATTR_DM_MAP_OP_ADDR_REQ_OP,
MLX5_IB_ATTR_DM_MAP_OP_ADDR_RESP_START_OFFSET,
MLX5_IB_ATTR_DM_MAP_OP_ADDR_RESP_PAGE_INDEX,
};

enum mlx5_ib_query_dm_attrs {
MLX5_IB_ATTR_QUERY_DM_REQ_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
MLX5_IB_ATTR_QUERY_DM_RESP_START_OFFSET,
MLX5_IB_ATTR_QUERY_DM_RESP_PAGE_INDEX,
MLX5_IB_ATTR_QUERY_DM_RESP_LENGTH,
};

enum mlx5_ib_alloc_dm_attrs {
MLX5_IB_ATTR_ALLOC_DM_RESP_START_OFFSET = (1U << UVERBS_ID_NS_SHIFT),
MLX5_IB_ATTR_ALLOC_DM_RESP_PAGE_INDEX,
Expand Down
2 changes: 2 additions & 0 deletions libibverbs/cmd_dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ int ibv_cmd_alloc_dm(struct ibv_context *ctx,
return errno;

dm->handle = read_attr_obj(UVERBS_ATTR_ALLOC_DM_HANDLE, handle);
dm->dm.handle = dm->handle;
dm->dm.comp_mask = IBV_DM_MASK_HANDLE;
dm->dm.context = ctx;

return 0;
Expand Down
3 changes: 3 additions & 0 deletions libibverbs/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ struct verbs_context_ops {
void (*free_context)(struct ibv_context *context);
int (*free_dm)(struct ibv_dm *dm);
int (*get_srq_num)(struct ibv_srq *srq, uint32_t *srq_num);
struct ibv_dm *(*import_dm)(struct ibv_context *context,
uint32_t dm_handle);
struct ibv_mr *(*import_mr)(struct ibv_pd *pd,
uint32_t mr_handle);
struct ibv_pd *(*import_pd)(struct ibv_context *context,
Expand Down Expand Up @@ -387,6 +389,7 @@ struct verbs_context_ops {
void *addr, size_t length, int access);
int (*resize_cq)(struct ibv_cq *cq, int cqe);
int (*set_ece)(struct ibv_qp *qp, struct ibv_ece *ece);
void (*unimport_dm)(struct ibv_dm *dm);
void (*unimport_mr)(struct ibv_mr *mr);
void (*unimport_pd)(struct ibv_pd *pd);
};
Expand Down
15 changes: 15 additions & 0 deletions libibverbs/dummy_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ static int get_srq_num(struct ibv_srq *srq, uint32_t *srq_num)
return EOPNOTSUPP;
}

static struct ibv_dm *import_dm(struct ibv_context *context,
uint32_t dm_handle)
{
errno = EOPNOTSUPP;
return NULL;
}

static struct ibv_mr *import_mr(struct ibv_pd *pd,
uint32_t mr_handle)
{
Expand Down Expand Up @@ -466,6 +473,10 @@ static int set_ece(struct ibv_qp *qp, struct ibv_ece *ece)
return EOPNOTSUPP;
}

static void unimport_dm(struct ibv_dm *dm)
{
}

static void unimport_mr(struct ibv_mr *mr)
{
}
Expand Down Expand Up @@ -528,6 +539,7 @@ const struct verbs_context_ops verbs_dummy_ops = {
free_context,
free_dm,
get_srq_num,
import_dm,
import_mr,
import_pd,
modify_cq,
Expand Down Expand Up @@ -557,6 +569,7 @@ const struct verbs_context_ops verbs_dummy_ops = {
rereg_mr,
resize_cq,
set_ece,
unimport_dm,
unimport_mr,
unimport_pd,
};
Expand Down Expand Up @@ -650,6 +663,7 @@ void verbs_set_ops(struct verbs_context *vctx,
SET_PRIV_OP_IC(ctx, free_context);
SET_OP(vctx, free_dm);
SET_OP(vctx, get_srq_num);
SET_PRIV_OP_IC(vctx, import_dm);
SET_PRIV_OP_IC(vctx, import_mr);
SET_PRIV_OP_IC(vctx, import_pd);
SET_OP(vctx, modify_cq);
Expand Down Expand Up @@ -679,6 +693,7 @@ void verbs_set_ops(struct verbs_context *vctx,
SET_PRIV_OP(ctx, rereg_mr);
SET_PRIV_OP(ctx, resize_cq);
SET_PRIV_OP_IC(vctx, set_ece);
SET_PRIV_OP_IC(vctx, unimport_dm);
SET_PRIV_OP_IC(vctx, unimport_mr);
SET_PRIV_OP_IC(vctx, unimport_pd);

Expand Down
2 changes: 2 additions & 0 deletions libibverbs/libibverbs.map.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ IBVERBS_1.12 {

IBVERBS_1.13 {
global:
ibv_import_dm;
ibv_is_fork_initialized;
ibv_unimport_dm;
} IBVERBS_1.12;

/* If any symbols in this stanza change ABI then the entire staza gets a new symbol
Expand Down
2 changes: 2 additions & 0 deletions libibverbs/man/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rdma_man_pages(
ibv_get_pkey_index.3.md
ibv_get_srq_num.3.md
ibv_import_device.3.md
ibv_import_dm.3.md
ibv_import_mr.3.md
ibv_import_pd.3.md
ibv_inc_rkey.3.md
Expand Down Expand Up @@ -107,6 +108,7 @@ rdma_alias_man_pages(
ibv_get_cq_event.3 ibv_ack_cq_events.3
ibv_get_device_list.3 ibv_free_device_list.3
ibv_import_pd.3 ibv_unimport_pd.3
ibv_import_dm.3 ibv_unimport_dm.3
ibv_import_mr.3 ibv_unimport_mr.3
ibv_open_device.3 ibv_close_device.3
ibv_open_xrcd.3 ibv_close_xrcd.3
Expand Down
1 change: 1 addition & 0 deletions libibverbs/man/ibv_alloc_dm.3
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ flag.
.SH "RETURN VALUE"
.B ibv_alloc_dm()
returns a pointer to an ibv_dm struct or NULL if the request fails.
The output dm contains the handle which could be used by user to import this device memory.
.PP
.B ibv_free_dm()
returns 0 on success, or the value of errno on failure (which indicates the failure reason).
Expand Down
59 changes: 59 additions & 0 deletions libibverbs/man/ibv_import_dm.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
date: 2021-1-17
footer: libibverbs
header: "Libibverbs Programmer's Manual"
layout: page
license: 'Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md'
section: 3
title: ibv_import_dm ibv_unimport_dm
---

# NAME

ibv_import_dm - import an DM from a given ibv_context

ibv_unimport_dm - unimport an DM

# SYNOPSIS

```c
#include <infiniband/verbs.h>

struct ibv_dm *ibv_import_dm(struct ibv_context *context, uint32_t dm_handle);
void ibv_unimport_dm(struct ibv_dm *dm)

```
# DESCRIPTION
**ibv_import_dm()** returns a Device memory (DM) that is associated with the given
*dm_handle* in the RDMA context.
The input *dm_handle* value must be a valid kernel handle for an DM object in the assosicated RDMA context.
It can be achieved from the original DM by getting its ibv_dm->handle member value.
**ibv_unimport_dm()** un import the DM.
Once the DM usage has been ended ibv_free_dm() or ibv_unimport_dm() should be called.
The first one will go to the kernel to destroy the object once the second one way cleanup what
ever is needed/opposite of the import without calling the kernel.
This is the responsibility of the application to coordinate between all ibv_context(s) that use this DM.
Once destroy is done no other process can touch the object except for unimport. All users of the context must
collaborate to ensure this.
# RETURN VALUE
**ibv_import_dm()** returns a pointer to the allocated DM, or NULL if the request fails and errno is set.
# NOTES
# SEE ALSO
**ibv_alloc_dm**(3),
**ibv_free_dm**(3),
# AUTHOR
Maor Gottlieb <[email protected]>
16 changes: 16 additions & 0 deletions libibverbs/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ void ibv_unimport_mr(struct ibv_mr *mr)
get_ops(mr->context)->unimport_mr(mr);
}

/**
* ibv_import_dm - Import a device memory
*/
struct ibv_dm *ibv_import_dm(struct ibv_context *context, uint32_t dm_handle)
{
return get_ops(context)->import_dm(context, dm_handle);
}

/**
* ibv_unimport_dm - Unimport a device memory
*/
void ibv_unimport_dm(struct ibv_dm *dm)
{
get_ops(dm->context)->unimport_dm(dm);
}

struct ibv_mr *ibv_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset,
size_t length, uint64_t iova, int fd,
int access)
Expand Down
16 changes: 16 additions & 0 deletions libibverbs/verbs.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,19 @@ struct ibv_alloc_dm_attr {
uint32_t comp_mask;
};

enum ibv_dm_mask {
IBV_DM_MASK_HANDLE = 1 << 0,
};

struct ibv_dm {
struct ibv_context *context;
int (*memcpy_to_dm)(struct ibv_dm *dm, uint64_t dm_offset,
const void *host_addr, size_t length);
int (*memcpy_from_dm)(void *host_addr, struct ibv_dm *dm,
uint64_t dm_offset, size_t length);
uint32_t comp_mask;

uint32_t handle;
};

struct ibv_device_attr {
Expand Down Expand Up @@ -2289,6 +2295,16 @@ struct ibv_mr *ibv_import_mr(struct ibv_pd *pd, uint32_t mr_handle);
*/
void ibv_unimport_mr(struct ibv_mr *mr);

/**
* ibv_import_dm - Import a device memory
*/
struct ibv_dm *ibv_import_dm(struct ibv_context *context, uint32_t dm_handle);

/**
* ibv_unimport_dm - Unimport a device memory
*/
void ibv_unimport_dm(struct ibv_dm *dm);

/**
* ibv_get_async_event - Get next async event
* @event: Pointer to use to return async event
Expand Down
1 change: 1 addition & 0 deletions providers/mlx5/libmlx5.map
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,5 @@ MLX5_1.18 {
MLX5_1.19 {
global:
mlx5dv_devx_umem_reg_ex;
mlx5dv_dm_map_op_addr;
} MLX5_1.18;
1 change: 1 addition & 0 deletions providers/mlx5/man/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ rdma_man_pages(
mlx5dv_devx_query_eqn.3.md
mlx5dv_devx_subscribe_devx_event.3.md
mlx5dv_devx_umem_reg.3.md
mlx5dv_dm_map_op_addr.3.md
mlx5dv_dr_flow.3.md
mlx5dv_dump.3.md
mlx5dv_flow_action_esp.3.md
Expand Down
47 changes: 47 additions & 0 deletions providers/mlx5/man/mlx5dv_dm_map_op_addr.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
layout: page
title: mlx5dv_dm_map_op_addr
section: 3
tagline: Verbs
date: 2021-1-21
header: "mlx5 Programmer's Manual"
footer: mlx5
---

# NAME

mlx5dv_dm_map_op_addr - Get operation address of a device memory (DM)

# SYNOPSIS

```c
#include <infiniband/mlx5dv.h>

void *mlx5dv_dm_map_op_addr(struct ibv_dm *dm, uint8_t op);
```
# DESCRIPTION
**mlx5dv_dm_map_op_addr()** returns a mmaped address to the device memory for the
requested **op**.
# ARGUMENTS
*dm*
: The associated ibv_dm for this operation.
*op*
: Indicates the DM operation type, based on device specification.
# RETURN VALUE
Returns a pointer to the mmaped address, on error NULL will be returned and errno will be set.
# SEE ALSO
**ibv_alloc_dm**(3),
**mlx5dv_alloc_dm**(3),
# AUTHOR
Maor Gottlieb <[email protected]>
2 changes: 2 additions & 0 deletions providers/mlx5/mlx5.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = {
.destroy_wq = mlx5_destroy_wq,
.free_dm = mlx5_free_dm,
.get_srq_num = mlx5_get_srq_num,
.import_dm = mlx5_import_dm,
.import_mr = mlx5_import_mr,
.import_pd = mlx5_import_pd,
.modify_cq = mlx5_modify_cq,
Expand All @@ -163,6 +164,7 @@ static const struct verbs_context_ops mlx5_ctx_common_ops = {
.alloc_null_mr = mlx5_alloc_null_mr,
.free_context = mlx5_free_context,
.set_ece = mlx5_set_ece,
.unimport_dm = mlx5_unimport_dm,
.unimport_mr = mlx5_unimport_mr,
.unimport_pd = mlx5_unimport_pd,
};
Expand Down
3 changes: 3 additions & 0 deletions providers/mlx5/mlx5.h
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ int mlx5_advise_mr(struct ibv_pd *pd,
uint32_t flags,
struct ibv_sge *sg_list,
uint32_t num_sges);
struct ibv_dm *mlx5_import_dm(struct ibv_context *context,
uint32_t dm_handle);
void mlx5_unimport_dm(struct ibv_dm *dm);
struct ibv_mr *mlx5_import_mr(struct ibv_pd *pd,
uint32_t mr_handle);
void mlx5_unimport_mr(struct ibv_mr *mr);
Expand Down
2 changes: 2 additions & 0 deletions providers/mlx5/mlx5dv.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ struct ibv_dm *mlx5dv_alloc_dm(struct ibv_context *context,
struct ibv_alloc_dm_attr *dm_attr,
struct mlx5dv_alloc_dm_attr *mlx5_dm_attr);

void *mlx5dv_dm_map_op_addr(struct ibv_dm *dm, uint8_t op);

struct mlx5_wqe_av;

struct mlx5dv_ah {
Expand Down
Loading

0 comments on commit 5b1e6d7

Please sign in to comment.