linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arch/microblaze: support get_user() of size 8 bytes
@ 2019-09-17  1:39 Randy Dunlap
  2019-09-18  7:49 ` Michal Simek
  0 siblings, 1 reply; 2+ messages in thread
From: Randy Dunlap @ 2019-09-17  1:39 UTC (permalink / raw)
  To: LKML, Linus Torvalds, Michal Simek
  Cc: Andrew Morton, Al Viro, Steven J. Magnani, Jason Gunthorpe,
	Leon Romanovsky, Doug Ledford

From: Randy Dunlap <rdunlap@infradead.org>

arch/microblaze/ is missing support for get_user() of size 8 bytes,
so add it by using __copy_from_user().

While there, also drop a lot of the code duplication.

Fixes these build errors:
   drivers/infiniband/core/uverbs_main.o: In function `ib_uverbs_write':
   drivers/infiniband/core/.tmp_gl_uverbs_main.o:(.text+0x13a4): undefined reference to `__user_bad'
   drivers/android/binder.o: In function `binder_thread_write':
   drivers/android/.tmp_gl_binder.o:(.text+0xda6c): undefined reference to `__user_bad'
   drivers/android/.tmp_gl_binder.o:(.text+0xda98): undefined reference to `__user_bad'
   drivers/android/.tmp_gl_binder.o:(.text+0xdf10): undefined reference to `__user_bad'
   drivers/android/.tmp_gl_binder.o:(.text+0xe498): undefined reference to `__user_bad'
   drivers/android/binder.o:drivers/android/.tmp_gl_binder.o:(.text+0xea78): more undefined references to `__user_bad' follow

'make allmodconfig' now builds successfully for arch/microblaze/.

Fixes: 538722ca3b76 ("microblaze: fix get_user/put_user side-effects")
Reported-by: kbuild test robot <lkp@intel.com>
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Steven J. Magnani <steve@digidescorp.com>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Jason Gunthorpe <jgg@mellanox.com>
Cc: Leon Romanovsky <leonro@mellanox.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Doug Ledford <dledford@redhat.com>
---
v4: drop code duplication (Linus).


 arch/microblaze/include/asm/uaccess.h |   42 +++++-------------------
 1 file changed, 9 insertions(+), 33 deletions(-)

--- lnx-53.orig/arch/microblaze/include/asm/uaccess.h
+++ lnx-53/arch/microblaze/include/asm/uaccess.h
@@ -163,44 +163,15 @@ extern long __user_bad(void);
  * Returns zero on success, or -EFAULT on error.
  * On error, the variable @x is set to zero.
  */
-#define get_user(x, ptr)						\
-	__get_user_check((x), (ptr), sizeof(*(ptr)))
-
-#define __get_user_check(x, ptr, size)					\
-({									\
-	unsigned long __gu_val = 0;					\
-	const typeof(*(ptr)) __user *__gu_addr = (ptr);			\
-	int __gu_err = 0;						\
-									\
-	if (access_ok(__gu_addr, size)) {			\
-		switch (size) {						\
-		case 1:							\
-			__get_user_asm("lbu", __gu_addr, __gu_val,	\
-				       __gu_err);			\
-			break;						\
-		case 2:							\
-			__get_user_asm("lhu", __gu_addr, __gu_val,	\
-				       __gu_err);			\
-			break;						\
-		case 4:							\
-			__get_user_asm("lw", __gu_addr, __gu_val,	\
-				       __gu_err);			\
-			break;						\
-		default:						\
-			__gu_err = __user_bad();			\
-			break;						\
-		}							\
-	} else {							\
-		__gu_err = -EFAULT;					\
-	}								\
-	x = (__force typeof(*(ptr)))__gu_val;				\
-	__gu_err;							\
+#define get_user(x, ptr) ({				\
+	const typeof(*(ptr)) __user *__gu_ptr = (ptr);	\
+	access_ok(__gu_ptr, sizeof(*__gu_ptr)) ?	\
+		__get_user(x, __gu_ptr) : -EFAULT;	\
 })
 
 #define __get_user(x, ptr)						\
 ({									\
 	unsigned long __gu_val = 0;					\
-	/*unsigned long __gu_ptr = (unsigned long)(ptr);*/		\
 	long __gu_err;							\
 	switch (sizeof(*(ptr))) {					\
 	case 1:								\
@@ -212,6 +183,11 @@ extern long __user_bad(void);
 	case 4:								\
 		__get_user_asm("lw", (ptr), __gu_val, __gu_err);	\
 		break;							\
+	case 8:								\
+		__gu_err = __copy_from_user(&__gu_val, ptr, 8);		\
+		if (__gu_err)						\
+			__gu_err = -EFAULT;				\
+		break;							\
 	default:							\
 		/* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\
 	}								\



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] arch/microblaze: support get_user() of size 8 bytes
  2019-09-17  1:39 [PATCH] arch/microblaze: support get_user() of size 8 bytes Randy Dunlap
@ 2019-09-18  7:49 ` Michal Simek
  0 siblings, 0 replies; 2+ messages in thread
