Skip to content

Commit 42ae644

Browse files
gaochaointelsean-jc
authored andcommitted
KVM: nVMX: Advertise new VM-Entry/Exit control bits for CET state
Advertise the LOAD_CET_STATE VM-Entry/Exit control bits in the nested VMX MSRS, as all nested support for CET virtualization, including consistency checks, is in place. Advertise support if and only if KVM supports at least one of IBT or SHSTK. While it's userspace's responsibility to provide a consistent CPU model to the guest, that doesn't mean KVM should set userspace up to fail. Note, the existing {CLEAR,LOAD}_BNDCFGS behavior predates KVM_X86_QUIRK_STUFF_FEATURE_MSRS, i.e. KVM "solved" the inconsistent CPU model problem by overwriting the VMX MSRs provided by userspace. Signed-off-by: Chao Gao <chao.gao@intel.com> Link: https://lore.kernel.org/r/20250919223258.1604852-35-seanjc@google.com Co-developed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 62f7533 commit 42ae644

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

arch/x86/kvm/vmx/nested.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7179,13 +7179,17 @@ static void nested_vmx_setup_exit_ctls(struct vmcs_config *vmcs_conf,
71797179
VM_EXIT_HOST_ADDR_SPACE_SIZE |
71807180
#endif
71817181
VM_EXIT_LOAD_IA32_PAT | VM_EXIT_SAVE_IA32_PAT |
7182-
VM_EXIT_CLEAR_BNDCFGS;
7182+
VM_EXIT_CLEAR_BNDCFGS | VM_EXIT_LOAD_CET_STATE;
71837183
msrs->exit_ctls_high |=
71847184
VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR |
71857185
VM_EXIT_LOAD_IA32_EFER | VM_EXIT_SAVE_IA32_EFER |
71867186
VM_EXIT_SAVE_VMX_PREEMPTION_TIMER | VM_EXIT_ACK_INTR_ON_EXIT |
71877187
VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
71887188

7189+
if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) &&
7190+
!kvm_cpu_cap_has(X86_FEATURE_IBT))
7191+
msrs->exit_ctls_high &= ~VM_EXIT_LOAD_CET_STATE;
7192+
71897193
/* We support free control of debug control saving. */
71907194
msrs->exit_ctls_low &= ~VM_EXIT_SAVE_DEBUG_CONTROLS;
71917195
}
@@ -7201,11 +7205,16 @@ static void nested_vmx_setup_entry_ctls(struct vmcs_config *vmcs_conf,
72017205
#ifdef CONFIG_X86_64
72027206
VM_ENTRY_IA32E_MODE |
72037207
#endif
7204-
VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_BNDCFGS;
7208+
VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_BNDCFGS |
7209+
VM_ENTRY_LOAD_CET_STATE;
72057210
msrs->entry_ctls_high |=
72067211
(VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR | VM_ENTRY_LOAD_IA32_EFER |
72077212
VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL);
72087213

7214+
if (!kvm_cpu_cap_has(X86_FEATURE_SHSTK) &&
7215+
!kvm_cpu_cap_has(X86_FEATURE_IBT))
7216+
msrs->entry_ctls_high &= ~VM_ENTRY_LOAD_CET_STATE;
7217+
72097218
/* We support free control of debug control loading. */
72107219
msrs->entry_ctls_low &= ~VM_ENTRY_LOAD_DEBUG_CONTROLS;
72117220
}

0 commit comments

Comments
 (0)