arch/arm64/kvm/hyp/nvhe/mem_protect.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp/nvhe/mem_protect.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp/nvhe/mem_protect.c- Extension
.c- Size
- 51172 bytes
- Lines
- 1932
- 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.
- 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/kvm_host.hasm/kvm_emulate.hasm/kvm_hyp.hasm/kvm_mmu.hasm/kvm_pgtable.hasm/kvm_pkvm.hasm/stage2_pgtable.hhyp/fault.hnvhe/arm-smccc.hnvhe/gfp.hnvhe/memory.hnvhe/mem_protect.hnvhe/mm.hnvhe/trap_handler.h
Detected Declarations
struct kvm_mem_rangestruct check_walk_datastruct pkvm_expected_statefunction pkvm_sme_dvmsync_fw_callfunction guest_lock_componentfunction guest_unlock_componentfunction host_lock_componentfunction host_unlock_componentfunction hyp_lock_componentfunction hyp_unlock_componentfunction host_s2_get_pagefunction host_s2_put_pagefunction host_s2_free_unlinked_tablefunction prepare_s2_poolfunction prepare_host_vtcrfunction kvm_host_prepare_stage2function guest_s2_free_pages_exactfunction guest_s2_get_pagefunction guest_s2_put_pagefunction __apply_guest_pagefunction clean_dcache_guest_pagefunction invalidate_icache_guest_pagefunction kvm_guest_prepare_stage2function kvm_guest_destroy_stage2function reclaim_pgtable_pagesfunction __pkvm_prot_finalizefunction host_stage2_unmap_dev_allfunction pfn_range_is_validfunction addr_is_memoryfunction is_in_mem_rangefunction check_range_allowed_memoryfunction range_is_memoryfunction __host_stage2_idmapfunction range_includedfunction host_stage2_adjust_rangefunction host_stage2_idmap_lockedfunction __host_update_page_statefunction host_stage2_set_owner_metadata_lockedfunction host_stage2_set_owner_lockedfunction host_stage2_encode_gfn_metafunction host_stage2_decode_gfn_metafunction host_stage2_force_pte_cbfunction host_stage2_idmapfunction host_inject_mem_abortfunction handle_host_mem_abortfunction __check_page_state_visitorfunction check_page_state_rangefunction __host_check_page_state_range
Annotated Snippet
struct kvm_mem_range {
u64 start;
u64 end;
};
static struct memblock_region *find_mem_range(phys_addr_t addr, struct kvm_mem_range *range)
{
int cur, left = 0, right = hyp_memblock_nr;
struct memblock_region *reg;
phys_addr_t end;
range->start = 0;
range->end = ULONG_MAX;
/* The list of memblock regions is sorted, binary search it */
while (left < right) {
cur = (left + right) >> 1;
reg = &hyp_memory[cur];
end = reg->base + reg->size;
if (addr < reg->base) {
right = cur;
range->end = reg->base;
} else if (addr >= end) {
left = cur + 1;
range->start = end;
} else {
range->start = reg->base;
range->end = end;
return reg;
}
}
return NULL;
}
bool addr_is_memory(phys_addr_t phys)
{
struct kvm_mem_range range;
return !!find_mem_range(phys, &range);
}
static bool is_in_mem_range(u64 addr, struct kvm_mem_range *range)
{
return range->start <= addr && addr < range->end;
}
static int check_range_allowed_memory(u64 start, u64 end)
{
struct memblock_region *reg;
struct kvm_mem_range range;
/*
* Callers can't check the state of a range that overlaps memory and
* MMIO regions, so ensure [start, end[ is in the same kvm_mem_range.
*/
reg = find_mem_range(start, &range);
if (!is_in_mem_range(end - 1, &range))
return -EINVAL;
if (!reg || reg->flags & MEMBLOCK_NOMAP)
return -EPERM;
return 0;
}
static bool range_is_memory(u64 start, u64 end)
{
struct kvm_mem_range r;
if (!find_mem_range(start, &r))
return false;
return is_in_mem_range(end - 1, &r);
}
static inline int __host_stage2_idmap(u64 start, u64 end,
enum kvm_pgtable_prot prot)
{
/*
* We don't make permission changes to the host idmap after
* initialisation, so we can squash -EAGAIN to save callers
* having to treat it like success in the case that they try to
* map something that is already mapped.
*/
return kvm_pgtable_stage2_map(&host_mmu.pgt, start, end - start, start,
prot, &host_s2_pool,
KVM_PGTABLE_WALK_IGNORE_EAGAIN);
}
Annotation
- Immediate include surface: `linux/kvm_host.h`, `asm/kvm_emulate.h`, `asm/kvm_hyp.h`, `asm/kvm_mmu.h`, `asm/kvm_pgtable.h`, `asm/kvm_pkvm.h`, `asm/stage2_pgtable.h`, `hyp/fault.h`.
- Detected declarations: `struct kvm_mem_range`, `struct check_walk_data`, `struct pkvm_expected_state`, `function pkvm_sme_dvmsync_fw_call`, `function guest_lock_component`, `function guest_unlock_component`, `function host_lock_component`, `function host_unlock_component`, `function hyp_lock_component`, `function hyp_unlock_component`.
- Atlas domain: Architecture Layer / arch/arm64.
- 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.