From nobody Thu Jul 3 23:53:29 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622571237; cv=none; d=zohomail.com; s=zohoarc; b=NdmciSVuA1mM0jS/1FPCx3orgXK7MgY7a8zPdGQSkx3JkeNmsz1/fQsvjaBpuv31GJONjdZPcU1kTDYPgJ84zjRyrIDUZWAx/Gxfi3YGhOLl83KQb8E6nTy6PNRKnhxVsS3jd5SQI1T58VAPX007dZNQ9UAbtz49R/MgBG7swoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622571237; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WWxxuc+yNU6M5AgsLtoKdH+zz1WdNZ2CPoRpA5Kh3LA=; b=D2XsiGUQXBczURYDJKD4mWpOnBZthkT7WEOvYfOPImE9n/dwc2anNMf4tKsLt3i0XdF/j/Fv6uKItu0nJlEbcLZiGQDdgMvDPa+bM+F66Ba/2mDD78EtR/ngfCa3EdhgDyT5AefSYaSDc1WviQJ6StXAR3F0j9+aQjxbShnlHR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1622571237933743.7793100329915; Tue, 1 Jun 2021 11:13:57 -0700 (PDT) Received: from localhost ([::1]:42584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lo8to-00078u-CO for importer2@patchew.org; Tue, 01 Jun 2021 14:13:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lo8qV-0002Ce-QR for qemu-devel@nongnu.org; Tue, 01 Jun 2021 14:10:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lo8qT-0005gP-HJ for qemu-devel@nongnu.org; Tue, 01 Jun 2021 14:10:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-op77rHRrOfOISzVY-o0DYg-1; Tue, 01 Jun 2021 14:10:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0EA28107ACED; Tue, 1 Jun 2021 18:10:24 +0000 (UTC) Received: from localhost (ovpn-112-239.rdu2.redhat.com [10.10.112.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF8D661008; Tue, 1 Jun 2021 18:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622571026; 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=WWxxuc+yNU6M5AgsLtoKdH+zz1WdNZ2CPoRpA5Kh3LA=; b=fSXorZEKzbpvCAYqCM5bIYp8KJ7RoOdYu+P0MndRVGMryBGyeTjiSDf9qSFyC6cLI5QJ1R KdrvHTPayY/wpC4KUvP5q9q0+MxrO2d+gH8107zvtNc28r/ylpKi1YWmmDq7p+hE9kTJEc FGznZfH3BXOxorJkgfgdOA5jJCtZUpM= X-MC-Unique: op77rHRrOfOISzVY-o0DYg-1 From: Eduardo Habkost To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 11/24] i386: stop using env->features[] for filling Hyper-V CPUIDs Date: Tue, 1 Jun 2021 14:10:01 -0400 Message-Id: <20210601181014.2568861-12-ehabkost@redhat.com> In-Reply-To: <20210601181014.2568861-1-ehabkost@redhat.com> References: <20210601181014.2568861-1-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ehabkost@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=ehabkost@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Vitaly Kuznetsov , Richard Henderson , Eduardo Habkost Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Vitaly Kuznetsov As a preparatory patch to dropping Hyper-V CPUID leaves from feature_word_info[] stop using env->features[] as a temporary storage of Hyper-V CPUIDs, just build Hyper-V CPUID leaves directly from kvm_hyperv_properties[] data. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost Message-Id: <20210422161130.652779-5-vkuznets@redhat.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 80 +++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index da72aa52286..681f11607ff 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1699,6 +1699,7 @@ struct X86CPU { uint32_t hyperv_interface_id[4]; uint32_t hyperv_version_id[4]; uint32_t hyperv_limits[3]; + uint32_t hyperv_nested[4]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4cd4df223fc..346528c6496 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1112,7 +1112,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, int feature) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; uint32_t r, fw, bits; uint64_t deps; int i, dep_feat; @@ -1152,8 +1151,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, return 0; } } - - env->features[fw] |=3D bits; } =20 if (cpu->hyperv_passthrough) { @@ -1163,6 +1160,29 @@ static int hv_cpuid_check_and_set(CPUState *cs, stru= ct kvm_cpuid2 *cpuid, return 0; } =20 +static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t fw) +{ + X86CPU *cpu =3D X86_CPU(cs); + uint32_t r =3D 0; + int i, j; + + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties); i++) { + if (!hyperv_feat_enabled(cpu, i)) { + continue; + } + + for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { + if (kvm_hyperv_properties[i].flags[j].fw !=3D fw) { + continue; + } + + r |=3D kvm_hyperv_properties[i].flags[j].bits; + } + } + + return r; +} + /* * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in * case of success, errno < 0 in case of failure and 0 when no Hyper-V @@ -1172,9 +1192,8 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *c; + struct kvm_cpuid_entry2 *c, *c2; uint32_t cpuid_i =3D 0; int r; =20 @@ -1195,9 +1214,7 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (!r) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - HV_ENLIGHTENED_VMCS_RECOMMENDED; - env->features[FEAT_HV_NESTED_EAX] =3D evmcs_version; + cpu->hyperv_nested[0] =3D evmcs_version; } } =20 @@ -1236,13 +1253,6 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_version_id[3] =3D c->edx; } =20 - c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); - if (c) { - env->features[FEAT_HYPERV_EAX] =3D c->eax; - env->features[FEAT_HYPERV_EBX] =3D c->ebx; - env->features[FEAT_HYPERV_EDX] =3D c->edx; - } - c =3D cpuid_find_entry(cpuid, HV_CPUID_IMPLEMENT_LIMITS, 0); if (c) { cpu->hv_max_vps =3D c->eax; @@ -1253,23 +1263,8 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { - env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; cpu->hyperv_spinlock_attempts =3D c->ebx; } - c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); - if (c) { - env->features[FEAT_HV_NESTED_EAX] =3D c->eax; - } - } - - if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_NO_NONARCH_CORESHARING; - } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - c->eax & HV_NO_NONARCH_CORESHARING; - } } =20 /* Features */ @@ -1299,9 +1294,6 @@ static int hyperv_handle_properties(CPUState *cs, r |=3D 1; } =20 - /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ - env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; - if (r) { r =3D -ENOSYS; goto free; @@ -1331,15 +1323,27 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; - c->eax =3D env->features[FEAT_HYPERV_EAX]; - c->ebx =3D env->features[FEAT_HYPERV_EBX]; - c->edx =3D env->features[FEAT_HYPERV_EDX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EAX); + c->ebx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EBX); + c->edx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EDX); + + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ + c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_ENLIGHTMENT_INFO; - c->eax =3D env->features[FEAT_HV_RECOMM_EAX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HV_RECOMM_EAX); c->ebx =3D cpu->hyperv_spinlock_attempts; =20 + if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { + c->eax |=3D HV_NO_NONARCH_CORESHARING; + } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { + c2 =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); + if (c2) { + c->eax |=3D c2->eax & HV_NO_NONARCH_CORESHARING; + } + } + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_IMPLEMENT_LIMITS; c->eax =3D cpu->hv_max_vps; @@ -1359,7 +1363,7 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_NESTED_FEATURES; - c->eax =3D env->features[FEAT_HV_NESTED_EAX]; + c->eax =3D cpu->hyperv_nested[0]; } r =3D cpuid_i; =20 --=20 2.30.2