From patchwork Sat Sep 23 12:20:06 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: 143896 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp157871vqu; Sat, 23 Sep 2023 05:52:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHi/TiSxKwMMIMGovOc2uoQMWcM32gExyoGFQjbx8EtpA4iweeR6HoSfyEoy8+iN5c4SOXO X-Received: by 2002:a17:902:c94d:b0:1c5:c546:fece with SMTP id i13-20020a170902c94d00b001c5c546fecemr6637401pla.34.1695473555839; Sat, 23 Sep 2023 05:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695473555; cv=none; d=google.com; s=arc-20160816; b=ZjKv7cupMiHZpASmsMFAY0vAbOAkin48aoPLOC8uRvo/MPkFQw2rwiOToRUfmxK1In F2IB+0SI51tLjmmfA6TkjQTVzTmr9bGJ4Z1nuDqLCdQ7c0wh3fh8Z/3SSzYHsffkjv6r fwZMGlUXJAwiko3+UJ0CMKsHOb9VOT3et3tyIRck1N2EowNNwG83vRuimerc/UBtgLmh ZjYPXgM41El0gD55eR57+7gukfuyCUpLG3DsI9q8zCeD78YG3gLi/1W9n8l4R2zciLxK 7tDvJ0ZK+h+SlwZpvPs41Z4jeti4HTWPJIjA0LULH9fbnNbmoXBJkwfje4f1WzsZ0O6s 78pg== 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=M7KEZCoe5ju1kNVC6Zn1SX9PPgHP02P29tTEaFfkK14=; fh=TJa98jjcJcAUyvo2yQiOqi+wukdLlQU80th5XskGe8U=; b=WSGfwOUUid03Swv9/Q9iP3fZ9tKILSMCrnc1JHe1uAGV9MTKSsp+lbkwCRFzKwTmPx hfGdd5lPHDnIHCpXpy+Ph6oYAWq77MeboBB+sOYVTU6fUiSh2Qg2r/fz8uQXhwNHPprq 0B3DGyR4QwlsCAfDlh+CQY6/vkV4h7Nxczwl95CZqX6ulL6fKxtX3oFBaG+GqTnpZ62x 25a0ZA+JgFvAr4XD/RD2FaW362cNe5V/b8mOo8uqA4xKCvwpId47t1lA1ngm4q2LevF7 nPW5O7W2G3fZ4kItzQCEOqqhSiSgfKTaEmOyL14G1BpNgap5r5dlbST0oosLKUZb7bBz AaUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wWbcIuM9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f11-20020a170902ce8b00b001c383a64ebesi1165708plg.319.2023.09.23.05.52.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 05:52:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=wWbcIuM9; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 83EF7812DBCC; Sat, 23 Sep 2023 05:20:18 -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 S231641AbjIWMUT (ORCPT + 29 others); Sat, 23 Sep 2023 08:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231596AbjIWMUP (ORCPT ); Sat, 23 Sep 2023 08:20:15 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6604199; Sat, 23 Sep 2023 05:20:08 -0700 (PDT) Date: Sat, 23 Sep 2023 12:20:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695471606; 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=M7KEZCoe5ju1kNVC6Zn1SX9PPgHP02P29tTEaFfkK14=; b=wWbcIuM9YjU4QVUjKq2COXKSoxR6pNNpOTqaMrd1UnIPA/k3RLbuK3Lt6UeRZVL60dviRk Jgg8C3G6Afv2N45aEfE0MsuBL427qEY4R8KeJNqkBdIYcMC/7tmUdP+95tQW6JxuTz34cH LD9NvT3bvGmItCrg7fzgeYcTtjippuq38IOEFj7NMoy5D+qQhEya4Izc1+FPVc/K9fftMY dgNA8BoqxS6kXml3fhqwQ1v+Q3ahLp2L6x9B3zTN3iLevOa0gagw06BvjjFQnnsxoz0JpR Nl39hfnJ1w8FA+50mHatp4INUFoyUHOFIhxnL+pO68l1X076YCea+ayDZl7C4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695471606; 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=M7KEZCoe5ju1kNVC6Zn1SX9PPgHP02P29tTEaFfkK14=; b=QFBUwWbKTKfjrh28C86pvZzIHXygW/jW+1CL7kYr0+zo6nOM9bdGRKKedyWmhjcSFRWuOm SVT0QEdbU4moxXAw== 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: <169547160606.27769.3396015442662054917.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 23 Sep 2023 05:20:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776217669953767940 X-GMAIL-MSGID: 1777832879194172666 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: e653cf101de2ac99d92049c38735cebc537fa2fb Gitweb: https://git.kernel.org/tip/e653cf101de2ac99d92049c38735cebc537fa2fb Author: Josh Poimboeuf AuthorDate: Mon, 04 Sep 2023 22:05:03 -07:00 Committer: Ingo Molnar CommitterDate: Sat, 23 Sep 2023 14:13:03 +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