Skip to content

Commit 17d85f3

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
Pull rdma fixes from Jason Gunthorpe: - Memory leak in bnxt GSI qp path - Failure in irdma registering large MRs - Failure to clean out the right CQ table entry in irdma - Invalid vf_id in some cases - Incorrect error unwind in EFA CQ create - hns doesn't use the optimal cq/qp relationships for it's HW banks - hns reports the wrong SGE size to userspace for its QPs - Corruption of the hns work queue entries in some cases * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: MAINTAINERS: Update irdma maintainers RDMA/irdma: Fix vf_id size to u16 to avoid overflow RDMA/hns: Remove an extra blank line RDMA/hns: Fix wrong WQE data when QP wraps around RDMA/hns: Fix the modification of max_send_sge RDMA/hns: Fix recv CQ and QP cache affinity RDMA/uverbs: Fix umem release in UVERBS_METHOD_CQ_CREATE RDMA/irdma: Set irdma_cq cq_num field during CQ create RDMA/irdma: Fix SD index calculation RDMA/bnxt_re: Fix a potential memory leak in destroy_gsi_sqp
2 parents c9cfc12 + b812620 commit 17d85f3

File tree

13 files changed

+87
-29
lines changed

13 files changed

+87
-29
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12521,6 +12521,7 @@ F: include/linux/avf/virtchnl.h
1252112521
F: include/linux/net/intel/*/
1252212522

1252312523
INTEL ETHERNET PROTOCOL DRIVER FOR RDMA
12524+
M: Krzysztof Czurylo <[email protected]>
1252412525
M: Tatyana Nikolova <[email protected]>
1252512526
1252612527
S: Supported

drivers/infiniband/core/uverbs_std_types_cq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
206206
return ret;
207207

208208
err_free:
209+
ib_umem_release(umem);
209210
rdma_restrack_put(&cq->res);
210211
kfree(cq);
211212
err_event_file:

drivers/infiniband/hw/bnxt_re/ib_verbs.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ void bnxt_re_unlock_cqs(struct bnxt_re_qp *qp,
913913
spin_unlock_irqrestore(&qp->scq->cq_lock, flags);
914914
}
915915

916-
static int bnxt_re_destroy_gsi_sqp(struct bnxt_re_qp *qp)
916+
static void bnxt_re_destroy_gsi_sqp(struct bnxt_re_qp *qp)
917917
{
918918
struct bnxt_re_qp *gsi_sqp;
919919
struct bnxt_re_ah *gsi_sah;
@@ -933,10 +933,9 @@ static int bnxt_re_destroy_gsi_sqp(struct bnxt_re_qp *qp)
933933

934934
ibdev_dbg(&rdev->ibdev, "Destroy the shadow QP\n");
935935
rc = bnxt_qplib_destroy_qp(&rdev->qplib_res, &gsi_sqp->qplib_qp);
936-
if (rc) {
936+
if (rc)
937937
ibdev_err(&rdev->ibdev, "Destroy Shadow QP failed");
938-
goto fail;
939-
}
938+
940939
bnxt_qplib_free_qp_res(&rdev->qplib_res, &gsi_sqp->qplib_qp);
941940

942941
/* remove from active qp list */
@@ -951,10 +950,6 @@ static int bnxt_re_destroy_gsi_sqp(struct bnxt_re_qp *qp)
951950
rdev->gsi_ctx.gsi_sqp = NULL;
952951
rdev->gsi_ctx.gsi_sah = NULL;
953952
rdev->gsi_ctx.sqp_tbl = NULL;
954-
955-
return 0;
956-
fail:
957-
return rc;
958953
}
959954

960955
static void bnxt_re_del_unique_gid(struct bnxt_re_dev *rdev)

drivers/infiniband/hw/efa/efa_verbs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,13 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12161216
if (umem->length < cq->size) {
12171217
ibdev_dbg(&dev->ibdev, "External memory too small\n");
12181218
err = -EINVAL;
1219-
goto err_free_mem;
1219+
goto err_out;
12201220
}
12211221

