Skip to content

feat(virtio-pci): add in-tree RNG and block backends - #447

Open
ZZJJWarth wants to merge 3 commits into
syswonder:devfrom
ZZJJWarth:integrate-virtio-pci
Open

ZZJJWarth wants to merge 3 commits into
syswonder:devfrom
ZZJJWarth:integrate-virtio-pci

Conversation

@ZZJJWarth

Copy link
Copy Markdown
Contributor

Summary

  • Add kernel and userspace backends for VirtIO PCI RNG and block devices under hvisor-tool/. Each device type can select its backend independently.
  • Bind configuration and data requests to a hypervisor-assigned zone instance. Check complete queue and descriptor ranges against that instance's RAM before either backend accesses them.
  • Release the bridge lock during waits, coalesce duplicate virtqueue kicks, and deliver MSI-X for matching completions. Drop late completion events on stopped vCPUs or zones undergoing shutdown.
  • Drain admitted I/O before managed zone shutdown, discard pending completions for the retired instance, and reclaim device slots and block image handles. Guest-initiated power-off leaves the zone allocated until zone0 completes managed shutdown.

Motivation

The existing VirtIO PCI frontend needs matching RNG and block backends in the monorepo. The frontend and monorepo import landed in #287 (#287) and #429 (#429).

During integration testing, sustained guest I/O filled the request ring. The frontend held the bridge lock while waiting for a free slot, and the backend needed that lock to report completions. The updated wait and completion paths let the backend make progress under queue pressure.

Compatibility and rollout

  • Tested 4f0cbe2 against base aefa166. Build and deploy hvisor, hvisor.ko, and the CLI together from the same monorepo revision. Roll back all three together.
  • Keep the one-page bridge and 32 data-request slots. The PCI protocol moves to version 2. The module checks the protocol before bridge registration and the userspace worker checks it before processing requests.
  • Hypercall 7 gains bridge teardown, version discovery, RAM resolution, and zone-instance liveness queries. The driver/CLI interface adds bridge, completion, RAM resolution, and I/O lease ioctls. VirtIO PCI zones require a drained-backend acknowledgement on the zone shutdown hypercall.
  • The backend is enabled on AArch64 when both PCI backend IRQ nodes are present. The matching hvisor-tool code is included in the same PR.

Verification

The following commands passed on the tested revision. AARCH64_CROSS is the Arm GNU 10.3.1 cross-compiler prefix and LINUX_54 points to the configured AArch64 Linux 5.4 source tree used to build the module.

cargo fmt --all -- --check
make BID=aarch64/qemu-gicv3 -j4
make BID=aarch64/qemu-gicv3 clippy
make -C hvisor-tool/tools ARCH=arm64 CROSS_COMPILE="$AARCH64_CROSS" LOG=LOG_INFO -j4 all
make -C hvisor-tool/driver ARCH=arm64 CROSS_COMPILE="$AARCH64_CROSS" KDIR="$LINUX_54" -j4 all

A local QEMU AArch64/GICv3 harness used one non-root Linux zone with two vCPUs, identity-mapped RAM, an MMIO console, and a VirtIO PCI block root disk. It loaded the module with virtio_pci_blk_image_path, started the daemon with hvisor virtio start virtio.json, and checked zone state with hvisor zone list before and after shutdown. The harness tested these module settings.

Backend mode Module parameters in addition to the image path Result
Kernel Defaults 6 lifecycle cycles passed
Userspace virtio_pci_userspace_blk=1 virtio_pci_userspace_rng=1 6 lifecycle cycles and guest-initiated power-off passed
Mixed virtio_pci_userspace_rng=1 6 lifecycle cycles passed
  • Each cycle booted from PCI block, read from /dev/hwrng, wrote and read back 128 × 4 KiB, and observed ITS-MSI interrupts for RNG and block. It then kept direct block reads running while initiating shutdown.
  • A controlled I/O lease verified that shutdown waited, rejected new leases during the drain, and completed after explicit lease release or file descriptor close. The userspace block image descriptor closed after cleanup. Each retired zone instance failed subsequent DMA resolution.
  • The first cycle in each mode ran RAM-resolution boundary checks through the zone0 driver. Valid ranges at both boundaries passed. Empty, out-of-bounds, cross-boundary, overflowing, wrong-zone, and stale-instance ranges returned EFAULT.

Risks and limitations

  • The drain gate is global. Shutting down one PCI zone can pause backend I/O for other zones. If a liveness query keeps failing during cleanup, the userspace backend stops processing requests until the query succeeds.
  • The module has one block image path. Block devices using that setting open the same image. Validation used a single block device and a single non-root zone.
  • Multi-zone mixed-mode stress, non-identity mappings, malformed descriptors through the guest datapath, mixed-version boot, deliberately injected late IPIs, the repository's make test target, and physical boards are unverified. VirtIO PCI Console is outside this PR's scope.
  • The matching hvisor-book instructions and examples have not been verified or updated. Contributor review of the AI-assisted changes remains pending.

Port the kernel and userspace backends into the monorepo while preserving the one-page bridge ABI. Coalesce repeated queue kicks, release the bridge lock while waiting, and deliver MSI-X when the matching request completes.

Validated on AArch64 QEMU/GICv3 in kernel, userspace, and mixed backend modes.
Bind bridge requests to a zone instance and validate complete DMA ranges before either backend accesses guest RAM. Negotiate bridge protocol v2 before registration.

Drain admitted backend requests before zone teardown, reclaim PCI device slots and block image handles, and ignore MSI-X completions on stopped or shutting-down vCPUs.

Validated on AArch64 QEMU/GICv3 in kernel, userspace, and mixed modes with six lifecycle cycles per mode, RAM range checks, and a userspace guest power-off scenario.
@github-actions github-actions Bot added aarch64 feature New feature or request labels Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aarch64 feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant