Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932375AbeAKImy (ORCPT + 1 other); Thu, 11 Jan 2018 03:42:54 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:56156 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932138AbeAKImx (ORCPT ); Thu, 11 Jan 2018 03:42:53 -0500 Date: Thu, 11 Jan 2018 09:42:38 +0100 From: Peter Zijlstra To: "Woodhouse, David" Cc: "ak@linux.intel.com" , "tim.c.chen@linux.intel.com" , "linux-kernel@vger.kernel.org" , "torvalds@linux-foundation.org" , "tglx@linutronix.de" , "x86@kernel.org" , "riel@redhat.com" , "keescook@google.com" , "gnomes@lxorguk.ukuu.org.uk" , "pjt@google.com" , "Ghitulete, Razvan-alin" , "bp@alien8.de" , "dave.hansen@intel.com" , "luto@amacapital.net" , "jikos@kernel.org" , "gregkh@linux-foundation.org" Subject: Re: [PATCH] x86/retpoline: Fill return stack buffer on vmexit Message-ID: <20180111084238.GT6176@hirez.programming.kicks-ass.net> References: <1515624682-3556-1-git-send-email-dwmw@amazon.co.uk> <5371f9a0-f221-af1f-641f-05e4d0991847@linux.intel.com> <1515629074.22302.282.camel@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1515629074.22302.282.camel@amazon.co.uk> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Thu, Jan 11, 2018 at 12:04:35AM +0000, Woodhouse, David wrote: > On Wed, 2018-01-10 at 15:47 -0800, Tim Chen wrote: > > > > > + > > > +?????asm volatile (ALTERNATIVE("", > > > +?????????????????????????????? __stringify(__FILL_RETURN_BUFFER(%0, %1, _%=)), > > > +?????????????????????????????? X86_FEATURE_RETPOLINE) > > > > We'll be patching in a fairly long set of instructions here.? Maybe put > > the ALTERNATIVE in the assembly and use a jmp skip_\@ for the ALTERNATIVE. > > Perhaps the alternatives.h header could give me a clean way of doing this: > > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -177,7 +178,7 @@ static inline void vmexit_fill_RSB(void) > ?{ > ????????unsigned long dummy; > ? > -???????asm volatile (ALTERNATIVE("", > +???????asm volatile (ALTERNATIVE("jmp " alt_end_marker "f", > ??????????????????????????????????__stringify(__FILL_RETURN_BUFFER(%0, %1, _%=)), > ??????????????????????????????????X86_FEATURE_RETPOLINE) > ??????????????????????: "=r" (dummy), ASM_CALL_CONSTRAINT : : "memory" ); Or we teach the alternative thing to patch in a jmp to end instead of NOP padding the entire thing as soon as the jmp (3 bytes) fits ?