Patch "KVM: VMX: Don't fudge CR0 and CR4 for restricted L2 guest" has been added to the 5.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    KVM: VMX: Don't fudge CR0 and CR4 for restricted L2 guest

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     kvm-vmx-don-t-fudge-cr0-and-cr4-for-restricted-l2-gu.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 7f78eab3ff8018f2ebcc5bf4d1e5492cd001ee10
Author: Sean Christopherson <seanjc@xxxxxxxxxx>
Date:   Tue Jun 13 13:30:36 2023 -0700

    KVM: VMX: Don't fudge CR0 and CR4 for restricted L2 guest
    
    [ Upstream commit c4abd7352023aa96114915a0bb2b88016a425cda ]
    
    Stuff CR0 and/or CR4 to be compliant with a restricted guest if and only
    if KVM itself is not configured to utilize unrestricted guests, i.e. don't
    stuff CR0/CR4 for a restricted L2 that is running as the guest of an
    unrestricted L1.  Any attempt to VM-Enter a restricted guest with invalid
    CR0/CR4 values should fail, i.e. in a nested scenario, KVM (as L0) should
    never observe a restricted L2 with incompatible CR0/CR4, since nested
    VM-Enter from L1 should have failed.
    
    And if KVM does observe an active, restricted L2 with incompatible state,
    e.g. due to a KVM bug, fudging CR0/CR4 instead of letting VM-Enter fail
    does more harm than good, as KVM will often neglect to undo the side
    effects, e.g. won't clear rmode.vm86_active on nested VM-Exit, and thus
    the damage can easily spill over to L1.  On the other hand, letting
    VM-Enter fail due to bad guest state is more likely to contain the damage
    to L2 as KVM relies on hardware to perform most guest state consistency
    checks, i.e. KVM needs to be able to reflect a failed nested VM-Enter into
    L1 irrespective of (un)restricted guest behavior.
    
    Cc: Jim Mattson <jmattson@xxxxxxxxxx>
    Cc: stable@xxxxxxxxxxxxxxx
    Fixes: bddd82d19e2e ("KVM: nVMX: KVM needs to unset "unrestricted guest" VM-execution control in vmcs02 if vmcs12 doesn't set it")
    Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
    Message-Id: <20230613203037.1968489-3-seanjc@xxxxxxxxxx>
    Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index ca51df0df3f94..2445c61038954 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -1519,6 +1519,11 @@ void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 	unsigned long old_rflags;
 
+	/*
+	 * Unlike CR0 and CR4, RFLAGS handling requires checking if the vCPU
+	 * is an unrestricted guest in order to mark L2 as needing emulation
+	 * if L1 runs L2 as a restricted guest.
+	 */
 	if (is_unrestricted_guest(vcpu)) {
 		kvm_register_mark_available(vcpu, VCPU_EXREG_RFLAGS);
 		vmx->rflags = rflags;
@@ -3073,7 +3078,7 @@ void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 	u32 tmp;
 
 	hw_cr0 = (cr0 & ~KVM_VM_CR0_ALWAYS_OFF);
-	if (is_unrestricted_guest(vcpu))
+	if (enable_unrestricted_guest)
 		hw_cr0 |= KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
 	else {
 		hw_cr0 |= KVM_VM_CR0_ALWAYS_ON;
@@ -3096,7 +3101,7 @@ void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 	}
 #endif
 
-	if (enable_ept && !is_unrestricted_guest(vcpu)) {
+	if (enable_ept && !enable_unrestricted_guest) {
 		/*
 		 * Ensure KVM has an up-to-date snapshot of the guest's CR3.  If
 		 * the below code _enables_ CR3 exiting, vmx_cache_reg() will
@@ -3231,7 +3236,7 @@ void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 	unsigned long hw_cr4;
 
 	hw_cr4 = (cr4_read_shadow() & X86_CR4_MCE) | (cr4 & ~X86_CR4_MCE);
-	if (is_unrestricted_guest(vcpu))
+	if (enable_unrestricted_guest)
 		hw_cr4 |= KVM_VM_CR4_ALWAYS_ON_UNRESTRICTED_GUEST;
 	else if (vmx->rmode.vm86_active)
 		hw_cr4 |= KVM_RMODE_VM_CR4_ALWAYS_ON;
@@ -3251,7 +3256,7 @@ void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 	vcpu->arch.cr4 = cr4;
 	kvm_register_mark_available(vcpu, VCPU_EXREG_CR4);
 
-	if (!is_unrestricted_guest(vcpu)) {
+	if (!enable_unrestricted_guest) {
 		if (enable_ept) {
 			if (!is_paging(vcpu)) {
 				hw_cr4 &= ~X86_CR4_PAE;



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux