virt: bao: add Bao hypervisor IPC and I/O dispatcher drivers
Subsystems (2)
v7 cover virt: bao: add Bao hypervisor IPC and I/O dispatcher drivers
This series adds guest-side drivers for the Bao static-partitioning
hypervisor: an IPC shared-memory driver, an I/O dispatcher that lets a backend guest service VirtIO I/O for frontend guests, their UAPI and a MAINTAINERS entry.
Bao is a lightweight static-partitioning hypervisor for embedded and safety-critical systems (https://github.com/bao-project).
- The IPC shared-memory driver lets Bao guests exchange data through a shared-memory region split into a read and a write channel, exposed as a misc character device (read(), write(), mmap()). The channels are declared on the kernel command line.
- The I/O dispatcher bridges Bao's Remote I/O mechanism to a userspace
VMM: the VMM creates each device model from /dev/bao, receives the frontend's MMIO accesses and completes them, with ioeventfd/irqfd support for the fast paths.
Changes since v6
----------------
The finding of the Sashiko review of v6 is addressed; it is in the I/O dispatcher, and patches 1 and 3 are unchanged.
- The EPOLLHUP path of an irqfd marked it for shutdown and queued the shutdown work outside any lock that deassign and the device-model teardown take, so these could skip queueing it, flush and destroy the workqueue and free the device model before the work was queued. irqfds now follow KVM: an irqfd is active while it is on its device model's list, and whichever path deactivates it (EPOLLHUP, deassign or teardown) removes it from the list and queues its shutdown under the same spinlock, so the flushes always wait for every shutdown. Queueing the work unconditionally, as suggested, would instead let an EPOLLHUP re-queue a shutdown that is already running and free the irqfd twice.
Changes since v5
----------------
All findings of the Sashiko review of v5 are addressed. They are all in the I/O dispatcher; patches 1 and 3 are unchanged.
- A device model is torn down in order: dispatching stops first, every I/O client is stopped before any is destroyed (the ioeventfds are released only once their thread is gone), then the queued, in-flight and still pending requests are completed. The dispatcher is no longer paused and resumed per client, which re-queued dispatch work during teardown and issued hypercalls when BAO_IOCTL_CREATE_DM failed.
- IO_CLIENT_ATTACH publishes a request only once it has been copied to userspace, so a concurrent IO_REQUEST_COMPLETE cannot complete it twice.
- ioeventfds follow KVM: two of them conflict when a write could match both, whatever eventfd they use; a request matches only the exact length; reads, and writes that no ioeventfd matches, are handed to the VMM instead of being answered or dropped by the kernel.
- Matching a request against an I/O range rejects zero or oversized access widths and wrap-around.
- An irqfd consumes the eventfd counter when signaled, and deassigning an unknown irqfd fails with -ENOENT.
- The I/O dispatcher is 64-bit only: the Remote I/O fields did not fit the RV32 hypercall registers.
Also, requests already pending when a device model is created (a frontend that started first, a VMM that restarted) are picked up at creation instead of waiting for a notification that does not come again.
Changes since v4
----------------
- BAO_IOCTL_CREATE_DM requires CAP_SYS_RAWIO, is refused under lockdown and claims a non-RAM region with request_mem_region(), mirroring /dev/mem. The notification line is checked against the interrupt controller and requested exclusively, and its mapping is never disposed, since it may be shared with whoever owns the line.
- Requests that cannot be delivered are completed instead of stranded. The requests handed to the VMM are tracked: a completion only provides the value, and a VMM that exits leaves nothing behind.
- ioeventfds and irqfds are bounded per device model, and a device model id is bound to one file descriptor at a time.
- RISC-V: the hypercall status is the SBI value (a1), and both drivers depend on RISCV_SBI.
- mmap goes through .mmap_prepare and only allows shared mappings; .compat_ioctl is set; the IPC driver never unwinds a registered device; bao_ipcshmem.channels= is documented in kernel-parameters.txt; rebased on v7.4-rc1.
Changes since v3
----------------
- No device tree (Krzysztof Kozlowski): the IPC channels are declared on the kernel command line and, following drivers/virt/acrn, the VMM creates each device model through /dev/bao (BAO_IOCTL_CREATE_DM), which returns a per-device-model file descriptor.
- No architecture code (Will Deacon): the hypercalls use arm_smccc_hvc()/arm_smccc_1_2_hvc() and sbi_ecall() from a driver-private header.
- The "consolidate the IPC hypercall ID" patch is folded in (Andrew Jones), and the ioctl type is 0xA7.
Testing
-------
Built on v7.4-rc1 with GCC 15 (W=1) for arm64, arm and riscv, at every commit, and with clang 21 (W=1) for arm64 and riscv. Run-time tested under Bao v2.0.0 on QEMU aarch64 virt and QEMU riscv64 virt with the bao-demos demos: the IPC driver exchanging messages in both directions between a Linux guest and a FreeRTOS guest, and the I/O dispatcher with a Linux backend serving console, network and block device models to a FreeRTOS guest and to Linux guests, including killing and restarting the VMMs, plus a userspace test of the /dev/bao error paths run next to the live VMMs, which now also races device-model teardown against eventfd close for the irqfds. The arm64 runs used a lockdep kernel. 32-bit Arm is compile-tested only.
Open items
----------
- RISC-V: the Bao SBI extension still uses the experimental extension space (0x08000ba0), and the Remote I/O hypercall returns the request in a2-a7, which does not follow the SBI calling convention (Andrew Jones, v2). Changing that means a hypervisor ABI change (status in a0/a1, request through shared memory); the RISC-V support is experimental until then, or it can be split out of this series if preferred.
- Bao does not implement the SMCCC vendor-hypervisor UID call, so the drivers cannot detect the hypervisor yet; adding it is planned on the hypervisor side.
- The notification line is a line of the interrupt controller the device tree's root node points at through interrupt-parent; a guest whose root node has none cannot use the I/O dispatcher yet.
v6: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
v3: https://lore.kernel.org/all/[email protected]/
João Peixoto (3):
virt: bao: add IPC shared-memory driver
virt: bao: add I/O dispatcher driver
MAINTAINERS: add Bao hypervisor entry
.../admin-guide/kernel-parameters.txt | 15 + .../userspace-api/ioctl/ioctl-number.rst | 2 + MAINTAINERS | 8 + drivers/virt/Kconfig | 2 + drivers/virt/Makefile | 1 + drivers/virt/bao/Kconfig | 5 + drivers/virt/bao/Makefile | 4 + drivers/virt/bao/bao_hypercall.h | 210 ++++++++ drivers/virt/bao/io-dispatcher/Kconfig | 20 + drivers/virt/bao/io-dispatcher/Makefile | 4 + drivers/virt/bao/io-dispatcher/bao_drv.h | 426 ++++++++++++++++ drivers/virt/bao/io-dispatcher/dm.c | 460 +++++++++++++++++ drivers/virt/bao/io-dispatcher/driver.c | 71 +++ drivers/virt/bao/io-dispatcher/intc.c | 186 +++++++ drivers/virt/bao/io-dispatcher/io_client.c | 475 ++++++++++++++++++ .../virt/bao/io-dispatcher/io_dispatcher.c | 184 +++++++ drivers/virt/bao/io-dispatcher/ioeventfd.c | 359 +++++++++++++ drivers/virt/bao/io-dispatcher/irqfd.c | 350 +++++++++++++ drivers/virt/bao/ipcshmem/Kconfig | 16 + drivers/virt/bao/ipcshmem/Makefile | 3 + drivers/virt/bao/ipcshmem/ipcshmem.c | 421 ++++++++++++++++ include/uapi/linux/bao.h | 126 +++++ 22 files changed, 3348 insertions(+) create mode 100644 drivers/virt/bao/Kconfig create mode 100644 drivers/virt/bao/Makefile create mode 100644 drivers/virt/bao/bao_hypercall.h create mode 100644 drivers/virt/bao/io-dispatcher/Kconfig create mode 100644 drivers/virt/bao/io-dispatcher/Makefile create mode 100644 drivers/virt/bao/io-dispatcher/bao_drv.h create mode 100644 drivers/virt/bao/io-dispatcher/dm.c create mode 100644 drivers/virt/bao/io-dispatcher/driver.c create mode 100644 drivers/virt/bao/io-dispatcher/intc.c create mode 100644 drivers/virt/bao/io-dispatcher/io_client.c create mode 100644 drivers/virt/bao/io-dispatcher/io_dispatcher.c create mode 100644 drivers/virt/bao/io-dispatcher/ioeventfd.c create mode 100644 drivers/virt/bao/io-dispatcher/irqfd.c create mode 100644 drivers/virt/bao/ipcshmem/Kconfig create mode 100644 drivers/virt/bao/ipcshmem/Makefile create mode 100644 drivers/virt/bao/ipcshmem/ipcshmem.c create mode 100644 include/uapi/linux/bao.h
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.53.0
PATCH v7 1/3 virt: bao: add IPC shared-memory driver
Add a driver that lets guests running on the Bao static-partitioning hypervisor communicate through shared memory. Each guest is assigned a read and a write region within a shared-memory area.
The IPC channels are a pure software contract between the Bao hypervisor and its guests, so they are not described in the device tree. Each channel is instead declared on the kernel command line:
bao_ipcshmem.channels=<channel>[;<channel>...]
where each <channel> is
<id>,<read_base>,<read_size>,<write_base>,<write_size>
The parameter is documented in kernel-parameters.txt.
Userspace accesses the regions through a misc character device using read(), write() and mmap(). The read region is written by the peer and mapped read-only at stage 2, so a writable mapping of it is refused, and so are private mappings, whose writes would never reach the peer. A write() notifies the peer guest through a hypercall issued with the architecture's standard hypervisor call convention: an SMCCC fast call in the vendor-specific hypervisor service range (HVC) on arm/arm64 and an SBI extension call (ecall) on RISC-V. The helpers live in the driver directory, built on the generic SMCCC and SBI support, so no architecture code is needed.
The regions are validated when parsed (page-aligned, not wrapping, not overlapping System RAM, so a channel cannot be pointed at kernel memory). The misc devices are only registered once every channel is set up, and once one of them is registered a later failure only drops its own channel, so module init never fails with a device already open.
---
v7:
- No change.
v6:
- No change.
v5:
- Register the misc devices only once every channel has been parsed and mapped (Sashiko review), and never unregister one from module init:
once a device is registered, a later misc_register() failure only drops its own channel, since the device may already be open. Refuse duplicate channel ids.
- Refuse regions overlapping System RAM (region_intersects()), so a channel cannot be pointed at kernel memory.
- Fail write() with -EIO when the notification hypercall fails.
- Use .mmap_prepare (.mmap is deprecated) and refuse private mappings, whose writes would never reach the peer.
- RISC-V: take the hypercall status from the SBI value (a1), where Bao returns it; the SBI error (a0) only says whether the extension exists.
- Kconfig: depend on RISCV_SBI instead of RISCV; sbi_ecall() does not exist in M-mode kernels, which failed to build the driver.
- Document bao_ipcshmem.channels= in kernel-parameters.txt.
- Rebase on v7.4-rc1; use kzalloc_obj().
v4:
- Drop the device-tree binding and the platform driver; the channels are declared on the kernel command line (bao_ipcshmem.channels=<id>,<read_base>, <read_size>,<write_base>,<write_size>[;...]) and the misc devices are created from module init (Krzysztof Kozlowski).
- Move the hypercall helper out of arch/ into drivers/virt/bao/bao_hypercall.h, built on arm_smccc_hvc() (arm/arm64) and sbi_ecall() (RISC-V); the hypercall ID is defined there, folding the v3 "consolidate the IPC hypercall ID" patch (Will Deacon, Andrew Jones).
- Kconfig: depend on HAVE_ARM_SMCCC || RISCV; the module is now bao_ipcshmem, so the documented parameter name is real.
- Add wmb() before the notify hypercall; refuse writable mappings of the read region and clear VM_MAYWRITE; require page-aligned regions and reject ranges that do not fit phys_addr_t/size_t; add .llseek; enlarge the label buffer; do the mmap offset arithmetic in u64 (Sashiko review).
- Devices live and die with the module and open files pin it, closing the unbind use-after-free of v3.
.../admin-guide/kernel-parameters.txt | 15 + drivers/virt/Kconfig | 2 + drivers/virt/Makefile | 1 + drivers/virt/bao/Kconfig | 3 + drivers/virt/bao/Makefile | 3 + drivers/virt/bao/bao_hypercall.h | 97 ++++ drivers/virt/bao/ipcshmem/Kconfig | 16 + drivers/virt/bao/ipcshmem/Makefile | 3 + drivers/virt/bao/ipcshmem/ipcshmem.c | 421 ++++++++++++++++++ 9 files changed, 561 insertions(+) create mode 100644 drivers/virt/bao/Kconfig create mode 100644 drivers/virt/bao/Makefile create mode 100644 drivers/virt/bao/bao_hypercall.h create mode 100644 drivers/virt/bao/ipcshmem/Kconfig create mode 100644 drivers/virt/bao/ipcshmem/Makefile create mode 100644 drivers/virt/bao/ipcshmem/ipcshmem.c
Documentation/admin-guide/kernel-parameters.txt +15 -0
@@ -621,6 +621,21 @@ Kernel parameters Format: <int> (must be >=0) Default: 64 + bao_ipcshmem.channels= + [ARM,ARM64,RISCV] Shared-memory IPC channels of a + guest of the Bao hypervisor (CONFIG_BAO_SHMEM), each + exposed as /dev/baoipc<id>. + Format: <channel>[;<channel>...] + where <channel> is + <id>,<read_base>,<read_size>,<write_base>,<write_size> + <id> is the channel id assigned by the hypervisor + and passed to its notification hypercall. The read + region is written by the peer guest, the write + region by this one. Bases and sizes are physical + addresses and sizes, decimal or 0x-prefixed hex, + page-aligned and outside System RAM. + Example: 0,0xf0000000,0x2000,0xf0002000,0x2000 + bdev_allow_write_mounted= Format: <bool> Control the ability to open a mounted block device
drivers/virt/Kconfig +2 -0
@@ -64,6 +64,8 @@ source "drivers/virt/nitro_enclaves/Kconfig" source "drivers/virt/acrn/Kconfig" +source "drivers/virt/bao/Kconfig" + endif source "drivers/virt/coco/Kconfig"
drivers/virt/Makefile +1 -0
@@ -11,3 +11,4 @@ obj-y += vboxguest/ obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/ obj-$(CONFIG_ACRN_HSM) += acrn/ obj-y += coco/ +obj-y += bao/
drivers/virt/bao/Kconfig new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +source "drivers/virt/bao/ipcshmem/Kconfig"
drivers/virt/bao/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_BAO_SHMEM) += ipcshmem/
drivers/virt/bao/bao_hypercall.h new file +97 -0
97 lines not on this page · raw message
drivers/virt/bao/ipcshmem/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +# SPDX-License-Identifier: GPL-2.0 +config BAO_SHMEM + tristate "Bao hypervisor shared memory support" + depends on HAVE_ARM_SMCCC || RISCV_SBI + help + This enables support for Bao shared memory communication. + It allows the kernel to interface with guests running under + the Bao hypervisor, providing a character device interface + for exchanging data through dedicated shared-memory regions. + Channels are declared on the kernel command line via + "bao_ipcshmem.channels=". + + To compile this driver as a module, choose M here: the module + will be called bao_ipcshmem. + + If unsure, say N.
drivers/virt/bao/ipcshmem/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_BAO_SHMEM) += bao_ipcshmem.o +bao_ipcshmem-y := ipcshmem.o
drivers/virt/bao/ipcshmem/ipcshmem.c new file +421 -0
421 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 2/3 virt: bao: add I/O dispatcher driver
In reply to João PeixotoAdd the Bao I/O dispatcher, used by backend VMs to service I/O on behalf of frontend guests. It bridges Bao's Remote I/O mechanism to userspace VirtIO backend device models.
The set of device models a backend serves is a software contract between the hypervisor and the userspace VMM, not hardware, so it is not described in the device tree. Following the model used by other hypervisor drivers (e.g. drivers/virt/acrn), the driver exposes a single /dev/bao control device; the VMM creates each device model from its own configuration with the BAO_IOCTL_CREATE_DM ioctl, which returns a per-DM file descriptor. Each device model has a contiguous shared-memory region for exchanging I/O buffers with its frontend and an interrupt the hypervisor uses to signal pending requests; both are provided by the VMM at creation time. The interrupt is given as a line of the system's root interrupt controller (the one the device tree's root node points at through interrupt-parent) and mapped by the driver. Userspace then drives the device model through a set of ioctls on that descriptor.
Creating a device model maps a physical region chosen by the VMM into userspace and claims an interrupt line, so BAO_IOCTL_CREATE_DM requires CAP_SYS_RAWIO, is refused under lockdown (LOCKDOWN_DEV_MEM), rejects regions overlapping System RAM and claims the region with request_mem_region(), mirroring /dev/mem. The line is checked against the sources the interrupt controller declares, since irqchip drivers trust the specifiers they are given, and is requested exclusively, so one already in use cannot be taken over. A DM id can only be bound to one descriptor at a time.
The queued requests, ioeventfds and irqfds of a device model are bounded, and a request that cannot be delivered (no client, full queue, teardown) is completed back to the hypervisor so the frontend never hangs. The requests handed to userspace are tracked until it completes
them: a completion only takes the value from userspace, and the requests a VMM leaves behind when it exits, like those still pending in the hypervisor, are completed by the kernel when the device model is released. As with KVM, a write that no ioeventfd matches is handed to the VMM rather than dropped.
The Remote I/O hypercall returns the pending request in x1-x6 on top of the status in x0, so on arm64 it is issued as an SMCCC v1.2 call through arm_smccc_1_2_hvc(); no architecture code is needed. The request fields are 64-bit and 32-bit Arm has no SMCCC v1.2 helper, so the I/O dispatcher is limited to arm64 and 64-bit RISC-V. On RISC-V the request comes back in a2-a7 through the (experimental) Bao SBI extension, which sbi_ecall() cannot express, hence the local ecall helper. The extension always succeeds from the SBI point of view and reports the hypercall status as the SBI value, so that is where both helpers take it from.
---
v7:
- Fix the irqfd teardown race reported by the Sashiko review of v6: the EPOLLHUP wakeup set the shutdown bit and queued the work outside any lock deassign and the DM teardown take, so they could skip queueing it, flush, and destroy the workqueue and free the DM before the work was queued. Follow KVM instead: an irqfd is active while it is on the DM's list, and deactivating it (list removal and queue_work()) is done under a spinlock by whichever path wins (EPOLLHUP, deassign, teardown), so their flushes always wait for every shutdown, which now only unhooks the irqfd from the eventfd and frees it. Assignments are serialized by a mutex and hook the irqfd to the eventfd before activating it; deassign always waits for the shutdowns, also when a concurrent deassign of the same eventfd won. Queueing the work unconditionally, as suggested, would let an EPOLLHUP re-queue a shutdown that is already running.
v6:
- Tear the DM down in order (Sashiko review): stop dispatching first, then the irqfds; stop every I/O client before destroying any, and release the ioeventfds only once their kernel thread has stopped; then complete the queued and in-flight requests. The dispatcher is no longer paused and resumed per client, which re-queued dispatch work mid-teardown and issued ASK hypercalls when BAO_IOCTL_CREATE_DM failed. The requests still pending in the hypervisor are completed only when the DM file descriptor is released.
- IO_CLIENT_ATTACH: allocate the tracking entry first and publish it only once the request has been copied to userspace, so a concurrent IO_REQUEST_COMPLETE cannot complete it twice (Sashiko review).
- ioeventfd, as with KVM (Sashiko review): two ioeventfds with the same address, length and an overlapping data match conflict whatever eventfd they use; a request matches only the exact length; reads, and writes that no ioeventfd matches, are forwarded to the VMM instead of being completed by the kernel.
- Reject zero or oversized access widths and wrap-around when matching a request against an I/O range (Sashiko review).
- irqfd: consume the eventfd counter when it is signaled; return -ENOENT when deassigning an unknown irqfd (Sashiko review).
- Limit the driver to arm64 and RV64: the Remote I/O fields are 64-bit and were truncated in the RV32 hypercall registers and xarray indices (Sashiko review).
- Look for pending requests once when a DM is created: they may have been raised before its line was requested (a VMM restart, a frontend that started first). The file descriptor is installed only after that, so a failed BAO_IOCTL_CREATE_DM issues no hypercall.
v5:
- BAO_IOCTL_CREATE_DM requires CAP_SYS_RAWIO, is refused under lockdown (LOCKDOWN_DEV_MEM), validates the shared-memory region (non-empty, page-aligned, not wrapping, not overlapping System RAM) and claims it with request_mem_region() (Sashiko review).
- Check the notification line against the sources the root interrupt controller declares (riscv,ndev for a PLIC, riscv,num-sources for an APLIC, SPIs 0-987 for a GIC) before mapping it: irqchip drivers do not validate specifiers, and an out-of-range PLIC line wrote past the end of its enable-state array. Request the line exclusively (Sashiko review).
- Never dispose the IRQ mapping. irq_create_of_mapping() returns the existing mapping of a line that is already mapped without counting its users, so disposing it after a failed request_irq() freed the interrupt of the DM or driver owning the line. A leftover mapping is reused when the same line is mapped again.
- Refuse a second file descriptor for a DM id in use (-EEXIST).
- Keep fetching after a request cannot be delivered: complete it and return the pending count instead of an error (Sashiko review).
- Bound the ioeventfds and irqfds per DM (256 each, -ENOSPC); validate their flags and the reserved field (Sashiko review).
- Complete the requests still queued when a client is destroyed instead of dropping them (Sashiko review).
- Track the requests handed to userspace: IO_REQUEST_COMPLETE only completes a read or write handed out on that file descriptor (-ENOENT otherwise) and only takes the value from userspace, and the requests a VMM leaves behind when it exits are completed on release. Userspace could previously issue an ASK through it, which lost a request.
- RISC-V: take the Remote I/O hypercall status from a1, where Bao returns it, instead of the always-successful SBI error in a0. An ASK with nothing pending (every DM teardown, or a racing notification) was taken as a success and its stale registers dispatched as a request. Leave the context untouched on failure on both architectures.
- ioeventfd deassign also matches the data match and returns -ENOENT when nothing matches; irqfd passes the DM id as u32 and uses key_to_poll().
- Kconfig: depend on RISCV_SBI instead of RISCV.
- Use .mmap_prepare and refuse private mappings; set .compat_ioctl to compat_ptr_ioctl, the structures having the same layout for 32-bit userspace.
- DM_GET_INFO and IO_CLIENT_ATTACH are _IOR (they only write to userspace); define the request operations (BAO_IO_WRITE, BAO_IO_READ) in the UAPI header; reserve 0xA7 00-0F instead of the whole type; use fixed_size_llseek(); copy the ioctl arguments on the stack; pr_fmt prefix for the messages.
- Rebase on v7.4-rc1; use kzalloc_obj().
v4:
- Drop the binding and the platform device: a single /dev/bao control device; BAO_IOCTL_CREATE_DM takes {shmem_addr, shmem_size, id, irq} from the VMM and returns a per-DM anonymous-inode fd; the DM lives as long as the fd (Krzysztof Kozlowski; also removes the unbind use-after-free).
- Resolve the notification line against the device tree's root interrupt parent instead of binding to a node (1-cell PLIC, 2-cell APLIC and 3/4-cell GIC specifiers).
- Issue the Remote I/O hypercall with arm_smccc_1_2_hvc() on arm64 (the request is returned in x1-x6, an SMCCC v1.2 call); no arch/ code. RISC-V keeps a local ecall since sbi_ecall() only exposes a0/a1. 32-bit Arm is not supported by this driver for now (no SMCCC v1.2 helper) (Will Deacon).
- UAPI: ioctl type 0xA7 (0xA6 is taken by alloc_tag since 7.3-rc1); struct bao_dm_info reordered to remove implicit padding, ioeventfd and irqfd flag values exported, ioeventfd fd signed, linux/ioctl.h included.
- Sashiko review: take the DM id from the fd, not from userspace; hold the irqfd lock across vfs_poll(), single-shot cleanup work and flush before destroy_workqueue(); per-DM interrupt handler; persistent request_irq() name; return after ioeventfd deassign and match the full {fd, addr, len}; cap queued requests; propagate -ERESTARTSYS; free pending requests on destroy; drop the unused kernel mapping of the shared memory; complete requests that cannot be delivered so the frontend does not hang.
- Found while testing: the kernel thread only exits through kthread_stop(); per-DM workqueue/work instead of static arrays (no more 16-DM limit); WQ_PERCPU on the dispatcher workqueue; fix the range-list walk type in bao_io_client_destroy(); module renamed to bao_io_dispatcher; ERR_PTR() errors from bao_dm_create().
.../userspace-api/ioctl/ioctl-number.rst | 2 + drivers/virt/bao/Kconfig | 2 + drivers/virt/bao/Makefile | 1 + drivers/virt/bao/bao_hypercall.h | 113 +++++ drivers/virt/bao/io-dispatcher/Kconfig | 20 + drivers/virt/bao/io-dispatcher/Makefile | 4 + drivers/virt/bao/io-dispatcher/bao_drv.h | 426 ++++++++++++++++ drivers/virt/bao/io-dispatcher/dm.c | 460 +++++++++++++++++ drivers/virt/bao/io-dispatcher/driver.c | 71 +++ drivers/virt/bao/io-dispatcher/intc.c | 186 +++++++ drivers/virt/bao/io-dispatcher/io_client.c | 475 ++++++++++++++++++ .../virt/bao/io-dispatcher/io_dispatcher.c | 184 +++++++ drivers/virt/bao/io-dispatcher/ioeventfd.c | 359 +++++++++++++ drivers/virt/bao/io-dispatcher/irqfd.c | 350 +++++++++++++ include/uapi/linux/bao.h | 126 +++++ 15 files changed, 2779 insertions(+) create mode 100644 drivers/virt/bao/io-dispatcher/Kconfig create mode 100644 drivers/virt/bao/io-dispatcher/Makefile create mode 100644 drivers/virt/bao/io-dispatcher/bao_drv.h create mode 100644 drivers/virt/bao/io-dispatcher/dm.c create mode 100644 drivers/virt/bao/io-dispatcher/driver.c create mode 100644 drivers/virt/bao/io-dispatcher/intc.c create mode 100644 drivers/virt/bao/io-dispatcher/io_client.c create mode 100644 drivers/virt/bao/io-dispatcher/io_dispatcher.c create mode 100644 drivers/virt/bao/io-dispatcher/ioeventfd.c create mode 100644 drivers/virt/bao/io-dispatcher/irqfd.c create mode 100644 include/uapi/linux/bao.h
Documentation/userspace-api/ioctl/ioctl-number.rst +2 -0
@@ -349,6 +349,8 @@ Code Seq# Include File Comments <mailto:[email protected]> 0xA6 00-0F uapi/linux/alloc_tag.h Memory allocation profiling <mailto:[email protected]> +0xA7 00-0F uapi/linux/bao.h Bao hypervisor + <mailto:[email protected]> 0xAA 00-3F linux/uapi/linux/userfaultfd.h 0xAB 00-1F linux/nbd.h 0xAC 00-1F linux/raw.h
drivers/virt/bao/Kconfig +2 -0
@@ -1,3 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 source "drivers/virt/bao/ipcshmem/Kconfig" + +source "drivers/virt/bao/io-dispatcher/Kconfig"
drivers/virt/bao/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_BAO_SHMEM) += ipcshmem/ +obj-$(CONFIG_BAO_IO_DISPATCHER) += io-dispatcher/
drivers/virt/bao/bao_hypercall.h +113 -0
131 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/Kconfig new file +20 -0
@@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0 +config BAO_IO_DISPATCHER + tristate "Bao Hypervisor I/O Dispatcher" + depends on ARM64 || (RISCV_SBI && 64BIT) + select EVENTFD + help + The Bao I/O Dispatcher is a kernel module for backend Linux VMs + running under the Bao hypervisor. It establishes the connection + between the Remote I/O system (Bao's mechanism for forwarding + I/O requests from frontend VMs to the backend VMs) and the + VirtIO backend device. + + This provides a unified API to support various VirtIO backends, + allowing Bao guests to perform I/O through the hypervisor + transparently. + + To compile this driver as a module, choose M here: the module + will be called bao_io_dispatcher. + + If unsure, say N.
drivers/virt/bao/io-dispatcher/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_BAO_IO_DISPATCHER) += bao_io_dispatcher.o +bao_io_dispatcher-y := driver.o dm.o intc.o io_client.o io_dispatcher.o \ + ioeventfd.o irqfd.o
drivers/virt/bao/io-dispatcher/bao_drv.h new file +426 -0
426 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/dm.c new file +460 -0
460 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/driver.c new file +71 -0
71 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/intc.c new file +186 -0
186 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/io_client.c new file +475 -0
475 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/io_dispatcher.c new file +184 -0
184 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/ioeventfd.c new file +359 -0
359 lines not on this page · raw message
drivers/virt/bao/io-dispatcher/irqfd.c new file +350 -0
350 lines not on this page · raw message
include/uapi/linux/bao.h new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH v7 3/3 MAINTAINERS: add Bao hypervisor entry
In reply to João PeixotoAdd a MAINTAINERS entry covering the Bao hypervisor drivers and their UAPI header.
---
v7:
- No change.
v6:
- No change.
v5:
- No change.
v4:
- Drop the arch/*/include/asm/bao.h and include/linux/bao.h entries (the files are gone); use the directory form for drivers/virt/bao/.
MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -4712,6 +4712,14 @@ F: drivers/video/backlight/ F: include/linux/backlight.h F: include/linux/pwm_backlight.h +BAO HYPERVISOR +M: José Martins <[email protected]> +M: David Cerdeira <[email protected]> +M: João Peixoto <[email protected]> +S: Maintained +F: drivers/virt/bao/ +F: include/uapi/linux/bao.h + BARCO P50 GPIO DRIVER M: Santosh Kumar Yadav <[email protected]> M: Peter Korsgaard <[email protected]>
Signature · 1 line
2.53.0