Skip to content

Commit cb58327

Browse files
Dapeng Misean-jc
authored andcommitted
KVM: nVMX: Add macros to simplify nested MSR interception setting
Add macros nested_vmx_merge_msr_bitmaps_xxx() to simplify nested MSR interception setting. No function change intended. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Dapeng Mi <dapeng1.mi@linux.intel.com> Signed-off-by: Mingwei Zhang <mizhang@google.com> Tested-by: Xudong Hao <xudong.hao@intel.com> Tested-by: Manali Shukla <manali.shukla@amd.com> Link: https://patch.msgid.link/20251206001720.468579-31-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 283a5aa commit cb58327

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

arch/x86/kvm/vmx/nested.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,19 @@ static inline void nested_vmx_set_intercept_for_msr(struct vcpu_vmx *vmx,
617617
msr_bitmap_l0, msr);
618618
}
619619

620+
#define nested_vmx_merge_msr_bitmaps(msr, type) \
621+
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, \
622+
msr_bitmap_l0, msr, type)
623+
624+
#define nested_vmx_merge_msr_bitmaps_read(msr) \
625+
nested_vmx_merge_msr_bitmaps(msr, MSR_TYPE_R)
626+
627+
#define nested_vmx_merge_msr_bitmaps_write(msr) \
628+
nested_vmx_merge_msr_bitmaps(msr, MSR_TYPE_W)
629+
630+
#define nested_vmx_merge_msr_bitmaps_rw(msr) \
631+
nested_vmx_merge_msr_bitmaps(msr, MSR_TYPE_RW)
632+
620633
/*
621634
* Merge L0's and L1's MSR bitmap, return false to indicate that
622635
* we do not use the hardware.
@@ -700,23 +713,13 @@ static inline bool nested_vmx_prepare_msr_bitmap(struct kvm_vcpu *vcpu,
700713
* other runtime changes to vmcs01's bitmap, e.g. dynamic pass-through.
701714
*/
702715
#ifdef CONFIG_X86_64
703-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
704-
MSR_FS_BASE, MSR_TYPE_RW);
705-
706-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
707-
MSR_GS_BASE, MSR_TYPE_RW);
708-
709-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
710-
MSR_KERNEL_GS_BASE, MSR_TYPE_RW);
716+
nested_vmx_merge_msr_bitmaps_rw(MSR_FS_BASE);
717+
nested_vmx_merge_msr_bitmaps_rw(MSR_GS_BASE);
718+
nested_vmx_merge_msr_bitmaps_rw(MSR_KERNEL_GS_BASE);
711719
#endif
712-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
713-
MSR_IA32_SPEC_CTRL, MSR_TYPE_RW);
714-
715-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
716-
MSR_IA32_PRED_CMD, MSR_TYPE_W);
717-
718-
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
719-
MSR_IA32_FLUSH_CMD, MSR_TYPE_W);
720+
nested_vmx_merge_msr_bitmaps_rw(MSR_IA32_SPEC_CTRL);
721+
nested_vmx_merge_msr_bitmaps_write(MSR_IA32_PRED_CMD);
722+
nested_vmx_merge_msr_bitmaps_write(MSR_IA32_FLUSH_CMD);
720723

721724
nested_vmx_set_intercept_for_msr(vmx, msr_bitmap_l1, msr_bitmap_l0,
722725
MSR_IA32_APERF, MSR_TYPE_R);

0 commit comments

Comments
 (0)