From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.72 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920422; b=1UPZMz8zh0XANodCS54mHweMELe5OIde73AMbERNzaAgWHLuuMDuYsiv/X2e2UQvw4DD gneVuznkxG8HhodCl6UFtSaEEJLtKnZFHZX9giiP+GtJ38i9pkbDuO2GkFrFN5de4pPDJ TQ7s+DuMg+zpxyMcZKSIVK2NBJ8G5wt59FblHT2eQ4SKJbYX28nmchPre9x8CL51wav8y lb6YvR7wB+0JCu2VuzKLR9bn/6UsectRhE+1+yN2vRnJHLNC9Ae8O5tz/p/weofK0deae qpE9MZDvoX3bIkPB9GQsoHIVn02t2ortrQ/OlSNd9fKbdB7+GGCnSW5f6ykaOKW0f8Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920422; 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=f6uRRk8VqhJrnXoF8Qu4fYRUtpG8J567en8h4gcX7aB70u4lUC4MCH6QDrPwggBuJpTO o7Z8VM12k3SZBF75lKdyka8RKcFCse6GPV/aH1/cGIRc6np/XusC4kOqRz/EIs00ODCHW gZazEZ8bA9AHXgGrcWn4n0GRWDUdZgngtIVbiazuOxhxyT4iISPFKmtFn0fEaM31eDDT/ +WgQ4KPNc0VMWNk3IEBNNunc6X7ks/1ESFcs3keZpM5VwRSK4hYEhJTP7OjdYp+zALhTT U+lr7h9wsS52Ddtm3+eluR8096xB2jOZMmTPvGTbyUmVDBVTz9cNi+MylH5d6Gs53XA== 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.72 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (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 763B5606A323 for ; Sun, 29 Nov 2026 02:47:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 763B5606A323 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-f72.google.com with SMTP id 98e67ed59e1d1-3b45655b428so8490151a91.0 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=ApWrbsV/FFvIfbTDNCTorzwosRCp1dcukcIKLc6o6lJYOhm3+jQSadneHK6IibFzZH +m3hSU0ODd8A56HnYvENdMcT/L+1sGErcIzij0Iw+yLdGq5rnr9l/IcplrCaE0AscxmF ywCIAmI6tqQciYwj4sT/gcGaQ9FJzEWGa1alNi4NGHv+7OzuqylZS57QK7zmQ+BfqHrD cwnjlmwulVEjJLWPs5D9AyPSMhYLVLl9GUtT50Ca2oenM9Vpq6psqZKrJnRSkYMG8z5g 1lRPzqwkfLLuuUrRtfzOqaxsuDKThMwAfoR9Q83lW1L7ntHd9Wc4S2uJdByVTXt268oD 5c5A== X-Forwarded-Encrypted: i=1; AL+hErEXtn57eFpbdfCbtE8w6L5247gDIrJtAHXvJ2so/W6chPuRakKNps0hPDgbSpm6pbqAo8W8ot8=@vger.kernel.org X-Gm-Message-State: APuU4Z+2iFaRJVyJ8ELkAwenqsuE7xrDi2HFmShXYGbdUVKW2PSRST66 UQoiaa7wkFwjlAIsg+9v4rQV3tHHB/QUZoB6mQAyTcO4SiRM6Ggm+g06kWKYA+pDq71LrZA3K4H A6+hnGXERURJ7G8NKhV/KiV85BmQzXA== 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: netdev@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