Skip to content

refactor(riscv64/plic): replace IPI_EVENT_UPDATE_HART_LINE with a VSEIP level line - #438

Merged
li041 merged 1 commit into
syswonder:devfrom
peikachu:refactor/remove-percpu-events-stage3
Nov 25, 2026
Merged

li041 merged 1 commit into
syswonder:devfrom
peikachu:refactor/remove-percpu-events-stage3

Conversation

@peikachu

Copy link
Copy Markdown
Collaborator

Summary

Continues removing PERCPU_EVENTS (follow-up to #407 and #415). The RISC-V vPLIC no longer sends IPI_EVENT_UPDATE_HART_LINE to update a remote hart's external interrupt line. Instead, it posts VSEIP as a level line on the target vCPU, using the level-line support added in #415.

  • RISC-V GUEST_LINES = &[IRQ_VS_EXT] (VSEIP, hvip bit 10). flush_guest_irqs() writes dirty lines to hvip (set_vseip/clear_vseip) before raising posted edge IRQs.
  • VirtualPLIC::update_hart_line() computes vplic_get_next_pending(vcontext) != 0 and calls post_guest_irq(pcpu, IRQ_VS_EXT, None, Level(..)). It runs under the vPLIC inner lock, so the last posted level always matches the latest vPLIC state. Local and remote targets now take the same path.
  • VirtualPLIC stores the zone's pCPU list at creation. vcontext ↔ pCPU/pcontext conversion now uses that list. Previously, every call collected cpu_set() into a Vec and read it from this_cpu_data().
  • Removed: the direct hvip write for local targets, send_event(IPI_EVENT_UPDATE_HART_LINE), plic::update_hart_line(), the free functions vcontext_to_pcontext()/pcontext_to_vcontext(), the arch_check_events() branch and the IPI_EVENT_UPDATE_HART_LINE constant.
  • plic::inject_irq() drops the IRQ with a warning when the current CPU is not in the zone. Previously the lookup fell back to vcontext 0.

AIA is not affected.

Motivation

The vPLIC output to a hart is a level signal. Sending it through the event FIFO means taking the queue lock, possibly allocating, and dispatching through arch_check_events() just to recompute the line on the target. Posting the level on the target vCPU publishes the state first and then kicks the target. Repeated updates to an unchanged level do not kick again.

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 up to the zone1 load; zone shutdown not run (GICv2 arch_irqchip_reset() is unimplemented). Passed
riscv64 qemu-plic, remote hart line zone1 virtio0 smp_affinity set to its second CPU, then 3 rounds of virtio-blk O_DIRECT reads (1 MiB × 64, 4 KiB × 2000) and a 4-process load. virtio0 took 6,221 interrupts on the second CPU Passed

All runs had no hypervisor panic and no ERROR logs. cargo fmt --all -- --check passes.

"Load" runs more shell busy-loop processes than the zone has vCPUs (8 in zone0, 4 in zone1).

Risks and Limitations

  • Virtio IRQs, LoongArch HWI, DWC MSI and virtio-pci events still use the legacy FIFO.
  • The pinned pCPU:vCPU mapping is unchanged.

Comment thread src/event.rs Outdated
true
}
Some(IPI_EVENT_CLEAR_INJECT_IRQ) | Some(IPI_EVENT_UPDATE_HART_LINE) => {
Some(IPI_EVENT_CLEAR_INJECT_IRQ) => {

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.

Is this path still needed?

Now I can't find any producer of IPI_EVENT_CLEAR_INJECT_IRQ in the tree. The HvClearInjectIrq hypercall goes through hv_virtio_deassert_irq(), which updates the IRQ line directly and never calls send_event().

On RISC-V, arch_check_events() is now just a panic!(), so if this event were ever queued, hvisor would panic instead of handling or ignoring it.

Since the event appears unused, can we remove IPI_EVENT_CLEAR_INJECT_IRQ and its dispatch branch in this PR? That would also let us drop arch_check_events() entirely on RISC-V.

@agicy

agicy commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

By the way, I noticed this is stage 3 of the refactor/remove-percpu-events series. Since GitHub stacked PRs are available now, could we use this feature on this PR series?

Using a stack would keep this PR's review diff limited to stage 3 while making the later work and its dependencies easier to track. When this PR changes, GitHub can also retarget and rebase the downstream PRs automatically, as long as there are no conflicts.

@peikachu

Copy link
Copy Markdown
Collaborator Author

By the way, I noticed this is stage 3 of the refactor/remove-percpu-events series. Since GitHub stacked PRs are available now, could we use this feature on this PR series?

Using a stack would keep this PR's review diff limited to stage 3 while making the later work and its dependencies easier to track. When this PR changes, GitHub can also retarget and rebase the downstream PRs automatically, as long as there are no conflicts.

Good suggestion. I will try it next time.

@agicy
agicy requested a review from liulog November 23, 2026 04:16
Comment thread src/device/irqchip/plic/vplic.rs Outdated
Comment on lines 320 to 321
let irq_id = value;
if inner.hw[value] {

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.

Guest-controlled value is used as a BitVec index without a bounds check (hw/active are sized max_interrupts + 1), so any out-of-range store to the complete register (e.g. sw 0xffffffff, 0x200004) panics the hypervisor; mirror the priority-arm guard at line 185:

Suggested change
let irq_id = value;
if inner.hw[value] {
let irq_id = value;
if irq_id == 0 || irq_id > self.max_interrupts {
error!("vplic_complete_access: invalid interrupt ID: {}", irq_id);
return 0;
}
if inner.hw[irq_id] {

@li041 li041 left a comment

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.

LGTM! Only a small nit inherits from previous code.

@peikachu
peikachu force-pushed the refactor/remove-percpu-events-stage3 branch from 1c896c1 to e6746a4 Compare November 25, 2026 02:56
@li041
li041 merged commit aefa166 into syswonder:dev Nov 25, 2026
29 of 32 checks passed
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.

4 participants