All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: "Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH 11/12] mm: make userland page table freeing RCU-safe
Date: Tue, 01 Sep 2026 11:52:16 +0000	[thread overview]
Message-ID: <20260901115217.73B4D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901-rcu-pagetable-freeing-v1-11-5456a81c8212@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] try_collapse_pte_mapped_thp accesses page tables under mmap_read_lock without excluding per-VMA locks, allowing concurrent MADV_DONTNEED to clear PMDs, leading to a UAF/Panic.
- [High] Page walk callbacks return ACTION_AGAIN infinitely when encountering migration entries.
--

commit 2921a41442d23274b78e2a0ab1dcfe01ec2fff5f
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>
mm: make userland page table freeing RCU-safe

This commit removes the configuration option for RCU table freeing, as all
architectures now support it, and cleans up dead code. It establishes a
kernel policy that all page tables are freed after an RCU grace period,
ensuring safe unconditional page table walks under RCU.

> With this change in place the kernel policy is now that all page tables are
> freed after an RCU grace period, and thus it is now safe to unconditionally
> perform page table walks under RCU, safe in the knowledge that page tables
> will not be freed underneath the walker.
> 
> This is all that is guaranteed, however, so naturally it is still incumbent
> upon page table walkers to ensure that the page table entries are as
> expected.

[Severity: High]
This is a pre-existing issue, but will these page walk callbacks spin
forever if they encounter a migration entry?

For example, in fs/proc/task_mmu.c:clear_refs_pte_range():

	pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
	if (!pte) {
		walk->action = ACTION_AGAIN;
		return 0;
	}

Since pte_offset_map_lock() returns NULL non-transiently for migration
entries, walk_pmd_range() handles ACTION_AGAIN by looping back to again:
immediately without a scheduling point. Could an unprivileged user
triggering THP migration concurrently with a /proc/pid/clear_refs read
cause a CPU soft lockup here?

The same pattern appears to exist in smaps_pte_range() in the same file,
and queue_folios_pte_range() in mm/mempolicy.c.

[Severity: Critical]
This is a pre-existing issue, but does try_collapse_pte_mapped_thp() in
mm/khugepaged.c properly exclude per-VMA locks to prevent concurrent
MADV_DONTNEED from clearing PMDs?

When checking the page tables under mmap_read_lock(), the pmd_same() check
is nested inside the if (ptl != pml) block:

mm/khugepaged.c:try_collapse_pte_mapped_thp() {
	...
	/* step 4: remove empty page table */
	if (!pml) {
		pml = pmd_lock(mm, pmd);
		if (ptl != pml) {
			spin_lock_nested(ptl, SINGLE_DEPTH_NESTING);
			if (unlikely(!pmd_same(pgt_pmd, pmdp_get_lockless(pmd)))) {
				flush_tlb_mm(mm);
				goto unlock;
			}
		}
	}
	...
}

If the system has ptl == pml, this bypasses the pmd_same() check entirely.
A concurrent MADV_DONTNEED running under the VMA lock could trigger
PT_RECLAIM and clear the PMD, freeing the PTE page.

Later in the same function:

mm/khugepaged.c:try_collapse_pte_mapped_thp() {
	...
	pgt_pmd = pmdp_collapse_flush(vma, haddr, pmd);
	pmdp_get_lockless_sync();
	pte_unmap_unlock(start_pte, ptl);
	if (ptl != pml)
		spin_unlock(pml);

	mmu_notifier_invalidate_range_end(&range);

	mm_dec_nr_ptes(mm);
	page_table_check_pte_clear_range(mm, haddr, pgt_pmd);
	pte_free_defer(mm, pmd_pgtable(pgt_pmd));
	...
}

Does this result in pmdp_collapse_flush() being called on a cleared PMD,
passing a garbage PFN to pte_free_defer() and potentially causing a kernel
panic?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901-rcu-pagetable-freeing-v1-0-5456a81c8212@kernel.org?part=11

  reply	other threads:[~2026-09-01 11:52 UTC|newest]

