Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753678AbeAGLq5 (ORCPT + 1 other); Sun, 7 Jan 2018 06:46:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:43445 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753303AbeAGLq4 (ORCPT ); Sun, 7 Jan 2018 06:46:56 -0500 Date: Sun, 7 Jan 2018 12:46:45 +0100 From: Borislav Petkov To: David Woodhouse Cc: Josh Poimboeuf , "tglx@linutronix.de" , "linux-kernel@vger.kernel.org" , "tim.c.chen@linux.intel.com" , "peterz@infradead.org" , "torvalds@linux-foundation.org" , "ak@linux.intel.com" , "riel@redhat.com" , "keescook@google.com" , "gnomes@lxorguk.ukuu.org.uk" , "pjt@google.com" , "dave.hansen@intel.com" , "luto@amacapital.net" , "jikos@kernel.org" , "gregkh@linux-foundation.org" Subject: Re: [PATCH v3 01/13] x86/retpoline: Add initial retpoline support Message-ID: <20180107114645.yydecgoi4x53fyrd@pd.tnic> References: <20180104143710.8961-1-dwmw@amazon.co.uk> <1515160619.29312.126.camel@amazon.co.uk> <1515170506.29312.149.camel@amazon.co.uk> <20180105164505.xpw5pefxsyu3z56e@pd.tnic> <20180105170806.mtylu2zagfxyj3ry@treble> <20180106003059.jhwx4ouc7xbt7yw6@pd.tnic> <1515227001.29312.205.camel@infradead.org> <20180106170243.ndkn3bfj5ezbijdd@pd.tnic> <1515318042.29312.311.camel@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1515318042.29312.311.camel@infradead.org> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Sun, Jan 07, 2018 at 09:40:42AM +0000, David Woodhouse wrote: > Right, so it all tends to work out OK purely by virtue of the fact that > oldinstr and altinstr end up far enough apart in the image that they're > 5-byte jumps. Which isn't perfect but we've lived with worse. Well, the reference point is important. And I don't think we've done more involved things than jumping back to something in .text proper. However, I think I know how to fix this so that arbitrary jump offsets would work but I need to talk to our gcc guys first. If the jump is close enough for 2 bytes, then it should work as long as the offset to the target doesn't change. The main thing recompute_jumps() does is turn 5-byte jumps - which gas creates because the jump target is in .text but the jump itself is in .altinstr_replacement - into 2-byte ones. Because when you copy the jump back into .text, the offset might fit in a signed byte all of a sudden. There are still some nasties with forcing 5-byte jumps but I think I know how to fix those. Stay tuned... > I'm relatively pleased that we've managed to eliminate this as a > dependency for inverting the X86_FEATURE_RETPOLINE logic though, by > following Linus' suggestion to just emit the thunk inline instead of > calling the same one as GCC. > > The other fun one for alternatives is in entry_64.S, where we really > need the return address of the call instruction to be *precisely* the  > .Lentry_SYSCALL_64_after_fastpath_call label, so we have to eschew the > normal NOSPEC_CALL there: So CALL, as the doc says, pushes the offset of the *next* insn onto the stack and branches to the target address. So I'm thinking, as long as the next insn doesn't move and gcc doesn't pad anything, you're fine. However, I suspect that I'm missing something else here and I guess I'll have more clue if I look at the whole thing. So can you point me to your current branch so that I can take a look at the code? Thx. -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --