Received: by 10.223.185.116 with SMTP id b49csp3369353wrg; Tue, 13 Feb 2018 01:17:14 -0800 (PST) X-Google-Smtp-Source: AH8x225BzDuWe/XIluurOYsBg7dS2FSY4GQGOjSQnCOGkjCpdO7jwmRSCdhptQTW9gu9/7bZRUGC X-Received: by 10.99.99.2 with SMTP id x2mr478868pgb.406.1518513434814; Tue, 13 Feb 2018 01:17:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518513434; cv=none; d=google.com; s=arc-20160816; b=lNZ8YqjuS5E7zir1DV0jhw/gCkWGpOQGr/4Ytn9CdGFW5EkP2E8/GjCiDb9a0orTrp zT0CAbKYDXr/mBaS/zv3Op83xh3McrNjP9K1w6wdupx6snORU7GSul4bettq8UsVnPka HfndRMc3DG0K6LWO5uZStysFp/ET0phh++Ai9KOu7ekdNy4209LAe3fPzz5DZhs+HPfc taHZwH0fpIFKUeWXAkPQ/iAyPKbaJpYuWilTlTtxjBI5YApVWGh+hAPFUl/xCfpzXj+L db+W2S75b8hbgFkQIXRrdFQTNI9s0Pa0ocsVjrE0nVNOjlao1bJSsD/czbjD/s+GxYXR U0oQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=l3eUXxql30gFL4VZIBJVI5DW+FSLKxcfgHeTnFRKVeg=; b=sxPVpbPpyZrWnzKUm8lxFfHkZq8zpsA+2pKUYbyL3w4vwBuBDwLAF+UGu6SmetuBjN eH/W1BZ9O7qWGCIbjoxZDPw1yju0+9/N1qp+vAfCqybOYRgbHN5wEi1wnMFT9lxREjAN VUwBT3zBX+KVQ0Z+EPGRzvf+mOyIUHVoGS1DanFWNEWmxweLQx8GahIAL0Fj/ovRJumk iiDlogPnWxVzlUZZvxPrAicLypVk3nTlK6sY2ZJjFuOCEtY94F5jMKfXmjBMWQHaB5Hx vr/N19arOzWOe7jpfO84uWy573zwaTS0bQM+SsTavjdKJxCJVc3fBbWdbLuPlQDMmiy2 hIbw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2-v6si1035868plo.537.2018.02.13.01.16.59; Tue, 13 Feb 2018 01:17:14 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934611AbeBMJPv (ORCPT + 99 others); Tue, 13 Feb 2018 04:15:51 -0500 Received: from terminus.zytor.com ([198.137.202.136]:42909 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934051AbeBMJPb (ORCPT ); Tue, 13 Feb 2018 04:15:31 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1D8wno8023976; Tue, 13 Feb 2018 00:58:49 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1D8wn5O023973; Tue, 13 Feb 2018 00:58:49 -0800 Date: Tue, 13 Feb 2018 00:58:49 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for David Woodhouse Message-ID: Cc: bp@alien8.de, dwmw@amazon.co.uk, dave.hansen@linux.intel.com, arjan@linux.intel.com, sironi@amazon.de, torvalds@linux-foundation.org, dan.j.williams@intel.com, peterz@infradead.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, gregkh@linuxfoundation.org, luto@kernel.org, jpoimboe@redhat.com, dwmw2@infradead.org Reply-To: bp@alien8.de, dwmw@amazon.co.uk, dave.hansen@linux.intel.com, arjan@linux.intel.com, sironi@amazon.de, torvalds@linux-foundation.org, dan.j.williams@intel.com, peterz@infradead.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com, tglx@linutronix.de, gregkh@linuxfoundation.org, luto@kernel.org, jpoimboe@redhat.com, dwmw2@infradead.org In-Reply-To: <1518305967-31356-4-git-send-email-dwmw@amazon.co.uk> References: <1518305967-31356-4-git-send-email-dwmw@amazon.co.uk> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] KVM/x86: Reduce retpoline performance impact in slot_handle_level_range(), by always inlining iterator helper methods Git-Commit-ID: 928a4c39484281f8ca366f53a1db79330d058401 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 928a4c39484281f8ca366f53a1db79330d058401 Gitweb: https://git.kernel.org/tip/928a4c39484281f8ca366f53a1db79330d058401 Author: David Woodhouse AuthorDate: Sat, 10 Feb 2018 23:39:24 +0000 Committer: Ingo Molnar CommitDate: Tue, 13 Feb 2018 08:59:45 +0100 KVM/x86: Reduce retpoline performance impact in slot_handle_level_range(), by always inlining iterator helper methods 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 Tested-by: Filippo Sironi Signed-off-by: David Woodhouse Reviewed-by: Filippo Sironi Acked-by: Paolo Bonzini Cc: Andy Lutomirski Cc: Arjan van de Ven Cc: Borislav Petkov Cc: Dan Williams Cc: Dave Hansen Cc: David Woodhouse Cc: Greg Kroah-Hartman Cc: Josh Poimboeuf Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: arjan.van.de.ven@intel.com Cc: dave.hansen@intel.com Cc: jmattson@google.com Cc: karahmed@amazon.de Cc: kvm@vger.kernel.org Cc: rkrcmar@redhat.com Link: http://lkml.kernel.org/r/1518305967-31356-4-git-send-email-dwmw@amazon.co.uk Signed-off-by: Ingo Molnar --- 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) {