linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Chris Mason <clm@meta.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Chris Mason <clm@meta.com>,
	Andrew Morton <akpm@linux-foundation.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Pedro Falcato" <pfalcato@suse.de>,
	David Hildenbrand <david@redhat.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	Michal Hocko <mhocko@suse.com>, Jann Horn <jannh@google.com>,
	<shikemeng@huaweicloud.com>, <kasong@tencent.com>,
	<nphamcs@gmail.com>, <bhe@redhat.com>, <baohua@kernel.org>,
	<chrisl@kernel.org>, Matthew Wilcox <willy@infradead.org>
Subject: Re: [PATCH v3 11/11] mm: Use unmap_desc struct for freeing page tables.
Date: Sat, 24 Jan 2026 10:45:51 -0800	[thread overview]
Message-ID: <20260124184555.3936797-1-clm@meta.com> (raw)
In-Reply-To: <20260121164946.2093480-12-Liam.Howlett@oracle.com>

On Wed, 21 Jan 2026 11:49:46 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:

> Pass through the unmap_desc to free_pgtables() because it almost has
> everything necessary and is already on the stack.
> 
> Updates testing code as necessary.
> 
> No functional changes intended.
>

Hi everyone,

I'm running some more aggressive prompts through linux-next and this one was
flagged.  Apologies in advance if it's way off:

> diff --git a/mm/memory.c b/mm/memory.c
> --- a/mm/memory.c
> +++ b/mm/memory.c

[ ... ]

> -void free_pgtables(struct mmu_gather *tlb, struct ma_state *mas,
> -		   struct vm_area_struct *vma, unsigned long pg_start,
> -		   unsigned long pg_end, unsigned long vma_end,
> -		   bool mm_wr_locked)
> +void free_pgtables(struct mmu_gather *tlb, struct unmap_desc *unmap)
>  {
>  	struct unlink_vma_file_batch vb;
> +	struct ma_state *mas = unmap->mas;
> +	struct vm_area_struct *vma = unmap->first;
>
>  	/*
>  	 * Note: USER_PGTABLES_CEILING may be passed as the value of pg_end and
> -	 * may be 0.  Underflow is expected in this case.  Otherwise the
> -	 * pagetable end is exclusive.
> -	 * vma_end is exclusive.
> -	 * The last vma address should never be larger than the pagetable end.
> +	 * may be 0.  The underflow here is fine and expected.
> +	 * The vma_end is exclusive, which is fine until we use the mas_ instead
> +	 * of the vma iterators.
> +	 * For freeing the page tables to make sense, the vma_end must be larger
> +	 * than the pg_end, so check that after the potential underflow.
                           ^^^^

The old comment said "should never be larger" but the new comment says
"must be larger".  The WARN_ON_ONCE fires when vma_end > pg_end, so
"must be larger" appears backwards?

> +	 */
> +	WARN_ON_ONCE(unmap->vma_end - 1 > unmap->pg_end - 1);
                     ^^^^

On the exit_mmap() path, unmap_all_init() sets vma_end = ULONG_MAX while
pg_end = USER_PGTABLES_CEILING.  On ARM, USER_PGTABLES_CEILING is defined
as TASK_SIZE (around 3GB), not zero.

Before this change, exit_mmap() explicitly passed both vma_end and pg_end
as USER_PGTABLES_CEILING, so the WARN_ON_ONCE would never trigger.

After this change, exit_mmap() uses the unmap struct from unmap_all_init()
which sets vma_end = ULONG_MAX but pg_end = USER_PGTABLES_CEILING.
On ARM this means:

  WARN_ON_ONCE(ULONG_MAX - 1 > TASK_SIZE - 1)

This would fire on every process exit on ARM systems.  Is this intended?

> diff --git a/mm/mmap.c b/mm/mmap.c
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1307,10 +1307,10 @@ void exit_mmap(struct mm_struct *mm)
>  	 */
>  	mm_flags_set(MMF_OOM_SKIP, mm);
>  	mmap_write_lock(mm);
> +	unmap.mm_wr_locked = true;
>  	mt_clear_in_rcu(&mm->mm_mt);
> -	vma_iter_set(&vmi, vma->vm_end);
> -	free_pgtables(&tlb, &vmi.mas, vma, FIRST_USER_ADDRESS,
> -		      USER_PGTABLES_CEILING, USER_PGTABLES_CEILING, true);
> +	vma_iter_set(&vmi, unmap.tree_reset);
> +	free_pgtables(&tlb, &unmap);

The old call passed USER_PGTABLES_CEILING for both pg_end and vma_end.
The new code uses unmap_all_init() which sets pg_end = USER_PGTABLES_CEILING
but vma_end = ULONG_MAX.  This changes the semantics of the WARN_ON_ONCE
check in free_pgtables().



  reply	other threads:[~2026-01-24 18:51 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-21 16:49 [PATCH v3 00/11] Remove XA_ZERO from error recovery of dup_mmap() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 01/11] mm: Relocate the page table ceiling and floor definitions Liam R. Howlett
2026-01-21 17:26   ` SeongJae Park
2026-01-21 18:52     ` Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 02/11] mm/mmap: Move exit_mmap() trace point Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 03/11] mm/mmap: Abstract vma clean up from exit_mmap() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 04/11] mm/vma: Add limits to unmap_region() for vmas Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 05/11] mm/memory: Add tree limit to free_pgtables() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 06/11] mm/vma: Add page table limit to unmap_region() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 07/11] mm: Change dup_mmap() recovery Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 08/11] mm: Introduce unmap_desc struct to reduce function arguments Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 09/11] mm/vma: Use unmap_desc in exit_mmap() and vms_clear_ptes() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 10/11] mm/vma: Use unmap_region() in vms_clear_ptes() Liam R. Howlett
2026-01-21 16:49 ` [PATCH v3 11/11] mm: Use unmap_desc struct for freeing page tables Liam R. Howlett
2026-01-24 18:45   ` Chris Mason [this message]
2026-02-07 12:37     ` Liam R. Howlett
2026-02-10 20:41       ` Liam R. Howlett
2026-02-10 21:42   ` [PATCH] mm: Fix up unmap desc use on exit_mmap() Liam R. Howlett
2026-01-21 18:59 ` [PATCH v3 00/11] Remove XA_ZERO from error recovery of dup_mmap() Andrew Morton
2026-01-21 19:34   ` Liam R. Howlett

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=20260124184555.3936797-1-clm@meta.com \
    --to=clm@meta.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=bhe@redhat.com \
    --cc=chrisl@kernel.org \
    --cc=david@redhat.com \
    --cc=jannh@google.com \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=nphamcs@gmail.com \
    --cc=pfalcato@suse.de \
    --cc=shikemeng@huaweicloud.com \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.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