Skip to content

Commit 93ac432

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: fix last send credit problem causing disconnects
When we are about to use the last send credit that was granted to us by the peer, we need to wait until we are ourself able to grant at least one credit to the peer. Otherwise it might not be possible for the peer to grant more credits. The following sections in MS-SMBD are related to this: 3.1.5.1 Sending Upper Layer Messages ... If Connection.SendCredits is 1 and the CreditsGranted field of the message is 0, stop processing. ... 3.1.5.9 Managing Credits Prior to Sending ... If Connection.ReceiveCredits is zero, or if Connection.SendCredits is one and the Connection.SendQueue is not empty, the sender MUST allocate and post at least one receive of size Connection.MaxReceiveSize and MUST increment Connection.ReceiveCredits by the number allocated and posted. If no receives are posted, the processing MUST return a value of zero to indicate to the caller that no Send message can be currently performed. ... This is a similar logic as we have in the server. Cc: <stable@vger.kernel.org> # 6.18.x Cc: Steve French <smfrench@gmail.com> Cc: Tom Talpey <tom@talpey.com> Cc: Long Li <longli@microsoft.com> Cc: Namjae Jeon <linkinjeon@kernel.org> Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 2153812 commit 93ac432

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

fs/smb/client/smbdirect.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,15 @@ static void smbd_post_send_credits(struct work_struct *work)
697697

698698
atomic_add(posted, &sc->recv_io.credits.available);
699699

700+
/*
701+
* If the last send credit is waiting for credits
702+
* it can grant we need to wake it up
703+
*/
704+
if (posted &&
705+
atomic_read(&sc->send_io.bcredits.count) == 0 &&
706+
atomic_read(&sc->send_io.credits.count) == 0)
707+
wake_up(&sc->send_io.credits.wait_queue);
708+
700709
/* Promptly send an immediate packet as defined in [MS-SMBD] 3.1.1.1 */
701710
if (atomic_read(&sc->recv_io.credits.count) <
702711
sc->recv_io.credits.target - 1) {
@@ -1394,6 +1403,26 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
13941403
goto err_wait_credit;
13951404
}
13961405

1406+
new_credits = manage_credits_prior_sending(sc);
1407+
if (new_credits == 0 &&
1408+
atomic_read(&sc->send_io.credits.count) == 0 &&
1409+
atomic_read(&sc->recv_io.credits.count) == 0) {
1410+
queue_work(sc->workqueue, &sc->recv_io.posted.refill_work);
1411+
rc = wait_event_interruptible(sc->send_io.credits.wait_queue,
1412+
atomic_read(&sc->send_io.credits.count) >= 1 ||
1413+
atomic_read(&sc->recv_io.credits.available) >= 1 ||
1414+
sc->status != SMBDIRECT_SOCKET_CONNECTED);
1415+
if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
1416+
rc = -ENOTCONN;
1417+
if (rc < 0) {
1418+
log_outgoing(ERR, "disconnected not sending on last credit\n");
1419+
rc = -EAGAIN;
1420+
goto err_wait_credit;
1421+
}
1422+
1423+
new_credits = manage_credits_prior_sending(sc);
1424+
}
1425+
13971426
request = smbd_alloc_send_io(sc);
13981427
if (IS_ERR(request)) {
13991428
rc = PTR_ERR(request);
@@ -1448,8 +1477,6 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
14481477

14491478
/* Fill in the packet header */
14501479
packet->credits_requested = cpu_to_le16(sp->send_credit_target);
1451-
1452-
new_credits = manage_credits_prior_sending(sc);
14531480
packet->credits_granted = cpu_to_le16(new_credits);
14541481

14551482
packet->flags = 0;

0 commit comments

Comments
 (0)