xref: /openbmc/linux/include/linux/secretmem.h (revision 0d727e18)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _LINUX_SECRETMEM_H
3 #define _LINUX_SECRETMEM_H
4 
5 #ifdef CONFIG_SECRETMEM
6 
7 extern const struct address_space_operations secretmem_aops;
8 
9 static inline bool page_is_secretmem(struct page *page)
10 {
11 	struct address_space *mapping;
12 
13 	/*
14 	 * Using page_mapping() is quite slow because of the actual call
15 	 * instruction and repeated compound_head(page) inside the
16 	 * page_mapping() function.
17 	 * We know that secretmem pages are not compound and LRU so we can
18 	 * save a couple of cycles here.
19 	 */
20 	if (PageCompound(page) || !PageLRU(page))
21 		return false;
22 
23 	mapping = (struct address_space *)
24 		((unsigned long)page->mapping & ~PAGE_MAPPING_FLAGS);
25 
26 	if (!mapping || mapping != page->mapping)
27 		return false;
28 
29 	return mapping->a_ops == &secretmem_aops;
30 }
31 
32 bool vma_is_secretmem(struct vm_area_struct *vma);
33 bool secretmem_active(void);
34 
35 #else
36 
37 static inline bool vma_is_secretmem(struct vm_area_struct *vma)
38 {
39 	return false;
40 }
41 
42 static inline bool page_is_secretmem(struct page *page)
43 {
44 	return false;
45 }
46 
47 static inline bool secretmem_active(void)
48 {
49 	return false;
50 }
51 
52 #endif /* CONFIG_SECRETMEM */
53 
54 #endif /* _LINUX_SECRETMEM_H */
55