[PATCH v5 17/17] mm: pgtable: introduce generic pagetable_dtor_free()

2025-01-07 Thread Qi Zheng
The pte_free(), pmd_free(), __pud_free() and __p4d_free() in asm-generic/pgalloc.h and the generic __tlb_remove_table() are basically the same, so let's introduce pagetable_dtor_free() to deduplicate them. In addition, the pagetable_dtor_free() in s390 does the same thing, so let's s390 also calls

[PATCH v5 14/17] mm: pgtable: introduce generic __tlb_remove_table()

2025-01-07 Thread Qi Zheng
Several architectures (arm, arm64, riscv and x86) define exactly the same __tlb_remove_table(), just introduce generic __tlb_remove_table() to eliminate these duplications. The s390 __tlb_remove_table() is nearly the same, so also make s390 __tlb_remove_table() version generic. Signed-off-by: Qi

[PATCH v5 15/17] mm: pgtable: completely move pagetable_dtor() to generic tlb_remove_table()

2025-01-07 Thread Qi Zheng
For the generic tlb_remove_table(), it is implemented in the following two forms: 1) CONFIG_MMU_GATHER_TABLE_FREE is enabled tlb_remove_table --> generic __tlb_remove_table() 2) CONFIG_MMU_GATHER_TABLE_FREE is disabled tlb_remove_table --> tlb_remove_page For case 1), the pagetable_dtor() has

[PATCH v5 13/17] s390: pgtable: consolidate PxD and PTE TLB free paths

2025-01-07 Thread Qi Zheng
Call pagetable_dtor() for PMD|PUD|P4D tables just before ptdesc is freed - same as it is done for PTE tables. That allows consolidating TLB free paths for all table types. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-s...@vger.kernel.org ---

[PATCH v5 11/17] x86: pgtable: convert __tlb_remove_table() to use struct ptdesc

2025-01-07 Thread Qi Zheng
Convert __tlb_remove_table() to use struct ptdesc, which will help to move pagetable_dtor() to __tlb_remove_table(). And page tables shouldn't have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng --- arch/x86/include/as

[PATCH v5 10/17] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
Move pagetable_dtor() to __tlb_remove_table(), so that ptlock and page table pages can be freed together (regardless of whether RCU is used). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. Page tables shouldn't have s

[PATCH v5 09/17] arm64: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
Move pagetable_dtor() to __tlb_remove_table(), so that ptlock and page table pages can be freed together (regardless of whether RCU is used). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. Page tables shouldn't have s

[PATCH v5 08/17] arm: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
Move pagetable_dtor() to __tlb_remove_table(), so that ptlock and page table pages can be freed together (regardless of whether RCU is used). This prevents the use-after-free problem where the ptlock is freed immediately but the page table pages is freed later via RCU. Page tables shouldn't have s

[PATCH v5 07/17] mm: pgtable: introduce pagetable_dtor()

2025-01-07 Thread Qi Zheng
The pagetable_p*_dtor() are exactly the same except for the handling of ptlock. If we make ptlock_free() handle the case where ptdesc->ptl is NULL and remove VM_BUG_ON_PAGE() from pmd_ptlock_free(), we can unify pagetable_p*_dtor() into one function. Let's introduce pagetable_dtor() to do this. La

[PATCH v5 06/17] s390: pgtable: add statistics for PUD and P4D level page table

2025-01-07 Thread Qi Zheng
Like PMD and PTE level page table, also add statistics for PUD and P4D page table. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-s...@vger.kernel.org --- arch/s390/include/asm/pgalloc.h | 29 + arch/s390/include/as

[PATCH v5 05/17] arm64: pgtable: use mmu gather to free p4d level page table

2025-01-07 Thread Qi Zheng
Like other levels of page tables, also use mmu gather mechanism to free p4d level page table. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 1 - arch/arm64/include/asm/tl

[PATCH v5 04/17] mm: pgtable: add statistics for P4D level page table

2025-01-07 Thread Qi Zheng
Like other levels of page tables, add statistics for P4D level page table. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky --- arch/riscv/include/asm/pgalloc.h | 6 +- arch/x86/mm/pgtable.c| 3 +++ include/asm-generic/pgalloc.h| 2

[PATCH v5 03/17] asm-generic: pgalloc: Provide generic p4d_{alloc_one,free}

