Received: by 10.223.185.116 with SMTP id b49csp1329424wrg; Wed, 14 Feb 2018 15:30:44 -0800 (PST) X-Google-Smtp-Source: AH8x224dJQfwpJoKub9Szh6q+gxUTFiPP0cgU9SQZzLYpyQ5J65bkSavu+J6PfiVw2vvHxsQJmIf X-Received: by 10.98.210.134 with SMTP id c128mr669346pfg.199.1518651044450; Wed, 14 Feb 2018 15:30:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518651044; cv=none; d=google.com; s=arc-20160816; b=reDsfmXuiH7NEJDMEMbmug31te9ZYyCelxILTgJrOTsl4o+vYneJPb2dwl27sI6XMV 1oey9AS2H/XnqorGNwtakdtxpBvxkHHmmA5KeOR6nJQYs7E7gG9q8+OJCn7DwDbJC3hO HU1SiY4LD6IDF0UiBsfbEvlQ1YyjU6MT/IgGo36E5vt9gEAaAacthhkMzLGKmMV3zF7k Xeqf6CdcJfS/Dk/E308dKXPs+OnJnGh2MeJB8ST357PXmBdpq/i+K7zNgGbB6Kt3VIOC vwQyGdpMiQ7+YfLK0vvbIkJgIAY3P4syZ8fAgb09HLzzb7zFXoXAIwZf1CimTYcrzt09 gFuA== 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=YAEFG5Ut7Z7itbzoe2Fo8irSzUQf8CJ4DD8sCG/EQxDneARKAl5+tXyg81hv2Z09uQ l3kk11NM0G2XEzT8a89kfg+25eK28M60AJs/LwfT7iIufNaqdkBnr7duQQxnrie/TiCh AC0k1PohsfHVSxfyim+qi4Ku68/zZhjar4Cs0ovsEe4QBuh2+wMD6aSNcQ6tuyXX4Ui5 du45o8MUHuP9CGqH9LpRJbgm9h36j6BBu/vPk36PF56Z2UYOQNxLlAeRDGQ9CQT+UOoX bC8SER/VVhOgv4sfjuxW/9LikK4yhj5HNjrCL5L3ND1ImhCHf5eoZfHOYaQkqssQmHIG nLAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.co.uk header.s=amazon201209 header.b=CxqC0Xzx; 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 u69si2619905pgd.619.2018.02.14.15.30.29; Wed, 14 Feb 2018 15:30:44 -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=CxqC0Xzx; 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 S1032143AbeBNX3s (ORCPT + 99 others); Wed, 14 Feb 2018 18:29:48 -0500 Received: from smtp-fw-6002.amazon.com ([52.95.49.90]:47686 "EHLO smtp-fw-6002.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032079AbeBNX3m (ORCPT ); Wed, 14 Feb 2018 18:29:42 -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=1518650982; x=1550186982; h=from:to:subject:date:message-id:in-reply-to:references; bh=7GUIRWILo0LT/aL4M47T6JJhUWbPNOoYuvv+uvYQDkM=; b=CxqC0XzxxA8umxny8OIbYPp/mKztBTbTBltcmaeMLXtHC2BPKROFwnAo TDRgA85c5L4At3DW9D5OCoeIT2f6/2aJVv9ak1cP2mlXR09JRVurVKp4x fvKh47CUP9fW4J0NmZIIrR4pv2NnSWacYZc9beAZtsfy7Lh5Jb+YgEATf 8=; X-IronPort-AV: E=Sophos;i="5.46,514,1511827200"; d="scan'208";a="332103801" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 Feb 2018 23:29:39 +0000 Received: from uc8d3ff76b9bc5848a9cc.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-4ff6265a.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w1ENTXtk128611 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 Feb 2018 23:29:34 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 w1ENTVPt000922; Wed, 14 Feb 2018 23:29:31 GMT Received: (from dwmw@localhost) by uc8d3ff76b9bc5848a9cc.ant.amazon.com (8.15.2/8.15.2/Submit) id w1ENTUUu000921; Wed, 14 Feb 2018 23:29:30 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 v2 4/4] x86/retpoline: Support retpoline build with Clang Date: Wed, 14 Feb 2018 23:29:18 +0000 Message-Id: <1518650958-550-5-git-send-email-dwmw@amazon.co.uk> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518650958-550-1-git-send-email-dwmw@amazon.co.uk> References: <1518650958-550-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