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

Configure Feed

Select the types of activity you want to include in your feed.

arm64: mm: Use generic enum pgtable_level

enum pgtable_type was introduced for arm64 by commit c64f46ee1377
("arm64: mm: use enum to identify pgtable level instead of
*_SHIFT"). In the meantime, the generic enum pgtable_level got
introduced by commit b22cc9a9c7ff ("mm/rmap: convert "enum
rmap_level" to "enum pgtable_level"").

Let's switch to the generic enum pgtable_level. The only difference
is that it also includes PGD level; __pgd_pgtable_alloc() isn't
expected to create PGD tables so we add a VM_WARN_ON() for that
case.

Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>

authored by

Kevin Brodsky and committed by
Catalin Marinas
5e0deb0a 3ce8f586

+31 -35
-7
arch/arm64/include/asm/mmu.h
··· 17 17 #include <linux/refcount.h> 18 18 #include <asm/cpufeature.h> 19 19 20 - enum pgtable_type { 21 - TABLE_PTE, 22 - TABLE_PMD, 23 - TABLE_PUD, 24 - TABLE_P4D, 25 - }; 26 - 27 20 typedef struct { 28 21 atomic64_t id; 29 22 #ifdef CONFIG_COMPAT
+31 -28
arch/arm64/mm/mmu.c
··· 112 112 } 113 113 EXPORT_SYMBOL(phys_mem_access_prot); 114 114 115 - static phys_addr_t __init early_pgtable_alloc(enum pgtable_type pgtable_type) 115 + static phys_addr_t __init early_pgtable_alloc(enum pgtable_level pgtable_level) 116 116 { 117 117 phys_addr_t phys; 118 118 ··· 197 197 static int alloc_init_cont_pte(pmd_t *pmdp, unsigned long addr, 198 198 unsigned long end, phys_addr_t phys, 199 199 pgprot_t prot, 200 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 200 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 201 201 int flags) 202 202 { 203 203 unsigned long next; ··· 212 212 if (flags & NO_EXEC_MAPPINGS) 213 213 pmdval |= PMD_TABLE_PXN; 214 214 BUG_ON(!pgtable_alloc); 215 - pte_phys = pgtable_alloc(TABLE_PTE); 215 + pte_phys = pgtable_alloc(PGTABLE_LEVEL_PTE); 216 216 if (pte_phys == INVALID_PHYS_ADDR) 217 217 return -ENOMEM; 218 218 ptep = pte_set_fixmap(pte_phys); ··· 252 252 253 253 static int init_pmd(pmd_t *pmdp, unsigned long addr, unsigned long end, 254 254 phys_addr_t phys, pgprot_t prot, 255 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), int flags) 255 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), int flags) 256 256 { 257 257 unsigned long next; 258 258 ··· 292 292 static int alloc_init_cont_pmd(pud_t *pudp, unsigned long addr, 293 293 unsigned long end, phys_addr_t phys, 294 294 pgprot_t prot, 295 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 295 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 296 296 int flags) 297 297 { 298 298 int ret; ··· 311 311 if (flags & NO_EXEC_MAPPINGS) 312 312 pudval |= PUD_TABLE_PXN; 313 313 BUG_ON(!pgtable_alloc); 314 - pmd_phys = pgtable_alloc(TABLE_PMD); 314 + pmd_phys = pgtable_alloc(PGTABLE_LEVEL_PMD); 315 315 if (pmd_phys == INVALID_PHYS_ADDR) 316 316 return -ENOMEM; 317 317 pmdp = pmd_set_fixmap(pmd_phys); ··· 349 349 350 350 static int alloc_init_pud(p4d_t *p4dp, unsigned long addr, unsigned long end, 351 351 phys_addr_t phys, pgprot_t prot, 352 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 352 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 353 353 int flags) 354 354 { 355 355 int ret = 0; ··· 364 364 if (flags & NO_EXEC_MAPPINGS) 365 365 p4dval |= P4D_TABLE_PXN; 366 366 BUG_ON(!pgtable_alloc); 367 - pud_phys = pgtable_alloc(TABLE_PUD); 367 + pud_phys = pgtable_alloc(PGTABLE_LEVEL_PUD); 368 368 if (pud_phys == INVALID_PHYS_ADDR) 369 369 return -ENOMEM; 370 370 pudp = pud_set_fixmap(pud_phys); ··· 415 415 416 416 static int alloc_init_p4d(pgd_t *pgdp, unsigned long addr, unsigned long end, 417 417 phys_addr_t phys, pgprot_t prot, 418 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 418 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 419 419 int flags) 420 420 { 421 421 int ret; ··· 430 430 if (flags & NO_EXEC_MAPPINGS) 431 431 pgdval |= PGD_TABLE_PXN; 432 432 BUG_ON(!pgtable_alloc); 433 - p4d_phys = pgtable_alloc(TABLE_P4D); 433 + p4d_phys = pgtable_alloc(PGTABLE_LEVEL_P4D); 434 434 if (p4d_phys == INVALID_PHYS_ADDR) 435 435 return -ENOMEM; 436 436 p4dp = p4d_set_fixmap(p4d_phys); ··· 467 467 static int __create_pgd_mapping_locked(pgd_t *pgdir, phys_addr_t phys, 468 468 unsigned long virt, phys_addr_t size, 469 469 pgprot_t prot, 470 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 470 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 471 471 int flags) 472 472 { 473 473 int ret; ··· 500 500 static int __create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, 501 501 unsigned long virt, phys_addr_t size, 502 502 pgprot_t prot, 503 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 503 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 504 504 int flags) 505 505 { 506 506 int ret; ··· 516 516 static void early_create_pgd_mapping(pgd_t *pgdir, phys_addr_t phys, 517 517 unsigned long virt, phys_addr_t size, 518 518 pgprot_t prot, 519 - phys_addr_t (*pgtable_alloc)(enum pgtable_type), 519 + phys_addr_t (*pgtable_alloc)(enum pgtable_level), 520 520 int flags) 521 521 { 522 522 int ret; ··· 528 528 } 529 529 530 530 static phys_addr_t __pgd_pgtable_alloc(struct mm_struct *mm, gfp_t gfp, 531 - enum pgtable_type pgtable_type) 531 + enum pgtable_level pgtable_level) 532 532 { 533 533 /* Page is zeroed by init_clear_pgtable() so don't duplicate effort. */ 534 534 struct ptdesc *ptdesc = pagetable_alloc(gfp & ~__GFP_ZERO, 0); ··· 539 539 540 540 pa = page_to_phys(ptdesc_page(ptdesc)); 541 541 542 - switch (pgtable_type) { 543 - case TABLE_PTE: 542 + switch (pgtable_level) { 543 + case PGTABLE_LEVEL_PTE: 544 544 BUG_ON(!pagetable_pte_ctor(mm, ptdesc)); 545 545 break; 546 - case TABLE_PMD: 546 + case PGTABLE_LEVEL_PMD: 547 547 BUG_ON(!pagetable_pmd_ctor(mm, ptdesc)); 548 548 break; 549 - case TABLE_PUD: 549 + case PGTABLE_LEVEL_PUD: 550 550 pagetable_pud_ctor(ptdesc); 551 551 break; 552 - case TABLE_P4D: 552 + case PGTABLE_LEVEL_P4D: 553 553 pagetable_p4d_ctor(ptdesc); 554 + break; 555 + case PGTABLE_LEVEL_PGD: 556 + VM_WARN_ON(1); 554 557 break; 555 558 } 556 559 ··· 561 558 } 562 559 563 560 static phys_addr_t 564 - pgd_pgtable_alloc_init_mm_gfp(enum pgtable_type pgtable_type, gfp_t gfp) 561 + pgd_pgtable_alloc_init_mm_gfp(enum pgtable_level pgtable_level, gfp_t gfp) 565 562 { 566 - return __pgd_pgtable_alloc(&init_mm, gfp, pgtable_type); 563 + return __pgd_pgtable_alloc(&init_mm, gfp, pgtable_level); 567 564 } 568 565 569 566 static phys_addr_t __maybe_unused 570 - pgd_pgtable_alloc_init_mm(enum pgtable_type pgtable_type) 567 + pgd_pgtable_alloc_init_mm(enum pgtable_level pgtable_level) 571 568 { 572 - return pgd_pgtable_alloc_init_mm_gfp(pgtable_type, GFP_PGTABLE_KERNEL); 569 + return pgd_pgtable_alloc_init_mm_gfp(pgtable_level, GFP_PGTABLE_KERNEL); 573 570 } 574 571 575 572 static phys_addr_t 576 - pgd_pgtable_alloc_special_mm(enum pgtable_type pgtable_type) 573 + pgd_pgtable_alloc_special_mm(enum pgtable_level pgtable_level) 577 574 { 578 - return __pgd_pgtable_alloc(NULL, GFP_PGTABLE_KERNEL, pgtable_type); 575 + return __pgd_pgtable_alloc(NULL, GFP_PGTABLE_KERNEL, pgtable_level); 579 576 } 580 577 581 578 static void split_contpte(pte_t *ptep) ··· 596 593 pte_t *ptep; 597 594 int i; 598 595 599 - pte_phys = pgd_pgtable_alloc_init_mm_gfp(TABLE_PTE, gfp); 596 + pte_phys = pgd_pgtable_alloc_init_mm_gfp(PGTABLE_LEVEL_PTE, gfp); 600 597 if (pte_phys == INVALID_PHYS_ADDR) 601 598 return -ENOMEM; 602 599 ptep = (pte_t *)phys_to_virt(pte_phys); ··· 641 638 pmd_t *pmdp; 642 639 int i; 643 640 644 - pmd_phys = pgd_pgtable_alloc_init_mm_gfp(TABLE_PMD, gfp); 641 + pmd_phys = pgd_pgtable_alloc_init_mm_gfp(PGTABLE_LEVEL_PMD, gfp); 645 642 if (pmd_phys == INVALID_PHYS_ADDR) 646 643 return -ENOMEM; 647 644 pmdp = (pmd_t *)phys_to_virt(pmd_phys); ··· 1229 1226 1230 1227 static phys_addr_t kpti_ng_temp_alloc __initdata; 1231 1228 1232 - static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_type type) 1229 + static phys_addr_t __init kpti_ng_pgd_alloc(enum pgtable_level pgtable_level) 1233 1230 { 1234 1231 kpti_ng_temp_alloc -= PAGE_SIZE; 1235 1232 return kpti_ng_temp_alloc;