From patchwork Thu Nov 15 22:01:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 12876 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9AA8B23FC0 for ; Thu, 15 Nov 2012 22:01:27 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 21AA5A190E9 for ; Thu, 15 Nov 2012 22:01:27 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so2608022iej.11 for ; Thu, 15 Nov 2012 14:01:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=3RBl16ke6bstVYLHGjkzE0AWG2UcED38/jJ4zBvHgGM=; b=hQkIFNzWjANMkmQ9MosN5T1aSYp7oc/yO/HbpWAUVbq5GBFiDROd8SuqmlJL4IpQDx C9YH5+jETG4YvxlEiHHkmviUhtPm89+0BeZaxDjYx4RghoRYsty2SNnsEs/U/SbjA/uB h+aZ8wnMVhjaQ2jufFbLuLhpGGpvyJKvvbpEh1vXa71MPw/dT+Sl1WqPdbGAOYURdYJV LjplNwdQm0KXZossXcdZA0HuB8JnTUCV7aHoFCY2nBjGnr+eaVr/wKiq+GrVgmd2R+fn zj4MV+jKotbdo/F6mUKV8mnaJ66pOZrHQDj38+bMClaw94TsMX4KwnVjouMrTyUP5Rsy Wu5w== Received: by 10.43.7.132 with SMTP id oo4mr2096211icb.6.1353016886439; Thu, 15 Nov 2012 14:01:26 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp860870igt; Thu, 15 Nov 2012 14:01:26 -0800 (PST) Received: by 10.182.157.45 with SMTP id wj13mr2233475obb.58.1353016885195; Thu, 15 Nov 2012 14:01:25 -0800 (PST) Received: from mail-ob0-f172.google.com (mail-ob0-f172.google.com [209.85.214.172]) by mx.google.com with ESMTPS id c7si16895300obv.132.2012.11.15.14.01.24 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 14:01:25 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.214.172 as permitted sender) client-ip=209.85.214.172; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.214.172 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-ob0-f172.google.com with SMTP id ef5so2310499obb.31 for ; Thu, 15 Nov 2012 14:01:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=3RBl16ke6bstVYLHGjkzE0AWG2UcED38/jJ4zBvHgGM=; b=a2uGKS7vMstuEvyAoRbayKBXgpJ8l1i1EDpD7dKZyYXGS6SwHzZ0Sm94x+1hQVmjKz QStOj0G0gk5oHC3ggsb47PVsfk2+zqIoPwPZWP2iSArxx7wA0xaKEjbWxH5eCeAUnqHc kKB5GQAKQYxVxnH3R8O3RerwQCcKxJ8XP0NFXJSqUAQ38e10xr0wVy5A+GPuJhJO0MR5 tDEf7+3utevrK4TEW7xD8Xwaogk+U/642SqWw/PrtmGnR5ji4xv4n009viFoZvANsP2x QIru2C3AnC80KZkIdntQmglZwWKrg0y3UQ4/54a+Ki9DogrLEbx9OKWxJ4ZhlIMzLX16 K+dQ== Received: by 10.60.169.133 with SMTP id ae5mr2170565oec.74.1353016884848; Thu, 15 Nov 2012 14:01:24 -0800 (PST) Received: from localhost (ppp-70-129-143-201.dsl.rcsntx.swbell.net. [70.129.143.201]) by mx.google.com with ESMTPS id w2sm13373268oeb.1.2012.11.15.14.01.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Nov 2012 14:01:23 -0800 (PST) Sender: Rob Clark From: Rob Clark To: linux-arm-kernel@lists.infradead.org Cc: patches@linaro.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, dri-devel@lists.freedesktop.org, Arnd Bergmann , Russell King , Rob Clark Subject: [PATCH] ARM: add get_user() support for 8 byte types Date: Thu, 15 Nov 2012 16:01:19 -0600 Message-Id: <1353016879-15007-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.8.0 X-Gm-Message-State: ALoCoQmr8pu+4OLd0CStPb7hr8N+iTd2r0C2tBqEh8BBKWsX976cLRYEYb7cKuP+8I+2b0EmXp9H From: Rob Clark A new atomic modeset/pageflip ioctl being developed in DRM requires get_user() to work for 64bit types (in addition to just put_user()). v1: original v2: pass correct size to check_uaccess, and better handling of narrowing double word read with __get_user_xb() (Russell King's suggestion) v3: explain in comment about why this works for narrowing fetch to 1, 2, or 4 byte type on ARM. Signed-off-by: Rob Clark Acked-by: Nicolas Pitre Acked-by: Arnd Bergmann --- arch/arm/include/asm/uaccess.h | 22 +++++++++++++++++++++- arch/arm/lib/getuser.S | 17 ++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h index 7e1f760..4cfa793 100644 --- a/arch/arm/include/asm/uaccess.h +++ b/arch/arm/include/asm/uaccess.h @@ -100,6 +100,7 @@ static inline void set_fs(mm_segment_t fs) extern int __get_user_1(void *); extern int __get_user_2(void *); extern int __get_user_4(void *); +extern int __get_user_8(void *); #define __GUP_CLOBBER_1 "lr", "cc" #ifdef CONFIG_CPU_USE_DOMAINS @@ -108,6 +109,7 @@ extern int __get_user_4(void *); #define __GUP_CLOBBER_2 "lr", "cc" #endif #define __GUP_CLOBBER_4 "lr", "cc" +#define __GUP_CLOBBER_8 "lr", "cc" #define __get_user_x(__r2,__p,__e,__l,__s) \ __asm__ __volatile__ ( \ @@ -118,11 +120,23 @@ extern int __get_user_4(void *); : "0" (__p), "r" (__l) \ : __GUP_CLOBBER_##__s) +/* + * Narrowing a double-word get into a single 32bit word register, which works + * for 1, 2, or 4 byte types on ARM because there are no integer registers + * smaller than 32bit + */ +#ifdef BIG_ENDIAN +#define __get_user_xb(__r2,__p,__e,__l,__s) \ + __get_user_x(__r2,(uintptr_t)__p + 4,__e,__l,__s) +#else +#define __get_user_xb __get_user_x +#endif + #define __get_user_check(x,p) \ ({ \ unsigned long __limit = current_thread_info()->addr_limit - 1; \ register const typeof(*(p)) __user *__p asm("r0") = (p);\ - register unsigned long __r2 asm("r2"); \ + register typeof(x) __r2 asm("r2"); \ register unsigned long __l asm("r1") = __limit; \ register int __e asm("r0"); \ switch (sizeof(*(__p))) { \ @@ -135,6 +149,12 @@ extern int __get_user_4(void *); case 4: \ __get_user_x(__r2, __p, __e, __l, 4); \ break; \ + case 8: \ + if (sizeof((x)) < 8) \ + __get_user_xb(__r2, __p, __e, __l, 4); \ + else \ + __get_user_x(__r2, __p, __e, __l, 8); \ + break; \ default: __e = __get_user_bad(); break; \ } \ x = (typeof(*(p))) __r2; \ diff --git a/arch/arm/lib/getuser.S b/arch/arm/lib/getuser.S index 9b06bb4..ed98707 100644 --- a/arch/arm/lib/getuser.S +++ b/arch/arm/lib/getuser.S @@ -18,7 +18,7 @@ * Inputs: r0 contains the address * r1 contains the address limit, which must be preserved * Outputs: r0 is the error code - * r2 contains the zero-extended value + * r2, r3 contains the zero-extended value * lr corrupted * * No other registers must be altered. (see @@ -66,6 +66,19 @@ ENTRY(__get_user_4) mov pc, lr ENDPROC(__get_user_4) +ENTRY(__get_user_8) + check_uaccess r0, 8, r1, r2, __get_user_bad +#ifdef CONFIG_THUMB2_KERNEL +5: TUSER(ldr) r2, [r0] +6: TUSER(ldr) r3, [r0, #4] +#else +5: TUSER(ldr) r2, [r0], #4 +6: TUSER(ldr) r3, [r0] +#endif + mov r0, #0 + mov pc, lr +ENDPROC(__get_user_8) + __get_user_bad: mov r2, #0 mov r0, #-EFAULT @@ -77,4 +90,6 @@ ENDPROC(__get_user_bad) .long 2b, __get_user_bad .long 3b, __get_user_bad .long 4b, __get_user_bad + .long 5b, __get_user_bad + .long 6b, __get_user_bad .popsection