Lines Matching refs:pkey

177 static u32 hw_pkey_get(int pkey, unsigned long flags)  in hw_pkey_get()  argument
182 __func__, pkey, flags, 0, 0); in hw_pkey_get()
185 return (u32) get_pkey_bits(pkey_reg, pkey); in hw_pkey_get()
188 static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags) in hw_pkey_set() argument
198 new_pkey_reg = set_pkey_bits(old_pkey_reg, pkey, rights); in hw_pkey_set()
204 __func__, pkey, rights, flags, 0, __read_pkey_reg(), in hw_pkey_set()
209 void pkey_disable_set(int pkey, int flags) in pkey_disable_set() argument
217 pkey, flags); in pkey_disable_set()
220 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_set()
223 pkey, pkey, pkey_rights); in pkey_disable_set()
229 ret = hw_pkey_set(pkey, pkey_rights, syscall_flags); in pkey_disable_set()
232 shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, pkey, pkey_rights); in pkey_disable_set()
234 __func__, pkey, shadow_pkey_reg); in pkey_disable_set()
238 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_set()
240 pkey, pkey, pkey_rights); in pkey_disable_set()
243 __func__, pkey, read_pkey_reg()); in pkey_disable_set()
247 pkey, flags); in pkey_disable_set()
250 void pkey_disable_clear(int pkey, int flags) in pkey_disable_clear() argument
254 int pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
260 pkey, pkey, pkey_rights); in pkey_disable_clear()
265 ret = hw_pkey_set(pkey, pkey_rights, 0); in pkey_disable_clear()
266 shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, pkey, pkey_rights); in pkey_disable_clear()
269 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
271 pkey, pkey, pkey_rights); in pkey_disable_clear()
274 pkey, read_pkey_reg()); in pkey_disable_clear()
279 void pkey_write_allow(int pkey) in pkey_write_allow() argument
281 pkey_disable_clear(pkey, PKEY_DISABLE_WRITE); in pkey_write_allow()
283 void pkey_write_deny(int pkey) in pkey_write_deny() argument
285 pkey_disable_set(pkey, PKEY_DISABLE_WRITE); in pkey_write_deny()
287 void pkey_access_allow(int pkey) in pkey_access_allow() argument
289 pkey_disable_clear(pkey, PKEY_DISABLE_ACCESS); in pkey_access_allow()
291 void pkey_access_deny(int pkey) in pkey_access_deny() argument
293 pkey_disable_set(pkey, PKEY_DISABLE_ACCESS); in pkey_access_deny()
470 unsigned long pkey) in sys_mprotect_pkey() argument
475 ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
478 sret = syscall(SYS_mprotect_key, ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
543 int sys_pkey_free(unsigned long pkey) in sys_pkey_free() argument
545 int ret = syscall(SYS_pkey_free, pkey); in sys_pkey_free()
546 dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); in sys_pkey_free()
597 unsigned long pkey) in mprotect_pkey() argument
604 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
606 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
620 pkey_assert(pkey < NR_PKEYS); in mprotect_pkey()
622 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
624 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
705 void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey) in malloc_pkey_with_mprotect() argument
712 size, prot, pkey); in malloc_pkey_with_mprotect()
713 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_with_mprotect()
716 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); in malloc_pkey_with_mprotect()
721 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); in malloc_pkey_with_mprotect()
725 void *malloc_pkey_anon_huge(long size, int prot, u16 pkey) in malloc_pkey_anon_huge() argument
731 size, prot, pkey); in malloc_pkey_anon_huge()
740 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_anon_huge()
751 dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_anon_huge()
806 void *malloc_pkey_hugetlb(long size, int prot, u16 pkey) in malloc_pkey_hugetlb() argument
814 dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey); in malloc_pkey_hugetlb()
816 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_hugetlb()
819 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_hugetlb()
823 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_hugetlb()
827 void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey) in malloc_pkey_mmap_dax() argument
833 size, prot, pkey); in malloc_pkey_mmap_dax()
834 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_mmap_dax()
841 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_mmap_dax()
845 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_mmap_dax()
850 void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {
862 void *malloc_pkey(long size, int prot, u16 pkey) in malloc_pkey() argument
868 pkey_assert(pkey < NR_PKEYS); in malloc_pkey()
873 ret = pkey_malloc[malloc_type](size, prot, pkey); in malloc_pkey()
888 size, prot, pkey, ret); in malloc_pkey()
894 void expected_pkey_fault(int pkey) in expected_pkey_fault() argument
898 dprintf2("%s(%d): last_si_pkey: %d\n", __func__, pkey, last_si_pkey); in expected_pkey_fault()
905 if (pkey != UNKNOWN_PKEY) in expected_pkey_fault()
906 pkey_assert(last_si_pkey == pkey); in expected_pkey_fault()
972 void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey) in test_pkey_alloc_free_attach_pkey0() argument
1024 void test_read_of_write_disabled_region(int *ptr, u16 pkey) in test_read_of_write_disabled_region() argument
1029 pkey_write_deny(pkey); in test_read_of_write_disabled_region()
1034 void test_read_of_access_disabled_region(int *ptr, u16 pkey) in test_read_of_access_disabled_region() argument
1038 dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); in test_read_of_access_disabled_region()
1040 pkey_access_deny(pkey); in test_read_of_access_disabled_region()
1043 expected_pkey_fault(pkey); in test_read_of_access_disabled_region()
1047 u16 pkey) in test_read_of_access_disabled_region_with_page_already_mapped() argument
1052 pkey, ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
1057 pkey_access_deny(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1060 expected_pkey_fault(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1064 u16 pkey) in test_write_of_write_disabled_region_with_page_already_mapped() argument
1068 "to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1069 pkey_write_deny(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1071 expected_pkey_fault(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1074 void test_write_of_write_disabled_region(int *ptr, u16 pkey) in test_write_of_write_disabled_region() argument
1076 dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region()
1077 pkey_write_deny(pkey); in test_write_of_write_disabled_region()
1079 expected_pkey_fault(pkey); in test_write_of_write_disabled_region()
1081 void test_write_of_access_disabled_region(int *ptr, u16 pkey) in test_write_of_access_disabled_region() argument
1083 dprintf1("disabling access to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region()
1084 pkey_access_deny(pkey); in test_write_of_access_disabled_region()
1086 expected_pkey_fault(pkey); in test_write_of_access_disabled_region()
1090 u16 pkey) in test_write_of_access_disabled_region_with_page_already_mapped() argument
1094 " to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1095 pkey_access_deny(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1097 expected_pkey_fault(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1100 void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_access_disabled_region() argument
1106 "having kernel read() to buffer\n", pkey); in test_kernel_write_of_access_disabled_region()
1107 pkey_access_deny(pkey); in test_kernel_write_of_access_disabled_region()
1112 void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_write_disabled_region() argument
1117 pkey_write_deny(pkey); in test_kernel_write_of_write_disabled_region()
1125 void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_of_access_disabled_region() argument
1135 "having kernel vmsplice from buffer\n", pkey); in test_kernel_gup_of_access_disabled_region()
1136 pkey_access_deny(pkey); in test_kernel_gup_of_access_disabled_region()
1147 void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_write_to_write_disabled_region() argument
1154 "doing futex gunk in buffer\n", pkey); in test_kernel_gup_write_to_write_disabled_region()
1156 pkey_write_deny(pkey); in test_kernel_gup_write_to_write_disabled_region()
1165 void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) in test_pkey_syscalls_on_non_allocated_pkey() argument
1172 if (pkey == i) in test_pkey_syscalls_on_non_allocated_pkey()
1188 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey) in test_pkey_syscalls_bad_args() argument
1214 void test_pkey_alloc_exhaust(int *ptr, u16 pkey) in test_pkey_alloc_exhaust() argument
1286 void test_mprotect_with_pkey_0(int *ptr, u16 pkey) in test_mprotect_with_pkey_0() argument
1307 mprotect_pkey(ptr, size, prot, pkey); in test_mprotect_with_pkey_0()
1310 void test_ptrace_of_child(int *ptr, u16 pkey) in test_ptrace_of_child() argument
1346 pkey_access_deny(pkey); in test_ptrace_of_child()
1347 pkey_write_deny(pkey); in test_ptrace_of_child()
1363 expected_pkey_fault(pkey); in test_ptrace_of_child()
1407 void test_executing_on_unreadable_memory(int *ptr, u16 pkey) in test_executing_on_unreadable_memory() argument
1419 ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC, (u64)pkey); in test_executing_on_unreadable_memory()
1421 pkey_access_deny(pkey); in test_executing_on_unreadable_memory()
1431 expect_fault_on_read_execonly_key(p1, pkey); in test_executing_on_unreadable_memory()
1434 void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) in test_implicit_mprotect_exec_only_memory() argument
1475 void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) in test_mprotect_pkey_on_unsupported_cpu() argument
1485 sret = syscall(SYS_mprotect_key, ptr, size, PROT_READ, pkey); in test_mprotect_pkey_on_unsupported_cpu()
1489 void (*pkey_tests[])(int *ptr, u16 pkey) = {
1517 int pkey; in run_tests_once() local
1524 pkey = alloc_random_pkey(); in run_tests_once()
1525 dprintf1("test %d starting with pkey: %d\n", test_nr, pkey); in run_tests_once()
1526 ptr = malloc_pkey(PAGE_SIZE, prot, pkey); in run_tests_once()
1528 pkey_tests[test_nr](ptr, pkey); in run_tests_once()
1531 sys_pkey_free(pkey); in run_tests_once()