All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: Bingyu.Xian <shanbeeyoo@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] RISC-V: KVM: Expose G-stage page table and mapping stats
Date: Fri, 04 Dec 2026 13:57:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-249915@kernel.org> (raw)
In-Reply-To: <20261204132651.413976-2-shanbeeyoo@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] KVM: riscv: stats drift on non-leaf overwrite in
  kvm_riscv_gstage_set_pte()
--

commit 2228a1399f45a06009b2d81ae199437ca73d3a36
Author: Bingyu.Xian <shanbeeyoo@gmail.com>

RISC-V: KVM: Expose G-stage page table and mapping stats

This commit adds per-VM G-stage page table and leaf mapping counters
(pgtable_pages, pages_4k, pages_2m, pages_1g on RV64; pages_4m on RV32)
to struct kvm_vm_stat and exposes them via kvm_vm_stats_desc[].

> diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c
> index 241f4c19ca181..dc311b77a0cc4 100644
> --- a/arch/riscv/kvm/gstage.c
> +++ b/arch/riscv/kvm/gstage.c

[ ... ]

> @@ -194,10 +231,18 @@ int kvm_riscv_gstage_set_pte(struct kvm_gstage *gstage,
>  		ptep = &next_ptep[gstage_pte_index(gstage, map->addr, current_level)];
>  	}
>  
> -	if (pte_val(*ptep) != pte_val(map->pte)) {
> -		bool was_invalid = !pte_val(*ptep);
> +	old_pte = ptep_get(ptep);
> +	if (pte_val(old_pte) != pte_val(map->pte)) {
> +		bool was_invalid = !pte_val(old_pte);
> +		bool was_leaf = gstage_pte_leaf(old_pte);
> +		bool is_leaf = gstage_pte_leaf(map->pte);
> +
>  		set_pte(ptep, map->pte);
> -		if (gstage_pte_leaf(map->pte) &&
> +		if (!was_leaf && is_leaf)
> +			gstage_update_leaf_stats(gstage, current_level, 1);
> +		else if (was_leaf && !is_leaf)
> +			gstage_update_leaf_stats(gstage, current_level, -1);

[Severity: Medium]
Can overwriting a non-leaf _PAGE_TABLE entry with a huge leaf PTE here cause
pgtable_pages and lower-level leaf counts to drift permanently?

When map->level > 0, !was_leaf holds for both an empty PTE and a valid
_PAGE_TABLE entry.  Since kvm_riscv_gstage_unmap_range() leaves lower-level
tables linked, a later huge-page fault in kvm_riscv_gstage_map_page() can
call kvm_riscv_gstage_set_pte() and overwrite the _PAGE_TABLE entry directly.

Because the overwritten subtree is not unaccounted, pgtable_pages and any
remaining child leaf counts stay inflated even after G-stage teardown.
Clearing a non-leaf old_pte via kvm_riscv_gstage_op_pte(..., GSTAGE_OP_CLEAR)
before installing the new leaf would keep the stats accurate.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204132651.413976-1-shanbeeyoo@gmail.com?part=1

  reply	other threads:[~2026-12-04 13:57 UTC|newest]

Thread overview: 11+ 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 ` Bingyu.Xian
2026-12-04 13:26 ` Bingyu.Xian
2026-12-04 13:26 ` [PATCH 1/2] " Bingyu.Xian
2026-12-04 13:26   ` Bingyu.Xian
2026-12-04 13:26   ` Bingyu.Xian
2026-12-04 13:57   ` sashiko-bot [this message]
2026-12-04 13:26 ` [PATCH 2/2] KVM: selftests: riscv: Add G-stage binary stats test Bingyu.Xian
2026-12-04 13:26   ` Bingyu.Xian
2026-12-04 13:26   ` Bingyu.Xian
2026-12-04 14:11   ` 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=sashiko-outbox-249915@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 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.