1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2020 Google LLC
4  * Author: Will Deacon <will@kernel.org>
5  */
6 
7 #ifndef __ARM64_KVM_PGTABLE_H__
8 #define __ARM64_KVM_PGTABLE_H__
9 
10 #include <linux/bits.h>
11 #include <linux/kvm_host.h>
12 #include <linux/types.h>
13 
14 #define KVM_PGTABLE_MAX_LEVELS		4U
15 
16 /*
17  * The largest supported block sizes for KVM (no 52-bit PA support):
18  *  - 4K (level 1):	1GB
19  *  - 16K (level 2):	32MB
20  *  - 64K (level 2):	512MB
21  */
22 #ifdef CONFIG_ARM64_4K_PAGES
23 #define KVM_PGTABLE_MIN_BLOCK_LEVEL	1U
24 #else
25 #define KVM_PGTABLE_MIN_BLOCK_LEVEL	2U
26 #endif
27 
kvm_get_parange(u64 mmfr0)28 static inline u64 kvm_get_parange(u64 mmfr0)
29 {
30 	u64 parange = cpuid_feature_extract_unsigned_field(mmfr0,
31 				ID_AA64MMFR0_EL1_PARANGE_SHIFT);
32 	if (parange > ID_AA64MMFR0_EL1_PARANGE_MAX)
33 		parange = ID_AA64MMFR0_EL1_PARANGE_MAX;
34 
35 	return parange;
36 }
37 
38 typedef u64 kvm_pte_t;
39 
40 #define KVM_PTE_VALID			BIT(0)
41 
42 #define KVM_PTE_ADDR_MASK		GENMASK(47, PAGE_SHIFT)
43 #define KVM_PTE_ADDR_51_48		GENMASK(15, 12)
44 
kvm_pte_valid(kvm_pte_t pte)45 static inline bool kvm_pte_valid(kvm_pte_t pte)
46 {
47 	return pte & KVM_PTE_VALID;
48 }
49 
kvm_pte_to_phys(kvm_pte_t pte)50 static inline u64 kvm_pte_to_phys(kvm_pte_t pte)
51 {
52 	u64 pa = pte & KVM_PTE_ADDR_MASK;
53 
54 	if (PAGE_SHIFT == 16)
55 		pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48;
56 
57 	return pa;
58 }
59 
kvm_granule_shift(u32 level)60 static inline u64 kvm_granule_shift(u32 level)
61 {
62 	/* Assumes KVM_PGTABLE_MAX_LEVELS is 4 */
63 	return ARM64_HW_PGTABLE_LEVEL_SHIFT(level);
64 }
65 
kvm_granule_size(u32 level)66 static inline u64 kvm_granule_size(u32 level)
67 {
68 	return BIT(kvm_granule_shift(level));
69 }
70 
kvm_level_supports_block_mapping(u32 level)71 static inline bool kvm_level_supports_block_mapping(u32 level)
72 {
73 	return level >= KVM_PGTABLE_MIN_BLOCK_LEVEL;
74 }
75 
76 /**
77  * struct kvm_pgtable_mm_ops - Memory management callbacks.
78  * @zalloc_page:		Allocate a single zeroed memory page.
79  *				The @arg parameter can be used by the walker
80  *				to pass a memcache. The initial refcount of
81  *				the page is 1.
82  * @zalloc_pages_exact:		Allocate an exact number of zeroed memory pages.
83  *				The @size parameter is in bytes, and is rounded
84  *				up to the next page boundary. The resulting
85  *				allocation is physically contiguous.
86  * @free_pages_exact:		Free an exact number of memory pages previously
87  *				allocated by zalloc_pages_exact.
88  * @get_page:			Increment the refcount on a page.
89  * @put_page:			Decrement the refcount on a page. When the
90  *				refcount reaches 0 the page is automatically
91  *				freed.
92  * @page_count:			Return the refcount of a page.
93  * @phys_to_virt:		Convert a physical address into a virtual
94  *				address	mapped in the current context.
95  * @virt_to_phys:		Convert a virtual address mapped in the current
96  *				context into a physical address.
97  * @dcache_clean_inval_poc:	Clean and invalidate the data cache to the PoC
98  *				for the	specified memory address range.
99  * @icache_inval_pou:		Invalidate the instruction cache to the PoU
100  *				for the specified memory address range.
101  */
102 struct kvm_pgtable_mm_ops {
103 	void*		(*zalloc_page)(void *arg);
104 	void*		(*zalloc_pages_exact)(size_t size);
105 	void		(*free_pages_exact)(void *addr, size_t size);
106 	void		(*get_page)(void *addr);
107 	void		(*put_page)(void *addr);
108 	int		(*page_count)(void *addr);
109 	void*		(*phys_to_virt)(phys_addr_t phys);
110 	phys_addr_t	(*virt_to_phys)(void *addr);
111 	void		(*dcache_clean_inval_poc)(void *addr, size_t size);
112 	void		(*icache_inval_pou)(void *addr, size_t size);
113 };
114 
115 /**
116  * enum kvm_pgtable_stage2_flags - Stage-2 page-table flags.
117  * @KVM_PGTABLE_S2_NOFWB:	Don't enforce Normal-WB even if the CPUs have
118  *				ARM64_HAS_STAGE2_FWB.
119  * @KVM_PGTABLE_S2_IDMAP:	Only use identity mappings.
120  */
121 enum kvm_pgtable_stage2_flags {
122 	KVM_PGTABLE_S2_NOFWB			= BIT(0),
123 	KVM_PGTABLE_S2_IDMAP			= BIT(1),
124 };
125 
126 /**
127  * enum kvm_pgtable_prot - Page-table permissions and attributes.
128  * @KVM_PGTABLE_PROT_X:		Execute permission.
129  * @KVM_PGTABLE_PROT_W:		Write permission.
130  * @KVM_PGTABLE_PROT_R:		Read permission.
131  * @KVM_PGTABLE_PROT_DEVICE:	Device attributes.
132  * @KVM_PGTABLE_PROT_SW0:	Software bit 0.
133  * @KVM_PGTABLE_PROT_SW1:	Software bit 1.
134  * @KVM_PGTABLE_PROT_SW2:	Software bit 2.
135  * @KVM_PGTABLE_PROT_SW3:	Software bit 3.
136  */
137 enum kvm_pgtable_prot {
138 	KVM_PGTABLE_PROT_X			= BIT(0),
139 	KVM_PGTABLE_PROT_W			= BIT(1),
140 	KVM_PGTABLE_PROT_R			= BIT(2),
141 
142 	KVM_PGTABLE_PROT_DEVICE			= BIT(3),
143 
144 	KVM_PGTABLE_PROT_SW0			= BIT(55),
145 	KVM_PGTABLE_PROT_SW1			= BIT(56),
146 	KVM_PGTABLE_PROT_SW2			= BIT(57),
147 	KVM_PGTABLE_PROT_SW3			= BIT(58),
148 };
149 
150 #define KVM_PGTABLE_PROT_RW	(KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W)
151 #define KVM_PGTABLE_PROT_RWX	(KVM_PGTABLE_PROT_RW | KVM_PGTABLE_PROT_X)
152 
153 #define PKVM_HOST_MEM_PROT	KVM_PGTABLE_PROT_RWX
154 #define PKVM_HOST_MMIO_PROT	KVM_PGTABLE_PROT_RW
155 
156 #define PAGE_HYP		KVM_PGTABLE_PROT_RW
157 #define PAGE_HYP_EXEC		(KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_X)
158 #define PAGE_HYP_RO		(KVM_PGTABLE_PROT_R)
159 #define PAGE_HYP_DEVICE		(PAGE_HYP | KVM_PGTABLE_PROT_DEVICE)
160 
161 typedef bool (*kvm_pgtable_force_pte_cb_t)(u64 addr, u64 end,
162 					   enum kvm_pgtable_prot prot);
163 
164 /**
165  * struct kvm_pgtable - KVM page-table.
166  * @ia_bits:		Maximum input address size, in bits.
167  * @start_level:	Level at which the page-table walk starts.
168  * @pgd:		Pointer to the first top-level entry of the page-table.
169  * @mm_ops:		Memory management callbacks.
170  * @mmu:		Stage-2 KVM MMU struct. Unused for stage-1 page-tables.
171  * @flags:		Stage-2 page-table flags.
172  * @force_pte_cb:	Function that returns true if page level mappings must
173  *			be used instead of block mappings.
174  */
175 struct kvm_pgtable {
176 	u32					ia_bits;
177 	u32					start_level;
178 	kvm_pte_t				*pgd;
179 	struct kvm_pgtable_mm_ops		*mm_ops;
180 
181 	/* Stage-2 only */
182 	struct kvm_s2_mmu			*mmu;
183 	enum kvm_pgtable_stage2_flags		flags;
184 	kvm_pgtable_force_pte_cb_t		force_pte_cb;
185 };
186 
187 /**
188  * enum kvm_pgtable_walk_flags - Flags to control a depth-first page-table walk.
189  * @KVM_PGTABLE_WALK_LEAF:		Visit leaf entries, including invalid
190  *					entries.
191  * @KVM_PGTABLE_WALK_TABLE_PRE:		Visit table entries before their
192  *					children.
193  * @KVM_PGTABLE_WALK_TABLE_POST:	Visit table entries after their
194  *					children.
195  */
196 enum kvm_pgtable_walk_flags {
197 	KVM_PGTABLE_WALK_LEAF			= BIT(0),
198 	KVM_PGTABLE_WALK_TABLE_PRE		= BIT(1),
199 	KVM_PGTABLE_WALK_TABLE_POST		= BIT(2),
200 };
201 
202 typedef int (*kvm_pgtable_visitor_fn_t)(u64 addr, u64 end, u32 level,
203 					kvm_pte_t *ptep,
204 					enum kvm_pgtable_walk_flags flag,
205 					void * const arg);
206 
207 /**
208  * struct kvm_pgtable_walker - Hook into a page-table walk.
209  * @cb:		Callback function to invoke during the walk.
210  * @arg:	Argument passed to the callback function.
211  * @flags:	Bitwise-OR of flags to identify the entry types on which to
212  *		invoke the callback function.
213  */
214 struct kvm_pgtable_walker {
215 	const kvm_pgtable_visitor_fn_t		cb;
216 	void * const				arg;
217 	const enum kvm_pgtable_walk_flags	flags;
218 };
219 
220 /**
221  * kvm_pgtable_hyp_init() - Initialise a hypervisor stage-1 page-table.
222  * @pgt:	Uninitialised page-table structure to initialise.
223  * @va_bits:	Maximum virtual address bits.
224  * @mm_ops:	Memory management callbacks.
225  *
226  * Return: 0 on success, negative error code on failure.
227  */
228 int kvm_pgtable_hyp_init(struct kvm_pgtable *pgt, u32 va_bits,
229 			 struct kvm_pgtable_mm_ops *mm_ops);
230 
231 /**
232  * kvm_pgtable_hyp_destroy() - Destroy an unused hypervisor stage-1 page-table.
233  * @pgt:	Page-table structure initialised by kvm_pgtable_hyp_init().
234  *
235  * The page-table is assumed to be unreachable by any hardware walkers prior
236  * to freeing and therefore no TLB invalidation is performed.
237  */
238 void kvm_pgtable_hyp_destroy(struct kvm_pgtable *pgt);
239 
240 /**
241  * kvm_pgtable_hyp_map() - Install a mapping in a hypervisor stage-1 page-table.
242  * @pgt:	Page-table structure initialised by kvm_pgtable_hyp_init().
243  * @addr:	Virtual address at which to place the mapping.
244  * @size:	Size of the mapping.
245  * @phys:	Physical address of the memory to map.
246  * @prot:	Permissions and attributes for the mapping.
247  *
248  * The offset of @addr within a page is ignored, @size is rounded-up to
249  * the next page boundary and @phys is rounded-down to the previous page
250  * boundary.
251  *
252  * If device attributes are not explicitly requested in @prot, then the
253  * mapping will be normal, cacheable. Attempts to install a new mapping
254  * for a virtual address that is already mapped will be rejected with an
255  * error and a WARN().
256  *
257  * Return: 0 on success, negative error code on failure.
258  */
259 int kvm_pgtable_hyp_map(struct kvm_pgtable *pgt, u64 addr, u64 size, u64 phys,
260 			enum kvm_pgtable_prot prot);
261 
262 /**
263  * kvm_pgtable_hyp_unmap() - Remove a mapping from a hypervisor stage-1 page-table.
264  * @pgt:	Page-table structure initialised by kvm_pgtable_hyp_init().
265  * @addr:	Virtual address from which to remove the mapping.
266  * @size:	Size of the mapping.
267  *
268  * The offset of @addr within a page is ignored, @size is rounded-up to
269  * the next page boundary and @phys is rounded-down to the previous page
270  * boundary.
271  *
272  * TLB invalidation is performed for each page-table entry cleared during the
273  * unmapping operation and the reference count for the page-table page
274  * containing the cleared entry is decremented, with unreferenced pages being
275  * freed. The unmapping operation will stop early if it encounters either an
276  * invalid page-table entry or a valid block mapping which maps beyond the range
277  * being unmapped.
278  *
279  * Return: Number of bytes unmapped, which may be 0.
280  */
281 u64 kvm_pgtable_hyp_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size);
282 
283 /**
284  * kvm_get_vtcr() - Helper to construct VTCR_EL2
285  * @mmfr0:	Sanitized value of SYS_ID_AA64MMFR0_EL1 register.
286  * @mmfr1:	Sanitized value of SYS_ID_AA64MMFR1_EL1 register.
287  * @phys_shfit:	Value to set in VTCR_EL2.T0SZ.
288  *
289  * The VTCR value is common across all the physical CPUs on the system.
290  * We use system wide sanitised values to fill in different fields,
291  * except for Hardware Management of Access Flags. HA Flag is set
292  * unconditionally on all CPUs, as it is safe to run with or without
293  * the feature and the bit is RES0 on CPUs that don't support it.
294  *
295  * Return: VTCR_EL2 value
296  */
297 u64 kvm_get_vtcr(u64 mmfr0, u64 mmfr1, u32 phys_shift);
298 
299 /**
300  * __kvm_pgtable_stage2_init() - Initialise a guest stage-2 page-table.
301  * @pgt:	Uninitialised page-table structure to initialise.
302  * @mmu:	S2 MMU context for this S2 translation
303  * @mm_ops:	Memory management callbacks.
304  * @flags:	Stage-2 configuration flags.
305  * @force_pte_cb: Function that returns true if page level mappings must
306  *		be used instead of block mappings.
307  *
308  * Return: 0 on success, negative error code on failure.
309  */
310 int __kvm_pgtable_stage2_init(struct kvm_pgtable *pgt, struct kvm_s2_mmu *mmu,
311 			      struct kvm_pgtable_mm_ops *mm_ops,
312 			      enum kvm_pgtable_stage2_flags flags,
313 			      kvm_pgtable_force_pte_cb_t force_pte_cb);
314 
315 #define kvm_pgtable_stage2_init(pgt, mmu, mm_ops) \
316 	__kvm_pgtable_stage2_init(pgt, mmu, mm_ops, 0, NULL)
317 
318 /**
319  * kvm_pgtable_stage2_destroy() - Destroy an unused guest stage-2 page-table.
320  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
321  *
322  * The page-table is assumed to be unreachable by any hardware walkers prior
323  * to freeing and therefore no TLB invalidation is performed.
324  */
325 void kvm_pgtable_stage2_destroy(struct kvm_pgtable *pgt);
326 
327 /**
328  * kvm_pgtable_stage2_map() - Install a mapping in a guest stage-2 page-table.
329  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
330  * @addr:	Intermediate physical address at which to place the mapping.
331  * @size:	Size of the mapping.
332  * @phys:	Physical address of the memory to map.
333  * @prot:	Permissions and attributes for the mapping.
334  * @mc:		Cache of pre-allocated and zeroed memory from which to allocate
335  *		page-table pages.
336  *
337  * The offset of @addr within a page is ignored, @size is rounded-up to
338  * the next page boundary and @phys is rounded-down to the previous page
339  * boundary.
340  *
341  * If device attributes are not explicitly requested in @prot, then the
342  * mapping will be normal, cacheable.
343  *
344  * Note that the update of a valid leaf PTE in this function will be aborted,
345  * if it's trying to recreate the exact same mapping or only change the access
346  * permissions. Instead, the vCPU will exit one more time from guest if still
347  * needed and then go through the path of relaxing permissions.
348  *
349  * Note that this function will both coalesce existing table entries and split
350  * existing block mappings, relying on page-faults to fault back areas outside
351  * of the new mapping lazily.
352  *
353  * Return: 0 on success, negative error code on failure.
354  */
355 int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
356 			   u64 phys, enum kvm_pgtable_prot prot,
357 			   void *mc);
358 
359 /**
360  * kvm_pgtable_stage2_set_owner() - Unmap and annotate pages in the IPA space to
361  *				    track ownership.
362  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
363  * @addr:	Base intermediate physical address to annotate.
364  * @size:	Size of the annotated range.
365  * @mc:		Cache of pre-allocated and zeroed memory from which to allocate
366  *		page-table pages.
367  * @owner_id:	Unique identifier for the owner of the page.
368  *
369  * By default, all page-tables are owned by identifier 0. This function can be
370  * used to mark portions of the IPA space as owned by other entities. When a
371  * stage 2 is used with identity-mappings, these annotations allow to use the
372  * page-table data structure as a simple rmap.
373  *
374  * Return: 0 on success, negative error code on failure.
375  */
376 int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size,
377 				 void *mc, u8 owner_id);
378 
379 /**
380  * kvm_pgtable_stage2_unmap() - Remove a mapping from a guest stage-2 page-table.
381  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
382  * @addr:	Intermediate physical address from which to remove the mapping.
383  * @size:	Size of the mapping.
384  *
385  * The offset of @addr within a page is ignored and @size is rounded-up to
386  * the next page boundary.
387  *
388  * TLB invalidation is performed for each page-table entry cleared during the
389  * unmapping operation and the reference count for the page-table page
390  * containing the cleared entry is decremented, with unreferenced pages being
391  * freed. Unmapping a cacheable page will ensure that it is clean to the PoC if
392  * FWB is not supported by the CPU.
393  *
394  * Return: 0 on success, negative error code on failure.
395  */
396 int kvm_pgtable_stage2_unmap(struct kvm_pgtable *pgt, u64 addr, u64 size);
397 
398 /**
399  * kvm_pgtable_stage2_wrprotect() - Write-protect guest stage-2 address range
400  *                                  without TLB invalidation.
401  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
402  * @addr:	Intermediate physical address from which to write-protect,
403  * @size:	Size of the range.
404  *
405  * The offset of @addr within a page is ignored and @size is rounded-up to
406  * the next page boundary.
407  *
408  * Note that it is the caller's responsibility to invalidate the TLB after
409  * calling this function to ensure that the updated permissions are visible
410  * to the CPUs.
411  *
412  * Return: 0 on success, negative error code on failure.
413  */
414 int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size);
415 
416 /**
417  * kvm_pgtable_stage2_mkyoung() - Set the access flag in a page-table entry.
418  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
419  * @addr:	Intermediate physical address to identify the page-table entry.
420  *
421  * The offset of @addr within a page is ignored.
422  *
423  * If there is a valid, leaf page-table entry used to translate @addr, then
424  * set the access flag in that entry.
425  *
426  * Return: The old page-table entry prior to setting the flag, 0 on failure.
427  */
428 kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr);
429 
430 /**
431  * kvm_pgtable_stage2_mkold() - Clear the access flag in a page-table entry.
432  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
433  * @addr:	Intermediate physical address to identify the page-table entry.
434  *
435  * The offset of @addr within a page is ignored.
436  *
437  * If there is a valid, leaf page-table entry used to translate @addr, then
438  * clear the access flag in that entry.
439  *
440  * Note that it is the caller's responsibility to invalidate the TLB after
441  * calling this function to ensure that the updated permissions are visible
442  * to the CPUs.
443  *
444  * Return: The old page-table entry prior to clearing the flag, 0 on failure.
445  */
446 kvm_pte_t kvm_pgtable_stage2_mkold(struct kvm_pgtable *pgt, u64 addr);
447 
448 /**
449  * kvm_pgtable_stage2_relax_perms() - Relax the permissions enforced by a
450  *				      page-table entry.
451  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
452  * @addr:	Intermediate physical address to identify the page-table entry.
453  * @prot:	Additional permissions to grant for the mapping.
454  *
455  * The offset of @addr within a page is ignored.
456  *
457  * If there is a valid, leaf page-table entry used to translate @addr, then
458  * relax the permissions in that entry according to the read, write and
459  * execute permissions specified by @prot. No permissions are removed, and
460  * TLB invalidation is performed after updating the entry. Software bits cannot
461  * be set or cleared using kvm_pgtable_stage2_relax_perms().
462  *
463  * Return: 0 on success, negative error code on failure.
464  */
465 int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr,
466 				   enum kvm_pgtable_prot prot);
467 
468 /**
469  * kvm_pgtable_stage2_is_young() - Test whether a page-table entry has the
470  *				   access flag set.
471  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
472  * @addr:	Intermediate physical address to identify the page-table entry.
473  *
474  * The offset of @addr within a page is ignored.
475  *
476  * Return: True if the page-table entry has the access flag set, false otherwise.
477  */
478 bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr);
479 
480 /**
481  * kvm_pgtable_stage2_flush_range() - Clean and invalidate data cache to Point
482  * 				      of Coherency for guest stage-2 address
483  *				      range.
484  * @pgt:	Page-table structure initialised by kvm_pgtable_stage2_init*().
485  * @addr:	Intermediate physical address from which to flush.
486  * @size:	Size of the range.
487  *
488  * The offset of @addr within a page is ignored and @size is rounded-up to
489  * the next page boundary.
490  *
491  * Return: 0 on success, negative error code on failure.
492  */
493 int kvm_pgtable_stage2_flush(struct kvm_pgtable *pgt, u64 addr, u64 size);
494 
495 /**
496  * kvm_pgtable_walk() - Walk a page-table.
497  * @pgt:	Page-table structure initialised by kvm_pgtable_*_init().
498  * @addr:	Input address for the start of the walk.
499  * @size:	Size of the range to walk.
500  * @walker:	Walker callback description.
501  *
502  * The offset of @addr within a page is ignored and @size is rounded-up to
503  * the next page boundary.
504  *
505  * The walker will walk the page-table entries corresponding to the input
506  * address range specified, visiting entries according to the walker flags.
507  * Invalid entries are treated as leaf entries. Leaf entries are reloaded
508  * after invoking the walker callback, allowing the walker to descend into
509  * a newly installed table.
510  *
511  * Returning a negative error code from the walker callback function will
512  * terminate the walk immediately with the same error code.
513  *
514  * Return: 0 on success, negative error code on failure.
515  */
516 int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size,
517 		     struct kvm_pgtable_walker *walker);
518 
519 /**
520  * kvm_pgtable_get_leaf() - Walk a page-table and retrieve the leaf entry
521  *			    with its level.
522  * @pgt:	Page-table structure initialised by kvm_pgtable_*_init()
523  *		or a similar initialiser.
524  * @addr:	Input address for the start of the walk.
525  * @ptep:	Pointer to storage for the retrieved PTE.
526  * @level:	Pointer to storage for the level of the retrieved PTE.
527  *
528  * The offset of @addr within a page is ignored.
529  *
530  * The walker will walk the page-table entries corresponding to the input
531  * address specified, retrieving the leaf corresponding to this address.
532  * Invalid entries are treated as leaf entries.
533  *
534  * Return: 0 on success, negative error code on failure.
535  */
536 int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr,
537 			 kvm_pte_t *ptep, u32 *level);
538 
539 /**
540  * kvm_pgtable_stage2_pte_prot() - Retrieve the protection attributes of a
541  *				   stage-2 Page-Table Entry.
542  * @pte:	Page-table entry
543  *
544  * Return: protection attributes of the page-table entry in the enum
545  *	   kvm_pgtable_prot format.
546  */
547 enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte);
548 
549 /**
550  * kvm_pgtable_hyp_pte_prot() - Retrieve the protection attributes of a stage-1
551  *				Page-Table Entry.
552  * @pte:	Page-table entry
553  *
554  * Return: protection attributes of the page-table entry in the enum
555  *	   kvm_pgtable_prot format.
556  */
557 enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte);
558 #endif	/* __ARM64_KVM_PGTABLE_H__ */
559