Skip to content

Commit 76ab816

Browse files
committed
x86/virt: KVM: Move "disable SVM" helper into KVM SVM
Move cpu_svm_disable() into KVM proper now that all hardware virtualization management is routed through KVM. Remove the now-empty virtext.h. No functional change intended. Reviewed-by: Kai Huang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent f9a8866 commit 76ab816

File tree

2 files changed

+25
-54
lines changed

2 files changed

+25
-54
lines changed

arch/x86/include/asm/virtext.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

arch/x86/kvm/svm/svm.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
#include <asm/reboot.h>
4343
#include <asm/fpu/api.h>
4444

45-
#include <asm/virtext.h>
46-
4745
#include <trace/events/ipi.h>
4846

4947
#include "trace.h"
@@ -582,9 +580,32 @@ void __svm_write_tsc_multiplier(u64 multiplier)
582580
preempt_enable();
583581
}
584582

583+
static inline void kvm_cpu_svm_disable(void)
584+
{
585+
uint64_t efer;
586+
587+
wrmsrl(MSR_VM_HSAVE_PA, 0);
588+
rdmsrl(MSR_EFER, efer);
589+
if (efer & EFER_SVME) {
590+
/*
591+
* Force GIF=1 prior to disabling SVM to ensure INIT and NMI
592+
* aren't blocked, e.g. if a fatal error occurred between CLGI
593+
* and STGI. Note, STGI may #UD if SVM is disabled from NMI
594+
* context between reading EFER and executing STGI. In that
595+
* case, GIF must already be set, otherwise the NMI would have
596+
* been blocked, so just eat the fault.
597+
*/
598+
asm_volatile_goto("1: stgi\n\t"
599+
_ASM_EXTABLE(1b, %l[fault])
600+
::: "memory" : fault);
601+
fault:
602+
wrmsrl(MSR_EFER, efer & ~EFER_SVME);
603+
}
604+
}
605+
585606
static void svm_emergency_disable(void)
586607
{
587-
cpu_svm_disable();
608+
kvm_cpu_svm_disable();
588609
}
589610

590611
static void svm_hardware_disable(void)
@@ -593,7 +614,7 @@ static void svm_hardware_disable(void)
593614
if (tsc_scaling)
594615
__svm_write_tsc_multiplier(SVM_TSC_RATIO_DEFAULT);
595616

596-
cpu_svm_disable();
617+
kvm_cpu_svm_disable();
597618

598619
amd_pmu_disable_virt();
599620
}

0 commit comments

Comments
 (0)