Skip to content

Commit 2d5d3fc

Browse files
committed
KVM: VMX: introduce module parameter to disable CET
There have been reports of host hangs caused by CET virtualization. Until these are analyzed further, introduce a module parameter that makes it possible to easily disable it. Link: https://lore.kernel.org/all/85548beb-1486-40f9-beb4-632c78e3360b@proxmox.com/ Cc: David Riley <d.riley@proxmox.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent ef7e0c5 commit 2d5d3fc

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

arch/x86/kvm/vmx/capabilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ extern bool __read_mostly flexpriority_enabled;
1414
extern bool __read_mostly enable_ept;
1515
extern bool __read_mostly enable_unrestricted_guest;
1616
extern bool __read_mostly enable_ept_ad_bits;
17+
extern bool __read_mostly enable_cet;
1718
extern bool __read_mostly enable_pml;
1819
extern int __read_mostly pt_mode;
1920

arch/x86/kvm/vmx/vmx.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ module_param_named(unrestricted_guest,
108108
bool __read_mostly enable_ept_ad_bits = 1;
109109
module_param_named(eptad, enable_ept_ad_bits, bool, 0444);
110110

111+
bool __read_mostly enable_cet = 1;
112+
module_param_named(cet, enable_cet, bool, 0444);
113+
111114
static bool __read_mostly emulate_invalid_guest_state = true;
112115
module_param(emulate_invalid_guest_state, bool, 0444);
113116

@@ -4476,7 +4479,7 @@ void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
44764479
* SSP is reloaded from IA32_PL3_SSP. Check SDM Vol.2A/B Chapter
44774480
* 3 and 4 for details.
44784481
*/
4479-
if (cpu_has_load_cet_ctrl()) {
4482+
if (enable_cet) {
44804483
vmcs_writel(HOST_S_CET, kvm_host.s_cet);
44814484
vmcs_writel(HOST_SSP, 0);
44824485
vmcs_writel(HOST_INTR_SSP_TABLE, 0);
@@ -4532,6 +4535,10 @@ static u32 vmx_get_initial_vmentry_ctrl(void)
45324535
if (vmx_pt_mode_is_system())
45334536
vmentry_ctrl &= ~(VM_ENTRY_PT_CONCEAL_PIP |
45344537
VM_ENTRY_LOAD_IA32_RTIT_CTL);
4538+
4539+
if (!enable_cet)
4540+
vmentry_ctrl &= ~VM_ENTRY_LOAD_CET_STATE;
4541+
45354542
/*
45364543
* IA32e mode, and loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically.
45374544
*/
@@ -4546,6 +4553,9 @@ static u32 vmx_get_initial_vmexit_ctrl(void)
45464553
{
45474554
u32 vmexit_ctrl = vmcs_config.vmexit_ctrl;
45484555

4556+
if (!enable_cet)
4557+
vmexit_ctrl &= ~VM_EXIT_LOAD_CET_STATE;
4558+
45494559
/*
45504560
* Not used by KVM and never set in vmcs01 or vmcs02, but emulated for
45514561
* nested virtualization and thus allowed to be set in vmcs12.
@@ -8155,7 +8165,7 @@ static __init void vmx_set_cpu_caps(void)
81558165
* VMX_BASIC[bit56] == 0, inject #CP at VMX entry with error code
81568166
* fails, so disable CET in this case too.
81578167
*/
8158-
if (!cpu_has_load_cet_ctrl() || !enable_unrestricted_guest ||
8168+
if (!enable_cet || !enable_unrestricted_guest ||
81598169
!cpu_has_vmx_basic_no_hw_errcode_cc()) {
81608170
kvm_cpu_cap_clear(X86_FEATURE_SHSTK);
81618171
kvm_cpu_cap_clear(X86_FEATURE_IBT);
@@ -8630,6 +8640,9 @@ __init int vmx_hardware_setup(void)
86308640
!cpu_has_vmx_invept_global())
86318641
enable_ept = 0;
86328642

8643+
if (!cpu_has_load_cet_ctrl())
8644+
enable_cet = 0;
8645+
86338646
/* NX support is required for shadow paging. */
86348647
if (!enable_ept && !boot_cpu_has(X86_FEATURE_NX)) {
86358648
pr_err_ratelimited("NX (Execute Disable) not supported\n");

0 commit comments

Comments
 (0)