Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: "Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Vasily Gorbik" <gor@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>
Subject: Re: [PATCH 10/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc32
Date: Tue, 01 Sep 2026 11:37:38 +0000	[thread overview]
Message-ID: <20260901113739.629851F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901-rcu-pagetable-freeing-v1-10-5456a81c8212@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Concurrent execution of pagetable_pte_ctor() and pagetable_dtor() on shared backing pages corrupts folio state.
--

commit f7114a4ac52b3be28e86c3e8ab381854e55bfcf6
Author: Lorenzo Stoakes (ARM) <ljs@kernel.org>

mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc32
    
This commit enables MMU_GATHER_RCU_TABLE_FREE for sparc32 by using an RCU
callback to free page tables. It introduces __tlb_remove_table() and modifies
__pte_free() to handle NULL mm pointers when called from softirq context.

> But more importantly - the reference count increment in pte_alloc_one() and
> decrement in __pte_free() are atomic with full ordering, so it simply isn't
> possible for there to be a meaningful race here.

[Severity: High]
Does this actually prevent concurrent execution of the page table constructor
and destructor?

The atomic refcount ensures the reference count itself is safe, but it does
not serialize the execution of the constructor and destructor bodies.

If a process unmaps memory and queues PTE pages for RCU free, a softirq could
begin executing __pte_free() and drop the page refcount to 1, entering
pagetable_dtor().

If a process concurrently page faults and allocates a new PTE table in the same
4KB physical page, it increments the refcount to 2 and enters
pagetable_pte_ctor(). 

Could both threads execute the constructor and destructor concurrently,
corrupting the folio state?

> diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
> index 9a74902ad1814..2a2c7bd210114 100644
> --- a/arch/sparc/mm/srmmu.c
> +++ b/arch/sparc/mm/srmmu.c
[ ... ]
> @@ -359,19 +359,39 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
>  	return ptep;
>  }
>  
> -void pte_free(struct mm_struct *mm, pgtable_t ptep)
> +static void __pte_free(struct mm_struct *mm, pgtable_t ptep)
>  {
> +	const bool process_context = mm;
>  	struct page *page;
>  
>  	page = pfn_to_page(__nocache_pa((unsigned long)ptep) >> PAGE_SHIFT);
> -	spin_lock(&mm->page_table_lock);
> +	if (process_context)
> +		spin_lock(&mm->page_table_lock);
>  	if (page_ref_dec_return(page) == 1)
>  		pagetable_dtor(page_ptdesc(page));
        ^^^^

[Severity: High]
Can this page table destructor run concurrently with the page table
constructor in pte_alloc_one()?

Since process_context is false when called from softirq context via RCU, this
executes without a lock protecting the physical page.

If pte_alloc_one() concurrently allocates another PTE table in the same
backing page, increments the refcount to 2, and calls
pagetable_pte_ctor(mm, page_ptdesc(page)), could this lead to non-atomic
modifications to folio->page.page_type?

Concurrent execution of __folio_clear_pgtable() in the destructor and
initialization in the constructor could corrupt the page state, which may
lead to kernel crashes when pages are returned to the buddy allocator.

> -	spin_unlock(&mm->page_table_lock);
> +	if (process_context)
> +		spin_unlock(&mm->page_table_lock);
>  
>  	srmmu_free_nocache(ptep, SRMMU_PTE_TABLE_SIZE);
>  }

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

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

Thread overview: 43+ 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 ` [PATCH 01/12] mm/huge_memory: zap deposited page tables after an RCU grace period Lorenzo Stoakes (ARM)
2026-09-01 11:18   ` sashiko-bot
2026-09-01 13:19   ` Kiryl Shutsemau
2026-09-01 14:12     ` Lorenzo Stoakes (ARM)
2026-09-01 14:24       ` Jason Gunthorpe
2026-09-01 14:41         ` Lorenzo Stoakes (ARM)
2026-09-01 15:28           ` Kiryl Shutsemau
2026-09-01 15:45             ` Lorenzo Stoakes (ARM)
2026-09-01 17:11               ` Kiryl Shutsemau
2026-09-01 17:14                 ` Lorenzo Stoakes (ARM)
2026-09-01 15:54             ` Liam R. Howlett
2026-09-01 16:06               ` Jason Gunthorpe
2026-09-01 17:13               ` Kiryl Shutsemau
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: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: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: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:28   ` sashiko-bot
2026-09-01 11:01 ` [PATCH 06/12] mm: enable MMU_GATHER_RCU_TABLE_FREE for sparc64 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: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: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: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:37   ` sashiko-bot [this message]
2026-09-01 11:01 ` [PATCH 11/12] mm: make userland page table freeing RCU-safe Lorenzo Stoakes (ARM)
2026-09-01 11:52   ` sashiko-bot
2026-09-01 13:33   ` Kiryl Shutsemau
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:37   ` sashiko-bot
2026-09-01 13:57   ` Kiryl Shutsemau
2026-09-01 14:31     ` Lorenzo Stoakes (ARM)
2026-09-01 17:15       ` Kiryl Shutsemau
2026-09-01 17:25         ` 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=20260901113739.629851F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox