Skip to content

Commit b63c129

Browse files
hansendcgregkh
authored andcommitted
x86/mm: use 'ptdesc' when freeing PMD pages
commit 412d000 upstream. There are a billion ways to refer to a physical memory address. One of the x86 PMD freeing code location chooses to use a 'pte_t *' to point to a PMD page and then call a PTE-specific freeing function for it. That's a bit wonky. Just use a 'struct ptdesc *' instead. Its entire purpose is to refer to page table pages. It also means being able to remove an explicit cast. Right now, pte_free_kernel() is a one-liner that calls pagetable_dtor_free(). Effectively, all this patch does is remove one superfluous __pa(__va(paddr)) conversion and then call pagetable_dtor_free() directly instead of through a helper. Link: https://lkml.kernel.org/r/20251022082635.2462433-5-baolu.lu@linux.intel.com Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Betkov <bp@alien8.de> Cc: David Hildenbrand <david@redhat.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jann Horn <jannh@google.com> Cc: Jean-Philippe Brucker <jean-philippe@linaro.org> Cc: Joerg Roedel <joro@8bytes.org> Cc: Liam Howlett <liam.howlett@oracle.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Michal Hocko <mhocko@kernel.org> Cc: Mike Rapoport (Microsoft) <rppt@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Robin Murohy <robin.murphy@arm.com> Cc: Thomas Gleinxer <tglx@linutronix.de> Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com> Cc: Vasant Hegde <vasant.hegde@amd.com> Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Will Deacon <will@kernel.org> Cc: Yi Lai <yi1.lai@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 83ce8bf commit b63c129

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

arch/x86/mm/pgtable.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ int pmd_clear_huge(pmd_t *pmd)
729729
int pud_free_pmd_page(pud_t *pud, unsigned long addr)
730730
{
731731
pmd_t *pmd, *pmd_sv;
732-
pte_t *pte;
732+
struct ptdesc *pt;
733733
int i;
734734

735735
pmd = pud_pgtable(*pud);
@@ -750,8 +750,8 @@ int pud_free_pmd_page(pud_t *pud, unsigned long addr)
750750

751751
for (i = 0; i < PTRS_PER_PMD; i++) {
752752
if (!pmd_none(pmd_sv[i])) {
753-
pte = (pte_t *)pmd_page_vaddr(pmd_sv[i]);
754-
pte_free_kernel(&init_mm, pte);
753+
pt = page_ptdesc(pmd_page(pmd_sv[i]));
754+
pagetable_dtor_free(pt);
755755
}
756756
}
757757

@@ -772,15 +772,15 @@ int pud_free_pmd_page(pud_t *pud, unsigned long addr)
772772
*/
773773
int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
774774
{
775-
pte_t *pte;
775+
struct ptdesc *pt;
776776

777-
pte = (pte_t *)pmd_page_vaddr(*pmd);
777+
pt = page_ptdesc(pmd_page(*pmd));
778778
pmd_clear(pmd);
779779

780780
/* INVLPG to clear all paging-structure caches */
781781
flush_tlb_kernel_range(addr, addr + PAGE_SIZE-1);
782782

783-
pte_free_kernel(&init_mm, pte);
783+
pagetable_dtor_free(pt);
784784

785785
return 1;
786786
}

0 commit comments

Comments
 (0)