Received: by 10.223.176.46 with SMTP id f43csp611561wra; Fri, 26 Jan 2018 04:12:41 -0800 (PST) X-Google-Smtp-Source: AH8x2242BsUAHyhr8IhDbRf54zKzlpooVqQJCAT98X308eC1e7uxCEKHMFVlSKe8GjAe7+HaipoR X-Received: by 2002:a17:902:f83:: with SMTP id 3-v6mr1046747plz.275.1516968761608; Fri, 26 Jan 2018 04:12:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516968761; cv=none; d=google.com; s=arc-20160816; b=U2/jh6GoDjwKH+jEyuqp01pcFcoT/mKJ5FQIp2zOdNMeNX498XA4fr2XGu1cues8uW OfZmS+YX9M+dxg6ONyANYFM07cvj8KNF8/uYnAs8jWcQ4OuFOGDYBY+DI+PH7ZsbcqlL wdaRujeEK66sX10RSlpZ+MgYQEyn7yXHr7DjPOGhDGCUybVU0E5NcFjFcBE94DvPb3Oa SvsHpeHmuE5aM89EuTKkcJKe3jmYvmlolnxxx7KCB/Y1/fz43JdEeW2aLpjJTJu8saOO qXTZjoIkoAiyKdxIpz8RZOQI8JNXcZ8YDFRSubGyyi8MgM/+DTGWREacDUCN2qYLjb4Y R6YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=sK7IJ08uqUPYX4wrV09Qa357+G/EIgkvNAhlWgaCAYo=; b=GjNSiWpOUmuimIotKRh+b9EFOH0VUkAh48aFWQMIyS5BvHbD9q23Wdcj/XaYYTMeqJ Qm5Ex1W6rRqsStpHMm3ogVqBcnOlWD03Td0TUuUEEOKPPjPi0E1MmU6/UvzA+Esmj+Se Z3+WqGg4/Zqvcs2zlWF2dNTOtWJA9YWMDk6Bjld2xmQMBdUEarkf6YKI++BYUqNeoCbw lUNWYdrquMHLRt/JCN8cmQWz9Rp/kL3uQCSEOt0ta5Wz1/pC6rEvP6p+cQEx7bFLsGSI IrkXiMxYARWUd+Dv3dQy4Q9PS3JcYpsFB78qYP1VN2gpolIvjnPd1yj5rK2Hnu6h/3MN V4fQ== ARC-Authentication-Results: i=1; mx.google.com; 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 g7si2926273pgc.663.2018.01.26.04.12.26; Fri, 26 Jan 2018 04:12:41 -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; 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 S1751900AbeAZML7 (ORCPT + 99 others); Fri, 26 Jan 2018 07:11:59 -0500 Received: from mail.skyhub.de ([5.9.137.197]:57440 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751868AbeAZML5 (ORCPT ); Fri, 26 Jan 2018 07:11:57 -0500 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id HLpjc77F1zfj; Fri, 26 Jan 2018 13:11:56 +0100 (CET) Received: from pd.tnic (p200300EC2BCF3A0024194793E6CFFC7A.dip0.t-ipconnect.de [IPv6:2003:ec:2bcf:3a00:2419:4793:e6cf:fc7a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 27F801EC03F6; Fri, 26 Jan 2018 13:11:56 +0100 (CET) From: Borislav Petkov To: X86 ML Cc: LKML , David Woodhouse , 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, peterz@infradead.org Subject: [PATCH 3/4] x86/retpoline: Simplify vmexit_fill_RSB() Date: Fri, 26 Jan 2018 13:11:38 +0100 Message-Id: <20180126121139.31959-4-bp@alien8.de> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20180126121139.31959-1-bp@alien8.de> References: <20180126121139.31959-1-bp@alien8.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov Simplify it to call an asm-function instead of pasting 41 insn bytes at every call site. Also, add alignment to the macro as suggested here: https://support.google.com/faqs/answer/7625886 Signed-off-by: Borislav Petkov Cc: David Woodhouse --- arch/x86/include/asm/nospec-branch.h | 39 +++++++++++++++++++++++++++--------- arch/x86/include/asm/processor.h | 5 +++++ arch/x86/lib/Makefile | 1 + arch/x86/lib/retpoline.S | 5 +++++ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 33a35daf6c4d..61d4d7033758 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -53,6 +53,8 @@ #ifdef __ASSEMBLY__ +#include + /* * This should be used immediately before a retpoline alternative. It tells * objtool where the retpolines are so that it can make sense of the control @@ -121,6 +123,30 @@ #endif .endm +/* Same as above but with alignment additionally */ +.macro ___FILL_RETURN_BUFFER reg:req nr:req sp:req + mov (\nr / 2), \reg + .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 \reg + jnz 771b + add (BITS_PER_LONG/8) * \nr, \sp +.endm + /* * A simpler FILL_RETURN_BUFFER macro. Don't make people use the CPP * monstrosity above, manually. @@ -206,15 +232,10 @@ extern char __indirect_thunk_end[]; static inline void vmexit_fill_RSB(void) { #ifdef CONFIG_RETPOLINE - unsigned long loops; - - asm volatile (ANNOTATE_NOSPEC_ALTERNATIVE - ALTERNATIVE("jmp 910f", - __stringify(__FILL_RETURN_BUFFER(%0, RSB_CLEAR_LOOPS, %1)), - X86_FEATURE_RETPOLINE) - "910:" - : "=r" (loops), ASM_CALL_CONSTRAINT - : : "memory" ); + alternative_input("", + "call __fill_rsb_clobber_ax", + X86_FEATURE_RETPOLINE, + ASM_NO_INPUT_CLOBBER(_ASM_AX, "memory")); #endif } diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index d3a67fba200a..491f6e0be66e 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -971,4 +971,9 @@ bool xen_set_default_idle(void); void stop_this_cpu(void *dummy); void df_debug(struct pt_regs *regs, long error_code); + +#ifdef CONFIG_RETPOLINE +asmlinkage void __fill_rsb_clobber_ax(void); +#endif + #endif /* _ASM_X86_PROCESSOR_H */ diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile index f23934bbaf4e..69a473919260 100644 --- a/arch/x86/lib/Makefile +++ b/arch/x86/lib/Makefile @@ -27,6 +27,7 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o lib-$(CONFIG_RETPOLINE) += retpoline.o +OBJECT_FILES_NON_STANDARD_retpoline.o :=y obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S index c909961e678a..297b0fd2ad10 100644 --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -46,3 +46,8 @@ GENERATE_THUNK(r13) GENERATE_THUNK(r14) GENERATE_THUNK(r15) #endif + +ENTRY(__fill_rsb_clobber_ax) + ___FILL_RETURN_BUFFER %_ASM_AX, RSB_CLEAR_LOOPS, %_ASM_SP +END(__fill_rsb_clobber_ax) +EXPORT_SYMBOL_GPL(__fill_rsb_clobber_ax) -- 2.13.0