From: Palmer Dabbelt <palmer@dabbelt.com>
To: Christoph Hellwig <hch@lst.de>
Cc: linux-arch@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, viro@zeniv.linux.org.uk,
Paul Walmsley <paul.walmsley@sifive.com>,
linux-riscv@lists.infradead.org
Subject: Re: [PATCH 6/8] riscv: refactor __get_user and __put_user
Date: Tue, 08 Sep 2020 21:59:25 -0700 (PDT) [thread overview]
Message-ID: <mhng-e4978c15-9e83-4621-a9e6-76a550f6dcda@palmerdabbelt-glaptop1> (raw)
In-Reply-To: <20200907055825.1917151-7-hch@lst.de>
On Sun, 06 Sep 2020 22:58:23 PDT (-0700), Christoph Hellwig wrote:
> Add new __get_user_nocheck and __put_user_nocheck that switch on the size
> and call the actual inline assembly helpers, and move the uaccess enable
> / disable into the actual __get_user and __put_user. This prepares for
> natively implementing __get_kernel_nofault and __put_kernel_nofault.
>
> Also don't bother with the deprecated register keyword for the error
> return.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> arch/riscv/include/asm/uaccess.h | 94 ++++++++++++++++++--------------
> 1 file changed, 52 insertions(+), 42 deletions(-)
>
> diff --git a/arch/riscv/include/asm/uaccess.h b/arch/riscv/include/asm/uaccess.h
> index e8eedf22e90747..b67d1c616ec348 100644
> --- a/arch/riscv/include/asm/uaccess.h
> +++ b/arch/riscv/include/asm/uaccess.h
> @@ -107,7 +107,6 @@ static inline int __access_ok(unsigned long addr, unsigned long size)
> do { \
> uintptr_t __tmp; \
> __typeof__(x) __x; \
> - __enable_user_access(); \
> __asm__ __volatile__ ( \
> "1:\n" \
> " " insn " %1, %3\n" \
> @@ -125,7 +124,6 @@ do { \
> " .previous" \
> : "+r" (err), "=&r" (__x), "=r" (__tmp) \
> : "m" (*(ptr)), "i" (-EFAULT)); \
> - __disable_user_access(); \
> (x) = __x; \
> } while (0)
>
> @@ -138,7 +136,6 @@ do { \
> u32 __user *__ptr = (u32 __user *)(ptr); \
> u32 __lo, __hi; \
> uintptr_t __tmp; \
> - __enable_user_access(); \
> __asm__ __volatile__ ( \
> "1:\n" \
> " lw %1, %4\n" \
> @@ -162,12 +159,30 @@ do { \
> "=r" (__tmp) \
> : "m" (__ptr[__LSW]), "m" (__ptr[__MSW]), \
> "i" (-EFAULT)); \
> - __disable_user_access(); \
> (x) = (__typeof__(x))((__typeof__((x)-(x)))( \
> (((u64)__hi << 32) | __lo))); \
> } while (0)
> #endif /* CONFIG_64BIT */
>
> +#define __get_user_nocheck(x, __gu_ptr, __gu_err) \
> +do { \
> + switch (sizeof(*__gu_ptr)) { \
> + case 1: \
> + __get_user_asm("lb", (x), __gu_ptr, __gu_err); \
> + break; \
> + case 2: \
> + __get_user_asm("lh", (x), __gu_ptr, __gu_err); \
> + break; \
> + case 4: \
> + __get_user_asm("lw", (x), __gu_ptr, __gu_err); \
> + break; \
> + case 8: \
> + __get_user_8((x), __gu_ptr, __gu_err); \
> + break; \
> + default: \
> + BUILD_BUG(); \
> + } \
> +} while (0)
>
> /**
> * __get_user: - Get a simple variable from user space, with less checking.
> @@ -191,25 +206,15 @@ do { \
> */
> #define __get_user(x, ptr) \
> ({ \
> - register long __gu_err = 0; \
> const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
> + long __gu_err = 0; \
> + \
> __chk_user_ptr(__gu_ptr); \
> - switch (sizeof(*__gu_ptr)) { \
> - case 1: \
> - __get_user_asm("lb", (x), __gu_ptr, __gu_err); \
> - break; \
> - case 2: \
> - __get_user_asm("lh", (x), __gu_ptr, __gu_err); \
> - break; \
> - case 4: \
> - __get_user_asm("lw", (x), __gu_ptr, __gu_err); \
> - break; \
> - case 8: \
> - __get_user_8((x), __gu_ptr, __gu_err); \
> - break; \
> - default: \
> - BUILD_BUG(); \
> - } \
> + \
> + __enable_user_access(); \
> + __get_user_nocheck(x, __gu_ptr, __gu_err); \
> + __disable_user_access(); \
> + \
> __gu_err; \
> })
>
> @@ -243,7 +248,6 @@ do { \
> do { \
> uintptr_t __tmp; \
> __typeof__(*(ptr)) __x = x; \
> - __enable_user_access(); \
> __asm__ __volatile__ ( \
> "1:\n" \
> " " insn " %z3, %2\n" \
> @@ -260,7 +264,6 @@ do { \
> " .previous" \
> : "+r" (err), "=r" (__tmp), "=m" (*(ptr)) \
> : "rJ" (__x), "i" (-EFAULT)); \
> - __disable_user_access(); \
> } while (0)
>
> #ifdef CONFIG_64BIT
> @@ -272,7 +275,6 @@ do { \
> u32 __user *__ptr = (u32 __user *)(ptr); \
> u64 __x = (__typeof__((x)-(x)))(x); \
> uintptr_t __tmp; \
> - __enable_user_access(); \
> __asm__ __volatile__ ( \
> "1:\n" \
> " sw %z4, %2\n" \
> @@ -294,10 +296,28 @@ do { \
> "=m" (__ptr[__LSW]), \
> "=m" (__ptr[__MSW]) \
> : "rJ" (__x), "rJ" (__x >> 32), "i" (-EFAULT)); \
> - __disable_user_access(); \
> } while (0)
> #endif /* CONFIG_64BIT */
>
> +#define __put_user_nocheck(x, __gu_ptr, __pu_err) \
> +do { \
> + switch (sizeof(*__gu_ptr)) { \
> + case 1: \
> + __put_user_asm("sb", (x), __gu_ptr, __pu_err); \
> + break; \
> + case 2: \
> + __put_user_asm("sh", (x), __gu_ptr, __pu_err); \
> + break; \
> + case 4: \
> + __put_user_asm("sw", (x), __gu_ptr, __pu_err); \
> + break; \
> + case 8: \
> + __put_user_8((x), __gu_ptr, __pu_err); \
> + break; \
> + default: \
> + BUILD_BUG(); \
> + } \
> +} while (0)
>
> /**
> * __put_user: - Write a simple value into user space, with less checking.
> @@ -320,25 +340,15 @@ do { \
> */
> #define __put_user(x, ptr) \
> ({ \
> - register long __pu_err = 0; \
> __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
> + long __pu_err = 0; \
> + \
> __chk_user_ptr(__gu_ptr); \
> - switch (sizeof(*__gu_ptr)) { \
> - case 1: \
> - __put_user_asm("sb", (x), __gu_ptr, __pu_err); \
> - break; \
> - case 2: \
> - __put_user_asm("sh", (x), __gu_ptr, __pu_err); \
> - break; \
> - case 4: \
> - __put_user_asm("sw", (x), __gu_ptr, __pu_err); \
> - break; \
> - case 8: \
> - __put_user_8((x), __gu_ptr, __pu_err); \
> - break; \
> - default: \
> - BUILD_BUG(); \
> - } \
> + \
> + __enable_user_access(); \
> + __put_user_nocheck(x, __gu_ptr, __pu_err); \
> + __disable_user_access(); \
> + \
> __pu_err; \
> })
Reviewed-by: Palmer Dabbelt <palmerdabbelt@google.com>
Acked-by: Palmer Dabbelt <palmerdabbelt@google.com>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2020-09-09 4:59 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-07 5:58 remove set_fs for riscv v2 Christoph Hellwig
2020-09-07 5:58 ` [PATCH 1/8] uaccess: provide a generic TASK_SIZE_MAX definition Christoph Hellwig
2020-09-07 5:58 ` [PATCH 2/8] asm-generic: improve the nommu {get,put}_user handling Christoph Hellwig
2020-09-07 5:58 ` [PATCH 3/8] asm-generic: add nommu implementations of __{get, put}_kernel_nofault Christoph Hellwig
2020-09-07 5:58 ` [PATCH 4/8] asm-generic: make the set_fs implementation optional Christoph Hellwig
2020-09-07 5:58 ` [PATCH 5/8] riscv: use memcpy based uaccess for nommu again Christoph Hellwig
2020-09-09 4:59 ` Palmer Dabbelt
2020-09-07 5:58 ` [PATCH 6/8] riscv: refactor __get_user and __put_user Christoph Hellwig
2020-09-09 4:59 ` Palmer Dabbelt [this message]
2020-09-07 5:58 ` [PATCH 7/8] riscv: implement __get_kernel_nofault and __put_user_nofault Christoph Hellwig
2020-09-09 4:59 ` Palmer Dabbelt
2020-09-07 5:58 ` [PATCH 8/8] riscv: remove address space overrides using set_fs() Christoph Hellwig
2020-09-09 4:59 ` Palmer Dabbelt
2020-09-09 4:59 ` remove set_fs for riscv v2 Palmer Dabbelt
2020-09-09 6:55 ` Christoph Hellwig
2020-09-09 20:38 ` Palmer Dabbelt
2020-09-22 4:37 ` Christoph Hellwig
2020-09-26 17:50 ` Palmer Dabbelt
2020-09-26 19:13 ` Arnd Bergmann
2020-10-04 17:27 ` Palmer Dabbelt
2020-09-28 12:49 ` Christoph Hellwig
2020-09-28 16:45 ` Palmer Dabbelt
2020-09-29 18:03 ` Christoph Hellwig
2020-09-26 6:58 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2020-09-04 16:52 remove set_fs for riscv Christoph Hellwig
2020-09-04 16:52 ` [PATCH 6/8] riscv: refactor __get_user and __put_user Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=mhng-e4978c15-9e83-4621-a9e6-76a550f6dcda@palmerdabbelt-glaptop1 \
--to=palmer@dabbelt.com \
--cc=arnd@arndb.de \
--cc=hch@lst.de \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=paul.walmsley@sifive.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).