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