[PATCH v3 0/2] rpmb: add virtio RPMB driver

From: Haruka Kuze

Date: Fri Oct 30 2026 - 09:32:26 EST


This adds a driver on top of the rpmb subsystem for virtio-rpmb devices.

Alex Bennée had an earlier virtio-rpmb driver in his RPMB series [1]
but that stalled due to the user space API.

The one that merged later has no user space API and OP-TEE routes frames
through it so this driver only needs to implement route_frames().

I added patch 1 to fix a use-after-free that I hit while testing
removing the device (OP-TEE can still route frames after driver unregisters
the rpmb device).

I tested this with UML (virtio_uml) and a vhost-user backend I wrote
for this on top of rust-vmm's vhost-device with KASAN, lockdep:

- key programming
- write counter
- single and multi block write and read
- MAC and counter failures
- max_wr_cnt
- unbinding the driver when the rpmb device is held

With OP-TEE 4.11 on QEMU virt arm64 the secure_storage example TA keeps
its objects in RPMB through the driver and an object written to in one
boot is found in the one after.

I have added myself in MAINTAINERS. I would like to maintain the driver.

Changes in v3:
- Take a spinlock around the virtqueue operations, so the completion
callback can not call virtqueue_get_buf() while a new request is
added (sashiko)
- Do not delete the virtqueue twice when restore failed (sashiko)
- Explain the reliable_wr_count calculation in a comment
- v2: https://lore.kernel.org/all/20261029124132.2354314-1-harukak@xxxxxxxxxxx/

Changes in v2:
- Use guard() and scoped_guard() for the locks in both patches (Greg)
- Call virtio_device_ready() before vr->vq is set, so a request on
restore can not kick the queue before DRIVER_OK (sashiko)
- v1: https://lore.kernel.org/all/20261029081317.2264887-1-harukak@xxxxxxxxxxx/

- haruka

[1] https://lore.kernel.org/all/20220405093759.1126835-1-alex.bennee@xxxxxxxxxx/

Haruka Kuze (2):
rpmb: stop the routing after unregister
rpmb: add a virtio RPMB device driver

MAINTAINERS | 7 +
drivers/misc/Kconfig | 10 ++
drivers/misc/Makefile | 1 +
drivers/misc/rpmb-core.c | 14 +-
drivers/misc/virtio_rpmb.c | 300 +++++++++++++++++++++++++++++++
include/linux/rpmb.h | 4 +
include/uapi/linux/virtio_rpmb.h | 56 ++++++
7 files changed, 391 insertions(+), 1 deletion(-)
create mode 100644 drivers/misc/virtio_rpmb.c
create mode 100644 include/uapi/linux/virtio_rpmb.h


base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
--
2.55.0