Skip to content

Commit

Permalink
asm-generic: provide entirely generic nommu uaccess
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and arndb committed Apr 23, 2019
1 parent c67fdc1 commit bd79f94
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 55 deletions.
1 change: 1 addition & 0 deletions arch/h8300/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config H8300
select HAVE_ARCH_KGDB
select HAVE_ARCH_HASH
select CPU_NO_EFFICIENT_FFS
select UACCESS_MEMCPY

config CPU_BIG_ENDIAN
def_bool y
Expand Down
1 change: 1 addition & 0 deletions arch/h8300/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ generic-y += timex.h
generic-y += tlbflush.h
generic-y += topology.h
generic-y += trace_clock.h
generic-y += uaccess.h
generic-y += unaligned.h
generic-y += vga.h
generic-y += word-at-a-time.h
Expand Down
55 changes: 0 additions & 55 deletions arch/h8300/include/asm/uaccess.h

This file was deleted.

48 changes: 48 additions & 0 deletions include/asm-generic/uaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,54 @@
*/
#include <linux/string.h>

#ifdef CONFIG_UACCESS_MEMCPY
static inline __must_check unsigned long
raw_copy_from_user(void *to, const void __user * from, unsigned long n)
{
if (__builtin_constant_p(n)) {
switch(n) {
case 1:
*(u8 *)to = *(u8 __force *)from;
return 0;
case 2:
*(u16 *)to = *(u16 __force *)from;
return 0;
case 4:
*(u32 *)to = *(u32 __force *)from;
return 0;
}
}

memcpy(to, (const void __force *)from, n);
return 0;
}

static inline __must_check unsigned long
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
{
if (__builtin_constant_p(n)) {
switch(n) {
case 1:
*(u8 __force *)to = *(u8 *)from;
return 0;
case 2:
*(u16 __force *)to = *(u16 *)from;
return 0;
case 4:
*(u32 __force *)to = *(u32 *)from;
return 0;
default:
break;
}
}

memcpy((void __force *)to, from, n);
return 0;
}
#define INLINE_COPY_FROM_USER
#define INLINE_COPY_TO_USER
#endif /* CONFIG_UACCESS_MEMCPY */

#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })

#ifndef KERNEL_DS
Expand Down
4 changes: 4 additions & 0 deletions lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ config ARCH_NO_SG_CHAIN
config ARCH_HAS_PMEM_API
bool

# use memcpy to implement user copies for nommu architectures
config UACCESS_MEMCPY
bool

config ARCH_HAS_UACCESS_FLUSHCACHE
bool

Expand Down

0 comments on commit bd79f94

Please sign in to comment.