unicore32 additional architecture files: low-level lib: uaccess
PATCH 5/12 unicore32 additional architecture files: low-level lib: uaccess
Message-Id: <2153a67890e24751c94029ef42e3a17c09249c8a.1297842537.git.gxt@mprc.pku.edu.cn>
In-Reply-To: <[email protected]>
References: <[email protected]>
From: GuanXuetao <[email protected]>
Date: Sat, 15 Jan 2011 18:22:46 +0800
This patch implements low-level uaccess libraries.
--- arch/unicore32/include/asm/uaccess.h | 47 +++++++ arch/unicore32/lib/clear_user.S | 57 +++++++++ arch/unicore32/lib/copy_from_user.S | 108 ++++++++++++++++ arch/unicore32/lib/copy_page.S | 39 ++++++ arch/unicore32/lib/copy_template.S | 214 ++++++++++++++++++++++++++++++++ arch/unicore32/lib/copy_to_user.S | 96 ++++++++++++++ arch/unicore32/lib/strncpy_from_user.S | 45 +++++++ arch/unicore32/lib/strnlen_user.S | 42 ++++++ 8 files changed, 648 insertions(+), 0 deletions(-) create mode 100644 arch/unicore32/include/asm/uaccess.h create mode 100644 arch/unicore32/lib/clear_user.S create mode 100644 arch/unicore32/lib/copy_from_user.S create mode 100644 arch/unicore32/lib/copy_page.S create mode 100644 arch/unicore32/lib/copy_template.S create mode 100644 arch/unicore32/lib/copy_to_user.S create mode 100644 arch/unicore32/lib/strncpy_from_user.S create mode 100644 arch/unicore32/lib/strnlen_user.S
arch/unicore32/include/asm/uaccess.h new file +47 -0
@@ -0,0 +1,47 @@ +/* +* linux/arch/unicore32/include/asm/uaccess.h +* +* Code specific to PKUnity SoC and UniCore ISA +* +* Copyright (C) 2001-2010 GUAN Xue-tao +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#ifndef __UNICORE_UACCESS_H__ +#define __UNICORE_UACCESS_H__ + +#include <linux/thread_info.h> +#include <linux/errno.h> + +#include <asm/memory.h> +#include <asm/system.h> + +#define __copy_from_user __copy_from_user +#define __copy_to_user __copy_to_user +#define __strncpy_from_user __strncpy_from_user +#define strnlen_user strnlen_user +#define __clear_user __clear_user + +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS)) +#define __user_ok (addr, size) (((size) <= TASK_SIZE) \ + && ((addr) <= TASK_SIZE - (size))) +#define __access_ok (addr, size) (__kernel_ok || __user_ok((addr), (size))) + +extern unsigned long __must_check +__copy_from_user (void *to,const void __user *from,unsigned long n); +extern unsigned long __must_check +__copy_to_user (void __user *to,const void *from,unsigned long n); +extern unsigned long __must_check +__clear_user (void __user *addr,unsigned long n); +extern unsigned long __must_check +__strncpy_from_user (char *to,const char __user *from,unsigned long count); +extern unsigned long +__strnlen_user (const char __user *s,long n); + +#include <asm-generic/uaccess.h> + +extern int fixup_exception (struct pt_regs *regs); + +#endif /* __UNICORE_UACCESS_H__ */
arch/unicore32/lib/clear_user.S new file +57 -0
57 lines not on this page · raw message
arch/unicore32/lib/copy_from_user.S new file +108 -0
108 lines not on this page · raw message
arch/unicore32/lib/copy_page.S new file +39 -0
@@ -0,0 +1,39 @@ +/* + * linux/arch/unicore32/lib/copy_page.S + * + * Code specific to PKUnity SoC and UniCore ISA + * + * Copyright (C) 2001-2010 GUAN Xue-tao + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * ASM optimised string functions + */ +#include <linux/linkage.h> +#include <asm/assembler.h> +#include <generated/asm-offsets.h> +#include <asm/cache.h> + +#define COPY_COUNT (PAGE_SZ/256) + + .text + .align 5 +/* + * UniCore optimised copy_page routine + */ +ENTRY(copy_page) + stm.w (r17 - r19, lr), [sp-] + mov r17, r0 + mov r18, r1 + mov r19, #COPY_COUNT +1: + .rept 4 + ldm.w (r0 - r15), [r18]+ + stm.w (r0 - r15), [r17]+ + .endr + sub.a r19, r19, #1 + bne 1b + ldm.w (r17 - r19, pc), [sp]+ +ENDPROC(copy_page)
arch/unicore32/lib/copy_template.S new file +214 -0
214 lines not on this page · raw message
arch/unicore32/lib/copy_to_user.S new file +96 -0
96 lines not on this page · raw message
arch/unicore32/lib/strncpy_from_user.S new file +45 -0
45 lines not on this page · raw message
arch/unicore32/lib/strnlen_user.S new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
1.6.2.2
Arnd Bergmann
maintainerarch/unicore32/include/asm/uaccess.h line 30
Quoted 5 lines · Guan Xuetao
arch/unicore32/include/asm/uaccess.h new file +5
-0+ +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS)) +#define __user_ok (addr, size) (((size) <= TASK_SIZE) \ + && ((addr) <= TASK_SIZE - (size))) +#define __access_ok (addr, size) (__kernel_ok || __user_ok((addr), (size)))
A nice trick to simplify this is to introduce a per-process variable for comparing the pointer, set_fs() then sets this variable to either TASK_SIZE or UINT_MAX.
This saves one conditional branch for each call to __access_ok.
Arnd
Quoted 10 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 1:45 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccessOn Wednesday 16 February 2011, Guan Xuetao wrote:
Quoted 9 lines
arch/unicore32/include/asm/uaccess.h line 30
Quoted 5 lines
arch/unicore32/include/asm/uaccess.h new file +5
-0+ +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS)) +#define __user_ok (addr, size) (((size) <= TASK_SIZE) \ + && ((addr) <= TASK_SIZE - (size))) +#define __access_ok (addr, size) (__kernel_ok || __user_ok((addr), (size)))A nice trick to simplify this is to introduce a per-process variable for comparing the pointer,
set_fs()then sets this variable to eitherTASK_SIZEorUINT_MAX.
Perhaps like this:
1. add a member named kaddr in thread_info
2. add following assignment codes in set_fs:
current_thread_info()->kaddr = segment_eq(fs, KERNEL_DS) ? UINT_MAX : TASK_SIZE;
3. then __access_ok will be:
#define addr
#define __access_ok(addr, size) (((size) <= TASK_SIZE) \
&& ((addr) <= current_thread_info()->kaddr) - (size)))Quoted 4 lines
This saves one conditional branch for each call to
__access_ok.Arnd
Arnd Bergmann
maintainerQuoted 18 lines · Guan Xuetao
Quoted 8 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 1:45 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccessOn Wednesday 16 February 2011, Guan Xuetao wrote:
Quoted 9 lines
arch/unicore32/include/asm/uaccess.h line 30
Quoted 5 lines
arch/unicore32/include/asm/uaccess.h new file +5
-0+ +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS)) +#define __user_ok (addr, size) (((size) <= TASK_SIZE) \ + && ((addr) <= TASK_SIZE - (size))) +#define __access_ok (addr, size) (__kernel_ok || __user_ok((addr), (size)))A nice trick to simplify this is to introduce a per-process variable for comparing the pointer,
set_fs()then sets this variable to eitherTASK_SIZEorUINT_MAX.
Quoted 8 lines
Perhaps like this:
1. add a member named kaddr inthread_info
2. add following assignment codes inset_fs:current_thread_info()->kaddr = segment_eq(fs, KERNEL_DS) ? UINT_MAX : TASK_SIZE; 3. then __access_ok will be: #define addr #define __access_ok(addr, size) (((size) <= TASK_SIZE) \ && ((addr) <= current_thread_info()->kaddr) - (size)))
That would also work. What I meant was to have
#define set_fs(fs) \
do { current_thread_info()->kaddr = (fs); } while (0)#define KERNEL_DS UINT_MAX
#define USER_DS TASK_SIZE
Either way is fine with me, just choose whichever works best for you in terms of code size.
Arnd
Quoted 39 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Monday, February 28, 2011 1:22 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccessQuoted 18 lines · Guan Xuetao
Quoted 8 lines
-----Original Message-----
From: Arnd Bergmann [mailto:[email protected]]
Sent: Friday, February 18, 2011 1:45 AM
To: Guan Xuetao
Cc: [email protected]; [email protected]; 'Greg KH'
Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccessOn Wednesday 16 February 2011, Guan Xuetao wrote:
Quoted 9 lines
arch/unicore32/include/asm/uaccess.h line 30
Quoted 5 lines
arch/unicore32/include/asm/uaccess.h new file +5
-0+ +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS)) +#define __user_ok (addr, size) (((size) <= TASK_SIZE) \ + && ((addr) <= TASK_SIZE - (size))) +#define __access_ok (addr, size) (__kernel_ok || __user_ok((addr), (size)))A nice trick to simplify this is to introduce a per-process variable for comparing the pointer,
set_fs()then sets this variable to eitherTASK_SIZEorUINT_MAX.Quoted 8 lines
Perhaps like this:
1. add a member named kaddr inthread_info
2. add following assignment codes inset_fs:current_thread_info()->kaddr = segment_eq(fs, KERNEL_DS) ? UINT_MAX : TASK_SIZE; 3. then __access_ok will be: #define addr #define __access_ok(addr, size) (((size) <= TASK_SIZE) \ && ((addr) <= current_thread_info()->kaddr) - (size)))That would also work. What I meant was to have
Quoted 7 lines
#define set_fs(fs) \ do { current_thread_info()->kaddr = (fs); } while (0)#define
KERNEL_DSUINT_MAX
#defineUSER_DSTASK_SIZEEither way is fine with me, just choose whichever works best for you in terms of code size.
I can't find the difference between this way and the way in asm-generic/uaccess.h. Perhaps, under this idea, __kernel_ok could be ignored.
Quoted 2 lines
Arnd
Thanks & Regards.
Guan Xuetao