Skip to contentSkip to conversation

QEMU/KVM: report paravirt features on cpuid

PATCH New Marcelo Tosatti 1 participant 1 message Feb 22, 2008 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 QEMU/KVM: report paravirt features on cpuid

Report paravirt features on cpuid.

qemu/qemu-kvm-x86.c +37 -5
Index: kvm-userspace/qemu/qemu-kvm-x86.c
===================================================================
@@ -20,6 +20,8 @@
 
 #define MSR_IA32_TSC		0x10
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
+
 static struct kvm_msr_list *kvm_msr_list;
 extern unsigned int kvm_shadow_memory;
 extern kvm_context_t kvm_context;
@@ -493,6 +495,40 @@ static void do_cpuid_ent(struct kvm_cpui
     }
 }
 
+struct kvm_para_features {
+	int cap;
+	int feature;
+} para_features[] = {
+#ifdef KVM_CAP_CLOCKSOURCE
+	{ KVM_CAP_CLOCKSOURCE, KVM_FEATURE_CLOCKSOURCE },
+#endif
+#ifdef KVM_CAP_NOP_IO_DELAY
+	{ KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
+#endif
+#ifdef KVM_CAP_MMU_WRITE
+	{ KVM_CAP_MMU_WRITE, KVM_FEATURE_MMU_WRITE },
+#endif
+#ifdef KVM_CAP_MULTICALL
+	{ KVM_CAP_MULTICALL, KVM_FEATURE_MULTICALL },
+#endif
+#ifdef KVM_CAP_CR3_CACHE
+	{ KVM_CAP_CR3_CACHE, KVM_FEATURE_CR3_CACHE },
+#endif
+	{ -1, -1 }
+};
+
+static int get_para_features(kvm_context_t kvm_context)
+{
+	int i, features = 0;
+
+	for (i = 0; i < ARRAY_SIZE(para_features)-1; i++) {
+		if (kvm_check_extension(kvm_context, para_features[i].cap))
+			features |= (1 << para_features[i].feature);
+	}
+
+	return features;
+}
+
 int kvm_arch_qemu_init_env(CPUState *cenv)
 {
     struct kvm_cpuid_entry cpuid_ent[100];
@@ -503,10 +539,6 @@ int kvm_arch_qemu_init_env(CPUState *cen
     int cpuid_nent = 0;
     CPUState copy;
     uint32_t i, limit;
-    int has_clocksource = 0;
-#ifdef KVM_CAP_CLOCKSOURCE
-    has_clocksource = kvm_check_extension(kvm_context, KVM_CAP_CLOCKSOURCE);
-#endif
 
     copy = *cenv;
 
@@ -524,7 +556,7 @@ int kvm_arch_qemu_init_env(CPUState *cen
     pv_ent = &cpuid_ent[cpuid_nent++];
     memset(pv_ent, 0, sizeof(*pv_ent));
     pv_ent->function = KVM_CPUID_FEATURES;
-    pv_ent->eax = (has_clocksource << KVM_FEATURE_CLOCKSOURCE);
+    pv_ent->eax = get_para_features(kvm_context);
 #endif
 
     copy.regs[R_EAX] = 0;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/