From: sashiko-bot@kernel.org
To: "Jinyu Tang" <jinyu.tang@linux.dev>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves
Date: Sat, 15 Aug 2026 10:22:18 +0000 [thread overview]
Message-ID: <20260815102218.6FCC11F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260815100411.861526-1-jinyu.tang@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Incomplete bug fix allows an infinite page fault loop when handling THP-backed memory.
--
--- Patch [2]: [PATCH v4 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves ---
commit 6582fbd6641ea5762d156dac1847e91f07decbd7
Author: Jinyu Tang <jinyu.tang@linux.dev>
KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves
This commit updates transparent_hugepage_adjust() to check if the original
fault GPA already has a 4K G-stage leaf. If so, it skips THP adjustment and
handles the fault at PAGE_SIZE granularity.
> diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c
> index bfd6168ebe308..2fabcd4099919 100644
> --- a/arch/riscv/kvm/mmu.c
> +++ b/arch/riscv/kvm/mmu.c
[ ... ]
> @@ -500,10 +500,21 @@ static int get_hva_mapping_size(struct kvm *kvm,
>
> static unsigned long transparent_hugepage_adjust(struct kvm *kvm,
> struct kvm_memory_slot *memslot,
> + struct kvm_gstage *gstage,
> unsigned long hva,
> kvm_pfn_t *hfnp, gpa_t *gpa)
> {
> kvm_pfn_t hfn = *hfnp;
> + u32 ptep_level;
> + pte_t *ptep;
> +
> + /*
> + * Keep the existing split G-stage leaf and update the original
> + * faulting 4K page in the vCPU fault path.
> + */
> + if (kvm_riscv_gstage_get_leaf(gstage, *gpa, &ptep, &ptep_level) &&
> + !ptep_level)
> + return PAGE_SIZE;
[Severity: High]
This is a pre-existing issue, but does this fully prevent the infinite page
fault loop when handling THP-backed memory?
This check only validates the unaligned faulting GPA. If the faulting GPA is
unmapped, it proceeds to align the GPA to the PMD base. However, if the PMD
base itself already has a 4K leaf (e.g., from a prior access while dirty
logging was enabled), transparent_hugepage_adjust() will still return
PMD_SIZE.
When called with the aligned GPA (the PMD base), kvm_riscv_gstage_map_page()
will find the 4K leaf at the PMD base:
arch/riscv/kvm/gstage.c:kvm_riscv_gstage_map_page() {
...
} else if (ALIGN_DOWN(PFN_PHYS(pte_pfn(ptep_get(ptep))), page_size) == hpa) {
kvm_riscv_gstage_update_pte_prot(gstage, ptep_level, gpa, ptep, prot);
return 0;
}
...
}
It updates the protection bits of the PMD base leaf and returns success
without mapping the original faulting GPA. Could this leave the originally
faulting GPA unmapped, causing the vCPU to hang in an infinite page fault
loop?
>
> /*
> * Make sure the adjustment is done only for THP pages. Also make
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260815095548.860018-1-jinyu.tang@linux.dev?part=2
next prev parent reply other threads:[~2026-08-15 10:22 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 9:55 [PATCH v4 0/5] KVM: riscv: Add KVM_PRE_FAULT_MEMORY support Jinyu Tang
2026-08-15 10:00 ` [PATCH v4 1/5] KVM: riscv: Avoid overwriting G-stage tables with huge leaves Jinyu Tang
2026-08-15 10:00 ` Jinyu Tang
2026-08-15 10:04 ` [PATCH v4 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves Jinyu Tang
2026-08-15 10:22 ` sashiko-bot [this message]
2026-08-15 10:06 ` [PATCH v4 3/5] KVM: riscv: Implement KVM_PRE_FAULT_MEMORY Jinyu Tang
2026-08-15 10:06 ` Jinyu Tang
2026-08-15 10:21 ` sashiko-bot
2026-08-15 10:08 ` [PATCH v4 4/5] KVM: selftests: Add RISC-V Sv57 page table indexing Jinyu Tang
2026-08-15 10:08 ` Jinyu Tang
2026-08-15 10:08 ` [PATCH v4 5/5] KVM: selftests: Enable pre_fault_memory_test for RISC-V Jinyu Tang
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=20260815102218.6FCC11F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=jinyu.tang@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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.