12221222
if (!ib_umem_is_contiguous(umem)) {
12231223
ibdev_dbg(&dev->ibdev, "Non contiguous CQ unsupported\n");
12241224
err = -EINVAL;
1225-
goto err_free_mem;
1225+
goto err_out;
12261226
}
12271227

12281228
cq->cpu_addr = NULL;
@@ -1251,7 +1251,7 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12511251

12521252
err = efa_com_create_cq(&dev->edev, &params, &result);
12531253
if (err)
1254-
goto err_free_mem;
1254+
goto err_free_mapped;
12551255

12561256
resp.db_off = result.db_off;
12571257
resp.cq_idx = result.cq_idx;
@@ -1299,12 +1299,10 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
12991299
efa_cq_user_mmap_entries_remove(cq);
13001300
err_destroy_cq:
13011301
efa_destroy_cq_idx(dev, cq->cq_idx);
1302-
err_free_mem:
1303-
if (umem)
1304-
ib_umem_release(umem);
1305-
else
1306-
efa_free_mapped(dev, cq->cpu_addr, cq->dma_addr, cq->size, DMA_FROM_DEVICE);
1307-
1302+
err_free_mapped:
1303+
if (!umem)
1304+
efa_free_mapped(dev, cq->cpu_addr, cq->dma_addr, cq->size,
1305+
DMA_FROM_DEVICE);
13081306
err_out:
13091307
atomic64_inc(&dev->stats.create_cq_err);
13101308
return err;

drivers/infiniband/hw/hns/hns_roce_cq.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,51 @@
3030
* SOFTWARE.
3131
*/
3232

33+
#include <linux/pci.h>
3334
#include <rdma/ib_umem.h>
3435
#include <rdma/uverbs_ioctl.h>
3536
#include "hns_roce_device.h"
3637
#include "hns_roce_cmd.h"
3738
#include "hns_roce_hem.h"
3839
#include "hns_roce_common.h"
3940

41+
void hns_roce_put_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx)
42+
{
43+
struct hns_roce_dev *hr_dev = to_hr_dev(uctx->ibucontext.device);
44+
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
45+
46+
if (hr_dev->pci_dev->revision < PCI_REVISION_ID_HIP09)
47+
return;
48+
49+
mutex_lock(&cq_table->bank_mutex);
50+
cq_table->ctx_num[uctx->cq_bank_id]--;
51+
mutex_unlock(&cq_table->bank_mutex);
52+
}
53+
54+
void hns_roce_get_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx)
55+
{
56+
struct hns_roce_dev *hr_dev = to_hr_dev(uctx->ibucontext.device);
57+
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
58+
u32 least_load = cq_table->ctx_num[0];
59+
u8 bankid = 0;
60+
u8 i;
61+
62+
if (hr_dev->pci_dev->revision < PCI_REVISION_ID_HIP09)
63+
return;
64+
65+
mutex_lock(&cq_table->bank_mutex);
66+
for (i = 1; i < HNS_ROCE_CQ_BANK_NUM; i++) {
67+
if (cq_table->ctx_num[i] < least_load) {
68+
least_load = cq_table->ctx_num[i];
69+
bankid = i;
70+
}
71+
}
72+
cq_table->ctx_num[bankid]++;
73+
mutex_unlock(&cq_table->bank_mutex);
74+
75+
uctx->cq_bank_id = bankid;
76+
}
77+
4078
static u8 get_least_load_bankid_for_cq(struct hns_roce_bank *bank)
4179
{
4280
u32 least_load = bank[0].inuse;
@@ -55,15 +93,29 @@ static u8 get_least_load_bankid_for_cq(struct hns_roce_bank *bank)
5593
return bankid;
5694
}
5795

