opensbi icon indicating copy to clipboard operation
opensbi copied to clipboard

Incorrect AIA mtopi handling without an IMSIC

Open LekKit opened this issue 9 months ago • 1 comments

The RISC-V AIA specification introduces a couple of new CSRs, and mandates that mtopei & stopei CSRs are ONLY present whenever there is AIA implemented, and an RISC-V IMSIC present in the system, but other CSRs may exist even without an IMSIC:

Image

OpenSBI apparently assumes that IMSIC must be present whenever mtopi CSR is available instead of mtopei... and crashes whenever the guest uses legacy CLINT for IPI.

[    0.103777] smp: Bringing up secondary CPUs ...

sbi_trap_error: hart0: trap0: unhandled local interrupt (error -1006)

sbi_trap_error: hart0: trap0: mcause=0x8000000000000003 mtval=0x0000000000000000
sbi_trap_error: hart0: trap0: mepc=0xffffffff80b4d2f8 mstatus=0x0000000a00000920
sbi_trap_error: hart0: trap0: ra=0xffffffff80b4d2ec sp=0xffffffc600003de0
sbi_trap_error: hart0: trap0: gp=0xffffffff82321198 tp=0xffffffff82325cc0
sbi_trap_error: hart0: trap0: s0=0xffffffc600003e10 s1=0xffffffff8235d3c8
sbi_trap_error: hart0: trap0: a0=0x000000000210f673 a1=0xffffffffffffffff
sbi_trap_error: hart0: trap0: a2=0x0000000000000015 a3=0x0000000000f5b338
sbi_trap_error: hart0: trap0: a4=0x0000000000000004 a5=0x000000000c800000
sbi_trap_error: hart0: trap0: a6=0x000000000200eeed a7=0xffffffff82786b60
sbi_trap_error: hart0: trap0: s2=0x0000000000000004 s3=0xffffffff8235d3c8
sbi_trap_error: hart0: trap0: s4=0x0000000000000000 s5=0x0000000000000000
sbi_trap_error: hart0: trap0: s6=0xffffffd602d50500 s7=0xffffffff80e00128
sbi_trap_error: hart0: trap0: s8=0x0000000000000000 s9=0x0000000000000001
sbi_trap_error: hart0: trap0: s10=0x0000000000000000 s11=0x0000000000000000
sbi_trap_error: hart0: trap0: t0=0x0000000000000040 t1=0x0000000000000000
sbi_trap_error: hart0: trap0: t2=0xffffffffffffffff t3=0x0000000000000002
sbi_trap_error: hart0: trap0: t4=0x0000000000000402 t5=0xffffffd602d53a68
sbi_trap_error: hart0: trap0: t6=0xffffffd602d53a70

This happens on a local RVVM branch that introduces RISC-V AIA support, and IMSIC+APLIC/PLIC supposed to be toggled, but AIA support in the CPU remains (That is, mtopi and stopi are still available, but mtopei / stopei are not).

Judging by the spec, it should be legal, but OpenSBI crashes unless I workaround it (By making mtopi unavailable too), so I think it is worth reporting.

LekKit avatar Feb 02 '25 19:02 LekKit

P.S. I also firmly believe an occasional invalid IRQ should not be able to bring the system down, but just print a warning, disable an interrupt and keep going. The same way Linux handles unexpected NMIs on x86 for example.

LekKit avatar Feb 02 '25 20:02 LekKit