From nobody Wed Sep 17 11:45:43 2025 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 CAFC4C10F1E for ; Tue, 20 Dec 2022 14:17:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233975AbiLTOQ5 (ORCPT ); Tue, 20 Dec 2022 09:16:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233912AbiLTOQV (ORCPT ); Tue, 20 Dec 2022 09:16:21 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCBEE0F2; Tue, 20 Dec 2022 06:16:20 -0800 (PST) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1p7csQ-00012f-TJ; Tue, 20 Dec 2022 13:41:50 +0000 Received: from 54-240-197-227.amazon.com ([54.240.197.227] helo=debian.cbg12.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p7csQ-0002HU-J6; Tue, 20 Dec 2022 13:41:50 +0000 From: Paul Durrant To: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Woodhouse Subject: [PATCH v6 1/2] KVM: x86/cpuid: generalize kvm_update_kvm_cpuid_base() and also capture limit Date: Tue, 20 Dec 2022 13:40:52 +0000 Message-Id: <20221220134053.15591-2-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221220134053.15591-1-pdurrant@amazon.com> References: <20221220134053.15591-1-pdurrant@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A sunsequent patch will need to acquire the CPUID leaf range for emulated Xen so explicitly pass the signature of the hypervisor we're interested in to the new function. Also introduce a new kvm_hypervisor_cpuid structure so we can neatly store both the base and limit leaf indices. Signed-off-by: Paul Durrant Reviewed-by: David Woodhouse --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse v6: - New in this version --- arch/x86/include/asm/kvm_host.h | 7 ++++++- arch/x86/kvm/cpuid.c | 15 ++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index f35f1ff4427b..ff201ad35551 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -710,6 +710,11 @@ struct kvm_queued_exception { bool has_payload; }; =20 +struct kvm_hypervisor_cpuid { + u32 base; + u32 limit; +}; + struct kvm_vcpu_arch { /* * rip and regs accesses must go through @@ -826,7 +831,7 @@ struct kvm_vcpu_arch { =20 int cpuid_nent; struct kvm_cpuid_entry2 *cpuid_entries; - u32 kvm_cpuid_base; + struct kvm_hypervisor_cpuid kvm_cpuid; =20 u64 reserved_gpa_bits; int maxphyaddr; diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 0b5bf013fcb8..2468720f8d84 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -180,12 +180,13 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcp= u, struct kvm_cpuid_entry2 return 0; } =20 -static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu) +static void kvm_update_hypervisor_cpuid(struct kvm_vcpu *vcpu, const char = *hypervisor_signature, + struct kvm_hypervisor_cpuid *hypervisor_cpuid) { u32 function; struct kvm_cpuid_entry2 *entry; =20 - vcpu->arch.kvm_cpuid_base =3D 0; + memset(hypervisor_cpuid, 0, sizeof(*hypervisor_cpuid)); =20 for_each_possible_hypervisor_cpuid_base(function) { entry =3D kvm_find_cpuid_entry(vcpu, function); @@ -197,9 +198,9 @@ static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *= vcpu) signature[1] =3D entry->ecx; signature[2] =3D entry->edx; =20 - BUILD_BUG_ON(sizeof(signature) > sizeof(KVM_SIGNATURE)); - if (!memcmp(signature, KVM_SIGNATURE, sizeof(signature))) { - vcpu->arch.kvm_cpuid_base =3D function; + if (!memcmp(signature, hypervisor_signature, sizeof(signature))) { + hypervisor_cpuid->base =3D function; + hypervisor_cpuid->limit =3D entry->eax; break; } } @@ -209,7 +210,7 @@ static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *= vcpu) static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_v= cpu *vcpu, struct kvm_cpuid_entry2 *entries, int nent) { - u32 base =3D vcpu->arch.kvm_cpuid_base; + u32 base =3D vcpu->arch.kvm_cpuid.base; =20 if (!base) return NULL; @@ -439,7 +440,7 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct = kvm_cpuid_entry2 *e2, vcpu->arch.cpuid_entries =3D e2; vcpu->arch.cpuid_nent =3D nent; =20 - kvm_update_kvm_cpuid_base(vcpu); + kvm_update_hypervisor_cpuid(vcpu, KVM_SIGNATURE, &vcpu->arch.kvm_cpuid); kvm_vcpu_after_set_cpuid(vcpu); =20 return 0; --=20 2.20.1