From: sashiko-bot@kernel.org
To: "Jinyu Tang" <jinyu.tang@linux.dev>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v4 RESEND 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves
Date: Sat, 15 Aug 2026 10:46:55 +0000 [thread overview]
Message-ID: <20260815104656.21D091F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260815103245.864925-1-jinyu.tang@linux.dev>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch's fix for an infinite page fault livelock is incomplete. It fails to detect a split THP when the specific faulting GPA lacks a valid 4K leaf, leading to an incorrect PMD alignment and a continuing infinite loop.
--
--- Patch [2]: [PATCH v4 RESEND 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves ---
commit e6651e4debdd3eb4a9adeb5c1e519831130009d2
Author: Jinyu Tang <jinyu.tang@linux.dev>
KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves
This commit attempts to fix a page fault handling issue where
transparent_hugepage_adjust() rewrites the fault GPA to the PMD base,
causing the wrong 4K leaf to be updated. It checks if the original fault
GPA already has a 4K G-stage leaf, and if so, skips THP adjustment.
> 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 the fix remain incomplete when the
specific faulting GPA lacks a valid 4K leaf?
If the guest accesses a 4K page within a THP-backed region during dirty
logging, it gets faulted in. If another page in that same split PMD directory
remains unmapped when dirty logging is disabled, what happens when the guest
eventually faults on the unmapped offset?
In that scenario, kvm_riscv_gstage_get_leaf() for the unmapped GPA returns
false. This allows transparent_hugepage_adjust() to fall through and align the
GPA to the PMD base.
When kvm_riscv_gstage_map_page() is subsequently called with the PMD-aligned
GPA and PMD_SIZE, it finds the existing 4K leaf at the PMD base. Because the
PFNs match, it updates the protection of the base leaf and returns success,
without mapping the originally faulting GPA or replacing the split table.
Can this result in an infinite page fault loop since the faulted page is
never actually mapped?
>
> /*
> * Make sure the adjustment is done only for THP pages. Also make
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260815102833.864330-1-jinyu.tang@linux.dev?part=2
next prev parent reply other threads:[~2026-08-15 10:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 10:28 [PATCH v4 RESEND 0/5] KVM: riscv: Add KVM_PRE_FAULT_MEMORY support Jinyu Tang
2026-08-15 10:28 ` Jinyu Tang
2026-08-15 10:28 ` Jinyu Tang
2026-08-15 10:31 ` [PATCH v4 RESEND 1/5] KVM: riscv: Avoid overwriting G-stage tables with huge leaves Jinyu Tang
2026-08-15 10:31 ` Jinyu Tang
2026-08-15 10:32 ` [PATCH v4 RESEND 2/5] KVM: riscv: Avoid THP adjustment for existing 4K G-stage leaves Jinyu Tang
2026-08-15 10:32 ` Jinyu Tang
2026-08-15 10:46 ` sashiko-bot [this message]
2026-08-15 10:33 ` [PATCH v4 RESEND 3/5] KVM: riscv: Implement KVM_PRE_FAULT_MEMORY Jinyu Tang
2026-08-15 10:33 ` Jinyu Tang
2026-08-15 10:47 ` sashiko-bot
2026-08-15 10:34 ` [PATCH v4 RESEND 4/5] KVM: selftests: Add RISC-V Sv57 page table indexing Jinyu Tang
2026-08-15 10:34 ` Jinyu Tang
2026-08-15 10:34 ` [PATCH v4 RESEND 5/5] KVM: selftests: Enable pre_fault_memory_test for RISC-V Jinyu Tang
2026-08-15 10:34 ` Jinyu Tang
2026-08-15 10:34 ` 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=20260815104656.21D091F000E9@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.