Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4702175imw; Tue, 12 Jul 2022 12:42:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u9+RzB35mop2tERRlqe4i/GNY6X6LbltzFYSJXMoMIh7fvw1l/BlDHIXDNutfMolfd54Hz X-Received: by 2002:a63:82c1:0:b0:415:d42c:1653 with SMTP id w184-20020a6382c1000000b00415d42c1653mr16307710pgd.334.1657654926774; Tue, 12 Jul 2022 12:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657654926; cv=none; d=google.com; s=arc-20160816; b=AZ8eJ1mgBwd1v0KAq8KRpmF37/ZSa8QkMkC48hbCGPkSPhwINWRtO/TIp8XpphHa+1 SL5dr03umAwuGSsVI/U81E6mWGPA8dd72hrHaVlD/MA64I5LBzzYxGgXchgUie0U51zo 50n792p4keaGEbT0AnWqSQ3gmHzUtBLy23+CcXbQyafEaU3+0R9dk+Znleq330qd6Nn0 d8hlqKXpQB3p5xdLIHeJheDOg8ReK12JgJrXdnT3kgtMP8PaQU/4AsOXmzs1lfuxPxfo WLPFOfi9IiChSrV8TI8qoz1eevGdAPkcvzw2xTOhyXzYjR0CwBlsK/BfWy559b6vTzJs BeFA== 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=aozh7tGWIg8Cjzx0eFnILy++eGZm0hhknGD6kwt2RbFZiJQA1DQyriItSg4O8KHmJu aODG8Ish7EBD6m7jH3ZVtvEeZTKn3dwy8h3n7fEanpls3tMwcBCam7RP75h1gEfd9ddW yUmChja8h1GrrVLFuAc3Gq0P5qvbjV9TZXbb0S7asvK0QaKBH3GfowdUe/wzuj/5ExUa K/98aisgavK40VYSFXXxlACVcsMYje3MKJyvZ2iqcCv5GVLTfhe3o+OcyO1FlAA6KBmD cxmy/BA6/SautI3uUue1J7shfqEBHJ9REJby1Py7QDkDqWnYONhxM8kBEYmZpeTG2fvR dPEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="WpNo/Gky"; 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 jc15-20020a17090325cf00b0016bd9a8f03csi12408210plb.147.2022.07.12.12.41.54; Tue, 12 Jul 2022 12:42:06 -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="WpNo/Gky"; 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 S234396AbiGLSqh (ORCPT + 99 others); Tue, 12 Jul 2022 14:46:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234175AbiGLSp6 (ORCPT ); Tue, 12 Jul 2022 14:45:58 -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 87147DAB9A; Tue, 12 Jul 2022 11:42:44 -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 C75D061ACC; Tue, 12 Jul 2022 18:42:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A96CC3411C; Tue, 12 Jul 2022 18:42:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1657651363; bh=D6Pxm5LuSsNkFmaR1etmsshRJ2ZUFrmrGMIFvboJej0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpNo/GkyjKCHucRkLpnmr20AbDK2b4rnwFAxc8lIVjCiuIFP/Ld3gPz4Tautq975V mVqcLWL+cumMHD8+jk3LLA5vxcZlyH/pXM3RmSbFHd3R1yRcJjXc+SrQswhrUT0UZZ sfxjVtZ8osgcwIjklvcw2CI5adzeoqp0LTgWFya4= 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/130] x86/retpoline: Create a retpoline thunk array Date: Tue, 12 Jul 2022 20:38:20 +0200 Message-Id: <20220712183248.936302019@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 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