Re: [PATCH] x86: add back the alignment of the destination to 8 bytes in copy_user_generic()

From: Linus Torvalds
Date: Mon Mar 17 2025 - 17:29:33 EST


On Mon, 17 Mar 2025 at 06:16, David Laight <david.laight.linux@xxxxxxxxx> wrote:
>
> You can also something similar for any trailing bytes.
> If you are feeling 'brave' copy the last 8 bytes first.

I think that would be a mistake.

Not only does ti cause bad patterns on page faults - we should recover
ok from it (the exception will go back and do the copy in the right
order one byte at a time in the "copy_user_tail" code) - but even in
the absence of page faults it quite possibly messes with CPU
prefetching and write buffer coalescing etc if you hop around like
that.

It *might* be worth trying doing last unaligned part the same way my
patch does the first one - by just doing a full-word write at the end,
offset backwards. That avoids the byte-at-a-time tail case.

I'm not convinced it's worth it, but if somebody spends the effort on
a patch and on benchmarking...

Linus