Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp1865118imd; Fri, 2 Nov 2018 01:49:08 -0700 (PDT) X-Google-Smtp-Source: AJdET5e/F+zAO5nDXR4b6eOpfEkFRJEhcoOVxmLXNr+boUSmvZ7tW/4g+EdT1poOOnFFmyy8BKy+ X-Received: by 2002:a17:902:a418:: with SMTP id p24-v6mr10481210plq.29.1541148548402; Fri, 02 Nov 2018 01:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541148548; cv=none; d=google.com; s=arc-20160816; b=LLIl2JTvTLCzJ5Az1P4umN4z78EBjdPIHLxjNnA5Im5XhvE4gyvZPQLxP9Az0w2ucZ ZZBwM4DhjDe9wumpqd8UrfyIuNzyMsPRtNp01ny0DXq2aSdGv4havBI+pTUzCQjVYZyh o25/mj47cKntLi5Ysig/uqGxvBqnI6RggcmvVgd8RkVJwqur5O3jIKpr0IguqKG8ScOQ XEMXRd8E7miWyq/3HfOwbcQPK31raqBl9cW9UJxRPgbAz757HT1W2VeY6xXcJcEXLRlE 91iThQ/Rkfg/CO4/2D/ahusSeRec+NZsXRyld44TKujna2qhg9NxgRmxG+KFaMRyJPX3 RqMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:subject:cc:to:from:date:message-id :mime-version:dkim-signature; bh=XMKLSXAuBWSIOY4aaxmHV31Wj5DCB2dsOz3hgRdMtM4=; b=sIIDkjRE+OlHvq7HqRRYKjO2xGTGJ2b+7WRwOYj4tcivHE/e3nMc4mhRxInbR1QF8I gTlgO/ug/Jzr7Yf4uEBOi+dIPr8MifrKOakicOjnU0MgapAmX0/g7LDJ45L5wd3PYkWH PHQcXLwYkr1lou5OAWHALXKOFxNnWqGz2FNGLqHFpbL8oQk6elZkWPH8S7Z0AY3hzjHY xDLlDAoaJmbleqNM4yGffrpv1WkURxFTKw/6tAmh+J50+ztJ2ymgc3VcT8x87Kmij3P7 6z23kaP0VdAiU50PQWJSNIej7qggzDiCrPiC4DanIeXfh+JYVPKHNeO6RYdWYaqYE9Dg Z29Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=jRzlrnUq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p3-v6si10947634pff.272.2018.11.02.01.48.53; Fri, 02 Nov 2018 01:49:08 -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=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=jRzlrnUq; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbeKBRxO (ORCPT + 99 others); Fri, 2 Nov 2018 13:53:14 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:34736 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726560AbeKBRxN (ORCPT ); Fri, 2 Nov 2018 13:53:13 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wA28jCeS086703; Fri, 2 Nov 2018 08:45:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : to : cc : subject : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=XMKLSXAuBWSIOY4aaxmHV31Wj5DCB2dsOz3hgRdMtM4=; b=jRzlrnUqJ9zp2Ok1X2WmodWoNG2TqucMqsphT42ZjGLfrmWc78WcFph1dNeNpGSG2MPg kH+EApApYXQNxzjWgXH0yAUUFR/EhwPWn4M/tzGXyKRSq6vW38yesmb3wou1x2gFQ1jl vcoXVgJMg3i10/SGCld7TGirCtVLQz/OPJlGqel3I95+KlcOWzs6/BjXXMxukHqfsgsI jeOTmt6BigDjad7vs/ZM2x1w+2l48CXMLBKqfPviH0LWVvIu6QWOsioyTTWwNeyiqauG pU+v7S7tHZ0CL/99T5JHA7M8l0IuNGOQwnbvEN4fJuJyukjMRSHljJVmSbpurNKfATgN cw== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2ncgnrd9bn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 02 Nov 2018 08:45:44 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wA28jhjv011044 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 2 Nov 2018 08:45:43 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id wA28jgtp004355; Fri, 2 Nov 2018 08:45:42 GMT MIME-Version: 1.0 Message-ID: Date: Fri, 2 Nov 2018 01:45:41 -0700 (PDT) From: Zhenzhong Duan To: Cc: , , , , , , , , , , , Subject: [PATCH v3 1/2] retpolines: Enable retpoline support only when compiler support it X-Mailer: Zimbra on Oracle Beehive Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9064 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811020083 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since retpoline capable compilers are widely available, make CONFIG_RETPOLINE hard depend on it. This is achieved by breaking the build early and showing an error like below: "arch/x86/Makefile:226: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop." [peterz@infradead.org: initial suggestion] Link: https://lore.kernel.org/lkml/caeb3213f13e57191e362ca04f2892cfa2ccda65= .camel@infradead.org [dwmw@amazon.co.uk: fail the build with non-retpoline compiler] Link: https://lore.kernel.org/lkml/alpine.DEB.2.21.1811011317400.1642@nanos= .tec.linutronix.de Signed-off-by: Zhenzhong Duan Suggested-by: Peter Zijlstra Cc: David Woodhouse Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Daniel Borkmann Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Masahiro Yamada Cc: Michal Marek --- arch/x86/Kconfig | 4 ---- arch/x86/Makefile | 5 +++-- arch/x86/include/asm/nospec-branch.h | 10 ++++++---- arch/x86/kernel/cpu/bugs.c | 2 +- scripts/Makefile.build | 2 -- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index c51c989..fcb7f37 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -443,10 +443,6 @@ config RETPOLINE =09 branches. Requires a compiler with -mindirect-branch=3Dthunk-extern =09 support for full protection. The kernel may run slower. =20 -=09 Without compiler support, at least indirect branches in assembler -=09 code are eliminated. Since this includes the syscall entry path, -=09 it is not entirely pointless. - config INTEL_RDT =09bool "Intel Resource Director Technology support" =09depends on X86 && CPU_SUP_INTEL diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 5b562e4..6d94fe8 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -222,9 +222,10 @@ KBUILD_CFLAGS +=3D -fno-asynchronous-unwind-tables =20 # Avoid indirect branches in kernel to deal with Spectre ifdef CONFIG_RETPOLINE -ifneq ($(RETPOLINE_CFLAGS),) - KBUILD_CFLAGS +=3D $(RETPOLINE_CFLAGS) -DRETPOLINE +ifeq ($(RETPOLINE_CFLAGS),) + $(error You are building kernel with non-retpoline compiler, please upda= te your compiler.) endif + KBUILD_CFLAGS +=3D $(RETPOLINE_CFLAGS) endif =20 archscripts: scripts_basic diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/no= spec-branch.h index 80dc144..8b09cbb 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -162,11 +162,12 @@ =09_ASM_PTR " 999b\n\t"=09=09=09=09=09\ =09".popsection\n\t" =20 -#if defined(CONFIG_X86_64) && defined(RETPOLINE) +#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_X86_64 =20 /* - * Since the inline asm uses the %V modifier which is only in newer GCC, - * the 64-bit one is dependent on RETPOLINE not CONFIG_RETPOLINE. + * Inline asm uses the %V modifier which is only in newer GCC + * which is ensured when CONFIG_RETPOLINE is defined. */ # define CALL_NOSPEC=09=09=09=09=09=09\ =09ANNOTATE_NOSPEC_ALTERNATIVE=09=09=09=09\ @@ -181,7 +182,7 @@ =09X86_FEATURE_RETPOLINE_AMD) # define THUNK_TARGET(addr) [thunk_target] "r" (addr) =20 -#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE) +#else /* CONFIG_X86_32 */ /* * For i386 we use the original ret-equivalent retpoline, because * otherwise we'll run out of registers. We don't care about CET @@ -211,6 +212,7 @@ =09X86_FEATURE_RETPOLINE_AMD) =20 # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) +#endif #else /* No retpoline for C / inline asm */ # define CALL_NOSPEC "call *%[thunk_target]\n" # define THUNK_TARGET(addr) [thunk_target] "rm" (addr) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index c37e66e..d0108fb 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -252,7 +252,7 @@ static void __init spec2_print_if_secure(const char *re= ason) =20 static inline bool retp_compiler(void) { -=09return __is_defined(RETPOLINE); +=09return __is_defined(CONFIG_RETPOLINE); } =20 static inline bool match_option(const char *arg, int arglen, const char *o= pt) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a8e7ba9..6a6be9f 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -236,10 +236,8 @@ ifdef CONFIG_GCOV_KERNEL objtool_args +=3D --no-unreachable endif ifdef CONFIG_RETPOLINE -ifneq ($(RETPOLINE_CFLAGS),) objtool_args +=3D --retpoline endif -endif =20 =20 ifdef CONFIG_MODVERSIONS --=20 1.8.3.1