Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1368145imi; Sat, 23 Jul 2022 03:53:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t6cr6wx/QEo9YhresGnwHCBuCKTJjswJScYrTou8GoYRm3WlmO2Lm9otWeL34BgMVNUEaZ X-Received: by 2002:a17:903:22d2:b0:16d:4873:80cf with SMTP id y18-20020a17090322d200b0016d487380cfmr3663473plg.134.1658573581432; Sat, 23 Jul 2022 03:53:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573581; cv=none; d=google.com; s=arc-20160816; b=r/T3BLQNTHY53V4pk66P6k9ngAvSXg3feAe3eM099/bwu8/Rz1a+YH5h5lbSSD133j 5Ucw44aTFwBPkntuUkIh3FD7w+lJuasO51dV+TNdo4CVZP6esgcKMjMMeiFTmdHdx09F VbLbi6AqlpKaG1t/G5nh/RKnftNXfZ4dcvuVNAweli75tc+HH/T9Q/I+f7mVllLsTOFT lkxcaOzup5Ukd2bLjweRJxcO1tjcFRnT0GxMAdoEK3FUa/X5/z1VgsPvfmwXWW65w2pl utoFeC8EC6/LO8Y8xDUP6oyBDADRQTQfE0mQ2OVyhSDIEjle+cD6dtAQH1eZXGdT9bEK zAYw== 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=X9115JpBY44A/kR6xL5dgNnw/qLYjSVtpL9qcxtCrst7/pxSDeg8UWN85SiKABJlgE 0MYkrU+sBjgfnFgkZhjxxbmjN0DEvggZLhIUf4QbQZFXmm+nux1QQqto9Dewm74Bggfs ucVa7NCRfiNS6sCLr3uB77WELGMGj6yQIXvt9Wy9VlX4hj5HMpQEWXFlGOVVf1PjPCXr twpNLV7l/nJjFxyshiRh59edTVh7QWTJyZLwh6RsHGuQuygfvSE/Y9V5fYRUDeUpgK4T /fDZmJH0DIK0HmXqzzkd+Ky2AD5UOfg+Y20MDKJ37taFpTLIrRm2hnVSRBK5S9okLemF H2CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d9BZ3yG5; 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 e11-20020a170903240b00b0016252715440si196294plo.494.2022.07.23.03.52.45; Sat, 23 Jul 2022 03:53:01 -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=d9BZ3yG5; 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 S238125AbiGWKFG (ORCPT + 99 others); Sat, 23 Jul 2022 06:05:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238560AbiGWKEa (ORCPT ); Sat, 23 Jul 2022 06:04:30 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E24DEC; Sat, 23 Jul 2022 03:00:07 -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 sin.source.kernel.org (Postfix) with ESMTPS id 610DBCE0DBE; Sat, 23 Jul 2022 10:00:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E017C341CB; Sat, 23 Jul 2022 09:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570398; bh=CiilJ/57YWWPXmSTZIsCpZokOcdA6EH6fCCm2gWX1Fo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d9BZ3yG5f0dRAkTL6kIViTzITNav4o3V5z2KDLxQIGqMI7UfeGta2lNV0NTZzfh3w I+H0yJaFRUTB7ELO4BK9QdzTfSK6dQrX2CY1eWr64+PlmCepfbeVj/WaRTMi6Xa87I v8kEj+ta75Zewy0sGS/7ppz1XAk48J15ExjpnHlE= 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/148] x86/retpoline: Use -mfunction-return Date: Sat, 23 Jul 2022 11:54:55 +0200 Message-Id: <20220723095247.615053520@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220723095224.302504400@linuxfoundation.org> References: <20220723095224.302504400@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.8 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 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)