From: sashiko-bot@kernel.org
To: Bingyu.Xian <shanbeeyoo@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: selftests: riscv: Add G-stage binary stats test
Date: Fri, 04 Dec 2026 14:11:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-249935@kernel.org> (raw)
In-Reply-To: <20261204132651.413976-3-shanbeeyoo@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] KVM: selftests: unconditional THP memslot aborts in
test_2m_split_lifecycle()
- [Medium] KVM: selftests: silent skip and mid-plan exit in
test_2m_split_lifecycle()
- [Low] KVM: selftests: missing EINTR/EAGAIN retry in pre_fault_range()
--
commit 6f758d9d5cfa8b40a68012d23780e14dac6f19ba
Author: Bingyu.Xian <shanbeeyoo@gmail.com>
KVM: selftests: riscv: Add G-stage binary stats test
This commit adds a RISC-V KVM selftest that checks per-VM G-stage binary
stats (pgtable_pages, pages_4k, pages_2m, pages_1g) across 4K pre-faulting,
dirty-log write-protection, 2M THP splitting, and memslot removal.
> diff --git a/tools/testing/selftests/kvm/riscv/gstage_stats_test.c b/tools/testing/selftests/kvm/riscv/gstage_stats_test.c
> new file mode 100644
> index 0000000000000..1b74edd501625
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/riscv/gstage_stats_test.c
> @@ -0,0 +1,158 @@
[ ... ]
> +static void pre_fault_range(struct kvm_vcpu *vcpu, u64 gpa, u64 size)
> +{
> + struct kvm_pre_fault_memory range = {
> + .gpa = gpa,
> + .size = size,
> + .flags = 0,
> + };
> +
> + while (range.size) {
> + int ret = __vcpu_ioctl(vcpu, KVM_PRE_FAULT_MEMORY, &range);
> +
> + TEST_ASSERT(!ret, "KVM_PRE_FAULT_MEMORY failed: %d (gpa=0x%llx, rem=0x%llx)",
> + ret, (unsigned long long)range.gpa,
> + (unsigned long long)range.size);
> + }
> +}
[Severity: Low]
Should pre_fault_range() retry KVM_PRE_FAULT_MEMORY on EINTR and EAGAIN?
kvm_vcpu_pre_fault_memory() returns -EINTR when a signal is pending before
any page is mapped, and the UAPI also allows EAGAIN on transient races.
Failing immediately causes spurious test failures, and the TEST_ASSERT
message also omits errno from its diagnostic.
[ ... ]
> +static void test_2m_split_lifecycle(void)
> +{
> + struct kvm_vm *vm;
> + struct kvm_vcpu *vcpu;
> + u64 pgtable_before_split, pages_2m_mapped, pages_4k_mapped;
> + void *hva;
> +
> + vm = vm_create_barebones();
> + vcpu = __vm_vcpu_add(vm, 0);
> +
> + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS_THP, TEST_HUGE_GPA,
> + TEST_HUGE_SLOT, TEST_NR_2M_PAGES, 0);
> + hva = addr_gpa2hva(vm, TEST_HUGE_GPA);
> + madvise(hva, SZ_2M, MADV_HUGEPAGE);
[Severity: Medium]
Can vm_userspace_mem_region_add() with VM_MEM_SRC_ANONYMOUS_THP abort on
kernels built without CONFIG_TRANSPARENT_HUGEPAGE?
vm_mem_add() resolves VM_MEM_SRC_ANONYMOUS_THP via get_backing_src_pagesz()
-> get_trans_hugepagesz(), which runs TEST_ASSERT(thp_configured(), ...)
before the 4K fallback branch can execute. Checking thp_configured() first
and skipping with ksft_test_result_skip() or falling back to
VM_MEM_SRC_ANONYMOUS avoids breaking make run_tests on !THP kernels.
Also, vm_mem_add() already calls and checks madvise(..., MADV_HUGEPAGE)
for VM_MEM_SRC_ANONYMOUS_THP when THP is configured, so the unchecked
madvise() call here is redundant.
[ ... ]
> + if (pages_2m_mapped == 1) {
> + TEST_ASSERT_EQ(pages_4k_mapped, 0);
> +
> + if (get_kvm_param_bool("eager_page_split")) {
> + /* Enabling dirty logging eagerly splits the 2M leaf into 512 4K leaves. */
> + vm_mem_region_set_flags(vm, TEST_HUGE_SLOT, KVM_MEM_LOG_DIRTY_PAGES);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pages_2m), 0);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pages_4k), TEST_NR_2M_PAGES);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pgtable_pages), pgtable_before_split + 1);
> + }
> +
> + vm_mem_region_delete(vm, TEST_HUGE_SLOT);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pages_4k), 0);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pages_2m), 0);
> + ksft_test_result_pass("2m_thp_and_dirty_log_split\n");
> + } else {
> + TEST_ASSERT_EQ(pages_2m_mapped, 0);
> + TEST_ASSERT_EQ(pages_4k_mapped, TEST_NR_2M_PAGES);
> +
> + vm_mem_region_delete(vm, TEST_HUGE_SLOT);
> + TEST_ASSERT_EQ(vm_get_stat(vm, pages_4k), 0);
> + ksft_test_result_pass("2m_slot_4k_fallback_and_unmap\n");
> + }
[Severity: Medium]
Does this branch report a false pass when eager_page_split is disabled or
when 2M THP backing is unavailable?
When eager_page_split is false, the dirty-log split assertions are skipped
but ksft_test_result_pass("2m_thp_and_dirty_log_split\n") is still emitted.
When pages_2m_mapped is 0, 2M mapping and splitting are never exercised yet
the test reports a pass under a different name instead of calling
ksft_test_result_skip() with a reason.
In addition, get_kvm_param_bool("eager_page_split") calls
open_path_or_exit(), which invokes ksft_exit_skip() on ENOENT or EACCES.
Calling it after ksft_set_plan(2) and test_4k_lifecycle() exits mid-plan
without freeing vm.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204132651.413976-1-shanbeeyoo@gmail.com?part=2
prev parent reply other threads:[~2026-12-04 14:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:26 [PATCH 0/2] RISC-V: KVM: Expose G-stage page table and mapping stats Bingyu.Xian
2026-12-04 13:26 ` [PATCH 1/2] " Bingyu.Xian
2026-12-04 13:57 ` sashiko-bot
2026-12-04 13:26 ` [PATCH 2/2] KVM: selftests: riscv: Add G-stage binary stats test Bingyu.Xian
2026-12-04 14:11 ` 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=sashiko-outbox-249935@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shanbeeyoo@gmail.com \
/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