xref: /openbmc/linux/arch/arm64/kvm/hyp/include/nvhe/pkvm.h (revision be66e67f)
1a1ec5c70SFuad Tabba /* SPDX-License-Identifier: GPL-2.0-only */
2a1ec5c70SFuad Tabba /*
3a1ec5c70SFuad Tabba  * Copyright (C) 2021 Google LLC
4a1ec5c70SFuad Tabba  * Author: Fuad Tabba <tabba@google.com>
5a1ec5c70SFuad Tabba  */
6a1ec5c70SFuad Tabba 
7a1ec5c70SFuad Tabba #ifndef __ARM64_KVM_NVHE_PKVM_H__
8a1ec5c70SFuad Tabba #define __ARM64_KVM_NVHE_PKVM_H__
9a1ec5c70SFuad Tabba 
10a1ec5c70SFuad Tabba #include <asm/kvm_pkvm.h>
11a1ec5c70SFuad Tabba 
1260dfe093SQuentin Perret #include <nvhe/gfp.h>
1360dfe093SQuentin Perret #include <nvhe/spinlock.h>
1460dfe093SQuentin Perret 
15a1ec5c70SFuad Tabba /*
16a1ec5c70SFuad Tabba  * Holds the relevant data for maintaining the vcpu state completely at hyp.
17a1ec5c70SFuad Tabba  */
18a1ec5c70SFuad Tabba struct pkvm_hyp_vcpu {
19a1ec5c70SFuad Tabba 	struct kvm_vcpu vcpu;
20a1ec5c70SFuad Tabba 
21a1ec5c70SFuad Tabba 	/* Backpointer to the host's (untrusted) vCPU instance. */
22a1ec5c70SFuad Tabba 	struct kvm_vcpu *host_vcpu;
23a1ec5c70SFuad Tabba };
24a1ec5c70SFuad Tabba 
25a1ec5c70SFuad Tabba /*
26a1ec5c70SFuad Tabba  * Holds the relevant data for running a protected vm.
27a1ec5c70SFuad Tabba  */
28a1ec5c70SFuad Tabba struct pkvm_hyp_vm {
29a1ec5c70SFuad Tabba 	struct kvm kvm;
30a1ec5c70SFuad Tabba 
31a1ec5c70SFuad Tabba 	/* Backpointer to the host's (untrusted) KVM instance. */
32a1ec5c70SFuad Tabba 	struct kvm *host_kvm;
33a1ec5c70SFuad Tabba 
34a1ec5c70SFuad Tabba 	/* The guest's stage-2 page-table managed by the hypervisor. */
35a1ec5c70SFuad Tabba 	struct kvm_pgtable pgt;
3660dfe093SQuentin Perret 	struct kvm_pgtable_mm_ops mm_ops;
3760dfe093SQuentin Perret 	struct hyp_pool pool;
3860dfe093SQuentin Perret 	hyp_spinlock_t lock;
39a1ec5c70SFuad Tabba 
40a1ec5c70SFuad Tabba 	/*
41a1ec5c70SFuad Tabba 	 * The number of vcpus initialized and ready to run.
42a1ec5c70SFuad Tabba 	 * Modifying this is protected by 'vm_table_lock'.
43a1ec5c70SFuad Tabba 	 */
44a1ec5c70SFuad Tabba 	unsigned int nr_vcpus;
45a1ec5c70SFuad Tabba 
46a1ec5c70SFuad Tabba 	/* Array of the hyp vCPU structures for this VM. */
47a1ec5c70SFuad Tabba 	struct pkvm_hyp_vcpu *vcpus[];
48a1ec5c70SFuad Tabba };
49a1ec5c70SFuad Tabba 
50a1ec5c70SFuad Tabba static inline struct pkvm_hyp_vm *
pkvm_hyp_vcpu_to_hyp_vm(struct pkvm_hyp_vcpu * hyp_vcpu)51a1ec5c70SFuad Tabba pkvm_hyp_vcpu_to_hyp_vm(struct pkvm_hyp_vcpu *hyp_vcpu)
52a1ec5c70SFuad Tabba {
53a1ec5c70SFuad Tabba 	return container_of(hyp_vcpu->vcpu.kvm, struct pkvm_hyp_vm, kvm);
54a1ec5c70SFuad Tabba }
55a1ec5c70SFuad Tabba 
56a1ec5c70SFuad Tabba void pkvm_hyp_vm_table_init(void *tbl);
57a1ec5c70SFuad Tabba 
58a1ec5c70SFuad Tabba int __pkvm_init_vm(struct kvm *host_kvm, unsigned long vm_hva,
59a1ec5c70SFuad Tabba 		   unsigned long pgd_hva);
60a1ec5c70SFuad Tabba int __pkvm_init_vcpu(pkvm_handle_t handle, struct kvm_vcpu *host_vcpu,
61a1ec5c70SFuad Tabba 		     unsigned long vcpu_hva);
62a1ec5c70SFuad Tabba int __pkvm_teardown_vm(pkvm_handle_t handle);
63a1ec5c70SFuad Tabba 
64*be66e67fSWill Deacon struct pkvm_hyp_vcpu *pkvm_load_hyp_vcpu(pkvm_handle_t handle,
65*be66e67fSWill Deacon 					 unsigned int vcpu_idx);
66*be66e67fSWill Deacon void pkvm_put_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu);
67*be66e67fSWill Deacon 
68a1ec5c70SFuad Tabba #endif /* __ARM64_KVM_NVHE_PKVM_H__ */
69