From: Gui-Dong Han <hanguidong02@gmail.com>
To: krzysztof.czurylo@intel.com, tatyana.e.nikolova@intel.com,
linux-rdma@vger.kernel.org
Cc: jgg@ziepe.ca, leon@kernel.org, mustafa.ismail@intel.com,
shiraz.saleem@intel.com, linux-kernel@vger.kernel.org,
baijiaju1990@gmail.com, Gui-Dong Han <hanguidong02@gmail.com>
Subject: [PATCH] RDMA/irdma: Use acquire/release for CQP request completion
Date: Thu, 4 Jun 2026 16:34:40 +0800 [thread overview]
Message-ID: <20260604083440.426033-1-hanguidong02@gmail.com> (raw)
The completion path fills cqp_request->compl_info before marking
request_done and waking waiters. irdma_wait_event() waits for
request_done before reading compl_info.
READ_ONCE()/WRITE_ONCE() do not order these accesses, so a waiter can
observe request_done while still seeing stale completion information.
Use release/acquire helpers for request_done to publish compl_info to the
waiting thread.
Clearing request_done does not publish completion information. It only
reinitializes a private request before returning it to cqp_avail_reqs under
req_lock, so WRITE_ONCE() is enough for the false transition.
Fixes: 44d9e52977a1 ("RDMA/irdma: Implement device initialization definitions")
Fixes: 915cc7ac0f8e ("RDMA/irdma: Add miscellaneous utility definitions")
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
---
Found by auditing READ_ONCE() used for synchronization.
A similar fix can be found in 8df672bfe3ec.
---
drivers/infiniband/hw/irdma/hw.c | 2 +-
drivers/infiniband/hw/irdma/main.h | 22 +++++++++++++++++++++-
drivers/infiniband/hw/irdma/utils.c | 6 +++---
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/hw/irdma/hw.c b/drivers/infiniband/hw/irdma/hw.c
index f9be467d137f..96fecb28af97 100644
--- a/drivers/infiniband/hw/irdma/hw.c
+++ b/drivers/infiniband/hw/irdma/hw.c
@@ -235,7 +235,7 @@ static void irdma_complete_cqp_request(struct irdma_cqp *cqp,
struct irdma_cqp_request *cqp_request)
{
if (cqp_request->waiting) {
- WRITE_ONCE(cqp_request->request_done, true);
+ irdma_cqp_request_mark_done(cqp_request);
wake_up(&cqp_request->waitq);
} else if (cqp_request->callback_fcn) {
cqp_request->callback_fcn(cqp_request);
diff --git a/drivers/infiniband/hw/irdma/main.h b/drivers/infiniband/hw/irdma/main.h
index 3d49bd57bae7..57102278ed64 100644
--- a/drivers/infiniband/hw/irdma/main.h
+++ b/drivers/infiniband/hw/irdma/main.h
@@ -167,12 +167,32 @@ struct irdma_cqp_request {
void (*callback_fcn)(struct irdma_cqp_request *cqp_request);
void *param;
struct irdma_cqp_compl_info compl_info;
- bool request_done; /* READ/WRITE_ONCE macros operate on it */
+ bool request_done; /* Use irdma_cqp_request_*() helpers. */
bool waiting:1;
bool dynamic:1;
bool pending:1;
};
+static inline void
+irdma_cqp_request_clear_done(struct irdma_cqp_request *cqp_request)
+{
+ WRITE_ONCE(cqp_request->request_done, false);
+}
+
+static inline void
+irdma_cqp_request_mark_done(struct irdma_cqp_request *cqp_request)
+{
+ /* Publish compl_info before waking the waiter. */
+ smp_store_release(&cqp_request->request_done, true);
+}
+
+static inline bool
+irdma_cqp_request_is_done(struct irdma_cqp_request *cqp_request)
+{
+ /* Pair with irdma_cqp_request_mark_done(). */
+ return smp_load_acquire(&cqp_request->request_done);
+}
+
struct irdma_cqp {
struct irdma_sc_cqp sc_cqp;
spinlock_t req_lock; /* protect CQP request list */
diff --git a/drivers/infiniband/hw/irdma/utils.c b/drivers/infiniband/hw/irdma/utils.c
index 495e5daff4b4..566f690a4e58 100644
--- a/drivers/infiniband/hw/irdma/utils.c
+++ b/drivers/infiniband/hw/irdma/utils.c
@@ -480,7 +480,7 @@ void irdma_free_cqp_request(struct irdma_cqp *cqp,
if (cqp_request->dynamic) {
kfree(cqp_request);
} else {
- WRITE_ONCE(cqp_request->request_done, false);
+ irdma_cqp_request_clear_done(cqp_request);
cqp_request->callback_fcn = NULL;
cqp_request->waiting = false;
cqp_request->pending = false;
@@ -515,7 +515,7 @@ irdma_free_pending_cqp_request(struct irdma_cqp *cqp,
{
if (cqp_request->waiting) {
cqp_request->compl_info.error = true;
- WRITE_ONCE(cqp_request->request_done, true);
+ irdma_cqp_request_mark_done(cqp_request);
wake_up(&cqp_request->waitq);
}
wait_event_timeout(cqp->remove_wq,
@@ -610,7 +610,7 @@ static int irdma_wait_event(struct irdma_pci_f *rf,
do {
irdma_cqp_ce_handler(rf, &rf->ccq.sc_cq);
if (wait_event_timeout(cqp_request->waitq,
- READ_ONCE(cqp_request->request_done),
+ irdma_cqp_request_is_done(cqp_request),
msecs_to_jiffies(CQP_COMPL_WAIT_TIME_MS)))
break;
--
2.34.1
next reply other threads:[~2026-06-04 8:34 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 8:34 Gui-Dong Han [this message]
2026-06-04 13:41 ` Jacob Moroni
2026-06-04 13:55 ` Jason Gunthorpe
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=20260604083440.426033-1-hanguidong02@gmail.com \
--to=hanguidong02@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=jgg@ziepe.ca \
--cc=krzysztof.czurylo@intel.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mustafa.ismail@intel.com \
--cc=shiraz.saleem@intel.com \
--cc=tatyana.e.nikolova@intel.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
all inboxes | Powered by JetHome®