Skip to content

Commit

Permalink
bnxt_re/lib: Avoid applications hang in resize cq operation
Browse files Browse the repository at this point in the history
[ Upstream commit ec106a3 ]

Library currently waits indefinitely for the resize CQ
completion notification from the hardware. Due to hardware
failure in handling the operation, there is a possible
application hang.

Add a loop count with a busy wait of definite time to avoid
the application hang.

Fixes: ae8b278 ("bnxt_re/lib: Resize CQ support")
Signed-off-by: Chandramohan Akula <chandramohan.akula@broadcom.com>
Signed-off-by: Selvin Xavier <selvin.xavier@broadcom.com>
Signed-off-by: Nicolas Morey <nmorey@suse.com>
  • Loading branch information
chandramohan-akula authored and nmorey committed Sep 24, 2024
1 parent 5acbf39 commit 40f77c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
36 changes: 36 additions & 0 deletions providers/bnxt_re/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#define CHIP_NUM_57508 0x1750
#define CHIP_NUM_57504 0x1751
#define CHIP_NUM_57502 0x1752
#define BNXT_NSEC_PER_SEC 1000000000UL

struct bnxt_re_chip_ctx {
__u16 chip_num;
Expand Down Expand Up @@ -531,4 +532,39 @@ static inline void bnxt_re_copy_data_to_pb(struct bnxt_re_push_buffer *pbuf,
mmio_write64(dst, *src);
}
}

static void timespec_sub(const struct timespec *a, const struct timespec *b,
struct timespec *res)
{
res->tv_sec = a->tv_sec - b->tv_sec;
res->tv_nsec = a->tv_nsec - b->tv_nsec;
if (res->tv_nsec < 0) {
res->tv_sec--;
res->tv_nsec += BNXT_NSEC_PER_SEC;
}
}

/*
* Function waits in a busy loop for a given nano seconds
* The maximum wait period allowed is less than one second
*/
static inline void bnxt_re_sub_sec_busy_wait(uint32_t nsec)
{
struct timespec start, cur, res;

if (nsec >= BNXT_NSEC_PER_SEC)
return;

if (clock_gettime(CLOCK_REALTIME, &start))
return;

while (1) {
if (clock_gettime(CLOCK_REALTIME, &cur))
return;
timespec_sub(&cur, &start, &res);
if (res.tv_nsec >= nsec)
break;
}
}

#endif
9 changes: 9 additions & 0 deletions providers/bnxt_re/verbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ int bnxt_re_resize_cq(struct ibv_cq *ibvcq, int ncqe)
struct bnxt_re_cq *cq = to_bnxt_re_cq(ibvcq);
struct ib_uverbs_resize_cq_resp resp = {};
struct ubnxt_re_resize_cq cmd = {};
uint16_t msec_wait = 100;
uint16_t exit_cnt = 20;
int rc = 0;

if (ncqe > dev->max_cq_depth)
Expand Down Expand Up @@ -355,6 +357,13 @@ int bnxt_re_resize_cq(struct ibv_cq *ibvcq, int ncqe)
list_add_tail(&cq->prev_cq_head, &compl->list);
compl = NULL;
memset(&tmp_wc, 0, sizeof(tmp_wc));
} else {
exit_cnt--;
if (unlikely(!exit_cnt)) {
rc = -EIO;
break;
}
bnxt_re_sub_sec_busy_wait(msec_wait * 1000000);
}
}
done:
Expand Down

0 comments on commit 40f77c0

Please sign in to comment.