Skip to content

Commit 8af174e

Browse files
haiyangzdavem330
authored andcommitted
net: mana: Fix race of mana_hwc_post_rx_wqe and new hwc response
The mana_hwc_rx_event_handler() / mana_hwc_handle_resp() calls complete(&ctx->comp_event) before posting the wqe back. It's possible that other callers, like mana_create_txq(), start the next round of mana_hwc_send_request() before the posting of wqe. And if the HW is fast enough to respond, it can hit no_wqe error on the HW channel, then the response message is lost. The mana driver may fail to create queues and open, because of waiting for the HW response and timed out. Sample dmesg: [ 528.610840] mana 39d4:00:02.0: HWC: Request timed out! [ 528.614452] mana 39d4:00:02.0: Failed to send mana message: -110, 0x0 [ 528.618326] mana 39d4:00:02.0 enP14804s2: Failed to create WQ object: -110 To fix it, move posting of rx wqe before complete(&ctx->comp_event). Cc: [email protected] Fixes: ca9c54d ("net: mana: Add a driver for Microsoft Azure Network Adapter (MANA)") Signed-off-by: Haiyang Zhang <[email protected]> Reviewed-by: Long Li <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 82b8000 commit 8af174e

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

drivers/net/ethernet/microsoft/mana/hw_channel.c

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,41 @@ static int mana_hwc_verify_resp_msg(const struct hwc_caller_ctx *caller_ctx,
5252
return 0;
5353
}
5454

55+
static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq,
56+
struct hwc_work_request *req)
57+
{
58+
struct device *dev = hwc_rxq->hwc->dev;
59+
struct gdma_sge *sge;
60+
int err;
61+
62+
sge = &req->sge;
63+
sge->address = (u64)req->buf_sge_addr;
64+
sge->mem_key = hwc_rxq->msg_buf->gpa_mkey;
65+
sge->size = req->buf_len;
66+
67+
memset(&req->wqe_req, 0, sizeof(struct gdma_wqe_request));
68+
req->wqe_req.sgl = sge;
69+
req->wqe_req.num_sge = 1;
70+
req->wqe_req.client_data_unit = 0;
71+
72+
err = mana_gd_post_and_ring(hwc_rxq->gdma_wq, &req->wqe_req, NULL);
73+
if (err)
74+
dev_err(dev, "Failed to post WQE on HWC RQ: %d\n", err);
75+
return err;
76+
}
77+
5578
static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
56-
const struct gdma_resp_hdr *resp_msg)
79+
struct hwc_work_request *rx_req)
5780
{
81+
const struct gdma_resp_hdr *resp_msg = rx_req->buf_va;
5882
struct hwc_caller_ctx *ctx;
5983
int err;
6084

6185
if (!test_bit(resp_msg->response.hwc_msg_id,
6286
hwc->inflight_msg_res.map)) {
6387
dev_err(hwc->dev, "hwc_rx: invalid msg_id = %u\n",
6488
resp_msg->response.hwc_msg_id);
89+
mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
6590
return;
6691
}
6792

@@ -75,30 +100,13 @@ static void mana_hwc_handle_resp(struct hw_channel_context *hwc, u32 resp_len,
75100
memcpy(ctx->output_buf, resp_msg, resp_len);
76101
out:
77102
ctx->error = err;
78-
complete(&ctx->comp_event);
79-
}
80-
81-
static int mana_hwc_post_rx_wqe(const struct hwc_wq *hwc_rxq,
82-
struct hwc_work_request *req)
83-
{
84-
struct device *dev = hwc_rxq->hwc->dev;
85-
struct gdma_sge *sge;
86-
int err;
87-
88-
sge = &req->sge;
89-
sge->address = (u64)req->buf_sge_addr;
90-
sge->mem_key = hwc_rxq->msg_buf->gpa_mkey;
91-
sge->size = req->buf_len;
92103

93-
memset(&req->wqe_req, 0, sizeof(struct gdma_wqe_request));
94-
req->wqe_req.sgl = sge;
95-
req->wqe_req.num_sge = 1;
96-
req->wqe_req.client_data_unit = 0;
104+
/* Must post rx wqe before complete(), otherwise the next rx may
105+
* hit no_wqe error.
106+
*/
107+
mana_hwc_post_rx_wqe(hwc->rxq, rx_req);
97108

98-
err = mana_gd_post_and_ring(hwc_rxq->gdma_wq, &req->wqe_req, NULL);
99-
if (err)
100-
dev_err(dev, "Failed to post WQE on HWC RQ: %d\n", err);
101-
return err;
109+
complete(&ctx->comp_event);
102110
}
103111

104112
static void mana_hwc_init_event_handler(void *ctx, struct gdma_queue *q_self,
@@ -235,14 +243,12 @@ static void mana_hwc_rx_event_handler(void *ctx, u32 gdma_rxq_id,
235243
return;
236244
}
237245

238-
mana_hwc_handle_resp(hwc, rx_oob->tx_oob_data_size, resp);
246+
mana_hwc_handle_resp(hwc, rx_oob->tx_oob_data_size, rx_req);
239247

240-
/* Do no longer use 'resp', because the buffer is posted to the HW
241-
* in the below mana_hwc_post_rx_wqe().
248+
/* Can no longer use 'resp', because the buffer is posted to the HW
249+
* in mana_hwc_handle_resp() above.
242250
*/
243251
resp = NULL;
244-
245-
mana_hwc_post_rx_wqe(hwc_rxq, rx_req);
246252
}
247253

248254
static void mana_hwc_tx_event_handler(void *ctx, u32 gdma_txq_id,

0 commit comments

Comments
 (0)