Skip to content

Commit bf653b7

Browse files
taoxu916bonzini
authored andcommitted
KVM: vmx: Introduce handle_unexpected_vmexit and handle WAITPKG vmexit
As the latest Intel 64 and IA-32 Architectures Software Developer's Manual, UMWAIT and TPAUSE instructions cause a VM exit if the RDTSC exiting and enable user wait and pause VM-execution controls are both 1. Because KVM never enable RDTSC exiting, the vm-exit for UMWAIT and TPAUSE should never happen. Considering EXIT_REASON_XSAVES and EXIT_REASON_XRSTORS is also unexpected VM-exit for KVM. Introduce a common exit helper handle_unexpected_vmexit() to handle these unexpected VM-exit. Suggested-by: Sean Christopherson <[email protected]> Co-developed-by: Jingqi Liu <[email protected]> Signed-off-by: Jingqi Liu <[email protected]> Signed-off-by: Tao Xu <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 6e3ba4a commit bf653b7

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

arch/x86/include/uapi/asm/vmx.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
#define EXIT_REASON_PML_FULL 62
8787
#define EXIT_REASON_XSAVES 63
8888
#define EXIT_REASON_XRSTORS 64
89+
#define EXIT_REASON_UMWAIT 67
90+
#define EXIT_REASON_TPAUSE 68
8991

9092
#define VMX_EXIT_REASONS \
9193
{ EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -144,7 +146,9 @@
144146
{ EXIT_REASON_RDSEED, "RDSEED" }, \
145147
{ EXIT_REASON_PML_FULL, "PML_FULL" }, \
146148
{ EXIT_REASON_XSAVES, "XSAVES" }, \
147-
{ EXIT_REASON_XRSTORS, "XRSTORS" }
149+
{ EXIT_REASON_XRSTORS, "XRSTORS" }, \
150+
{ EXIT_REASON_UMWAIT, "UMWAIT" }, \
151+
{ EXIT_REASON_TPAUSE, "TPAUSE" }
148152

149153
#define VMX_ABORT_SAVE_GUEST_MSR_FAIL 1
150154
#define VMX_ABORT_LOAD_HOST_PDPTE_FAIL 2

arch/x86/kvm/vmx/nested.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5470,6 +5470,10 @@ bool nested_vmx_exit_reflected(struct kvm_vcpu *vcpu, u32 exit_reason)
54705470
case EXIT_REASON_ENCLS:
54715471
/* SGX is never exposed to L1 */
54725472
return false;
5473+
case EXIT_REASON_UMWAIT:
5474+
case EXIT_REASON_TPAUSE:
5475+
return nested_cpu_has2(vmcs12,
5476+
SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE);
54735477
default:
54745478
return true;
54755479
}

arch/x86/kvm/vmx/vmx.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5007,20 +5007,6 @@ static int handle_xsetbv(struct kvm_vcpu *vcpu)
50075007
return 1;
50085008
}
50095009

5010-
static int handle_xsaves(struct kvm_vcpu *vcpu)
5011-
{
5012-
kvm_skip_emulated_instruction(vcpu);
5013-
WARN(1, "this should never happen\n");
5014-
return 1;
5015-
}
5016-
5017-
static int handle_xrstors(struct kvm_vcpu *vcpu)
5018-
{
5019-
kvm_skip_emulated_instruction(vcpu);
5020-
WARN(1, "this should never happen\n");
5021-
return 1;
5022-
}
5023-
50245010
static int handle_apic_access(struct kvm_vcpu *vcpu)
50255011
{
50265012
if (likely(fasteoi)) {
@@ -5514,6 +5500,14 @@ static int handle_encls(struct kvm_vcpu *vcpu)
55145500
return 1;
55155501
}
55165502

5503+
static int handle_unexpected_vmexit(struct kvm_vcpu *vcpu)
5504+
{
5505+
kvm_skip_emulated_instruction(vcpu);
5506+
WARN_ONCE(1, "Unexpected VM-Exit Reason = 0x%x",
5507+
vmcs_read32(VM_EXIT_REASON));
5508+
return 1;
5509+
}
5510+
55175511
/*
55185512
* The exit handlers return 1 if the exit was handled fully and guest execution
55195513
* may resume. Otherwise they set the kvm_run parameter to indicate what needs
@@ -5565,13 +5559,15 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = {
55655559
[EXIT_REASON_INVVPID] = handle_vmx_instruction,
55665560
[EXIT_REASON_RDRAND] = handle_invalid_op,
55675561
[EXIT_REASON_RDSEED] = handle_invalid_op,
5568-
[EXIT_REASON_XSAVES] = handle_xsaves,
5569-
[EXIT_REASON_XRSTORS] = handle_xrstors,
5562+
[EXIT_REASON_XSAVES] = handle_unexpected_vmexit,
5563+
[EXIT_REASON_XRSTORS] = handle_unexpected_vmexit,
55705564
[EXIT_REASON_PML_FULL] = handle_pml_full,
55715565
[EXIT_REASON_INVPCID] = handle_invpcid,
55725566
[EXIT_REASON_VMFUNC] = handle_vmx_instruction,
55735567
[EXIT_REASON_PREEMPTION_TIMER] = handle_preemption_timer,
55745568
[EXIT_REASON_ENCLS] = handle_encls,
5569+
[EXIT_REASON_UMWAIT] = handle_unexpected_vmexit,
5570+
[EXIT_REASON_TPAUSE] = handle_unexpected_vmexit,
55755571
};
55765572

55775573
static const int kvm_vmx_max_exit_handlers =

0 commit comments

Comments
 (0)