arch/loongarch/kvm/mmu.c
Source file repositories/reference/linux-study-clean/arch/loongarch/kvm/mmu.c
File Facts
- System
- Linux kernel
- Corpus path
arch/loongarch/kvm/mmu.c- Extension
.c- Size
- 26036 bytes
- Lines
- 948
- Domain
- Architecture Layer
- Bucket
- arch/loongarch
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/highmem.hlinux/hugetlb.hlinux/kvm_host.hlinux/page-flags.hlinux/uaccess.hasm/mmu_context.hasm/pgalloc.hasm/tlb.hasm/kvm_mmu.h
Detected Declarations
function Copyrightfunction kvm_hugepage_incapablefunction kvm_ptw_preparefunction oldfunction cleanfunction kvm_flush_ptefunction kvm_pgd_allocfunction _kvm_pte_initfunction kvm_ptw_leaffunction kvm_ptw_dirfunction kvm_ptw_topfunction kvm_flush_rangefunction kvm_mkclean_gpa_ptfunction kvm_arch_mmu_enable_log_dirty_pt_maskedfunction kvm_arch_prepare_memory_regionfunction kvm_arch_commit_memory_regionfunction kvm_arch_flush_shadow_memslotfunction kvm_arch_flush_shadow_allfunction kvm_arch_flush_shadow_memslotfunction kvm_unmap_gfn_rangefunction kvm_age_gfnfunction kvm_test_age_gfnfunction kvm_map_page_fastfunction fault_supports_huge_mappingfunction mmu_lockfunction kvm_map_pagefunction kvm_handle_mm_faultfunction kvm_arch_sync_dirty_log
Annotated Snippet
if (kvm_pte_none(&ctx, entry)) {
if (!cache)
return NULL;
child = kvm_mmu_memory_cache_alloc(cache);
_kvm_pte_init(child, ctx.invalid_ptes[ctx.level - 1]);
smp_wmb(); /* Make pte visible before pmd */
kvm_set_pte(entry, __pa(child));
} else if (kvm_pte_huge(*entry)) {
return entry;
} else
child = (kvm_pte_t *)__va(PHYSADDR(*entry));
kvm_ptw_enter(&ctx);
}
entry = kvm_pgtable_offset(&ctx, child, addr);
return entry;
}
/*
* Page walker for VM shadow mmu at last level
* The last level is small pte page or huge pmd page
*/
static int kvm_ptw_leaf(kvm_pte_t *dir, phys_addr_t addr, phys_addr_t end, kvm_ptw_ctx *ctx)
{
int ret;
phys_addr_t next, start, size;
struct list_head *list;
kvm_pte_t *entry, *child;
ret = 0;
start = addr;
child = (kvm_pte_t *)__va(PHYSADDR(*dir));
entry = kvm_pgtable_offset(ctx, child, addr);
do {
next = addr + (0x1UL << ctx->pgtable_shift);
if (!kvm_pte_present(ctx, entry))
continue;
ret |= ctx->ops(entry, addr, ctx);
} while (entry++, addr = next, addr < end);
if (kvm_need_flush(ctx)) {
size = 0x1UL << (ctx->pgtable_shift + PAGE_SHIFT - 3);
if (start + size == end) {
list = (struct list_head *)child;
list_add_tail(list, &ctx->list);
*dir = ctx->invalid_ptes[ctx->level + 1];
}
}
return ret;
}
/*
* Page walker for VM shadow mmu at page table dir level
*/
static int kvm_ptw_dir(kvm_pte_t *dir, phys_addr_t addr, phys_addr_t end, kvm_ptw_ctx *ctx)
{
int ret;
phys_addr_t next, start, size;
struct list_head *list;
kvm_pte_t *entry, *child;
ret = 0;
start = addr;
child = (kvm_pte_t *)__va(PHYSADDR(*dir));
entry = kvm_pgtable_offset(ctx, child, addr);
do {
next = kvm_pgtable_addr_end(ctx, addr, end);
if (!kvm_pte_present(ctx, entry))
continue;
if (kvm_pte_huge(*entry)) {
ret |= ctx->ops(entry, addr, ctx);
continue;
}
kvm_ptw_enter(ctx);
if (ctx->level == 0)
ret |= kvm_ptw_leaf(entry, addr, next, ctx);
else
ret |= kvm_ptw_dir(entry, addr, next, ctx);
kvm_ptw_exit(ctx);
} while (entry++, addr = next, addr < end);
if (kvm_need_flush(ctx)) {
size = 0x1UL << (ctx->pgtable_shift + PAGE_SHIFT - 3);
if (start + size == end) {
Annotation
- Immediate include surface: `linux/highmem.h`, `linux/hugetlb.h`, `linux/kvm_host.h`, `linux/page-flags.h`, `linux/uaccess.h`, `asm/mmu_context.h`, `asm/pgalloc.h`, `asm/tlb.h`.
- Detected declarations: `function Copyright`, `function kvm_hugepage_incapable`, `function kvm_ptw_prepare`, `function old`, `function clean`, `function kvm_flush_pte`, `function kvm_pgd_alloc`, `function _kvm_pte_init`, `function kvm_ptw_leaf`, `function kvm_ptw_dir`.
- Atlas domain: Architecture Layer / arch/loongarch.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.