LekKit / RVVM

The RISC-V Virtual Machine
GNU General Public License v3.0
866 stars 60 forks source link

RV32 U-Mode JIT is nonconformant and slow on ctx switch #133

Open LekKit opened 5 months ago

LekKit commented 5 months ago

The issue

Steps to reproduce

Investigation

LekKit commented 5 months ago

No CSR access is happening in rv32 umode (at least not before it crashes). I'd assume kernel never uses smth like rv32 S-mode so S-mode CSRs can't be messed up this way.

SV32 MMU doesn't seem to be used at all.

LekKit commented 5 months ago

Sign-extending or zero-extending rv32 VA pointers in SV39/SV48 translation doesn't help.

The kernel always faults on some magical address 0x3803b0af8. Perhaps this could lead debugging somewhere.

LekKit commented 5 months ago

Crashes are caused by riscv_handle_irqs() in RV32 U-Mode. Using a workaround that disables IRQs when hart is in rv32 mode & disabling RVJIT allows RV32 Buildroot to boot properly on RV64 kernel.

This is due to invalid IRQ mask computed for origin priv_mode and not the one we are switched into on IRQ.

LekKit commented 5 months ago

Fixed the interpreter side in 8aef67b

LekKit commented 5 months ago

RV32 U-Mode somewhat works with JIT since e108450. Note it still isn't spec conformant (RVJIT should sign-extend 32-bit results to 64-bit register, but doesn't now). Performance is pretty low since the JIT cache is flushed on each XLEN change.