Skip to content

Commit baeb4de

Browse files
committed
x86/reboot: KVM: Disable SVM during reboot via virt/KVM reboot callback
Use the virt callback to disable SVM (and set GIF=1) during an emergency instead of blindly attempting to disable SVM. Like the VMX case, if a hypervisor, i.e. KVM, isn't loaded/active, SVM can't be in use. Acked-by: Kai Huang <kai.huang@intel.com> Link: https://lore.kernel.org/r/20230721201859.2307736-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 119b5cb commit baeb4de

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

arch/x86/include/asm/virtext.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,4 @@ static inline void cpu_svm_disable(void)
133133
}
134134
}
135135

136-
/** Makes sure SVM is disabled, if it is supported on the CPU
137-
*/
138-
static inline void cpu_emergency_svm_disable(void)
139-
{
140-
if (cpu_has_svm(NULL))
141-
cpu_svm_disable();
142-
}
143-
144136
#endif /* _ASM_X86_VIRTEX_H */

arch/x86/kernel/reboot.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,9 +826,6 @@ void cpu_emergency_disable_virtualization(void)
826826
if (callback)
827827
callback();
828828
rcu_read_unlock();
829-
830-
/* KVM_AMD doesn't yet utilize the common callback. */
831-
cpu_emergency_svm_disable();
832829
}
833830

834831
#if defined(CONFIG_SMP)

arch/x86/kvm/svm/svm.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <asm/spec-ctrl.h>
4040
#include <asm/cpu_device_id.h>
4141
#include <asm/traps.h>
42+
#include <asm/reboot.h>
4243
#include <asm/fpu/api.h>
4344

4445
#include <asm/virtext.h>
@@ -563,6 +564,11 @@ void __svm_write_tsc_multiplier(u64 multiplier)
563564
preempt_enable();
564565
}
565566

567+
static void svm_emergency_disable(void)
568+
{
569+
cpu_svm_disable();
570+
}
571+
566572
static void svm_hardware_disable(void)
567573
{
568574
/* Make sure we clean up behind us */
@@ -5209,6 +5215,13 @@ static struct kvm_x86_init_ops svm_init_ops __initdata = {
52095215
.pmu_ops = &amd_pmu_ops,
52105216
};
52115217

5218+
static void __svm_exit(void)
5219+
{
5220+
kvm_x86_vendor_exit();
5221+
5222+
cpu_emergency_unregister_virt_callback(svm_emergency_disable);
5223+
}
5224+
52125225
static int __init svm_init(void)
52135226
{
52145227
int r;
@@ -5222,6 +5235,8 @@ static int __init svm_init(void)
52225235
if (r)
52235236
return r;
52245237

5238+
cpu_emergency_register_virt_callback(svm_emergency_disable);
5239+
52255240
/*
52265241
* Common KVM initialization _must_ come last, after this, /dev/kvm is
52275242
* exposed to userspace!
@@ -5234,14 +5249,14 @@ static int __init svm_init(void)
52345249
return 0;
52355250

52365251
err_kvm_init:
5237-
kvm_x86_vendor_exit();
5252+
__svm_exit();
52385253
return r;
52395254
}
52405255

52415256
static void __exit svm_exit(void)
52425257
{
52435258
kvm_exit();
5244-
kvm_x86_vendor_exit();
5259+
__svm_exit();
52455260
}
52465261

52475262
module_init(svm_init)

0 commit comments

Comments
 (0)