[PATCH 2/2] riscv: uaccess: do not do misaligned accesses in get/put_user()
Maciej W. Rozycki
macro at orcam.me.uk
Sun Jun 1 10:35:13 PDT 2025
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.
Maciej
More information about the linux-riscv
mailing list