mirror of
https://github.com/torvalds/linux.git
synced 2026-12-03 20:06:35 +00:00
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. Later, pagetable_dtor() will be moved to tlb_remove_ptdesc(), 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. Link: https://lkml.kernel.org/r/47f44fff9dc68d9d9e9a0d6c036df275f820598a.1736317725.git.zhengqi.arch@bytedance.com Signed-off-by: Qi Zheng <[email protected]> Originally-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Kevin Brodsky <[email protected]> Acked-by: Alexander Gordeev <[email protected]> [s390] Cc: Alexandre Ghiti <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Andreas Larsson <[email protected]> Cc: Aneesh Kumar K.V (Arm) <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Dave Hansen <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Rientjes <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Jann Horn <[email protected]> Cc: Lorenzo Stoakes <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Mike Rapoport (Microsoft) <[email protected]> Cc: Muchun Song <[email protected]> Cc: Nicholas Piggin <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Vishal Moola (Oracle) <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yu Zhao <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_SH_PGALLOC_H
|
|
#define __ASM_SH_PGALLOC_H
|
|
|
|
#include <linux/mm.h>
|
|
#include <asm/page.h>
|
|
|
|
#define __HAVE_ARCH_PMD_ALLOC_ONE
|
|
#define __HAVE_ARCH_PMD_FREE
|
|
#define __HAVE_ARCH_PGD_FREE
|
|
#include <asm-generic/pgalloc.h>
|
|
|
|
extern pgd_t *pgd_alloc(struct mm_struct *);
|
|
extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
|
|
|
|
#if PAGETABLE_LEVELS > 2
|
|
extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
|
|
extern pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address);
|
|
extern void pmd_free(struct mm_struct *mm, pmd_t *pmd);
|
|
#define __pmd_free_tlb(tlb, pmdp, addr) pmd_free((tlb)->mm, (pmdp))
|
|
#endif
|
|
|
|
static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
|
|
pte_t *pte)
|
|
{
|
|
set_pmd(pmd, __pmd((unsigned long)pte));
|
|
}
|
|
|
|
static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
|
|
pgtable_t pte)
|
|
{
|
|
set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
|
|
}
|
|
|
|
#define __pte_free_tlb(tlb, pte, addr) \
|
|
do { \
|
|
pagetable_dtor(page_ptdesc(pte)); \
|
|
tlb_remove_page_ptdesc((tlb), (page_ptdesc(pte))); \
|
|
} while (0)
|
|
|
|
#endif /* __ASM_SH_PGALLOC_H */
|