KVM: VMX: Invert handling of CR0.WP for EPT without unrestricted guest
[ Upstream commit ee5a5584cba316bc90bc2fad0c6d10b71f1791cb ] Opt-in to forcing CR0.WP=1 for shadow paging, and stop lying about WP being "always on" for unrestricted guest. In addition to making KVM a wee bit more honest, this paves the way for additional cleanup. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20210713163324.627647-22-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Stable-dep-of: c4abd7352023 ("KVM: VMX: Don't fudge CR0 and CR4 for restricted L2 guest") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
90cd5ab951
commit
96c73bc9ef
@@ -135,8 +135,7 @@ module_param(allow_smaller_maxphyaddr, bool, S_IRUGO);
|
|||||||
#define KVM_VM_CR0_ALWAYS_OFF (X86_CR0_NW | X86_CR0_CD)
|
#define KVM_VM_CR0_ALWAYS_OFF (X86_CR0_NW | X86_CR0_CD)
|
||||||
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST X86_CR0_NE
|
#define KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST X86_CR0_NE
|
||||||
#define KVM_VM_CR0_ALWAYS_ON \
|
#define KVM_VM_CR0_ALWAYS_ON \
|
||||||
(KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | \
|
(KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST | X86_CR0_PG | X86_CR0_PE)
|
||||||
X86_CR0_WP | X86_CR0_PG | X86_CR0_PE)
|
|
||||||
|
|
||||||
#define KVM_VM_CR4_ALWAYS_ON_UNRESTRICTED_GUEST X86_CR4_VMXE
|
#define KVM_VM_CR4_ALWAYS_ON_UNRESTRICTED_GUEST X86_CR4_VMXE
|
||||||
#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE)
|
#define KVM_PMODE_VM_CR4_ALWAYS_ON (X86_CR4_PAE | X86_CR4_VMXE)
|
||||||
@@ -3064,9 +3063,7 @@ void ept_save_pdptrs(struct kvm_vcpu *vcpu)
|
|||||||
kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
|
kvm_register_mark_dirty(vcpu, VCPU_EXREG_PDPTR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
|
static void ept_update_paging_mode_cr0(unsigned long cr0, struct kvm_vcpu *vcpu)
|
||||||
unsigned long cr0,
|
|
||||||
struct kvm_vcpu *vcpu)
|
|
||||||
{
|
{
|
||||||
struct vcpu_vmx *vmx = to_vmx(vcpu);
|
struct vcpu_vmx *vmx = to_vmx(vcpu);
|
||||||
|
|
||||||
@@ -3085,9 +3082,6 @@ static void ept_update_paging_mode_cr0(unsigned long *hw_cr0,
|
|||||||
vcpu->arch.cr0 = cr0;
|
vcpu->arch.cr0 = cr0;
|
||||||
vmx_set_cr4(vcpu, kvm_read_cr4(vcpu));
|
vmx_set_cr4(vcpu, kvm_read_cr4(vcpu));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cr0 & X86_CR0_WP))
|
|
||||||
*hw_cr0 &= ~X86_CR0_WP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
|
void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
|
||||||
@@ -3100,6 +3094,8 @@ void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
|
|||||||
hw_cr0 |= KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
|
hw_cr0 |= KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
|
||||||
else {
|
else {
|
||||||
hw_cr0 |= KVM_VM_CR0_ALWAYS_ON;
|
hw_cr0 |= KVM_VM_CR0_ALWAYS_ON;
|
||||||
|
if (!enable_ept)
|
||||||
|
hw_cr0 |= X86_CR0_WP;
|
||||||
|
|
||||||
if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE))
|
if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE))
|
||||||
enter_pmode(vcpu);
|
enter_pmode(vcpu);
|
||||||
@@ -3118,7 +3114,7 @@ void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (enable_ept && !is_unrestricted_guest(vcpu))
|
if (enable_ept && !is_unrestricted_guest(vcpu))
|
||||||
ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu);
|
ept_update_paging_mode_cr0(cr0, vcpu);
|
||||||
|
|
||||||
vmcs_writel(CR0_READ_SHADOW, cr0);
|
vmcs_writel(CR0_READ_SHADOW, cr0);
|
||||||
vmcs_writel(GUEST_CR0, hw_cr0);
|
vmcs_writel(GUEST_CR0, hw_cr0);
|
||||||
|
Reference in New Issue
Block a user