Commit 4797c2f3 authored by Thomas Gleixner's avatar Thomas Gleixner Committed by Greg Kroah-Hartman

x86/kvm: Allow runtime control of L1D flush

commit 895ae47f upstream

All mitigation modes can be switched at run time with a static key now:

 - Use sysfs_streq() instead of strcmp() to handle the trailing new line
   from sysfs writes correctly.
 - Make the static key management handle multiple invocations properly.
 - Set the module parameter file to RW
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Tested-by: default avatarJiri Kosina <jkosina@suse.cz>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
Link: https://lkml.kernel.org/r/20180713142322.954525119@linutronix.deSigned-off-by: default avatarDavid Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6ccf6332
...@@ -638,7 +638,7 @@ void x86_spec_ctrl_setup_ap(void) ...@@ -638,7 +638,7 @@ void x86_spec_ctrl_setup_ap(void)
#define pr_fmt(fmt) "L1TF: " fmt #define pr_fmt(fmt) "L1TF: " fmt
#if IS_ENABLED(CONFIG_KVM_INTEL) #if IS_ENABLED(CONFIG_KVM_INTEL)
enum vmx_l1d_flush_state l1tf_vmx_mitigation __ro_after_init = VMENTER_L1D_FLUSH_AUTO; enum vmx_l1d_flush_state l1tf_vmx_mitigation = VMENTER_L1D_FLUSH_AUTO;
EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation); EXPORT_SYMBOL_GPL(l1tf_vmx_mitigation);
#endif #endif
......
...@@ -235,12 +235,15 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf) ...@@ -235,12 +235,15 @@ static int vmx_setup_l1d_flush(enum vmx_l1d_flush_state l1tf)
l1tf_vmx_mitigation = l1tf; l1tf_vmx_mitigation = l1tf;
if (l1tf == VMENTER_L1D_FLUSH_NEVER) if (l1tf != VMENTER_L1D_FLUSH_NEVER)
return 0;
static_branch_enable(&vmx_l1d_should_flush); static_branch_enable(&vmx_l1d_should_flush);
else
static_branch_disable(&vmx_l1d_should_flush);
if (l1tf == VMENTER_L1D_FLUSH_ALWAYS) if (l1tf == VMENTER_L1D_FLUSH_ALWAYS)
static_branch_enable(&vmx_l1d_flush_always); static_branch_enable(&vmx_l1d_flush_always);
else
static_branch_disable(&vmx_l1d_flush_always);
return 0; return 0;
} }
...@@ -250,7 +253,7 @@ static int vmentry_l1d_flush_parse(const char *s) ...@@ -250,7 +253,7 @@ static int vmentry_l1d_flush_parse(const char *s)
if (s) { if (s) {
for (i = 0; i < ARRAY_SIZE(vmentry_l1d_param); i++) { for (i = 0; i < ARRAY_SIZE(vmentry_l1d_param); i++) {
if (!strcmp(s, vmentry_l1d_param[i].option)) if (sysfs_streq(s, vmentry_l1d_param[i].option))
return vmentry_l1d_param[i].cmd; return vmentry_l1d_param[i].cmd;
} }
} }
...@@ -294,7 +297,7 @@ static const struct kernel_param_ops vmentry_l1d_flush_ops = { ...@@ -294,7 +297,7 @@ static const struct kernel_param_ops vmentry_l1d_flush_ops = {
.set = vmentry_l1d_flush_set, .set = vmentry_l1d_flush_set,
.get = vmentry_l1d_flush_get, .get = vmentry_l1d_flush_get,
}; };
module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, NULL, S_IRUGO); module_param_cb(vmentry_l1d_flush, &vmentry_l1d_flush_ops, NULL, 0644);
#define NR_AUTOLOAD_MSRS 8 #define NR_AUTOLOAD_MSRS 8
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment