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()
596 unsigned long pkey) in mprotect_pkey() argument
603 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
605 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
619 pkey_assert(pkey < NR_PKEYS); in mprotect_pkey()
621 ret = sys_mprotect_pkey(ptr, size, orig_prot, pkey); in mprotect_pkey()
623 ptr, size, orig_prot, pkey, ret); in mprotect_pkey()
704 void *malloc_pkey_with_mprotect(long size, int prot, u16 pkey) in malloc_pkey_with_mprotect() argument
711 size, prot, pkey); in malloc_pkey_with_mprotect()
712 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_with_mprotect()
715 ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey); in malloc_pkey_with_mprotect()
720 dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr); in malloc_pkey_with_mprotect()
724 void *malloc_pkey_anon_huge(long size, int prot, u16 pkey) in malloc_pkey_anon_huge() argument
730 size, prot, pkey); in malloc_pkey_anon_huge()
739 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_anon_huge()
750 dprintf1("mmap()'d thp for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_anon_huge()
805 void *malloc_pkey_hugetlb(long size, int prot, u16 pkey) in malloc_pkey_hugetlb() argument
813 dprintf1("doing %s(%ld, %x, %x)\n", __func__, size, prot, pkey); in malloc_pkey_hugetlb()
815 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_hugetlb()
818 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_hugetlb()
822 dprintf1("mmap()'d hugetlbfs for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_hugetlb()
826 void *malloc_pkey_mmap_dax(long size, int prot, u16 pkey) in malloc_pkey_mmap_dax() argument
832 size, prot, pkey); in malloc_pkey_mmap_dax()
833 pkey_assert(pkey < NR_PKEYS); in malloc_pkey_mmap_dax()
840 mprotect_pkey(ptr, size, prot, pkey); in malloc_pkey_mmap_dax()
844 dprintf1("mmap()'d for pkey %d @ %p\n", pkey, ptr); in malloc_pkey_mmap_dax()
849 void *(*pkey_malloc[])(long size, int prot, u16 pkey) = {
861 void *malloc_pkey(long size, int prot, u16 pkey) in malloc_pkey() argument
867 pkey_assert(pkey < NR_PKEYS); in malloc_pkey()
872 ret = pkey_malloc[malloc_type](size, prot, pkey); in malloc_pkey()
887 size, prot, pkey, ret); in malloc_pkey()
893 void expected_pkey_fault(int pkey) in expected_pkey_fault() argument
897 dprintf2("%s(%d): last_si_pkey: %d\n", __func__, pkey, last_si_pkey); in expected_pkey_fault()
904 if (pkey != UNKNOWN_PKEY) in expected_pkey_fault()
905 pkey_assert(last_si_pkey == pkey); in expected_pkey_fault()
971 void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey) in test_pkey_alloc_free_attach_pkey0() argument
1023 void test_read_of_write_disabled_region(int *ptr, u16 pkey) in test_read_of_write_disabled_region() argument
1028 pkey_write_deny(pkey); in test_read_of_write_disabled_region()
1033 void test_read_of_access_disabled_region(int *ptr, u16 pkey) in test_read_of_access_disabled_region() argument
1037 dprintf1("disabling access to PKEY[%02d], doing read @ %p\n", pkey, ptr); in test_read_of_access_disabled_region()
1039 pkey_access_deny(pkey); in test_read_of_access_disabled_region()
1042 expected_pkey_fault(pkey); in test_read_of_access_disabled_region()
1046 u16 pkey) in test_read_of_access_disabled_region_with_page_already_mapped() argument
1051 pkey, ptr); in test_read_of_access_disabled_region_with_page_already_mapped()
1056 pkey_access_deny(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1059 expected_pkey_fault(pkey); in test_read_of_access_disabled_region_with_page_already_mapped()
1063 u16 pkey) in test_write_of_write_disabled_region_with_page_already_mapped() argument
1067 "to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1068 pkey_write_deny(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1070 expected_pkey_fault(pkey); in test_write_of_write_disabled_region_with_page_already_mapped()
1073 void test_write_of_write_disabled_region(int *ptr, u16 pkey) in test_write_of_write_disabled_region() argument
1075 dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); in test_write_of_write_disabled_region()
1076 pkey_write_deny(pkey); in test_write_of_write_disabled_region()
1078 expected_pkey_fault(pkey); in test_write_of_write_disabled_region()
1080 void test_write_of_access_disabled_region(int *ptr, u16 pkey) in test_write_of_access_disabled_region() argument
1082 dprintf1("disabling access to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region()
1083 pkey_access_deny(pkey); in test_write_of_access_disabled_region()
1085 expected_pkey_fault(pkey); in test_write_of_access_disabled_region()
1089 u16 pkey) in test_write_of_access_disabled_region_with_page_already_mapped() argument
1093 " to PKEY[%02d], doing write\n", pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1094 pkey_access_deny(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1096 expected_pkey_fault(pkey); in test_write_of_access_disabled_region_with_page_already_mapped()
1099 void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_access_disabled_region() argument
1105 "having kernel read() to buffer\n", pkey); in test_kernel_write_of_access_disabled_region()
1106 pkey_access_deny(pkey); in test_kernel_write_of_access_disabled_region()
1111 void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) in test_kernel_write_of_write_disabled_region() argument
1116 pkey_write_deny(pkey); in test_kernel_write_of_write_disabled_region()
1124 void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_of_access_disabled_region() argument
1134 "having kernel vmsplice from buffer\n", pkey); in test_kernel_gup_of_access_disabled_region()
1135 pkey_access_deny(pkey); in test_kernel_gup_of_access_disabled_region()
1146 void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) in test_kernel_gup_write_to_write_disabled_region() argument
1153 "doing futex gunk in buffer\n", pkey); in test_kernel_gup_write_to_write_disabled_region()
1155 pkey_write_deny(pkey); in test_kernel_gup_write_to_write_disabled_region()
1164 void test_pkey_syscalls_on_non_allocated_pkey(int *ptr, u16 pkey) in test_pkey_syscalls_on_non_allocated_pkey() argument
1171 if (pkey == i) in test_pkey_syscalls_on_non_allocated_pkey()
1187 void test_pkey_syscalls_bad_args(int *ptr, u16 pkey) in test_pkey_syscalls_bad_args() argument
1213 void test_pkey_alloc_exhaust(int *ptr, u16 pkey) in test_pkey_alloc_exhaust() argument
1319 void test_pkey_init_state(int *ptr, u16 pkey) in test_pkey_init_state() argument
1357 void test_mprotect_with_pkey_0(int *ptr, u16 pkey) in test_mprotect_with_pkey_0() argument
1378 mprotect_pkey(ptr, size, prot, pkey); in test_mprotect_with_pkey_0()
1381 void test_ptrace_of_child(int *ptr, u16 pkey) in test_ptrace_of_child() argument
1417 pkey_access_deny(pkey); in test_ptrace_of_child()
1418 pkey_write_deny(pkey); in test_ptrace_of_child()
1434 expected_pkey_fault(pkey); in test_ptrace_of_child()
1478 void test_executing_on_unreadable_memory(int *ptr, u16 pkey) in test_executing_on_unreadable_memory() argument
1490 ret = mprotect_pkey(p1, PAGE_SIZE, PROT_EXEC, (u64)pkey); in test_executing_on_unreadable_memory()
1492 pkey_access_deny(pkey); in test_executing_on_unreadable_memory()
1502 expect_fault_on_read_execonly_key(p1, pkey); in test_executing_on_unreadable_memory()
1505 void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) in test_implicit_mprotect_exec_only_memory() argument
1553 void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) in test_mprotect_pkey_on_unsupported_cpu() argument
1563 sret = syscall(SYS_mprotect_key, ptr, size, PROT_READ, pkey); in test_mprotect_pkey_on_unsupported_cpu()
1567 void (*pkey_tests[])(int *ptr, u16 pkey) = {
1596 int pkey; in run_tests_once() local
1603 pkey = alloc_random_pkey(); in run_tests_once()
1604 dprintf1("test %d starting with pkey: %d\n", test_nr, pkey); in run_tests_once()
1605 ptr = malloc_pkey(PAGE_SIZE, prot, pkey); in run_tests_once()
1607 pkey_tests[test_nr](ptr, pkey); in run_tests_once()
1610 sys_pkey_free(pkey); in run_tests_once()