Repository navigation
[libcpu][risc-v] Fix PLIC completion order in non-DM mode - #12011
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: libcpu_riscvReviewers: @Yaochenger Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-11-09 23:37 CST)
📝 Review Instructions
|
handler_plic_irq() completes a claimed interrupt before dispatching its handler. If a level-triggered source is still asserted at completion time, the PLIC gateway forwards the request again, so the same interrupt can be dispatched twice. Run the handler first, then complete. Completing after the handler means a handler may have masked its own source; the PLIC ignores a completion for an interrupt that is not enabled for the target, so temporarily enable the source around the completion, as the Linux SiFive PLIC driver does. Link: RT-Thread#12010
9afba5f to
843ac9d
Compare
|
BernardXiong
left a comment
There was a problem hiding this comment.
Verdict: the fix is sound; no blocking issue found.
Verified:
handler_plic_irq()now dispatches the handler beforeplic_irq_ack_or_eoi(), so an asserted level source cannot be re-dispatched before the handler has run.- Completion of a masked source is only ignored when the enable bit is clear; temporarily setting and restoring the bit under
enable_lockwith IRQs saved matches the PLIC rule and keeps the window interrupt-safe. - The DM path uses the same helper (
irq_ackfor edge before dispatch,irq_eoifor level after), so the ordering change is scoped and consistent. - CI: 107 pass / 3 skipping. The non-DM path is not covered by CI, as noted in the PR description.
Non-blocking: the fast path reads this hart's enable register without enable_lock (pic-sifive-plic.c#L187). In DM mode plic_irq_mask() clears enable bits on every CPU in the affinity set, so a concurrent mask targeting this hart between that read and the completion write can make the completion silently ignored — the same failure mode this patch fixes. Taking the lock on both paths (or re-checking after taking it) removes the race at the cost of one irqsave in the common path.
拉取/合并请求描述:(PR description)
为什么提交这份PR (why to submit this PR)
In non-DM mode, handler_plic_irq() completes a PLIC interrupt before calling its handler. For level-triggered sources, this can cause duplicate interrupts if the source is still asserted.
Fixes #12010. Related to #11305.
你的解决方案是什么 (what is your solution)
请提供验证的bsp和config (provide the config and bsp)
bsp/qemu-virt64-riscvwith its default DM config for build/boot regression. It does not build the non-DM path, so the non-DM tests used a temporary out-of-tree M-modeqemu-system-riscv64 -M virtBSP (not included in this PR).CONFIG_ARCH_RISCV=y,CONFIG_ARCH_RISCV64=y,CONFIG_ARCH_RISCV_M_MODE=y,CONFIG_RT_USING_RISCV_NEW_COMMON=y, withCONFIG_RT_USING_DMandCONFIG_RT_USING_SMPnot set. DM regression used the unmodifiedbsp/qemu-virt64-riscv.config.验证结果 (Validation)
-d exectracing confirms the masked-source completion branch executes, not just compiles.bsp/qemu-virt64-riscvbuilds, boots through OpenSBI to RT-Thread, reachesmsh, andhelpover the UART works.实机验证 (Hardware validation, 2026-11-09)
PIC_DISABLE_DM, no SMP), BSPbsp/artinchip/d213-demo128-nand, non-DM common PLIC path.GE_STATUS. With the original order, every GE operation was dispatched twice on silicon: the first IRQ readGE_STATUS=0x31, the immediate duplicate readGE_STATUS=0x00. The duplicate overwrote the completion status, soge_start_and_wait()took its timeout path (256-register dump + engine reset) even though the operation had completed; onege_testcommand took about 1.8 s, dominated by the UART dump.[aic] ge timeouton every step.ge_test20/20 PASS (fillrect, bitblt, 2x scale, alpha blend, 90-degree rotate, pixel-checked), zeroge timeout, 124-125 ms per cycle.bsp.d213.*utest 15/16 PASS, only the pre-existing pure-BSP FPU context known-failure, andge_test20/20 PASS (123-127 ms per cycle).未覆盖的场景与剩余风险 (Not covered / remaining risks)
hw/intc/sifive_plic.cdoes not model gateway re-forwarding of an asserted level source on completion, nor ignoring completion for a disabled source. It cannot A/B the original duplicate dispatch; the runs above validate the non-DM path and the workaround execution, not the duplicate itself.fence o,ois added around the completion. RT-ThreadHWREG32does not have the ordering semantics of Linuxwritel(), so ordering with the device write relies on the platform interconnect and is unverified on hardware.handler_irq()passes the rawhwirqto handlers while install/umask use the framework vector. This is pre-existing and intentionally unchanged.当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up