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

sparc64: remove hugetlb_free_pgd_range()

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>

authored by

Anthony Yznaga and committed by
Andrew Morton
d0813985 6344a6d9

-124
-5
arch/sparc/include/asm/hugetlb.h
··· 50 50 return changed; 51 51 } 52 52 53 - #define __HAVE_ARCH_HUGETLB_FREE_PGD_RANGE 54 - void hugetlb_free_pgd_range(struct mmu_gather *tlb, unsigned long addr, 55 - unsigned long end, unsigned long floor, 56 - unsigned long ceiling); 57 - 58 53 #include <asm-generic/hugetlb.h> 59 54 60 55 #endif /* _ASM_SPARC64_HUGETLB_H */
-119
arch/sparc/mm/hugetlbpage.c
··· 295 295 296 296 return entry; 297 297 } 298 - 299 - static void hugetlb_free_pte_range(struct mmu_gather *tlb, pmd_t *pmd, 300 - unsigned long addr) 301 - { 302 - pgtable_t token = pmd_pgtable(*pmd); 303 - 304 - pmd_clear(pmd); 305 - pte_free_tlb(tlb, token, addr); 306 - mm_dec_nr_ptes(tlb->mm); 307 - } 308 - 309 - static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud, 310 - unsigned long addr, unsigned long end, 311 - unsigned long floor, unsigned long ceiling) 312 - { 313 - pmd_t *pmd; 314 - unsigned long next; 315 - unsigned long start; 316 - 317 - start = addr; 318 - pmd = pmd_offset(pud, addr); 319 - do { 320 - next = pmd_addr_end(addr, end); 321 - if (pmd_none(*pmd)) 322 - continue; 323 - if (is_hugetlb_pmd(*pmd)) 324 - pmd_clear(pmd); 325 - else 326 - hugetlb_free_pte_range(tlb, pmd, addr); 327 - } while (pmd++, addr = next, addr != end); 328 - 329 - start &= PUD_MASK; 330 - if (start < floor) 331 - return; 332 - if (ceiling) { 333 - ceiling &= PUD_MASK; 334 - if (!ceiling) 335 - return; 336 - } 337 - if (end - 1 > ceiling - 1) 338 - return; 339 - 340 - pmd = pmd_offset(pud, start); 341 - pud_clear(pud); 342 - pmd_free_tlb(tlb, pmd, start); 343 - mm_dec_nr_pmds(tlb->mm); 344 - } 345 - 346 - static void hugetlb_free_pud_range(struct mmu_gather *tlb, p4d_t *p4d, 347 - unsigned long addr, unsigned long end, 348 - unsigned long floor, unsigned long ceiling) 349 - { 350 - pud_t *pud; 351 - unsigned long next; 352 - unsigned long start; 353 - 354 - start = addr; 355 - pud = pud_offset(p4d, addr); 356 - do { 357 - next = pud_addr_end(addr, end); 358 - if (pud_none_or_clear_bad(pud)) 359 - continue; 360 - if (is_hugetlb_pud(*pud)) 361 - pud_clear(pud); 362 - else 363 - hugetlb_free_pmd_range(tlb, pud, addr, next, floor, 364 - ceiling); 365 - } while (pud++, addr = next, addr != end); 366 - 367 - start &= PGDIR_MASK; 368 - if (start < floor) 369 - return; 370 - if (ceiling) { 371 - ceiling &= PGDIR_MASK; 372 - if (!ceiling) 373 - return; 374 - } 375 - if (end - 1 > ceiling - 1) 376 - return; 377 - 378 - pud = pud_offset(p4d, start); 379 - p4d_clear(p4d); 380 - pud_free_tlb(tlb, pud, start); 381 - mm_dec_nr_puds(tlb->mm); 382 - } 383 - 384 - void hugetlb_free_pgd_range(struct mmu_gather *tlb, 385 - unsigned long addr, unsigned long end, 386 - unsigned long floor, unsigned long ceiling) 387 - { 388 - pgd_t *pgd; 389 - p4d_t *p4d; 390 - unsigned long next; 391 - 392 - addr &= PMD_MASK; 393 - if (addr < floor) { 394 - addr += PMD_SIZE; 395 - if (!addr) 396 - return; 397 - } 398 - if (ceiling) { 399 - ceiling &= PMD_MASK; 400 - if (!ceiling) 401 - return; 402 - } 403 - if (end - 1 > ceiling - 1) 404 - end -= PMD_SIZE; 405 - if (addr > end - 1) 406 - return; 407 - 408 - pgd = pgd_offset(tlb->mm, addr); 409 - p4d = p4d_offset(pgd, addr); 410 - do { 411 - next = p4d_addr_end(addr, end); 412 - if (p4d_none_or_clear_bad(p4d)) 413 - continue; 414 - hugetlb_free_pud_range(tlb, p4d, addr, next, floor, ceiling); 415 - } while (p4d++, addr = next, addr != end); 416 - }