Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1724435pxp; Thu, 10 Mar 2022 10:50:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyG/ypJvojDV1IqDdxSBLykdMXAQLSPZZs8/4cVo9pBeyXHZHk7cXPhB3S5AyGd6ojDXRGE X-Received: by 2002:a65:6cc7:0:b0:380:6a04:cecc with SMTP id g7-20020a656cc7000000b003806a04ceccmr5177508pgw.455.1646938247170; Thu, 10 Mar 2022 10:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646938247; cv=none; d=google.com; s=arc-20160816; b=Kct52HUL/YDANNPLDiB8FHR8U0CMEoiowj0bD3cmC23lap9zQFcuqakYHBFrbY+L8K /Em/oqkQcJIhecmZWbnmtdmgt/B8jRSwxyElYb3Q5pod33BBCm1sUUDfkdzejV3bDTeo Az+eUAU2/5JOSIptNKqDhJB0npvL/OTtkJLgXIOL2753A8e32Gdj/61cMAMynuCp/P0X scVheRATtdkNWQlqYu5WSbyH/KvSlRiGNSBMz+mfmyfQ4vfGerwF6o4wnqTWN6+l6moD 6LOVEXqG2HDBdJjzdoDRcb+yQSYgEt8ViI1CMdCjflxrSznxzvN/7GaODgV57IW/8ukU 8E5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O5Kcur/LwN/VSRcQWp6ght3ogD4fONhkcd5RYBaKMXo=; b=FYmPw/DjT7rXe/HKtiBtRDj/4WuJQMLSwJ8rIe+aLBmNdwQJo5P1Ka4Zir+57QJjvC oIut0Xx03JeGcQWAu5iAEBP2htvJmGEqTSltd0Yki5vhtC+Kzyl7VRz9SEyZROttaHRx hyzmZle0l0zD9ed/6z4dvvPFQCY8rYPTvXPg3aLQQ8KjQiuzinu/tkv71Xy9YfhTzO3u sWSW2jyrDcfA64lu50bBB/5esrDwQhHjw3hGAaBVhjWSXcvVmYSNxvzrGMhRPnOfGcih 9aT7oyEVyr+HjDXwbflkHQT8CuY/qvJAJhg1mG+ax8aXts0Ksz6+S2ThR24IyLF/8L8T BLVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HZ3G9PrE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020aa79831000000b004f6d362bf6dsi192869pfl.11.2022.03.10.10.50.29; Thu, 10 Mar 2022 10:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HZ3G9PrE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243634AbiCJOYj (ORCPT + 99 others); Thu, 10 Mar 2022 09:24:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243761AbiCJOSV (ORCPT ); Thu, 10 Mar 2022 09:18:21 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4CBD1662D7; Thu, 10 Mar 2022 06:14:41 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6A0E6B825F3; Thu, 10 Mar 2022 14:14:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A43D0C340E8; Thu, 10 Mar 2022 14:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646921680; bh=9xSbW6RIMMhTdHAqKKPczN6O01gAoWr/nHWbJelAumw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HZ3G9PrEV+RwmnYjAIgtWy2EH9RfcWeEAhtJzmJEYng1DXWyB52/GAWva2ZHteE4X 410jeH12h2EX0iB+jooaeKGlB7sidUFRrX5Yh81xoN2UBjrEklnvPZrFvAH0ntywaP I1l5xAAAJyx1lxGlTMDGTy9hxWNC81OjGc4L5+ZI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Zijlstra , Zhenzhong Duan , Thomas Gleixner , David Woodhouse , Borislav Petkov , Daniel Borkmann , "H. Peter Anvin" , Konrad Rzeszutek Wilk , Andy Lutomirski , Masahiro Yamada , Michal Marek , srinivas.eeda@oracle.com, Ben Hutchings Subject: [PATCH 4.9 02/38] x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support Date: Thu, 10 Mar 2022 15:13:15 +0100 Message-Id: <20220310140808.209912532@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220310140808.136149678@linuxfoundation.org> References: <20220310140808.136149678@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhenzhong Duan commit 4cd24de3a0980bf3100c9dcb08ef65ca7c31af48 upstream. Since retpoline capable compilers are widely available, make CONFIG_RETPOLINE hard depend on the compiler capability. Break the build when CONFIG_RETPOLINE is enabled and the compiler does not support it. Emit an error message in that case: "arch/x86/Makefile:226: *** You are building kernel with non-retpoline compiler, please update your compiler.. Stop." [dwmw: Fail the build with non-retpoline compiler] Suggested-by: Peter Zijlstra Signed-off-by: Zhenzhong Duan Signed-off-by: Thomas Gleixner Cc: David Woodhouse Cc: Borislav Petkov Cc: Daniel Borkmann Cc: H. Peter Anvin Cc: Konrad Rzeszutek Wilk Cc: Andy Lutomirski Cc: Masahiro Yamada Cc: Michal Marek Cc: Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/cca0cb20-f9e2-4094-840b-fb0f8810cd34@default [bwh: Backported to 4.9: - Drop change to objtool options - Adjust context, indentation] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/Kconfig | 4 ---- arch/x86/Makefile | 5 +++-- arch/x86/include/asm/nospec-branch.h | 10 ++++++---- arch/x86/kernel/cpu/bugs.c | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -418,10 +418,6 @@ config RETPOLINE branches. Requires a compiler with -mindirect-branch=thunk-extern support for full protection. The kernel may run slower. - Without compiler support, at least indirect branches in assembler - code are eliminated. Since this includes the syscall entry path, - it is not entirely pointless. - if X86_32 config X86_EXTENDED_PLATFORM bool "Support for extended (non-PC) x86 platforms" --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -221,9 +221,10 @@ ifdef CONFIG_RETPOLINE RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk RETPOLINE_CFLAGS += $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG))) - ifneq ($(RETPOLINE_CFLAGS),) - KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE + ifeq ($(RETPOLINE_CFLAGS),) + $(error You are building kernel with non-retpoline compiler, please update your compiler.) endif + KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) endif archscripts: scripts_basic --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -164,11 +164,12 @@ _ASM_PTR " 999b\n\t" \ ".popsection\n\t" -#if defined(CONFIG_X86_64) && defined(RETPOLINE) +#ifdef CONFIG_RETPOLINE +#ifdef CONFIG_X86_64 /* - * 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 \ ANNOTATE_NOSPEC_ALTERNATIVE \ @@ -183,7 +184,7 @@ X86_FEATURE_RETPOLINE_AMD) # define THUNK_TARGET(addr) [thunk_target] "r" (addr) -#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 @@ -213,6 +214,7 @@ X86_FEATURE_RETPOLINE_AMD) # 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) --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -812,7 +812,7 @@ static void __init spec_v2_print_cond(co static inline bool retp_compiler(void) { - return __is_defined(RETPOLINE); + return __is_defined(CONFIG_RETPOLINE); } static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)