ksmbd_conn_try_dequeue_request() decrements conn->req_running with atomic_dec() and then calls waitqueue_active() without holding the wait queue lock. atomic_dec() does not return a value and is unordered, so the load in waitqueue_active() can be satisfied before the decrement is visible to other CPUs. The waiter, ksmbd_conn_wait_idle(), adds itself to req_running_q, sets its task state (a full barrier) and then checks req_running. The waker can therefore see an empty wait queue while the waiter still sees the old value of req_running, and the wakeup is lost. Only requests that are not on the request list, such as SMB2_CANCEL, are affected: for them the function returns right after the conditional wake_up(). Requests on the list are woken again by the wake_up_all() at the end of the function, which takes the wait queue lock. When the wakeup is lost, the logoff waiter blocks until another request on the same connection completes or the connection is aborted; if the client is itself waiting for the logoff reply and sends nothing else, it stays blocked. Add smp_mb__after_atomic() between atomic_dec() and waitqueue_active(). The comment on waitqueue_active() in include/linux/wait.h requires a full barrier here, and the comment on wake_up_var() in kernel/sched/wait_bit.c names smp_mb__after_atomic() for a condition updated by atomic_dec(). It pairs with the barrier in set_current_state() in the waiter. On x86 it compiles to nothing, since atomic_dec() is already fully ordered there. A litmus test abstracted from a machine-checked witness execution showed the lost wakeup on arm64 in 145093 of 10^8 runs. The fix was checked with herd7 on a litmus test derived from the patched code (LKMM and AArch64 models: forbidden), and the outcome was not observed in 10^8 runs of the patched litmus test on the same machine. The problem was found, and this patch prepared, with the help of a formal analysis tool we are developing that uses AI assistance; I have reviewed the analysis and the patch. Compile-tested on arm64 (clang) and x86-64 (gcc) with W=1; not runtime-tested beyond litmus7 runs of litmus tests on arm64 hardware. Fixes: 43fb7bce8866 ("ksmbd: fix broken transfers when exceeding max simultaneous operations") Cc: stable@vger.kernel.org Signed-off-by: Zhenwen Liang --- fs/smb/server/connection.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/smb/server/connection.c b/fs/smb/server/connection.c index 0fcf90b877ae..e3bad5dbf533 100644 --- a/fs/smb/server/connection.c +++ b/fs/smb/server/connection.c @@ -373,6 +373,11 @@ void ksmbd_conn_try_dequeue_request(struct ksmbd_work *work) struct ksmbd_conn *conn = work->conn; atomic_dec(&conn->req_running); + /* + * Order the decrement before the lockless waitqueue_active() check. + * Pairs with the barrier in set_current_state() in the waiter. + */ + smp_mb__after_atomic(); if (waitqueue_active(&conn->req_running_q)) wake_up(&conn->req_running_q); -- 2.56.1.839.g22a8290db9-goog