Skip to content

Commit 1438921

Browse files
Liran Alonbonzini
authored andcommitted
KVM: nVMX: Flush TLB entries tagged by dest EPTP on L1<->L2 transitions
If L1 and L2 share VPID (because L1 don't use VPID or we haven't allocated a vpid02), we need to flush TLB on L1<->L2 transitions. Before this patch, this TLB flushing was done by vmx_flush_tlb(). If L0 use EPT, this will translate into INVEPT(active_eptp); However, if L1 use EPT, in L1->L2 VMEntry, active EPTP is EPTP01 but TLB entries populated by L2 are tagged with EPTP02. Therefore we should delay vmx_flush_tlb() until active_eptp is EPTP02. To achieve this, instead of directly calling vmx_flush_tlb() we request it to be called by KVM_REQ_TLB_FLUSH which is evaluated after KVM_REQ_LOAD_CR3 which sets the active_eptp to EPTP02 as required. Similarly, on L2->L1 VMExit, active EPTP is EPTP02 but TLB entries populated by L1 are tagged with EPTP01 and therefore we should delay vmx_flush_tlb() until active_eptp is EPTP01. Reviewed-by: Mihai Carabas <mihai.carabas@oracle.com> Reviewed-by: Darren Kenny <darren.kenny@oracle.com> Reviewed-by: Nikita Leshenko <nikita.leshchenko@oracle.com> Signed-off-by: Liran Alon <liran.alon@oracle.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 3de6347 commit 1438921

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

arch/x86/kvm/vmx.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12290,7 +12290,15 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
1229012290
__vmx_flush_tlb(vcpu, vmx->nested.vpid02, true);
1229112291
}
1229212292
} else {
12293-
vmx_flush_tlb(vcpu, true);
12293+
/*
12294+
* If L1 use EPT, then L0 needs to execute INVEPT on
12295+
* EPTP02 instead of EPTP01. Therefore, delay TLB
12296+
* flush until vmcs02->eptp is fully updated by
12297+
* KVM_REQ_LOAD_CR3. Note that this assumes
12298+
* KVM_REQ_TLB_FLUSH is evaluated after
12299+
* KVM_REQ_LOAD_CR3 in vcpu_enter_guest().
12300+
*/
12301+
kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
1229412302
}
1229512303
}
1229612304

@@ -13188,10 +13196,14 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
1318813196
* Therefore, flush TLB only in case vmcs01 uses VPID and
1318913197
* vmcs12 don't use VPID as in this case L1 & L2 TLB entries
1319013198
* are both tagged with vmx->vpid.
13199+
*
13200+
* If vmcs12 uses EPT, we need to execute this flush on EPTP01
13201+
* and therefore we request the TLB flush to happen only after VMCS EPTP
13202+
* has been set by KVM_REQ_LOAD_CR3.
1319113203
*/
1319213204
if (enable_vpid &&
1319313205
!(nested_cpu_has_vpid(vmcs12) && to_vmx(vcpu)->nested.vpid02)) {
13194-
vmx_flush_tlb(vcpu, true);
13206+
kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
1319513207
}
1319613208

1319713209
vmcs_write32(GUEST_SYSENTER_CS, vmcs12->host_ia32_sysenter_cs);

0 commit comments

Comments
 (0)