]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - arch/x86/kernel/cpu/bugs.c
x86/bugs: Unify x86_spec_ctrl_{set_guest,restore_host}
[mirror_ubuntu-artful-kernel.git] / arch / x86 / kernel / cpu / bugs.c
index 8f1bc5560fd88dcaad9df827af55d0b76cfdc7c8..b26ea5a60aaf6764da57ba12d0f37b384a7ccefe 100644 (file)
@@ -150,55 +150,25 @@ u64 x86_spec_ctrl_get_default(void)
 }
 EXPORT_SYMBOL_GPL(x86_spec_ctrl_get_default);
 
-/**
- * x86_spec_ctrl_set_guest - Set speculation control registers for the guest
- * @guest_spec_ctrl:           The guest content of MSR_SPEC_CTRL
- * @guest_virt_spec_ctrl:      The guest controlled bits of MSR_VIRT_SPEC_CTRL
- *                             (may get translated to MSR_AMD64_LS_CFG bits)
- *
- * Avoids writing to the MSR if the content/bits are the same
- */
-void x86_spec_ctrl_set_guest(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)
+void
+x86_virt_spec_ctrl(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl, bool setguest)
 {
-       u64 host = x86_spec_ctrl_base;
+       struct thread_info *ti = current_thread_info();
+       u64 msr, host = x86_spec_ctrl_base;
 
        /* Is MSR_SPEC_CTRL implemented ? */
-       if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
-               return;
-
-       /* SSBD controlled in MSR_SPEC_CTRL */
-       if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))
-               host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
-
-       if (host != guest_spec_ctrl)
-               wrmsrl(MSR_IA32_SPEC_CTRL, guest_spec_ctrl);
-}
-EXPORT_SYMBOL_GPL(x86_spec_ctrl_set_guest);
-
-/**
- * x86_spec_ctrl_restore_host - Restore host speculation control registers
- * @guest_spec_ctrl:           The guest content of MSR_SPEC_CTRL
- * @guest_virt_spec_ctrl:      The guest controlled bits of MSR_VIRT_SPEC_CTRL
- *                             (may get translated to MSR_AMD64_LS_CFG bits)
- *
- * Avoids writing to the MSR if the content/bits are the same
- */
-void x86_spec_ctrl_restore_host(u64 guest_spec_ctrl, u64 guest_virt_spec_ctrl)
-{
-       u64 host = x86_spec_ctrl_base;
-
-       /* Is MSR_SPEC_CTRL implemented ? */
-       if (!static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL))
-               return;
-
-       /* SSBD controlled in MSR_SPEC_CTRL */
-       if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))
-               host |= ssbd_tif_to_spec_ctrl(current_thread_info()->flags);
-
-       if (host != guest_spec_ctrl)
-               wrmsrl(MSR_IA32_SPEC_CTRL, host);
+       if (static_cpu_has(X86_FEATURE_MSR_SPEC_CTRL)) {
+               /* SSBD controlled in MSR_SPEC_CTRL */
+               if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD))
+                       host |= ssbd_tif_to_spec_ctrl(ti->flags);
+
+               if (host != guest_spec_ctrl) {
+                       msr = setguest ? guest_spec_ctrl : host;
+                       wrmsrl(MSR_IA32_SPEC_CTRL, msr);
+               }
+       }
 }
-EXPORT_SYMBOL_GPL(x86_spec_ctrl_restore_host);
+EXPORT_SYMBOL_GPL(x86_virt_spec_ctrl);
 
 static void x86_amd_ssb_disable(void)
 {