Skip to content

Commit 7df48e3

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: - Quite a few irdma bug fixes, several user triggerable - Fix a 0 SMAC header in ionic - Tolerate FW errors for RAAS in bng_re - Don't UAF in efa when printing error events - Better handle pool exhaustion in the new bvec paths * tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: RDMA/irdma: Harden depth calculation functions RDMA/irdma: Return EINVAL for invalid arp index error RDMA/irdma: Fix deadlock during netdev reset with active connections RDMA/irdma: Remove reset check from irdma_modify_qp_to_err() RDMA/irdma: Clean up unnecessary dereference of event->cm_node RDMA/irdma: Remove a NOP wait_event() in irdma_modify_qp_roce() RDMA/irdma: Update ibqp state to error if QP is already in error state RDMA/irdma: Initialize free_qp completion before using it RDMA/efa: Fix possible deadlock RDMA/rw: Fix MR pool exhaustion in bvec RDMA READ path RDMA/rw: Fall back to direct SGE on MR pool exhaustion RDMA/efa: Fix use of completion ctx after free RDMA/bng_re: Fix silent failure in HWRM version query RDMA/ionic: Preserve and set Ethernet source MAC after ib_ud_header_init() RDMA/irdma: Fix double free related to rereg_user_mr
2 parents 8af4fad + e37afcb commit 7df48e3

8 files changed

Lines changed: 123 additions & 100 deletions

File tree

drivers/infiniband/core/rw.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,29 @@ int rdma_rw_ctx_init(struct rdma_rw_ctx *ctx, struct ib_qp *qp, u32 port_num,
608608
if (rdma_rw_io_needs_mr(qp->device, port_num, dir, sg_cnt)) {
609609
ret = rdma_rw_init_mr_wrs(ctx, qp, port_num, sg, sg_cnt,
610610
sg_offset, remote_addr, rkey, dir);
611-
} else if (sg_cnt > 1) {
611+
/*
612+
* If MR init succeeded or failed for a reason other
613+
* than pool exhaustion, that result is final.
614+
*
615+
* Pool exhaustion (-EAGAIN) from the max_sgl_rd
616+
* optimization is recoverable: fall back to
617+
* direct SGE posting. iWARP and force_mr require
618+
* MRs unconditionally, so -EAGAIN is terminal.
619+
*/
620+
if (ret != -EAGAIN ||
621+
rdma_protocol_iwarp(qp->device, port_num) ||
622+
unlikely(rdma_rw_force_mr))
623+
goto out;
624+
}
625+
626+
if (sg_cnt > 1)
612627
ret = rdma_rw_init_map_wrs(ctx, qp, sg, sg_cnt, sg_offset,
613628
remote_addr, rkey, dir);
614-
} else {
629+
else
615630
ret = rdma_rw_init_single_wr(ctx, qp, sg, sg_offset,
616631
remote_addr, rkey, dir);
617-
}
618632

633+
out:
619634
if (ret < 0)
620635
goto out_unmap_sg;
621636
return ret;
@@ -686,14 +701,16 @@ int rdma_rw_ctx_init_bvec(struct rdma_rw_ctx *ctx, struct ib_qp *qp,
686701
return ret;
687702

688703
/*
689-
* IOVA mapping not available. Check if MR registration provides
690-
* better performance than multiple SGE entries.
704+
* IOVA not available; fall back to the map_wrs path, which maps
705+
* each bvec as a direct SGE. This is always correct: the MR path
706+
* is a throughput optimization, not a correctness requirement.
707+
* (iWARP, which does require MRs, is handled by the check above.)
708+
*
709+
* The rdma_rw_io_needs_mr() gate is not used here because nr_bvec
710+
* is a raw page count that overstates DMA entry demand -- the bvec
711+
* caller has no post-DMA-coalescing segment count, and feeding the
712+
* inflated count into the MR path exhausts the pool on RDMA READs.
691713
*/
692-
if (rdma_rw_io_needs_mr(dev, port_num, dir, nr_bvec))
693-
return rdma_rw_init_mr_wrs_bvec(ctx, qp, port_num, bvecs,
694-
nr_bvec, &iter, remote_addr,
695-
rkey, dir);
696-
697714
return rdma_rw_init_map_wrs_bvec(ctx, qp, bvecs, nr_bvec, &iter,
698715
remote_addr, rkey, dir);
699716
}

