From: sashiko-bot@kernel.org
To: "Tina Zhang" <zhang_wei@open-hieco.net>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/9] KVM: nSVM: Track hardware-provided instruction bytes
Date: Thu, 30 Jul 2026 12:34:03 +0000 [thread overview]
Message-ID: <20260730123403.96BA11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <0d1e1110881aada32e474c74105f3d4cc5ba991e.1785411877.git.zhang_wei@open-hieco.net>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The patch clears instruction bytes only on nested VMRUN, causing stale DecodeAssist data from L0-handled exits to be falsely flagged as fresh during subsequent intercepts.
- [High] Hardware-provided DecodeAssist data and the fresh flag are lost across live migration for a pending nested #PF.
--
--- Patch [3]: [PATCH v3 3/9] KVM: nSVM: Track hardware-provided instruction bytes ---
commit e944fdb4c1650228b5e210eab6c8b6fe2761112a
Author: Tina Zhang <zhang_wei@open-hieco.net>
KVM: nSVM: Track hardware-provided instruction bytes
DecodeAssists provides instruction bytes for nested page faults and
intercepted page faults caused by data accesses. When reflecting such an
exit to L1, KVM needs to distinguish bytes produced by the current hardware
VM-Exit from stale VMCB02 state.
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index b63234a2feb8d..6e2ceb700567c 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
[ ... ]
> @@ -1953,14 +1953,20 @@ static void svm_set_dr7(struct kvm_vcpu *vcpu, unsigned long value)
> static int pf_interception(struct kvm_vcpu *vcpu)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> -
> u64 fault_address = svm->vmcb->control.exit_info_2;
> u64 error_code = svm->vmcb->control.exit_info_1;
> + int r;
> +
> + r = kvm_handle_page_fault(vcpu, error_code, fault_address,
> + static_cpu_has(X86_FEATURE_DECODEASSISTS) ?
> + svm->vmcb->control.insn_bytes : NULL,
> + svm->vmcb->control.insn_len);
>
> - return kvm_handle_page_fault(vcpu, error_code, fault_address,
> - static_cpu_has(X86_FEATURE_DECODEASSISTS) ?
> - svm->vmcb->control.insn_bytes : NULL,
> - svm->vmcb->control.insn_len);
> + if (is_guest_mode(vcpu) && vcpu->arch.exception_vmexit.pending &&
> + vcpu->arch.exception_vmexit.vector == PF_VECTOR)
> + svm->nested.vmcb02_insn_bytes_fresh = true;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Does this unconditionally mark the instruction bytes as fresh for any PF_VECTOR,
including instruction fetches where DecodeAssist is inactive?
If so, could this result in stale bytes from a previous hardware VM-Exit
being incorrectly synthesized to the L1 hypervisor?
> +
> + return r;
> }
[ ... ]
> @@ -3725,7 +3731,7 @@ static int svm_handle_exit(struct kvm_vcpu *vcpu, fastpath_t exit_fastpath)
> vmexit = nested_svm_exit_special(svm);
>
> if (vmexit == NESTED_EXIT_CONTINUE)
> - vmexit = nested_svm_exit_handled(svm);
> + vmexit = nested_svm_exit_handled(svm, true);
^^^^
[Severity: High]
By passing true here for all NESTED_EXIT_CONTINUE VM-exits, does this
incorrectly flag stale bytes as fresh for exits where DecodeAssist is
not active?
For example, if L2 causes a data #PF handled by L0 (which writes insn_bytes)
and is resumed without clearing the instruction bytes, and then L2 causes a
different exit intercepted by L1 (like an MSR intercept), will this pass the
stale instruction bytes to L1 as fresh?
>
> if (vmexit == NESTED_EXIT_DONE)
> return 1;
[ ... ]
> diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h
> index a327bf751ecd5..96d2471a03c8c 100644
> --- a/arch/x86/kvm/svm/svm.h
> +++ b/arch/x86/kvm/svm/svm.h
> @@ -242,6 +242,12 @@ struct svm_nested_state {
> * on its side.
> */
> bool force_msr_bitmap_recalc;
> +
> + /*
> + * True if VMCB02 contains DecodeAssist instruction bytes from the
> + * hardware VM-Exit currently being reflected to L1.
> + */
> + bool vmcb02_insn_bytes_fresh;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Severity: High]
Will this tracking state be lost across live migration?
Since it appears this flag is added to the nested state structure but omitted
from KVM_GET_NESTED_STATE serialization, if a migration occurs while a nested
exit is pending, won't the target host fail to receive the instruction bytes
and potentially cause emulation failure in L1?
> };
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1785411877.git.zhang_wei@open-hieco.net?part=3
next prev parent reply other threads:[~2026-07-30 12:34 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 [this message]
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
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=20260730123403.96BA11F000E9@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.