arch/x86/mm/pgtable.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/pgtable.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/pgtable.c- Extension
.c- Size
- 20163 bytes
- Lines
- 836
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/mm.hlinux/gfp.hlinux/hugetlb.hasm/pgalloc.hasm/tlb.hasm/fixmap.hasm/mtrr.h
Detected Declarations
function pte_alloc_onefunction ___pte_free_tlbfunction ___pmd_free_tlbfunction ___pud_free_tlbfunction ___p4d_free_tlbfunction pgd_list_addfunction pgd_list_delfunction pgd_set_mmfunction pgd_ctorfunction pgd_dtorfunction pud_populatefunction free_pmdsfunction preallocate_pmdsfunction mop_up_one_pmdfunction pgd_mop_up_pmdsfunction pgd_prepopulate_pmdfunction pgd_prepopulate_user_pmdfunction pgd_prepopulate_user_pmdfunction _pgd_freefunction pgd_freefunction ptep_set_access_flagsfunction pmdp_set_access_flagsfunction pudp_set_access_flagsfunction ptep_test_and_clear_youngfunction pmdp_test_and_clear_youngfunction pudp_test_and_clear_youngfunction ptep_clear_flush_youngfunction pmdp_clear_flush_youngfunction pmdp_invalidate_adfunction pudp_invalidatefunction reserve_top_addressfunction __native_set_fixmapfunction native_set_fixmapfunction p4d_set_hugefunction p4d_clear_hugefunction pud_set_hugefunction failurefunction failurefunction pud_free_pmd_pagefunction pmd_free_pte_pagefunction pmd_free_pte_pagefunction pte_mkwritefunction pmd_mkwritefunction arch_check_zapped_ptefunction arch_check_zapped_pmdfunction arch_check_zapped_pudexport physical_mask
Annotated Snippet
if (pmds[i]) {
ptdesc = virt_to_ptdesc(pmds[i]);
pagetable_dtor(ptdesc);
pagetable_free(ptdesc);
mm_dec_nr_pmds(mm);
}
}
static int preallocate_pmds(struct mm_struct *mm, pmd_t *pmds[], int count)
{
int i;
bool failed = false;
gfp_t gfp = GFP_PGTABLE_USER;
if (mm == &init_mm)
gfp &= ~__GFP_ACCOUNT;
gfp &= ~__GFP_HIGHMEM;
for (i = 0; i < count; i++) {
pmd_t *pmd = NULL;
struct ptdesc *ptdesc = pagetable_alloc(gfp, 0);
if (!ptdesc)
failed = true;
if (ptdesc && !pagetable_pmd_ctor(mm, ptdesc)) {
pagetable_free(ptdesc);
ptdesc = NULL;
failed = true;
}
if (ptdesc) {
mm_inc_nr_pmds(mm);
pmd = ptdesc_address(ptdesc);
}
pmds[i] = pmd;
}
if (failed) {
free_pmds(mm, pmds, count);
return -ENOMEM;
}
return 0;
}
/*
* Mop up any pmd pages which may still be attached to the pgd.
* Normally they will be freed by munmap/exit_mmap, but any pmd we
* preallocate which never got a corresponding vma will need to be
* freed manually.
*/
static void mop_up_one_pmd(struct mm_struct *mm, pgd_t *pgdp)
{
pgd_t pgd = *pgdp;
if (pgd_val(pgd) != 0) {
pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
pgd_clear(pgdp);
paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
pmd_free(mm, pmd);
mm_dec_nr_pmds(mm);
}
}
static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
{
int i;
for (i = 0; i < PREALLOCATED_PMDS; i++)
mop_up_one_pmd(mm, &pgdp[i]);
#ifdef CONFIG_MITIGATION_PAGE_TABLE_ISOLATION
if (!boot_cpu_has(X86_FEATURE_PTI))
return;
pgdp = kernel_to_user_pgdp(pgdp);
for (i = 0; i < PREALLOCATED_USER_PMDS; i++)
mop_up_one_pmd(mm, &pgdp[i + KERNEL_PGD_BOUNDARY]);
#endif
}
static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
{
p4d_t *p4d;
pud_t *pud;
Annotation
- Immediate include surface: `linux/mm.h`, `linux/gfp.h`, `linux/hugetlb.h`, `asm/pgalloc.h`, `asm/tlb.h`, `asm/fixmap.h`, `asm/mtrr.h`.
- Detected declarations: `function pte_alloc_one`, `function ___pte_free_tlb`, `function ___pmd_free_tlb`, `function ___pud_free_tlb`, `function ___p4d_free_tlb`, `function pgd_list_add`, `function pgd_list_del`, `function pgd_set_mm`, `function pgd_ctor`, `function pgd_dtor`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.