From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Steve French <smfrench@gmail.com>,
Tom Talpey <tom@talpey.com>, Long Li <longli@microsoft.com>,
Namjae Jeon <linkinjeon@kernel.org>,
linux-cifs@vger.kernel.org, samba-technical@lists.samba.org,
Stefan Metzmacher <metze@samba.org>,
Steve French <stfrench@microsoft.com>
Subject: [PATCH 6.18 14/49] smb: client: make use of smbdirect_socket.recv_io.credits.available
Date: Fri, 13 Feb 2026 14:47:58 +0100 [thread overview]
Message-ID: <20260213134709.409827711@linuxfoundation.org> (raw)
In-Reply-To: <20260213134708.885500854@linuxfoundation.org>
6.18-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefan Metzmacher <metze@samba.org>
commit 9911b1ed187a770a43950bf51f340ad4b7beecba upstream.
The logic off managing recv credits by counting posted recv_io and
granted credits is racy.
That's because the peer might already consumed a credit,
but between receiving the incoming recv at the hardware
and processing the completion in the 'recv_done' functions
we likely have a window where we grant credits, which
don't really exist.
So we better have a decicated counter for the
available credits, which will be incremented
when we posted new recv buffers and drained when
we grant the credits to the peer.
Fixes: 5fb9b459b368 ("smb: client: count the number of posted recv_io messages in order to calculated credits")
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/smb/client/smbdirect.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -618,6 +618,7 @@ static void smbd_post_send_credits(struc
struct smbdirect_recv_io *response;
struct smbdirect_socket *sc =
container_of(work, struct smbdirect_socket, recv_io.posted.refill_work);
+ int posted = 0;
if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
return;
@@ -640,9 +641,12 @@ static void smbd_post_send_credits(struc
}
atomic_inc(&sc->recv_io.posted.count);
+ posted += 1;
}
}
+ atomic_add(posted, &sc->recv_io.credits.available);
+
/* Promptly send an immediate packet as defined in [MS-SMBD] 3.1.1.1 */
if (atomic_read(&sc->recv_io.credits.count) <
sc->recv_io.credits.target - 1) {
@@ -1033,19 +1037,38 @@ dma_mapping_failed:
*/
static int manage_credits_prior_sending(struct smbdirect_socket *sc)
{
+ int missing;
+ int available;
int new_credits;
if (atomic_read(&sc->recv_io.credits.count) >= sc->recv_io.credits.target)
return 0;
- new_credits = atomic_read(&sc->recv_io.posted.count);
- if (new_credits == 0)
+ missing = (int)sc->recv_io.credits.target - atomic_read(&sc->recv_io.credits.count);
+ available = atomic_xchg(&sc->recv_io.credits.available, 0);
+ new_credits = (u16)min3(U16_MAX, missing, available);
+ if (new_credits <= 0) {
+ /*
+ * If credits are available, but not granted
+ * we need to re-add them again.
+ */
+ if (available)
+ atomic_add(available, &sc->recv_io.credits.available);
return 0;
+ }
- new_credits -= atomic_read(&sc->recv_io.credits.count);
- if (new_credits <= 0)
- return 0;
+ if (new_credits < available) {
+ /*
+ * Readd the remaining available again.
+ */
+ available -= new_credits;
+ atomic_add(available, &sc->recv_io.credits.available);
+ }
+ /*
+ * Remember we granted the credits
+ */
+ atomic_add(new_credits, &sc->recv_io.credits.count);
return new_credits;
}
@@ -1217,7 +1240,6 @@ wait_credit:
packet->credits_requested = cpu_to_le16(sp->send_credit_target);
new_credits = manage_credits_prior_sending(sc);
- atomic_add(new_credits, &sc->recv_io.credits.count);
packet->credits_granted = cpu_to_le16(new_credits);
packet->flags = 0;
next prev parent reply other threads:[~2026-02-13 13:52 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260213134708.885500854@linuxfoundation.org>
2026-02-13 13:47 ` [PATCH 6.18 07/49] smb: smbdirect: introduce smbdirect_socket.recv_io.credits.available Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 08/49] smb: smbdirect: introduce smbdirect_socket.send_io.bcredits.* Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 09/49] smb: server: make use of smbdirect_socket.recv_io.credits.available Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 10/49] smb: server: let recv_done() queue a refill when the peer is low on credits Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 11/49] smb: server: make use of smbdirect_socket.send_io.bcredits Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 12/49] smb: server: fix last send credit problem causing disconnects Greg Kroah-Hartman
2026-02-13 13:47 ` [PATCH 6.18 13/49] smb: server: let send_done handle a completion without IB_SEND_SIGNALED Greg Kroah-Hartman
2026-02-13 13:47 ` Greg Kroah-Hartman [this message]
2026-02-13 13:47 ` [PATCH 6.18 15/49] smb: client: let recv_done() queue a refill when the peer is low on credits Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 16/49] smb: client: let smbd_post_send() make use of request->wr Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 17/49] smb: client: remove pointless sc->recv_io.credits.count rollback Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 18/49] smb: client: remove pointless sc->send_io.pending handling in smbd_post_send_iter() Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 19/49] smb: client: port and use the wait_for_credits logic used by server Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 20/49] smb: client: split out smbd_ib_post_send() Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 21/49] smb: client: introduce and use smbd_{alloc, free}_send_io() Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 22/49] smb: client: use smbdirect_send_batch processing Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 23/49] smb: client: make use of smbdirect_socket.send_io.bcredits Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 24/49] smb: client: fix last send credit problem causing disconnects Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 25/49] smb: client: let smbd_post_send_negotiate_req() use smbd_post_send() Greg Kroah-Hartman
2026-02-13 13:48 ` [PATCH 6.18 26/49] smb: client: let send_done handle a completion without IB_SEND_SIGNALED Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260213134709.409827711@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=linkinjeon@kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=longli@microsoft.com \
--cc=metze@samba.org \
--cc=patches@lists.linux.dev \
--cc=samba-technical@lists.samba.org \
--cc=smfrench@gmail.com \
--cc=stable@vger.kernel.org \
--cc=stfrench@microsoft.com \
--cc=tom@talpey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox