Re: [PATCH] x86: __memcpy_flushcache: fix wrong alignment if size > 2^32

From: Linus Torvalds
Date: Tue Apr 19 2022 - 13:14:21 EST


On Tue, Apr 19, 2022 at 6:56 AM Mikulas Patocka <mpatocka@xxxxxxxxxx> wrote:
>
> The first "if" condition in __memcpy_flushcache is supposed to align the
> "dest" variable to 8 bytes and copy data up to this alignment. However,
> this condition may misbehave if "size" is greater than 4GiB.

You're not wrong, but I also don't think it would be wrong to just have a

if (WARN_ON_ONCE(size > MAX_INT))
return;

in there instead.

It' not like "> 2**32" should ever really be a valid thing for any
kind of copy in the kernel. Even if that were to be what you actually
wanted to do (which sounds very unlikely), you'd need to split it up
with cond_resched() just for latency reasons.

Linus