arch/arm64/kvm/hyp/pgtable.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp/pgtable.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp/pgtable.c- Extension
.c- Size
- 43125 bytes
- Lines
- 1708
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitfield.hasm/kvm_pgtable.hasm/stage2_pgtable.h
Detected Declarations
struct kvm_pgtable_walk_datastruct leaf_walk_datastruct hyp_map_datastruct stage2_map_datastruct stage2_attr_datastruct stage2_age_datafunction kvm_pgtable_walk_skip_bbm_tlbifunction kvm_pgtable_walk_skip_cmofunction kvm_block_mapping_supportedfunction kvm_pgtable_idxfunction kvm_pgd_page_idxfunction kvm_pgd_pagesfunction kvm_pte_tablefunction kvm_clear_ptefunction kvm_init_table_ptefunction kvm_init_valid_leaf_ptefunction kvm_pgtable_visitor_cbfunction kvm_pgtable_walk_continuefunction __kvm_pgtable_visitfunction __kvm_pgtable_walkfunction _kvm_pgtable_walkfunction kvm_pgtable_walkfunction leaf_walkerfunction kvm_pgtable_get_leaffunction hyp_set_prot_attrfunction kvm_pgtable_hyp_pte_protfunction hyp_map_walker_try_leaffunction hyp_map_walkerfunction kvm_pgtable_hyp_mapfunction hyp_unmap_walkerfunction kvm_pgtable_hyp_unmapfunction kvm_pgtable_hyp_initfunction hyp_free_walkerfunction kvm_pgtable_hyp_destroyfunction kvm_get_vtcrfunction kvm_tlb_flush_vmid_rangefunction stage2_set_xn_attrfunction stage2_set_prot_attrfunction kvm_pgtable_stage2_pte_protfunction stage2_pte_needs_updatefunction stage2_pte_is_countedfunction stage2_pte_is_lockedfunction stage2_try_set_ptefunction stage2_try_break_ptefunction stage2_make_ptefunction stage2_unmap_defer_tlb_flushfunction stage2_unmap_put_ptefunction stage2_pte_cacheable
Annotated Snippet
struct kvm_pgtable_walk_data {
struct kvm_pgtable_walker *walker;
const u64 start;
u64 addr;
const u64 end;
};
static bool kvm_pgtable_walk_skip_bbm_tlbi(const struct kvm_pgtable_visit_ctx *ctx)
{
return unlikely(ctx->flags & KVM_PGTABLE_WALK_SKIP_BBM_TLBI);
}
static bool kvm_pgtable_walk_skip_cmo(const struct kvm_pgtable_visit_ctx *ctx)
{
return unlikely(ctx->flags & KVM_PGTABLE_WALK_SKIP_CMO);
}
static bool kvm_block_mapping_supported(const struct kvm_pgtable_visit_ctx *ctx, u64 phys)
{
u64 granule = kvm_granule_size(ctx->level);
if (!kvm_level_supports_block_mapping(ctx->level))
return false;
if (granule > (ctx->end - ctx->addr))
return false;
if (!IS_ALIGNED(phys, granule))
return false;
return IS_ALIGNED(ctx->addr, granule);
}
static u32 kvm_pgtable_idx(struct kvm_pgtable_walk_data *data, s8 level)
{
u64 shift = kvm_granule_shift(level);
u64 mask = BIT(PAGE_SHIFT - 3) - 1;
return (data->addr >> shift) & mask;
}
static u32 kvm_pgd_page_idx(struct kvm_pgtable *pgt, u64 addr)
{
u64 shift = kvm_granule_shift(pgt->start_level - 1); /* May underflow */
u64 mask = BIT(pgt->ia_bits) - 1;
return (addr & mask) >> shift;
}
static u32 kvm_pgd_pages(u32 ia_bits, s8 start_level)
{
struct kvm_pgtable pgt = {
.ia_bits = ia_bits,
.start_level = start_level,
};
return kvm_pgd_page_idx(&pgt, -1ULL) + 1;
}
static bool kvm_pte_table(kvm_pte_t pte, s8 level)
{
if (level == KVM_PGTABLE_LAST_LEVEL)
return false;
if (!kvm_pte_valid(pte))
return false;
return FIELD_GET(KVM_PTE_TYPE, pte) == KVM_PTE_TYPE_TABLE;
}
static kvm_pte_t *kvm_pte_follow(kvm_pte_t pte, struct kvm_pgtable_mm_ops *mm_ops)
{
return mm_ops->phys_to_virt(kvm_pte_to_phys(pte));
}
static void kvm_clear_pte(kvm_pte_t *ptep)
{
WRITE_ONCE(*ptep, 0);
}
static kvm_pte_t kvm_init_table_pte(kvm_pte_t *childp, struct kvm_pgtable_mm_ops *mm_ops)
{
kvm_pte_t pte = kvm_phys_to_pte(mm_ops->virt_to_phys(childp));
pte |= FIELD_PREP(KVM_PTE_TYPE, KVM_PTE_TYPE_TABLE);
pte |= KVM_PTE_VALID;
return pte;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `asm/kvm_pgtable.h`, `asm/stage2_pgtable.h`.
- Detected declarations: `struct kvm_pgtable_walk_data`, `struct leaf_walk_data`, `struct hyp_map_data`, `struct stage2_map_data`, `struct stage2_attr_data`, `struct stage2_age_data`, `function kvm_pgtable_walk_skip_bbm_tlbi`, `function kvm_pgtable_walk_skip_cmo`, `function kvm_block_mapping_supported`, `function kvm_pgtable_idx`.
- Atlas domain: Architecture Layer / arch/arm64.
- 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.