Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3914660ybi; Mon, 29 Jul 2019 15:13:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8xiG0lCrGfJWeqlxEDYfYkqALkgJGXXAtnEBDxzyS/TkzpaI2j5j9vsO4i44qdn4GYtwM X-Received: by 2002:a17:902:b285:: with SMTP id u5mr23585076plr.329.1564438435940; Mon, 29 Jul 2019 15:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564438435; cv=none; d=google.com; s=arc-20160816; b=KGTZUy7eIF3No8UVe9CsRYqnPfVYdq3Hr1D5f3LoV2IRH2QaaRKVF3TtTNE7VGa7Dw /r5EbM8atl2aCHQlyNSbTh/LdT3QUBnPfLKz/OVcKBQ3SeJAA+ekTBB+hjxjVpp0b7Ze 9skgnXHSBFzIvOqpfKX8b5wvVwq3K26VC43WJ0O1C7laaxA2/k8i6TXRzmrM9ZU5ULgW lxMvyntqUQmVpTDhe5M/0g3XOlHmA12SsuRc/xLfEBbv+7nqoXU7H0ertNyaC+h3H+Zs cUyorn+xWKJPC3VwX1C0IoL3X3Ha6kcRoF6+0JWU3XBjIMs0LEFTgn54HDQ7kTDXJg50 wqdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=PpRpizyjUXZEMcPcTn0hc8/bnrT/gFolEYASVIzKSzk=; b=NqWhwOGApSd9EZbitxj4LllWmfmkMqOX+t6G8W6IEW4rewwRaDMGcZEkxP9YCjUFzc vOh0HH8oTN8nY0Y8OVwaRCBcPtzRFEjD/Ri54Nwd27EVX5LvSrXNoMYGkYy1uLVjqmQ1 5TVWk4pWRf1IRFbaBpifywj3/4fQWPEEwirmS4ci8SmeJiOkVkAj4R7RnDi81Xd/JGuh S8XWK2s253LRrpLUr9FklHGMWfZHaLLJ081FrNKfBZV4DlndzGM2UFE61xU6QvAF4uO0 2kRW9vkBB0VHOWU7+EixQbtIY8nhwwtxyHljD0YQ5bIV3vEY6ioZgPIzPewk+9Mh/oEX 58pw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e36si31317115pgm.527.2019.07.29.15.13.41; Mon, 29 Jul 2019 15:13:55 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728122AbfG2Ruq (ORCPT + 99 others); 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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 >