smbdirect_connect_negotiate_start() and smbdirect_accept_connect_request() create the memory pools and the QP, which may sleep, and then take a recv_io from the pool, with a WARN_ON_ONCE() if that fails. But a concurrent teardown can set first_error in the meantime, e.g. when the waiter of a connect times out or is interrupted or the listener is torn down, and then smbdirect_connection_get_recv_io() returns NULL although the pool was just filled: CPU0 CPU1 smbdirect_connect_negotiate_start() smbdirect_connection_create_mem_pools() schedule_cleanup(sc) first_error = ... smbdirect_connection_get_recv_io() returns NULL as first_error is set WARN_ON_ONCE(!recv_io) That's not a bug, so only warn if first_error is not set, and return first_error instead of -EINVAL. Fixes: d1f187656797 ("smb: smbdirect: introduce smbdirect_connect[_sync]()") Fixes: eb3ed1e9048c ("smb: smbdirect: introduce smbdirect_accept_connect_request()") 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-eb934b08-9b80-4e13-a535-6332a3d53abb Signed-off-by: Stefan Metzmacher --- fs/smb/smbdirect/accept.c | 11 +++++++++-- fs/smb/smbdirect/connect.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/fs/smb/smbdirect/accept.c b/fs/smb/smbdirect/accept.c index 6ba1f8d8e2e0..d9e2fea73e38 100644 --- a/fs/smb/smbdirect/accept.c +++ b/fs/smb/smbdirect/accept.c @@ -87,8 +87,15 @@ int smbdirect_accept_connect_request(struct smbdirect_socket *sc, } recv_io = smbdirect_connection_get_recv_io(sc); - if (WARN_ON_ONCE(!recv_io)) { - ret = -EINVAL; + if (!recv_io) { + /* + * The pool was just filled, so only a concurrent + * teardown, which sets first_error, makes + * smbdirect_connection_get_recv_io() fail here. + */ + ret = READ_ONCE(sc->first_error); + if (WARN_ON_ONCE(!ret)) + ret = -EINVAL; smbdirect_log_rdma_event(sc, SMBDIRECT_LOG_ERR, "smbdirect_connection_get_recv_io() failed %1pe\n", SMBDIRECT_DEBUG_ERR_PTR(ret)); diff --git a/fs/smb/smbdirect/connect.c b/fs/smb/smbdirect/connect.c index 6c5504c0b0fc..98ee25c0c334 100644 --- a/fs/smb/smbdirect/connect.c +++ b/fs/smb/smbdirect/connect.c @@ -430,8 +430,15 @@ static int smbdirect_connect_negotiate_start(struct smbdirect_socket *sc) atomic_set(&sc->send_io.lcredits.count, sp->send_credit_target); recv_io = smbdirect_connection_get_recv_io(sc); - if (WARN_ON_ONCE(!recv_io)) { - ret = -EINVAL; + if (!recv_io) { + /* + * The pool was just filled, so only a concurrent + * teardown, which sets first_error, makes + * smbdirect_connection_get_recv_io() fail here. + */ + ret = READ_ONCE(sc->first_error); + if (WARN_ON_ONCE(!ret)) + ret = -EINVAL; smbdirect_log_rdma_event(sc, SMBDIRECT_LOG_ERR, "smbdirect_connection_get_recv_io() failed %1pe\n", SMBDIRECT_DEBUG_ERR_PTR(ret)); -- 2.43.0