Skip to content

Commit 86406d5

Browse files
lucvoopalmer-dabbelt
authored andcommitted
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>
1 parent 9bf9739 commit 86406d5

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

arch/riscv/include/asm/uaccess.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,19 +392,21 @@ do { \
392392
})
393393

394394

395-
extern unsigned long __must_check __copy_user(void __user *to,
395+
extern unsigned long __must_check __asm_copy_to_user(void __user *to,
396+
const void *from, unsigned long n);
397+
extern unsigned long __must_check __asm_copy_from_user(void *to,
396398
const void __user *from, unsigned long n);
397399

398400
static inline unsigned long
399401
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
400402
{
401-
return __copy_user(to, from, n);
403+
return __asm_copy_to_user(to, from, n);
402404
}
403405

404406
static inline unsigned long
405407
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
406408
{
407-
return __copy_user(to, from, n);
409+
return __asm_copy_from_user(to, from, n);
408410
}
409411

410412
extern long strncpy_from_user(char *dest, const char __user *src, long count);

arch/riscv/kernel/riscv_ksyms.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Assembly functions that may be used (directly or indirectly) by modules
1414
*/
1515
EXPORT_SYMBOL(__clear_user);
16-
EXPORT_SYMBOL(__copy_user);
16+
EXPORT_SYMBOL(__asm_copy_to_user);
17+
EXPORT_SYMBOL(__asm_copy_from_user);
1718
EXPORT_SYMBOL(memset);
1819
EXPORT_SYMBOL(memcpy);

arch/riscv/lib/uaccess.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ _epc:
1313
.previous
1414
.endm
1515

16-
ENTRY(__copy_user)
16+
ENTRY(__asm_copy_to_user)
17+
ENTRY(__asm_copy_from_user)
1718

1819
/* Enable access to user memory */
1920
li t6, SR_SUM
@@ -63,7 +64,8 @@ ENTRY(__copy_user)
6364
addi a0, a0, 1
6465
bltu a1, a3, 5b
6566
j 3b
66-
ENDPROC(__copy_user)
67+
ENDPROC(__asm_copy_to_user)
68+
ENDPROC(__asm_copy_from_user)
6769

6870

6971
ENTRY(__clear_user)

0 commit comments

Comments
 (0)