From patchwork Fri Oct 20 11:37:17 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: 156031 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp990869vqb; Fri, 20 Oct 2023 04:38:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnovHnU5H2EO3WTW6EDgGNdUTFQMFHbvtS0tV/1/4wQzu1i2YAFg/XGuNvPR7aOq08zkm8 X-Received: by 2002:a17:903:24e:b0:1c5:f110:efa0 with SMTP id j14-20020a170903024e00b001c5f110efa0mr1727522plh.30.1697801930389; Fri, 20 Oct 2023 04:38:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697801930; cv=none; d=google.com; s=arc-20160816; b=BueDIxUj7AuOtrTpp4+NKDOV32XqouNUllKVHe7HxGA++dubBPBe86oh9esvIlwq9g oh6aSLHJxAaqXzC8BBRobd8LCuNfS/2gcG7l+4xIEnaGImWDV+od1OYoFOhSUhN1J7kB ZRVxDa/pkdUXGN2VbwM568qTK6963oSK02ZwuErzyBPoYzDDvsYo+gj0Bj477U94nPJ+ N3CnyPiMTlITEZdVfr+IP18NUi/uHXF9smgATMdcJ+8ucTOJjsX7VQDjr2FXHdrsi7gs 6s+voV2f0vqenXWk3YfSkUALDLDiHq2Dj4zhYoBsF20zPhW3JFQyPrcTiVOInzVRYOT7 WVgg== 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=slkUJVLkIZ2/W81wH7uMrMnpVIv0aEYCumyRZYwPMno=; fh=TJa98jjcJcAUyvo2yQiOqi+wukdLlQU80th5XskGe8U=; b=pbIBd56PmmkknYG2/E82rHkBeoZT43s+efI50T4CS171/HEWJ86tmbA8iNVhFXys2H jXQDKNzcN7Of3MKwEggBMm/33TUD8N4C+jPWWrrOz2yWxsZPvfyM8HCiyZHhIDZRDkV0 GtG2A6+0H9fpLAX3hAModIXbK/KqyOOc8BwXDCTGEtKNSKAz75yLh5TFP8715Vlc6YRE Z2F3N58zl0bT8v6FeqkwsroP7xGXQy8Ejh9h42JxhyQ13wrG5dr+yWTINM3qjI8Q+hxb /z/f8C+Sz4ysMLHTD15PVinG4CgW/azWQylzTiDsfAr81JUcshy5vjVIAKgJjGQJhI+T C1Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qGDVtnjB; 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:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id g19-20020a170902869300b001c3e13018ffsi1578834plo.51.2023.10.20.04.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:38:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=qGDVtnjB; 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:2 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 agentk.vger.email (Postfix) with ESMTP id 68ED082F09AA; Fri, 20 Oct 2023 04:38:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377204AbjJTLhm (ORCPT + 25 others); Fri, 20 Oct 2023 07:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377176AbjJTLhW (ORCPT ); Fri, 20 Oct 2023 07:37:22 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 677FCD51; Fri, 20 Oct 2023 04:37:19 -0700 (PDT) Date: Fri, 20 Oct 2023 11:37:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1697801837; 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=slkUJVLkIZ2/W81wH7uMrMnpVIv0aEYCumyRZYwPMno=; b=qGDVtnjBlaCykaNLg4xo89Sw2yrw/yfccN4PAGmECfd6p88auVNJYpbewOcUlCWlAhYowX bNsqMY4IOSEJDIhu6N0FbOkiCOzIqvBWupG4sctm+PL+i9/icPe+DXkbpiFyQSivMpw1U4 7DFKL3BGEkZdopEDDGEhhoW1H2bTHxts8af4W9WEaBVJh3nyusAv88EEFEpFbEeTx049hj l+HQ5eH/1ErXlL7RMu3w2JdOWzLYiECNQnyjp5zhGaT5njXIThCt/eVxEzF0cfdrHzI1Es Rb3io+3tFHYnOm7hZw8o18oY9RlZnaD5aW/mW1O0iC07iWXhZkhGDZvgpBflmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1697801837; 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=slkUJVLkIZ2/W81wH7uMrMnpVIv0aEYCumyRZYwPMno=; b=6BxT+yZklqBGfsR2+oYP3gpe4+8RRNzyvhp6uXx6YvFTId3y2cMC5AkiD7YhGgK13KraUP v00oZhvHssL8vwAw== 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: <169780183712.3135.11984022841629342518.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Fri, 20 Oct 2023 04:38:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776217669953767940 X-GMAIL-MSGID: 1780274357022174263 The following commit has been merged into the x86/bugs branch of tip: Commit-ID: e8efc0800b8b5045ba8c0d1256bfbb47e92e192a Gitweb: https://git.kernel.org/tip/e8efc0800b8b5045ba8c0d1256bfbb47e92e192a Author: Josh Poimboeuf AuthorDate: Mon, 04 Sep 2023 22:05:03 -07:00 Committer: Borislav Petkov (AMD) CommitterDate: Fri, 20 Oct 2023 12:41:57 +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 Signed-off-by: Borislav Petkov (AMD) 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