Re: [PATCH v2 3/6 update] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-03-03 Thread Qi Zheng
On 3/4/25 12:08 PM, Andrew Morton wrote: On Tue, 4 Mar 2025 10:31:07 +0800 Qi Zheng wrote: On 3/4/25 7:53 AM, Andrew Morton wrote: On Mon, 3 Mar 2025 15:26:03 +0800 Qi Zheng wrote: Now, the nine architectures of csky, hexagon, loongarch, m68k, mips, nios2, openrisc, sh and um do not

Re: [PATCH v2 3/6 update] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-03-03 Thread Qi Zheng
On 3/4/25 7:53 AM, Andrew Morton wrote: On Mon, 3 Mar 2025 15:26:03 +0800 Qi Zheng wrote: Now, the nine architectures of csky, hexagon, loongarch, m68k, mips, nios2, openrisc, sh and um do not select CONFIG_MMU_GATHER_RCU_TABLE_FREE, and just call pagetable_dtor() + tlb_remove_page_ptdesc

[PATCH v2 3/6 update] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-03-02 Thread Qi Zheng
|table}() under !CONFIG_MMU_GATHER_TABLE_FREE, so convert these architectures to use tlb_remove_ptdesc(). The ultimate goal is to make the architecture only use tlb_remove_ptdesc() or tlb_remove_table() for page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed

Re: [PATCH v2 4/6] riscv: pgtable: unconditionally use tlb_remove_ptdesc()

2025-03-02 Thread Qi Zheng
On 3/3/25 9:45 AM, yunhui cui wrote: Hi Qi, [...] This set of patches mainly refactors the remove page table function interfaces. The comment "riscv_ipi_for_rfence" has been removed, as it was no longer needed, and this patch handles that. Additionally, whether riscv_use_sbi_for_rfen

Re: [PATCH v2 3/6] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-02-27 Thread Qi Zheng
On 2/27/25 9:21 PM, Geert Uytterhoeven wrote: Hi Qi, On Tue, 25 Feb 2025 at 04:46, Qi Zheng wrote: Now, the nine architectures of csky, hexagon, loongarch, m68k, mips, nios2, openrisc, sh and um do not select CONFIG_MMU_GATHER_RCU_TABLE_FREE, and just call pagetable_dtor

Re: [PATCH v2 5/6] x86: pgtable: convert to use tlb_remove_ptdesc()

2025-02-25 Thread Qi Zheng
On 2/26/25 上午10:35, Andrew Morton wrote: On Tue, 25 Feb 2025 11:45:55 +0800 Qi Zheng wrote: The x86 has already been converted to use struct ptdesc, so convert it to use tlb_remove_ptdesc() instead of tlb_remove_table(). This is dependent upon Rik's a37259732a7dc ("x8

[PATCH v2 6/6] mm: pgtable: remove tlb_remove_page_ptdesc()

2025-02-24 Thread Qi Zheng
ff-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- include/asm-generic/tlb.h | 6 -- 1 file changed, 6 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 18bf499ef8801..dd292c6d3ce88 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/

[PATCH v2 5/6] x86: pgtable: convert to use tlb_remove_ptdesc()

2025-02-24 Thread Qi Zheng
The x86 has already been converted to use struct ptdesc, so convert it to use tlb_remove_ptdesc() instead of tlb_remove_table(). Signed-off-by: Qi Zheng --- arch/x86/mm/pgtable.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm

[PATCH v2 4/6] riscv: pgtable: unconditionally use tlb_remove_ptdesc()

2025-02-24 Thread Qi Zheng
system. So, in summary, we can use tlb_remove_ptdesc() to support fast gup in all cases, and this interface is specifically designed for page table pages. So let's use it unconditionally. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/riscv/include/asm/pgalloc.h | 26

[PATCH v2 0/6] remove tlb_remove_page_ptdesc()

2025-02-24 Thread Qi Zheng
[1]. https://lore.kernel.org/linux-mm/20250103111457.gc22...@noisy.programming.kicks-ass.net/ Qi Zheng (6): mm: pgtable: make generic tlb_remove_table() use struct ptdesc mm: pgtable: change pt parameter of tlb_remove_ptdesc() to struct ptdesc * mm: pgtable: convert some architectures

