* [PATCH RESEND v2 1/2] KVM: Introduce pv check helpers
@ 2020-02-18 1:08 Wanpeng Li
2020-02-18 1:08 ` [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis Wanpeng Li
0 siblings, 1 reply; 8+ messages in thread
From: Wanpeng Li @ 2020-02-18 1:08 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel
From: Wanpeng Li <wanpengli@tencent.com>
Introduce some pv check helpers for consistency.
Suggested-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
arch/x86/kernel/kvm.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index d817f25..76ea8c4 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -425,7 +425,27 @@ static void __init sev_map_percpu_data(void)
}
}
+static bool pv_tlb_flush_supported(void)
+{
+ return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) &&
+ !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
+ kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+}
+
#ifdef CONFIG_SMP
+
+static bool pv_ipi_supported(void)
+{
+ return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI);
+}
+
+static bool pv_sched_yield_supported(void)
+{
+ return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
+ !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
+ kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
+}
+
#define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG)
static void __send_ipi_mask(const struct cpumask *mask, int vector)
@@ -619,9 +639,7 @@ static void __init kvm_guest_init(void)
pv_ops.time.steal_clock = kvm_steal_clock;
}
- 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)) {
+ if (pv_tlb_flush_supported()) {
pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
pv_ops.mmu.tlb_remove_table = tlb_remove_table;
}
@@ -632,9 +650,7 @@ static void __init kvm_guest_init(void)
#ifdef CONFIG_SMP
smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus;
smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
- if (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) &&
- !kvm_para_has_hint(KVM_HINTS_REALTIME) &&
- kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
+ if (pv_sched_yield_supported()) {
smp_ops.send_call_func_ipi = kvm_smp_send_call_func_ipi;
pr_info("KVM setup pv sched yield\n");
}
@@ -700,7 +716,7 @@ static uint32_t __init kvm_detect(void)
static void __init kvm_apic_init(void)
{
#if defined(CONFIG_SMP)
- if (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI))
+ if (pv_ipi_supported())
kvm_setup_pv_ipi();
#endif
}
@@ -739,9 +755,7 @@ static __init int kvm_setup_pv_tlb_flush(void)
if (!kvm_para_available() || nopv)
return 0;
- 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)) {
+ if (pv_tlb_flush_supported()) {
for_each_possible_cpu(cpu) {
zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
GFP_KERNEL, cpu_to_node(cpu));
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-18 1:08 [PATCH RESEND v2 1/2] KVM: Introduce pv check helpers Wanpeng Li
@ 2020-02-18 1:08 ` Wanpeng Li
2020-02-25 7:55 ` Wanpeng Li
2020-02-28 9:35 ` Paolo Bonzini
0 siblings, 2 replies; 8+ messages in thread
From: Wanpeng Li @ 2020-02-18 1:08 UTC (permalink / raw)
To: linux-kernel, kvm
Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel, Peter Zijlstra, Nick Desaulniers
From: Wanpeng Li <wanpengli@tencent.com>
Nick Desaulniers Reported:
When building with:
$ make CC=clang arch/x86/ CFLAGS=-Wframe-larger-than=1000
The following warning is observed:
arch/x86/kernel/kvm.c:494:13: warning: stack frame size of 1064 bytes in
function 'kvm_send_ipi_mask_allbutself' [-Wframe-larger-than=]
static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int
vector)
^
Debugging with:
https://github.com/ClangBuiltLinux/frame-larger-than
via:
$ python3 frame_larger_than.py arch/x86/kernel/kvm.o \
kvm_send_ipi_mask_allbutself
points to the stack allocated `struct cpumask newmask` in
`kvm_send_ipi_mask_allbutself`. The size of a `struct cpumask` is
potentially large, as it's CONFIG_NR_CPUS divided by BITS_PER_LONG for
the target architecture. CONFIG_NR_CPUS for X86_64 can be as high as
8192, making a single instance of a `struct cpumask` 1024 B.
This patch fixes it by pre-allocate 1 cpumask variable per cpu and use it for
both pv tlb and pv ipis..
Reported-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Nick Desaulniers <ndesaulniers@google.com>
Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
---
v1 -> v2:
* remove '!alloc' check
* use new pv check helpers
arch/x86/kernel/kvm.c | 33 +++++++++++++++++++++------------
1 file changed, 21 insertions(+), 12 deletions(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 76ea8c4..377b224 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -432,6 +432,8 @@ static bool pv_tlb_flush_supported(void)
kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
}
+static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask);
+
#ifdef CONFIG_SMP
static bool pv_ipi_supported(void)
@@ -510,12 +512,12 @@ static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
{
unsigned int this_cpu = smp_processor_id();
- struct cpumask new_mask;
+ struct cpumask *new_mask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
const struct cpumask *local_mask;
- cpumask_copy(&new_mask, mask);
- cpumask_clear_cpu(this_cpu, &new_mask);
- local_mask = &new_mask;
+ cpumask_copy(new_mask, mask);
+ cpumask_clear_cpu(this_cpu, new_mask);
+ local_mask = new_mask;
__send_ipi_mask(local_mask, vector);
}
@@ -595,7 +597,6 @@ static void __init kvm_apf_trap_init(void)
update_intr_gate(X86_TRAP_PF, async_page_fault);
}
-static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
static void kvm_flush_tlb_others(const struct cpumask *cpumask,
const struct flush_tlb_info *info)
@@ -603,7 +604,7 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask,
u8 state;
int cpu;
struct kvm_steal_time *src;
- struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
+ struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
cpumask_copy(flushmask, cpumask);
/*
@@ -642,6 +643,7 @@ static void __init kvm_guest_init(void)
if (pv_tlb_flush_supported()) {
pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
pv_ops.mmu.tlb_remove_table = tlb_remove_table;
+ pr_info("KVM setup pv remote TLB flush\n");
}
if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
@@ -748,24 +750,31 @@ static __init int activate_jump_labels(void)
}
arch_initcall(activate_jump_labels);
-static __init int kvm_setup_pv_tlb_flush(void)
+static __init int kvm_alloc_cpumask(void)
{
int cpu;
+ bool alloc = false;
if (!kvm_para_available() || nopv)
return 0;
- if (pv_tlb_flush_supported()) {
+ if (pv_tlb_flush_supported())
+ alloc = true;
+
+#if defined(CONFIG_SMP)
+ if (pv_ipi_supported())
+ alloc = true;
+#endif
+
+ if (alloc)
for_each_possible_cpu(cpu) {
- zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
+ zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu),
GFP_KERNEL, cpu_to_node(cpu));
}
- pr_info("KVM setup pv remote TLB flush\n");
- }
return 0;
}
-arch_initcall(kvm_setup_pv_tlb_flush);
+arch_initcall(kvm_alloc_cpumask);
#ifdef CONFIG_PARAVIRT_SPINLOCKS
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-18 1:08 ` [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis Wanpeng Li
@ 2020-02-25 7:55 ` Wanpeng Li
2020-02-25 19:15 ` Nick Desaulniers
2020-02-28 9:35 ` Paolo Bonzini
1 sibling, 1 reply; 8+ messages in thread
From: Wanpeng Li @ 2020-02-25 7:55 UTC (permalink / raw)
To: LKML, kvm
Cc: Paolo Bonzini, Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li,
Jim Mattson, Joerg Roedel, Peter Zijlstra, Nick Desaulniers
ping,
On Tue, 18 Feb 2020 at 09:12, Wanpeng Li <kernellwp@gmail.com> wrote:
>
> From: Wanpeng Li <wanpengli@tencent.com>
>
> Nick Desaulniers Reported:
>
> When building with:
> $ make CC=clang arch/x86/ CFLAGS=-Wframe-larger-than=1000
> The following warning is observed:
> arch/x86/kernel/kvm.c:494:13: warning: stack frame size of 1064 bytes in
> function 'kvm_send_ipi_mask_allbutself' [-Wframe-larger-than=]
> static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int
> vector)
> ^
> Debugging with:
> https://github.com/ClangBuiltLinux/frame-larger-than
> via:
> $ python3 frame_larger_than.py arch/x86/kernel/kvm.o \
> kvm_send_ipi_mask_allbutself
> points to the stack allocated `struct cpumask newmask` in
> `kvm_send_ipi_mask_allbutself`. The size of a `struct cpumask` is
> potentially large, as it's CONFIG_NR_CPUS divided by BITS_PER_LONG for
> the target architecture. CONFIG_NR_CPUS for X86_64 can be as high as
> 8192, making a single instance of a `struct cpumask` 1024 B.
>
> This patch fixes it by pre-allocate 1 cpumask variable per cpu and use it for
> both pv tlb and pv ipis..
>
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Acked-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> v1 -> v2:
> * remove '!alloc' check
> * use new pv check helpers
>
> arch/x86/kernel/kvm.c | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 76ea8c4..377b224 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -432,6 +432,8 @@ static bool pv_tlb_flush_supported(void)
> kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
> }
>
> +static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask);
> +
> #ifdef CONFIG_SMP
>
> static bool pv_ipi_supported(void)
> @@ -510,12 +512,12 @@ static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
> {
> unsigned int this_cpu = smp_processor_id();
> - struct cpumask new_mask;
> + struct cpumask *new_mask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
> const struct cpumask *local_mask;
>
> - cpumask_copy(&new_mask, mask);
> - cpumask_clear_cpu(this_cpu, &new_mask);
> - local_mask = &new_mask;
> + cpumask_copy(new_mask, mask);
> + cpumask_clear_cpu(this_cpu, new_mask);
> + local_mask = new_mask;
> __send_ipi_mask(local_mask, vector);
> }
>
> @@ -595,7 +597,6 @@ static void __init kvm_apf_trap_init(void)
> update_intr_gate(X86_TRAP_PF, async_page_fault);
> }
>
> -static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
>
> static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> const struct flush_tlb_info *info)
> @@ -603,7 +604,7 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> u8 state;
> int cpu;
> struct kvm_steal_time *src;
> - struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
> + struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
>
> cpumask_copy(flushmask, cpumask);
> /*
> @@ -642,6 +643,7 @@ static void __init kvm_guest_init(void)
> if (pv_tlb_flush_supported()) {
> pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
> pv_ops.mmu.tlb_remove_table = tlb_remove_table;
> + pr_info("KVM setup pv remote TLB flush\n");
> }
>
> if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
> @@ -748,24 +750,31 @@ static __init int activate_jump_labels(void)
> }
> arch_initcall(activate_jump_labels);
>
> -static __init int kvm_setup_pv_tlb_flush(void)
> +static __init int kvm_alloc_cpumask(void)
> {
> int cpu;
> + bool alloc = false;
>
> if (!kvm_para_available() || nopv)
> return 0;
>
> - if (pv_tlb_flush_supported()) {
> + if (pv_tlb_flush_supported())
> + alloc = true;
> +
> +#if defined(CONFIG_SMP)
> + if (pv_ipi_supported())
> + alloc = true;
> +#endif
> +
> + if (alloc)
> for_each_possible_cpu(cpu) {
> - zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
> + zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu),
> GFP_KERNEL, cpu_to_node(cpu));
> }
> - pr_info("KVM setup pv remote TLB flush\n");
> - }
>
> return 0;
> }
> -arch_initcall(kvm_setup_pv_tlb_flush);
> +arch_initcall(kvm_alloc_cpumask);
>
> #ifdef CONFIG_PARAVIRT_SPINLOCKS
>
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-25 7:55 ` Wanpeng Li
@ 2020-02-25 19:15 ` Nick Desaulniers
2020-02-26 13:10 ` Vitaly Kuznetsov
0 siblings, 1 reply; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-25 19:15 UTC (permalink / raw)
To: Paolo Bonzini, Vitaly Kuznetsov
Cc: LKML, kvm, Sean Christopherson, Wanpeng Li, Jim Mattson,
Joerg Roedel, Peter Zijlstra, Wanpeng Li
(putting Paolo in To: field, in case email filters are to blame.
Vitaly, maybe you could ping Paolo internally?)
On Mon, Feb 24, 2020 at 11:55 PM Wanpeng Li <kernellwp@gmail.com> wrote:
>
> ping,
> On Tue, 18 Feb 2020 at 09:12, Wanpeng Li <kernellwp@gmail.com> wrote:
> >
> > From: Wanpeng Li <wanpengli@tencent.com>
> >
> > Nick Desaulniers Reported:
> >
> > When building with:
> > $ make CC=clang arch/x86/ CFLAGS=-Wframe-larger-than=1000
> > The following warning is observed:
> > arch/x86/kernel/kvm.c:494:13: warning: stack frame size of 1064 bytes in
> > function 'kvm_send_ipi_mask_allbutself' [-Wframe-larger-than=]
> > static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int
> > vector)
> > ^
> > Debugging with:
> > https://github.com/ClangBuiltLinux/frame-larger-than
> > via:
> > $ python3 frame_larger_than.py arch/x86/kernel/kvm.o \
> > kvm_send_ipi_mask_allbutself
> > points to the stack allocated `struct cpumask newmask` in
> > `kvm_send_ipi_mask_allbutself`. The size of a `struct cpumask` is
> > potentially large, as it's CONFIG_NR_CPUS divided by BITS_PER_LONG for
> > the target architecture. CONFIG_NR_CPUS for X86_64 can be as high as
> > 8192, making a single instance of a `struct cpumask` 1024 B.
> >
> > This patch fixes it by pre-allocate 1 cpumask variable per cpu and use it for
> > both pv tlb and pv ipis..
> >
> > Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> > Acked-by: Nick Desaulniers <ndesaulniers@google.com>
> > Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> > ---
> > v1 -> v2:
> > * remove '!alloc' check
> > * use new pv check helpers
> >
> > arch/x86/kernel/kvm.c | 33 +++++++++++++++++++++------------
> > 1 file changed, 21 insertions(+), 12 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > index 76ea8c4..377b224 100644
> > --- a/arch/x86/kernel/kvm.c
> > +++ b/arch/x86/kernel/kvm.c
> > @@ -432,6 +432,8 @@ static bool pv_tlb_flush_supported(void)
> > kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
> > }
> >
> > +static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask);
> > +
> > #ifdef CONFIG_SMP
> >
> > static bool pv_ipi_supported(void)
> > @@ -510,12 +512,12 @@ static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> > static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
> > {
> > unsigned int this_cpu = smp_processor_id();
> > - struct cpumask new_mask;
> > + struct cpumask *new_mask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
> > const struct cpumask *local_mask;
> >
> > - cpumask_copy(&new_mask, mask);
> > - cpumask_clear_cpu(this_cpu, &new_mask);
> > - local_mask = &new_mask;
> > + cpumask_copy(new_mask, mask);
> > + cpumask_clear_cpu(this_cpu, new_mask);
> > + local_mask = new_mask;
> > __send_ipi_mask(local_mask, vector);
> > }
> >
> > @@ -595,7 +597,6 @@ static void __init kvm_apf_trap_init(void)
> > update_intr_gate(X86_TRAP_PF, async_page_fault);
> > }
> >
> > -static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
> >
> > static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> > const struct flush_tlb_info *info)
> > @@ -603,7 +604,7 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> > u8 state;
> > int cpu;
> > struct kvm_steal_time *src;
> > - struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
> > + struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
> >
> > cpumask_copy(flushmask, cpumask);
> > /*
> > @@ -642,6 +643,7 @@ static void __init kvm_guest_init(void)
> > if (pv_tlb_flush_supported()) {
> > pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
> > pv_ops.mmu.tlb_remove_table = tlb_remove_table;
> > + pr_info("KVM setup pv remote TLB flush\n");
> > }
> >
> > if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
> > @@ -748,24 +750,31 @@ static __init int activate_jump_labels(void)
> > }
> > arch_initcall(activate_jump_labels);
> >
> > -static __init int kvm_setup_pv_tlb_flush(void)
> > +static __init int kvm_alloc_cpumask(void)
> > {
> > int cpu;
> > + bool alloc = false;
> >
> > if (!kvm_para_available() || nopv)
> > return 0;
> >
> > - if (pv_tlb_flush_supported()) {
> > + if (pv_tlb_flush_supported())
> > + alloc = true;
> > +
> > +#if defined(CONFIG_SMP)
> > + if (pv_ipi_supported())
> > + alloc = true;
> > +#endif
> > +
> > + if (alloc)
> > for_each_possible_cpu(cpu) {
> > - zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
> > + zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu),
> > GFP_KERNEL, cpu_to_node(cpu));
> > }
> > - pr_info("KVM setup pv remote TLB flush\n");
> > - }
> >
> > return 0;
> > }
> > -arch_initcall(kvm_setup_pv_tlb_flush);
> > +arch_initcall(kvm_alloc_cpumask);
> >
> > #ifdef CONFIG_PARAVIRT_SPINLOCKS
> >
> > --
> > 2.7.4
> >
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-25 19:15 ` Nick Desaulniers
@ 2020-02-26 13:10 ` Vitaly Kuznetsov
2020-02-26 13:26 ` Paolo Bonzini
0 siblings, 1 reply; 8+ messages in thread
From: Vitaly Kuznetsov @ 2020-02-26 13:10 UTC (permalink / raw)
To: Nick Desaulniers, Paolo Bonzini
Cc: LKML, kvm, Sean Christopherson, Wanpeng Li, Jim Mattson,
Joerg Roedel, Peter Zijlstra, Wanpeng Li
Nick Desaulniers <ndesaulniers@google.com> writes:
> (putting Paolo in To: field, in case email filters are to blame.
> Vitaly, maybe you could ping Paolo internally?)
>
I could, but the only difference from what I'm doing right now would
proabbly be the absence of non-@redaht.com emails in To/Cc: fields of
this email :-)
Do we want this fix for one of the last 5.6 RCs or 5.7 would be fine?
Personally, I'd say we're not in a great hurry and 5.7 is OK.
--
Vitaly
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-26 13:10 ` Vitaly Kuznetsov
@ 2020-02-26 13:26 ` Paolo Bonzini
2020-02-27 23:49 ` Nick Desaulniers
0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2020-02-26 13:26 UTC (permalink / raw)
To: Vitaly Kuznetsov, Nick Desaulniers
Cc: LKML, kvm, Sean Christopherson, Wanpeng Li, Jim Mattson,
Joerg Roedel, Peter Zijlstra, Wanpeng Li
On 26/02/20 14:10, Vitaly Kuznetsov wrote:
> Nick Desaulniers <ndesaulniers@google.com> writes:
>
>> (putting Paolo in To: field, in case email filters are to blame.
>> Vitaly, maybe you could ping Paolo internally?)
>>
>
> I could, but the only difference from what I'm doing right now would
> proabbly be the absence of non-@redaht.com emails in To/Cc: fields of
> this email :-)
>
> Do we want this fix for one of the last 5.6 RCs or 5.7 would be fine?
> Personally, I'd say we're not in a great hurry and 5.7 is OK.
I think we can do it for 5.6, but we're not in a great hurry. :) The
rc4 pull request was already going to be relatively large and I had just
been scolded by Linus so I postponed this, but I am going to include it
this week.
Paolo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-26 13:26 ` Paolo Bonzini
@ 2020-02-27 23:49 ` Nick Desaulniers
0 siblings, 0 replies; 8+ messages in thread
From: Nick Desaulniers @ 2020-02-27 23:49 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Vitaly Kuznetsov, LKML, kvm, Sean Christopherson, Wanpeng Li,
Jim Mattson, Joerg Roedel, Peter Zijlstra, Wanpeng Li
On Wed, Feb 26, 2020 at 5:27 AM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 26/02/20 14:10, Vitaly Kuznetsov wrote:
> > Nick Desaulniers <ndesaulniers@google.com> writes:
> >
> >> (putting Paolo in To: field, in case email filters are to blame.
> >> Vitaly, maybe you could ping Paolo internally?)
> >>
> >
> > I could, but the only difference from what I'm doing right now would
> > proabbly be the absence of non-@redaht.com emails in To/Cc: fields of
> > this email :-)
> >
> > Do we want this fix for one of the last 5.6 RCs or 5.7 would be fine?
> > Personally, I'd say we're not in a great hurry and 5.7 is OK.
>
> I think we can do it for 5.6, but we're not in a great hurry. :) The
> rc4 pull request was already going to be relatively large and I had just
> been scolded by Linus so I postponed this, but I am going to include it
> this week.
No rush; soak time is good.
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis
2020-02-18 1:08 ` [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis Wanpeng Li
2020-02-25 7:55 ` Wanpeng Li
@ 2020-02-28 9:35 ` Paolo Bonzini
1 sibling, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2020-02-28 9:35 UTC (permalink / raw)
To: Wanpeng Li, linux-kernel, kvm
Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
Joerg Roedel, Peter Zijlstra, Nick Desaulniers
On 18/02/20 02:08, Wanpeng Li wrote:
> From: Wanpeng Li <wanpengli@tencent.com>
>
> Nick Desaulniers Reported:
>
> When building with:
> $ make CC=clang arch/x86/ CFLAGS=-Wframe-larger-than=1000
> The following warning is observed:
> arch/x86/kernel/kvm.c:494:13: warning: stack frame size of 1064 bytes in
> function 'kvm_send_ipi_mask_allbutself' [-Wframe-larger-than=]
> static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int
> vector)
> ^
> Debugging with:
> https://github.com/ClangBuiltLinux/frame-larger-than
> via:
> $ python3 frame_larger_than.py arch/x86/kernel/kvm.o \
> kvm_send_ipi_mask_allbutself
> points to the stack allocated `struct cpumask newmask` in
> `kvm_send_ipi_mask_allbutself`. The size of a `struct cpumask` is
> potentially large, as it's CONFIG_NR_CPUS divided by BITS_PER_LONG for
> the target architecture. CONFIG_NR_CPUS for X86_64 can be as high as
> 8192, making a single instance of a `struct cpumask` 1024 B.
>
> This patch fixes it by pre-allocate 1 cpumask variable per cpu and use it for
> both pv tlb and pv ipis..
>
> Reported-by: Nick Desaulniers <ndesaulniers@google.com>
> Acked-by: Nick Desaulniers <ndesaulniers@google.com>
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Wanpeng Li <wanpengli@tencent.com>
> ---
> v1 -> v2:
> * remove '!alloc' check
> * use new pv check helpers
>
> arch/x86/kernel/kvm.c | 33 +++++++++++++++++++++------------
> 1 file changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 76ea8c4..377b224 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -432,6 +432,8 @@ static bool pv_tlb_flush_supported(void)
> kvm_para_has_feature(KVM_FEATURE_STEAL_TIME));
> }
>
> +static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask);
> +
> #ifdef CONFIG_SMP
>
> static bool pv_ipi_supported(void)
> @@ -510,12 +512,12 @@ static void kvm_send_ipi_mask(const struct cpumask *mask, int vector)
> static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)
> {
> unsigned int this_cpu = smp_processor_id();
> - struct cpumask new_mask;
> + struct cpumask *new_mask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
> const struct cpumask *local_mask;
>
> - cpumask_copy(&new_mask, mask);
> - cpumask_clear_cpu(this_cpu, &new_mask);
> - local_mask = &new_mask;
> + cpumask_copy(new_mask, mask);
> + cpumask_clear_cpu(this_cpu, new_mask);
> + local_mask = new_mask;
> __send_ipi_mask(local_mask, vector);
> }
>
> @@ -595,7 +597,6 @@ static void __init kvm_apf_trap_init(void)
> update_intr_gate(X86_TRAP_PF, async_page_fault);
> }
>
> -static DEFINE_PER_CPU(cpumask_var_t, __pv_tlb_mask);
>
> static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> const struct flush_tlb_info *info)
> @@ -603,7 +604,7 @@ static void kvm_flush_tlb_others(const struct cpumask *cpumask,
> u8 state;
> int cpu;
> struct kvm_steal_time *src;
> - struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_tlb_mask);
> + struct cpumask *flushmask = this_cpu_cpumask_var_ptr(__pv_cpu_mask);
>
> cpumask_copy(flushmask, cpumask);
> /*
> @@ -642,6 +643,7 @@ static void __init kvm_guest_init(void)
> if (pv_tlb_flush_supported()) {
> pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others;
> pv_ops.mmu.tlb_remove_table = tlb_remove_table;
> + pr_info("KVM setup pv remote TLB flush\n");
> }
>
> if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
> @@ -748,24 +750,31 @@ static __init int activate_jump_labels(void)
> }
> arch_initcall(activate_jump_labels);
>
> -static __init int kvm_setup_pv_tlb_flush(void)
> +static __init int kvm_alloc_cpumask(void)
> {
> int cpu;
> + bool alloc = false;
>
> if (!kvm_para_available() || nopv)
> return 0;
>
> - if (pv_tlb_flush_supported()) {
> + if (pv_tlb_flush_supported())
> + alloc = true;
> +
> +#if defined(CONFIG_SMP)
> + if (pv_ipi_supported())
> + alloc = true;
> +#endif
> +
> + if (alloc)
> for_each_possible_cpu(cpu) {
> - zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu),
> + zalloc_cpumask_var_node(per_cpu_ptr(&__pv_cpu_mask, cpu),
> GFP_KERNEL, cpu_to_node(cpu));
> }
> - pr_info("KVM setup pv remote TLB flush\n");
> - }
>
> return 0;
> }
> -arch_initcall(kvm_setup_pv_tlb_flush);
> +arch_initcall(kvm_alloc_cpumask);
>
> #ifdef CONFIG_PARAVIRT_SPINLOCKS
>
>
Queued now, thanks.
Paolo
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-02-28 9:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-18 1:08 [PATCH RESEND v2 1/2] KVM: Introduce pv check helpers Wanpeng Li
2020-02-18 1:08 ` [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis Wanpeng Li
2020-02-25 7:55 ` Wanpeng Li
2020-02-25 19:15 ` Nick Desaulniers
2020-02-26 13:10 ` Vitaly Kuznetsov
2020-02-26 13:26 ` Paolo Bonzini
2020-02-27 23:49 ` Nick Desaulniers
2020-02-28 9:35 ` Paolo Bonzini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.