Replace the compile-time #if/#elif preprocessor ladder in
aarch64_host_initfn() with runtime calls and add mshv_enabled() to it.
This ensures the correct accelerator is selected at runtime when
multiple accelerators are compiled in.

Add CONFIG_MSHV to the aarch64_cpus[] guard so that mshv accelerator can
register the "host" CPU type.

Signed-off-by: Aastha Rawat <[email protected]>
---
 target/arm/cpu64.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index b38a78aac3..aed84a3c0b 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -859,17 +859,21 @@ static void aarch64_host_initfn(Object *obj)
     }
 #endif
 
+    if (mshv_enabled()) {
+        mshv_arm_set_cpu_features_from_host(cpu);
+    } else if (kvm_enabled()) {
 #if defined(CONFIG_KVM)
-    kvm_arm_set_cpreg_mig_tolerances(cpu);
-    kvm_arm_set_cpu_features_from_host(cpu);
-    aarch64_add_sve_properties(obj);
-#elif defined(CONFIG_HVF)
-    hvf_arm_set_cpu_features_from_host(cpu);
-#elif defined(CONFIG_WHPX)
-    whpx_arm_set_cpu_features_from_host(cpu);
-#else
-    g_assert_not_reached();
+        kvm_arm_set_cpreg_mig_tolerances(cpu);
 #endif
+        kvm_arm_set_cpu_features_from_host(cpu);
+        aarch64_add_sve_properties(obj);
+    } else if (hvf_enabled()) {
+        hvf_arm_set_cpu_features_from_host(cpu);
+    } else if (whpx_enabled()) {
+        whpx_arm_set_cpu_features_from_host(cpu);
+    } else {
+        g_assert_not_reached();
+    }
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         aarch64_add_pauth_properties(obj);
     }
@@ -897,7 +901,8 @@ static const ARMCPUInfo aarch64_cpus[] = {
     { .name = "cortex-a57",         .initfn = aarch64_a57_initfn },
     { .name = "cortex-a53",         .initfn = aarch64_a53_initfn },
     { .name = "max",                .initfn = aarch64_max_initfn },
-#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || defined(CONFIG_WHPX)
+#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || \
+    defined(CONFIG_WHPX) || defined(CONFIG_MSHV)
     { .name = "host",               .initfn = aarch64_host_initfn },
 #endif
 };

-- 
2.45.4


Reply via email to