From: sashiko-bot@kernel.org
To: zhangdaolong <dlzhangak@isoftstone.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: VMX: Disallow 16-bit busy TSS (type 3) for TR in IA-32e mode
Date: Mon, 16 Nov 2026 07:29:50 +0000 [thread overview]
Message-ID: <sashiko-outbox-216429@kernel.org> (raw)
In-Reply-To: <1794812900.6AFAABE3.003.4jSf8g6LZ4z562g@fangwg01>
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
prev parent reply other threads:[~2026-11-16 7:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-216429@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dlzhangak@isoftstone.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).