Skip to content

Commit 064eedf

Browse files
vittyvkbonzini
authored andcommitted
KVM: VMX: eVMCS: make evmcs_sanitize_exec_ctrls() work again
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>
1 parent 97a71a5 commit 064eedf

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
@@ -297,14 +297,13 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] = {
297297
};
298298
const unsigned int nr_evmcs_1_fields = ARRAY_SIZE(vmcs_field_to_evmcs_1);
299299

300-
void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
300+
__init void evmcs_sanitize_exec_ctrls(struct vmcs_config *vmcs_conf)
301301
{
302302
vmcs_conf->pin_based_exec_ctrl &= ~EVMCS1_UNSUPPORTED_PINCTRL;
303303
vmcs_conf->cpu_based_2nd_exec_ctrl &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
304304

305305
vmcs_conf->vmexit_ctrl &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
306306
vmcs_conf->vmentry_ctrl &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
307-
308307
}
309308
#endif
310309

arch/x86/kvm/vmx/evmcs.h

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

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

arch/x86/kvm/vmx/vmx.c

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

2563-
if (static_branch_unlikely(&enable_evmcs))
2563+
#if IS_ENABLED(CONFIG_HYPERV)
2564+
if (enlightened_vmcs)
25642565
evmcs_sanitize_exec_ctrls(vmcs_conf);
2566+
#endif
25652567

25662568
return 0;
25672569
}

0 commit comments

Comments
 (0)