From patchwork Mon Dec 5 19:14:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 29907 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2431865wrr; Mon, 5 Dec 2022 11:17:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf7WC7AcFegCvZRHxO3rsM+EptIfYyLAp0hK7mx4mbz3LkFKLdqEkBdCu2mfYjbCa2JcR6ie X-Received: by 2002:a17:906:4914:b0:7c0:93e6:9f18 with SMTP id b20-20020a170906491400b007c093e69f18mr23230993ejq.350.1670267869387; Mon, 05 Dec 2022 11:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670267869; cv=none; d=google.com; s=arc-20160816; b=tdb3iJw8nKpGkU0zOHRlWFN74OvYVsyaRGLkkcvMSm+aYtaZvVwEmE7ZEmxT6VwU/B Md2vADEtgpVg9iDSzPZHNXDstkSQUSjrxTxlRmfKwRqT9JKDL3WHkILbbaFGIUSMs9eZ NMClscOnY8WFqJ/8eemQneo+g6fv1K1Apd463A1G89x3WXbwWy8SuoetAKyMzFmV57qx LTBeG2apfnpr6Y/BQsV6hV96NfV0oSVN7le5Mz7/X/8LRCfa4iDMdtLbjXQHhjuBIrwo RP0c5kf1BPej6vND7KsMfQH2N8VVRoYauitQpwVnxP6ktwroYaFgbjVU9X4et8mKGyQ4 LjHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=ymzZgm3kdkmvlZIFJjZckFL+Q9shQpgL5xdoQ3SJG8M=; b=yh4kWNDnSnHkc0BkNa2udiEfBxKNyquS1Habo9SyghtfwV8GvXnm9UU1u7g38QwQAi dD8rSUgZe4vh/Ha/pfQyG27EWr66DmW044jXa8vaUqKA/ez2q9rg2xSWsMPw5tE9zRVD okMzl34rrHRTa6pSDRlKcxgP48xsqZUgBBFg/lRG1DG3ONGtyLh6lyY27w0PWj5v2HXP h+1qvhwOeRKI7Vo10dP7LWzsvXOngT5V5BtKl+9FHdCNvFPKt4rKAZk9qEZIAyLam54d 6Wuv9/3ean3eHO1dpQHvruAwmXyScsXjkTqA9lFcT0s66VGoYoorCMWTRIV3XkMXeQSr RjkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=N+f0O3TL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e8-20020aa7d7c8000000b00469ba7cbc7asi250504eds.67.2022.12.05.11.17.26; Mon, 05 Dec 2022 11:17:49 -0800 (PST) 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=@google.com header.s=20210112 header.b=N+f0O3TL; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232801AbiLETP3 (ORCPT + 99 others); Mon, 5 Dec 2022 14:15:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232372AbiLETOp (ORCPT ); Mon, 5 Dec 2022 14:14:45 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3BB21F625 for ; Mon, 5 Dec 2022 11:14:43 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id k2-20020a17090a514200b002198214abdcso10009471pjm.8 for ; Mon, 05 Dec 2022 11:14:43 -0800 (PST) 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:message-id:reply-to; bh=ymzZgm3kdkmvlZIFJjZckFL+Q9shQpgL5xdoQ3SJG8M=; b=N+f0O3TLmyG9dP6pYfSoGC632e996Xnqay8l5DVGY2PYYjTCwZogRFdlVIOVb1Ti2Y b9rFzEfDVcpsvLJTbMQaadyt13t1fJ0rqd971ZQcVX+e0qFY/uKe/i7Pt1b1upPM0XBp I7bJL9/PjJfch7lDXkJpxoww12kGDjcV5b/suDIC29TgOl3MO6DXeS9RHTsQW5a7GYIP UX9zukVVp2G6HQz5NLw8cis+NgJe3T5iljpo63OgjV6XAkqc4d34Mq716rbYTFUa5ggi OpnTIggYBz54pGeYz4Zh6emNpIofVTmjUnqcRQq0LGrexqucvzVUhz2VAP7oyhbq4iQW 3JIA== 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:message-id:reply-to; bh=ymzZgm3kdkmvlZIFJjZckFL+Q9shQpgL5xdoQ3SJG8M=; b=deAAjhWIqN/ich8D10XHaVdpOSn0Kr2NY0z7e6g0pudFpnfzXbHAp2pyPdcgoUCaJc pYZby4oatmndwxAu5z/csfmOHTBhEvdrOQFSubKTD7lxEW4m+5X/uW7TfGZtzzhbaoh2 7HGm2n9o/s0/9Gnd/wUTX7E7Fn936+2/1GpWNKJisnbyENQCjEVXzL8cgc7UAEPPsRZj xdXecQHxlmfek20joc71qkVj+SBblm9Zx1DarBz/yboJV6YGeEU9Wo4IRCGqZLC6HRtP ltRpU1jgtVP3Q5cvBaw7fSxl8dUPc1OljE4Z9tJU3BDAtQX8BfOtEFVJC+k47bYfI6oZ wTrA== X-Gm-Message-State: ANoB5pkO4YKCgp1Vfxv5mHU4hfW6w+doUFqP4Q9cpZR3mnnksJTmrcb8 02GytyGS/4QjNcHnTERmdUO8CHmTyt2k X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a05:6a00:4509:b0:562:641b:c1b2 with SMTP id cw9-20020a056a00450900b00562641bc1b2mr70604752pfb.8.1670267683289; Mon, 05 Dec 2022 11:14:43 -0800 (PST) Date: Mon, 5 Dec 2022 11:14:19 -0800 In-Reply-To: <20221205191430.2455108-1-vipinsh@google.com> Mime-Version: 1.0 References: <20221205191430.2455108-1-vipinsh@google.com> X-Mailer: git-send-email 2.39.0.rc0.267.gcb52ba06e7-goog Message-ID: <20221205191430.2455108-3-vipinsh@google.com> Subject: [Patch v3 02/13] KVM: x86: Add a KVM-only leaf for CPUID_8000_0007_EDX From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com, dmatlack@google.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751402801355027256?= X-GMAIL-MSGID: =?utf-8?q?1751402801355027256?= From: Vitaly Kuznetsov CPUID_8000_0007_EDX may come handy when X86_FEATURE_CONSTANT_TSC needs to be checked. No functional change intended. Reviewed-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/cpuid.c | 8 ++++++-- arch/x86/kvm/reverse_cpuid.h | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 723502181a3a..42913695fedd 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -701,6 +701,10 @@ void kvm_set_cpu_caps(void) if (!tdp_enabled && IS_ENABLED(CONFIG_X86_64)) kvm_cpu_cap_set(X86_FEATURE_GBPAGES); + kvm_cpu_cap_init_kvm_defined(CPUID_8000_0007_EDX, + SF(CONSTANT_TSC) + ); + kvm_cpu_cap_mask(CPUID_8000_0008_EBX, F(CLZERO) | F(XSAVEERPTR) | F(WBNOINVD) | F(AMD_IBPB) | F(AMD_IBRS) | F(AMD_SSBD) | F(VIRT_SSBD) | @@ -1153,8 +1157,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) entry->edx &= ~GENMASK(17, 16); break; case 0x80000007: /* Advanced power management */ - /* invariant TSC is CPUID.80000007H:EDX[8] */ - entry->edx &= (1 << 8); + cpuid_entry_override(entry, CPUID_8000_0007_EDX); + /* mask against host */ entry->edx &= boot_cpu_data.x86_power; entry->eax = entry->ebx = entry->ecx = 0; diff --git a/arch/x86/kvm/reverse_cpuid.h b/arch/x86/kvm/reverse_cpuid.h index 203fdad07bae..25b9b51abb20 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -14,6 +14,7 @@ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, CPUID_7_1_EDX, + CPUID_8000_0007_EDX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -42,6 +43,9 @@ enum kvm_only_cpuid_leafs { #define X86_FEATURE_AVX_NE_CONVERT KVM_X86_FEATURE(CPUID_7_1_EDX, 5) #define X86_FEATURE_PREFETCHITI KVM_X86_FEATURE(CPUID_7_1_EDX, 14) +/* CPUID level 0x80000007 (EDX). */ +#define KVM_X86_FEATURE_CONSTANT_TSC KVM_X86_FEATURE(CPUID_8000_0007_EDX, 8) + struct cpuid_reg { u32 function; u32 index; @@ -67,6 +71,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, [CPUID_7_1_EDX] = { 7, 1, CPUID_EDX}, + [CPUID_8000_0007_EDX] = {0x80000007, 0, CPUID_EDX}, }; /* @@ -97,6 +102,8 @@ static __always_inline u32 __feature_translate(int x86_feature) return KVM_X86_FEATURE_SGX1; else if (x86_feature == X86_FEATURE_SGX2) return KVM_X86_FEATURE_SGX2; + else if (x86_feature == X86_FEATURE_CONSTANT_TSC) + return KVM_X86_FEATURE_CONSTANT_TSC; return x86_feature; }