#include <linux/kvm_host.h>
#include <asm/kvm_hyp.h>
#include <asm/kvm_mmu.h>
#include <asm/kvm_pgtable.h>
#include <asm/kvm_pkvm.h>
#include <asm/spectre.h>
#include <nvhe/early_alloc.h>
#include <nvhe/gfp.h>
#include <nvhe/memory.h>
#include <nvhe/mem_protect.h>
#include <nvhe/mm.h>
#include <nvhe/spinlock.h>
Go to the source code of this file.
|
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) |
|
static int | __pkvm_alloc_private_va_range (unsigned long start, size_t size) |
|
int | pkvm_alloc_private_va_range (size_t size, unsigned long *haddr) |
|
int | __pkvm_create_private_mapping (phys_addr_t phys, size_t size, enum kvm_pgtable_prot prot, unsigned long *haddr) |
|
int | pkvm_create_mappings_locked (void *from, void *to, enum kvm_pgtable_prot prot) |
|
int | pkvm_create_mappings (void *from, void *to, enum kvm_pgtable_prot prot) |
|
int | hyp_back_vmemmap (phys_addr_t back) |
|
int | pkvm_cpu_set_vector (enum arm64_hyp_spectre_vector slot) |
|
int | hyp_map_vectors (void) |
|
void * | hyp_fixmap_map (phys_addr_t phys) |
|
static void | fixmap_clear_slot (struct hyp_fixmap_slot *slot) |
|
void | hyp_fixmap_unmap (void) |
|
static int | __create_fixmap_slot_cb (const struct kvm_pgtable_visit_ctx *ctx, enum kvm_pgtable_walk_flags visit) |
|
static int | create_fixmap_slot (u64 addr, u64 cpu) |
|
int | hyp_create_pcpu_fixmap (void) |
|
int | hyp_create_idmap (u32 hyp_va_bits) |
|
int | pkvm_create_stack (phys_addr_t phys, unsigned long *haddr) |
|
static void * | admit_host_page (void *arg) |
|
int | refill_memcache (struct kvm_hyp_memcache *mc, unsigned long min_pages, struct kvm_hyp_memcache *host_mc) |
|
◆ __create_fixmap_slot_cb()
static int __create_fixmap_slot_cb |
( |
const struct kvm_pgtable_visit_ctx * |
ctx, |
|
|
enum kvm_pgtable_walk_flags |
visit |
|
) |
| |
|
static |
Definition at line 273 of file mm.c.
276 struct hyp_fixmap_slot *slot = per_cpu_ptr(&fixmap_slots, (u64)ctx->arg);
278 if (!kvm_pte_valid(ctx->old) || ctx->level != KVM_PGTABLE_LAST_LEVEL)
281 slot->
addr = ctx->addr;
282 slot->
ptep = ctx->ptep;
static void fixmap_clear_slot(struct hyp_fixmap_slot *slot)
◆ __pkvm_alloc_private_va_range()
static int __pkvm_alloc_private_va_range |
( |
unsigned long |
start, |
|
|
size_t |
size |
|
) |
| |
|
static |
Definition at line 47 of file mm.c.
hyp_spinlock_t pkvm_pgd_lock
static void hyp_assert_lock_held(hyp_spinlock_t *lock)
◆ __pkvm_create_mappings()
static int __pkvm_create_mappings |
( |
unsigned long |
start, |
|
|
unsigned long |
size, |
|
|
unsigned long |
phys, |
|
|
enum kvm_pgtable_prot |
prot |
|
) |
| |
|
static |
Definition at line 35 of file mm.c.
struct kvm_pgtable pkvm_pgtable
int kvm_pgtable_hyp_map(struct kvm_pgtable *pgt, u64 addr, u64 size, u64 phys, enum kvm_pgtable_prot prot)
static void hyp_spin_unlock(hyp_spinlock_t *lock)
static void hyp_spin_lock(hyp_spinlock_t *lock)
◆ __pkvm_create_private_mapping()
int __pkvm_create_private_mapping |
( |
phys_addr_t |
phys, |
|
|
size_t |
size, |
|
|
enum kvm_pgtable_prot |
prot, |
|
|
unsigned long * |
haddr |
|
) |
| |
Definition at line 93 of file mm.c.
100 size = PAGE_ALIGN(
size + offset_in_page(phys));
109 *haddr = addr + offset_in_page(phys);
static int __pkvm_create_mappings(unsigned long start, unsigned long size, unsigned long phys, enum kvm_pgtable_prot prot)
int pkvm_alloc_private_va_range(size_t size, unsigned long *haddr)
◆ admit_host_page()
static void* admit_host_page |
( |
void * |
arg | ) |
|
|
static |
Definition at line 392 of file mm.c.
394 struct kvm_hyp_memcache *host_mc = arg;
396 if (!host_mc->nr_pages)
int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages)
static void * hyp_phys_to_virt(phys_addr_t phys)
#define hyp_phys_to_pfn(phys)
◆ create_fixmap_slot()
static int create_fixmap_slot |
( |
u64 |
addr, |
|
|
u64 |
cpu |
|
) |
| |
|
static |
Definition at line 294 of file mm.c.
296 struct kvm_pgtable_walker walker = {
298 .flags = KVM_PGTABLE_WALK_LEAF,
static int __create_fixmap_slot_cb(const struct kvm_pgtable_visit_ctx *ctx, enum kvm_pgtable_walk_flags visit)
int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, struct kvm_pgtable_walker *walker)
◆ DEFINE_PER_CPU()
◆ fixmap_clear_slot()
Definition at line 246 of file mm.c.
248 kvm_pte_t *ptep = slot->
ptep;
249 u64 addr = slot->
addr;
251 WRITE_ONCE(*ptep, *ptep & ~KVM_PTE_VALID);
263 __tlbi_level(vale2is, __TLBI_VADDR(addr, 0), KVM_PGTABLE_LAST_LEVEL);
◆ hyp_back_vmemmap()
int hyp_back_vmemmap |
( |
phys_addr_t |
back | ) |
|
Definition at line 149 of file mm.c.
151 unsigned long i, start,
size,
end = 0;
162 start = max(start,
end);
#define hyp_phys_to_page(phys)
struct memblock_region hyp_memory[HYP_MEMBLOCK_REGIONS]
unsigned int hyp_memblock_nr
◆ hyp_create_idmap()
int hyp_create_idmap |
( |
u32 |
hyp_va_bits | ) |
|
Definition at line 328 of file mm.c.
330 unsigned long start,
end;
333 start = ALIGN_DOWN(start, PAGE_SIZE);
336 end = ALIGN(
end, PAGE_SIZE);
static phys_addr_t hyp_virt_to_phys(void *addr)
◆ hyp_create_pcpu_fixmap()
int hyp_create_pcpu_fixmap |
( |
void |
| ) |
|
Definition at line 305 of file mm.c.
307 unsigned long addr, i;
316 __hyp_pa(__hyp_bss_start), PAGE_HYP);
unsigned long hyp_nr_cpus
static int create_fixmap_slot(u64 addr, u64 cpu)
◆ hyp_fixmap_map()
void* hyp_fixmap_map |
( |
phys_addr_t |
phys | ) |
|
Definition at line 232 of file mm.c.
238 pte &= ~kvm_phys_to_pte(KVM_PHYS_INVALID);
239 pte |= kvm_phys_to_pte(phys) | KVM_PTE_VALID;
240 WRITE_ONCE(*
ptep, pte);
243 return (
void *)slot->
addr;
◆ hyp_fixmap_unmap()
void hyp_fixmap_unmap |
( |
void |
| ) |
|
Definition at line 268 of file mm.c.
◆ hyp_map_vectors()
int hyp_map_vectors |
( |
void |
| ) |
|
Definition at line 210 of file mm.c.
213 unsigned long bp_base;
216 if (!kvm_system_needs_idmapped_vectors()) {
221 phys = __hyp_pa(__bp_harden_hyp_vecs);
223 PAGE_HYP_EXEC, &bp_base);
int __pkvm_create_private_mapping(phys_addr_t phys, size_t size, enum kvm_pgtable_prot prot, unsigned long *haddr)
static void * __hyp_bp_vect_base
◆ pkvm_alloc_private_va_range()
int pkvm_alloc_private_va_range |
( |
size_t |
size, |
|
|
unsigned long * |
haddr |
|
) |
| |
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.
Definition at line 78 of file mm.c.
static int __pkvm_alloc_private_va_range(unsigned long start, size_t size)
◆ pkvm_cpu_set_vector()
int pkvm_cpu_set_vector |
( |
enum arm64_hyp_spectre_vector |
slot | ) |
|
Definition at line 182 of file mm.c.
187 case HYP_VECTOR_DIRECT: {
188 vector = __kvm_hyp_vector;
191 case HYP_VECTOR_SPECTRE_DIRECT: {
192 vector = __bp_harden_hyp_vecs;
195 case HYP_VECTOR_INDIRECT:
196 case HYP_VECTOR_SPECTRE_INDIRECT: {
204 vector = __kvm_vector_slot2addr(vector, slot);
205 *this_cpu_ptr(&kvm_hyp_vector) = (
unsigned long)vector;
◆ pkvm_create_mappings()
int pkvm_create_mappings |
( |
void * |
from, |
|
|
void * |
to, |
|
|
enum kvm_pgtable_prot |
prot |
|
) |
| |
Definition at line 138 of file mm.c.
int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot)
◆ pkvm_create_mappings_locked()
int pkvm_create_mappings_locked |
( |
void * |
from, |
|
|
void * |
to, |
|
|
enum kvm_pgtable_prot |
prot |
|
) |
| |
Definition at line 113 of file mm.c.
115 unsigned long start = (
unsigned long)from;
116 unsigned long end = (
unsigned long)to;
117 unsigned long virt_addr;
122 start = start & PAGE_MASK;
125 for (virt_addr = start; virt_addr <
end; virt_addr += PAGE_SIZE) {
◆ pkvm_create_stack()
int pkvm_create_stack |
( |
phys_addr_t |
phys, |
|
|
unsigned long * |
haddr |
|
) |
| |
Definition at line 353 of file mm.c.
355 unsigned long addr, prev_base;
366 size = PAGE_SIZE * 2;
381 PAGE_SIZE, phys, PAGE_HYP);
387 *haddr = addr +
size;
◆ refill_memcache()
int refill_memcache |
( |
struct kvm_hyp_memcache * |
mc, |
|
|
unsigned long |
min_pages, |
|
|
struct kvm_hyp_memcache * |
host_mc |
|
) |
| |
Definition at line 412 of file mm.c.
415 struct kvm_hyp_memcache tmp = *host_mc;
static void * admit_host_page(void *arg)
◆ __hyp_bp_vect_base
Definition at line 181 of file mm.c.
◆ __io_map_base
Definition at line 27 of file mm.c.
◆ hyp_memblock_nr
unsigned int hyp_memblock_nr |
Definition at line 25 of file mm.c.
◆ hyp_memory
struct memblock_region hyp_memory[HYP_MEMBLOCK_REGIONS] |
Definition at line 22 of file mm.c.
◆ pkvm_pgd_lock
Definition at line 22 of file mm.c.
◆ pkvm_pgtable
struct kvm_pgtable pkvm_pgtable |
Definition at line 1 of file mm.c.