Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp4127015rwj; Tue, 20 Dec 2022 06:28:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXu1szNFLHi2v2RFXHI708xQMT5Pe8C4kwW/OTjy5FTDpTya8AmJ6MiVoonTNw6eoPgAPD+s X-Received: by 2002:aa7:d281:0:b0:47c:1827:692d with SMTP id w1-20020aa7d281000000b0047c1827692dmr3692077edq.10.1671546519448; Tue, 20 Dec 2022 06:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671546519; cv=none; d=google.com; s=arc-20160816; b=gPcWMmr4aBzJ8vwOrj5ol5qNOGbGxXQV67RWnCs4Z1dyGmY9ESc1oUrmGB37azLt+c NlT3NAzAkqNSKfKUg5htilN6b+EHR5VFjnhwiFCc2PsET/IAzJK5+yxoBW+Ug27BluTS HvGsA2LZmeHZ2oXhMZ7K452lKonFYjIhlnD9Z3Fx47Y3U7SAPGmYnGSBVFLYVmT/s0fW YFa4fQWo31WnCNOW0W1Zk93qBH7Sjx1uk3aPTjAUPQXpF7P+ZT956/9o2ccYNJu61o9z 9BHO5sINNSZgMzL4oY1BXv4a2ZypoXU8M8eAcNfp0Co+6N0A2x1fmYGpq4Yal7aEFxMy TkuA== 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=rHmUes2iGzRfhHitFulBWu513SbnhDIxQnuaB6wQzRQ=; b=urKJ7oyILibDSbu/v19ssr4FaclNF7+4bk/XQsyq+WA0BJ+ealoqT/j12n6CoqZNGn x1by4FGP+s1jrz+pYGQVXnLi8YbS9Tx9RSdojYhlUESx2sN2QAA8LiNZxt5+g2+VWQlE J3BKF0D8ecMdRPQPwocB17cgE9YMvGd8oyyoTOusjvYx1r7ZVGPeVMc41xP6RvT0HgX7 1tZi0zTXuYxrnNDS/xbCbbf0EyT08bxvJfjZABkfcCwhNjgGXRQ9zM1vYjiMUOOwT9yB Pgp/JLsQSbCAwmhN5TKms7mTuZCGADcOqP0bG7AR6J8Ru7gJJf22d4PRwtgfGH6ahmpk GxzA== 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 r20-20020a05640251d400b004697a8fd1f7si11982731edd.549.2022.12.20.06.28.22; Tue, 20 Dec 2022 06:28:39 -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 S233970AbiLTOQ4 (ORCPT + 69 others); Tue, 20 Dec 2022 09:16:56 -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: 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 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 --- 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_host.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; }; +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 { 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 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 *vcpu, struct kvm_cpuid_entry2 return 0; } -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; - vcpu->arch.kvm_cpuid_base = 0; + memset(hypervisor_cpuid, 0, sizeof(*hypervisor_cpuid)); for_each_possible_hypervisor_cpuid_base(function) { entry = kvm_find_cpuid_entry(vcpu, function); @@ -197,9 +198,9 @@ 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, hypervisor_signature, sizeof(signature))) { + hypervisor_cpuid->base = function; + hypervisor_cpuid->limit = 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_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 +440,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); + kvm_update_hypervisor_cpuid(vcpu, KVM_SIGNATURE, &vcpu->arch.kvm_cpuid); kvm_vcpu_after_set_cpuid(vcpu); return 0; -- 2.20.1