#include "trace.h"
+#include "vmenter.h"
#include "svm.h"
#include "svm_ops.h"
return EXIT_FASTPATH_NONE;
}
-static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, bool spec_ctrl_intercepted)
+static noinstr void svm_vcpu_enter_exit(struct kvm_vcpu *vcpu, unsigned enter_flags)
{
struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, vcpu->cpu);
struct vcpu_svm *svm = to_svm(vcpu);
amd_clear_divider();
if (is_sev_es_guest(vcpu))
- __svm_sev_es_vcpu_run(svm, spec_ctrl_intercepted,
+ __svm_sev_es_vcpu_run(svm, enter_flags,
sev_es_host_save_area(sd));
else
- __svm_vcpu_run(svm, spec_ctrl_intercepted);
+ __svm_vcpu_run(svm, enter_flags);
raw_local_irq_disable();
{
bool force_immediate_exit = run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT;
struct vcpu_svm *svm = to_svm(vcpu);
- bool spec_ctrl_intercepted = msr_write_intercepted(svm, MSR_IA32_SPEC_CTRL);
+ unsigned enter_flags = 0;
+
+ if (!msr_write_intercepted(svm, MSR_IA32_SPEC_CTRL))
+ enter_flags |= KVM_ENTER_SAVE_SPEC_CTRL;
trace_kvm_entry(vcpu, force_immediate_exit);
if (!static_cpu_has(X86_FEATURE_V_SPEC_CTRL))
x86_spec_ctrl_set_guest(svm->virt_spec_ctrl);
- svm_vcpu_enter_exit(vcpu, spec_ctrl_intercepted);
+ svm_vcpu_enter_exit(vcpu, enter_flags);
if (!static_cpu_has(X86_FEATURE_V_SPEC_CTRL))
x86_spec_ctrl_restore_host(svm->virt_spec_ctrl);
/* vmenter.S */
-void __svm_sev_es_vcpu_run(struct vcpu_svm *svm, bool spec_ctrl_intercepted,
+void __svm_sev_es_vcpu_run(struct vcpu_svm *svm, unsigned int flags,
struct sev_es_save_area *hostsa);
-void __svm_vcpu_run(struct vcpu_svm *svm, bool spec_ctrl_intercepted);
+void __svm_vcpu_run(struct vcpu_svm *svm, unsigned int flags);
#define DEFINE_KVM_GHCB_ACCESSORS(field) \
static __always_inline u64 kvm_ghcb_get_##field(struct vcpu_svm *svm) \
#include <asm/kvm_vcpu_regs.h>
#include <asm/nospec-branch.h>
#include "kvm-asm-offsets.h"
+#include "vmenter.h"
#define WORD_SIZE (BITS_PER_LONG / 8)
"jmp 900f", X86_FEATURE_MSR_SPEC_CTRL, \
"", X86_FEATURE_V_SPEC_CTRL
.endm
-.macro RESTORE_HOST_SPEC_CTRL_BODY guest_spec_ctrl:req, spec_ctrl_intercepted:req, label:req
+.macro RESTORE_HOST_SPEC_CTRL_BODY guest_spec_ctrl:req, enter_flags:req, label:req
/* Same for after vmexit. */
mov $MSR_IA32_SPEC_CTRL, %ecx
* Load the value that the guest had written into MSR_IA32_SPEC_CTRL,
* if it was not intercepted during guest execution.
*/
- cmpb $0, \spec_ctrl_intercepted
- jnz 998f
+ testl $KVM_ENTER_SAVE_SPEC_CTRL, \enter_flags
+ jz 998f
rdmsr
movl %eax, \guest_spec_ctrl
movl %edx, 4 + \guest_spec_ctrl
/**
* __svm_vcpu_run - Run a vCPU via a transition to SVM guest mode
- * @svm: struct vcpu_svm *
- * @spec_ctrl_intercepted: bool
+ * @svm: struct vcpu_svm *
+ * @enter_flags: u32
*/
SYM_FUNC_START(__svm_vcpu_run)
push %_ASM_BP
xor %r15d, %r15d
#endif
- /* "Pop" @spec_ctrl_intercepted. */
+ /* "Pop" @enter_flags. */
pop %_ASM_BX
pop %_ASM_BX
/**
* __svm_sev_es_vcpu_run - Run a SEV-ES vCPU via a transition to SVM guest mode
- * @svm: struct vcpu_svm *
- * @spec_ctrl_intercepted: bool
+ * @svm: struct vcpu_svm *
+ * @enter_flags: u32
*/
SYM_FUNC_START(__svm_sev_es_vcpu_run)
FRAME_BEGIN
/*
* Save volatile registers that hold arguments that are needed after
- * #VMEXIT (RDI=@svm and RSI=@spec_ctrl_intercepted).
+ * #VMEXIT (RDI=@svm and RSI=@enter_flags).
*/
mov %rdi, SEV_ES_RDI (%rdx)
mov %rsi, SEV_ES_RSI (%rdx)
/* IMPORTANT: Stuff the RSB immediately after VM-Exit, before RET! */
FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_FEATURE_RSB_VMEXIT
- /* Clobbers RAX, RCX, RDX, consumes RDI (@svm) and RSI (@spec_ctrl_intercepted). */
+ /* Clobbers RAX, RCX, RDX, consumes RDI (@svm) and RSI (@enter_flags). */
RESTORE_HOST_SPEC_CTRL
901:
RESTORE_GUEST_SPEC_CTRL_BODY SVM_spec_ctrl(%_ASM_DI), 801b
jmp 801b
900:
- RESTORE_HOST_SPEC_CTRL_BODY SVM_spec_ctrl(%_ASM_DI), %sil, 901b
+ RESTORE_HOST_SPEC_CTRL_BODY SVM_spec_ctrl(%_ASM_DI), %esi, 901b
jmp 901b
3: cmpb $0, virt_rebooting(%rip)
--- /dev/null
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __KVM_X86_VMENTER_H
+#define __KVM_X86_VMENTER_H
+
+#define KVM_ENTER_VMRESUME BIT(0)
+#define KVM_ENTER_SAVE_SPEC_CTRL BIT(1)
+#define KVM_ENTER_CLEAR_CPU_BUFFERS_FOR_MMIO BIT(2)
+
+#endif /* __KVM_X86_VMENTER_H */
+++ /dev/null
-/* SPDX-License-Identifier: GPL-2.0 */
-#ifndef __KVM_X86_VMX_RUN_FLAGS_H
-#define __KVM_X86_VMX_RUN_FLAGS_H
-
-#define VMX_RUN_VMRESUME BIT(0)
-#define VMX_RUN_SAVE_SPEC_CTRL BIT(1)
-#define VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO BIT(2)
-
-#endif /* __KVM_X86_VMX_RUN_FLAGS_H */
#include <asm/percpu.h>
#include <asm/segment.h>
#include "kvm-asm-offsets.h"
-#include "run_flags.h"
+#include "vmenter.h"
#define WORD_SIZE (BITS_PER_LONG / 8)
/**
* __vmx_vcpu_run - Run a vCPU via a transition to VMX guest mode
* @vmx: struct vcpu_vmx *
- * @flags: VMX_RUN_VMRESUME: use VMRESUME instead of VMLAUNCH
- * VMX_RUN_SAVE_SPEC_CTRL: save guest SPEC_CTRL into vmx->spec_ctrl
- * VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO: vCPU can access host MMIO
+ * @flags: KVM_ENTER_VMRESUME: use VMRESUME instead of VMLAUNCH
+ * KVM_ENTER_SAVE_SPEC_CTRL: save guest SPEC_CTRL into vmx->spec_ctrl
+ * KVM_ENTER_CLEAR_CPU_BUFFERS_FOR_MMIO: vCPU can access host MMIO
*
* Returns:
* 0 on VM-Exit, 1 on VM-Fail
* do VERW. Else, do nothing (no mitigations needed/enabled).
*/
ALTERNATIVE_2 "", \
- __stringify(testl $VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO, (%_ASM_SP); \
+ __stringify(testl $KVM_ENTER_CLEAR_CPU_BUFFERS_FOR_MMIO, (%_ASM_SP); \
jz .Lskip_mmio_verw; \
VERW; \
.Lskip_mmio_verw:), \
__stringify(VERW), X86_FEATURE_CLEAR_CPU_BUF_VM
/* Check @flags to see if VMLAUNCH or VMRESUME is needed. */
- testl $VMX_RUN_VMRESUME, (%_ASM_SP)
+ testl $KVM_ENTER_VMRESUME, (%_ASM_SP)
jz .Lvmlaunch
/*
#include "x86_ops.h"
#include "smm.h"
#include "vmx_onhyperv.h"
+#include "vmenter.h"
#include "posted_intr.h"
#include "mmu/spte.h"
return vmx_test_msr_bitmap_write(vmx->loaded_vmcs->msr_bitmap, msr);
}
-unsigned int __vmx_vcpu_run_flags(struct vcpu_vmx *vmx)
+unsigned int __vmx_vcpu_enter_flags(struct vcpu_vmx *vmx)
{
unsigned int flags = 0;
if (vmx->loaded_vmcs->launched)
- flags |= VMX_RUN_VMRESUME;
+ flags |= KVM_ENTER_VMRESUME;
/*
* If writes to the SPEC_CTRL MSR aren't intercepted, the guest is free
* it after vmexit and store it in vmx->spec_ctrl.
*/
if (!msr_write_intercepted(vmx, MSR_IA32_SPEC_CTRL))
- flags |= VMX_RUN_SAVE_SPEC_CTRL;
+ flags |= KVM_ENTER_SAVE_SPEC_CTRL;
if (cpu_feature_enabled(X86_FEATURE_CLEAR_CPU_BUF_VM_MMIO) &&
kvm_vcpu_can_access_host_mmio(&vmx->vcpu))
- flags |= VMX_RUN_CLEAR_CPU_BUFFERS_FOR_MMIO;
+ flags |= KVM_ENTER_CLEAR_CPU_BUFFERS_FOR_MMIO;
return flags;
}
if (!cpu_feature_enabled(X86_FEATURE_MSR_SPEC_CTRL))
return;
- if (flags & VMX_RUN_SAVE_SPEC_CTRL)
+ if (flags & KVM_ENTER_SAVE_SPEC_CTRL)
vmx->spec_ctrl = native_rdmsrq(MSR_IA32_SPEC_CTRL);
/*
kvm_wait_lapic_expire(vcpu);
/* The actual VMENTER/EXIT is in the .noinstr.text section. */
- vmx_vcpu_enter_exit(vcpu, __vmx_vcpu_run_flags(vmx));
+ vmx_vcpu_enter_exit(vcpu, __vmx_vcpu_enter_flags(vmx));
/* All fields are clean at this point */
if (kvm_is_using_evmcs()) {
#include "vmcs.h"
#include "vmx_ops.h"
#include "../cpuid.h"
-#include "run_flags.h"
#include "../mmu.h"
#include "common.h"
void pt_update_intercept_for_msr(struct kvm_vcpu *vcpu);
void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp);
void vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx, unsigned int flags);
-unsigned int __vmx_vcpu_run_flags(struct vcpu_vmx *vmx);
+unsigned int __vmx_vcpu_enter_flags(struct vcpu_vmx *vmx);
bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned int flags);
void vmx_ept_load_pdptrs(struct kvm_vcpu *vcpu);