@@ -150,20 +150,16 @@ EXPORT_SYMBOL(_copy_to_user_key);
150
150
151
151
#define CMPXCHG_USER_KEY_MAX_LOOPS 128
152
152
153
- int __kprobes __cmpxchg_user_key1 (unsigned long address , unsigned char * uval ,
154
- unsigned char old , unsigned char new , unsigned long key )
153
+ static nokprobe_inline int __cmpxchg_user_key_small (unsigned long address , unsigned int * uval ,
154
+ unsigned int old , unsigned int new ,
155
+ unsigned int mask , unsigned long key )
155
156
{
156
- unsigned int prev , shift , mask , _old , _new ;
157
157
unsigned long count ;
158
+ unsigned int prev ;
158
159
bool sacf_flag ;
159
160
int rc = 0 ;
160
161
161
162
skey_regions_initialize ();
162
- shift = (3 ^ (address & 3 )) << 3 ;
163
- address ^= address & 3 ;
164
- _old = (unsigned int )old << shift ;
165
- _new = (unsigned int )new << shift ;
166
- mask = ~(0xff << shift );
167
163
sacf_flag = enable_sacf_uaccess ();
168
164
asm_inline volatile (
169
165
"20: spka 0(%[key])\n"
@@ -193,77 +189,51 @@ int __kprobes __cmpxchg_user_key1(unsigned long address, unsigned char *uval,
193
189
: [rc ] "+ & d " (rc),
194
190
[prev ] "= & d " (prev),
195
191
[address ] "+ Q " (*(int *)address),
196
- [tmp ] "+ & d " (_old ),
197
- [new ] "+ & d " (_new ),
192
+ [tmp ] "+ & d " (old ),
193
+ [new ] "+ & d " (new ),
198
194
[mask ] "+ & d " (mask),
199
195
[count ] "= a " (count)
200
196
: [key ] "%[count]" (key << 4 ),
201
197
[default_key ] "J" (PAGE_DEFAULT_KEY ),
202
198
[max_loops ] "J" (CMPXCHG_USER_KEY_MAX_LOOPS )
203
199
: "memory ", " cc ");
204
200
disable_sacf_uaccess (sacf_flag );
205
- * uval = prev >> shift ;
201
+ * uval = prev ;
206
202
if (!count )
207
203
rc = - EAGAIN ;
208
204
return rc ;
209
205
}
206
+
207
+ int __kprobes __cmpxchg_user_key1 (unsigned long address , unsigned char * uval ,
208
+ unsigned char old , unsigned char new , unsigned long key )
209
+ {
210
+ unsigned int prev , shift , mask , _old , _new ;
211
+ int rc ;
212
+
213
+ shift = (3 ^ (address & 3 )) << 3 ;
214
+ address ^= address & 3 ;
215
+ _old = (unsigned int )old << shift ;
216
+ _new = (unsigned int )new << shift ;
217
+ mask = ~(0xff << shift );
218
+ rc = __cmpxchg_user_key_small (address , & prev , _old , _new , mask , key );
219
+ * uval = prev >> shift ;
220
+ return rc ;
221
+ }
210
222
EXPORT_SYMBOL (__cmpxchg_user_key1 );
211
223
212
224
int __kprobes __cmpxchg_user_key2 (unsigned long address , unsigned short * uval ,
213
225
unsigned short old , unsigned short new , unsigned long key )
214
226
{
215
227
unsigned int prev , shift , mask , _old , _new ;
216
- unsigned long count ;
217
- bool sacf_flag ;
218
- int rc = 0 ;
228
+ int rc ;
219
229
220
- skey_regions_initialize ();
221
230
shift = (2 ^ (address & 2 )) << 3 ;
222
231
address ^= address & 2 ;
223
232
_old = (unsigned int )old << shift ;
224
233
_new = (unsigned int )new << shift ;
225
234
mask = ~(0xffff << shift );
226
- sacf_flag = enable_sacf_uaccess ();
227
- asm_inline volatile (
228
- "20: spka 0(%[key])\n"
229
- " sacf 256\n"
230
- " llill %[count],%[max_loops]\n"
231
- "0: l %[prev],%[address]\n"
232
- "1: nr %[prev],%[mask]\n"
233
- " xilf %[mask],0xffffffff\n"
234
- " or %[new],%[prev]\n"
235
- " or %[prev],%[tmp]\n"
236
- "2: lr %[tmp],%[prev]\n"
237
- "3: cs %[prev],%[new],%[address]\n"
238
- "4: jnl 5f\n"
239
- " xr %[tmp],%[prev]\n"
240
- " xr %[new],%[tmp]\n"
241
- " nr %[tmp],%[mask]\n"
242
- " jnz 5f\n"
243
- " brct %[count],2b\n"
244
- "5: sacf 768\n"
245
- " spka %[default_key]\n"
246
- "21:\n"
247
- EX_TABLE_UA_LOAD_REG (0b , 5b , %[rc ], %[prev ])
248
- EX_TABLE_UA_LOAD_REG (1b , 5b , %[rc ], %[prev ])
249
- EX_TABLE_UA_LOAD_REG (3b , 5b , %[rc ], %[prev ])
250
- EX_TABLE_UA_LOAD_REG (4b , 5b , %[rc ], %[prev ])
251
- SKEY_REGION (20b , 21b )
252
- : [rc ] "+ & d " (rc),
253
- [prev ] "= & d " (prev),
254
- [address ] "+ Q " (*(int *)address),
255
- [tmp ] "+ & d " (_old),
256
- [new ] "+ & d " (_new),
257
- [mask ] "+ & d " (mask),
258
- [count ] "= a " (count)
259
- : [key ] "%[count]" (key << 4 ),
260
- [default_key ] "J" (PAGE_DEFAULT_KEY ),
261
- [max_loops ] "J" (CMPXCHG_USER_KEY_MAX_LOOPS )
262
- : "memory ", " cc ");
263
- disable_sacf_uaccess (sacf_flag );
235
+ rc = __cmpxchg_user_key_small (address , & prev , _old , _new , mask , key );
264
236
* uval = prev >> shift ;
265
- if (!count )
266
- rc = - EAGAIN ;
267
237
return rc ;
268
238
}
269
239
EXPORT_SYMBOL (__cmpxchg_user_key2 );
0 commit comments