Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>
Cc: linux-perf-users@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v2 09/15] riscv/mm: avoid Svnapot consistency checks in ptep_get()
Date: Thu, 16 Jul 2026 13:03:21 +0000	[thread overview]
Message-ID: <20260716130321.E8B9A1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <687dadf430c49a840e24976e37ba09f991bc3222.1784201104.git.cuiyunhui@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unbounded `goto retry` loop in `napotpte_ptep_get_lockless()` causes a hard lockup if it interrupts a thread on the same CPU that is concurrently modifying the NAPOT block.
--

--- Patch [9]: [PATCH v2 09/15] riscv/mm: avoid Svnapot consistency checks in ptep_get() ---
commit 6e778d5fb0d9c3254546937eeef1badca713e19a
Author: Yunhui Cui <cuiyunhui@bytedance.com>

riscv/mm: avoid Svnapot consistency checks in ptep_get()

This commit removes range consistency checks from the generic ptep_get() path,
leaving them only in napotpte_ptep_get_lockless(). It also adds comments
explaining the lockless retry behavior.

> diff --git a/arch/riscv/mm/contpte.c b/arch/riscv/mm/contpte.c
> index 70f9a0668b50c..0f66426b0ecfd 100644
> --- a/arch/riscv/mm/contpte.c
> +++ b/arch/riscv/mm/contpte.c
[ ... ]
> @@ -345,6 +346,12 @@ EXPORT_SYMBOL(napotpte_ptep_get);
>  
>  pte_t napotpte_ptep_get_lockless(pte_t *orig_ptep)
>  {
> +	/*
> +	 * ptep_get_lockless() must return a self-consistent PTE without the
> +	 * PTL. Recheck that the whole NAPOT range still describes the same
> +	 * mapping, ignoring A/D bits, and retry if a concurrent update tears
> +	 * the range while A/D state is being gathered.
> +	 */
>  	pte_t orig_pte, pte;
>  	pte_t *ptep;
>  	unsigned int i, nr;

[Severity: High]
Could the unbounded retry loop in napotpte_ptep_get_lockless() cause a hard
lockup regression if it interrupts a modifying thread on the same CPU?

If a thread modifying the NAPOT block is preempted by an NMI (such as a PMU
sampling interrupt) exactly in the middle of an update, and the NMI handler
calls ptep_get_lockless():

arch/riscv/mm/contpte.c:napotpte_ptep_get_lockless() {
    ...
retry:
	orig_pte = READ_ONCE(*orig_ptep);
	if (!pte_present_napot(orig_pte))
		return orig_pte;

	ptep = napot_align_ptep(orig_ptep);

	for (i = 0; i < nr; i++, ptep++) {
		pte = READ_ONCE(*ptep);

		if (!napotpte_is_consistent(pte, orig_pte))
			goto retry;
    ...
}

Will this partially updated block cause napotpte_is_consistent() to fail and
jump to retry?

Since the modifying thread is suspended on the same CPU, it would never be able
to resume and finish the update, resulting in an infinite spin loop.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784201104.git.cuiyunhui@bytedance.com?part=9

  reply	other threads:[~2026-07-16 13:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16 12:41 [PATCH v2 00/15] riscv: add Svnapot PTE folding support Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 01/15] riscv: introduce raw PTE helpers Yunhui Cui
2026-07-16 12:59   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 02/15] riscv: switch arch page-table users to " Yunhui Cui
2026-07-16 13:05   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 03/15] riscv/mm: implement Svnapot contpte read-side helpers Yunhui Cui
2026-07-16 12:59   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 04/15] riscv/mm: implement Svnapot contpte update helpers Yunhui Cui
2026-07-16 13:03   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 05/15] mm: extend pte batch and leaf-size helpers Yunhui Cui
2026-07-16 13:06   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 06/15] riscv: make pte_batch_hint() honor folio batch flags Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 07/15] riscv/mm: preserve Svnapot leaf-size semantics for page-table consumers Yunhui Cui
2026-07-16 12:57   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 08/15] riscv/mm: avoid redundant Svnapot A/D aggregation Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 09/15] riscv/mm: avoid Svnapot consistency checks in ptep_get() Yunhui Cui
2026-07-16 13:03   ` sashiko-bot [this message]
2026-07-16 12:41 ` [PATCH v2 10/15] mm/gup: add fast-GUP specific lockless PTE helpers Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 11/15] riscv: mm: avoid Svnapot A/D aggregation in fast-GUP Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 12/15] arm64: mm: avoid contpte " Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 13/15] riscv/mm: remove redundant TLB flush in napotpte_convert Yunhui Cui
2026-07-16 13:17   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 14/15] riscv/mm: optimize mprotect for Svnapot mappings Yunhui Cui
2026-07-16 13:07   ` sashiko-bot
2026-07-16 12:41 ` [PATCH v2 15/15] riscv: mm: Request large exec folios for Svnapot Yunhui Cui

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=20260716130321.E8B9A1F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=cuiyunhui@bytedance.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-perf-users@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox