Re: [PATCH v4] char/nvram: Remove redundant nvram_mutex

Ritesh Harjani
2026-03-31T02:07:16Z

Venkat Rao Bagalkote <venkat88@linux.ibm.com> writes:

> The global nvram_mutex in drivers/char/nvram.c is redundant and unused,
> and this triggers compiler warnings on some configurations.
>
> All platform-specific nvram operations already provide their own internal
> synchronization, meaning the wrapper-level mutex does not provide any
> additional safety.
>
> Remove the nvram_mutex definition along with all remaining lock/unlock
> users across PPC32, x86, and m68k code paths, and rely entirely on the
> per-architecture nvram implementations for locking.
>
> Suggested-by: Arnd Bergmann <arnd@arndb.de>
> Signed-off-by: Venkat Rao Bagalkote <venkat88@linux.ibm.com>
> ---
> v4:
> - Remove all remaining nvram_mutex call sites, completing the mutex removal
>

Let me cut paste the review from Sashiko here..

Does this removal expose the underlying raw spinlock to concurrent userspace
contention?
Looking at ppc_md.nvram_sync() implementations like core99_nvram_sync() on
PowerMac, the code acquires a raw spinlock (nv_lock) and performs hardware
flash memory operations with polling loops and udelay() calls that can take
hundreds of milliseconds to complete.
Because IOC_NVRAM_SYNC does not require CAP_SYS_ADMIN, any user with access
to the device can call this ioctl.
Previously, nvram_mutex provided a sleepable barrier for concurrent
IOC_NVRAM_SYNC callers. Without it, won't secondary callers spin on the raw
spinlock with interrupts disabled for the entire duration of the first
caller's slow flash I/O?
Could this prolonged spinning with IRQs disabled completely freeze the
waiting CPUs and trigger NMI watchdog timeouts or system lockups?

First of all the above problem is only being talked about PowerMAC and
not for x86 / m68k. In there I think, we just read/write few bytes under
the spinlock.

On PowerMac too, I don't think the above problem gives a reason, to keep
a redundant locking at a generic wrapper layer which can affects other
platforms/archs. And the comment in PowerMac code above nv_lock says:
// XXX Turn that into a sem
static DEFINE_RAW_SPINLOCK(nv_lock);

So, it looks like Sashiko review comment can be ignored, and the patch
looks right to me, which kills the redundant mutex lock from here. So as
for this patch please feel free to add...

Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>

... But I would also let Chrisptophe comment from ppc32 / PowerMac perspective.

-ritesh