* [PATCH] KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode
@ 2026-11-16 7:08 zhangdaolong
2026-11-16 7:29 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: zhangdaolong @ 2026-11-16 7:08 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, zhangdaolong
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.
Fixes: 648dfaa7df2d ("KVM: VMX: Add Guest State Validity Checks")
Signed-off-by: zhangdaolong <dlzhangak@isoftstone.com>
---
arch/x86/kvm/vmx/vmx.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index cc75feec05da..2a5db87fae0e 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -3898,7 +3898,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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode
2026-11-16 7:08 [PATCH] KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode zhangdaolong
@ 2026-11-16 7:29 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16 7:29 UTC (permalink / raw)
To: zhangdaolong; +Cc: kvm
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] KVM: VMX: invalid Signed-off-by trailer using handle instead of
real name
- [High] KVM: VMX: stale EFER in prepare_vmcs02() via tr_valid() hits
KVM_BUG_ON()
--
commit b3cbe60df7c397383ce043a8a068896cca8bff45
Author: zhangdaolong <dlzhangak@isoftstone.com>
> KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode
>
> 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.
>
> Fixes: 648dfaa7df2d ("KVM: VMX: Add Guest State Validity Checks")
> Signed-off-by: zhangdaolong <dlzhangak@isoftstone.com>
[Severity: High]
Per Documentation/process/submitting-patches.rst, the Signed-off-by tag and
commit Author need a full real name (given name and family name separated by
a space) rather than a single-word handle ("zhangdaolong").
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 612ab07d4100f..901280328cee3 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -3917,7 +3917,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;
[Severity: High]
Can checking is_long_mode(vcpu) here evaluate a stale vcpu->arch.efer during
prepare_vmcs02() and leave vmx->vt.emulation_required out of sync with
vmx_guest_state_valid()?
arch/x86/kvm/vmx/nested.c:prepare_vmcs02() {
...
vmx_set_cr0(vcpu, vmcs12->guest_cr0);
vmcs_writel(CR0_READ_SHADOW, nested_read_cr0(vmcs12));
vmx_set_cr4(vcpu, vmcs12->guest_cr4);
vmcs_writel(CR4_READ_SHADOW, nested_read_cr4(vmcs12));
vcpu->arch.efer = nested_vmx_calc_efer(vmx, vmcs12);
/* Note: may modify VM_ENTRY/EXIT_CONTROLS and GUEST/HOST_IA32_EFER */
vmx_set_efer(vcpu, vcpu->arch.efer);
if (CC(from_vmentry && !vmx_guest_state_valid(vcpu))) {
...
}
vmx_set_cr0() computes vmx->vt.emulation_required = vmx_emulation_required(vcpu)
before vcpu->arch.efer is updated to L2's EFER, and vmx_set_efer() does not
recompute it.
When a 64-bit L1 guest (EFER_LMA == 1, CR0.PG == 1) enters a 32-bit paged
protected-mode L2 guest (VM_ENTRY_IA32E_MODE == 0, CR0.PG == 1) with
SECONDARY_EXEC_UNRESTRICTED_GUEST disabled and a valid 16-bit busy TSS
(tr.type == 3), vmx_set_cr0() sees no change in CR0.PG, leaves L1's
EFER_LMA == 1 in vcpu->arch.efer, and sets vmx->vt.emulation_required = true.
Once vcpu->arch.efer is updated to L2's EFER (EFER_LMA == 0),
vmx_guest_state_valid() succeeds and nested VM-Enter completes with
nested_run_pending set, causing vmx_vcpu_run() to bail out on
emulation_required and hit KVM_BUG_ON(vcpu->arch.nested_run_pending, vcpu->kvm)
in __vmx_handle_exit().
Conversely, when prepare_vmcs02() runs with from_vmentry == false while
EFER_LMA is 0 to load a 64-bit restricted L2 state with tr.type == 3,
emulation_required is left false, resulting in a hardware VM-Entry failure
instead of emulating the invalid guest state.
--
Sashiko AI review · https://sashiko.dev/#/patchset/1794812900.6AFAABE3.003.4jSf8g6LZ4z562g@fangwg01?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 7:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 7:08 [PATCH] KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode zhangdaolong
2026-11-16 7:29 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox