Skip to content

Commit 3ffbe78

Browse files
longlimsftsmfrench
authored andcommitted
cifs: smbd: Check send queue size before posting a send
Sometimes the remote peer may return more send credits than the send queue depth. If all the send credits are used to post senasd, we may overflow the send queue. Fix this by checking the send queue size before posting a send. Signed-off-by: Long Li <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 072a14e commit 3ffbe78

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

fs/cifs/smbdirect.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
287287
if (atomic_dec_and_test(&request->info->send_pending))
288288
wake_up(&request->info->wait_send_pending);
289289

290+
wake_up(&request->info->wait_post_send);
290291

291292
mempool_free(request, request->info->request_mempool);
292293
}
@@ -939,7 +940,14 @@ static int smbd_post_send(struct smbd_connection *info,
939940
send_wr.opcode = IB_WR_SEND;
940941
send_wr.send_flags = IB_SEND_SIGNALED;
941942

942-
atomic_inc(&info->send_pending);
943+
wait_sq:
944+
wait_event(info->wait_post_send,
945+
atomic_read(&info->send_pending) < info->send_credit_target);
946+
if (unlikely(atomic_inc_return(&info->send_pending) >
947+
info->send_credit_target)) {
948+
atomic_dec(&info->send_pending);
949+
goto wait_sq;
950+
}
943951

944952
rc = ib_post_send(info->id->qp, &send_wr, NULL);
945953
if (rc) {
@@ -1733,6 +1741,7 @@ static struct smbd_connection *_smbd_get_connection(
17331741
init_waitqueue_head(&info->wait_send_pending);
17341742
atomic_set(&info->send_pending, 0);
17351743

1744+
init_waitqueue_head(&info->wait_post_send);
17361745

17371746
INIT_WORK(&info->disconnect_work, smbd_disconnect_rdma_work);
17381747
INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits);

fs/cifs/smbdirect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ struct smbd_connection {
114114
/* Activity accoutning */
115115
atomic_t send_pending;
116116
wait_queue_head_t wait_send_pending;
117+
wait_queue_head_t wait_post_send;
117118

118119
/* Receive queue */
119120
struct list_head receive_queue;

0 commit comments

Comments
 (0)