Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1150583rdb; Sun, 20 Aug 2023 20:40:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEio81QlAL74SWign19sKb5N+yxjXpw86MTfMSzYvXh3rl0GUdaq21UNqsfZvnrYVCoDZ1B X-Received: by 2002:a05:6402:11c8:b0:51e:5bd5:fe7e with SMTP id j8-20020a05640211c800b0051e5bd5fe7emr6181036edw.17.1692589220809; Sun, 20 Aug 2023 20:40:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692589220; cv=none; d=google.com; s=arc-20160816; b=CrtidgtpIlobMKtRYiEz96KmSox3HiXCkUfS3C6CjKcLVTy+Imx8IwiWmQMRetw+fL c1HWfSvrpt+iLG8qs1UEGubsfxfVFIGGFaZgjgYSVNN4ssWK90bAUieiUD/SMyPGz19H vrLKHFaduO6iZ5YNxN4rAU9xO3Un3/jlAbdIjVX93HPNXd3jMU1OIysqWfXKkUNUKyoY 0gUmIDnw6FVymWmZ/n6vu4lESO0In1EnPz7rxWsnTGNspvofDO64/HtnNXDzPnwuBdhv 02LcvGRMC2mYzSjM/4x9soEazM0S8wawrd89Stabaxk7UAKfEs+2S5wilBYJcvCdyAje 7aMw== 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=1KVrD/LnRsN9N7k2d12iARV4DA2tVMW012QtKSrD46c=; b=cZLko9Y2stcyljNegRJEJOaglYrAPw2j8S2OtNbHBElwUrj7Ghd/6vcYm3JA9sm6OO fiEJuvgxkZvsvkVXXuH2hY8jfRMIqNS6ofHYn2cJpSUc/eh9xh8QDO8Ipxvkqnh+KJuY +csjrWeW8Q616LC0oT/aACdQ5ezbtAlEiT7+0cmHKRQSm0Zr1sioQqceKY7ukPmo9AhP 5TdoywxxeZBSsX1Z+mGrdGPZzySeIDsEkTERzItizlvqZ6c9tR8CkDmwx6OdBRoq8bHW WiBraLg9qgxAFm8NdT8Lc8WH19tsSDwtYzWuoywtEqREJGkXRYK1fF5Fo1mSTcZ2p9qe k97A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="WpK/wBKT"; 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 q15-20020aa7d44f000000b0052553cc3360si5142383edr.118.2023.08.20.20.39.56; Sun, 20 Aug 2023 20:40:20 -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="WpK/wBKT"; 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 S232350AbjHUBUP (ORCPT + 99 others); Sun, 20 Aug 2023 21:20:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232289AbjHUBTv (ORCPT ); Sun, 20 Aug 2023 21:19:51 -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 DD96AEB for ; Sun, 20 Aug 2023 18:19:40 -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 48885625F7 for ; Mon, 21 Aug 2023 01:19:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44843C433CC; Mon, 21 Aug 2023 01:19:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692580779; bh=ABB0VEm/1qgHSMYLRDciSz5DC9qBJP3kxsxjFgJZZ5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WpK/wBKT6GpIMS/8IETxzEpkcHpLnvA9UsqO92eoDLBs99jIMhyVrlhW9jJzghW/1 +dp+CPf3Xu4AZUDYX12af367DJWF37hKsebdxbyaC0irs5eKXvv6TfuKCemNcygLuS csw+q6zuFy22vxEAN8JXX3hDzGS6sIgkYF+JtTyMV7G267gC2BVWPs7KbM3Hac7v+C JVlt4YBAci80ZKZlQA3ushe58ywyXomV0s8a4JjZoipLLi010ey02sVY0NUwzwuo0A 7GvkaWHzjouqK/v+oSpjshtdtsCiyMZrTVYhA2e1IhQVOW9U/fmT9Uq8M6NwkiJX/z 4LHfCGUIvDD+g== 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 21/22] x86/nospec: Refactor UNTRAIN_RET[_*] Date: Sun, 20 Aug 2023 18:19:18 -0700 Message-ID: <316ee83d450de92924273f65580a7d23f7355f40.1692580085.git.jpoimboe@kernel.org> 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=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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