Received: by 10.223.185.116 with SMTP id b49csp640488wrg; Sat, 10 Feb 2018 15:42:24 -0800 (PST) X-Google-Smtp-Source: AH8x227dPSxA+DzOU4d1OyJV2VODJvhnguYxJrS1TxvrHelfx3hpWllqe2cKTpmVIdqONh2fxaHS X-Received: by 2002:a17:902:a585:: with SMTP id az5-v6mr6813543plb.167.1518306144793; Sat, 10 Feb 2018 15:42:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518306144; cv=none; d=google.com; s=arc-20160816; b=rOM1kZY8D54BmN2alaXgQwE+1aZZZiP/sf68QvbOPUovxbjw16w5j7rd665BXyEaRc dp8K1ryRAqeoCS18BZJcCO3x2u9PeM1UZ6yc+Aupw+T60mCJ2gmD+c68mgm4S6WbMtlu 3N/bYLVdYs8vYpkw4qe5OXvjJ9588XNg2mh3JbrU9al+utQKMZxij4DRrzdprBrw9bMh F50VsgfkmfODnzOpT51nBTS1cZNdbXV4eZiaNf2QJ97UC/OiN6fkm9gMOL+Vw1ac/s80 X2LShAoaRD+HcRhVBphfPcJmd1WMcWSVmNMxdSxzoqRrbPdmX6EzanQiIYCraDkaMhD1 Ixbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-authentication-results; bh=oDZcgkx/CPhCYrDzSEVJ5sYO7s1ZWuclLYBOLrcoKOc=; b=Gy6FboDQYfJskVM1+0wyXJdlwes2RxZ/SC1V89x4U0ciKQIZimY6QqN+bwsIdDCWWj KyRG9F6vbv2/q+ZSi42ruELkZMagyNv2UgMwVTOBVb4U/TwzgK3tXbU8voosrCxxTuKQ xgeglwqiGi6vxoF28uMR/RFro1/0usWYyUzOnshwmpuMHUFwnz8cnwtTomyokTgGGyVf +xQn9eIzdZi9yrj5l+MBdSDq/0uWUmBldYYpFb+NIGaKX1WMdfFnr2CJ9++kukYdfJum unjG/bf4tSj7QrC7O4KdgDwgPp/uL8hUPK9/fcIKvQ/nYKxc2P4f4Um506CLPOndGCIp BWoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=MyXqzBYq; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si418534pla.333.2018.02.10.15.41.41; Sat, 10 Feb 2018 15:42:24 -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=@amazon.co.uk header.s=amazon201209 header.b=MyXqzBYq; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752979AbeBJXju (ORCPT + 99 others); Sat, 10 Feb 2018 18:39:50 -0500 Received: from smtp-fw-9101.amazon.com ([207.171.184.25]:12571 "EHLO smtp-fw-9101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752896AbeBJXjr (ORCPT ); Sat, 10 Feb 2018 18:39:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1518305987; x=1549841987; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=oDZcgkx/CPhCYrDzSEVJ5sYO7s1ZWuclLYBOLrcoKOc=; b=MyXqzBYqSsrarBOePOz9Y/UIn7rKfmNUmMUDLqF1IDp+3Ne7LZmPDhYg 0AD0Fbqqhw9nbOOoBLvEmYibONHrLXJzvmiP+ZTOmJWs9PFSmEIRp4zh9 NPAB6pz3ZhJ0rkecv9NrmPXWx0uCI21984sYM2sHNj0IYc5sAW9vDIKrt Y=; X-IronPort-AV: E=Sophos;i="5.46,492,1511827200"; d="scan'208";a="722034696" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2b-1171e197.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Feb 2018 23:39:46 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-1171e197.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w1ANdgp1048557 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 10 Feb 2018 23:39:44 GMT Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (localhost [127.0.0.1]) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w1ANdfmt031605; Sat, 10 Feb 2018 23:39:41 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w1ANdfFL031604; Sat, 10 Feb 2018 23:39:41 GMT From: David Woodhouse To: tglx@linutronix.de, karahmed@amazon.de, sironi@amazon.de, x86@kernel.org, kvm@vger.kernel.org, torvalds@linux-foundation.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, jmattson@google.com, rkrcmar@redhat.com, arjan.van.de.ven@intel.com, dave.hansen@intel.com Subject: [PATCH v2 3/6] KVM: x86: Reduce retpoline performance impact in slot_handle_level_range() Date: Sat, 10 Feb 2018 23:39:24 +0000 Message-Id: <1518305967-31356-4-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518305967-31356-1-git-send-email-dwmw@amazon.co.uk> References: <1518305967-31356-1-git-send-email-dwmw@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With retpoline, tight loops of "call this function for every XXX" are very much pessimised by taking a prediction miss *every* time. This one is by far the biggest contributor to the guest launch time with retpoline. By marking the iterator slot_handle_…() functions always_inline, we can ensure that the indirect function call can be optimised away into a direct call and it actually generates slightly smaller code because some of the other conditionals can get optimised away too. Performance is now pretty close to what we see with nospectre_v2 on the command line. Suggested-by: Linus Torvalds Signed-off-by: David Woodhouse Reviewed-by: Filippo Sironi Tested-by: Filippo Sironi --- arch/x86/kvm/mmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 2b8eb4d..cc83bdc 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -5058,7 +5058,7 @@ void kvm_mmu_uninit_vm(struct kvm *kvm) typedef bool (*slot_level_handler) (struct kvm *kvm, struct kvm_rmap_head *rmap_head); /* The caller should hold mmu-lock before calling this function. */ -static bool +static __always_inline bool slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot, slot_level_handler fn, int start_level, int end_level, gfn_t start_gfn, gfn_t end_gfn, bool lock_flush_tlb) @@ -5088,7 +5088,7 @@ slot_handle_level_range(struct kvm *kvm, struct kvm_memory_slot *memslot, return flush; } -static bool +static __always_inline bool slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot, slot_level_handler fn, int start_level, int end_level, bool lock_flush_tlb) @@ -5099,7 +5099,7 @@ slot_handle_level(struct kvm *kvm, struct kvm_memory_slot *memslot, lock_flush_tlb); } -static bool +static __always_inline bool slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot, slot_level_handler fn, bool lock_flush_tlb) { @@ -5107,7 +5107,7 @@ slot_handle_all_level(struct kvm *kvm, struct kvm_memory_slot *memslot, PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb); } -static bool +static __always_inline bool slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot, slot_level_handler fn, bool lock_flush_tlb) { @@ -5115,7 +5115,7 @@ slot_handle_large_level(struct kvm *kvm, struct kvm_memory_slot *memslot, PT_MAX_HUGEPAGE_LEVEL, lock_flush_tlb); } -static bool +static __always_inline bool slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot, slot_level_handler fn, bool lock_flush_tlb) { -- 2.7.4