refactor(somehal): modernize x86 qemu irq routing#1430
Merged
Conversation
This was referenced Jun 29, 2026
Merged
Contributor
There was a problem hiding this comment.
PR #1430 审查意见
变更概述
本 PR 重构了 somehal x86 QEMU 中断路由层,将原来散落在 mod.rs 中的 LAPIC/x2APIC 逻辑拆分为独立的 lapic.rs 和 vector.rs 模块,移除了全局原子旁路表 VECTOR_ROUTES / IOAPIC_GSI_ROUTES 和外部 bypass API set_ioapic_gsi_enabled_from_irq,使 IOAPIC 操作统一经过 rdif_intc::Intc 锁路径。
实现逻辑
- 模块拆分:
lapic.rs封装 EOI、IPI 发送(运行时区分 x2APIC MSR / xAPIC MMIO);vector.rs封装 vector→IrqId 映射和保留 vector 校验。X86IoApicIntc内部新增vector_routes: Vec<(usize, IrqId)>替代全局原子表。 - x2APIC 支持:
someboot和somehal均运行时检测IA32_APIC_BASE.X2APIC_ENABLE,x2APIC 保留完整 u32 APIC ID,xAPIC 对 >0xFF ID 返回InvalidCpu错误,避免静默截断。 - IPI 超时:
someboot::send_ipi和somehal::lapic均增加IPI_DELIVERY_WAIT_SPINS有限等待,超时返回Err。axipi::run_on_cpu_sync_raw()使用Arc替代裸指针并增加SYNC_IPI_SPIN_LIMIT超时。 - IRQ 上下文保护:
registry::enable在 per-CPU 远程 enable 前检查in_irq_context(),返回InIrqContext,避免 IRQ 中等待 IPI 导致死锁。 - AxVM 统一路径:
host/irq.rs中set_ioapic_gsi_enabled_from_irq简化为set_host_irq_enable,通过ax_hal::irq::set_enable走标准IrqIdenable 路径。 - 未知 vector 处理:
begin_irq对未路由的 vector 发送 EOI 并记录 warning,不再静默分发为 CPU-local IRQ(旧行为可能导致错误处理)。
测试与验证
cargo fmt --check✅cargo test -p somehal arch::tests::(12 tests)✅cargo test -p someboot(16+3 tests)✅cargo test -p irq-framework --test std_sim(36 tests,含新增remote_per_cpu_enable_from_irq_context_is_rejected_without_ipi)✅cargo test -p ax-ipi sync_call_wait(2 tests)✅cargo clippy -p somehal / irq-framework / ax-ipi均无 warning ✅
CI 状态
head sha 6125f754 的 CI 运行中,Test axvisor x86_64 svm hosted / run_host 为 success,其余多个 job(starry qemu、arceos qemu、loongarch64、riscv64、board、axloader 等)为 skipped,属于 CI 路径过滤和 run_host/run_container 互斥的预期行为,不影响本 PR 变更表面的覆盖判断。
重复与重叠分析
搜索了 dev 分支上的其他 open PR,#1417(net-bench)、#1432(ax-net rx wake 修复)、#1076 等均与本 PR 的 x86 IRQ 中断层重构无重叠。
未解决事项
无阻塞问题。本 PR 无 [patch.crates-io],无合并冲突,测试覆盖充分,CI 已通过相关路径。
Powered by mimo-v2.5-pro
Closed
luodeb
pushed a commit
that referenced
this pull request
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
当前 x86 QEMU 动态平台的中断路径仍混有一些旧式假设:外部 GSI 可以绕过
rdif_intc::Intc直接改 IOAPIC,trap vector 和 GSI 之间存在全局原子旁路表,LAPIC IPI 发送缺少超时,xAPIC APIC ID 也存在潜在截断风险。这些行为和 GIC 风格的“外部中断控制器 / CPU 本地接口”分层不一致,在多核和虚拟化场景下更容易形成锁等待或路由状态不一致。修改内容
somehalx86 中断层,拆出lapic和vector模块:X86IoApicIntc集中持有 ACPI GSI route、vector route 和 destination 状态。VECTOR_ROUTES/IOAPIC_GSI_ROUTES全局原子旁路表,以及set_ioapic_gsi_enabled_from_irq这类外部 bypass API。rdif_intc::Intccontroller 锁修改,避免 axhal/axplat-dyn/AxVM 直接改 GSI。u32APIC ID。somebootx86 AP 启动和 LAPIC timer 初始化同步支持 x2APIC。axipi::run_on_cpu_sync_raw()增加超时返回;irq-framework禁止在 IRQ 上下文中触发远程 per-CPU 同步 enable/disable,避免互等死锁。IrqId的正常 enable 路径。arch-platform-porting技能文档,记录现代 x86 QEMU IRQ 契约。验证
cargo fmtcargo test -p somehal arch::tests::cargo test -p somebootcargo test -p irq-framework --test std_simcargo test -p ax-ipi sync_call_waitcargo xtask clippy --package somehalcargo xtask clippy --package somebootcargo xtask clippy --package irq-frameworkcargo xtask clippy --package ax-ipicargo xtask clippy --package ax-halcargo xtask clippy --package axplat-dyncargo xtask clippy --package ax-runtimecargo xtask clippy --package axvmcargo xtask arceos test qemu --arch x86_64 --test-group rust --test-case task-ipicargo xtask starry test qemu --arch x86_64 --test-case qemu-smp4/system