Received: by 10.223.185.116 with SMTP id b49csp3600109wrg; Mon, 19 Feb 2018 02:52:37 -0800 (PST) X-Google-Smtp-Source: AH8x2248M8/2xXKg8Gw2JfULiCYFb4JBMl/zgx+zIOJEFVaOhPi5Gt+AcrRswBdnym2NebNRL9/C X-Received: by 10.98.80.89 with SMTP id e86mr14099828pfb.46.1519037557568; Mon, 19 Feb 2018 02:52:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519037557; cv=none; d=google.com; s=arc-20160816; b=kcEt6OINc8lEri6pYroUtthLciFeu37n/62mZgmnb/eE5lSikeveLI45g5YG3MlgI7 B34zGsEfPrsR+gFAghKeGEy/Gdx9VuR/EOguk1PWX38p/xQVor+D+yqeoCk4Vu3C6ZyE edHFeDy2m6XFmfU30vL2EsBVuMEiWGevcFTf+kzV8uY67LIsucf05Fq2Qr5Cd7e30G7b 3ZRVQUnQt7+wFbnRRoYS5fR9PbSmYG8NRj0gPgWegL2pqe40GXiQNK0L8OTq0dGd9m1X QJsceqXVpFnzMDBTuuRV8NVuaaPNsYUUxTQ8/yn6JLXan8o7GA1SmT0GsVxq3ooRYf3b mYtQ== 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=5DQfJv3d2vhLZm9x2pIJI9nEHWlqEjfeHAty52X4uKw=; b=rsDmPXYjmZcpryN6TYEasB+HrH1m6mVBd0BG+Xl37lqBvUDqEQN7JT8zqsoeKUhA5G eux7LE6xdcB1tEUQcCTul39SIVdRyAAs+dASZoIYocrD4kT2Ket572jao14TcHVnB21o uc1kFNvH2ow0gn2lNv5LmbVO/sL2NQhBV4VZ0NcWxRqelXIvptb51aVgDsWmtsDRtMCK fUCX/YsE5FZOgq46Ni1i1N/0HlLkrejlyHT6/r1GGbUzOTUxVlZ9GXXfhE7Y2tdxMvlU C3iXeN68lkBzClkhvukAT8EuEd8I0T4s1jxr395lroj5A4Ivgg2GbALoBfKexpQrOfWG Zl5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=U73yKN5L; 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 m10-v6si5763720plt.185.2018.02.19.02.52.23; Mon, 19 Feb 2018 02:52:37 -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=U73yKN5L; 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 S1752685AbeBSKvW (ORCPT + 99 others); Mon, 19 Feb 2018 05:51:22 -0500 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:8610 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752392AbeBSKvR (ORCPT ); Mon, 19 Feb 2018 05:51:17 -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=1519037477; x=1550573477; h=from:to:subject:date:message-id:in-reply-to:references; bh=5DQfJv3d2vhLZm9x2pIJI9nEHWlqEjfeHAty52X4uKw=; b=U73yKN5LEAZz94z3gDCK87X6TjOz+Ax2/um1QiU1DyRpduKjzKEVYLBF E3iHmEhPx6bwKKXrDVRv/XeHXOLFJWPuuSwTL3k3MXd+ysQYcDftyLi6M tMn6C+5GENX9F7R4RVqMm+TLof0w4JDzCKKseZ6pGAj+Ovu5xG9AXkQ7+ w=; X-IronPort-AV: E=Sophos;i="5.46,534,1511827200"; d="scan'208";a="720268878" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-859fe132.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Feb 2018 10:51:15 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan3.amazon.com [10.247.140.70]) by email-inbound-relay-2b-859fe132.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w1JAp9YK052549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 19 Feb 2018 10:51:11 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 w1JAp8lv007972; Mon, 19 Feb 2018 10:51:08 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w1JAp8AY007970; Mon, 19 Feb 2018 10:51:08 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 v3 4/4] x86/retpoline: Support retpoline build with Clang Date: Mon, 19 Feb 2018 10:50:57 +0000 Message-Id: <1519037457-7643-5-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519037457-7643-1-git-send-email-dwmw@amazon.co.uk> References: <1519037457-7643-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 d02a4df..d3f264a 100644 --- a/include/linux/compiler-clang.h +++ b/include/linux/compiler-clang.h @@ -27,3 +27,8 @@ #if __has_feature(address_sanitizer) #define __SANITIZE_ADDRESS__ #endif + +/* 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 73bc63e..673fbf9 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