[PATCH v2 3/6] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-02-24 Thread Qi Zheng
|table}() under !CONFIG_MMU_GATHER_TABLE_FREE, so convert these architectures to use tlb_remove_ptdesc(). The ultimate goal is to make the architecture only use tlb_remove_ptdesc() or tlb_remove_table() for page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch

[PATCH v2 2/6] mm: pgtable: change pt parameter of tlb_remove_ptdesc() to struct ptdesc *

2025-02-24 Thread Qi Zheng
All callers of tlb_remove_ptdesc() pass it a pointer of struct ptdesc, so let's change the pt parameter from void * to struct ptdesc * to perform a type safety check. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) --- include/asm-generic/tlb.h | 2 +- 1 file changed, 1 inse

[PATCH v2 1/6] mm: pgtable: make generic tlb_remove_table() use struct ptdesc

2025-02-24 Thread Qi Zheng
. Signed-off-by: Qi Zheng --- include/asm-generic/tlb.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index b35b36fa7aabf..54f579750c8e5 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -232,10

Re: [PATCH 0/5] remove tlb_remove_page_ptdesc()

2025-01-24 Thread Qi Zheng
On 2025/1/24 19:47, Peter Zijlstra wrote: On Thu, Jan 23, 2025 at 09:26:13PM +0800, Qi Zheng wrote: Hi all, As suggested by Peter Zijlstra below [1], this series aims to remove tlb_remove_page_ptdesc(). : Fundamentally tlb_remove_page() is about removing *pages* as from a PTE, : there

Re: [PATCH 4/5] x86: pgtable: unconditionally use tlb_remove_table()

2025-01-24 Thread Qi Zheng
On 2025/1/24 19:38, Peter Zijlstra wrote: On Thu, Jan 23, 2025 at 09:26:17PM +0800, Qi Zheng wrote: If the CONFIG_MMU_GATHER_TABLE_FREE is disabled, the tlb_remove_table() will fall back to pagetable_dtor() + tlb_remove_page(). So let's use tlb_remove_table() unconditionally to free

[PATCH 5/5] mm: pgtable: remove tlb_remove_page_ptdesc()

2025-01-23 Thread Qi Zheng
ff-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- include/asm-generic/tlb.h | 6 -- 1 file changed, 6 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index 10cdbe0e7adfe..dec030cb12108 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/

[PATCH 4/5] x86: pgtable: unconditionally use tlb_remove_table()

2025-01-23 Thread Qi Zheng
If the CONFIG_MMU_GATHER_TABLE_FREE is disabled, the tlb_remove_table() will fall back to pagetable_dtor() + tlb_remove_page(). So let's use tlb_remove_table() unconditionally to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/x86/kernel/parav

[PATCH 0/5] remove tlb_remove_page_ptdesc()

2025-01-23 Thread Qi Zheng
/lkml/20250123042447.2259648-2-r...@surriel.com/ Qi Zheng (5): mm: pgtable: make generic tlb_remove_table() use struct ptdesc mm: pgtable: convert some architectures to use tlb_remove_ptdesc() riscv: pgtable: unconditionally use tlb_remove_ptdesc() x86: pgtable: unconditionally use tlb_remove_

[PATCH 1/5] mm: pgtable: make generic tlb_remove_table() use struct ptdesc

2025-01-23 Thread Qi Zheng
. Signed-off-by: Qi Zheng --- include/asm-generic/tlb.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h index e402aef79c93e..10cdbe0e7adfe 100644 --- a/include/asm-generic/tlb.h +++ b/include/asm-generic/tlb.h @@ -228,10

[PATCH 3/5] riscv: pgtable: unconditionally use tlb_remove_ptdesc()

2025-01-23 Thread Qi Zheng
system. So, in summary, we can use tlb_remove_ptdesc() to support fast gup in all cases, and this interface is specifically designed for page table pages. So let's use it unconditionally. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/riscv/include/asm/pgalloc.h | 26

[PATCH 2/5] mm: pgtable: convert some architectures to use tlb_remove_ptdesc()

2025-01-23 Thread Qi Zheng
|table}() under !CONFIG_MMU_GATHER_TABLE_FREE, so convert these architectures to use tlb_remove_ptdesc(). The ultimate goal is to make the architecture only use tlb_remove_ptdesc() or tlb_remove_table() for page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch

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

