From: James Hilliard <james.hilliard1@gmail.com>
To: "Srinivas Kandagatla" <srini@kernel.org>,
"Mathieu Dubois-Briand" <mathieu.dubois-briand@bootlin.com>,
"Michael Walle" <mwalle@kernel.org>,
"Rafał Miłecki" <rafal@milecki.pl>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Paul Cercueil <paul@crapouillou.net>,
linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
James Hilliard <james.hilliard1@gmail.com>
Subject: [PATCH 02/11] nvmem: drain keepout and cell post-processing accesses
Date: Tue, 17 Nov 2026 12:38:09 -0700 [thread overview]
Message-ID: <20261117-submit-nvmem-provider-lifetime-v1-v1-2-3cfbd48812b5@gmail.com> (raw)
In-Reply-To: <20261117-submit-nvmem-provider-lifetime-v1-v1-0-3cfbd48812b5@gmail.com>
The register callbacks are protected by SRCU, but keepout traversal and
cell post-processing take place outside that protection. Unregister can
finish draining a register read and return while its caller still uses
a provider-owned keepout table or invokes a post-processing callback.
Hold the SRCU read lock across the complete access, including keepout
handling and post-processing. Reject accesses after the operations pointer
has been cleared, including reads satisfied entirely by a keepout.
Fixes: 6a7b4134fb7a ("nvmem: protect nvmem_device::ops with SRCU")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/nvmem/core.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 802637f375f8..73aa53145f0b 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -164,6 +164,10 @@ static int nvmem_access_with_keepouts(struct nvmem_device *nvmem,
static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
void *val, size_t bytes)
{
+ guard(srcu)(&nvmem->srcu);
+ if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
+ return -ENODEV;
+
if (!nvmem->nkeepout)
return __nvmem_reg_read(nvmem, offset, val, bytes);
@@ -173,6 +177,10 @@ static int nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset,
static int nvmem_reg_write(struct nvmem_device *nvmem, unsigned int offset,
void *val, size_t bytes)
{
+ guard(srcu)(&nvmem->srcu);
+ if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
+ return -ENODEV;
+
if (!nvmem->nkeepout)
return __nvmem_reg_write(nvmem, offset, val, bytes);
@@ -1651,6 +1659,10 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem,
{
int rc;
+ guard(srcu)(&nvmem->srcu);
+ if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
+ return -ENODEV;
+
rc = nvmem_reg_read(nvmem, cell->offset, buf, cell->raw_len);
if (rc)
--
2.53.0
next prev parent reply other threads:[~2026-11-17 19:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:38 [PATCH 00/11] nvmem: complete provider and layout disconnection James Hilliard
2026-11-17 19:38 ` [PATCH 01/11] nvmem: retain the provider node until device release James Hilliard
2026-11-19 13:52 ` Bartosz Golaszewski
2026-11-17 19:38 ` James Hilliard [this message]
2026-11-19 13:56 ` [PATCH 02/11] nvmem: drain keepout and cell post-processing accesses Bartosz Golaszewski
2026-11-17 19:38 ` [PATCH 03/11] nvmem: exclude disconnected providers from callback admission James Hilliard
2026-11-17 19:38 ` [PATCH 04/11] nvmem: release write protection when the provider disconnects James Hilliard
2026-11-17 19:38 ` [PATCH 05/11] nvmem: reference cell entries independently of their provider list James Hilliard
2026-11-17 19:38 ` [PATCH 06/11] nvmem: manage cell attributes independently of device resources James Hilliard
2026-11-17 19:38 ` [PATCH 07/11] nvmem: distinguish layout cells from provider cells James Hilliard
2026-11-17 19:38 ` [PATCH 08/11] nvmem: disconnect cells before removing their layout James Hilliard
2026-11-17 19:38 ` [PATCH 09/11] nvmem: disconnect published devices before registration rollback James Hilliard
2026-11-17 19:38 ` [PATCH 10/11] nvmem: u-boot-env: propagate cell registration errors James Hilliard
2026-11-19 14:01 ` Bartosz Golaszewski
2026-11-17 19:38 ` [PATCH 11/11] nvmem: allow providers to specify an explicit NULL owner James Hilliard
2026-11-19 14:01 ` Bartosz Golaszewski
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=20261117-submit-nvmem-provider-lifetime-v1-v1-2-3cfbd48812b5@gmail.com \
--to=james.hilliard1@gmail.com \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=paul@crapouillou.net \
--cc=rafal@milecki.pl \
--cc=srini@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
all inboxes | Powered by JetHome®