drivers/infiniband/hw/bng_re/bng_dev.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static int bng_re_stats_ctx_alloc(struct bng_re_dev *rdev)
210210
return rc;
211211
}
212212

213-
static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
213+
static int bng_re_query_hwrm_version(struct bng_re_dev *rdev)
214214
{
215215
struct bnge_auxr_dev *aux_dev = rdev->aux_dev;
216216
struct hwrm_ver_get_output ver_get_resp = {};
@@ -230,7 +230,7 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
230230
if (rc) {
231231
ibdev_err(&rdev->ibdev, "Failed to query HW version, rc = 0x%x",
232232
rc);
233-
return;
233+
return rc;
234234
}
235235

236236
cctx = rdev->chip_ctx;
@@ -244,6 +244,8 @@ static void bng_re_query_hwrm_version(struct bng_re_dev *rdev)
244244

245245
if (!cctx->hwrm_cmd_max_timeout)
246246
cctx->hwrm_cmd_max_timeout = BNG_ROCE_FW_MAX_TIMEOUT;
247+
248+
return 0;
247249
}
248250

249251
static void bng_re_dev_uninit(struct bng_re_dev *rdev)
@@ -306,13 +308,15 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
306308
goto msix_ctx_fail;
307309
}
308310

309-
bng_re_query_hwrm_version(rdev);
311+
rc = bng_re_query_hwrm_version(rdev);
312+
if (rc)
313+
goto destroy_chip_ctx;
310314

311315
rc = bng_re_alloc_fw_channel(&rdev->bng_res, &rdev->rcfw);
312316
if (rc) {
313317
ibdev_err(&rdev->ibdev,
314318
"Failed to allocate RCFW Channel: %#x\n", rc);
315-
goto alloc_fw_chl_fail;
319+
goto destroy_chip_ctx;
316320
}
317321

318322
/* Allocate nq record memory */
@@ -391,7 +395,7 @@ static int bng_re_dev_init(struct bng_re_dev *rdev)
391395
kfree(rdev->nqr);
392396
nq_alloc_fail:
393397
bng_re_free_rcfw_channel(&rdev->rcfw);
394-
alloc_fw_chl_fail:
398+
destroy_chip_ctx:
395399
bng_re_destroy_chip_ctx(rdev);
396400
msix_ctx_fail:
397401
bnge_unregister_dev(rdev->aux_dev);

drivers/infiniband/hw/efa/efa_com.c

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
22
/*
3-
* Copyright 2018-2025 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2026 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include <linux/log2.h>
@@ -310,23 +310,19 @@ static inline struct efa_comp_ctx *efa_com_get_comp_ctx_by_cmd_id(struct efa_com
310310
return &aq->comp_ctx[ctx_id];
311311
}
312312

313-
static struct efa_comp_ctx *__efa_com_submit_admin_cmd(struct efa_com_admin_queue *aq,
314-
struct efa_admin_aq_entry *cmd,
315-
size_t cmd_size_in_bytes,
316-
struct efa_admin_acq_entry *comp,
317-
size_t comp_size_in_bytes)
313+
static void __efa_com_submit_admin_cmd(struct efa_com_admin_queue *aq,
314+
struct efa_comp_ctx *comp_ctx,
315+
struct efa_admin_aq_entry *cmd,
316+
size_t cmd_size_in_bytes,
317+
struct efa_admin_acq_entry *comp,
318+
size_t comp_size_in_bytes)
318319
{
319320
struct efa_admin_aq_entry *aqe;
320-
struct efa_comp_ctx *comp_ctx;
321321
u16 queue_size_mask;
322322
u16 cmd_id;
323323
u16 ctx_id;
324324
u16 pi;
325325

326-
comp_ctx = efa_com_alloc_comp_ctx(aq);
327-
if (!comp_ctx)
328-
return ERR_PTR(-EINVAL);
329-
330326
queue_size_mask = aq->depth - 1;
331327
pi = aq->sq.pc & queue_size_mask;
332328
ctx_id = efa_com_get_comp_ctx_id(aq, comp_ctx);
@@ -360,8 +356,6 @@ static struct efa_comp_ctx *__efa_com_submit_admin_cmd(struct efa_com_admin_queu
360356

361357
/* barrier not needed in case of writel */
362358
writel(aq->sq.pc, aq->sq.db_addr);
363-
364-
return comp_ctx;
365359
}
366360

