From patchwork Tue Feb 18 01:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11387725 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 67522924 for ; Tue, 18 Feb 2020 01:12:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 48089208C4 for ; Tue, 18 Feb 2020 01:12:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SgnErVfo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726171AbgBRBMR (ORCPT ); Mon, 17 Feb 2020 20:12:17 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46041 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbgBRBMR (ORCPT ); Mon, 17 Feb 2020 20:12:17 -0500 Received: by mail-pl1-f194.google.com with SMTP id b22so7380381pls.12; Mon, 17 Feb 2020 17:12:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZxKP5V2Mq8nq1NJT8kCExycpnJ7xXGIEe62BmBC6pgo=; b=SgnErVfo7B0izjblZdA7Xjs+KoiIHz/UwsemL9I+V5sI8Tnr8cHyqoLbYLkmJFBJy4 5nbmHMJpaHep+xoxexfAbnCpnLXgE8flUzIKz2viz/FWFiSlBVuFskCxoo9H9Y60CwQJ acNe1VUdIpPRPamEDEkTyllDVGSXre11aHOpSF13dbhLRzpqaxmjEREmt5kAZnh1cFzk N47zcEDYxVpMEsAAg29OK5hkNncjuDzvGZKO2sQyS92MW/H9Vmt7/IiUKSlEBfRjlB3q VpA32+S67p8kmm/PavGgILWqVeg7xr2t7Hw0SZgOLuAZu5LEUHR15C9k6jmC4HmnmAQo fkUg== 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:date:message-id; bh=ZxKP5V2Mq8nq1NJT8kCExycpnJ7xXGIEe62BmBC6pgo=; b=iI0+UtxWccX7phl8UMbd84fwT+iyAqy/dE9ZvaupdwaY9Znlj5z0TqYJv0OW10WRiW tBJ+PbObZSjUJdK/R08iVA2lINt3cmyiciKrnIbanx1Qh/wknoSkUQKJ30kQwbuClA8w qN8M2CWPX8FSjAK0tX5yQMIbmqaKGH9vLlZ8qg/JcSPrt/QtePf5wwrRs0vuXSQMUpd5 7MpMYBniPuhWlVxckXQb79mcQA05uDWSUmdYN6Thdk7MFaXOaBfSRVGqz5EOuYk0S6qu X/0qlFqR8n6vXTuJcItfIfJI2ph40ENrtXrF0e/cKRGVGjqdFLfAYPPZem2WK+Zkwjrn CFxA== X-Gm-Message-State: APjAAAVWryNJCJolhV/JU0ysUGtwIgszwPPyxLa6eJZwzZHPBizIJG4+ Is+NK3jQfadXy2SmT6XGoQPfNNMGtshHpg== X-Google-Smtp-Source: APXvYqwHq705bhIBaKvXNiyqjqNYqnBThSAuV9Rof4MWuNkr6sKJSMR5/LOIEjIYURud6plj7bvurA== X-Received: by 2002:a17:90a:a88d:: with SMTP id h13mr2085017pjq.48.1581988336244; Mon, 17 Feb 2020 17:12:16 -0800 (PST) Received: from kernel.DHCP ([120.244.140.205]) by smtp.googlemail.com with ESMTPSA id x23sm2074774pge.89.2020.02.17.17.11.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Feb 2020 17:12:15 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel Subject: [PATCH RESEND v2 1/2] KVM: Introduce pv check helpers Date: Tue, 18 Feb 2020 09:08:23 +0800 Message-Id: <1581988104-16628-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Wanpeng Li Introduce some pv check helpers for consistency. Suggested-by: Vitaly Kuznetsov Reviewed-by: Konrad Rzeszutek Wilk Signed-off-by: Wanpeng Li --- arch/x86/kernel/kvm.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index d817f25..76ea8c4 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -425,7 +425,27 @@ static void __init sev_map_percpu_data(void) } } +static bool pv_tlb_flush_supported(void) +{ + return (kvm_para_has_feature(KVM_FEATURE_PV_TLB_FLUSH) && + !kvm_para_has_hint(KVM_HINTS_REALTIME) && + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); +} + #ifdef CONFIG_SMP + +static bool pv_ipi_supported(void) +{ + return kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI); +} + +static bool pv_sched_yield_supported(void) +{ + return (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && + !kvm_para_has_hint(KVM_HINTS_REALTIME) && + kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)); +} + #define KVM_IPI_CLUSTER_SIZE (2 * BITS_PER_LONG) static void __send_ipi_mask(const struct cpumask *mask, int vector) @@ -619,9 +639,7 @@ static void __init kvm_guest_init(void) pv_ops.time.steal_clock = kvm_steal_clock; } - 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)) { + if (pv_tlb_flush_supported()) { pv_ops.mmu.flush_tlb_others = kvm_flush_tlb_others; pv_ops.mmu.tlb_remove_table = tlb_remove_table; } @@ -632,9 +650,7 @@ static void __init kvm_guest_init(void) #ifdef CONFIG_SMP smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus; smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; - if (kvm_para_has_feature(KVM_FEATURE_PV_SCHED_YIELD) && - !kvm_para_has_hint(KVM_HINTS_REALTIME) && - kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) { + if (pv_sched_yield_supported()) { smp_ops.send_call_func_ipi = kvm_smp_send_call_func_ipi; pr_info("KVM setup pv sched yield\n"); } @@ -700,7 +716,7 @@ static uint32_t __init kvm_detect(void) static void __init kvm_apic_init(void) { #if defined(CONFIG_SMP) - if (kvm_para_has_feature(KVM_FEATURE_PV_SEND_IPI)) + if (pv_ipi_supported()) kvm_setup_pv_ipi(); #endif } @@ -739,9 +755,7 @@ static __init int kvm_setup_pv_tlb_flush(void) if (!kvm_para_available() || nopv) return 0; - 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)) { + if (pv_tlb_flush_supported()) { for_each_possible_cpu(cpu) { zalloc_cpumask_var_node(per_cpu_ptr(&__pv_tlb_mask, cpu), GFP_KERNEL, cpu_to_node(cpu)); From patchwork Tue Feb 18 01:08:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 11387727 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 10A2A924 for ; Tue, 18 Feb 2020 01:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E52AC208C4 for ; Tue, 18 Feb 2020 01:12:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ENkDYBLu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726266AbgBRBMf (ORCPT ); Mon, 17 Feb 2020 20:12:35 -0500 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35282 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726069AbgBRBMf (ORCPT ); Mon, 17 Feb 2020 20:12:35 -0500 Received: by mail-pf1-f195.google.com with SMTP id y73so9783977pfg.2; Mon, 17 Feb 2020 17:12:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SzGI6xs2fHTPFP1btrspKrYRFCHYr+qic+EgFU1IfK0=; b=ENkDYBLud7go9wvHtB/pF+TIBZ+b1aERO8eipPTrMhsl91IEvDMliQkwOQTGtcH9C4 Hq597ccPiy6VFwLo1iveUmaoCVhKHt7efRwYXEyp/E1OUiVfoJ3gXVwdV/BEje7qjX6I +UW48QJUl6d0Cp+oKzdYa3JPqQKchWknyCSoRk/Sl/YuVNfcjN+73gwsZaCSVRtebpWl 7UBOaQjLS/i1/E5vdDIxHY4NXIclr5Si9s/+UHQozfpKKVNhZKoDDcQKltZ0cIr03Nxf UIc+n8rvgJ7SoxZT3YhlZ03QHTQeNb9Yy2LloRQ3JUCCwp/ZoAc7dCRcrmgNEM+tumKX iu+g== 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:date:message-id:in-reply-to :references; bh=SzGI6xs2fHTPFP1btrspKrYRFCHYr+qic+EgFU1IfK0=; b=dzPq2q/ACMtS/XzqT2Le8KBVjUCvWTmCcH1xqOb6wIQqyS/4iEjX3iaQqiXdV/Sn4+ lPUunQUmzVmm+1O4mNBdIeDqXAuMFMUxPCWK+RP01OofT8q86+0Du1NzffGaFuBEKjTU 5JSEKmpRUsxI88ctMvobigCbcGuvZ4y3yAjiC5XOM+/+THK0k5cIGWUNgHudYpjcJOQj mIMPo98aGZ+o3mOSAi19RKPrnZO44tkOkjcqaEo11oaDws+jS2fBVytlNyyG3Jr63mne RBh1o8k5KBRU6ryhb18ZM2bZdjVa4siKYeSYUOf7TXhcPEXD5pOzJJY39wNBqgaoN97p sX6A== X-Gm-Message-State: APjAAAXXgveONYZjR82z9p1XpnUmF0xrSKsLKKgwgb5rwzdjECWfaNMQ Kfpks499xa6EqA4cjJiJdMIVwya7EvjAag== X-Google-Smtp-Source: APXvYqwbA2WBnXkqnVFAOGAIfekLcWZR9ie/X7qJ37c2i6oBa5pOq5qarBPZ1rQx5VrPFTL0EPz+pA== X-Received: by 2002:a62:830c:: with SMTP id h12mr19877979pfe.162.1581988354348; Mon, 17 Feb 2020 17:12:34 -0800 (PST) Received: from kernel.DHCP ([120.244.140.205]) by smtp.googlemail.com with ESMTPSA id x23sm2074774pge.89.2020.02.17.17.12.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Feb 2020 17:12:33 -0800 (PST) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Peter Zijlstra , Nick Desaulniers Subject: [PATCH RESEND v2 2/2] KVM: Pre-allocate 1 cpumask variable per cpu for both pv tlb and pv ipis Date: Tue, 18 Feb 2020 09:08:24 +0800 Message-Id: <1581988104-16628-2-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1581988104-16628-1-git-send-email-wanpengli@tencent.com> References: <1581988104-16628-1-git-send-email-wanpengli@tencent.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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