mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 22:52:19 +02:00
x86: pgtable: move pagetable_dtor() to __tlb_remove_table()
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. Link: https://lkml.kernel.org/r/27b3cdc8786bebd4f748380bf82f796482718504.1736317725.git.zhengqi.arch@bytedance.com Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com> Suggested-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Alexandre Ghiti <alex@ghiti.fr> Cc: Alexandre Ghiti <alexghiti@rivosinc.com> Cc: Andreas Larsson <andreas@gaisler.com> Cc: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> 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: 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>
This commit is contained in:
parent
0b6476f939
commit
ee0934b035
|
|
@ -33,6 +33,7 @@ static inline void __tlb_remove_table(void *table)
|
|||
{
|
||||
struct ptdesc *ptdesc = (struct ptdesc *)table;
|
||||
|
||||
pagetable_dtor(ptdesc);
|
||||
pagetable_free(ptdesc);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ static void native_tlb_remove_table(struct mmu_gather *tlb, void *table)
|
|||
{
|
||||
struct ptdesc *ptdesc = (struct ptdesc *)table;
|
||||
|
||||
pagetable_dtor(ptdesc);
|
||||
tlb_remove_page(tlb, ptdesc_page(ptdesc));
|
||||
}
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ void paravirt_tlb_remove_table(struct mmu_gather *tlb, void *table)
|
|||
{
|
||||
struct ptdesc *ptdesc = (struct ptdesc *)table;
|
||||
|
||||
pagetable_dtor(ptdesc);
|
||||
tlb_remove_page(tlb, ptdesc_page(ptdesc));
|
||||
}
|
||||
#else
|
||||
|
|
@ -62,7 +63,6 @@ early_param("userpte", setup_userpte);
|
|||
|
||||
void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
|
||||
{
|
||||
pagetable_dtor(page_ptdesc(pte));
|
||||
paravirt_release_pte(page_to_pfn(pte));
|
||||
paravirt_tlb_remove_table(tlb, page_ptdesc(pte));
|
||||
}
|
||||
|
|
@ -70,7 +70,6 @@ void ___pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
|
|||
#if CONFIG_PGTABLE_LEVELS > 2
|
||||
void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
|
||||
{
|
||||
struct ptdesc *ptdesc = virt_to_ptdesc(pmd);
|
||||
paravirt_release_pmd(__pa(pmd) >> PAGE_SHIFT);
|
||||
/*
|
||||
* NOTE! For PAE, any changes to the top page-directory-pointer-table
|
||||
|
|
@ -79,28 +78,21 @@ void ___pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd)
|
|||
#ifdef CONFIG_X86_PAE
|
||||
tlb->need_flush_all = 1;
|
||||
#endif
|
||||
pagetable_dtor(ptdesc);
|
||||
paravirt_tlb_remove_table(tlb, ptdesc);
|
||||
paravirt_tlb_remove_table(tlb, virt_to_ptdesc(pmd));
|
||||
}
|
||||
|
||||
#if CONFIG_PGTABLE_LEVELS > 3
|
||||
void ___pud_free_tlb(struct mmu_gather *tlb, pud_t *pud)
|
||||
{
|
||||
struct ptdesc *ptdesc = virt_to_ptdesc(pud);
|
||||
|
||||
pagetable_dtor(ptdesc);
|
||||
paravirt_release_pud(__pa(pud) >> PAGE_SHIFT);
|
||||
paravirt_tlb_remove_table(tlb, ptdesc);
|
||||
paravirt_tlb_remove_table(tlb, virt_to_ptdesc(pud));
|
||||
}
|
||||
|
||||
#if CONFIG_PGTABLE_LEVELS > 4
|
||||
void ___p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d)
|
||||
{
|
||||
struct ptdesc *ptdesc = virt_to_ptdesc(p4d);
|
||||
|
||||
pagetable_dtor(ptdesc);
|
||||
paravirt_release_p4d(__pa(p4d) >> PAGE_SHIFT);
|
||||
paravirt_tlb_remove_table(tlb, ptdesc);
|
||||
paravirt_tlb_remove_table(tlb, virt_to_ptdesc(p4d));
|
||||
}
|
||||
#endif /* CONFIG_PGTABLE_LEVELS > 4 */
|
||||
#endif /* CONFIG_PGTABLE_LEVELS > 3 */
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user