mbox series

[0/4] : KVM: nVMX: Consider TLB are tagged with different EPTP if L1 uses EPT

Message ID 20180906133228.118282-1-liran.alon@oracle.com (mailing list archive)
Headers show
Series : KVM: nVMX: Consider TLB are tagged with different EPTP if L1 uses EPT | expand

Message

Liran Alon Sept. 6, 2018, 1:32 p.m. UTC
Hi,

This patch series aim to enhance L1<->L2 transitions to avoid
unnecessary TLB flushes in case L1 uses VPID and EPT.

The 1st patch fixes a bug that INVEPT was executed on L1<->L2
transitions to flush TLB but with the wrong EPTP because it hasn't been
loaded yet with the destination EPTP. The patch handles this issue
easily by just delaying vmx_flush_tlb() to be called after EPTP has been
set to destination by using KVM_REQ_TLB_FLUSH.

The 2nd patch avoids unnecessary flushing TLB on L2->L1 VMExit if L1
uses VPID and EPT. This is because TLB entries of L1 and L2 are
separated by the fact they are tagged with different EPTP.

The 3rd patch modifies L1->L2 VMEntry code such that it will set
vmcs02->vpid to vmcs12->vpid in case L1 uses EPT. This leverages the
fact TLB entries of L1 and L2 are separated by being tagged with
different EPTPs and therefore we don't need to use the special vpid02.

The 4rd patch then modifies L1->L2 VMEntry code to avoid unnecessary
flushing TLB in case L1 uses both VPID and EPT as TLB entries of L1 and
L2 are separated by different EPTP tags.

Regards,
-Liran

Comments

Paolo Bonzini Oct. 1, 2018, 12:56 p.m. UTC | #1
On 06/09/2018 15:32, Liran Alon wrote:
> Hi,
> 
> This patch series aim to enhance L1<->L2 transitions to avoid
> unnecessary TLB flushes in case L1 uses VPID and EPT.
> 
> The 1st patch fixes a bug that INVEPT was executed on L1<->L2
> transitions to flush TLB but with the wrong EPTP because it hasn't been
> loaded yet with the destination EPTP. The patch handles this issue
> easily by just delaying vmx_flush_tlb() to be called after EPTP has been
> set to destination by using KVM_REQ_TLB_FLUSH.
> 
> The 2nd patch avoids unnecessary flushing TLB on L2->L1 VMExit if L1
> uses VPID and EPT. This is because TLB entries of L1 and L2 are
> separated by the fact they are tagged with different EPTP.
> 
> The 3rd patch modifies L1->L2 VMEntry code such that it will set
> vmcs02->vpid to vmcs12->vpid in case L1 uses EPT. This leverages the
> fact TLB entries of L1 and L2 are separated by being tagged with
> different EPTPs and therefore we don't need to use the special vpid02.
> 
> The 4rd patch then modifies L1->L2 VMEntry code to avoid unnecessary
> flushing TLB in case L1 uses both VPID and EPT as TLB entries of L1 and
> L2 are separated by different EPTP tags.

Queued patches 1-2-4, thanks.

Paolo
Liran Alon Oct. 7, 2018, 8:28 p.m. UTC | #2
> On 1 Oct 2018, at 15:56, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> On 06/09/2018 15:32, Liran Alon wrote:
>> Hi,
>> 
>> This patch series aim to enhance L1<->L2 transitions to avoid
>> unnecessary TLB flushes in case L1 uses VPID and EPT.
>> 
>> The 1st patch fixes a bug that INVEPT was executed on L1<->L2
>> transitions to flush TLB but with the wrong EPTP because it hasn't been
>> loaded yet with the destination EPTP. The patch handles this issue
>> easily by just delaying vmx_flush_tlb() to be called after EPTP has been
>> set to destination by using KVM_REQ_TLB_FLUSH.
>> 
>> The 2nd patch avoids unnecessary flushing TLB on L2->L1 VMExit if L1
>> uses VPID and EPT. This is because TLB entries of L1 and L2 are
>> separated by the fact they are tagged with different EPTP.
>> 
>> The 3rd patch modifies L1->L2 VMEntry code such that it will set
>> vmcs02->vpid to vmcs12->vpid in case L1 uses EPT. This leverages the
>> fact TLB entries of L1 and L2 are separated by being tagged with
>> different EPTPs and therefore we don't need to use the special vpid02.
>> 
>> The 4rd patch then modifies L1->L2 VMEntry code to avoid unnecessary
>> flushing TLB in case L1 uses both VPID and EPT as TLB entries of L1 and
>> L2 are separated by different EPTP tags.
> 
> Queued patches 1-2-4, thanks.
> 
> Paolo

Thanks.

However, because we haven’t taken patch 3 of the series, I think we should also remove patch 4 from kvm.git/queue.
Otherwise, it introduce a bug. This dependency is documented on commit message :)

We can replace patch 4 with a simpler one that in case vmx->nested.vpid02 isn’t allocated,
we need to vmx_flush_tlb() only in case (!nested_cpu_has_ept(vmcs12)  || (vmcs12->virtual_processor_id != vmx->nested.last_vpid)).
I will create such a patch and submit it separately.

-Liran