arch/arm64/kvm/hyp/nvhe/mm.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp/nvhe/mm.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp/nvhe/mm.c- Extension
.c- Size
- 11969 bytes
- Lines
- 505
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kvm_host.hasm/kvm_hyp.hasm/kvm_mmu.hasm/kvm_pgtable.hasm/kvm_pkvm.hasm/spectre.hnvhe/early_alloc.hnvhe/gfp.hnvhe/memory.hnvhe/mem_protect.hnvhe/mm.hnvhe/spinlock.h
Detected Declarations
struct hyp_fixmap_slotfunction __pkvm_create_mappingsfunction __pkvm_alloc_private_va_rangefunction addressfunction __pkvm_create_private_mappingfunction pkvm_create_mappings_lockedfunction pkvm_create_mappingsfunction hyp_back_vmemmapfunction pkvm_cpu_set_vectorfunction hyp_map_vectorsfunction fixmap_clear_slotfunction hyp_fixmap_unmapfunction __create_fixmap_slot_cbfunction create_fixmap_slotfunction create_fixblockfunction hyp_fixblock_unmapfunction hyp_create_fixmapfunction hyp_create_idmapfunction pkvm_create_stackfunction refill_memcache
Annotated Snippet
struct hyp_fixmap_slot {
u64 addr;
kvm_pte_t *ptep;
};
static DEFINE_PER_CPU(struct hyp_fixmap_slot, fixmap_slots);
static int __pkvm_create_mappings(unsigned long start, unsigned long size,
unsigned long phys, enum kvm_pgtable_prot prot)
{
int err;
hyp_spin_lock(&pkvm_pgd_lock);
err = kvm_pgtable_hyp_map(&pkvm_pgtable, start, size, phys, prot);
hyp_spin_unlock(&pkvm_pgd_lock);
return err;
}
static int __pkvm_alloc_private_va_range(unsigned long start, size_t size)
{
unsigned long cur;
hyp_assert_lock_held(&pkvm_pgd_lock);
if (!start || start < __io_map_base)
return -EINVAL;
/* The allocated size is always a multiple of PAGE_SIZE */
cur = start + PAGE_ALIGN(size);
/* Are we overflowing on the vmemmap ? */
if (cur > __hyp_vmemmap)
return -ENOMEM;
__io_map_base = cur;
return 0;
}
/**
* pkvm_alloc_private_va_range - Allocates a private VA range.
* @size: The size of the VA range to reserve.
* @haddr: The hypervisor virtual start address of the allocation.
*
* The private virtual address (VA) range is allocated above __io_map_base
* and aligned based on the order of @size.
*
* Return: 0 on success or negative error code on failure.
*/
int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr)
{
unsigned long addr;
int ret;
hyp_spin_lock(&pkvm_pgd_lock);
addr = __io_map_base;
ret = __pkvm_alloc_private_va_range(addr, size);
hyp_spin_unlock(&pkvm_pgd_lock);
*haddr = addr;
return ret;
}
int __pkvm_create_private_mapping(phys_addr_t phys, size_t size,
enum kvm_pgtable_prot prot,
unsigned long *haddr)
{
unsigned long addr;
int err;
size = PAGE_ALIGN(size + offset_in_page(phys));
err = pkvm_alloc_private_va_range(size, &addr);
if (err)
return err;
err = __pkvm_create_mappings(addr, size, phys, prot);
if (err)
return err;
*haddr = addr + offset_in_page(phys);
return err;
}
int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot)
{
unsigned long start = (unsigned long)from;
unsigned long end = (unsigned long)to;
unsigned long virt_addr;
phys_addr_t phys;
Annotation
- Immediate include surface: `linux/kvm_host.h`, `asm/kvm_hyp.h`, `asm/kvm_mmu.h`, `asm/kvm_pgtable.h`, `asm/kvm_pkvm.h`, `asm/spectre.h`, `nvhe/early_alloc.h`, `nvhe/gfp.h`.
- Detected declarations: `struct hyp_fixmap_slot`, `function __pkvm_create_mappings`, `function __pkvm_alloc_private_va_range`, `function address`, `function __pkvm_create_private_mapping`, `function pkvm_create_mappings_locked`, `function pkvm_create_mappings`, `function hyp_back_vmemmap`, `function pkvm_cpu_set_vector`, `function hyp_map_vectors`.
- 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.