[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 2/3] x86/clang: add retpoline support


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Wed, 16 Feb 2022 17:21:41 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J/c6eVyHYJXVUlazWNeV+ylcxSqZ5nGqV/mmllNoyMw=; b=av1yU3eMMX5oMtJjsffdN9h1A+PThG1Eh/A+mehnlrTgIZXeOHDOl3QW48/XQVCRr9juOYy6N6y8w3OlMeJNb1zXqNB0pDBSr5ln0zE0eitbYwGXX/qh4y48VARb476AAKhs35H/Wn8lv2AadaMSEKjqFdobJKcdd9qyWNzMgnmiSJWyzwZyZ6CYNlnChL+KHQNkZqOxjQlIeaktbWlztzH5KK2IDWG+0J4pg8ByxoB6E09/NtfSnsIprk5Io+w7/0u/a8KuYChTmIuleZM8DezPtS1aq0kLxoMU0svwJwbOt6oQe3nMTK2nLMRB2eYNRyvWDcZ5lhxZkV8DcuVRYQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HhO8ffn98OsJYe7Vbfje5Sd2hy1/bzrzNRago4iq018a8Yhr1dxnOveI3KzMkJuoJ3QZkDb89a5hALzvvsoxYQ1/MEWTwrvSnoIaHXLuOw92l5sLfvBa3rWA6Lj/HwqMRcMsIz0az3Shs62p8ZmiH1I/ti+huF2PPwSi/kZ8QqiAfZVY0U5bkU2wRyCSj3C5aj7Syh81G8rxl+Wh6eCHbTaTY00+fkP8uYXEBKKjRsanwaCE2Z4O54wADuDVKy522Ru5tA/RBbZzkmEGf4JUnOZFj8bDUnjmPeI9yvrwJUNRMUz1183r7BWZZ5KwbF5ucPmgpAdC4PsqQGyCkg2SHg==
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Wed, 16 Feb 2022 16:22:13 +0000
  • Ironport-data: A9a23:KDx1Na6lPxdl9F6X0BcIwQxRtOTAchMFZxGqfqrLsTDasY5as4F+v mUbCjuEO6uCYjT2etx1Ptm0809QusfWm9ZkTANl/Hs8Hi5G8cbLO4+Ufxz6V8+wwmwvb67FA +E2MISowBUcFyeEzvuV3zyIQUBUjclkfJKlYAL/En03FV8MpBsJ00o5wbZj29Aw27BVPivW0 T/Mi5yHULOa82Yc3lI8s8pvfzs24ZweEBtB1rAPTagjUG32zhH5P7pGTU2FFFPqQ5E8IwKPb 72rIIdVXI/u10xF5tuNyt4Xe6CRK1LYFVDmZnF+A8BOjvXez8CbP2lS2Pc0MC9qZzu1c99Z+ YwWqLqdEggQLqTItORCUyYEFQddFPgTkFPHCSDXXc27ykTHdz3nwul0DVFwNoodkgp1KTgQr 7pCcmlLN03dwbLtqF64YrAEasALNs7kMZlZonh95TrYEewnUdbIRKCiCdpwgmtq254WQaa2i 8wxdDdCTEvKbBB1F3Q3Gq8lwvuSiDryWmgNwL6SjfVuuDWCpOBr65DyNPLFd9rMQt9a9m6ar G/b+2XyAjkBKceSjzGC9xqEluLJ2C/2Ro8WPLm57eJxxk2ewHQJDx8bXkf9puO24nNSQPoGd RZSoHB36/Fvqgr7FbERQiFUvla150UBffcLHNQq4QWhyvXU3FqfIEstG2sphMMdiOc6Qjkj1 1msltzvBCByvLD9dU9x5ot4vhvpZ3FLcDZqiTssCFJcvo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y1PUemff9wYnqeTFlBBaMXu3QXdvatExslLtS+GsIgdG NOtxvNCTcwZ9FW3sQojB733CYrZdJW9G73ELYnEXAyvyl0EMMw6wv1crZYefKfhSLP/q5aQ1r6 UdEhVcdYVb0JYRV2R6PXviXnyYzpdx5F4htu3WVtAHpa9Q42aC3UG6GyHu6n57feLpK+def49P uuxsZ/GM/dsIC9MmXRKBJxRI92vobPkB34xQIaCW/1HDfEpv8I0IGSNsChcrYpwxkXd5WVonhd BW/NopGiUVJHZkEnovXU9WRi
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Detect whether the compiler supports clang retpoline option and enable
by default if available, just like it's done for gcc.

Note clang already disables jump tables when retpoline is enabled, so
there's no need to also pass the fno-jump-tables parameter. Also clang
already passes the return address on a register always on amd64, so
there's no need for any equivalent mindirect-branch-register
parameter.

Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/Kconfig | 5 ++++-
 xen/arch/x86/arch.mk | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig
index 219ef9791d..2fa456292b 100644
--- a/xen/arch/x86/Kconfig
+++ b/xen/arch/x86/Kconfig
@@ -35,9 +35,12 @@ config ARCH_DEFCONFIG
 config GCC_INDIRECT_THUNK
        def_bool $(cc-option,-mindirect-branch-register)
 
+config CLANG_INDIRECT_THUNK
+       def_bool $(cc-option,-mretpoline-external-thunk)
+
 config INDIRECT_THUNK
        def_bool y
-       depends on GCC_INDIRECT_THUNK
+       depends on GCC_INDIRECT_THUNK || CLANG_INDIRECT_THUNK
 
 config HAS_AS_CET_SS
        # binutils >= 2.29 or LLVM >= 6
diff --git a/xen/arch/x86/arch.mk b/xen/arch/x86/arch.mk
index 2da4bdb1ed..f2aa2a515f 100644
--- a/xen/arch/x86/arch.mk
+++ b/xen/arch/x86/arch.mk
@@ -47,6 +47,9 @@ CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += 
-mindirect-branch=thunk-extern
 CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -mindirect-branch-register
 CFLAGS-$(CONFIG_GCC_INDIRECT_THUNK) += -fno-jump-tables
 
+# Enable clang retpoline support if available.
+CFLAGS-$(CONFIG_CLANG_INDIRECT_THUNK) += -mretpoline-external-thunk
+
 # If supported by the compiler, reduce stack alignment to 8 bytes. But allow
 # this to be overridden elsewhere.
 $(call cc-option-add,CFLAGS_stack_boundary,CC,-mpreferred-stack-boundary=3)
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.