Skip to content

Commit

Permalink
verbs: Enhance async FD usage
Browse files Browse the repository at this point in the history
Enhance async FD usage by adding an option to enforce it be a mandatory
attribute in a given device once the applicable objects are created
(e.g.QP, CQ, etc.).

This is some preparation step before introducing in the next patch the
ibv_import_device() verb which must use its own async FD to be able to
get events on its private created objects.

In addition, we moved ibv_cmd_alloc_async_fd() to be called as part of
ibv_open_device() in case wasn't allocated yet (i.e. ioctl flow), this
will be aligned with the import device flow that will be introduced.

Signed-off-by: Yishai Hadas <yishaih@mellanox.com>
  • Loading branch information
yishaih committed Jul 9, 2020
1 parent 5f200b1 commit 317d889
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 6 deletions.
9 changes: 7 additions & 2 deletions libibverbs/cmd_cq.c
Expand Up @@ -31,13 +31,15 @@
*/

#include <infiniband/cmd_write.h>
#include "ibverbs.h"

static int ibv_icmd_create_cq(struct ibv_context *context, int cqe,
struct ibv_comp_channel *channel, int comp_vector,
uint32_t flags, struct ibv_cq *cq,
struct ibv_command_buffer *link)
{
DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_CQ, UVERBS_METHOD_CQ_CREATE, 8, link);
struct verbs_ex_private *priv = get_priv(context);
struct ib_uverbs_attr *handle;
struct ib_uverbs_attr *async_fd_attr;
uint32_t resp_cqe;
Expand All @@ -54,8 +56,11 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe,
fill_attr_in_fd(cmdb, UVERBS_ATTR_CREATE_CQ_COMP_CHANNEL, channel->fd);
fill_attr_in_uint32(cmdb, UVERBS_ATTR_CREATE_CQ_COMP_VECTOR, comp_vector);
async_fd_attr = fill_attr_in_fd(cmdb, UVERBS_ATTR_CREATE_CQ_EVENT_FD, context->async_fd);
/* Prevent fallback to the 'write' mode if kernel doesn't support it */
attr_optional(async_fd_attr);
if (priv->imported)
fallback_require_ioctl(cmdb);
else
/* Prevent fallback to the 'write' mode if kernel doesn't support it */
attr_optional(async_fd_attr);

if (flags) {
fallback_require_ex(cmdb);
Expand Down
5 changes: 1 addition & 4 deletions libibverbs/cmd_device.c
Expand Up @@ -99,7 +99,7 @@ int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
return 0;
}

static int cmd_alloc_async_fd(struct ibv_context *context)
int ibv_cmd_alloc_async_fd(struct ibv_context *context)
{
DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_ASYNC_EVENT,
UVERBS_METHOD_ASYNC_EVENT_ALLOC, 1);
Expand Down Expand Up @@ -153,9 +153,6 @@ static int cmd_get_context(struct verbs_context *context_ex,
return 0;
}
case SUCCESS:
ret = cmd_alloc_async_fd(context);
if (ret)
return ret;
break;
default:
return ret;
Expand Down
4 changes: 4 additions & 0 deletions libibverbs/cmd_qp.c
Expand Up @@ -76,6 +76,7 @@ static int ibv_icmd_create_qp(struct ibv_context *context,
struct ibv_command_buffer *link)
{
DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_QP, UVERBS_METHOD_QP_CREATE, 15, link);
struct verbs_ex_private *priv = get_priv(context);
struct ib_uverbs_attr *handle;
uint32_t qp_num;
uint32_t pd_handle;
Expand Down Expand Up @@ -172,6 +173,9 @@ static int ibv_icmd_create_qp(struct ibv_context *context,
fill_attr_in_ptr(cmdb, UVERBS_ATTR_CREATE_QP_CAP, &attr_ex->cap);
fill_attr_in_fd(cmdb, UVERBS_ATTR_CREATE_QP_EVENT_FD, context->async_fd);

if (priv->imported)
fallback_require_ioctl(cmdb);

if (attr_ex->sq_sig_all)
create_flags |= IB_UVERBS_QP_CREATE_SQ_SIG_ALL;

Expand Down
4 changes: 4 additions & 0 deletions libibverbs/cmd_srq.c
Expand Up @@ -53,6 +53,7 @@ static int ibv_icmd_create_srq(struct ibv_pd *pd, struct verbs_srq *vsrq,
struct ibv_command_buffer *link)
{
DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_SRQ, UVERBS_METHOD_SRQ_CREATE, 13, link);
struct verbs_ex_private *priv = get_priv(pd->context);
struct ib_uverbs_attr *handle;
uint32_t max_wr;
uint32_t max_sge;
Expand Down Expand Up @@ -107,6 +108,9 @@ static int ibv_icmd_create_srq(struct ibv_pd *pd, struct verbs_srq *vsrq,
fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_SRQ_RESP_MAX_WR, &max_wr);
fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_SRQ_RESP_MAX_SGE, &max_sge);

