[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAK8P3a1=udSEq8kpsmLk-b7ye0p=6eKTvBV74jBoGYmufL2oEw@mail.gmail.com>
Date: Fri, 4 Sep 2020 20:04:34 +0200
From: Arnd Bergmann <arnd@...db.de>
To: Christoph Hellwig <hch@....de>
Cc: Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Alexander Viro <viro@...iv.linux.org.uk>,
linux-riscv <linux-riscv@...ts.infradead.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
linux-arch <linux-arch@...r.kernel.org>
Subject: Re: [PATCH 3/8] asm-generic: fix unaligned access hamdling in raw_copy_{from,to}_user
On Fri, Sep 4, 2020 at 6:52 PM Christoph Hellwig <hch@....de> wrote:
>
> Use get_unaligned and put_unaligned for the small constant size cases
> in the generic uaccess routines. This ensures they can be used for
> architectures that do not support unaligned loads and stores, while
> being a no-op for those that do.
>
> Signed-off-by: Christoph Hellwig <hch@....de>
> ---
> include/asm-generic/uaccess.h | 20 ++++++++------------
> 1 file changed, 8 insertions(+), 12 deletions(-)
>
> diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
> index cc3b2c8b68fab4..768502bbfb154e 100644
> --- a/include/asm-generic/uaccess.h
> +++ b/include/asm-generic/uaccess.h
> @@ -36,19 +36,17 @@ raw_copy_from_user(void *to, const void __user * from, unsigned long n)
> if (__builtin_constant_p(n)) {
> switch(n) {
> case 1:
> - *(u8 *)to = *(u8 __force *)from;
> + *(u8 *)to = get_unaligned((u8 __force *)from);
> return 0;
> case 2:
> - *(u16 *)to = *(u16 __force *)from;
> + *(u16 *)to = get_unaligned((u16 __force *)from);
> return 0;
The change look correct and necessary, but I wonder if this could be done
in a way that is a little easier on the compiler than the nested switch/case.
If I see it right, __put_user() and __get_user() can probably
be reduced to a plain put_unaligned() and get_unaligned() here,
which would simplify these a lot.
In turn it seems that the generic raw_copy_to_user() can just be the
a plain memcpy(), IIRC the optimization for small sizes should also
be done by modern compilers whenever they can.
Arnd
Powered by blists - more mailing lists