Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5315465rwb; Wed, 9 Aug 2023 02:03:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlHotaVYnTVJGo8gTBy607QoRdcHMwyDBez9LJsgY/ojVuzzCLaIGHgeFfWUB2jT3zeSJy X-Received: by 2002:a17:902:7048:b0:1bb:f82f:fb93 with SMTP id h8-20020a170902704800b001bbf82ffb93mr1755605plt.2.1691571794782; Wed, 09 Aug 2023 02:03:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691571794; cv=none; d=google.com; s=arc-20160816; b=UdR7S/idufmv8rBoSgJ7L3XUI7rhbu+5NqyV+2Q2TpC9aJjOEvrC5tDB1g0NCo0GzS xd/9WYu29LIaQm26+2uaJUK7VSW6liGLD/m/DgOzbMe1FTDzCNB6/U1pSA+2ZGduomKB PuVtiCi9PmD1OZpr+nCYucsJ3mHsYT6BLsC/avEcP6b5kliAl+a9jNj4wvz/pJMWcarQ SdexvAi3i5ze32KKFgjr+MGvlTjjI88sx9DHArAJcZpdwXYzVeLkKcVMe/bb11AF7xWJ gfzHsdCHZtkcGki/BIF7ioA+xYbz3V6bCROCQeSasAEgfRyCUWj2lkxcPUmC+07b4eFU N3cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature; bh=8xFU9MBBRCXYqcJsEM5lvzkq5hInOlKwoKgeAy28v10=; fh=o45i9bBrOE/GuAHaEwxsN59PvrZuIOmhioZFWcmA1tw=; b=ISZc/EuiOFZZrBdhYsbViB16auChXICqpgbih83yi7Wo+8hHc1jD0ejypKZj81HQay 7H1ApigXaV1u4NQ4CDLPamBP3ban0hbm/a4IMKM3bHIo75NXH9XGQFFRQyCdGX8Ij8wS e4cbmNsaTcPLQad25CLX0/eM+Mq1XUDICpAJWWhNHcwS+adfp8WCTsSXpGs/24j2yx44 DagehTobIlQg3q9UNo5WxEodBUtAO9oNJL1PMuxwyaYLErZglQplI67y9iXqgS99UCiw PJ4BBYa42Jto+/DFxoFwXugH6xDkhdKvfcnPloCwEggyVLtJaJqw6dLiEnaTp0Q5f6+D JQEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EajMsa8j; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m9-20020a170902bb8900b001bc7d730accsi3055665pls.382.2023.08.09.02.03.02; Wed, 09 Aug 2023 02:03:14 -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=@infradead.org header.s=casper.20170209 header.b=EajMsa8j; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231218AbjHIH1p (ORCPT + 99 others); Wed, 9 Aug 2023 03:27:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231534AbjHIH1D (ORCPT ); Wed, 9 Aug 2023 03:27:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFCC7172A for ; Wed, 9 Aug 2023 00:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: Subject:Cc:To:From:Date:Message-ID:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To; bh=8xFU9MBBRCXYqcJsEM5lvzkq5hInOlKwoKgeAy28v10=; b=EajMsa8j7ET1nFWY7bCbGtfEDw 0CBpeSECh8MfbWfhOl9u4tWKKqlAqaQkwaXaSa1d6nFKLOeo6R5eMjB4OXYavYxt7Q3Js7SD1MY9m 5qZJ6H/JlRh/SScwrpc8/e9cFA2D7PC4gqGn5Tf8QxbATfPY9YCbil4gclo7Z+QtyNP6pDsXvCjVn S3Z7Vfehk9s1ovI/9a8+eLbe9NUzLgb6/AdkARaAmq4pqdNGnfImI67g3b1UWQAfQKf69gD0uHEHL cMlWyBC5VFpxxyteSUvl0AQco39jlY/g8muU9AmEbiw6vEN40+c38fJiRFR6Lwt2ExUzJv4oC9BZW c0N8Zxdw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qTdag-004olT-3p; Wed, 09 Aug 2023 07:26:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 96AF430067B; Wed, 9 Aug 2023 09:26:44 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 0) id 5FAC82CEC71E0; Wed, 9 Aug 2023 09:26:44 +0200 (CEST) Message-ID: <20230809072200.922634286@infradead.org> User-Agent: quilt/0.66 Date: Wed, 09 Aug 2023 09:12:25 +0200 From: Peter Zijlstra To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, David.Kaplan@amd.com, Andrew.Cooper3@citrix.com, jpoimboe@kernel.org, gregkh@linuxfoundation.org Subject: [RFC][PATCH 07/17] x86/cpu/kvm: Provide UNTRAIN_RET_VM References: <20230809071218.000335006@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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_NONE,URIBL_BLOCKED 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 With the difference being that UNTRAIN_RET_VM uses X86_FEATURE_IBPB_ON_VMEXIT instead of X86_FEATURE_ENTRY_IBPB. This cures VMEXIT doing potentially unret+IBPB or double IBPB. Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/nospec-branch.h | 11 +++++++++++ arch/x86/kernel/cpu/bugs.c | 17 ++++++++++++++++- arch/x86/kvm/svm/vmenter.S | 7 ++----- 3 files changed, 29 insertions(+), 6 deletions(-) --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -299,6 +299,17 @@ #endif .endm +.macro UNTRAIN_RET_VM +#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \ + defined(CONFIG_CALL_DEPTH_TRACKING) || defined(CONFIG_CPU_SRSO) + 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 + .macro UNTRAIN_RET_FROM_CALL #if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \ defined(CONFIG_CALL_DEPTH_TRACKING) --- a/arch/x86/kvm/svm/vmenter.S +++ b/arch/x86/kvm/svm/vmenter.S @@ -222,10 +222,7 @@ SYM_FUNC_START(__svm_vcpu_run) * because interrupt handlers won't sanitize 'ret' if the return is * from the kernel. */ - UNTRAIN_RET - - /* SRSO */ - ALTERNATIVE "", "call entry_ibpb", X86_FEATURE_IBPB_ON_VMEXIT + UNTRAIN_RET_VM /* * Clear all general purpose registers except RSP and RAX to prevent @@ -362,7 +359,7 @@ SYM_FUNC_START(__svm_sev_es_vcpu_run) * because interrupt handlers won't sanitize RET if the return is * from the kernel. */ - UNTRAIN_RET + UNTRAIN_RET_VM /* "Pop" @spec_ctrl_intercepted. */ pop %_ASM_BX