Skip to content

Commit 2d0e7ba

Browse files
mrgolinrleon
authored andcommitted
RDMA/efa: Properly handle unexpected AQ completions
Do not try to handle admin command completion if it has an unexpected command id and print a relevant error message. Reviewed-by: Firas Jahjah <[email protected]> Reviewed-by: Yehuda Yitschak <[email protected]> Signed-off-by: Michael Margolin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Gal Pressman <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]>
1 parent e095405 commit 2d0e7ba

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

drivers/infiniband/hw/efa/efa_com.c

Lines changed: 17 additions & 13 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-2021 Amazon.com, Inc. or its affiliates. All rights reserved.
3+
* Copyright 2018-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
44
*/
55

66
#include "efa_com.h"
@@ -406,8 +406,8 @@ static struct efa_comp_ctx *efa_com_submit_admin_cmd(struct efa_com_admin_queue
406406
return comp_ctx;
407407
}
408408

409-
static void efa_com_handle_single_admin_completion(struct efa_com_admin_queue *aq,
410-
struct efa_admin_acq_entry *cqe)
409+
static int efa_com_handle_single_admin_completion(struct efa_com_admin_queue *aq,
410+
struct efa_admin_acq_entry *cqe)
411411
{
412412
struct efa_comp_ctx *comp_ctx;
413413
u16 cmd_id;
@@ -416,26 +416,29 @@ static void efa_com_handle_single_admin_completion(struct efa_com_admin_queue *a
416416
EFA_ADMIN_ACQ_COMMON_DESC_COMMAND_ID);
417417

418418
comp_ctx = efa_com_get_comp_ctx(aq, cmd_id, false);
419-
if (!comp_ctx) {
419+
if (comp_ctx->status != EFA_CMD_SUBMITTED) {
420420
ibdev_err(aq->efa_dev,
421-
"comp_ctx is NULL. Changing the admin queue running state\n");
422-
clear_bit(EFA_AQ_STATE_RUNNING_BIT, &aq->state);
423-
return;
421+
"Received completion with unexpected command id[%d], sq producer: %d, sq consumer: %d, cq consumer: %d\n",
422+
cmd_id, aq->sq.pc, aq->sq.cc, aq->cq.cc);
423+
return -EINVAL;
424424
}
425425

426426
comp_ctx->status = EFA_CMD_COMPLETED;
427427
memcpy(comp_ctx->user_cqe, cqe, comp_ctx->comp_size);
428428

429429
if (!test_bit(EFA_AQ_STATE_POLLING_BIT, &aq->state))
430430
complete(&comp_ctx->wait_event);
431+
432+
return 0;
431433
}
432434

433435
static void efa_com_handle_admin_completion(struct efa_com_admin_queue *aq)
434436
{
435437
struct efa_admin_acq_entry *cqe;
436438
u16 queue_size_mask;
437-
u16 comp_num = 0;
439+
u16 comp_cmds = 0;
438440
u8 phase;
441+
int err;
439442
u16 ci;
440443

441444
queue_size_mask = aq->depth - 1;
@@ -453,10 +456,12 @@ static void efa_com_handle_admin_completion(struct efa_com_admin_queue *aq)
453456
* phase bit was validated
454457
*/
455458
dma_rmb();
456-
efa_com_handle_single_admin_completion(aq, cqe);
459+
err = efa_com_handle_single_admin_completion(aq, cqe);
460+
if (!err)
461+
comp_cmds++;
457462

463+
aq->cq.cc++;
458464
ci++;
459-
comp_num++;
460465
if (ci == aq->depth) {
461466
ci = 0;
462467
phase = !phase;
@@ -465,10 +470,9 @@ static void efa_com_handle_admin_completion(struct efa_com_admin_queue *aq)
465470
cqe = &aq->cq.entries[ci];
466471
}
467472

468-
aq->cq.cc += comp_num;
469473
aq->cq.phase = phase;
470-
aq->sq.cc += comp_num;
471-
atomic64_add(comp_num, &aq->stats.completed_cmd);
474+
aq->sq.cc += comp_cmds;
475+
atomic64_add(comp_cmds, &aq->stats.completed_cmd);
472476
}
473477

474478
static int efa_com_comp_status_to_errno(u8 comp_status)

0 commit comments

Comments
 (0)