smbdirect_connection_send_single_iter() moves the receive credits it grants in the message from sc->recv_io.credits.available to sc->recv_io.credits.count before the message is allocated, mapped and posted. If that fails, the peer never gets the message, but the credits stay accounted as granted, which permanently shrinks the receive credit window of the connection. Give them back to sc->recv_io.credits.available on the error paths. Fixes: 54abc694ebb8 ("smb: smbdirect: introduce smbdirect_connection_send_iter() and related functions") Cc: stable@vger.kernel.org Cc: Namjae Jeon Cc: Paulo Alcantara Cc: Tom Talpey Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Reported-by: Sashiko Closes: https://sashiko.dev/#/bug/linux-27f04b17-0356-40b9-94be-b0b865fde826 Reviewed-by: Paulo Alcantara Signed-off-by: Stefan Metzmacher --- fs/smb/smbdirect/connection.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/smb/smbdirect/connection.c b/fs/smb/smbdirect/connection.c index 475ec88c238b..40b45759ebb3 100644 --- a/fs/smb/smbdirect/connection.c +++ b/fs/smb/smbdirect/connection.c @@ -1370,6 +1370,13 @@ int smbdirect_connection_send_single_iter(struct smbdirect_socket *sc, smbdirect_connection_free_send_io(msg); flush_failed: alloc_failed: + /* + * The peer never got the credits we granted in this message. + */ + if (new_credits) { + atomic_sub(new_credits, &sc->recv_io.credits.count); + atomic_add(new_credits, &sc->recv_io.credits.available); + } atomic_inc(&sc->send_io.credits.count); wake_up(&sc->send_io.credits.wait_queue); credit_failed: -- 2.43.0