From: sashiko-bot@kernel.org
To: "Tina Zhang" <zhang_wei@open-hieco.net>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v2 6/8] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF
Date: Tue, 14 Jul 2026 05:45:44 +0000 [thread overview]
Message-ID: <20260714054545.2E3641F000E9@smtp.kernel.org> (raw)
In-Reply-To: <341a0d64b31f03bf580beab32a36bf58042ccf2a.1783999988.git.zhang_wei@open-hieco.net>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Missing 32-bit linear address truncation when computing `rip + count` for instruction fetch.
--
--- Patch [6]: [PATCH v2 6/8] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF ---
commit 92b0b1d782b47781c3462fcdfb9a37ae5af201c8
Author: Tina Zhang <zhang_wei@open-hieco.net>
KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF
This commit updates nested SVM to fetch missing DecodeAssist instruction
bytes directly from the L2 guest page tables when the emulator fetch cache
is incomplete. It honors CS limits and handles page faults, but skips tail
reads for SEV guests.
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -75,6 +75,54 @@ static void nested_svm_clear_synthesized_insn_bytes(struct vcpu_svm *svm)
[ ... ]
> +static u8 nested_svm_fetch_insn_bytes(struct kvm_vcpu *vcpu, u8 *bytes,
> + u8 count, u8 max_bytes)
> +{
> + struct kvm_mmu *mmu = vcpu->arch.walk_mmu;
> + u64 access = PFERR_FETCH_MASK;
> + gva_t rip = kvm_get_linear_rip(vcpu);
> + struct x86_exception e;
> +
> + if (to_svm(vcpu)->vmcb->save.cpl == 3)
> + access |= PFERR_USER_MASK;
> +
> + /*
> + * Hardware truncates the fetch at the CS limit. CS.base and CS.limit
> + * checks do not apply in 64-bit mode.
> + */
> + 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;
> + max_bytes = min_t(u64, max_bytes, (u64)limit - eip + 1);
> + }
> +
> + count = min(count, max_bytes);
> +
> + while (count < max_bytes) {
> + unsigned int chunk = min_t(unsigned int, max_bytes - count,
> + PAGE_SIZE - offset_in_page(rip + count));
> + gpa_t gpa = mmu->gva_to_gpa(vcpu, mmu, rip + count, access, &e);
[Severity: Medium]
Does this properly handle linear address wrap-around for 32-bit guests?
For a 32-bit L2 guest, if CS.base + EIP is close to 0xffffffff, adding
count to rip can cause rip + count to exceed 4GB. Because rip is a
64-bit gva_t, the addition won't automatically truncate to 32 bits,
meaning the address will evaluate as greater than 4GB rather than wrapping
to 0.
Could this cause KVM to fetch instruction bytes from the wrong guest
physical address when the instruction fetch wraps around the 4GB boundary?
> +
> + if (gpa == INVALID_GPA ||
> + kvm_vcpu_read_guest_page(vcpu, gpa_to_gfn(gpa),
> + bytes + count,
> + offset_in_page(gpa), chunk))
> + break;
> +
> + count += chunk;
> + }
> +
> + return count;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1783999988.git.zhang_wei@open-hieco.net?part=6
next prev parent reply other threads:[~2026-07-14 5:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 5:09 [PATCH v2 0/8] KVM: nSVM: Enable DecodeAssists for nested guests Tina Zhang
2026-07-14 5:09 ` [PATCH v2 1/8] KVM: x86: Add intercept_linear_addr to x86_instruction_info Tina Zhang
2026-07-14 5:09 ` [PATCH v2 2/8] KVM: nSVM: Synthesize DecodeAssists EXITINFO for emulated intercepts Tina Zhang
2026-07-14 5:31 ` sashiko-bot
2026-07-14 5:09 ` [PATCH v2 3/8] KVM: nSVM: Track fresh VMCB02 DecodeAssist bytes Tina Zhang
2026-07-14 5:30 ` sashiko-bot
2026-07-14 5:10 ` [PATCH v2 4/8] KVM: nSVM: Propagate hardware DecodeAssist bytes to VMCB12 Tina Zhang
2026-07-14 5:32 ` sashiko-bot
2026-07-14 5:10 ` [PATCH v2 5/8] KVM: nSVM: Use emulator bytes for synthesized nested #NPF/#PF Tina Zhang
2026-07-14 5:32 ` sashiko-bot
2026-07-14 5:10 ` [PATCH v2 6/8] KVM: nSVM: Fetch missing DecodeAssist bytes for synthesized #NPF/#PF Tina Zhang
2026-07-14 5:45 ` sashiko-bot [this message]
2026-07-14 5:10 ` [PATCH v2 7/8] KVM: nSVM: Advertise DecodeAssists to L1 Tina Zhang
2026-07-14 5:10 ` [PATCH v2 8/8] KVM: selftests: Add nested SVM DecodeAssists test Tina Zhang
2026-07-14 5:29 ` 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=20260714054545.2E3641F000E9@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