Skip to content

refactor: post x86 and RISC-V virtio IRQs directly and remove VIRTIO_IRQS - #449

Draft
peikachu wants to merge 3 commits into
peikachu/percpu-events/stage4from
peikachu/percpu-events/stage4-2
Draft

peikachu wants to merge 3 commits into
peikachu/percpu-events/stage4from
peikachu/percpu-events/stage4-2

Conversation

@peikachu

@peikachu peikachu commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Finishes moving virtio IRQs off PERCPU_EVENTS (follow-up to #407, #415, #438 and #448). On x86 and RISC-V, the CPU that produces a virtio IRQ now updates the target zone's virtual interrupt controller directly, and VIRTIO_IRQS and the two virtio events are removed.

  • refactor(x86_64): pulse the root virtio wakeup on the vIOAPIC directly
    • New ioapic_pulse(zone_id, irq, allow_repeat) -> bool pulses the pin and delivers the vector under the zone's IoApicState lock. The root wakeup uses it instead of sending IPI_EVENT_WAKEUP_VIRTIO_DEVICE. Inject and deassert already use ioapic_set_line() since fix(x86_64): model virtual IOAPIC interrupt lines #410.
    • inject_vector() is renamed post_guest_vector().
  • refactor(zone): share the IRQ lifecycle lock between riscv64 and x86_64
    • X86_IOAPIC_LIFECYCLE becomes ZONE_IRQ_LIFECYCLE in zone.rs, also enabled on riscv64. The lock is private and only reachable through two guards: IrqPostGuard (read) and IrqLifecycleGuard (write).
    • Functions that post into another zone's virtual irqchip (ioapic_pulse(), ioapic_set_line()) take &IrqPostGuard; ioapic_reset() and arch_irqchip_reset() take &IrqLifecycleGuard, so skipping the lock does not compile.
    • Zone start takes the write lock before zone_create(); shutdown holds it from arch_irqchip_reset() to remove_zone(). aarch64 and LoongArch do not take it.
  • refactor(riscv64): pulse virtio IRQs directly and remove VIRTIO_IRQS
    • New plic::vplic_pulse() and aia::vaplic_pulse() raise a software IRQ in a given zone from any CPU. hv_virtio_inject_irq() and the root wakeup use them; hv_virtio_inject_irq() drops the IRQ with a warning if the target zone or IRQ no longer exists.
    • AIA's VAPLIC_MAP and MSI_PT_MAP move from static mut to spin::Mutex, so the vAPLIC MMIO handler no longer reads the map unguarded.

Motivation

On x86 and RISC-V, virtio IRQs still went through the event FIFO, and RISC-V also queued them in VIRTIO_IRQS under a global lock, only for the target CPU to inject them into its own vPLIC/vAPLIC. All three controllers can be updated from any CPU (the vPLIC through post_guest_irq() since #438, the vAPLIC through the IMSIC guest file, the vIOAPIC through post_guest_vector()), so the queue, the extra IPI and the per-CPU lists are unnecessary. Both architectures need the same guard against zone start/shutdown, so they share one lock.

Verification

Platform What was run Result
riscv64 qemu-plic, qemu-aia; aarch64 qemu-gicv3 zone0 load → insmod hvisor.ko → virtio backend → zone start → zone1 shell and load → zone shutdown -id 1 → zone0 load Passed
aarch64 qemu-gicv2 Same flow without zone shutdown (GICv2 arch_irqchip_reset() is unimplemented) Passed
x86_64 qemu (KVM) Same full flow, plus zone1 virtio-blk reads with a console flood Passed

No hypervisor panic or ERROR logs. Each commit builds on all six boards (qemu-gicv3/gicv2/plic/aia, ls3a5000, x86_64 qemu) with no new warnings and passes cargo fmt --all -- --check.

Risks and Limitations

  • spin's RwLock prefers readers, so heavy virtio traffic can delay zone start or shutdown.
  • Some events still use the event FIFO. The pinned pCPU:vCPU mapping is unchanged.

@peikachu
peikachu added this pull request to stack #450 November 25, 2026 10:15
@peikachu
peikachu marked this pull request as draft November 25, 2026 10:17
Comment thread src/zone.rs Outdated
Comment on lines +826 to +829
/// Serializes IRQ producers targeting a zone's virtual irqchip with zone start and shutdown.
/// Producers take it for reading; start and shutdown take it for writing, before any `ctrl_lock`.
#[cfg(any(target_arch = "riscv64", target_arch = "x86_64"))]
pub static ZONE_IRQ_LIFECYCLE: RwLock<()> = RwLock::new(());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main issue with ZONE_IRQ_LIFECYCLE is that acquiring this lock is entirely the caller's responsibility. It's a standalone pub static, so any code that wants to touch a zone's virtual irqchip or start/shutdown a zone can simply... not take the lock, and nothing stops it.

Idiomatic Rust tries to make the invariant impossible to violate by construction rather than documented. The usual pattern is to move the guarded state behind a type that owns the lock, so the only way to reach the state is through a method that takes the lock for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants