]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sparc64: remove hugetlb_free_pgd_range()
authorAnthony Yznaga <anthony.yznaga@oracle.com>
Wed, 16 Jul 2025 01:26:09 +0000 (18:26 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 25 Jul 2025 02:12:31 +0000 (19:12 -0700)
Patch series "drop hugetlb_free_pgd_range()".

For all architectures that support hugetlb except for sparc,
hugetlb_free_pgd_range() just calls free_pgd_range().  It turns out the
sparc implementation is essentially identical to free_pgd_range() and can
be removed.  Remove it and update free_pgtables() to treat hugetlb VMAs
the same as others.

This patch (of 3):

The sparc implementation of hugetlb_free_pgd_range() is identical to
free_pgd_range() with the exception of checking for and skipping possible
leaf entries at the PUD and PMD levels.

These checks are unnecessary because any huge pages have been freed and
their PTEs cleared by the time page tables needed to map them are freed.
While some huge page sizes do populate the page table with multiple PTEs,
they are correctly cleared by huge_ptep_get_and_clear().

To verify this, libhugetlbfs tests were run for 64K, 8M, and 256M page
sizes with an instrumented kernel on a qemu guest modified to support the
256M page size.  The same tests were used to verify no regressions after
applying this patch and were also run on x86 for both 2M and 1G page
sizes.

Link: https://lkml.kernel.org/r/20250716012611.10369-1-anthony.yznaga@oracle.com
Link: https://lkml.kernel.org/r/20250716012611.10369-2-anthony.yznaga@oracle.com
Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Acked-by: Oscar Salvador <osalvador@suse.de>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Ghiti <alexghiti@rivosinc.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: David Hildenbrand <david@redhat.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/sparc/include/asm/hugetlb.h
arch/sparc/mm/hugetlbpage.c

index e7a9cdd498dca6bf035b11e94e4951cc3f31d31b..d3bc16fbcbbd572a86560a18baac853ab2733801 100644 (file)
@@ -50,11 +50,6 @@ static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
        return changed;
 }
 
-#define __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE
-void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr,
-                           unsigned long end, unsigned long floor,
-                           unsigned long ceiling);
-
 #include <asm-generic/hugetlb.h>
 
 #endif /* _ASM_SPARC64_HUGETLB_H */
index 80504148d8a5bf527919ae07955053594b395043..4b9431311e059ba70a623beaf0df8042b0e97923 100644 (file)
@@ -295,122 +295,3 @@ pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
 
        return entry;
 }
-
-static void hugetlb_free_pte_range(struct mmu_gather *tlb, pmd_t *pmd,
-                          unsigned long addr)
-{
-       pgtable_t token = pmd_pgtable(*pmd);
-
-       pmd_clear(pmd);
-       pte_free_tlb(tlb, token, addr);
-       mm_dec_nr_ptes(tlb->mm);
-}
-
-static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
-                                  unsigned long addr, unsigned long end,
-                                  unsigned long floor, unsigned long ceiling)
-{
-       pmd_t *pmd;
-       unsigned long next;
-       unsigned long start;
-
-       start = addr;
-       pmd = pmd_offset(pud, addr);
-       do {
-               next = pmd_addr_end(addr, end);
-               if (pmd_none(*pmd))
-                       continue;
-               if (is_hugetlb_pmd(*pmd))
-                       pmd_clear(pmd);
-               else
-                       hugetlb_free_pte_range(tlb, pmd, addr);
-       } while (pmd++, addr = next, addr != end);
-
-       start &= PUD_MASK;
-       if (start < floor)
-               return;
-       if (ceiling) {
-               ceiling &= PUD_MASK;
-               if (!ceiling)
-                       return;
-       }
-       if (end - 1 > ceiling - 1)
-               return;
-
-       pmd = pmd_offset(pud, start);
-       pud_clear(pud);
-       pmd_free_tlb(tlb, pmd, start);
-       mm_dec_nr_pmds(tlb->mm);
-}
-
-static void hugetlb_free_pud_range(struct mmu_gather *tlb, p4d_t *p4d,
-                                  unsigned long addr, unsigned long end,
-                                  unsigned long floor, unsigned long ceiling)
-{
-       pud_t *pud;
-       unsigned long next;
-       unsigned long start;
-
-       start = addr;
-       pud = pud_offset(p4d, addr);
-       do {
-               next = pud_addr_end(addr, end);
-               if (pud_none_or_clear_bad(pud))
-                       continue;
-               if (is_hugetlb_pud(*pud))
-                       pud_clear(pud);
-               else
-                       hugetlb_free_pmd_range(tlb, pud, addr, next, floor,
-                                              ceiling);
-       } while (pud++, addr = next, addr != end);
-
-       start &= PGDIR_MASK;
-       if (start < floor)
-               return;
-       if (ceiling) {
-               ceiling &= PGDIR_MASK;
-               if (!ceiling)
-                       return;
-       }
-       if (end - 1 > ceiling - 1)
-               return;
-
-       pud = pud_offset(p4d, start);
-       p4d_clear(p4d);
-       pud_free_tlb(tlb, pud, start);
-       mm_dec_nr_puds(tlb->mm);
-}
-
-void hugetlb_free_pgd_range(struct mmu_gather *tlb,
-                           unsigned long addr, unsigned long end,
-                           unsigned long floor, unsigned long ceiling)
-{
-       pgd_t *pgd;
-       p4d_t *p4d;
-       unsigned long next;
-
-       addr &= PMD_MASK;
-       if (addr < floor) {
-               addr += PMD_SIZE;
-               if (!addr)
-                       return;
-       }
-       if (ceiling) {
-               ceiling &= PMD_MASK;
-               if (!ceiling)
-                       return;
-       }
-       if (end - 1 > ceiling - 1)
-               end -= PMD_SIZE;
-       if (addr > end - 1)
-               return;
-
-       pgd = pgd_offset(tlb->mm, addr);
-       p4d = p4d_offset(pgd, addr);
-       do {
-               next = p4d_addr_end(addr, end);
-               if (p4d_none_or_clear_bad(p4d))
-                       continue;
-               hugetlb_free_pud_range(tlb, p4d, addr, next, floor, ceiling);
-       } while (p4d++, addr = next, addr != end);
-}