367361
static inline int efa_com_init_comp_ctxt(struct efa_com_admin_queue *aq)
@@ -394,28 +388,25 @@ static inline int efa_com_init_comp_ctxt(struct efa_com_admin_queue *aq)
394388
return 0;
395389
}
396390

397-
static struct efa_comp_ctx *efa_com_submit_admin_cmd(struct efa_com_admin_queue *aq,
398-
struct efa_admin_aq_entry *cmd,
399-
size_t cmd_size_in_bytes,
400-
struct efa_admin_acq_entry *comp,
401-
size_t comp_size_in_bytes)
391+
static int efa_com_submit_admin_cmd(struct efa_com_admin_queue *aq,
392+
struct efa_comp_ctx *comp_ctx,
393+
struct efa_admin_aq_entry *cmd,
394+
size_t cmd_size_in_bytes,
395+
struct efa_admin_acq_entry *comp,
396+
size_t comp_size_in_bytes)
402397
{
403-
struct efa_comp_ctx *comp_ctx;
404-
405398
spin_lock(&aq->sq.lock);
406399
if (!test_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state)) {
407400
ibdev_err_ratelimited(aq->efa_dev, "Admin queue is closed\n");
408401
spin_unlock(&aq->sq.lock);
409-
return ERR_PTR(-ENODEV);
402+
return -ENODEV;
410403
}
411404

412-
comp_ctx = __efa_com_submit_admin_cmd(aq, cmd, cmd_size_in_bytes, comp,
413-
comp_size_in_bytes);
405+
__efa_com_submit_admin_cmd(aq, comp_ctx, cmd, cmd_size_in_bytes, comp,
406+
comp_size_in_bytes);
414407
spin_unlock(&aq->sq.lock);
415-
if (IS_ERR(comp_ctx))
416-
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
417408

418-
return comp_ctx;
409+
return 0;
419410
}
420411

421412
static int efa_com_handle_single_admin_completion(struct efa_com_admin_queue *aq,
@@ -512,7 +503,6 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_c
512503
{
513504
unsigned long timeout;
514505
unsigned long flags;
515-
int err;
516506

517507
timeout = jiffies + usecs_to_jiffies(aq->completion_timeout);
518508

@@ -532,24 +522,20 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_c
532522
atomic64_inc(&aq->stats.no_completion);
533523

534524
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
535-
err = -ETIME;
536-
goto out;
525+
return -ETIME;
537526
}
538527

539528
msleep(aq->poll_interval);
540529
}
541530

542-
err = efa_com_comp_status_to_errno(comp_ctx->user_cqe->acq_common_descriptor.status);
543-
out:
544-
efa_com_dealloc_comp_ctx(aq, comp_ctx);
545-
return err;
531+
return efa_com_comp_status_to_errno(
532+
comp_ctx->user_cqe->acq_common_descriptor.status);
546533
}
547534

548535
static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *comp_ctx,
549536
struct efa_com_admin_queue *aq)
550537
{
551538
unsigned long flags;
552-
int err;
553539

554540
wait_for_completion_timeout(&comp_ctx->wait_event,
555541
usecs_to_jiffies(aq->completion_timeout));
@@ -585,14 +571,11 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com
585571
aq->cq.cc);
586572

587573
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
588-
err = -ETIME;
589-
goto out;
574+
return -ETIME;
590575
}
591576

