From: Nick Desaulniers <nick.desaulniers@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
bp@alien8.de,
Sean Christopherson <sean.j.christopherson@intel.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
"H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, kvm@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH] dynamically allocate struct cpumask
Date: Mon, 27 Jan 2020 00:14:27 -0800 [thread overview]
Message-ID: <CAH7mPvi9uH6210Np2GmzaMDY7k7MNRaBZdwhPakLu8ZEfoq0pQ@mail.gmail.com> (raw)
In-Reply-To: <20200127080935.GH14914@hirez.programming.kicks-ass.net>
On Mon, Jan 27, 2020 at 12:09 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Sun, Jan 26, 2020 at 11:16:02PM -0800, Nick Desaulniers wrote:
> > This helps avoid avoid a potentially large stack allocation.
> >
> > 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.
> >
> > Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
> > ---
> > arch/x86/kernel/kvm.c | 10 ++++++----
> > 1 file changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > index 32ef1ee733b7..d41c0a0d62a2 100644
> > --- a/arch/x86/kernel/kvm.c
> > +++ b/arch/x86/kernel/kvm.c
> > @@ -494,13 +494,15 @@ 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;
>
> Right, on stack cpumask is definitely dodgy.
>
> > + struct cpumask *new_mask;
> > const struct cpumask *local_mask;
> >
> > - cpumask_copy(&new_mask, mask);
> > - cpumask_clear_cpu(this_cpu, &new_mask);
> > - local_mask = &new_mask;
> > + new_mask = kmalloc(sizeof(*new_mask), GFP_KERNEL);
Probably should check for allocation failure, d'oh!
> > + cpumask_copy(new_mask, mask);
> > + cpumask_clear_cpu(this_cpu, new_mask);
> > + local_mask = new_mask;
> > __send_ipi_mask(local_mask, vector);
> > + kfree(new_mask);
> > }
>
> One alternative approach is adding the inverse of cpu_bit_bitmap. I'm
> not entirely sure how often we need the all-but-self mask, but ISTR
> there were other places too.
next prev parent reply other threads:[~2020-01-27 8:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-27 7:16 [PATCH] dynamically allocate struct cpumask Nick Desaulniers
2020-01-27 8:09 ` Peter Zijlstra
2020-01-27 8:14 ` Nick Desaulniers [this message]
2020-01-27 8:56 ` Vitaly Kuznetsov
2020-02-03 8:31 ` Wanpeng Li
2020-02-03 15:02 ` Nick Desaulniers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH7mPvi9uH6210Np2GmzaMDY7k7MNRaBZdwhPakLu8ZEfoq0pQ@mail.gmail.com \
--to=nick.desaulniers@gmail.com \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--cc=hpa@zytor.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=sean.j.christopherson@intel.com \
--cc=tglx@linutronix.de \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).