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

Revert "mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge"

This reverts commit c742199a014de23ee92055c2473d91fe5561ffdf.

c742199a014d ("mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge")
breaks arm64 in at least two ways for configurations where PUD or PMD
folding occur:

1. We no longer install huge-vmap mappings and silently fall back to
page-granular entries, despite being able to install block entries
at what is effectively the PGD level.

2. If the linear map is backed with block mappings, these will now
silently fail to be created in alloc_init_pud(), causing a panic
early during boot.

The pgtable selftests caught this, although a fix has not been
forthcoming and Christophe is AWOL at the moment, so just revert the
change for now to get a working -rc3 on which we can queue patches for
5.15.

A simple revert breaks the build for 32-bit PowerPC 8xx machines, which
rely on the default function definitions when the corresponding
page-table levels are folded, since commit a6a8f7c4aa7e ("powerpc/8xx:
add support for huge pages on VMAP and VMALLOC"), eg:

powerpc64-linux-ld: mm/vmalloc.o: in function `vunmap_pud_range':
linux/mm/vmalloc.c:362: undefined reference to `pud_clear_huge'

To avoid that, add stubs for pud_clear_huge() and pmd_clear_huge() in
arch/powerpc/mm/nohash/8xx.c as suggested by Christophe.

Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Fixes: c742199a014d ("mm/pgtable: add stubs for {pmd/pub}_{set/clear}_huge")
Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Marc Zyngier <maz@kernel.org>
[mpe: Fold in 8xx.c changes from Christophe and mention in change log]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/linux-arm-kernel/CAMuHMdXShORDox-xxaeUfDW3wx2PeggFSqhVSHVZNKCGK-y_vQ@mail.gmail.com/
Link: https://lore.kernel.org/r/20210717160118.9855-1-jonathan@marek.ca
Link: https://lore.kernel.org/r/87r1fs1762.fsf@mpe.ellerman.id.au
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Jonathan Marek and committed by
Will Deacon
d8a71905 a7c3acca

+34 -56
+8 -12
arch/arm64/mm/mmu.c
··· 1339 1339 return dt_virt; 1340 1340 } 1341 1341 1342 - #if CONFIG_PGTABLE_LEVELS > 3 1343 1342 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) 1344 1343 { 1345 1344 pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot)); ··· 1353 1354 return 1; 1354 1355 } 1355 1356 1356 - int pud_clear_huge(pud_t *pudp) 1357 - { 1358 - if (!pud_sect(READ_ONCE(*pudp))) 1359 - return 0; 1360 - pud_clear(pudp); 1361 - return 1; 1362 - } 1363 - #endif 1364 - 1365 - #if CONFIG_PGTABLE_LEVELS > 2 1366 1357 int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) 1367 1358 { 1368 1359 pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot)); ··· 1367 1378 return 1; 1368 1379 } 1369 1380 1381 + int pud_clear_huge(pud_t *pudp) 1382 + { 1383 + if (!pud_sect(READ_ONCE(*pudp))) 1384 + return 0; 1385 + pud_clear(pudp); 1386 + return 1; 1387 + } 1388 + 1370 1389 int pmd_clear_huge(pmd_t *pmdp) 1371 1390 { 1372 1391 if (!pmd_sect(READ_ONCE(*pmdp))) ··· 1382 1385 pmd_clear(pmdp); 1383 1386 return 1; 1384 1387 } 1385 - #endif 1386 1388 1387 1389 int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) 1388 1390 {
+10
arch/powerpc/mm/nohash/8xx.c
··· 240 240 mtspr(SPRN_MD_AP, MD_APG_KUAP); 241 241 } 242 242 #endif 243 + 244 + int pud_clear_huge(pud_t *pud) 245 + { 246 + return 0; 247 + } 248 + 249 + int pmd_clear_huge(pmd_t *pmd) 250 + { 251 + return 0; 252 + }
+15 -19
arch/x86/mm/pgtable.c
··· 682 682 } 683 683 #endif 684 684 685 - #if CONFIG_PGTABLE_LEVELS > 3 686 685 /** 687 686 * pud_set_huge - setup kernel PUD mapping 688 687 * ··· 721 722 } 722 723 723 724 /** 724 - * pud_clear_huge - clear kernel PUD mapping when it is set 725 - * 726 - * Returns 1 on success and 0 on failure (no PUD map is found). 727 - */ 728 - int pud_clear_huge(pud_t *pud) 729 - { 730 - if (pud_large(*pud)) { 731 - pud_clear(pud); 732 - return 1; 733 - } 734 - 735 - return 0; 736 - } 737 - #endif 738 - 739 - #if CONFIG_PGTABLE_LEVELS > 2 740 - /** 741 725 * pmd_set_huge - setup kernel PMD mapping 742 726 * 743 727 * See text over pud_set_huge() above. ··· 751 769 } 752 770 753 771 /** 772 + * pud_clear_huge - clear kernel PUD mapping when it is set 773 + * 774 + * Returns 1 on success and 0 on failure (no PUD map is found). 775 + */ 776 + int pud_clear_huge(pud_t *pud) 777 + { 778 + if (pud_large(*pud)) { 779 + pud_clear(pud); 780 + return 1; 781 + } 782 + 783 + return 0; 784 + } 785 + 786 + /** 754 787 * pmd_clear_huge - clear kernel PMD mapping when it is set 755 788 * 756 789 * Returns 1 on success and 0 on failure (no PMD map is found). ··· 779 782 780 783 return 0; 781 784 } 782 - #endif 783 785 784 786 #ifdef CONFIG_X86_64 785 787 /**
+1 -25
include/linux/pgtable.h
··· 1397 1397 } 1398 1398 #endif /* !__PAGETABLE_P4D_FOLDED */ 1399 1399 1400 - #ifndef __PAGETABLE_PUD_FOLDED 1401 1400 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); 1402 - int pud_clear_huge(pud_t *pud); 1403 - #else 1404 - static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) 1405 - { 1406 - return 0; 1407 - } 1408 - static inline int pud_clear_huge(pud_t *pud) 1409 - { 1410 - return 0; 1411 - } 1412 - #endif /* !__PAGETABLE_PUD_FOLDED */ 1413 - 1414 - #ifndef __PAGETABLE_PMD_FOLDED 1415 1401 int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 1402 + int pud_clear_huge(pud_t *pud); 1416 1403 int pmd_clear_huge(pmd_t *pmd); 1417 - #else 1418 - static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) 1419 - { 1420 - return 0; 1421 - } 1422 - static inline int pmd_clear_huge(pmd_t *pmd) 1423 - { 1424 - return 0; 1425 - } 1426 - #endif /* !__PAGETABLE_PMD_FOLDED */ 1427 - 1428 1404 int p4d_free_pud_page(p4d_t *p4d, unsigned long addr); 1429 1405 int pud_free_pmd_page(pud_t *pud, unsigned long addr); 1430 1406 int pmd_free_pte_page(pmd_t *pmd, unsigned long addr);