From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473428; cv=none; d=zohomail.com; s=zohoarc; b=Dv8mta+Qzw4y7yLzUWBEcy3/SBM3nP+HeZ98A5SME7LwAV3qTthW9aOUqhe4QwHkA7giGv6v2rl2PNlUiBypk9B28GXtmd39cVswRlFcfJc/3avbk+lhN44YOW+vIjHe71RTyNKJbiixrdoaO5RfvvzaFh/RCwk2OmutKtJwV4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473428; 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=2gHtymYiG0Jue5klJotwsT3ynD0ksSXNSyXr3nVsQF8=; b=gk8gAb6C6Wvv0c8WGaiz9tg9Kkub+sogN3BZPuTUQmwJvqP5SeYPfipEOYi2qVx9jN3WeqKPE0qumpwoPd32lX9CJ9QIoG4/1K2HS55vG+nx6WtnvkJHM09IkDq+2OHWFjUq0fo2S2ZKgdnCfuf5V2NO4yp80U/B/RTZEzLAT3E= 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+importer=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 1601473428093677.1417240816174; Wed, 30 Sep 2020 06:43:48 -0700 (PDT) Received: from localhost ([::1]:39870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcOY-0007Qc-Qa for importer@patchew.org; Wed, 30 Sep 2020 09:43:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcLW-0005eS-O8 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:40:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51270) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcLS-0005X6-8a for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:40:38 -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-593-80zn--etO0S-rbQzHVGp0w-1; Wed, 30 Sep 2020 09:40:31 -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 0A6C7185FD8B for ; Wed, 30 Sep 2020 13:40:31 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDB5660C05; Wed, 30 Sep 2020 13:40:29 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473233; 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=2gHtymYiG0Jue5klJotwsT3ynD0ksSXNSyXr3nVsQF8=; b=Kjp0ZOcK4kFXZVDR52i+mbBrEMWbmaYJm+5JeVQuymJCLQKrnkCqFq/7hn/IIptaZlZo/A /WcI9lpF0GdrH7BNZ4Yg660VesGfNtyqaTy/vSmxBg4srUn6s3BLNRhHh9aypL4GHEAA7j j+ewlwtdz70MMohgf9YducFj+ZrGucw= X-MC-Unique: 80zn--etO0S-rbQzHVGp0w-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 01/19] WIP: update linux/headers Date: Wed, 30 Sep 2020 15:40:09 +0200 Message-Id: <20200930134027.1348021-2-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM_CAP_SYS_HYPERV_CPUID definition is needed for this series. Signed-off-by: Vitaly Kuznetsov --- linux-headers/asm-x86/kvm.h | 20 ++++++++++++++++++++ linux-headers/linux/kvm.h | 27 ++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/linux-headers/asm-x86/kvm.h b/linux-headers/asm-x86/kvm.h index 0780f97c1850..89e5f3d1bba8 100644 --- a/linux-headers/asm-x86/kvm.h +++ b/linux-headers/asm-x86/kvm.h @@ -192,6 +192,26 @@ struct kvm_msr_list { __u32 indices[0]; }; =20 +/* Maximum size of any access bitmap in bytes */ +#define KVM_MSR_FILTER_MAX_BITMAP_SIZE 0x600 + +/* for KVM_X86_SET_MSR_FILTER */ +struct kvm_msr_filter_range { +#define KVM_MSR_FILTER_READ (1 << 0) +#define KVM_MSR_FILTER_WRITE (1 << 1) + __u32 flags; + __u32 nmsrs; /* number of msrs in bitmap */ + __u32 base; /* MSR index the bitmap starts at */ + __u8 *bitmap; /* a 1 bit allows the operations in flags, 0 denies */ +}; + +#define KVM_MSR_FILTER_MAX_RANGES 16 +struct kvm_msr_filter { +#define KVM_MSR_FILTER_DEFAULT_ALLOW (0 << 0) +#define KVM_MSR_FILTER_DEFAULT_DENY (1 << 0) + __u32 flags; + struct kvm_msr_filter_range ranges[KVM_MSR_FILTER_MAX_RANGES]; +}; =20 struct kvm_cpuid_entry { __u32 function; diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 6683e2e1b0a0..b28b806530b7 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -248,6 +248,8 @@ struct kvm_hyperv_exit { #define KVM_EXIT_IOAPIC_EOI 26 #define KVM_EXIT_HYPERV 27 #define KVM_EXIT_ARM_NISV 28 +#define KVM_EXIT_X86_RDMSR 29 +#define KVM_EXIT_X86_WRMSR 30 =20 /* For KVM_EXIT_INTERNAL_ERROR */ /* Emulate instruction failed. */ @@ -413,6 +415,17 @@ struct kvm_run { __u64 esr_iss; __u64 fault_ipa; } arm_nisv; + /* KVM_EXIT_X86_RDMSR / KVM_EXIT_X86_WRMSR */ + struct { + __u8 error; /* user -> kernel */ + __u8 pad[7]; +#define KVM_MSR_EXIT_REASON_INVAL (1 << 0) +#define KVM_MSR_EXIT_REASON_UNKNOWN (1 << 1) +#define KVM_MSR_EXIT_REASON_FILTER (1 << 2) + __u32 reason; /* kernel -> user */ + __u32 index; /* kernel -> user */ + __u64 data; /* kernel <-> user */ + } msr; /* Fix the size of the union. */ char padding[256]; }; @@ -790,9 +803,10 @@ struct kvm_ppc_resize_hpt { #define KVM_VM_PPC_HV 1 #define KVM_VM_PPC_PR 2 =20 -/* on MIPS, 0 forces trap & emulate, 1 forces VZ ASE */ -#define KVM_VM_MIPS_TE 0 +/* on MIPS, 0 indicates auto, 1 forces VZ ASE, 2 forces trap & emulate */ +#define KVM_VM_MIPS_AUTO 0 #define KVM_VM_MIPS_VZ 1 +#define KVM_VM_MIPS_TE 2 =20 #define KVM_S390_SIE_PAGE_OFFSET 1 =20 @@ -1035,6 +1049,10 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_LAST_CPU 184 #define KVM_CAP_SMALLER_MAXPHYADDR 185 #define KVM_CAP_S390_DIAG318 186 +#define KVM_CAP_STEAL_TIME 187 +#define KVM_CAP_X86_USER_SPACE_MSR 188 +#define KVM_CAP_X86_MSR_FILTER 189 +#define KVM_CAP_SYS_HYPERV_CPUID 190 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 @@ -1493,7 +1511,7 @@ struct kvm_enc_region { /* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT_2 */ #define KVM_CLEAR_DIRTY_LOG _IOWR(KVMIO, 0xc0, struct kvm_clear_d= irty_log) =20 -/* Available with KVM_CAP_HYPERV_CPUID */ +/* Available with KVM_CAP_HYPERV_CPUID (vcpu) / KVM_CAP_SYS_HYPERV_CPUID (= system) */ #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) =20 /* Available with KVM_CAP_ARM_SVE */ @@ -1536,6 +1554,9 @@ struct kvm_pv_cmd { /* Available with KVM_CAP_S390_PROTECTED */ #define KVM_S390_PV_COMMAND _IOWR(KVMIO, 0xc5, struct kvm_pv_cmd) =20 +/* Available with KVM_CAP_X86_MSR_FILTER */ +#define KVM_X86_SET_MSR_FILTER _IOW(KVMIO, 0xc6, struct kvm_msr_filter) + /* Secure Encrypted Virtualization command */ enum sev_cmd_id { /* Guest initialization commands */ --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473500; cv=none; d=zohomail.com; s=zohoarc; b=csIJmiN8CdafMjqwKNdRTH2qp62EJCWebEsKLkuKoKg7qbB1HIyxERyP1mYItIOtn8zk/c0yB34fClagdvZ9Y50vEWIsyXrno/LUk3KwlPtWcBSOCJCF/2xRlORc25rEgKayxWPkTVbQV/KOTFhOKARgAAyZ9RnZmoiYVjCFfsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473500; 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=qmfbkiGn03zmgQD3JeI1y8LTaAsG9imkLwbM2/BzZmM=; b=CYPxFBefcEEL+u6BEAIZgJn/LaJ0DmFuHzxamTCYPXdMc4Sd/bh5xIsB5wvAxCi3XmklkAXPyGueFpRHT6pYuKMunMPUY+qzSHQux0xbAPWzjahkpsUMs8F0fM/anY9f5F83ufggy/RLrefc22nDjbAXugmCr6VDlvkKYBQaWcM= 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+importer=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 1601473500860669.1570178569093; Wed, 30 Sep 2020 06:45:00 -0700 (PDT) Received: from localhost ([::1]:44568 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcPj-0000vp-Im for importer@patchew.org; Wed, 30 Sep 2020 09:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcLk-0005mz-9r for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:40:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcLe-0005YK-2k for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:40:51 -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-25-qQeKPCnbOladjiUVGX91dg-1; Wed, 30 Sep 2020 09:40:42 -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 10B32186840F for ; Wed, 30 Sep 2020 13:40:41 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59CFB672CD; Wed, 30 Sep 2020 13:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473244; 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=qmfbkiGn03zmgQD3JeI1y8LTaAsG9imkLwbM2/BzZmM=; b=EwfFiNQquotip+/kRTsSNu+h2axzM/rnUmThADDm2fklQw5C7x1voQpNwZGVDTX9J3gXgn DFxNwAOwmetJFRzpY2cLxXZ95EysW+NxnzAEzUZntNumFhd4WrmtqhNs/VkrbPg48U2uJl l5cHC7+59lKm3Qwa2bt1cduuUnc2seE= X-MC-Unique: qQeKPCnbOladjiUVGX91dg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 02/19] i386: fill in FEAT_HYPERV_EDX from edx instead of eax Date: Wed, 30 Sep 2020 15:40:10 +0200 Message-Id: <20200930134027.1348021-3-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There was a typo which went unnoticed. Fixes: e48ddcc6ce13 ("i386/kvm: implement 'hv-passthrough' mode") Signed-off-by: Vitaly Kuznetsov --- - Similar fix had been submitted at: = = = https://lore.kernel.org/qemu-devel/20190820103030.12515-1-zhen= yuw@linux.intel.com/ --- target/i386/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 9efb07e7c839..aa5dc562b697 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1229,7 +1229,7 @@ static int hyperv_handle_properties(CPUState *cs, 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->eax; + env->features[FEAT_HYPERV_EDX] =3D c->edx; } c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473605; cv=none; d=zohomail.com; s=zohoarc; b=C5HsmxBi/zLCSSxZp4/gtxEWvuMnJ//XEMmNMz1EXce/SQ99n5dxVOeIpR4gUwYAO33mgshR+NHX8/UnhdqEGTx8JjdNdOLFvyYlB6rEe66Qhwx0kuLdD1y8ieCof4N9Jr2uLoo01RAyZYFiPdufaKdXqOWcHpsrgb5RYjmUUFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473605; 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=hbQqRXdxKodrYywmABWVHrBLXZrkKZbQLWB0ZWRdRWk=; b=GP7mlwMGL2k6jR/MADz0yuvBWCNT8ex4D6dCZxaS+dtzC7ZgGS0ykubJBTLxsBRWx/av7yl4cVKXTnDt9ew+/EkSJcjHK9gx39Tav0VQwF4QBFrDNm0R1BVGRmJv76alYXpfBVawjEZsJqno7wd4cMFWIVd2wjbPmEZIa298IME= 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+importer=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 1601473605710953.4443668867025; Wed, 30 Sep 2020 06:46:45 -0700 (PDT) Received: from localhost ([::1]:48364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcRQ-0002Vw-FN for importer@patchew.org; Wed, 30 Sep 2020 09:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcLu-00061e-C6 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcLr-0005aN-6e for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:02 -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-544-eWH4eZJGM66NRUG-45zbYA-1; Wed, 30 Sep 2020 09:40:53 -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 E8BB88030AB for ; Wed, 30 Sep 2020 13:40:52 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8916E60C05; Wed, 30 Sep 2020 13:40:41 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473258; 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=hbQqRXdxKodrYywmABWVHrBLXZrkKZbQLWB0ZWRdRWk=; b=BR+Typ0Yef8XJJSBsB3iDnIBWMmhXtDyqEGGcrepLNUhD42H0Jojm9B+aKngXVUgpTO8lu yhDV1Z2qMnCaoOwUYE5uldg6eRMldDxHQ5GZB8zxcSdFYfyEiQKpM7xPlsi3hkDC7gYAzO filN9mg3HEfMZqHky5DzFg58w3lI91s= X-MC-Unique: eWH4eZJGM66NRUG-45zbYA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 03/19] i386: drop x86_cpu_get_supported_feature_word() forward declaration Date: Wed, 30 Sep 2020 15:40:11 +0200 Message-Id: <20200930134027.1348021-4-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We only use x86_cpu_get_supported_feature_word() after its implementation, no forward declaration needed. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 3ffd877dd51f..ca713bef5eaf 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -4179,9 +4179,6 @@ void x86_cpu_change_kvm_default(const char *prop, con= st char *value) assert(pv->prop); } =20 -static uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, - bool migratable_only); - static bool lmce_supported(void) { uint64_t mce_cap =3D 0; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473700; cv=none; d=zohomail.com; s=zohoarc; b=WIOW1sqHsttDE1bRds7CeTahdTcnIky7ppTOykWf6MOk6XOG5qyqw4BKUmJJ6RAVNGf9lbteaOmkzCr4z+Ex9dsV4Vh9f6YFuiwtVk4fOsxV6DEXyoPbqYS12u0ZxMcQe42G7tVd9l4LrheI7WM9LrS6NOKAiGs0qEW7YfLNlio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473700; 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=Gx+vDL90hiYO+S5tXxBxBGxG+KdB47ALS9oMAajmWkk=; b=iZ+Q2IObk4wQIoEKz4Lfd368NazUAmyu0oU5+h2hjMKJDXb6Gl4A94dmn00ZKSduEE+35XtxtR1bR3q11g0vJxXCnUO+q48kCIijMc96njcHHwIhRcIqZQ03id1CVi8pWHvO7Rn80qTb8zoxxxfuxEdzaO4JYbB0RnZ8rz+gQ10= 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+importer=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 1601473700826129.58517211238166; Wed, 30 Sep 2020 06:48:20 -0700 (PDT) Received: from localhost ([::1]:53262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcSx-0004XA-6o for importer@patchew.org; Wed, 30 Sep 2020 09:48:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcM0-000632-9j for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40343) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcLx-0005aq-PU for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:07 -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-2-HG6cZlbNNMGl-qWVGV_GiQ-1; Wed, 30 Sep 2020 09:41:02 -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 EB12EADF09 for ; Wed, 30 Sep 2020 13:41:01 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5239060C05; Wed, 30 Sep 2020 13:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473264; 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=Gx+vDL90hiYO+S5tXxBxBGxG+KdB47ALS9oMAajmWkk=; b=WXbWfdTFQBsJkZNW1G71SeoPuoiT5nW+TY6EwYA4B/5OWlpEeWGk9sTluF+gYhl9SAiXnu mVhrZcqzRSjfMc237FrPO7gZ2JHdiVkhulbaECLpP/v8ld8GkltcnsqiIkmXEB3h4t/CPY cw3bJTuSZ9HIBarMfHq0KNqxoZ/6O/w= X-MC-Unique: HG6cZlbNNMGl-qWVGV_GiQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 04/19] i386: move hyperv_vendor_id initialization to x86_cpu_realizefn() Date: Wed, 30 Sep 2020 15:40:12 +0200 Message-Id: <20200930134027.1348021-5-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparation to expanding Hyper-V CPU features early, move hyperv_vendor_id initialization to x86_cpu_realizefn(). Introduce x86_cpu_hyperv_realize() to not not pollute x86_cpu_realizefn() itself. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 23 ++++++++++++++++++++++- target/i386/cpu.h | 3 ++- target/i386/kvm.c | 25 ++++++++++--------------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index ca713bef5eaf..71b96e383573 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6489,6 +6489,24 @@ static void x86_cpu_filter_features(X86CPU *cpu, boo= l verbose) } } =20 +static void x86_cpu_hyperv_realize(X86CPU *cpu) +{ + size_t len; + + if (!cpu->hyperv_vendor) { + memcpy(cpu->hyperv_vendor_id, "Microsoft Hv", 12); + } else { + len =3D strlen(cpu->hyperv_vendor); + + if (len > 12) { + warn_report("hv-vendor-id truncated to 12 characters"); + len =3D 12; + } + memset(cpu->hyperv_vendor_id, 0, 12); + memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); + } +} + static void x86_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs =3D CPU(dev); @@ -6539,6 +6557,9 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) return; } =20 + /* Process Hyper-V enlightenments */ + x86_cpu_hyperv_realize(cpu); + x86_cpu_expand_features(cpu, &local_err); if (local_err) { goto out; @@ -7209,7 +7230,7 @@ static Property x86_cpu_properties[] =3D { DEFINE_PROP_UINT32("min-xlevel2", X86CPU, env.cpuid_min_xlevel2, 0), DEFINE_PROP_UINT64("ucode-rev", X86CPU, ucode_rev, 0), DEFINE_PROP_BOOL("full-cpuid-auto-level", X86CPU, full_cpuid_auto_leve= l, true), - DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor_id), + DEFINE_PROP_STRING("hv-vendor-id", X86CPU, hyperv_vendor), DEFINE_PROP_BOOL("cpuid-0xb", X86CPU, enable_cpuid_0xb, true), DEFINE_PROP_BOOL("lmce", X86CPU, enable_lmce, false), DEFINE_PROP_BOOL("l3-cache", X86CPU, enable_l3_cache, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index f519d2bfd48d..b0bef3f1c793 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1654,11 +1654,12 @@ struct X86CPU { uint64_t ucode_rev; =20 uint32_t hyperv_spinlock_attempts; - char *hyperv_vendor_id; + char *hyperv_vendor; bool hyperv_synic_kvm_only; uint64_t hyperv_features; bool hyperv_passthrough; OnOffAuto hyperv_no_nonarch_cs; + uint32_t hyperv_vendor_id[3]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index aa5dc562b697..c5c4eaefe862 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1225,6 +1225,13 @@ static int hyperv_handle_properties(CPUState *cs, memcpy(cpuid_ent, &cpuid->entries[0], cpuid->nent * sizeof(cpuid->entries[0])); =20 + c =3D cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0= ); + if (c) { + cpu->hyperv_vendor_id[0] =3D c->ebx; + cpu->hyperv_vendor_id[1] =3D c->ecx; + cpu->hyperv_vendor_id[2] =3D c->edx; + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); if (c) { env->features[FEAT_HYPERV_EAX] =3D c->eax; @@ -1299,23 +1306,11 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; - if (!cpu->hyperv_vendor_id) { - memcpy(signature, "Microsoft Hv", 12); - } else { - size_t len =3D strlen(cpu->hyperv_vendor_id); - - if (len > 12) { - error_report("hv-vendor-id truncated to 12 characters"); - len =3D 12; - } - memset(signature, 0, 12); - memcpy(signature, cpu->hyperv_vendor_id, len); - } c->eax =3D hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? HV_CPUID_NESTED_FEATURES : HV_CPUID_IMPLEMENT_LIMITS; - c->ebx =3D signature[0]; - c->ecx =3D signature[1]; - c->edx =3D signature[2]; + c->ebx =3D cpu->hyperv_vendor_id[0]; + c->ecx =3D cpu->hyperv_vendor_id[1]; + c->edx =3D cpu->hyperv_vendor_id[2]; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_INTERFACE; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473605; cv=none; d=zohomail.com; s=zohoarc; b=gDnqt5A34oqfmoH45+teKQJ6+VE+FOSBzwy46jLoOYFugZ4Q/y2VJwRx6SySS993+TT1HT+QMm3/abZQua+4E2ffBFxD05FI1GDb27WCHl2qplIeoZUjc/tWMgVGws4w+YivnisPYA0ftNGe+f5ebbPJRifdeG4xDNdlWjodHxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473605; 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=xGqt4c6IVlTyWvMmUueqyxJAl2Ib2SzkhlmfxkKMplM=; b=bUyNctBBY5ypmTmR5K7xeBsrzVEEChkO2ex680hY8a/e46gXtQFlAcZ71GlJTfMB0OF8H6uvrzugmSHDlfa+6ln1CvTz03gLmW514bG5o12gdh7U37JBUgQVH8HErDPfzoz5P1f29ZHsX8PYV7FSocKa3zJduj1K0mNvr5G0t1Y= 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+importer=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 1601473605394373.9760881177931; Wed, 30 Sep 2020 06:46:45 -0700 (PDT) Received: from localhost ([::1]:48294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcRQ-0002UE-1B for importer@patchew.org; Wed, 30 Sep 2020 09:46:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMI-000674-EK for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48461) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMC-0005bY-Iz for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:23 -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-164-rZzzzyPPPxuAYJg1KDNmmQ-1; Wed, 30 Sep 2020 09:41:13 -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 94F57800138 for ; Wed, 30 Sep 2020 13:41:12 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C558672C6; Wed, 30 Sep 2020 13:41:02 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473275; 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=xGqt4c6IVlTyWvMmUueqyxJAl2Ib2SzkhlmfxkKMplM=; b=URC3wlrvD1OnbOHdiUDuuUO4/fHt2xue0ibVLEuTISEaaKySRrBtqqZ5nfWPFV3MuSAvwK E36+hS0o0F7Jggmut2Xx+JYq9JXXLtnQNPULGBCwITQdJsZfxg33SnAK8CYvX8AX78CX3s M1PQI/n/privEwEu+rqSe6MqBP3EmNs= X-MC-Unique: rZzzzyPPPxuAYJg1KDNmmQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 05/19] i386: move hyperv_interface_id initialization to x86_cpu_realizefn() Date: Wed, 30 Sep 2020 15:40:13 +0200 Message-Id: <20200930134027.1348021-6-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparation to expanding Hyper-V CPU features early, move hyperv_interface_id initialization to x86_cpu_realizefn(). Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 6 ++++++ target/i386/cpu.h | 1 + target/i386/kvm.c | 18 ++++++++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 71b96e383573..9e77d9579b5c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6505,6 +6505,12 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) memset(cpu->hyperv_vendor_id, 0, 12); memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); } + + /* 'Hv#1' interface identification*/ + cpu->hyperv_interface_id[0] =3D 0x31237648; + cpu->hyperv_interface_id[1] =3D 0; + cpu->hyperv_interface_id[2] =3D 0; + cpu->hyperv_interface_id[3] =3D 0; } =20 static void x86_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b0bef3f1c793..702949462ab9 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1660,6 +1660,7 @@ struct X86CPU { bool hyperv_passthrough; OnOffAuto hyperv_no_nonarch_cs; uint32_t hyperv_vendor_id[3]; + uint32_t hyperv_interface_id[4]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index c5c4eaefe862..6dde7c97deb3 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1188,7 +1188,6 @@ static int hyperv_handle_properties(CPUState *cs, CPUX86State *env =3D &cpu->env; struct kvm_cpuid2 *cpuid; struct kvm_cpuid_entry2 *c; - uint32_t signature[3]; uint32_t cpuid_i =3D 0; int r; =20 @@ -1232,6 +1231,14 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor_id[2] =3D c->edx; } =20 + c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); + if (c) { + cpu->hyperv_interface_id[0] =3D c->eax; + cpu->hyperv_interface_id[1] =3D c->ebx; + cpu->hyperv_interface_id[2] =3D c->ecx; + cpu->hyperv_interface_id[3] =3D c->edx; + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); if (c) { env->features[FEAT_HYPERV_EAX] =3D c->eax; @@ -1314,11 +1321,10 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_INTERFACE; - memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12); - c->eax =3D signature[0]; - c->ebx =3D 0; - c->ecx =3D 0; - c->edx =3D 0; + c->eax =3D cpu->hyperv_interface_id[0]; + c->ebx =3D cpu->hyperv_interface_id[1]; + c->ecx =3D cpu->hyperv_interface_id[2]; + c->edx =3D cpu->hyperv_interface_id[3]; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VERSION; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473866; cv=none; d=zohomail.com; s=zohoarc; b=g7i/QTwC+8sNfHoC7/5igpTiggUDfAOTTEsKWheG0rQKPu2yU/FpseDiOCbiG5Wn1TlU5mopBAhLQgYX1mabVtjnVIVTTy7JkkX1eYYkpufGFQCjiXU93Zw1ds4TLWlaEsOuwYEaVgi3b7f25+gc2Vmn6O1OO0NB+UOdRB3rjm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473866; 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=cRKCvAJzbGC4n/pGjCuBkh9xgOAleZcJhxYpNzpXK+Y=; b=APtY/Q7P4IVhzqtD+Dl8a6FSQCDJEUQbFgAhVZK5qADwWguRX9/ShjnRMDcCzb6VxcJNjFUY5TckD/GljavcvELv23ijbtzryNMXad6wgbVwIlAkxe0NN22d7WL3HKynmH1UqRtJNgSIh8xqCuTmIT/caSa0Uq7wVpjVcxLu3f4= 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+importer=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 1601473866925297.4293895194206; Wed, 30 Sep 2020 06:51:06 -0700 (PDT) Received: from localhost ([::1]:33296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcVd-00080x-NX for importer@patchew.org; Wed, 30 Sep 2020 09:51:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37834) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMM-00068s-Bj for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMF-0005bx-Qd for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:29 -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-254-3dloJli-O4-ckWikIGL1HA-1; Wed, 30 Sep 2020 09:41:19 -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 A57A81040C2F for ; Wed, 30 Sep 2020 13:41:18 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3D9260C05; Wed, 30 Sep 2020 13:41:12 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473282; 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=cRKCvAJzbGC4n/pGjCuBkh9xgOAleZcJhxYpNzpXK+Y=; b=WCPZzaZsrCqMFAZgSshmthYTi8FO9z86G3rcHJ1cqJ4Oxd/8Ge6eczSZ6Ud6i074vAl2TT bfiaLj9HH9C26peo/lqYSm0lbKyRPPlLna3epuIO99hJ+6ZDQKlHf/eo90TsXgE5npLczo dLWIdBpwgPCiQs7afhtAuJ2yDpCRsxQ= X-MC-Unique: 3dloJli-O4-ckWikIGL1HA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 06/19] i386: move hyperv_version_id initialization to x86_cpu_realizefn() Date: Wed, 30 Sep 2020 15:40:14 +0200 Message-Id: <20200930134027.1348021-7-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparation to expanding Hyper-V CPU features early, move hyperv_version_id initialization to x86_cpu_realizefn(). Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 4 ++++ target/i386/cpu.h | 1 + target/i386/kvm.c | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9e77d9579b5c..99bcfcbb448a 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6511,6 +6511,10 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) cpu->hyperv_interface_id[1] =3D 0; cpu->hyperv_interface_id[2] =3D 0; cpu->hyperv_interface_id[3] =3D 0; + + /* Hypervisor system identity */ + cpu->hyperv_version_id[0] =3D 0x00001bbc; + cpu->hyperv_version_id[1] =3D 0x00060001; } =20 static void x86_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 702949462ab9..077c19c5642b 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1661,6 +1661,7 @@ struct X86CPU { OnOffAuto hyperv_no_nonarch_cs; uint32_t hyperv_vendor_id[3]; uint32_t hyperv_interface_id[4]; + uint32_t hyperv_version_id[4]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 6dde7c97deb3..b335b3a3d1c7 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1239,6 +1239,14 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_interface_id[3] =3D c->edx; } =20 + c =3D cpuid_find_entry(cpuid, HV_CPUID_VERSION, 0); + if (c) { + cpu->hyperv_version_id[0] =3D c->eax; + cpu->hyperv_version_id[1] =3D c->ebx; + cpu->hyperv_version_id[2] =3D c->ecx; + cpu->hyperv_version_id[3] =3D c->edx; + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); if (c) { env->features[FEAT_HYPERV_EAX] =3D c->eax; @@ -1328,8 +1336,10 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VERSION; - c->eax =3D 0x00001bbc; - c->ebx =3D 0x00060001; + c->eax =3D cpu->hyperv_version_id[0]; + c->ebx =3D cpu->hyperv_version_id[1]; + c->ecx =3D cpu->hyperv_version_id[2]; + c->edx =3D cpu->hyperv_version_id[3]; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474072; cv=none; d=zohomail.com; s=zohoarc; b=nuktgrEDY7bXrfgr2AEcP3RICoG0Me0mIzpG7tH02QmgWaGYVmy+qr0l5COVN0jsIIMTZwMn4b3OCK5p2OihoMLRl9XHM2dHddzMQwnNLzTZGYVpB4gg8+33QAhW5HOASWcFqhlWKFgC/pd9V8DHUggoFV0rXhAicK2JeuxoQBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474072; 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=WyKspBYuAkv+mkQrGRTfCl9R6UGLSu0mbqmmr6qQfGo=; b=avYxgdTTkSYEW+aeFLZNCf4DkJ75ZDy7GXwtvrj0qbNOAudvbK5LD/vUlGOVdx2VHIoqqK4hqISNYurMwsFXhINLh0ghoPAPwzlZqo6tR4cMIRw8dGmk+loOXCLcFfKr1XOfnF2nzMPgZfY0Ohma903WbhezQJkpRajG4a0epTk= 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+importer=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 1601474072583273.37967599535955; Wed, 30 Sep 2020 06:54:32 -0700 (PDT) Received: from localhost ([::1]:41640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcYs-00031V-TK for importer@patchew.org; Wed, 30 Sep 2020 09:54:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37892) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMR-0006ER-HO for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcML-0005c9-W1 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:35 -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-400-eHPg2FnEO8WxrMN7NaJGfQ-1; Wed, 30 Sep 2020 09:41:22 -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 60B9C1868413 for ; Wed, 30 Sep 2020 13:41:20 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00B2260C05; Wed, 30 Sep 2020 13:41:18 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473284; 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=WyKspBYuAkv+mkQrGRTfCl9R6UGLSu0mbqmmr6qQfGo=; b=RuFJNXrQmaerXnZbzb3oxhu5/4MqASGR80O8ZLf05gaoOoGRNbEmjeEd5UYdkc1T6QANul n2aTrDtsrcOfB5cocv0X7tH4Wo8VCvuB9tX2DF98jK8SovnuZBW7yjMxTt1iMYxz36BH4+ 9pbpXi1kuqHKVyF702yQKb++1KdBNJc= X-MC-Unique: eHPg2FnEO8WxrMN7NaJGfQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 07/19] i386: move hyperv_limits initialization to x86_cpu_realizefn() Date: Wed, 30 Sep 2020 15:40:15 +0200 Message-Id: <20200930134027.1348021-8-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As a preparation to expanding Hyper-V CPU features early, move hyperv_limits initialization to x86_cpu_realizefn(). Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 5 +++++ target/i386/cpu.h | 1 + target/i386/kvm.c | 13 ++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 99bcfcbb448a..d657590ab55d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6515,6 +6515,11 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) /* Hypervisor system identity */ cpu->hyperv_version_id[0] =3D 0x00001bbc; cpu->hyperv_version_id[1] =3D 0x00060001; + + /* Hypervisor implementation limits */ + cpu->hyperv_limits[0] =3D 64; + cpu->hyperv_limits[1] =3D 0; + cpu->hyperv_limits[2] =3D 0; } =20 static void x86_cpu_realizefn(DeviceState *dev, Error **errp) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 077c19c5642b..187e4a09e65d 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1662,6 +1662,7 @@ struct X86CPU { uint32_t hyperv_vendor_id[3]; uint32_t hyperv_interface_id[4]; uint32_t hyperv_version_id[4]; + uint32_t hyperv_limits[3]; =20 bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index b335b3a3d1c7..afddc9a4a260 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1253,6 +1253,15 @@ static int hyperv_handle_properties(CPUState *cs, 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; + cpu->hyperv_limits[0] =3D c->ebx; + cpu->hyperv_limits[1] =3D c->ecx; + cpu->hyperv_limits[2] =3D c->edx; + } + c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; @@ -1355,7 +1364,9 @@ static int hyperv_handle_properties(CPUState *cs, c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_IMPLEMENT_LIMITS; c->eax =3D cpu->hv_max_vps; - c->ebx =3D 0x40; + c->ebx =3D cpu->hyperv_limits[0]; + c->ecx =3D cpu->hyperv_limits[1]; + c->edx =3D cpu->hyperv_limits[2]; =20 if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { __u32 function; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473563; cv=none; d=zohomail.com; s=zohoarc; b=cGOB5AHAbLtj0qL6K07O4eINvfVk5lWVdp1xp/z+MqdQlvkz8qhzgQmKD2EK2NGh9ubqoLaFDhLnR9+2z3d7TlCvjNcSoVGYKjVYbpHr7XvY90jg9zCxiCKurwC4mI5PCqDqtweKUP6KWhjiJbK/h+L9H6m96/zw7jVaWZF4ih8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473563; 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=yJBU8aZ+zZJD/zVbzW/GKomX9R0tdkTMKW4JLjL86MM=; b=fruUD7XO0cfTloCD91ev4/ifK+pXrjI+7kJQhWZiRo6JsF4Mt86NR4rmy/lQ/LKPtEXruma1I8dFSZhghggJwIgCpOeFcP6foj2YQI7q2WrWnkApyzTLfUW1mA/By5mQQkMpgv50ZL/HgLMo4AVQe1+F00KV99Lfc+RB5jZKKgg= 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+importer=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 1601473563310860.0246306184335; Wed, 30 Sep 2020 06:46:03 -0700 (PDT) Received: from localhost ([::1]:46950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcQj-0001vJ-Qx for importer@patchew.org; Wed, 30 Sep 2020 09:46:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMR-0006Di-4M for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:32940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcML-0005cD-W2 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:34 -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-286-V1k8gMFeOJKjZQ81QAI2jw-1; Wed, 30 Sep 2020 09:41:23 -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 1FFC110BBEC3 for ; Wed, 30 Sep 2020 13:41:22 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDF5B60C05; Wed, 30 Sep 2020 13:41:20 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473284; 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=yJBU8aZ+zZJD/zVbzW/GKomX9R0tdkTMKW4JLjL86MM=; b=Ny3qf7Xk3VRd1nZGVr/mnnGCtDKATMAaRwEMOllMSoCgAh4oYP6ivbPhY7TOsWlCY7N0LO 8vpqPbsJUPO7d16XvZ7GFZ7u75s5Y06s0pT3jZydxTWSTV9ZUb/dOOrnrc9SHxmgBngmzk 9CtDmTOi1deDzns/0KDBi9qB2pd2Tx8= X-MC-Unique: V1k8gMFeOJKjZQ81QAI2jw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 08/19] i386: keep hyperv_vendor string up-to-date Date: Wed, 30 Sep 2020 15:40:16 +0200 Message-Id: <20200930134027.1348021-9-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" When cpu->hyperv_vendor is not set manually we default to "Microsoft Hv" and in 'hv_passthrough' mode we get the information from the host. This information is stored in cpu->hyperv_vendor_id[] array but we don't update cpu->hyperv_vendor string so e.g. QMP's query-cpu-model-expansion output is incorrect. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 20 ++++++++++---------- target/i386/kvm.c | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index d657590ab55d..8ec0af0a6d48 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6493,18 +6493,18 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu) { size_t len; =20 + /* Hyper-V vendor id */ if (!cpu->hyperv_vendor) { - memcpy(cpu->hyperv_vendor_id, "Microsoft Hv", 12); - } else { - len =3D strlen(cpu->hyperv_vendor); - - if (len > 12) { - warn_report("hv-vendor-id truncated to 12 characters"); - len =3D 12; - } - memset(cpu->hyperv_vendor_id, 0, 12); - memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); + object_property_set_str(OBJECT(cpu), "hv-vendor-id", "Microsoft Hv= ", + &error_abort); + } + len =3D strlen(cpu->hyperv_vendor); + if (len > 12) { + warn_report("hv-vendor-id truncated to 12 characters"); + len =3D 12; } + memset(cpu->hyperv_vendor_id, 0, 12); + memcpy(cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); =20 /* 'Hv#1' interface identification*/ cpu->hyperv_interface_id[0] =3D 0x31237648; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index afddc9a4a260..eb21f77be51b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1229,6 +1229,10 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor_id[0] =3D c->ebx; cpu->hyperv_vendor_id[1] =3D c->ecx; cpu->hyperv_vendor_id[2] =3D c->edx; + cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, + sizeof(cpu->hyperv_vendor_id) += 1); + memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, + sizeof(cpu->hyperv_vendor_id)); } =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473934; cv=none; d=zohomail.com; s=zohoarc; b=lvyvxJmxjCOVNA7054OV2QjY3LF89A4AmF6ZagFKNX6tds0NOj7njJuf9QRRl0v8c1N9ebqTLzf40Bz+xS/F6z9tdD3bwOLXzpC2Vt+R2RCGloottEQ10X1Mg4gQkzB6/gZhXdaPD85KWCxXaKJVKp7wMU+sYcLmqLcuMAxo1Ac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473934; 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=gf2wukrz25gggOGNXWghFVU/a5BCiAqWLqdLkPFpT7c=; b=LSCY9J7Qu6M1wfZz7+O4vmk0tx/58j32Y1T8L+mwQo7qLSTjrrJXZkAna5ntEgOy5JbHAAdAOB64tnovmEakLxaoIAUSvC1QQM45XiwbW0DKUFNvwey2TWNcdjnLcz2Ga/GxykdQn3JjKV7xTMsiWWU61SJQo1brEWlobnVjOq8= 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+importer=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 1601473934979914.4648851981708; Wed, 30 Sep 2020 06:52:14 -0700 (PDT) Received: from localhost ([::1]:36736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcWj-00010V-KF for importer@patchew.org; Wed, 30 Sep 2020 09:52:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMQ-0006D2-SF for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMM-0005cO-0V for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:34 -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-543-2ZSUujTVMRy-SQMqOUiUkg-1; Wed, 30 Sep 2020 09:41:24 -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 DBFF8ADF04 for ; Wed, 30 Sep 2020 13:41:23 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F6E560C05; Wed, 30 Sep 2020 13:41:22 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473286; 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=gf2wukrz25gggOGNXWghFVU/a5BCiAqWLqdLkPFpT7c=; b=TpKDqkuJHeeOpiuKSDZ+VpRJR7YMctX/NboiJRN0P373Gt6GKAiy6F7773Zwc61I0wIhI3 1UooD15AwvB8Gs2mWFTagcJYHnU3tWSSWbJ0hoYJhNTZEIoxnD0fE2PyZc+2gU/gWj+oYk 6HinXwEH4jYwreaY7xiXHt6c5uOqV3k= X-MC-Unique: 2ZSUujTVMRy-SQMqOUiUkg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 09/19] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough Date: Wed, 30 Sep 2020 15:40:17 +0200 Message-Id: <20200930134027.1348021-10-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is no need to have this special case: like all other Hyper-V enlightenments we can just use kernel's supplied value in hv_passthrough mode. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index eb21f77be51b..94e2195acb36 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1269,11 +1269,7 @@ static int hyperv_handle_properties(CPUState *cs, c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; - - /* hv-spinlocks may have been overriden */ - if (cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_N= OTIFY) { - c->ebx =3D cpu->hyperv_spinlock_attempts; - } + cpu->hyperv_spinlock_attempts =3D c->ebx; } c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); if (c) { --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473781; cv=none; d=zohomail.com; s=zohoarc; b=LFes6kUKklF0OPQbti7oIB70A+z9llY0raVTWfsuKXFCGIRZrUHXwsYfx6klLgdCoe8rD3WsVa3PlJbqjatAegeVZLJtEHH6n0O91LsHzSLfL3vQNGotngFM1ZFGnR9oiGQlmFDDicWNfubYTn7/8joTsfQbTRJgrjVXfZOS69g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473781; 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=TNUlf4HG9Bhbu2x1+xQFhhuRB7KGhsXXrZbsjxzvt1c=; b=HgOumG6Xf6KEPjb3d3mnqgPlWeDLvRsUKaObMAxGMCOyID+W0OcXLxKVqJih6bmO2u6lQw3LjnoRKmkc8iCoFI4BD75qTHZJ3hYWiffP16IAmGHqrM+FBhj7WrDnuH8grrsS9PVNP5gZGt9itlaZZYfQUXdpxIK961kk6O7S984= 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+importer=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 160147378133891.65336404694756; Wed, 30 Sep 2020 06:49:41 -0700 (PDT) Received: from localhost ([::1]:56648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcUG-00060X-1k for importer@patchew.org; Wed, 30 Sep 2020 09:49:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMQ-0006Bl-7x for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28655) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcML-0005cT-V4 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:33 -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-418-WfTtT-TgPI2lxfjdn5iuTQ-1; Wed, 30 Sep 2020 09:41:26 -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 AFAD4801F95 for ; Wed, 30 Sep 2020 13:41:25 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58B6760C05; Wed, 30 Sep 2020 13:41:24 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473288; 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=TNUlf4HG9Bhbu2x1+xQFhhuRB7KGhsXXrZbsjxzvt1c=; b=VoptofODT0gtW6PNXZtlNgneZBIJLh0TicZUvJhPzgExTZdcYpjPG7zgmjkMZl2Pk35CFe WiOCrCskRVus3NEv/o25l8jobi9qUwqpI04qGnLYlcF0tXzGSLzHIC0sVZznE8yGKulTSm PKOGD36TAAK7fzKw7LJA+C5T8gL3oEk= X-MC-Unique: WfTtT-TgPI2lxfjdn5iuTQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 10/19] i386: always fill Hyper-V CPUID feature leaves from X86CPU data Date: Wed, 30 Sep 2020 15:40:18 +0200 Message-Id: <20200930134027.1348021-11-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We have all the required data in X86CPU already and as we are about to split hyperv_handle_properties() into hyperv_expand_features()/ hyperv_fill_cpuids() we can remove the blind copy. The functional change is that QEMU won't pass CPUID leaves it doesn't currently know about to the guest but arguably this is a good change. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 94e2195acb36..a9823d4af7cb 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1221,9 +1221,6 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (cpu->hyperv_passthrough) { - memcpy(cpuid_ent, &cpuid->entries[0], - cpuid->nent * sizeof(cpuid->entries[0])); - c =3D cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0= ); if (c) { cpu->hyperv_vendor_id[0] =3D c->ebx; @@ -1322,12 +1319,6 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } =20 - if (cpu->hyperv_passthrough) { - /* We already copied all feature words from KVM as is */ - r =3D cpuid->nent; - goto free; - } - c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; c->eax =3D hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473769; cv=none; d=zohomail.com; s=zohoarc; b=N2jgBNmm9imZRVApBbPlh3DdcQ2eoglikBIIHG83NvPa9JE6Pe/LddiVYaVqQp8OGlbejAwoRfH+k/nBzS4Rdt98yog7n3HzUxjLP+p+JxBbRhXIHGi7dIQ4AtDzKDc1wsMI0unDRsDROU6JFMqk7ZQxLRI6sp+AkYg7XE6WkdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473769; 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=rJCOJwuy0qnMblB9QXbD7hfjLj8mv2qXcOGW5yP7M3U=; b=JJWkJc2iiBgjVW3Q75AfZ8lfdg5VcQ4CGFxhtP4wyBT1oVS6a+fCfGZ6lO+w9Xa1h+KYC9r03RAxQr3M0lQqrmEt7EdPJJD3lT8DhNDJi0PXnEvuKLJRVAv3kokSBIo/Gwx/KJtPLHmPIpkUoXy/6YchVmnagiWz3n3WqOrpo9g= 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+importer=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 1601473769124563.5756972640866; Wed, 30 Sep 2020 06:49:29 -0700 (PDT) Received: from localhost ([::1]:55420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcU3-0005S2-CS for importer@patchew.org; Wed, 30 Sep 2020 09:49:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMS-0006GY-Ld for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45456) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMN-0005cu-UG for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:36 -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-111-7VP_PUlXO7eNtiFIaSSYnA-1; Wed, 30 Sep 2020 09:41:28 -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 8844AADF05 for ; Wed, 30 Sep 2020 13:41:27 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1981D60C05; Wed, 30 Sep 2020 13:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473290; 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=rJCOJwuy0qnMblB9QXbD7hfjLj8mv2qXcOGW5yP7M3U=; b=BzzZDCRWdsHatht1ITywMdr5VOGD1LR6dMQdLLpEUksgEO4FZ3vZXBpGpGrxSOtVJdtyLu nncX/I8yYkCbszcvnZUheIuOThq3FGYM4mzaqhfS0tv1oAleMKiLPlDtqeC3E2zmBe0t4+ /gv0svHC2+XImdVyYU78gljy1Bxa65M= X-MC-Unique: 7VP_PUlXO7eNtiFIaSSYnA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 11/19] i386: introduce hv_cpuid_cache Date: Wed, 30 Sep 2020 15:40:19 +0200 Message-Id: <20200930134027.1348021-12-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Just like with cpuid_cache, it makes no sense to call KVM_GET_SUPPORTED_HV_CPUID more than once and instead of (ab)using env->features[] and/or trying to keep all the code in one place, it is better to introduce persistent hv_cpuid_cache and hv_cpuid_get_host() accessor to it. Note, hv_cpuid_get_fw() is converted to using hv_cpuid_get_host() just to be removed later with Hyper-V specific feature words. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 213 +++++++++++++++++++++++----------------------- 1 file changed, 106 insertions(+), 107 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a9823d4af7cb..0e6eef6a52c2 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -124,6 +124,7 @@ static int has_exception_payload; static bool has_msr_mcg_ext_ctl; =20 static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_cpuid2 *hv_cpuid_cache; static struct kvm_msr_list *kvm_feature_msrs; =20 int kvm_has_pit_state2(void) @@ -1079,9 +1080,36 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid_leg= acy(CPUState *cs) return cpuid; } =20 -static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r) +static uint32_t hv_cpuid_get_host(CPUState *cs, uint32_t func, int reg) { struct kvm_cpuid_entry2 *entry; + struct kvm_cpuid2 *cpuid; + + if (hv_cpuid_cache) { + cpuid =3D hv_cpuid_cache; + } else { + if (kvm_check_extension(kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { + cpuid =3D get_supported_hv_cpuid(cs); + } else { + cpuid =3D get_supported_hv_cpuid_legacy(cs); + } + hv_cpuid_cache =3D cpuid; + } + + if (!cpuid) { + return 0; + } + + entry =3D cpuid_find_entry(cpuid, func, 0); + if (!entry) { + return 0; + } + + return cpuid_entry_get_reg(entry, reg); +} + +static uint32_t hv_cpuid_get_fw(CPUState *cs, int fw) +{ uint32_t func; int reg; =20 @@ -1099,30 +1127,13 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid= , int fw, uint32_t *r) func =3D HV_CPUID_ENLIGHTMENT_INFO; break; default: - return -EINVAL; - } - - entry =3D cpuid_find_entry(cpuid, func, 0); - if (!entry) { - return -ENOENT; - } - - switch (reg) { - case R_EAX: - *r =3D entry->eax; - break; - case R_EDX: - *r =3D entry->edx; - break; - default: - return -EINVAL; + return 0; } =20 - return 0; + return hv_cpuid_get_host(cs, func, reg); } =20 -static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, - int feature) +static int hv_cpuid_check_and_set(CPUState *cs, int feature) { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; @@ -1155,7 +1166,8 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, continue; } =20 - if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + r =3D hv_cpuid_get_fw(cs, fw); + if ((r & bits) !=3D bits) { if (hyperv_feat_enabled(cpu, feature)) { fprintf(stderr, "Hyper-V %s is not supported by kernel\n", @@ -1186,7 +1198,6 @@ static int hyperv_handle_properties(CPUState *cs, { X86CPU *cpu =3D X86_CPU(cs); CPUX86State *env =3D &cpu->env; - struct kvm_cpuid2 *cpuid; struct kvm_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; @@ -1214,92 +1225,85 @@ static int hyperv_handle_properties(CPUState *cs, } } =20 - if (kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_CPUID) > 0) { - cpuid =3D get_supported_hv_cpuid(cs); - } else { - cpuid =3D get_supported_hv_cpuid_legacy(cs); - } - if (cpu->hyperv_passthrough) { - c =3D cpuid_find_entry(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, 0= ); - if (c) { - cpu->hyperv_vendor_id[0] =3D c->ebx; - cpu->hyperv_vendor_id[1] =3D c->ecx; - cpu->hyperv_vendor_id[2] =3D c->edx; - cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, - sizeof(cpu->hyperv_vendor_id) += 1); - memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, - sizeof(cpu->hyperv_vendor_id)); - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_INTERFACE, 0); - if (c) { - cpu->hyperv_interface_id[0] =3D c->eax; - cpu->hyperv_interface_id[1] =3D c->ebx; - cpu->hyperv_interface_id[2] =3D c->ecx; - cpu->hyperv_interface_id[3] =3D c->edx; - } - - c =3D cpuid_find_entry(cpuid, HV_CPUID_VERSION, 0); - if (c) { - cpu->hyperv_version_id[0] =3D c->eax; - cpu->hyperv_version_id[1] =3D c->ebx; - cpu->hyperv_version_id[2] =3D c->ecx; - cpu->hyperv_version_id[3] =3D c->edx; - } - - 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; - cpu->hyperv_limits[0] =3D c->ebx; - cpu->hyperv_limits[1] =3D c->ecx; - cpu->hyperv_limits[2] =3D c->edx; - } - - 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; - } + cpu->hyperv_vendor_id[0] =3D + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); + cpu->hyperv_vendor_id[1] =3D + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_ECX= ); + cpu->hyperv_vendor_id[2] =3D + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EDX= ); + cpu->hyperv_vendor =3D g_realloc(cpu->hyperv_vendor, + sizeof(cpu->hyperv_vendor_id) + 1); + memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id, + sizeof(cpu->hyperv_vendor_id)); + + cpu->hyperv_interface_id[0] =3D + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EAX); + cpu->hyperv_interface_id[1] =3D + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EBX); + cpu->hyperv_interface_id[2] =3D + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_ECX); + cpu->hyperv_interface_id[3] =3D + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EDX); + + cpu->hyperv_version_id[0] =3D + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EAX); + cpu->hyperv_version_id[1] =3D + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX); + cpu->hyperv_version_id[2] =3D + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_ECX); + cpu->hyperv_version_id[3] =3D + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX); + + env->features[FEAT_HYPERV_EAX] =3D + hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EAX); + env->features[FEAT_HYPERV_EBX] =3D + hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EBX); + env->features[FEAT_HYPERV_EDX] =3D + hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EDX); + + cpu->hv_max_vps =3D hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMIT= S, + R_EAX); + cpu->hyperv_limits[0] =3D + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); + cpu->hyperv_limits[1] =3D + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); + cpu->hyperv_limits[2] =3D + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); + + env->features[FEAT_HV_RECOMM_EAX] =3D + hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX); + cpu->hyperv_spinlock_attempts =3D + hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); + + env->features[FEAT_HV_NESTED_EAX] =3D + hv_cpuid_get_host(cs, HV_CPUID_NESTED_FEATURES, R_EAX); } =20 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; - } + env->features[FEAT_HV_RECOMM_EAX] |=3D + hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX) & + HV_NO_NONARCH_CORESHARING; } =20 /* Features */ - r =3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RELAXED); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_VAPIC); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TIME); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_CRASH); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RESET); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_VPINDEX); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_RUNTIME); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_SYNIC); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_FREQUENCIES); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_REENLIGHTENMENT); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_TLBFLUSH); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_EVMCS); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_IPI); - r |=3D hv_cpuid_check_and_set(cs, cpuid, HYPERV_FEAT_STIMER_DIRECT); + r =3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI); + r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT); =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && @@ -1315,8 +1319,7 @@ static int hyperv_handle_properties(CPUState *cs, env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; =20 if (r) { - r =3D -ENOSYS; - goto free; + return -ENOSYS; } =20 c =3D &cpuid_ent[cpuid_i++]; @@ -1373,12 +1376,8 @@ static int hyperv_handle_properties(CPUState *cs, c->function =3D HV_CPUID_NESTED_FEATURES; c->eax =3D env->features[FEAT_HV_NESTED_EAX]; } - r =3D cpuid_i; - -free: - g_free(cpuid); =20 - return r; + return cpuid_i; } =20 static Error *hv_passthrough_mig_blocker; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473824; cv=none; d=zohomail.com; s=zohoarc; b=OfEoVDab12mxrrAThPqVbcqTlBICP5TankO8NJVwo4fmMwspFtbXrwVn/bRiWkw6QDFdCkDIUjv3O36Zd0/9j6AYn4mC/u9fZ8wNphcaTaOcwtY2DXvRFFmOIntZ9nash204bxKFjqI67+L6a3yJEPXodVkWrfQis9dg0/V09ds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473824; 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=lmoWUC+KaSFC0AvTaDVRAouxYqWCJF3sPBCV1Ou8AhI=; b=jjaB6aH/X8kzHFeG/laTT3Xcue7mE5lQTzv1vlGEXYPAxmKLFG5DEw0TBtOa4QQbDVJkWQRgJKHyvxaX44jIbrt77Jzky/sWmy+G3dNPOqWXjZF4NMyF4zmAEknLQerZaSaFcfj+8uKSnLAyg7ZNaJmJcBz93XGz4hqIqVo8o/0= 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+importer=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 1601473824426767.5000041259715; Wed, 30 Sep 2020 06:50:24 -0700 (PDT) Received: from localhost ([::1]:58916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcUw-0006xb-VP for importer@patchew.org; Wed, 30 Sep 2020 09:50:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMT-0006Ib-NS for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48484) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMQ-0005dD-2K for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:37 -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-307-npHH0OzUPo2d1q6_tuZdJA-1; Wed, 30 Sep 2020 09:41:31 -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 954AD10BBEC9 for ; Wed, 30 Sep 2020 13:41:29 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id E769260C05; Wed, 30 Sep 2020 13:41:27 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473293; 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=lmoWUC+KaSFC0AvTaDVRAouxYqWCJF3sPBCV1Ou8AhI=; b=JdtfMJPKWvugla/ev9KiARS9OeVTqL11raTskeH5foZYVBnIz5Dm8mCetrfEiTpJ+4bgog 1To7ZbAqefgsehoZFWWoHDSRbeyv1gbxg56wH0bw7ALltaY3c/J4cDDWVwGNddCs0KT892 Ee8u2vME1rZSMpmg5wg2K2YZaEoic4c= X-MC-Unique: npHH0OzUPo2d1q6_tuZdJA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 12/19] i386: drop FEAT_HYPERV feature leaves Date: Wed, 30 Sep 2020 15:40:20 +0200 Message-Id: <20200930134027.1348021-13-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Hyper-V feature leaves are weird. We have some of them in feature_word_info[] array but we don't use feature_word_info magic to enable them. Neither do we use feature_dependencies[] mechanism to validate the configuration as it doesn't allign well with Hyper-V's many-to-many dependency chains. Some of the feature leaves hold not only feature bits, but also values. E.g. FEAT_HV_NESTED_EAX contains both features and the supported Enlightened VMCS range. Hyper-V features are already represented in 'struct X86CPU' with uint64_t hyperv_features so duplicating them in env->features adds little (or zero) benefits. THe other half of Hyper-V emulation features is also stored with values in hyperv_vendor_id[], hyperv_limits[],... so env->features[] is already incomplete. Remove Hyper-V feature leaves from env->features[] completely. kvm_hyperv_properties[] is converted to using raw CPUID func/reg pairs for features, this allows us to get rid of hv_cpuid_get_fw() conversion. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 90 +---------------------- target/i386/cpu.h | 6 +- target/i386/kvm.c | 181 ++++++++++++++++++++++------------------------ 3 files changed, 90 insertions(+), 187 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 8ec0af0a6d48..a178db255641 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -828,94 +828,6 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS= ] =3D { */ .no_autoenable_flags =3D ~0U, }, - /* - * .feat_names are commented out for Hyper-V enlightenments because we - * don't want to have two different ways for enabling them on QEMU com= mand - * line. Some features (e.g. "hyperv_time", "hyperv_vapic", ...) requi= re - * enabling several feature bits simultaneously, exposing these bits - * individually may just confuse guests. - */ - [FEAT_HYPERV_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_msr_vp_runtime_access */, NULL /* hv_msr_time_refco= unt_access */, - NULL /* hv_msr_synic_access */, NULL /* hv_msr_stimer_access *= /, - NULL /* hv_msr_apic_access */, NULL /* hv_msr_hypercall_access= */, - NULL /* hv_vpindex_access */, NULL /* hv_msr_reset_access */, - NULL /* hv_msr_stats_access */, NULL /* hv_reftsc_access */, - NULL /* hv_msr_idle_access */, NULL /* hv_msr_frequency_access= */, - NULL /* hv_msr_debug_access */, NULL /* hv_msr_reenlightenment= _access */, - NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EAX, }, - }, - [FEAT_HYPERV_EBX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_create_partitions */, NULL /* hv_access_partition_i= d */, - NULL /* hv_access_memory_pool */, NULL /* hv_adjust_message_bu= ffers */, - NULL /* hv_post_messages */, NULL /* hv_signal_events */, - NULL /* hv_create_port */, NULL /* hv_connect_port */, - NULL /* hv_access_stats */, NULL, NULL, NULL /* hv_debugging *= /, - NULL /* hv_cpu_power_management */, NULL /* hv_configure_profi= ler */, - NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EBX, }, - }, - [FEAT_HYPERV_EDX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_mwait */, NULL /* hv_guest_debugging */, - NULL /* hv_perf_monitor */, NULL /* hv_cpu_dynamic_part */, - NULL /* hv_hypercall_params_xmm */, NULL /* hv_guest_idle_stat= e */, - NULL, NULL, - NULL, NULL, NULL /* hv_guest_crash_msr */, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000003, .reg =3D R_EDX, }, - }, - [FEAT_HV_RECOMM_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .feat_names =3D { - NULL /* hv_recommend_pv_as_switch */, - NULL /* hv_recommend_pv_tlbflush_local */, - NULL /* hv_recommend_pv_tlbflush_remote */, - NULL /* hv_recommend_msr_apic_access */, - NULL /* hv_recommend_msr_reset */, - NULL /* hv_recommend_relaxed_timing */, - NULL /* hv_recommend_dma_remapping */, - NULL /* hv_recommend_int_remapping */, - NULL /* hv_recommend_x2apic_msrs */, - NULL /* hv_recommend_autoeoi_deprecation */, - NULL /* hv_recommend_pv_ipi */, - NULL /* hv_recommend_ex_hypercalls */, - NULL /* hv_hypervisor_is_nested */, - NULL /* hv_recommend_int_mbec */, - NULL /* hv_recommend_evmcs */, - NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }, - .cpuid =3D { .eax =3D 0x40000004, .reg =3D R_EAX, }, - }, - [FEAT_HV_NESTED_EAX] =3D { - .type =3D CPUID_FEATURE_WORD, - .cpuid =3D { .eax =3D 0x4000000A, .reg =3D R_EAX, }, - }, [FEAT_SVM] =3D { .type =3D CPUID_FEATURE_WORD, .feat_names =3D { @@ -6906,7 +6818,7 @@ static GuestPanicInformation *x86_cpu_get_crash_info(= CPUState *cs) CPUX86State *env =3D &cpu->env; GuestPanicInformation *panic_info =3D NULL; =20 - if (env->features[FEAT_HYPERV_EDX] & HV_GUEST_CRASH_MSR_AVAILABLE) { + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_CRASH)) { panic_info =3D g_malloc0(sizeof(GuestPanicInformation)); =20 panic_info->type =3D GUEST_PANIC_INFORMATION_TYPE_HYPER_V; diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 187e4a09e65d..b07325745bcb 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -519,11 +519,6 @@ typedef enum FeatureWord { FEAT_C000_0001_EDX, /* CPUID[C000_0001].EDX */ FEAT_KVM, /* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */ FEAT_KVM_HINTS, /* CPUID[4000_0001].EDX */ - FEAT_HYPERV_EAX, /* CPUID[4000_0003].EAX */ - FEAT_HYPERV_EBX, /* CPUID[4000_0003].EBX */ - FEAT_HYPERV_EDX, /* CPUID[4000_0003].EDX */ - FEAT_HV_RECOMM_EAX, /* CPUID[4000_0004].EAX */ - FEAT_HV_NESTED_EAX, /* CPUID[4000_000A].EAX */ FEAT_SVM, /* CPUID[8000_000A].EDX */ FEAT_XSAVE, /* CPUID[EAX=3D0xd,ECX=3D1].EAX */ FEAT_6_EAX, /* CPUID[6].EAX */ @@ -1663,6 +1658,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.c b/target/i386/kvm.c index 0e6eef6a52c2..86a5cfa1e12b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -815,7 +815,8 @@ static bool tsc_is_stable_and_known(CPUX86State *env) static struct { const char *desc; struct { - uint32_t fw; + uint32_t func; + int reg; uint32_t bits; } flags[2]; uint64_t dependencies; @@ -823,25 +824,25 @@ static struct { [HYPERV_FEAT_RELAXED] =3D { .desc =3D "relaxed timing (hv-relaxed)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE}, - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_RELAXED_TIMING_RECOMMENDED} } }, [HYPERV_FEAT_VAPIC] =3D { .desc =3D "virtual APIC (hv-vapic)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE | HV_APIC_ACCESS_AVAILABLE}, - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_APIC_ACCESS_RECOMMENDED} } }, [HYPERV_FEAT_TIME] =3D { .desc =3D "clocksources (hv-time)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_HYPERCALL_AVAILABLE | HV_TIME_REF_COUNT_AVAILABL= E | HV_REFERENCE_TSC_AVAILABLE} } @@ -849,42 +850,42 @@ static struct { [HYPERV_FEAT_CRASH] =3D { .desc =3D "crash MSRs (hv-crash)", .flags =3D { - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_GUEST_CRASH_MSR_AVAILABLE} } }, [HYPERV_FEAT_RESET] =3D { .desc =3D "reset MSR (hv-reset)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_RESET_AVAILABLE} } }, [HYPERV_FEAT_VPINDEX] =3D { .desc =3D "VP_INDEX MSR (hv-vpindex)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_VP_INDEX_AVAILABLE} } }, [HYPERV_FEAT_RUNTIME] =3D { .desc =3D "VP_RUNTIME MSR (hv-runtime)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_VP_RUNTIME_AVAILABLE} } }, [HYPERV_FEAT_SYNIC] =3D { .desc =3D "synthetic interrupt controller (hv-synic)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_SYNIC_AVAILABLE} } }, [HYPERV_FEAT_STIMER] =3D { .desc =3D "synthetic timers (hv-stimer)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_SYNTIMERS_AVAILABLE} }, .dependencies =3D BIT(HYPERV_FEAT_SYNIC) | BIT(HYPERV_FEAT_TIME) @@ -892,23 +893,23 @@ static struct { [HYPERV_FEAT_FREQUENCIES] =3D { .desc =3D "frequency MSRs (hv-frequencies)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_ACCESS_FREQUENCY_MSRS}, - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_FREQUENCY_MSRS_AVAILABLE} } }, [HYPERV_FEAT_REENLIGHTENMENT] =3D { .desc =3D "reenlightenment MSRs (hv-reenlightenment)", .flags =3D { - {.fw =3D FEAT_HYPERV_EAX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EAX, .bits =3D HV_ACCESS_REENLIGHTENMENTS_CONTROL} } }, [HYPERV_FEAT_TLBFLUSH] =3D { .desc =3D "paravirtualized TLB flush (hv-tlbflush)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_REMOTE_TLB_FLUSH_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} }, @@ -917,7 +918,7 @@ static struct { [HYPERV_FEAT_EVMCS] =3D { .desc =3D "enlightened VMCS (hv-evmcs)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_ENLIGHTENED_VMCS_RECOMMENDED} }, .dependencies =3D BIT(HYPERV_FEAT_VAPIC) @@ -925,7 +926,7 @@ static struct { [HYPERV_FEAT_IPI] =3D { .desc =3D "paravirtualized IPI (hv-ipi)", .flags =3D { - {.fw =3D FEAT_HV_RECOMM_EAX, + {.func =3D HV_CPUID_ENLIGHTMENT_INFO, .reg =3D R_EAX, .bits =3D HV_CLUSTER_IPI_RECOMMENDED | HV_EX_PROCESSOR_MASKS_RECOMMENDED} }, @@ -934,7 +935,7 @@ static struct { [HYPERV_FEAT_STIMER_DIRECT] =3D { .desc =3D "direct mode synthetic timers (hv-stimer-direct)", .flags =3D { - {.fw =3D FEAT_HYPERV_EDX, + {.func =3D HV_CPUID_FEATURES, .reg =3D R_EDX, .bits =3D HV_STIMER_DIRECT_MODE_AVAILABLE} }, .dependencies =3D BIT(HYPERV_FEAT_STIMER) @@ -1108,38 +1109,34 @@ static uint32_t hv_cpuid_get_host(CPUState *cs, uin= t32_t func, int reg) return cpuid_entry_get_reg(entry, reg); } =20 -static uint32_t hv_cpuid_get_fw(CPUState *cs, int fw) +static bool hyperv_feature_supported(CPUState *cs, int feature) { - uint32_t func; - int reg; + uint32_t func, bits; + int i, reg; =20 - switch (fw) { - case FEAT_HYPERV_EAX: - reg =3D R_EAX; - func =3D HV_CPUID_FEATURES; - break; - case FEAT_HYPERV_EDX: - reg =3D R_EDX; - func =3D HV_CPUID_FEATURES; - break; - case FEAT_HV_RECOMM_EAX: - reg =3D R_EAX; - func =3D HV_CPUID_ENLIGHTMENT_INFO; - break; - default: - return 0; + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { + + func =3D kvm_hyperv_properties[feature].flags[i].func; + reg =3D kvm_hyperv_properties[feature].flags[i].reg; + bits =3D kvm_hyperv_properties[feature].flags[i].bits; + + if (!func) { + continue; + } + + if ((hv_cpuid_get_host(cs, func, reg) & bits) !=3D bits) { + return false; + } } =20 - return hv_cpuid_get_host(cs, func, reg); + return true; } =20 static int hv_cpuid_check_and_set(CPUState *cs, 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; + int dep_feat; =20 if (!hyperv_feat_enabled(cpu, feature) && !cpu->hyperv_passthrough) { return 0; @@ -1158,27 +1155,15 @@ static int hv_cpuid_check_and_set(CPUState *cs, int= feature) deps &=3D ~(1ull << dep_feat); } =20 - for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { - fw =3D kvm_hyperv_properties[feature].flags[i].fw; - bits =3D kvm_hyperv_properties[feature].flags[i].bits; - - if (!fw) { - continue; - } - - r =3D hv_cpuid_get_fw(cs, fw); - if ((r & bits) !=3D bits) { - if (hyperv_feat_enabled(cpu, feature)) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); - return 1; - } else { - return 0; - } + if (!hyperv_feature_supported(cs, feature)) { + if (hyperv_feat_enabled(cpu, feature)) { + fprintf(stderr, + "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[feature].desc); + return 1; + } else { + return 0; } - - env->features[fw] |=3D bits; } =20 if (cpu->hyperv_passthrough) { @@ -1188,6 +1173,32 @@ static int hv_cpuid_check_and_set(CPUState *cs, int = feature) return 0; } =20 +static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t func, int reg) +{ + 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].func !=3D func) { + continue; + } + if (kvm_hyperv_properties[i].flags[j].reg !=3D reg) { + 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 @@ -1197,7 +1208,6 @@ 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_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; @@ -1219,9 +1229,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 @@ -1255,13 +1263,6 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_version_id[3] =3D hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX); =20 - env->features[FEAT_HYPERV_EAX] =3D - hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EAX); - env->features[FEAT_HYPERV_EBX] =3D - hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EBX); - env->features[FEAT_HYPERV_EDX] =3D - hv_cpuid_get_host(cs, HV_CPUID_FEATURES, R_EDX); - cpu->hv_max_vps =3D hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMIT= S, R_EAX); cpu->hyperv_limits[0] =3D @@ -1271,21 +1272,8 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_limits[2] =3D hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); =20 - env->features[FEAT_HV_RECOMM_EAX] =3D - hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX); cpu->hyperv_spinlock_attempts =3D hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); - - env->features[FEAT_HV_NESTED_EAX] =3D - hv_cpuid_get_host(cs, HV_CPUID_NESTED_FEATURES, R_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) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX) & - HV_NO_NONARCH_CORESHARING; } =20 /* Features */ @@ -1315,9 +1303,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) { return -ENOSYS; } @@ -1346,15 +1331,25 @@ 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, HV_CPUID_FEATURES, R_EAX); + c->ebx =3D hv_build_cpuid_leaf(cs, HV_CPUID_FEATURES, R_EBX); + c->edx =3D hv_build_cpuid_leaf(cs, HV_CPUID_FEATURES, R_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, HV_CPUID_ENLIGHTMENT_INFO, R_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) { + c->eax |=3D hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_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; @@ -1374,7 +1369,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]; } =20 return cpuid_i; --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474223; cv=none; d=zohomail.com; s=zohoarc; b=kqDV/qvDfVz4RCxEn+Hy3gWFkYgq91zt1+1mrtaQMEhi4O5OS8yP7tflAQCXodipm3H75l7hwjbYjg2CB7ysKdubemHpvFhNmAzEweUT8prGeweyx228XyFGTa6KxFSCHSIGurpHQ+HE3VgECz19A+wOZzWZKcOWvW7j3iaohac= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474223; 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=WN4LE8t/DByIxTz/JRhY5PRr1t/M3a5mw6/p7Ud2ibE=; b=IDyjhhZYVuPUMA6XPnBfwIN379Mxrf6E5QzY49uzp5I0pd6KfcV4oc82OnGPkbFKVJvxDlG0FKUVNGeEaDwx9Xxt0T7aEH9wZ7T8e7WGs6UcfJwurouFkx+1F2ELSNt/UxzjRsyo+WqxL1WLjEcriP/zlVeodv99/4S48B/eQ5I= 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+importer=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 1601474223650746.656257044316; Wed, 30 Sep 2020 06:57:03 -0700 (PDT) Received: from localhost ([::1]:50006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcbO-0006T5-5r for importer@patchew.org; Wed, 30 Sep 2020 09:57:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMT-0006Ie-Ma for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56775) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMR-0005dX-Rd for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:37 -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-179-AHjjN0IzMvyyzKQhilpiSA-1; Wed, 30 Sep 2020 09:41:32 -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 654908030DF for ; Wed, 30 Sep 2020 13:41:31 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id F322360C05; Wed, 30 Sep 2020 13:41:29 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473295; 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=WN4LE8t/DByIxTz/JRhY5PRr1t/M3a5mw6/p7Ud2ibE=; b=HpqABRIVZN6cGtwl1WyTHybpY9I99N1Qum2RQaMP2o/Qfv9YkMvms9IIY/j87aeXiuLZqW xxmxBjLGzjTTtiHFUWkBx9zZiuAO03iBumRgCy4gkLPGQLR8tt+QbW9Ig56qxP3u7MU2os MoEAK1Bvq+MZyzHJz4ELQuyxSRyl26A= X-MC-Unique: AHjjN0IzMvyyzKQhilpiSA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 13/19] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() Date: Wed, 30 Sep 2020 15:40:21 +0200 Message-Id: <20200930134027.1348021-14-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The intention is to call hyperv_expand_features() early, before vCPUs are created and use the acquired data later when we set guest visible CPUID data. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 86a5cfa1e12b..0808355bfcfd 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1200,16 +1200,15 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) } =20 /* - * 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 - * extentions are enabled. + * Expand Hyper-V CPU features. In partucular, check that all the requested + * features are supported by the host and the sanity of the configuration + * (that all the required dependencies are included). Also, this takes care + * of 'hv_passthrough' mode and fills the environment with all supported + * Hyper-V features. */ -static int hyperv_handle_properties(CPUState *cs, - struct kvm_cpuid_entry2 *cpuid_ent) +static int hyperv_expand_features(CPUState *cs) { X86CPU *cpu =3D X86_CPU(cs); - struct kvm_cpuid_entry2 *c; - uint32_t cpuid_i =3D 0; int r; =20 if (!hyperv_enabled(cpu)) @@ -1307,6 +1306,19 @@ static int hyperv_handle_properties(CPUState *cs, return -ENOSYS; } =20 + return 0; +} + +/* + * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt. + */ +static int hyperv_fill_cpuids(CPUState *cs, + struct kvm_cpuid_entry2 *cpuid_ent) +{ + X86CPU *cpu =3D X86_CPU(cs); + struct kvm_cpuid_entry2 *c; + uint32_t cpuid_i =3D 0; + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_VENDOR_AND_MAX_FUNCTIONS; c->eax =3D hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ? @@ -1514,11 +1526,13 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - r =3D hyperv_handle_properties(cs, cpuid_data.entries); + r =3D hyperv_expand_features(cs); if (r < 0) { return r; - } else if (r > 0) { - cpuid_i =3D r; + } + + if (hyperv_enabled(cpu)) { + cpuid_i =3D hyperv_fill_cpuids(cs, cpuid_data.entries); kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; } --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601473905; cv=none; d=zohomail.com; s=zohoarc; b=I11CdivrVgoHp1ZZZWuwlm97tqjDpqCrTit4IeFoOuf04nWVR+7nMVbX1TsZwQeMTsgr5G90gP7oDutjWnOq2KUyiCoVJ/240Bsiuz2JO/ItX/1ynqZc0qThTxsLBYrE3Hs0h7/yDgOK50eoNwU9SBcWDyYICv39My5okg4wd8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601473905; 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=UpZKa7lGV2ZXbfTkflmLPamKfI5j5q26s1sGK0a6/WY=; b=ag44Yec9BHqwdm6n12OXU0gpm62aS/zRcZVDJNKOSk4UV5MWDcp9I0I/NdknoAHjFGKpLwuw26CNDGE0WS52sM0Qu6UR87uKQk1cHnepsnizOhOd70qSLoA4p33hBPxQkjpzwBocVFloJIB5msnsrM2ZPomsU92HCOGqDoJ5uto= 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+importer=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 1601473905637865.443587691363; Wed, 30 Sep 2020 06:51:45 -0700 (PDT) Received: from localhost ([::1]:35446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcWG-0000TK-FU for importer@patchew.org; Wed, 30 Sep 2020 09:51:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMb-0006LT-5p for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMT-0005di-BG for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:43 -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-272-jJiteyeqOvmiBNCv3sXPkg-1; Wed, 30 Sep 2020 09:41:34 -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 48AE0873157 for ; Wed, 30 Sep 2020 13:41:33 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id C490760C05; Wed, 30 Sep 2020 13:41:31 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473296; 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=UpZKa7lGV2ZXbfTkflmLPamKfI5j5q26s1sGK0a6/WY=; b=TYeJ/WazOcH5ifth8D2MfiJVIJFAe4od5JA/Kmsqt9T/0bY2ueTL9t9P3DCKXycujJZOIu IFo2pHgs0AR/DDLEFMZaxPOd9+MhlVEpd2oAnyyA56qI/ubdCw5+jw8La/QbEm0cPAF3ZH TpcHet6CDLD67laW8yWHli+Zvq7ySbo= X-MC-Unique: jJiteyeqOvmiBNCv3sXPkg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 14/19] i386: move eVMCS enablement to hyperv_init_vcpu() Date: Wed, 30 Sep 2020 15:40:22 +0200 Message-Id: <20200930134027.1348021-15-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" hyperv_expand_features() will be called before we create vCPU so evmcs enablement should go away. hyperv_init_vcpu() looks like the right place. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 60 +++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 0808355bfcfd..181e034da701 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -976,6 +976,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSta= te *cs) { struct kvm_cpuid2 *cpuid; int max =3D 7; /* 0x40000000..0x40000005, 0x4000000A */ + int i; =20 /* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with @@ -985,6 +986,22 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSt= ate *cs) while ((cpuid =3D try_get_hv_cpuid(cs, max)) =3D=3D NULL) { max++; } + + /* + * KVM_GET_SUPPORTED_HV_CPUID does not set EVMCS CPUID bit before + * KVM_CAP_HYPERV_ENLIGHTENED_VMCS is enabled but we want to get the + * information early, just check for the capability and set the bit + * manually. + */ + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_ENLIGHTENED_VMCS) > 0) { + for (i =3D 0; i < cpuid->nent; i++) { + if (cpuid->entries[i].function =3D=3D HV_CPUID_ENLIGHTMENT_INF= O) { + cpuid->entries[i].eax |=3D HV_ENLIGHTENED_VMCS_RECOMMENDED; + } + } + } + return cpuid; } =20 @@ -1214,24 +1231,6 @@ static int hyperv_expand_features(CPUState *cs) if (!hyperv_enabled(cpu)) return 0; =20 - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) || - cpu->hyperv_passthrough) { - uint16_t evmcs_version; - - r =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, - (uintptr_t)&evmcs_version); - - if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) && r) { - fprintf(stderr, "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); - return -ENOSYS; - } - - if (!r) { - cpu->hyperv_nested[0] =3D evmcs_version; - } - } - if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); @@ -1468,6 +1467,21 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } =20 + if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { + uint16_t evmcs_version; + + ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, + (uintptr_t)&evmcs_version); + + if (ret < 0) { + fprintf(stderr, "Hyper-V %s is not supported by kernel\n", + kvm_hyperv_properties[HYPERV_FEAT_EVMCS].desc); + return ret; + } + + cpu->hyperv_nested[0] =3D evmcs_version; + } + return 0; } =20 @@ -1532,6 +1546,11 @@ int kvm_arch_init_vcpu(CPUState *cs) } =20 if (hyperv_enabled(cpu)) { + r =3D hyperv_init_vcpu(cpu); + if (r) { + return r; + } + cpuid_i =3D hyperv_fill_cpuids(cs, cpuid_data.entries); kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; @@ -1879,11 +1898,6 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 kvm_init_msrs(cpu); =20 - r =3D hyperv_init_vcpu(cpu); - if (r) { - goto fail; - } - return 0; =20 fail: --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474122; cv=none; d=zohomail.com; s=zohoarc; b=I+2MJOF0lt3znPJsxZcvpy1qQ8RwXJzPcrEyo/1K7eUMoVVgG2dI09Ma1YoW+2Ktilc8zORCTGN3iuRS8Zq/mQOtn9foyA2wFFyCRIMNivpiukhgvlsK/H90ZZ3KNbLQjBCkP/0zQik9ZLJ9vOJ5qKWNhq0sorxi1jMW1giukTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474122; 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=arb4Vkg/IiXovO0rnzjC19MaVYDKE+UhYIRempQ0NyI=; b=NNpzIyEVEXEz3fKLRfMPUHi67dpJUWCkVNr90JS1AvHEBQ2ucNk49GsJXRcEXHQIa6AAvgvswGFfmE34ric1G4ymJ5nn+y9OLtbFMoe2B1/dMIih/Pc39zivoduHyZ3WGwIFgW7SOf5amdKjwapSKNSDYfAcBzNHJs8hc1RjRL8= 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+importer=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 1601474122411963.5274836007553; Wed, 30 Sep 2020 06:55:22 -0700 (PDT) Received: from localhost ([::1]:43864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcZl-0003yF-4u for importer@patchew.org; Wed, 30 Sep 2020 09:55:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMd-0006MT-Az for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMa-0005e5-Rm for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:47 -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-195-vOhb1neXOmqMT-h6bUHhvA-1; Wed, 30 Sep 2020 09:41:36 -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 3AA341007285 for ; Wed, 30 Sep 2020 13:41:35 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6C3060C05; Wed, 30 Sep 2020 13:41:33 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473298; 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=arb4Vkg/IiXovO0rnzjC19MaVYDKE+UhYIRempQ0NyI=; b=fGWG6kC3QefPnHzLXta6yQzLmYE0lHdlHow3TXOh8Qv/dSD4JGE5WnZfmYWVAbgEZL+dZO srckXbW6wYmWCAvUxfXRj4ixZWy55FuOzQ1rdHTCFbwaPaU0yP4oyaq//5It/i/McgkFWy /2jI0M8lbIHsyX0danOX3oxyB1cBrsM= X-MC-Unique: vOhb1neXOmqMT-h6bUHhvA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 15/19] i386: switch hyperv_expand_features() to using error_setg() Date: Wed, 30 Sep 2020 15:40:23 +0200 Message-Id: <20200930134027.1348021-16-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Use standard error_setg() mechanism in hyperv_expand_features(). Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 101 ++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 181e034da701..32678154837f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1149,7 +1149,7 @@ static bool hyperv_feature_supported(CPUState *cs, in= t feature) return true; } =20 -static int hv_cpuid_check_and_set(CPUState *cs, int feature) +static int hv_cpuid_check_and_set(CPUState *cs, int feature, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); uint64_t deps; @@ -1163,20 +1163,18 @@ static int hv_cpuid_check_and_set(CPUState *cs, int= feature) while (deps) { dep_feat =3D ctz64(deps); if (!(hyperv_feat_enabled(cpu, dep_feat))) { - fprintf(stderr, - "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[feature].desc, - kvm_hyperv_properties[dep_feat].desc); - return 1; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[feature].desc, + kvm_hyperv_properties[dep_feat].desc); + return 1; } deps &=3D ~(1ull << dep_feat); } =20 if (!hyperv_feature_supported(cs, feature)) { if (hyperv_feat_enabled(cpu, feature)) { - fprintf(stderr, - "Hyper-V %s is not supported by kernel\n", - kvm_hyperv_properties[feature].desc); + error_setg(errp, "Hyper-V %s is not supported by kernel", + kvm_hyperv_properties[feature].desc); return 1; } else { return 0; @@ -1223,13 +1221,12 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) * of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static int hyperv_expand_features(CPUState *cs) +static void hyperv_expand_features(CPUState *cs, Error **errp) { X86CPU *cpu =3D X86_CPU(cs); - int r; =20 if (!hyperv_enabled(cpu)) - return 0; + return; =20 if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D @@ -1275,37 +1272,60 @@ static int hyperv_expand_features(CPUState *cs) } =20 /* Features */ - r =3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI); - r |=3D hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT); + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RELAXED, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VAPIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_CRASH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RESET, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_VPINDEX, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_RUNTIME, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_SYNIC, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_FREQUENCIES, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_REENLIGHTENMENT, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_TLBFLUSH, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_EVMCS, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_IPI, errp)) { + return; + } + if (hv_cpuid_check_and_set(cs, HYPERV_FEAT_STIMER_DIRECT, errp)) { + return; + } =20 /* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) && !cpu->hyperv_synic_kvm_only && !hyperv_feat_enabled(cpu, HYPERV_FEAT_VPINDEX)) { - fprintf(stderr, "Hyper-V %s requires Hyper-V %s\n", - kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, - kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); - r |=3D 1; - } - - if (r) { - return -ENOSYS; + error_setg(errp, "Hyper-V %s requires Hyper-V %s", + kvm_hyperv_properties[HYPERV_FEAT_SYNIC].desc, + kvm_hyperv_properties[HYPERV_FEAT_VPINDEX].desc); } - - return 0; } =20 /* @@ -1540,9 +1560,10 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - r =3D hyperv_expand_features(cs); - if (r < 0) { - return r; + hyperv_expand_features(cs, &local_err); + if (local_err) { + error_report_err(local_err); + return -ENOSYS; } =20 if (hyperv_enabled(cpu)) { --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474012; cv=none; d=zohomail.com; s=zohoarc; b=EUuRnuOWcGjwdiJv+XIluJ+YJA0dJWjbDSUlJ8vDdoN77xLxZH2UMLPCPdaCcra60XwGpUsoxHWNHHldfl7rDb/oeLzqsJZ2INWvEuLQfmodpzDJU67e6lcIfGRPj3MLAarGS87VfQqSAmnpXJMxw6Q99MiupzN18/Wz5CSL9Gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474012; 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=rYRvlyeh4UdprzkfJSkkxE01i+dMEIab9wKgYrofCe0=; b=NNn9gMl4dYRKClfO6jdMwRKVWUx6KAtazrts415QiVoeBt3kGkxQTLnMFdKjEqOfY8rgXWAhyEcqXz7a0MS+9bFy2uaB1CCGtLN2lPubewWQ/SdaDJMC74OGkCpyoBMIay+Rz3Xb3DdqxNn33UMc2KAuqqIkBU626CzEfIXs34w= 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+importer=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 1601474012824759.5828937947417; Wed, 30 Sep 2020 06:53:32 -0700 (PDT) Received: from localhost ([::1]:39280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcXz-00023O-J9 for importer@patchew.org; Wed, 30 Sep 2020 09:53:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMj-0006N2-UZ for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMb-0005eF-3f for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:53 -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-157-SKusdtRuOPKZnDRTQcFf8A-1; Wed, 30 Sep 2020 09:41:38 -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 166B58030D6 for ; Wed, 30 Sep 2020 13:41:37 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9950260C05; Wed, 30 Sep 2020 13:41:35 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473300; 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=rYRvlyeh4UdprzkfJSkkxE01i+dMEIab9wKgYrofCe0=; b=H1OvX5+h3U3CoUbXM/jMx6eTbkO7hKnJ2HhAJ+7EImvLoSDdXd2fR5IvgCkFCkNJr+XwW8 AxEEszElToXk2vypG/LyGE1zg6Q9BX1YI72QZzJYVONyFIZafEnLHfFzDUb0FClrrfuVWq 5NFU1goOYeeY3qTFSKAAjqHUr+Z01Pc= X-MC-Unique: SKusdtRuOPKZnDRTQcFf8A-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 16/19] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size Date: Wed, 30 Sep 2020 15:40:24 +0200 Message-Id: <20200930134027.1348021-17-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" SYNDBG leaves were recently (Linux-5.8) added to KVM but we haven't updated the expected size of KVM_GET_SUPPORTED_HV_CPUID output in KVM so we now make serveral tries before succeeding. Update the default. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 32678154837f..39a6e89dbb60 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -975,7 +975,8 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs= , int max) static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs) { struct kvm_cpuid2 *cpuid; - int max =3D 7; /* 0x40000000..0x40000005, 0x4000000A */ + /* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ + int max =3D 10; int i; =20 /* --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474251; cv=none; d=zohomail.com; s=zohoarc; b=AtCwXesvRt7fyEcqstCsRiO69tYAwLqIa95p7q/vwo2zViJLB8S9CwEJ8JHeRa1+WAw89p0pXYlE4te0uIIdf/tiOEGSV77YdBBB9ssyUyyoLsjJWMWwFxfrv3+LxJ+57k3TK/ai+onN9x3W9gyZaH9JeH03x003bOA8A2AV504= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474251; 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=Cb7AYxa52bczCra2WNWtZH3Ub0GdlJaxkEkTO/fkjMo=; b=FYm+6YgGTONVJdzxSM2NfMaBL1jcszg1IXOzSCW7FFU77a3sCk2iSpXxS4Jngw+EgHqKFNDc4alocNplmjh0b9aya9VhEuckJVPbl/AA92ROIl/YWj2XK13cZDjAv0B56adWzJ5dqKQ5+XHtW6xl/5Rb4NshJBw1pkeun4utbE8= 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+importer=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 16014742515401014.0489292914216; Wed, 30 Sep 2020 06:57:31 -0700 (PDT) Received: from localhost ([::1]:51890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcbq-0007Du-8l for importer@patchew.org; Wed, 30 Sep 2020 09:57:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMp-0006Nt-Pd for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:42:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMb-0005eJ-6D for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:59 -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-432-XvAb72UqMo-Q3DvCWxIXYA-1; Wed, 30 Sep 2020 09:41:39 -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 9542F1868416 for ; Wed, 30 Sep 2020 13:41:38 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6458460C05; Wed, 30 Sep 2020 13:41:37 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473301; 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=Cb7AYxa52bczCra2WNWtZH3Ub0GdlJaxkEkTO/fkjMo=; b=M8n25+HL6+NzZjWA/3OV8PrRQdrAIp93ttFbFCdjop9MrCFr+u6SJcJzMKt+c2u6lfBaKf m49oVEyBQ8VZb2jmfRCzpCAMDRQ9EH/Y1cDIjolKwyq4J2MoQUrr2cHNcxjTF3zbr4UO5w CViDTlmRD96gvaTmDQqFn4JFg6kzaiw= X-MC-Unique: XvAb72UqMo-Q3DvCWxIXYA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 17/19] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one Date: Wed, 30 Sep 2020 15:40:25 +0200 Message-Id: <20200930134027.1348021-18-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" KVM_GET_SUPPORTED_HV_CPUID was made a system wide ioctl which can be called prior to creating vCPUs and we are going to use that to expand Hyper-V cpu features early. Use it when it is supported by KVM. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 39a6e89dbb60..af59b5f1a935 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -942,7 +942,8 @@ static struct { }, }; =20 -static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) +static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max, + bool do_sys_ioctl) { struct kvm_cpuid2 *cpuid; int r, size; @@ -951,7 +952,11 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *c= s, int max) cpuid =3D g_malloc0(size); cpuid->nent =3D max; =20 - r =3D kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + if (do_sys_ioctl) { + r =3D kvm_ioctl(kvm_state, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + } else { + r =3D kvm_vcpu_ioctl(cs, KVM_GET_SUPPORTED_HV_CPUID, cpuid); + } if (r =3D=3D 0 && cpuid->nent >=3D max) { r =3D -E2BIG; } @@ -978,13 +983,17 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUS= tate *cs) /* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ int max =3D 10; int i; + bool do_sys_ioctl; + + do_sys_ioctl =3D + kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID) > 0; =20 /* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with * -E2BIG, however, it doesn't report back the right size. Keep increa= sing * it and re-trying until we succeed. */ - while ((cpuid =3D try_get_hv_cpuid(cs, max)) =3D=3D NULL) { + while ((cpuid =3D try_get_hv_cpuid(cs, max, do_sys_ioctl)) =3D=3D NULL= ) { max++; } =20 @@ -994,7 +1003,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSt= ate *cs) * information early, just check for the capability and set the bit * manually. */ - if (kvm_check_extension(cs->kvm_state, + if (!do_sys_ioctl && kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_ENLIGHTENED_VMCS) > 0) { for (i =3D 0; i < cpuid->nent; i++) { if (cpuid->entries[i].function =3D=3D HV_CPUID_ENLIGHTMENT_INF= O) { --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474330; cv=none; d=zohomail.com; s=zohoarc; b=HR9z4WmPoXsyBXDIdofagEpdJAlxCXmbGZlYXwvgtp4ImOMSAYH/cnJQPW3knvsyBrR8zV4hD94jabtOmnkra2b7GRg/lXcI5TMTdGDyHBR8Pl0BTQA1aceMJRG2j1SkvqTUVIMNxHqDInuLDSbj1XFPqr+eGa8pBKZ8tnEfoWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474330; 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=KZtuN9FeNN2fdIVwOkbEQKnG9nNtOI0I5MfI+MS2jXk=; b=ex9ln3Gm96urj7zz+bXdXPjFNYCDVwAbEbakPg8IpAImwyvzAExuQpV0OCN2o3q3IV/9qyJdqqV4AX14eFRWg6Gm8Vohmr0lLlH9OqphcuLXb0phEI6+KtxQZE/aKTINSBjWFcIIMzm8DH33iDGLeWRFnOrrVCpwOmke0bs4Qzc= 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+importer=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 1601474330104903.9619380793016; Wed, 30 Sep 2020 06:58:50 -0700 (PDT) Received: from localhost ([::1]:56740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNcd6-0000kt-Tb for importer@patchew.org; Wed, 30 Sep 2020 09:58:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38046) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMe-0006MZ-D7 for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMb-0005eQ-4h for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:48 -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-480-d_LN3MbeOVGfMIiMg2iELQ-1; Wed, 30 Sep 2020 09:41:41 -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 2192C1007469 for ; Wed, 30 Sep 2020 13:41:40 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id E37FB619B5; Wed, 30 Sep 2020 13:41:38 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473303; 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=KZtuN9FeNN2fdIVwOkbEQKnG9nNtOI0I5MfI+MS2jXk=; b=VO+inl8YgcUFt9FZM4ieG3GcMGz7LNFkI1/lyKr4LxsKvAdmuL6Rp4/JA7A3taDm3BRci9 /dnHTangUwcbz66eiXEoeo4KWW11XCqggklK2afw110Bsd8+D7ZVVGy7KtrVXeMv2otNcj yUPyqWrqPixhHw3zNFRJZyFZevKnQLU= X-MC-Unique: d_LN3MbeOVGfMIiMg2iELQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 18/19] i386: use global kvm_state in hyperv_enabled() check Date: Wed, 30 Sep 2020 15:40:26 +0200 Message-Id: <20200930134027.1348021-19-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:31:59 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There is no need to use vCPU-specific kvm state in hyperv_enabled() check and we need to do that when feature expansion happens early, before vCPU specific KVM state is created. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index af59b5f1a935..2c62122a1bc8 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -729,8 +729,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs) =20 static bool hyperv_enabled(X86CPU *cpu) { - CPUState *cs =3D CPU(cpu); - return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 && + return kvm_check_extension(kvm_state, KVM_CAP_HYPERV) > 0 && ((cpu->hyperv_spinlock_attempts !=3D HYPERV_SPINLOCK_NEVER_NOTIFY)= || cpu->hyperv_features || cpu->hyperv_passthrough); } --=20 2.25.4 From nobody Mon Feb 9 00:06:55 2026 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601474142; cv=none; d=zohomail.com; s=zohoarc; b=LTEKu52qqbTLytTaj0Wg6qGy7ClACBqEceMP+vecECj83ApxN6PUrW1d+jf+8R+2Ng7WcjR/FqFBqTU40gfhIzp62JtDvWN9E11dtqewhE1m8LXh7miOosIrGdxrnVeh5Vpyb75ZVy0KwJ/xIKMemBFjH5kYoWykRDyWgVedME8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601474142; 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=rF29+ivM2oJ8A8MacCH3LRLVPyDVbcedCuAmiAMdg28=; b=KTv7lHj+STXtAq0j7xZtD2vgj7c3AJG9Gab8OPeD9LAMRKyJ1F+2rOOjLS7YDLH68uULkjcq7ohr3HfHCmWtJS+9NVBRS10igLHrsPlTiKCMJp5tFpzu5FulUtIeoZbBLX9agk296dXJI5EJD66DnBYDsaQgb/zxpW3TrkHWEow= 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+importer=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 1601474142745498.6619978295987; Wed, 30 Sep 2020 06:55:42 -0700 (PDT) Received: from localhost ([::1]:45170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNca5-0004VM-Dd for importer@patchew.org; Wed, 30 Sep 2020 09:55:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kNcMm-0006NK-Sy for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kNcMb-0005eg-Ml for qemu-devel@nongnu.org; Wed, 30 Sep 2020 09:41:54 -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-581-gZVB7BVxPri7lbqe1S4wdQ-1; Wed, 30 Sep 2020 09:41:42 -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 A0FF11007467 for ; Wed, 30 Sep 2020 13:41:41 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.194.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FFD165F5E; Wed, 30 Sep 2020 13:41:40 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601473304; 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=rF29+ivM2oJ8A8MacCH3LRLVPyDVbcedCuAmiAMdg28=; b=cuBG5UGHdh04n7rUSUONBnvmgenFE6T52SfMbc7DopVUWOg/b9R0KY5Shq2a3dxupwuW9q XQmpmwZyJtzi1NxRwSH/GitW5weP0xkIZct2438cK3KXDxZRuMryxn2M/x2KrjPwnadlQZ xQ6ygjC1rhTdkRzUGQqd2Xb45/RK/+g= X-MC-Unique: gZVB7BVxPri7lbqe1S4wdQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v2 19/19] i386: expand Hyper-V features during CPU feature expansion time Date: Wed, 30 Sep 2020 15:40:27 +0200 Message-Id: <20200930134027.1348021-20-vkuznets@redhat.com> In-Reply-To: <20200930134027.1348021-1-vkuznets@redhat.com> References: <20200930134027.1348021-1-vkuznets@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=vkuznets@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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=vkuznets@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/30 00:26:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.469, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=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 , Marcelo Tosatti , Eduardo Habkost Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To make Hyper-V features appear in e.g. QMP query-cpu-model-expansion we need to expand and set the corresponding CPUID leaves early. Modify x86_cpu_get_supported_feature_word() to call newly intoduced Hyper-V specific kvm_hv_get_supported_cpuid() instead of kvm_arch_get_supported_cpuid(). We can't use kvm_arch_get_supported_cpuid() as Hyper-V specific CPUID leaves intersect with KVM's. Note, early expansion will only happen when KVM supports system wide KVM_GET_SUPPORTED_HV_CPUID ioctl (KVM_CAP_SYS_HYPERV_CPUID). Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 4 ++++ target/i386/kvm-stub.c | 5 +++++ target/i386/kvm.c | 15 ++++++++++++--- target/i386/kvm_i386.h | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index a178db255641..272091eab057 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6345,6 +6345,10 @@ static void x86_cpu_expand_features(X86CPU *cpu, Err= or **errp) if (env->cpuid_xlevel2 =3D=3D UINT32_MAX) { env->cpuid_xlevel2 =3D env->cpuid_min_xlevel2; } + + if (kvm_enabled()) { + kvm_hyperv_expand_features(cpu, errp); + } } =20 /* diff --git a/target/i386/kvm-stub.c b/target/i386/kvm-stub.c index 872ef7df4c88..4abb5afa1168 100644 --- a/target/i386/kvm-stub.c +++ b/target/i386/kvm-stub.c @@ -44,3 +44,8 @@ bool kvm_hv_vpindex_settable(void) { return false; } + +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) +{ + return; +} diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 2c62122a1bc8..ba99aecb5a64 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1230,13 +1230,22 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, u= int32_t func, int reg) * of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static void hyperv_expand_features(CPUState *cs, Error **errp) +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) { - X86CPU *cpu =3D X86_CPU(cs); + CPUState *cs =3D CPU(cpu); =20 if (!hyperv_enabled(cpu)) return; =20 + /* + * When kvm_hyperv_expand_features is called at CPU feature expansion + * time per-CPU kvm_state is not available yet so we can only proceed + * when KVM_CAP_SYS_HYPERV_CPUID is supported. + */ + if (!cs->kvm_state && + !kvm_check_extension(kvm_state, KVM_CAP_SYS_HYPERV_CPUID)) + return; + if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =3D hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); @@ -1569,7 +1578,7 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =3D KVM_APIC_BUS_FREQUENCY; =20 /* Paravirtualization CPUIDs */ - hyperv_expand_features(cs, &local_err); + kvm_hyperv_expand_features(cpu, &local_err); if (local_err) { error_report_err(local_err); return -ENOSYS; diff --git a/target/i386/kvm_i386.h b/target/i386/kvm_i386.h index 064b8798a26c..126a1bcef2dd 100644 --- a/target/i386/kvm_i386.h +++ b/target/i386/kvm_i386.h @@ -47,5 +47,6 @@ bool kvm_has_x2apic_api(void); bool kvm_has_waitpkg(void); =20 bool kvm_hv_vpindex_settable(void); +void kvm_hyperv_expand_features(X86CPU *cpu, Error **errp); =20 #endif --=20 2.25.4