The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
@ 2026-07-21 13:46 Mark Brown
  2026-07-21 16:14 ` Lorenzo Stoakes (ARM)
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2026-07-21 13:46 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra
  Cc: Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Lorenzo Stoakes, Mike Rapoport

[-- Attachment #1: Type: text/plain, Size: 2487 bytes --]

Hi all,

Today's linux-next merge of the tip tree got a conflict in:

  arch/x86/mm/pat/set_memory.c

between commit:

  b8228ddfd0586 ("x86/mm/pat: allocate split page tables as kernel page tables")

from the mm-hotfixes-unstable tree and commit:

  5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")

from the tip tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --cc arch/x86/mm/pat/set_memory.c
index a67ca33b9dd12,1f2a2ba9ce57d..0000000000000
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@@ -439,26 -441,12 +442,28 @@@ static void __cpa_collapse_large_pages(
  
  	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
  		list_del(&ptdesc->pt_list);
 -		pagetable_free(ptdesc);
 +
 +		if (folio_test_pgtable(ptdesc_folio(ptdesc)))
 +			pagetable_dtor_free(ptdesc);
 +		else
 +			pagetable_free(ptdesc);
  	}
+ 
+ 	spin_unlock(&cpa_lock);
  }
  
 +static void cpa_collapse_large_pages(struct cpa_data *cpa)
 +{
 +	/*
 +	 * Take the mmap write lock on init_mm to:
 +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
 +	 *   write lock on init_mm).
 +	 * - Serialise concurrent CPA walkers.
 +	 */
 +	scoped_guard(mmap_write_lock, &init_mm)
 +		__cpa_collapse_large_pages(cpa);
 +}
 +
  static void cpa_flush(struct cpa_data *cpa, int cache)
  {
  	unsigned int i;
@@@ -1249,18 -1237,16 +1253,16 @@@ __split_large_page(struct cpa_data *cpa
  static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
  			    unsigned long address)
  {
 -	struct ptdesc *ptdesc;
 +	pte_t *pte;
  
- 	if (!debug_pagealloc_enabled())
- 		spin_unlock(&cpa_lock);
+ 	spin_unlock(&cpa_lock);
 -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
 +	pte = pte_alloc_one_kernel(&init_mm);
- 	if (!debug_pagealloc_enabled())
- 		spin_lock(&cpa_lock);
+ 	spin_lock(&cpa_lock);
 -	if (!ptdesc)
 +	if (!pte)
  		return -ENOMEM;
  
 -	if (__split_large_page(cpa, kpte, address, ptdesc))
 -		pagetable_free(ptdesc);
 +	if (__split_large_page(cpa, kpte, address, pte))
 +		pte_free_kernel(&init_mm, pte);
  
  	return 0;
  }

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-21 13:46 Mark Brown
@ 2026-07-21 16:14 ` Lorenzo Stoakes (ARM)
  0 siblings, 0 replies; 9+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-07-21 16:14 UTC (permalink / raw)
  To: Mark Brown
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra,
	Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Mike Rapoport

On Tue, Jul 21, 2026 at 02:46:23PM +0100, Mark Brown wrote:
> Hi all,
>
> Today's linux-next merge of the tip tree got a conflict in:
>
>   arch/x86/mm/pat/set_memory.c
>
> between commit:
>
>   b8228ddfd0586 ("x86/mm/pat: allocate split page tables as kernel page tables")
>
> from the mm-hotfixes-unstable tree and commit:
>
>   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
>
> from the tip tree.
>
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.

Thanks, the resolution looks correct! :)

There's some discussion on the patches themselves but that's by-the-by.

Cheers, Lorenzo

