Skip to content

Commit adccfb1

Browse files
greentimepalmer-dabbelt
authored andcommitted
riscv: uaccess should be used in nommu mode
It might have the unaligned access exception when trying to exchange data with user space program. In this case, it failed in tty_ioctl(). Therefore we should enable uaccess.S for NOMMU mode since the generic code doesn't handle the unaligned access cases. 0x8013a212 <tty_ioctl+462>: ld a5,460(s1) [ 0.115279] Oops - load address misaligned [#1] [ 0.115284] CPU: 0 PID: 29 Comm: sh Not tainted 5.4.0-rc5-00020-gb4c27160d562-dirty torvalds#36 [ 0.115294] epc: 000000008013a212 ra : 000000008013a212 sp : 000000008f48dd50 [ 0.115303] gp : 00000000801cac28 tp : 000000008fb80000 t0 : 00000000000000e8 [ 0.115312] t1 : 000000008f58f108 t2 : 0000000000000009 s0 : 000000008f48ddf0 [ 0.115321] s1 : 000000008f8c6220 a0 : 0000000000000001 a1 : 000000008f48dd28 [ 0.115330] a2 : 000000008fb80000 a3 : 00000000801a7398 a4 : 0000000000000000 [ 0.115339] a5 : 0000000000000000 a6 : 000000008f58f0c6 a7 : 000000000000001d [ 0.115348] s2 : 000000008f8c6308 s3 : 000000008f78b7c8 s4 : 000000008fb834c0 [ 0.115357] s5 : 0000000000005413 s6 : 0000000000000000 s7 : 000000008f58f2b0 [ 0.115366] s8 : 000000008f858008 s9 : 000000008f776818 s10: 000000008f776830 [ 0.115375] s11: 000000008fb840a8 t3 : 1999999999999999 t4 : 000000008f78704c [ 0.115384] t5 : 0000000000000005 t6 : 0000000000000002 [ 0.115391] status: 0000000200001880 badaddr: 000000008f8c63ec cause: 0000000000000004 [ 0.115401] ---[ end trace 00d490c6a8b6c9ac ]--- This failure could be fixed after this patch applied. [ 0.002282] Run /init as init process Initializing random number generator... [ 0.005573] random: dd: uninitialized urandom read (512 bytes read) done. Welcome to Buildroot buildroot login: root Password: Jan 1 00:00:00 login[62]: root login on 'ttySIF0' ~ # Signed-off-by: Greentime Hu <[email protected]> Reviewed-by: Palmer Dabbelt <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent fb33c65 commit adccfb1

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

arch/riscv/Kconfig

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ config RISCV
5050
select PCI_DOMAINS_GENERIC if PCI
5151
select PCI_MSI if PCI
5252
select RISCV_TIMER
53-
select UACCESS_MEMCPY if !MMU
5453
select GENERIC_IRQ_MULTI_HANDLER
5554
select GENERIC_ARCH_TOPOLOGY if SMP
5655
select ARCH_HAS_PTE_SPECIAL

arch/riscv/include/asm/uaccess.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111
/*
1212
* User space memory access functions
1313
*/
14+
15+
extern unsigned long __must_check __asm_copy_to_user(void __user *to,
16+
const void *from, unsigned long n);
17+
extern unsigned long __must_check __asm_copy_from_user(void *to,
18+
const void __user *from, unsigned long n);
19+
20+
static inline unsigned long
21+
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
22+
{
23+
return __asm_copy_from_user(to, from, n);
24+
}
25+
26+
static inline unsigned long
27+
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
28+
{
29+
return __asm_copy_to_user(to, from, n);
30+
}
31+
1432
#ifdef CONFIG_MMU
1533
#include <linux/errno.h>
1634
#include <linux/compiler.h>
@@ -367,24 +385,6 @@ do { \
367385
-EFAULT; \
368386
})
369387

370-
371-
extern unsigned long __must_check __asm_copy_to_user(void __user *to,
372-
const void *from, unsigned long n);
373-
extern unsigned long __must_check __asm_copy_from_user(void *to,
374-
const void __user *from, unsigned long n);
375-
376-
static inline unsigned long
377-
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
378-
{
379-
return __asm_copy_from_user(to, from, n);
380-
}
381-
382-
static inline unsigned long
383-
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
384-
{
385-
return __asm_copy_to_user(to, from, n);
386-
}
387-
388388
extern long strncpy_from_user(char *dest, const char __user *src, long count);
389389

390390
extern long __must_check strlen_user(const char __user *str);

arch/riscv/lib/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
lib-y += delay.o
33
lib-y += memcpy.o
44
lib-y += memset.o
5-
lib-$(CONFIG_MMU) += uaccess.o
5+
lib-y += uaccess.o
66
lib-$(CONFIG_64BIT) += tishift.o

0 commit comments

Comments
 (0)