Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5008944imm; Tue, 18 Sep 2018 02:53:19 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYBZT1MoQ7SJJK7Vb5lkpGtqcaC0PfHuHzZsbo8efuY5Jqe+ZEjW1FPRWL+yAbltDgzoLp4 X-Received: by 2002:a17:902:6501:: with SMTP id b1-v6mr29012474plk.31.1537264398999; Tue, 18 Sep 2018 02:53:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537264398; cv=none; d=google.com; s=arc-20160816; b=GhmBqPjKW2j6z2UxZNMdALIHlzDTPg/Nz9bGotJwgSuaaINvkREtSYax04iuGcBln2 aIhzMj8R2YHOqJiYTUlzy8JJsFAGfhE5F0P/MPwSMjU6bNXnF+8Mhf0Kr9xOa6ksnf4z gsnyLODLvPKRtzO3hEJ5BnngO1Df5OWXsdp3XAiOQ7I2FD9x3Z0HfDeFov5ZFC7aSN1S 6+8GF+OxGpEoEI+QgDPa0RZp9VpFvBNeARDrnRtaDSs+ZP/vpIS6hhsgjLAnfZjUbey+ AiEMILDVv5ldrCu+xB+eo1tud16CMKUmr9lMgZgG/ABnmDZ7ExheyKdZGSefBnNOH6Fx YO9A== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xOhm0LaIHslYqMKqZt9OBU+2V2ssXX8gMA5DbBV6FiU=; b=tV4gHFlTUt91x4LyRmR98tX86HPW8SJRKMTESeXNBYaGhOiBJhAUT3yOXsfrepVtBu cYgHs8Vcqfn3XcJPMc18TGJW1uwmU1abRQPCkPPvzm8gKWMa5nW3krsEzTubLkJ59UlS JRuQ2X3cPZb50OUu68Zx8O49xoh88jSnThTPY88q+oMLMTBn+D6RukuKy9m1c0zTkHK4 BHrpFAJftPeZ6DFOATjKSIkdI9Nh4/QVyiufpM45VGqwjPH2wPGCvZ6Jcqhz5cFDYDyh y0kfzmegA6B7VmnNN/iGoNbgrIzvd+c9mENXP+mXRj+3ImpDDF87T8/LlifbAFDv4HaK mU4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=ENTInC70; 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 142-v6si20200537pfy.182.2018.09.18.02.53.03; Tue, 18 Sep 2018 02:53:18 -0700 (PDT) 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=ENTInC70; 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 S1729277AbeIRPWV (ORCPT + 99 others); Tue, 18 Sep 2018 11:22:21 -0400 Received: from merlin.infradead.org ([205.233.59.134]:48506 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728783AbeIRPWU (ORCPT ); Tue, 18 Sep 2018 11:22:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=xOhm0LaIHslYqMKqZt9OBU+2V2ssXX8gMA5DbBV6FiU=; b=ENTInC705CRys2e31H4kUlaqj 2wubRu6Uh+knDeG0YzH9bpjN8lKmoFE3pmkCVVz57DGnHpR0zbYW49hm3+qfl64oKgh1nOPH+vkWR Jo+w5ZpedlSzGtvqwf0Ay/vsDTEvdRyvZu9i3Fgs+NxDX9ItlJQFPD9s2wulL856Dl/+VEVk++udE ejNsd8p2oPM43rSzy2yrnrx3belCDcJal6EESAJzQ2rXTkd4VA+8krocC+DC4ZOCC9zPgb3bXbfNv TWeArNHeObcuRehcKctA+qR1SVAfIcSjJQyt4MfN9a2qZl5YvoYc2/9XGgCXn37BEmzF4CpuF3iVO b3e2hqZdg==; 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.90_1 #2 (Red Hat Linux)) id 1g2CeA-0001Fh-E9; Tue, 18 Sep 2018 09:50:18 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E9DCB202C1A09; Tue, 18 Sep 2018 11:50:15 +0200 (CEST) Date: Tue, 18 Sep 2018 11:50:15 +0200 From: Peter Zijlstra To: Zhenzhong Duan Cc: linux-kernel@vger.kernel.org, mingo@redhat.com, konrad.wilk@oracle.com, x86@kernel.org, dwmw@amazon.co.uk, tglx@linutronix.de, Srinivas REDDY Eeda , bp@suse.de, hpa@zytor.com, dhaval.giani@oracle.com Subject: Re: [PATCH] x86/speculation: Use AMD specific retpoline for inline asm on AMD Message-ID: <20180918095015.GE19234@hirez.programming.kicks-ass.net> References: <87411705-893f-46d3-b899-b09ed9fa8d1b@default> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87411705-893f-46d3-b899-b09ed9fa8d1b@default> User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 17, 2018 at 10:17:30PM -0700, Zhenzhong Duan wrote: > Lfence is preferred than general retpoline on AMD, add this option > in C / inline asm just as the ASM code does. > > For x86_64, it still help to have minimal retpoline for kernel even > if gcc doesn't support it, change the inline asm for x86 so that it > could also be used by x86_64. > Add ANNOTATE_NOSPEC_ALTERNATIVE for i386 to avoid below warning: > "warning: objtool: .altinstr_replacement+0x10: unsupported > intra-function call" > "warning: objtool: If this is a retpoline, please patch it > in with alternatives and annotate it with ANNOTATE_NOSPEC_ALTERNATIVE." This Changelog is almost unreadable, please rewrite. Reverse engineering the patch you add RETPOLINE_AMD support to the inline-asm CALL_NOSPEC so that they match the asm CALL_NOSPEC. > Signed-off-by: Zhenzhong Duan > --- > arch/x86/include/asm/nospec-branch.h | 23 ++++++++++++++++------- > 1 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index fd2a8c1..2d49eab 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -170,21 +170,26 @@ > */ > # define CALL_NOSPEC \ > ANNOTATE_NOSPEC_ALTERNATIVE \ > - ALTERNATIVE( \ > + ALTERNATIVE_2( \ > ANNOTATE_RETPOLINE_SAFE \ > "call *%[thunk_target]\n", \ > "call __x86_indirect_thunk_%V[thunk_target]\n", \ > - X86_FEATURE_RETPOLINE) > + X86_FEATURE_RETPOLINE, \ > + "lfence;\n" \ > + ANNOTATE_RETPOLINE_SAFE \ > + "call *%[thunk_target]\n", \ > + X86_FEATURE_RETPOLINE_AMD) > # define THUNK_TARGET(addr) [thunk_target] "r" (addr) That's OK. > > -#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE) > +#elif defined(CONFIG_RETPOLINE) This doesn't make any sense.. > /* > * 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 CALL_NOSPEC \ > - ALTERNATIVE( \ > + ANNOTATE_NOSPEC_ALTERNATIVE \ > + ALTERNATIVE_2( \ > ANNOTATE_RETPOLINE_SAFE \ > "call *%[thunk_target]\n", \ > " jmp 904f;\n" \ > @@ -194,12 +199,16 @@ > " lfence;\n" \ > " jmp 902b;\n" \ > " .align 16\n" \ > - "903: addl $4, %%esp;\n" \ > - " pushl %[thunk_target];\n" \ > + "903: add $4, %%" _ASM_SP ";\n" \ > + " push %[thunk_target];\n" \ Yeah, don't do that. > " ret;\n" \ > " .align 16\n" \ > "904: call 901b;\n", \ > - X86_FEATURE_RETPOLINE) > + X86_FEATURE_RETPOLINE, \ > + "lfence;\n" \ > + ANNOTATE_RETPOLINE_SAFE \ > + "call *%[thunk_target]\n", \ > + X86_FEATURE_RETPOLINE_AMD) And that's OK again.