Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
> On May 27, 2019, at 2:47 AM, Peter Zijlstra wrote: > > On Sat, May 25, 2019 at 10:54:50AM +0200, Juergen Gross wrote: >> On 25/05/2019 10:22, Nadav Amit wrote: > >>> diff --git a/arch/x86/include/asm/paravirt_types.h >>> b/arch/x86/include/asm/paravirt_types.h >>> index 946f8f1f1efc..3a156e63c57d 100644 >>> --- a/arch/x86/include/asm/paravirt_types.h >>> +++ b/arch/x86/include/asm/paravirt_types.h >>> @@ -211,6 +211,12 @@ struct pv_mmu_ops { >>> void (*flush_tlb_user)(void); >>> void (*flush_tlb_kernel)(void); >>> void (*flush_tlb_one_user)(unsigned long addr); >>> + /* >>> +* flush_tlb_multi() is the preferred interface. When it is used, >>> +* flush_tlb_others() should return false. >> >> This comment does not make sense. flush_tlb_others() return type is >> void. > > I suspect that is an artifact from before the static_key; an attempt to > make the pv interface less awkward. Yes, remainders that should have been removed - I will remove them for the next version. > Something like the below would work for KVM I suspect, the others > (Hyper-V and Xen are more 'interesting'). > > --- > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -580,7 +580,7 @@ static void __init kvm_apf_trap_init(voi > > static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); > > -static void kvm_flush_tlb_others(const struct cpumask *cpumask, > +static void kvm_flush_tlb_multi(const struct cpumask *cpumask, > const struct flush_tlb_info *info) > { > u8 state; > @@ -594,6 +594,9 @@ static void kvm_flush_tlb_others(const s >* queue flush_on_enter for pre-empted vCPUs >*/ > for_each_cpu(cpu, flushmask) { > + if (cpu == smp_processor_id()) > + continue; > + > src = _cpu(steal_time, cpu); > state = READ_ONCE(src->preempted); > if ((state & KVM_VCPU_PREEMPTED)) { > @@ -603,7 +606,7 @@ static void kvm_flush_tlb_others(const s > } > } > > - native_flush_tlb_others(flushmask, info); > + native_flush_tlb_multi(flushmask, info); > } > > static void __init kvm_guest_init(void) > @@ -628,9 +631,8 @@ static void __init kvm_guest_init(void) > if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && > !kvm_para_has_hint(KVM_HINTS_REALTIME) && > kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { > - pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; > + pv_ops.mmu.flush_tlb_multi = kvm_flush_tlb_multi; > pv_ops.mmu.tlb_remove_table = tlb_remove_table; > - static_key_disable(_tlb_multi_enabled.key); > } > > if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) That’s what I have as well ;-). As you mentioned (in another email), specifically hyper-v code seems convoluted to me. In general, I prefer not to touch KVM/Xen/hyper-v, but you twist my arm, I will send a compile-tested version for Xen and hyper-v. ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
On 27/05/19 14:32, Peter Zijlstra wrote: > On Mon, May 27, 2019 at 12:21:59PM +0200, Paolo Bonzini wrote: >> On 27/05/19 11:47, Peter Zijlstra wrote: > >>> --- a/arch/x86/kernel/kvm.c >>> +++ b/arch/x86/kernel/kvm.c >>> @@ -580,7 +580,7 @@ static void __init kvm_apf_trap_init(voi >>> >>> static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); >>> >>> -static void kvm_flush_tlb_others(const struct cpumask *cpumask, >>> +static void kvm_flush_tlb_multi(const struct cpumask *cpumask, >>> const struct flush_tlb_info *info) >>> { >>> u8 state; >>> @@ -594,6 +594,9 @@ static void kvm_flush_tlb_others(const s >>> * queue flush_on_enter for pre-empted vCPUs >>> */ >>> for_each_cpu(cpu, flushmask) { >>> + if (cpu == smp_processor_id()) >>> + continue; >>> + >> >> Even this would be just an optimization; the vCPU you're running on >> cannot be preempted. You can just change others to multi. > > Yeah, I know, but it felt weird so I added the explicit skip. No strong > feelings though. Neither here, and it would indeed deserve a comment if you left the if out. Paolo ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
On Mon, May 27, 2019 at 12:21:59PM +0200, Paolo Bonzini wrote: > On 27/05/19 11:47, Peter Zijlstra wrote: > > --- a/arch/x86/kernel/kvm.c > > +++ b/arch/x86/kernel/kvm.c > > @@ -580,7 +580,7 @@ static void __init kvm_apf_trap_init(voi > > > > static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); > > > > -static void kvm_flush_tlb_others(const struct cpumask *cpumask, > > +static void kvm_flush_tlb_multi(const struct cpumask *cpumask, > > const struct flush_tlb_info *info) > > { > > u8 state; > > @@ -594,6 +594,9 @@ static void kvm_flush_tlb_others(const s > > * queue flush_on_enter for pre-empted vCPUs > > */ > > for_each_cpu(cpu, flushmask) { > > + if (cpu == smp_processor_id()) > > + continue; > > + > > Even this would be just an optimization; the vCPU you're running on > cannot be preempted. You can just change others to multi. Yeah, I know, but it felt weird so I added the explicit skip. No strong feelings though. ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
On 27/05/19 11:47, Peter Zijlstra wrote: > On Sat, May 25, 2019 at 10:54:50AM +0200, Juergen Gross wrote: >> On 25/05/2019 10:22, Nadav Amit wrote: > >>> diff --git a/arch/x86/include/asm/paravirt_types.h >>> b/arch/x86/include/asm/paravirt_types.h >>> index 946f8f1f1efc..3a156e63c57d 100644 >>> --- a/arch/x86/include/asm/paravirt_types.h >>> +++ b/arch/x86/include/asm/paravirt_types.h >>> @@ -211,6 +211,12 @@ struct pv_mmu_ops { >>> void (*flush_tlb_user)(void); >>> void (*flush_tlb_kernel)(void); >>> void (*flush_tlb_one_user)(unsigned long addr); >>> + /* >>> +* flush_tlb_multi() is the preferred interface. When it is used, >>> +* flush_tlb_others() should return false. >> >> This comment does not make sense. flush_tlb_others() return type is >> void. > > I suspect that is an artifact from before the static_key; an attempt to > make the pv interface less awkward. > > Something like the below would work for KVM I suspect, the others > (Hyper-V and Xen are more 'interesting'). > > --- > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -580,7 +580,7 @@ static void __init kvm_apf_trap_init(voi > > static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); > > -static void kvm_flush_tlb_others(const struct cpumask *cpumask, > +static void kvm_flush_tlb_multi(const struct cpumask *cpumask, > const struct flush_tlb_info *info) > { > u8 state; > @@ -594,6 +594,9 @@ static void kvm_flush_tlb_others(const s >* queue flush_on_enter for pre-empted vCPUs >*/ > for_each_cpu(cpu, flushmask) { > + if (cpu == smp_processor_id()) > + continue; > + Even this would be just an optimization; the vCPU you're running on cannot be preempted. You can just change others to multi. Paolo > src = _cpu(steal_time, cpu); > state = READ_ONCE(src->preempted); > if ((state & KVM_VCPU_PREEMPTED)) { > @@ -603,7 +606,7 @@ static void kvm_flush_tlb_others(const s > } > } > > - native_flush_tlb_others(flushmask, info); > + native_flush_tlb_multi(flushmask, info); > } > > static void __init kvm_guest_init(void) > @@ -628,9 +631,8 @@ static void __init kvm_guest_init(void) > if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && > !kvm_para_has_hint(KVM_HINTS_REALTIME) && > kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { > - pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; > + pv_ops.mmu.flush_tlb_multi = kvm_flush_tlb_multi; > pv_ops.mmu.tlb_remove_table = tlb_remove_table; > - static_key_disable(_tlb_multi_enabled.key); > } > > if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) > ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
On Sat, May 25, 2019 at 10:54:50AM +0200, Juergen Gross wrote: > On 25/05/2019 10:22, Nadav Amit wrote: > > diff --git a/arch/x86/include/asm/paravirt_types.h > > b/arch/x86/include/asm/paravirt_types.h > > index 946f8f1f1efc..3a156e63c57d 100644 > > --- a/arch/x86/include/asm/paravirt_types.h > > +++ b/arch/x86/include/asm/paravirt_types.h > > @@ -211,6 +211,12 @@ struct pv_mmu_ops { > > void (*flush_tlb_user)(void); > > void (*flush_tlb_kernel)(void); > > void (*flush_tlb_one_user)(unsigned long addr); > > + /* > > +* flush_tlb_multi() is the preferred interface. When it is used, > > +* flush_tlb_others() should return false. > > This comment does not make sense. flush_tlb_others() return type is > void. I suspect that is an artifact from before the static_key; an attempt to make the pv interface less awkward. Something like the below would work for KVM I suspect, the others (Hyper-V and Xen are more 'interesting'). --- --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -580,7 +580,7 @@ static void __init kvm_apf_trap_init(voi static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask); -static void kvm_flush_tlb_others(const struct cpumask *cpumask, +static void kvm_flush_tlb_multi(const struct cpumask *cpumask, const struct flush_tlb_info *info) { u8 state; @@ -594,6 +594,9 @@ static void kvm_flush_tlb_others(const s * queue flush_on_enter for pre-empted vCPUs */ for_each_cpu(cpu, flushmask) { + if (cpu == smp_processor_id()) + continue; + src = _cpu(steal_time, cpu); state = READ_ONCE(src->preempted); if ((state & KVM_VCPU_PREEMPTED)) { @@ -603,7 +606,7 @@ static void kvm_flush_tlb_others(const s } } - native_flush_tlb_others(flushmask, info); + native_flush_tlb_multi(flushmask, info); } static void __init kvm_guest_init(void) @@ -628,9 +631,8 @@ static void __init kvm_guest_init(void) if (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && !kvm_para_has_hint(KVM_HINTS_REALTIME) && kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { - pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; + pv_ops.mmu.flush_tlb_multi = kvm_flush_tlb_multi; pv_ops.mmu.tlb_remove_table = tlb_remove_table; - static_key_disable(_tlb_multi_enabled.key); } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
On 25/05/2019 10:22, Nadav Amit wrote: > To improve TLB shootdown performance, flush the remote and local TLBs > concurrently. Introduce flush_tlb_multi() that does so. The current > flush_tlb_others() interface is kept, since paravirtual interfaces need > to be adapted first before it can be removed. This is left for future > work. In such PV environments, TLB flushes are not performed, at this > time, concurrently. > > Add a static key to tell whether this new interface is supported. > > Cc: "K. Y. Srinivasan" > Cc: Haiyang Zhang > Cc: Stephen Hemminger > Cc: Sasha Levin > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: x...@kernel.org > Cc: Juergen Gross > Cc: Paolo Bonzini > Cc: Dave Hansen > Cc: Andy Lutomirski > Cc: Peter Zijlstra > Cc: Boris Ostrovsky > Cc: linux-hyp...@vger.kernel.org > Cc: linux-ker...@vger.kernel.org > Cc: virtualization@lists.linux-foundation.org > Cc: k...@vger.kernel.org > Cc: xen-de...@lists.xenproject.org > Signed-off-by: Nadav Amit > --- > arch/x86/hyperv/mmu.c | 2 + > arch/x86/include/asm/paravirt.h | 8 +++ > arch/x86/include/asm/paravirt_types.h | 6 ++ > arch/x86/include/asm/tlbflush.h | 6 ++ > arch/x86/kernel/kvm.c | 1 + > arch/x86/kernel/paravirt.c| 3 + > arch/x86/mm/tlb.c | 80 +++ > arch/x86/xen/mmu_pv.c | 2 + > 8 files changed, 96 insertions(+), 12 deletions(-) > > diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c > index e65d7fe6489f..ca28b400c87c 100644 > --- a/arch/x86/hyperv/mmu.c > +++ b/arch/x86/hyperv/mmu.c > @@ -233,4 +233,6 @@ void hyperv_setup_mmu_ops(void) > pr_info("Using hypercall for remote TLB flush\n"); > pv_ops.mmu.flush_tlb_others = hyperv_flush_tlb_others; > pv_ops.mmu.tlb_remove_table = tlb_remove_table; > + > + static_key_disable(_tlb_multi_enabled.key); > } > diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h > index c25c38a05c1c..192be7254457 100644 > --- a/arch/x86/include/asm/paravirt.h > +++ b/arch/x86/include/asm/paravirt.h > @@ -47,6 +47,8 @@ static inline void slow_down_io(void) > #endif > } > > +DECLARE_STATIC_KEY_TRUE(flush_tlb_multi_enabled); > + > static inline void __flush_tlb(void) > { > PVOP_VCALL0(mmu.flush_tlb_user); > @@ -62,6 +64,12 @@ static inline void __flush_tlb_one_user(unsigned long addr) > PVOP_VCALL1(mmu.flush_tlb_one_user, addr); > } > > +static inline void flush_tlb_multi(const struct cpumask *cpumask, > +const struct flush_tlb_info *info) > +{ > + PVOP_VCALL2(mmu.flush_tlb_multi, cpumask, info); > +} > + > static inline void flush_tlb_others(const struct cpumask *cpumask, > const struct flush_tlb_info *info) > { > diff --git a/arch/x86/include/asm/paravirt_types.h > b/arch/x86/include/asm/paravirt_types.h > index 946f8f1f1efc..3a156e63c57d 100644 > --- a/arch/x86/include/asm/paravirt_types.h > +++ b/arch/x86/include/asm/paravirt_types.h > @@ -211,6 +211,12 @@ struct pv_mmu_ops { > void (*flush_tlb_user)(void); > void (*flush_tlb_kernel)(void); > void (*flush_tlb_one_user)(unsigned long addr); > + /* > + * flush_tlb_multi() is the preferred interface. When it is used, > + * flush_tlb_others() should return false. This comment does not make sense. flush_tlb_others() return type is void. Juergen ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
> On May 25, 2019, at 1:22 AM, Nadav Amit wrote: > > To improve TLB shootdown performance, flush the remote and local TLBs > concurrently. Introduce flush_tlb_multi() that does so. The current > flush_tlb_others() interface is kept, since paravirtual interfaces need > to be adapted first before it can be removed. This is left for future > work. In such PV environments, TLB flushes are not performed, at this > time, concurrently. > > +void native_flush_tlb_multi(const struct cpumask *cpumask, > + const struct flush_tlb_info *info) > { > + /* > + * native_flush_tlb_multi() can handle a single CPU, but it is > + * suboptimal if the local TLB should be flushed, and therefore should > + * not be used in such case. Check that it is not used in such case, > + * and use this assumption for tracing and accounting of remote TLB > + * flushes. > + */ > + VM_WARN_ON(!cpumask_any_but(cpumask, smp_processor_id())); This warning might fire off incorrectly and will be removed. ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
To improve TLB shootdown performance, flush the remote and local TLBs concurrently. Introduce flush_tlb_multi() that does so. The current flush_tlb_others() interface is kept, since paravirtual interfaces need to be adapted first before it can be removed. This is left for future work. In such PV environments, TLB flushes are not performed, at this time, concurrently. Add a static key to tell whether this new interface is supported. Cc: "K. Y. Srinivasan" Cc: Haiyang Zhang Cc: Stephen Hemminger Cc: Sasha Levin Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x...@kernel.org Cc: Juergen Gross Cc: Paolo Bonzini Cc: Dave Hansen Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: Boris Ostrovsky Cc: linux-hyp...@vger.kernel.org Cc: linux-ker...@vger.kernel.org Cc: virtualization@lists.linux-foundation.org Cc: k...@vger.kernel.org Cc: xen-de...@lists.xenproject.org Signed-off-by: Nadav Amit --- arch/x86/hyperv/mmu.c | 2 + arch/x86/include/asm/paravirt.h | 8 +++ arch/x86/include/asm/paravirt_types.h | 6 ++ arch/x86/include/asm/tlbflush.h | 6 ++ arch/x86/kernel/kvm.c | 1 + arch/x86/kernel/paravirt.c| 3 + arch/x86/mm/tlb.c | 80 +++ arch/x86/xen/mmu_pv.c | 2 + 8 files changed, 96 insertions(+), 12 deletions(-) diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index e65d7fe6489f..ca28b400c87c 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -233,4 +233,6 @@ void hyperv_setup_mmu_ops(void) pr_info("Using hypercall for remote TLB flush\n"); pv_ops.mmu.flush_tlb_others = hyperv_flush_tlb_others; pv_ops.mmu.tlb_remove_table = tlb_remove_table; + + static_key_disable(_tlb_multi_enabled.key); } diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h index c25c38a05c1c..192be7254457 100644 --- a/arch/x86/include/asm/paravirt.h +++ b/arch/x86/include/asm/paravirt.h @@ -47,6 +47,8 @@ static inline void slow_down_io(void) #endif } +DECLARE_STATIC_KEY_TRUE(flush_tlb_multi_enabled); + static inline void __flush_tlb(void) { PVOP_VCALL0(mmu.flush_tlb_user); @@ -62,6 +64,12 @@ static inline void __flush_tlb_one_user(unsigned long addr) PVOP_VCALL1(mmu.flush_tlb_one_user, addr); } +static inline void flush_tlb_multi(const struct cpumask *cpumask, + const struct flush_tlb_info *info) +{ + PVOP_VCALL2(mmu.flush_tlb_multi, cpumask, info); +} + static inline void flush_tlb_others(const struct cpumask *cpumask, const struct flush_tlb_info *info) { diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h index 946f8f1f1efc..3a156e63c57d 100644 --- a/arch/x86/include/asm/paravirt_types.h +++ b/arch/x86/include/asm/paravirt_types.h @@ -211,6 +211,12 @@ struct pv_mmu_ops { void (*flush_tlb_user)(void); void (*flush_tlb_kernel)(void); void (*flush_tlb_one_user)(unsigned long addr); + /* +* flush_tlb_multi() is the preferred interface. When it is used, +* flush_tlb_others() should return false. +*/ + void (*flush_tlb_multi)(const struct cpumask *cpus, + const struct flush_tlb_info *info); void (*flush_tlb_others)(const struct cpumask *cpus, const struct flush_tlb_info *info); diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h index dee375831962..79272938cf79 100644 --- a/arch/x86/include/asm/tlbflush.h +++ b/arch/x86/include/asm/tlbflush.h @@ -569,6 +569,9 @@ static inline void flush_tlb_page(struct vm_area_struct *vma, unsigned long a) flush_tlb_mm_range(vma->vm_mm, a, a + PAGE_SIZE, PAGE_SHIFT, false); } +void native_flush_tlb_multi(const struct cpumask *cpumask, +const struct flush_tlb_info *info); + void native_flush_tlb_others(const struct cpumask *cpumask, const struct flush_tlb_info *info); @@ -593,6 +596,9 @@ static inline void arch_tlbbatch_add_mm(struct arch_tlbflush_unmap_batch *batch, extern void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch); #ifndef CONFIG_PARAVIRT +#define flush_tlb_multi(mask, info)\ + native_flush_tlb_multi(mask, info) + #define flush_tlb_others(mask, info) \ native_flush_tlb_others(mask, info) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 3f0cc828cc36..c1c2b88ea3f1 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -643,6 +643,7 @@ static void __init kvm_guest_init(void) kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; pv_ops.mmu.tlb_remove_table = tlb_remove_table; + static_key_disable(_tlb_multi_enabled.key); } if