1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2017, Michael Ellerman, IBM Corporation.
4  */
5 #ifndef _LINUX_SET_MEMORY_H_
6 #define _LINUX_SET_MEMORY_H_
7 
8 #ifdef CONFIG_ARCH_HAS_SET_MEMORY
9 #include <asm/set_memory.h>
10 #else
set_memory_ro(unsigned long addr,int numpages)11 static inline int __must_check set_memory_ro(unsigned long addr, int numpages) { return 0; }
set_memory_rw(unsigned long addr,int numpages)12 static inline int __must_check set_memory_rw(unsigned long addr, int numpages) { return 0; }
set_memory_x(unsigned long addr,int numpages)13 static inline int __must_check set_memory_x(unsigned long addr,  int numpages) { return 0; }
set_memory_nx(unsigned long addr,int numpages)14 static inline int __must_check set_memory_nx(unsigned long addr, int numpages) { return 0; }
15 #endif
16 
17 #ifndef set_memory_rox
set_memory_rox(unsigned long addr,int numpages)18 static inline int set_memory_rox(unsigned long addr, int numpages)
19 {
20 	int ret = set_memory_ro(addr, numpages);
21 	if (ret)
22 		return ret;
23 	return set_memory_x(addr, numpages);
24 }
25 #endif
26 
27 #ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP
set_direct_map_invalid_noflush(struct page * page)28 static inline int set_direct_map_invalid_noflush(struct page *page)
29 {
30 	return 0;
31 }
set_direct_map_default_noflush(struct page * page)32 static inline int set_direct_map_default_noflush(struct page *page)
33 {
34 	return 0;
35 }
36 
set_direct_map_valid_noflush(struct page * page,unsigned nr,bool valid)37 static inline int set_direct_map_valid_noflush(struct page *page,
38 					       unsigned nr, bool valid)
39 {
40 	return 0;
41 }
42 
kernel_page_present(struct page * page)43 static inline bool kernel_page_present(struct page *page)
44 {
45 	return true;
46 }
47 #else /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */
48 /*
49  * Some architectures, e.g. ARM64 can disable direct map modifications at
50  * boot time. Let them overrive this query.
51  */
52 #ifndef can_set_direct_map
can_set_direct_map(void)53 static inline bool can_set_direct_map(void)
54 {
55 	return true;
56 }
57 #define can_set_direct_map can_set_direct_map
58 #endif
59 #endif /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */
60 
61 #ifdef CONFIG_X86_64
62 int set_mce_nospec(unsigned long pfn);
63 int clear_mce_nospec(unsigned long pfn);
64 #else
set_mce_nospec(unsigned long pfn)65 static inline int set_mce_nospec(unsigned long pfn)
66 {
67 	return 0;
68 }
clear_mce_nospec(unsigned long pfn)69 static inline int clear_mce_nospec(unsigned long pfn)
70 {
71 	return 0;
72 }
73 #endif
74 
75 #ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT
set_memory_encrypted(unsigned long addr,int numpages)76 static inline int set_memory_encrypted(unsigned long addr, int numpages)
77 {
78 	return 0;
79 }
80 
set_memory_decrypted(unsigned long addr,int numpages)81 static inline int set_memory_decrypted(unsigned long addr, int numpages)
82 {
83 	return 0;
84 }
85 #endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */
86 
87 #endif /* _LINUX_SET_MEMORY_H_ */
88