diff options
author | Gleb Natapov <gleb@redhat.com> | 2013-02-04 09:00:28 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2013-02-06 19:00:02 -0500 |
commit | 5037878e2223278aa627162aa0bf106dffac19d4 (patch) | |
tree | 34acc92617f0df16ceed4ff8a674184d218227ef /arch | |
parent | b0da5bec30eca7ffbb2c89afa6fe503fd418d3a6 (diff) |
KVM: VMX: cleanup vmx_set_cr0().
When calculating hw_cr0 teh current code masks bits that should be always
on and re-adds them back immediately after. Cleanup the code by masking
only those bits that should be dropped from hw_cr0. This allow us to
get rid of some defines.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/kvm/vmx.c | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index fe9a9cfadbd6..fe09fdc5624c 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -95,12 +95,8 @@ module_param(enable_apicv_reg_vid, bool, S_IRUGO); | |||
95 | static bool __read_mostly nested = 0; | 95 | static bool __read_mostly nested = 0; |
96 | module_param(nested, bool, S_IRUGO); | 96 | module_param(nested, bool, S_IRUGO); |
97 | 97 | ||
98 | #define KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST \ | 98 | #define KVM_GUEST_CR0_MASK (X86_CR0_NW | X86_CR0_CD) |
99 | (X86_CR0_WP | X86_CR0_NE | X86_CR0_NW | X86_CR0_CD) | 99 | #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST (X86_CR0_WP | X86_CR0_NE) |
100 | #define KVM_GUEST_CR0_MASK \ | ||
101 | (KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE) | ||
102 | #define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST \ | ||
103 | (X86_CR0_WP | X86_CR0_NE) | ||
104 | #define KVM_VM_CR0_ALWAYS_ON \ | 100 | #define KVM_VM_CR0_ALWAYS_ON \ |
105 | (KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE) | 101 | (KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE) |
106 | #define KVM_CR4_GUEST_OWNED_BITS \ | 102 | #define KVM_CR4_GUEST_OWNED_BITS \ |
@@ -3137,11 +3133,11 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) | |||
3137 | struct vcpu_vmx *vmx = to_vmx(vcpu); | 3133 | struct vcpu_vmx *vmx = to_vmx(vcpu); |
3138 | unsigned long hw_cr0; | 3134 | unsigned long hw_cr0; |
3139 | 3135 | ||
3136 | hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK); | ||
3140 | if (enable_unrestricted_guest) | 3137 | if (enable_unrestricted_guest) |
3141 | hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST) | 3138 | hw_cr0 |= KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST; |
3142 | | KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST; | ||
3143 | else { | 3139 | else { |
3144 | hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON; | 3140 | hw_cr0 |= KVM_VM_CR0_ALWAYS_ON; |
3145 | 3141 | ||
3146 | if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE)) | 3142 | if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE)) |
3147 | enter_pmode(vcpu); | 3143 | enter_pmode(vcpu); |