Skip to content

Commit c70285f

Browse files
yishaihdledford
authored andcommitted
IB/uverbs: Extend create QP to get RWQ indirection table
User applications that want to spread incoming traffic between several WQs should create a QP which contains an indirection table. When such a QP is created other receive side parameters are not valid and should not be given. Its send side is optional and assumed active based on max_send_wr capability value. Extend create QP to work accordingly. Signed-off-by: Yishai Hadas <[email protected]> Signed-off-by: Matan Barak <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Doug Ledford <[email protected]>
1 parent a9017e2 commit c70285f

File tree

2 files changed

+73
-12
lines changed

2 files changed

+73
-12
lines changed

drivers/infiniband/core/uverbs_cmd.c

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ static void put_wq_read(struct ib_wq *wq)
255255
put_uobj_read(wq->uobject);
256256
}
257257

258+
static struct ib_rwq_ind_table *idr_read_rwq_indirection_table(int ind_table_handle,
259+
struct ib_ucontext *context)
260+
{
261+
return idr_read_obj(&ib_uverbs_rwq_ind_tbl_idr, ind_table_handle, context, 0);
262+
}
263+
264+
static void put_rwq_indirection_table_read(struct ib_rwq_ind_table *ind_table)
265+
{
266+
put_uobj_read(ind_table->uobject);
267+
}
268+
258269
static struct ib_qp *idr_write_qp(int qp_handle, struct ib_ucontext *context)
259270
{
260271
struct ib_uobject *uobj;
@@ -1761,9 +1772,11 @@ static int create_qp(struct ib_uverbs_file *file,
17611772
struct ib_srq *srq = NULL;
17621773
struct ib_qp *qp;
17631774
char *buf;
1764-
struct ib_qp_init_attr attr;
1775+
struct ib_qp_init_attr attr = {};
17651776
struct ib_uverbs_ex_create_qp_resp resp;
17661777
int ret;
1778+
struct ib_rwq_ind_table *ind_tbl = NULL;
1779+
bool has_sq = true;
17671780

17681781
if (cmd->qp_type == IB_QPT_RAW_PACKET && !capable(CAP_NET_RAW))
17691782
return -EPERM;
@@ -1775,6 +1788,32 @@ static int create_qp(struct ib_uverbs_file *file,
17751788
init_uobj(&obj->uevent.uobject, cmd->user_handle, file->ucontext,
17761789
&qp_lock_class);
17771790
down_write(&obj->uevent.uobject.mutex);
1791+
if (cmd_sz >= offsetof(typeof(*cmd), rwq_ind_tbl_handle) +
1792+
sizeof(cmd->rwq_ind_tbl_handle) &&
1793+
(cmd->comp_mask & IB_UVERBS_CREATE_QP_MASK_IND_TABLE)) {
1794+
ind_tbl = idr_read_rwq_indirection_table(cmd->rwq_ind_tbl_handle,
1795+
file->ucontext);
1796+
if (!ind_tbl) {
1797+
ret = -EINVAL;
1798+
goto err_put;
1799+
}
1800+
1801+
attr.rwq_ind_tbl = ind_tbl;
1802+
}
1803+
1804+
if ((cmd_sz >= offsetof(typeof(*cmd), reserved1) +
1805+
sizeof(cmd->reserved1)) && cmd->reserved1) {
1806+
ret = -EOPNOTSUPP;
1807+
goto err_put;
1808+
}
1809+
1810+
if (ind_tbl && (cmd->max_recv_wr || cmd->max_recv_sge || cmd->is_srq)) {
1811+
ret = -EINVAL;
1812+
goto err_put;
1813+
}
1814+
1815+
if (ind_tbl && !cmd->max_send_wr)
1816+
has_sq = false;
17781817

17791818
if (cmd->qp_type == IB_QPT_XRC_TGT) {
17801819
xrcd = idr_read_xrcd(cmd->pd_handle, file->ucontext,
@@ -1798,20 +1837,24 @@ static int create_qp(struct ib_uverbs_file *file,
17981837
}
17991838
}
18001839

1801-
if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1802-
rcq = idr_read_cq(cmd->recv_cq_handle,
1803-
file->ucontext, 0);
1804-
if (!rcq) {
1805-
ret = -EINVAL;
1806-
goto err_put;
1840+
if (!ind_tbl) {
1841+
if (cmd->recv_cq_handle != cmd->send_cq_handle) {
1842+
rcq = idr_read_cq(cmd->recv_cq_handle,
1843+
file->ucontext, 0);
1844+
if (!rcq) {
1845+
ret = -EINVAL;
1846+
goto err_put;
1847+
}
18071848
}
18081849
}
18091850
}
18101851

1811-
scq = idr_read_cq(cmd->send_cq_handle, file->ucontext, !!rcq);
1812-
rcq = rcq ?: scq;
1852+
if (has_sq)
1853+
scq = idr_read_cq(cmd->send_cq_handle, file->ucontext, !!rcq);
1854+
if (!ind_tbl)
1855+
rcq = rcq ?: scq;
18131856
pd = idr_read_pd(cmd->pd_handle, file->ucontext);
1814-
if (!pd || !scq) {
1857+
if (!pd || (!scq && has_sq)) {
18151858
ret = -EINVAL;
18161859
goto err_put;
18171860
}
@@ -1878,16 +1921,20 @@ static int create_qp(struct ib_uverbs_file *file,
18781921
qp->send_cq = attr.send_cq;
18791922
qp->recv_cq = attr.recv_cq;
18801923
qp->srq = attr.srq;
1924+
qp->rwq_ind_tbl = ind_tbl;
18811925
qp->event_handler = attr.event_handler;
18821926
qp->qp_context = attr.qp_context;
18831927
qp->qp_type = attr.qp_type;
18841928
atomic_set(&qp->usecnt, 0);
18851929
atomic_inc(&pd->usecnt);
1886-
atomic_inc(&attr.send_cq->usecnt);
1930+
if (attr.send_cq)
1931+
atomic_inc(&attr.send_cq->usecnt);
18871932
if (attr.recv_cq)
18881933
atomic_inc(&attr.recv_cq->usecnt);
18891934
if (attr.srq)
18901935
atomic_inc(&attr.srq->usecnt);
1936+
if (ind_tbl)
1937+
atomic_inc(&ind_tbl->usecnt);
18911938
}
18921939
qp->uobject = &obj->uevent.uobject;
18931940

@@ -1927,6 +1974,8 @@ static int create_qp(struct ib_uverbs_file *file,
19271974
put_cq_read(rcq);
19281975
if (srq)
19291976
put_srq_read(srq);
1977+
if (ind_tbl)
1978+
put_rwq_indirection_table_read(ind_tbl);
19301979

19311980
mutex_lock(&file->mutex);
19321981
list_add_tail(&obj->uevent.uobject.list, &file->ucontext->qp_list);
@@ -1954,6 +2003,8 @@ static int create_qp(struct ib_uverbs_file *file,
19542003
put_cq_read(rcq);
19552004
if (srq)
19562005
put_srq_read(srq);
2006+
if (ind_tbl)
2007+
put_rwq_indirection_table_read(ind_tbl);
19572008

19582009
put_uobj_write(&obj->uevent.uobject);
19592010
return ret;
@@ -2047,7 +2098,7 @@ int ib_uverbs_ex_create_qp(struct ib_uverbs_file *file,
20472098
if (err)
20482099
return err;
20492100

2050-
if (cmd.comp_mask)
2101+
if (cmd.comp_mask & ~IB_UVERBS_CREATE_QP_SUP_COMP_MASK)
20512102
return -EINVAL;
20522103

20532104
if (cmd.reserved)

include/uapi/rdma/ib_user_verbs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,14 @@ struct ib_uverbs_create_qp {
523523
__u64 driver_data[0];
524524
};
525525

526+
enum ib_uverbs_create_qp_mask {
527+
IB_UVERBS_CREATE_QP_MASK_IND_TABLE = 1UL << 0,
528+
};
529+
530+
enum {
531+
IB_UVERBS_CREATE_QP_SUP_COMP_MASK = IB_UVERBS_CREATE_QP_MASK_IND_TABLE,
532+
};
533+
526534
struct ib_uverbs_ex_create_qp {
527535
__u64 user_handle;
528536
__u32 pd_handle;
@@ -540,6 +548,8 @@ struct ib_uverbs_ex_create_qp {
540548
__u8 reserved;
541549
__u32 comp_mask;
542550
__u32 create_flags;
551+
__u32 rwq_ind_tbl_handle;
552+
__u32 reserved1;
543553
};
544554

545555
struct ib_uverbs_open_qp {

0 commit comments

Comments
 (0)