I've set up a noble container and in there was driving riscv64 emulation
as instructed following https://wiki.ubuntu.com/RISC-V/QEMU

Then in that guest I did updates and installed the test workload:

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install build-essential unzip
$ wget 
https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2095169/+attachment/5852451/+files/repro.zip


ubuntu@ubuntu:~$ unzip repro.zip 
Archive:  repro.zip
  inflating: Makefile                
  inflating: sigill.S                
  inflating: test.c                  
ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc
make: *** [Makefile:7: check] Illegal instruction (core dumped

This crashed the program in the guest, but not the guest itself.
It was 100% reproducible on each try.


Update on the host to the version from proposed

root@n-lp2095169:~# apt install qemu-block-extra/noble-proposed 
qemu-system-common/noble-proposed qemu-system-data/noble-proposed 
qemu-system-gui/noble-proposed qemu-system-misc/noble-proposed 
qemu-system-modules-opengl/noble-proposed 
qemu-system-modules-spice/noble-proposed qemu-utils/noble-proposed
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-block-extra'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-system-common'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [all]) 
for 'qemu-system-data'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-system-gui'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-system-misc'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-system-modules-opengl'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-system-modules-spice'
Selected version '1:8.2.2+ds-0ubuntu1.6' (Ubuntu:24.04/noble-proposed [amd64]) 
for 'qemu-utils'
Suggested packages:
  samba vde2
The following packages will be upgraded:
  qemu-block-extra qemu-system-common qemu-system-data qemu-system-gui 
qemu-system-misc qemu-system-modules-opengl qemu-system-modules-spice qemu-utils
8 upgraded, 0 newly installed, 0 to remove and 59 not upgraded.
Need to get 63.7 MB of archives.
After this operation, 135 kB disk space will be freed.
Get:1 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-modules-spice amd64 1:8.2.2+ds-0ubuntu1.6 [70.2 kB]
Get:2 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-modules-opengl amd64 1:8.2.2+ds-0ubuntu1.6 [183 kB]
Get:3 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-gui amd64 1:8.2.2+ds-0ubuntu1.6 [314 kB]
Get:4 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-block-extra amd64 1:8.2.2+ds-0ubuntu1.6 [111 kB]
Get:5 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 qemu-utils 
amd64 1:8.2.2+ds-0ubuntu1.6 [2220 kB]
Get:6 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-misc amd64 1:8.2.2+ds-0ubuntu1.6 [57.7 MB]
Get:7 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-common amd64 1:8.2.2+ds-0ubuntu1.6 [1252 kB]                        
                                             
Get:8 http://archive.ubuntu.com/ubuntu noble-proposed/main amd64 
qemu-system-data all 1:8.2.2+ds-0ubuntu1.6 [1790 kB]                            
                                             
