Skip to contentSkip to conversation

target/riscv: Remove the redundant initialization of env->misa_mxl

PATCH In review Bin Meng 2 participants 9 messages Jun 9, 2022 – Jun 16, 2022 RISC-V

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

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
index a91253d4bd..61d1737741 100644
@@ -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
author
#1 lore raw

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
index 70b4cff06f..c592980299 100644
@@ -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
Reviewed-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] target/riscv: kvm: Set env->misa_ext_mask to the supported value

Quoted 8 lines · Bin Meng

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().

Alistair

Quoted 22 lines

---

 target/riscv/kvm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/kvm.c +1 -2
index 70b4cff06f..c592980299 100644
@@ -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

author
#3 lore raw

PATCH 3/3 target/riscv: Skip parsing extensions from properties for KVM

In reply to 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.

---

 target/riscv/cpu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.c +5 -2
index 61d1737741..ff911017c3 100644
@@ -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
Reviewed-by on v1 3/3
#4 lore raw

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.

Alistair

Quoted 27 lines

---

 target/riscv/cpu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
target/riscv/cpu.c +5 -3
index 61d1737741..ff911017c3 100644
@@ -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

#5 lore raw
In reply to Bin Meng
Quoted 16 lines · Bin Meng

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 +0 -0
index a91253d4bd..61d1737741 100644

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

author
#6 lore raw
Quoted 21 lines · Alistair Francis
Quoted 19 lines · Bin Meng

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 +0 -0
index a91253d4bd..61d1737741 100644
@@ -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

#7 lore raw
Quoted 31 lines · Bin Meng
Quoted 21 lines · Alistair Francis
Quoted 19 lines · Bin Meng

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 +0 -0
index a91253d4bd..61d1737741 100644
@@ -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_ext only. 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

author
#8 lore raw
Quoted 33 lines · Alistair Francis
Quoted 31 lines · Bin Meng
Quoted 28 lines · Alistair Francis
Quoted 16 lines · Bin Meng

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 +0 -0
index a91253d4bd..61d1737741 100644

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?

Quoted 7 lines
Quoted 2 lines

There is no helper for assigning misa_ext only. 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