aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-06-08 20:33:51 -0400
committerPalmer Dabbelt <palmer@sifive.com>2018-06-09 15:34:31 -0400
commit86406d51d3600bfa2b6f86e1e6bfce712bec0d53 (patch)
tree377b5f849722635bc2e919a4a7176da05d7859d0
parent9bf97390b3030b68a465681043a66461c7cf6a65 (diff)
riscv: split the declaration of __copy_user
We use a single __copy_user assembly function to copy memory both from and to userspace. While this works, it triggers sparse errors because we're implicitly casting between the kernel and user address spaces by calling __copy_user. This patch splits the C declaration into a pair of functions, __asm_copy_{to,from}_user, that have sane semantics WRT __user. This split make things fine from sparse's point of view. The assembly implementation keeps a single definition but add a double ENTRY() for it, one for __asm_copy_to_user and another one for __asm_copy_from_user. The result is a spare-safe implementation that pays no performance or code size penalty. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
-rw-r--r--arch/riscv/include/asm/uaccess.h8
-rw-r--r--arch/riscv/kernel/riscv_ksyms.c3
-rw-r--r--arch/riscv/lib/uaccess.S6
3 files changed, 11 insertions, 6 deletions
diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
index 14b0b22fb578..473cfc84e412 100644
--- a/arch/riscv/include/asm/uaccess.h
+++ b/arch/riscv/include/asm/uaccess.h
@@ -392,19 +392,21 @@ do { \
392}) 392})
393 393
394 394
395extern unsigned long __must_check __copy_user(void __user *to, 395extern unsigned long __must_check __asm_copy_to_user(void __user *to,
396 const void *from, unsigned long n);
397extern unsigned long __must_check __asm_copy_from_user(void *to,
396 const void __user *from, unsigned long n); 398 const void __user *from, unsigned long n);
397 399
398static inline unsigned long 400static inline unsigned long
399raw_copy_from_user(void *to, const void __user *from, unsigned long n) 401raw_copy_from_user(void *to, const void __user *from, unsigned long n)
400{ 402{
401 return __copy_user(to, from, n); 403 return __asm_copy_to_user(to, from, n);
402} 404}
403 405
404static inline unsigned long 406static inline unsigned long
405raw_copy_to_user(void __user *to, const void *from, unsigned long n) 407raw_copy_to_user(void __user *to, const void *from, unsigned long n)
406{ 408{
407 return __copy_user(to, from, n); 409 return __asm_copy_from_user(to, from, n);
408} 410}
409 411
410extern long strncpy_from_user(char *dest, const char __user *src, long count); 412extern long strncpy_from_user(char *dest, const char __user *src, long count);
diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c
index 551734248748..f247d6d2137c 100644
--- a/arch/riscv/kernel/riscv_ksyms.c
+++ b/arch/riscv/kernel/riscv_ksyms.c
@@ -13,6 +13,7 @@
13 * Assembly functions that may be used (directly or indirectly) by modules 13 * Assembly functions that may be used (directly or indirectly) by modules
14 */ 14 */
15EXPORT_SYMBOL(__clear_user); 15EXPORT_SYMBOL(__clear_user);
16EXPORT_SYMBOL(__copy_user); 16EXPORT_SYMBOL(__asm_copy_to_user);
17EXPORT_SYMBOL(__asm_copy_from_user);
17EXPORT_SYMBOL(memset); 18EXPORT_SYMBOL(memset);
18EXPORT_SYMBOL(memcpy); 19EXPORT_SYMBOL(memcpy);
diff --git a/arch/riscv/lib/uaccess.S b/arch/riscv/lib/uaccess.S
index 58fb2877c865..f8e6440cad6e 100644
--- a/arch/riscv/lib/uaccess.S
+++ b/arch/riscv/lib/uaccess.S
@@ -13,7 +13,8 @@ _epc:
13 .previous 13 .previous
14 .endm 14 .endm
15 15
16ENTRY(__copy_user) 16ENTRY(__asm_copy_to_user)
17ENTRY(__asm_copy_from_user)
17 18
18 /* Enable access to user memory */ 19 /* Enable access to user memory */
19 li t6, SR_SUM 20 li t6, SR_SUM
@@ -63,7 +64,8 @@ ENTRY(__copy_user)
63 addi a0, a0, 1 64 addi a0, a0, 1
64 bltu a1, a3, 5b 65 bltu a1, a3, 5b
65 j 3b 66 j 3b
66ENDPROC(__copy_user) 67ENDPROC(__asm_copy_to_user)
68ENDPROC(__asm_copy_from_user)
67 69
68 70
69ENTRY(__clear_user) 71ENTRY(__clear_user)