Fetched 63.7 MB in 7s (8810 kB/s)                                               
                                                                                
                              
(Reading database ... 52709 files and directories currently installed.)
Preparing to unpack 
.../0-qemu-system-modules-spice_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-system-modules-spice (1:8.2.2+ds-0ubuntu1.6) over 
(1:8.2.2+ds-0ubuntu1.5) ...
Preparing to unpack 
.../1-qemu-system-modules-opengl_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-system-modules-opengl (1:8.2.2+ds-0ubuntu1.6) over 
(1:8.2.2+ds-0ubuntu1.5) ...
Preparing to unpack .../2-qemu-system-gui_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-system-gui (1:8.2.2+ds-0ubuntu1.6) over (1:8.2.2+ds-0ubuntu1.5) 
...
Preparing to unpack .../3-qemu-block-extra_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-block-extra (1:8.2.2+ds-0ubuntu1.6) over (1:8.2.2+ds-0ubuntu1.5) 
...
Preparing to unpack .../4-qemu-utils_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-utils (1:8.2.2+ds-0ubuntu1.6) over (1:8.2.2+ds-0ubuntu1.5) ...
Preparing to unpack .../5-qemu-system-misc_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb ...
Unpacking qemu-system-misc (1:8.2.2+ds-0ubuntu1.6) over (1:8.2.2+ds-0ubuntu1.5) 
...
Preparing to unpack .../6-qemu-system-common_1%3a8.2.2+ds-0ubuntu1.6_amd64.deb 
...
Unpacking qemu-system-common (1:8.2.2+ds-0ubuntu1.6) over 
(1:8.2.2+ds-0ubuntu1.5) ...
Preparing to unpack .../7-qemu-system-data_1%3a8.2.2+ds-0ubuntu1.6_all.deb ...
Unpacking qemu-system-data (1:8.2.2+ds-0ubuntu1.6) over (1:8.2.2+ds-0ubuntu1.5) 
...
Setting up qemu-system-common (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-system-data (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-utils (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-block-extra (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-system-misc (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-system-modules-opengl (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-system-gui (1:8.2.2+ds-0ubuntu1.6) ...
Setting up qemu-system-modules-spice (1:8.2.2+ds-0ubuntu1.6) ...
Processing triggers for man-db (2.12.0-4build2) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...


root@n-lp2095169:~# dpkg -l | grep '\sqemu-' 
ii  qemu-block-extra                     1:8.2.2+ds-0ubuntu1.6                  
 amd64        extra block backend modules for qemu-system and qemu-utils
ii  qemu-system-common                   1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU full system emulation binaries (common files)
ii  qemu-system-data                     1:8.2.2+ds-0ubuntu1.6                  
 all          QEMU full system emulation (data files)
ii  qemu-system-gui                      1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU full system emulation binaries (graphical display and audio 
modules)
ii  qemu-system-misc                     1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU full system emulation binaries (miscellaneous)
ii  qemu-system-modules-opengl           1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU full system emulation binaries (OpenGL display modules)
ii  qemu-system-modules-spice            1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU full system emulation binaries (spice display modules)
ii  qemu-utils                           1:8.2.2+ds-0ubuntu1.6                  
 amd64        QEMU utilities


Then starting the guest again

root@n-lp2095169:~# qemu-system-riscv64 -machine virt -nographic -m 2048
-smp 4 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-
device,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::6666-:22 -drive
file=/root/ubuntu-24.04.1-preinstalled-server-
riscv64.img,format=raw,if=virtio

And in the guest run the test workload with the updated qemu:

Hrm,
at least to me that does not change a thing ... :-/

ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc
make: *** [Makefile:7: check] Illegal instruction (core dumped)

Re-reading and realizing in comment 5 that I might need to add `-cpu
max` to the command line to expose the offending half implemented
instruction n the first place.


Ok, now this works reliably

ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc
ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc
ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc


Which means I have to downgrade qemu again to ensure this was broken before the 
fix.

root@n-lp2095169:~# v=1:8.2.2+ds-0ubuntu1.5; apt install qemu-block-extra=$v 
qemu-system-common=$v qemu-system-data=$v qemu-system-gui=$v 
qemu-system-misc=$v qemu-system-modules-opengl=$v qemu-system-modules-spice=$v 
qemu-utils=$v
...
root@n-lp2095169:~# qemu-system-riscv64 -machine virt -cpu max -nographic -m 
2048 -smp 4 -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.elf 
-kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device 
virtio-net-device,netdev=eth0 -netdev user,id=eth0,hostfwd=tcp::6666-:22 -drive 
file=/root/ubuntu-24.04.1-preinstalled-server-riscv64.img,format=raw,if=virtio
...


ubuntu@ubuntu:~$ make
gcc -g -march=rv64gcv test.c sigill.S -o test
./test abc abc
make: *** [Makefile:7: check] Illegal instruction (core dumped)


Ok, so all was fine, just the test instructions should mention the cpu type.
I'll add that and set verification done


** Tags removed: verification-needed verification-needed-noble
** Tags added: verification-done verification-done-noble

** Description changed:

  [ Impact ]
  
   * Qemu 8.2.2 claims to support the riscv64 vector extension, but fails to 
set the emulated vstart_eq_zero flag, which then causes illegal instruction 
crashes in certain cases.
   * Launchpad builders currently use the same Qemu package as Noble, so this 
SRU will be the basis for fixing our riscv64 builds for future Ubuntu versions.
   * This was reported upstream 
(https://gitlab.com/qemu-project/qemu/-/issues/1976) and fixed in Qemu 9.0, so 
please backport the fix linked in the issue.
  
  [ Test Plan ]
  
   * I've attached some code which can reproduce the issue.
-  * Reproduction requires running a riscv64 Noble image, via Qemu system 
emulation, on an amd64 host; see instructions in 
https://wiki.ubuntu.com/RISC-V/QEMU
+  * Reproduction requires running a riscv64 Noble image, via Qemu system 
emulation, on an amd64 host; see instructions in 
https://wiki.ubuntu.com/RISC-V/QEMU but to expose the half way implemented 
instruction one needs to also add -cpu max
   * Boot up the VM, transfer the necessary files over, `apt install 
build-essential unzip`, then unzip the reproduction files and compile & run the 
test (within the VM) with `make`.
  
  [ Where problems could occur ]
  
   * All changes would be restricted to target/riscv in the Qemu tree, so other 
architectures shouldn't be affected at all. Furthermore, fixes should only 
affect vector instructions.
   * Possible problems range from build failures to riscv emulation failing 
completely, but the test above covers those cases.
  
  [ Other Info ]
  
   * Relevant MR: 
https://code.launchpad.net/~baioc/ubuntu/+source/qemu/+git/qemu/+merge/479676
-  * PPA for testing: 
https://launchpad.net/~baioc/+archive/ubuntu/qemu-sru-riscv-vstart-eq-zero
+  * PPA for testing: 
https://launchpad.net/~baioc/+archive/ubuntu/qemu-sru-riscv-vstart-eq-zero

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2095169

Title:
  [SRU] SIGILL on emulation of RISC-V Vector instructions

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/qemu/+bug/2095169/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to