Re: [RFC PATCH] Drop some asm from copy_user_64.S

From: Linus Torvalds
Date: Wed May 13 2015 - 12:02:46 EST

On Wed, May 13, 2015 at 2:52 AM, Borislav Petkov <bp@xxxxxxxxx> wrote:
> Now we CALL _copy_*_user which does CALL the optimal alternative
> version. Advantage is that we're saving some space and alternatives
> application for copy_user* is being done in less places, i.e.
> arch/x86/lib/uaccess_64.c. If I move all copy_user_generic() callers
> there, it would be the only compilation unit where the alternatives will
> be done.
> The disadvantage is that we have CALL after CALL and I wanted to have a
> single CALL directly to the optimal copy_user function. That'll cost us
> space, though, and more alternatives sites to patch during boot...
> Thoughts?

So I think we should do this first call-to-call thing, because it
makes it easier to go to the second step: replace the final call with
a asm-alternative that just puts the "rep movsb" inline for the (more
and more common) case of X86_FEATURE_ERMS.

The nice thing about using "rep movsb" for the user copy is that not
only is it fairly close to optimal (for non-constant sizes) on newer
Intel CPU's, but the fixup is also trivial. So we really should inline
it. Just look at it: the copy_user_enhanced_fast_string function is
literally just three 2-byte instructions right now:

mov %edx,%ecx
rep movsb
xor %eax,%eax

and the rest is just the exception table thing.

(And yes, there's the STAC/CLAC thing around it, but I think that
should just be moved into _copy_from/to_user() too, since *all* of the
copy_user_generic() cases need it).

Yeah, yeah, we'd still do the double call thing for the more complex
cases of the unrolled copy loop or the "movsq + tail" cases, but those
are at least big enough that it makes sense. And they are presumably
getting less common anyway.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at