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