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 11 static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } 12 static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } 13 static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } 14 static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } 15 #endif 16 17 static inline int set_memory_rox(unsigned long addr, int numpages) 18 { 19 int ret = set_memory_ro(addr, numpages); 20 if (ret) 21 return ret; 22 return set_memory_x(addr, numpages); 23 } 24 25 #ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP 26 static inline int set_direct_map_invalid_noflush(struct page *page) 27 { 28 return 0; 29 } 30 static inline int set_direct_map_default_noflush(struct page *page) 31 { 32 return 0; 33 } 34 35 static inline bool kernel_page_present(struct page *page) 36 { 37 return true; 38 } 39 #else /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */ 40 /* 41 * Some architectures, e.g. ARM64 can disable direct map modifications at 42 * boot time. Let them overrive this query. 43 */ 44 #ifndef can_set_direct_map 45 static inline bool can_set_direct_map(void) 46 { 47 return true; 48 } 49 #define can_set_direct_map can_set_direct_map 50 #endif 51 #endif /* CONFIG_ARCH_HAS_SET_DIRECT_MAP */ 52 53 #ifdef CONFIG_X86_64 54 int set_mce_nospec(unsigned long pfn); 55 int clear_mce_nospec(unsigned long pfn); 56 #else 57 static inline int set_mce_nospec(unsigned long pfn) 58 { 59 return 0; 60 } 61 static inline int clear_mce_nospec(unsigned long pfn) 62 { 63 return 0; 64 } 65 #endif 66 67 #ifndef CONFIG_ARCH_HAS_MEM_ENCRYPT 68 static inline int set_memory_encrypted(unsigned long addr, int numpages) 69 { 70 return 0; 71 } 72 73 static inline int set_memory_decrypted(unsigned long addr, int numpages) 74 { 75 return 0; 76 } 77 #endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */ 78 79 #endif /* _LINUX_SET_MEMORY_H_ */ 80