1 From 535005ca8e5e71918d64074032f4b9d4fef8981e Mon Sep 17 00:00:00 2001
2 From: Yuval Avnery <yuvalav@mellanox.com>
3 Date: Tue, 22 Jan 2019 09:02:05 +0200
4 Subject: IB/core: Destroy QP if XRC QP fails
6 From: Yuval Avnery <yuvalav@mellanox.com>
8 commit 535005ca8e5e71918d64074032f4b9d4fef8981e upstream.
10 The open-coded variant missed destroy of SELinux created QP, reuse already
11 existing ib_detroy_qp() call and use this opportunity to clean
12 ib_create_qp() from double prints and unclear exit paths.
14 Reported-by: Parav Pandit <parav@mellanox.com>
15 Fixes: d291f1a65232 ("IB/core: Enforce PKey security on QPs")
16 Signed-off-by: Yuval Avnery <yuvalav@mellanox.com>
17 Reviewed-by: Parav Pandit <parav@mellanox.com>
18 Reviewed-by: Daniel Jurgens <danielj@mellanox.com>
19 Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
20 Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24 drivers/infiniband/core/verbs.c | 41 +++++++++++++++++++++++-----------------
25 1 file changed, 24 insertions(+), 17 deletions(-)
27 --- a/drivers/infiniband/core/verbs.c
28 +++ b/drivers/infiniband/core/verbs.c
29 @@ -1087,8 +1087,8 @@ struct ib_qp *ib_open_qp(struct ib_xrcd
31 EXPORT_SYMBOL(ib_open_qp);
33 -static struct ib_qp *ib_create_xrc_qp(struct ib_qp *qp,
34 - struct ib_qp_init_attr *qp_init_attr)
35 +static struct ib_qp *create_xrc_qp(struct ib_qp *qp,
36 + struct ib_qp_init_attr *qp_init_attr)
38 struct ib_qp *real_qp = qp;
40 @@ -1103,10 +1103,10 @@ static struct ib_qp *ib_create_xrc_qp(st
42 qp = __ib_open_qp(real_qp, qp_init_attr->event_handler,
43 qp_init_attr->qp_context);
45 - __ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
47 - real_qp->device->destroy_qp(real_qp);
51 + __ib_insert_xrcd_qp(qp_init_attr->xrcd, real_qp);
55 @@ -1137,10 +1137,8 @@ struct ib_qp *ib_create_qp(struct ib_pd
58 ret = ib_create_qp_security(qp, device);
61 - return ERR_PTR(ret);
67 qp->qp_type = qp_init_attr->qp_type;
68 @@ -1153,8 +1151,15 @@ struct ib_qp *ib_create_qp(struct ib_pd
69 INIT_LIST_HEAD(&qp->sig_mrs);
72 - if (qp_init_attr->qp_type == IB_QPT_XRC_TGT)
73 - return ib_create_xrc_qp(qp, qp_init_attr);
74 + if (qp_init_attr->qp_type == IB_QPT_XRC_TGT) {
75 + struct ib_qp *xrc_qp = create_xrc_qp(qp, qp_init_attr);
77 + if (IS_ERR(xrc_qp)) {
78 + ret = PTR_ERR(xrc_qp);
84 qp->event_handler = qp_init_attr->event_handler;
85 qp->qp_context = qp_init_attr->qp_context;
86 @@ -1181,11 +1186,8 @@ struct ib_qp *ib_create_qp(struct ib_pd
88 if (qp_init_attr->cap.max_rdma_ctxs) {
89 ret = rdma_rw_init_mrs(qp, qp_init_attr);
91 - pr_err("failed to init MR pool ret= %d\n", ret);
93 - return ERR_PTR(ret);
100 @@ -1198,6 +1200,11 @@ struct ib_qp *ib_create_qp(struct ib_pd
101 device->attrs.max_sge_rd);
107 + return ERR_PTR(ret);
110 EXPORT_SYMBOL(ib_create_qp);