Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1236154rdb; Mon, 21 Aug 2023 01:09:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIuZ4K+Th/eDsdAeE85DNA+7Ox9CUx5l7ESSZuoz6OWgBS+KdKUTsvczoFOO0UOm7vQ/wM X-Received: by 2002:a17:902:f54f:b0:1bd:f1ae:309d with SMTP id h15-20020a170902f54f00b001bdf1ae309dmr4083721plf.9.1692605364755; Mon, 21 Aug 2023 01:09:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692605364; cv=none; d=google.com; s=arc-20160816; b=Imt2LgN2kK7Ae+CEd5Dm8OcFiMDo8bqRzhUACnkbELrg/fx26ERc/vwxVmZ+U8x97s W2GKAy0ZHy51RW2Tq7K+I7by4vW0LGx7SDe9HhacXpereM5mpE73ZQDkUT4QMNCY4pQX YDPFBSqgQEF0byGLXr4o93mfiYYD/8eZ77eCQgu53R18dj3pAFGJ6XlLYR8YCdgFAv3e ndIxisXf9nTxZz3Wb7iv0QkyKGaj/uVkOgLWdS14488zd9hJcKs7px3aXlxZAWhH0HYg Izzl2gfPnn4/KSuOMQCtOlFOi8N2rf4pzYrtiiK6x//nG9F+BnenPHQL8TL9i2KERQA7 VxNQ== 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=L/dzgkxQA+In6HfB9p0CxR1u0ZUKsUyMntA+nVc6ASY=; fh=1KVrD/LnRsN9N7k2d12iARV4DA2tVMW012QtKSrD46c=; b=SvQslYox/zaRMTe6IUJYZHUv7z5Qal7U9NdPdP9JOZqqfQgOjUVnX6mdniiVbG7dYZ NqGlgGOWuWQ26QO2QMGMjrfXIVdrjRv6G0TVjvxrfLDwhTFtkqqKjnQ/1UhOR/54Whew rJVrn05+RphUq3whSe6cva20wXKlR7eDH45JIoxXDn5nA08d06a1VK57tOO82xkB9eCd GINctsYDqHYhf7n3qLgGsNvrapkkouYifYTCfyERS+TvdvhTXczFz/Wl6Adxc6zw9EQM 7P3V1r5kTGpU/iR2HNnNsR0kR40RXvoAyG7qg6vnbB+xhI0V1jnhBarynoCl8MOgLbAs Naug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rXszqG9h; 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 l6-20020a170903120600b001b8ac52a19esi7065362plh.436.2023.08.21.01.09.09; Mon, 21 Aug 2023 01:09:24 -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=rXszqG9h; 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 S232295AbjHUBTg (ORCPT + 99 others); Sun, 20 Aug 2023 21:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232273AbjHUBTb (ORCPT ); Sun, 20 Aug 2023 21:19:31 -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 E51D8A0 for ; Sun, 20 Aug 2023 18:19:29 -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 7719C62600 for ; Mon, 21 Aug 2023 01:19:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72EF5C433C7; Mon, 21 Aug 2023 01:19:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692580768; bh=DW3Rkm64vuwtwMBbIqCA2GpSEy3gnsoalKuEuFJJaWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rXszqG9hnuzM5B5aORpcJM5tFbtP47DwlBt7MX4jqQcPs1Vi0T7hd151utynjdkf8 P+TF4obMZ7dlEgLmkl5eh+zDf/ySNWvOmoCauwHrJ0ZL55i9Yo8xLvzsEpdO32RY/k oCzenoJe+M77+MIVT+m0McZil227wB+kjSqQZGne3I93oqWuqan16w2/9jHwf5kiFP Wj9oK3wXDHuL/QDHs+9XXwhs1az1c+HWXtojP8LXX2tjNk7ISgBBYTPiHX3U0wgdt6 HrxwmiIqoesxLDA942+qurp0XondanfqJTFPyad0g1WH5FRMBsRHyM6IEejydodvVl bcW9O0sdSQ5iw== 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 03/22] KVM: x86: Support IBPB_BRTYPE and SBPB Date: Sun, 20 Aug 2023 18:19:00 -0700 Message-ID: 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 The IBPB_BRTYPE and SBPB CPUID bits aren't set by HW. From the AMD SRSO whitepaper: "Hypervisor software should synthesize the value of both the IBPB_BRTYPE and SBPB CPUID bits on these platforms for use by guest software." These bits are already set during kernel boot. Manually propagate them to the guest. Also, propagate PRED_CMD_SBPB writes. Signed-off-by: Josh Poimboeuf --- arch/x86/kvm/cpuid.c | 4 ++++ arch/x86/kvm/x86.c | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index d3432687c9e6..cdf703eec42d 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -729,6 +729,10 @@ void kvm_set_cpu_caps(void) F(NULL_SEL_CLR_BASE) | F(AUTOIBRS) | 0 /* PrefetchCtlMsr */ ); + if (cpu_feature_enabled(X86_FEATURE_SBPB)) + kvm_cpu_cap_set(X86_FEATURE_SBPB); + if (cpu_feature_enabled(X86_FEATURE_IBPB_BRTYPE)) + kvm_cpu_cap_set(X86_FEATURE_IBPB_BRTYPE); if (cpu_feature_enabled(X86_FEATURE_SRSO_NO)) kvm_cpu_cap_set(X86_FEATURE_SRSO_NO); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c381770bcbf1..dd7472121142 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3676,12 +3676,13 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) if (!msr_info->host_initiated && !guest_has_pred_cmd_msr(vcpu)) return 1; - if (!boot_cpu_has(X86_FEATURE_IBPB) || (data & ~PRED_CMD_IBPB)) + if (boot_cpu_has(X86_FEATURE_IBPB) && data == PRED_CMD_IBPB) + wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB); + else if (boot_cpu_has(X86_FEATURE_SBPB) && data == PRED_CMD_SBPB) + wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_SBPB); + else if (data) return 1; - if (!data) - break; - wrmsrl(MSR_IA32_PRED_CMD, PRED_CMD_IBPB); break; case MSR_IA32_FLUSH_CMD: if (!msr_info->host_initiated && -- 2.41.0