From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.69 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920423; b=QpYl6dD3gcfR+C6lovrHvFIEa9Bb/TFncaSIxCD60qFS79Aw+sgv+K+5eCymuIxcTUf0 YCPQjQjAiiERMIy3qunOCEyD+Fhx/POtjXX850vn0G+02GzE+koFFKLB2ST6gVr9O5V4S 1QIyfYbKReK3e0b+twvWXwPKUMYdqqojZswl13Oe0khTpFkV7lfHFZ/HHLUVD3og1hScI GwD4BSgJXz6B3Yk0qLTX9FDa12KOUleNjW51n8MsFefItYPJryK9MaXtMbcEoV84YNR4h KrSfB/0NyWm0Z8vz6XihFCIeLRegj9rKMjuIHFrtDHdzV3Pn2CC0VFVAo6NsQoQwhDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920423; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=GUshJKOWpO1iEeD494r9s1iokZQ/sBDLo85MqRjtqNE=; b=E8wxeEoapegFDrA6J2hBJFXm5csvawwegk1u2wjMcneBWy1cd1c4o4ALgRX66I5AQFWu GF1inGdqztNerhIPBUuOjCIx3E6czA3rPCIhgTaM2IPI6CvbOBtBOrjIpYzCxXNcfSNWQ SOOik6GnDuYD27bY3JrDlSV6RpJEbwG1znW530x0NHVsr7lxV7zAhRONw/tFDEeJPYfg1 H8BYuMyKD7gf/NV13phu97Korpe1mj2IB608/szvjpDEku7RM99gvXEfyQEuMImQp9QU+ wxTd3CR7zDoUL42OJYELeYuMtwqMjJM9V1bBY7pjTwly3UaRv/cdAux3mFGc/IywH3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=HyWW5nTu; arc=none smtp.remote-ip=209.85.216.69 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77BBE606A324 for ; Sun, 29 Nov 2026 02:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 77BBE606A324 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--zhenwenliang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=HyWW5nTu Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-3b191f8a9b3so10683046a91.1 for ; Sat, 28 Nov 2026 18:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1795920422; x=1796525222; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=GUshJKOWpO1iEeD494r9s1iokZQ/sBDLo85MqRjtqNE=; b=HyWW5nTukwTVwvuE9OllarfxPScUm+svdNPhyC/1fEx/2kwr35MiXoknvrPlJZkGow KETnkjO6X4xoYnZJsxJzeXa1zM0yWEaR17JmqGPg95VUU3T1nAXkSPSBuKgLk20wG24V Kik72THCJA29TsPg6pKLpxUJYJWEpZjxqRkn+9eUSjnriCREr75wh9WgNhCqOntor5cv Z+kdG5/TG/x7MWPM79+Qam5y0NSYYWP0O9A8i5bWIVIgXPCXCbUwW/W+uGMsHr1pjqWZ 0CN+nzN62yxUHT5zV6xSQDEZCpQ+wpqnLF0RhDPBENUD8XTEGrDrqXRYCONyCKH1w6lE m2pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795920422; x=1796525222; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GUshJKOWpO1iEeD494r9s1iokZQ/sBDLo85MqRjtqNE=; b=Vrb+tovyZu/K7gos+XxwTFBFUm2GDg+ETH7IkE7vTQG6mPxMdnmUZN3aIfHQ9QsrJM TmCCv3+mOz2aNMngiRFSJ7iyatfnlwl5vczwWklvbVm6U/Cxrl4re6tMe/eImAF/qr0B /iXns6t5zFN3rHhd7FzAEW/EsOU3gHsQImRU9ot8GjES45gVQnGuRqUoA6OWnyY+Ajn4 2x9eLzXXc9Ls+YPoCbSZprr4NbjSqgqPrnLlwBAkwOpZL/hURo+RsOW6HI3pwpIDApov iTGXgFEMvrbLUww+OLwOkX9k08csl1aVO9O5OCIxspqhdaKMmO8Slx4UUPNfh+iFqOIb bowA== X-Forwarded-Encrypted: i=1; AL+hErGbLTavbtqahq0nC1UzJ86k/iw0v21qCvDukpF2jvwDTQWLAFNWkJVUAGjnZoObMPVTNcybf0nxfm8/@vger.kernel.org X-Gm-Message-State: APuU4Z+cqFa12ofTlYS3gvmktFslj3cNSBbL+ba0/fVET7bmr4+y9ZN6 4UwFBlRGxAOTQGzjGij2PGMb/mBwFT6kbCp6BFRq05wWHt6fzlarmvybiRK3IycxnvdrUc/hcuo anIrXm7QjN7EXmM5x4PJFjNSNoRW0sg== X-Received: from pjo6.prod.google.com ([2002:a17:90b:5666:b0:3b3:e838:829d]) (user=zhenwenliang job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:5543:b0:3b0:a1af:e4fa with SMTP id 98e67ed59e1d1-3b41c9e4290mr30147594a91.24.1795920421657; Sat, 28 Nov 2026 18:47:01 -0800 (PST) Date: Sun, 29 Nov 2026 02:47:01 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.839.g22a8290db9-goog Message-ID: <20261129024701.277838-1-zhenwenliang@google.com> Subject: [PATCH net] net/rds: use wq_has_sleeper() in rds_ib_ring_free() From: Zhenwen Liang To: Allison Henderson Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , Simon Horman , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com Content-Type: text/plain; charset="UTF-8" rds_ib_ring_free() returns slots to a work ring with atomic_add() and then checks waitqueue_active() on rds_ib_ring_empty_wait to decide whether anyone needs waking. atomic_add() carries no ordering and waitqueue_active() is a plain load, so nothing orders the counter update before the wait queue read. The waiter does the mirror image: rds_ib_conn_path_shutdown() adds itself to rds_ib_ring_empty_wait in wait_event_timeout(), which sets the task state with a full barrier, and then checks, among other conditions, whether the receive ring is empty. That is the store-buffering pattern described above waitqueue_active() in include/linux/wait.h: the waker can observe an empty wait queue while the waiter still observes the ring as not empty, and no wakeup is issued, so connection shutdown in rds_ib_conn_path_shutdown() stalls: on kernels with commit 16f48efaeb69 ("net/rds: Don't sleep inside rds_ib_conn_path_shutdown") or its stable backports, the waiter wakes after at most about 1 s; on kernels without it, it waits until the next wakeup. Use wq_has_sleeper(), which is waitqueue_active() preceded by the required full barrier, as was done for the same pattern in commit d4f484661961 ("net/rds: use wq_has_sleeper() in rds_cong_map_updated()") and commit 6d0c8b707391 ("net/rds: use wq_has_sleeper() in release_in_xmit()"); commit 17c4476dbb9c ("net/rds: use clear_bit_unlock() in release_refill()") also switched to wq_has_sleeper(). The outcome is allowed by the Linux kernel memory model for a litmus test derived from the code, and by the AArch64 and PPC models for a litmus test of the same pattern. With smp_mb() added before the wait queue check, where wq_has_sleeper() places it, herd7 forbids it (LKMM, AArch64 and PPC models). 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 with clang on arm64 and x86-64 with W=1, and checked that the barrier is emitted between the atomic_add() and the wait queue load in arm64 object code; not runtime-tested. Fixes: f528efe276ec ("RDS/IB: Ring-handling code.") Signed-off-by: Zhenwen Liang --- net/rds/ib_ring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/rds/ib_ring.c b/net/rds/ib_ring.c index 006b2e441418..4bbd3426b724 100644 --- a/net/rds/ib_ring.c +++ b/net/rds/ib_ring.c @@ -120,7 +120,7 @@ void rds_ib_ring_free(struct rds_ib_work_ring *ring, u32 val) atomic_add(val, &ring->w_free_ctr); if (__rds_ib_ring_empty(ring) && - waitqueue_active(&rds_ib_ring_empty_wait)) + wq_has_sleeper(&rds_ib_ring_empty_wait)) wake_up(&rds_ib_ring_empty_wait); } -- 2.56.1.839.g22a8290db9-goog