From: Paolo Bonzini <pbonzini@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Invert the inlining of MSR interception helpers
Date: Mon, 26 Apr 2021 11:19:54 +0200 [thread overview]
Message-ID: <febab7f6-aab8-6278-5782-07d75dd40166@redhat.com> (raw)
In-Reply-To: <20210423221912.3857243-1-seanjc@google.com>
On 24/04/21 00:19, Sean Christopherson wrote:
> Invert the inline declarations of the MSR interception helpers between
> the wrapper, vmx_set_intercept_for_msr(), and the core implementations,
> vmx_{dis,en}able_intercept_for_msr(). Letting the compiler _not_
> inline the implementation reduces KVM's code footprint by ~3k bytes.
>
> Back when the helpers were added in commit 904e14fb7cb9 ("KVM: VMX: make
> MSR bitmaps per-VCPU"), both the wrapper and the implementations were
> __always_inline because the end code distilled down to a few conditionals
> and a bit operation. Today, the implementations involve a variety of
> checks and bit ops in order to support userspace MSR filtering.
>
> Furthermore, the vast majority of calls to manipulate MSR interception
> are not performance sensitive, e.g. vCPU creation and x2APIC toggling.
> On the other hand, the one path that is performance sensitive, dynamic
> LBR passthrough, uses the wrappers, i.e. is largely untouched by
> inverting the inlining.
>
> In short, forcing the low level MSR interception code to be inlined no
> longer makes sense.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
> arch/x86/kvm/vmx/vmx.c | 17 ++---------------
> arch/x86/kvm/vmx/vmx.h | 15 +++++++++++++--
> 2 files changed, 15 insertions(+), 17 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 6501d66167b8..b77bc72d97a4 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -362,8 +362,6 @@ static const struct kernel_param_ops vmentry_l1d_flush_ops = {
> module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, NULL, 0644);
>
> static u32 vmx_segment_access_rights(struct kvm_segment *var);
> -static __always_inline void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu,
> - u32 msr, int type);
>
> void vmx_vmexit(void);
>
> @@ -3818,8 +3816,7 @@ static void vmx_set_msr_bitmap_write(ulong *msr_bitmap, u32 msr)
> __set_bit(msr & 0x1fff, msr_bitmap + 0xc00 / f);
> }
>
> -static __always_inline void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu,
> - u32 msr, int type)
> +void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
> unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap;
> @@ -3864,8 +3861,7 @@ static __always_inline void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu,
> vmx_clear_msr_bitmap_write(msr_bitmap, msr);
> }
>
> -static __always_inline void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu,
> - u32 msr, int type)
> +void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type)
> {
> struct vcpu_vmx *vmx = to_vmx(vcpu);
> unsigned long *msr_bitmap = vmx->vmcs01.msr_bitmap;
> @@ -3898,15 +3894,6 @@ static __always_inline void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu,
> vmx_set_msr_bitmap_write(msr_bitmap, msr);
> }
>
> -void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu,
> - u32 msr, int type, bool value)
> -{
> - if (value)
> - vmx_enable_intercept_for_msr(vcpu, msr, type);
> - else
> - vmx_disable_intercept_for_msr(vcpu, msr, type);
> -}
> -
> static u8 vmx_msr_bitmap_mode(struct kvm_vcpu *vcpu)
> {
> u8 mode = 0;
> diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h
> index 19fe09fad2fe..008cb87ff088 100644
> --- a/arch/x86/kvm/vmx/vmx.h
> +++ b/arch/x86/kvm/vmx/vmx.h
> @@ -392,8 +392,19 @@ void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp);
> bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched);
> int vmx_find_loadstore_msr_slot(struct vmx_msrs *m, u32 msr);
> void vmx_ept_load_pdptrs(struct kvm_vcpu *vcpu);
> -void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu,
> - u32 msr, int type, bool value);
> +
> +void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
> +void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
> +
> +static inline void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr,
> + int type, bool value)
> +{
> + if (value)
> + vmx_enable_intercept_for_msr(vcpu, msr, type);
> + else
> + vmx_disable_intercept_for_msr(vcpu, msr, type);
> +}
> +
> void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
>
> static inline u8 vmx_get_rvi(void)
>
Queued (and pretty much closing the 5.13 kvm/next branch after this).
Paolo
prev parent reply other threads:[~2021-04-26 9:20 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 22:19 [PATCH] KVM: VMX: Invert the inlining of MSR interception helpers Sean Christopherson
2021-04-26 9:19 ` Paolo Bonzini [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=febab7f6-aab8-6278-5782-07d75dd40166@redhat.com \
--to=pbonzini@redhat.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).