Received: by 2002:a05:7412:1703:b0:e2:908c:2ebd with SMTP id dm3csp814325rdb; Fri, 25 Aug 2023 01:41:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVnNO6WmywFDgVLWG4Aysg2uK2wjlq0/83lV8KKC+QmpNl2ftO8UeEDVyPuuoLrqcIBWd6 X-Received: by 2002:a17:90b:f0f:b0:267:faf1:21bb with SMTP id br15-20020a17090b0f0f00b00267faf121bbmr14554839pjb.15.1692952867148; Fri, 25 Aug 2023 01:41:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692952867; cv=none; d=google.com; s=arc-20160816; b=SV2Ph7pkh13C2haBz5nTlDv1VGkpu/pIPsEKa5MlGInIgBCnrFXbLyIKyWDq1tEx32 KC+xNqH340X6lM9YZgneKxwDkxfqoLdYe3L7e+dFaltLA3vgDGPVsgAcAeFL9UB4cuu+ i+Y9mwBolfiG/k8yarcokSqFaMq5vHo79+EDorgHUG/3oy8Xfjf6tDux8EKppeJuzRHf AhHEHMiTxXNFcfqTWioPc4bfggaCWv/qyJOKE7hYml1nd/15KRvj14IYy4EaPfGCScXK 4y3MnSFjZ7NQIC7d0tNnSFn1uxdpQ9lQfmVMyMcWnYpPlR8hP/YMGn0639fFB6AGPbft l9oA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WYhYomtoKb+dBpcccC3ApeW5khmLI2zP5wGR9wjr5qo=; fh=ZwaEcDYNCnlh+U7YxZ1LCEcet9pcdhSkEX0cCEOksvY=; b=CMAqGWPXXqbI1SC4/xaklTaCKBd2+BP4E38ISDzHKDe0w60sHf09/CSA9vvDAjEFZ0 4ye1sj4lKFfiaBOz1HUPnMKUPsUk1vtZ1I0cZK+tREOCnHqviqGRLZ4V21tGUUAUrn4P wVZNPbVfABXa8PHoMeX5vunEvy3wYm2wn0rLHlJkk3xvgfL/Cgw262DLZ+ze7+d0Yd0k sQ2UAG6JxHNImpyc94iubn4PNfMtwZwk1/d0CcpdvBH8bBmjIYS6pbTc1VNnXp4XLMTH lrIWIZVTWrCWi6UqBt+GaBdcfARMkiEspiYOGKFUS05Q8CkZY/5Cg6NzXK/f2YqwOXFx Rxog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JxjhrIs0; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r14-20020a17090a690e00b0026369cc7286si1572192pjj.154.2023.08.25.01.40.53; Fri, 25 Aug 2023 01:41:07 -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=@kernel.org header.s=k20201202 header.b=JxjhrIs0; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243252AbjHYHDJ (ORCPT + 99 others); Fri, 25 Aug 2023 03:03:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242743AbjHYHCR (ORCPT ); Fri, 25 Aug 2023 03:02:17 -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 C7B4719AE for ; Fri, 25 Aug 2023 00:02:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A8C5066652 for ; Fri, 25 Aug 2023 07:02:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADFD2C433C9; Fri, 25 Aug 2023 07:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692946935; bh=ABB0VEm/1qgHSMYLRDciSz5DC9qBJP3kxsxjFgJZZ5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JxjhrIs0rBIPXQXYG9kU5qXezDgbkKf84mVH/fYPRIX2mJ2/EwUmTYV8sL2Jb1Z/G QIVfB4zN76RVQfVn1knoOTgFQ6YDv05KZ+3GOOKcaAstk9sHXlv3EN8/vH/Ziihs0j F1ywibRdPmJLQLb5vlc0xC2ojVF0dtIgHoYlJNgeLp+3DtRaJKyjukceY+V5ffHozE 0z9o0+fJ27k7tnL/NxKLyTQR09amF1cB93+gZYgb9ZciethDKJ+W29/JSNXChx8Rbw 7y7kXO4CsKrFuPfWN1689OPvI9b600/wbkEHR/XjRbS89I2TjwXpr6T4e07m+qHofb 7805gv1HeAw1A== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Borislav Petkov , Peter Zijlstra , Babu Moger , Paolo Bonzini , Sean Christopherson , David.Kaplan@amd.com, Andrew Cooper , Nikolay Borisov , gregkh@linuxfoundation.org, Thomas Gleixner Subject: [PATCH 22/23] x86/nospec: Refactor UNTRAIN_RET[_*] Date: Fri, 25 Aug 2023 00:01:53 -0700 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 Factor out the UNTRAIN_RET[_*] common bits into a helper macro. Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/nospec-branch.h | 31 +++++++++------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 51e3f1a287d2..dcc78477a38d 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -288,35 +288,24 @@ * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point * where we have a stack but before any RET instruction. */ -.macro UNTRAIN_RET +.macro __UNTRAIN_RET ibpb_feature, call_depth_insns #if defined(CONFIG_RETHUNK) || defined(CONFIG_CPU_IBPB_ENTRY) VALIDATE_UNRET_END ALTERNATIVE_3 "", \ CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \ - "call entry_ibpb", X86_FEATURE_ENTRY_IBPB, \ - __stringify(RESET_CALL_DEPTH), X86_FEATURE_CALL_DEPTH + "call entry_ibpb", \ibpb_feature, \ + __stringify(\call_depth_insns), X86_FEATURE_CALL_DEPTH #endif .endm -.macro UNTRAIN_RET_VM -#if defined(CONFIG_RETHUNK) || defined(CONFIG_CPU_IBPB_ENTRY) - VALIDATE_UNRET_END - ALTERNATIVE_3 "", \ - CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \ - "call entry_ibpb", X86_FEATURE_IBPB_ON_VMEXIT, \ - __stringify(RESET_CALL_DEPTH), X86_FEATURE_CALL_DEPTH -#endif -.endm +#define UNTRAIN_RET \ + __UNTRAIN_RET X86_FEATURE_ENTRY_IBPB, __stringify(RESET_CALL_DEPTH) -.macro UNTRAIN_RET_FROM_CALL -#if defined(CONFIG_RETHUNK) || defined(CONFIG_CPU_IBPB_ENTRY) - VALIDATE_UNRET_END - ALTERNATIVE_3 "", \ - CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \ - "call entry_ibpb", X86_FEATURE_ENTRY_IBPB, \ - __stringify(RESET_CALL_DEPTH_FROM_CALL), X86_FEATURE_CALL_DEPTH -#endif -.endm +#define UNTRAIN_RET_VM \ + __UNTRAIN_RET X86_FEATURE_IBPB_ON_VMEXIT, __stringify(RESET_CALL_DEPTH) + +#define UNTRAIN_RET_FROM_CALL \ + __UNTRAIN_RET X86_FEATURE_ENTRY_IBPB, __stringify(RESET_CALL_DEPTH_FROM_CALL) .macro CALL_DEPTH_ACCOUNT -- 2.41.0