Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp1365793imi; Sat, 23 Jul 2022 03:47:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vH6vhhQPrv7O4fBDvlxY/3T3S9qghQrXrLagCbAIdyY6p1oLzQMhYf16sHFmhJDkFubqAf X-Received: by 2002:a17:907:720f:b0:72f:1c62:8dac with SMTP id dr15-20020a170907720f00b0072f1c628dacmr3086986ejc.437.1658573249391; Sat, 23 Jul 2022 03:47:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658573249; cv=none; d=google.com; s=arc-20160816; b=A+rPNlBD2bwRG+RemTE9UPYx1LiO+exklvIItzcNYSglCK9WFCmJX2ZGD4fflDIAfC hN834FAorPMYgHMhjdyVPcLnvphqZFvXP8xG6HHUTUz/90Otw9H4l/B56JfP1RmEGvND GtBHTS7hrzqO8/YOGWg9l5UHJIuMzZac2g8v0LTyXmEtC+UCZ/hA4t7hsAqkgmSivey5 2S++Z3heqbV5pGZvLG+9VljZMnxI5mXcbybCVHUMOd8KhzpyYC5hB71iBemkQPZyT7eZ uQAsoviaGr28Jf0AyJLqkvCbiwYESGOYEtGkIzIXaWISp+veVsIBkd25GGxaNQgd7VPc EN1Q== 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=FzXB+aLRNdG+WsdEVhUV+LhGhHGDKNQ1LpvFT189Zhk=; b=OkO8aASNIC+egGTkAx8N/kZCgjysda/OIMsRlTrkcJeX/3o7L+tW2HTxCDlzmmFR7V ZEcvNSjaoOhOO0xlj6/jODCpAwtOS1P2euGoJfhqWLrsgyWWn4ARWcPo+uh0N9DxsOiv gUkmmJ8QlWdRfQodIqrcvC7v0ua2JlX0UwIzEi+MaENavkzW5MrRl/rYHFvEOhCJhj1V TsNncdqbFPzyT5ahr9uHrpbc8sSjfMk0I7QoS/zoTIrsyiCKHGzXg8QIQyy5qXs+bb17 HY728D0U5m1ggVRFvkzmfDa+zBnVGVND4qoX63ELnCscwP8s7YBG16p3DshFDfDEJiA1 7BDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E2EJhavH; 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 y10-20020a170906524a00b0072642bbc8cfsi7188816ejm.914.2022.07.23.03.47.00; Sat, 23 Jul 2022 03:47:29 -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=E2EJhavH; 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 S237966AbiGWKDD (ORCPT + 99 others); Sat, 23 Jul 2022 06:03:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237958AbiGWKCg (ORCPT ); Sat, 23 Jul 2022 06:02:36 -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 AD43382FAA; Sat, 23 Jul 2022 02:59:05 -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 9AFF76125D; Sat, 23 Jul 2022 09:59:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9578C341C0; Sat, 23 Jul 2022 09:59:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658570344; bh=D6Pxm5LuSsNkFmaR1etmsshRJ2ZUFrmrGMIFvboJej0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E2EJhavHrsh1X4XVZYT+dekFr9aI6wpXP4F4agk6C7Zf4edwIXKvrmSO+4qoFp3md u1QA6xha4pS1l4WypdztQKazTFXBSV9XDeP5ggu7s9qoKynbz8QMYmF/qoPOtCuZgt 937/OIY11YBBPwTMfKUVCobL2wmw9s7EPjGzHWc8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Borislav Petkov , Josh Poimboeuf , Alexei Starovoitov , Thadeu Lima de Souza Cascardo , Ben Hutchings Subject: [PATCH 5.10 054/148] x86/retpoline: Create a retpoline thunk array Date: Sat, 23 Jul 2022 11:54:26 +0200 Message-Id: <20220723095239.410889364@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 1a6f74429c42a3854980359a758e222005712aee upstream. Stick all the retpolines in a single symbol and have the individual thunks as inner labels, this should guarantee thunk order and layout. Previously there were 16 (or rather 15 without rsp) separate symbols and a toolchain might reasonably expect it could displace them however it liked, with disregard for their relative position. However, now they're part of a larger symbol. Any change to their relative position would disrupt this larger _array symbol and thus not be sound. This is the same reasoning used for data symbols. On their own there is no guarantee about their relative position wrt to one aonther, but we're still able to do arrays because an array as a whole is a single larger symbol. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Borislav Petkov Acked-by: Josh Poimboeuf Tested-by: Alexei Starovoitov Link: https://lore.kernel.org/r/20211026120310.169659320@infradead.org Signed-off-by: Thadeu Lima de Souza Cascardo Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/nospec-branch.h | 8 +++++++- arch/x86/lib/retpoline.S | 14 +++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -12,6 +12,8 @@ #include #include +#define RETPOLINE_THUNK_SIZE 32 + /* * Fill the CPU return stack buffer. * @@ -120,11 +122,15 @@ #ifdef CONFIG_RETPOLINE +typedef u8 retpoline_thunk_t[RETPOLINE_THUNK_SIZE]; + #define GEN(reg) \ - extern asmlinkage void __x86_indirect_thunk_ ## reg (void); + extern retpoline_thunk_t __x86_indirect_thunk_ ## reg; #include #undef GEN +extern retpoline_thunk_t __x86_indirect_thunk_array[]; + #ifdef CONFIG_X86_64 /* --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -28,16 +28,14 @@ .macro THUNK reg - .align 32 - -SYM_FUNC_START(__x86_indirect_thunk_\reg) + .align RETPOLINE_THUNK_SIZE +SYM_INNER_LABEL(__x86_indirect_thunk_\reg, SYM_L_GLOBAL) + UNWIND_HINT_EMPTY ALTERNATIVE_2 __stringify(ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), \ __stringify(RETPOLINE \reg), X86_FEATURE_RETPOLINE, \ __stringify(lfence; ANNOTATE_RETPOLINE_SAFE; jmp *%\reg), X86_FEATURE_RETPOLINE_LFENCE -SYM_FUNC_END(__x86_indirect_thunk_\reg) - .endm /* @@ -55,10 +53,16 @@ SYM_FUNC_END(__x86_indirect_thunk_\reg) #define __EXPORT_THUNK(sym) _ASM_NOKPROBE(sym); EXPORT_SYMBOL(sym) #define EXPORT_THUNK(reg) __EXPORT_THUNK(__x86_indirect_thunk_ ## reg) + .align RETPOLINE_THUNK_SIZE +SYM_CODE_START(__x86_indirect_thunk_array) + #define GEN(reg) THUNK reg #include #undef GEN + .align RETPOLINE_THUNK_SIZE +SYM_CODE_END(__x86_indirect_thunk_array) + #define GEN(reg) EXPORT_THUNK(reg) #include #undef GEN