Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp476452ybf; Fri, 28 Feb 2020 01:35:32 -0800 (PST) X-Google-Smtp-Source: APXvYqweVtIUiHTGMKiABi5lQ4ES80N8Emnh1lw91CCTmIpUZYiz7aBGd9Cph/aeyk1Vz/6F+wAL X-Received: by 2002:aca:b504:: with SMTP id e4mr2558890oif.28.1582882532761; Fri, 28 Feb 2020 01:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582882532; cv=none; d=google.com; s=arc-20160816; b=ya6jRz7b4Ew4dBl1mEkZDYaQb+4a2JeZygkW/aAHaLLteBilO3xWFzfDhgYiaO3avd EH4Ai8b2JusuQN4XOCbe1AOWBOBxruXUOZyoZ/sMjo6L1omdKVl58m0iC+pSgCF0nwkf AVDVlWEJ68gOrrDXl6g49d+oz75dnOLdTITJ/0BWf5/2YXhmU3QKkLa1z08E0g2cQ/Ok B3EhLXDPgWLs891nIp1KgU5rnuRtCj4J1ULM+4cBUV4RcaV6gVPnIhydQLJibg9Ko2Mo uXuGOybcvhlwYNDkmHQ+1/Br9fAAh/5pFecIerVZkhrnIG3YYaQmXELGbimeCKAAFafm SbiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=DpY+KYD45ZukUr2uiluCWuyD5nGDLRfeur7I9dYkvWA=; b=zFOZ7zbhwICi7ZgkfuWycWlSyMzwoCAuwXBbxI2aafs6TvOj5/NSGaKtMuKOMBID1f 1w1qvXZQsHPBivDelSi8IApnGDmlUhtehPlTECcYjQvt+fSNAlgaBxYX8/rKo8Qm1S1E oRLdCn3W8g3lUWBOQaqqtpmtye84JdF6P0ci1GN9JZekGfHYwz+B5A8gGKERldhA0V3C PVYapJV8gJTq+1FjU5sUbqhdLRKoThmd+nubAvD8LYgGfR0lbwZxdMee//yiZ5Neu04o 5KhRaiG0BjuxH3Q/BZFpaprTwE5aubBKV0aTdvKKtSBQ0g1nlUFmapbj1tRNbqn5GZeB ShaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dkU+tfuE; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f23si1244478oto.205.2020.02.28.01.35.20; Fri, 28 Feb 2020 01:35:32 -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=@redhat.com header.s=mimecast20190719 header.b=dkU+tfuE; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726810AbgB1JfM (ORCPT + 99 others); Fri, 28 Feb 2020 04:35:12 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:36995 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726673AbgB1JfM (ORCPT ); Fri, 28 Feb 2020 04:35:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582882511; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DpY+KYD45ZukUr2uiluCWuyD5nGDLRfeur7I9dYkvWA=; b=dkU+tfuE10tfIrsv3AXDDuU3NFg/xeNTjBj0QmlQrxTRKA7un2HMeIFhcMoRYxRRmb4l9L Cx8cpC8vgrOjlq3S5RJ+FJtk1e0NecQJ8rokV1YQWut0f6xsuGTgFdmYM/+pObkwbncZ7T 97zIMEmARgDtyvYC6lcH60kBYInvnXs= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-333-QoqrWToSMdOwCeCKmHYcAw-1; Fri, 28 Feb 2020 04:35:08 -0500 X-MC-Unique: QoqrWToSMdOwCeCKmHYcAw-1 Received: by mail-wr1-f70.google.com with SMTP id j32so1060907wre.13 for ; Fri, 28 Feb 2020 01:35:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DpY+KYD45ZukUr2uiluCWuyD5nGDLRfeur7I9dYkvWA=; b=kbuP7XiJ8jTuzsArVrZOjCT7kzhZVe4bNOu6XrRUVFzAy9pqy36HqAL/cGaMMhuIXy 0hNzdnyT1QEnufOIDtsU3t4R5KC243u/6Vvl8WAbMFRyHNMKO8hlkMMbsLkuPqTl4X3x a1a3RYqvUhd1zNB89bXu/NxErVn9LPecIkHMQ/T+R9V4wgr2qIrcuxqqgZnAxmTxYPhb oFuKH4BxqBA9e8udWQQnjJw74twa1JQZHc4yMSPDgPWkcDvBYlC6i76Vq7wU2TrOUo18 fCzehyD0HSln7NFzeALJmAo/3PySoMRp3AdJLnTUo62LoguYt8xyL4/12AqRf1Z0Xs1H uvEQ== X-Gm-Message-State: APjAAAUTaYzNLKMJLSPCI3OWVkcLavOUfI2K3rJ9js6xX1rOlVGKtVXB TiLLOx9WtQkpTpnfBMlHMz4YKDjctAXn1GS2poqsduvqa6IvMAYHOGovagpHraUmxz1drQu5Udc C/rklVKD8rfNicI06mBSSZ9/3 X-Received: by 2002:adf:ecca:: with SMTP id s10mr4127725wro.255.1582882507328; Fri, 28 Feb 2020 01:35:07 -0800 (PST) X-Received: by 2002:adf:ecca:: with SMTP id s10mr4127691wro.255.1582882507036; Fri, 28 Feb 2020 01:35:07 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:d0d9:ea10:9775:f33f? ([2001:b07:6468:f312:d0d9:ea10:9775:f33f]) by smtp.gmail.com with ESMTPSA id q138sm590995wme.41.2020.02.28.01.35.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Feb 2020 01:35:06 -0800 (PST) Subject: Re: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis To: Wanpeng Li , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Peter Zijlstra , Nick Desaulniers References: <1581988104-16628-1-git-send-email-wanpengli@tencent.com> <1581988104-16628-2-git-send-email-wanpengli@tencent.com> From: Paolo Bonzini Message-ID: Date: Fri, 28 Feb 2020 10:35:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <1581988104-16628-2-git-send-email-wanpengli@tencent.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/02/20 02:08, Wanpeng Li wrote: > From: Wanpeng Li > > 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 > Acked-by: Nick Desaulniers > Reviewed-by: Vitaly Kuznetsov > Cc: Peter Zijlstra > Cc: Nick Desaulniers > Signed-off-by: Wanpeng Li > --- > 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