Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wang Yechao" <wang.yechao255@zte.com.cn>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v5 4/5] RISC-V: KVM: Split huge pages during KVM_CLEAR_DIRTY_LOG
Date: Fri, 31 Jul 2026 09:38:12 +0000	[thread overview]
Message-ID: <20260731093812.9B3911F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260731091215.1549430-5-wang.yechao255@zte.com.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Dropping `mmu_lock` inside `mmu_split_huge_pages` before flushing the TLB for write-protected pages breaks caller atomicity and allows untracked guest writes.
- [Medium] Splitting huge pages after write-protecting them causes all resulting 4KB pages to inherit read-only permissions, unintentionally write-protecting memory outside the requested mask.
--

--- Patch [4]: [PATCH v5 4/5] RISC-V: KVM: Split huge pages during KVM_CLEAR_DIRTY_LOG ---
commit 7f655ea60f5c58e768006af9329d81bc92d97d34
Author: Wang Yechao <wang.yechao255@zte.com.cn>

RISC-V: KVM: Split huge pages during KVM_CLEAR_DIRTY_LOG

Split huge pages on the range specified using KVM_CLEAR_DIRTY_LOG.
And do not split when enabling dirty logging if KVM_DIRTY_LOG_INITIALLY_SET
is set.

> diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
> index 5a93cffa9ad7f..722637a85bdf9 100644
> --- a/arch/riscv/kvm/mmu.c
> +++ b/arch/riscv/kvm/mmu.c
> @@ -168,6 +168,9 @@ void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm,
>  
>  	kvm_riscv_gstage_wp_range(&gstage, start, end);
>  
> +	if (kvm_dirty_log_manual_protect_and_init_set(kvm))
> +		mmu_split_huge_pages(&gstage, start, end);

[Severity: Medium]
Since mmu_split_huge_pages() is called after kvm_riscv_gstage_wp_range(),
won't the newly split 4KB child PTEs inherit the read-only permission from
the huge PTE?

If KVM_CLEAR_DIRTY_LOG targets only a subset of pages in a 2MB huge page,
this would unintentionally write-protect memory outside the requested mask
and cause spurious page faults.

Could this be resolved by performing the split before write-protecting?

[Severity: High]
Does dropping the mmu_lock inside mmu_split_huge_pages() before the TLB is
flushed break caller atomicity and allow untracked guest writes?

Looking at arch/riscv/kvm/mmu.c:mmu_split_huge_pages():

	while (addr < end) {
		if (need_topup_split_caches_or_resched(kvm, count)) {
			...
			write_unlock(&kvm->mmu_lock);
			cond_resched();

If kvm_riscv_gstage_wp_range() write-protects the PTE, and then
mmu_split_huge_pages() drops kvm->mmu_lock, the hardware TLB is still
writable because the caller hasn't flushed the TLB yet.

Can concurrent guest writes succeed without a VM-exit during this window,
bypassing the cleared software dirty bitmap and violating the dirty logging
contract?

> +
>  	/*
>  	 * remote TLB flush is not needed here since callers of
>  	 * kvm_arch_mmu_enable_log_dirty_pt_masked() already do it.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731091215.1549430-1-wang.yechao255@zte.com.cn?part=4

  reply	other threads:[~2026-07-31  9:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31  9:12 [PATCH v5 0/5] Implement Eager Page Splitting for RISC-V Wang Yechao
2026-07-31  9:12 ` [PATCH v5 1/5] RISC-V: KVM: Add the split page cache for ioctl context Wang Yechao
2026-07-31  9:40   ` sashiko-bot
2026-07-31  9:12 ` [PATCH v5 2/5] RISC-V: KVM: Split huge pages when dirty logging is enabled Wang Yechao
2026-07-31  9:29   ` sashiko-bot
2026-07-31  9:12 ` [PATCH v5 3/5] RISC-V: KVM: Remove redundant TLB flush operations Wang Yechao
2026-07-31  9:39   ` sashiko-bot
2026-07-31  9:12 ` [PATCH v5 4/5] RISC-V: KVM: Split huge pages during KVM_CLEAR_DIRTY_LOG Wang Yechao
2026-07-31  9:38   ` sashiko-bot [this message]
2026-07-31  9:12 ` [PATCH v5 5/5] RISC-V: KVM: Add the eager_page_split module parameter Wang Yechao

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=20260731093812.9B3911F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wang.yechao255@zte.com.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