592-
err = efa_com_comp_status_to_errno(comp_ctx->user_cqe->acq_common_descriptor.status);
593-
out:
594-
efa_com_dealloc_comp_ctx(aq, comp_ctx);
595-
return err;
577+
return efa_com_comp_status_to_errno(
578+
comp_ctx->user_cqe->acq_common_descriptor.status);
596579
}
597580

598581
/*
@@ -642,30 +625,39 @@ int efa_com_cmd_exec(struct efa_com_admin_queue *aq,
642625
ibdev_dbg(aq->efa_dev, "%s (opcode %d)\n",
643626
efa_com_cmd_str(cmd->aq_common_descriptor.opcode),
644627
cmd->aq_common_descriptor.opcode);
645-
comp_ctx = efa_com_submit_admin_cmd(aq, cmd, cmd_size, comp, comp_size);
646-
if (IS_ERR(comp_ctx)) {
628+
629+
comp_ctx = efa_com_alloc_comp_ctx(aq);
630+
if (!comp_ctx) {
631+
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
632+
up(&aq->avail_cmds);
633+
return -EINVAL;
634+
}
635+
636+
err = efa_com_submit_admin_cmd(aq, comp_ctx, cmd, cmd_size, comp, comp_size);
637+
if (err) {
647638
ibdev_err_ratelimited(
648639
aq->efa_dev,
649-
"Failed to submit command %s (opcode %u) err %pe\n",
640+
"Failed to submit command %s (opcode %u) err %d\n",
650641
efa_com_cmd_str(cmd->aq_common_descriptor.opcode),
651-
cmd->aq_common_descriptor.opcode, comp_ctx);
642+
cmd->aq_common_descriptor.opcode, err);
652643

644+
efa_com_dealloc_comp_ctx(aq, comp_ctx);
653645
up(&aq->avail_cmds);
654646
atomic64_inc(&aq->stats.cmd_err);
655-
return PTR_ERR(comp_ctx);
647+
return err;
656648
}
657649

658650
err = efa_com_wait_and_process_admin_cq(comp_ctx, aq);
659651
if (err) {
660652
ibdev_err_ratelimited(
661653
aq->efa_dev,
662-
"Failed to process command %s (opcode %u) comp_status %d err %d\n",
654+
"Failed to process command %s (opcode %u) err %d\n",
663655
efa_com_cmd_str(cmd->aq_common_descriptor.opcode),
664-
cmd->aq_common_descriptor.opcode,
665-
comp_ctx->user_cqe->acq_common_descriptor.status, err);
656+
cmd->aq_common_descriptor.opcode, err);
666657
atomic64_inc(&aq->stats.cmd_err);
667658
}
668659

660+
efa_com_dealloc_comp_ctx(aq, comp_ctx);
669661
up(&aq->avail_cmds);
670662

671663
return err;

drivers/infiniband/hw/ionic/ionic_controlpath.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ static int ionic_build_hdr(struct ionic_ibdev *dev,
508508
{
509509
const struct ib_global_route *grh;
510510
enum rdma_network_type net;
511+
u8 smac[ETH_ALEN];
511512
u16 vlan;
512513
int rc;
513514

@@ -518,7 +519,7 @@ static int ionic_build_hdr(struct ionic_ibdev *dev,
518519

519520
grh = rdma_ah_read_grh(attr);
520521

521-
rc = rdma_read_gid_l2_fields(grh->sgid_attr, &vlan, &hdr->eth.smac_h[0]);
522+
rc = rdma_read_gid_l2_fields(grh->sgid_attr, &vlan, smac);
522523
if (rc)
523524
return rc;
524525

@@ -536,6 +537,7 @@ static int ionic_build_hdr(struct ionic_ibdev *dev,
536537
if (rc)
537538
return rc;
538539

540+
ether_addr_copy(hdr->eth.smac_h, smac);
539541
ether_addr_copy(hdr->eth.dmac_h, attr->roce.dmac);
540542

541543
if (net == RDMA_NETWORK_IPV4) {

0 commit comments

Comments
 (0)