mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Clément Léger" <cleger@rivosinc.com>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>,
	David Laight <david.laight.linux@gmail.com>
Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>
Subject: Re: [PATCH 2/2] riscv: uaccess: do not do misaligned accesses in get/put_user()
Date: Mon, 2 Jun 2025 09:35:30 +0200	[thread overview]
Message-ID: <ff60e791-7305-4ea8-8048-ff33316bf8f1@rivosinc.com> (raw)
In-Reply-To: <alpine.DEB.2.21.2506011830130.28395@angie.orcam.me.uk>



On 01/06/2025 19:35, Maciej W. Rozycki wrote:
> On Sat, 31 May 2025, David Laight wrote:
> 
>>> Such behavior was detected with GET_UNALIGN_CTL() that was doing
>>> a put_user() with an unsigned long* address that should have been an
>>> unsigned int*. Reenabling kernel misaligned access emulation is a bit
>>> risky and it would also degrade performances. Rather than doing that,
>>> we will try to avoid any misaligned accessed by using copy_from/to_user()
>>> which does not do any misaligned accesses. This can be done only for
>>> !CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS and thus allows to only generate
>>> a bit more code for this config.
>>
>> For get_user() you are much better off reading the two words that contain
>> the value and then doing 'shift' and 'or' to get the correct value.
>>
>> Even for put_user() doing the explicit byte accesses will be faster than
>> going though the generic copy_to/from_user() function.
> 
>  FWIW I think optimising copy_to/from_user for such cases would be a more 
> robust approach moving forward than sprinkling open-coded implementations 
> across code.

Hi Maciej,

Indeed, that's a good idea, we could optimize small copy in
copy_from/to_user so that will benefit all the users as well.

Thanks,

Clément

> 
>   Maciej


  reply	other threads:[~2025-06-02  7:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-30 20:56 [PATCH 0/2] riscv: misaligned: fix misaligned accesses handling in put/get_user() Clément Léger
2025-05-30 20:56 ` [PATCH 1/2] riscv: process: use unsigned int instead of unsigned long for put_user() Clément Léger
2025-05-31 12:29   ` Alexandre Ghiti
2025-05-30 20:56 ` [PATCH 2/2] riscv: uaccess: do not do misaligned accesses in get/put_user() Clément Léger
2025-05-31 12:35   ` Alexandre Ghiti
2025-06-02  7:37     ` Clément Léger
2025-06-02 15:22       ` Alexandre Ghiti
2025-05-31 18:28   ` David Laight
2025-06-01 17:35     ` Maciej W. Rozycki
2025-06-02  7:35       ` Clément Léger [this message]
2025-06-02  7:34     ` Clément Léger
2025-05-31 13:32 ` [PATCH 0/2] riscv: misaligned: fix misaligned accesses handling in put/get_user() Alexandre Ghiti
2025-06-02  7:19   ` Clément Léger

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=ff60e791-7305-4ea8-8048-ff33316bf8f1@rivosinc.com \
    --to=cleger@rivosinc.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=david.laight.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=macro@orcam.me.uk \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /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

all inboxes | Powered by JetHome®