Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp374486imw; Thu, 14 Jul 2022 03:04:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s74SJB3lHNIqQv8oIfW3I7gOlp5w/+oluWGuhS9skufasT3l8D9F3xoySfV0mtnL7NzGks X-Received: by 2002:a05:6402:4306:b0:43a:b794:9f9f with SMTP id m6-20020a056402430600b0043ab7949f9fmr11184855edc.205.1657793041386; Thu, 14 Jul 2022 03:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657793041; cv=none; d=google.com; s=arc-20160816; b=b40dYMM5FS6Vb8D07hCV9W8IqV7rlbD0D5t0YuxWGymcy+fFXQpTuT/QN701wmV6Fi E3S3pLICCO17xhGbQtU86eV9+C+Ps/O4kHBsaSeqvijDtRJJ3fRdlnxGalL9ZHfF6D6B DEzlooG409tmlPqCxvA+H42qLwqbERsx9lD+wkt5IEiU+2RrBhAbDl3MBKZCH7tdirqt BsEYgWbh+1ANuc7ac+wTEF42yysS3n030Ig9jHeM20C8oFnd4rXdlxI/TEkC8rGoLFIT /pHI+wOrFPaImX39f1Kww1Tqs0IFINsgoA9Mm78hPAVNGFJ428LoCMsG429DYR8kI0U1 ezfA== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=zXjYUn/LR7t2A7uSGt42ou7GfATznOMUig3WAXqM26I=; b=Z5FP9jsUS4u4k9NX+sJoeFcm6/RTDOBWXvYw69crB2opPzZS8SuFIIwi7H8mXzFdsD edyr9IE/26f44eIhOTQjF6tcAcCQ5r+LCkVGTtI0y2Qp/mGfRELmoJjQmoB9Gi/InnCi gr9v6uiixs0dNqSpCfYebih0GDORzksV9UAy2vtYGz+JwiloKE+kYHPR/jS6i48ri63J Ay2rmFvBQEGMOUd5kM3wAZT67brTN+MFvS07eau86JvOORQpg33kxkC7SPFWl1qCj3vO rG3Ebokj3qdZ0r/HqnDcQsJ/A6EorceBNEWZvV1DBY8f49ISKlWwIkyc9TgnwYpvPs3R W8IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dT0dvZPF; 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 nc4-20020a1709071c0400b0072b13fa7314si1485209ejc.439.2022.07.14.03.03.36; Thu, 14 Jul 2022 03:04:01 -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=dT0dvZPF; 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 S234314AbiGNJ7g (ORCPT + 99 others); Thu, 14 Jul 2022 05:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231356AbiGNJ7c (ORCPT ); Thu, 14 Jul 2022 05:59:32 -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 ESMTP id 7501A237 for ; Thu, 14 Jul 2022 02:59:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657792770; 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=zXjYUn/LR7t2A7uSGt42ou7GfATznOMUig3WAXqM26I=; b=dT0dvZPF/eF1I2wT/FMwNAWTd1pOMYAQMsmjUTnifRTfF0ITXTxRWDWVJUDuqIB4P4isAY WZ4ygg3p/yVetPAovW8OgyVWpNmvwm69U3+fK1P4w0xy3vogwLNA/rC7hv9UEPO4bxBE6C a2UlakKc9oTism/jDmLAvTovVkfFDLE= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-303-fvkaN_mQPwqg48ElpFmtMw-1; Thu, 14 Jul 2022 05:59:29 -0400 X-MC-Unique: fvkaN_mQPwqg48ElpFmtMw-1 Received: by mail-wm1-f71.google.com with SMTP id 83-20020a1c0256000000b003a2d01897e4so429592wmc.9 for ; Thu, 14 Jul 2022 02:59:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=zXjYUn/LR7t2A7uSGt42ou7GfATznOMUig3WAXqM26I=; b=HUsYq0pv9Q6wwFBymcYKIyR39SD4fi2tUNADVMaHm9b6zL3YjKUCBGRr6PtMRPszTk wgHHTEk6blTDDJ79zF7dZY1bQJVnvFU7JYyMjzUKDpCjyxRuuuVFDYjirUk/aRiYYxv2 ma0HKMkQOEKcRH8tqxDoeOvg0Uo+zLhtl9nPT0hlv520k4pXe2aa/qNbTgc7U5G5nHkh a6pi3BlHyRbdxEYu7LmSpnxmIaDxnpMMAywcirqEYUBmmCMzUFGrhwfuevNepT/Vkg0l 0nJwn6NlJSuYH0FqqLXUUYEjbuXJGNP7sIwWRGqC55fkmjC1nrNsI5H7+FKURzpnGDU3 hpPw== X-Gm-Message-State: AJIora+EdSaJ33qZvledcYq+u/3462GDPl0bPeaVRHyt6YPAJB3MEB45 AZL4ypFsNFayoY3Exet7gxKgaOdFzaTTzGytx1oJBLg+YPNKSCDKeErfprqGtRmJOFYAatuDiAq Rws4LWhz5KdZctBnxXw8yy6cL X-Received: by 2002:a05:6000:184f:b0:21d:a1fb:4581 with SMTP id c15-20020a056000184f00b0021da1fb4581mr7681670wri.651.1657792768133; Thu, 14 Jul 2022 02:59:28 -0700 (PDT) X-Received: by 2002:a05:6000:184f:b0:21d:a1fb:4581 with SMTP id c15-20020a056000184f00b0021da1fb4581mr7681655wri.651.1657792767963; Thu, 14 Jul 2022 02:59:27 -0700 (PDT) Received: from [10.35.4.238] (bzq-82-81-161-50.red.bezeqint.net. [82.81.161.50]) by smtp.gmail.com with ESMTPSA id p6-20020a05600c358600b003a2e2ba94ecsm4693716wmq.40.2022.07.14.02.59.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Jul 2022 02:59:27 -0700 (PDT) Message-ID: <849757ed499c4190762a28a1bbf819382abaf22c.camel@redhat.com> Subject: Re: [PATCH v4 06/25] KVM: x86: hyper-v: Cache HYPERV_CPUID_NESTED_FEATURES CPUID leaf From: Maxim Levitsky To: Vitaly Kuznetsov , kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Anirudh Rayabharam , Wanpeng Li , Jim Mattson , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 14 Jul 2022 12:59:25 +0300 In-Reply-To: <20220714091327.1085353-7-vkuznets@redhat.com> References: <20220714091327.1085353-1-vkuznets@redhat.com> <20220714091327.1085353-7-vkuznets@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-5.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Thu, 2022-07-14 at 11:13 +0200, Vitaly Kuznetsov wrote: > KVM has to check guest visible HYPERV_CPUID_NESTED_FEATURES.EBX CPUID > leaf to know which Enlightened VMCS definition to use (original or 2022 > update). Cache the leaf along with other Hyper-V CPUID feature leaves > to make the check quick. > > While on it, wipe the whole 'hv_vcpu->cpuid_cache' with memset() instead > of having to zero each particular member when the corresponding CPUID entry > was not found. > > Signed-off-by: Vitaly Kuznetsov > --- >  arch/x86/include/asm/kvm_host.h |  2 ++ >  arch/x86/kvm/hyperv.c           | 17 ++++++++--------- >  2 files changed, 10 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h > index de5a149d0971..077ec9cf3169 100644 > --- a/arch/x86/include/asm/kvm_host.h > +++ b/arch/x86/include/asm/kvm_host.h > @@ -616,6 +616,8 @@ struct kvm_vcpu_hv { >                 u32 enlightenments_eax; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EAX */ >                 u32 enlightenments_ebx; /* HYPERV_CPUID_ENLIGHTMENT_INFO.EBX */ >                 u32 syndbg_cap_eax; /* HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES.EAX */ > +               u32 nested_eax; /* HYPERV_CPUID_NESTED_FEATURES.EAX */ > +               u32 nested_ebx; /* HYPERV_CPUID_NESTED_FEATURES.EBX */ >         } cpuid_cache; >  }; >   > diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c > index e08189211d9a..a8e4944ca110 100644 > --- a/arch/x86/kvm/hyperv.c > +++ b/arch/x86/kvm/hyperv.c > @@ -2005,31 +2005,30 @@ void kvm_hv_set_cpuid(struct kvm_vcpu *vcpu) >   >         hv_vcpu = to_hv_vcpu(vcpu); >   > +       memset(&hv_vcpu->cpuid_cache, 0, sizeof(hv_vcpu->cpuid_cache)); > + >         entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_FEATURES, 0); >         if (entry) { >                 hv_vcpu->cpuid_cache.features_eax = entry->eax; >                 hv_vcpu->cpuid_cache.features_ebx = entry->ebx; >                 hv_vcpu->cpuid_cache.features_edx = entry->edx; > -       } else { > -               hv_vcpu->cpuid_cache.features_eax = 0; > -               hv_vcpu->cpuid_cache.features_ebx = 0; > -               hv_vcpu->cpuid_cache.features_edx = 0; >         } >   >         entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_ENLIGHTMENT_INFO, 0); >         if (entry) { >                 hv_vcpu->cpuid_cache.enlightenments_eax = entry->eax; >                 hv_vcpu->cpuid_cache.enlightenments_ebx = entry->ebx; > -       } else { > -               hv_vcpu->cpuid_cache.enlightenments_eax = 0; > -               hv_vcpu->cpuid_cache.enlightenments_ebx = 0; >         } >   >         entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_SYNDBG_PLATFORM_CAPABILITIES, 0); >         if (entry) >                 hv_vcpu->cpuid_cache.syndbg_cap_eax = entry->eax; > -       else > -               hv_vcpu->cpuid_cache.syndbg_cap_eax = 0; > + > +       entry = kvm_find_cpuid_entry(vcpu, HYPERV_CPUID_NESTED_FEATURES, 0); > +       if (entry) { > +               hv_vcpu->cpuid_cache.nested_eax = entry->eax; > +               hv_vcpu->cpuid_cache.nested_ebx = entry->ebx; > +       } >  } >   >  int kvm_hv_set_enforce_cpuid(struct kvm_vcpu *vcpu, bool enforce) Makes sense, looks good. Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky