Skip to content

fix(loongarch64): repair IRQ delivery and SMP zone startup - #365

Draft
li041 wants to merge 14 commits into
syswonder:devfrom
li041:fix-interrupt-la
Draft

fix(loongarch64): repair IRQ delivery and SMP zone startup#365
li041 wants to merge 14 commits into
syswonder:devfrom
li041:fix-interrupt-la

Conversation

@li041

@li041 li041 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • fix LoongArch interrupt/IPI state handling and per-line virtio IRQ deassertion
  • harden LoongArch PCI configuration and SR-IOV initialization
  • restore the LS3A6000 root/non-root memory layout and current root kernel entry
  • support two-vCPU non-root zones with dense guest CPU IDs
  • support Python 3.10 in the Kconfig bootstrap environment

Validation

  • built with make ARCH=loongarch64 BOARD=ls3a6000 MODE=debug all
  • booted the root Linux 6.11.6 zone on physical CPUs 0-1
  • started linux1 on physical CPUs 2-3
  • logged into linux1 through the virtio console and verified both guest CPUs
  • exercised virtio IRQ assertion/deassertion on the LS3A6000 board

li041 and others added 14 commits July 21, 2026 16:24
Keep per-CPU events in a FIFO and coalesce physical IPI doorbells so queued work is not discarded. Align guest wakeup with the smp-la VcpuState lifecycle.
Merge guest IPI action bits, publish blocking sends before return, and keep the virtual IPI line asserted until all pending actions are cleared.
Maintain asserted HWI bits per physical CPU, update only GINTC.VIP, preserve PIP and HC, and remove timer-driven global injection cleanup.
Route the clear-inject hypercall through zone and IRQ arguments so concurrent guest HWI lines are not cleared together.
Use the LoongArch split-offset mapping consistently for device discovery and direct MMIO access. Perform sub-dword configuration accesses through aligned 32-bit read-modify-write operations, and retain each bridge own configuration base for later bridge control updates.

Co-authored-by: ZhongkaiXu <3605832858@qq.com>
Configure the supported system page size, reset and latch VF routing fields, and enable upstream ARI forwarding before exposing VFs. Use the actual routed VF count and avoid creating disabled VFs.

Co-authored-by: ZhongkaiXu <3605832858@qq.com>
@github-actions github-actions Bot added loongarch64 bug Something isn't working labels Jul 21, 2026
@li041
li041 marked this pull request as draft July 21, 2026 12:31
@li041

li041 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

This draft PR is intended only as a temporary reference and for validation. It is not intended to be merged in its current form. The related changes will be split into multiple focused PRs and submitted separately for review.

@DaisyRLight

Copy link
Copy Markdown

I noticed that you seem to be using only 4 cores during SMP debugging. If so, board-level configurations and CPU-related code will need to be modified.
The guest Linux VM encounters issues when restarted after shutdown, which appears to be interrupt-related—such as problems with interrupt cleanup and the timer.

@DaisyRLight

Copy link
Copy Markdown

During testing, I triggered the following error. On the surface, it appears to be a page fault occurring on a secondary core; however, this issue has only been observed once so far.

[ERROR 5] (hvisor::panic:24) panic occurred: PanicInfo {
payload: Any { .. },
message: Some(
unhandled instruction: 0b110010000000000010110001100/0x640058c,
),
location: Location {
file: "src/arch/loongarch64/trap.rs",
line: 524,
col: 17,
},
can_unwind: true,
force_no_backtrace: false,
}
[ERROR 7] (hvisor::panic:24) panic occurred: PanicInfo {
payload: Any { .. },
message: Some(
unhandled instruction: 0b110010000000000010110001100/0x640058c,
),
location: Location {
file: "src/arch/loongarch64/trap.rs",
line: 524,
col: 17,
},
can_unwind: true,
force_no_backtrace: false,
}

@li041

li041 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

During testing, I triggered the following error. On the surface, it appears to be a page fault occurring on a secondary core; however, this issue has only been observed once so far.

Thanks for the report! I appreciate you bringing this up.
I have not encountered this issue in my testing so far, so it would be very helpful if you could provide a stable reproduction method or any additional details (e.g., workload, boot configuration, or timing conditions) that can help reproduce it.
I will investigate further once there is a reliable way to trigger the issue.

@li041

li041 commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback!

I noticed that you seem to be using only 4 cores during SMP debugging. If so, board-level configurations and CPU-related code will need to be modified.

The board-level configuration and CPU-related code need to be adjusted when using a different number of cores. The corresponding SDK and JSON configuration files also need to be updated accordingly. The configuration details can be found in the hvisor doc.

The guest Linux VM encounters issues when restarted after shutdown, which appears to be interrupt-related—such as problems with interrupt cleanup and the timer.

For the guest Linux VM restart issue after shutdown, I will investigate it further, especially the interrupt cleanup and timer-related parts. Thanks for pointing this out.

Comment on lines 153 to 167
pub fn cpu_start(cpuid: usize, start_addr: usize, opaque: usize) {
let start_addr = start_addr & 0x0000_ffff_ffff_ffff;
let ipi: &MMIODerefWrapper<IpiRegisters> = match cpuid {
1 => &CORE1_IPI,
2 => &CORE2_IPI,
3 => &CORE3_IPI,
_ => {
panic!("loongarch64: cpu_start: invalid cpuid={}", cpuid);
}
};
ipi.ipi_enable.write(IpiEnable::IPIENABLE.val(0xffffffff));
let entry_addr = start_addr;
mail_send(entry_addr, cpuid, 0);
ipi_write_action(cpuid, SMP_BOOT_CPU);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This implementation currently hardcodes IPIs for cores 1–3, which limits SMP support to exactly 4 cores and doesn't scale with CONFIG_NR_CPUS.
Additionally, the _ => panic!() clause makes the function brittle.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this issue. The hardcoded IPI mapping problem and the limitation to only 4 cores have already been fixed in #368.

The new implementation supports scalable SMP startup based on the configured CPU count. Thanks again for the helpful review.

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

Labels

bug Something isn't working loongarch64

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants