Patch "KVM: X86: Fix tlb flush for tdp in kvm_invalidate_pcid()" has been added to the 5.15-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: X86: Fix tlb flush for tdp in kvm_invalidate_pcid()

to the 5.15-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-x86-fix-tlb-flush-for-tdp-in-kvm_invalidate_pcid.patch
and it can be found in the queue-5.15 subdirectory.

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



commit 8cb8f818be6f46e87ff6397ea429852357f8048c
Author: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
Date:   Tue Oct 19 19:01:51 2021 +0800

    KVM: X86: Fix tlb flush for tdp in kvm_invalidate_pcid()
    
    [ Upstream commit e45e9e3998f0001079b09555db5bb3b4257f6746 ]
    
    The KVM doesn't know whether any TLB for a specific pcid is cached in
    the CPU when tdp is enabled.  So it is better to flush all the guest
    TLB when invalidating any single PCID context.
    
    The case is very rare or even impossible since KVM generally doesn't
    intercept CR3 write or INVPCID instructions when tdp is enabled, so the
    fix is mostly for the sake of overall robustness.
    
    Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxxxxx>
    Message-Id: <20211019110154.4091-2-jiangshanlai@xxxxxxxxx>
    Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index eff065ce6f8e8..3c9e2d236830c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1091,6 +1091,18 @@ static void kvm_invalidate_pcid(struct kvm_vcpu *vcpu, unsigned long pcid)
 	unsigned long roots_to_free = 0;
 	int i;
 
+	/*
+	 * MOV CR3 and INVPCID are usually not intercepted when using TDP, but
+	 * this is reachable when running EPT=1 and unrestricted_guest=0,  and
+	 * also via the emulator.  KVM's TDP page tables are not in the scope of
+	 * the invalidation, but the guest's TLB entries need to be flushed as
+	 * the CPU may have cached entries in its TLB for the target PCID.
+	 */
+	if (unlikely(tdp_enabled)) {
+		kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu);
+		return;
+	}
+
 	/*
 	 * If neither the current CR3 nor any of the prev_roots use the given
 	 * PCID, then nothing needs to be done here because a resync will



[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