mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/9] nvmem: rework nvmem core and allow unbinding with active consumers
@ 2026-04-29 15:43 Bartosz Golaszewski
  2026-04-29 15:43 ` [PATCH v3 1/9] nvmem: remove unused field from struct nvmem_device Bartosz Golaszewski
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Bartosz Golaszewski @ 2026-04-29 15:43 UTC (permalink / raw)
  To: Srinivas Kandagatla, Bartosz Golaszewski, Johan Hovold
  Cc: linux-kernel, brgl, Bartosz Golaszewski

Nvmem is one of the subsystems vulnerable to object life-time issues.
The memory nvmem core dereferences is owned by nvmem providers which can
be unbound at any time and even though nvmem devices themselves are
reference-counted, there's no synchronization with the provider modules.

This typically is not a problem because thanks to fw_devlink, consumers
get synchronously unbound before providers but it's enough to pass
fw_devlink=off over the command line, unbind the nvmem controller with
consumers still holding references to it and try to read/write in order
to see fireworks in the kernel log.

User-space can trigger it too if a device (for instance: i2c eeprom on a
cp2112 USB expander) is unplugged halfway through a long read.

This series proposes to use SRCU to protect nvmem against accessing
invalid memory after unbinding with active consumers and also reworks
several places in nvmem core.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v3:
- Add Fixes tag to patch 1
- Don't check the presence of read/write callbacks in sysfs attributes
  as these are not visible without them
- Rework mutex guards and drop unneeded helper variables
- Fix mutex guard conversion: it accidentally converted nvmem_lookup_mutex
  locks to nvmem_mutex
- Extend patch 5 to also rename __nvmem_device_get() to
  nvmem_device_match()
- Call nvmem_sysfs_remove_compat() on unregister, not release
- Split patch 7 into two: one removing the redundant kref and second
  adding SRCU
- Link to v2: https://patch.msgid.link/20260223-nvmem-unbind-v2-0-0df33a933dca@oss.qualcomm.com

Changes in v2:
- add missing SRCU struct cleanup
- improve the teardown path on error in nvmem_register()
- Link to v1: https://lore.kernel.org/r/20260116-nvmem-unbind-v1-0-7bb401ab19a8@oss.qualcomm.com

---
Bartosz Golaszewski (9):
      nvmem: remove unused field from struct nvmem_device
      nvmem: return -EOPNOTSUPP to in-kernel users on missing callbacks
      nvmem: check the return value of gpiod_set_value_cansleep()
      nvmem: simplify locking with guard()
      nvmem: remove unneeded __nvmem_device_put()
      nvmem: split out the reg_read/write() callbacks out of struct nvmem_device
      nvmem: simplify nvmem_sysfs_remove_compat()
      nvmem: remove duplicated reference counting
      nvmem: protect nvmem_device::ops with SRCU

 drivers/nvmem/core.c      | 298 ++++++++++++++++++++++++----------------------
 drivers/nvmem/internals.h |  13 +-
 2 files changed, 163 insertions(+), 148 deletions(-)
---
base-commit: 09edb1ec49a5eef1910905fb9d3be57a6aaf7e40
change-id: 20260114-nvmem-unbind-673b52fc84a0

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-04-29 15:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-29 15:43 [PATCH v3 0/9] nvmem: rework nvmem core and allow unbinding with active consumers Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 1/9] nvmem: remove unused field from struct nvmem_device Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 2/9] nvmem: return -EOPNOTSUPP to in-kernel users on missing callbacks Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 3/9] nvmem: check the return value of gpiod_set_value_cansleep() Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 4/9] nvmem: simplify locking with guard() Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 5/9] nvmem: remove unneeded __nvmem_device_put() Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 6/9] nvmem: split out the reg_read/write() callbacks out of struct nvmem_device Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 7/9] nvmem: simplify nvmem_sysfs_remove_compat() Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 8/9] nvmem: remove duplicated reference counting Bartosz Golaszewski
2026-04-29 15:43 ` [PATCH v3 9/9] nvmem: protect nvmem_device::ops with SRCU Bartosz Golaszewski

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®