[PATCH 3/4] KVM: nVMX: Set vmcs02->vpid to vmcs12->vpid if L1 uses EPT

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

 



If CPU use both VPID and EPT, TLB entries populated by CPU are tagged
with both EPTP and VPID. Therefore, if L1 uses EPT, L2 TLB entries
are separated from L1 TLB entries by the EPTP tags as vmcs02 use
EPTP02 while vmcs01 use EPTP01.

Thus, we don't need to make sure that vmcs02->vpid != vmcs01->vpid.
Therefore, we can just set vmcs02->vpid to vmcs12->vpid.

Reviewed-by: Mihai Carabas <mihai.carabas@xxxxxxxxxx>
Reviewed-by: Darren Kenny <darren.kenny@xxxxxxxxxx>
Reviewed-by: Nikita Leshchenko <nikita.leshchenko@xxxxxxxxxx>
Signed-off-by: Liran Alon <liran.alon@xxxxxxxxxx>
---
 arch/x86/kvm/vmx.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index b97e0c5ccb46..98faba65c24a 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -12018,10 +12018,20 @@ static void prepare_vmcs02_full(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
 		vmcs_write64(GUEST_BNDCFGS, vmcs12->guest_bndcfgs);
 
 	if (enable_vpid) {
-		if (nested_cpu_has_vpid(vmcs12) && vmx->nested.vpid02)
-			vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->nested.vpid02);
-		else
-			vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid);
+		u16 vmcs02_vpid;
+
+		if (nested_cpu_has_vpid(vmcs12)) {
+			if (nested_cpu_has_ept(vmcs12))
+				vmcs02_vpid = vmcs12->virtual_processor_id;
+			else if (vmx->nested.vpid02)
+				vmcs02_vpid = vmx->nested.vpid02;
+			else
+				vmcs02_vpid = vmx->vpid;
+		} else {
+			vmcs02_vpid = vmx->vpid;
+		}
+
+		vmcs_write16(VIRTUAL_PROCESSOR_ID, vmcs02_vpid);
 	}
 
 	/*
-- 
2.16.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux