Skip to content

Commit 92e6480

Browse files
committed
KVM: nVMX: Add a helper to encode VMCS info in MSR_IA32_VMX_BASIC
Add a helper to encode the VMCS revision, size, and supported memory types in MSR_IA32_VMX_BASIC, i.e. when synthesizing KVM's supported BASIC MSR value, and delete the now unused VMCS size and memtype shift macros. For a variety of reasons, KVM has shifted (pun intended) to using helpers to *get* information from the VMX MSRs, as opposed to defined MASK and SHIFT macros for direct use. Provide a similar helper for the nested VMX code, which needs to *set* information, so that KVM isn't left with a mix of SHIFT macros and dedicated helpers. Reported-by: Xiaoyao Li <[email protected]> Reviewed-by: Xiaoyao Li <[email protected]> Reviewed-by: Kai Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent c97b106 commit 92e6480

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

arch/x86/include/asm/vmx.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@
135135
#define VMX_VMFUNC_EPTP_SWITCHING VMFUNC_CONTROL_BIT(EPTP_SWITCHING)
136136
#define VMFUNC_EPTP_ENTRIES 512
137137

138-
#define VMX_BASIC_VMCS_SIZE_SHIFT 32
139138
#define VMX_BASIC_32BIT_PHYS_ADDR_ONLY BIT_ULL(48)
140139
#define VMX_BASIC_DUAL_MONITOR_TREATMENT BIT_ULL(49)
141-
#define VMX_BASIC_MEM_TYPE_SHIFT 50
142140
#define VMX_BASIC_INOUT BIT_ULL(54)
143141
#define VMX_BASIC_TRUE_CTLS BIT_ULL(55)
144142

@@ -157,6 +155,11 @@ static inline u32 vmx_basic_vmcs_mem_type(u64 vmx_basic)
157155
return (vmx_basic & GENMASK_ULL(53, 50)) >> 50;
158156
}
159157

158+
static inline u64 vmx_basic_encode_vmcs_info(u32 revision, u16 size, u8 memtype)
159+
{
160+
return revision | ((u64)size << 32) | ((u64)memtype << 50);
161+
}
162+
160163
static inline int vmx_misc_preemption_timer_rate(u64 vmx_misc)
161164
{
162165
return vmx_misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK;

arch/x86/kvm/vmx/nested.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7077,12 +7077,10 @@ static void nested_vmx_setup_basic(struct nested_vmx_msrs *msrs)
70777077
* guest, and the VMCS structure we give it - not about the
70787078
* VMX support of the underlying hardware.
70797079
*/
7080-
msrs->basic =
7081-
VMCS12_REVISION |
7082-
VMX_BASIC_TRUE_CTLS |
7083-
((u64)VMCS12_SIZE << VMX_BASIC_VMCS_SIZE_SHIFT) |
7084-
(X86_MEMTYPE_WB << VMX_BASIC_MEM_TYPE_SHIFT);
7080+
msrs->basic = vmx_basic_encode_vmcs_info(VMCS12_REVISION, VMCS12_SIZE,
7081+
X86_MEMTYPE_WB);
70857082

7083+
msrs->basic |= VMX_BASIC_TRUE_CTLS;
70867084
if (cpu_has_vmx_basic_inout())
70877085
msrs->basic |= VMX_BASIC_INOUT;
70887086
}

0 commit comments

Comments
 (0)