Skip to content

Commit f253d82

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: uaccess: refactor __{get,put}_user
As a step towards implementing __{get,put}_kernel_nofault(), this patch splits most user-memory specific logic out of __{get,put}_user(), with the memory access and fault handling in new __{raw_get,put}_mem() helpers. For now the LDR/LDTR patching is left within the *get_mem() helpers, and will be removed in a subsequent patch. There should be no functional change as a result of this patch. Signed-off-by: Mark Rutland <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: James Morse <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 9e94fda commit f253d82

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

arch/arm64/include/asm/uaccess.h

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
253253
* The "__xxx_error" versions set the third argument to -EFAULT if an error
254254
* occurs, and leave it unchanged on success.
255255
*/
256-
#define __get_user_asm(instr, alt_instr, reg, x, addr, err, feature) \
256+
#define __get_mem_asm(instr, alt_instr, reg, x, addr, err, feature) \
257257
asm volatile( \
258258
"1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \
259259
alt_instr " " reg "1, [%2]\n", feature) \
@@ -268,35 +268,40 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)
268268
: "+r" (err), "=&r" (x) \
269269
: "r" (addr), "i" (-EFAULT))
270270

271-
#define __raw_get_user(x, ptr, err) \
271+
#define __raw_get_mem(x, ptr, err) \
272272
do { \
273273
unsigned long __gu_val; \
274-
__chk_user_ptr(ptr); \
275-
uaccess_enable_not_uao(); \
276274
switch (sizeof(*(ptr))) { \
277275
case 1: \
278-
__get_user_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \
276+
__get_mem_asm("ldrb", "ldtrb", "%w", __gu_val, (ptr), \
279277
(err), ARM64_HAS_UAO); \
280278
break; \
281279
case 2: \
282-
__get_user_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr), \
280+
__get_mem_asm("ldrh", "ldtrh", "%w", __gu_val, (ptr), \
283281
(err), ARM64_HAS_UAO); \
284282
break; \
285283
case 4: \
286-
__get_user_asm("ldr", "ldtr", "%w", __gu_val, (ptr), \
284+
__get_mem_asm("ldr", "ldtr", "%w", __gu_val, (ptr), \
287285
(err), ARM64_HAS_UAO); \
288286
break; \
289287
case 8: \
290-
__get_user_asm("ldr", "ldtr", "%x", __gu_val, (ptr), \
288+
__get_mem_asm("ldr", "ldtr", "%x", __gu_val, (ptr), \
291289
(err), ARM64_HAS_UAO); \
292290
break; \
293291
default: \
294292
BUILD_BUG(); \
295293
} \
296-
uaccess_disable_not_uao(); \
297294
(x) = (__force __typeof__(*(ptr)))__gu_val; \
298295
} while (0)
299296

297+
#define __raw_get_user(x, ptr, err) \
298+
do { \
299+
__chk_user_ptr(ptr); \
300+
uaccess_enable_not_uao(); \
301+
__raw_get_mem(x, ptr, err); \
302+
uaccess_disable_not_uao(); \
303+
} while (0)
304+
300305
#define __get_user_error(x, ptr, err) \
301306
do { \
302307
__typeof__(*(ptr)) __user *__p = (ptr); \
@@ -318,7 +323,7 @@ do { \
318323

319324
#define get_user __get_user
320325

321-
#define __put_user_asm(instr, alt_instr, reg, x, addr, err, feature) \
326+
#define __put_mem_asm(instr, alt_instr, reg, x, addr, err, feature) \
322327
asm volatile( \
323328
"1:"ALTERNATIVE(instr " " reg "1, [%2]\n", \
324329
alt_instr " " reg "1, [%2]\n", feature) \
@@ -332,31 +337,36 @@ do { \
332337
: "+r" (err) \
333338
: "r" (x), "r" (addr), "i" (-EFAULT))
334339

335-
#define __raw_put_user(x, ptr, err) \
340+
#define __raw_put_mem(x, ptr, err) \
336341
do { \
337342
__typeof__(*(ptr)) __pu_val = (x); \
338-
__chk_user_ptr(ptr); \
339-
uaccess_enable_not_uao(); \
340343
switch (sizeof(*(ptr))) { \
341344
case 1: \
342-
__put_user_asm("strb", "sttrb", "%w", __pu_val, (ptr), \
345+
__put_mem_asm("strb", "sttrb", "%w", __pu_val, (ptr), \
343346
(err), ARM64_HAS_UAO); \
344347
break; \
345348
case 2: \
346-
__put_user_asm("strh", "sttrh", "%w", __pu_val, (ptr), \
349+
__put_mem_asm("strh", "sttrh", "%w", __pu_val, (ptr), \
347350
(err), ARM64_HAS_UAO); \
348351
break; \
349352
case 4: \
350-
__put_user_asm("str", "sttr", "%w", __pu_val, (ptr), \
353+
__put_mem_asm("str", "sttr", "%w", __pu_val, (ptr), \
351354
(err), ARM64_HAS_UAO); \
352355
break; \
353356
case 8: \
354-
__put_user_asm("str", "sttr", "%x", __pu_val, (ptr), \
357+
__put_mem_asm("str", "sttr", "%x", __pu_val, (ptr), \
355358
(err), ARM64_HAS_UAO); \
356359
break; \
357360
default: \
358361
BUILD_BUG(); \
359362
} \
363+
} while (0)
364+
365+
#define __raw_put_user(x, ptr, err) \
366+
do { \
367+
__chk_user_ptr(ptr); \
368+
uaccess_enable_not_uao(); \
369+
__raw_put_mem(x, ptr, err); \
360370
uaccess_disable_not_uao(); \
361371
} while (0)
362372

0 commit comments

Comments
 (0)