According to Intel SDM Vol. 3C, "Checks on Guest Segment Registers", the TR segment type must be 11 (64-bit busy TSS) when the "IA-32e mode guest" VM-entry control is 1, and may be 3 (16-bit busy TSS) or 11 (32-bit busy TSS) only when "IA-32e mode guest" is 0. Currently, tr_valid() unconditionally allows type 3 even when the guest is in IA-32e mode (long mode). When emulate_invalid_guest_state is enabled, this causes __vmx_guest_state_valid() to falsely report a valid guest state for a 64-bit guest with a 16-bit busy TSS, resulting in a hardware VM-Entry failure (EXIT_REASON_INVALID_STATE / KVM_EXIT_FAIL_ENTRY) instead of emulating the invalid guest state. Check is_long_mode(vcpu) in tr_valid() and reject type 3 when the vCPU is in IA-32e mode. Also update vmx->vt.emulation_required in vmx_set_efer() so that changes to EFER.LMA (such as in prepare_vmcs02() after vmx_set_cr0()) keep emulation_required in sync with vmx_guest_state_valid(). Fixes: 648dfaa7df2d ("KVM: VMX: Add Guest State Validity Checks") Signed-off-by: Daolong Zhang --- v2: - Recompute vmx->vt.emulation_required in vmx_set_efer() so that EFER.LMA updates (e.g. in prepare_vmcs02() after vmx_set_cr0()) do not leave emulation_required out of sync with vmx_guest_state_valid(). - Use full real name ("Daolong Zhang") in Author and Signed-off-by. arch/x86/kvm/vmx/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index cc75feec05da..bc5137a3fb68 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -3253,6 +3253,7 @@ int vmx_set_efer(struct kvm_vcpu *vcpu, u64 efer) #endif vmx_setup_uret_msrs(vmx); + vmx->vt.emulation_required = vmx_emulation_required(vcpu); return 0; } @@ -3898,7 +3899,7 @@ static bool tr_valid(struct kvm_vcpu *vcpu) return false; if (tr.selector & SEGMENT_TI_MASK) /* TI = 1 */ return false; - if (tr.type != 3 && tr.type != 11) /* TODO: Check if guest is in IA32e mode */ + if (tr.type != 11 && (is_long_mode(vcpu) || tr.type != 3)) return false; if (!tr.present) return false; -- 2.48.1