Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Tina Zhang" <zhang_wei@open-hieco.net>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v7 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts
Date: Fri, 18 Sep 2026 09:12:34 +0000	[thread overview]
Message-ID: <20260918091234.9A9731F0089D@smtp.kernel.org> (raw)
In-Reply-To: <2b30c180a7ec1fb22033cc1b89debc36c9f569d0.1789721173.git.zhang_wei@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] kvm: nSVM: Stale EXITINFO2 leaked to L1 for Decode Assists and SWINT/ICEBP
- [High] kvm: nSVM: Unconditional CR_VALID injects spurious #GP into 32-bit guests
- [Medium] kvm: nSVM: Missing Decode Assists synthesis for SVM instructions
--

commit 426ea34e024e5747a2d0375a678f4064cd396fdd
Author: Tina Zhang <zhang_wei@open-hieco.net>

KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts

This commit adds synthesis of DecodeAssists EXITINFO1 fields for emulated
instruction intercepts such as MOV CR/DR, INTn, and INVLPG when the guest
CPU exposes DecodeAssists capabilities.

> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
[ ... ]
> @@ -4846,14 +4847,26 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu,
>  	if (stage != icpt_info.stage)
>  		goto out;
>  
> +	decode_assists = guest_cpu_cap_has(vcpu, X86_FEATURE_DECODEASSISTS);
> +
>  	switch (icpt_info.exit_code) {

[Severity: Medium]
Does this switch statement miss several mandatory intercepts defined in the
hardware specification for Decode Assists?

According to AMD APM Vol 2, Table 15-22, Decode Assists also apply to VMRUN,
VMLOAD, VMSAVE, CLGI, STGI, and PAUSE, requiring EXITINFO1 to be explicitly
cleared to 0.

Since these intercepts are omitted, will they fall through to the default
case and leave uninitialized, stale garbage in EXITINFO1 instead of the
architecturally required 0?

>  	case SVM_EXIT_READ_CR0:
>  		if (info->intercept == x86_intercept_cr_read)
>  			icpt_info.exit_code += info->modrm_reg;
> +
> +		if (decode_assists)
> +			vmcb->control.exit_info_1 =
> +				info->intercept == x86_intercept_cr_read ?
> +				CR_VALID | (info->modrm_rm & SVM_EXITINFO_REG_MASK) : 0;

[Severity: High]
Does setting CR_VALID unconditionally here, and below in SVM_EXIT_WRITE_CR0,
inject spurious #GP faults into 32-bit guests?

AMD APM defines Bit 63 (CR_VALID) of EXITINFO1 for CR accesses under
Decode Assists as "1 = instruction is 64-bit, 0 = instruction is 32-bit".

If a 32-bit L2 guest executes a CR access and its general purpose register
happens to have non-zero upper 32 bits (which is permissible), L1 will see
Bit 63 set.

If L1 treats this as a 64-bit instruction, will it read the full 64-bit
vCPU register and fail safety checks (like cr0 & 0xffffffff00000000UL),
resulting in a spurious #GP being injected into L2?

[Severity: High]
Should exit_info_2 also be unconditionally zeroed here when decode_assists
is true?

AMD APM mandates that when Decode Assists is enabled, EXITINFO2 must contain
NextRIP for INTn and ICEBP, and must be 0 for other intercepts like MOV CRx.

Because KVM does not zero exit_info_2 prior to calling svm_check_intercept(),
could this retain a stale value in the L2 VMCB from a prior exit (such as a
#NPF faulting GPA) and leak it to L1?

>  		break;
>  	case SVM_EXIT_WRITE_CR0: {
>  		unsigned long cr0, val;
>  
> +		if (decode_assists)
> +			vmcb->control.exit_info_1 =
> +				info->intercept == x86_intercept_cr_write ?
> +				CR_VALID | (info->modrm_rm & SVM_EXITINFO_REG_MASK) : 0;
> +
[ ... ]
>  	case SVM_EXIT_SWINT:
> +		if (decode_assists)
> +			vmcb->control.exit_info_1 = info->src_val & 0xff;
> +		break;

[Severity: High]
Does this miss setting exit_info_2 for the SWINT intercept?

AMD APM mandates that EXITINFO2 must contain NextRIP for INTn (SVM_EXIT_SWINT)
and ICEBP (SVM_EXIT_ICEBP) when Decode Assists is enabled.

By not setting exit_info_2 = info->next_rip for SWINT, and completely
omitting handling for SVM_EXIT_ICEBP, does L1 read the stale EXITINFO2 as
NextRIP?

If L1 relies on this for NextRIP, could it cause L2 to resume at a corrupted
instruction pointer and crash the L2 guest?

>  	case SVM_EXIT_INVLPG:
> +		if (decode_assists)
> +			vmcb->control.exit_info_1 = info->invlpg_linear_addr;
> +		break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1789721173.git.zhang_wei@open-hieco.net?part=2

  reply	other threads:[~2026-09-18  9:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18  8:56 [PATCH v7 0/8] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang
2026-09-18  8:56 ` [PATCH v7 1/8] KVM: x86: Provide INVLPG linear address to intercept handlers Tina Zhang
2026-09-18 11:10   ` Jim Mattson
2026-09-18 12:10     ` Tina Zhang
2026-09-18  8:56 ` [PATCH v7 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-09-18  9:12   ` sashiko-bot [this message]
2026-09-18 11:27   ` Jim Mattson
2026-09-18  8:56 ` [PATCH v7 3/8] KVM: nSVM: Track valid hardware DecodeAssist bytes Tina Zhang
2026-09-18 11:12   ` Jim Mattson
2026-09-18  8:56 ` [PATCH v7 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-09-18  8:56 ` [PATCH v7 5/8] KVM: nSVM: Fetch DecodeAssist bytes for synthesized faults Tina Zhang
2026-09-18  8:56 ` [PATCH v7 6/8] KVM: nSVM: Use emulator bytes for synthesized nested #NPF Tina Zhang
2026-09-18 11:21   ` Jim Mattson
2026-09-18  8:56 ` [PATCH v7 7/8] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-09-18  8:56 ` [PATCH v7 8/8] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
2026-09-18 11:24   ` Jim Mattson

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=20260918091234.9A9731F0089D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=zhang_wei@open-hieco.net \
    /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