Lines Matching refs:pkey

178 static u32 hw_pkey_get(int pkey, unsigned long flags)  in hw_pkey_get()  argument
183 __func__, pkey, flags, 0, 0); in hw_pkey_get()
186 return (u32) get_pkey_bits(pkey_reg, pkey); in hw_pkey_get()
189 static int hw_pkey_set(int pkey, unsigned long rights, unsigned long flags) in hw_pkey_set() argument
199 new_pkey_reg = set_pkey_bits(old_pkey_reg, pkey, rights); in hw_pkey_set()
205 __func__, pkey, rights, flags, 0, __read_pkey_reg(), in hw_pkey_set()
210 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()
245 pkey, flags); in pkey_disable_set()
248 void pkey_disable_clear(int pkey, int flags) in pkey_disable_clear() argument
252 int pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
257 pkey, pkey, pkey_rights); in pkey_disable_clear()
262 ret = hw_pkey_set(pkey, pkey_rights, 0); in pkey_disable_clear()
263 shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, pkey, pkey_rights); in pkey_disable_clear()
266 pkey_rights = hw_pkey_get(pkey, syscall_flags); in pkey_disable_clear()
268 pkey, pkey, pkey_rights); in pkey_disable_clear()
271 pkey, read_pkey_reg()); in pkey_disable_clear()
274 void pkey_write_allow(int pkey) in pkey_write_allow() argument
276 pkey_disable_clear(pkey, PKEY_DISABLE_WRITE); in pkey_write_allow()
278 void pkey_write_deny(int pkey) in pkey_write_deny() argument
280 pkey_disable_set(pkey, PKEY_DISABLE_WRITE); in pkey_write_deny()
282 void pkey_access_allow(int pkey) in pkey_access_allow() argument
284 pkey_disable_clear(pkey, PKEY_DISABLE_ACCESS); in pkey_access_allow()
286 void pkey_access_deny(int pkey) in pkey_access_deny() argument
288 pkey_disable_set(pkey, PKEY_DISABLE_ACCESS); in pkey_access_deny()
464 unsigned long pkey) in sys_mprotect_pkey() argument
469 ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
472 sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey); in sys_mprotect_pkey()
537 int sys_pkey_free(unsigned long pkey) in sys_pkey_free() argument
539 int ret = syscall(SYS_pkey_free, pkey); in sys_pkey_free()
540 dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret); in sys_pkey_free()
590 unsigned long pkey) in mprotect_pkey() argument
597 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
599 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
613 pkey_assert(pkey < NR_PKEYS); in mprotect_pkey()
615 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
617 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
698 void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey) in malloc_pkey_with_mprotect() argument
705 size, prot, pkey); in malloc_pkey_with_mprotect()
706 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_with_mprotect()
709 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); in malloc_pkey_with_mprotect()
714 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); in malloc_pkey_with_mprotect()
718 void *malloc_pkey_anon_huge(long size, int prot, u16 pkey) in malloc_pkey_anon_huge() argument
724 size, prot, pkey); in malloc_pkey_anon_huge()
733 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_anon_huge()
744 dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_anon_huge()
799 void *malloc_pkey_hugetlb(long size, int prot, u16 pkey) in malloc_pkey_hugetlb() argument
807 dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey); in malloc_pkey_hugetlb()
809 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_hugetlb()
812 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_hugetlb()
816 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_hugetlb()
820 void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey) in malloc_pkey_mmap_dax() argument
826 size, prot, pkey); in malloc_pkey_mmap_dax()
827 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_mmap_dax()
834 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_mmap_dax()
838 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_mmap_dax()
843 void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {
855 void *malloc_pkey(long size, int prot, u16 pkey) in malloc_pkey() argument
861 pkey_assert(pkey < NR_PKEYS); in malloc_pkey()
866 ret = pkey_malloc[malloc_type](size, prot, pkey); in malloc_pkey()
881 size, prot, pkey, ret); in malloc_pkey()
887 void expected_pkey_fault(int pkey) in expected_pkey_fault() argument
891 dprintf2("%s(%d): last_si_pkey: %d\n", __func__, pkey, last_si_pkey); in expected_pkey_fault()
898 if (pkey != UNKNOWN_PKEY) in expected_pkey_fault()
899 pkey_assert(last_si_pkey == pkey); in expected_pkey_fault()
957 void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey) in test_pkey_alloc_free_attach_pkey0() argument
1009 void test_read_of_write_disabled_region(int *ptr, u16 pkey) in test_read_of_write_disabled_region() argument
1014 pkey_write_deny(pkey); in test_read_of_write_disabled_region()
1019 void test_read_of_access_disabled_region(int *ptr, u16 pkey) in test_read_of_access_disabled_region() argument
1023 dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); in test_read_of_access_disabled_region()
1025 pkey_access_deny(pkey); in test_read_of_access_disabled_region()
1028 expected_pkey_fault(pkey); in test_read_of_access_disabled_region()
1032 u16 pkey) in test_read_of_access_disabled_region_with_page_already_mapped() argument
1037 pkey, ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
1042 pkey_access_deny(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1045 expected_pkey_fault(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1049 u16 pkey) in test_write_of_write_disabled_region_with_page_already_mapped() argument
1053 "to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1054 pkey_write_deny(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1056 expected_pkey_fault(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1059 void test_write_of_write_disabled_region(int *ptr, u16 pkey) in test_write_of_write_disabled_region() argument
1061 dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region()
1062 pkey_write_deny(pkey); in test_write_of_write_disabled_region()
1064 expected_pkey_fault(pkey); in test_write_of_write_disabled_region()
1066 void test_write_of_access_disabled_region(int *ptr, u16 pkey) in test_write_of_access_disabled_region() argument
1068 dprintf1("disabling access to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region()
1069 pkey_access_deny(pkey); in test_write_of_access_disabled_region()
1071 expected_pkey_fault(pkey); in test_write_of_access_disabled_region()
1075 u16 pkey) in test_write_of_access_disabled_region_with_page_already_mapped() argument
1079 " to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1080 pkey_access_deny(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1082 expected_pkey_fault(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1085 void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_access_disabled_region() argument
1091 "having kernel read() to buffer\n", pkey); in test_kernel_write_of_access_disabled_region()
1092 pkey_access_deny(pkey); in test_kernel_write_of_access_disabled_region()
1097 void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_write_disabled_region() argument
1102 pkey_write_deny(pkey); in test_kernel_write_of_write_disabled_region()
1110 void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_of_access_disabled_region() argument
1120 "having kernel vmsplice from buffer\n", pkey); in test_kernel_gup_of_access_disabled_region()
1121 pkey_access_deny(pkey); in test_kernel_gup_of_access_disabled_region()
1132 void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_write_to_write_disabled_region() argument
1139 "doing futex gunk in buffer\n", pkey); in test_kernel_gup_write_to_write_disabled_region()
1141 pkey_write_deny(pkey); in test_kernel_gup_write_to_write_disabled_region()
1150 void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) in test_pkey_syscalls_on_non_allocated_pkey() argument
1157 if (pkey == i) in test_pkey_syscalls_on_non_allocated_pkey()
1173 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey) in test_pkey_syscalls_bad_args() argument
1199 void test_pkey_alloc_exhaust(int *ptr, u16 pkey) in test_pkey_alloc_exhaust() argument
1305 void test_pkey_init_state(int *ptr, u16 pkey) in test_pkey_init_state() argument
1343 void test_mprotect_with_pkey_0(int *ptr, u16 pkey) in test_mprotect_with_pkey_0() argument
1364 mprotect_pkey(ptr, size, prot, pkey); in test_mprotect_with_pkey_0()
1367 void test_ptrace_of_child(int *ptr, u16 pkey) in test_ptrace_of_child() argument
1403 pkey_access_deny(pkey); in test_ptrace_of_child()
1404 pkey_write_deny(pkey); in test_ptrace_of_child()
1420 expected_pkey_fault(pkey); in test_ptrace_of_child()
1464 void test_executing_on_unreadable_memory(int *ptr, u16 pkey) in test_executing_on_unreadable_memory() argument
1476 ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC, (u64)pkey); in test_executing_on_unreadable_memory()
1478 pkey_access_deny(pkey); in test_executing_on_unreadable_memory()
1488 expect_fault_on_read_execonly_key(p1, pkey); in test_executing_on_unreadable_memory()
1492 ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC | PROT_READ, (u64)pkey); in test_executing_on_unreadable_memory()
1496 void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) in test_implicit_mprotect_exec_only_memory() argument
1545 void test_ptrace_modifies_pkru(int *ptr, u16 pkey) in test_ptrace_modifies_pkru() argument
1668 void test_ptrace_modifies_pkru(int *ptr, u16 pkey) in test_ptrace_modifies_pkru() argument
1745 void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) in test_mprotect_pkey_on_unsupported_cpu() argument
1755 sret = syscall(__NR_pkey_mprotect, ptr, size, PROT_READ, pkey); in test_mprotect_pkey_on_unsupported_cpu()
1759 void (*pkey_tests[])(int *ptr, u16 pkey) = {
1791 int pkey; in run_tests_once() local
1798 pkey = alloc_random_pkey(); in run_tests_once()
1799 dprintf1("test %d starting with pkey: %d\n", test_nr, pkey); in run_tests_once()
1800 ptr = malloc_pkey(PAGE_SIZE, prot, pkey); in run_tests_once()
1802 pkey_tests[test_nr](ptr, pkey); in run_tests_once()
1805 sys_pkey_free(pkey); in run_tests_once()