Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp642091rwi; Thu, 13 Oct 2022 03:17:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4ShPgH9Y9M/+GpGRvri18+dLUx2zYgR1uDBwfwgeAk3fei2Yb2uPRbDruEt+8aKi9K0zbU X-Received: by 2002:a63:1608:0:b0:45a:355a:9420 with SMTP id w8-20020a631608000000b0045a355a9420mr29815745pgl.354.1665656247162; Thu, 13 Oct 2022 03:17:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665656247; cv=none; d=google.com; s=arc-20160816; b=pkxratxY0LJL+fMHa/GJH6AWiuwGN77YLUvks90uTcyzKK37zlWk3dM3IVVKAKFXJs FoNh4D7Tc7uZJZOLw34of6wbtS31mD/3mVh7ojooqiMQwnDNQudNSopn4I9PXyfWN3BZ LBhxZYt0QyCEOHcJoXoh1l9Yo21TSIl10FMhmOG85zKIKZM9YZbNuYcxjkk3yPVY+bhy geNRsZD+DQBYnB52/3QzMT6orR7378AYsLlVB+qqInVzMmfUMqKb/KJiMGglgwlhpvOB Z41cJODIFMb0f4DtRYiwgMyZzFNLM0RHDKQd9SydsGC0LOrG0Ld5ZiIyZA4YVFB7tFNd CdJg== 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=i4O+ol5c5sUsTx7lfOB8mTDwwEXXAIod8O/mKbMJwpE=; b=fMWrxVU0YwiAjTCTXVs9/0C47cBDuh2h1Zh13OuiYUfqu1CdYVxdTjH8HhVqi+sgyw qRE2sSFF8C++CHr3d9l6YSJdtFRaLYGc5bgVd8LKpm4BpDZQdVqtyH4gbjUzBCZoIE1L 4vntQKDuGyopIjpc2SecPDhoWMGa1pub7Z6epnAuBBV6+Syt5+jlXjjE78f58HootreV TOr2z7liOLExV7G4wT+Rbd4Z3HbuCmgXs+QYIBmxFZqkaH0dh1aQ1sCkVitxUIZU1PdH feyDnFymZJPmRLXuFmYAbt+ANZvIDwjVMFeK4q55nhMZgbV9ism9m1iitj+tL6HFIkip hSUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hHB5DSRF; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k188-20020a6324c5000000b00439ce3a76absi16046867pgk.549.2022.10.13.03.17.08; Thu, 13 Oct 2022 03:17:27 -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=@redhat.com header.s=mimecast20190719 header.b=hHB5DSRF; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbiJMJ7O (ORCPT + 99 others); Thu, 13 Oct 2022 05:59:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229594AbiJMJ7D (ORCPT ); Thu, 13 Oct 2022 05:59:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD91AF9844 for ; Thu, 13 Oct 2022 02:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665655142; h=from:from: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=i4O+ol5c5sUsTx7lfOB8mTDwwEXXAIod8O/mKbMJwpE=; b=hHB5DSRF12uYIeKt9EKRO8x8o7W6w9n/EUNLUQp3TCR0Bpla60p81nMEXidu3ASJBrROzA jFAE4CjlJcoTuIjc4Qw7LgLrOSjMy7jcsR02kL82Zm3bjUFzhGghJES+44k66K8UwlGomo h0G7JWLst2AjNnfB6rdde+1Zs5BB4C8= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-y3oPu_LhOPyyeiaQY0G3RQ-1; Thu, 13 Oct 2022 05:58:58 -0400 X-MC-Unique: y3oPu_LhOPyyeiaQY0G3RQ-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1774F2A2AD79; Thu, 13 Oct 2022 09:58:58 +0000 (UTC) Received: from ovpn-194-196.brq.redhat.com (ovpn-194-196.brq.redhat.com [10.40.194.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0206B47505F; Thu, 13 Oct 2022 09:58:55 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Michael Kelley , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/7] KVM: x86: Add a KVM-only leaf for CPUID_8000_0007_EDX Date: Thu, 13 Oct 2022 11:58:44 +0200 Message-Id: <20221013095849.705943-3-vkuznets@redhat.com> In-Reply-To: <20221013095849.705943-1-vkuznets@redhat.com> References: <20221013095849.705943-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE 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 CPUID_8000_0007_EDX may come handy when X86_FEATURE_CONSTANT_TSC needs to be checked. No functional change intended. 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 7065462378e2..9f0be73002cd 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -690,6 +690,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_scattered(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) | @@ -1140,8 +1144,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_array *array, u32 function) /* L2 cache and TLB: pass through host info. */ 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 a19d473d0184..dbe05f168c90 100644 --- a/arch/x86/kvm/reverse_cpuid.h +++ b/arch/x86/kvm/reverse_cpuid.h @@ -13,6 +13,7 @@ */ enum kvm_only_cpuid_leafs { CPUID_12_EAX = NCAPINTS, + CPUID_8000_0007_EDX, NR_KVM_CPU_CAPS, NKVMCAPINTS = NR_KVM_CPU_CAPS - NCAPINTS, @@ -24,6 +25,9 @@ enum kvm_only_cpuid_leafs { #define KVM_X86_FEATURE_SGX1 KVM_X86_FEATURE(CPUID_12_EAX, 0) #define KVM_X86_FEATURE_SGX2 KVM_X86_FEATURE(CPUID_12_EAX, 1) +/* 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; @@ -48,6 +52,7 @@ static const struct cpuid_reg reverse_cpuid[] = { [CPUID_7_1_EAX] = { 7, 1, CPUID_EAX}, [CPUID_12_EAX] = {0x00000012, 0, CPUID_EAX}, [CPUID_8000_001F_EAX] = {0x8000001f, 0, CPUID_EAX}, + [CPUID_8000_0007_EDX] = {0x80000007, 0, CPUID_EDX}, }; /* @@ -78,6 +83,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; } -- 2.37.3