.endm
#else
-enum {
- IBRS_DISABLED,
- /* in host kernel, disabled in guest and userland */
- IBRS_ENABLED,
- /* in host kernel and host userland, disabled in guest */
- IBRS_ENABLED_USER,
- IBRS_MAX = IBRS_ENABLED_USER,
-};
/* indicate usage of IBRS to control execution speculation */
extern int use_ibrs;
if (kstrtouint(buf, 0, &enable))
return -EINVAL;
- if (enable > IBRS_MAX)
+ /* Only 0 and 1 are allowed */
+ if (enable > 1)
return -EINVAL;
+ if (!!enable != !!ibrs_disabled)
+ return count;
+
mutex_lock(&spec_ctrl_mutex);
- if (enable == IBRS_DISABLED) {
- /* disable IBRS usage */
+ if (!enable) {
set_ibrs_disabled();
if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED)
spec_ctrl_flush_all_cpus(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_DISABLE_IBRS);
- } else if (enable == IBRS_ENABLED) {
- /* enable IBRS usage in kernel */
+ } else {
clear_ibrs_disabled();
if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED)
set_ibrs_inuse();
else
/* Platform don't support IBRS */
- enable = IBRS_DISABLED;
- } else if (enable == IBRS_ENABLED_USER) {
- /* enable IBRS usage in both userspace and kernel */
- clear_ibrs_disabled();
- /* don't change IBRS value once we set it to always on */
- clear_ibrs_inuse();
- if (use_ibrs & SPEC_CTRL_IBRS_SUPPORTED)
- spec_ctrl_flush_all_cpus(MSR_IA32_SPEC_CTRL, SPEC_CTRL_FEATURE_ENABLE_IBRS);
- else
- /* Platform don't support IBRS */
- enable = IBRS_DISABLED;
+ enable = 0;
}
sysctl_ibrs_enabled = enable;