Skip to content

refactor: post LoongArch HWI and aarch64 virtio IRQs through per-vCPU state - #448

Open
peikachu wants to merge 4 commits into
devfrom
peikachu/percpu-events/stage4
Open

peikachu wants to merge 4 commits into
devfrom
peikachu/percpu-events/stage4

Conversation

@peikachu

Copy link
Copy Markdown
Collaborator

Summary

Continues removing PERCPU_EVENTS (follow-up to #407, #415 and #438). Virtio IRQs on LoongArch and aarch64 no longer go through the event FIFO. The root CPU posts them to the target vCPU, which installs them on its next guest entry.

  • fix(zone): tolerate in-flight IRQ producers holding a removed zone: hv_virtio_inject_irq() and hv_virtio_deassert_irq() reuse the zone from their first find_zone(). Before, get_target_cpu() looked it up again and panicked if the zone had been removed in between. remove_zone() warns instead of asserting strong_count == 1, and the zone is freed on the last drop. Without the VIRTIO_IRQS lock, a producer may still hold the zone during shutdown.
  • refactor(loongarch64): model guest HWI as level lines: HWI0..=HWI7 (ESTAT.IS bits 2..=9) join INT_IPI in GUEST_LINES. Virtio inject, deassert and the root wakeup call the new ls7a2000::post_guest_hwi(). This replaces the per-pCPU GUEST_HWI_ASSERTED bitmap and its helpers, and LoongArch no longer uses the virtio events. HVISOR_VIPI_DOORBELL is renamed HVISOR_VIRQ_DOORBELL.
  • refactor(irqchip): share GIC INTID range helpers: GICv2 and GICv3 share SGI_RANGE, SPI_RANGE (32..1020), is_sgi() and is_spi(), plus is_lpi() on GICv3. These replace the per-driver helpers and literal comparisons. The only behavior change is that the GICv3 IRQ entry checks is_spi() || is_lpi() instead of > 31, so INTIDs 1020–1022 now hit the existing warning branch.
  • refactor(aarch64): post virtio IRQs as software SPIs: post_guest_irq() accepts SGIs and SPIs. Virtio responses and the root wakeup go through the new post_guest_spi().
    • On guest entry, GICv2 and GICv3 now install posted SPIs into software LRs, not just SGIs. As with SGIs, an LR that already holds the same vINTID absorbs the post (an active-only one becomes pending); otherwise the SPI takes a free LR.
    • On GICv2, virtio SPIs now use software LRs instead of HW=1 LRs.
    • VIRTIO_IRQS, handle_virtio_irq*() and the two virtio events are now compiled only for riscv64 and x86_64.

Hardware SPIs, PPIs and LPIs still use inject_irq() and PENDING_VIRQS.

Motivation

Every virtio IRQ went through the shared event FIFO: the root CPU took the queue lock, might grow the queue on the heap, and sent an IPI, only for the target to set a line or install an LR itself. aarch64 also kept the IRQs in VIRTIO_IRQS under a global lock, and LoongArch kept HWI lines in a separate per-pCPU bitmap. Posting to per-vCPU state, as virtual IPIs do since #407 and #415, removes that cost and the extra state, and takes the two virtio events off the FIFO on these architectures. HWI is a level signal held until the root deasserts it, so a level line models it directly and only kicks when the level changes.

Verification

Platform What was run Result
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 up to the zone1 load; zone shutdown not run (GICv2 arch_irqchip_reset() is unimplemented) Passed
loongarch64 ls3a5000 Build Builds and links; not run (no QEMU or hardware)

All runs had no hypervisor panic and no ERROR logs. Each commit builds on qemu-gicv3, qemu-gicv2, qemu-plic, qemu-aia, ls3a5000 and x86_64 qemu, and cargo fmt --all -- --check passes. "Load" runs more busy-loop processes than the zone has vCPUs.

Risks and Limitations

  • LoongArch is compile-tested only.
  • The pinned pCPU:vCPU mapping is unchanged.

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.

1 participant