mm/debug_vm_pgtable.c
Source file repositories/reference/linux-study-clean/mm/debug_vm_pgtable.c
File Facts
- System
- Linux kernel
- Corpus path
mm/debug_vm_pgtable.c- Extension
.c- Size
- 39534 bytes
- Lines
- 1372
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- 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/gfp.hlinux/highmem.hlinux/hugetlb.hlinux/kernel.hlinux/kconfig.hlinux/memblock.hlinux/mm.hlinux/mman.hlinux/mm_types.hlinux/module.hlinux/printk.hlinux/pgtable.hlinux/random.hlinux/spinlock.hlinux/swap.hlinux/leafops.hlinux/start_kernel.hlinux/sched/mm.hlinux/io.hlinux/vmalloc.hlinux/pgalloc.hasm/cacheflush.hasm/tlbflush.h
Detected Declarations
struct pgtable_debug_argsfunction pte_basic_testsfunction pte_advanced_testsfunction pmd_basic_testsfunction pmd_advanced_testsfunction pmd_leaf_testsfunction pud_basic_testsfunction pud_advanced_testsfunction pud_leaf_testsfunction pud_basic_testsfunction pud_huge_testsfunction pmd_huge_testsfunction pgd_basic_testsfunction pud_clear_testsfunction pud_populate_testsfunction pud_clear_testsfunction p4d_populate_testsfunction pgd_clear_testsfunction pgd_populate_testsfunction p4d_clear_testsfunction pmd_clear_testsfunction pmd_populate_testsfunction pte_special_testsfunction pte_protnone_testsfunction pmd_protnone_testsfunction pmd_protnone_testsfunction pte_swap_soft_dirty_testsfunction pmd_soft_dirty_testsfunction pmd_leaf_soft_dirty_testsfunction pmd_soft_dirty_testsfunction pte_swap_testsfunction pmd_softleaf_testsfunction pmd_softleaf_testsfunction hugetlb_basic_testsfunction hugetlb_basic_testsfunction pud_thp_testsfunction pud_thp_testsfunction debug_vm_pgtable_free_huge_pagefunction destroy_argsfunction debug_vm_pgtable_alloc_huge_pagefunction phys_align_checkfunction init_fixed_pfnsfunction for_each_mem_rangefunction init_argsfunction Allocatefunction debug_vm_pgtable
Annotated Snippet
#include <linux/start_kernel.h>
#include <linux/sched/mm.h>
#include <linux/io.h>
#include <linux/vmalloc.h>
#include <linux/pgalloc.h>
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
/*
* Please refer Documentation/mm/arch_pgtable_helpers.rst for the semantics
* expectations that are being validated here. All future changes in here
* or the documentation need to be in sync.
*/
#define RANDOM_NZVALUE GENMASK(7, 0)
struct pgtable_debug_args {
struct mm_struct *mm;
struct vm_area_struct *vma;
pgd_t *pgdp;
p4d_t *p4dp;
pud_t *pudp;
pmd_t *pmdp;
pte_t *ptep;
p4d_t *start_p4dp;
pud_t *start_pudp;
pmd_t *start_pmdp;
pgtable_t start_ptep;
unsigned long vaddr;
pgprot_t page_prot;
pgprot_t page_prot_none;
bool is_contiguous_page;
unsigned long pud_pfn;
unsigned long pmd_pfn;
unsigned long pte_pfn;
unsigned long fixed_alignment;
unsigned long fixed_pgd_pfn;
unsigned long fixed_p4d_pfn;
unsigned long fixed_pud_pfn;
unsigned long fixed_pmd_pfn;
unsigned long fixed_pte_pfn;
swp_entry_t swp_entry;
swp_entry_t leaf_entry;
};
static void __init pte_basic_tests(struct pgtable_debug_args *args, int idx)
{
pgprot_t prot = vm_get_page_prot(idx);
pte_t pte = pfn_pte(args->fixed_pte_pfn, prot);
unsigned long val = idx, *ptr = &val;
pr_debug("Validating PTE basic (%pGv)\n", ptr);
/*
* This test needs to be executed after the given page table entry
* is created with pfn_pte() to make sure that vm_get_page_prot(idx)
* does not have the dirty bit enabled from the beginning. This is
* important for platforms like arm64 where (!PTE_RDONLY) indicate
* dirty bit being set.
*/
WARN_ON(pte_dirty(pte_wrprotect(pte)));
WARN_ON(!pte_same(pte, pte));
WARN_ON(!pte_young(pte_mkyoung(pte_mkold(pte))));
WARN_ON(!pte_dirty(pte_mkdirty(pte_mkclean(pte))));
WARN_ON(!pte_write(pte_mkwrite(pte_wrprotect(pte), args->vma)));
WARN_ON(pte_young(pte_mkold(pte_mkyoung(pte))));
WARN_ON(pte_dirty(pte_mkclean(pte_mkdirty(pte))));
WARN_ON(pte_write(pte_wrprotect(pte_mkwrite(pte, args->vma))));
WARN_ON(pte_dirty(pte_wrprotect(pte_mkclean(pte))));
WARN_ON(!pte_dirty(pte_wrprotect(pte_mkdirty(pte))));
WARN_ON(!pte_dirty(pte_mkwrite_novma(pte_mkdirty(pte))));
WARN_ON(pte_dirty(pte_mkwrite_novma(pte_mkclean(pte))));
WARN_ON(!pte_write(pte_mkdirty(pte_mkwrite_novma(pte))));
WARN_ON(!pte_write(pte_mkwrite_novma(pte_wrprotect(pte))));
WARN_ON(pte_write(pte_wrprotect(pte_mkwrite_novma(pte))));
}
static void __init pte_advanced_tests(struct pgtable_debug_args *args)
{
struct page *page;
pte_t pte;
Annotation
- Immediate include surface: `linux/gfp.h`, `linux/highmem.h`, `linux/hugetlb.h`, `linux/kernel.h`, `linux/kconfig.h`, `linux/memblock.h`, `linux/mm.h`, `linux/mman.h`.
- Detected declarations: `struct pgtable_debug_args`, `function pte_basic_tests`, `function pte_advanced_tests`, `function pmd_basic_tests`, `function pmd_advanced_tests`, `function pmd_leaf_tests`, `function pud_basic_tests`, `function pud_advanced_tests`, `function pud_leaf_tests`, `function pud_basic_tests`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source 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.