From: Zhu Yanjun <yanjun.zhu@linux.dev>
To: linke li <lilinke99@qq.com>
Cc: Bernard Metzler <bmt@zurich.ibm.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/siw: Reuse value read using READ_ONCE instead of re-reading it
Date: Sun, 10 Mar 2024 05:53:26 +0100 [thread overview]
Message-ID: <2d508574-c2b8-489b-a26d-71b1c36961cf@linux.dev> (raw)
In-Reply-To: <tencent_32C3AEB0599DF0A0010A862439636CDA2707@qq.com>
在 2024/3/9 13:27, linke li 写道:
> In siw_orqe_start_rx, the orqe's flag in the if condition is read using
> READ_ONCE, checked, and then re-read, voiding all guarantees of the
> checks. Reuse the value that was read by READ_ONCE to ensure the
> consistency of the flags throughout the function.
>
> Signed-off-by: linke li <lilinke99@qq.com>
> ---
> drivers/infiniband/sw/siw/siw_qp_rx.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/infiniband/sw/siw/siw_qp_rx.c b/drivers/infiniband/sw/siw/siw_qp_rx.c
> index ed4fc39718b4..f5f69de56882 100644
> --- a/drivers/infiniband/sw/siw/siw_qp_rx.c
> +++ b/drivers/infiniband/sw/siw/siw_qp_rx.c
> @@ -740,6 +740,7 @@ static int siw_orqe_start_rx(struct siw_qp *qp)
> {
> struct siw_sqe *orqe;
> struct siw_wqe *wqe = NULL;
> + u16 orqe_flags;
>
> if (unlikely(!qp->attrs.orq_size))
> return -EPROTO;
> @@ -748,7 +749,8 @@ static int siw_orqe_start_rx(struct siw_qp *qp)
> smp_mb();
>
> orqe = orq_get_current(qp);
> - if (READ_ONCE(orqe->flags) & SIW_WQE_VALID) {
In this if test, READ_ONCE is needed to read orqe->flags. But in this
commit, this READ_ONCE is moved to other places.
In a complicated environment, for example, this function is called many
times at the same time and orqe->flags is changed at the same time, I am
not sure if this will introduce risks or not.
if you need to ensure the consistency of the flags throughout the
function, not sure if the following is better or not.
if (((orqe_flags=READ_ONCE(orqe->flags))) & SIW_WQE_VALID) {
Thanks,
Zhu Yanjun
> + orqe_flags = READ_ONCE(orqe->flags);
> + if (orqe_flags & SIW_WQE_VALID) {
> /* RRESP is a TAGGED RDMAP operation */
> wqe = rx_wqe(&qp->rx_tagged);
> wqe->sqe.id = orqe->id;
> @@ -756,7 +758,7 @@ static int siw_orqe_start_rx(struct siw_qp *qp)
> wqe->sqe.sge[0].laddr = orqe->sge[0].laddr;
> wqe->sqe.sge[0].lkey = orqe->sge[0].lkey;
> wqe->sqe.sge[0].length = orqe->sge[0].length;
> - wqe->sqe.flags = orqe->flags;
> + wqe->sqe.flags = orqe_flags;
> wqe->sqe.num_sge = 1;
> wqe->bytes = orqe->sge[0].length;
> wqe->processed = 0;
next prev parent reply other threads:[~2024-03-10 4:53 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-09 12:27 [PATCH] RDMA/siw: Reuse value read using READ_ONCE instead of re-reading it linke li
2024-03-10 4:53 ` Zhu Yanjun [this message]
2024-03-10 12:36 ` linke li
2024-03-10 17:00 ` Greg Sword
2024-03-11 2:57 ` linke li
2024-03-11 8:17 ` Zhu Yanjun
2024-03-10 11:33 ` Leon Romanovsky
2024-03-10 12:15 ` linke li
2024-03-10 19:19 ` Leon Romanovsky
2024-03-11 2:34 ` linke li
2024-03-11 5:11 ` Zhu Yanjun
2024-03-10 17:02 ` Greg Sword
2024-03-11 14:14 ` Bernard Metzler
2024-03-12 1:30 ` linke li
2024-03-12 7:57 ` 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=2d508574-c2b8-489b-a26d-71b1c36961cf@linux.dev \
--to=yanjun.zhu@linux.dev \
--cc=bmt@zurich.ibm.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=lilinke99@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
/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