From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 842CEC7618B for ; Mon, 29 Jul 2019 17:50:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67AC8216C8 for ; Mon, 29 Jul 2019 17:50:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728032AbfG2Ruq (ORCPT ); Mon, 29 Jul 2019 13:50:46 -0400 Received: from mga18.intel.com ([134.134.136.126]:29243 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726973AbfG2Ruq (ORCPT ); Mon, 29 Jul 2019 13:50:46 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Jul 2019 10:50:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,323,1559545200"; d="scan'208";a="173324183" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga007.fm.intel.com with ESMTP; 29 Jul 2019 10:50:45 -0700 Date: Mon, 29 Jul 2019 10:50:45 -0700 From: Sean Christopherson To: Wanpeng Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Nadav Amit Subject: Re: [PATCH RESEND] KVM: X86: Use IPI shorthands in kvm guest when support Message-ID: <20190729175044.GI21120@linux.intel.com> References: <1564121727-30020-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1564121727-30020-1-git-send-email-wanpengli@tencent.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, Jul 26, 2019 at 02:15:27PM +0800, Wanpeng Li wrote: > From: Wanpeng Li > > IPI shorthand is supported now by linux apic/x2apic driver, switch to > IPI shorthand for all excluding self and all including self destination > shorthand in kvm guest, to avoid splitting the target mask into serveral > PV IPI hypercalls. > > Cc: Thomas Gleixner > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Sean Christopherson > Cc: Nadav Amit > Signed-off-by: Wanpeng Li > --- > Note: rebase against tip tree's x86/apic branch > > arch/x86/kernel/kvm.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c > index b7f34fe..87b73b8 100644 > --- a/arch/x86/kernel/kvm.c > +++ b/arch/x86/kernel/kvm.c > @@ -34,7 +34,9 @@ > #include > #include > > +static struct apic orig_apic; Copying the entire struct apic to snapshot two functions is funky, explicitly capturing the two functions would be more intuitive. Tangentially related, kvm_setup_pv_ipi() can be annotated __init, which means the function snapshots can be __ro_after_init. That being said, can't we just remove kvm_send_ipi_all() and kvm_send_ipi_allbutself()? AFAICT, the variations that lead to shorthand are only used when apic_use_ipi_shorthand is true. If that isn't the case, fixing the callers in the APIC code seems like the correct thing to do. > static int kvmapf = 1; > +DECLARE_STATIC_KEY_FALSE(apic_use_ipi_shorthand); > static int __init parse_no_kvmapf(char *arg) > { > @@ -507,12 +509,18 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector) > > static void kvm_send_ipi_allbutself(int vector) > { > - kvm_send_ipi_mask_allbutself(cpu_online_mask, vector); > + if (static_branch_likely(&apic_use_ipi_shorthand)) > + orig_apic.send_IPI_allbutself(vector); > + else > + kvm_send_ipi_mask_allbutself(cpu_online_mask, vector); > } > > static void kvm_send_ipi_all(int vector) > { > - __send_ipi_mask(cpu_online_mask, vector); > + if (static_branch_likely(&apic_use_ipi_shorthand)) > + orig_apic.send_IPI_all(vector); > + else > + __send_ipi_mask(cpu_online_mask, vector); > } > > /* > @@ -520,6 +528,8 @@ static void kvm_send_ipi_all(int vector) > */ > static void kvm_setup_pv_ipi(void) > { > + orig_apic = *apic; > + > apic->send_IPI_mask = kvm_send_ipi_mask; > apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself; > apic->send_IPI_allbutself = kvm_send_ipi_allbutself; > -- > 2.7.4 >