* [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid
@ 2015-09-23 10:26 Wanpeng Li
2015-09-24 16:12 ` Bandan Das
0 siblings, 1 reply; 4+ messages in thread
From: Wanpeng Li @ 2015-09-23 10:26 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Jan Kiszka, Bandan Das, Wincy Van, kvm, linux-kernel, Wanpeng Li
Introduce __vmx_flush_tlb() to handle specific vpid.
Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
---
arch/x86/kvm/vmx.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 794c529..7188c5e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1343,13 +1343,13 @@ static void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs)
__loaded_vmcs_clear, loaded_vmcs, 1);
}
-static inline void vpid_sync_vcpu_single(struct vcpu_vmx *vmx)
+static inline void vpid_sync_vcpu_single(int vpid)
{
- if (vmx->vpid == 0)
+ if (vpid == 0)
return;
if (cpu_has_vmx_invvpid_single())
- __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
+ __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vpid, 0);
}
static inline void vpid_sync_vcpu_global(void)
@@ -1358,10 +1358,10 @@ static inline void vpid_sync_vcpu_global(void)
__invvpid(VMX_VPID_EXTENT_ALL_CONTEXT, 0, 0);
}
-static inline void vpid_sync_context(struct vcpu_vmx *vmx)
+static inline void vpid_sync_context(int vpid)
{
if (cpu_has_vmx_invvpid_single())
- vpid_sync_vcpu_single(vmx);
+ vpid_sync_vcpu_single(vpid);
else
vpid_sync_vcpu_global();
}
@@ -3450,9 +3450,9 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
#endif
-static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
+static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid)
{
- vpid_sync_context(to_vmx(vcpu));
+ vpid_sync_context(vpid);
if (enable_ept) {
if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
return;
@@ -3460,6 +3460,11 @@ static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
}
}
+static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
+{
+ __vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid);
+}
+
static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
{
ulong cr0_guest_owned_bits = vcpu->arch.cr0_guest_owned_bits;
@@ -4795,7 +4800,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
vmx_fpu_activate(vcpu);
update_exception_bitmap(vcpu);
- vpid_sync_context(vmx);
+ vpid_sync_context(vmx->vpid);
}
/*
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid
2015-09-23 10:26 [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid Wanpeng Li
@ 2015-09-24 16:12 ` Bandan Das
2015-09-25 3:01 ` Wanpeng Li
2015-09-25 8:01 ` Paolo Bonzini
0 siblings, 2 replies; 4+ messages in thread
From: Bandan Das @ 2015-09-24 16:12 UTC (permalink / raw)
To: Wanpeng Li; +Cc: Paolo Bonzini, Jan Kiszka, Wincy Van, kvm, linux-kernel
Wanpeng Li <wanpeng.li@hotmail.com> writes:
> Introduce __vmx_flush_tlb() to handle specific vpid.
>
> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
> ---
> arch/x86/kvm/vmx.c | 21 +++++++++++++--------
> 1 file changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 794c529..7188c5e 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -1343,13 +1343,13 @@ static void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs)
> __loaded_vmcs_clear, loaded_vmcs, 1);
> }
>
> -static inline void vpid_sync_vcpu_single(struct vcpu_vmx *vmx)
> +static inline void vpid_sync_vcpu_single(int vpid)
> {
> - if (vmx->vpid == 0)
> + if (vpid == 0)
> return;
>
> if (cpu_has_vmx_invvpid_single())
> - __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
> + __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vpid, 0);
> }
>
> static inline void vpid_sync_vcpu_global(void)
> @@ -1358,10 +1358,10 @@ static inline void vpid_sync_vcpu_global(void)
> __invvpid(VMX_VPID_EXTENT_ALL_CONTEXT, 0, 0);
> }
>
> -static inline void vpid_sync_context(struct vcpu_vmx *vmx)
> +static inline void vpid_sync_context(int vpid)
> {
> if (cpu_has_vmx_invvpid_single())
> - vpid_sync_vcpu_single(vmx);
> + vpid_sync_vcpu_single(vpid);
> else
> vpid_sync_vcpu_global();
> }
Not sure myself what's the right thing to do but this may be undesirable
in a nested environment. Assuming the processor supports global invalidation
only, this seems like a easy way for the nested guest to invalidate *all*
mappings - even the L1 specific mappings.
> @@ -3450,9 +3450,9 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
>
> #endif
>
> -static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
> +static inline void __vmx_flush_tlb(struct kvm_vcpu *vcpu, int vpid)
> {
> - vpid_sync_context(to_vmx(vcpu));
> + vpid_sync_context(vpid);
> if (enable_ept) {
> if (!VALID_PAGE(vcpu->arch.mmu.root_hpa))
> return;
> @@ -3460,6 +3460,11 @@ static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
> }
> }
>
> +static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
> +{
> + __vmx_flush_tlb(vcpu, to_vmx(vcpu)->vpid);
> +}
> +
> static void vmx_decache_cr0_guest_bits(struct kvm_vcpu *vcpu)
> {
> ulong cr0_guest_owned_bits = vcpu->arch.cr0_guest_owned_bits;
> @@ -4795,7 +4800,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu, bool init_event)
> vmx_fpu_activate(vcpu);
> update_exception_bitmap(vcpu);
>
> - vpid_sync_context(vmx);
> + vpid_sync_context(vmx->vpid);
> }
>
> /*
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid
2015-09-24 16:12 ` Bandan Das
@ 2015-09-25 3:01 ` Wanpeng Li
2015-09-25 8:01 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Wanpeng Li @ 2015-09-25 3:01 UTC (permalink / raw)
To: Bandan Das; +Cc: Paolo Bonzini, Jan Kiszka, Wincy Van, kvm, linux-kernel
On 9/25/15 12:12 AM, Bandan Das wrote:
> Wanpeng Li <wanpeng.li@hotmail.com> writes:
>
>> Introduce __vmx_flush_tlb() to handle specific vpid.
>>
>> Signed-off-by: Wanpeng Li <wanpeng.li@hotmail.com>
>> ---
>> arch/x86/kvm/vmx.c | 21 +++++++++++++--------
>> 1 file changed, 13 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
>> index 794c529..7188c5e 100644
>> --- a/arch/x86/kvm/vmx.c
>> +++ b/arch/x86/kvm/vmx.c
>> @@ -1343,13 +1343,13 @@ static void loaded_vmcs_clear(struct loaded_vmcs *loaded_vmcs)
>> __loaded_vmcs_clear, loaded_vmcs, 1);
>> }
>>
>> -static inline void vpid_sync_vcpu_single(struct vcpu_vmx *vmx)
>> +static inline void vpid_sync_vcpu_single(int vpid)
>> {
>> - if (vmx->vpid == 0)
>> + if (vpid == 0)
>> return;
>>
>> if (cpu_has_vmx_invvpid_single())
>> - __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vmx->vpid, 0);
>> + __invvpid(VMX_VPID_EXTENT_SINGLE_CONTEXT, vpid, 0);
>> }
>>
>> static inline void vpid_sync_vcpu_global(void)
>> @@ -1358,10 +1358,10 @@ static inline void vpid_sync_vcpu_global(void)
>> __invvpid(VMX_VPID_EXTENT_ALL_CONTEXT, 0, 0);
>> }
>>
>> -static inline void vpid_sync_context(struct vcpu_vmx *vmx)
>> +static inline void vpid_sync_context(int vpid)
>> {
>> if (cpu_has_vmx_invvpid_single())
>> - vpid_sync_vcpu_single(vmx);
>> + vpid_sync_vcpu_single(vpid);
>> else
>> vpid_sync_vcpu_global();
>> }
> Not sure myself what's the right thing to do but this may be undesirable
> in a nested environment. Assuming the processor supports global invalidation
> only, this seems like a easy way for the nested guest to invalidate *all*
> mappings - even the L1 specific mappings.
Indeed, however, there's no easy way to handle the w/o single
invalidation case, we can improve it if you have any idea, otherwise, it
can be left to further optimization. :-)
Regards,
Wanpeng Li
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid
2015-09-24 16:12 ` Bandan Das
2015-09-25 3:01 ` Wanpeng Li
@ 2015-09-25 8:01 ` Paolo Bonzini
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-09-25 8:01 UTC (permalink / raw)
To: Bandan Das, Wanpeng Li; +Cc: Jan Kiszka, Wincy Van, kvm, linux-kernel
On 24/09/2015 18:12, Bandan Das wrote:
> Not sure myself what's the right thing to do but this may be undesirable
> in a nested environment. Assuming the processor supports global invalidation
> only, this seems like a easy way for the nested guest to invalidate *all*
> mappings - even the L1 specific mappings.
It's not a great thing but it's already what happens if you do a global
INVEPT (it calls vmx_flush_tlb, which results in a global INVVPID if the
single-context variant is not supported).
Even without nested virt a single guest could slow down all other guests
just by triggering frequent TLB flushes (e.g. by moving around a ROM BAR
thousands of times per second).
It would help to know _which_ processors actually don't support
single-context INVVPIDs...
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-09-25 8:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-23 10:26 [PATCH 1/2] KVM: introduce __vmx_flush_tlb to handle specific vpid Wanpeng Li
2015-09-24 16:12 ` Bandan Das
2015-09-25 3:01 ` Wanpeng Li
2015-09-25 8:01 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).