Skip to content

getauxval(AT_HWCAP) returns different value under qemu-system-riscv64 and qemu-riscv64

Host environment

  • Operating system: Gentoo Linux
  • OS/kernel version: 5.4.48-gentoo
  • Architecture: x86_64
  • QEMU flavor: qemu-system-riscv64 qemu-riscv64
  • QEMU version: qemu-riscv64 version 8.0.3
  • QEMU command line:
    qemu-system-riscv64 -cpu rv64,v=true,vlen=256,elen=64,vext_spec=v1.0 -m 8G -kernel Image -drive file=gentoo.img,format=raw,id=hd0

Emulated/Virtualized environment

  • Operating system: Gentoo Linux
  • OS/kernel version: 6.5-rc3
  • Architecture: riscv64

Description of problem

I have a test program that checks for the presence of the RISC-V Vector extension (RVV) via getauxval().

#include <sys/auxv.h>
#include <stdio.h>

#define ISA_V_HWCAP (1 << ('v' - 'a'))

void main() {
  unsigned long hw_cap = getauxval(AT_HWCAP);
  printf("RVV %s\n", hw_cap & ISA_V_HWCAP ? "detected" : "not found");
}

When run inside qemu-system-riscv64 with a 6.5-rc3 kernel where CONFIG_RISCV_ISA_V=y and CONFIG_RISCV_ISA_V_DEFAULT_ENABLE=y it correctly shows:

$ ./hwcap
RVV detected

However when executed with qemu-riscv64 it does not return the V bit set:

$ qemu-riscv64 hwcap
RVV not found

Steps to reproduce

  1. Boot 6.5-rc3 kernel with CONFIG_RISCV_ISA_V=y and CONFIG_RISCV_ISA_V_DEFAULT_ENABLE=y
  2. In guest run test program hwcap (source above)
  3. On host run qemu-riscv64 hwcap

Additional information

Edited by Nathan Egge
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information