Thread overview: 117+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01 11:01 [PATCH 00/12] mm: make userland page table freeing RCU-safe Lorenzo Stoakes (ARM)
2026-09-01 11:01 ` Lorenzo Stoakes (ARM)
2026-09-01 11:01 ` Lorenzo Stoakes (ARM)
2026-09-01 11:01 ` [PATCH 01/12] mm/huge_memory: zap deposited page tables after an RCU grace period Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:18   ` sashiko-bot
2026-09-01 13:19   ` Kiryl Shutsemau
2026-09-01 13:19     ` Kiryl Shutsemau
2026-09-01 13:19     ` Kiryl Shutsemau
2026-09-01 14:12     ` Lorenzo Stoakes (ARM)
2026-09-01 14:12       ` Lorenzo Stoakes (ARM)
2026-09-01 14:12       ` Lorenzo Stoakes (ARM)
2026-09-01 14:24       ` Jason Gunthorpe
2026-09-01 14:24         ` Jason Gunthorpe
2026-09-01 14:24         ` Jason Gunthorpe
2026-09-01 14:41         ` Lorenzo Stoakes (ARM)
2026-09-01 14:41           ` Lorenzo Stoakes (ARM)
2026-09-01 14:41           ` Lorenzo Stoakes (ARM)
2026-09-01 15:28           ` Kiryl Shutsemau
2026-09-01 15:28             ` Kiryl Shutsemau
2026-09-01 15:28             ` Kiryl Shutsemau
2026-09-01 15:45             ` Lorenzo Stoakes (ARM)
2026-09-01 15:45               ` Lorenzo Stoakes (ARM)
2026-09-01 15:45               ` Lorenzo Stoakes (ARM)
2026-09-01 17:11               ` Kiryl Shutsemau
2026-09-01 17:11                 ` Kiryl Shutsemau
2026-09-01 17:11                 ` Kiryl Shutsemau
2026-09-01 17:14                 ` Lorenzo Stoakes (ARM)
2026-09-01 17:14                   ` Lorenzo Stoakes (ARM)
2026-09-01 17:14                   ` Lorenzo Stoakes (ARM)
2026-09-01 15:54             ` Liam R. Howlett
2026-09-01 15:54               ` Liam R. Howlett
2026-09-01 15:54               ` Liam R. Howlett
2026-09-01 16:06               ` Jason Gunthorpe
2026-09-01 16:06                 ` Jason Gunthorpe
2026-09-01 16:06                 ` Jason Gunthorpe
2026-09-01 17:13               ` Kiryl Shutsemau
2026-09-01 17:13                 ` Kiryl Shutsemau
2026-09-01 17:13                 ` Kiryl Shutsemau
2026-09-01 17:47                 ` Liam R. Howlett
2026-09-01 17:47                   ` Liam R. Howlett
2026-09-01 17:47                   ` Liam R. Howlett
2026-09-01 11:01 ` [PATCH 02/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for most 2-level architectures Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:22   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 03/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for MMU riscv Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:14   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 04/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for MMU arm Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:18   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 05/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for arc, microblaze, xtensa Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:28   ` sashiko-bot
2026-09-07 21:07   ` Suren Baghdasaryan
2026-09-07 21:07     ` Suren Baghdasaryan
2026-09-07 21:07     ` Suren Baghdasaryan
2026-09-08 11:28     ` Lorenzo Stoakes (ARM)
2026-09-08 11:28       ` Lorenzo Stoakes (ARM)
2026-09-08 11:28       ` Lorenzo Stoakes (ARM)
2026-09-01 11:01 ` [PATCH 06/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc64 Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:23   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 07/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for m68k-coldfire Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:23   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 08/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sh-X2 Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:30   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 09/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for m68k-motorola Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:30   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 10/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc32 Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:37   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 11/12] mm: make userland page table freeing RCU-safe Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:52   ` sashiko-bot [this message]
2026-09-01 13:33   ` Kiryl Shutsemau
2026-09-01 13:33     ` Kiryl Shutsemau
2026-09-01 13:33     ` Kiryl Shutsemau
2026-09-01 14:03     ` Lorenzo Stoakes (ARM)
2026-09-01 14:03       ` Lorenzo Stoakes (ARM)
2026-09-01 14:03       ` Lorenzo Stoakes (ARM)
2026-09-01 11:01 ` [PATCH 12/12] mm: change the contract for free_pgtables(), update docs Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:01   ` Lorenzo Stoakes (ARM)
2026-09-01 11:37   ` sashiko-bot
2026-09-01 13:57   ` Kiryl Shutsemau
2026-09-01 13:57     ` Kiryl Shutsemau
2026-09-01 13:57     ` Kiryl Shutsemau
2026-09-01 14:31     ` Lorenzo Stoakes (ARM)
2026-09-01 14:31       ` Lorenzo Stoakes (ARM)
2026-09-01 14:31       ` Lorenzo Stoakes (ARM)
2026-09-01 17:15       ` Kiryl Shutsemau
2026-09-01 17:15         ` Kiryl Shutsemau
2026-09-01 17:15         ` Kiryl Shutsemau
2026-09-01 17:25         ` Lorenzo Stoakes (ARM)
2026-09-01 17:25           ` Lorenzo Stoakes (ARM)
2026-09-01 17:25           ` Lorenzo Stoakes (ARM)
2026-09-07 16:53           ` Suren Baghdasaryan
2026-09-07 16:53             ` Suren Baghdasaryan
2026-09-07 16:53             ` Suren Baghdasaryan
2026-09-08 11:29             ` Lorenzo Stoakes (ARM)
2026-09-08 11:29               ` Lorenzo Stoakes (ARM)
2026-09-08 11:29               ` Lorenzo Stoakes (ARM)

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=20260901115217.73B4D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=ljs@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.