Path: blob/master/arch/arm64/kvm/hyp/include/nvhe/pkvm.h
26532 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2021 Google LLC3* Author: Fuad Tabba <[email protected]>4*/56#ifndef __ARM64_KVM_NVHE_PKVM_H__7#define __ARM64_KVM_NVHE_PKVM_H__89#include <asm/kvm_pkvm.h>1011#include <nvhe/gfp.h>12#include <nvhe/spinlock.h>1314/*15* Holds the relevant data for maintaining the vcpu state completely at hyp.16*/17struct pkvm_hyp_vcpu {18struct kvm_vcpu vcpu;1920/* Backpointer to the host's (untrusted) vCPU instance. */21struct kvm_vcpu *host_vcpu;2223/*24* If this hyp vCPU is loaded, then this is a backpointer to the25* per-cpu pointer tracking us. Otherwise, NULL if not loaded.26*/27struct pkvm_hyp_vcpu **loaded_hyp_vcpu;28};2930/*31* Holds the relevant data for running a protected vm.32*/33struct pkvm_hyp_vm {34struct kvm kvm;3536/* Backpointer to the host's (untrusted) KVM instance. */37struct kvm *host_kvm;3839/* The guest's stage-2 page-table managed by the hypervisor. */40struct kvm_pgtable pgt;41struct kvm_pgtable_mm_ops mm_ops;42struct hyp_pool pool;43hyp_spinlock_t lock;4445/* Array of the hyp vCPU structures for this VM. */46struct pkvm_hyp_vcpu *vcpus[];47};4849extern hyp_spinlock_t vm_table_lock;5051static inline struct pkvm_hyp_vm *52pkvm_hyp_vcpu_to_hyp_vm(struct pkvm_hyp_vcpu *hyp_vcpu)53{54return container_of(hyp_vcpu->vcpu.kvm, struct pkvm_hyp_vm, kvm);55}5657static inline bool pkvm_hyp_vcpu_is_protected(struct pkvm_hyp_vcpu *hyp_vcpu)58{59return vcpu_is_protected(&hyp_vcpu->vcpu);60}6162static inline bool pkvm_hyp_vm_is_protected(struct pkvm_hyp_vm *hyp_vm)63{64return kvm_vm_is_protected(&hyp_vm->kvm);65}6667void pkvm_hyp_vm_table_init(void *tbl);6869int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva,70unsigned long pgd_hva);71int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu,72unsigned long vcpu_hva);73int __pkvm_teardown_vm(pkvm_handle_t handle);7475struct pkvm_hyp_vcpu *pkvm_load_hyp_vcpu(pkvm_handle_t handle,76unsigned int vcpu_idx);77void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu);78struct pkvm_hyp_vcpu *pkvm_get_loaded_hyp_vcpu(void);7980struct pkvm_hyp_vm *get_pkvm_hyp_vm(pkvm_handle_t handle);81struct pkvm_hyp_vm *get_np_pkvm_hyp_vm(pkvm_handle_t handle);82void put_pkvm_hyp_vm(struct pkvm_hyp_vm *hyp_vm);8384bool kvm_handle_pvm_sysreg(struct kvm_vcpu *vcpu, u64 *exit_code);85bool kvm_handle_pvm_restricted(struct kvm_vcpu *vcpu, u64 *exit_code);86void kvm_init_pvm_id_regs(struct kvm_vcpu *vcpu);87int kvm_check_pvm_sysreg_table(void);8889#endif /* __ARM64_KVM_NVHE_PKVM_H__ */909192