riscv-software-src / riscv-software-src/opensbi

Incorrect AIA mtopi handling without an IMSIC

Open
#387 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
1.5k
Forks
712
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in the local RVVM branch with AIA support enabled, IMSIC and APLIC/PLIC toggled off, and legacy CLINT IPI in use. Trace OpenSBI's handling of the unhandled local interrupt and the mtopi/stopi versus mtopei/stopei CSR distinction; done means this configuration no longer crashes while remaining consistent with the RISC-V AIA specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.