Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/mm: ensure pkey-*.h define inline functions only

Headers should not define non-inline functions, as this prevents them from
being included more than once in a given program. pkey-helpers.h and the
arch-specific headers it includes currently define multiple such
non-inline functions.

In most cases those functions can simply be made inline - this patch does
just that. read_ptr() is an exception as it must not be inlined. Since
it is only called from protection_keys.c, we just move it there.

Link: https://lkml.kernel.org/r/20241209095019.1732120-9-kevin.brodsky@arm.com
Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Cc: Aruna Ramakrishna <aruna.ramakrishna@oracle.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Joey Gouly <joey.gouly@arm.com>
Cc: Keith Lucas <keith.lucas@oracle.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Kevin Brodsky and committed by
Andrew Morton
21309ac2 f7ed8331

+15 -14
+2 -2
tools/testing/selftests/mm/pkey-arm64.h
··· 81 81 return NR_RESERVED_PKEYS; 82 82 } 83 83 84 - void expect_fault_on_read_execonly_key(void *p1, int pkey) 84 + static inline void expect_fault_on_read_execonly_key(void *p1, int pkey) 85 85 { 86 86 } 87 87 88 - void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 88 + static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 89 89 { 90 90 return PTR_ERR_ENOTSUP; 91 91 }
+1 -7
tools/testing/selftests/mm/pkey-helpers.h
··· 84 84 # define noinline __attribute__((noinline)) 85 85 #endif 86 86 87 - noinline int read_ptr(int *ptr) 88 - { 89 - /* Keep GCC from optimizing this away somehow */ 90 - barrier(); 91 - return *ptr; 92 - } 93 - 87 + noinline int read_ptr(int *ptr); 94 88 void expected_pkey_fault(int pkey); 95 89 int sys_pkey_alloc(unsigned long flags, unsigned long init_val); 96 90 int sys_pkey_free(unsigned long pkey);
+2 -2
tools/testing/selftests/mm/pkey-powerpc.h
··· 91 91 return NR_RESERVED_PKEYS_64K_3KEYS; 92 92 } 93 93 94 - void expect_fault_on_read_execonly_key(void *p1, int pkey) 94 + static inline void expect_fault_on_read_execonly_key(void *p1, int pkey) 95 95 { 96 96 /* 97 97 * powerpc does not allow userspace to change permissions of exec-only ··· 105 105 /* 4-byte instructions * 16384 = 64K page */ 106 106 #define __page_o_noops() asm(".rept 16384 ; nop; .endr") 107 107 108 - void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 108 + static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 109 109 { 110 110 void *ptr; 111 111 int ret;
+3 -3
tools/testing/selftests/mm/pkey-x86.h
··· 113 113 #define XSTATE_PKEY 0x200 114 114 #define XSTATE_BV_OFFSET 512 115 115 116 - int pkey_reg_xstate_offset(void) 116 + static inline int pkey_reg_xstate_offset(void) 117 117 { 118 118 unsigned int eax; 119 119 unsigned int ebx; ··· 148 148 return NR_RESERVED_PKEYS; 149 149 } 150 150 151 - void expect_fault_on_read_execonly_key(void *p1, int pkey) 151 + static inline void expect_fault_on_read_execonly_key(void *p1, int pkey) 152 152 { 153 153 int ptr_contents; 154 154 ··· 157 157 expected_pkey_fault(pkey); 158 158 } 159 159 160 - void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 160 + static inline void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 161 161 { 162 162 return PTR_ERR_ENOTSUP; 163 163 }
+7
tools/testing/selftests/mm/protection_keys.c
··· 54 54 u64 shadow_pkey_reg; 55 55 int dprint_in_signal; 56 56 57 + noinline int read_ptr(int *ptr) 58 + { 59 + /* Keep GCC from optimizing this away somehow */ 60 + barrier(); 61 + return *ptr; 62 + } 63 + 57 64 void cat_into_file(char *str, char *file) 58 65 { 59 66 int fd = open(file, O_RDWR);