The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: David Carlier <devnexen@gmail.com>
Cc: syzbot+fd95a72470f5a44e464c@syzkaller.appspotmail.com,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	Lu Baolu <baolu.lu@linux.intel.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm: pgtable: protect lockless kernel page table walks with RCU
Date: Fri, 12 Jun 2026 09:12:15 -0700	[thread overview]
Message-ID: <20260612091215.b06dc7dc9dc894a5bfc75429@linux-foundation.org> (raw)
In-Reply-To: <20260612050540.31594-1-devnexen@gmail.com>

On Fri, 12 Jun 2026 06:05:40 +0100 David Carlier <devnexen@gmail.com> wrote:

> ptdump walks the kernel page tables locklessly through
> walk_kernel_page_table_range_lockless().  It only holds the init_mm
> mmap lock and the memory hotplug lock, and neither excludes
> vmalloc/ioremap teardown from freeing kernel PTE pages via
> pmd_free_pte_page() -> pagetable_free_kernel().  syzbot hit a
> use-after-free in ptdump_pte_entry() reading a PTE page that was freed
> underneath the walk.
> 
> Deferring the kernel page table free only batches the TLB flush; it does
> not wait for lockless walkers.  Mirror the user page table walk, where
> pte_offset_map() already takes the RCU read lock: hold rcu_read_lock()
> across the lockless kernel walk and rcu-free the page tables in the
> kernel page table free worker, after the batched TLB flush.  A walker
> then either observes the cleared PMD and skips the page, or keeps it
> alive until it drops the RCU read lock.
> 
> ...
>
> --- a/mm/pagewalk.c
> +++ b/mm/pagewalk.c
> @@ -655,13 +655,26 @@ int walk_kernel_page_table_range_lockless(unsigned long start, unsigned long end
>  		.private	= private,
>  		.no_vma		= true
>  	};
> +	int err;
>  
>  	if (start >= end)
>  		return -EINVAL;
>  	if (!check_ops_safe(ops))
>  		return -EINVAL;
>  
> -	return walk_pgd_range(start, end, &walk);
> +	/*
> +	 * Kernel intermediate page tables can be freed concurrently by
> +	 * vmalloc/ioremap teardown (e.g. pmd_free_pte_page()), which routes
> +	 * the freed pages through pagetable_free_kernel(). That path defers
> +	 * the free past an RCU grace period, so hold the RCU read lock across
> +	 * the lockless walk to prevent a page table from being freed while we
> +	 * are still dereferencing it.
> +	 */
> +	rcu_read_lock();
> +	err = walk_pgd_range(start, end, &walk);
> +	rcu_read_unlock();
> +
> +	return err;
>  }

Adding a lock to a function which is advertised to "walk the kernel
page tables locklessly" is a bit of a head-spinner.

Sashiko claims that some callback functions can perform sleeping
allocations:

	https://sashiko.dev/#/patchset/20260612050540.31594-1-devnexen@gmail.com



  reply	other threads:[~2026-06-12 16:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12  4:38 [PATCH] mm: pgtable: protect lockless kernel page table walks with RCU David Carlier
2026-06-12  4:52 ` Matthew Wilcox
2026-06-12  4:59   ` David CARLIER
2026-06-12  5:05   ` [PATCH v2] " David Carlier
2026-06-12 16:12     ` Andrew Morton [this message]
2026-06-12 17:21       ` David CARLIER
2026-06-12 17:23       ` [PATCH v3] " David Carlier
2026-06-12 17:39         ` Matthew Wilcox
2026-06-12 18:10           ` David CARLIER
2026-06-12 18:29         ` Lorenzo Stoakes
2026-06-12 18:48           ` David CARLIER

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=20260612091215.b06dc7dc9dc894a5bfc75429@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=baolu.lu@linux.intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=devnexen@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=rppt@kernel.org \
    --cc=surenb@google.com \
    --cc=syzbot+fd95a72470f5a44e464c@syzkaller.appspotmail.com \
    --cc=vbabka@kernel.org \
    /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