From patchwork Fri Aug 26 21:00:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 12956593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AD69ECAAD6 for ; Fri, 26 Aug 2022 21:00:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345022AbiHZVAb (ORCPT ); Fri, 26 Aug 2022 17:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345012AbiHZVA3 (ORCPT ); Fri, 26 Aug 2022 17:00:29 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1609DE1916 for ; Fri, 26 Aug 2022 14:00:28 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id c135-20020a624e8d000000b0053617082770so1366022pfb.8 for ; Fri, 26 Aug 2022 14:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date; bh=kKEei8yAqADdtFSTkBJAqxxc/VkzhmqquJB4WzGX/lg=; b=HGIkNNvNfFuRTV1NzxYWfcLHK2EqNDy1qPNe4jKYWKPKfJT1k6B6D4xWvTI9MrS+zE 0gqqVXsm2+TWENyW33Bf12O4MKNDL8n9hpm1YrP2MU2lvrRFeg1f2q2tZLaD95gK/kLY 6hHfzhTfaRffLA1OoACODVmSDxg6GP0xVpaouNtRV8toIKhcF+ZufLFDi+1fP1A635l5 rmKlbYVKilf1mC6mByzgtwfJBuAJKmI25N5R/TxVg7LsKPibAfr1UA27IulsraTWWg2Q aVMcy28/Bf/mX7v+1PVjMvoaHrm1/kHR70JDAThSCpZY3FfAGjNuGu8n3SDMN93sCc9X uuxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date; bh=kKEei8yAqADdtFSTkBJAqxxc/VkzhmqquJB4WzGX/lg=; b=a7Nc6x20KzSTgCp/4s6VK3jCRDXjQeAHqT32pqgTzTuNueClYWFUUg+eA8B2nILWZS FZ42/ySz1t3qYan6mVcjJKRFM0+P7Z7Bt4YOnNvM2TyKCuryrIz8M+b7reQ7fe+K/LhP v6Wc2znpv5k9m/2CqiqDyMhhzAjiTp9MASvuYw/Lth37qTUp7R6lf6xjr8dYlPF3fSSq YeMcfgFqQuIN0PbSlxboLQEXq9CxWOb/qCvbEuC6UgPk9m1t1v92WWxRx5OhCeQb4sxD ESAMBPBjTpUA5auRw9IGUalnxOJ00Jn6qQ0ESpQFl+UGraNBmnxIMdgy5fzI8bIe/i+r UvPA== X-Gm-Message-State: ACgBeo0BYYDEm8/WgVZZQaFkcsiqjt2HVc51JEtH7sjPYfEoMQin/lEm VJ/AgGcPRGG5J7bMdpXzf6UNa4R7QeePKqWeut5spsL86q2711F/KKHiQQFLHmpNlYhjikw4jgP pV/UJQVN4okiiaw9VXHiwI6zeSyH0bVlEbr+SGRcdvwwyKc1sEUen17/tH0vvqxg= X-Google-Smtp-Source: AA6agR44YgVjl+zSdjdmZzaAaHy96t1Ze+2e/RYJnTzHOcfLWqMjm14EfFmxSrQoDYyXyZivoKiVQXAlpYWhYg== X-Received: from loggerhead.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:29a]) (user=jmattson job=sendgmr) by 2002:a63:5702:0:b0:42a:b77b:85b3 with SMTP id l2-20020a635702000000b0042ab77b85b3mr4511539pgb.263.1661547627489; Fri, 26 Aug 2022 14:00:27 -0700 (PDT) Date: Fri, 26 Aug 2022 14:00:17 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826210019.1211302-1-jmattson@google.com> Subject: [PATCH 1/3] KVM: x86: Insert "AMD" in KVM_X86_FEATURE_PSFD From: Jim Mattson To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: Jim Mattson , Babu Moger Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Intel and AMD have separate CPUID bits for each SPEC_CTRL bit. In the case of every bit other than PFSD, the Intel CPUID bit has no vendor name qualifier, but the AMD CPUID bit does. For consistency, rename KVM_X86_FEATURE_PSFD to KVM_X86_FEATURE_AMD_PSFD. No functional change intended. Signed-off-by: Jim Mattson Cc: Babu Moger --- arch/x86/kvm/cpuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 75dcf7a72605..07be45c5bb93 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -62,7 +62,7 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted) * This one is tied to SSB in the user API, and not * visible in /proc/cpuinfo. */ -#define KVM_X86_FEATURE_PSFD (13*32+28) /* Predictive Store Forwarding Disable */ +#define KVM_X86_FEATURE_AMD_PSFD (13*32+28) /* Predictive Store Forwarding Disable */ #define F feature_bit #define SF(name) (boot_cpu_has(X86_FEATURE_##name) ? F(name) : 0) @@ -673,7 +673,7 @@ void kvm_set_cpu_caps(void) F(CLZERO) | F(XSAVEERPTR) | F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | F(AMD_SSB_NO) | F(AMD_STIBP) | F(AMD_STIBP_ALWAYS_ON) | - __feature_bit(KVM_X86_FEATURE_PSFD) + __feature_bit(KVM_X86_FEATURE_AMD_PSFD) ); /* From patchwork Fri Aug 26 21:00:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 12956594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C702BECAAD8 for ; Fri, 26 Aug 2022 21:00:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243298AbiHZVAc (ORCPT ); Fri, 26 Aug 2022 17:00:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345003AbiHZVAa (ORCPT ); Fri, 26 Aug 2022 17:00:30 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6590E1908 for ; Fri, 26 Aug 2022 14:00:29 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id m5-20020a170902f64500b0016d313f3ce7so1724990plg.23 for ; Fri, 26 Aug 2022 14:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=nLh/sEBwEiC0QIMEtp/GiRB6P15JdaiLeuaytMstG80=; b=NZjG81ZeUzl6mXbsnxcda2x0BhOOBuT+qa2NRq0psVS1+DERw+ZHyY1KUUBMqOxg5t Qkt6fIRfXQzqMFj6zNPkcwe9+qkx5vVNVdHxtPdRRa1kx7Ze+yapnmNo0uFhAIzxyHzY czrqjPsfIu7YCF4jAJdNbqAAOq3X720LzZfPcmDzgerQHglU2j+JlJGloaCsWcV2ePmA sbo34xZJot4iX5eX9s6Hsj87Zju7MsZGhgroefOav40cwpgysB17xuBi9q2wWwNlpNTw gdVX3MPQ7sMb8a8A5QZaYvxeSXgJ1XvmeYfNn7b1146dqlp9JaPUEIEeO7BYymQ3CvN9 vVqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=nLh/sEBwEiC0QIMEtp/GiRB6P15JdaiLeuaytMstG80=; b=z3CbZP4/y9dPUlY1b079p6rddnnJwHfgljEkPCU2FLF72UmeAntKOYTWoUDXOQAHLf cargpWp/imB2ctWRKM3L7xZQ6woBos/YF68CMqo6HI08/S/Yr7S5suayvuAzQ7YxaLLl Aw1Fj5o79gFkkL0M2EO46X+ewmv1WBcIga8Jpll24YnxhmYQiJwesHxF/fR2+eI8bqmR Rf4ne9XhoxcRRLmS/vjEBECkGA6RUq/NwlfgnCvjrUQATcxAVa2/H6qR4eDiPL1hb8VT udC0oMV1j1H2txQ30N3pIQ78AgwWiG2Env1+sTdrRKXgfb8Gn3aw43vvtIxv3LVZQabv bNMQ== X-Gm-Message-State: ACgBeo2kX7LGW8glMuKy1Uc8gFzzWV9/w8G9lwxxwi/OBuFEWn88M98f 7w8Gm7vvnw/GKgcdM4VPe1F+vHgp4QKDZMje9eAsuaU/CGhLXXExZxhpLpVzSLM2xBYuxnBX69o xbISvjzi0KF3W5+8d2FPmmF55RWhzukpQiAK2xsw07xphgVBLJU6r+eyv0WvCyY0= X-Google-Smtp-Source: AA6agR5A30xxYjPVF4S/var2cLfF/zrE0FpjC6vf2Q71X3hqtR2cJizCDxsFjtfB3WNp7PRr06jiX3X5IOz/yQ== X-Received: from loggerhead.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:29a]) (user=jmattson job=sendgmr) by 2002:a17:90b:1803:b0:1fb:45e2:5d85 with SMTP id lw3-20020a17090b180300b001fb45e25d85mr6315953pjb.163.1661547629232; Fri, 26 Aug 2022 14:00:29 -0700 (PDT) Date: Fri, 26 Aug 2022 14:00:18 -0700 In-Reply-To: <20220826210019.1211302-1-jmattson@google.com> Mime-Version: 1.0 References: <20220826210019.1211302-1-jmattson@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826210019.1211302-2-jmattson@google.com> Subject: [PATCH 2/3] KVM: x86: Report CPUID.7.1 support on CPUs with CPUID.7 indices > 1 From: Jim Mattson To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: Jim Mattson , Sean Christopherson Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Previously, KVM reported support for CPUID.(EAX=7,ECX=1) only if the maximum leaf 7 index on the host was exactly 1. A recent microcode patch for Ice Lake raised the maximum leaf 7 index from 0 to 2, skipping right over 1. Though that patch left CPUID.(EAX=7,ECX=1) filled with zeros on Ice Lake, it nonetheless exposed this bug. Report CPUID.(EAX=7,ECX=1) support if the maximum leaf 7 index on the host is at least 1. Cc: Sean Christopherson Fixes: bcf600ca8d21 ("KVM: x86: Remove the unnecessary loop on CPUID 0x7 sub-leafs") Signed-off-by: Jim Mattson --- arch/x86/kvm/cpuid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 07be45c5bb93..64cdabb3cb2c 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -886,7 +886,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) cpuid_entry_override(entry, CPUID_7_EDX); /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */ - if (entry->eax == 1) { + if (entry->eax >= 1) { entry = do_host_cpuid(array, function, 1); if (!entry) goto out; From patchwork Fri Aug 26 21:00:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Mattson X-Patchwork-Id: 12956595 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0BD76ECAAD6 for ; Fri, 26 Aug 2022 21:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345030AbiHZVAj (ORCPT ); Fri, 26 Aug 2022 17:00:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344803AbiHZVAc (ORCPT ); Fri, 26 Aug 2022 17:00:32 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3519E1916 for ; Fri, 26 Aug 2022 14:00:31 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id b9-20020a170903228900b001730a0e11e5so1711843plh.19 for ; Fri, 26 Aug 2022 14:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=h4rAinPFGMG5yc8vpdGKhK71xBVSYfag1nRdoNB2yBU=; b=fw5AHYzCT6Fwb0A6pieP7JFsZ5ZWGGTbe/IhWbwDDI33BOcorXXk9nAuHxGjE5bN3e oP4IpB1Bq5ilBwuJW59mCXp48Yzr8I6KV0l8KLIlfduAqZqY7LiizoqZktlG4uPIVHHR Iei4m7NelOBDQvSLR40H6BI7vNJZVXRRTlA6e9ZdkcH3lFr1DYNQKKLCoAt3FdVC4NOw n8YdvMvCd2NEeAI6uMvCa+PGH94iqbzjBrjiJMMDbYdlluieLLcJ+PynEmZDOc8zgyzG UhzxB8nXkI6IApNDnwqQp6pLOLfe1LulGW7Xbinh7Xg8Ac0k3xh5RdDBWgCgJ1H9xqT7 TQfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=h4rAinPFGMG5yc8vpdGKhK71xBVSYfag1nRdoNB2yBU=; b=R0EBJZOeA9V+fAoQqxvYelDiYErU+2fCniK1Y9XBnmPAzvs/Hzq90ZnMPIHYFc7v0l /LvLslUeIKJCjpU05HVq4G5fbRGptyY7Oaq9rRb6OkHyPDYTqf71mB1uNeWgtngGeCFq /j4ZXqHxp/R+7faJrhhSh7hq/Lt809nriPHIFDspVeUeK7lY/MDHkGvURLaRogUY0RBr 7qZ8W60fAfDPXI5vUIWRixk3mYgZxVks3Fo8Q+4nk0XLSt25w9Qkf3onHNLNTCSfnxsa d0I1SrzXcdnvfuxJEDo6BqcoQsEA6GHu9eug0Le4DiTsT4mJxhhr8QwNoo04HLjIa0pX 78SA== X-Gm-Message-State: ACgBeo23/rf2aVqpRmX1uNbhjZCVLMLwkXu+2ZRW5jAHkGJOx3IT+zdX ElbVtjNccBJKhj39q/MnLDx89IQbSY9STpyob7lf18/lsBx1Qy+2l5BXS6kPpYhVR69j5wOAM9x DFnvnnzbJ/M9gn7QYh7IOzQvX1DS4OoJ4rY7DETaX6Wqtaj7C/0tgMlXGWnMEm/k= X-Google-Smtp-Source: AA6agR6/e+urKTZ+3FN64BzLpnvKjtT2iG6+36Uu94+gTivqntR5dyHDZPaEl08dVcwYCJgslvHzAfTBkJstmA== X-Received: from loggerhead.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:29a]) (user=jmattson job=sendgmr) by 2002:a17:902:b08d:b0:172:e2f8:7f1f with SMTP id p13-20020a170902b08d00b00172e2f87f1fmr5039753plr.21.1661547631109; Fri, 26 Aug 2022 14:00:31 -0700 (PDT) Date: Fri, 26 Aug 2022 14:00:19 -0700 In-Reply-To: <20220826210019.1211302-1-jmattson@google.com> Mime-Version: 1.0 References: <20220826210019.1211302-1-jmattson@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220826210019.1211302-3-jmattson@google.com> Subject: [PATCH 3/3] KVM: x86: Expose Predictive Store Forwarding Disable on Intel parts From: Jim Mattson To: kvm@vger.kernel.org, pbonzini@redhat.com Cc: Jim Mattson Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Intel enumerates support for PSFD in CPUID.(EAX=7,ECX=2):EDX.PSFD[bit 0]. Report support for this feature in KVM if it is available on the host. Presumably, this feature bit, like its AMD counterpart, is not welcome in cpufeatures.h, so add a local definition of this feature in KVM. Signed-off-by: Jim Mattson --- arch/x86/kvm/cpuid.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 64cdabb3cb2c..b5af9e451bef 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -62,6 +62,7 @@ u32 xstate_required_size(u64 xstate_bv, bool compacted) * This one is tied to SSB in the user API, and not * visible in /proc/cpuinfo. */ +#define KVM_X86_FEATURE_PSFD 0 /* Predictive Store Forwarding Disable */ #define KVM_X86_FEATURE_AMD_PSFD (13*32+28) /* Predictive Store Forwarding Disable */ #define F feature_bit @@ -677,9 +678,9 @@ void kvm_set_cpu_caps(void) ); /* - * AMD has separate bits for each SPEC_CTRL bit. - * arch/x86/kernel/cpu/bugs.c is kind enough to - * record that in cpufeatures so use them. + * AMD has separate bits for each SPEC_CTRL bit. Except for + * PSFD, arch/x86/kernel/cpu/bugs.c is kind enough to record + * that in cpufeatures so use them. */ if (boot_cpu_has(X86_FEATURE_IBPB)) kvm_cpu_cap_set(X86_FEATURE_AMD_IBPB); @@ -880,13 +881,13 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) break; /* function 7 has additional index. */ case 7: - entry->eax = min(entry->eax, 1u); + /* KVM only supports leaf 7 indices 0 through 2. */ + max_idx = entry->eax = min(entry->eax, 2u); cpuid_entry_override(entry, CPUID_7_0_EBX); cpuid_entry_override(entry, CPUID_7_ECX); cpuid_entry_override(entry, CPUID_7_EDX); - /* KVM only supports 0x7.0 and 0x7.1, capped above via min(). */ - if (entry->eax >= 1) { + if (max_idx >= 1) { entry = do_host_cpuid(array, function, 1); if (!entry) goto out; @@ -896,6 +897,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->ecx = 0; entry->edx = 0; } + if (max_idx >= 2) { + entry = do_host_cpuid(array, function, 2); + if (!entry) + goto out; + + entry->eax = 0; + entry->ebx = 0; + entry->ecx = 0; + entry->edx &= BIT(KVM_X86_FEATURE_PSFD); + } break; case 9: break;