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 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 16/17] mm: pgtable: move __tlb_remove_table_one() in x86 to generic file

2025-01-07 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 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 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 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 12/17] x86: 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. Signed-off-by: Qi Zheng

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

[PATCH v5 13/13] mm: pgtable: remove pte_offset_map_nolock()

2024-09-25 Thread Qi Zheng
Now no users are using the pte_offset_map_nolock(), remove it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand --- Documentation/mm/split_page_table_lock.rst | 3 --- include/linux/mm.h | 2 -- mm/pgtable-generic.c

[PATCH v5 12/13] mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand --- mm/vmscan.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c745..bdca94e663bc5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3375,8 +3375,10 @@ static bool

[PATCH v5 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
In move_pages_pte(), we may modify the dst_pte and src_pte after acquiring the ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will use pte_same() to detect the change of the pte entry, there is no need to get pmdval, so just pass a dummy variable to it. Signed-off-by: Qi

[PATCH v5 10/13] mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
y of pvmw->pmd. Signed-off-by: Qi Zheng --- mm/page_vma_mapped.c | 24 ++-- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index ae5cc42aa2087..ab1671e71cb2d 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mappe

[PATCH v5 09/13] mm: mremap: move_ptes() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
we already hold the exclusive mmap_lock, so this new_pte page is stable, so there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/mremap.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b

[PATCH v5 08/13] mm: copy_pte_range() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
ble, there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/memory.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 6432b636d1ba7..c19cf14e1c565 100644 --- a/mm/memory.c +++ b

[PATCH v5 07/13] mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
: Qi Zheng --- mm/khugepaged.c | 18 +- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6498721d4783a..854577f39957d 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1605,7 +1605,7 @@ int collapse_pte_mapped_thp(struct

[PATCH v5 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
In handle_pte_fault(), we may modify the vmf->pte after acquiring the vmf->ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng

[PATCH v5 05/13] arm: adjust_pte() use pte_offset_map_rw_nolock()

2024-09-25 Thread Qi Zheng
of update_mmu_cache_range() hold the vmf->ptl, so we can determined whether split PTE locks is being used by doing the following, just as we do elsewhere in the kernel. ptl != vmf->ptl And then we can delete the do_pte_lock() and do_pte_unlock(). Signed-off-by: Qi Zheng Acked-by:

[PATCH v5 04/13] mm: khugepaged: __collapse_huge_page_swapin() use pte_offset_map_ro_nolock()

2024-09-25 Thread Qi Zheng
In __collapse_huge_page_swapin(), we just use the ptl for pte_same() check in do_swap_page(). In other places, we directly use pte_offset_map_lock(), so convert it to using pte_offset_map_ro_nolock(). Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- mm

[PATCH v5 03/13] mm: filemap: filemap_fault_recheck_pte_none() use pte_offset_map_ro_nolock()

2024-09-25 Thread Qi Zheng
In filemap_fault_recheck_pte_none(), we just do pte_none() check, so convert it to using pte_offset_map_ro_nolock(). Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- mm/filemap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm

[PATCH v5 02/13] powerpc: assert_pte_locked() use pte_offset_map_ro_nolock()

2024-09-25 Thread Qi Zheng
In assert_pte_locked(), we just get the ptl and assert if it was already held, so convert it to using pte_offset_map_ro_nolock(). Signed-off-by: Qi Zheng Acked-by: David Hildenbrand Reviewed-by: Muchun Song --- arch/powerpc/mm/pgtable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion

[PATCH v5 01/13] mm: pgtable: introduce pte_offset_map_{ro|rw}_nolock()

2024-09-25 Thread Qi Zheng
presses the intended semantics, not that the *kmap* will be read-only/read-write protected. Subsequent commits will convert pte_offset_map_nolock() into the above two functions one by one, and finally completely delete it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Acked-by: David Hildenbrand -

[PATCH v5 00/13] introduce pte_offset_map_{ro|rw}_nolock()

2024-09-25 Thread Qi Zheng
series will convert all pte_offset_map_nolock() into the above two helper functions one by one, and finally completely delete it. This also a preparation for reclaiming the empty user PTE page table pages. This series is based on the next-20240926. Comments and suggestions are welcome! Thanks,

Re: [PATCH v4 07/13] mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock()

2024-09-24 Thread Qi Zheng
On 2024/9/24 16:52, Muchun Song wrote: On Sep 24, 2024, at 15:29, Qi Zheng wrote: On 2024/9/24 15:14, Muchun Song wrote: On Sep 24, 2024, at 14:11, Qi Zheng wrote: In collapse_pte_mapped_thp(), we may modify the pte and pmd entry after acquring the ptl, so convert it to using

Re: [PATCH v4 10/13] mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock()

2024-09-24 Thread Qi Zheng
On 2024/9/24 16:39, Muchun Song wrote: On Sep 24, 2024, at 16:33, Qi Zheng wrote: On 2024/9/24 16:25, Muchun Song wrote: On Sep 24, 2024, at 14:11, Qi Zheng wrote: In the caller of map_pte(), we may modify the pvmw->pte after acquiring the pvmw->ptl, so convert it to

Re: [PATCH v4 10/13] mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock()

2024-09-24 Thread Qi Zheng
On 2024/9/24 16:25, Muchun Song wrote: On Sep 24, 2024, at 14:11, Qi Zheng wrote: In the caller of map_pte(), we may modify the pvmw->pte after acquiring the pvmw->ptl, so convert it to using pte_offset_map_rw_nolock(). At this time, the pte_same() check is not performed after th

Re: [PATCH v4 07/13] mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock()

2024-09-24 Thread Qi Zheng
On 2024/9/24 15:14, Muchun Song wrote: On Sep 24, 2024, at 14:11, Qi Zheng wrote: In collapse_pte_mapped_thp(), we may modify the pte and pmd entry after acquring the ptl, so convert it to using pte_offset_map_rw_nolock(). At this time, the pte_same() check is not performed after the PTL

[PATCH v4 13/13] mm: pgtable: remove pte_offset_map_nolock()

2024-09-23 Thread Qi Zheng
Now no users are using the pte_offset_map_nolock(), remove it. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- Documentation/mm/split_page_table_lock.rst | 3 --- include/linux/mm.h | 2 -- mm/pgtable-generic.c | 21 - 3

[PATCH v4 12/13] mm: multi-gen LRU: walk_pte_range() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
: Qi Zheng Reviewed-by: Muchun Song --- mm/vmscan.c | 9 - 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 749cdc110c745..bdca94e663bc5 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3375,8 +3375,10 @@ static bool walk_pte_range(pmd_t *pmd

[PATCH v4 11/13] mm: userfaultfd: move_pages_pte() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
In move_pages_pte(), we may modify the dst_pte and src_pte after acquiring the ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will use pte_same() to detect the change of the pte entry, there is no need to get pmdval, so just pass a dummy variable to it. Signed-off-by: Qi

[PATCH v4 10/13] mm: page_vma_mapped_walk: map_pte() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
y of pvmw->pmd. Signed-off-by: Qi Zheng --- mm/page_vma_mapped.c | 25 - 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index ae5cc42aa2087..6410f29b37c1b 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mappe

[PATCH v4 09/13] mm: mremap: move_ptes() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
we already hold the exclusive mmap_lock, so this new_pte page is stable, so there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng --- mm/mremap.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 24712f8dbb

[PATCH v4 08/13] mm: copy_pte_range() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
ble, there is no need to get pmdval and do pmd_same() check. Signed-off-by: Qi Zheng --- mm/memory.c | 11 ++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 6432b636d1ba7..c19cf14e1c565 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1086,6 +108

[PATCH v4 07/13] mm: khugepaged: collapse_pte_mapped_thp() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
: Qi Zheng --- mm/khugepaged.c | 14 +++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6498721d4783a..8ab79c13d077f 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1605,7 +1605,7 @@ int collapse_pte_mapped_thp(struct

[PATCH v4 06/13] mm: handle_pte_fault() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
In handle_pte_fault(), we may modify the vmf->pte after acquiring the vmf->ptl, so convert it to using pte_offset_map_rw_nolock(). But since we will do the pte_same() check, so there is no need to get pmdval to do pmd_same() check, just pass a dummy variable to it. Signed-off-by: Qi Zheng

[PATCH v4 05/13] arm: adjust_pte() use pte_offset_map_rw_nolock()

2024-09-23 Thread Qi Zheng
of update_mmu_cache_range() hold the vmf->ptl, so we can determined whether split PTE locks is being used by doing the following, just as we do elsewhere in the kernel. ptl != vmf->ptl And then we can delete the do_pte_lock() and do_pte_unlock(). Signed-off-by: Qi Zheng Acked-by:

  1   2   >