linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
	"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-mtd@lists.infradead.org
Subject: Re: [PATCH 03/11] nvmem: exclude disconnected providers from callback admission
Date: Tue, 17 Nov 2026 20:07:14 +0000	[thread overview]
Message-ID: <sashiko-outbox-219563@kernel.org> (raw)
In-Reply-To: <20261117-submit-nvmem-provider-lifetime-v1-v1-3-3cfbd48812b5@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmem: SRCU held across nvmem_cell_entry_add() without
  rechecking ops
--

commit f2f33b1005de81978c098ebed41d0fc8a71c6f7e
Author: James Hilliard <james.hilliard1@gmail.com>

nvmem: exclude disconnected providers from callback admission

This commit protects sysfs permission checks, cell addition, DT fixups,
layout population, and device matching with the provider's SRCU domain,
and serializes provider disconnection against consumer lookup under
nvmem_mutex.

> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 73aa53145f0b7..c41266241f3f9 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
[ ... ]
> @@ -673,6 +682,10 @@ int nvmem_add_one_cell(struct nvmem_device *nvmem,
>  	struct nvmem_cell_entry *cell;
>  	int rval;
>  
> +	guard(srcu)(&nvmem->srcu);
> +	if (!srcu_dereference(nvmem->ops, &nvmem->srcu))
> +		return -ENODEV;
> +
>  	cell = kzalloc_obj(*cell);
>  	if (!cell)
>  		return -ENOMEM;

[Severity: Medium]
Does holding nvmem->srcu across nvmem_cell_entry_add() invert the lock
ordering with nvmem_notifier.rwsem and allow cells to be added after
nvmem_unregister() has disconnected the provider?

nvmem_cell_entry_add() calls blocking_notifier_call_chain(&nvmem_notifier,
NVMEM_CELL_ADD, cell) while nvmem->srcu is held. All nvmem->srcu instances
are initialized with init_srcu_struct() and share a single static lockdep
class. Notifier callbacks such as cp500_nvmem() call nvmem_register() and
nvmem_unregister() under nvmem_notifier.rwsem, which on error unwind or
removal calls nvmem_disconnect() -> synchronize_srcu(&nvmem->srcu):

CPU0                              CPU1
----                              ----
lock(&nvmem->srcu)
                                  down_read(&nvmem_notifier.rwsem)
down_read(&nvmem_notifier.rwsem)
                                  synchronize_srcu(&nvmem->srcu)

 *** DEADLOCK ***

CPU0: nvmem_add_one_cell() -> nvmem_cell_entry_add()
CPU1: blocking_notifier_call_chain() -> cp500_nvmem() -> nvmem_register()
      -> nvmem_disconnect()

In addition, nvmem_add_one_cell() only checks nvmem->ops at entry before
nvmem_cell_entry_add() acquires nvmem_mutex:

drivers/nvmem/core.c:nvmem_cell_entry_add() {
	scoped_guard(mutex, &nvmem_mutex)
		list_add_tail(&cell->node, &cell->nvmem->cells);
	blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
}

If nvmem_unregister() runs concurrently, it sends NVMEM_REMOVE, clears
nvmem->ops under nvmem_mutex in nvmem_disconnect(), and waits in
synchronize_srcu(). An in-flight nvmem_add_one_cell() that passed the
initial check then acquires nvmem_mutex without rechecking nvmem->ops,
appends the cell to the disconnected provider, and emits NVMEM_CELL_ADD
after NVMEM_REMOVE.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-submit-nvmem-provider-lifetime-v1-v1-0-3cfbd48812b5@gmail.com?part=3

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

  reply	other threads:[~2026-11-17 20:07 UTC|newest]

Thread overview: 17+ 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-17 19:38 ` [PATCH 02/11] nvmem: drain keepout and cell post-processing accesses James Hilliard
2026-11-17 19:50   ` sashiko-bot
2026-11-17 19:38 ` [PATCH 03/11] nvmem: exclude disconnected providers from callback admission James Hilliard
2026-11-17 20:07   ` sashiko-bot [this message]
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:48   ` sashiko-bot
2026-11-17 19:38 ` [PATCH 06/11] nvmem: manage cell attributes independently of device resources James Hilliard
2026-11-17 19:59   ` sashiko-bot
2026-11-17 19:38 ` [PATCH 07/11] nvmem: distinguish layout cells from provider cells James Hilliard
2026-11-17 19:51   ` sashiko-bot
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-17 19:38 ` [PATCH 11/11] nvmem: allow providers to specify an explicit NULL owner James Hilliard

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=sashiko-outbox-219563@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=james.hilliard1@gmail.com \
    --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=sashiko-reviews@lists.linux.dev \
    --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;
as well as URLs for NNTP newsgroup(s).