Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 3160499aacb81f6735941eb4c372d87a > files > 320

kvm-83-164.el5_5.30.src.rpm

From eb61d03a4d103463239c191e835b60a964378c18 Mon Sep 17 00:00:00 2001
From: Amit Shah <amit.shah@redhat.com>
Date: Wed, 21 Jan 2009 15:10:11 -0200
Subject: [PATCH 2/9] KVM: x86: Report supported virtualization extensions at init

When inserting the kvm-<arch> module, this code will report in
the system log the virtualization features supported by the
CPU in the following format:

<intel>
KVM: Virtualization flags detected on this hardware: vmx tpr_shadow

<amd>
KVM: Virtualization flags detected on this hardware: svm

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
RH-Type: improvement
RH-Upstream-status: not_applicable # upstream has /proc/cpuinfo
---
 arch/x86/include/asm/kvm_host.h |    1 +
 arch/x86/kvm/svm.c              |   15 ++++++++++++++-
 arch/x86/kvm/vmx.c              |   27 +++++++++++++++++++++++++++
 arch/x86/kvm/x86.c              |    6 ++++++
 4 files changed, 48 insertions(+), 1 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 730843d..9183222 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -434,6 +434,7 @@ struct kvm_x86_ops {
 	void (*check_processor_compatibility)(void *rtn);
 	int (*hardware_setup)(void);               /* __init */
 	void (*hardware_unsetup)(void);            /* __exit */
+	void (*dump_virtflags)(void);              /* __init */
 	bool (*cpu_has_accelerated_tpr)(void);
 
 	/* Create, but do not attach this VCPU */
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1452851..08233b0 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -1921,6 +1921,18 @@ static int svm_get_mt_mask_shift(void)
 	return 0;
 }
 
+static void __init svm_dump_virtflags(void)
+{
+	printk(" svm");
+	if (svm_has(SVM_FEATURE_NPT))
+		printk(" npt");
+	if (svm_has(SVM_FEATURE_LBRV))
+		printk(" lbrv");
+	if (svm_has(SVM_FEATURE_SVML))
+		printk(" svml");
+	printk("\n");
+}
+
 static struct kvm_x86_ops svm_x86_ops = {
 	.cpu_has_kvm_support = has_svm,
 	.disabled_by_bios = is_disabled,
@@ -1929,6 +1941,7 @@ static struct kvm_x86_ops svm_x86_ops = {
 	.check_processor_compatibility = svm_check_processor_compat,
 	.hardware_enable = svm_hardware_enable,
 	.hardware_disable = svm_hardware_disable,
+	.dump_virtflags = svm_dump_virtflags,
 	.cpu_has_accelerated_tpr = svm_cpu_has_accelerated_tpr,
 
 	.vcpu_create = svm_create_vcpu,
@@ -1982,7 +1995,7 @@ static struct kvm_x86_ops svm_x86_ops = {
 static int __init svm_init(void)
 {
 	return kvm_init(&svm_x86_ops, sizeof(struct vcpu_svm),
-			      THIS_MODULE);
+			THIS_MODULE);
 }
 
 static void __exit svm_exit(void)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 6259d74..890e744 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3576,6 +3576,32 @@ static int vmx_get_mt_mask_shift(void)
 	return VMX_EPT_MT_EPTE_SHIFT;
 }
 
+static void __init vmx_dump_virtflags(void)
+{
+	u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
+
+	printk(" vmx");
+	rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
+	msr_ctl = (0xffffffff & vmx_msr_high) | vmx_msr_low;
+	if (msr_ctl & CPU_BASED_TPR_SHADOW)
+		printk(" tpr_shadow");
+	if (msr_ctl & CPU_BASED_VIRTUAL_NMI_PENDING)
+		printk(" vnmi");
+	if (msr_ctl & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) {
+		rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
+		      vmx_msr_low, vmx_msr_high);
+		msr_ctl2 = (0xffffffff & vmx_msr_high) | vmx_msr_low;
+		if ((msr_ctl2 & SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES) &&
+		    (msr_ctl & CPU_BASED_TPR_SHADOW))
+			printk(" flexpriority");
+		if (msr_ctl2 & SECONDARY_EXEC_ENABLE_EPT)
+			printk(" ept");
+		if (msr_ctl2 & SECONDARY_EXEC_ENABLE_VPID)
+			printk(" vpid");
+	}
+	printk("\n");
+}
+
 static struct kvm_x86_ops vmx_x86_ops = {
 	.cpu_has_kvm_support = cpu_has_kvm_support,
 	.disabled_by_bios = vmx_disabled_by_bios,
@@ -3584,6 +3610,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
 	.check_processor_compatibility = vmx_check_processor_compat,
 	.hardware_enable = hardware_enable,
 	.hardware_disable = hardware_disable,
+	.dump_virtflags = vmx_dump_virtflags,
 	.cpu_has_accelerated_tpr = cpu_has_vmx_virtualize_apic_accesses,
 
 	.vcpu_create = vmx_create_vcpu,
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index cc17546..fc198e8 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2618,6 +2618,12 @@ int kvm_arch_init(void *opaque)
 	kvm_mmu_set_base_ptes(PT_PRESENT_MASK);
 	kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
 			PT_DIRTY_MASK, PT64_NX_MASK, 0, 0);
+
+	if (ops->dump_virtflags) {
+		printk(KERN_INFO "kvm: virtualization flags detected on "
+		       "this hardware:");
+		ops->dump_virtflags();
+	}
 	return 0;
 
 out:
-- 
1.6.1