* [PATCH net] net/rds: use wq_has_sleeper() in rds_ib_ring_free()
@ 2026-11-29 2:47 Zhenwen Liang
2026-11-30 7:25 ` Allison Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Zhenwen Liang @ 2026-11-29 2:47 UTC (permalink / raw)
To: Allison Henderson
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, netdev, linux-rdma, rds-devel
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 <zhenwenliang@google.com>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net/rds: use wq_has_sleeper() in rds_ib_ring_free()
2026-11-29 2:47 [PATCH net] net/rds: use wq_has_sleeper() in rds_ib_ring_free() Zhenwen Liang
@ 2026-11-30 7:25 ` Allison Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Allison Henderson @ 2026-11-30 7:25 UTC (permalink / raw)
To: Zhenwen Liang
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, netdev, linux-rdma, rds-devel
On Sun, 2026-11-29 at 02:47 +0000, Zhenwen Liang wrote:
> 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 <zhenwenliang@google.com>
Thanks Zhenwen, this looks right to me.
Reviewed-by: Allison Henderson <achender@kernel.org>
Also, this patch did have a sashiko review, though I didnt see that it
got mailed out. Mostly it identified a similar issue in
rds_transition_frwr_state(), so a similar fix could apply there too but I
didnt see that it should hold up this patch. If you do decide to address it,
please send a separate patch,
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129024701.277838-1-zhenwenliang%40google.com
Thanks!
Allison
> ---
> 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);
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 7:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 2:47 [PATCH net] net/rds: use wq_has_sleeper() in rds_ib_ring_free() Zhenwen Liang
2026-11-30 7:25 ` Allison Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox