mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-03 17:51:23 +00:00

In preparation for supporting stage-2 huge mappings for np-guest. Add a nr_pages argument to the __pkvm_host_test_clear_young_guest hypercall. This range supports only two values: 1 or PMD_SIZE / PAGE_SIZE (that is 512 on a 4K-pages system). Signed-off-by: Vincent Donnefort <vdonnefort@google.com> Link: https://lore.kernel.org/r/20250521124834.1070650-7-vdonnefort@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
77 lines
2.6 KiB
C
77 lines
2.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2020 Google LLC
|
|
* Author: Quentin Perret <qperret@google.com>
|
|
*/
|
|
|
|
#ifndef __KVM_NVHE_MEM_PROTECT__
|
|
#define __KVM_NVHE_MEM_PROTECT__
|
|
#include <linux/kvm_host.h>
|
|
#include <asm/kvm_hyp.h>
|
|
#include <asm/kvm_mmu.h>
|
|
#include <asm/kvm_pgtable.h>
|
|
#include <asm/virt.h>
|
|
#include <nvhe/memory.h>
|
|
#include <nvhe/pkvm.h>
|
|
#include <nvhe/spinlock.h>
|
|
|
|
struct host_mmu {
|
|
struct kvm_arch arch;
|
|
struct kvm_pgtable pgt;
|
|
struct kvm_pgtable_mm_ops mm_ops;
|
|
hyp_spinlock_t lock;
|
|
};
|
|
extern struct host_mmu host_mmu;
|
|
|
|
/* This corresponds to page-table locking order */
|
|
enum pkvm_component_id {
|
|
PKVM_ID_HOST,
|
|
PKVM_ID_HYP,
|
|
PKVM_ID_FFA,
|
|
};
|
|
|
|
extern unsigned long hyp_nr_cpus;
|
|
|
|
int __pkvm_prot_finalize(void);
|
|
int __pkvm_host_share_hyp(u64 pfn);
|
|
int __pkvm_host_unshare_hyp(u64 pfn);
|
|
int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages);
|
|
int __pkvm_hyp_donate_host(u64 pfn, u64 nr_pages);
|
|
int __pkvm_host_share_ffa(u64 pfn, u64 nr_pages);
|
|
int __pkvm_host_unshare_ffa(u64 pfn, u64 nr_pages);
|
|
int __pkvm_host_share_guest(u64 pfn, u64 gfn, u64 nr_pages, struct pkvm_hyp_vcpu *vcpu,
|
|
enum kvm_pgtable_prot prot);
|
|
int __pkvm_host_unshare_guest(u64 gfn, u64 nr_pages, struct pkvm_hyp_vm *hyp_vm);
|
|
int __pkvm_host_relax_perms_guest(u64 gfn, struct pkvm_hyp_vcpu *vcpu, enum kvm_pgtable_prot prot);
|
|
int __pkvm_host_wrprotect_guest(u64 gfn, u64 nr_pages, struct pkvm_hyp_vm *hyp_vm);
|
|
int __pkvm_host_test_clear_young_guest(u64 gfn, u64 nr_pages, bool mkold, struct pkvm_hyp_vm *vm);
|
|
int __pkvm_host_mkyoung_guest(u64 gfn, struct pkvm_hyp_vcpu *vcpu);
|
|
|
|
bool addr_is_memory(phys_addr_t phys);
|
|
int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot);
|
|
int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id);
|
|
int kvm_host_prepare_stage2(void *pgt_pool_base);
|
|
int kvm_guest_prepare_stage2(struct pkvm_hyp_vm *vm, void *pgd);
|
|
void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt);
|
|
|
|
int hyp_pin_shared_mem(void *from, void *to);
|
|
void hyp_unpin_shared_mem(void *from, void *to);
|
|
void reclaim_pgtable_pages(struct pkvm_hyp_vm *vm, struct kvm_hyp_memcache *mc);
|
|
int refill_memcache(struct kvm_hyp_memcache *mc, unsigned long min_pages,
|
|
struct kvm_hyp_memcache *host_mc);
|
|
|
|
static __always_inline void __load_host_stage2(void)
|
|
{
|
|
if (static_branch_likely(&kvm_protected_mode_initialized))
|
|
__load_stage2(&host_mmu.arch.mmu, &host_mmu.arch);
|
|
else
|
|
write_sysreg(0, vttbr_el2);
|
|
}
|
|
|
|
#ifdef CONFIG_NVHE_EL2_DEBUG
|
|
void pkvm_ownership_selftest(void *base);
|
|
#else
|
|
static inline void pkvm_ownership_selftest(void *base) { }
|
|
#endif
|
|
#endif /* __KVM_NVHE_MEM_PROTECT__ */
|