Re: [PATCH v8 0/9] target/riscv: Add support for Smdbltrp and Ssdbltrp extensions
On Fri, Jan 10, 2025 at 10:55 PM Clément Léger wrote: > > A double trap typically arises during a sensitive phase in trap handling > operations — when an exception or interrupt occurs while the trap > handler (the component responsible for managing these events) is in a > non-reentrant state. This non-reentrancy usually occurs in the early > phase of trap handling, wherein the trap handler has not yet preserved > the necessary state to handle and resume from the trap. The occurrence > of such event is unlikely but can happen when dealing with hardware > errors. > > This series adds support for Ssdbltrp and Smdbltrp ratified ISA > extensions [1]. It is based on the Smrnmi series [5]. > > Ssdbltrp can be tested using qemu[2], opensbi (master branch), linux[3] and > kvm-unit-tests[4]. Assuming you have a riscv environment available and > configured (CROSS_COMPILE), it can be built for riscv64 using the > following instructions: > > Qemu: > $ git clone https://github.com/rivosinc/qemu.git > $ cd qemu > $ git switch -C dbltrp_v8 dev/cleger/dbltrp_v8 > $ mkdir build && cd build > $ ../configure --target-list=riscv64-softmmu > $ make > > OpenSBI: > $ git clone https://github.com/rivosinc/opensbi.git > $ cd opensbi > $ make O=build PLATFORM_RISCV_XLEN=64 PLATFORM=generic > > Linux: > $ git clone https://github.com/rivosinc/linux.git > $ cd linux > $ git switch -C dbltrp_v1 dev/cleger/dbltrp_v1 > $ export ARCH=riscv > $ make O=build defconfig > $ ./script/config --file build/.config --enable RISCV_DBLTRP > $ make O=build > > kvm-unit-tests: > $ git clone https://github.com/clementleger/kvm-unit-tests.git > $ cd kvm-unit-tests > $ git switch -C dbltrp_v1 dev/cleger/dbltrp_v1 > $ ./configure --arch=riscv64 --cross-prefix=$CROSS_COMPILE > $ make > > You will also need kvmtool in your rootfs. > > Run with kvm-unit-test test as kernel: > $ qemu-system-riscv64 \ > -M virt \ > -cpu rv64,ssdbltrp=true,smdbltrp=true \ > -nographic \ > -serial mon:stdio \ > -bios opensbi/build/platform/generic/firmware/fw_jump.bin \ > -kernel kvm-unit-tests-dbltrp/riscv/sbi_dbltrp.flat > ... > [OpenSBI boot partially elided] > Boot HART ISA Extensions : > sscofpmf,sstc,zicntr,zihpm,zicboz,zicbom,sdtrig,svadu,ssdbltrp > ... > ## > #kvm-unit-tests > ## > > PASS: sbi: fwft: FWFT extension probing no error > PASS: sbi: fwft: FWFT extension is present > PASS: sbi: fwft: dbltrp: Get double trap enable feature value > PASS: sbi: fwft: dbltrp: Set double trap enable feature value == 0 > PASS: sbi: fwft: dbltrp: Get double trap enable feature value == 0 > PASS: sbi: fwft: dbltrp: Double trap disabled, trap first time ok > PASS: sbi: fwft: dbltrp: Set double trap enable feature value == 1 > PASS: sbi: fwft: dbltrp: Get double trap enable feature value == 1 > PASS: sbi: fwft: dbltrp: Trapped twice allowed ok > INFO: sbi: fwft: dbltrp: Should generate a double trap and crash ! > > sbi_trap_error: hart0: trap0: double trap handler failed (error -10) > > sbi_trap_error: hart0: trap0: mcause=0x0010 > mtval=0x > sbi_trap_error: hart0: trap0: mtval2=0x0003 > mtinst=0x > sbi_trap_error: hart0: trap0: mepc=0x802000d8 > mstatus=0x800a01006900 > sbi_trap_error: hart0: trap0: ra=0x802001fc sp=0x80213e70 > sbi_trap_error: hart0: trap0: gp=0x tp=0x80088000 > sbi_trap_error: hart0: trap0: s0=0x80213e80 s1=0x0001 > sbi_trap_error: hart0: trap0: a0=0x80213e80 a1=0x80208193 > sbi_trap_error: hart0: trap0: a2=0x8020dc20 a3=0x000f > sbi_trap_error: hart0: trap0: a4=0x80210cd8 a5=0x802110d0 > sbi_trap_error: hart0: trap0: a6=0x802136e4 a7=0x46574654 > sbi_trap_error: hart0: trap0: s2=0x80210cd9 s3=0x > sbi_trap_error: hart0: trap0: s4=0x s5=0x > sbi_trap_error: hart0: trap0: s6=0x s7=0x0001 > sbi_trap_error: hart0: trap0: s8=0x2000 s9=0x80083700 > sbi_trap_error: hart0: trap0: s10=0x s11=0x > sbi_trap_error: hart0: trap0: t0=0x t1=0x80213ed8 > sbi_trap_error: hart0: trap0: t2=0x1000 t3=0x80213ee0 > sbi_trap_error: hart0: trap0: t4=0x t5=0x8020f8d0 > sbi_trap_error: hart0: trap0: t6=0x > > Run with linux and kvm-unit-test test in kvm (testing VS-mode): > $ qemu-system-riscv64 \ > -M virt \ > -cpu rv64,ssdbltrp=true,smdbltrp=true \ > -nographic \ > -serial mon:stdio \ > -bios opensbi/build/platform/generic/firmware/fw_jump.bin \ > -kernel linux/build
[PATCH v8 0/9] target/riscv: Add support for Smdbltrp and Ssdbltrp extensions
A double trap typically arises during a sensitive phase in trap handling operations — when an exception or interrupt occurs while the trap handler (the component responsible for managing these events) is in a non-reentrant state. This non-reentrancy usually occurs in the early phase of trap handling, wherein the trap handler has not yet preserved the necessary state to handle and resume from the trap. The occurrence of such event is unlikely but can happen when dealing with hardware errors. This series adds support for Ssdbltrp and Smdbltrp ratified ISA extensions [1]. It is based on the Smrnmi series [5]. Ssdbltrp can be tested using qemu[2], opensbi (master branch), linux[3] and kvm-unit-tests[4]. Assuming you have a riscv environment available and configured (CROSS_COMPILE), it can be built for riscv64 using the following instructions: Qemu: $ git clone https://github.com/rivosinc/qemu.git $ cd qemu $ git switch -C dbltrp_v8 dev/cleger/dbltrp_v8 $ mkdir build && cd build $ ../configure --target-list=riscv64-softmmu $ make OpenSBI: $ git clone https://github.com/rivosinc/opensbi.git $ cd opensbi $ make O=build PLATFORM_RISCV_XLEN=64 PLATFORM=generic Linux: $ git clone https://github.com/rivosinc/linux.git $ cd linux $ git switch -C dbltrp_v1 dev/cleger/dbltrp_v1 $ export ARCH=riscv $ make O=build defconfig $ ./script/config --file build/.config --enable RISCV_DBLTRP $ make O=build kvm-unit-tests: $ git clone https://github.com/clementleger/kvm-unit-tests.git $ cd kvm-unit-tests $ git switch -C dbltrp_v1 dev/cleger/dbltrp_v1 $ ./configure --arch=riscv64 --cross-prefix=$CROSS_COMPILE $ make You will also need kvmtool in your rootfs. Run with kvm-unit-test test as kernel: $ qemu-system-riscv64 \ -M virt \ -cpu rv64,ssdbltrp=true,smdbltrp=true \ -nographic \ -serial mon:stdio \ -bios opensbi/build/platform/generic/firmware/fw_jump.bin \ -kernel kvm-unit-tests-dbltrp/riscv/sbi_dbltrp.flat ... [OpenSBI boot partially elided] Boot HART ISA Extensions : sscofpmf,sstc,zicntr,zihpm,zicboz,zicbom,sdtrig,svadu,ssdbltrp ... ## #kvm-unit-tests ## PASS: sbi: fwft: FWFT extension probing no error PASS: sbi: fwft: FWFT extension is present PASS: sbi: fwft: dbltrp: Get double trap enable feature value PASS: sbi: fwft: dbltrp: Set double trap enable feature value == 0 PASS: sbi: fwft: dbltrp: Get double trap enable feature value == 0 PASS: sbi: fwft: dbltrp: Double trap disabled, trap first time ok PASS: sbi: fwft: dbltrp: Set double trap enable feature value == 1 PASS: sbi: fwft: dbltrp: Get double trap enable feature value == 1 PASS: sbi: fwft: dbltrp: Trapped twice allowed ok INFO: sbi: fwft: dbltrp: Should generate a double trap and crash ! sbi_trap_error: hart0: trap0: double trap handler failed (error -10) sbi_trap_error: hart0: trap0: mcause=0x0010 mtval=0x sbi_trap_error: hart0: trap0: mtval2=0x0003 mtinst=0x sbi_trap_error: hart0: trap0: mepc=0x802000d8 mstatus=0x800a01006900 sbi_trap_error: hart0: trap0: ra=0x802001fc sp=0x80213e70 sbi_trap_error: hart0: trap0: gp=0x tp=0x80088000 sbi_trap_error: hart0: trap0: s0=0x80213e80 s1=0x0001 sbi_trap_error: hart0: trap0: a0=0x80213e80 a1=0x80208193 sbi_trap_error: hart0: trap0: a2=0x8020dc20 a3=0x000f sbi_trap_error: hart0: trap0: a4=0x80210cd8 a5=0x802110d0 sbi_trap_error: hart0: trap0: a6=0x802136e4 a7=0x46574654 sbi_trap_error: hart0: trap0: s2=0x80210cd9 s3=0x sbi_trap_error: hart0: trap0: s4=0x s5=0x sbi_trap_error: hart0: trap0: s6=0x s7=0x0001 sbi_trap_error: hart0: trap0: s8=0x2000 s9=0x80083700 sbi_trap_error: hart0: trap0: s10=0x s11=0x sbi_trap_error: hart0: trap0: t0=0x t1=0x80213ed8 sbi_trap_error: hart0: trap0: t2=0x1000 t3=0x80213ee0 sbi_trap_error: hart0: trap0: t4=0x t5=0x8020f8d0 sbi_trap_error: hart0: trap0: t6=0x Run with linux and kvm-unit-test test in kvm (testing VS-mode): $ qemu-system-riscv64 \ -M virt \ -cpu rv64,ssdbltrp=true,smdbltrp=true \ -nographic \ -serial mon:stdio \ -bios opensbi/build/platform/generic/firmware/fw_jump.bin \ -kernel linux/build/arch/riscv/boot/Image ... [Linux boot partially elided] [0.735079] riscv-dbltrp: Double trap handling registered ... $ lkvm run -k sbi_dbltrp.flat -m 128 -c 2 ## #kvm-
