aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm
diff options
context:
space:
mode:
authorYang, Wei Y <wei.y.yang@intel.com>2011-06-02 23:13:42 -0400
committerAvi Kivity <avi@redhat.com>2011-07-12 06:16:13 -0400
commitc68b734fba402b9bfdd49e23b776c42dbeaf1f5b (patch)
tree4d149de96cf2e4021e8f1b4c4e678bd0ffe21754 /arch/x86/kvm
parent8d9c975fc5b825cb76953a1b45a84195ffc6f4ab (diff)
KVM: Add SMEP support when setting CR4
This patch adds SMEP handling when setting CR4. Signed-off-by: Yang, Wei <wei.y.yang@intel.com> Signed-off-by: Shan, Haitao <haitao.shan@intel.com> Signed-off-by: Li, Xin <xin.li@intel.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r--arch/x86/kvm/x86.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 694538a043e..ba5cd27b429 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -580,6 +580,14 @@ static bool guest_cpuid_has_xsave(struct kvm_vcpu *vcpu)
580 return best && (best->ecx & bit(X86_FEATURE_XSAVE)); 580 return best && (best->ecx & bit(X86_FEATURE_XSAVE));
581} 581}
582 582
583static bool guest_cpuid_has_smep(struct kvm_vcpu *vcpu)
584{
585 struct kvm_cpuid_entry2 *best;
586
587 best = kvm_find_cpuid_entry(vcpu, 7, 0);
588 return best && (best->ebx & bit(X86_FEATURE_SMEP));
589}
590
583static void update_cpuid(struct kvm_vcpu *vcpu) 591static void update_cpuid(struct kvm_vcpu *vcpu)
584{ 592{
585 struct kvm_cpuid_entry2 *best; 593 struct kvm_cpuid_entry2 *best;
@@ -599,14 +607,17 @@ static void update_cpuid(struct kvm_vcpu *vcpu)
599int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 607int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
600{ 608{
601 unsigned long old_cr4 = kvm_read_cr4(vcpu); 609 unsigned long old_cr4 = kvm_read_cr4(vcpu);
602 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE; 610 unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE |
603 611 X86_CR4_PAE | X86_CR4_SMEP;
604 if (cr4 & CR4_RESERVED_BITS) 612 if (cr4 & CR4_RESERVED_BITS)
605 return 1; 613 return 1;
606 614
607 if (!guest_cpuid_has_xsave(vcpu) && (cr4 & X86_CR4_OSXSAVE)) 615 if (!guest_cpuid_has_xsave(vcpu) && (cr4 & X86_CR4_OSXSAVE))
608 return 1; 616 return 1;
609 617
618 if (!guest_cpuid_has_smep(vcpu) && (cr4 & X86_CR4_SMEP))
619 return 1;
620
610 if (is_long_mode(vcpu)) { 621 if (is_long_mode(vcpu)) {
611 if (!(cr4 & X86_CR4_PAE)) 622 if (!(cr4 & X86_CR4_PAE))
612 return 1; 623 return 1;