Skip to content

Commit bd79f94

Browse files
Christoph Hellwigarndb
authored andcommitted
asm-generic: provide entirely generic nommu uaccess
Move the code to implement uaccess using memcpy or direct loads and stores to asm-generic/uaccess.h and make it selectable kconfig option. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent c67fdc1 commit bd79f94

5 files changed

Lines changed: 54 additions & 55 deletions

File tree

‎arch/h8300/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ config H8300
2323
select HAVE_ARCH_KGDB
2424
select HAVE_ARCH_HASH
2525
select CPU_NO_EFFICIENT_FFS
26+
select UACCESS_MEMCPY
2627

2728
config CPU_BIG_ENDIAN
2829
def_bool y

‎arch/h8300/include/asm/Kbuild‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ generic-y += timex.h
4646
generic-y += tlbflush.h
4747
generic-y += topology.h
4848
generic-y += trace_clock.h
49+
generic-y += uaccess.h
4950
generic-y += unaligned.h
5051
generic-y += vga.h
5152
generic-y += word-at-a-time.h

‎arch/h8300/include/asm/uaccess.h‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

‎include/asm-generic/uaccess.h‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@
99
*/
1010
#include <linux/string.h>
1111

12+
#ifdef CONFIG_UACCESS_MEMCPY
13+
static inline __must_check unsigned long
14+
raw_copy_from_user(void *to, const void __user * from, unsigned long n)
15+
{
16+
if (__builtin_constant_p(n)) {
17+
switch(n) {
18+
case 1:
19+
*(u8 *)to = *(u8 __force *)from;
20+
return 0;
21+
case 2:
22+
*(u16 *)to = *(u16 __force *)from;
23+
return 0;
24+
case 4:
25+
*(u32 *)to = *(u32 __force *)from;
26+
return 0;
27+
}
28+
}
29+
30+
memcpy(to, (const void __force *)from, n);
31+
return 0;
32+
}
33+
34+
static inline __must_check unsigned long
35+
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
36+
{
37+
if (__builtin_constant_p(n)) {
38+
switch(n) {
39+
case 1:
40+
*(u8 __force *)to = *(u8 *)from;
41+
return 0;
42+
case 2:
43+
*(u16 __force *)to = *(u16 *)from;
44+
return 0;
45+
case 4:
46+
*(u32 __force *)to = *(u32 *)from;
47+
return 0;
48+
default:
49+
break;
50+
}
51+
}
52+
53+
memcpy((void __force *)to, from, n);
54+
return 0;
55+
}
56+
#define INLINE_COPY_FROM_USER
57+
#define INLINE_COPY_TO_USER
58+
#endif /* CONFIG_UACCESS_MEMCPY */
59+
1260
#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
1361

1462
#ifndef KERNEL_DS

‎lib/Kconfig‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,10 @@ config ARCH_NO_SG_CHAIN
591591
config ARCH_HAS_PMEM_API
592592
bool
593593

594+
# use memcpy to implement user copies for nommu architectures
595+
config UACCESS_MEMCPY
596+
bool
597+
594598
config ARCH_HAS_UACCESS_FLUSHCACHE
595599
bool
596600

0 commit comments

Comments
 (0)