From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752431AbbEMQCn (ORCPT ); Wed, 13 May 2015 12:02:43 -0400 Received: from mail-ig0-f181.google.com ([209.85.213.181]:33252 "EHLO mail-ig0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751441AbbEMQCl (ORCPT ); Wed, 13 May 2015 12:02:41 -0400 MIME-Version: 1.0 In-Reply-To: <20150513095248.GD1517@pd.tnic> References: <20150512205750.GJ3497@pd.tnic> <20150512215320.GK3497@pd.tnic> <20150513095248.GD1517@pd.tnic> Date: Wed, 13 May 2015 09:02:41 -0700 X-Google-Sender-Auth: hQ5OGr6BMWoSX7aliZtXnJG024I Message-ID: Subject: Re: [RFC PATCH] Drop some asm from copy_user_64.S From: Linus Torvalds To: Borislav Petkov Cc: Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andy Lutomirski , Denys Vlasenko , lkml Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 13, 2015 at 2:52 AM, Borislav Petkov 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. Linus