All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Cygnus Qiu" <eritque-arcus@ikuyo.dev>
Cc: linux-rdma@vger.kernel.org, "Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>,
	"Anna Schumaker" <anna@kernel.org>
Subject: Re: [PATCH] RDMA/siw: don't complete a fenced READ twice on flush
Date: Wed, 25 Nov 2026 06:19:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-232671@kernel.org> (raw)
In-Reply-To: <20261125060646.155172-1-eritque-arcus@ikuyo.dev>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] RDMA/siw: data race on tx_ctx bitfields clobbers orq_fence in
  siw_sq_flush()
--

commit 2dacef6eebec78b6dccffd22a13876b9c48ca403
Author: Cygnus Qiu <eritque-arcus@ikuyo.dev>

RDMA/siw: don't complete a fenced READ twice on flush

This commit gates completing a SIW_WR_QUEUED READ from the TX slot in
siw_sq_flush() on qp->tx_ctx.orq_fence so a READ already copied into the
ORQ is not completed twice.

> diff --git a/drivers/infiniband/sw/siw/siw_qp.c b/drivers/infiniband/sw/siw/siw_qp.c
> index bb780e3904a21..2cc0f466e757f 100644
> --- a/drivers/infiniband/sw/siw/siw_qp.c
> +++ b/drivers/infiniband/sw/siw/siw_qp.c
> @@ -1188,10 +1188,11 @@ void siw_sq_flush(struct siw_qp *qp)
>  		if (tx_type(wqe) != SIW_OP_READ_RESPONSE &&
>  		    ((tx_type(wqe) != SIW_OP_READ &&
>  		      tx_type(wqe) != SIW_OP_READ_LOCAL_INV) ||
> -		     wqe->wr_status == SIW_WR_QUEUED))
> +		     (wqe->wr_status == SIW_WR_QUEUED &&
> +		      qp->tx_ctx.orq_fence)))
>  			/*
> -			 * An in-progress Read Request is already in
> -			 * the ORQ
> +			 * A Read Request is already in the ORQ unless
> +			 * a full ORQ fenced it
>  			 */
>  			siw_sqe_complete(qp, &wqe->sqe, wqe->bytes,
>  					 SIW_WC_WR_FLUSH_ERR);

[Severity: Medium]
Can a concurrent update to qp->tx_ctx.tx_suspend clobber
qp->tx_ctx.orq_fence and cause siw_sq_flush() to drop or duplicate the
flush completion?

In struct siw_iwarp_tx, orq_fence and tx_suspend are u8 bitfields packed
into the same byte:

drivers/infiniband/sw/siw/siw.h:struct siw_iwarp_tx {
    ...
	u8 do_crc : 1; /* do crc for segment */
	u8 use_sendpage : 1; /* send w/o copy */
	u8 tx_suspend : 1; /* stop sending DDP segs. */
	u8 pad : 2; /* # pad in current fpdu */
	u8 orq_fence : 1; /* ORQ full or Send fenced */
	u8 in_syscall : 1; /* TX out of user context */
	u8 zcopy_tx : 1; /* Use TCP_SENDPAGE if possible */
};

siw_activate_tx_from_sq() and siw_check_tx_fence() update orq_fence under
qp->orq_lock, whereas siw_cm_llp_state_change() sets tx_suspend = 1 on
inbound TCP_CLOSE or TCP_CLOSE_WAIT without holding qp->orq_lock,
qp->sq_lock or qp->state_lock:

CPU0                                  CPU1
siw_activate_tx_from_sq()             siw_cm_llp_state_change()
  spin_lock(&qp->orq_lock)              /* load shared bitfield byte
  ...                                      (orq_fence == 0) */
  qp->tx_ctx.orq_fence = 1;
  spin_unlock(&qp->orq_lock)
                                        cep->qp->tx_ctx.tx_suspend = 1;
                                          /* stores orq_fence = 0 */
                                      ...
                                      siw_sq_flush()
                                        /* orq_fence == 0: skips completing
                                           fenced READ in tx_wqe(qp) */

If the clobber loses orq_fence = 1, the fenced READ is never moved to the
ORQ and siw_sq_flush() now skips completing it from tx_wqe(qp), hanging
callers waiting on SQ drain.  Conversely, if tx_suspend = 1 races with
siw_check_tx_fence() clearing orq_fence = 0 after copying the READ to the
ORQ, restoring orq_fence = 1 causes siw_sq_flush() to complete the READ
from both the ORQ and tx_wqe(qp).

Making orq_fence (or the concurrently accessed flags in struct
siw_iwarp_tx) a separate u8 field would avoid the shared-byte read-modify-
write race.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125060646.155172-1-eritque-arcus@ikuyo.dev?part=1

  reply	other threads:[~2026-11-25  6:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25  6:06 [PATCH] RDMA/siw: don't complete a fenced READ twice on flush Cygnus Qiu
2026-11-25  6:19 ` sashiko-bot [this message]
2026-11-26 13:55 ` Leon Romanovsky

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=sashiko-outbox-232671@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=anna@kernel.org \
    --cc=cel@kernel.org \
    --cc=eritque-arcus@ikuyo.dev \
    --cc=jlayton@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.