Skip to content

Commit 8cf2bba

Browse files
metze-sambasmfrench
authored andcommitted
smb: server: 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 problem was found by running this on Windows 2025 against ksmbd with required smb signing: 'frametest.exe -r 4k -t 20 -n 2000' after 'frametest.exe -w 4k -t 20 -n 2000'. Link: https://lore.kernel.org/linux-cifs/b58fa352-2386-4145-b42e-9b4b1d484e17@samba.org/ Cc: <stable@vger.kernel.org> # 6.18.x Cc: Namjae Jeon <linkinjeon@kernel.org> Cc: Steve French <smfrench@gmail.com> Cc: Tom Talpey <tom@talpey.com> Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Signed-off-by: Stefan Metzmacher <metze@samba.org> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 34abd40 commit 8cf2bba

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

fs/smb/server/transport_rdma.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,15 @@ static void smb_direct_post_recv_credits(struct work_struct *work)
10331033

10341034
atomic_add(credits, &sc->recv_io.credits.available);
10351035

1036+
/*
1037+
* If the last send credit is waiting for credits
1038+
* it can grant we need to wake it up
1039+
*/
1040+
if (credits &&
1041+
atomic_read(&sc->send_io.bcredits.count) == 0 &&
1042+
atomic_read(&sc->send_io.credits.count) == 0)
1043+
wake_up(&sc->send_io.credits.wait_queue);
1044+
10361045
if (credits)
10371046
queue_work(sc->workqueue, &sc->idle.immediate_work);
10381047
}
@@ -1306,6 +1315,7 @@ static int calc_rw_credits(struct smbdirect_socket *sc,
13061315

13071316
static int smb_direct_create_header(struct smbdirect_socket *sc,
13081317
int size, int remaining_data_length,
1318+
int new_credits,
13091319
struct smbdirect_send_io **sendmsg_out)
13101320
{
13111321
struct smbdirect_socket_parameters *sp = &sc->parameters;
@@ -1321,7 +1331,7 @@ static int smb_direct_create_header(struct smbdirect_socket *sc,
13211331
/* Fill in the packet header */
13221332
packet = (struct smbdirect_data_transfer *)sendmsg->packet;
13231333
packet->credits_requested = cpu_to_le16(sp->send_credit_target);
1324-
packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(sc));
1334+
packet->credits_granted = cpu_to_le16(new_credits);
13251335

13261336
packet->flags = 0;
13271337
if (manage_keep_alive_before_sending(sc))
@@ -1459,6 +1469,7 @@ static int smb_direct_post_send_data(struct smbdirect_socket *sc,
14591469
int data_length;
14601470
struct scatterlist sg[SMBDIRECT_SEND_IO_MAX_SGE - 1];
14611471
struct smbdirect_send_batch _send_ctx;
1472+
int new_credits;
14621473

14631474
if (!send_ctx) {
14641475
smb_direct_send_ctx_init(&_send_ctx, false, 0);
@@ -1477,12 +1488,29 @@ static int smb_direct_post_send_data(struct smbdirect_socket *sc,
14771488
if (ret)
14781489
goto credit_failed;
14791490

1491+
new_credits = manage_credits_prior_sending(sc);
1492+
if (new_credits == 0 &&
1493+
atomic_read(&sc->send_io.credits.count) == 0 &&
1494+
atomic_read(&sc->recv_io.credits.count) == 0) {
1495+
queue_work(sc->workqueue, &sc->recv_io.posted.refill_work);
1496+
ret = wait_event_interruptible(sc->send_io.credits.wait_queue,
1497+
atomic_read(&sc->send_io.credits.count) >= 1 ||
1498+
atomic_read(&sc->recv_io.credits.available) >= 1 ||
1499+
sc->status != SMBDIRECT_SOCKET_CONNECTED);
1500+
if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
1501+
ret = -ENOTCONN;
1502+
if (ret < 0)
1503+
goto credit_failed;
1504+
1505+
new_credits = manage_credits_prior_sending(sc);
1506+
}
1507+
14801508
data_length = 0;
14811509
for (i = 0; i < niov; i++)
14821510
data_length += iov[i].iov_len;
14831511

14841512
ret = smb_direct_create_header(sc, data_length, remaining_data_length,
1485-
&msg);
1513+
new_credits, &msg);
14861514
if (ret)
14871515
goto header_failed;
14881516

0 commit comments

Comments
 (0)