Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2163735rwl; Fri, 6 Jan 2023 02:48:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXt3gGg1Q9FU1XZUm+E+GRia75yPEwJrvV4G65Hh5dWNEn5VAm9NYwHWmPO6LuCsIwjmCcsN X-Received: by 2002:a17:902:d893:b0:193:b7e:2bf8 with SMTP id b19-20020a170902d89300b001930b7e2bf8mr2228848plz.59.1673002101216; Fri, 06 Jan 2023 02:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673002101; cv=none; d=google.com; s=arc-20160816; b=eZesGJzI8KxPdmcgjS6tLklTC0tAXjD8meeT95RviGSGZrHBi+Tv33IVeODlcH4l1o vPMNPm3N5EV4IQDKvrlWeS+zfyQgvOA/4dvbnPFSzFF70leLxJgfDBOxjSWDhi3UMIXr MbYbDyfYJMTUX3Yw4sDL0GKkVvHzhADkd788HHGubnhLL49rVkKlhghWoYctiTsdCHev u9I86cSKGsWexQD5+/XS0VLFrc0T2sVjnBMsExnS/Ll3lgDCl406xonFwCG4mOv1WMwg t26vvJJeDKzrlB72knAqB9NWiI8yAKDbDXNN9hoOcCznBpSAnshq8eO2MK/7T2tfqIwE 6lvA== 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; bh=5vqjxVs8Be/XsGYmi4T9CsCigrrqwrmdgboTDGh92bQ=; b=jsHTUB7kVnmNRC5zATZDffFJh4UaAmw/I560nW69hiVBaKTw9yR4mhY2LAQnXq8nRg bH/5EhEWAOszqvvENXJyjdP/uLrNRDmDpF+BOE0ZDUk6YNOuyPa9m+9PrMUU1S4bWTZi WdXxa14C4Jmb+Tm10KeXOW2cdjg3lYqcMLWk+9HbqyBcznZZh33dmh/743FHxFOZF76n X6NEZ1+zW1uzjfYXs13pebIn1ZN0xJqXbaqgv4zly3btrDS4HeMvfdhzpBr7PyLVGIqU XxbeNj9fxQNijOwx1ssBdfGvJIRKQamBgzZ4LVLKAxEFgjSKoLCtll1X2GHJH2HDdm9e w3GQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j9-20020a170902da8900b00180680b8f1bsi794288plx.264.2023.01.06.02.48.13; Fri, 06 Jan 2023 02:48:21 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232478AbjAFKgg (ORCPT + 56 others); Fri, 6 Jan 2023 05:36:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232173AbjAFKgc (ORCPT ); Fri, 6 Jan 2023 05:36:32 -0500 Received: from mail.xenproject.org (mail.xenproject.org [104.130.215.37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C791A6B5FF; Fri, 6 Jan 2023 02:36:31 -0800 (PST) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pDk5K-0003o2-SY; Fri, 06 Jan 2023 10:36:26 +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 1pDk5K-0001wX-Ir; Fri, 06 Jan 2023 10:36:26 +0000 From: Paul Durrant To: x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.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 v7 1/2] KVM: x86/cpuid: generalize kvm_update_kvm_cpuid_base() and also capture limit Date: Fri, 6 Jan 2023 10:35:59 +0000 Message-Id: <20230106103600.528-2-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230106103600.528-1-pdurrant@amazon.com> References: <20230106103600.528-1-pdurrant@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_ADSP_ALL, RCVD_IN_DNSWL_MED,SPF_FAIL,SPF_HELO_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 A subsequent 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 --- Cc: Sean Christopherson Cc: Paolo Bonzini Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: David Woodhouse v7: - Morph kvm_update_hypervisor_cpuid() into kvm_get_hypervisor_cpuid() - Place the definition of struct kvm_hypervisor_cpuid to avoid churn in patch #2. v6: - New in this version --- arch/x86/include/asm/kvm_host.h | 7 ++++++- arch/x86/kvm/cpuid.c | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index c70690b2c82d..85cbe4571ac9 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -678,6 +678,11 @@ struct kvm_vcpu_hv { } nested; }; +struct kvm_hypervisor_cpuid { + u32 base; + u32 limit; +}; + /* Xen HVM per vcpu emulation context */ struct kvm_vcpu_xen { u64 hypercall_rip; @@ -826,7 +831,7 @@ struct kvm_vcpu_arch { int cpuid_nent; struct kvm_cpuid_entry2 *cpuid_entries; - u32 kvm_cpuid_base; + struct kvm_hypervisor_cpuid kvm_cpuid; u64 reserved_gpa_bits; int maxphyaddr; diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index 69768e4d53a6..db5a4d38fcd0 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -180,15 +180,15 @@ static int kvm_cpuid_check_equal(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 return 0; } -static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu) +static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu, + const char *sig) { - u32 function; + struct kvm_hypervisor_cpuid cpuid = {}; struct kvm_cpuid_entry2 *entry; + u32 base; - vcpu->arch.kvm_cpuid_base = 0; - - for_each_possible_hypervisor_cpuid_base(function) { - entry = kvm_find_cpuid_entry(vcpu, function); + for_each_possible_hypervisor_cpuid_base(base) { + entry = kvm_find_cpuid_entry(vcpu, base); if (entry) { u32 signature[3]; @@ -197,19 +197,21 @@ static void kvm_update_kvm_cpuid_base(struct kvm_vcpu *vcpu) signature[1] = entry->ecx; signature[2] = entry->edx; - BUILD_BUG_ON(sizeof(signature) > sizeof(KVM_SIGNATURE)); - if (!memcmp(signature, KVM_SIGNATURE, sizeof(signature))) { - vcpu->arch.kvm_cpuid_base = function; + if (!memcmp(signature, sig, sizeof(signature))) { + cpuid.base = base; + cpuid.limit = entry->eax; break; } } } + + return cpuid; } static struct kvm_cpuid_entry2 *__kvm_find_kvm_cpuid_features(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *entries, int nent) { - u32 base = vcpu->arch.kvm_cpuid_base; + u32 base = vcpu->arch.kvm_cpuid.base; if (!base) return NULL; @@ -439,7 +441,7 @@ static int kvm_set_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid_entry2 *e2, vcpu->arch.cpuid_entries = e2; vcpu->arch.cpuid_nent = nent; - kvm_update_kvm_cpuid_base(vcpu); + vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE); kvm_vcpu_after_set_cpuid(vcpu); return 0; -- 2.20.1