Re: [PATCH] x86/uaccess: use unrolled string copy for short strings

From: Linus Torvalds
Date: Thu Jun 22 2017 - 13:30:12 EST


On Wed, Jun 21, 2017 at 4:09 AM, Paolo Abeni <pabeni@xxxxxxxxxx> wrote:
>
> + if (len <= 64)
> + return copy_user_generic_unrolled(to, from, len);
> +
> /*
> * If CPU has ERMS feature, use copy_user_enhanced_fast_string.
> * Otherwise, if CPU has rep_good feature, use copy_user_generic_string.

NAK. Please do *not* do this. It puts the check in completely the
wrong place for several reasons:

(a) it puts it in the inlined caller case (which could be ok for
constant sizes, but not in general)

(b) it uses the copy_user_generic_unrolled() function that will then
just test the size *AGAIN* against small cases.

so it's both bigger than necessary, and stupid.

So if you want to do this optimization, I'd argue that you should just
do it inside the copy_user_enhanced_fast_string() function itself, the
same way we already handle the really small case specially in
copy_user_generic_string().

And do *not* use the unrolled code, which isn't used for small copies
anyway - rewrite the "copy_user_generic_unrolled" function in that
same asm file to have the non-unrolled cases (label "17" and forward)
accessible, so that you don't bother re-testing the size.

Linus