Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp606365imd; Thu, 1 Nov 2018 02:35:24 -0700 (PDT) X-Google-Smtp-Source: AJdET5fZ2SjwdHsGyP7rgKHd9DRAiYK7hAzg6MXtbOVUfc2uaLHIwNMXfr1yEr3JjsbMce3TCDXU X-Received: by 2002:a62:d586:: with SMTP id d128-v6mr3140997pfg.196.1541064924279; Thu, 01 Nov 2018 02:35:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541064924; cv=none; d=google.com; s=arc-20160816; b=h04tCGzf212pirTqjjw41QImjnnX5qs6jcYddCTvOBncfFtDmoCw0oj9OlL/Jr/uen u6e8V2RMADc21OzPBfo0K/S61AcdiCrvm0ezGGza8bBzcZP4wnF9v9roXDcqFaC+2sND cavvhQw9nXf5OT7wDA8Ds6b5YrZBpvrYNdYhHSyomlhHoPh37zmD/1Y77MCjB4stRJoj usuAO5JStuINXrl9V5ypDCZl+9yfOF3dt0zzx5d7CbpyHhgwFlYK9EqOhElBaJOqEmba hmOynEwCW2HqAeBU2y3ooiAhYR3wnDJcdRmFZvxEWuaEyroNEUqRbIEY2Rd5cQFL9ddl 8YoQ== 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=HAQdjCzG24J0ddTMUU+s8Zwk+DhfnxEqa/kfTN8HXlY=; b=C3f4x4g/DF+hxUYfa3L+b7VEWoIlczU3tZxA9GKHHSo6UaYZhmyD/jrSd2Ox7cxHYb eIuneEE7HnyIcsN2t0hQeOOtbp5Ti4TFrcw5coRLEalyRY7ANYf+xic11s16MQmBZImY zCImMJ2TbEGzCBjFnTdEQBouVxMEhqPXL2mqs3G5f64+a2iBEMbPHIpehUuX6GWCU6fR 3I//331CB0Lbj7TAMwq3DFnJK31wC+0kDQciuLSIIMkk/Cz6W1NS3GBtl3+JJXFAiPFk efvVKsHgUirIxRwT+e7twvC1RiB7ihf427eCx2BdpqejVVkcU3+zHh+LtAMyTSQenIo1 g7TA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="y/2Wvoqz"; 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 31-v6si2994853pgl.64.2018.11.01.02.35.09; Thu, 01 Nov 2018 02:35:24 -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="y/2Wvoqz"; 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 S1728078AbeKASfJ (ORCPT + 99 others); Thu, 1 Nov 2018 14:35:09 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:38296 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727801AbeKASfJ (ORCPT ); Thu, 1 Nov 2018 14:35:09 -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 wA19NwRs182492; Thu, 1 Nov 2018 09:31:46 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=HAQdjCzG24J0ddTMUU+s8Zwk+DhfnxEqa/kfTN8HXlY=; b=y/2WvoqzHwZW8mONDo3oQUEDnYz2z9AaXkhKOtNZsnTZRzrATHX/eZgOPSisSa97B/x5 oIIhXtfrvGrgVKnv3H0N8L2fx8ImVnTm77EH8X5WVyjmUBE18jNqYLonaMofplbMlL91 pb5I1jdVT+JMG7nPFAu+C2m78B757xG0ByCnK3wSEs9SSvuyD6rHcCuItfdPs66ghKrU ZKvXkJH0/450dttTGcrb5majmu4hJcXdynIlC8PEjUp2wjnXAK6+kSv0YpTnkCnu7lTI rjZP0DLWe/4BF1syEz+dC+0ukEMw2A2Q0d8XSSBj4VfJB3dCALJ4/h+43e20+JmTVxR1 oQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2ncgnr7t7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Nov 2018 09:31:46 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wA19VkfQ006395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Nov 2018 09:31:46 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wA19VicV029478; Thu, 1 Nov 2018 09:31:44 GMT MIME-Version: 1.0 Message-ID: <991cbe9b-1e31-4b12-b572-91fde5c79699@default> Date: Thu, 1 Nov 2018 02:31:44 -0700 (PDT) From: Zhenzhong Duan To: Cc: , , , , , , , , , , , Subject: [PATCH v2 1/2] retpolines: Only enable retpoline support 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=9063 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-1811010083 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. The check of RETPOLINE is changed to CONFIG_RETPOLINE. This change is based on suggestion in https://lkml.org/lkml/2018/9/18/1016 Signed-off-by: Zhenzhong Duan Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Borislav Petkov Cc: Daniel Borkmann Cc: David Woodhouse Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Masahiro Yamada Cc: Michal Marek --- arch/x86/Kconfig | 6 ++---- arch/x86/Makefile | 4 +--- arch/x86/include/asm/nospec-branch.h | 10 ++++++---- arch/x86/kernel/cpu/bugs.c | 2 +- scripts/Makefile.build | 2 -- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index ffebfc3f..277e0df 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -436,6 +436,8 @@ config GOLDFISH =20 config RETPOLINE =09bool "Avoid speculative indirect branches in kernel" +=09depends on $(cc-option,-mindirect-branch=3Dthunk-extern -mindirect-bran= ch-register) || \ + $(cc-option,-mretpoline-external-thunk) =09default y =09select STACK_VALIDATION if HAVE_STACK_VALIDATION =09help @@ -444,10 +446,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..30573dd 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -222,9 +222,7 @@ 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 -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