diff mbox series

[v2] qemuriscv: Enable Sv39 memory address scheme by default

Message ID 20250203091519.1205884-1-Yash.Shinde@windriver.com
State New
Headers show
Series [v2] qemuriscv: Enable Sv39 memory address scheme by default | expand

Commit Message

Yash Shinde Feb. 3, 2025, 9:15 a.m. UTC
From: Yash Shinde <Yash.Shinde@windriver.com>

Currently, GCC Asan supports only Sv39 on RISC-V 64 due to custom allocator configurations optimized for large allocations.
These configurations are incompatible with larger address spaces like Sv48/Sv57.
This fix enables RISC-V 64 configuration for RVA22S64 profile(which has sv39 mode and other extensions) by default when running `runqemu nographic`,
eliminating the need for manual configuration via command line flags (`qemuparams="-cpu rv64, sv39=true"`).

Fixes [YOCTO #15691]
https://bugzilla.yoctoproject.org/show_bug.cgi?id=15691

Reference:

https://github.com/qemu/qemu/commit/af651969eb23ecf018bcaa8e0761b58425de550c
https://git.openembedded.org/openembedded-core/commit/?id=4b4450ff695ef73bf7a2437e142d2e0730d6a547

Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>
---
 meta/conf/machine/include/riscv/qemuriscv.inc | 1 +
 1 file changed, 1 insertion(+)

Comments

Yash Shinde Feb. 3, 2025, 9:40 a.m. UTC | #1
On 03-02-2025 14:45, Yash.Shinde@windriver.com wrote:
> From: Yash Shinde<Yash.Shinde@windriver.com>
>
> Currently, GCC Asan supports only Sv39 on RISC-V 64 due to custom allocator configurations optimized for large allocations.
> These configurations are incompatible with larger address spaces like Sv48/Sv57.
> This fix enables RISC-V 64 configuration for RVA22S64 profile(which has sv39 mode and other extensions) by default when running `runqemu nographic`,
> eliminating the need for manual configuration via command line flags (`qemuparams="-cpu rv64, sv39=true"`).
>
> Fixes [YOCTO #15691]
> https://bugzilla.yoctoproject.org/show_bug.cgi?id=15691
>
> Reference:
>
> https://github.com/qemu/qemu/commit/af651969eb23ecf018bcaa8e0761b58425de550c
> https://git.openembedded.org/openembedded-core/commit/?id=4b4450ff695ef73bf7a2437e142d2e0730d6a547
>
> Signed-off-by: Yash Shinde<Yash.Shinde@windriver.com>
> ---
>   meta/conf/machine/include/riscv/qemuriscv.inc | 1 +
>   1 file changed, 1 insertion(+)
>
> diff --git a/meta/conf/machine/include/riscv/qemuriscv.inc b/meta/conf/machine/include/riscv/qemuriscv.inc
> index d01d988eee..65cbfd66ee 100644
> --- a/meta/conf/machine/include/riscv/qemuriscv.inc
> +++ b/meta/conf/machine/include/riscv/qemuriscv.inc
> @@ -27,6 +27,7 @@ UBOOT_ENTRYPOINT:riscv64 = "0x80200000"
>   # qemuboot options
>   QB_SMP ?= "-smp 4"
>   QB_KERNEL_CMDLINE_APPEND = "earlycon=sbi"
> +QB_CPU:riscv64 ?= "-cpu rva22s64"
>   QB_MACHINE = "-machine virt"
>   QB_DEFAULT_BIOS = "fw_jump.elf"
>   QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"

As suggested by Randy in 
(https://lists.openembedded.org/g/openembedded-core/message/210411),
I performed the openSSL ptest and the results were positive with no 
deviations.
Additionally, I tested the GCC oe-selftest for risc-v 64, but it seems 
to be currently unsupported. I triggered several full GCC test suites, 
which did not finish
and I did not observe any errors. Also, there are no risc-v 64 GCC 
testing AB logs available. (For eg, 
https://autobuilder.yocto.io/pub/non-release/20241006-8/testresults/testresult-report.txt 
)
If anyone has further insights regarding the risc-v 64 GCC oe-selftest, 
please let me know.

Also, tested Asan test as follows with command "runqemu nographic"
(with IMAGE_INSTALL:append = " libasanĀ  libasan-dev"):

root@qemuriscv64:~# vi asan_test.c
root@qemuriscv64:~# gcc -g -fsanitize=address -o asan asan_test.c
root@qemuriscv64:~# ./asan
Running AddressSanitizer test...
=================================================================
==326==ERROR: AddressSanitizer: stack-buffer-overflow on address 
0x003fbb70002a at pc 0x002ac9fb5b88 bp 0x003ff203b910 sp 0x003ff203b8e0
WRITE of size 1 at 0x003fbb70002a thread T0
#0 0x2ac9fb5b86 in cause_buffer_overflow /home/root/asan_test.c:9
#1 0x2ac9fb5ca2 in main /home/root/asan_test.c:16
#2 0x3fbda737b4 (/lib/libc.so.6+0x277b4) (BuildId: 
89440b2a8f8e9f78366a816e4685a39d6a4de4c5)
#3 0x3fbda7385c in __libc_start_main (/lib/libc.so.6+0x2785c) (BuildId: 
89440b2a8f8e9f78366a816e4685a39d6a4de4c5)
#4 0x2ac9fb5a1e in _start ../sysdeps/riscv/start.S:67
Address 0x003fbb70002a is located in stack of thread T0 at offset 42 in 
frame
#0 0x2ac9fb5ac4 in cause_buffer_overflow /home/root/asan_test.c:5
This frame has 1 object(s):
[32, 42) 'buffer' (line 6)<== Memory access at offset 42 overflows this 
variable
HINT: this may be a false positive if your program uses some custom 
stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow 
/home/root/asan_test.c:9 in cause_buffer_overflow
Shadow bytes around the buggy address:
0x003fbb6ffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb6ffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb6ffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb6fff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb6fff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x003fbb700000: f1f1f1f100[02]f3f300 00 00 00 00 00 00 00
0x003fbb700080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb700100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb700180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb700200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x003fbb700280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==326==ABORTING
root@qemuriscv64:~#
root@qemuriscv64:~#

Regards, Yash
diff mbox series

Patch

diff --git a/meta/conf/machine/include/riscv/qemuriscv.inc b/meta/conf/machine/include/riscv/qemuriscv.inc
index d01d988eee..65cbfd66ee 100644
--- a/meta/conf/machine/include/riscv/qemuriscv.inc
+++ b/meta/conf/machine/include/riscv/qemuriscv.inc
@@ -27,6 +27,7 @@  UBOOT_ENTRYPOINT:riscv64 = "0x80200000"
 # qemuboot options
 QB_SMP ?= "-smp 4"
 QB_KERNEL_CMDLINE_APPEND = "earlycon=sbi"
+QB_CPU:riscv64 ?= "-cpu rva22s64"
 QB_MACHINE = "-machine virt"
 QB_DEFAULT_BIOS = "fw_jump.elf"
 QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no"