From: Michal Simek @ 2019-09-18  7:49 UTC (permalink / raw)
  To: Randy Dunlap, LKML, Linus Torvalds
  Cc: Andrew Morton, Al Viro, Steven J. Magnani, Jason Gunthorpe,
	Leon Romanovsky, Doug Ledford


[-- Attachment #1.1: Type: text/plain, Size: 4000 bytes --]

On 17. 09. 19 3:39, Randy Dunlap wrote:
> From: Randy Dunlap <rdunlap@infradead.org>
> 
> arch/microblaze/ is missing support for get_user() of size 8 bytes,
> so add it by using __copy_from_user().
> 
> While there, also drop a lot of the code duplication.
> 
> Fixes these build errors:
>    drivers/infiniband/core/uverbs_main.o: In function `ib_uverbs_write':
>    drivers/infiniband/core/.tmp_gl_uverbs_main.o:(.text+0x13a4): undefined reference to `__user_bad'
>    drivers/android/binder.o: In function `binder_thread_write':
>    drivers/android/.tmp_gl_binder.o:(.text+0xda6c): undefined reference to `__user_bad'
>    drivers/android/.tmp_gl_binder.o:(.text+0xda98): undefined reference to `__user_bad'
>    drivers/android/.tmp_gl_binder.o:(.text+0xdf10): undefined reference to `__user_bad'
>    drivers/android/.tmp_gl_binder.o:(.text+0xe498): undefined reference to `__user_bad'
>    drivers/android/binder.o:drivers/android/.tmp_gl_binder.o:(.text+0xea78): more undefined references to `__user_bad' follow
> 
> 'make allmodconfig' now builds successfully for arch/microblaze/.
> 
> Fixes: 538722ca3b76 ("microblaze: fix get_user/put_user side-effects")
> Reported-by: kbuild test robot <lkp@intel.com>
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Cc: Steven J. Magnani <steve@digidescorp.com>
> Cc: Michal Simek <monstr@monstr.eu>
> Cc: Jason Gunthorpe <jgg@mellanox.com>
> Cc: Leon Romanovsky <leonro@mellanox.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Doug Ledford <dledford@redhat.com>
> ---
> v4: drop code duplication (Linus).
> 
> 
>  arch/microblaze/include/asm/uaccess.h |   42 +++++-------------------
>  1 file changed, 9 insertions(+), 33 deletions(-)
> 
> --- lnx-53.orig/arch/microblaze/include/asm/uaccess.h
> +++ lnx-53/arch/microblaze/include/asm/uaccess.h
> @@ -163,44 +163,15 @@ extern long __user_bad(void);
>   * Returns zero on success, or -EFAULT on error.
>   * On error, the variable @x is set to zero.
>   */
> -#define get_user(x, ptr)						\
> -	__get_user_check((x), (ptr), sizeof(*(ptr)))
> -
> -#define __get_user_check(x, ptr, size)					\
> -({									\
> -	unsigned long __gu_val = 0;					\
> -	const typeof(*(ptr)) __user *__gu_addr = (ptr);			\
> -	int __gu_err = 0;						\
> -									\
> -	if (access_ok(__gu_addr, size)) {			\
> -		switch (size) {						\
> -		case 1:							\
> -			__get_user_asm("lbu", __gu_addr, __gu_val,	\
> -				       __gu_err);			\
> -			break;						\
> -		case 2:							\
> -			__get_user_asm("lhu", __gu_addr, __gu_val,	\
> -				       __gu_err);			\
> -			break;						\
> -		case 4:							\
> -			__get_user_asm("lw", __gu_addr, __gu_val,	\
> -				       __gu_err);			\
> -			break;						\
> -		default:						\
> -			__gu_err = __user_bad();			\
> -			break;						\
> -		}							\
> -	} else {							\
> -		__gu_err = -EFAULT;					\
> -	}								\
> -	x = (__force typeof(*(ptr)))__gu_val;				\
> -	__gu_err;							\
> +#define get_user(x, ptr) ({				\
> +	const typeof(*(ptr)) __user *__gu_ptr = (ptr);	\
> +	access_ok(__gu_ptr, sizeof(*__gu_ptr)) ?	\
> +		__get_user(x, __gu_ptr) : -EFAULT;	\
>  })
>  
>  #define __get_user(x, ptr)						\
>  ({									\
>  	unsigned long __gu_val = 0;					\
> -	/*unsigned long __gu_ptr = (unsigned long)(ptr);*/		\
>  	long __gu_err;							\
>  	switch (sizeof(*(ptr))) {					\
>  	case 1:								\
> @@ -212,6 +183,11 @@ extern long __user_bad(void);
>  	case 4:								\
>  		__get_user_asm("lw", (ptr), __gu_val, __gu_err);	\
>  		break;							\
> +	case 8:								\
> +		__gu_err = __copy_from_user(&__gu_val, ptr, 8);		\
> +		if (__gu_err)						\
> +			__gu_err = -EFAULT;				\
> +		break;							\
>  	default:							\
>  		/* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\
>  	}								\
> 
> 

Applied.

Thanks,
Michal




[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-18  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-17  1:39 [PATCH] arch/microblaze: support get_user() of size 8 bytes Randy Dunlap
2019-09-18  7:49 ` Michal Simek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).