58-
static int alloc_cqn(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq)
96+
static u8 select_cq_bankid(struct hns_roce_dev *hr_dev,
97+
struct hns_roce_bank *bank, struct ib_udata *udata)
98+
{
99+
struct hns_roce_ucontext *uctx = udata ?
100+
rdma_udata_to_drv_context(udata, struct hns_roce_ucontext,
101+
ibucontext) : NULL;
102+
103+
if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
104+
return uctx ? uctx->cq_bank_id : 0;
105+
106+
return get_least_load_bankid_for_cq(bank);
107+
}
108+
109+
static int alloc_cqn(struct hns_roce_dev *hr_dev, struct hns_roce_cq *hr_cq,
110+
struct ib_udata *udata)
59111
{
60112
struct hns_roce_cq_table *cq_table = &hr_dev->cq_table;
61113
struct hns_roce_bank *bank;
62114
u8 bankid;
63115
int id;
64116

65117
mutex_lock(&cq_table->bank_mutex);
66-
bankid = get_least_load_bankid_for_cq(cq_table->bank);
118+
bankid = select_cq_bankid(hr_dev, cq_table->bank, udata);
67119
bank = &cq_table->bank[bankid];
68120

69121
id = ida_alloc_range(&bank->ida, bank->min, bank->max, GFP_KERNEL);
@@ -396,7 +448,7 @@ int hns_roce_create_cq(struct ib_cq *ib_cq, const struct ib_cq_init_attr *attr,
396448
goto err_cq_buf;
397449
}
398450

399-
ret = alloc_cqn(hr_dev, hr_cq);
451+
ret = alloc_cqn(hr_dev, hr_cq, udata);
400452
if (ret) {
401453
ibdev_err(ibdev, "failed to alloc CQN, ret = %d.\n", ret);
402454
goto err_cq_db;

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ struct hns_roce_ucontext {
217217
struct mutex page_mutex;
218218
struct hns_user_mmap_entry *db_mmap_entry;
219219
u32 config;
220+
u8 cq_bank_id;
220221
};
221222

222223
struct hns_roce_pd {
@@ -495,6 +496,7 @@ struct hns_roce_cq_table {
495496
struct hns_roce_hem_table table;
496497
struct hns_roce_bank bank[HNS_ROCE_CQ_BANK_NUM];
497498
struct mutex bank_mutex;
499+
u32 ctx_num[HNS_ROCE_CQ_BANK_NUM];
498500
};
499501

500502
struct hns_roce_srq_table {
@@ -1305,5 +1307,7 @@ hns_roce_user_mmap_entry_insert(struct ib_ucontext *ucontext, u64 address,
13051307
size_t length,
13061308
enum hns_roce_mmap_type mmap_type);
13071309
bool check_sl_valid(struct hns_roce_dev *hr_dev, u8 sl);
1310+
void hns_roce_put_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx);
1311+
void hns_roce_get_cq_bankid_for_uctx(struct hns_roce_ucontext *uctx);
13081312

13091313
#endif /* _HNS_ROCE_DEVICE_H */

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ static void set_frmr_seg(struct hns_roce_v2_rc_send_wqe *rc_sq_wqe,
165165
hr_reg_write(fseg, FRMR_PBL_BUF_PG_SZ,
166166
to_hr_hw_page_shift(mr->pbl_mtr.hem_cfg.buf_pg_shift));
167167
hr_reg_clear(fseg, FRMR_BLK_MODE);
168+
hr_reg_clear(fseg, FRMR_BLOCK_SIZE);
169+
hr_reg_clear(fseg, FRMR_ZBVA);
168170
}
169171

170172
static void set_atomic_seg(const struct ib_send_wr *wr,
@@ -339,9 +341,6 @@ static int set_rwqe_data_seg(struct ib_qp *ibqp, const struct ib_send_wr *wr,
339341
int j = 0;
340342
int i;
341343

342-
hr_reg_write(rc_sq_wqe, RC_SEND_WQE_MSG_START_SGE_IDX,
343-
(*sge_ind) & (qp->sge.sge_cnt - 1));
344-
345344
hr_reg_write(rc_sq_wqe, RC_SEND_WQE_INLINE,
346345
!!(wr->send_flags & IB_SEND_INLINE));
347346
if (wr->send_flags & IB_SEND_INLINE)
@@ -586,6 +585,9 @@ static inline int set_rc_wqe(struct hns_roce_qp *qp,
586585
hr_reg_write(rc_sq_wqe, RC_SEND_WQE_CQE,
587586
(wr->send_flags & IB_SEND_SIGNALED) ? 1 : 0);
588587

588+
hr_reg_write(rc_sq_wqe, RC_SEND_WQE_MSG_START_SGE_IDX,
589+
curr_idx & (qp->sge.sge_cnt - 1));
590+
589591
if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
590592
wr->opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
591593
if (msg_len != ATOMIC_WR_LEN)
@@ -734,6 +736,9 @@ static int hns_roce_v2_post_send(struct ib_qp *ibqp,
734736
owner_bit =
735737
~(((qp->sq.head + nreq) >> ilog2(qp->sq.wqe_cnt)) & 0x1);
736738

739+
/* RC and UD share the same DirectWQE field layout */
740+
((struct hns_roce_v2_rc_send_wqe *)wqe)->byte_4 = 0;
741+
737742
/* Corresponding to the QP type, wqe process separately */
738743
if (ibqp->qp_type == IB_QPT_RC)
739744
ret = set_rc_wqe(qp, wr, wqe, &sge_idx, owner_bit);
@@ -7048,7 +7053,6 @@ static int __hns_roce_hw_v2_init_instance(struct hnae3_handle *handle)
70487053
goto error_failed_roce_init;
70497054
}
70507055

7051-
70527056
handle->priv = hr_dev;
70537057

70547058
return 0;

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
425425
if (ret)
426426
goto error_fail_copy_to_udata;
427427

428+
hns_roce_get_cq_bankid_for_uctx(context);
429+
428430
return 0;
429431

430432
error_fail_copy_to_udata:
@@ -447,6 +449,8 @@ static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
447449
struct hns_roce_ucontext *context = to_hr_ucontext(ibcontext);
448450
struct hns_roce_dev *hr_dev = to_hr_dev(ibcontext->device);
449451

452+
hns_roce_put_cq_bankid_for_uctx(context);
453+
450454
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB ||
451455
hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB)
452456
mutex_destroy(&context->page_mutex);

drivers/infiniband/hw/hns/hns_roce_qp.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,6 @@ static int set_user_sq_size(struct hns_roce_dev *hr_dev,
662662

663663
hr_qp->sq.wqe_shift = ucmd->log_sq_stride;
664664
hr_qp->sq.wqe_cnt = cnt;
665-
cap->max_send_sge = hr_qp->sq.max_gs;
666665

667666
return 0;
668667
}
@@ -744,7 +743,6 @@ static int set_kernel_sq_size(struct hns_roce_dev *hr_dev,
744743

745744
/* sync the parameters of kernel QP to user's configuration */
746745
cap->max_send_wr = cnt;
747-
cap->max_send_sge = hr_qp->sq.max_gs;
748746

749747
return 0;
750748
}

drivers/infiniband/hw/irdma/pble.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int irdma_hmc_init_pble(struct irdma_sc_dev *dev,
7171
static void get_sd_pd_idx(struct irdma_hmc_pble_rsrc *pble_rsrc,
7272
struct sd_pd_idx *idx)
7373
{
74-
idx->sd_idx = (u32)pble_rsrc->next_fpm_addr / IRDMA_HMC_DIRECT_BP_SIZE;
74+
idx->sd_idx = pble_rsrc->next_fpm_addr / IRDMA_HMC_DIRECT_BP_SIZE;
7575
idx->pd_idx = (u32)(pble_rsrc->next_fpm_addr / IRDMA_HMC_PAGED_BP_SIZE);
7676
idx->rel_pd_idx = (idx->pd_idx % IRDMA_HMC_PD_CNT_IN_SD);
7777
}

0 commit comments

Comments
 (0)