Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4739148ybv; Mon, 17 Feb 2020 05:04:55 -0800 (PST) X-Google-Smtp-Source: APXvYqwn/dEEi4IGN8GsU9eZAHycFpSMXD+TowZgKK1c1/h/tu0QtGsnxRxDRQCOcgrN8nsHANW/ X-Received: by 2002:a9d:6c06:: with SMTP id f6mr12705559otq.318.1581944695354; Mon, 17 Feb 2020 05:04:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581944695; cv=none; d=google.com; s=arc-20160816; b=d/Dqqq5V+pQTnLmfpduRt2AvhW3oWUp7oMzR1928I/RSL2pMXYIRNHSpN8Sd9Oi+6T /WM/BRWYcNHVh8ruqljZqlFOaxzm32tJpCPl5OT8qwjf6L0nWUX/gt/btHTmX6cF7SWF wQrtckNs+EW9suZt65qPOUGsRsp1hH+9fYIod05ckr8Tt7nWJSdp0HmUtMi08pyz3yS4 v5mr+nEpjMLyeX47a50u2cXAuiH8QrDhNRLiuPrOfZzaQxr0KFeWM43k5N/J65HU+m5O v8yhIgbJoB0sv9+sBWB8/uQbC5WhJkh/oHdM98h9hmQxsL8wn0upDKXLpnYl1uZpfUs8 Wn4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=1IBRJqn+scoqGFE7Ecg3JdfKODqslJ6sMFIQcaVmgmQ=; b=tAiQ60vgdV+fRgqSB5wZLVHHFqZlEXpL3bjFGutwl7SkI/3bLiGi76RK/LvQCaKnHb aDd2VVPuZPkqfAh7MDtIrXzwjcII2fgXwYGlMdaFJjFjW7akEHMVLH9VwoxaCCc8oMJg jmqfIxfQrty8BTos33ZaoPYIrDj+RY34WpBmj8CWHv8RLLg7FqcddSmcSMgm0CNn0Bgb ovBgB9lYqTFfNDY2qJouCRVV4/5epfL82DpVEJXLROFgIg4UAsmWunL3lCJo7O941ZVN ENlPcO3ORjMiiTv7nt+xa67+/AVlLBevs6+WUHXP76BbELPO273Xwk0eLKU5t/7PKE9Q z3eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gTcaC1yD; 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 n21si6283380oic.0.2020.02.17.05.04.42; Mon, 17 Feb 2020 05:04:55 -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=gTcaC1yD; 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 S1728696AbgBQMqV (ORCPT + 99 others); Mon, 17 Feb 2020 07:46:21 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38013 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728436AbgBQMqV (ORCPT ); Mon, 17 Feb 2020 07:46:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581943579; 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: in-reply-to:in-reply-to:references:references; bh=1IBRJqn+scoqGFE7Ecg3JdfKODqslJ6sMFIQcaVmgmQ=; b=gTcaC1yDdaKsG2Ig+/8h5igXLVkFcMrUAvlq0/bWCGYVZxsihSNetTH3BGytrhgKz0G5D7 mzM3mOfe5DR67pohMH5NEE+/xzhq3c0bn7++0qO9aX75+RZKTOGD+9hUW0pGUWdcOPOew2 BhmnxZDvxwjjkVVoDo8TPRLGEJ1kLoA= 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-1-7K2_9xTKMYSf5cBxzgJkHg-1; Mon, 17 Feb 2020 07:46:16 -0500 X-MC-Unique: 7K2_9xTKMYSf5cBxzgJkHg-1 Received: by mail-wr1-f70.google.com with SMTP id d8so8850721wrq.12 for ; Mon, 17 Feb 2020 04:46:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=1IBRJqn+scoqGFE7Ecg3JdfKODqslJ6sMFIQcaVmgmQ=; b=f3RqQQjfDDWdREnFTAY4z7LR8iiLzT9KLiqemqL2m8Lyw0UlYwhR1ooFiHZjoC5f8h mcCbetPkhg6DMggpCW62WS0LFaMQjtiDWZ9eFFBlI+HBaPuxwzNadUcs9UOUXrm8IKVj soZCHS3WwBkSXlLtVJjs250165xmHmH/LZtt+mYEmjyY1597XOEvrz4BV+6YZPKtLOaQ 6y5f8/rNErACOwiuyk2fA+/jHY66vRab0Mjfgxx5kGtvZYIIsrsAnRXf3WMg+kkhw+2x l2Xt7jOcpomGwIvmAFF3Eskjf8kgop8Z//SSGU6iDTgTbXqNjAGeKWfDAfiOmC3jhi+U 7IOA== X-Gm-Message-State: APjAAAXi9cOB3a082/kCQbt1ezEZuW0wpDEdl0HP4WVQhNMJiC3ePrec MNqCQjnFAOQ7E6qBFRLuuJBj+QaGjUlEOQTlEJJ4EZvaFoHi+hgU1ncmPKcEQW4Iwfo2iuBxRX5 acm+sIHg4SR+t5DqCw+PZOqf4 X-Received: by 2002:a7b:c459:: with SMTP id l25mr21600360wmi.17.1581943575040; Mon, 17 Feb 2020 04:46:15 -0800 (PST) X-Received: by 2002:a7b:c459:: with SMTP id l25mr21600335wmi.17.1581943574741; Mon, 17 Feb 2020 04:46:14 -0800 (PST) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id t12sm775315wrq.97.2020.02.17.04.46.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 04:46:14 -0800 (PST) From: Vitaly Kuznetsov To: Wanpeng Li Cc: Paolo Bonzini , Sean Christopherson , Wanpeng Li , Jim Mattson , Joerg Roedel , LKML , kvm Subject: Re: [PATCH v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis In-Reply-To: References: Date: Mon, 17 Feb 2020 13:46:13 +0100 Message-ID: <871rqtbcve.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Wanpeng Li writes: > 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 > 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"); Nit: to be consistent with __send_ipi_mask() the message should be somthing like "KVM: switch to using PV TLB flush" > } > > 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 > Reviewed-by: Vitaly Kuznetsov -- Vitaly