From: "Clément Léger" <cleger@rivosinc.com>
To: Alexandre Ghiti <alex@ghiti.fr>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>
Subject: Re: [PATCH 0/2] riscv: misaligned: fix misaligned accesses handling in put/get_user()
Date: Mon, 2 Jun 2025 09:19:45 +0200 [thread overview]
Message-ID: <01a5ab11-ed87-4d30-a162-987db34e6483@rivosinc.com> (raw)
In-Reply-To: <1aefb8dc-9145-4cee-b262-7d4212159444@ghiti.fr>
On 31/05/2025 15:32, Alexandre Ghiti wrote:
> On 5/30/25 22:56, Clément Léger wrote:
>> While debugging a few problems with the misaligned access kselftest,
>> Alexandre discovered some crash with the current code. Indeed, some
>> misaligned access was done by the kernel using put_user(). This
>> was resulting in trap and a kernel crash since. The path was the
>> following:
>> user -> kernel -> access to user memory -> misaligned trap -> trap ->
>> kernel -> misaligned handling -> memcpy -> crash due to failed page fault
>> while in interrupt disabled section.
>>
>> Last discussion about kernel misaligned handling and interrupt reenabling
>> were actually not to reenable interrupt when handling misaligned access
>> being done by kernel. The best solution being not to do any misaligned
>> accesses to userspace memory, we considered a few options:
>>
>> - Remove any call to put/get_user() potientally doing misaligned
>> accesses
>> - Do not do any misaligned accesses in put/get_user() itself
>>
>> The second solution was the one chosen as there are too many callsite to
>> put/get_user() that could potentially do misaligned accesses. We tried
>> two approaches for that, either split access in two aligned accesses
>> (and do RMW for put_user()) or call copy_from/to_user() which does not
>> do any misaligned accesses. The later one was the simpler to implement
>> (although the performances are probably lower than split aligned
>> accesses but still way better than doing misaligned access emulation)
>> and allows to support what we wanted.
>>
>> These commits are based on top of Alex dev/alex/get_user_misaligned_v1
>> branch.
>>
>> Clément Léger (2):
>> riscv: process: use unsigned int instead of unsigned long for
>> put_user()
>> riscv: uaccess: do not do misaligned accesses in get/put_user()
>>
>> arch/riscv/include/asm/uaccess.h | 28 ++++++++++++++++++++++------
>> arch/riscv/kernel/process.c | 2 +-
>> 2 files changed, 23 insertions(+), 7 deletions(-)
>
>
> We also need to prevent unsafe routines to trigger misaligned accesses,
> I have a patch for this here https://github.com/linux-riscv/linux/
> commit/7c172121aeb235dedeb6f5e06740527530edd6af
>
> Clément, can you add this one to the series please?
Yep sure.
>
> I have just triggered a CI with those fixes on top of my sbi 3.0 branch.
>
> Thanks,
>
> Alex
>
>
prev parent reply other threads:[~2025-06-02 7:19 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-30 20:56 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
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 [this message]
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=01a5ab11-ed87-4d30-a162-987db34e6483@rivosinc.com \
--to=cleger@rivosinc.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--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®