Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3288884ybl; Mon, 27 Jan 2020 00:50:08 -0800 (PST) X-Google-Smtp-Source: APXvYqxuKrB3qonlm8kyYtqIQRCwHeliiZDFDJWq/h3DI5n+xEa2VFaQ0XokhW/zvKzP6AAr9gwM X-Received: by 2002:a05:6808:8e5:: with SMTP id d5mr6513433oic.154.1580115008239; Mon, 27 Jan 2020 00:50:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580115008; cv=none; d=google.com; s=arc-20160816; b=kz7YqSen8j20UpFmiSHKrNb1vDD/wyzuHSFEHbHHiYbOhJrbfuy8TUS0FiZ+pyMVb8 +dTvGRmA08olcJOt+F5x60cN1BlzjxaZI624zAtAlnNopgLmPmRzBJ1QhxkU/1JpxdPT DBQs5MBgZQZKaDJm7VajkncLSRG9N8UewgiQ9ofWj1igzpkPqg04ofFvo8jbQRED3loL 8AZF8FtuHgw48iYavN0LL7JYIDI8fpaHct9CegJw+gRIMmELUDxjwtYeWzr1QkPfzQmQ 8Ao0BfjFvNBUW+OIazuVSiIMcyNOTMY+A1FowTQ+lLaZmLu5pbhMVg5+AwNXQFj/saxj ODUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NSkXKOkLVFSqskr8Fv8C50qKSUgO0Fch8+tEjDsF97E=; b=C6E58mPI0F7C5mGji+1R2uH6oOOvqO3IE6d0EqROLg6B5G87vHwtH73UB0ZidKu44s CHEUtni5Drw0WQeumOT6kAy01OZEIVKfIKOlEerJSqNTOBVWUXtFABgfNyMu0cYZ6C99 K+lTPAMi6Sdev8Nu5BIbRZ/Xbb8ZtUnAtGdx+fVmMtEA7KzPtO0Nav1Av9fbSUH1KzK1 YQdNg1YDXlhVoKufH16iEdK4ZbS0m9aKAN1TxkaFX9pDnSBDM9V9XfvNnQMR7tyYV5dL dZIPJOC7pdGm/A3x9hIzdBMhoRySQaEMWnwhjc+6qh1t1iwYnpxJU8lYnpOzv0dYVCYk O2MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=F4hAZJLK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s74si3182344oie.109.2020.01.27.00.49.55; Mon, 27 Jan 2020 00:50:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=F4hAZJLK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728292AbgA0IKE (ORCPT + 99 others); Mon, 27 Jan 2020 03:10:04 -0500 Received: from merlin.infradead.org ([205.233.59.134]:56232 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbgA0IKE (ORCPT ); Mon, 27 Jan 2020 03:10:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NSkXKOkLVFSqskr8Fv8C50qKSUgO0Fch8+tEjDsF97E=; b=F4hAZJLK7Fe2reLHo/KcRVnHz 0Z8pBkj5nWzXnOz7AKhokwWpIjmIr+RMt6mUxbe1naCa2WJE5MDnXarGvxwFNNinfvMQqbrjEcXjy nLRoVrupuxBlAXhn/0MiqkhQ1G1NiDaj7IwcCKW/0JlURpDfwNnZxwfpMpZ8kRvF1fWhcuOmynjPE NcEFeH37cjRNaUhPuN7GBOmhQ8/sAiPatuige+3tUyGRoLMCG2qg2wESc1KELSf0u8NDu1ZhXylb/ kmdqyd7feqDD/2g5BzYWwC9oKl1t30bva3v5s2XRn+NNWzKLVL4yqOoLrqhVS7jVngUj0xo7V+tsq 0aqGhlCrw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ivzSk-0004Vq-1F; Mon, 27 Jan 2020 08:09:38 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 437B2300F4B; Mon, 27 Jan 2020 09:07:54 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 08180203CF5D4; Mon, 27 Jan 2020 09:09:36 +0100 (CET) Date: Mon, 27 Jan 2020 09:09:36 +0100 From: Peter Zijlstra To: Nick Desaulniers Cc: pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, clang-built-linux@googlegroups.com Subject: Re: [PATCH] dynamically allocate struct cpumask Message-ID: <20200127080935.GH14914@hirez.programming.kicks-ass.net> References: <20200127071602.11460-1-nick.desaulniers@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200127071602.11460-1-nick.desaulniers@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > --- > 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); > + 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.