2025-01-07 Thread Qi Zheng
From: Kevin Brodsky Four architectures currently implement 5-level pgtables: arm64, riscv, x86 and s390. The first three have essentially the same implementation for p4d_alloc_one() and p4d_free(), so we've got an opportunity to reduce duplication like at the lower levels. Provide a generic vers

[PATCH v5 02/17] riscv: mm: Skip pgtable level check in {pud,p4d}_alloc_one

2025-01-07 Thread Qi Zheng
From: Kevin Brodsky {pmd,pud,p4d}_alloc_one() is never called if the corresponding page table level is folded, as {pmd,pud,p4d}_alloc() already does the required check. We can therefore remove the runtime page table level checks in {pud,p4d}_alloc_one. The PUD helper becomes equivalent to the gen

[PATCH v5 01/17] Revert "mm: pgtable: make ptlock be freed by RCU"

2025-01-07 Thread Qi Zheng
This reverts commit 2f3443770437e49abc39af26962d293851cbab6d. Signed-off-by: Qi Zheng Reviewed-by: Kevin Brodsky --- include/linux/mm.h | 2 +- include/linux/mm_types.h | 9 + mm/memory.c | 22 ++ 3 files changed, 8 insertions(+), 25 deletions(-)

[PATCH v5 00/17] move pagetable_*_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
Changes in v5: - cancel the move of p4d_free_tlb()'s location in [PATCH v4 06/15] (Alexander Gordeev) - fix the missing pagetable_dtor() in [PATCH v4 08/15] (Kevin Brodsky) - change the subject and description in [PATCH v4 12/15] (Alexander Gordeev) - remove the redundant __HAVE_ARCH_TLB_

[PATCH 3/6] syscall.h: introduce syscall_set_nr()

2025-01-07 Thread Dmitry V. Levin
Similar to syscall_set_arguments() that complements syscall_get_arguments(), introduce syscall_set_nr() that complements syscall_get_nr(). syscall_set_nr() is going to be needed along with syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK architectures to implement PTRACE_SET_SYSCALL_INFO API. S

