Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: zhenwenliang@google.com
Cc: achender@kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, willemb@google.com,
	horms@kernel.org, netdev@vger.kernel.org,
	linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com
Subject: Re: [PATCH net] net/rds: use wq_has_sleeper() in rds_transition_frwr_state()
Date: Tue, 01 Dec 2026 16:47:34 +0000	[thread overview]
Message-ID: <179614365498.3146.898864177949613339@kernel.org> (raw)
In-Reply-To: <20261130164729.981519-1-zhenwenliang@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 2 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch fixes only one of the two unordered wakers of
  rds_ib_ring_empty_wait.
- [High] The wakeup that the patch makes reliable fires before the
  shutdown wait condition can be true, and nothing wakes the waiter once…

--

net/rds: use wq_has_sleeper() in rds_transition_frwr_state()

This patch replaces waitqueue_active() with wq_has_sleeper() in
rds_transition_frwr_state(). The full barrier then orders the
i_fastreg_inuse_count decrement before the wait queue check. The aim is to
stop rds_ib_conn_path_shutdown() from missing the wakeup and sleeping until
its 1 s timeout on weakly ordered architectures.

> diff --git a/net/rds/ib_frmr.c b/net/rds/ib_frmr.c
> index 8397aa4a17ac8..9a9424a499a37 100644
> --- a/net/rds/ib_frmr.c
> +++ b/net/rds/ib_frmr.c
> @@ -45,7 +45,7 @@ rds_transition_frwr_state(struct rds_ib_mr *ibmr,
>  		 */
>  		smp_mb__before_atomic();
>  		atomic_dec(&ibmr->ic->i_fastreg_inuse_count);
> -		if (waitqueue_active(&rds_ib_ring_empty_wait))
> +		if (wq_has_sleeper(&rds_ib_ring_empty_wait))
>  			wake_up(&rds_ib_ring_empty_wait);

[Severity: High]
Is there a second waker of rds_ib_ring_empty_wait with the same missing
barrier? rds_ib_ring_free() in net/rds/ib_ring.c does a void atomic RMW
and then calls waitqueue_active() with no barrier in between:

net/rds/ib_ring.c:rds_ib_ring_free() {
	ring->w_free_ptr = (ring->w_free_ptr + val) % ring->w_nr;
	atomic_add(val, &ring->w_free_ctr);

	if (__rds_ib_ring_empty(ring) &&
	    waitqueue_active(&rds_ib_ring_empty_wait))
		wake_up(&rds_ib_ring_empty_wait);
}

It wakes the same waiter, because rds_ib_conn_path_shutdown_check_wait()
requires rds_ib_ring_empty(&ic->i_recv_ring).

During shutdown, flushed receive WRs go through
rds_ib_recv_cqe_handler()->rds_ib_ring_free(). If that is the last event
that satisfies the wait condition, the store buffering problem described
in the commit message applies here too.

The similar fix mentioned in the commit message (commit 6d0c8b707391)
changed release_in_xmit() in net/rds/send.c. It did not touch ib_ring.c.

rds_ib_sub_signaled() uses atomic_sub_return(), which is fully ordered. That
makes rds_ib_ring_free() the only unordered waker left on this wait queue.

Should rds_ib_ring_free() also be converted to wq_has_sleeper() in this
patch?

[Severity: High]
Can this wakeup fire before the shutdown condition is able to become true?

rds_ib_conn_path_shutdown_check_wait() needs both counters to have settled:

	(atomic_read(&ic->i_fastreg_inuse_count)) == 0 &&
	(atomic_read(&ic->i_fastreg_wrs) == RDS_IB_DEFAULT_FR_WR)

Every FRWR post first takes an i_fastreg_wrs slot with atomic_dec_return().
While the last WR is in flight, i_fastreg_wrs is therefore one below
RDS_IB_DEFAULT_FR_WR.

On completion, rds_ib_mr_cqe_handler() wakes the waiter through
rds_transition_frwr_state(). It only gives the slot back at the end:

net/rds/ib_frmr.c:rds_ib_mr_cqe_handler() {
	...
	if (frmr->fr_inv) {
		rds_transition_frwr_state(ibmr, FRMR_IS_INUSE, FRMR_IS_FREE);
		frmr->fr_inv = false;
		wake_up(&frmr->fr_inv_done);
	}
	...
	smp_mb__before_atomic();
	atomic_inc(&ic->i_fastreg_wrs);
}

Suppose the shutdown thread re-checks between the wake and the
atomic_inc(). It sees inuse_count == 0 with i_fastreg_wrs still one short,
and goes back to sleep.

Nothing wakes rds_ib_ring_empty_wait after the increment, and poll_scq()
does not add a wakeup either. The waiter would then sleep until the
1000 ms timeout, on any architecture.

The error paths do things in the same order, with wider windows. In
rds_ib_post_reg_frmr(), the wake happens when ib_post_send() fails. Then
printk_ratelimit()/pr_warn() runs, and i_fastreg_wrs is only restored at
out_inc:

	rds_transition_frwr_state(ibmr, FRMR_IS_INUSE, FRMR_IS_STALE);

	if (printk_ratelimit())
		pr_warn("RDS/IB: %s returned error(%d)\n",
			__func__, ret);
	goto out_inc;
	...
out_inc:
	atomic_inc(&ibmr->ic->i_fastreg_wrs);

Two other paths have the same order:

  - the ib_post_send() error path in rds_ib_post_inv()
  - the wc->status != IB_WC_SUCCESS branch of rds_ib_mr_cqe_handler(),
    which flushed WRs take during disconnect

Would it work better to do the wq_has_sleeper()/wake_up() after each
atomic_inc(&i_fastreg_wrs), instead of only adding a barrier at this wake
site?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130164729.981519-1-zhenwenliang%40google.com

      parent reply	other threads:[~2026-12-01 16:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 16:47 [PATCH net] net/rds: use wq_has_sleeper() in rds_transition_frwr_state() Zhenwen Liang
2026-11-30 17:04 ` sashiko-bot
2026-12-01 16:47 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179614365498.3146.898864177949613339@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=achender@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rds-devel@oss.oracle.com \
    --cc=willemb@google.com \
    --cc=zhenwenliang@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox