Received: by 10.223.185.116 with SMTP id b49csp1738090wrg; Sun, 11 Feb 2018 20:07:14 -0800 (PST) X-Google-Smtp-Source: AH8x226iAlUdA2xrB15TkBiu9bi0DOhCfIFIHgPiWXgDfWN0/GaXD8YJYApRTX1SWQbUwWrSCHty X-Received: by 10.98.99.5 with SMTP id x5mr10011123pfb.106.1518408434344; Sun, 11 Feb 2018 20:07:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518408434; cv=none; d=google.com; s=arc-20160816; b=K5ssMr9FvDLbnxQ8UFGEyIRtXhZHIuAo1ZAK2/Ca2rnxPLyB2gYPc0B5z+kFfdKn2A FKNreweifUVCOxrFIbeo737IfYdVcYUl9Hdau/bdwWEo5yL8M4KhdlzjG7oXWNVcWoRx DvYsNiB33BbKI62vv+OW4as9ON+z5zB8k+31SBgU9xjAYJyUWbyQCGgvHc+sIm0ouxAO XqFKwuTEFPU8VDRtIFkjwYN0S6v65nOW6BIwPxNfswOvLi06Fieb8zl7AHNMztZ4kAzn u6glQi//oHTFluqGla47fMs8oLoijL+tmeZTc1bn193tTiiMRbMKBWfLVv3C5Irr7dIq JZVA== 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=78jj7+oHJHUpfu0vZEih/RnVpBK2/IUMQS0K4hXfO2k=; b=rYoAuia0PyhIc8j1fv46tcIb024Gy5wxGh3hg3wx9r30MVs7NfFx0qliV74H/WUMyx jouIyeFBPUFTvqpiyF2037FGspbsvgXloHW04pe4VQWrU0uRp9F2YX8kS/fQGY7GsKcd jN+QrV9TkVQaE2vDJH3wvkuGIAb0WRJMV3kL+FqHogcDkasuEO1vEKKP9vHeezNC9MxD FsuszKA/a6TYwSj9ogieYewdsBjsjouGpPy1+ldhguCg87zL6s72L4Gv0xxL+FJKCL1b y4Z+x74Tu1ZKeHOYbwzzh3WPDPAFlvCYOBuRmKHCGExEPOueko2kZkhPPUuHA94DDRUO CSnA== 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 j5si3427355pfe.415.2018.02.11.20.06.26; Sun, 11 Feb 2018 20:07: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 S932645AbeBLCrg (ORCPT + 99 others); Sun, 11 Feb 2018 21:47:36 -0500 Received: from [198.137.202.136] ([198.137.202.136]:32831 "EHLO mail.zytor.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932373AbeBLCrf (ORCPT ); Sun, 11 Feb 2018 21:47:35 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w1BC9s7a031744; Sun, 11 Feb 2018 04:09:54 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w1BC9sHW031741; Sun, 11 Feb 2018 04:09:54 -0800 Date: Sun, 11 Feb 2018 04:09:54 -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: gregkh@linuxfoundation.org, dwmw@amazon.co.uk, hpa@zytor.com, peterz@infradead.org, luto@kernel.org, arjan@linux.intel.com, dwmw2@infradead.org, sironi@amazon.de, jpoimboe@redhat.com, torvalds@linux-foundation.org, dave.hansen@linux.intel.com, tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org, dan.j.williams@intel.com, bp@alien8.de Reply-To: torvalds@linux-foundation.org, jpoimboe@redhat.com, dave.hansen@linux.intel.com, tglx@linutronix.de, dan.j.williams@intel.com, bp@alien8.de, mingo@kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, hpa@zytor.com, dwmw@amazon.co.uk, gregkh@linuxfoundation.org, sironi@amazon.de, luto@kernel.org, arjan@linux.intel.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: 33f1e899478efb7c77b2b833e7edee1203a24a48 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: 33f1e899478efb7c77b2b833e7edee1203a24a48 Gitweb: https://git.kernel.org/tip/33f1e899478efb7c77b2b833e7edee1203a24a48 Author: David Woodhouse AuthorDate: Sat, 10 Feb 2018 23:39:24 +0000 Committer: Ingo Molnar CommitDate: Sun, 11 Feb 2018 11:24:15 +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 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: pbonzini@redhat.com 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) {