Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp13713213rwl; Wed, 4 Jan 2023 11:56:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXvXEUi/BPFjM3QSJKTZZ9DwE+yMhsAInaIYhcvj5NquG96LGfz0Byd5JMhTFN6wqS8lzXJ4 X-Received: by 2002:a62:1887:0:b0:582:5886:e1b7 with SMTP id 129-20020a621887000000b005825886e1b7mr11851358pfy.14.1672862201093; Wed, 04 Jan 2023 11:56:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672862201; cv=none; d=google.com; s=arc-20160816; b=tnbdM8F7Y7Ml2w3G5e5IIEBMvny45fIbV6mTkTaeC+KLUSl/VbDRnk0Dg6BhJshvr0 urw4/Uck8uUJOeuqOaXach2U+CR+80o/SZksZHKAc2xnNcd1eVr2SlMQMGwc7QyhVAER FPPFSlHcF2hZjx/BhMHoM61HJPkU+3PZ4eBNDLFWl+1Gx5ZGE0qKccCC6ZDIyUdWChG5 nqYbKtnYelPjVqTKahV/Lr0gYJeG4VAt2RB2zOm5VowR0zobQsnb2tX7P/SjTrB8YgzO dvwAia+ECXlZB+CctO/kK2S4URi+KMwNf8/marrjCSukdXnq1adZDcxJzNHKumip5Z88 Azkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hec4l6+at5WSRcm7OYvARniaVMgLC26qEPf8vcDcszw=; b=0Qb/647N4qK9NaaPoe4wesD9IRp7PJ2EqohIEPT1ksA1MBZnzEz0HKC4qATqy1oJ00 7Gh89XY6dWvaIOc7JudzsmmJAQwcZt6WUowLLgSO4N1IhVRpKS8CvpD4qzxT0SZdIqeZ qEoogGybj3RIvAmydJQfBuLC+Ps6i8xiU+HBOtVDBCK7ZIy+CVQ9gVDRPV8Qe1lbiOxc ems4xMqtn+jUujSEAtkXUHxACN+1fBg0fWXNMz3BH5V3VzMMbH5G9fENP9jGTGJP+Ii/ PqA7626GBoG730ZEJG7QzRB5ijXYsrTeADb+I6Q56P7itFuHQvP23lthx87gCfin/KPZ OAkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=lAfdpdRA; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020aa78bd3000000b00565cb1ebdbcsi30601717pfd.277.2023.01.04.11.56.34; Wed, 04 Jan 2023 11:56:41 -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=lAfdpdRA; 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 S240153AbjADTe4 (ORCPT + 56 others); Wed, 4 Jan 2023 14:34:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240138AbjADTey (ORCPT ); Wed, 4 Jan 2023 14:34:54 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 322EC3C3B5 for ; Wed, 4 Jan 2023 11:34:54 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id 36so22928443pgp.10 for ; Wed, 04 Jan 2023 11:34:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hec4l6+at5WSRcm7OYvARniaVMgLC26qEPf8vcDcszw=; b=lAfdpdRAWCHlsIepuddv34x9a8FqsGMAnXmLXaUtAv2nYJENBdHCf6oGBuVHkOjQjH EDqn7eTzgEfaRUJoy1w7rl0Pe4T+iZhj/dp2m8DMo/s9BBdQaRm3+Tur4By66hSmxtR6 44IbGgoazsxg5JG7IkyHCUL1TFVLCRXWR/ludEle/oXzWhSL47e1blotcrmF9o17mHDX mjXtkCBFpPdMOH4t3ePqxZ4eIynrgSnEZf1VIbIR1D17Zz3Di3acZ2KZ1xpV3X9Bata8 hXGoPEaQEpG1moN6GDs64l8VPW/u5i9rKgL8w41Y5ja256ZpPF0oc5aRU4yz0RQltWgH 2KEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hec4l6+at5WSRcm7OYvARniaVMgLC26qEPf8vcDcszw=; b=6XNGkdXebmqXsFj7hjbv8mrG8L22/V87xleZretD9hczG/QUzAmUOzab/v66A8EKfZ CpyRTmnX+/TlVVygStWpFs4c02S4kdcOgjrA9vt3beKwbCqAN/3OCmRopviky6uC9aye rGkEi3kgt5Rjv+zsIvhXCHhQ0aaLu8BX1V/s6KpNDDshWorvAbPCEQGXkd5capJRRkYz SuXdSAfXTaaIITrlSIsx2s7JtQ4cgKYF/5UITwcV+BhwgiZ6pm66W3NUOyFwLl63A98T QkufrVLz4sHyzl7HmnnYFDWtRseaK9/ULTHnolGQYMznd4DuX/ARU4vBe/fNYSrVxF6+ vSRg== X-Gm-Message-State: AFqh2kpjrUdPImN5eV5exXaiSDIv1+gWIugBKuQB+A0h3UncGc51sLt5 pdLSuRACb2Ucz3IJAeekLVhiXQ== X-Received: by 2002:aa7:8084:0:b0:574:8995:c0d0 with SMTP id v4-20020aa78084000000b005748995c0d0mr3883534pff.1.1672860893603; Wed, 04 Jan 2023 11:34:53 -0800 (PST) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id x24-20020aa78f18000000b0058134d2df41sm17961993pfr.146.2023.01.04.11.34.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 11:34:53 -0800 (PST) Date: Wed, 4 Jan 2023 19:34:49 +0000 From: Sean Christopherson To: Paul Durrant Cc: x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Woodhouse Subject: Re: [PATCH v6 1/2] KVM: x86/cpuid: generalize kvm_update_kvm_cpuid_base() and also capture limit Message-ID: References: <20221220134053.15591-1-pdurrant@amazon.com> <20221220134053.15591-2-pdurrant@amazon.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221220134053.15591-2-pdurrant@amazon.com> X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Tue, Dec 20, 2022, Paul Durrant wrote: > 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; > +}; Probably makes sense to place this above "struct kvm_vcpu_xen" right away to avoid the (very minor) churn. > 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, Please wrap. The 80 char limit is a soft limit, but should still be honored unless there's a good reason to run over. I also vote to name the param "sig" to keep line lengths short. > + struct kvm_hypervisor_cpuid *hypervisor_cpuid) Since the struct is a 64-bit value, what about making this a pure getter that returns a copy? static struct kvm_hypervisor_cpuid kvm_get_hypervisor_cpuid(struct kvm_vcpu *vcpu, const char *sig) { struct kvm_hypervisor_cpuid cpuid = {}; struct kvm_cpuid_entry2 *entry; u32 function; for_each_possible_hypervisor_cpuid_base(cpuid.base) { entry = kvm_find_cpuid_entry(vcpu, function); if (entry) { u32 signature[3]; signature[0] = entry->ebx; signature[1] = entry->ecx; signature[2] = entry->edx; if (!memcmp(signature, sig, sizeof(signature))) { cpuid.base = function; cpuid.limit = entry->eax; break; } } } return cpuid; } vcpu->arch.kvm_cpuid = kvm_get_hypervisor_cpuid(vcpu, KVM_SIGNATURE); vcpu->arch.xen.cpuid = kvm_get_hypervisor_cpuid(vcpu, XEN_SIGNATURE);