1 // SPDX-License-Identifier: GPL-2.0 1 2 /* 3 * Standard user space access functions based 4 * interesting things in the secondary space 5 * 6 * Copyright IBM Corp. 2006,2014 7 * Author(s): Martin Schwidefsky (schwidefs 8 * Gerald Schaefer (gerald.schae 9 */ 10 11 #include <linux/uaccess.h> 12 #include <linux/export.h> 13 #include <linux/mm.h> 14 #include <asm/asm-extable.h> 15 #include <asm/ctlreg.h> 16 17 #ifdef CONFIG_DEBUG_ENTRY 18 void debug_user_asce(int exit) 19 { 20 struct ctlreg cr1, cr7; 21 22 local_ctl_store(1, &cr1); 23 local_ctl_store(7, &cr7); 24 if (cr1.val == get_lowcore()->kernel_a 25 return; 26 panic("incorrect ASCE on kernel %s\n" 27 "cr1: %016lx cr7: %016lx\n" 28 "kernel: %016lx user: %016lx\n", 29 exit ? "exit" : "entry", cr1.val 30 get_lowcore()->kernel_asce.val, 31 } 32 #endif /*CONFIG_DEBUG_ENTRY */ 33 34 static unsigned long raw_copy_from_user_key(vo 35 un 36 { 37 unsigned long rem; 38 union oac spec = { 39 .oac2.key = key, 40 .oac2.as = PSW_BITS_AS_SECONDA 41 .oac2.k = 1, 42 .oac2.a = 1, 43 }; 44 45 asm volatile( 46 " lr 0,%[spec]\n" 47 "0: mvcos 0(%[to]),0(%[f 48 "1: jz 5f\n" 49 " algr %[size],%[val] 50 " slgr %[from],%[val] 51 " slgr %[to],%[val]\n 52 " j 0b\n" 53 "2: la %[rem],4095(%[ 54 " nr %[rem],%[val]\ 55 " slgr %[rem],%[from] 56 " clgr %[size],%[rem] 57 " jnh 6f\n" 58 "3: mvcos 0(%[to]),0(%[f 59 "4: slgr %[size],%[rem] 60 " j 6f\n" 61 "5: slgr %[size],%[size 62 "6:\n" 63 EX_TABLE(0b, 2b) 64 EX_TABLE(1b, 2b) 65 EX_TABLE(3b, 6b) 66 EX_TABLE(4b, 6b) 67 : [size] "+&a" (size), [from] 68 : [val] "a" (-4096UL), [spec] 69 : "cc", "memory", ""); 70 return size; 71 } 72 73 unsigned long raw_copy_from_user(void *to, con 74 { 75 return raw_copy_from_user_key(to, from 76 } 77 EXPORT_SYMBOL(raw_copy_from_user); 78 79 unsigned long _copy_from_user_key(void *to, co 80 unsigned lon 81 { 82 unsigned long res = n; 83 84 might_fault(); 85 if (!should_fail_usercopy()) { 86 instrument_copy_from_user_befo 87 res = raw_copy_from_user_key(t 88 instrument_copy_from_user_afte 89 } 90 if (unlikely(res)) 91 memset(to + (n - res), 0, res) 92 return res; 93 } 94 EXPORT_SYMBOL(_copy_from_user_key); 95 96 static unsigned long raw_copy_to_user_key(void 97 unsi 98 { 99 unsigned long rem; 100 union oac spec = { 101 .oac1.key = key, 102 .oac1.as = PSW_BITS_AS_SECONDA 103 .oac1.k = 1, 104 .oac1.a = 1, 105 }; 106 107 asm volatile( 108 " lr 0,%[spec]\n" 109 "0: mvcos 0(%[to]),0(%[f 110 "1: jz 5f\n" 111 " algr %[size],%[val] 112 " slgr %[to],%[val]\n 113 " slgr %[from],%[val] 114 " j 0b\n" 115 "2: la %[rem],4095(%[ 116 " nr %[rem],%[val]\ 117 " slgr %[rem],%[to]\n 118 " clgr %[size],%[rem] 119 " jnh 6f\n" 120 "3: mvcos 0(%[to]),0(%[f 121 "4: slgr %[size],%[rem] 122 " j 6f\n" 123 "5: slgr %[size],%[size 124 "6:\n" 125 EX_TABLE(0b, 2b) 126 EX_TABLE(1b, 2b) 127 EX_TABLE(3b, 6b) 128 EX_TABLE(4b, 6b) 129 : [size] "+&a" (size), [to] "+ 130 : [val] "a" (-4096UL), [spec] 131 : "cc", "memory", ""); 132 return size; 133 } 134 135 unsigned long raw_copy_to_user(void __user *to 136 { 137 return raw_copy_to_user_key(to, from, 138 } 139 EXPORT_SYMBOL(raw_copy_to_user); 140 141 unsigned long _copy_to_user_key(void __user *t 142 unsigned long 143 { 144 might_fault(); 145 if (should_fail_usercopy()) 146 return n; 147 instrument_copy_to_user(to, from, n); 148 return raw_copy_to_user_key(to, from, 149 } 150 EXPORT_SYMBOL(_copy_to_user_key); 151 152 unsigned long __clear_user(void __user *to, un 153 { 154 unsigned long rem; 155 union oac spec = { 156 .oac1.as = PSW_BITS_AS_SECONDA 157 .oac1.a = 1, 158 }; 159 160 asm volatile( 161 " lr 0,%[spec]\n" 162 "0: mvcos 0(%[to]),0(%[z 163 "1: jz 5f\n" 164 " algr %[size],%[val] 165 " slgr %[to],%[val]\n 166 " j 0b\n" 167 "2: la %[rem],4095(%[ 168 " nr %[rem],%[val]\ 169 " slgr %[rem],%[to]\n 170 " clgr %[size],%[rem] 171 " jnh 6f\n" 172 "3: mvcos 0(%[to]),0(%[z 173 "4: slgr %[size],%[rem] 174 " j 6f\n" 175 "5: slgr %[size],%[size 176 "6:\n" 177 EX_TABLE(0b, 2b) 178 EX_TABLE(1b, 2b) 179 EX_TABLE(3b, 6b) 180 EX_TABLE(4b, 6b) 181 : [size] "+&a" (size), [to] "+ 182 : [val] "a" (-4096UL), [zeropg 183 : "cc", "memory", ""); 184 return size; 185 } 186 EXPORT_SYMBOL(__clear_user); 187
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.