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

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

For architectures with no PMD and/or no PUD, add stubs similar to what we
have for architectures without P4D.

[christophe.leroy@csgroup.eu: arm64: define only {pud/pmd}_{set/clear}_huge when useful]
Link: https://lkml.kernel.org/r/73ec95f40cafbbb69bdfb43a7f53876fd845b0ce.1620990479.git.christophe.leroy@csgroup.eu
[christophe.leroy@csgroup.eu: x86: define only {pud/pmd}_{set/clear}_huge when useful]
Link: https://lkml.kernel.org/r/7fbf1b6bc3e15c07c24fa45278d57064f14c896b.1620930415.git.christophe.leroy@csgroup.eu

Link: https://lkml.kernel.org/r/5ac5976419350e8e048d463a64cae449eb3ba4b0.1620795204.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Uladzislau Rezki <uladzislau.rezki@sony.com>
Cc: Naresh Kamboju <naresh.kamboju@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Christophe Leroy and committed by
Linus Torvalds
c742199a 79c1c594

+56 -24
+12 -8
arch/arm64/mm/mmu.c
··· 1338 1338 return dt_virt; 1339 1339 } 1340 1340 1341 + #if CONFIG_PGTABLE_LEVELS > 3 1341 1342 int pud_set_huge(pud_t *pudp, phys_addr_t phys, pgprot_t prot) 1342 1343 { 1343 1344 pud_t new_pud = pfn_pud(__phys_to_pfn(phys), mk_pud_sect_prot(prot)); ··· 1353 1352 return 1; 1354 1353 } 1355 1354 1355 + int pud_clear_huge(pud_t *pudp) 1356 + { 1357 + if (!pud_sect(READ_ONCE(*pudp))) 1358 + return 0; 1359 + pud_clear(pudp); 1360 + return 1; 1361 + } 1362 + #endif 1363 + 1364 + #if CONFIG_PGTABLE_LEVELS > 2 1356 1365 int pmd_set_huge(pmd_t *pmdp, phys_addr_t phys, pgprot_t prot) 1357 1366 { 1358 1367 pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), mk_pmd_sect_prot(prot)); ··· 1377 1366 return 1; 1378 1367 } 1379 1368 1380 - int pud_clear_huge(pud_t *pudp) 1381 - { 1382 - if (!pud_sect(READ_ONCE(*pudp))) 1383 - return 0; 1384 - pud_clear(pudp); 1385 - return 1; 1386 - } 1387 - 1388 1369 int pmd_clear_huge(pmd_t *pmdp) 1389 1370 { 1390 1371 if (!pmd_sect(READ_ONCE(*pmdp))) ··· 1384 1381 pmd_clear(pmdp); 1385 1382 return 1; 1386 1383 } 1384 + #endif 1387 1385 1388 1386 int pmd_free_pte_page(pmd_t *pmdp, unsigned long addr) 1389 1387 {
+19 -15
arch/x86/mm/pgtable.c
··· 682 682 } 683 683 #endif 684 684 685 + #if CONFIG_PGTABLE_LEVELS > 3 685 686 /** 686 687 * pud_set_huge - setup kernel PUD mapping 687 688 * ··· 722 721 } 723 722 724 723 /** 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 + /** 725 741 * pmd_set_huge - setup kernel PMD mapping 726 742 * 727 743 * See text over pud_set_huge() above. ··· 769 751 } 770 752 771 753 /** 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 - /** 787 754 * pmd_clear_huge - clear kernel PMD mapping when it is set 788 755 * 789 756 * Returns 1 on success and 0 on failure (no PMD map is found). ··· 782 779 783 780 return 0; 784 781 } 782 + #endif 785 783 786 784 #ifdef CONFIG_X86_64 787 785 /**
+25 -1
include/linux/pgtable.h
··· 1379 1379 } 1380 1380 #endif /* !__PAGETABLE_P4D_FOLDED */ 1381 1381 1382 + #ifndef __PAGETABLE_PUD_FOLDED 1382 1383 int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot); 1383 - int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 1384 1384 int pud_clear_huge(pud_t *pud); 1385 + #else 1386 + static inline int pud_set_huge(pud_t *pud, phys_addr_t addr, pgprot_t prot) 1387 + { 1388 + return 0; 1389 + } 1390 + static inline int pud_clear_huge(pud_t *pud) 1391 + { 1392 + return 0; 1393 + } 1394 + #endif /* !__PAGETABLE_PUD_FOLDED */ 1395 + 1396 + #ifndef __PAGETABLE_PMD_FOLDED 1397 + int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot); 1385 1398 int pmd_clear_huge(pmd_t *pmd); 1399 + #else 1400 + static inline int pmd_set_huge(pmd_t *pmd, phys_addr_t addr, pgprot_t prot) 1401 + { 1402 + return 0; 1403 + } 1404 + static inline int pmd_clear_huge(pmd_t *pmd) 1405 + { 1406 + return 0; 1407 + } 1408 + #endif /* !__PAGETABLE_PMD_FOLDED */ 1409 + 1386 1410 int p4d_free_pud_page(p4d_t *p4d, unsigned long addr); 1387 1411 int pud_free_pmd_page(pud_t *pud, unsigned long addr); 1388 1412 int pmd_free_pte_page(pmd_t *pmd, unsigned long addr);