target/riscv: avoid abort when reading vtype before env->xl is set
PATCH 1/1 target/riscv: avoid abort when reading vtype before env->xl is set
TCG plugins may read registers from the vcpu_init_cb() callback. For vtype, this reaches read_vtype() before env->xl has been initialized.
In that case read_vtype() currently hits g_assert_not_reached() because env->xl is zero. Fall back to the CPU's maximum XLEN only for this early-init case.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3545
--- target/riscv/csr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
target/riscv/csr.c +10 -1
@@ -936,7 +936,16 @@ static RISCVException read_vtype(CPURISCVState *env, int csrno, target_ulong *val) {uint64_t vill; -switch (env->xl) { +int xl = env->xl; +/* +* TCG plugins can read registers before env->xl is initialized. +* Fall back to the CPU's maximum XLEN in that early-init case. +*/ +if (xl ==0 ) { + xl =riscv_cpu_mxl (env); + } + +switch (xl) {case MXL_RV32 : vill = (uint32_t )env->vill <<31 ;break ;
Signature · 1 line
2.43.0
Quoted 11 lines · ZhengXiang Qin
TCG plugins may read registers from the
vcpu_init_cb()callback. For vtype, this reachesread_vtype()beforeenv->xlhas been initialized.In that case
read_vtype()currently hitsg_assert_not_reached()becauseenv->xlis zero. Fall back to the CPU's maximum XLEN only for this early-init case.Fixes 638181a180bd ("core/cpu-common: initialise plugin state before thread creation")Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3545
Signed-off-by ZhengXiang Qin <[email protected]>---
Quoted 25 lines
target/riscv/csr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)target/riscv/csr.c +10
-1@@ -936,7 +936,16 @@ static RISCVException read_vtype(CPURISCVState *env, int csrno, target_ulong *val) {uint64_t vill; -switch (env->xl) { +int xl = env->xl; +/* +* TCG plugins can read registers before env->xl is initialized. +* Fall back to the CPU's maximum XLEN in that early-init case. +*/ +if (xl ==0 ) { + xl =riscv_cpu_mxl (env); + } + +switch (xl) {case MXL_RV32 : vill = (uint32_t )env->vill <<31 ;break ;
Thanks Daniel!
Alistair Francis
AppliedQuoted 11 lines · ZhengXiang Qin
TCG plugins may read registers from the
vcpu_init_cb()callback. For vtype, this reachesread_vtype()beforeenv->xlhas been initialized.In that case
read_vtype()currently hitsg_assert_not_reached()becauseenv->xlis zero. Fall back to the CPU's maximum XLEN only for this early-init case.Fixes 638181a180bd ("core/cpu-common: initialise plugin state before thread creation")Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3545
Signed-off-by ZhengXiang Qin <[email protected]>
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 30 lines
--- target/riscv/csr.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)target/riscv/csr.c +10
-2@@ -936,7 +936,16 @@ static RISCVException read_vtype(CPURISCVState *env, int csrno, target_ulong *val) {uint64_t vill; -switch (env->xl) { +int xl = env->xl; +/* +* TCG plugins can read registers before env->xl is initialized. +* Fall back to the CPU's maximum XLEN in that early-init case. +*/ +if (xl ==0 ) { + xl =riscv_cpu_mxl (env); + } + +switch (xl) {case MXL_RV32 : vill = (uint32_t )env->vill <<31 ;break ; --2.43.0