Received: by 10.223.185.116 with SMTP id b49csp700928wrg; Wed, 14 Feb 2018 05:46:56 -0800 (PST) X-Google-Smtp-Source: AH8x227kISLdi6rLBAV0t23QxknAtb/JRnGA+X/RRiXW2ynVXpeOc8MLvpOX4Pl6oAMCWn0oFhcT X-Received: by 2002:a17:902:a617:: with SMTP id u23-v6mr4543035plq.201.1518616016520; Wed, 14 Feb 2018 05:46:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518616016; cv=none; d=google.com; s=arc-20160816; b=XiSG3Ggz6dFwlHmrYUouYvb/qwzpNB5Os4m4PnrGzR6E49nilApnpzlWVZrSc7zmyn eNLZUKHQV/WR0Y5fnk6pMcb7Pj7vlZpIWyEqDrQkVqJ5uTuY16Lq7ONhAtzOCTdFd3st EJRiap1Fb7ZfbnoGFdABYICtbpsDzbnhl6Ig/fmzNjoUCitqZXt5411h4294nZRpynmN 1r9TO7LYcfT7KRMc71d0Tx3OSHNHMK/rzPc+Dgwx2nL7dOo8sO8i8Wdw0+UkkfifkwVE nU2HwDGtPj5jxlEUukrNwr11TAZILjKL+oUfWax4qQRBbuwkIDHKXCun9Hy5Fw5y9gdy 05RA== 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:to:from:dkim-signature:arc-authentication-results; bh=7GUIRWILo0LT/aL4M47T6JJhUWbPNOoYuvv+uvYQDkM=; b=Jyq90+FHcA9YNq90V4XbxJC4Aj7hJZr6QJjWW2TYlSEBRgEXuxBTeG1epEvU40iBRK gkUrH2/l2KNPIJdlBo0UjOg+8olQ/EZN3/WmLaTCVsrPaoyR7AfxbwKdB0Mq0D/HuQHA POURwY6vaKLyIoNmc3fahisPgDpWSqBj8lpafggqN3r30P4KyAoylTX6d4822n5KZnp0 9+8YWehwmqmZxb3a3gxSPfCkDYI+opYG2/vWE+j55SN0fPZvfX4RwPoE38t48WeZmuPr atPn6az2kOvymj7+Ny9BjfmxbSMUjdyVHjdngnYvazOQWls9sHuk2TKQJf5Iwv6/AWE+ q1mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=V+hua1qv; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si6119093pgt.200.2018.02.14.05.46.42; Wed, 14 Feb 2018 05:46:56 -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; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=V+hua1qv; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.co.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030533AbeBNNp1 (ORCPT + 99 others); Wed, 14 Feb 2018 08:45:27 -0500 Received: from smtp-fw-4101.amazon.com ([72.21.198.25]:40868 "EHLO smtp-fw-4101.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030252AbeBNNo4 (ORCPT ); Wed, 14 Feb 2018 08:44:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazon201209; t=1518615896; x=1550151896; h=from:to:subject:date:message-id:in-reply-to:references; bh=7GUIRWILo0LT/aL4M47T6JJhUWbPNOoYuvv+uvYQDkM=; b=V+hua1qvMaIoPqzA98wM7vAiZcjLWH/zraNWZvN4cka5MTQCRTBkvDb5 Mj9amLSE2S4JLe2NDIj8PuAtLY4tq2uP+DEI3Fmzx2bu758MWfQ2y+dSX lfkvQeUPDqauEEqQHWoHuef4tPzvGvL1UaLd4UMD9LQggC+czwDnkn/J1 M=; X-IronPort-AV: E=Sophos;i="5.46,512,1511827200"; d="scan'208";a="708104511" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1a-807d4a99.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Feb 2018 13:44:55 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (iad1-ws-svc-lb91-vlan2.amazon.com [10.0.103.146]) by email-inbound-relay-1a-807d4a99.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id w1EDiiJb102378 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Feb 2018 13:44:47 GMT Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (localhost [127.0.0.1]) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w1EDih8s014281; Wed, 14 Feb 2018 13:44:44 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w1EDiher014280; Wed, 14 Feb 2018 13:44:43 GMT From: David Woodhouse To: tglx@linutronix.de, karahmed@amazon.de, x86@kernel.org, kvm@vger.kernel.org, torvalds@linux-foundation.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, bp@alien8.de, peterz@infradead.org, jmattson@google.com, rkrcmar@redhat.com, arjan.van.de.ven@intel.com, dave.hansen@intel.com, mingo@kernel.org Subject: [PATCH 4/4] x86/retpoline: Support retpoline build with Clang Date: Wed, 14 Feb 2018 13:44:34 +0000 Message-Id: <1518615874-13806-5-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518615874-13806-1-git-send-email-dwmw@amazon.co.uk> References: <1518615874-13806-1-git-send-email-dwmw@amazon.co.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: David Woodhouse --- arch/x86/Makefile | 5 ++++- include/linux/compiler-clang.h | 5 +++++ include/linux/compiler-gcc.h | 4 ++++ include/linux/init.h | 8 ++++---- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/arch/x86/Makefile b/arch/x86/Makefile index fad5516..dbc7d0e 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -232,7 +232,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables # Avoid indirect branches in kernel to deal with Spectre ifdef CONFIG_RETPOLINE - RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) + RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register + 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 endif diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h index 3b609ed..be3aef6 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -19,3 +19,8 @@ #define randomized_struct_fields_start struct { #define randomized_struct_fields_end }; + +/* Clang doesn't have a way to turn it off per-function, yet. */ +#ifdef __noretpoline +#undef __noretpoline +#endif diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 631354a..2e8a287 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -93,6 +93,10 @@ #define __weak __attribute__((weak)) #define __alias(symbol) __attribute__((alias(#symbol))) +#ifdef RETPOLINE +#define __noretpoline __attribute__((indirect_branch("keep"))) +#endif + /* * it doesn't make sense on ARM (currently the only user of __naked) * to trace naked functions because then mcount is called without diff --git a/include/linux/init.h b/include/linux/init.h index 506a981..bc27cf0 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -6,10 +6,10 @@ #include /* Built-in __init functions needn't be compiled with retpoline */ -#if defined(RETPOLINE) && !defined(MODULE) -#define __noretpoline __attribute__((indirect_branch("keep"))) +#if defined(__noretpoline) && !defined(MODULE) +#define __noinitretpoline __noretpoline #else -#define __noretpoline +#define __noinitretpoline #endif /* These macros are used to mark some functions or @@ -47,7 +47,7 @@ /* These are for everybody (although not all archs will actually discard it in modules) */ -#define __init __section(.init.text) __cold __latent_entropy __noretpoline +#define __init __section(.init.text) __cold __latent_entropy __noinitretpoline #define __initdata __section(.init.data) #define __initconst __section(.init.rodata) #define __exitdata __section(.exit.data) -- 2.7.4