mm/page_table_check.c
Source file repositories/reference/linux-study-clean/mm/page_table_check.c
File Facts
- System
- Linux kernel
- Corpus path
mm/page_table_check.c- Extension
.c- Size
- 7123 bytes
- Lines
- 283
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kstrtox.hlinux/mm.hlinux/page_table_check.hlinux/swap.hlinux/leafops.h
Detected Declarations
struct page_table_checkfunction early_page_table_check_paramfunction need_page_table_checkfunction init_page_table_checkfunction page_table_check_clearfunction page_table_check_setfunction __page_table_check_zerofunction __page_table_check_pte_clearfunction __page_table_check_pmd_clearfunction __page_table_check_pud_clearfunction softleaf_cached_writablefunction page_table_check_pte_flagsfunction __page_table_check_ptes_setfunction page_table_check_pmd_flagsfunction __page_table_check_pmds_setfunction __page_table_check_puds_setfunction __page_table_check_pte_clear_rangeexport page_table_check_disabledexport __page_table_check_pte_clearexport __page_table_check_pmd_clearexport __page_table_check_pud_clearexport __page_table_check_ptes_setexport __page_table_check_pmds_setexport __page_table_check_puds_set
Annotated Snippet
struct page_table_check {
atomic_t anon_map_count;
atomic_t file_map_count;
};
static bool __page_table_check_enabled __initdata =
IS_ENABLED(CONFIG_PAGE_TABLE_CHECK_ENFORCED);
DEFINE_STATIC_KEY_TRUE(page_table_check_disabled);
EXPORT_SYMBOL(page_table_check_disabled);
static int __init early_page_table_check_param(char *buf)
{
return kstrtobool(buf, &__page_table_check_enabled);
}
early_param("page_table_check", early_page_table_check_param);
static bool __init need_page_table_check(void)
{
return __page_table_check_enabled;
}
static void __init init_page_table_check(void)
{
if (!__page_table_check_enabled)
return;
static_branch_disable(&page_table_check_disabled);
}
struct page_ext_operations page_table_check_ops = {
.size = sizeof(struct page_table_check),
.need = need_page_table_check,
.init = init_page_table_check,
.need_shared_flags = false,
};
static struct page_table_check *get_page_table_check(struct page_ext *page_ext)
{
BUG_ON(!page_ext);
return page_ext_data(page_ext, &page_table_check_ops);
}
/*
* An entry is removed from the page table, decrement the counters for that page
* verify that it is of correct type and counters do not become negative.
*/
static void page_table_check_clear(unsigned long pfn, unsigned long pgcnt)
{
struct page_ext_iter iter;
struct page_ext *page_ext;
struct page *page;
bool anon;
if (!pfn_valid(pfn))
return;
page = pfn_to_page(pfn);
BUG_ON(PageSlab(page));
anon = PageAnon(page);
rcu_read_lock();
for_each_page_ext(page, pgcnt, page_ext, iter) {
struct page_table_check *ptc = get_page_table_check(page_ext);
if (anon) {
BUG_ON(atomic_read(&ptc->file_map_count));
BUG_ON(atomic_dec_return(&ptc->anon_map_count) < 0);
} else {
BUG_ON(atomic_read(&ptc->anon_map_count));
BUG_ON(atomic_dec_return(&ptc->file_map_count) < 0);
}
}
rcu_read_unlock();
}
/*
* A new entry is added to the page table, increment the counters for that page
* verify that it is of correct type and is not being mapped with a different
* type to a different process.
*/
static void page_table_check_set(unsigned long pfn, unsigned long pgcnt,
bool rw)
{
struct page_ext_iter iter;
struct page_ext *page_ext;
struct page *page;
bool anon;
if (!pfn_valid(pfn))
Annotation
- Immediate include surface: `linux/kstrtox.h`, `linux/mm.h`, `linux/page_table_check.h`, `linux/swap.h`, `linux/leafops.h`.
- Detected declarations: `struct page_table_check`, `function early_page_table_check_param`, `function need_page_table_check`, `function init_page_table_check`, `function page_table_check_clear`, `function page_table_check_set`, `function __page_table_check_zero`, `function __page_table_check_pte_clear`, `function __page_table_check_pmd_clear`, `function __page_table_check_pud_clear`.
- Atlas domain: Core OS / Memory Management.
- 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.