Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4725321imw; Tue, 12 Jul 2022 13:05:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tRoZ/uCMsxcn+tbtm6HedGhgbqJ9m6NMOKGJnre018pJpd0zDkps1lTJ5+B9FPPrS1JC2Y X-Received: by 2002:a63:cb:0:b0:40c:a2b4:4890 with SMTP id 194-20020a6300cb000000b0040ca2b44890mr21755687pga.304.1657656326754; Tue, 12 Jul 2022 13:05:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657656326; cv=none; d=google.com; s=arc-20160816; b=vy/fFOIZARxlBTBn+oq6Tpn5EuAH13x7ryEBoj7Ay7oCt1Osqm1InyJpEGnapu/Mw2 gCtdWXWc/DL871MONq07T7LXu+dgCPahAFHeFH7lgdjIk4TPg+W2xzfeLgdO3+AvHOri 9mo5t8nsavfc+m/K7iD7LJfe+Owr7km7IGfIQX4hIRTQ2zc0vtzhfO1YYBMKDG2ziaig 02lijUQEY1eiJ7pPezF/Qkp8yJ9PrcFkXGnRVhWs/IQIhVwfuso/VlNiZI4OwXsgcwLo GaTRA+YRcQ3OTHC32ShtxHL+b9hyDxm8S0NvfvAEK/Hvg9qgC5mo0ugTVQsObfCAnUak DzRg== 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=Oy5h9rF2yevGbooAynuxO0u5nTB9vTifuiCAw4jMxT4=; b=aOE3OD83E+MXECPmrNGjI6hpqHy3CWWzLIWwJRdS4Bhlgm/Zrrmbt2d+/1mrLhtRrl yAp2O+YH/flAJFzCyDjRSkk96yyXn/4Ibdo+2Y2OD+FjWCL+Li0xAgZG5IxgMzsNVrK2 6UDvOGAvaFy9I7mSIfuxlOqsnYX1iSWlv05BKG2a3bUgYJsk5gUrtf2kHJZTw0YjXUmb HC3G8D55Klvm4QY/L9qFCOZ08DAPWiV9psRgKx3ErDrNpDeDFNsMYgi9GVrvtyaNafRh qzKWgQEUPVnHQOj5vjecD8JLOzBS0VgfFugVc5Fcq/ejz7dWrC6rX2cGjuUD/YRYJwzk nZxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Jfdse2Z9; 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 bg8-20020a1709028e8800b0016c281b1de3si12579713plb.501.2022.07.12.13.04.23; Tue, 12 Jul 2022 13:05:26 -0700 (PDT) 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=Jfdse2Z9; 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 S234164AbiGLSvU (ORCPT + 99 others); Tue, 12 Jul 2022 14:51:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234368AbiGLSup (ORCPT ); Tue, 12 Jul 2022 14:50:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76FDFE43DB; Tue, 12 Jul 2022 11:44:22 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7C1FB60AC9; Tue, 12 Jul 2022 18:44:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AE29C341CA; Tue, 12 Jul 2022 18:44:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651459; bh=CiilJ/57YWWPXmSTZIsCpZokOcdA6EH6fCCm2gWX1Fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jfdse2Z9Intwrj79ZOOUQX0oxzELpMZLsihW8TN5DxWn4GrumAgXl8MMprA2b48gH h3L6jLtLxA81z0naqXflYDSkPOq0cDH8SJLy0o+//r6TNoRAw749mPLGwEhS0hToV9 gWBVbbpYjwkpA8znSoL6MUX21K0SIqytPe5ZY/tM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Nick Desaulniers , Josh Poimboeuf , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 083/130] x86/retpoline: Use -mfunction-return Date: Tue, 12 Jul 2022 20:38:49 +0200 Message-Id: <20220712183250.292155176@linuxfoundation.org> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220712183246.394947160@linuxfoundation.org> References: <20220712183246.394947160@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.7 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: Peter Zijlstra commit 0b53c374b9eff2255a386f1f1cfb9a928e52a5ae upstream. Utilize -mfunction-return=thunk-extern when available to have the compiler replace RET instructions with direct JMPs to the symbol __x86_return_thunk. This does not affect assembler (.S) sources, only C sources. -mfunction-return=thunk-extern has been available since gcc 7.3 and clang 15. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Borislav Petkov Reviewed-by: Nick Desaulniers Reviewed-by: Josh Poimboeuf Tested-by: Nick Desaulniers Signed-off-by: Borislav Petkov [cascardo: RETPOLINE_CFLAGS is at Makefile] [cascardo: remove ANNOTATE_NOENDBR from __x86_return_thunk] Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- Makefile | 2 ++ arch/x86/include/asm/nospec-branch.h | 2 ++ arch/x86/lib/retpoline.S | 12 ++++++++++++ 3 files changed, 16 insertions(+) --- a/Makefile +++ b/Makefile @@ -672,11 +672,13 @@ endif ifdef CONFIG_CC_IS_GCC RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register) +RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register) endif ifdef CONFIG_CC_IS_CLANG RETPOLINE_CFLAGS := -mretpoline-external-thunk RETPOLINE_VDSO_CFLAGS := -mretpoline +RETPOLINE_CFLAGS += $(call cc-option,-mfunction-return=thunk-extern) endif export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -120,6 +120,8 @@ _ASM_PTR " 999b\n\t" \ ".popsection\n\t" +extern void __x86_return_thunk(void); + #ifdef CONFIG_RETPOLINE typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -66,3 +66,15 @@ SYM_CODE_END(__x86_indirect_thunk_array) #define GEN(reg) EXPORT_THUNK(reg) #include #undef GEN + +/* + * This function name is magical and is used by -mfunction-return=thunk-extern + * for the compiler to generate JMPs to it. + */ +SYM_CODE_START(__x86_return_thunk) + UNWIND_HINT_EMPTY + ret + int3 +SYM_CODE_END(__x86_return_thunk) + +__EXPORT_THUNK(__x86_return_thunk)