Re: [PATCH v2 07/15] x86/lib/copy_user_64.S: Convert to ALTERNATIVE_2

From: Ingo Molnar
Date: Wed Mar 04 2015 - 02:13:34 EST



* Ingo Molnar <mingo@xxxxxxxxxx> wrote:

>
> * Borislav Petkov <bp@xxxxxxxxx> wrote:
>
> > From: Borislav Petkov <bp@xxxxxxx>
> >
> > Use the asm macro and drop the locally grown version.
>
> > @@ -73,9 +49,11 @@ ENTRY(_copy_to_user)
> > jc bad_to_user
> > cmpq TI_addr_limit(%rax),%rcx
> > ja bad_to_user
> > + ALTERNATIVE_2 "jmp copy_user_generic_unrolled", \
> > + "jmp copy_user_generic_string", \
> > + X86_FEATURE_REP_GOOD, \
> > + "jmp copy_user_enhanced_fast_string", \
> > + X86_FEATURE_ERMS
>
> Btw., as a future optimization, wouldn't it be useful to patch this
> function at its first instruction, i.e. to have three fully functional
> copy_user_generic_ variants and choose to jmp to one of them in the
> first instruction of the original function?
>
> The advantage would be two-fold:
>
> 1) right now: smart microarchitectures that are able to optimize
> jump-after-jump (and jump-after-call) targets in their branch
> target cache can do so in this case, reducing the overhead of the
> patching, possibly close to zero in the cached case.

Btw., the x86 memset() variants are using this today, and I think this
is the most optimal jump-patching variant, even if it means a small
amount of code duplication between the copy_user variants.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/