Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3934499ybl; Mon, 3 Feb 2020 09:16:58 -0800 (PST) X-Google-Smtp-Source: APXvYqyYhxRNXv4ipgPX0lCULXu6VAKzTe342pzyhZ5p1Omu4f1gP8PjuDyceMUCP1TMsNz0iImd X-Received: by 2002:a05:6830:9a:: with SMTP id a26mr18760761oto.273.1580750218598; Mon, 03 Feb 2020 09:16:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580750218; cv=none; d=google.com; s=arc-20160816; b=xahIM6G4FoO555xbH5VPzYw9Ak2NTOFd5T7d4Q6yYfmIUTvon++/vAJg4ahdwe1ryN MKCd3D3kk8Jqvvyq5jlaOLEhLmpotpKzCIed/rCpktnvqv67yWJ5xYDsCo0pPZRCa9+D sPV3v5QyJCvvRjQTIeQpQtk0iolYqN/zpvZ7vtg4NbTTInNIDz/d7DpJFT3jQkDBHf8T fCoCJe8c92u9LNt9cgStmzUN+PymZRKAkr2WGLXE/d5Tz8GJiDaTAHCRxtSJBfY9WD/h DQQMEfagzKHB8HHjG6jlkuWKRssrV9yyrWcEdbWERPVhOwdE3y+miYzXGN7t8qkgn2ou Mx0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=dQK4ORCAhYC2TygAyENUq1Q+925Z/9wGLN91NM9l6UU=; b=ntoqI5viXiYZmvE4jMfWNsIaKQyyuzHesiSbeEj1RKN6Eevif9KRGITqbcYsRDhbrc i+Fy+7vSgaiPL2nlLCJ7G3giF8uNCm910YJDk4zmCp36sr3NdKMfwh0S4jeZjL2RTiFs 3YPiGm/2Bjh/bASWCSViOeqLyBJfvatr1mVczoR4nbQkpXJPRMpQhtPygBXhACK84Lnf 7VNd4OvHDRUM+jjDnsHs8S5IyoI7bHYhNBCSg5iTx0tY2F3BqXSWBZriQ2BBMsSuB225 isCkw4fIeTSpeYqcBxKT9N6eeWWY73SNQcxw5QmY7YomnjTkBlf3ASZioXiBOoi63sm3 PJaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qBazqR06; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 8si9141755ota.266.2020.02.03.09.16.46; Mon, 03 Feb 2020 09:16:58 -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=pass header.i=@google.com header.s=20161025 header.b=qBazqR06; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728603AbgBCPDF (ORCPT + 99 others); Mon, 3 Feb 2020 10:03:05 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40524 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727188AbgBCPDE (ORCPT ); Mon, 3 Feb 2020 10:03:04 -0500 Received: by mail-pg1-f195.google.com with SMTP id k25so7958252pgt.7 for ; Mon, 03 Feb 2020 07:03:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dQK4ORCAhYC2TygAyENUq1Q+925Z/9wGLN91NM9l6UU=; b=qBazqR061kVg8v/Z8p7nBu1H7IXupX7i4lpnY8jUobCGDQ/rxhNQypnA74Avdyk0QT 9vWGwBk+bGjA7/AdJJ2Kln8dtDBLuKYmoYZrpYh0+96J4SWcKi317h3DIDYFQ4eBbTgB KAnxFWfqoHtNtM9FT0ONAFtcW82nwvl3Gr4WMnbgH4lR96YaB2Wwx2zpGSK39KZP8rjf Tn7wRdP67jpxr7ArhQqUaWd2R4vxKk5xluqHm7F7pn9tUNcA0bKQgP0LCw+JoZ1Q0BJC 7XMw7kL0mCiBTZKZTY4P3Jg6ARZUlfa3jkymf0dPURusFWn/umMslprlVcR9VrpWEmNr /1rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dQK4ORCAhYC2TygAyENUq1Q+925Z/9wGLN91NM9l6UU=; b=fVIodv6zehKFlTXdn/KMZG32jfY7nz5WRMEkYloWOSYBbIsEUNiyY72OGZjf0rVNkk eG33SqUM1THot3sDaSTmmIkMJadsjwkITTCKqzbpgwVTWFJSupsY2+9RUCdBWtijkp0K s6vOgci3gHRi9i+phEyc9Jv0al3gbpfhIq7XiG2NiuhplS7MzdGk1zQRlvNyJDarSQQa aZnoSOkFsyKpwBBHAJTJ8VymVNK3cNJ1Z+jJfBTT4o/U3KDbV5MKhBaggrsWmFD78IfH 1U3dmP2l5a4WCjZKqtE+I/eLwGhCYNlMmtkChVNvXPi/c7DygJGG91Picckq/dEXz+Qw g3Ww== X-Gm-Message-State: APjAAAVnOxj5Cc3SC36EjBuVcPFQqB0Wdfm3OzVS5XUzY2kJhfjeyyp1 3ZBfZC/fPI+4b6bwvVGXL1a40z7vkWlkBYYZa44MQQ== X-Received: by 2002:a62:38c9:: with SMTP id f192mr25348029pfa.165.1580742182018; Mon, 03 Feb 2020 07:03:02 -0800 (PST) MIME-Version: 1.0 References: <20200127071602.11460-1-nick.desaulniers@gmail.com> In-Reply-To: From: Nick Desaulniers Date: Mon, 3 Feb 2020 15:02:50 +0000 Message-ID: Subject: Re: [PATCH] dynamically allocate struct cpumask To: Wanpeng Li Cc: Nick Desaulniers , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , "H. Peter Anvin" , "the arch/x86 maintainers" , kvm , LKML , clang-built-linux Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 3, 2020 at 8:32 AM Wanpeng Li wrote: > > Hi Nick, > On Mon, 27 Jan 2020 at 15:16, 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. > > Could you help test the below untested patch? > > From 867753e2fa27906f15df7902ba1bce7f9cef6ebe Mon Sep 17 00:00:00 2001 > From: Wanpeng Li > Date: Mon, 3 Feb 2020 16:26:35 +0800 > Subject: [PATCH] KVM: Pre-allocate 1 cpumask variable per cpu for both > pv tlb and pv ipis > > Reported-by: Nick Desaulniers > Signed-off-by: Wanpeng Li > --- > 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 81045aab..b1e8efa 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -425,6 +425,8 @@ static void __init sev_map_percpu_data(void) > } > } > > +static DEFINE_PER_CPU(cpumask_var_t, __pv_cpu_mask); > + > #ifdef CONFIG_SMP > #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) > > @@ -490,12 +492,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); Yes, this should help reduce the stack usage, thanks. Acked-by: Nick Desaulniers > 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); > } > > @@ -575,7 +577,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) > @@ -583,7 +584,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); > /* > @@ -624,6 +625,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; > + pr_info("KVM setup pv remote TLB flush\n"); > } > > if (kvm_para_has_feature(KVM_FEATURE_PV_EOI)) > @@ -732,23 +734,30 @@ 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_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && > !kvm_para_has_hint(KVM_HINTS_REALTIME) && > - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { > + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) > + alloc = true; > + > +#if defined(CONFIG_SMP) > + if (!alloc && kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI)) > + 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 > > -- > 1.8.3.1 > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/CANRm%2BCwK0Cg45mktda9Yz9fsjPCvtuB8O%2Bfma5L3tV725ki1qw%40mail.gmail.com. -- Thanks, ~Nick Desaulniers