arch/x86/mm/pti.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/pti.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/pti.c- Extension
.c- Size
- 18773 bytes
- Lines
- 693
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
Dependency Surface
linux/kernel.hlinux/errno.hlinux/string.hlinux/types.hlinux/bug.hlinux/init.hlinux/spinlock.hlinux/mm.hlinux/uaccess.hlinux/cpu.hasm/cpufeature.hasm/hypervisor.hasm/cpuid/api.hasm/vsyscall.hasm/cmdline.hasm/pti.hasm/tlbflush.hasm/desc.hasm/sections.hasm/set_memory.hasm/bugs.h
Detected Declarations
enum pti_clone_levelfunction Copyrightfunction pti_print_if_securefunction pti_check_boottime_disablefunction pti_parse_cmdlinefunction pti_parse_cmdline_noptifunction __pti_set_user_pgtblfunction tablesfunction tablesfunction tablesfunction pti_setup_vsyscallfunction pti_setup_vsyscallfunction pti_clone_pgtablefunction p4dfunction pti_clone_user_sharedfunction for_each_possible_cpufunction pti_clone_user_sharedfunction pti_setup_espfix64function pti_clone_entry_textfunction pti_kernel_image_global_okfunction pti_clone_kernel_textfunction pti_set_kernel_image_nonglobalfunction pti_initfunction pti_init
Annotated Snippet
if (late_text) {
set_pmd(pmd, __pmd(0));
} else {
WARN_ON_ONCE(1);
return NULL;
}
}
if (pmd_none(*pmd)) {
unsigned long new_pte_page = __get_free_page(gfp);
if (!new_pte_page)
return NULL;
set_pmd(pmd, __pmd(_KERNPG_TABLE | __pa(new_pte_page)));
}
pte = pte_offset_kernel(pmd, address);
if (pte_flags(*pte) & _PAGE_USER) {
WARN_ONCE(1, "attempt to walk to user pte\n");
return NULL;
}
return pte;
}
#ifdef CONFIG_X86_VSYSCALL_EMULATION
static void __init pti_setup_vsyscall(void)
{
pte_t *pte, *target_pte;
unsigned int level;
pte = lookup_address(VSYSCALL_ADDR, &level);
if (!pte || WARN_ON(level != PG_LEVEL_4K) || pte_none(*pte))
return;
target_pte = pti_user_pagetable_walk_pte(VSYSCALL_ADDR, false);
if (WARN_ON(!target_pte))
return;
*target_pte = *pte;
set_vsyscall_pgtable_user_bits(kernel_to_user_pgdp(swapper_pg_dir));
}
#else
static void __init pti_setup_vsyscall(void) { }
#endif
enum pti_clone_level {
PTI_CLONE_PMD,
PTI_CLONE_PTE,
};
static void
pti_clone_pgtable(unsigned long start, unsigned long end,
enum pti_clone_level level, bool late_text)
{
unsigned long addr;
/*
* Clone the populated PMDs which cover start to end. These PMD areas
* can have holes.
*/
for (addr = start; addr < end;) {
pte_t *pte, *target_pte;
pmd_t *pmd, *target_pmd;
pgd_t *pgd;
p4d_t *p4d;
pud_t *pud;
/* Overflow check */
if (addr < start)
break;
pgd = pgd_offset_k(addr);
if (WARN_ON(pgd_none(*pgd)))
return;
p4d = p4d_offset(pgd, addr);
if (WARN_ON(p4d_none(*p4d)))
return;
pud = pud_offset(p4d, addr);
if (pud_none(*pud)) {
WARN_ON_ONCE(addr & ~PUD_MASK);
addr = round_up(addr + 1, PUD_SIZE);
continue;
}
pmd = pmd_offset(pud, addr);
if (pmd_none(*pmd)) {
WARN_ON_ONCE(addr & ~PMD_MASK);
addr = round_up(addr + 1, PMD_SIZE);
continue;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/string.h`, `linux/types.h`, `linux/bug.h`, `linux/init.h`, `linux/spinlock.h`, `linux/mm.h`.
- Detected declarations: `enum pti_clone_level`, `function Copyright`, `function pti_print_if_secure`, `function pti_check_boottime_disable`, `function pti_parse_cmdline`, `function pti_parse_cmdline_nopti`, `function __pti_set_user_pgtbl`, `function tables`, `function tables`, `function tables`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.