• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __KVM_NVHE_ALLOC__
3 #define __KVM_NVHE_ALLOC__
4 #include <linux/types.h>
5 
6 #include <asm/kvm_host.h>
7 
8 /**
9  * hyp_alloc() - Allocate memory from the heap allocator
10  *
11  * @size:	Allocation size in bytes.
12  *
13  * Return: A pointer to the allocated memory on success, else NULL.
14  */
15 void *hyp_alloc(size_t size);
16 
17 /**
18  * hyp_alloc_account() - Allocate memory from the heap allocator and account
19  *
20  * Similar to hyp_alloc(). But on success, the allocated memory will be
21  * accounted against the vm (@host_kvm) protected_hyp_mem counter. This allows
22  * the host to know about detailed footprint of that vm.
23  *
24  * @size:	Allocation size in bytes.
25  * @host_kvm:	Pointer (in the hyp VA space) to the host KVM struct.
26  *
27  * Return: A pointer to the allocated memory on success, else NULL.
28  */
29 void *hyp_alloc_account(size_t size, struct kvm *host_kvm);
30 
31 /**
32  * hyp_alloc_errno() - Read the errno on allocation error
33  *
34  * Get the return code from an allocation failure.
35  *
36  * Return: -ENOMEM if the allocator needs a refill from the host, -E2BIG if
37  * there is no VA space left else 0.
38  */
39 int hyp_alloc_errno(void);
40 
41 /**
42  * hyp_free() - Free memory allocated with hyp_alloc()
43  *
44  * @addr:	Address returned by the original hyp_alloc().
45  *
46  * The use of any other address than one returned by hyp_alloc() will cause a
47  * hypervisor panic.
48  */
49 void hyp_free(void *addr);
50 
51 /**
52  * hyp_free_account() - Free memory allocated with hyp_alloc_account()
53  *
54  * Similar to hyp_free, but for memory allocated with hyp_alloc_account().
55  *
56  * @addr:	Address returned by the original hyp_alloc_account().
57  * @host_kvm:	pointer (in the hyp VA space) to the host KVM struct.
58  *
59  * The use of any other address than one returned by hyp_alloc() will cause a
60  * hypervisor panic.
61  */
62 void hyp_free_account(void *addr, struct kvm *host_kvm);
63 
64 int hyp_alloc_init(size_t size);
65 int hyp_alloc_refill(struct kvm_hyp_memcache *host_mc);
66 int hyp_alloc_reclaimable(void);
67 void hyp_alloc_reclaim(struct kvm_hyp_memcache *host_mc, int target);
68 u8 hyp_alloc_missing_donations(void);
69 
70 extern struct hyp_mgt_allocator_ops hyp_alloc_ops;
71 #endif
72