With max CPU type, PTW feature is enabled in TCG mode and auto detected
in KVM mode. Enable this feature in both TCG and KVM mode in the
beginning, and detect it in late with KVM mode.

Signed-off-by: Bibo Mao <[email protected]>
Reviewed-by:   Song Gao <[email protected]>
---
 target/loongarch/cpu.c     | 7 +------
 target/loongarch/kvm/kvm.c | 1 +
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 99499034ed..4a75d53f7e 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -472,6 +472,7 @@ static void loongarch_max_initfn(Object *obj)
     /* '-cpu max': use it for max supported CPU features */
     loongarch_la464_initfn(obj);
 
+    cpu->env.cpucfg[2] = FIELD_DP32(cpu->env.cpucfg[2], CPUCFG2, HPTW, 1);
     cpu->ptw = ON_OFF_AUTO_AUTO;
     cpu->env.cpucfg[1] = FIELD_DP32(cpu->env.cpucfg[1], CPUCFG1, MSG_INT, 1);
     cpu->msgint = ON_OFF_AUTO_AUTO;
@@ -488,12 +489,6 @@ static void loongarch_max_initfn(Object *obj)
     data = cpu->env.cpucfg[3];
     data = FIELD_DP32(data, CPUCFG3, DBAR_HINTS, 1);
     cpu->env.cpucfg[3] = data;
-
-    if (tcg_enabled()) {
-        data = cpu->env.cpucfg[2];
-        data = FIELD_DP32(data, CPUCFG2, HPTW, 1);
-        cpu->env.cpucfg[2] = data;
-    }
 }
 
 #if defined(CONFIG_KVM)
diff --git a/target/loongarch/kvm/kvm.c b/target/loongarch/kvm/kvm.c
index 0626c553d5..941142305e 100644
--- a/target/loongarch/kvm/kvm.c
+++ b/target/loongarch/kvm/kvm.c
@@ -1150,6 +1150,7 @@ static int kvm_cpu_check_ptw(CPUState *cs, Error **errp)
     CPULoongArchState *env = cpu_env(cs);
     bool kvm_supported;
 
+    env->cpucfg[2] = FIELD_DP32(env->cpucfg[2], CPUCFG2, HPTW, 0);
     kvm_supported = kvm_feature_supported(cs, LOONGARCH_FEATURE_PTW);
     if (cpu->ptw == ON_OFF_AUTO_ON) {
         if (!kvm_supported) {
-- 
2.54.0


Reply via email to