From: Gui-Dong Han <hanguidong02@gmail•com>
To: sven@kernel•org, kbusch@kernel•org, linux-nvme@lists•infradead.org
Cc: axboe@kernel•dk, hch@lst•de, sagi@grimberg•me, j@jannau•net,
neal@gompa•dev, asahi@lists•linux.dev,
linux-kernel@vger•kernel.org,
linux-arm-kernel@lists•infradead.org, baijiaju1990@gmail•com,
Gui-Dong Han <hanguidong02@gmail•com>
Subject: [PATCH] nvme-apple: Use acquire/release for queue enabled state
Date: Wed, 3 Jun 2026 15:22:05 +0800 [thread overview]
Message-ID: <20260603072205.3291888-1-hanguidong02@gmail.com> (raw)
apple_nvme_init_queue() initializes queue state and then marks the queue
enabled. The interrupt and request paths check enabled before using that
queue state.
The existing wmb() after WRITE_ONCE(enabled, true) orders the enabled
store before later queue use, but it does not publish the earlier
initialization before enabled becomes visible.
Use a release store when enabling the queue and acquire loads when
testing it. Keep the existing wmb() in place for the
store-before-later-use ordering.
Fixes: 5bd2927aceba ("nvme-apple: Add initial Apple SoC NVMe driver")
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/nvme/host/apple.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c
index c692fc73babf..fcaf8f230b19 100644
--- a/drivers/nvme/host/apple.c
+++ b/drivers/nvme/host/apple.c
@@ -151,6 +151,18 @@ struct apple_nvme_queue {
bool enabled;
};
+static inline bool apple_nvme_queue_enabled(struct apple_nvme_queue *q)
+{
+ /* Pair with apple_nvme_enable_queue(). */
+ return smp_load_acquire(&q->enabled);
+}
+
+static inline void apple_nvme_enable_queue(struct apple_nvme_queue *q)
+{
+ /* Publish queue initialization before setting q->enabled. */
+ smp_store_release(&q->enabled, true);
+}
+
/*
* The apple_nvme_iod describes the data in an I/O.
*
@@ -677,7 +689,7 @@ static bool apple_nvme_handle_cq(struct apple_nvme_queue *q, bool force)
bool found;
DEFINE_IO_COMP_BATCH(iob);
- if (!READ_ONCE(q->enabled) && !force)
+ if (!apple_nvme_queue_enabled(q) && !force)
return false;
found = apple_nvme_poll_cq(q, &iob);
@@ -780,7 +792,7 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
* We should not need to do this, but we're still using this to
* ensure we can drain requests on a dying queue.
*/
- if (unlikely(!READ_ONCE(q->enabled)))
+ if (unlikely(!apple_nvme_queue_enabled(q)))
return BLK_STS_IOERR;
if (!nvme_check_ready(&anv->ctrl, req, true))
@@ -1016,7 +1028,7 @@ static void apple_nvme_init_queue(struct apple_nvme_queue *q)
memset(q->tcbs, 0, anv->hw->max_queue_depth
* sizeof(struct apple_nvmmu_tcb));
memset(q->cqes, 0, depth * sizeof(struct nvme_completion));
- WRITE_ONCE(q->enabled, true);
+ apple_nvme_enable_queue(q);
wmb(); /* ensure the first interrupt sees the initialization */
}
--
2.34.1
next reply other threads:[~2026-06-03 7:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 7:22 Gui-Dong Han [this message]
2026-06-03 9:54 ` [PATCH] nvme-apple: Use acquire/release for queue enabled state Keith Busch
2026-06-03 11:45 ` Gui-Dong Han
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=20260603072205.3291888-1-hanguidong02@gmail.com \
--to=hanguidong02@gmail$(echo .)com \
--cc=asahi@lists$(echo .)linux.dev \
--cc=axboe@kernel$(echo .)dk \
--cc=baijiaju1990@gmail$(echo .)com \
--cc=hch@lst$(echo .)de \
--cc=j@jannau$(echo .)net \
--cc=kbusch@kernel$(echo .)org \
--cc=linux-arm-kernel@lists$(echo .)infradead.org \
--cc=linux-kernel@vger$(echo .)kernel.org \
--cc=linux-nvme@lists$(echo .)infradead.org \
--cc=neal@gompa$(echo .)dev \
--cc=sagi@grimberg$(echo .)me \
--cc=sven@kernel$(echo .)org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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