* gcc 3.3.4/3.4.1 and get_user
@ 2004-08-31 16:22 Atsushi Nemoto
2004-09-01 8:51 ` Richard Sandiford
0 siblings, 1 reply; 13+ messages in thread
From: Atsushi Nemoto @ 2004-08-31 16:22 UTC (permalink / raw)
To: linux-mips
I found that gcc 3.3.4/3.4.1 can not compile this sample code properly.
--- k.c ---
/* mips-linux-gcc -D__KERNEL__ -O2 -mno-abicalls -fno-pic -I $(KERNEL)/include -S k.c */
#include <asm/uaccess.h>
extern char ptr[];
static int func0(int arg0)
{
return 0;
}
int func1(int *arg)
{
int arg0 = arg[0];
int arg1;
if (arg0)
return -1;
arg0 = func0(0);
get_user(arg1 , (int*)arg[1]);
if (func0(ptr[arg0]))
return 0;
if (arg1)
ptr[arg0] = 0;
return 0;
}
--- k.c end ---
The codes around the first calling of func0 are:
.set noreorder
.set nomacro
jal func0
.set macro
.set reorder
lw $4,4($16)
The jal does not have delay slot. Then "lw $4" (part of get_user)
executed as the delay slot instruction.
I create a sample code with very stripped version of get_user.
--- kk.c ---
/* mips-linux-gcc -O2 -mno-abicalls -fno-pic -S kk.c */
#define get_user(x,ptr) \
{ \
int __gu_val; \
__asm__ ("":"=r" (__gu_val)); \
if (ptr) { \
__asm__ __volatile__( \
"\tlw\t%0,%1\n\t" \
:"=r" (__gu_val) \
:"o" (*(ptr))); \
} \
(x) = __gu_val; \
}
extern char ptr[];
static int func0(int arg0)
{
return 0;
}
int func1(int *arg)
{
int arg0 = arg[0];
int arg1;
if (arg0)
return -1;
arg0 = func0(0);
get_user(arg1 , (int*)arg[1]);
if (func0(ptr[arg0]))
return 0;
if (arg1)
ptr[arg0] = 0;
return 0;
}
--- kk.c end ---
And complete output of gcc 3.3.4:
.file 1 "kk.c"
.section .mdebug.abi32
.previous
.text
.align 2
.ent func0
.type func0, @function
func0:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
j $31
move $2,$0
.set macro
.set reorder
.end func0
.align 2
.globl func1
.ent func1
.type func1, @function
func1:
.frame $sp,32,$31 # vars= 0, regs= 3/0, args= 16, extra= 0
.mask 0x80030000,-8
.fmask 0x00000000,0
subu $sp,$sp,32
sw $16,16($sp)
sw $31,24($sp)
move $16,$4
sw $17,20($sp)
lw $2,0($16)
move $4,$0
.set noreorder
.set nomacro
bne $2,$0,$L2
li $3,-1 # 0xffffffffffffffff
.set macro
.set reorder
.set noreorder
.set nomacro
jal func0
.set macro
.set reorder
lw $4,4($16)
#nop
beq $4,$0,$L4
#APP
lw $17,0($4)
#NO_APP
$L4:
la $16,ptr($2)
lb $4,0($16)
jal func0
.set noreorder
.set nomacro
bne $2,$0,$L2
move $3,$0
.set macro
.set reorder
beq $17,$0,$L2
sb $0,0($16)
$L2:
lw $31,24($sp)
lw $17,20($sp)
lw $16,16($sp)
move $2,$3
.set noreorder
.set nomacro
j $31
addu $sp,$sp,32
.set macro
.set reorder
.end func1
.ident "GCC: (GNU) 3.3.4"
Also complete output of gcc 3.4.1:
.file 1 "kk.c"
.section .mdebug.abi32
.previous
.text
.align 2
.ent func0
.type func0, @function
func0:
.frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, gp= 0
.mask 0x00000000,0
.fmask 0x00000000,0
.set noreorder
.set nomacro
j $31
move $2,$0
.set macro
.set reorder
.end func0
.align 2
.globl func1
.ent func1
.type func1, @function
func1:
.frame $sp,32,$31 # vars= 0, regs= 3/0, args= 16, gp= 0
.mask 0x80030000,-8
.fmask 0x00000000,0
addiu $sp,$sp,-32
sw $16,16($sp)
sw $31,24($sp)
move $16,$4
sw $17,20($sp)
lw $3,0($16)
move $4,$0
.set noreorder
.set nomacro
bne $3,$0,$L2
li $5,-1 # 0xffffffffffffffff
.set macro
.set reorder
.set noreorder
.set nomacro
jal func0
.set macro
.set reorder
lw $4,4($16)
#nop
.set noreorder
.set nomacro
bne $4,$0,$L8
move $3,$2
.set macro
.set reorder
lui $2,%hi(ptr)
$L9:
addiu $2,$2,%lo(ptr)
addu $16,$3,$2
lb $4,0($16)
jal func0
.set noreorder
.set nomacro
bne $2,$0,$L2
move $5,$0
.set macro
.set reorder
beq $17,$0,$L2
sb $0,0($16)
$L2:
lw $31,24($sp)
lw $17,20($sp)
lw $16,16($sp)
move $2,$5
.set noreorder
.set nomacro
j $31
addiu $sp,$sp,32
.set macro
.set reorder
$L8:
#APP
lw $17,0($4)
#NO_APP
.set noreorder
.set nomacro
j $L9
lui $2,%hi(ptr)
.set macro
.set reorder
.end func1
.ident "GCC: (GNU) 3.4.1"
Is this a get_user's problem or gcc's?
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-08-31 16:22 gcc 3.3.4/3.4.1 and get_user Atsushi Nemoto
@ 2004-09-01 8:51 ` Richard Sandiford
2004-09-01 15:14 ` Atsushi Nemoto
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Richard Sandiford @ 2004-09-01 8:51 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-mips
Atsushi Nemoto <anemo@mba.ocn.ne.jp> writes:
> Is this a get_user's problem or gcc's?
The latter. gcc is putting the empty asm:
__asm__ ("":"=r" (__gu_val));
into the delay slot of the call.
Part of the problem is that gcc estimates the length of an asm to be the
number of instruction separators + 1. This means that it estimates the
asm above to be one instruction long, which is perhaps a little silly
for an empty string.
But the real problem is that gcc should never trust this estimate anyway,
since each "instruction" could obviously be a multi-instruction macro.
gcc should certainly never put asms into delay slots.
FWIW, I don't think the bug is specific to 3.3 or 3.4. It could
probably trigger for other gcc versions too. It is highly dependent
on scheduling though.
The attached 3.4.x patch fixes the problem there, but if you want to work
around it for old versions, just avoid using empty asms if you can,
or make them volatile if you can't.
Of course, the problem isn't confined to empty asms. If you have an asm
with a single, multi-instruction macro, gcc might try putting that in a
delay slot too. You should at least get an assembler warning in that case.
Richard
Index: config/mips/mips.md
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/mips/mips.md,v
retrieving revision 1.211.4.7
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.211.4.7 mips.md
--- config/mips/mips.md 25 Jun 2004 07:35:30 -0000 1.211.4.7
+++ config/mips/mips.md 1 Sep 2004 08:26:02 -0000
@@ -251,7 +251,7 @@ (define_attr "single_insn" "no,yes"
;; Can the instruction be put into a delay slot?
(define_attr "can_delay" "no,yes"
- (if_then_else (and (eq_attr "type" "!branch,call,jump")
+ (if_then_else (and (eq_attr "type" "!branch,call,jump,multi")
(and (eq_attr "hazard" "none")
(eq_attr "single_insn" "yes")))
(const_string "yes")
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-01 8:51 ` Richard Sandiford
@ 2004-09-01 15:14 ` Atsushi Nemoto
2004-09-01 15:16 ` Atsushi Nemoto
2004-09-20 8:59 ` Richard Sandiford
2004-09-20 15:40 ` Ralf Baechle
2 siblings, 1 reply; 13+ messages in thread
From: Atsushi Nemoto @ 2004-09-01 15:14 UTC (permalink / raw)
To: rsandifo; +Cc: linux-mips
>>>>> On Wed, 01 Sep 2004 09:51:16 +0100, Richard Sandiford <rsandifo@redhat.com> said:
>> Is this a get_user's problem or gcc's?
rsandifo> The latter. gcc is putting the empty asm:
rsandifo> __asm__ ("":"=r" (__gu_val));
rsandifo> into the delay slot of the call.
Thank you for the detailed explanation.
rsandifo> FWIW, I don't think the bug is specific to 3.3 or 3.4. It
rsandifo> could probably trigger for other gcc versions too. It is
rsandifo> highly dependent on scheduling though.
Yes, this problem was originally found on gcc 3.2.
rsandifo> The attached 3.4.x patch fixes the problem there, but if you
rsandifo> want to work around it for old versions, just avoid using
rsandifo> empty asms if you can, or make them volatile if you can't.
Thank you. I create a patch for kernel with this workaround.
# This patch assumes gcc 3.5 will be free from this problem :-)
Could you apply, Ralf?
diff -u linux-mips-cvs/include/asm-mips/paccess.h linux-mips/include/asm-mips/paccess.h
--- linux-mips-cvs/include/asm-mips/paccess.h Mon Nov 24 20:22:01 2003
+++ linux-mips/include/asm-mips/paccess.h Wed Sep 1 22:49:30 2004
@@ -15,6 +15,7 @@
#include <linux/config.h>
#include <linux/errno.h>
+#include <asm/war.h>
#ifdef CONFIG_MIPS32
#define __PA_ADDR ".word"
@@ -37,7 +38,7 @@
long __gu_err; \
__typeof(*(ptr)) __gu_val; \
unsigned long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (unsigned long) (ptr); \
__asm__("":"=r" (__gu_err)); \
switch (size) { \
@@ -78,7 +79,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_dbe_asm("sb"); break; \
case 2: __put_dbe_asm("sh"); break; \
diff -u linux-mips-cvs/include/asm-mips/uaccess.h linux-mips/include/asm-mips/uaccess.h
--- linux-mips-cvs/include/asm-mips/uaccess.h Wed Mar 31 20:21:59 2004
+++ linux-mips/include/asm-mips/uaccess.h Wed Sep 1 23:24:15 2004
@@ -13,6 +13,7 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/thread_info.h>
+#include <asm/war.h>
/*
* The fs value determines whether argument validity checking should be
@@ -235,9 +236,9 @@
__typeof(*(ptr)) __gu_val; \
long __gu_addr; \
might_sleep(); \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
case 2: __get_user_asm("lh"); break; \
@@ -253,9 +254,9 @@
__typeof__(*(ptr)) __gu_val; \
long __gu_addr; \
might_sleep(); \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
if (access_ok(VERIFY_READ,__gu_addr,size)) { \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
@@ -329,7 +330,7 @@
might_sleep(); \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
case 2: __put_user_asm("sh"); break; \
@@ -348,7 +349,7 @@
might_sleep(); \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
diff -u linux-mips-cvs/include/asm-mips/war.h linux-mips/include/asm-mips/war.h
--- linux-mips-cvs/include/asm-mips/war.h Sat Aug 21 00:34:12 2004
+++ linux-mips/include/asm-mips/war.h Wed Sep 1 23:22:29 2004
@@ -221,4 +221,10 @@
#define R10000_LLSC_WAR 0
#endif
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 4))
+#define GCC_ASM_PROTECT_DSLOT
+#else
+#define GCC_ASM_PROTECT_DSLOT __volatile__
+#endif
+
#endif /* _ASM_WAR_H */
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-01 15:14 ` Atsushi Nemoto
@ 2004-09-01 15:16 ` Atsushi Nemoto
0 siblings, 0 replies; 13+ messages in thread
From: Atsushi Nemoto @ 2004-09-01 15:16 UTC (permalink / raw)
To: rsandifo; +Cc: linux-mips
>>>>> On Thu, 02 Sep 2004 00:14:33 +0900 (JST), Atsushi Nemoto <anemo@mba.ocn.ne.jp> said:
anemo> Thank you. I create a patch for kernel with this workaround.
anemo> # This patch assumes gcc 3.5 will be free from this problem :-)
anemo> Could you apply, Ralf?
And this is for 2.4 tree.
diff -u linux-mips-2.4-cvs/include/asm-mips/paccess.h linux-mips-2.4/include/asm-mips/paccess.h
--- linux-mips-2.4-cvs/include/asm-mips/paccess.h Tue Nov 11 21:49:34 2003
+++ linux-mips-2.4/include/asm-mips/paccess.h Wed Sep 1 23:21:41 2004
@@ -14,6 +14,7 @@
#define _ASM_PACCESS_H
#include <linux/errno.h>
+#include <asm/war.h>
#define put_dbe(x,ptr) __put_dbe((x),(ptr),sizeof(*(ptr)))
#define get_dbe(x,ptr) __get_dbe((x),(ptr),sizeof(*(ptr)))
@@ -25,7 +26,7 @@
int __gu_err; \
__typeof(*(ptr)) __gu_val; \
unsigned long __gu_addr; \
-__asm__("":"=r" (__gu_val)); \
+__asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (unsigned long) (ptr); \
__asm__("":"=r" (__gu_err)); \
switch (size) { \
@@ -64,7 +65,7 @@
unsigned long __pu_addr; \
__pu_val = (x); \
__pu_addr = (unsigned long) (ptr); \
-__asm__("":"=r" (__pu_err)); \
+__asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_dbe_asm("sb"); break; \
case 2: __put_dbe_asm("sh"); break; \
diff -u linux-mips-2.4-cvs/include/asm-mips/uaccess.h linux-mips-2.4/include/asm-mips/uaccess.h
--- linux-mips-2.4-cvs/include/asm-mips/uaccess.h Mon Sep 15 10:28:51 2003
+++ linux-mips-2.4/include/asm-mips/uaccess.h Wed Sep 1 23:24:00 2004
@@ -12,6 +12,7 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/sched.h>
+#include <asm/war.h>
#define STR(x) __STR(x)
#define __STR(x) #x
@@ -200,9 +201,9 @@
long __gu_err; \
__typeof(*(ptr)) __gu_val; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
case 2: __get_user_asm("lh"); break; \
@@ -218,9 +219,9 @@
long __gu_err; \
__typeof__(*(ptr)) __gu_val; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
if (access_ok(VERIFY_READ, __gu_addr, size)) { \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
@@ -294,7 +295,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
case 2: __put_user_asm("sh"); break; \
@@ -312,7 +313,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
diff -u linux-mips-2.4-cvs/include/asm-mips/war.h linux-mips-2.4/include/asm-mips/war.h
--- linux-mips-2.4-cvs/include/asm-mips/war.h Mon Mar 8 20:21:39 2004
+++ linux-mips-2.4/include/asm-mips/war.h Wed Sep 1 23:23:04 2004
@@ -210,4 +210,10 @@
#define RM9000_CDEX_SMP_WAR 0
#endif
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 4))
+#define GCC_ASM_PROTECT_DSLOT
+#else
+#define GCC_ASM_PROTECT_DSLOT __volatile__
+#endif
+
#endif /* _ASM_WAR_H */
diff -u linux-mips-2.4-cvs/include/asm-mips64/paccess.h linux-mips-2.4/include/asm-mips64/paccess.h
--- linux-mips-2.4-cvs/include/asm-mips64/paccess.h Mon Jul 9 09:25:38 2001
+++ linux-mips-2.4/include/asm-mips64/paccess.h Wed Sep 1 23:21:41 2004
@@ -14,6 +14,7 @@
#define _ASM_PACCESS_H
#include <linux/errno.h>
+#include <asm/war.h>
#define put_dbe(x,ptr) __put_dbe((x),(ptr),sizeof(*(ptr)))
#define get_dbe(x,ptr) __get_dbe((x),(ptr),sizeof(*(ptr)))
@@ -25,7 +26,7 @@
long __gu_err; \
__typeof(*(ptr)) __gu_val; \
long __gu_addr; \
-__asm__("":"=r" (__gu_val)); \
+__asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
__asm__("":"=r" (__gu_err)); \
switch (size) { \
@@ -61,7 +62,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
-__asm__("":"=r" (__pu_err)); \
+__asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_dbe_asm("sb"); break; \
case 2: __put_dbe_asm("sh"); break; \
diff -u linux-mips-2.4-cvs/include/asm-mips64/uaccess.h linux-mips-2.4/include/asm-mips64/uaccess.h
--- linux-mips-2.4-cvs/include/asm-mips64/uaccess.h Wed Sep 17 23:22:35 2003
+++ linux-mips-2.4/include/asm-mips64/uaccess.h Wed Sep 1 23:23:35 2004
@@ -12,6 +12,7 @@
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/sched.h>
+#include <asm/war.h>
#define STR(x) __STR(x)
#define __STR(x) #x
@@ -190,9 +191,9 @@
long __gu_err; \
__typeof(*(ptr)) __gu_val; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
case 2: __get_user_asm("lh"); break; \
@@ -208,9 +209,9 @@
long __gu_err; \
__typeof__(*(ptr)) __gu_val; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__gu_err)); \
if (access_ok(VERIFY_READ, __gu_addr, size)) { \
switch (size) { \
case 1: __get_user_asm("lb"); break; \
@@ -250,7 +251,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
case 2: __put_user_asm("sh"); break; \
@@ -268,7 +269,7 @@
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
+ __asm__ GCC_ASM_PROTECT_DSLOT ("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
case 1: __put_user_asm("sb"); break; \
diff -u linux-mips-2.4-cvs/include/asm-mips64/war.h linux-mips-2.4/include/asm-mips64/war.h
--- linux-mips-2.4-cvs/include/asm-mips64/war.h Mon Mar 8 20:21:39 2004
+++ linux-mips-2.4/include/asm-mips64/war.h Wed Sep 1 23:23:12 2004
@@ -210,4 +210,10 @@
#define RM9000_CDEX_SMP_WAR 0
#endif
+#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 4))
+#define GCC_ASM_PROTECT_DSLOT
+#else
+#define GCC_ASM_PROTECT_DSLOT __volatile__
+#endif
+
#endif /* _ASM_WAR_H */
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-01 8:51 ` Richard Sandiford
2004-09-01 15:14 ` Atsushi Nemoto
@ 2004-09-20 8:59 ` Richard Sandiford
2004-09-20 14:18 ` Atsushi Nemoto
2004-09-20 15:40 ` Ralf Baechle
2 siblings, 1 reply; 13+ messages in thread
From: Richard Sandiford @ 2004-09-20 8:59 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-mips
Richard Sandiford <rsandifo@redhat.com> writes:
> Atsushi Nemoto <anemo@mba.ocn.ne.jp> writes:
>> Is this a get_user's problem or gcc's?
>
> The latter. gcc is putting the empty asm:
>
> __asm__ ("":"=r" (__gu_val));
>
> into the delay slot of the call.
FYI, this is now being tracked as gcc bugzilla PR 17565:
http://gcc.gnu.org/PR17565
The fix has so far been applied to 4.0.
Richard
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-20 8:59 ` Richard Sandiford
@ 2004-09-20 14:18 ` Atsushi Nemoto
0 siblings, 0 replies; 13+ messages in thread
From: Atsushi Nemoto @ 2004-09-20 14:18 UTC (permalink / raw)
To: rsandifo; +Cc: linux-mips
>>>>> On Mon, 20 Sep 2004 09:59:28 +0100, Richard Sandiford <rsandifo@redhat.com> said:
rsandifo> FYI, this is now being tracked as gcc bugzilla PR 17565:
rsandifo> http://gcc.gnu.org/PR17565
rsandifo> The fix has so far been applied to 4.0.
Thank you. I tried the fix on gcc 3.3.4 and it works fine.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-01 8:51 ` Richard Sandiford
2004-09-01 15:14 ` Atsushi Nemoto
2004-09-20 8:59 ` Richard Sandiford
@ 2004-09-20 15:40 ` Ralf Baechle
2004-09-20 17:10 ` Ralf Baechle
2004-09-24 3:18 ` Atsushi Nemoto
2 siblings, 2 replies; 13+ messages in thread
From: Ralf Baechle @ 2004-09-20 15:40 UTC (permalink / raw)
To: Richard Sandiford; +Cc: Atsushi Nemoto, linux-mips
On Wed, Sep 01, 2004 at 09:51:16AM +0100, Richard Sandiford wrote:
> The latter. gcc is putting the empty asm:
>
> __asm__ ("":"=r" (__gu_val));
>
> into the delay slot of the call.
The purpose of this was to avoid a warning about __gu_val possibly being
used uninitialized without inflating the code. I've got a better solution
that'll actually shrinks the code size of my defconfig build by 5448
bytes. Untested patch below.
Ralf
Index: include/asm-mips/uaccess.h
===================================================================
RCS file: /home/cvs/linux/include/asm-mips/uaccess.h,v
retrieving revision 1.35
diff -u -r1.35 uaccess.h
--- include/asm-mips/uaccess.h 19 Sep 2004 12:30:20 -0000 1.35
+++ include/asm-mips/uaccess.h 20 Sep 2004 12:33:27 -0000
@@ -225,88 +225,86 @@
* for 32 bit mode and old iron.
*/
#ifdef __mips64
-#define __GET_USER_DW __get_user_asm("ld")
+#define __GET_USER_DW(__gu_err) __get_user_asm("ld", __gu_err)
#else
-#define __GET_USER_DW __get_user_asm_ll32
+#define __GET_USER_DW(__gu_err) __get_user_asm_ll32(__gu_err)
#endif
-#define __get_user_nocheck(x,ptr,size) \
-({ \
- long __gu_err; \
- __typeof(*(ptr)) __gu_val; \
- long __gu_addr; \
- might_sleep(); \
- __asm__("":"=r" (__gu_val)); \
- __gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
- switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __GET_USER_DW; break; \
- default: __get_user_unknown(); break; \
- } x = (__typeof__(*(ptr))) __gu_val; __gu_err; \
+#define __get_user_nocheck(x,ptr,size) \
+({ \
+ long __gu_err = 0; \
+ __typeof(*(ptr)) __gu_val = 0; \
+ long __gu_addr; \
+ might_sleep(); \
+ __gu_addr = (long) (ptr); \
+ switch (size) { \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
+ default: __get_user_unknown(); break; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
})
#define __get_user_check(x,ptr,size) \
({ \
- long __gu_err; \
- __typeof__(*(ptr)) __gu_val; \
+ long __gu_err = 0; \
+ __typeof__(*(ptr)) __gu_val = 0; \
long __gu_addr; \
might_sleep(); \
- __asm__("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
if (access_ok(VERIFY_READ,__gu_addr,size)) { \
switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __GET_USER_DW; break; \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
default: __get_user_unknown(); break; \
} \
- } x = (__typeof__(*(ptr))) __gu_val; __gu_err; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
})
-#define __get_user_asm(insn) \
+#define __get_user_asm(insn,__gu_err) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%1,%2\n\t" \
- "move\t%0,$0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0,%3\n\t" \
- "move\t%1,$0\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- __UA_ADDR "\t1b,3b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=r" (__gu_val) \
- :"o" (__m(__gu_addr)), "i" (-EFAULT)); \
+ "1: " insn " %1, %3 \n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0, %4 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " "__UA_ADDR "\t1b, 3b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=r" (__gu_val) \
+ : "0" (__gu_err), "o" (__m(__gu_addr)), "i" (-EFAULT)); \
})
/*
* Get a long long 64 using 32 bit registers.
*/
-#define __get_user_asm_ll32 \
+#define __get_user_asm_ll32(__gu_err) \
({ \
__asm__ __volatile__( \
- "1:\tlw\t%1,%2\n" \
- "2:\tlw\t%D1,%3\n\t" \
- "move\t%0,$0\n" \
- "3:\t.section\t.fixup,\"ax\"\n" \
- "4:\tli\t%0,%4\n\t" \
- "move\t%1,$0\n\t" \
- "move\t%D1,$0\n\t" \
- "j\t3b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- __UA_ADDR "\t1b,4b\n\t" \
- __UA_ADDR "\t2b,4b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=&r" (__gu_val) \
- :"o" (__m(__gu_addr)), "o" (__m(__gu_addr + 4)), \
+ "1: lw %1,%2 \n" \
+ "2: lw %D1,%3 \n" \
+ " move %0,$0 \n" \
+ "3: .section .fixup,\"ax\" \n" \
+ "4: li %0,%4 \n" \
+ " move %1,$0 \n" \
+ " move %D1,$0 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b,4b \n" \
+ " " __UA_ADDR " 2b,4b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=&r" (__gu_val) \
+ : "o" (__m(__gu_addr)), "o" (__m(__gu_addr + 4)), \
"i" (-EFAULT)); \
})
@@ -317,25 +315,24 @@
* for 32 bit mode and old iron.
*/
#ifdef __mips64
-#define __PUT_USER_DW __put_user_asm("sd")
+#define __PUT_USER_DW(__pu_val) __put_user_asm("sd", __pu_val)
#else
-#define __PUT_USER_DW __put_user_asm_ll32
+#define __PUT_USER_DW(__pu_val) __put_user_asm_ll32(__pu_val)
#endif
#define __put_user_nocheck(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
might_sleep(); \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __PUT_USER_DW; break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
default: __put_user_unknown(); break; \
} \
__pu_err; \
@@ -343,57 +340,55 @@
#define __put_user_check(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
might_sleep(); \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __PUT_USER_DW; break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
default: __put_user_unknown(); break; \
} \
} \
__pu_err; \
})
-#define __put_user_asm(insn) \
+#define __put_user_asm(insn, __pu_val) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%z1, %2\t\t\t# __put_user_asm\n\t" \
- "move\t%0, $0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0,%3\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- __UA_ADDR "\t1b,3b\n\t" \
- ".previous" \
+ "1: " insn " %z1, %2 # __put_user_asm\n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0,%3 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 3b \n" \
+ " .previous \n" \
:"=r" (__pu_err) \
:"Jr" (__pu_val), "o" (__m(__pu_addr)), "i" (-EFAULT)); \
})
-#define __put_user_asm_ll32 \
+#define __put_user_asm_ll32(__pu_val) \
({ \
__asm__ __volatile__( \
- "1:\tsw\t%1, %2\t\t\t# __put_user_asm_ll32\n\t" \
- "2:\tsw\t%D1, %3\n" \
- "move\t%0, $0\n" \
- "3:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "4:\tli\t%0,%4\n\t" \
- "j\t3b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- __UA_ADDR "\t1b,4b\n\t" \
- __UA_ADDR "\t2b,4b\n\t" \
- ".previous" \
+ "1: sw %1, %2 # __put_user_asm_ll32 \n" \
+ "2: sw %D1, %3 \n" \
+ " move %0, $0 \n" \
+ "3: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "4: li %0, %4 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 4b \n" \
+ " " __UA_ADDR " 2b, 4b \n" \
+ " .previous" \
:"=r" (__pu_err) \
:"r" (__pu_val), "o" (__m(__pu_addr)), \
"o" (__m(__pu_addr + 4)), "i" (-EFAULT)); \
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-20 15:40 ` Ralf Baechle
@ 2004-09-20 17:10 ` Ralf Baechle
2004-09-24 7:39 ` Atsushi Nemoto
2004-11-04 6:37 ` Atsushi Nemoto
2004-09-24 3:18 ` Atsushi Nemoto
1 sibling, 2 replies; 13+ messages in thread
From: Ralf Baechle @ 2004-09-20 17:10 UTC (permalink / raw)
To: Richard Sandiford; +Cc: Atsushi Nemoto, linux-mips
On Mon, Sep 20, 2004 at 05:40:42PM +0200, Ralf Baechle wrote:
> The purpose of this was to avoid a warning about __gu_val possibly being
> used uninitialized without inflating the code. I've got a better solution
> that'll actually shrinks the code size of my defconfig build by 5448
> bytes. Untested patch below.
And here the same for 2.4. Actually this is a straight backport of the
2.6 uaccess.h to 2.4 so with this patch include/asm-mips/uaccess.h and
include/asm-mips64/uaccess.h are going to be identical.
Ralf
Index: include/asm-mips/uaccess.h
===================================================================
RCS file: /home/cvs/linux/include/asm-mips/uaccess.h,v
retrieving revision 1.19.2.2
diff -u -r1.19.2.2 uaccess.h
--- include/asm-mips/uaccess.h 14 Sep 2003 20:55:20 -0000 1.19.2.2
+++ include/asm-mips/uaccess.h 20 Sep 2004 17:04:42 -0000
@@ -3,19 +3,17 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
- * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03 by Ralf Baechle
+ * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
*/
#ifndef _ASM_UACCESS_H
#define _ASM_UACCESS_H
+#include <linux/config.h>
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/sched.h>
-#define STR(x) __STR(x)
-#define __STR(x) #x
-
/*
* The fs value determines whether argument validity checking should be
* performed or not. If get_fs() == USER_DS, checking is performed, with
@@ -23,15 +21,47 @@
*
* For historical reasons, these macros are grossly misnamed.
*/
-#define KERNEL_DS ((mm_segment_t) { (unsigned long) 0L })
-#define USER_DS ((mm_segment_t) { (unsigned long) -1L })
+#ifdef CONFIG_MIPS32
+
+#define __UA_LIMIT 0x80000000UL
+
+#define __UA_ADDR ".word"
+#define __UA_LA "la"
+#define __UA_ADDU "addu"
+#define __UA_t0 "$8"
+#define __UA_t1 "$9"
+
+#endif /* CONFIG_MIPS32 */
+
+#ifdef CONFIG_MIPS64
+
+#define __UA_LIMIT (- TASK_SIZE)
+
+#define __UA_ADDR ".dword"
+#define __UA_LA "dla"
+#define __UA_ADDU "daddu"
+#define __UA_t0 "$12"
+#define __UA_t1 "$13"
+
+#endif /* CONFIG_MIPS64 */
+
+/*
+ * USER_DS is a bitmask that has the bits set that may not be set in a valid
+ * userspace address. Note that we limit 32-bit userspace to 0x7fff8000 but
+ * the arithmetic we're doing only works if the limit is a power of two, so
+ * we use 0x80000000 here on 32-bit kernels. If a process passes an invalid
+ * address in this range it's the process's problem, not ours :-)
+ */
+
+#define KERNEL_DS ((mm_segment_t) { 0UL })
+#define USER_DS ((mm_segment_t) { __UA_LIMIT })
#define VERIFY_READ 0
#define VERIFY_WRITE 1
-#define get_fs() (current->thread.current_ds)
#define get_ds() (KERNEL_DS)
-#define set_fs(x) (current->thread.current_ds=(x))
+#define get_fs() (current->thread.current_ds)
+#define set_fs(x) (current->thread.current_ds = (x))
#define segment_eq(a,b) ((a).seg == (b).seg)
@@ -45,14 +75,12 @@
* - AND "size" doesn't have any high-bits set
* - AND "addr+size" doesn't have any high-bits set
* - OR we are in kernel mode.
+ *
+ * __ua_size() is a trick to avoid runtime checking of positive constant
+ * sizes; for those we already know at compile time that the size is ok.
*/
#define __ua_size(size) \
- (__builtin_constant_p(size) && (signed long) (size) > 0 ? 0 : (size))
-
-#define __access_ok(addr,size,mask) \
- (((signed long)((mask)&(addr | (addr + size) | __ua_size(size)))) >= 0)
-
-#define __access_mask ((long)(get_fs().seg))
+ ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))
/*
* access_ok: - Checks if a user space pointer is valid
@@ -73,8 +101,14 @@
* checks that the pointer is in the user space range - after calling
* this function, memory access functions may still return -EFAULT.
*/
+
+#define __access_mask get_fs().seg
+
+#define __access_ok(addr, size, mask) \
+ (((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0)
+
#define access_ok(type, addr, size) \
- likely(__access_ok((unsigned long)(addr), (size), __access_mask))
+ likely(__access_ok((unsigned long)(addr), (size),__access_mask))
/*
* verify_area: - Obsolete, use access_ok()
@@ -190,88 +224,84 @@
* for 32 bit mode and old iron.
*/
#ifdef __mips64
-#define __GET_USER_DW __get_user_asm("ld")
+#define __GET_USER_DW(__gu_err) __get_user_asm("ld", __gu_err)
#else
-#define __GET_USER_DW __get_user_asm_ll32
+#define __GET_USER_DW(__gu_err) __get_user_asm_ll32(__gu_err)
#endif
#define __get_user_nocheck(x,ptr,size) \
({ \
- long __gu_err; \
- __typeof(*(ptr)) __gu_val; \
+ long __gu_err = 0; \
+ __typeof(*(ptr)) __gu_val = 0; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __GET_USER_DW; break; \
- default: __get_user_unknown(); break; \
- } x = (__typeof__(*(ptr))) __gu_val; \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
+ default: __get_user_unknown(); break; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
__gu_err; \
})
#define __get_user_check(x,ptr,size) \
({ \
- long __gu_err; \
- __typeof__(*(ptr)) __gu_val; \
+ long __gu_err = 0; \
+ __typeof__(*(ptr)) __gu_val = 0; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
- if (access_ok(VERIFY_READ, __gu_addr, size)) { \
+ if (access_ok(VERIFY_READ,__gu_addr,size)) { \
switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __GET_USER_DW; break; \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
default: __get_user_unknown(); break; \
} \
- } x = (__typeof__(*(ptr))) __gu_val; \
- __gu_err; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
})
-#define __get_user_asm(insn) \
+#define __get_user_asm(insn,__gu_err) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%1,%2\n\t" \
- "move\t%0,$0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0,%3\n\t" \
- "move\t%1,$0\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".word\t1b,3b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=r" (__gu_val) \
- :"o" (__m(__gu_addr)), "i" (-EFAULT)); \
+ "1: " insn " %1, %3 \n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0, %4 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " "__UA_ADDR "\t1b, 3b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=r" (__gu_val) \
+ : "0" (__gu_err), "o" (__m(__gu_addr)), "i" (-EFAULT)); \
})
/*
* Get a long long 64 using 32 bit registers.
*/
-#define __get_user_asm_ll32 \
+#define __get_user_asm_ll32(__gu_err) \
({ \
-__asm__ __volatile__( \
- "1:\tlw\t%1,%2\n" \
- "2:\tlw\t%D1,%3\n\t" \
- "move\t%0,$0\n" \
- "3:\t.section\t.fixup,\"ax\"\n" \
- "4:\tli\t%0,%4\n\t" \
- "move\t%1,$0\n\t" \
- "move\t%D1,$0\n\t" \
- "j\t3b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".word\t1b,4b\n\t" \
- ".word\t2b,4b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=&r" (__gu_val) \
- :"o" (__m(__gu_addr)), "o" (__m(__gu_addr + 4)), \
+ __asm__ __volatile__( \
+ "1: lw %1,%2 \n" \
+ "2: lw %D1,%3 \n" \
+ " move %0,$0 \n" \
+ "3: .section .fixup,\"ax\" \n" \
+ "4: li %0,%4 \n" \
+ " move %1,$0 \n" \
+ " move %D1,$0 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b,4b \n" \
+ " " __UA_ADDR " 2b,4b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=&r" (__gu_val) \
+ : "o" (__m(__gu_addr)), "o" (__m(__gu_addr + 4)), \
"i" (-EFAULT)); \
})
@@ -282,84 +312,81 @@
* for 32 bit mode and old iron.
*/
#ifdef __mips64
-#define __PUT_USER_DW __put_user_asm("sd")
+#define __PUT_USER_DW(__pu_val) __put_user_asm("sd", __pu_val)
#else
-#define __PUT_USER_DW __put_user_asm_ll32
+#define __PUT_USER_DW(__pu_val) __put_user_asm_ll32(__pu_val)
#endif
#define __put_user_nocheck(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __PUT_USER_DW; break; \
- default: __put_user_unknown(); break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
+ default: __put_user_unknown(); break; \
} \
__pu_err; \
})
#define __put_user_check(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __PUT_USER_DW; break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
default: __put_user_unknown(); break; \
} \
} \
__pu_err; \
})
-#define __put_user_asm(insn) \
+#define __put_user_asm(insn, __pu_val) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%z1, %2\t\t\t# __put_user_asm\n\t" \
- "move\t%0, $0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0, %3\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".word\t1b, 3b\n\t" \
- ".previous" \
+ "1: " insn " %z1, %2 # __put_user_asm\n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0,%3 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 3b \n" \
+ " .previous \n" \
:"=r" (__pu_err) \
:"Jr" (__pu_val), "o" (__m(__pu_addr)), "i" (-EFAULT)); \
})
-#define __put_user_asm_ll32 \
+#define __put_user_asm_ll32(__pu_val) \
({ \
-__asm__ __volatile__( \
- "1:\tsw\t%1, %2\t\t\t# __put_user_asm_ll32\n\t" \
- "2:\tsw\t%D1, %3\n" \
- "move\t%0, $0\n" \
- "3:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "4:\tli\t%0, %4\n\t" \
- "j\t3b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".word\t1b,4b\n\t" \
- ".word\t2b,4b\n\t" \
- ".previous" \
+ __asm__ __volatile__( \
+ "1: sw %1, %2 # __put_user_asm_ll32 \n" \
+ "2: sw %D1, %3 \n" \
+ " move %0, $0 \n" \
+ "3: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "4: li %0, %4 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 4b \n" \
+ " " __UA_ADDR " 2b, 4b \n" \
+ " .previous" \
:"=r" (__pu_err) \
- :"r" (__pu_val), "o" (__m(__pu_addr)), "o" (__m(__pu_addr + 4)),\
- "i" (-EFAULT)); \
+ :"r" (__pu_val), "o" (__m(__pu_addr)), \
+ "o" (__m(__pu_addr + 4)), "i" (-EFAULT)); \
})
extern void __put_user_unknown(void);
@@ -371,7 +398,7 @@
#ifdef MODULE
#define __MODULE_JAL(destination) \
".set\tnoat\n\t" \
- "la\t$1, " #destination "\n\t" \
+ __UA_LA "\t$1, " #destination "\n\t" \
"jalr\t$1\n\t" \
".set\tat\n\t"
#else
@@ -426,6 +453,9 @@
__cu_len; \
})
+#define __copy_to_user_inatomic __copy_to_user
+#define __copy_from_user_inatomic __copy_from_user
+
/*
* copy_to_user: - Copy a block of data into user space.
* @to: Destination address, in user space.
@@ -467,9 +497,10 @@
".set\tnoreorder\n\t" \
__MODULE_JAL(__copy_user) \
".set\tnoat\n\t" \
- "addu\t$1, %1, %2\n\t" \
+ __UA_ADDU "\t$1, %1, %2\n\t" \
".set\tat\n\t" \
".set\treorder\n\t" \
+ "move\t%0, $6" /* XXX */ \
: "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
: \
: "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \
@@ -538,6 +569,24 @@
__cu_len; \
})
+#define __copy_in_user(to, from, n) __copy_from_user(to, from, n)
+
+#define copy_in_user(to,from,n) \
+({ \
+ void *__cu_to; \
+ const void *__cu_from; \
+ long __cu_len; \
+ \
+ __cu_to = (to); \
+ __cu_from = (from); \
+ __cu_len = (n); \
+ if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \
+ access_ok(VERIFY_WRITE, __cu_to, __cu_len))) \
+ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
+ __cu_len); \
+ __cu_len; \
+})
+
/*
* __clear_user: - Zero a block of memory in user space, with less checking.
* @to: Destination address, in user space.
@@ -562,7 +611,7 @@
"move\t%0, $6"
: "=r" (res)
: "r" (addr), "r" (size)
- : "$4", "$5", "$6", "$8", "$9", "$31");
+ : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
return res;
}
@@ -610,7 +659,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -646,7 +695,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -662,7 +711,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
return res;
}
@@ -691,7 +740,24 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
+
+ return res;
+}
+
+/* Returns: 0 if bad, string length+1 (memory size) of string if ok */
+static inline long __strnlen_user(const char *s, long n)
+{
+ long res;
+
+ __asm__ __volatile__(
+ "move\t$4, %1\n\t"
+ "move\t$5, %2\n\t"
+ __MODULE_JAL(__strnlen_user_nocheck_asm)
+ "move\t%0, $2"
+ : "=r" (res)
+ : "r" (s), "r" (n)
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
@@ -699,13 +765,16 @@
/*
* strlen_user: - Get the size of a string in user space.
* @str: The string to measure.
- * @n: The maximum valid length
+ *
+ * Context: User context only. This function may sleep.
*
* Get the size of a NUL-terminated string in user space.
*
* Returns the size of the string INCLUDING the terminating NUL.
* On exception, returns 0.
- * If the string is too long, returns a value greater than @n.
+ *
+ * If there is a limit on the length of a valid string, you may wish to
+ * consider using strnlen_user() instead.
*/
static inline long strnlen_user(const char *s, long n)
{
@@ -718,7 +787,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
- : "$2", "$4", "$5", "$8", "$31");
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
Index: include/asm-mips64/uaccess.h
===================================================================
RCS file: /home/cvs/linux/include/asm-mips64/Attic/uaccess.h,v
retrieving revision 1.13.2.4
diff -u -r1.13.2.4 uaccess.h
--- include/asm-mips64/uaccess.h 14 Sep 2003 20:55:20 -0000 1.13.2.4
+++ include/asm-mips64/uaccess.h 20 Sep 2004 17:04:42 -0000
@@ -3,19 +3,17 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
- * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03 by Ralf Baechle
+ * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
*/
#ifndef _ASM_UACCESS_H
#define _ASM_UACCESS_H
+#include <linux/config.h>
#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/sched.h>
-#define STR(x) __STR(x)
-#define __STR(x) #x
-
/*
* The fs value determines whether argument validity checking should be
* performed or not. If get_fs() == USER_DS, checking is performed, with
@@ -23,15 +21,47 @@
*
* For historical reasons, these macros are grossly misnamed.
*/
+#ifdef CONFIG_MIPS32
+
+#define __UA_LIMIT 0x80000000UL
+
+#define __UA_ADDR ".word"
+#define __UA_LA "la"
+#define __UA_ADDU "addu"
+#define __UA_t0 "$8"
+#define __UA_t1 "$9"
+
+#endif /* CONFIG_MIPS32 */
+
+#ifdef CONFIG_MIPS64
+
+#define __UA_LIMIT (- TASK_SIZE)
+
+#define __UA_ADDR ".dword"
+#define __UA_LA "dla"
+#define __UA_ADDU "daddu"
+#define __UA_t0 "$12"
+#define __UA_t1 "$13"
+
+#endif /* CONFIG_MIPS64 */
+
+/*
+ * USER_DS is a bitmask that has the bits set that may not be set in a valid
+ * userspace address. Note that we limit 32-bit userspace to 0x7fff8000 but
+ * the arithmetic we're doing only works if the limit is a power of two, so
+ * we use 0x80000000 here on 32-bit kernels. If a process passes an invalid
+ * address in this range it's the process's problem, not ours :-)
+ */
+
#define KERNEL_DS ((mm_segment_t) { 0UL })
-#define USER_DS ((mm_segment_t) { -TASK_SIZE })
+#define USER_DS ((mm_segment_t) { __UA_LIMIT })
#define VERIFY_READ 0
#define VERIFY_WRITE 1
-#define get_fs() (current->thread.current_ds)
#define get_ds() (KERNEL_DS)
-#define set_fs(x) (current->thread.current_ds=(x))
+#define get_fs() (current->thread.current_ds)
+#define set_fs(x) (current->thread.current_ds = (x))
#define segment_eq(a,b) ((a).seg == (b).seg)
@@ -45,14 +75,12 @@
* - AND "size" doesn't have any high-bits set
* - AND "addr+size" doesn't have any high-bits set
* - OR we are in kernel mode.
+ *
+ * __ua_size() is a trick to avoid runtime checking of positive constant
+ * sizes; for those we already know at compile time that the size is ok.
*/
#define __ua_size(size) \
- ((__builtin_constant_p(size) && (size)) > 0 ? 0 : (size))
-
-#define __access_ok(addr, size, mask) \
- (((mask) & ((addr) | ((addr) + (size)) | __ua_size(size))) == 0)
-
-#define __access_mask get_fs().seg
+ ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))
/*
* access_ok: - Checks if a user space pointer is valid
@@ -73,8 +101,14 @@
* checks that the pointer is in the user space range - after calling
* this function, memory access functions may still return -EFAULT.
*/
+
+#define __access_mask get_fs().seg
+
+#define __access_ok(addr, size, mask) \
+ (((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0)
+
#define access_ok(type, addr, size) \
- likely(__access_ok((unsigned long)(addr), (size), __access_mask))
+ likely(__access_ok((unsigned long)(addr), (size),__access_mask))
/*
* verify_area: - Obsolete, use access_ok()
@@ -185,119 +219,176 @@
struct __large_struct { unsigned long buf[100]; };
#define __m(x) (*(struct __large_struct *)(x))
+/*
+ * Yuck. We need two variants, one for 64bit operation and one
+ * for 32 bit mode and old iron.
+ */
+#ifdef __mips64
+#define __GET_USER_DW(__gu_err) __get_user_asm("ld", __gu_err)
+#else
+#define __GET_USER_DW(__gu_err) __get_user_asm_ll32(__gu_err)
+#endif
+
#define __get_user_nocheck(x,ptr,size) \
({ \
- long __gu_err; \
- __typeof(*(ptr)) __gu_val; \
+ long __gu_err = 0; \
+ __typeof(*(ptr)) __gu_val = 0; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __get_user_asm("ld"); break; \
- default: __get_user_unknown(); break; \
- } x = (__typeof__(*(ptr))) __gu_val; \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
+ default: __get_user_unknown(); break; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
__gu_err; \
})
#define __get_user_check(x,ptr,size) \
({ \
- long __gu_err; \
- __typeof__(*(ptr)) __gu_val; \
+ long __gu_err = 0; \
+ __typeof__(*(ptr)) __gu_val = 0; \
long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
__gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
- if (access_ok(VERIFY_READ, __gu_addr, size)) { \
+ if (access_ok(VERIFY_READ,__gu_addr,size)) { \
switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __get_user_asm("ld"); break; \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
default: __get_user_unknown(); break; \
} \
- } x = (__typeof__(*(ptr))) __gu_val; \
- __gu_err; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
})
-#define __get_user_asm(insn) \
+#define __get_user_asm(insn,__gu_err) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%1,%2\n\t" \
- "move\t%0,$0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0,%3\n\t" \
- "move\t%1,$0\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".dword\t1b,3b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=r" (__gu_val) \
- :"o" (__m(__gu_addr)), "i" (-EFAULT)); \
+ "1: " insn " %1, %3 \n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0, %4 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " "__UA_ADDR "\t1b, 3b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=r" (__gu_val) \
+ : "0" (__gu_err), "o" (__m(__gu_addr)), "i" (-EFAULT)); \
+})
+
+/*
+ * Get a long long 64 using 32 bit registers.
+ */
+#define __get_user_asm_ll32(__gu_err) \
+({ \
+ __asm__ __volatile__( \
+ "1: lw %1,%2 \n" \
+ "2: lw %D1,%3 \n" \
+ " move %0,$0 \n" \
+ "3: .section .fixup,\"ax\" \n" \
+ "4: li %0,%4 \n" \
+ " move %1,$0 \n" \
+ " move %D1,$0 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b,4b \n" \
+ " " __UA_ADDR " 2b,4b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=&r" (__gu_val) \
+ : "o" (__m(__gu_addr)), "o" (__m(__gu_addr + 4)), \
+ "i" (-EFAULT)); \
})
extern void __get_user_unknown(void);
+/*
+ * Yuck. We need two variants, one for 64bit operation and one
+ * for 32 bit mode and old iron.
+ */
+#ifdef __mips64
+#define __PUT_USER_DW(__pu_val) __put_user_asm("sd", __pu_val)
+#else
+#define __PUT_USER_DW(__pu_val) __put_user_asm_ll32(__pu_val)
+#endif
+
#define __put_user_nocheck(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __put_user_asm("sd"); break; \
- default: __put_user_unknown(); break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
+ default: __put_user_unknown(); break; \
} \
__pu_err; \
})
#define __put_user_check(x,ptr,size) \
({ \
- long __pu_err; \
+ long __pu_err = 0; \
__typeof__(*(ptr)) __pu_val; \
long __pu_addr; \
__pu_val = (x); \
__pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \
switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __put_user_asm("sd"); break; \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
default: __put_user_unknown(); break; \
} \
} \
__pu_err; \
})
-#define __put_user_asm(insn) \
+#define __put_user_asm(insn, __pu_val) \
({ \
__asm__ __volatile__( \
- "1:\t" insn "\t%z1, %2\t\t\t# __put_user_asm\n\t" \
- "move\t%0, $0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0, %3\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".dword\t1b, 3b\n\t" \
- ".previous" \
+ "1: " insn " %z1, %2 # __put_user_asm\n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0,%3 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 3b \n" \
+ " .previous \n" \
:"=r" (__pu_err) \
:"Jr" (__pu_val), "o" (__m(__pu_addr)), "i" (-EFAULT)); \
})
+#define __put_user_asm_ll32(__pu_val) \
+({ \
+ __asm__ __volatile__( \
+ "1: sw %1, %2 # __put_user_asm_ll32 \n" \
+ "2: sw %D1, %3 \n" \
+ " move %0, $0 \n" \
+ "3: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "4: li %0, %4 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 4b \n" \
+ " " __UA_ADDR " 2b, 4b \n" \
+ " .previous" \
+ :"=r" (__pu_err) \
+ :"r" (__pu_val), "o" (__m(__pu_addr)), \
+ "o" (__m(__pu_addr + 4)), "i" (-EFAULT)); \
+})
+
extern void __put_user_unknown(void);
/*
@@ -307,7 +398,7 @@
#ifdef MODULE
#define __MODULE_JAL(destination) \
".set\tnoat\n\t" \
- "dla\t$1, " #destination "\n\t" \
+ __UA_LA "\t$1, " #destination "\n\t" \
"jalr\t$1\n\t" \
".set\tat\n\t"
#else
@@ -362,6 +453,9 @@
__cu_len; \
})
+#define __copy_to_user_inatomic __copy_to_user
+#define __copy_from_user_inatomic __copy_from_user
+
/*
* copy_to_user: - Copy a block of data into user space.
* @to: Destination address, in user space.
@@ -403,10 +497,10 @@
".set\tnoreorder\n\t" \
__MODULE_JAL(__copy_user) \
".set\tnoat\n\t" \
- "daddu\t$1, %1, %2\n\t" \
+ __UA_ADDU "\t$1, %1, %2\n\t" \
".set\tat\n\t" \
".set\treorder\n\t" \
- "move\t%0, $6" \
+ "move\t%0, $6" /* XXX */ \
: "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
: \
: "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \
@@ -475,6 +569,24 @@
__cu_len; \
})
+#define __copy_in_user(to, from, n) __copy_from_user(to, from, n)
+
+#define copy_in_user(to,from,n) \
+({ \
+ void *__cu_to; \
+ const void *__cu_from; \
+ long __cu_len; \
+ \
+ __cu_to = (to); \
+ __cu_from = (from); \
+ __cu_len = (n); \
+ if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \
+ access_ok(VERIFY_WRITE, __cu_to, __cu_len))) \
+ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \
+ __cu_len); \
+ __cu_len; \
+})
+
/*
* __clear_user: - Zero a block of memory in user space, with less checking.
* @to: Destination address, in user space.
@@ -499,7 +611,7 @@
"move\t%0, $6"
: "=r" (res)
: "r" (addr), "r" (size)
- : "$4", "$5", "$6", "$8", "$9", "$31");
+ : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
return res;
}
@@ -547,7 +659,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -583,7 +695,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -599,7 +711,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
return res;
}
@@ -628,7 +740,24 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
+
+ return res;
+}
+
+/* Returns: 0 if bad, string length+1 (memory size) of string if ok */
+static inline long __strnlen_user(const char *s, long n)
+{
+ long res;
+
+ __asm__ __volatile__(
+ "move\t$4, %1\n\t"
+ "move\t$5, %2\n\t"
+ __MODULE_JAL(__strnlen_user_nocheck_asm)
+ "move\t%0, $2"
+ : "=r" (res)
+ : "r" (s), "r" (n)
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
@@ -636,13 +765,16 @@
/*
* strlen_user: - Get the size of a string in user space.
* @str: The string to measure.
- * @n: The maximum valid length
+ *
+ * Context: User context only. This function may sleep.
*
* Get the size of a NUL-terminated string in user space.
*
* Returns the size of the string INCLUDING the terminating NUL.
* On exception, returns 0.
- * If the string is too long, returns a value greater than @n.
+ *
+ * If there is a limit on the length of a valid string, you may wish to
+ * consider using strnlen_user() instead.
*/
static inline long strnlen_user(const char *s, long n)
{
@@ -655,7 +787,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
- : "$2", "$4", "$5", "$8", "$31");
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-20 15:40 ` Ralf Baechle
2004-09-20 17:10 ` Ralf Baechle
@ 2004-09-24 3:18 ` Atsushi Nemoto
1 sibling, 0 replies; 13+ messages in thread
From: Atsushi Nemoto @ 2004-09-24 3:18 UTC (permalink / raw)
To: ralf; +Cc: rsandifo, linux-mips
>>>>> On Mon, 20 Sep 2004 17:40:42 +0200, Ralf Baechle <ralf@linux-mips.org> said:
ralf> The purpose of this was to avoid a warning about __gu_val
ralf> possibly being used uninitialized without inflating the code.
ralf> I've got a better solution that'll actually shrinks the code
ralf> size of my defconfig build by 5448 bytes. Untested patch below.
Thank you. This patch (and following commit to CVS :-)) works fine.
Please change paccess.h also?
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-20 17:10 ` Ralf Baechle
@ 2004-09-24 7:39 ` Atsushi Nemoto
2004-11-04 6:37 ` Atsushi Nemoto
1 sibling, 0 replies; 13+ messages in thread
From: Atsushi Nemoto @ 2004-09-24 7:39 UTC (permalink / raw)
To: ralf; +Cc: linux-mips
>>>>> On Mon, 20 Sep 2004 19:10:21 +0200, Ralf Baechle <ralf@linux-mips.org> said:
ralf> And here the same for 2.4. Actually this is a straight backport
ralf> of the 2.6 uaccess.h to 2.4 so with this patch
ralf> include/asm-mips/uaccess.h and include/asm-mips64/uaccess.h are
ralf> going to be identical.
This also fixes long standing bug in 2.4 mips64 __ua_size macro. Thank you.
There is still an another problem in 64-bit __access_ok (both 2.4 and
2.6).
The __access_ok for 64-bit kernel returns 0 if 'addr' + 'size' ==
TASK_SIZE (which should be OK).
#define __access_ok(addr, size, mask) \
(((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0)
I think this should be:
#define __access_ok(addr, size, mask) \
(((signed long)((mask) & ((addr) | ((addr) + (size) - 1) | __ua_size(size)))) == 0)
This fix is needed for 64-bit native mount syscall (which try to read
variable length string parameters from user stack. See
fs/namespace.c:copy_mount_options).
This fix also makes __access_ok(0, 0, __access_mask) return 0, but
pointer 0 is invalid anyway.
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-09-20 17:10 ` Ralf Baechle
2004-09-24 7:39 ` Atsushi Nemoto
@ 2004-11-04 6:37 ` Atsushi Nemoto
2004-11-12 13:44 ` Ralf Baechle
1 sibling, 1 reply; 13+ messages in thread
From: Atsushi Nemoto @ 2004-11-04 6:37 UTC (permalink / raw)
To: ralf; +Cc: linux-mips
>>>>> On Mon, 20 Sep 2004 19:10:21 +0200, Ralf Baechle <ralf@linux-mips.org> said:
ralf> And here the same for 2.4. Actually this is a straight backport
ralf> of the 2.6 uaccess.h to 2.4 so with this patch
ralf> include/asm-mips/uaccess.h and include/asm-mips64/uaccess.h are
ralf> going to be identical.
I found that asm-mips/uaccess.h and asm-mips64/uaccess.h in 2.4 are
sill not identical. Is this intentional? Current
asm-mips64/uaccess.h seems broken...
Also, arch/mips64/lib/strxxx_user.S should be modified to use t0/t1
instead of ta0/ta1 ? (__UA_t0 is now $12, not $8)
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-11-04 6:37 ` Atsushi Nemoto
@ 2004-11-12 13:44 ` Ralf Baechle
2004-11-16 3:15 ` Atsushi Nemoto
0 siblings, 1 reply; 13+ messages in thread
From: Ralf Baechle @ 2004-11-12 13:44 UTC (permalink / raw)
To: Atsushi Nemoto; +Cc: linux-mips
On Thu, Nov 04, 2004 at 03:37:44PM +0900, Atsushi Nemoto wrote:
Slow answer - but not forgotten :-)
> ralf> And here the same for 2.4. Actually this is a straight backport
> ralf> of the 2.6 uaccess.h to 2.4 so with this patch
> ralf> include/asm-mips/uaccess.h and include/asm-mips64/uaccess.h are
> ralf> going to be identical.
>
> I found that asm-mips/uaccess.h and asm-mips64/uaccess.h in 2.4 are
> sill not identical. Is this intentional? Current
> asm-mips64/uaccess.h seems broken...
They were both supposed to be identical.
> Also, arch/mips64/lib/strxxx_user.S should be modified to use t0/t1
> instead of ta0/ta1 ? (__UA_t0 is now $12, not $8)
Right, part of the same mistake. See the patch below which gets my test
system working. The 32-bit parts are cosmetic and shouldn't change the
generated code. They just make the 32-bit and 64-bit str*_user.S files
almost identical.
I'm surprised somebody still cares about 2.4 64-bit ;-) The 64-bit
improvments in 2.6, especially in the area of the 32-bit compatibility
code are so substancial that I don't think 2.4 is still a good choice.
Ralf
Index: arch/mips/lib/strlen_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips/lib/strlen_user.S,v
retrieving revision 1.6.2.1
diff -u -r1.6.2.1 strlen_user.S
--- arch/mips/lib/strlen_user.S 1 Jul 2002 15:27:23 -0000 1.6.2.1
+++ arch/mips/lib/strlen_user.S 12 Nov 2004 13:32:02 -0000
@@ -23,18 +23,18 @@
* Return 0 for error
*/
LEAF(__strlen_user_asm)
- lw v0, THREAD_CURDS($28) # pointer ok?
- and v0, a0
- bltz v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a0
+ bltz v0, fault
FEXPORT(__strlen_user_nocheck_asm)
- move v0, a0
+ move v0, a0
1: EX(lb, t0, (v0), fault)
- addiu v0, 1
- bnez t0, 1b
- subu v0, a0
- jr ra
+ addiu v0, 1
+ bnez t0, 1b
+ subu v0, a0
+ jr ra
END(__strlen_user_asm)
-fault: move v0, zero
- jr ra
+fault: move v0, zero
+ jr ra
Index: arch/mips/lib/strncpy_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips/lib/strncpy_user.S,v
retrieving revision 1.5
diff -u -r1.5 strncpy_user.S
--- arch/mips/lib/strncpy_user.S 6 Sep 2001 13:12:02 -0000 1.5
+++ arch/mips/lib/strncpy_user.S 12 Nov 2004 13:32:02 -0000
@@ -28,31 +28,31 @@
*/
LEAF(__strncpy_from_user_asm)
- lw v0, THREAD_CURDS($28) # pointer ok?
- and v0, a1
- bltz v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a1
+ bltz v0, fault
-EXPORT(__strncpy_from_user_nocheck_asm)
- move v0, zero
- move v1, a1
- .set noreorder
-1: EX(lbu, t0, (v1), fault)
- addiu v1, v1, 1
- beqz t0, 2f
- sb t0, (a0)
- addiu v0, 1
- bne v0, a2, 1b
- addiu a0, 1
- .set reorder
-2: addu t0, a1, v0
- xor t0, a1
- bltz t0, fault
- jr ra # return n
+FEXPORT(__strncpy_from_user_nocheck_asm)
+ move v0, zero
+ move v1, a1
+ .set noreorder
+1: EX(lbu, t0, (v1), fault)
+ PTR_ADDIU v1, 1
+ beqz t0, 2f
+ sb t0, (a0)
+ PTR_ADDIU v0, 1
+ bne v0, a2, 1b
+ PTR_ADDIU a0, 1
+ .set reorder
+2: PTR_ADDU t0, a1, v0
+ xor t0, a1
+ bltz t0, fault
+ jr ra # return n
END(__strncpy_from_user_asm)
-fault: li v0, -EFAULT
- jr ra
+fault: li v0, -EFAULT
+ jr ra
- .section __ex_table,"a"
- PTR 1b, fault
+ .section __ex_table,"a"
+ PTR 1b, fault
.previous
Index: arch/mips/lib/strnlen_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips/lib/strnlen_user.S,v
retrieving revision 1.3.2.1
diff -u -r1.3.2.1 strnlen_user.S
--- arch/mips/lib/strnlen_user.S 1 Jul 2002 15:27:23 -0000 1.3.2.1
+++ arch/mips/lib/strnlen_user.S 12 Nov 2004 13:32:02 -0000
@@ -27,23 +27,22 @@
* bytes. There's nothing secret there ...
*/
LEAF(__strnlen_user_asm)
- lw v0, THREAD_CURDS($28) # pointer ok?
- and v0, a0
- bltz v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a0
+ bltz v0, fault
FEXPORT(__strnlen_user_nocheck_asm)
- .type __strnlen_user_nocheck_asm,@function
- move v0, a0
- addu a1, a0 # stop pointer
- .set noreorder
-1: beq v0, a1, 1f # limit reached?
- addiu v0, 1
- .set reorder
+ move v0, a0
+ PTR_ADDU a1, a0 # stop pointer
+ .set noreorder
+1: beq v0, a1, 1f # limit reached?
+ PTR_ADDIU v0, 1
+ .set reorder
EX(lb, t0, -1(v0), fault)
- bnez t0, 1b
-1: subu v0, a0
- jr ra
+ bnez t0, 1b
+1: PTR_SUBU v0, a0
+ jr ra
END(__strnlen_user_asm)
-fault: move v0, zero
- jr ra
+fault: move v0, zero
+ jr ra
Index: arch/mips64/lib/strlen_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips64/lib/Attic/strlen_user.S,v
retrieving revision 1.4.2.2
diff -u -r1.4.2.2 strlen_user.S
--- arch/mips64/lib/strlen_user.S 9 Dec 2002 21:24:13 -0000 1.4.2.2
+++ arch/mips64/lib/strlen_user.S 12 Nov 2004 13:32:02 -0000
@@ -23,18 +23,18 @@
* Return 0 for error
*/
LEAF(__strlen_user_asm)
- ld v0, THREAD_CURDS($28) # pointer ok?
- and v0, a0
- bnez v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a0
+ bnez v0, fault
FEXPORT(__strlen_user_nocheck_asm)
- move v0, a0
-1: EX(lb, ta0, (v0), fault)
- daddiu v0, 1
- bnez ta0, 1b
- dsubu v0, a0
- jr ra
+ move v0, a0
+1: EX(lb, t0, (v0), fault)
+ PTR_ADDIU v0, 1
+ bnez t0, 1b
+ PTR_SUBU v0, a0
+ jr ra
END(__strlen_user_asm)
-fault: move v0, zero
- jr ra
+fault: move v0, zero
+ jr ra
Index: arch/mips64/lib/strncpy_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips64/lib/Attic/strncpy_user.S,v
retrieving revision 1.4.2.1
diff -u -r1.4.2.1 strncpy_user.S
--- arch/mips64/lib/strncpy_user.S 9 Dec 2002 21:24:13 -0000 1.4.2.1
+++ arch/mips64/lib/strncpy_user.S 12 Nov 2004 13:32:02 -0000
@@ -28,31 +28,31 @@
*/
LEAF(__strncpy_from_user_asm)
- ld v0, THREAD_CURDS($28) # pointer ok?
- and v0, a1
- bnez v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a1
+ bnez v0, fault
FEXPORT(__strncpy_from_user_nocheck_asm)
- move v0, zero
- move v1, a1
- .set noreorder
-1: EX(lbu, ta0, (v1), fault)
- daddiu v1, 1
- beqz ta0, 2f
- sb ta0, (a0)
- daddiu v0, 1
- bne v0, a2, 1b
- daddiu a0, 1
- .set reorder
-2: daddu ta0, a1, v0
- xor ta0, a1
- bltz ta0, fault
- jr ra # return n
+ move v0, zero
+ move v1, a1
+ .set noreorder
+1: EX(lbu, t0, (v1), fault)
+ PTR_ADDIU v1, 1
+ beqz t0, 2f
+ sb t0, (a0)
+ PTR_ADDIU v0, 1
+ bne v0, a2, 1b
+ PTR_ADDIU a0, 1
+ .set reorder
+2: PTR_ADDU t0, a1, v0
+ xor t0, a1
+ bltz t0, fault
+ jr ra # return n
END(__strncpy_from_user_asm)
-fault: li v0, -EFAULT
- jr ra
+fault: li v0, -EFAULT
+ jr ra
.section __ex_table,"a"
- PTR 1b, fault
+ PTR 1b, fault
.previous
Index: arch/mips64/lib/strnlen_user.S
===================================================================
RCS file: /home/cvs/linux/arch/mips64/lib/Attic/strnlen_user.S,v
retrieving revision 1.2.2.3
diff -u -r1.2.2.3 strnlen_user.S
--- arch/mips64/lib/strnlen_user.S 9 Dec 2002 21:24:13 -0000 1.2.2.3
+++ arch/mips64/lib/strnlen_user.S 12 Nov 2004 13:32:02 -0000
@@ -20,23 +20,29 @@
/*
* Return the size of a string (including the ending 0)
*
- * Return 0 for error, len on string but at max a1 otherwise
+ * Return 0 for error, len of string but at max a1 otherwise
+ *
+ * Note: for performance reasons we deliberately accept that a user may
+ * make strlen_user and strnlen_user access the first few KSEG0
+ * bytes. There's nothing secret there ...
*/
LEAF(__strnlen_user_asm)
- ld v0, THREAD_CURDS($28) # pointer ok?
- and v0, a0
- bnez v0, fault
+ LONG_L v0, THREAD_CURDS($28) # pointer ok?
+ and v0, a0
+ bnez v0, fault
FEXPORT(__strnlen_user_nocheck_asm)
- move v0, a0
- daddu a1, a0 # stop pointer
-1: beq v0, a1, 1f # limit reached?
- EX(lb, ta0, (v0), fault)
- daddiu v0, 1
- bnez ta0, 1b
-1: dsubu v0, a0
- jr ra
+ move v0, a0
+ PTR_ADDU a1, a0 # stop pointer
+ .set noreorder
+1: beq v0, a1, 1f # limit reached?
+ PTR_ADDIU v0, 1
+ .set reorder
+ EX(lb, t0, -1(v0), fault)
+ bnez t0, 1b
+1: PTR_SUBU v0, a0
+ jr ra
END(__strnlen_user_asm)
-fault: move v0, zero
- jr ra
+fault: move v0, zero
+ jr ra
Index: include/asm-mips64/uaccess.h
===================================================================
RCS file: /home/cvs/linux/include/asm-mips64/Attic/uaccess.h,v
retrieving revision 1.13.2.3
diff -u -r1.13.2.3 uaccess.h
--- include/asm-mips64/uaccess.h 5 Jul 2003 03:23:46 -0000 1.13.2.3
+++ include/asm-mips64/uaccess.h 12 Nov 2004 13:32:06 -0000
@@ -3,18 +3,17 @@
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
- * Copyright (C) 1996, 1997, 1998, 1999, 2000 by Ralf Baechle
+ * Copyright (C) 1996, 1997, 1998, 1999, 2000, 03, 04 by Ralf Baechle
* Copyright (C) 1999, 2000 Silicon Graphics, Inc.
*/
#ifndef _ASM_UACCESS_H
#define _ASM_UACCESS_H
+#include <linux/config.h>
+#include <linux/compiler.h>
#include <linux/errno.h>
#include <linux/sched.h>
-#define STR(x) __STR(x)
-#define __STR(x) #x
-
/*
* The fs value determines whether argument validity checking should be
* performed or not. If get_fs() == USER_DS, checking is performed, with
@@ -22,15 +21,47 @@
*
* For historical reasons, these macros are grossly misnamed.
*/
+#ifdef CONFIG_MIPS32
+
+#define __UA_LIMIT 0x80000000UL
+
+#define __UA_ADDR ".word"
+#define __UA_LA "la"
+#define __UA_ADDU "addu"
+#define __UA_t0 "$8"
+#define __UA_t1 "$9"
+
+#endif /* CONFIG_MIPS32 */
+
+#ifdef CONFIG_MIPS64
+
+#define __UA_LIMIT (- TASK_SIZE)
+
+#define __UA_ADDR ".dword"
+#define __UA_LA "dla"
+#define __UA_ADDU "daddu"
+#define __UA_t0 "$12"
+#define __UA_t1 "$13"
+
+#endif /* CONFIG_MIPS64 */
+
+/*
+ * USER_DS is a bitmask that has the bits set that may not be set in a valid
+ * userspace address. Note that we limit 32-bit userspace to 0x7fff8000 but
+ * the arithmetic we're doing only works if the limit is a power of two, so
+ * we use 0x80000000 here on 32-bit kernels. If a process passes an invalid
+ * address in this range it's the process's problem, not ours :-)
+ */
+
#define KERNEL_DS ((mm_segment_t) { 0UL })
-#define USER_DS ((mm_segment_t) { -TASK_SIZE })
+#define USER_DS ((mm_segment_t) { __UA_LIMIT })
#define VERIFY_READ 0
#define VERIFY_WRITE 1
-#define get_fs() (current->thread.current_ds)
#define get_ds() (KERNEL_DS)
-#define set_fs(x) (current->thread.current_ds=(x))
+#define get_fs() (current->thread.current_ds)
+#define set_fs(x) (current->thread.current_ds = (x))
#define segment_eq(a,b) ((a).seg == (b).seg)
@@ -44,14 +75,12 @@
* - AND "size" doesn't have any high-bits set
* - AND "addr+size" doesn't have any high-bits set
* - OR we are in kernel mode.
+ *
+ * __ua_size() is a trick to avoid runtime checking of positive constant
+ * sizes; for those we already know at compile time that the size is ok.
*/
#define __ua_size(size) \
- ((__builtin_constant_p(size) && (size)) > 0 ? 0 : (size))
-
-#define __access_ok(addr, size, mask) \
- (((mask) & ((addr) | ((addr) + (size)) | __ua_size(size))) == 0)
-
-#define __access_mask get_fs().seg
+ ((__builtin_constant_p(size) && (signed long) (size) > 0) ? 0 : (size))
/*
* access_ok: - Checks if a user space pointer is valid
@@ -72,8 +101,14 @@
* checks that the pointer is in the user space range - after calling
* this function, memory access functions may still return -EFAULT.
*/
+
+#define __access_mask get_fs().seg
+
+#define __access_ok(addr, size, mask) \
+ (((signed long)((mask) & ((addr) | ((addr) + (size)) | __ua_size(size)))) == 0)
+
#define access_ok(type, addr, size) \
- __access_ok((unsigned long)(addr), (size), __access_mask)
+ likely(__access_ok((unsigned long)(addr), (size),__access_mask))
/*
* verify_area: - Obsolete, use access_ok()
@@ -184,117 +219,177 @@
struct __large_struct { unsigned long buf[100]; };
#define __m(x) (*(struct __large_struct *)(x))
-#define __get_user_nocheck(x,ptr,size) \
-({ \
- long __gu_err; \
- __typeof(*(ptr)) __gu_val; \
- long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
- __gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
- switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __get_user_asm("ld"); break; \
- default: __get_user_unknown(); break; \
- } x = (__typeof__(*(ptr))) __gu_val; \
- __gu_err; \
-})
-
-#define __get_user_check(x,ptr,size) \
-({ \
- long __gu_err; \
- __typeof__(*(ptr)) __gu_val; \
- long __gu_addr; \
- __asm__("":"=r" (__gu_val)); \
- __gu_addr = (long) (ptr); \
- __asm__("":"=r" (__gu_err)); \
- if (__access_ok(__gu_addr,size,__access_mask)) { \
- switch (size) { \
- case 1: __get_user_asm("lb"); break; \
- case 2: __get_user_asm("lh"); break; \
- case 4: __get_user_asm("lw"); break; \
- case 8: __get_user_asm("ld"); break; \
- default: __get_user_unknown(); break; \
- } \
- } x = (__typeof__(*(ptr))) __gu_val; \
- __gu_err; \
-})
-
-#define __get_user_asm(insn) \
-({ \
- __asm__ __volatile__( \
- "1:\t" insn "\t%1,%2\n\t" \
- "move\t%0,$0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0,%3\n\t" \
- "move\t%1,$0\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".dword\t1b,3b\n\t" \
- ".previous" \
- :"=r" (__gu_err), "=r" (__gu_val) \
- :"o" (__m(__gu_addr)), "i" (-EFAULT)); \
+/*
+ * Yuck. We need two variants, one for 64bit operation and one
+ * for 32 bit mode and old iron.
+ */
+#ifdef __mips64
+#define __GET_USER_DW(__gu_err) __get_user_asm("ld", __gu_err)
+#else
+#define __GET_USER_DW(__gu_err) __get_user_asm_ll32(__gu_err)
+#endif
+
+#define __get_user_nocheck(x,ptr,size) \
+({ \
+ long __gu_err = 0; \
+ __typeof(*(ptr)) __gu_val = 0; \
+ long __gu_addr; \
+ __gu_addr = (long) (ptr); \
+ switch (size) { \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
+ default: __get_user_unknown(); break; \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
+})
+
+#define __get_user_check(x,ptr,size) \
+({ \
+ __typeof__(*(ptr)) __gu_val = 0; \
+ long __gu_addr = (long) (ptr); \
+ long __gu_err; \
+ \
+ __gu_err = verify_area(VERIFY_READ, (void *) __gu_addr, size); \
+ \
+ if (likely(!__gu_err)) { \
+ switch (size) { \
+ case 1: __get_user_asm("lb", __gu_err); break; \
+ case 2: __get_user_asm("lh", __gu_err); break; \
+ case 4: __get_user_asm("lw", __gu_err); break; \
+ case 8: __GET_USER_DW(__gu_err); break; \
+ default: __get_user_unknown(); break; \
+ } \
+ } \
+ x = (__typeof__(*(ptr))) __gu_val; \
+ __gu_err; \
+})
+
+#define __get_user_asm(insn,__gu_err) \
+({ \
+ __asm__ __volatile__( \
+ "1: " insn " %1, %3 \n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0, %4 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " "__UA_ADDR "\t1b, 3b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=r" (__gu_val) \
+ : "0" (__gu_err), "o" (__m(__gu_addr)), "i" (-EFAULT)); \
+})
+
+/*
+ * Get a long long 64 using 32 bit registers.
+ */
+#define __get_user_asm_ll32(__gu_err) \
+({ \
+ __asm__ __volatile__( \
+ "1: lw %1, %3 \n" \
+ "2: lw %D1, %4 \n" \
+ " move %0, $0 \n" \
+ "3: .section .fixup,\"ax\" \n" \
+ "4: li %0, %5 \n" \
+ " move %1, $0 \n" \
+ " move %D1, $0 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 4b \n" \
+ " " __UA_ADDR " 2b, 4b \n" \
+ " .previous \n" \
+ : "=r" (__gu_err), "=&r" (__gu_val) \
+ : "0" (__gu_err), "o" (__m(__gu_addr)), \
+ "o" (__m(__gu_addr + 4)), "i" (-EFAULT)); \
})
extern void __get_user_unknown(void);
-#define __put_user_nocheck(x,ptr,size) \
-({ \
- long __pu_err; \
- __typeof__(*(ptr)) __pu_val; \
- long __pu_addr; \
- __pu_val = (x); \
- __pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
- switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __put_user_asm("sd"); break; \
- default: __put_user_unknown(); break; \
- } \
- __pu_err; \
-})
-
-#define __put_user_check(x,ptr,size) \
-({ \
- long __pu_err; \
- __typeof__(*(ptr)) __pu_val; \
- long __pu_addr; \
- __pu_val = (x); \
- __pu_addr = (long) (ptr); \
- __asm__("":"=r" (__pu_err)); \
- if (__access_ok(__pu_addr,size,__access_mask)) { \
- switch (size) { \
- case 1: __put_user_asm("sb"); break; \
- case 2: __put_user_asm("sh"); break; \
- case 4: __put_user_asm("sw"); break; \
- case 8: __put_user_asm("sd"); break; \
- default: __put_user_unknown(); break; \
- } \
- } \
- __pu_err; \
-})
-
-#define __put_user_asm(insn) \
-({ \
- __asm__ __volatile__( \
- "1:\t" insn "\t%z1, %2\t\t\t# __put_user_asm\n\t" \
- "move\t%0, $0\n" \
- "2:\n\t" \
- ".section\t.fixup,\"ax\"\n" \
- "3:\tli\t%0, %3\n\t" \
- "j\t2b\n\t" \
- ".previous\n\t" \
- ".section\t__ex_table,\"a\"\n\t" \
- ".dword\t1b, 3b\n\t" \
- ".previous" \
- :"=r" (__pu_err) \
- :"Jr" (__pu_val), "o" (__m(__pu_addr)), "i" (-EFAULT)); \
+/*
+ * Yuck. We need two variants, one for 64bit operation and one
+ * for 32 bit mode and old iron.
+ */
+#ifdef __mips64
+#define __PUT_USER_DW(__pu_val) __put_user_asm("sd", __pu_val)
+#else
+#define __PUT_USER_DW(__pu_val) __put_user_asm_ll32(__pu_val)
+#endif
+
+#define __put_user_nocheck(x,ptr,size) \
+({ \
+ long __pu_err = 0; \
+ __typeof__(*(ptr)) __pu_val; \
+ long __pu_addr; \
+ __pu_val = (x); \
+ __pu_addr = (long) (ptr); \
+ switch (size) { \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
+ default: __put_user_unknown(); break; \
+ } \
+ __pu_err; \
+})
+
+#define __put_user_check(x,ptr,size) \
+({ \
+ __typeof__(*(ptr)) __pu_val = (x); \
+ long __pu_addr = (long) (ptr); \
+ long __pu_err; \
+ \
+ __pu_err = verify_area(VERIFY_WRITE, (void *) __pu_addr, size); \
+ \
+ if (likely(!__pu_err)) { \
+ switch (size) { \
+ case 1: __put_user_asm("sb", __pu_val); break; \
+ case 2: __put_user_asm("sh", __pu_val); break; \
+ case 4: __put_user_asm("sw", __pu_val); break; \
+ case 8: __PUT_USER_DW(__pu_val); break; \
+ default: __put_user_unknown(); break; \
+ } \
+ } \
+ __pu_err; \
+})
+
+#define __put_user_asm(insn, __pu_val) \
+({ \
+ __asm__ __volatile__( \
+ "1: " insn " %z2, %3 # __put_user_asm\n" \
+ "2: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "3: li %0, %4 \n" \
+ " j 2b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 3b \n" \
+ " .previous \n" \
+ : "=r" (__pu_err) \
+ : "0" (__pu_err), "Jr" (__pu_val), "o" (__m(__pu_addr)), \
+ "i" (-EFAULT)); \
+})
+
+#define __put_user_asm_ll32(__pu_val) \
+({ \
+ __asm__ __volatile__( \
+ "1: sw %2, %3 # __put_user_asm_ll32 \n" \
+ "2: sw %D2, %4 \n" \
+ "3: \n" \
+ " .section .fixup,\"ax\" \n" \
+ "4: li %0, %5 \n" \
+ " j 3b \n" \
+ " .previous \n" \
+ " .section __ex_table,\"a\" \n" \
+ " " __UA_ADDR " 1b, 4b \n" \
+ " " __UA_ADDR " 2b, 4b \n" \
+ " .previous" \
+ : "=r" (__pu_err) \
+ : "0" (__pu_err), "r" (__pu_val), "o" (__m(__pu_addr)), \
+ "o" (__m(__pu_addr + 4)), "i" (-EFAULT)); \
})
extern void __put_user_unknown(void);
@@ -304,13 +399,13 @@
* jump instructions
*/
#ifdef MODULE
-#define __MODULE_JAL(destination) \
- ".set\tnoat\n\t" \
- "dla\t$1, " #destination "\n\t" \
- "jalr\t$1\n\t" \
+#define __MODULE_JAL(destination) \
+ ".set\tnoat\n\t" \
+ __UA_LA "\t$1, " #destination "\n\t" \
+ "jalr\t$1\n\t" \
".set\tat\n\t"
#else
-#define __MODULE_JAL(destination) \
+#define __MODULE_JAL(destination) \
"jal\t" #destination "\n\t"
#endif
@@ -361,6 +456,9 @@
__cu_len; \
})
+#define __copy_to_user_inatomic __copy_to_user
+#define __copy_from_user_inatomic __copy_from_user
+
/*
* copy_to_user: - Copy a block of data into user space.
* @to: Destination address, in user space.
@@ -402,10 +500,9 @@
".set\tnoreorder\n\t" \
__MODULE_JAL(__copy_user) \
".set\tnoat\n\t" \
- "daddu\t$1, %1, %2\n\t" \
+ __UA_ADDU "\t$1, %1, %2\n\t" \
".set\tat\n\t" \
- ".set\treorder\n\t" \
- "move\t%0, $6" \
+ ".set\treorder" \
: "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \
: \
: "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \
@@ -498,19 +595,19 @@
"move\t%0, $6"
: "=r" (res)
: "r" (addr), "r" (size)
- : "$4", "$5", "$6", "$8", "$9", "$31");
+ : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31");
return res;
}
-#define clear_user(addr,n) \
-({ \
- void * __cl_addr = (addr); \
- unsigned long __cl_size = (n); \
- if (__cl_size && access_ok(VERIFY_WRITE, \
- ((unsigned long)(__cl_addr)), __cl_size)) \
- __cl_size = __clear_user(__cl_addr, __cl_size); \
- __cl_size; \
+#define clear_user(addr,n) \
+({ \
+ void * __cl_addr = (addr); \
+ unsigned long __cl_size = (n); \
+ if (__cl_size && access_ok(VERIFY_WRITE, \
+ ((unsigned long)(__cl_addr)), __cl_size)) \
+ __cl_size = __clear_user(__cl_addr, __cl_size); \
+ __cl_size; \
})
/*
@@ -546,7 +643,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -582,7 +679,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (__to), "r" (__from), "r" (__len)
- : "$2", "$3", "$4", "$5", "$6", "$8", "$31", "memory");
+ : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory");
return res;
}
@@ -598,7 +695,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
return res;
}
@@ -627,7 +724,24 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s)
- : "$2", "$4", "$8", "$31");
+ : "$2", "$4", __UA_t0, "$31");
+
+ return res;
+}
+
+/* Returns: 0 if bad, string length+1 (memory size) of string if ok */
+static inline long __strnlen_user(const char *s, long n)
+{
+ long res;
+
+ __asm__ __volatile__(
+ "move\t$4, %1\n\t"
+ "move\t$5, %2\n\t"
+ __MODULE_JAL(__strnlen_user_nocheck_asm)
+ "move\t%0, $2"
+ : "=r" (res)
+ : "r" (s), "r" (n)
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
@@ -635,13 +749,16 @@
/*
* strlen_user: - Get the size of a string in user space.
* @str: The string to measure.
- * @n: The maximum valid length
+ *
+ * Context: User context only. This function may sleep.
*
* Get the size of a NUL-terminated string in user space.
*
* Returns the size of the string INCLUDING the terminating NUL.
* On exception, returns 0.
- * If the string is too long, returns a value greater than @n.
+ *
+ * If there is a limit on the length of a valid string, you may wish to
+ * consider using strnlen_user() instead.
*/
static inline long strnlen_user(const char *s, long n)
{
@@ -654,7 +771,7 @@
"move\t%0, $2"
: "=r" (res)
: "r" (s), "r" (n)
- : "$2", "$4", "$5", "$8", "$31");
+ : "$2", "$4", "$5", __UA_t0, "$31");
return res;
}
@@ -669,9 +786,9 @@
extern unsigned long search_exception_table(unsigned long addr);
/* Returns the new pc */
-#define fixup_exception(map_reg, fixup_unit, pc) \
-({ \
- fixup_unit; \
+#define fixup_exception(map_reg, fixup_unit, pc) \
+({ \
+ fixup_unit; \
})
#endif /* _ASM_UACCESS_H */
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: gcc 3.3.4/3.4.1 and get_user
2004-11-12 13:44 ` Ralf Baechle
@ 2004-11-16 3:15 ` Atsushi Nemoto
0 siblings, 0 replies; 13+ messages in thread
From: Atsushi Nemoto @ 2004-11-16 3:15 UTC (permalink / raw)
To: ralf; +Cc: linux-mips
>>>>> On Fri, 12 Nov 2004 14:44:40 +0100, Ralf Baechle <ralf@linux-mips.org> said:
ralf> Right, part of the same mistake. See the patch below which gets
ralf> my test system working. The 32-bit parts are cosmetic and
ralf> shouldn't change the generated code. They just make the 32-bit
ralf> and 64-bit str*_user.S files almost identical.
Thank you. They work fine.
ralf> I'm surprised somebody still cares about 2.4 64-bit ;-) The
ralf> 64-bit improvments in 2.6, especially in the area of the 32-bit
ralf> compatibility code are so substancial that I don't think 2.4 is
ralf> still a good choice.
Yes, I agree that 2.6 is better. I just want to run 2.4 64-bit for
comparison from time to time. (only when something failed on 2.6 :-))
---
Atsushi Nemoto
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2004-11-16 3:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-31 16:22 gcc 3.3.4/3.4.1 and get_user Atsushi Nemoto
2004-09-01 8:51 ` Richard Sandiford
2004-09-01 15:14 ` Atsushi Nemoto
2004-09-01 15:16 ` Atsushi Nemoto
2004-09-20 8:59 ` Richard Sandiford
2004-09-20 14:18 ` Atsushi Nemoto
2004-09-20 15:40 ` Ralf Baechle
2004-09-20 17:10 ` Ralf Baechle
2004-09-24 7:39 ` Atsushi Nemoto
2004-11-04 6:37 ` Atsushi Nemoto
2004-11-12 13:44 ` Ralf Baechle
2004-11-16 3:15 ` Atsushi Nemoto
2004-09-24 3:18 ` Atsushi Nemoto
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.