[PATCH 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API

2025-01-07 Thread Dmitry V. Levin
PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in. This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way. Current im

[PATCH 1/6] Revert "arch: remove unused function syscall_set_arguments()"

2025-01-07 Thread Dmitry V. Levin
syscall_set_arguments() is going to be needed to implement PTRACE_SET_SYSCALL_INFO API. This is a partial revert: on a few architectures syscall_set_arguments() implementations were buggy, so instead of adding them here and applying fixes on top, cleaner implementations are coming in follow-up com

Re: [PATCH] um: add back support for FXSAVE registers

2025-01-07 Thread SeongJae Park
Hello, On Wed, 4 Dec 2024 08:48:27 +0100 Benjamin Berg wrote: > From: Benjamin Berg > > It was reported that qemu may not enable the XSTATE CPU extension, which > is a requirement after commit 3f17fed21491 ("um: switch to regset API > and depend on XSTATE"). Add a fallback to use FXSAVE (FP r

Re: [PATCH v7] mm/memblock: Add memblock_alloc_or_panic interface

2025-01-07 Thread Alexander Gordeev
On Sun, Dec 22, 2024 at 07:15:37PM +0800, Guo Weikang wrote: Hi Guo, > Before SLUB initialization, various subsystems used memblock_alloc to > allocate memory. In most cases, when memory allocation fails, an immediate > panic is required. To simplify this behavior and reduce repetitive checks, >

Re: [PATCH v4 15/15] mm: pgtable: introduce generic pagetable_dtor_free()

2025-01-07 Thread Alexander Gordeev
On Mon, Dec 30, 2024 at 05:07:50PM +0800, Qi Zheng wrote: > The pte_free(), pmd_free(), __pud_free() and __p4d_free() in > asm-generic/pgalloc.h and the generic __tlb_remove_table() are basically > the same, so let's introduce pagetable_dtor_free() to deduplicate them. > > In addition, the pagetab

Re: [PATCH v4 13/15] mm: pgtable: introduce generic __tlb_remove_table()

2025-01-07 Thread Alexander Gordeev
On Mon, Dec 30, 2024 at 05:07:48PM +0800, Qi Zheng wrote: > Several architectures (arm, arm64, riscv and x86) define exactly the > same __tlb_remove_table(), just introduce generic __tlb_remove_table() to > eliminate these duplications. > > The s390 __tlb_remove_table() is nearly the same, so also

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 07/01/2025 13:31, Qi Zheng wrote: > On 2025/1/7 19:58, Kevin Brodsky wrote: >> On 07/01/2025 11:51, Qi Zheng wrote: >>> [...] >>> >>> Author: Qi Zheng >>> Date:   Fri Dec 13 17:13:48 2024 +0800 >>> >>> mm: pgtable: completely move pagetable_dtor() to generic >>> tlb_remove_table() >>> >>>

[PATCH] um: properly align signal stack on x86_64

2025-01-07 Thread Benjamin Berg
From: Benjamin Berg The stack needs to be properly aligned so 16 byte memory accesses on the stack are correct. This was broken when introducing the dynamic math register sizing as the rounding was not moved appropriately. Fixes: 3f17fed21491 ("um: switch to regset API and depend on XSTATE") Sig

Re: [PATCH v4 13/15] mm: pgtable: introduce generic __tlb_remove_table()

2025-01-07 Thread Qi Zheng
On 2025/1/7 20:32, Andreas Larsson wrote: On 2024-12-30 10:07, Qi Zheng wrote: diff --git a/arch/sparc/include/asm/tlb_32.h b/arch/sparc/include/asm/tlb_32.h index 5cd28a8793e39..910254867dfbd 100644 --- a/arch/sparc/include/asm/tlb_32.h +++ b/arch/sparc/include/asm/tlb_32.h @@ -2,6 +2,7 @@

Re: [PATCH v4 13/15] mm: pgtable: introduce generic __tlb_remove_table()

2025-01-07 Thread Andreas Larsson
On 2024-12-30 10:07, Qi Zheng wrote: > diff --git a/arch/sparc/include/asm/tlb_32.h b/arch/sparc/include/asm/tlb_32.h > index 5cd28a8793e39..910254867dfbd 100644 > --- a/arch/sparc/include/asm/tlb_32.h > +++ b/arch/sparc/include/asm/tlb_32.h > @@ -2,6 +2,7 @@ > #ifndef _SPARC_TLB_H > #define _SPA

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
On 2025/1/7 19:58, Kevin Brodsky wrote: On 07/01/2025 11:51, Qi Zheng wrote: [...] Author: Qi Zheng Date:   Fri Dec 13 17:13:48 2024 +0800     mm: pgtable: completely move pagetable_dtor() to generic tlb_remove_table()     For the generic tlb_remove_table(), it is implemented in the fol

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 07/01/2025 11:51, Qi Zheng wrote: > [...] > > Author: Qi Zheng > Date:   Fri Dec 13 17:13:48 2024 +0800 > >     mm: pgtable: completely move pagetable_dtor() to generic > tlb_remove_table() > >     For the generic tlb_remove_table(), it is implemented in the > following two >     forms: > >    

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Qi Zheng
On 2025/1/7 17:57, Kevin Brodsky wrote: On 06/01/2025 04:49, Qi Zheng wrote: [...] Once this is done, we should be able to replace all those confusing calls to tlb_remove_page() on PTPs with tlb_remove_table() and remove the explicit call to pagetable_dtor(). AIUI this is essentially what P

Re: [PATCH v4 10/15] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-07 Thread Kevin Brodsky
On 06/01/2025 04:49, Qi Zheng wrote: > [...] > >> Once this is done, we should be able to replace all those confusing >> calls to tlb_remove_page() on PTPs with tlb_remove_table() and remove >> the explicit call to pagetable_dtor(). AIUI this is essentially what >> Peter suggested on v3 [2]. > > Si

Re: [PATCH v4 07/15] mm: pgtable: introduce pagetable_dtor()

2025-01-07 Thread Kevin Brodsky
On 06/01/2025 14:23, Qi Zheng wrote: > On 2025/1/6 20:36, Alexander Gordeev wrote: >> On Mon, Jan 06, 2025 at 06:55:58PM +0800, Qi Zheng wrote: > +static inline void pagetable_dtor(struct ptdesc *ptdesc) > +{ > +    struct folio *folio = ptdesc_folio(ptdesc); > + > +    ptlock_f

Re: [PATCH v2 0/6] Account page tables at all levels

2025-01-07 Thread Kevin Brodsky
On 06/01/2025 09:38, Qi Zheng wrote: > For this series: > > Acked-by: Qi Zheng Thank you for the review, appreciated! - Kevin