From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>
Cc: kvm@vger.kernel.org, linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v2 13/15] riscv/mm: remove redundant TLB flush in napotpte_convert
Date: Thu, 16 Jul 2026 13:17:23 +0000 [thread overview]
Message-ID: <20260716131724.61A901F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <e55fb906990083b05272648f5299514a68cf8456.1784201104.git.cuiyunhui@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Removing the TLB flush in napotpte_convert() allows stale 4KB TLB entries to survive when folding base PTEs into a NAPOT block, leading to silent data corruption during partial-block TLB flushes.
--
--- Patch [13]: [PATCH v2 13/15] riscv/mm: remove redundant TLB flush in napotpte_convert ---
commit 63217ab7f83ce36005df21143bf66fc315027a26
Author: Yunhui Cui <cuiyunhui@bytedance.com>
riscv/mm: remove redundant TLB flush in napotpte_convert
This commit removes the TLB flush during the conversion between a NAPOT
block and its equivalent base PTEs in napotpte_convert(). The justification
is that since the effective translations (PFNs and permissions) are unchanged,
TLB invalidation can be deferred to operations that actually change the
effective mapping.
Link: https://lists.riscv.org/g/tech-privileged/message/2950
> diff --git a/arch/riscv/mm/contpte.c b/arch/riscv/mm/contpte.c
> index b0b8ff0aade3a..8289f39d6e188 100644
> --- a/arch/riscv/mm/contpte.c
> +++ b/arch/riscv/mm/contpte.c
[ ... ]
> @@ -149,8 +149,15 @@ static void napotpte_convert(struct mm_struct *mm, unsigned long addr,
> target = pte_mkyoung(target);
> }
>
> - flush_tlb_mm_range(mm, start_addr, end, PAGE_SIZE);
> -
[Severity: High]
Does removing this TLB flush allow stale 4KB TLB entries to survive when
folding base PTEs into a NAPOT block?
When set_ptes() maps a single page that completes a 16-page aligned block
backed by a large folio, __napotpte_try_fold() folds the 16 base PTEs into
a 64KB NAPOT block via napotpte_convert(). The CPU may have already cached
separate 4KB TLB entries for the existing 15 pages. Without the TLB flush
in napotpte_convert(), these 4KB TLB entries can survive the folding process.
Could this lead to silent data corruption during partial-block TLB flushes?
Later, if an operation like madvise(MADV_FREE) targets a single 4KB subpage
of this NAPOT block, it calls split_folio(), which splits the underlying
folio but does not alter the NAPOT page table entries. On retry, the loop
processes the now order-0 folio with nr = 1 and calls
clear_young_dirty_ptes() with nr = 1.
Because the PTE still has the NAPOT bit set, napotpte_clear_young_dirty_ptes()
correctly expands the operation to clear the young and dirty bits for all 16
PTEs in the page table to maintain the NAPOT encoding invariant. However,
madvise_free_pte_range() then queues only a 1-page TLB flush:
tlb_remove_tlb_entries(tlb, pte, 1, addr);
If the TLB held a 64KB NAPOT entry, the single-page sfence.vma would
successfully invalidate the entire 64KB block. But because the old 4KB TLB
entries survived the folding, the flush only invalidates the single targeted
4KB entry, leaving the other 15 4KB TLB entries valid.
Since their dirty bits were cleared in the page table but they are still
cached as dirty in the TLB, subsequent writes to these 15 pages will not set
the hardware dirty bit in the page table. Will the kernel later view these
modified pages as clean and discard them without writeback during memory
reclaim, dropping dirty data?
> + /*
> + * This conversion only changes the representation of the same
> + * effective translations: NAPOT encoding <-> equivalent base PTEs.
> + * A flush here would not replace the TLB maintenance required by a
> + * later permission downgrade, because writable base-PTE translations
> + * could be refilled after this conversion and before that downgrade.
> + * Leave TLB invalidation to the operation that changes the effective
> + * mapping.
> + */
> page_table_check_ptes_set(mm, start_addr, start_ptep, target, nr);
> if (pte_napot(target)) {
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784201104.git.cuiyunhui@bytedance.com?part=13
next prev parent reply other threads:[~2026-07-16 13:17 UTC|newest]
Thread overview: 57+ 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 ` Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 01/15] riscv: introduce raw PTE helpers Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 ` Yunhui Cui
2026-07-16 12:41 ` 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:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 ` Yunhui Cui
2026-07-16 12:41 ` 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 12:41 ` Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 13:03 ` sashiko-bot
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 ` Yunhui Cui
2026-07-16 12:41 ` 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 ` Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` [PATCH v2 12/15] arm64: mm: avoid contpte " Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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 12:41 ` Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 13:17 ` sashiko-bot [this message]
2026-07-16 12:41 ` [PATCH v2 14/15] riscv/mm: optimize mprotect for Svnapot mappings Yunhui Cui
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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
2026-07-16 12:41 ` Yunhui Cui
2026-07-16 12:41 ` 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=20260716131724.61A901F00A3A@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 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.