target/riscv: Remove the redundant initialization of env->misa_mxl
PATCH 1/3 target/riscv: Remove the redundant initialization of env->misa_mxl
env->misa_mxl was already set in the RISC-V cpu init routine, and validated at the beginning of riscv_cpu_realize(). There is no need to do a redundant initialization later.
---
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/cpu.c +1 -1
@@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) ext |=RVJ ; } -set_misa (env, env->misa_mxl, ext); + env->misa_ext_mask = env->misa_ext = ext; }riscv_cpu_register_gdb_regs_for_features (cs);
Signature · 1 line
2.34.1
PATCH 2/3 target/riscv: kvm: Set env->misa_ext_mask to the supported value
env->misa_ext_mask might be set to the same value of env->misa_ext in riscv_cpu_realize() based on given properties, but it may differ from what KVM tells us.
Let's set the correct env->misa_ext_mask in kvm_arch_init_vcpu().
---
target/riscv/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/kvm.c +1 -1
@@ -410,7 +410,7 @@ int kvm_arch_init_vcpu(CPUState *cs)if (ret) {return ret; } - env->misa_ext = isa; + env->misa_ext_mask = env->misa_ext = isa;return ret; }
Signature · 1 line
2.34.1
Re: [PATCH 2/3] target/riscv: kvm: Set env->misa_ext_mask to the supported value
Quoted 8 lines · Bin Meng
env->misa_ext_maskmight be set to the same value ofenv->misa_extinriscv_cpu_realize()based on given properties, but it may differ from what KVM tells us.Let's set the correct
env->misa_ext_maskinkvm_arch_init_vcpu().Signed-off-by Bin Meng <[email protected]>
Alistair
Quoted 22 lines
---
target/riscv/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/kvm.c +1
-2@@ -410,7 +410,7 @@ int kvm_arch_init_vcpu(CPUState *cs)if (ret) {return ret; } - env->misa_ext = isa; + env->misa_ext_mask = env->misa_ext = isa;return ret; } --2.34.1
PATCH 3/3 target/riscv: Skip parsing extensions from properties for KVM
In reply to Bin MengWhen running with accel=kvm, the extensions are actually told by KVM, so let's skip the parsing logic from properties for KVM.
---
target/riscv/cpu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.c +5 -2
@@ -581,8 +581,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }assert (env->misa_mxl_max == env->misa_mxl); -/* If only MISA_EXT is unset for misa, then set it from properties */ -if (env->misa_ext ==0 ) { +/* +* If only MISA_EXT is unset for misa, then set it from properties. +* For KVM, misa is told by KVM so properties are ignored. +*/ +if (!kvm_enabled () && env->misa_ext ==0 ) {uint32_t ext =0 ;/* Do some ISA extension error checking */
Signature · 1 line
2.34.1
Re: [PATCH 3/3] target/riscv: Skip parsing extensions from properties for KVM
Quoted 5 lines · Bin Meng
When running with accel=kvm, the extensions are actually told by KVM, so let's skip the parsing logic from properties for KVM.
Signed-off-by Bin Meng <[email protected]>
Alistair
Quoted 27 lines
---
target/riscv/cpu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)target/riscv/cpu.c +5
-3@@ -581,8 +581,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) }assert (env->misa_mxl_max == env->misa_mxl); -/* If only MISA_EXT is unset for misa, then set it from properties */ -if (env->misa_ext ==0 ) { +/* +* If only MISA_EXT is unset for misa, then set it from properties. +* For KVM, misa is told by KVM so properties are ignored. +*/ +if (!kvm_enabled () && env->misa_ext ==0 ) {uint32_t ext =0 ;/* Do some ISA extension error checking */ --2.34.1
Quoted 16 lines · Bin Meng
env->misa_mxlwas already set in the RISC-V cpu init routine, and validated at the beginning ofriscv_cpu_realize(). There is no need to do a redundant initialization later.Signed-off-by Bin Meng <[email protected]>---
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +0
-0
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 755
Quoted 5 lines
target/riscv/cpu.c +1
-1@@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) ext |=RVJ ; } -set_misa (env, env->misa_mxl, ext); + env->misa_ext_mask = env->misa_ext = ext;
You're right that we don't need to set misa_mxl, but isn't it cleaner calling the helper function here instead of manually assigning it?
Alistair
Quoted 7 lines
target/riscv/cpu.c +0
-1}riscv_cpu_register_gdb_regs_for_features (cs); --2.34.1
Quoted 21 lines · Alistair Francis
Quoted 19 lines · Bin Meng
env->misa_mxlwas already set in the RISC-V cpu init routine, and validated at the beginning ofriscv_cpu_realize(). There is no need to do a redundant initialization later.Signed-off-by Bin Meng <[email protected]>---
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +0
-0@@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) ext |=RVJ ; }
Quoted 7 lines
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 755
Quoted 2 lines
target/riscv/cpu.c +1
-1-set_misa (env, env->misa_mxl, ext); + env->misa_ext_mask = env->misa_ext = ext;You're right that we don't need to set
misa_mxl, but isn't it cleaner calling the helper function here instead of manually assigning it?
There is no helper for assigning misa_ext only. Do you want a new helper for that?
Regards,
Bin
Quoted 31 lines · Bin Meng
Quoted 21 lines · Alistair Francis
Quoted 19 lines · Bin Meng
env->misa_mxlwas already set in the RISC-V cpu init routine, and validated at the beginning ofriscv_cpu_realize(). There is no need to do a redundant initialization later.Signed-off-by Bin Meng <[email protected]>---
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +0
-0@@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) ext |=RVJ ; }Quoted 7 lines
target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 755
Quoted 2 lines
target/riscv/cpu.c +1
-1-set_misa (env, env->misa_mxl, ext); + env->misa_ext_mask = env->misa_ext = ext;You're right that we don't need to set
misa_mxl, but isn't it cleaner calling the helper function here instead of manually assigning it?
Quoted 2 lines
There is no helper for assigning
misa_extonly. Do you want a new helper for that?
No, I don't think we need a new helper. I mean, is there any harm in just calling set_misa() even if that means we are performing a redundant operation?
Alistair
Quoted 3 lines
Regards,
Bin
Quoted 33 lines · Alistair Francis
Quoted 31 lines · Bin Meng
Quoted 28 lines · Alistair Francis
Quoted 16 lines · Bin Meng
env->misa_mxlwas already set in the RISC-V cpu init routine, and validated at the beginning ofriscv_cpu_realize(). There is no need to do a redundant initialization later.Signed-off-by Bin Meng <[email protected]>---
target/riscv/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target/riscv/cpu.c +0
-0target/riscv/cpu.c static void riscv_cpu_realize(DeviceState *dev, Error **errp) · line 755
Quoted 5 lines
target/riscv/cpu.c +1
-1@@ -752,7 +752,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) ext |=RVJ ; } -set_misa (env, env->misa_mxl, ext); + env->misa_ext_mask = env->misa_ext = ext;You're right that we don't need to set
misa_mxl, but isn't it cleaner calling the helper function here instead of manually assigning it?
Quoted 7 lines
Quoted 2 lines
There is no helper for assigning
misa_extonly. Do you want a new helper for that?No, I don't think we need a new helper. I mean, is there any harm in just calling
set_misa()even if that means we are performing a redundant operation?
No there is no harm to perform a redundant initialization.
Feel free to drop this patch then.
Regards,
Bin