From dc53662638818a887b42ab2632f49f3e20233741 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 2 Jan 2025 09:33:18 -0800 Subject: [PATCH] Fix uninitialized cs_base value for RISC-V and MIPS targets This results in QEMU being extremely slow since the TCG tb hash lookups now compare uninitialized values from the stack and are likely to fail. This brings the CheriBSD kernel init benchmark `~/cheri/output/sdk/bin/qemu-system-riscv64cheri.slow -M virt -m 2048 -nographic -kernel ~/cheri/output/kernel-riscv64-purecap.CHERI-QEMU-MFS-ROOT-NODEBUG.full -device virtio-net-device,netdev=net0 -netdev user,id=net0,ipv6=off,hostfwd=tcp::12345-:22 -append init_path=/sbin/startup-benchmark.sh` back down to 2.5 seconds instead of around 60 seconds. --- target/mips/cpu.h | 1 + target/riscv/cpu_helper.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index 6e3b269750..43eb416611 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -1470,6 +1470,7 @@ mips_cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc, uint32_t *flags) { *pc = PC_ADDR(env); // We want the full virtual address here (no offset) + *cs_base = 0; *flags = env->hflags & (MIPS_HFLAG_TMASK | MIPS_HFLAG_BMASK | MIPS_HFLAG_HWRENA_ULR); #ifdef TARGET_CHERI diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 9cd535e3ae..a1fbcd3c61 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -106,9 +106,8 @@ void riscv_cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, #ifdef TARGET_CHERI cheri_cpu_get_tb_cpu_state(&env->PCC, &env->DDC, pcc_base, pcc_top, cheri_flags); -#else - *cs_base = 0; #endif + *cs_base = 0; if (riscv_has_ext(env, RVV)) { uint32_t vlmax = vext_get_vlmax(env_archcpu(env), env->vtype);