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 v3 7/9] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF
Date: Thu, 30 Jul 2026 12:31:35 +0000	[thread overview]
Message-ID: <20260730123135.B3FB21F000E9@smtp.kernel.org> (raw)
In-Reply-To: <9dae4bd5ad241b72193b38cfe8857c968c47a4b7.1785411877.git.zhang_wei@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Already-prepared instruction bytes are discarded if the instruction pointer exceeds the CS limit (or due to residual upper bits in 16-bit mode).
--

--- Patch [7]: [PATCH v3 7/9] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF ---
commit 96d13188ab4298d9414e0345853cc8950d39abb9
Author: Tina Zhang <zhang_wei@open-hieco.net>

KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF

This commit limits the preparation of synthesized state to matching the
emulator fetch cache and fetches any missing tail bytes through L2 guest
page tables. If the emulator cache is empty, it attempts to fetch the full
window from the L2 RIP, avoiding fetches for SEV guests.

> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index cfb686c29bb47..cf2b6bb8126ff 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c

[ ... ]

> +static u8 nested_svm_fetch_insn_bytes(struct kvm_vcpu *vcpu, u8 *bytes,
> +				      u8 count, u8 max_bytes)
> +{
> +	struct kvm_pagewalk *gva_walk = &vcpu->arch.gva_walk;
> +	u64 access = PFERR_FETCH_MASK;
> +	gva_t rip = kvm_get_linear_rip(vcpu);
> +	struct x86_exception e;
> +
> +	if (kvm_x86_call(get_cpl)(vcpu) == 3)
> +		access |= PFERR_USER_MASK;
> +
> +	if (!is_64_bit_mode(vcpu)) {
> +		u32 eip = kvm_rip_read(vcpu);
> +		u32 limit = to_svm(vcpu)->vmcb->save.cs.limit;
> +
> +		if (eip > limit)
> +			return 0;

[Severity: Medium]
Should this return count instead of 0?

If an L2 guest in 16-bit or 32-bit mode causes a nested page fault where
eip > limit evaluates to true (for example, in 16-bit mode if kvm_rip_read()
retains residual upper 16-bits), returning 0 here causes the caller to
overwrite vmcb12->control.insn_len with 0. 

This would inadvertently discard any already-prepared valid instruction bytes
that were passed in via the count parameter, forcing the L1 hypervisor to
manually read the instruction from L2 memory and defeating the DecodeAssist
optimization.

> +		max_bytes = min_t(u64, max_bytes, (u64)limit - eip + 1);
> +	}
> +
> +	count = min(count, max_bytes);
> +
> +	while (count < max_bytes) {

[ ... ]

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

  reply	other threads:[~2026-07-30 12:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 12:08 [PATCH v3 0/9] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang
2026-07-30 12:08 ` [PATCH v3 1/9] KVM: x86: Add helper to provide intercept linear addresses Tina Zhang
2026-07-30 12:38   ` sashiko-bot
2026-07-30 12:08 ` [PATCH v3 2/9] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-07-30 12:30   ` sashiko-bot
2026-07-30 12:08 ` [PATCH v3 3/9] KVM: nSVM: Track hardware-provided instruction bytes Tina Zhang
2026-07-30 12:34   ` sashiko-bot
2026-07-30 12:08 ` [PATCH v3 4/9] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-07-30 12:08 ` [PATCH v3 5/9] KVM: x86: Track emulator-originated nested #PF VM-Exits Tina Zhang
2026-07-30 12:08 ` [PATCH v3 6/9] KVM: nSVM: Use emulator bytes for synthesized nested #NPF/#PF Tina Zhang
2026-07-30 12:08 ` [PATCH v3 7/9] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF Tina Zhang
2026-07-30 12:31   ` sashiko-bot [this message]
2026-07-30 12:08 ` [PATCH v3 8/9] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-07-30 12:33   ` sashiko-bot
2026-07-30 12:08 ` [PATCH v3 9/9] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
2026-07-30 12:34   ` sashiko-bot

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=20260730123135.B3FB21F000E9@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