Re: [PATCH] KVM: x86: Reduce retpoline performance impact in slot_handle_level_range()

From: Linus Torvalds
Date: Fri Feb 02 2018 - 14:10:33 EST


On Fri, Feb 2, 2018 at 10:50 AM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> Will it make for bigger code? Yes. But probably not really all *that*
> much bigger, because of how it also will allow the compiler to
> simplify some things.

Actually, testing this with my fairly minimal config, it actually
makes for *smaller* code to inline those things.

That may be a quirk of my configuration, or maybe I screwed something
else up, but:

[torvalds@i7 linux]$ size ~/mmu.o arch/x86/kvm/mmu.o
text data bss dec hex filename
85587 9310 120 95017 17329 /home/torvalds/mmu.o
85531 9310 120 94961 172f1 arch/x86/kvm/mmu.o

so the attached patch actually shrank things down by about 50 bytes
because of the code simplification.

Of course, I have been known to screw up retpoline testing in the
past, so my numbers are suspect ;). Somebody should double-check me.

Linus
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 2b8eb4da4d08..b9f0de6e309b 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 bool __always_inline
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 bool __always_inline
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 bool __always_inline
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 bool __always_inline
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 bool __always_inline
slot_handle_leaf(struct kvm *kvm, struct kvm_memory_slot *memslot,
slot_level_handler fn, bool lock_flush_tlb)
{