1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2020 Google LLC
4  * Author: Quentin Perret <qperret@google.com>
5  */
6 
7 #ifndef __KVM_NVHE_MEM_PROTECT__
8 #define __KVM_NVHE_MEM_PROTECT__
9 #include <linux/kvm_host.h>
10 #include <asm/kvm_hyp.h>
11 #include <asm/kvm_pgtable.h>
12 #include <asm/virt.h>
13 #include <nvhe/spinlock.h>
14 
15 struct host_kvm {
16 	struct kvm_arch arch;
17 	struct kvm_pgtable pgt;
18 	struct kvm_pgtable_mm_ops mm_ops;
19 	hyp_spinlock_t lock;
20 };
21 extern struct host_kvm host_kvm;
22 
23 int __pkvm_prot_finalize(void);
24 int __pkvm_mark_hyp(phys_addr_t start, phys_addr_t end);
25 
26 int kvm_host_prepare_stage2(void *pgt_pool_base);
27 void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt);
28 
29 static __always_inline void __load_host_stage2(void)
30 {
31 	if (static_branch_likely(&kvm_protected_mode_initialized))
32 		__load_stage2(&host_kvm.arch.mmu, host_kvm.arch.vtcr);
33 	else
34 		write_sysreg(0, vttbr_el2);
35 }
36 #endif /* __KVM_NVHE_MEM_PROTECT__ */
37