~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/mm/pkey-powerpc.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 
  3 #ifndef _PKEYS_POWERPC_H
  4 #define _PKEYS_POWERPC_H
  5 
  6 #ifndef SYS_pkey_alloc
  7 # define SYS_pkey_alloc         384
  8 # define SYS_pkey_free          385
  9 #endif
 10 #define REG_IP_IDX              PT_NIP
 11 #define REG_TRAPNO              PT_TRAP
 12 #define gregs                   gp_regs
 13 #define fpregs                  fp_regs
 14 #define si_pkey_offset          0x20
 15 
 16 #undef PKEY_DISABLE_ACCESS
 17 #define PKEY_DISABLE_ACCESS     0x3  /* disable read and write */
 18 
 19 #undef PKEY_DISABLE_WRITE
 20 #define PKEY_DISABLE_WRITE      0x2
 21 
 22 #define NR_PKEYS                32
 23 #define NR_RESERVED_PKEYS_4K    27 /* pkey-0, pkey-1, exec-only-pkey
 24                                       and 24 other keys that cannot be
 25                                       represented in the PTE */
 26 #define NR_RESERVED_PKEYS_64K_3KEYS     3 /* PowerNV and KVM: pkey-0,
 27                                              pkey-1 and exec-only key */
 28 #define NR_RESERVED_PKEYS_64K_4KEYS     4 /* PowerVM: pkey-0, pkey-1,
 29                                              pkey-31 and exec-only key */
 30 #define PKEY_BITS_PER_PKEY      2
 31 #define HPAGE_SIZE              (1UL << 24)
 32 #define PAGE_SIZE               sysconf(_SC_PAGESIZE)
 33 
 34 static inline u32 pkey_bit_position(int pkey)
 35 {
 36         return (NR_PKEYS - pkey - 1) * PKEY_BITS_PER_PKEY;
 37 }
 38 
 39 static inline u64 __read_pkey_reg(void)
 40 {
 41         u64 pkey_reg;
 42 
 43         asm volatile("mfspr %0, 0xd" : "=r" (pkey_reg));
 44 
 45         return pkey_reg;
 46 }
 47 
 48 static inline void __write_pkey_reg(u64 pkey_reg)
 49 {
 50         u64 amr = pkey_reg;
 51 
 52         dprintf4("%s() changing %016llx to %016llx\n",
 53                          __func__, __read_pkey_reg(), pkey_reg);
 54 
 55         asm volatile("isync; mtspr 0xd, %0; isync"
 56                      : : "r" ((unsigned long)(amr)) : "memory");
 57 
 58         dprintf4("%s() pkey register after changing %016llx to %016llx\n",
 59                         __func__, __read_pkey_reg(), pkey_reg);
 60 }
 61 
 62 static inline int cpu_has_pkeys(void)
 63 {
 64         /* No simple way to determine this */
 65         return 1;
 66 }
 67 
 68 static inline bool arch_is_powervm()
 69 {
 70         struct stat buf;
 71 
 72         if ((stat("/sys/firmware/devicetree/base/ibm,partition-name", &buf) == 0) &&
 73             (stat("/sys/firmware/devicetree/base/hmc-managed?", &buf) == 0) &&
 74             (stat("/sys/firmware/devicetree/base/chosen/qemu,graphic-width", &buf) == -1) )
 75                 return true;
 76 
 77         return false;
 78 }
 79 
 80 static inline int get_arch_reserved_keys(void)
 81 {
 82         if (sysconf(_SC_PAGESIZE) == 4096)
 83                 return NR_RESERVED_PKEYS_4K;
 84         else
 85                 if (arch_is_powervm())
 86                         return NR_RESERVED_PKEYS_64K_4KEYS;
 87                 else
 88                         return NR_RESERVED_PKEYS_64K_3KEYS;
 89 }
 90 
 91 void expect_fault_on_read_execonly_key(void *p1, int pkey)
 92 {
 93         /*
 94          * powerpc does not allow userspace to change permissions of exec-only
 95          * keys since those keys are not allocated by userspace. The signal
 96          * handler wont be able to reset the permissions, which means the code
 97          * will infinitely continue to segfault here.
 98          */
 99         return;
100 }
101 
102 /* 4-byte instructions * 16384 = 64K page */
103 #define __page_o_noops() asm(".rept 16384 ; nop; .endr")
104 
105 void *malloc_pkey_with_mprotect_subpage(long size, int prot, u16 pkey)
106 {
107         void *ptr;
108         int ret;
109 
110         dprintf1("doing %s(size=%ld, prot=0x%x, pkey=%d)\n", __func__,
111                         size, prot, pkey);
112         pkey_assert(pkey < NR_PKEYS);
113         ptr = mmap(NULL, size, prot, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
114         pkey_assert(ptr != (void *)-1);
115 
116         ret = syscall(__NR_subpage_prot, ptr, size, NULL);
117         if (ret) {
118                 perror("subpage_perm");
119                 return PTR_ERR_ENOTSUP;
120         }
121 
122         ret = mprotect_pkey((void *)ptr, PAGE_SIZE, prot, pkey);
123         pkey_assert(!ret);
124         record_pkey_malloc(ptr, size, prot);
125 
126         dprintf1("%s() for pkey %d @ %p\n", __func__, pkey, ptr);
127         return ptr;
128 }
129 
130 #endif /* _PKEYS_POWERPC_H */
131 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php