>
> diff --cc arch/x86/mm/pat/set_memory.c
> index a67ca33b9dd12,1f2a2ba9ce57d..0000000000000
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@@ -439,26 -441,12 +442,28 @@@ static void __cpa_collapse_large_pages(
>
>   	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
>   		list_del(&ptdesc->pt_list);
>  -		pagetable_free(ptdesc);
>  +
>  +		if (folio_test_pgtable(ptdesc_folio(ptdesc)))
>  +			pagetable_dtor_free(ptdesc);
>  +		else
>  +			pagetable_free(ptdesc);
>   	}
> +
> + 	spin_unlock(&cpa_lock);
>   }
>
>  +static void cpa_collapse_large_pages(struct cpa_data *cpa)
>  +{
>  +	/*
>  +	 * Take the mmap write lock on init_mm to:
>  +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
>  +	 *   write lock on init_mm).
>  +	 * - Serialise concurrent CPA walkers.
>  +	 */
>  +	scoped_guard(mmap_write_lock, &init_mm)
>  +		__cpa_collapse_large_pages(cpa);
>  +}
>  +
>   static void cpa_flush(struct cpa_data *cpa, int cache)
>   {
>   	unsigned int i;
> @@@ -1249,18 -1237,16 +1253,16 @@@ __split_large_page(struct cpa_data *cpa
>   static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
>   			    unsigned long address)
>   {
>  -	struct ptdesc *ptdesc;
>  +	pte_t *pte;
>
> - 	if (!debug_pagealloc_enabled())
> - 		spin_unlock(&cpa_lock);
> + 	spin_unlock(&cpa_lock);
>  -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
>  +	pte = pte_alloc_one_kernel(&init_mm);
> - 	if (!debug_pagealloc_enabled())
> - 		spin_lock(&cpa_lock);
> + 	spin_lock(&cpa_lock);
>  -	if (!ptdesc)
>  +	if (!pte)
>   		return -ENOMEM;
>
>  -	if (__split_large_page(cpa, kpte, address, ptdesc))
>  -		pagetable_free(ptdesc);
>  +	if (__split_large_page(cpa, kpte, address, pte))
>  +		pte_free_kernel(&init_mm, pte);
>
>   	return 0;
>   }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
@ 2026-07-26 21:33 Mark Brown
  2026-07-27  5:48 ` Mike Rapoport
  0 siblings, 1 reply; 9+ messages in thread
From: Mark Brown @ 2026-07-26 21:33 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra
  Cc: Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Lorenzo Stoakes, Mike Rapoport

[-- Attachment #1: Type: text/plain, Size: 2907 bytes --]

Hi all,

Today's linux-next merge of the tip tree got a conflict in:

  arch/x86/mm/pat/set_memory.c

between commits:

  7a7c16a2d2b4d ("x86/mm/pat: acquire init_mm read lock on attribute change to avoid UAF")
  25a54f65ccbaf ("x86/mm/pat: allocate split page tables as kernel page tables")

from the mm-hotfixes-unstable tree and commit:

  5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")

from the tip tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --cc arch/x86/mm/pat/set_memory.c
index 422ce7fba00c6,1f2a2ba9ce57d..0000000000000
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@@ -440,30 -441,12 +443,32 @@@ static void __cpa_collapse_large_pages(
  
  	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
  		list_del(&ptdesc->pt_list);
 -		pagetable_free(ptdesc);
 +		/*
 +		 * Only early alloc'd direct map should not be flagged PG_table
 +		 * here and those shouldn't be collapsed. However be abundantly
 +		 * cautious and handle the !PG_table case too.
 +		 */
 +		if (PageTable((ptdesc_page(ptdesc))))
 +			pagetable_dtor_free(ptdesc);
 +		else
 +			pagetable_free(ptdesc);
  	}
+ 
+ 	spin_unlock(&cpa_lock);
  }
  
 +static void cpa_collapse_large_pages(struct cpa_data *cpa)
 +{
 +	/*
 +	 * Take the mmap write lock on init_mm to:
 +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
 +	 *   write lock on init_mm).
 +	 * - Serialise concurrent CPA walkers.
 +	 */
 +	scoped_guard(mmap_write_lock, &init_mm)
 +		__cpa_collapse_large_pages(cpa);
 +}
 +
  static void cpa_flush(struct cpa_data *cpa, int cache)
  {
  	unsigned int i;
@@@ -1254,22 -1237,16 +1258,20 @@@ __split_large_page(struct cpa_data *cpa
  static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
  			    unsigned long address)
  {
 -	struct ptdesc *ptdesc;
 +	pte_t *pte;
  
- 	if (!debug_pagealloc_enabled())
- 		spin_unlock(&cpa_lock);
+ 	spin_unlock(&cpa_lock);
 -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
 +	if (cpa->init_mm_read_locked)
 +		mmap_read_unlock(&init_mm);
 +	pte = pte_alloc_one_kernel(&init_mm);
 +	if (cpa->init_mm_read_locked)
 +		mmap_read_lock(&init_mm);
- 	if (!debug_pagealloc_enabled())
- 		spin_lock(&cpa_lock);
+ 	spin_lock(&cpa_lock);
 -	if (!ptdesc)
 +	if (!pte)
  		return -ENOMEM;
  
 -	if (__split_large_page(cpa, kpte, address, ptdesc))
 -		pagetable_free(ptdesc);
 +	if (__split_large_page(cpa, kpte, address, pte))
 +		pte_free_kernel(&init_mm, pte);
  
  	return 0;
  }

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-26 21:33 linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree Mark Brown
@ 2026-07-27  5:48 ` Mike Rapoport
  2026-07-27 11:33   ` Lorenzo Stoakes (ARM)
  2026-07-27 11:38   ` Mark Brown
  0 siblings, 2 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-07-27  5:48 UTC (permalink / raw)
  To: Mark Brown
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra,
	Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Lorenzo Stoakes

Hi Mark,

On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:
> Hi all,
> 
> Today's linux-next merge of the tip tree got a conflict in:
> 
>   arch/x86/mm/pat/set_memory.c
> 
> between commits:
> 
>   7a7c16a2d2b4d ("x86/mm/pat: acquire init_mm read lock on attribute change to avoid UAF")
>   25a54f65ccbaf ("x86/mm/pat: allocate split page tables as kernel page tables")
> 
> from the mm-hotfixes-unstable tree and commit:
> 
>   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
> 
> from the tip tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
> 
> diff --cc arch/x86/mm/pat/set_memory.c
> index 422ce7fba00c6,1f2a2ba9ce57d..0000000000000
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@@ -440,30 -441,12 +443,32 @@@ static void __cpa_collapse_large_pages(
>   
>   	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
>   		list_del(&ptdesc->pt_list);
>  -		pagetable_free(ptdesc);
>  +		/*
>  +		 * Only early alloc'd direct map should not be flagged PG_table
>  +		 * here and those shouldn't be collapsed. However be abundantly
>  +		 * cautious and handle the !PG_table case too.
>  +		 */
>  +		if (PageTable((ptdesc_page(ptdesc))))
>  +			pagetable_dtor_free(ptdesc);
>  +		else
>  +			pagetable_free(ptdesc);
>   	}
> + 
> + 	spin_unlock(&cpa_lock);
>   }
>   
>  +static void cpa_collapse_large_pages(struct cpa_data *cpa)
>  +{
>  +	/*
>  +	 * Take the mmap write lock on init_mm to:
>  +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
>  +	 *   write lock on init_mm).
>  +	 * - Serialise concurrent CPA walkers.
>  +	 */
>  +	scoped_guard(mmap_write_lock, &init_mm)
>  +		__cpa_collapse_large_pages(cpa);
>  +}
>  +
>   static void cpa_flush(struct cpa_data *cpa, int cache)
>   {
>   	unsigned int i;
> @@@ -1254,22 -1237,16 +1258,20 @@@ __split_large_page(struct cpa_data *cpa
>   static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
>   			    unsigned long address)
>   {
>  -	struct ptdesc *ptdesc;
>  +	pte_t *pte;
>   
> - 	if (!debug_pagealloc_enabled())
> - 		spin_unlock(&cpa_lock);
> + 	spin_unlock(&cpa_lock);

This should be

 	if (!debug_pagealloc_enabled())
 		spin_unlock(&cpa_lock);

>  -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
>  +	if (cpa->init_mm_read_locked)
>  +		mmap_read_unlock(&init_mm);
>  +	pte = pte_alloc_one_kernel(&init_mm);
>  +	if (cpa->init_mm_read_locked)
>  +		mmap_read_lock(&init_mm);
> - 	if (!debug_pagealloc_enabled())
> - 		spin_lock(&cpa_lock);
> + 	spin_lock(&cpa_lock);

And this 

	if (!debug_pagealloc_enabled())
 		spin_lock(&cpa_lock);

>  -	if (!ptdesc)
>  +	if (!pte)
>   		return -ENOMEM;
>   
>  -	if (__split_large_page(cpa, kpte, address, ptdesc))
>  -		pagetable_free(ptdesc);
>  +	if (__split_large_page(cpa, kpte, address, pte))
>  +		pte_free_kernel(&init_mm, pte);
>   
>   	return 0;
>   }



-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-27  5:48 ` Mike Rapoport
@ 2026-07-27 11:33   ` Lorenzo Stoakes (ARM)
  2026-07-27 13:03     ` Mike Rapoport
  2026-07-27 11:38   ` Mark Brown
  1 sibling, 1 reply; 9+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-07-27 11:33 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Mark Brown, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Peter Zijlstra, Andrew Morton, Dave Hansen,
	Linux Kernel Mailing List, Linux Next Mailing List

On Mon, Jul 27, 2026 at 08:48:31AM +0300, Mike Rapoport wrote:
> Hi Mark,
>
> On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:
> > Hi all,
> >
> > Today's linux-next merge of the tip tree got a conflict in:
> >
> >   arch/x86/mm/pat/set_memory.c
> >
> > between commits:
> >
> >   7a7c16a2d2b4d ("x86/mm/pat: acquire init_mm read lock on attribute change to avoid UAF")
> >   25a54f65ccbaf ("x86/mm/pat: allocate split page tables as kernel page tables")
> >
> > from the mm-hotfixes-unstable tree and commit:
> >
> >   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
> >
> > from the tip tree.
> >
> > I fixed it up (see below) and can carry the fix as necessary. This
> > is now fixed as far as linux-next is concerned, but any non trivial
> > conflicts should be mentioned to your upstream maintainer when your tree
> > is submitted for merging.  You may also want to consider cooperating
> > with the maintainer of the conflicting tree to minimise any particularly
> > complex conflicts.
> >
> > diff --cc arch/x86/mm/pat/set_memory.c
> > index 422ce7fba00c6,1f2a2ba9ce57d..0000000000000
> > --- a/arch/x86/mm/pat/set_memory.c
> > +++ b/arch/x86/mm/pat/set_memory.c
> > @@@ -440,30 -441,12 +443,32 @@@ static void __cpa_collapse_large_pages(
> >
> >   	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
> >   		list_del(&ptdesc->pt_list);
> >  -		pagetable_free(ptdesc);
> >  +		/*
> >  +		 * Only early alloc'd direct map should not be flagged PG_table
> >  +		 * here and those shouldn't be collapsed. However be abundantly
> >  +		 * cautious and handle the !PG_table case too.
> >  +		 */
> >  +		if (PageTable((ptdesc_page(ptdesc))))
> >  +			pagetable_dtor_free(ptdesc);
> >  +		else
> >  +			pagetable_free(ptdesc);
> >   	}
> > +
> > + 	spin_unlock(&cpa_lock);
> >   }
> >
> >  +static void cpa_collapse_large_pages(struct cpa_data *cpa)
> >  +{
> >  +	/*
> >  +	 * Take the mmap write lock on init_mm to:
> >  +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
> >  +	 *   write lock on init_mm).
> >  +	 * - Serialise concurrent CPA walkers.
> >  +	 */
> >  +	scoped_guard(mmap_write_lock, &init_mm)
> >  +		__cpa_collapse_large_pages(cpa);
> >  +}
> >  +
> >   static void cpa_flush(struct cpa_data *cpa, int cache)
> >   {
> >   	unsigned int i;
> > @@@ -1254,22 -1237,16 +1258,20 @@@ __split_large_page(struct cpa_data *cpa
> >   static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
> >   			    unsigned long address)
> >   {
> >  -	struct ptdesc *ptdesc;
> >  +	pte_t *pte;
> >
> > - 	if (!debug_pagealloc_enabled())
> > - 		spin_unlock(&cpa_lock);
> > + 	spin_unlock(&cpa_lock);
>
> This should be
>
>  	if (!debug_pagealloc_enabled())
>  		spin_unlock(&cpa_lock);
>
> >  -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
> >  +	if (cpa->init_mm_read_locked)
> >  +		mmap_read_unlock(&init_mm);
> >  +	pte = pte_alloc_one_kernel(&init_mm);
> >  +	if (cpa->init_mm_read_locked)
> >  +		mmap_read_lock(&init_mm);
> > - 	if (!debug_pagealloc_enabled())
> > - 		spin_lock(&cpa_lock);
> > + 	spin_lock(&cpa_lock);
>
> And this
>
> 	if (!debug_pagealloc_enabled())
>  		spin_lock(&cpa_lock);
>
> >  -	if (!ptdesc)
> >  +	if (!pte)
> >   		return -ENOMEM;
> >
> >  -	if (__split_large_page(cpa, kpte, address, ptdesc))
> >  -		pagetable_free(ptdesc);
> >  +	if (__split_large_page(cpa, kpte, address, pte))
> >  +		pte_free_kernel(&init_mm, pte);
> >
> >   	return 0;
> >   }
>
>
>
> --
> Sincerely yours,
> Mike.

Hmm, what's the status of the x86/mm trees on this though? AFAICT Denis's
patch is still as-is and the spin_lock() vs. spin_[un]lock_irq*() issue
raised in [0] is unaddressed?

So is this fixup actually representative of what's going upstream?

Thanks, Lorenzo

[0]:https://lore.kernel.org/all/al-MrKyIafA8QR_8@lucifer/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-27  5:48 ` Mike Rapoport
  2026-07-27 11:33   ` Lorenzo Stoakes (ARM)
@ 2026-07-27 11:38   ` Mark Brown
  2026-07-27 13:09     ` Mike Rapoport
  1 sibling, 1 reply; 9+ messages in thread
From: Mark Brown @ 2026-07-27 11:38 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra,
	Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Lorenzo Stoakes

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

On Mon, Jul 27, 2026 at 08:48:31AM +0300, Mike Rapoport wrote:
> On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:

> > from the mm-hotfixes-unstable tree and commit:

> >   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")

> > from the tip tree.

> > - 	if (!debug_pagealloc_enabled())
> > - 		spin_unlock(&cpa_lock);
> > + 	spin_unlock(&cpa_lock);
> 
> This should be

>  	if (!debug_pagealloc_enabled())
>  		spin_unlock(&cpa_lock);

So essentially dropping the changes from the above commit from the tip
tree?  Should that commit be there?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-27 11:33   ` Lorenzo Stoakes (ARM)
@ 2026-07-27 13:03     ` Mike Rapoport
  2026-07-27 18:15       ` Lorenzo Stoakes (ARM)
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-07-27 13:03 UTC (permalink / raw)
  To: Lorenzo Stoakes (ARM)
  Cc: Mark Brown, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Peter Zijlstra, Andrew Morton, Dave Hansen,
	Linux Kernel Mailing List, Linux Next Mailing List

On Mon, Jul 27, 2026 at 12:33:30PM +0100, Lorenzo Stoakes (ARM) wrote:
> On Mon, Jul 27, 2026 at 08:48:31AM +0300, Mike Rapoport wrote:
> > Hi Mark,
> >
> > On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:
> > > Hi all,
> > >
> > > Today's linux-next merge of the tip tree got a conflict in:
> > >
> > >   arch/x86/mm/pat/set_memory.c
> > >
> > > between commits:
> > >
> > >   7a7c16a2d2b4d ("x86/mm/pat: acquire init_mm read lock on attribute change to avoid UAF")
> > >   25a54f65ccbaf ("x86/mm/pat: allocate split page tables as kernel page tables")
> > >
> > > from the mm-hotfixes-unstable tree and commit:
> > >
> > >   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
> > >
> > > from the tip tree.
> > >
> > > I fixed it up (see below) and can carry the fix as necessary. This
> > > is now fixed as far as linux-next is concerned, but any non trivial
> > > conflicts should be mentioned to your upstream maintainer when your tree
> > > is submitted for merging.  You may also want to consider cooperating
> > > with the maintainer of the conflicting tree to minimise any particularly
> > > complex conflicts.
> > >
> > > diff --cc arch/x86/mm/pat/set_memory.c
> > > index 422ce7fba00c6,1f2a2ba9ce57d..0000000000000
> > > --- a/arch/x86/mm/pat/set_memory.c
> > > +++ b/arch/x86/mm/pat/set_memory.c
> > > @@@ -440,30 -441,12 +443,32 @@@ static void __cpa_collapse_large_pages(
> > >
> > >   	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
> > >   		list_del(&ptdesc->pt_list);
> > >  -		pagetable_free(ptdesc);
> > >  +		/*
> > >  +		 * Only early alloc'd direct map should not be flagged PG_table
> > >  +		 * here and those shouldn't be collapsed. However be abundantly
> > >  +		 * cautious and handle the !PG_table case too.
> > >  +		 */
> > >  +		if (PageTable((ptdesc_page(ptdesc))))
> > >  +			pagetable_dtor_free(ptdesc);
> > >  +		else
> > >  +			pagetable_free(ptdesc);
> > >   	}
> > > +
> > > + 	spin_unlock(&cpa_lock);
> > >   }
> > >
> > >  +static void cpa_collapse_large_pages(struct cpa_data *cpa)
> > >  +{
> > >  +	/*
> > >  +	 * Take the mmap write lock on init_mm to:
> > >  +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
> > >  +	 *   write lock on init_mm).
> > >  +	 * - Serialise concurrent CPA walkers.
> > >  +	 */
> > >  +	scoped_guard(mmap_write_lock, &init_mm)
> > >  +		__cpa_collapse_large_pages(cpa);
> > >  +}
> > >  +
> > >   static void cpa_flush(struct cpa_data *cpa, int cache)
> > >   {
> > >   	unsigned int i;
> > > @@@ -1254,22 -1237,16 +1258,20 @@@ __split_large_page(struct cpa_data *cpa
> > >   static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
> > >   			    unsigned long address)
> > >   {
> > >  -	struct ptdesc *ptdesc;
> > >  +	pte_t *pte;
> > >
> > > - 	if (!debug_pagealloc_enabled())
> > > - 		spin_unlock(&cpa_lock);
> > > + 	spin_unlock(&cpa_lock);
> >
> > This should be
> >
> >  	if (!debug_pagealloc_enabled())
> >  		spin_unlock(&cpa_lock);
> >
> > >  -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
> > >  +	if (cpa->init_mm_read_locked)
> > >  +		mmap_read_unlock(&init_mm);
> > >  +	pte = pte_alloc_one_kernel(&init_mm);
> > >  +	if (cpa->init_mm_read_locked)
> > >  +		mmap_read_lock(&init_mm);
> > > - 	if (!debug_pagealloc_enabled())
> > > - 		spin_lock(&cpa_lock);
> > > + 	spin_lock(&cpa_lock);
> >
> > And this
> >
> > 	if (!debug_pagealloc_enabled())
> >  		spin_lock(&cpa_lock);
> >
> > >  -	if (!ptdesc)
> > >  +	if (!pte)
> > >   		return -ENOMEM;
> > >
> > >  -	if (__split_large_page(cpa, kpte, address, ptdesc))
> > >  -		pagetable_free(ptdesc);
> > >  +	if (__split_large_page(cpa, kpte, address, pte))
> > >  +		pte_free_kernel(&init_mm, pte);
> > >
> > >   	return 0;
> > >   }
> >
> >
> >
> > --
> > Sincerely yours,
> > Mike.
> 
> Hmm, what's the status of the x86/mm trees on this though? AFAICT Denis's
> patch is still as-is and the spin_lock() vs. spin_[un]lock_irq*() issue
> raised in [0] is unaddressed?

Maybe it's best to take x86 cpa fixes via x86 tree in the end.

I collected them on top of the current tip/x86/mm:

https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=cpa-fixes

Can you please take a look and check I didn't miss anything? I'd like to
test it a bit more before sending out.

If we route your x86 fixes via x86 tree rather than mm tree there will be a
trivial conflict in definition of the new guards for mmap_lock, but other
than that they should merge nicely with generic and arm64 part of your UAF
set.
 
> Thanks, Lorenzo
> 
> [0]:https://lore.kernel.org/all/al-MrKyIafA8QR_8@lucifer/

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-27 11:38   ` Mark Brown
@ 2026-07-27 13:09     ` Mike Rapoport
  0 siblings, 0 replies; 9+ messages in thread
From: Mike Rapoport @ 2026-07-27 13:09 UTC (permalink / raw)
  To: Mark Brown
  Cc: Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Peter Zijlstra,
	Andrew Morton, Dave Hansen, Linux Kernel Mailing List,
	Linux Next Mailing List, Lorenzo Stoakes

On Mon, Jul 27, 2026 at 12:38:58PM +0100, Mark Brown wrote:
> On Mon, Jul 27, 2026 at 08:48:31AM +0300, Mike Rapoport wrote:
> > On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:
> 
> > > from the mm-hotfixes-unstable tree and commit:
> 
> > >   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
> 
> > > from the tip tree.
> 
> > > - 	if (!debug_pagealloc_enabled())
> > > - 		spin_unlock(&cpa_lock);
> > > + 	spin_unlock(&cpa_lock);
> > 
> > This should be
> 
> >  	if (!debug_pagealloc_enabled())
> >  		spin_unlock(&cpa_lock);
> 
> So essentially dropping the changes from the above commit from the tip
> tree? 

It's a bit more messy, but essentially yes :)

> Should that commit be there?

There is another commit Lorenzo mentioned that depends on that.

And the patches I have mentioned in reply to Lorenzo should take care of
it.

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree
  2026-07-27 13:03     ` Mike Rapoport
@ 2026-07-27 18:15       ` Lorenzo Stoakes (ARM)
  0 siblings, 0 replies; 9+ messages in thread
From: Lorenzo Stoakes (ARM) @ 2026-07-27 18:15 UTC (permalink / raw)
  To: Mike Rapoport
  Cc: Mark Brown, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Peter Zijlstra, Andrew Morton, Dave Hansen,
	Linux Kernel Mailing List, Linux Next Mailing List

On Mon, Jul 27, 2026 at 04:03:38PM +0300, Mike Rapoport wrote:
> On Mon, Jul 27, 2026 at 12:33:30PM +0100, Lorenzo Stoakes (ARM) wrote:
> > On Mon, Jul 27, 2026 at 08:48:31AM +0300, Mike Rapoport wrote:
> > > Hi Mark,
> > >
> > > On Sun, Jul 26, 2026 at 10:33:53PM +0100, Mark Brown wrote:
> > > > Hi all,
> > > >
> > > > Today's linux-next merge of the tip tree got a conflict in:
> > > >
> > > >   arch/x86/mm/pat/set_memory.c
> > > >
> > > > between commits:
> > > >
> > > >   7a7c16a2d2b4d ("x86/mm/pat: acquire init_mm read lock on attribute change to avoid UAF")
> > > >   25a54f65ccbaf ("x86/mm/pat: allocate split page tables as kernel page tables")
> > > >
> > > > from the mm-hotfixes-unstable tree and commit:
> > > >
> > > >   5fce67641a3ed ("x86/mm/pat: Don't gate cpa_lock on debug_pagealloc_enabled()")
> > > >
> > > > from the tip tree.
> > > >
> > > > I fixed it up (see below) and can carry the fix as necessary. This
> > > > is now fixed as far as linux-next is concerned, but any non trivial
> > > > conflicts should be mentioned to your upstream maintainer when your tree
> > > > is submitted for merging.  You may also want to consider cooperating
> > > > with the maintainer of the conflicting tree to minimise any particularly
> > > > complex conflicts.
> > > >
> > > > diff --cc arch/x86/mm/pat/set_memory.c
> > > > index 422ce7fba00c6,1f2a2ba9ce57d..0000000000000
> > > > --- a/arch/x86/mm/pat/set_memory.c
> > > > +++ b/arch/x86/mm/pat/set_memory.c
> > > > @@@ -440,30 -441,12 +443,32 @@@ static void __cpa_collapse_large_pages(
> > > >
> > > >   	list_for_each_entry_safe(ptdesc, tmp, &pgtables, pt_list) {
> > > >   		list_del(&ptdesc->pt_list);
> > > >  -		pagetable_free(ptdesc);
> > > >  +		/*
> > > >  +		 * Only early alloc'd direct map should not be flagged PG_table
> > > >  +		 * here and those shouldn't be collapsed. However be abundantly
> > > >  +		 * cautious and handle the !PG_table case too.
> > > >  +		 */
> > > >  +		if (PageTable((ptdesc_page(ptdesc))))
> > > >  +			pagetable_dtor_free(ptdesc);
> > > >  +		else
> > > >  +			pagetable_free(ptdesc);
> > > >   	}
> > > > +
> > > > + 	spin_unlock(&cpa_lock);
> > > >   }
> > > >
> > > >  +static void cpa_collapse_large_pages(struct cpa_data *cpa)
> > > >  +{
> > > >  +	/*
> > > >  +	 * Take the mmap write lock on init_mm to:
> > > >  +	 * - Avoid a use-after-free if raced by ptdump (which takes its own
> > > >  +	 *   write lock on init_mm).
> > > >  +	 * - Serialise concurrent CPA walkers.
> > > >  +	 */
> > > >  +	scoped_guard(mmap_write_lock, &init_mm)
> > > >  +		__cpa_collapse_large_pages(cpa);
> > > >  +}
> > > >  +
> > > >   static void cpa_flush(struct cpa_data *cpa, int cache)
> > > >   {
> > > >   	unsigned int i;
> > > > @@@ -1254,22 -1237,16 +1258,20 @@@ __split_large_page(struct cpa_data *cpa
> > > >   static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
> > > >   			    unsigned long address)
> > > >   {
> > > >  -	struct ptdesc *ptdesc;
> > > >  +	pte_t *pte;
> > > >
> > > > - 	if (!debug_pagealloc_enabled())
> > > > - 		spin_unlock(&cpa_lock);
> > > > + 	spin_unlock(&cpa_lock);
> > >
> > > This should be
> > >
> > >  	if (!debug_pagealloc_enabled())
> > >  		spin_unlock(&cpa_lock);
> > >
> > > >  -	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
> > > >  +	if (cpa->init_mm_read_locked)
> > > >  +		mmap_read_unlock(&init_mm);
> > > >  +	pte = pte_alloc_one_kernel(&init_mm);
> > > >  +	if (cpa->init_mm_read_locked)
> > > >  +		mmap_read_lock(&init_mm);
> > > > - 	if (!debug_pagealloc_enabled())
> > > > - 		spin_lock(&cpa_lock);
> > > > + 	spin_lock(&cpa_lock);
> > >
> > > And this
> > >
> > > 	if (!debug_pagealloc_enabled())
> > >  		spin_lock(&cpa_lock);
> > >
> > > >  -	if (!ptdesc)
> > > >  +	if (!pte)
> > > >   		return -ENOMEM;
> > > >
> > > >  -	if (__split_large_page(cpa, kpte, address, ptdesc))
> > > >  -		pagetable_free(ptdesc);
> > > >  +	if (__split_large_page(cpa, kpte, address, pte))
> > > >  +		pte_free_kernel(&init_mm, pte);
> > > >
> > > >   	return 0;
> > > >   }
> > >
> > >
> > >
> > > --
> > > Sincerely yours,
> > > Mike.
> >
> > Hmm, what's the status of the x86/mm trees on this though? AFAICT Denis's
> > patch is still as-is and the spin_lock() vs. spin_[un]lock_irq*() issue
> > raised in [0] is unaddressed?
>
> Maybe it's best to take x86 cpa fixes via x86 tree in the end.
>
> I collected them on top of the current tip/x86/mm:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/rppt/linux.git/log/?h=cpa-fixes
>
> Can you please take a look and check I didn't miss anything? I'd like to
> test it a bit more before sending out.

Will take a look later to make sure :)

>
> If we route your x86 fixes via x86 tree rather than mm tree there will be a
> trivial conflict in definition of the new guards for mmap_lock, but other
> than that they should merge nicely with generic and arm64 part of your UAF
> set.

In terms of having the x86 fixes there it's fine, as long as the mm fixes land
and the x86 fixes land, we're all good.

>
> > Thanks, Lorenzo
> >
> > [0]:https://lore.kernel.org/all/al-MrKyIafA8QR_8@lucifer/
>
> --
> Sincerely yours,
> Mike.

Cheers, Lorenzo

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-07-27 18:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-26 21:33 linux-next: manual merge of the tip tree with the mm-hotfixes-unstable tree Mark Brown
2026-07-27  5:48 ` Mike Rapoport
2026-07-27 11:33   ` Lorenzo Stoakes (ARM)
2026-07-27 13:03     ` Mike Rapoport
2026-07-27 18:15       ` Lorenzo Stoakes (ARM)
2026-07-27 11:38   ` Mark Brown
2026-07-27 13:09     ` Mike Rapoport
  -- strict thread matches above, loose matches on Subject: below --
2026-07-21 13:46 Mark Brown
2026-07-21 16:14 ` Lorenzo Stoakes (ARM)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox