Skip to content

Commit e23f6d4

Browse files
sean-jcbonzini
authored andcommitted
KVM: VMX: Invert the inlining of MSR interception helpers
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 904e14f ("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> Message-Id: <20210423221912.3857243-1-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent f82762f commit e23f6d4

2 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎arch/x86/kvm/vmx/vmx.c‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ static const struct kernel_param_ops vmentry_l1d_flush_ops = {
362362
module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, NULL, 0644);
363363

364364
static u32 vmx_segment_access_rights(struct kvm_segment *var);
365-
static __always_inline void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu,
366-
u32 msr, int type);
367365

368366
void vmx_vmexit(void);
369367

@@ -3818,8 +3816,7 @@ static void vmx_set_msr_bitmap_write(ulong *msr_bitmap, u32 msr)
38183816
__set_bit(msr & 0x1fff, msr_bitmap + 0xc00 / f);
38193817
}
38203818

3821-
static __always_inline void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu,
3822-
u32 msr, int type)
3819+
void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type)
38233820
{
38243821
struct vcpu_vmx *vmx = to_vmx(vcpu);
38253822
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,
38643861
vmx_clear_msr_bitmap_write(msr_bitmap, msr);
38653862
}
38663863

3867-
static __always_inline void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu,
3868-
u32 msr, int type)
3864+
void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type)
38693865
{
38703866
struct vcpu_vmx *vmx = to_vmx(vcpu);
38713867
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,
38983894
vmx_set_msr_bitmap_write(msr_bitmap, msr);
38993895
}
39003896

3901-
void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu,
3902-
u32 msr, int type, bool value)
3903-
{
3904-
if (value)
3905-
vmx_enable_intercept_for_msr(vcpu, msr, type);
3906-
else
3907-
vmx_disable_intercept_for_msr(vcpu, msr, type);
3908-
}
3909-
39103897
static u8 vmx_msr_bitmap_mode(struct kvm_vcpu *vcpu)
39113898
{
39123899
u8 mode = 0;

‎arch/x86/kvm/vmx/vmx.h‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,19 @@ void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp);
392392
bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched);
393393
int vmx_find_loadstore_msr_slot(struct vmx_msrs *m, u32 msr);
394394
void vmx_ept_load_pdptrs(struct kvm_vcpu *vcpu);
395-
void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu,
396-
u32 msr, int type, bool value);
395+
396+
void vmx_disable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
397+
void vmx_enable_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr, int type);
398+
399+
static inline void vmx_set_intercept_for_msr(struct kvm_vcpu *vcpu, u32 msr,
400+
int type, bool value)
401+
{
402+
if (value)
403+
vmx_enable_intercept_for_msr(vcpu, msr, type);
404+
else
405+
vmx_disable_intercept_for_msr(vcpu, msr, type);
406+
}
407+
397408
void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu);
398409

399410
static inline u8 vmx_get_rvi(void)

0 commit comments

Comments
 (0)