riscv: split the declaration of __copy_user
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Sat, 9 Jun 2018 00:33:51 +0000 (02:33 +0200)
committerPalmer Dabbelt <palmer@sifive.com>
Sat, 9 Jun 2018 19:34:31 +0000 (12:34 -0700)
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>
arch/riscv/include/asm/uaccess.h
arch/riscv/kernel/riscv_ksyms.c
arch/riscv/lib/uaccess.S

index 14b0b22fb57875dfe920685265a79da317c517e0..473cfc84e412f3827703caaadffa34a8983c978d 100644 (file)
@@ -392,19 +392,21 @@ do {                                                              \
 })
 
 
-extern unsigned long __must_check __copy_user(void __user *to,
+extern unsigned long __must_check __asm_copy_to_user(void __user *to,
+       const void *from, unsigned long n);
+extern unsigned long __must_check __asm_copy_from_user(void *to,
        const void __user *from, unsigned long n);
 
 static inline unsigned long
 raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 {
-       return __copy_user(to, from, n);
+       return __asm_copy_to_user(to, from, n);
 }
 
 static inline unsigned long
 raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 {
-       return __copy_user(to, from, n);
+       return __asm_copy_from_user(to, from, n);
 }
 
 extern long strncpy_from_user(char *dest, const char __user *src, long count);
index 5517342487489b6ee35c4a95bbfa3d5c4a31f2aa..f247d6d2137c4515678052565b1ab43a29c523e2 100644 (file)
@@ -13,6 +13,7 @@
  * Assembly functions that may be used (directly or indirectly) by modules
  */
 EXPORT_SYMBOL(__clear_user);
-EXPORT_SYMBOL(__copy_user);
+EXPORT_SYMBOL(__asm_copy_to_user);
+EXPORT_SYMBOL(__asm_copy_from_user);
 EXPORT_SYMBOL(memset);
 EXPORT_SYMBOL(memcpy);
index 58fb2877c865286a32894d343f483202f28c229e..f8e6440cad6e825652d25a6f3ef84e206df478aa 100644 (file)
@@ -13,7 +13,8 @@ _epc:
        .previous
        .endm
 
-ENTRY(__copy_user)
+ENTRY(__asm_copy_to_user)
+ENTRY(__asm_copy_from_user)
 
        /* Enable access to user memory */
        li t6, SR_SUM
@@ -63,7 +64,8 @@ ENTRY(__copy_user)
        addi a0, a0, 1
        bltu a1, a3, 5b
        j 3b
-ENDPROC(__copy_user)
+ENDPROC(__asm_copy_to_user)
+ENDPROC(__asm_copy_from_user)
 
 
 ENTRY(__clear_user)