From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67C621D9663 for ; Thu, 18 Jun 2026 02:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781749009; cv=none; b=mYONyy4EFzcD83dfCd93HoLp1VMhFqQtsYyXUJD9ZRg6pfeNC9payd8SIaFWx7cbgoHg09RtU8VXlcDxK32gwZkcLVjh7nzkbq6OgS3vCm5L/qveEVKBaL59UsiHFtXkyQY0wxJTp11kjmYOxKYUv/Zaf59ETVBPxff50mWwy+c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781749009; c=relaxed/simple; bh=MsS0KDl7YWx1slEsJmktzRF9IWNN3CLmS1v1KYJV9MQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=A0N53Ra7JEL/D4N6ej84hbFTCvkLifAJO1tb8FFtGo+AIEOSQloev/bjc8M1YxSZ4xBkyvWHPGfhE5n/cmbJ2AXA9EGZAtebOrDfSM9yyHPkve44+w55GD5bVvGgwsy2XSsZ4+B98OwNCB/Mq9PNEIQBzzTM75XlgxY97ql9nIg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pseS7yMt; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pseS7yMt" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2c6be9cd89bso1828205ad.2 for ; Wed, 17 Jun 2026 19:16:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781749008; x=1782353808; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=G6bgdFP6eQHqUIHYA197THpQx8Z+j/fXy0gSUXkLpxo=; b=pseS7yMtuqU4WsVav8o4jvApzVmyJYxY6OVo3WGp5mXMYar0dJULwqFbXX/N3oACE2 iZAv1dN1USCiqZl1Kt4bgmJFdXsRm7QzW4DmI4k3YL1VeCsx+MjMOi0gx5JfPwaWgGw+ HS118q+3h7Ls2lUQW50WzNAkpFo5kR+kYZD6VoZV8+QpYBA8unOhu7yNzrYo4ycfJFOz lljgaSsDQUBl2QbVSN49vyXnWh/plxFqng/3dukCOCLagwKTVb/JSoRkDoioTSD3ORn8 JG+FQkGepGSwvYuNGrDN7f/YoTNPK0Y4njFAPZ6gtJ1fHefODy9Eb3+GyLS5mLYykULo y1pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781749008; x=1782353808; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G6bgdFP6eQHqUIHYA197THpQx8Z+j/fXy0gSUXkLpxo=; b=LoBnntmZhYvn9XspRsiDnEtKv2UUdwac8lfsDi6uv9GoI9BM5YeFa8CMmilN0Yosy8 IlmChn74QFxJO3Gq9nHfTx0KNevPErFBrVaZVG38dbb7kTJDsUoTb5SK3kNXkMF7em2+ 6mSfXrAQZECNx+3xfSBD+nQul3DKWHKzfD/bALjhdtEv0lvQQSlmwlFAZGPrh5CGdbk0 Z+wzgrqWNM8dvUF6W9PnGUkbLG8V9p0CVMXM1wHC0iNnbC72PmuCESQZbamxcgGUwAh5 RNaG8z7Xjjhu0OQS/GfcS5cZ1eVNg2vYH89k75Z2ZakyoZ5x5HB20f748bQKNwDX5NiC nxyg== X-Forwarded-Encrypted: i=1; AFNElJ/9YzqlwD4EBz0p4HAYahpwabGSXNAYbzninmCXFQzwqpSNmgxgaoTMnuTOElNa0tkRH5El3ronWHBRtgg=@vger.kernel.org X-Gm-Message-State: AOJu0YyZxdOW9b0hv0ieoZQr88U2r7rO8VHrIDjz/8wf5/8cLISApF3o 6lnQvI06rhMN8bm4vqKDBOjSSgV+k5jLBp3OXXTEQidVTXre13nqPnCT X-Gm-Gg: AfdE7ckkDrRnIm00/md+iEATJkYUX8+3PbnNLhktD5SY4S6CDmVlcbxXIV/P3WcTRPM 5++d3qfVyPhrS3Y7zPI5AYi/E6tQDwu6HcNHINybMlNu1zAC50WvEz/0rJZviNNMf8jDVHTRq2C hmVWPfWMEugOXVUQiEhFZhLddKOD6YIlpuawtjuGziossRyYH755UP9lOXMUOeWiiSEDoXdu43L JXkpKjxbax0m52xCtnQZyHb2qpsVzJ8X0qobAk//sUB9EzkyLQGWI6w/VA/L+PvxTT/SyUu+an4 Hw8AxBRo0AHQFvrGNMKuLw3dLeagx6eiMqh2ZpvYSADjqojNcRmz3rqBe0OX4T4Z3VNebPMClQJ 5pPSONVQZ16J71kbsm1d+NdNwCGjh/mpmoCaScfkNaeIaySXcVlrH9t550NdepABJ/ejqtPCLRL A0sjwHTo0sTvMmwqhQ8g9GdHNbAeRRphviNkO/PNWMBGG9tYVjAURhQzlATF/RNAvVVrRqCnLP/ Tv/c2gI2d9WULcpiuOWZz+ow1gCK4Zo6cvtJEOzOnQEicM= X-Received: by 2002:a17:903:19ed:b0:2c2:50c7:58a4 with SMTP id d9443c01a7336-2c6bc223ee0mr64827035ad.22.1781749007689; Wed, 17 Jun 2026 19:16:47 -0700 (PDT) Received: from bass-virtual-machine.. ([111.202.175.140]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c6a1878493sm61854705ad.81.2026.06.17.19.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 19:16:47 -0700 (PDT) From: Gui-Dong Han 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 Subject: [PATCH v2] nvme-apple: Use acquire/release for queue enabled state Date: Thu, 18 Jun 2026 10:15:43 +0800 Message-Id: <20260618021543.3866850-1-hanguidong02@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 old wmb() after WRITE_ONCE(enabled, true) does not publish the earlier initialization before enabled becomes visible. Use a release store when enabling the queue and acquire loads when testing it. Although the shutdown-side enabled accesses are not used for publishing queue initialization, use helpers for them as well for consistency. Fixes: 5bd2927aceba ("nvme-apple: Add initial Apple SoC NVMe driver") Signed-off-by: Gui-Dong Han --- v2: - Drop the old wmb(), as suggested by Keith Busch. - Use the queue enabled helpers in apple_nvme_disable(), as suggested by Keith Busch. v1: - Found by auditing READ_ONCE() used for synchronization. - A similar fix can be found in 8df672bfe3ec. --- drivers/nvme/host/apple.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index f9327feb87d0..291271c3954b 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -151,6 +151,23 @@ 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); +} + +static inline void apple_nvme_disable_queue(struct apple_nvme_queue *q) +{ + WRITE_ONCE(q->enabled, false); +} + /* * The apple_nvme_iod describes the data in an I/O. * @@ -677,7 +694,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 +797,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)) @@ -863,7 +880,7 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown) nvme_quiesce_io_queues(&anv->ctrl); if (!dead) { - if (READ_ONCE(anv->ioq.enabled)) { + if (apple_nvme_queue_enabled(&anv->ioq)) { apple_nvme_remove_sq(anv); apple_nvme_remove_cq(anv); } @@ -887,8 +904,8 @@ static void apple_nvme_disable(struct apple_nvme *anv, bool shutdown) nvme_disable_ctrl(&anv->ctrl, false); } - WRITE_ONCE(anv->ioq.enabled, false); - WRITE_ONCE(anv->adminq.enabled, false); + apple_nvme_disable_queue(&anv->ioq); + apple_nvme_disable_queue(&anv->adminq); mb(); /* ensure that nvme_queue_rq() sees that enabled is cleared */ nvme_quiesce_admin_queue(&anv->ctrl); @@ -1016,8 +1033,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); - wmb(); /* ensure the first interrupt sees the initialization */ + apple_nvme_enable_queue(q); } static void apple_nvme_reset_work(struct work_struct *work) -- 2.34.1