if (priv->imported)
fallback_require_ioctl(cmdb);

switch (execute_ioctl_fallback(srq->context, create_srq, cmdb, &ret)) {
case TRY_WRITE: {
if (attr_ex->srq_type == IBV_SRQT_BASIC && abi_ver > 5) {
Expand Down
4 changes: 4 additions & 0 deletions libibverbs/cmd_wq.c
Expand Up @@ -31,13 +31,15 @@
*/

#include <infiniband/cmd_write.h>
#include "ibverbs.h"

static int ibv_icmd_create_wq(struct ibv_context *context,
struct ibv_wq_init_attr *wq_init_attr,
struct ibv_wq *wq,
struct ibv_command_buffer *link)
{
DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_WQ, UVERBS_METHOD_WQ_CREATE, 13, link);
struct verbs_ex_private *priv = get_priv(context);
struct ib_uverbs_attr *handle;
uint32_t max_wr;
uint32_t max_sge;
Expand All @@ -62,6 +64,8 @@ static int ibv_icmd_create_wq(struct ibv_context *context,
fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_WQ_RESP_MAX_SGE, &max_sge);
fill_attr_out_ptr(cmdb, UVERBS_ATTR_CREATE_WQ_RESP_WQ_NUM, &wq_num);

if (priv->imported)
fallback_require_ioctl(cmdb);
fallback_require_ex(cmdb);

switch (execute_ioctl_fallback(context, create_wq, cmdb, &ret)) {
Expand Down
8 changes: 8 additions & 0 deletions libibverbs/device.c
Expand Up @@ -344,6 +344,7 @@ struct ibv_context *verbs_open_device(struct ibv_device *device, void *private_d
struct verbs_device *verbs_device = verbs_get_device(device);
int cmd_fd;
struct verbs_context *context_ex;
int ret;

/*
* We'll only be doing writes, but we need O_RDWR in case the
Expand All @@ -363,6 +364,13 @@ struct ibv_context *verbs_open_device(struct ibv_device *device, void *private_d
return NULL;

set_lib_ops(context_ex);
if (context_ex->context.async_fd == -1) {
ret = ibv_cmd_alloc_async_fd(&context_ex->context);
if (ret) {
ibv_close_device(&context_ex->context);
return NULL;
}
}

return &context_ex->context;
}
Expand Down
1 change: 1 addition & 0 deletions libibverbs/driver.h
Expand Up @@ -453,6 +453,7 @@ int ibv_cmd_query_device_ex(struct ibv_context *context,
int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num,
struct ibv_port_attr *port_attr,
struct ibv_query_port *cmd, size_t cmd_size);
int ibv_cmd_alloc_async_fd(struct ibv_context *context);
int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd,
struct ibv_alloc_pd *cmd, size_t cmd_size,
struct ib_uverbs_alloc_pd_resp *resp, size_t resp_size);
Expand Down
1 change: 1 addition & 0 deletions libibverbs/ibverbs.h
Expand Up @@ -74,6 +74,7 @@ struct verbs_ex_private {
uint32_t driver_id;
bool use_ioctl_write;
struct verbs_context_ops ops;
bool imported;
};

static inline struct verbs_ex_private *get_priv(struct ibv_context *ctx)
Expand Down

0 comments on commit 317d889

Please sign in to comment.