Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756580AbeAHKpq (ORCPT + 1 other); Mon, 8 Jan 2018 05:45:46 -0500 Received: from merlin.infradead.org ([205.233.59.134]:49670 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756514AbeAHKpm (ORCPT ); Mon, 8 Jan 2018 05:45:42 -0500 Date: Mon, 8 Jan 2018 11:45:12 +0100 From: Peter Zijlstra To: David Woodhouse Cc: Andi Kleen , Paul Turner , LKML , Linus Torvalds , Greg Kroah-Hartman , Tim Chen , Dave Hansen , tglx@linutronix.de, Kees Cook , Rik van Riel , Andy Lutomirski , Jiri Kosina , gnomes@lxorguk.ukuu.org.uk Subject: Re: [PATCH v6 01/10] x86/retpoline: Add initial retpoline support Message-ID: <20180108104512.GG3040@hirez.programming.kicks-ass.net> References: <1515363085-4219-1-git-send-email-dwmw@amazon.co.uk> <1515363085-4219-2-git-send-email-dwmw@amazon.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1515363085-4219-2-git-send-email-dwmw@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 Sun, Jan 07, 2018 at 10:11:16PM +0000, David Woodhouse wrote: > +#ifdef __ASSEMBLY__ > + > +/* > + * These are the bare retpoline primitives for indirect jmp and call. > + * Do not use these directly; they only exist to make the ALTERNATIVE > + * invocation below less ugly. > + */ > +.macro RETPOLINE_JMP reg:req > + call 1112f > +1111: pause > + jmp 1111b > +1112: mov \reg, (%_ASM_SP) > + ret > +.endm Should this not use local name labels instead? .macro RETPOLINE_JMP reg:req call .Ldo_rop_\@ .Lspec_trap_\@: pause jmp .Lspec_trap_\@ .Ldo_rop_\@: mov \reg, (%_ASM_SP) ret .endm And I suppose it might be nice to put a little comment with them explaining how they work. > +/* > + * For i386 we use the original ret-equivalent retpoline, because > + * otherwise we'll run out of registers. We don't care about CET > + * here, anyway. > + */ > +# define NOSPEC_CALL ALTERNATIVE( \ > + "call *%[thunk_target]\n", \ > + " jmp 1113f; " \ > + "1110: call 1112f; " \ > + "1111: pause; " \ > + " jmp 1111b; " \ > + "1112: addl $4, %%esp; " \ > + " pushl %[thunk_target]; " \ > + " ret; " \ > + "1113: call 1110b;\n", \ > + X86_FEATURE_RETPOLINE) Ideally this would too, just not sure that works in inline asm.