arch/x86/mm/init_64.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/init_64.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/init_64.c- Extension
.c- Size
- 43714 bytes
- Lines
- 1670
- 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/signal.hlinux/sched.hlinux/kernel.hlinux/errno.hlinux/string.hlinux/types.hlinux/ptrace.hlinux/mman.hlinux/mm.hlinux/swap.hlinux/smp.hlinux/init.hlinux/initrd.hlinux/pagemap.hlinux/memblock.hlinux/proc_fs.hlinux/pci.hlinux/pfn.hlinux/poison.hlinux/dma-mapping.hlinux/memory.hlinux/memory_hotplug.hlinux/memremap.hlinux/nmi.hlinux/gfp.hlinux/kcore.hlinux/bootmem_info.hasm/processor.hasm/bios_ebda.hlinux/uaccess.hasm/pgalloc.hasm/dma.h
Detected Declarations
function prot_sethugefunction nonx32_setupfunction sync_global_pgds_l5function list_for_each_entryfunction sync_global_pgds_l4function list_for_each_entryfunction sync_global_pgdsfunction pgd_populatefunction __set_pte_vaddrfunction set_pte_vaddr_p4dfunction set_pte_vaddr_pudfunction set_pte_vaddrfunction populate_extra_pmdfunction populate_extra_ptefunction __init_extra_mappingfunction init_extra_mapping_wbfunction init_extra_mapping_ucfunction cleanup_highmapfunction phys_pte_initfunction phys_pmd_initfunction notefunction phys_pud_initfunction notefunction phys_p4d_initfunction __kernel_physical_mapping_initfunction kernel_physical_mapping_initfunction kernel_physical_mapping_initfunction x86_numa_initfunction initmem_initfunction paging_initfunction vmemmap_flush_unused_pmdfunction vmemmap_pmd_is_unusedfunction __vmemmap_use_sub_pmdfunction vmemmap_use_sub_pmdfunction vmemmap_use_new_sub_pmdfunction update_end_of_memory_varsfunction add_pagesfunction arch_add_memoryfunction free_reserved_pagesfunction free_pagetablefunction free_vmemmap_pagesfunction free_pte_tablefunction free_pmd_tablefunction free_pud_tablefunction remove_pte_tablefunction remove_pmd_tablefunction remove_pud_tablefunction remove_p4d_table
Annotated Snippet
list_for_each_entry(page, &pgd_list, lru) {
pgd_t *pgd;
spinlock_t *pgt_lock;
pgd = (pgd_t *)page_address(page) + pgd_index(addr);
/* the pgt_lock only for Xen */
pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
spin_lock(pgt_lock);
if (!pgd_none(*pgd_ref) && !pgd_none(*pgd))
BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
if (pgd_none(*pgd))
set_pgd(pgd, *pgd_ref);
spin_unlock(pgt_lock);
}
spin_unlock(&pgd_lock);
}
}
static void sync_global_pgds_l4(unsigned long start, unsigned long end)
{
unsigned long addr;
for (addr = start; addr <= end; addr = ALIGN(addr + 1, PGDIR_SIZE)) {
pgd_t *pgd_ref = pgd_offset_k(addr);
const p4d_t *p4d_ref;
struct page *page;
/*
* With folded p4d, pgd_none() is always false, we need to
* handle synchronization on p4d level.
*/
MAYBE_BUILD_BUG_ON(pgd_none(*pgd_ref));
p4d_ref = p4d_offset(pgd_ref, addr);
if (p4d_none(*p4d_ref))
continue;
spin_lock(&pgd_lock);
list_for_each_entry(page, &pgd_list, lru) {
pgd_t *pgd;
p4d_t *p4d;
spinlock_t *pgt_lock;
pgd = (pgd_t *)page_address(page) + pgd_index(addr);
p4d = p4d_offset(pgd, addr);
/* the pgt_lock only for Xen */
pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
spin_lock(pgt_lock);
if (!p4d_none(*p4d_ref) && !p4d_none(*p4d))
BUG_ON(p4d_pgtable(*p4d)
!= p4d_pgtable(*p4d_ref));
if (p4d_none(*p4d))
set_p4d(p4d, *p4d_ref);
spin_unlock(pgt_lock);
}
spin_unlock(&pgd_lock);
}
}
/*
* When memory was added make sure all the processes MM have
* suitable PGD entries in the local PGD level page.
*/
static void sync_global_pgds(unsigned long start, unsigned long end)
{
if (pgtable_l5_enabled())
sync_global_pgds_l5(start, end);
else
sync_global_pgds_l4(start, end);
}
/*
* Make kernel mappings visible in all page tables in the system.
* This is necessary except when the init task populates kernel mappings
* during the boot process. In that case, all processes originating from
* the init task copies the kernel mappings, so there is no issue.
* Otherwise, missing synchronization could lead to kernel crashes due
* to missing page table entries for certain kernel mappings.
*
* Synchronization is performed at the top level, which is the PGD in
* 5-level paging systems. But in 4-level paging systems, however,
* pgd_populate() is a no-op, so synchronization is done at the P4D level.
* sync_global_pgds() handles this difference between paging levels.
*/
Annotation
- Immediate include surface: `linux/signal.h`, `linux/sched.h`, `linux/kernel.h`, `linux/errno.h`, `linux/string.h`, `linux/types.h`, `linux/ptrace.h`, `linux/mman.h`.
- Detected declarations: `function prot_sethuge`, `function nonx32_setup`, `function sync_global_pgds_l5`, `function list_for_each_entry`, `function sync_global_pgds_l4`, `function list_for_each_entry`, `function sync_global_pgds`, `function pgd_populate`, `function __set_pte_vaddr`, `function set_pte_vaddr_p4d`.
- 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.