From patchwork Tue Jul 23 13:06:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: luferry X-Patchwork-Id: 11054513 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B7CB6912 for ; Tue, 23 Jul 2019 13:07:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A28BB274D1 for ; Tue, 23 Jul 2019 13:07:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96E382860C; Tue, 23 Jul 2019 13:07:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 12C85274D1 for ; Tue, 23 Jul 2019 13:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389989AbfGWNHD (ORCPT ); Tue, 23 Jul 2019 09:07:03 -0400 Received: from m12-16.163.com ([220.181.12.16]:37350 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728323AbfGWNHD (ORCPT ); Tue, 23 Jul 2019 09:07:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=9lG6yT47F7RErrfkXD KOGZz0ZbIUfiaqrIASWyZ+lwE=; b=eHzX/yue41CF6cafpBHGIFp2fMUg1G3Wnv qK8d77YvZUJzgmDN3xYq1/DLQSr8RYHJMffwhnKZYe3QMH+DOivxPdB0VrjGSbLD xKSwrTXqcSUvXrz2rr5H9Rz9CHpmhNdeQEfh228TIhcAV/3oGp68q/trmBnxhaJb odUWH3cCc= Received: from e69c04485.et15sqa.tbsite.net (unknown [106.11.237.219]) by smtp12 (Coremail) with SMTP id EMCowABXyPFHBjdd7_GoCQ--.30018S2; Tue, 23 Jul 2019 21:06:19 +0800 (CST) From: luferry@163.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov Cc: "H. Peter Anvin" , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, luferry Subject: [PATCH] KVM: x86: init x2apic_enabled() once Date: Tue, 23 Jul 2019 21:06:08 +0800 Message-Id: <20190723130608.26528-1-luferry@163.com> X-Mailer: git-send-email 2.14.1.40.g8e62ba1 X-CM-TRANSID: EMCowABXyPFHBjdd7_GoCQ--.30018S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tryxKFW3AF4ruF48XF1kKrg_yoW8AFW7pr 9FgwsYqr4DGr9Ig39rArW8uw13uan3KFWxCr4DWa1avw1YqFy3JFs3KryjyF18XFZYva13 JF4jg3WDJw45JwUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UmD7fUUUUU= X-Originating-IP: [106.11.237.219] X-CM-SenderInfo: poxiv2lu16il2tof0z/xtbBZgv6WlaD2sFWlgAAsD Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: luferry x2apic_eanbled() costs about 200 cycles when guest trigger halt pretty high, pi ops in hotpath Signed-off-by: luferry Reviewed-by: Krish Sadhukhan --- arch/x86/kvm/vmx/vmx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d98eac371c0a..e17dbf011e47 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -186,6 +186,8 @@ static DEFINE_STATIC_KEY_FALSE(vmx_l1d_should_flush); static DEFINE_STATIC_KEY_FALSE(vmx_l1d_flush_cond); static DEFINE_MUTEX(vmx_l1d_flush_mutex); +static int __read_mostly host_x2apic_enabled; + /* Storage for pre module init parameter parsing */ static enum vmx_l1d_flush_state __read_mostly vmentry_l1d_flush_param = VMENTER_L1D_FLUSH_AUTO; @@ -1204,7 +1206,7 @@ static void vmx_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu) dest = cpu_physical_id(cpu); - if (x2apic_enabled()) + if (host_x2apic_enabled) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00; @@ -7151,7 +7153,7 @@ static void __pi_post_block(struct kvm_vcpu *vcpu) dest = cpu_physical_id(vcpu->cpu); - if (x2apic_enabled()) + if (host_x2apic_enabled) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00; @@ -7221,7 +7223,7 @@ static int pi_pre_block(struct kvm_vcpu *vcpu) */ dest = cpu_physical_id(vcpu->pre_pcpu); - if (x2apic_enabled()) + if (host_x2apic_enabled) new.ndst = dest; else new.ndst = (dest << 8) & 0xFF00; @@ -7804,6 +7806,8 @@ static int __init vmx_init(void) } #endif + host_x2apic_enabled = x2apic_enabled(); + r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), __alignof__(struct vcpu_vmx), THIS_MODULE); if (r)