2025-01-13 Thread Qi Zheng
Hi Will, On 2025/1/14 00:26, Will Deacon wrote: On Wed, Jan 08, 2025 at 02:57:21PM +0800, Qi Zheng wrote: 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

[PATCH v5 16/17] mm: pgtable: move __tlb_remove_table_one() in x86 to generic file

2025-01-08 Thread Qi Zheng
The __tlb_remove_table_one() in x86 does not contain architecture-specific content, so move it to the generic file. Signed-off-by: Qi Zheng Reviewed-by: Kevin Brodsky --- arch/x86/include/asm/tlb.h | 19 --- mm/mmu_gather.c| 20 ++-- 2 files changed

[PATCH v5 12/17] x86: pgtable: move pagetable_dtor() to __tlb_remove_table()

2025-01-08 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. Signed-off-by: Qi Zheng

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

2025-01-07 Thread Qi Zheng
s390 also calls generic pagetable_dtor_free(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Acked-by: Alexander Gordeev # s390 --- arch/s390/mm/pgalloc.c| 6 -- include/asm-generic/pgalloc.h | 12 include/asm-generic/tlb.

[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
more easily. Signed-off-by: Qi Zheng Suggested-by: Kevin Brodsky Reviewed-by: Kevin Brodsky --- arch/arm/include/asm/tlb.h | 4 include/asm-generic/tlb.h | 10 -- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/arch/arm/include/asm/tlb.h b/arch/arm/include/asm/

[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/in

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

2025-01-07 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. By the way, move the comment above __tlb_remove_table() to riscv_tlb_remove_ptdesc(), it will be more appropriate. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by:

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

2025-01-07 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/tlb.h | 10 -- 1 file ch

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

2025-01-07 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky Cc: linux-arm-ker...@lists.infradead.org --- arch/arm/include/asm/tlb.h | 9 ++--- 1 file chang

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

2025-01-07 Thread Qi Zheng
d-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) Reviewed-by: Kevin Brodsky --- Documentation/mm/split_page_table_lock.rst | 4 +- arch/arm/include/asm/tlb.h | 4 +- arch/arm64/include/asm/tlb.h | 8 ++-- arch/csky/include/asm/pgalloc.h| 2

[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

[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

[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

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

2025-01-07 Thread Qi Zheng
orted architectures, so we might as well include this check in the generic implementation. No runtime check is required in p4d_alloc_one() as the top-level p4d_alloc() already does the required check. Signed-off-by: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng --- arch/arm64/includ

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

2025-01-07 Thread Qi Zheng
generic version, so we remove it altogether. This is consistent with the way arm64 and x86 handle this situation (runtime check in p4d_free() only). Signed-off-by: Kevin Brodsky Signed-off-by: Qi Zheng Acked-by: Dave Hansen Reviewed-by: Alexandre Ghiti --- arch/riscv/include/asm/pgalloc.h | 22

[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
. Comments and suggestions are welcome! Thanks, Qi [1]. https://lore.kernel.org/all/20241211133433.gc12...@noisy.programming.kicks-ass.net/ [2]. https://lore.kernel.org/all/67548279.050a0220.a30f1.015b@google.com/ Kevin Brodsky (2): riscv: mm: Skip pgtable level check in {pud,p4d}_alloc_one asm-gen

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 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

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

Re: [PATCH v4 12/15] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table()

2025-01-06 Thread Qi Zheng
On 2025/1/6 22:35, Alexander Gordeev wrote: On Mon, Jan 06, 2025 at 09:34:55PM +0800, Qi Zheng wrote: OK, will change the subject and description to: s390: pgtable: also move pagetable_dtor() of PxD to pagetable_dtor_free() To unify the PxD and PTE TLB free path, also move the

Re: [PATCH v4 06/15] s390: pgtable: add statistics for PUD and P4D level page table

2025-01-06 Thread Qi Zheng
On 2025/1/6 21:34, Alexander Gordeev wrote: On Mon, Jan 06, 2025 at 07:05:16PM +0800, Qi Zheng wrote: I understand that you want to sort p.._free_tlb() routines, but please Yes, I thought it was a minor change, so I just did it. do not move the code around or make a separate follow-up

Re: [PATCH v4 12/15] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table()

2025-01-06 Thread Qi Zheng
On 2025/1/6 20:44, Alexander Gordeev wrote: On Mon, Jan 06, 2025 at 07:02:17PM +0800, Qi Zheng wrote: On Mon, Dec 30, 2024 at 05:07:47PM +0800, Qi Zheng wrote: To unify the PxD and PTE TLB free path, also move the pagetable_dtor() of PMD|PUD|P4D to __tlb_remove_table(). The above and

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

2025-01-06 Thread Qi Zheng
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_free(ptdesc); + __folio_clear_pgtable(folio

Re: [PATCH v4 06/15] s390: pgtable: add statistics for PUD and P4D level page table

2025-01-06 Thread Qi Zheng
On 2025/1/6 18:32, Alexander Gordeev wrote: On Mon, Dec 30, 2024 at 05:07:41PM +0800, Qi Zheng wrote: Like PMD and PTE level page table, also add statistics for PUD and P4D page table. ... diff --git a/arch/s390/include/asm/tlb.h b/arch/s390/include/asm/tlb.h index e95b2c8081eb8

Re: [PATCH v4 12/15] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table()

2025-01-06 Thread Qi Zheng
On 2025/1/6 18:36, Alexander Gordeev wrote: On Mon, Dec 30, 2024 at 05:07:47PM +0800, Qi Zheng wrote: To unify the PxD and PTE TLB free path, also move the pagetable_dtor() of PMD|PUD|P4D to __tlb_remove_table(). The above and Subject are still incorrect: pagetable_dtor() is called from

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

2025-01-06 Thread Qi Zheng
On 2025/1/6 18:34, Alexander Gordeev wrote: On Mon, Dec 30, 2024 at 05:07:42PM +0800, Qi Zheng wrote: 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() f

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

2025-01-06 Thread Qi Zheng
Cc: Catalin Marinas Cc: Dave Hansen Cc: Linus Walleij Cc: Andy Lutomirski Cc: Peter Zijlstra Cc: "Mike Rapoport (IBM)" Cc: Ryan Roberts Cc: Thomas Gleixner Cc: Will Deacon Cc: Matthew Wilcox Cc: Qi Zheng Cc: linux-al...@vger.kernel.org Cc: linux-a...@vger.kernel.org Cc: linux-ar

Re: [PATCH v3 15/17] mm: pgtable: remove tlb_remove_page_ptdesc()

2025-01-05 Thread Qi Zheng
On 2025/1/3 19:14, Peter Zijlstra wrote: On Sat, Dec 28, 2024 at 11:26:22AM +0200, Mike Rapoport wrote: On Mon, Dec 23, 2024 at 05:41:01PM +0800, Qi Zheng wrote: Here we are explicitly dealing with struct page, and the following logic semms strange: tlb_remove_page_ptdesc((tlb

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

2025-01-05 Thread Qi Zheng
Hi Kevin, On 2025/1/3 21:27, Kevin Brodsky wrote: On 03/01/2025 10:35, Qi Zheng wrote: On 2025/1/3 17:13, Qi Zheng wrote: On 2025/1/3 16:02, Kevin Brodsky wrote: On 03/01/2025 04:48, Qi Zheng wrote: [...] In __tlb_batch_free_encoded_pages(), we can indeed detect PageTable() and call

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

2025-01-03 Thread Qi Zheng
On 2025/1/3 17:13, Qi Zheng wrote: On 2025/1/3 16:02, Kevin Brodsky wrote: On 03/01/2025 04:48, Qi Zheng wrote: Hi Kevin, On 2025/1/3 00:53, Kevin Brodsky wrote: On 30/12/2024 10:07, Qi Zheng wrote:    static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt

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

2025-01-03 Thread Qi Zheng
On 2025/1/3 16:02, Kevin Brodsky wrote: On 03/01/2025 04:48, Qi Zheng wrote: Hi Kevin, On 2025/1/3 00:53, Kevin Brodsky wrote: On 30/12/2024 10:07, Qi Zheng wrote:   static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt)   { -    if (riscv_use_sbi_for_rfence

Re: [PATCH v4 00/15] move pagetable_*_dtor() to __tlb_remove_table()

2025-01-02 Thread Qi Zheng
On 2025/1/3 01:00, Kevin Brodsky wrote: On 30/12/2024 10:07, Qi Zheng wrote: Qi Zheng (13): Revert "mm: pgtable: make ptlock be freed by RCU" mm: pgtable: add statistics for P4D level page table arm64: pgtable: use mmu gather to free p4d level page table s390: pg

Re: [PATCH v4 04/15] mm: pgtable: add statistics for P4D level page table

2025-01-02 Thread Qi Zheng
On 2025/1/3 00:53, Kevin Brodsky wrote: On 30/12/2024 10:07, Qi Zheng wrote: diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h index 551d614d3369c..3466fbe2e508d 100644 --- a/arch/riscv/include/asm/pgalloc.h +++ b/arch/riscv/include/asm/pgalloc.h @@ -108,8

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

2025-01-02 Thread Qi Zheng
Hi Kevin, On 2025/1/3 00:53, Kevin Brodsky wrote: On 30/12/2024 10:07, Qi Zheng wrote: static inline void riscv_tlb_remove_ptdesc(struct mmu_gather *tlb, void *pt) { - if (riscv_use_sbi_for_rfence()) + if (riscv_use_sbi_for_rfence()) { tlb_remove_ptdesc(tlb, pt

[PATCH v4 09/15] arm64: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-30 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/tlb.h | 10 -- 1 file changed, 4 insertions(+), 6 dele

[PATCH v4 11/15] x86: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-30 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: x...@kernel.org --- arch/x86/include/asm/tlb.h | 17 ++--- arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/pgta

[PATCH v4 12/15] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table()

2024-12-30 Thread Qi Zheng
To unify the PxD and PTE TLB free path, also move the pagetable_dtor() of PMD|PUD|P4D to __tlb_remove_table(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-s...@vger.kernel.org --- arch/s390/include/asm/tlb.h | 3 --- arch/s390/mm/pgalloc.c | 14

[PATCH v4 14/15] mm: pgtable: move __tlb_remove_table_one() in x86 to generic file

2024-12-30 Thread Qi Zheng
The __tlb_remove_table_one() in x86 does not contain architecture-specific content, so move it to the generic file. Signed-off-by: Qi Zheng --- arch/x86/include/asm/tlb.h | 19 --- mm/mmu_gather.c| 20 ++-- 2 files changed, 18 insertions(+), 21

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

2024-12-30 Thread Qi Zheng
s390 also calls generic pagetable_dtor_free(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/s390/mm/pgalloc.c| 6 -- include/asm-generic/pgalloc.h | 12 include/asm-generic/tlb.h | 3 +-- include/linux/mm.h| 6 ++ 4 files c

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

2024-12-30 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 v4 06/15] s390: pgtable: add statistics for PUD and P4D level page table

2024-12-30 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) Cc: linux-s...@vger.kernel.org --- arch/s390/include/asm/pgalloc.h | 29 +++--- arch/s390/include/asm/tlb.h | 37

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

2024-12-30 Thread Qi Zheng
orted architectures, so we might as well include this check in the generic implementation. No runtime check is required in p4d_alloc_one() as the top-level p4d_alloc() already does the required check. Signed-off-by: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng --- arch/arm64/includ

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

2024-12-30 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. By the way, move the comment above __tlb_remove_table() to riscv_tlb_remove_ptdesc(), it will be more appropriate. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: lin

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

2024-12-30 Thread Qi Zheng
This reverts commit 2f3443770437e49abc39af26962d293851cbab6d. Signed-off-by: Qi Zheng --- include/linux/mm.h | 2 +- include/linux/mm_types.h | 9 + mm/memory.c | 22 ++ 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/include

[PATCH v4 08/15] arm: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-30 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm/include/asm/tlb.h | 9 - 1 file changed, 4 insertions(+), 5 dele

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

2024-12-30 Thread Qi Zheng
d-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) --- Documentation/mm/split_page_table_lock.rst | 4 +- arch/arm/include/asm/tlb.h | 4 +- arch/arm64/include/asm/tlb.h | 8 ++-- arch/csky/include/asm/pgalloc.h| 2 +- arch/hexagon/include/asm/p

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

2024-12-30 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) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 1 - arch/arm64/include/asm/tlb.h | 14

[PATCH v4 04/15] mm: pgtable: add statistics for P4D level page table

2024-12-30 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) --- arch/riscv/include/asm/pgalloc.h | 6 +- arch/x86/mm/pgtable.c| 3 +++ include/asm-generic/pgalloc.h| 2 ++ include/linux/mm.h

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

2024-12-30 Thread Qi Zheng
generic version, so we remove it altogether. This is consistent with the way arm64 and x86 handle this situation (runtime check in p4d_free() only). Signed-off-by: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng Acked-by: Palmer Dabbelt --- arch/riscv/include/asm/pgalloc.h | 22

[PATCH v4 00/15] move pagetable_*_dtor() to __tlb_remove_table()

2024-12-30 Thread Qi Zheng
loc: Provide generic p4d_{alloc_one,free} Qi Zheng (13): Revert "mm: pgtable: make ptlock be freed by RCU" mm: pgtable: add statistics for P4D level page table arm64: pgtable: use mmu gather to free p4d level page table s390: pgtable: add statistics for PUD and P4D level page tab

Re: [PATCH v3 15/17] mm: pgtable: remove tlb_remove_page_ptdesc()

2024-12-29 Thread Qi Zheng
Hi Andrew, On 2024/12/30 12:55, Andrew Morton wrote: On Mon, 30 Dec 2024 11:12:00 +0800 Qi Zheng wrote: For now struct ptdesc overlaps struct page, but the goal is to have them separate and always operate on struct ptdesc when working with page tables. OK, so tlb_remove_page_ptdesc() and

Re: [PATCH v3 15/17] mm: pgtable: remove tlb_remove_page_ptdesc()

2024-12-29 Thread Qi Zheng
Hi Mike, On 2024/12/28 17:26, Mike Rapoport wrote: On Mon, Dec 23, 2024 at 05:41:01PM +0800, Qi Zheng wrote: Here we are explicitly dealing with struct page, and the following logic semms strange: tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); tlb_remove_page_ptdesc --> tlb_remove_p

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

2024-12-27 Thread Qi Zheng
: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng ---  arch/riscv/include/asm/pgalloc.h | 22 --  1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/arch/riscv/include/asm/pgalloc.h b/arch/riscv/include/asm/pgalloc.h index f52264304f772..8ad0bbe838a24

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

2024-12-23 Thread Qi Zheng
d-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) --- Documentation/mm/split_page_table_lock.rst | 4 +- arch/arm/include/asm/tlb.h | 4 +- arch/arm64/include/asm/tlb.h | 8 ++-- arch/csky/include/asm/pgalloc.h| 2 +- arch/hexagon/include/asm/p

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

2024-12-23 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm/include/asm/tlb.h | 9 - 1 file changed, 4 insertions(+), 5 dele

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

2024-12-23 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) --- arch/riscv/include/asm/pgalloc.h | 6 +- arch/x86/mm/pgtable.c| 3 +++ include/asm-generic/pgalloc.h| 2 ++ include/linux/mm.h

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

2024-12-23 Thread Qi Zheng
orted architectures, so we might as well include this check in the generic implementation. No runtime check is required in p4d_alloc_one() as the top-level p4d_alloc() already does the required check. Signed-off-by: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng --- arch/arm64/includ

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

2024-12-23 Thread Qi Zheng
x27;s s390 also calls generic pagetable_dtor_free(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) --- arch/s390/mm/pgalloc.c| 18 ++ include/asm-generic/pgalloc.h | 23 --- include/asm-generic/tlb.h | 5 + include/

[PATCH v3 16/17] mm: pgtable: remove tlb_remove_ptdesc()

2024-12-23 Thread Qi Zheng
Just like removing tlb_remove_page_ptdesc(), remove tlb_remove_ptdesc() as well, and make callers call tlb_remove_table() directly. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) --- arch/arm/include/asm/tlb.h | 8 ++-- arch/arm64/include/asm/tlb.h | 16

[PATCH v3 15/17] mm: pgtable: remove tlb_remove_page_ptdesc()

2024-12-23 Thread Qi Zheng
tly. Signed-off-by: Qi Zheng Originally-by: Peter Zijlstra (Intel) --- arch/csky/include/asm/pgalloc.h | 2 +- arch/hexagon/include/asm/pgalloc.h | 2 +- arch/loongarch/include/asm/pgalloc.h | 2 +- arch/m68k/include/asm/sun3_pgalloc.h | 2 +- arch/mips/include/asm/pgalloc.h | 2 +- arch/ni

[PATCH v3 14/17] mm: pgtable: move __tlb_remove_table_one() in x86 to generic file

2024-12-23 Thread Qi Zheng
The __tlb_remove_table_one() in x86 does not contain architecture-specific content, so move it to the generic file. Signed-off-by: Qi Zheng --- arch/x86/include/asm/tlb.h | 19 --- mm/mmu_gather.c| 20 ++-- 2 files changed, 18 insertions(+), 21

[PATCH v3 13/17] mm: pgtable: introduce generic __tlb_remove_table()

2024-12-23 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 v3 12/17] s390: pgtable: also move pagetable_dtor() of PxD to __tlb_remove_table()

2024-12-23 Thread Qi Zheng
To unify the PxD and PTE TLB free path, also move the pagetable_dtor() of PMD|PUD|P4D to __tlb_remove_table(). Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-s...@vger.kernel.org --- arch/s390/include/asm/tlb.h | 3 --- arch/s390/mm/pgalloc.c | 14

[PATCH v3 11/17] x86: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-23 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: x...@kernel.org --- arch/x86/include/asm/tlb.h | 17 ++--- arch/x86/kernel/paravirt.c | 1 + arch/x86/mm/pgta

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

2024-12-23 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/tlb.h | 10 -- 1 file changed, 4 insertions(+), 6 dele

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

2024-12-23 Thread Qi Zheng
have swap cache, so use pagetable_free() instead of free_page_and_swap_cache() to free page table pages. By the way, move the comment above __tlb_remove_table() to riscv_tlb_remove_ptdesc(), it will be more appropriate. Signed-off-by: Qi Zheng Suggested-by: Peter Zijlstra (Intel) Cc: lin

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

2024-12-23 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) Cc: linux-s...@vger.kernel.org --- arch/s390/include/asm/pgalloc.h | 29 +++--- arch/s390/include/asm/tlb.h | 37

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

2024-12-23 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) Cc: linux-arm-ker...@lists.infradead.org --- arch/arm64/include/asm/pgalloc.h | 1 - arch/arm64/include/asm/tlb.h | 14

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

2024-12-23 Thread Qi Zheng
generic version, so we remove it altogether. This is consistent with the way arm64 and x86 handle this situation (runtime check in p4d_free() only). Signed-off-by: Kevin Brodsky Acked-by: Dave Hansen Signed-off-by: Qi Zheng --- arch/riscv/include/asm/pgalloc.h | 22 -- 1 file

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

2024-12-23 Thread Qi Zheng
This reverts commit 2f3443770437e49abc39af26962d293851cbab6d. Signed-off-by: Qi Zheng --- include/linux/mm.h | 2 +- include/linux/mm_types.h | 9 + mm/memory.c | 22 ++ 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/include

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

2024-12-23 Thread Qi Zheng
lloc_one asm-generic: pgalloc: Provide generic p4d_{alloc_one,free} Qi Zheng (15): Revert "mm: pgtable: make ptlock be freed by RCU" mm: pgtable: add statistics for P4D level page table arm64: pgtable: use mmu gather to free p4d level page table s390: pgtable: add statist

Re: [PATCH 01/10] mm: Move common parts of pagetable_*_[cd]tor to helpers

2024-12-20 Thread Qi Zheng
On 2024/12/20 22:28, Kevin Brodsky wrote: On 20/12/2024 15:16, Qi Zheng wrote: Did I miss something? My patch series is not only for cleanup, but also for fixes of UAF issue [1], so is it possible to rebase your patch series onto mine? I can post v3 ASAP. I see, yours should be merged

Re: [PATCH 01/10] mm: Move common parts of pagetable_*_[cd]tor to helpers

2024-12-20 Thread Qi Zheng
On 2024/12/20 21:50, Kevin Brodsky wrote: On 20/12/2024 12:46, Qi Zheng wrote: Hi Kevin, On 2024/12/20 18:49, Kevin Brodsky wrote: [...] Qi, shall we collaborate to make our series complementary? I believe my series covers patch 2 and 4 of your series, but it goes further by covering all

Re: [PATCH 01/10] mm: Move common parts of pagetable_*_[cd]tor to helpers

2024-12-20 Thread Qi Zheng
Hi Kevin, On 2024/12/20 18:49, Kevin Brodsky wrote: Hi Peter, Qi, On 19/12/2024 18:19, Peter Zijlstra wrote: On Thu, Dec 19, 2024 at 04:44:16PM +, Kevin Brodsky wrote: Besides the ptlock management at PTE/PMD level, all the pagetable_*_[cd]tor have the same implementation. Introduce commo