Skip to content

Commit db5df35

Browse files
vittyvkksacilotto
authored andcommitted
KVM: VMX: eVMCS: make evmcs_sanitize_exec_ctrls() work again
BugLink: https://bugs.launchpad.net/bugs/1950462 It was noticed that evmcs_sanitize_exec_ctrls() is not being executed nowadays despite the code checking 'enable_evmcs' static key looking correct. Turns out, static key magic doesn't work in '__init' section (and it is unclear when things changed) but setup_vmcs_config() is called only once per CPU so we don't really need it to. Switch to checking 'enlightened_vmcs' instead, it is supposed to be in sync with 'enable_evmcs'. Opportunistically make evmcs_sanitize_exec_ctrls '__init' and drop unneeded extra newline from it. Reported-by: Yang Weijiang <weijiang.yang@intel.com> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com> Message-Id: <20201014143346.2430936-1-vkuznets@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> (cherry picked from commit 064eedf) Signed-off-by: Tim Gardner <tim.gardner@canonical.com> Acked-by: Stefan Bader <stefan.bader@canonical.com> Acked-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com> Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
1 parent edf5dd6 commit db5df35

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

arch/x86/kvm/vmx/evmcs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,13 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = {
303303
};
304304
const unsigned int nr_evmcs_1_fields = ARRAY_SIZE(vmcs_field_to_evmcs_1);
305305

306-
void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
306+
__init void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
307307
{
308308
vmcs_conf->pin_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_PINCTRL;
309309
vmcs_conf->cpu_based_2nd_exec_ctrl &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
310310

311311
vmcs_conf->vmexit_ctrl &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
312312
vmcs_conf->vmentry_ctrl &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
313-
314313
}
315314
#endif
316315

arch/x86/kvm/vmx/evmcs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static inline void evmcs_load(u64 phys_addr)
184184
vp_ap->enlighten_vmentry = 1;
185185
}
186186

187-
void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf);
187+
__init void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf);
188188
#else /* !IS_ENABLED(CONFIG_HYPERV) */
189189
static inline void evmcs_write64(unsigned long field, u64 value) {}
190190
static inline void evmcs_write32(unsigned long field, u32 value) {}
@@ -193,7 +193,6 @@ static inline u64 evmcs_read64(unsigned long field) { return 0; }
193193
static inline u32 evmcs_read32(unsigned long field) { return 0; }
194194
static inline u16 evmcs_read16(unsigned long field) { return 0; }
195195
static inline void evmcs_load(u64 phys_addr) {}
196-
static inline void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf) {}
197196
static inline void evmcs_touch_msr_bitmap(void) {}
198197
#endif /* IS_ENABLED(CONFIG_HYPERV) */
199198

arch/x86/kvm/vmx/vmx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2505,8 +2505,10 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf,
25052505
vmcs_conf->vmexit_ctrl = _vmexit_control;
25062506
vmcs_conf->vmentry_ctrl = _vmentry_control;
25072507

2508-
if (static_branch_unlikely(&enable_evmcs))
2508+
#if IS_ENABLED(CONFIG_HYPERV)
2509+
if (enlightened_vmcs)
25092510
evmcs_sanitize_exec_ctrls(vmcs_conf);
2511+
#endif
25102512

25112513
return 0;
25122514
}

0 commit comments

Comments
 (0)