arch/mips/mm/cache.c
Source file repositories/reference/linux-study-clean/arch/mips/mm/cache.c
File Facts
- System
- Linux kernel
- Corpus path
arch/mips/mm/cache.c- Extension
.c- Size
- 6266 bytes
- Lines
- 219
- Domain
- Architecture Layer
- Bucket
- arch/mips
- Inferred role
- Architecture Layer: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- 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/fs.hlinux/fcntl.hlinux/kernel.hlinux/linkage.hlinux/export.hlinux/sched.hlinux/syscalls.hlinux/mm.hlinux/highmem.hlinux/pagemap.hasm/bcache.hasm/cacheflush.hasm/processor.hasm/cpu.hasm/cpu-features.hasm/setup.hasm/pgtable.h
Detected Declarations
syscall cacheflushfunction cache_noopfunction __flush_dcache_folio_pagesfunction __flush_anon_pagefunction __update_cachefunction setup_protection_mapfunction cpu_cache_initexport __flush_cache_allexport flush_icache_rangeexport local_flush_icache_rangeexport __local_flush_icache_user_rangeexport __flush_kernel_vmap_rangeexport flush_data_cache_pageexport flush_icache_allexport __flush_dcache_folio_pagesexport __flush_anon_pageexport _page_cachable_default
Annotated Snippet
SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, bytes,
unsigned int, cache)
{
if (bytes == 0)
return 0;
if (!access_ok((void __user *) addr, bytes))
return -EFAULT;
__flush_icache_user_range(addr, addr + bytes);
return 0;
}
void __flush_dcache_folio_pages(struct folio *folio, struct page *page,
unsigned int nr)
{
struct address_space *mapping = folio_flush_mapping(folio);
unsigned long addr;
unsigned int i;
if (mapping && !mapping_mapped(mapping)) {
folio_set_dcache_dirty(folio);
return;
}
/*
* We could delay the flush for the !folio_mapping case too. But that
* case is for exec env/arg pages and those are %99 certainly going to
* get faulted into the tlb (and thus flushed) anyways.
*/
for (i = 0; i < nr; i++) {
addr = (unsigned long)kmap_local_page(page + i);
flush_data_cache_page(addr);
kunmap_local((void *)addr);
}
}
EXPORT_SYMBOL(__flush_dcache_folio_pages);
void __flush_anon_page(struct page *page, unsigned long vmaddr)
{
unsigned long addr = (unsigned long) page_address(page);
struct folio *folio = page_folio(page);
if (pages_do_alias(addr, vmaddr)) {
if (folio_mapped(folio) && !folio_test_dcache_dirty(folio)) {
void *kaddr;
kaddr = kmap_coherent(page, vmaddr);
flush_data_cache_page((unsigned long)kaddr);
kunmap_coherent();
} else
flush_data_cache_page(addr);
}
}
EXPORT_SYMBOL(__flush_anon_page);
void __update_cache(unsigned long address, pte_t pte)
{
struct folio *folio;
unsigned long pfn, addr;
int exec = !pte_no_exec(pte) && !cpu_has_ic_fills_f_dc;
unsigned int i;
pfn = pte_pfn(pte);
if (unlikely(!pfn_valid(pfn)))
return;
folio = page_folio(pfn_to_page(pfn));
address &= PAGE_MASK;
address -= offset_in_folio(folio, pfn << PAGE_SHIFT);
if (folio_test_dcache_dirty(folio)) {
for (i = 0; i < folio_nr_pages(folio); i++) {
addr = (unsigned long)kmap_local_folio(folio, i);
if (exec || pages_do_alias(addr, address))
flush_data_cache_page(addr);
kunmap_local((void *)addr);
address += PAGE_SIZE;
}
folio_clear_dcache_dirty(folio);
}
}
unsigned long _page_cachable_default;
EXPORT_SYMBOL(_page_cachable_default);
#define PM(p) __pgprot(_page_cachable_default | (p))
Annotation
- Immediate include surface: `linux/fs.h`, `linux/fcntl.h`, `linux/kernel.h`, `linux/linkage.h`, `linux/export.h`, `linux/sched.h`, `linux/syscalls.h`, `linux/mm.h`.
- Detected declarations: `syscall cacheflush`, `function cache_noop`, `function __flush_dcache_folio_pages`, `function __flush_anon_page`, `function __update_cache`, `function setup_protection_map`, `function cpu_cache_init`, `export __flush_cache_all`, `export flush_icache_range`, `export local_flush_icache_range`.
- Atlas domain: Architecture Layer / arch/mips.
- Implementation status: core 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.