Received: by 10.223.176.5 with SMTP id f5csp3131934wra; Mon, 29 Jan 2018 09:14:25 -0800 (PST) X-Google-Smtp-Source: AH8x224MU3pj1J/BlFSnWCTzs9y43dcOiQg2EaQn80IiBmo1o6YhpeMEh9ticTBJ/El96NErIb/O X-Received: by 2002:a17:902:6ac7:: with SMTP id i7-v6mr21983955plt.368.1517246064997; Mon, 29 Jan 2018 09:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517246064; cv=none; d=google.com; s=arc-20160816; b=OetPgrkOxekGgHjCBWK78MJGm+D9KQDO1fnrCjLyqhw2EfGhgR+8DYTwPyGePD6cvu IEbrMW5yWtfhAx6MpW36/HF9kKDuMG1kvQmOdHNwaaUjBWBjDLtWfFlad41DvfVsvSTY 9NeK2JiHHX8JjG7aVV0QXknaIvGPANY2DCKJAh3GdHCtvEiJwwalgubvB9XwFSKommZI LEfxIlha6sWhV9VEp8aCoQZTIfaDefqXs5UhFqdiZDdswd4TVTS6BLv6ue5FQJAgpfs8 r3Yy9y0BM7pi4YtFHyczQFN8c0XVHiYCgh3SNTseTrOboWiih5ZrLOK65LpXVxQfD8Iz QkwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=ZHwnvf86blW3cl9Jg6W3ez8M/F0eA1bXNU7NJllH4Po=; b=m7wbEjhB7ou7WnllUJmtv5ohgdTCsiM3Rf4HTT01hmrURn94B02Yut4GbLwIuMSihu kr7sY1dXh5K6MhqRrLaGH83VydH78EkgytNL+CGl24WOHPm4tE/ByvuUu9ki9dq2yjpz 19h/VDXyMVvFs5iNrWMLk3paElLl+8VjoULBBQT2DnGmXf/AzLTxbLwyUfPAwjD+N7Om vwXjjnFS/SBP6fdMV7j0dd02el5GOlJfQs20hE+d8+1qQrKEbwSvSQdQF4dqXYSNNtoH 4sGisWHxUrlXFV9Ke2dcYPKM7TjMyPQbA3aHYA78aZhm7/0zICbwDQvipe9Bgwrh2m5z WGMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=IKmZQL10; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si69591pgv.34.2018.01.29.09.14.09; Mon, 29 Jan 2018 09:14:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=IKmZQL10; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751402AbeA2RNn (ORCPT + 99 others); Mon, 29 Jan 2018 12:13:43 -0500 Received: from merlin.infradead.org ([205.233.59.134]:57674 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751249AbeA2RNm (ORCPT ); Mon, 29 Jan 2018 12:13:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZHwnvf86blW3cl9Jg6W3ez8M/F0eA1bXNU7NJllH4Po=; b=IKmZQL10djmT4d+SLXuU40JFtl 1ZOZV4bvLO+OzXxKEVNynq6v+6GoEKkrNIl43McUIyxVLmyP2GityRxDv9CqUivCM5bHwxI1oDMvn jnCjgcE/HBK/W8HVvDdPM7oM9gPFieEpVhirp1bEqXvh0jcV/4AWDy3YxmGDhgtvLpdoY6Wgc/kOb RpbPaAtGh2urwoC5wFqAWN5KffLAAIYWiqV1RPIux7mMuHPbpFV3Xr6dlesmWW5l18cyunUQo0yPe K4PD4Ylu2pwRG7TQ/2t4HfXvIEVm0LfyPM2BC/TeEJHoSDO1gKnTb+IyDFmSt05G0eOrvZ/HfszSo oc9pP9gA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.89 #1 (Red Hat Linux)) id 1egCzi-0002zB-Hb; Mon, 29 Jan 2018 17:13:22 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 44AEE2029B115; Mon, 29 Jan 2018 18:13:19 +0100 (CET) Date: Mon, 29 Jan 2018 18:13:19 +0100 From: Peter Zijlstra To: Borislav Petkov Cc: David Woodhouse , X86 ML , LKML , Josh Poimboeuf , tim.c.chen@linux.intel.com, pjt@google.com, jikos@kernel.org, gregkh@linux-foundation.org, dave.hansen@intel.com, riel@redhat.com, luto@amacapital.net, torvalds@linux-foundation.org, ak@linux.intel.com, keescook@google.com Subject: Re: [PATCH v2 1/2] x86/retpoline: Simplify vmexit_fill_RSB() Message-ID: <20180129171319.GG2228@hirez.programming.kicks-ass.net> References: <20180126121139.31959-1-bp@alien8.de> <20180126121139.31959-4-bp@alien8.de> <1516970011.30244.223.camel@infradead.org> <20180126132431.fsbd3c3g2yreazy6@pd.tnic> <1516983879.30244.236.camel@infradead.org> <20180126164746.dpo7dswid5tjk2tz@pd.tnic> <20180126200616.5xfn244uzeu7ptyo@pd.tnic> <20180126200725.rueqb2m6b4w47eu3@pd.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180126200725.rueqb2m6b4w47eu3@pd.tnic> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 26, 2018 at 09:07:25PM +0100, Borislav Petkov wrote: > +.macro FILL_RETURN_BUFFER nr:req ftr:req > #ifdef CONFIG_RETPOLINE > + ALTERNATIVE "", "call __clear_rsb", \ftr > #endif > .endm > > @@ -206,15 +174,10 @@ extern char __indirect_thunk_end[]; > static inline void vmexit_fill_RSB(void) > { > #ifdef CONFIG_RETPOLINE > + alternative_input("", > + "call __fill_rsb", > + X86_FEATURE_RETPOLINE, > + ASM_NO_INPUT_CLOBBER("memory")); > #endif > } > > @@ -19,6 +20,37 @@ ENDPROC(__x86_indirect_thunk_\reg) > .endm > > /* > + * Google experimented with loop-unrolling and this turned out to be > + * the optimal version — two calls, each with their own speculation > + * trap should their return address end up getting used, in a loop. > + */ > +.macro BOINK_RSB nr:req sp:req > + push %_ASM_AX > + mov $(\nr / 2), %_ASM_AX > + .align 16 > +771: > + call 772f > +773: /* speculation trap */ > + pause > + lfence > + jmp 773b > + .align 16 > +772: > + call 774f > +775: /* speculation trap */ > + pause > + lfence > + jmp 775b > + .align 16 > +774: > + dec %_ASM_AX > + jnz 771b > + add $((BITS_PER_LONG/8) * \nr), \sp > + pop %_ASM_AX > +.endm > + > + > +/* > * Despite being an assembler file we can't just use .irp here > * because __KSYM_DEPS__ only uses the C preprocessor and would > * only see one instance of "__x86_indirect_thunk_\reg" rather > @@ -46,3 +78,15 @@ GENERATE_THUNK(r13) > GENERATE_THUNK(r14) > GENERATE_THUNK(r15) > #endif > + > +ENTRY(__fill_rsb) > + BOINK_RSB RSB_FILL_LOOPS, %_ASM_SP > + ret > +END(__fill_rsb) > +EXPORT_SYMBOL_GPL(__fill_rsb) > + > +ENTRY(__clear_rsb) > + BOINK_RSB RSB_CLEAR_LOOPS, %_ASM_SP > + ret > +END(__clear_rsb) > +EXPORT_SYMBOL_GPL(__clear_rsb) One thing I feel this ought to mention (in the Changelog probably) is that it looses one RET for SKL+. That is, where we used to have 16 'safe' RETs before this, we now have 15.