riscv64 EDK 2 crashes in KVM based emulation

Bug #2077731 reported by Heinrich Schuchardt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
edk2 (Ubuntu)
Status tracked in Oracular
Noble
New
Undecided
Unassigned
Oracular
New
Undecided
Unassigned
linux-meta-riscv (Ubuntu)
Status tracked in Oracular
Noble
New
Undecided
Unassigned
Oracular
New
Undecided
Unassigned

Bug Description

When running EDK2 as payload for QEMU using KVM a crash occurs in the VM:

$ qemu-system-riscv64 -M virt,acpi=off -accel kvm -m 4096 -nographic -drive if=pflash,format=raw,unit=0,file=RISCV_VIRT_CODE.fd,readonly=on -drive if=pflash,format=raw,unit=1,file=RISCV_VIRT_VARS.fd
!!!! RISCV64 Exception Type - 0000000000000002(EXCEPT_RISCV_ILLEGAL_INST) !!!!
     t0 = 0x00000000083FFFB28 t1 = 0x00000000083238BC8
     t2 = 0x00000000000000000 t3 = 0x00000000000000000
     t4 = 0x00000000000000000 t5 = 0x00000000000000000
     t6 = 0x00000000000000000 s0 = 0x00000000083FFFBC0
     s1 = 0x00000000000000000 s2 = 0x00000000000000000
     s3 = 0x00000000000000000 s4 = 0x00000000000000000
     s5 = 0x00000000000000000 s6 = 0x00000000000000000
     s7 = 0x00000000000000000 s8 = 0x00000000000000000
     s9 = 0x00000000000000000 s10 = 0x00000000000000000
    s11 = 0x00000000000000000 a0 = 0x0000000017E1DDD10
     a1 = 0x00000000000000021 a2 = 0x0000000017E1B1A80
     a3 = 0x00000000000000032 a4 = 0x00000000000000021
     a5 = 0x00000000000000021 a6 = 0x000000000832391E0
     a7 = 0x00000000083FFFA64 zero = 0x00000000000000000
     ra = 0x0000000017E0AFA08 sp = 0x00000000000000004
     gp = 0x00000000000000000 tp = 0x00000000000000000
   sepc = 0x0000000017E0B0824 sstatus = 0x00000000200000120
  stval = 0x000000000D20787D3
QEMU: Terminated

To reproduce the issue:

Run a Noble RISC-V virtual machine as described in https://wiki.ubuntu.com/RISC-V/QEMU.

sudo apt-get update
sudo apt-get install qemu-efi-riscv64 qemu-system-misc
cp /usr/share/qemu-efi-riscv64/RISCV_VIRT_*.fd .
qemu-system-riscv64 \
  -M virt,acpi=off -accel tcg -m 1024 \
  -nographic \
  -drive if=pflash,format=raw,unit=0,file=RISCV_VIRT_CODE.fd,readonly=on \
  -drive if=pflash,format=raw,unit=1,file=RISCV_VIRT_VARS.fd
# In the EFI shell
reset -s
sudo modprobe kvm
sudo qemu-system-riscv64 \
  -M virt,acpi=off -accel kvm -m 1024 \
  -nographic \
  -drive if=pflash,format=raw,unit=0,file=RISCV_VIRT_CODE.fd,readonly=on \
  -drive if=pflash,format=raw,unit=1,file=RISCV_VIRT_VARS.fd
# A crash occurs
# RISCV64 Exception Type - 0000000000000002(EXCEPT_RISCV_ILLEGAL_INST)
# Terminate emulation with <CTRL+A><x>

ProblemType: Bug
DistroRelease: Ubuntu 24.04
Package: qemu-efi-riscv64 2024.02-2
ProcVersionSignature: Ubuntu 6.8.0-31.31.1-generic 6.8.1
Uname: Linux 6.8.0-31-generic riscv64
ApportVersion: 2.28.1-0ubuntu2
Architecture: riscv64
CasperMD5CheckResult: unknown
CloudArchitecture: riscv64
CloudBuildName: server
CloudID: nocloud
CloudName: unknown
CloudPlatform: nocloud
CloudSerial: 20240423
CloudSubPlatform: seed-dir (/var/lib/cloud/seed/nocloud-net)
Date: Fri Aug 23 13:10:55 2024
Dependencies:

PackageArchitecture: all
ProcEnviron:
 LANG=C.UTF-8
 PATH=(custom, no user)
 SHELL=/bin/bash
 TERM=vt220
SourcePackage: edk2
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Heinrich Schuchardt (xypron) wrote :
affects: edk2 (Ubuntu) → linux-meta-riscv (Ubuntu)
summary: - riscv64 EDK 2 crashes in KVM
+ riscv64 EDK 2 crashes in KVM based emulation
Revision history for this message
Heinrich Schuchardt (xypron) wrote :

The crash output is generated in EDK II, UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandlerLib.c

Here we could add code showing the failing instruction. Only showing the registers is not helpful.

U-Boot creates output like:

Unhandled exception: Illegal instruction
EPC: 0000000087732eb0 RA: 000000008773c092 TVAL: 00000000ffffffff
EPC: 0000000080214eb0 RA: 000000008021e092 reloc adjusted

Code: f517 0006 0513 7305 b721 9002 4505 8082 (ffff ffff)

The last line can be disassembled with objcopy. See Linux' scripts/decodecode.

Revision history for this message
Heinrich Schuchardt (xypron) wrote (last edit ):

The problem is reproducible with Ubuntu 24.10 running kernel 6.8.0-31-generic riscv64.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.