From: "Bingyu.Xian" <shanbeeyoo@gmail.com>
To: Anup Patel <anup@brainfault.org>,
Atish Patra <atish.patra@linux.dev>,
Paolo Bonzini <pbonzini@redhat.com>,
Sean Christopherson <seanjc@google.com>
Cc: Andrew Jones <andrew.jones@linux.dev>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Shuah Khan <shuah@kernel.org>,
Quan Zhou <zhouquan@iscas.ac.cn>,
"Bingyu . Xian" <shanbeeyoo@gmail.com>,
kvm-riscv@lists.infradead.org, kvm@vger.kernel.org,
linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 0/2] RISC-V: KVM: Expose G-stage page table and mapping stats
Date: Fri, 4 Dec 2026 21:26:49 +0800 [thread overview]
Message-ID: <20261204132651.413976-1-shanbeeyoo@gmail.com> (raw)
From: Bingyu Xian <shanbeeyoo@gmail.com>
This series exposes per-VM G-stage page table and leaf mapping page counts
through the KVM binary stats interface on RISC-V, together with a KVM
selftest validating the counters across mapping, write-protection, huge
page splitting, and memslot removal.
While commit a92e6041c5e5 ("RISC-V: KVM: Account G-stage page table
memory") accounts G-stage page table allocations globally and per cgroup
via NR_SECONDARY_PAGETABLE (SecPageTables), userspace VMMs still cannot
inspect per-VM G-stage page table consumption or leaf mapping sizes
through KVM_GET_STATS_FD because kvm_vm_stats_desc[] on RISC-V currently
exposes only KVM_GENERIC_VM_STATS().
Patch 1 adds per-VM instantaneous counters (pgtable_pages, pages_4k,
pages_2m, pages_1g on RV64; pgtable_pages, pages_4k, pages_4m on RV32) to
struct kvm_vm_stat and kvm_vm_stats_desc[]. All updates happen under
write_lock(&kvm->mmu_lock) (or during PGD initialization), skip local
G-stages marked with KVM_GSTAGE_FLAGS_LOCAL, and decrement pgtable_pages
synchronously when page tables are unlinked rather than inside RCU free
callbacks. Matching x86's pages_4k/pages_2m/pages_1g naming also prepares
RISC-V for selftests such as dirty_log_page_splitting_test.
Patch 2 adds tools/testing/selftests/kvm/riscv/gstage_stats_test.c, which
verifies root PGD accounting on empty VMs, 4K pre-faulting, repeated
faulting and dirty-log write-protection without counter drift, 2M THP
mapping and eager page splitting (2M -> 512 x 4K, pgtable_pages +1) when
backed by THP and kvm.eager_page_split is enabled, and memslot removal.
Validation:
- Rebased on riscv_kvm_next (ffdc855900a8).
- RV64 full kernel Image + arch/riscv/kvm/kvm.ko (W=1): 0 errors, 0 warnings.
- RV32 rv32_defconfig + CONFIG_KVM=m (W=1 on vm.o/gstage.o/mmu.o): 0 errors,
0 warnings.
- QEMU 10.0.2 (rv64,h=true,sstc=true) L1 KVM runtime test:
* kvm_binary_stats_test 2 2: 2/2 pass
* riscv/gstage_stats_test: 2/2 pass (4k_mapping_and_unmap and
2m_thp_and_dirty_log_split), 0 kernel warnings.
Thanks,
Bingyu
Bingyu.Xian (2):
RISC-V: KVM: Expose G-stage page table and mapping stats
KVM: selftests: riscv: Add G-stage binary stats test
arch/riscv/include/asm/kvm_host.h | 8 +
arch/riscv/kvm/gstage.c | 60 ++++++-
arch/riscv/kvm/mmu.c | 2 +
arch/riscv/kvm/vm.c | 10 +-
tools/testing/selftests/kvm/Makefile.kvm | 1 +
.../selftests/kvm/riscv/gstage_stats_test.c | 158 ++++++++++++++++++
6 files changed, 234 insertions(+), 5 deletions(-)
create mode 100644 tools/testing/selftests/kvm/riscv/gstage_stats_test.c
base-commit: ffdc855900a894034a63a46d699e0326dea3c991
--
2.34.1
next reply other threads:[~2026-12-04 13:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:26 Bingyu.Xian [this message]
2026-12-04 13:26 ` [PATCH 1/2] " Bingyu.Xian
2026-12-04 13:26 ` [PATCH 2/2] KVM: selftests: riscv: Add G-stage binary stats test Bingyu.Xian
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=20261204132651.413976-1-shanbeeyoo@gmail.com \
--to=shanbeeyoo@gmail.com \
--cc=alex@ghiti.fr \
--cc=andrew.jones@linux.dev \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=atish.patra@linux.dev \
--cc=kvm-riscv@lists.infradead.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=pbonzini@redhat.com \
--cc=pjw@kernel.org \
--cc=seanjc@google.com \
--cc=shuah@kernel.org \
--cc=zhouquan@iscas.ac.cn \
/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
all inboxes | Powered by JetHome®