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

2024-12-23 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 v3 08/17] arm: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-23 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 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
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 v3 17/17] mm: pgtable: introduce generic pagetable_dtor_free()

2024-12-23 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 actually does the same thing, so let's s390 a

[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
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_page(tlb, ptdesc_page(pt)); So remove tlb_remove_page_ptdesc() and make callers call tlb_remove_page() directly. Signe

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

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

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

2024-12-23 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 v3 09/17] arm64: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-23 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 v3 10/17] riscv: pgtable: move pagetable_dtor() to __tlb_remove_table()

2024-12-23 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 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
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 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/linux

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

2024-12-23 Thread Qi Zheng
Changes in v3: - take patch #5 and #6 from Kevin Brodsky's patch series below. Link: https://lore.kernel.org/lkml/20241219164425.2277022-1-kevin.brod...@arm.com/ - separate the statistics part from [PATCH v2 02/15] as [PATCH v3 04/17], and replace the rest part with Kevin Brodsky's patch #

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

2024-12-23 Thread Borislav Petkov
On Mon, Dec 23, 2024 at 03:32:01PM +0800, Weikang Guo wrote: > First of all, thank you for your reminder and patience. In fact, this > is the first time I received a patch discussion when submitting a > patch. > About Reviewed-by or Acked-by tags, I will not add it myself in the > future. Regarding