Commit 7da63b3d authored by Linus Torvalds's avatar Linus Torvalds

x86: get rid of 'rtype' argument to __get_user_asm() macro

This is the exact same thing as 36807856 ("x86: get rid of 'rtype'
argument to __put_user_goto() macro") except it's about __get_user_asm()
rather than __put_user_goto().

The reasons are the same: having the low-level asm access the argument
with a different size than the compiler thinks it does is fundamentally
wrong.

But unlike the __put_user_goto() case, we actually did tell the compiler
that we used a bigger variable (either long or long long), and then only
filled in the low bits, and ended up "fixing" this by casting the result
to the proper pointer type.

That's because we needed to use a non-qualified type (the user pointer
might be a const pointer!), and that makes this a bit more painful.  Our
'__inttype()' macro used to be lazy and only differentiate between "fits
in a register" or "needs two registers".

So this fix had to also make that '__inttype()' macro more precise.
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 36807856
...@@ -126,11 +126,17 @@ extern int __get_user_bad(void); ...@@ -126,11 +126,17 @@ extern int __get_user_bad(void);
}) })
/* /*
* This is a type: either unsigned long, if the argument fits into * This is the smallest unsigned integer type that can fit a value
* that type, or otherwise unsigned long long. * (up to 'long long')
*/ */
#define __inttype(x) \ #define __inttype(x) __typeof__( \
__typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL)) __typefits(x,char, \
__typefits(x,short, \
__typefits(x,int, \
__typefits(x,long,0ULL)))))
#define __typefits(x,type,not) \
__builtin_choose_expr(sizeof(x)<=sizeof(type),(unsigned type)0,not)
/** /**
* get_user - Get a simple variable from user space. * get_user - Get a simple variable from user space.
...@@ -301,7 +307,7 @@ do { \ ...@@ -301,7 +307,7 @@ do { \
#else #else
#define __get_user_asm_u64(x, ptr, retval) \ #define __get_user_asm_u64(x, ptr, retval) \
__get_user_asm(x, ptr, retval, "q", "", "=r") __get_user_asm(x, ptr, retval, "q", "=r")
#endif #endif
#define __get_user_size(x, ptr, size, retval) \ #define __get_user_size(x, ptr, size, retval) \
...@@ -310,13 +316,13 @@ do { \ ...@@ -310,13 +316,13 @@ do { \
__chk_user_ptr(ptr); \ __chk_user_ptr(ptr); \
switch (size) { \ switch (size) { \
case 1: \ case 1: \
__get_user_asm(x, ptr, retval, "b", "b", "=q"); \ __get_user_asm(x, ptr, retval, "b", "=q"); \
break; \ break; \
case 2: \ case 2: \
__get_user_asm(x, ptr, retval, "w", "w", "=r"); \ __get_user_asm(x, ptr, retval, "w", "=r"); \
break; \ break; \
case 4: \ case 4: \
__get_user_asm(x, ptr, retval, "l", "k", "=r"); \ __get_user_asm(x, ptr, retval, "l", "=r"); \
break; \ break; \
case 8: \ case 8: \
__get_user_asm_u64(x, ptr, retval); \ __get_user_asm_u64(x, ptr, retval); \
...@@ -326,13 +332,13 @@ do { \ ...@@ -326,13 +332,13 @@ do { \
} \ } \
} while (0) } while (0)
#define __get_user_asm(x, addr, err, itype, rtype, ltype) \ #define __get_user_asm(x, addr, err, itype, ltype) \
asm volatile("\n" \ asm volatile("\n" \
"1: mov"itype" %2,%"rtype"1\n" \ "1: mov"itype" %2,%1\n" \
"2:\n" \ "2:\n" \
".section .fixup,\"ax\"\n" \ ".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \ "3: mov %3,%0\n" \
" xor"itype" %"rtype"1,%"rtype"1\n" \ " xor"itype" %1,%1\n" \
" jmp 2b\n" \ " jmp 2b\n" \
".previous\n" \ ".previous\n" \
_ASM_EXTABLE_UA(1b, 3b) \ _ASM_EXTABLE_UA(1b, 3b) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment