All of lore.kernel.org
 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 9/9] KVM: selftests: Add nested SVM DecodeAssists test
Date: Thu, 30 Jul 2026 12:34:25 +0000	[thread overview]
Message-ID: <20260730123425.7918B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <0e335bfb321909a0ddba98337a2325f8f88e58ce.1785411877.git.zhang_wei@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The selftest `test_synthesized_npf_linear_wrap` incorrectly asserts that 64-bit linear addresses wrap at 4GB in compatibility mode, cementing a preexisting KVM emulator bug.
--

--- Patch [9]: [PATCH v3 9/9] KVM: selftests: Add nested SVM DecodeAssists test ---
commit 90a4009aecfc1596a0c559275e2cf280935e0a29
Author: Tina Zhang <zhang_wei@open-hieco.net>

KVM: selftests: Add nested SVM DecodeAssists test

Add a nested SVM selftest for DecodeAssists. Verify that KVM exposes
the feature to L1 and provides architectural exit state for various
instructions and intercepts.

> diff --git a/tools/testing/selftests/kvm/x86/svm_nested_decode_assists_test.c b/tools/testing/selftests/kvm/x86/svm_nested_decode_assists_test.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/svm_nested_decode_assists_test.c
[ ... ]
> +static void test_synthesized_npf_linear_wrap(struct svm_test_data *svm,
> +					     gpa_t npf_gpa)
> +{
> +	struct vmcb *vmcb = svm->vmcb;
[ ... ]
> +	prepare_l2_for_vmrun(svm, setup_eip);
> +	run_guest(vmcb, svm->vmcb_gpa);
> +	GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_NPF);
> +	GUEST_ASSERT_EQ(vmcb->control.exit_info_2, npf_gpa);
> +	GUEST_ASSERT_EQ(vmcb->save.rip, outsb_eip);
> +	GUEST_ASSERT_EQ(vmcb->control.insn_len,
> +			sizeof(linear_wrap_insn_bytes));

[Severity: Medium]
Does this test enforce an architectural violation by requiring the KVM
emulator to wrap 64-bit linear addresses to 32 bits?

By setting up L2 in compatibility mode (CS.L=0) with a non-zero segment
base and an EIP that crosses the 4GB boundary, this asserts that KVM
successfully fetches all 15 instruction bytes from GVA 0. This appears to
cement a pre-existing KVM emulator bug rather than verifying correct
hardware behavior (where the correct 64-bit linear address would be
0x100000000).

> +	GUEST_ASSERT(!memcmp(vmcb->control.insn_bytes,
> +			     linear_wrap_insn_bytes,
> +			     sizeof(linear_wrap_insn_bytes)));
> +	vmcb->save.cs.attrib = cs_attrib;
> +	vmcb->save.cs.base = cs_base;
> +	vmcb->save.cs.limit = cs_limit;
> +}
[ ... ]
> +static void prepare_linear_wrap_outsb_code(struct kvm_vm *vm)
> +{
[ ... ]
> +	memcpy(&high_page[LINEAR_WRAP_OUTSB_OFFSET],
> +	       linear_wrap_insn_bytes,
> +	       PAGE_SIZE - LINEAR_WRAP_OUTSB_OFFSET);
> +	memcpy(low_page,
> +	       &linear_wrap_insn_bytes[PAGE_SIZE - LINEAR_WRAP_OUTSB_OFFSET],
> +	       sizeof(linear_wrap_insn_bytes) -
> +	       (PAGE_SIZE - LINEAR_WRAP_OUTSB_OFFSET));
> +
> +	virt_map(vm, LINEAR_WRAP_CODE_GVA, high_gpa, 1);
> +	virt_map(vm, 0, low_gpa, 1);

[Severity: Medium]
Is mapping GVA 0 here anticipating and validating the emulator's incorrect
32-bit truncation of the linear address?

If the emulator is ever fixed to comply with the AMD APM and use the full
64-bit address, wouldn't this test begin failing since it maps the
fallback wrapped address?

> +}

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

      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
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 [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=20260730123425.7918B1F000E9@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.