Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

riscv: mm: skip pgtable level check in {pud,p4d}_alloc_one

Patch series "move pagetable_*_dtor() to __tlb_remove_table()", v5.

As proposed [1] by Peter Zijlstra below, this patch series aims to move
pagetable_*_dtor() into __tlb_remove_table(). This will cleanup
pagetable_*_dtor() a bit and more gracefully fix the UAF issue [2]
reported by syzbot.

: Notably:
:
: - s390 pud isn't calling the existing pagetable_pud_[cd]tor()
: - none of the p4d things have pagetable_p4d_[cd]tor() (x86,arm64,s390,riscv)
: and they have inconsistent accounting
: - while much of the _ctor calls are in generic code, many of the _dtor
: calls are in arch code for hysterial raisins, this could easily be
: fixed
: - if we fix ptlock_free() to handle NULL, then all the _dtor()
: functions can use it, and we can observe they're all identical
: and can be folded
:
: after all that cleanup, you can move the _dtor from *_free_tlb() into
: tlb_remove_table() -- which for the above case, would then have it called
: from __tlb_remove_table_free().


This patch (of 16):

{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 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).

Link: https://lkml.kernel.org/r/cover.1736317725.git.zhengqi.arch@bytedance.com
Link: https://lkml.kernel.org/r/93a1c6bddc0ded9f1a9f15658c1e4af5c93d1194.1736317725.git.zhengqi.arch@bytedance.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kevin Brodsky and committed by
Andrew Morton
5a32443f 1aa43598

+4 -18
+4 -18
arch/riscv/include/asm/pgalloc.h
··· 12 12 #include <asm/tlb.h> 13 13 14 14 #ifdef CONFIG_MMU 15 - #define __HAVE_ARCH_PUD_ALLOC_ONE 16 15 #define __HAVE_ARCH_PUD_FREE 17 16 #include <asm-generic/pgalloc.h> 18 17 ··· 87 88 } 88 89 } 89 90 90 - #define pud_alloc_one pud_alloc_one 91 - static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) 92 - { 93 - if (pgtable_l4_enabled) 94 - return __pud_alloc_one(mm, addr); 95 - 96 - return NULL; 97 - } 98 - 99 91 #define pud_free pud_free 100 92 static inline void pud_free(struct mm_struct *mm, pud_t *pud) 101 93 { ··· 108 118 #define p4d_alloc_one p4d_alloc_one 109 119 static inline p4d_t *p4d_alloc_one(struct mm_struct *mm, unsigned long addr) 110 120 { 111 - if (pgtable_l5_enabled) { 112 - gfp_t gfp = GFP_PGTABLE_USER; 121 + gfp_t gfp = GFP_PGTABLE_USER; 113 122 114 - if (mm == &init_mm) 115 - gfp = GFP_PGTABLE_KERNEL; 116 - return (p4d_t *)get_zeroed_page(gfp); 117 - } 118 - 119 - return NULL; 123 + if (mm == &init_mm) 124 + gfp = GFP_PGTABLE_KERNEL; 125 + return (p4d_t *)get_zeroed_page(gfp); 120 126 } 121 127 122 128 static inline void __p4d_free(struct mm_struct *mm, p4d_t *p4d)