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 v2 8/8] KVM: selftests: Add nested SVM DecodeAssists test
Date: Tue, 14 Jul 2026 05:29:38 +0000	[thread overview]
Message-ID: <20260714052938.900D11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <6ce7357cee9aac5e57434681b9aff9ab8d9f8162.1783999988.git.zhang_wei@open-hieco.net>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Unmapping the page containing `npf_target` may accidentally unmap other variables like `l2_guest_stack`, causing unintended page faults.
- [Medium] Guest assertion failures are obscured because `get_ucall()`'s return value is checked with a simple equality assertion rather than handling `UCALL_ABORT`.
--

--- Patch [8]: [PATCH v2 8/8] KVM: selftests: Add nested SVM DecodeAssists test ---
commit 022271cf32a29cba4b8af8cdce602deac0fd3ec4
Author: Tina Zhang <zhang_wei@open-hieco.net>

KVM: selftests: Add nested SVM DecodeAssists test

This commit adds a nested SVM selftest for DecodeAssists to verify that KVM
exposes the feature to L1 and provides the correct architectural exit state
for various 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
> index 0000000000000..ac9601dda9365
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/svm_nested_decode_assists_test.c
> @@ -0,0 +1,694 @@

[ ... ]

> +#define USERSPACE_PF_STAGE 1
> +#define TEST_IOPM_SIZE (3 * PAGE_SIZE)
> +
> +static u64 npf_target __aligned(PAGE_SIZE);
> +static u8 boundary_outsb_code[2 * PAGE_SIZE] __aligned(PAGE_SIZE);
> +static u8 limit_outsb_code[PAGE_SIZE] __aligned(PAGE_SIZE);
> +static unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];

[ ... ]

> +	tdp_identity_map_default_memslots(vm);
> +	pte = tdp_get_pte(vm, npf_gpa);
> +	*pte &= ~PTE_PRESENT_MASK(&vm->stage2_mmu);

[Severity: Medium]
Since npf_target is only 8 bytes long but page-aligned, could the linker
pack other variables (like l2_guest_stack) into the remaining 4088 bytes
of the same page?

If so, when this code unmaps the stage-2 PTE for the page containing
npf_target, it might accidentally unmap the guest stack. Would L2
execution then #NPF on its first stack operation and fail the test
misleadingly?

> +	pte = tdp_get_pte(vm, fetch_npf_gpa);
> +	*pte &= ~PTE_PRESENT_MASK(&vm->stage2_mmu);
> +
> +	boundary_page_gva = (gva_t)&boundary_outsb_code[PAGE_SIZE];
> +	pte = vm_get_pte(vm, boundary_page_gva);
> +	*pte &= ~PTE_PRESENT_MASK(&vm->mmu);
> +
> +	vcpu_args_set(vcpu, 5, svm_gva, npf_gpa, fetch_npf_gva,
> +		      fetch_npf_gpa, iopm_gpa);
> +	vcpu_run(vcpu);
> +	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
> +	{
> +		struct ucall uc;
> +
> +		TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_SYNC);

[Severity: Medium]
If a guest assertion fails, it exits with UCALL_ABORT containing detailed
file, line, and message information.

By using a simple equality assertion here, wouldn't a guest failure result
in a generic host-side failure (e.g., "Expected UCALL_SYNC, got UCALL_ABORT")
and drop the actual guest failure reason, making it harder to debug?

> +		TEST_ASSERT_EQ(uc.args[1], USERSPACE_PF_STAGE);
> +	}
> +	queue_userspace_pf(vcpu);
> +	vcpu_run(vcpu);
> +	TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
> +	TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);

[Severity: Medium]
Similarly, wouldn't this assertion also silently drop the payload of a
UCALL_ABORT if the guest aborts at the end of the test?

> +
> +	kvm_vm_free(vm);
> +	return 0;
> +}

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

      reply	other threads:[~2026-07-14  5:29 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
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 [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=20260714052938.900D11F000E9@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.