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

selftests/vm/pkeys: introduce a sub-page allocator

This introduces a new allocator that allocates 4K hardware pages to back
64K linux pages. This allocator is available only on powerpc.

Signed-off-by: Ram Pai <linuxram@us.ibm.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Signed-off-by: Sandipan Das <sandipan@linux.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Acked-by: Dave Hansen <dave.hansen@intel.com>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Link: http://lkml.kernel.org/r/c4a82fa962ec71015b994fab1aaf83bdfd091553.1585646528.git.sandipan@linux.ibm.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Ram Pai and committed by
Linus Torvalds
6e2c2d0f 4e06e718

+37
+6
tools/testing/selftests/vm/pkey-helpers.h
··· 28 28 extern int dprint_in_signal; 29 29 extern char dprint_in_signal_buffer[DPRINT_IN_SIGNAL_BUF_SIZE]; 30 30 31 + extern int test_nr; 32 + extern int iteration_nr; 33 + 31 34 #ifdef __GNUC__ 32 35 __attribute__((format(printf, 1, 2))) 33 36 #endif ··· 81 78 void expected_pkey_fault(int pkey); 82 79 int sys_pkey_alloc(unsigned long flags, unsigned long init_val); 83 80 int sys_pkey_free(unsigned long pkey); 81 + int mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot, 82 + unsigned long pkey); 83 + void record_pkey_malloc(void *ptr, long size, int prot); 84 84 85 85 #if defined(__i386__) || defined(__x86_64__) /* arch */ 86 86 #include "pkey-x86.h"
+25
tools/testing/selftests/vm/pkey-powerpc.h
··· 107 107 /* 4-byte instructions * 16384 = 64K page */ 108 108 #define __page_o_noops() asm(".rept 16384 ; nop; .endr") 109 109 110 + void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 111 + { 112 + void *ptr; 113 + int ret; 114 + 115 + dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__, 116 + size, prot, pkey); 117 + pkey_assert(pkey < NR_PKEYS); 118 + ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); 119 + pkey_assert(ptr != (void *)-1); 120 + 121 + ret = syscall(__NR_subpage_prot, ptr, size, NULL); 122 + if (ret) { 123 + perror("subpage_perm"); 124 + return PTR_ERR_ENOTSUP; 125 + } 126 + 127 + ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); 128 + pkey_assert(!ret); 129 + record_pkey_malloc(ptr, size, prot); 130 + 131 + dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); 132 + return ptr; 133 + } 134 + 110 135 #endif /* _PKEYS_POWERPC_H */
+5
tools/testing/selftests/vm/pkey-x86.h
··· 173 173 expected_pkey_fault(pkey); 174 174 } 175 175 176 + void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey) 177 + { 178 + return PTR_ERR_ENOTSUP; 179 + } 180 + 176 181 #endif /* _PKEYS_X86_H */
+1
tools/testing/selftests/vm/protection_keys.c
··· 845 845 void *(*pkey_malloc[])(long size, int prot, u16 pkey) = { 846 846 847 847 malloc_pkey_with_mprotect, 848 + malloc_pkey_with_mprotect_subpage, 848 849 malloc_pkey_anon_huge, 849 850 malloc_pkey_hugetlb 850 851 /* can not do direct with the pkey_mprotect() API: