Peter Zijlstra
2019-May-27 09:47 UTC
[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 = &per_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(&flush_tlb_multi_enabled.key); } if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
Paolo Bonzini
2019-May-27 10:21 UTC
[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 = &per_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(&flush_tlb_multi_enabled.key); > } > > if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) >
Peter Zijlstra
2019-May-27 12:32 UTC
[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.
Nadav Amit
2019-May-27 17:49 UTC
[RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
> On May 27, 2019, at 2:47 AM, Peter Zijlstra <peterz at infradead.org> 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 = &per_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(&flush_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.
Seemingly Similar Threads
- [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
- [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently
- [PATCH v3 4/9] x86/mm/tlb: Flush remote and local TLBs concurrently
- [PATCH v2 4/9] x86/mm/tlb: Flush remote and local TLBs concurrently
- [RFC PATCH 5/6] x86/mm/tlb: Flush remote and local TLBs concurrently