Skip to content

riscv64: install legacy serial irqchip via set_intc#591

Merged
slp merged 1 commit intocontainers:mainfrom
yzewei:vmm-rv
Mar 25, 2026
Merged

riscv64: install legacy serial irqchip via set_intc#591
slp merged 1 commit intocontainers:mainfrom
yzewei:vmm-rv

Conversation

@yzewei
Copy link
Copy Markdown
Contributor

@yzewei yzewei commented Mar 17, 2026

Background

In the RISCv64 boot path, the legacy serial initialization chain is not synchronized, causing cargo check -p vmm --target riscv64gc-unknown-linux-gnu to fail to compile.

  1. The attach_legacy_devices() method in builder.rs calls a non-existent serial_device.

  2. The KVM MMIO serial registration logic for RISCv64 calls a non-existent serial.set_intc(intc). The current RISCv64 legacy serial does not provide this interface; its interrupt triggering path depends on the registered IRQFD, rather than actively injecting interrupts through the interrupt controller held by the serial device as in Aarch64.

@yzewei
Copy link
Copy Markdown
Contributor Author

yzewei commented Mar 17, 2026

PTAL

dorindabassey
dorindabassey previously approved these changes Mar 19, 2026
Copy link
Copy Markdown
Collaborator

@dorindabassey dorindabassey left a comment

Choose a reason for hiding this comment

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

LGTM

@mz-pdm
Copy link
Copy Markdown
Collaborator

mz-pdm commented Mar 20, 2026

It would be nice to put the PR description to the commit message.

@yzewei
Copy link
Copy Markdown
Contributor Author

yzewei commented Mar 23, 2026

It would be nice to put the PR description to the commit message.

done. PLZ

mz-pdm
mz-pdm previously approved these changes Mar 23, 2026
Copy link
Copy Markdown
Collaborator

@mz-pdm mz-pdm left a comment

Choose a reason for hiding this comment

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

Thank you for adding the commit message. It would be even better if the markup, namely the backslashes and the double quote at the end, were removed, but other than that the change looks good to me.

@yzewei
Copy link
Copy Markdown
Contributor Author

yzewei commented Mar 24, 2026

Thank you for adding the commit message. It would be even better if the markup, namely the backslashes and the double quote at the end, were removed, but other than that the change looks good to me.

got it.

Copy link
Copy Markdown
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

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

NAK. RISCV does have its own IrqChip abstraction, KvmAia. The serial device implementation should be updated to install it via set_intc and make use of it for triggering interrupts.

@yzewei
Copy link
Copy Markdown
Contributor Author

yzewei commented Mar 25, 2026

NAK. RISCV does have its own IrqChip abstraction, KvmAia. The serial device implementation should be updated to install it via set_intc and make use of it for triggering interrupts.

I updated the RISC-V serial path, installed the irqchip via set_intc() during MMIO registration, and routed interrupt signals via IrqChip::set_irq().

@yzewei yzewei dismissed stale reviews from dorindabassey and mz-pdm via fd4e7d5 March 25, 2026 01:52
@yzewei yzewei changed the title vmm: fix riscv64 legacy serial MMIO setup riscv64: install legacy serial irqchip via set_intc Mar 25, 2026
RISC-V already has a dedicated irqchip abstraction in KvmAia, but the
legacy MMIO serial device was still signaling its interrupt EventFd
directly. That bypasses the installed interrupt controller instead of
using the same set_intc()/set_irq() path as the rest of the MMIO
interrupt plumbing.

Install the irqchip on the legacy RISC-V serial device during MMIO
registration, record the assigned IRQ line, and route interrupt delivery
through IrqChip::set_irq(). Keep the existing EventFd as the backing
interrupt source so the KVM irqfd registration remains unchanged.

This aligns the serial device with the existing RISC-V irqchip
abstraction and makes it use the interrupt controller configured by the
VMM.

Signed-off-by: Zewei Yang <yangzewei@loongson.cn>
@slp
Copy link
Copy Markdown
Collaborator

slp commented Mar 25, 2026

/gemini review

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates an IrqChip (Interrupt Controller Chip) for serial devices in the RISC-V64 legacy emulation, centralizing interrupt handling. The Serial struct now includes optional IrqChip and irq_line fields, with new methods set_intc and set_irq_line for configuration. The trigger_interrupt method has been updated to utilize the IrqChip if present. Corresponding changes in build_microvm and MMIODeviceManager ensure the IrqChip is properly passed and configured for serial devices. The review comments point out that using unwrap() on Mutex locks in both serial.rs and mmio.rs could lead to panics if the mutex becomes poisoned, suggesting a more robust error handling approach like expect() or explicit PoisonError handling.

Copy link
Copy Markdown
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@slp slp merged commit a9e04fd into containers:main Mar 25, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants