From patchwork Tue Sep 19 09:53:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 141798 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3263685vqi; Tue, 19 Sep 2023 03:14:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZjrpVro3NMpI+C5copZX19dfSkJ1v6UIzPzp2VgQLmXW0uWEAtJMWXQZJuwj9YMQuoRZT X-Received: by 2002:a05:6358:9491:b0:134:e3d2:1e50 with SMTP id i17-20020a056358949100b00134e3d21e50mr11853630rwb.18.1695118465051; Tue, 19 Sep 2023 03:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695118465; cv=none; d=google.com; s=arc-20160816; b=Z3cV0+zEOfco+KbnI2ITm3wRy0Hq0bw95zJtWuCOpmSo2QjO+UTbSp/lWI6lxR0aXy vJVARqjV3Htb37UCitGdaN6x4847e/pDDhT8GMwKdlxS4cBbyib7aydSPXiP+WrFutGf /BupDDwJO+ZbcOfhDK0JFLmbZdxWb1xoPGiMHNr2/j1TwZOfYZ1tVINWAES6bVZASxlz j6iLJ7mQK546uZNc5S2L6lIRxoo1zJNnXBDwhpuTr7SK+7qpYtTgX0cXwc7qQmCp5KEt 1Tlp2vqKCY06TQ14fubgu0yPxCudz1+tUaS/qInQXLfrgMGth6FioBVMRRI0lbpwooCR gp6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=mtOpL4jmWHLRhl2XYTHgN/f1js2UvQ3IL6p/GzsFw2k=; fh=TJa98jjcJcAUyvo2yQiOqi+wukdLlQU80th5XskGe8U=; b=bCoMKyF/ibOz3Cb6uKYbd7JO5o1FPwxiK12Uoz3Kh74SPN+UnWdmZaciIX118ZPZaS 8LN+45teSJIqhTPAqbFIDgu7RM1e4zYcuDhTKPUibHRlKM9xTzviKHbKHdcJ3R0qsTH7 mieKCqaeo9r0dmSe6HpkO+/uCY8KMWzp91SX/k32dMFSJtUCOTk0sZ2pAqrW4p1R9dqR /n9w+ClOINN+AmuanA0ch5bQk4XI954cbh4bFqqS9pr2SGiZOhFJe9MySWVzrnwv9yj5 ZAdLf0xo9mrH0sP1rEuPMSvTtfZl3zeSD89haCT5wizyJy1A2SPmhFwWtaoshjO30R/9 upiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I5rPv29T; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z14-20020a65610e000000b0056951c32d80si9180836pgu.556.2023.09.19.03.14.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 03:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=I5rPv29T; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7F33081BAF27; Tue, 19 Sep 2023 02:53:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231909AbjISJxj (ORCPT + 26 others); Tue, 19 Sep 2023 05:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231799AbjISJxS (ORCPT ); Tue, 19 Sep 2023 05:53:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF3891A6; Tue, 19 Sep 2023 02:53:10 -0700 (PDT) Date: Tue, 19 Sep 2023 09:53:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695117189; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mtOpL4jmWHLRhl2XYTHgN/f1js2UvQ3IL6p/GzsFw2k=; b=I5rPv29TKX73S0O8uNrXQyWFk+QcOI5a6LPsI4mxIWkOwxuamzwg53DqaTFC4y0X0QrETD NDitOl16+xLiBgoZlWvif1DgzaQip8JBftZHyhc6qDQzztZLz1MSwSUzIsRxeUicc03oGw e6xUXw/FPuKGeDtib6IVT3hvHhcYe+LMx6lGRz+fqGPCHhy4vBKxUnwk4G5OeEDwGRFnU2 N0Skvg0261yfAPXJSxuq74jr21iM1cv3cTFk6cMMn8KZNDQnZRgV25c6MyDHsbTl0tf71G x9Fp8KqGT41H1TeKw6bWgXoiUMrilrtbkbYPVhoP0wPlx7UsCiIksOoI/Miing== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695117189; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mtOpL4jmWHLRhl2XYTHgN/f1js2UvQ3IL6p/GzsFw2k=; b=sGDPWpaWDDQ1U8JptdTKu/eU9JWd5Plkf/HwNZ4BUrnHakve79pxWw1CG/SHwEfQHiyc8C TXtwvtEVxP+AN/BQ== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/bugs] x86/nospec: Refactor UNTRAIN_RET[_*] Cc: Josh Poimboeuf , Ingo Molnar , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <169511718870.27769.18298208676594278772.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 19 Sep 2023 02:53:47 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776217669953767940 X-GMAIL-MSGID: 1777460539386630004 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: 82c6462008641aed2f213e7c51394cb8c7c1fce7 Gitweb: https://git.kernel.org/tip/82c6462008641aed2f213e7c51394cb8c7c1fce7 Author: Josh Poimboeuf AuthorDate: Mon, 04 Sep 2023 22:05:03 -07:00 Committer: Ingo Molnar CommitterDate: Tue, 19 Sep 2023 11:42:48 +02:00 x86/nospec: Refactor UNTRAIN_RET[_*] Factor out the UNTRAIN_RET[_*] common bits into a helper macro. Signed-off-by: Josh Poimboeuf Signed-off-by: Ingo Molnar Acked-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/f06d45489778bd49623297af2a983eea09067a74.1693889988.git.jpoimboe@kernel.org --- 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 51e3f1a..dcc7847 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