From nobody Sun Nov 16 23:04:00 2025 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=1602246064; cv=none; d=zohomail.com; s=zohoarc; b=FmlbmGCmlgZqJL1XtMRRjoNNe6Ai1IsC5GJy2fJ60wtor4HoA1qjDey9/gMsa6arVeLvc5rbHsgd+bS9YKS7unHv2sgwKcXBRHiBTYB4uIAoK5r68IvjkbThhdiWZm9MuF+ruOCuwOTZ/kK3h5tFnNb0Jm6np8mVzJNbOwEmrsk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246064; 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=dwAsvsMhG4JoU+1ScP2AB56yPavPrAEvGViSXNzdUzKokne3sf4eTJRtKonR48avXo7zd7wealE1FSo0WlcOsyzRzVmzPVT1NaowBEKL9OG5dDsglR+0+jXCxXuOvV3XPtiGtQ519LWBbc7JDFjh5GCtA5C6wK+m1tdxq0uKaSU= 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 1602246064344967.8051598977213; Fri, 9 Oct 2020 05:21:04 -0700 (PDT) Received: from localhost ([::1]:42818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrOQ-0001VU-Si for importer@patchew.org; Fri, 09 Oct 2020 08:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMK-00088b-JN for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMI-0007tW-Oa for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18:52 -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-222-aCyoPDflOgqXfvmmvxrhfw-1; Fri, 09 Oct 2020 08:18:48 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 49BD0108E1AB for ; Fri, 9 Oct 2020 12:18:47 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C5625C1BB; Fri, 9 Oct 2020 12:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245930; 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=TYSqKjGNGD2JkM8vAKyuWmkrkoJmWskmon3GpzRsrTiF4/j42ZeArJixhcgUxdSFaTvzl4 KCcl/VVKeYAsQTZF1quayRL3pT41McU4fWdIy/4TyWn7F3dv2LJv2zL3ckKbeAX9yBjf1j hmDn2sfcQppgWRpLIpSYZzFc/K7L83E= X-MC-Unique: aCyoPDflOgqXfvmmvxrhfw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 01/23] WIP: update linux/headers Date: Fri, 9 Oct 2020 14:18:20 +0200 Message-Id: <20201009121842.1938010-2-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 Sun Nov 16 23:04:00 2025 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=1602246232; cv=none; d=zohomail.com; s=zohoarc; b=R1ioNXRYGdkuvTXUcCwgPSfTroLY/kVilpnjEur7xNCSHMU/9vbb1spR6JPgfACHgtlkwguCuGLDZL6kHYO0DNCwTfCSMGJof7fxGxgpKJw4i3q/8NP2B+VbK28Og1m75vEoGIXWmfSro1DtlJNxcSItl5SsByA8FcMtZJCYrAI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246232; 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=TUYMLH2ggTcrD/F/kmD011uAsOlGebjgC/tzd3ZqTiw=; b=OmZnfHFNlGSa6wAnHii4DuODx8P1bOGQOlmw7bOEe7oAzjmgxOgZcGoEtS015ibVoDrSslYGfLWs/OiOTNEGvBkBV8pyGaRyfiJQFuKPuKzbuCA3XOC+k6xDxsHMqG4EQwNxhCFbC+FkyB9wTvw+8Y5XqfVkz9PbZ02sYRbkEJQ= 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 1602246232442948.2649813846859; Fri, 9 Oct 2020 05:23:52 -0700 (PDT) Received: from localhost ([::1]:51002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrR7-00051X-2y for importer@patchew.org; Fri, 09 Oct 2020 08:23:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMM-0008Cd-Oi for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44083) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMK-0007tz-WD for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18: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-330-R9n4jdPVN_uysCvnWQjSBQ-1; Fri, 09 Oct 2020 08:18:50 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83B56AFD07 for ; Fri, 9 Oct 2020 12:18:49 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA3E05C1BB; Fri, 9 Oct 2020 12:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245932; 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=TUYMLH2ggTcrD/F/kmD011uAsOlGebjgC/tzd3ZqTiw=; b=LYKiNSb+218bJ41B9yO9fcQ9m33LlrJRoi8BAfArWwKX2PScrW/lVjMAp6EoLZbRQDel1y 11h+OQRaV0PQ/GrHhVCjtGLqEq85lSRrtr48Amit0D1FfiQO4yOsiOS0YYqvfbFs4lYdxi CAzup8She46vqFmxQ9K3csIfvrmTW6A= X-MC-Unique: R9n4jdPVN_uysCvnWQjSBQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 02/23] i386: fill in FEAT_HYPERV_EDX from edx instead of eax Date: Fri, 9 Oct 2020 14:18:21 +0200 Message-Id: <20201009121842.1938010-3-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 8b12387d30af..0098be701511 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1214,7 +1214,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 Sun Nov 16 23:04:00 2025 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=1602246067; cv=none; d=zohomail.com; s=zohoarc; b=nFTBFKiEYLf50OPqwfApCUa5ULgodDe15UHo6SMNQ7RE1bHu/L4nvK4TeXiqJULvEyR3guQahpyJJ8B+EoP6I19omUqYoQTfSHlAITkTXWJ6LSsYHG/wIdqdEYuBy0NYLwvV6g9y7ad8AeSEDbVNYOk3nKIab7HeBp5NUVTQdyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246067; 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=89B3NDlOf/g93zNQ8nugWZbkCavwpKNJ5AKv0Sc7XW0=; b=Xo3wOIsKWZTK0uLEqMSaEsUwvmPXXsw9T6G1/ZN/5ZNoSj+lE50EP56JuO+QAqTbv9XNDTxtRrGffTXJ0O7yV65FZEW7pmEyoX+t18B9hdcMQvMc9EhzD/Sp6A+8ieXb9y5SAIkACjY30pWdEb/9f2HCN2eWoUONAuY/l5UmBP8= 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 1602246067166598.6213754617318; Fri, 9 Oct 2020 05:21:07 -0700 (PDT) Received: from localhost ([::1]:43084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrOT-0001cc-JW for importer@patchew.org; Fri, 09 Oct 2020 08:21:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMO-0008H3-Ve for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58161) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMN-0007uI-DX for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:18:56 -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-51-aD65eikKOSGSJNi1NjGdHA-1; Fri, 09 Oct 2020 08:18:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BEB99108E1A1 for ; Fri, 9 Oct 2020 12:18:51 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id E250F5C1BB; Fri, 9 Oct 2020 12:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245934; 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=89B3NDlOf/g93zNQ8nugWZbkCavwpKNJ5AKv0Sc7XW0=; b=VxOQ4UK5dD8D/g1szzngV7W0HzTf3WjgwE9/Xm9jlnk4f6hRWwgPquxRkhJwdMAzF9W3zZ 5t2OlIyTtpp7rHm4ypM5FUjFhVrtbEKHtUwFOp87m2FyQJkHVPCN9WHxENDx9Lifhim6gM QAqh+e5Q9yzCQozkwv4nnmew/KWRGIA= X-MC-Unique: aD65eikKOSGSJNi1NjGdHA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 03/23] i386: drop x86_cpu_get_supported_feature_word() forward declaration Date: Fri, 9 Oct 2020 14:18:22 +0200 Message-Id: <20201009121842.1938010-4-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 f37eb7b675f4..bbfdfb8a3f88 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 Sun Nov 16 23:04:00 2025 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=1602246270; cv=none; d=zohomail.com; s=zohoarc; b=Oj+NPi6+gRTC78UAWjwuUWYgLFgfS5tzSqR1lTZxANj97dPCzlI18JXUQQND44HFUOcGBLjuHcYSCePOcOdGBOIw3rV76ir5L0e5qt/kgZeVDK7KpdulZ2aRPlH29cB8AUpE2bQL8GNWn6sQmXs0jZfrrzjOEptPdsw3jTMQVHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246270; 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=pSM/rOeYu7Cp3+SfWmmaUaIqAxpZuN/FkBdYNwSMXKE=; b=EoCxIqEfMBdWZKfdBSkCXKKk6uTWFRYoQ06J4oDFgEyWnSCAO/JY1xOvPHB0GHFcyjTNIlJPOaVoVIYLgXqmZ11laYPkRbeZpTD0Vk/+hlkb/x/XIGczx51aeuzP387/xPJLRMi8NZiOxTjoJWrWaMKBuHI7Kldk7oQTFzmEwtU= 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 1602246270244798.4845702855421; Fri, 9 Oct 2020 05:24:30 -0700 (PDT) Received: from localhost ([::1]:51328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrRg-0005Al-RV for importer@patchew.org; Fri, 09 Oct 2020 08:24:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38370) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMT-0008JU-RV for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45344) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMP-0007uR-6C for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:01 -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-421-1TUhStcXOgu977pvdDwACw-1; Fri, 09 Oct 2020 08:18:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA1801029D20 for ; Fri, 9 Oct 2020 12:18:53 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F32A5C1C7; Fri, 9 Oct 2020 12:18:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245936; 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=pSM/rOeYu7Cp3+SfWmmaUaIqAxpZuN/FkBdYNwSMXKE=; b=R0tY97fJ40YDIl29bRoaoBt/ZRm1Nfakn1zSDt6q9WsUXCMvjW/o3TSCQRZPyZHrzaHnOL JjoBGzKx4214GC70b8o40zQ7NKuew2HNTZDPWNS5uZLIGxzoj4oKzgjIccfk23cvh/YBSb FzcWJDlMdE9dX2/Op2W5y8tCtYpPOfE= X-MC-Unique: 1TUhStcXOgu977pvdDwACw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 04/23] i386: move hyperv_vendor_id initialization to x86_cpu_realizefn() Date: Fri, 9 Oct 2020 14:18:23 +0200 Message-Id: <20201009121842.1938010-5-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 bbfdfb8a3f88..ce485dd9afd9 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6491,6 +6491,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); @@ -6541,6 +6559,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; @@ -7212,7 +7233,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 51c1d5f60a74..2e7ee40372de 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1655,11 +1655,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 0098be701511..75d4cb17a5ba 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1210,6 +1210,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; @@ -1284,23 +1291,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 Sun Nov 16 23:04:00 2025 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=1602246224; cv=none; d=zohomail.com; s=zohoarc; b=AyL7FEMHhi9MOIwgBinxK3ljD90+w/g0H8gosEDj3gVIilt1qFs4EaXiCV3EOZJqVuCpxbSMgGvLOb9DwOm/lAozvAQwUryC2Ai/6XuJ1F4PJtchuTQx07fLKdBKK+TUL3zp9TouMF3Lok9Xo8eeINPsJJceysviBCk+gTFNJ9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246224; 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=0tT6pTTej2yatf8fMzxJfzoh3zO+2aZRpKmOqKc2NEI=; b=kyJ5BLXwZBz7fq1OFhvYwfQSqdwc8oH/BICQA61LQltK37IUigQWYtUwjrPGZ4qn6F9DzAnFsMEBWq37Z6gd1zu2TGZRsLq1HKTsrFVUL1pkAEs79MvqVMqLECaqA9FeoamP2k2hoxarctwkcIv9RW/SYcuW9H/KBJz3j3LowOE= 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 1602246224386537.0194929143704; Fri, 9 Oct 2020 05:23:44 -0700 (PDT) Received: from localhost ([::1]:50970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrR0-00050a-WE for importer@patchew.org; Fri, 09 Oct 2020 08:23:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMV-0008Jf-SF for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:05 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48818) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMR-0007vm-KO for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:03 -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-YTlNrsZcPoyRQjVv2YomWA-1; Fri, 09 Oct 2020 08:18:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFFA7196C900 for ; Fri, 9 Oct 2020 12:18:55 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 524365C1BB; Fri, 9 Oct 2020 12:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245938; 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=0tT6pTTej2yatf8fMzxJfzoh3zO+2aZRpKmOqKc2NEI=; b=E1Y2Bizxfz5yGhWK6U06tCg6Jdm62PLnEXYV59A+5Pk8haW3w24ZNhzyqwwi8edTie5l/q Vnwl1K6QeQD1ST+XOVfwbeybKzmaHrZMQx1oZRMYqbF146QG+80nAdcibqARLEQLoWkMyT 1RftfB/9pSr5OXw78jwmHWNVJWwEz3w= X-MC-Unique: YTlNrsZcPoyRQjVv2YomWA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 05/23] i386: move hyperv_interface_id initialization to x86_cpu_realizefn() Date: Fri, 9 Oct 2020 14:18:24 +0200 Message-Id: <20201009121842.1938010-6-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 ce485dd9afd9..52e050a7785c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6507,6 +6507,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 2e7ee40372de..d49e34a80a34 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1661,6 +1661,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 75d4cb17a5ba..eec0a7e31315 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1173,7 +1173,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 @@ -1217,6 +1216,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; @@ -1299,11 +1306,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 Sun Nov 16 23:04:00 2025 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=1602246521; cv=none; d=zohomail.com; s=zohoarc; b=H6HZos/77iTwNI5u1F/GJazg5veFnXryvpq8OaLLHrono717tVR5sAVS7410oTFiRs/jXiEchSl02rNllYD/kLxeffwnMqHHwmOIiPIPwdjYngeFJsOP9XtXBl2H/BhVO6jpTAG9fhSnXFrIBC5U2GEbhxv/wLU2RCGLTkIIPv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246521; 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=jIWwRjJFUT/NqBREKg7yfmtN/GKOBor8yF9qjrT88xU=; b=AA6sAKLxzfptESmwh9L05b3OUcj+uX1kY34iQobmgnOVloE3Gnr4cSuSbqJBaJSsSqPEQszCTGBJb5vt++44QUOylbsvmLO7iqGcmONorHT/Tw9CN6zRFWLt2cD9Elk1KCXMQxoUuR2+BlIYr8s84P76qqWt1WoWM51Efu1p5lU= 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 1602246521200700.3967220478243; Fri, 9 Oct 2020 05:28:41 -0700 (PDT) Received: from localhost ([::1]:59814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrVn-0000Ka-Rx for importer@patchew.org; Fri, 09 Oct 2020 08:28:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMX-0008Ju-OC for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41728) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMT-0007w0-IG for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:05 -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-wJTgVq1JO5aS1qeMEVY65g-1; Fri, 09 Oct 2020 08:18:59 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2B7F21029D20 for ; Fri, 9 Oct 2020 12:18:58 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58E105C1BB; Fri, 9 Oct 2020 12:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245940; 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=jIWwRjJFUT/NqBREKg7yfmtN/GKOBor8yF9qjrT88xU=; b=Yi4NdtTtF7zkbbsj3RPrFK2wBl2qh8JdB47QDCM6cNmDHpbA+rdKG6eb06Ct8V2rFdmkmq rhcEHeSe9iWfOUL1n2yqqCPCOoManktiknDEvboqQVPpPmQNwDkQQkEEE0vzZvxSruduqb F9t3zRUDUBU4XIs9eoA3mVaq7JC2kiw= X-MC-Unique: wJTgVq1JO5aS1qeMEVY65g-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 06/23] i386: move hyperv_version_id initialization to x86_cpu_realizefn() Date: Fri, 9 Oct 2020 14:18:25 +0200 Message-Id: <20201009121842.1938010-7-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 52e050a7785c..a8992b0c1c75 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6513,6 +6513,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 d49e34a80a34..da1fdfd7a9fd 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1662,6 +1662,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 eec0a7e31315..cce07f412d2f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1224,6 +1224,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; @@ -1313,8 +1321,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 Sun Nov 16 23:04:00 2025 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=1602246512; cv=none; d=zohomail.com; s=zohoarc; b=dDl4w6Cb9nY3IDjN7tiLNEMIpggytEsrwCIferXvDdjPwfj4DKYnCrFPizdefu9zTqlsZNuB6SXVbed6ndqDfZ9YLib05EcbP+ikvRsS+qmuibzKQOPxPZa28EYPXukuRxDvw/bxoIdl2Gag0GgdFc4Q/mvwsUTB3TeAKx9ERQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246512; 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=sSFopokYikvCH7iKBWMAWgY/bdhTJdC0gSqi/NFL5wA=; b=F499/y3sRi+glgSjBjRSjy82lVLBOz5jVAS+7vgf3DKCK2v3eZLaW60xN6o47yIphOwgarZZ3JXjPP7cWvGgtAugpH2ZodfSFGtQT8YSMwxDgiQAA6P3kw8TZtkd0CY52HUVzbd6QpXGU29EKZ4KiD14z34PILIMboKaTYCMjhM= 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 1602246512804892.1979278041023; Fri, 9 Oct 2020 05:28:32 -0700 (PDT) Received: from localhost ([::1]:59406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrVf-00009Y-Es for importer@patchew.org; Fri, 09 Oct 2020 08:28:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMf-0008KN-3s for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53304) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMX-0007wG-EJ for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:12 -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-566-UOWsyBTENUqztXkJAsPV2Q-1; Fri, 09 Oct 2020 08:19:01 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5CD6F196C90F for ; Fri, 9 Oct 2020 12:19:00 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3AFD5C1BB; Fri, 9 Oct 2020 12:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245943; 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=sSFopokYikvCH7iKBWMAWgY/bdhTJdC0gSqi/NFL5wA=; b=TLNeXTCjJNDkv8jT+xMBcBs9FCDMaZXxMHiki+BHWIwoDSl3VbdAh++PxrQqyvyB58Sdx6 hHC7IQBblhQG1bfVGwMHYep2pVprWq5vyiP05nmU7eQ6Mmyq6Aae/2cmTpefbG1Tz0ywJZ CesrMts0XrknIs8yHRuYoF75ELhByqY= X-MC-Unique: UOWsyBTENUqztXkJAsPV2Q-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 07/23] i386: move hyperv_limits initialization to x86_cpu_realizefn() Date: Fri, 9 Oct 2020 14:18:26 +0200 Message-Id: <20201009121842.1938010-8-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 a8992b0c1c75..45644f063947 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6517,6 +6517,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 da1fdfd7a9fd..4a4f88f24d78 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1663,6 +1663,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 cce07f412d2f..d2fee220d653 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1238,6 +1238,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; @@ -1340,7 +1349,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 Sun Nov 16 23:04:00 2025 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=1602246686; cv=none; d=zohomail.com; s=zohoarc; b=JsWxQwP9tqiuxExI0k64fWZAqPLip4OpIDcWqVjvvOY+xVgE8wU8E9KEk2LYEcp8xSA1bzTeGbIjef9jvXigH5rzGKUC/lR197cBfln/klYO/jyD/F0fE2/zOOuXrUEagEsLuGOrAQX8ZdzPQRypHZ2rV7qKCtCl/asQoVIzlhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246686; 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=KX8WF/p7qQT0rQD3w6aNDaZLClnEUMrJKD9j0lEu768=; b=XdAmtqJftPP3oa6h6dYsO8B7cyNz6QrUQZwWV3Jf0FJGspakyGt6nes9WEJ9DP81p4rmz5Lf0TY53RW4rIkN7O3koYH4CxvUM51tA8YEmQQwAa4u4nwog27COIC9psyDZ8T/UYkP1jLroVlDDNiNoDTYWyVf8CE550DkQ8sv178= 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 1602246686170886.8301282070253; Fri, 9 Oct 2020 05:31:26 -0700 (PDT) Received: from localhost ([::1]:39588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrYS-0003cq-Qp for importer@patchew.org; Fri, 09 Oct 2020 08:31:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMe-0008KM-Tl for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23531) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMX-0007wS-Fw for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:08 -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-585-FlhajIUgPiqBGJxzu_cDVg-1; Fri, 09 Oct 2020 08:19:03 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 685CC108E1A3 for ; Fri, 9 Oct 2020 12:19:02 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABD9D5C1BB; Fri, 9 Oct 2020 12:19:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245944; 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=KX8WF/p7qQT0rQD3w6aNDaZLClnEUMrJKD9j0lEu768=; b=BK8xLWAtpRf/OEk7gkQCQgFoFh4MiGjCdFCuZSm+xU3Ju3JqtwFqclM3jxKzXuK5n30mUe ZNjl1hQJMcDyjWYMSXsjrj/G8tVaOBR467ojk77wOUVtPqw9qIK+s27sSjeavCO9/OUSA9 kWBRyjbM8uDxGLPihjUntJ97eRPeM20= X-MC-Unique: FlhajIUgPiqBGJxzu_cDVg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 08/23] i386: keep hyperv_vendor string up-to-date Date: Fri, 9 Oct 2020 14:18:27 +0200 Message-Id: <20201009121842.1938010-9-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 45644f063947..c12d53938970 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6495,18 +6495,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 d2fee220d653..67e650d1e810 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1214,6 +1214,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 Sun Nov 16 23:04:00 2025 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=1602246931; cv=none; d=zohomail.com; s=zohoarc; b=WRPe/dWBRhV5wep5BXFXN6mIAvcOVmvJLzQcajazIxNYgDLzSEqezCzX4ExcCMc2NcY2LTQCWz8J9qmzBTaicf8kO7gpTJ9Cjj7enyBw3vWmmOt7GAa/p/pjSnHXD4JfjLLy80PIlX8C6qt7fcKo39qUGVQONgV+IWFWS7MSSt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246931; 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=T04itX31MVoGGAzfcbIzJMkkgUVsVfumPou/7abL0vw=; b=HNO7eFbYZrr9f39J1k/9EpTkS2C9osVAnULBmpkMWc3cabENd0FiS5p3loYCgRDBwIWhdOqEwXxuJqjRbq/WiNxi0v4RERC+QC7302F1Gb3V+TvsO6IA+Mrx2cQkNrtE4Y92wFVA/U/jvKy0Bla99b5J9qfLdGKXoU8Ehayj/gs= 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 1602246931864182.88259540786748; Fri, 9 Oct 2020 05:35:31 -0700 (PDT) Received: from localhost ([::1]:48072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrcQ-00079B-I1 for importer@patchew.org; Fri, 09 Oct 2020 08:35:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMl-0008La-Cl for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMc-0007wk-0l for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:15 -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-71-gJtZ_KPXNDW0gL9-MAszUQ-1; Fri, 09 Oct 2020 08:19:05 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6B159196C909 for ; Fri, 9 Oct 2020 12:19:04 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id C73475C1BB; Fri, 9 Oct 2020 12:19:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245947; 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=T04itX31MVoGGAzfcbIzJMkkgUVsVfumPou/7abL0vw=; b=Zm25MfY8112+LzZYJ/F6WGnKWICVJ0ZaSLCCOw/6fSiE/f5cclvdm68aNxIw6DxEuVbABh yS3WEJghj1LVfqEKm/gSOkF5/A40OkxAfcgxo3yRbShLIzHTJmmKNbUwt+BgKr5bAUjiyu E8PrxtVV85zaSiN7IoXP0c6dXp/bPwM= X-MC-Unique: gJtZ_KPXNDW0gL9-MAszUQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 09/23] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough Date: Fri, 9 Oct 2020 14:18:28 +0200 Message-Id: <20201009121842.1938010-10-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 67e650d1e810..5350cd867759 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1254,11 +1254,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 Sun Nov 16 23:04:00 2025 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=1602246513; cv=none; d=zohomail.com; s=zohoarc; b=Tklku21kPW9/AEG7T1HYn6oFhcXFi5nnN1Saik85lRf74fM5BE8/VjUl3CVIZaoLRKyfOIKRcpNnXtHTDECwaT4RJceBSOxKtIpopFJr+EYr0lFLDBu918CnN2zn+HghmynLDGHZweS+z3O/Xll8zNl9VDXP1LMcEUMYTGqEbr4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246513; 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=0enY7T6ZHGh0XkE8zNI+IsOTO+STNh/rJg1glKZ9qm4=; b=C/oTLM7rZXuryNrfCDTr0EeuRZEqSByHLV5J/zCG5uJTuFnURN5y0ArsGYEgNAcgiQzgDdG878hRtrJW22HSgasweNCTnGLz2vs0lPiOI7jB5FFL7E5pMv6RGMHIBTUW73QBz3YX7tVOteT0Le3R3YS2nJ3gi4AtV6K4cQ1XFBY= 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 1602246513711407.3585507068335; Fri, 9 Oct 2020 05:28:33 -0700 (PDT) Received: from localhost ([::1]:59472 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrVg-0000BM-F0 for importer@patchew.org; Fri, 09 Oct 2020 08:28:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMl-0008Lb-Gp for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMe-0007wz-UB for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:19 -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-266-GKmzzcwAPriK8HRUoU8S5g-1; Fri, 09 Oct 2020 08:19:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 77EFC8C2C57 for ; Fri, 9 Oct 2020 12:19:06 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id D32EF5C1BB; Fri, 9 Oct 2020 12:19:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245949; 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=0enY7T6ZHGh0XkE8zNI+IsOTO+STNh/rJg1glKZ9qm4=; b=MQJWmolL0rBcB39FLfaLOlkFB1YKvxkR+3+2wExHVWCkyO7ymdRd0XvX9CehAYVeFltKS9 wVaP/m20Q7lk5zM5MTNFwpVPPn1xZjGmb4rABTu49R2+cj0sHWGvktiFd8xICdib8FeDzO Dn3rZxwGCjFX9fwynf4xTCwEo8iB0GY= X-MC-Unique: GKmzzcwAPriK8HRUoU8S5g-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 10/23] i386: always fill Hyper-V CPUID feature leaves from X86CPU data Date: Fri, 9 Oct 2020 14:18:29 +0200 Message-Id: <20201009121842.1938010-11-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 5350cd867759..56bfc8da85d0 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1206,9 +1206,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; @@ -1307,12 +1304,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 Sun Nov 16 23:04:00 2025 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=1602246810; cv=none; d=zohomail.com; s=zohoarc; b=XkkN5i/Brn4xaeXFadaEAn/MD79LyivQSrxKQfXuMRXyNMxjzN9cJF4kB8uu52NmLQYkh8HhIdErrfEzNOjFnDk05BtH7Bk8ENYqIr+gJfm3UGp+MLA5tmDMAe3bG1kKnCudYSaTrSQBvmEo0Ft0T3xgHMAKJxcrQKHR3LzBjX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246810; 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=T+0fz2uGSQ7OjlZNo5B48kZSDXEhLyUAOhbl5mRPg7w=; b=aYClb4evQ3e9zSxG5pydXHYljBAZ578k3XJf4dDuLAQ0KxNtxfguJDPru4RUW8uGVBvS1YKSrFjufTpbTYGlIc9bsuXkIt8cbzfzJ9Gwc66HsWz0PPuB+E0PUBygAMPlOba0UqlIhgbxLMxu1K5ClpSCV8aiVVFcjnLaEgWoCUA= 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 1602246810597406.85618033819526; Fri, 9 Oct 2020 05:33:30 -0700 (PDT) Received: from localhost ([::1]:43232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQraT-0005BB-8H for importer@patchew.org; Fri, 09 Oct 2020 08:33:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMs-00009N-Up for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55533) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMn-0007x8-2L for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:26 -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-419-KQO4nCVyN3uGtz1RWuRk3Q-1; Fri, 09 Oct 2020 08:19:09 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF982AFD08 for ; Fri, 9 Oct 2020 12:19:08 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id DEC3B5C1BB; Fri, 9 Oct 2020 12:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245951; 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=T+0fz2uGSQ7OjlZNo5B48kZSDXEhLyUAOhbl5mRPg7w=; b=eelj5Gbmft2f76do4N2NcCtMjXDS7hgzXq4MmV3/AB2LNZ1iXWFSS+jun9odjkZAyvW46+ OSEXfYfmN40ejmgo80joOHYddr1UVJpkSNzFPtPsYidPJnUj4d03lJmp5BfR0v4NYPR8MY AqeC/Q/twgdwnuKaUYZjp6P2lzRcfm8= X-MC-Unique: KQO4nCVyN3uGtz1RWuRk3Q-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 11/23] i386: stop using env->features[] for filling Hyper-V CPUIDs Date: Fri, 9 Oct 2020 14:18:30 +0200 Message-Id: <20201009121842.1938010-12-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 preparatory patch to dropping Hyper-V CPUID leaves from feature_word_info[] stop using env->features[] as a temporary storage of Hyper-V CPUIDs, just build Hyper-V CPUID leaves directly from kvm_hyperv_properties[] data. Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.h | 1 + target/i386/kvm.c | 80 +++++++++++++++++++++++++---------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 4a4f88f24d78..67985e7c0951 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1664,6 +1664,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 56bfc8da85d0..2c14d45b40bf 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1110,7 +1110,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, int feature) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; uint32_t r, fw, bits; uint64_t deps; int i, dep_feat; @@ -1150,8 +1149,6 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, return 0; } } - - env->features[fw] |=3D bits; } =20 if (cpu->hyperv_passthrough) { @@ -1161,6 +1158,29 @@ static int hv_cpuid_check_and_set(CPUState *cs, stru= ct kvm_cpuid2 *cpuid, return 0; } =20 +static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t fw) +{ + X86CPU *cpu =3D X86_CPU(cs); + uint32_t r =3D 0; + int i, j; + + for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties); i++) { + if (!hyperv_feat_enabled(cpu, i)) { + continue; + } + + for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { + if (kvm_hyperv_properties[i].flags[j].fw !=3D fw) { + continue; + } + + r |=3D kvm_hyperv_properties[i].flags[j].bits; + } + } + + return r; +} + /* * Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_e= nt in * case of success, errno < 0 in case of failure and 0 when no Hyper-V @@ -1170,9 +1190,8 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); - CPUX86State *env =3D &cpu->env; struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *c; + struct kvm_cpuid_entry2 *c, *c2; uint32_t cpuid_i =3D 0; int r; =20 @@ -1193,9 +1212,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 @@ -1233,13 +1250,6 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_version_id[3] =3D c->edx; } =20 - c =3D cpuid_find_entry(cpuid, HV_CPUID_FEATURES, 0); - if (c) { - env->features[FEAT_HYPERV_EAX] =3D c->eax; - env->features[FEAT_HYPERV_EBX] =3D c->ebx; - env->features[FEAT_HYPERV_EDX] =3D c->edx; - } - c =3D cpuid_find_entry(cpuid, HV_CPUID_IMPLEMENT_LIMITS, 0); if (c) { cpu->hv_max_vps =3D c->eax; @@ -1250,23 +1260,8 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); if (c) { - env->features[FEAT_HV_RECOMM_EAX] =3D c->eax; cpu->hyperv_spinlock_attempts =3D c->ebx; } - c =3D cpuid_find_entry(cpuid, HV_CPUID_NESTED_FEATURES, 0); - if (c) { - env->features[FEAT_HV_NESTED_EAX] =3D c->eax; - } - } - - if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { - env->features[FEAT_HV_RECOMM_EAX] |=3D HV_NO_NONARCH_CORESHARING; - } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c) { - env->features[FEAT_HV_RECOMM_EAX] |=3D - c->eax & HV_NO_NONARCH_CORESHARING; - } } =20 /* Features */ @@ -1296,9 +1291,6 @@ static int hyperv_handle_properties(CPUState *cs, r |=3D 1; } =20 - /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ - env->features[FEAT_HYPERV_EDX] |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILA= BLE; - if (r) { r =3D -ENOSYS; goto free; @@ -1328,15 +1320,27 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; - c->eax =3D env->features[FEAT_HYPERV_EAX]; - c->ebx =3D env->features[FEAT_HYPERV_EBX]; - c->edx =3D env->features[FEAT_HYPERV_EDX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EAX); + c->ebx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EBX); + c->edx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EDX); + + /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ + c->edx |=3D HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE; =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_ENLIGHTMENT_INFO; - c->eax =3D env->features[FEAT_HV_RECOMM_EAX]; + c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HV_RECOMM_EAX); c->ebx =3D cpu->hyperv_spinlock_attempts; =20 + if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { + c->eax |=3D HV_NO_NONARCH_CORESHARING; + } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { + c2 =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); + if (c2) { + c->eax |=3D c2->eax & HV_NO_NONARCH_CORESHARING; + } + } + c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_IMPLEMENT_LIMITS; c->eax =3D cpu->hv_max_vps; @@ -1356,7 +1360,7 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_NESTED_FEATURES; - c->eax =3D env->features[FEAT_HV_NESTED_EAX]; + c->eax =3D cpu->hyperv_nested[0]; } r =3D cpuid_i; =20 --=20 2.25.4 From nobody Sun Nov 16 23:04:00 2025 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=1602246686; cv=none; d=zohomail.com; s=zohoarc; b=U7AgTlxvIGT55i6Z7OuSVmv9TKENHZmgLuRmAQTyqpk/iNOtww3ER7tdycDxo/w38fbBp7uJeweFPbkclMxRKp/pyG66dpJELmhXasIDh72BuQNcrlBIkC0XaUSwji5L0oDd2UIMSFRFYjAkgBzY3jsn8EQnSLxJSqiQCVNk/g8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246686; 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=pwKgAq/hxf+mLEUYqoBAonkOswOPT3+KglEcPT79SCI=; b=kFtpN2jnqzK3A00FlNCW7IaVS1Nkp3V0JDCAPoY5JxT24M492GXwrzWk5U37YcT7vQ4ndU5mxhRO7PYL7vW7xH7YFG/hVFEnRPxFa7AKSNsM95HNJn1A7mXlbOlErzFYYT5LsZOJ/oXSNCrTGN75J6AAcGjRzam4RzwCKnKRm8A= 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 1602246686315699.0542004118297; Fri, 9 Oct 2020 05:31:26 -0700 (PDT) Received: from localhost ([::1]:39660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrYT-0003ej-1Z for importer@patchew.org; Fri, 09 Oct 2020 08:31:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMq-0008Uu-HR for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58399) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMn-0007xX-4z for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:24 -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-428-l8eokaYzPTWyBeTnxIXfUA-1; Fri, 09 Oct 2020 08:19:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF8681029D46 for ; Fri, 9 Oct 2020 12:19:10 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 284B65C1BB; Fri, 9 Oct 2020 12:19:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245953; 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=pwKgAq/hxf+mLEUYqoBAonkOswOPT3+KglEcPT79SCI=; b=ctvhZ1bSEBSobHeKJW6/mHX5AoehEjfWTJmHPnXyYnuBE1PQHpSUQ3mSo41oD2KfnMYKWh I1eSyOeZkP58kUP4iPiifhRzuRJTXcnUn2iCaINOPJ4rFMQ7hLzcxxSpwyzrHRXvusgQJx df4Z5ETUXQjRvxJc+yBKfHAv/DxzSIE= X-MC-Unique: l8eokaYzPTWyBeTnxIXfUA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 12/23] i386: introduce hyperv_feature_supported() Date: Fri, 9 Oct 2020 14:18:31 +0200 Message-Id: <20201009121842.1938010-13-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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" Clean up hv_cpuid_check_and_set() by separating hyperv_feature_supported() off it. No functional change intended. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 49 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 2c14d45b40bf..73f0d3cd0c37 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1106,13 +1106,33 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid= , int fw, uint32_t *r) return 0; } =20 +static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) +{ + uint32_t r, fw, bits; + int i; + + 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; + } + + if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + return false; + } + } + + return true; +} + static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, int feature) { X86CPU *cpu =3D X86_CPU(cs); - 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; @@ -1131,23 +1151,14 @@ static int hv_cpuid_check_and_set(CPUState *cs, str= uct kvm_cpuid2 *cpuid, 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; - } - - if (hv_cpuid_get_fw(cpuid, fw, &r) || (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(cpuid, 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; } } =20 --=20 2.25.4 From nobody Sun Nov 16 23:04:00 2025 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=1602246689; cv=none; d=zohomail.com; s=zohoarc; b=Z5TOZ3yZKU1Gmv/usmcWtNDSQT0n4Ya2MSfMzdfggbGzDhgQVN1+azsjJrH+b2nP5wPSz2F6bxb163YpQHZ1TSrD0sO5jLTrMu/1nPmmRJpZLtVwhUXnCG5/VpYv73etziNGFiFBw1Qoq58sLKSKg9pbnxiZot6PK9p49799O0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246689; 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=l+L48HxNUF/CF2ENqTmbBr9TXViabH+p1EZikdcCXpI=; b=WE0xEetUVwtZ/cSmQb0kzPnmjneclHUsYJG1Vmc1w0Z77kR2M//I8irsVd4NzUqRsWXuTrZj7RetyrPQ+JAD6sT5Yxpt+DOHKOXbgNnWX5zaIer/gJwQV2/XUhMNpBby87gxZ+9kguRFa7kYbR8i5q4lIb/0EzmgSaf79NFmeHI= 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 1602246689536753.1762214274439; Fri, 9 Oct 2020 05:31:29 -0700 (PDT) Received: from localhost ([::1]:39818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrYW-0003ij-25 for importer@patchew.org; Fri, 09 Oct 2020 08:31:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMo-0008Qi-U1 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMn-0007xj-26 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:22 -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-159-ZgBrw1f2ORqv1ymm_E-QxA-1; Fri, 09 Oct 2020 08:19:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE41FAFD02 for ; Fri, 9 Oct 2020 12:19:12 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33CD45C1BB; Fri, 9 Oct 2020 12:19:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245956; 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=l+L48HxNUF/CF2ENqTmbBr9TXViabH+p1EZikdcCXpI=; b=BebPKZio8eEqBWZXdcsvtqbtn4idGfVI9jjdcVdQdl/cxIioHZEIIFuyuuiYQeb0ohvh1d fmwXFNUjnfL0R0fMg7ox8GY3UlWJdV88sRvZBz4oUtEtaHyCx0IvdNvOH/to49iXFUTJkc GQ7tQc2LVL7znW29aApbWNCroifDyYE= X-MC-Unique: ZgBrw1f2ORqv1ymm_E-QxA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 13/23] i386: introduce hv_cpuid_get_host() Date: Fri, 9 Oct 2020 14:18:32 +0200 Message-Id: <20201009121842.1938010-14-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 implementing hv_cpuid_cache intro introduce hv_cpuid_get_host(). No functional change intended. Signed-off-by: Vitaly Kuznetsov --- target/i386/kvm.c | 100 ++++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 73f0d3cd0c37..24636ce4bc69 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1106,6 +1106,19 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid,= int fw, uint32_t *r) return 0; } =20 +static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, + int reg) +{ + struct kvm_cpuid_entry2 *entry; + + entry =3D cpuid_find_entry(cpuid, func, 0); + if (!entry) { + return 0; + } + + return cpuid_entry_get_reg(entry, reg); +} + static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) { uint32_t r, fw, bits; @@ -1202,7 +1215,7 @@ static int hyperv_handle_properties(CPUState *cs, { X86CPU *cpu =3D X86_CPU(cs); struct kvm_cpuid2 *cpuid; - struct kvm_cpuid_entry2 *c, *c2; + struct kvm_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; =20 @@ -1234,45 +1247,46 @@ static int hyperv_handle_properties(CPUState *cs, } =20 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_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) { - cpu->hyperv_spinlock_attempts =3D c->ebx; - } + cpu->hyperv_vendor_id[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EBX); + cpu->hyperv_vendor_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= ECX); + cpu->hyperv_vendor_id[2] =3D + hv_cpuid_get_host(cpuid, 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(cpuid, HV_CPUID_INTERFACE, R_EAX); + cpu->hyperv_interface_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EBX); + cpu->hyperv_interface_id[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_ECX); + cpu->hyperv_interface_id[3] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EDX); + + cpu->hyperv_version_id[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EAX); + cpu->hyperv_version_id[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EBX); + cpu->hyperv_version_id[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_ECX); + cpu->hyperv_version_id[3] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EDX); + + cpu->hv_max_vps =3D hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LI= MITS, + R_EAX); + cpu->hyperv_limits[0] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); + cpu->hyperv_limits[1] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); + cpu->hyperv_limits[2] =3D + hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); + + cpu->hyperv_spinlock_attempts =3D + hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); } =20 /* Features */ @@ -1346,10 +1360,8 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_ON) { c->eax |=3D HV_NO_NONARCH_CORESHARING; } else if (cpu->hyperv_no_nonarch_cs =3D=3D ON_OFF_AUTO_AUTO) { - c2 =3D cpuid_find_entry(cpuid, HV_CPUID_ENLIGHTMENT_INFO, 0); - if (c2) { - c->eax |=3D c2->eax & HV_NO_NONARCH_CORESHARING; - } + c->eax |=3D hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_= EAX) & + HV_NO_NONARCH_CORESHARING; } =20 c =3D &cpuid_ent[cpuid_i++]; --=20 2.25.4 From nobody Sun Nov 16 23:04:00 2025 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=1602247048; cv=none; d=zohomail.com; s=zohoarc; b=a2OSfxOlv4RA7xjWz/UfGGidfxYV26cmilEfLGSaLx4CjTX+WERtcLL32bx6+lhV4UFjVxh3hpVs3GkT4XNNo1tAcbHmDCXUgLEAh3+HKU/lOSu7H9syONZIkifq7S/hZfPkIAVN402jd4bY7qypAf/eY4bpNcXwPs9ViiFkklE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247048; 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=+64Vsvz3fwBAqJhY6+9UhKzkneu2g8ObPvxXx1Wpa28=; b=WU0+tADHl/lJiboPJE09rKIuisvOY8XFHRcjyRVkR6zJpu4CKZU+kqJu/BS1Np16mZThiMittRb81mWqyNAuIoVzriB41JZ8u0Jm5/8VWK4KnvNtkJ3bL3DvSF4tTIXjRA0PPJdqOpgHmscTktQIUG8qmIJMzKQDmA06yEDUuyc= 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 1602247048498542.314178176547; Fri, 9 Oct 2020 05:37:28 -0700 (PDT) Received: from localhost ([::1]:55906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQreJ-0001xR-3k for importer@patchew.org; Fri, 09 Oct 2020 08:37:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38620) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMr-00005k-LI for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55366) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMn-0007xs-5Q for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:25 -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-317-p734BOnDNPC2x8avMfp7KA-1; Fri, 09 Oct 2020 08:19:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F213C1029D20 for ; Fri, 9 Oct 2020 12:19:14 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58B325C1BB; Fri, 9 Oct 2020 12:19:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245957; 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=+64Vsvz3fwBAqJhY6+9UhKzkneu2g8ObPvxXx1Wpa28=; b=eF18ksxm+0S7OfEYOZqT5P97e9bozY0KrdXauB82p0fbAd3i4GBWzuLDaJ79uiMGZ42TlK +ro1u2/V2iYZqIXj6z4nZbi7bZ/L2plUlpZ3ybW9CZSA1NXVW4EXi8jO6xk9dTmNKzA4Eh 5GhBGUDNiy5U9Mo9PNFuVyZHWlIPt3c= X-MC-Unique: p734BOnDNPC2x8avMfp7KA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 14/23] i386: drop FEAT_HYPERV feature leaves Date: Fri, 9 Oct 2020 14:18:33 +0200 Message-Id: <20201009121842.1938010-15-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 | 5 --- target/i386/kvm.c | 108 ++++++++++++++++------------------------------ 3 files changed, 37 insertions(+), 166 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c12d53938970..bfa3f5515aff 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 { @@ -6908,7 +6820,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 67985e7c0951..2100a9ded847 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 */ diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 24636ce4bc69..a4f3ad2f7564 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -799,7 +799,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; @@ -807,25 +808,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} } @@ -833,42 +834,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) @@ -876,23 +877,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} }, @@ -901,7 +902,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) @@ -909,7 +910,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} }, @@ -918,7 +919,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) @@ -1064,48 +1065,6 @@ 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) -{ - struct kvm_cpuid_entry2 *entry; - uint32_t func; - int reg; - - 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 -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; -} - static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, int reg) { @@ -1121,18 +1080,20 @@ static uint32_t hv_cpuid_get_host(struct kvm_cpuid2= *cpuid, uint32_t func, =20 static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) { - uint32_t r, fw, bits; - int i; + uint32_t func, bits; + int i, reg; =20 for (i =3D 0; i < ARRAY_SIZE(kvm_hyperv_properties[feature].flags); i+= +) { - fw =3D kvm_hyperv_properties[feature].flags[i].fw; + + 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; =20 - if (!fw) { + if (!func) { continue; } =20 - if (hv_cpuid_get_fw(cpuid, fw, &r) || (r & bits) !=3D bits) { + if ((hv_cpuid_get_host(cpuid, func, reg) & bits) !=3D bits) { return false; } } @@ -1182,7 +1143,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, return 0; } =20 -static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t fw) +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; @@ -1194,7 +1155,10 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, ui= nt32_t fw) } =20 for (j =3D 0; j < ARRAY_SIZE(kvm_hyperv_properties[i].flags); j++)= { - if (kvm_hyperv_properties[i].flags[j].fw !=3D fw) { + if (kvm_hyperv_properties[i].flags[j].func !=3D func) { + continue; + } + if (kvm_hyperv_properties[i].flags[j].reg !=3D reg) { continue; } =20 @@ -1345,16 +1309,16 @@ static int hyperv_handle_properties(CPUState *cs, =20 c =3D &cpuid_ent[cpuid_i++]; c->function =3D HV_CPUID_FEATURES; - c->eax =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EAX); - c->ebx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EBX); - c->edx =3D hv_build_cpuid_leaf(cs, FEAT_HYPERV_EDX); + 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); =20 /* 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 hv_build_cpuid_leaf(cs, 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) { --=20 2.25.4 From nobody Sun Nov 16 23:04:00 2025 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=1602246932; cv=none; d=zohomail.com; s=zohoarc; b=Hp0YVteNfv/fbvyAlOGSJRkJ3bFzpX/S0OI1fZtbt+LRfyQc15th40Q9649UQXs196GozZmu5xMFyzk66dmLLpz56/+WJPTxF/nciZD1cRKF86Ky2Uu6XRtFRpuVK97H4Cf/v/yeG8OPP6hMBYt2qwDNEAghncOxPjHvMNMapes= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246932; 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=J666hlWTkFnVigMc6hwMHCeRF1949qKDBm7pQfFluy0=; b=EllBLdjFc2JsOnYIxG9w9nfYi1nGQ2UNM2UTfo8dfMnCZTRZttVtBKnd7TKBQSOJelL9Cr5B9xM7LhZ/bmsFt+kuZMgoTbL6X/QoFevWef+8CoOCMhdN2GjTI49JJ9tngup0rG9oTmY2gs7hgZKSo2awarhyH1tBO55pxciLAhw= 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 160224693271055.62028734453759; Fri, 9 Oct 2020 05:35:32 -0700 (PDT) Received: from localhost ([::1]:48160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrcR-0007BN-4a for importer@patchew.org; Fri, 09 Oct 2020 08:35:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMr-0008WE-10 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMn-0007yJ-5m for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:24 -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-305-px3eyiegNn-WYKuPFurj1g-1; Fri, 09 Oct 2020 08:19:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1111C80B70A for ; Fri, 9 Oct 2020 12:19:17 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C5645C1D0; Fri, 9 Oct 2020 12:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245959; 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=J666hlWTkFnVigMc6hwMHCeRF1949qKDBm7pQfFluy0=; b=YnHVesYt3wgutlq7OlSNXdJUu4Dk6eO+Xb46K+hEmoAg66zJgllQSyc9r0IduEkJSTg5WF dq7Y1ryXkpgQmcwsSVoIMcJn06CdUD00zr7NldPBZRTebaE3XvtgF3Omt9zHLS4UMTodXt AkqFR5v3vB9rffCxo+IY8J1zOBm6Og8= X-MC-Unique: px3eyiegNn-WYKuPFurj1g-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 15/23] i386: introduce hv_cpuid_cache Date: Fri, 9 Oct 2020 14:18:34 +0200 Message-Id: <20201009121842.1938010-16-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 | 109 ++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a4f3ad2f7564..cfb5ced003f6 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -125,6 +125,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) @@ -1065,10 +1066,25 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid_le= gacy(CPUState *cs) return cpuid; } =20 -static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func, - int reg) +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; + } =20 entry =3D cpuid_find_entry(cpuid, func, 0); if (!entry) { @@ -1078,7 +1094,7 @@ static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *= cpuid, uint32_t func, return cpuid_entry_get_reg(entry, reg); } =20 -static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature) +static bool hyperv_feature_supported(CPUState *cs, int feature) { uint32_t func, bits; int i, reg; @@ -1093,7 +1109,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid= 2 *cpuid, int feature) continue; } =20 - if ((hv_cpuid_get_host(cpuid, func, reg) & bits) !=3D bits) { + if ((hv_cpuid_get_host(cs, func, reg) & bits) !=3D bits) { return false; } } @@ -1101,8 +1117,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid= 2 *cpuid, int feature) return true; } =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); uint64_t deps; @@ -1125,7 +1140,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struc= t kvm_cpuid2 *cpuid, deps &=3D ~(1ull << dep_feat); } =20 - if (!hyperv_feature_supported(cpuid, feature)) { + if (!hyperv_feature_supported(cs, feature)) { if (hyperv_feat_enabled(cpu, feature)) { fprintf(stderr, "Hyper-V %s is not supported by kernel\n", @@ -1178,7 +1193,6 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) { X86CPU *cpu =3D X86_CPU(cs); - struct kvm_cpuid2 *cpuid; struct kvm_cpuid_entry2 *c; uint32_t cpuid_i =3D 0; int r; @@ -1204,71 +1218,65 @@ 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) { cpu->hyperv_vendor_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EBX); + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_EBX= ); cpu->hyperv_vendor_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= ECX); + hv_cpuid_get_host(cs, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_ECX= ); cpu->hyperv_vendor_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VENDOR_AND_MAX_FUNCTIONS, R_= EDX); + 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)); =20 cpu->hyperv_interface_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EAX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EAX); cpu->hyperv_interface_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EBX); cpu->hyperv_interface_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_ECX); cpu->hyperv_interface_id[3] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_INTERFACE, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_INTERFACE, R_EDX); =20 cpu->hyperv_version_id[0] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EAX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EAX); cpu->hyperv_version_id[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EBX); cpu->hyperv_version_id[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_ECX); cpu->hyperv_version_id[3] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_VERSION, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_VERSION, R_EDX); =20 - cpu->hv_max_vps =3D hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LI= MITS, + 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(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EBX); cpu->hyperv_limits[1] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_ECX); cpu->hyperv_limits[2] =3D - hv_cpuid_get_host(cpuid, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); + hv_cpuid_get_host(cs, HV_CPUID_IMPLEMENT_LIMITS, R_EDX); =20 cpu->hyperv_spinlock_attempts =3D - hv_cpuid_get_host(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); + hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EBX); } =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) && @@ -1281,8 +1289,7 @@ static int hyperv_handle_properties(CPUState *cs, } =20 if (r) { - r =3D -ENOSYS; - goto free; + return -ENOSYS; } =20 c =3D &cpuid_ent[cpuid_i++]; @@ -1324,7 +1331,7 @@ static int hyperv_handle_properties(CPUState *cs, 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(cpuid, HV_CPUID_ENLIGHTMENT_INFO, R_= EAX) & + c->eax |=3D hv_cpuid_get_host(cs, HV_CPUID_ENLIGHTMENT_INFO, R_EAX= ) & HV_NO_NONARCH_CORESHARING; } =20 @@ -1349,12 +1356,8 @@ static int hyperv_handle_properties(CPUState *cs, c->function =3D HV_CPUID_NESTED_FEATURES; c->eax =3D cpu->hyperv_nested[0]; } - r =3D cpuid_i; =20 -free: - g_free(cpuid); - - return r; + return cpuid_i; } =20 static Error *hv_passthrough_mig_blocker; --=20 2.25.4 From nobody Sun Nov 16 23:04:00 2025 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=1602247190; cv=none; d=zohomail.com; s=zohoarc; b=A/FGvyxBwv5FWNPZS9VQ6mRA089AwA7MggiL8+L5DKPYbkgCG3l52Fc9aShcQ/EUTUX3+h7IWVXu2fmCj01kja2timAaMtal+iOTji4K7rNkQFs+VErkGS1WF1RkHkcaxAX3PgGC7eIcGPbesJyrIIRCNzH07cQafbme4fPwom4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247190; 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=0JZHbOlTqt3A5jWQdh+w6TWh01jeQl9kVh7EGIr7CVA=; b=gjnsvgqlqjgfigAWOK1rRIiUvO3qZtZq6EI8k6nuoghsZPxp9d0GkFm0cSxv52Pt9KFoVRfqpKg6f46uiat1RDOwr+5+IYrgntQHN0G+QkkJ0xAEqmX1k9yoCQ4O13qHGAq2NubfmZmdnGhagxhppESicYB0UpybkOQVKK+fBx0= 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 1602247190738619.0185048314491; Fri, 9 Oct 2020 05:39:50 -0700 (PDT) Received: from localhost ([::1]:33782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrgb-0004R1-HV for importer@patchew.org; Fri, 09 Oct 2020 08:39:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMv-0000Ex-7V for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMo-0007yc-PN for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -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-443-KCtTAco-OUS9t1De0u-CZw-1; Fri, 09 Oct 2020 08:19:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1607CAFD03 for ; Fri, 9 Oct 2020 12:19:19 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67BE05C1BB; Fri, 9 Oct 2020 12:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245962; 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=0JZHbOlTqt3A5jWQdh+w6TWh01jeQl9kVh7EGIr7CVA=; b=UaAhQQ33xsvSzIUCZFjQrcz3z7MOFy+VM2OHBGNZ7kWbmFb/vLKpW19ZBGnU7JJMsyYz2A aqMDbzqlkeT10GZ9buOyc9E0EosQ7oXisr5+sn/u2XzeeiPeWyswJsiZkuN57F2Ia8xM+R f6omV7KmKqL/ypLIOcGqpqlmnqlKi0o= X-MC-Unique: KCtTAco-OUS9t1De0u-CZw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 16/23] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() Date: Fri, 9 Oct 2020 14:18:35 +0200 Message-Id: <20201009121842.1938010-17-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 cfb5ced003f6..8c846f80a25f 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1185,16 +1185,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)) @@ -1292,6 +1291,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) ? @@ -1499,11 +1511,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 Sun Nov 16 23:04:00 2025 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=1602247046; cv=none; d=zohomail.com; s=zohoarc; b=juBBNIm82JwsTX+UT8wmmgOCiEgZqR2dtfELrYvkvWOVqmx6c1dQx/Wb/DN5Q0fyVp0lofCsJeXdp05rRBIyfeOwjE5ABonf6R9Vx1f7BeFBgahrsbzdH2QPE/O0fsTvVozoS2J/qW/+TEOtKPmSRM6HNg7ljwNDUsUYuhiqP+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247046; 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=x6/dINnK1xGWIv+2QiH6QEgSoZAv36Yv/1COTLahlT4=; b=dGRWTxFfjqN4dkT/gm8kYtEERh0gGWyS5PmQiF5wdSd3W2TKhgie1RyZqtn8d2hSzbQ8UxX8ZCRt7tih5/BaFslAE66pEtF1OaWoOj54OeYxhsMc1o4cG7lA6RliXfCYHbVovNczmdtgHFTcDcBADkQpNCXdiONPSmE505tkl5s= 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 1602247045989623.326744045938; Fri, 9 Oct 2020 05:37:25 -0700 (PDT) Received: from localhost ([::1]:55658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQreG-0001rK-JH for importer@patchew.org; Fri, 09 Oct 2020 08:37:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMu-0000DT-CB for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMq-0007z0-Em for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -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-378-DADcCyYbOJ2TNwctqCZpBg-1; Fri, 09 Oct 2020 08:19:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2AE42AFD0A for ; Fri, 9 Oct 2020 12:19:21 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7ECE65C1BB; Fri, 9 Oct 2020 12:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245963; 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=x6/dINnK1xGWIv+2QiH6QEgSoZAv36Yv/1COTLahlT4=; b=e7aKXb6CCCKbNHD1OqFdOeMz4fANOCaIvczk6hq5Hxo0mreMAx2FC4xzy5YvOEjgnp919x M5UYHR4BTbG9HLBQiSyKDs4dCvmFiKfrpYQ0W/5z/kz3HExNJyBtTdwHJcASpB5t0Rzg4C fPtHUmpi6YU9gYW6Ko5SRvzlDscKOo4= X-MC-Unique: DADcCyYbOJ2TNwctqCZpBg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 17/23] i386: move eVMCS enablement to hyperv_init_vcpu() Date: Fri, 9 Oct 2020 14:18:36 +0200 Message-Id: <20201009121842.1938010-18-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 8c846f80a25f..06f78a09304e 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -961,6 +961,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 @@ -970,6 +971,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 @@ -1199,24 +1216,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= ); @@ -1453,6 +1452,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 @@ -1517,6 +1531,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; @@ -1864,11 +1883,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 Sun Nov 16 23:04:00 2025 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=1602247193; cv=none; d=zohomail.com; s=zohoarc; b=c9wvHqP85GNHHOto1ZlGMQuYSKecYTnjqZ2tKIm3QcHa/7c0nQxiVBMGPB74z8DNsFawU5nbahjzh9W7knhJA1FwiD7J3N9mFScztBLXU5VFQhSqfbijlOz4ExosMpCRnoSOFhZDLSzLW2NWWTgFsBMGotXpjP5eyaBcxF6lMTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247193; 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=2zkz2SEKDwDKngOS2g2FJBlJQ/tGTWTMzrwYb9qJdhk=; b=Vuo5ybmvyo7uMcDHJPF6qDE1S5prpffzm1rpPis/fcNMII0a+en6ZJ2llj8TTiEkAeLh852sm2Dphaztk7/AdWfDnvLlgD++1xNcp+U/p3a2llfeYJxgpJzjEM2mVzzIGstOZnnxPZzyHgF26xS4FCPHKBrp7PA732L3lpZqtO4= 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 160224719375258.15580546063052; Fri, 9 Oct 2020 05:39:53 -0700 (PDT) Received: from localhost ([::1]:34112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrge-0004ZT-EG for importer@patchew.org; Fri, 09 Oct 2020 08:39:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMu-0000Dp-PV for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45709) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMs-0007zV-PY for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:28 -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-549-xOtzICMpPfeobKMH4iPIEw-1; Fri, 09 Oct 2020 08:19:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0140108E1A0 for ; Fri, 9 Oct 2020 12:19:23 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 904F45C1BB; Fri, 9 Oct 2020 12:19:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245966; 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=2zkz2SEKDwDKngOS2g2FJBlJQ/tGTWTMzrwYb9qJdhk=; b=LR0AcQvp5cPzUyWfYNX7sSy1vle2u6WaRbVlW0cC2TgYQdDyyHdEXJfZkPqIBcmPqWIabG 1yL/lP6nfnl1PckqRwKzMzcDNzdXS/TlOr19eNrw8DdbUopYJENE2F/YTVKw0dHFC0j6p6 z8QWNOUbgNHAlCYbxtj4RRaVfycm43U= X-MC-Unique: xOtzICMpPfeobKMH4iPIEw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 18/23] i386: switch hyperv_expand_features() to using error_setg() Date: Fri, 9 Oct 2020 14:18:37 +0200 Message-Id: <20201009121842.1938010-19-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 06f78a09304e..1c1fa04b7c02 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1134,7 +1134,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; @@ -1148,20 +1148,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; @@ -1208,13 +1206,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 @@ -1260,37 +1257,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 /* @@ -1525,9 +1545,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 Sun Nov 16 23:04:00 2025 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=1602246935; cv=none; d=zohomail.com; s=zohoarc; b=L/pN33BKBn2g3v+4ZpTfbQBAyS+f9waCdEtw4oVtIt3kPcicU5U2MeWmR6ZVzuZhe3XJ9zbWUH+m96dx3rM+ijpXCXeGp7Gmy/FfhL/YJxMqjR+rkJWTadpYKjzCNSacT2V4Xy2usTKWsUU1su1qK6WZjWogfdyOi7X3KPsR+2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246935; 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+AowyM7oBeEOqENkZM3nF4NF6lJENQiEi8MXtaILQ=; b=jX2mM0Y5mk4EbJCKdisJhFXUUHd3C/Z+W4g2Wx/SilDTZJyXHZnuYjlXA777ruQgbH8ZBwsMlKmFNaG8bm0mbQ72deuo7Ik7Bxq6c36qmZAnjy47F4x02AK/86YEkH/re+4DYpw9wOhPJEaqJQb7q88ugkfhuM5oOXGnMpFH9Mo= 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 1602246935003367.373159175625; Fri, 9 Oct 2020 05:35:35 -0700 (PDT) Received: from localhost ([::1]:48420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrcT-0007It-LS for importer@patchew.org; Fri, 09 Oct 2020 08:35:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38702) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrMx-0000N6-VR for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMw-000805-6y for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-9MFRtqPlNACquGORh5CIbA-1; Fri, 09 Oct 2020 08:19:26 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D74CF800460 for ; Fri, 9 Oct 2020 12:19:25 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C05E5C1BB; Fri, 9 Oct 2020 12:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245969; 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+AowyM7oBeEOqENkZM3nF4NF6lJENQiEi8MXtaILQ=; b=KU1V9tAWx8fv++HIFEmV/BSG9W+OoV6gdRO3HJgewbJ2WaxU9lGkYjbfmQTUqAjwPAgDA9 Vi5etcoqEYI0wlRB1GFCyS/beiWP6VP1OTkCmHe3JpsDo9Abnz7LpP4IS8jpM/dRmk5t7y xV6OvqjN36n4yXCZFaS0dZ686SgM1Zg= X-MC-Unique: 9MFRtqPlNACquGORh5CIbA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 19/23] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size Date: Fri, 9 Oct 2020 14:18:38 +0200 Message-Id: <20201009121842.1938010-20-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 1c1fa04b7c02..a80fc8fcdfc5 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -960,7 +960,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 Sun Nov 16 23:04:00 2025 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=1602247308; cv=none; d=zohomail.com; s=zohoarc; b=j+86ERgYmE8DjisQHc3YIYEe1ESGJboVm+28/96Mc2YQyIt4uRQKYcJguHaaDAcCxtT2pUDDngaGJnp2VTlIrae7k6f3mt3zv2+FvV/4MbAt1waWW4DxTjfNxmCIt5JVmOGtQwX+5D16nMIf2aFRFwsInAMd9SHo9RZ52srj7KE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247308; 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=VgJ8UTi5RcoLrHm5/qD45D2e03XD/czHQST8nRIvT9g=; b=eoPzwtUkggbiMyJ3z1FV/+G5hDpQyKYFRW4kepcfCigJceNv3MvNPOe+oA+cuemvnstYgwE6/D9iD5tKSyZiPFW1YZfkWkPom6KuG7aza0/qM2p2uFNYInTtVSNXcpUFXJTwHmDv41sYPixnExfNBKnVW4hN/f4GTSbdETt+xOk= 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 1602247308701757.2844061221596; Fri, 9 Oct 2020 05:41:48 -0700 (PDT) Received: from localhost ([::1]:38342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQriV-0006OI-Al for importer@patchew.org; Fri, 09 Oct 2020 08:41:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38718) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrN1-0000VT-44 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40708) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrMy-00080I-RQ for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19: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-362-cdOUJ-Q8Px2zk_IYCh8HTA-1; Fri, 09 Oct 2020 08:19:30 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8122A196C909 for ; Fri, 9 Oct 2020 12:19:29 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41C965C1BB; Fri, 9 Oct 2020 12:19:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245972; 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=VgJ8UTi5RcoLrHm5/qD45D2e03XD/czHQST8nRIvT9g=; b=Yx4eqB70QJgQbMQZR+yHVrZqfk+60x9L1EmZhYDTmKY4jhvurpbNYEO9IPjeYZLiL+w8x1 Hth/nuUkx01F10oImOcSTP/nqynmLLLLSfJGSnaKQvKcETmOGB4gKXPpdolfRPImozcGPF I8D0s/S0g2FOZ1ovGN87BZLMHnbs51U= X-MC-Unique: cdOUJ-Q8Px2zk_IYCh8HTA-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 20/23] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one Date: Fri, 9 Oct 2020 14:18:39 +0200 Message-Id: <20201009121842.1938010-21-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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 a80fc8fcdfc5..fb6eff276caf 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -927,7 +927,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; @@ -936,7 +937,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; } @@ -963,13 +968,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 @@ -979,7 +988,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUSta= te *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 Sun Nov 16 23:04:00 2025 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=1602246984; cv=none; d=zohomail.com; s=zohoarc; b=fg66mw0lRST9G6dklSQfOLCTbpoH0yzcRzsKOheHN37ggpV07MOqFXnKQgZBzpPAC02B/twLv0gLTC9K375xzJ/wOJxtnVykBit1sL5PIRggJYiRZwLD6JSlN2Zg6WLMl1shhLHnCwLCOzdyEpnPcxcS6Ty4Q7Uj5XSH/6P8Vik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602246984; 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=TvTbaOYB9tcrF5OV9v9aPrAsxIifa6CcQ04eGdYN+RA=; b=Vo2ozPqCbTl+BIolJx/jDu8feX5LUYhtmNLAE/lhOxaXdJywaPuWgGiQlbQFuo259vZ9mnJkxvGHfshQ8yZ4KolOTEkNRpJ9rPEON8IePVD9OSIZQA06vN2FzK42UQqFAIMrGwQB3xKqcpb5KIEhV1WIl6K1y2EkfCiSBJbJZjw= 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 1602246984912906.1344503702661; Fri, 9 Oct 2020 05:36:24 -0700 (PDT) Received: from localhost ([::1]:51738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrdH-0000Dd-IT for importer@patchew.org; Fri, 09 Oct 2020 08:36:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrN2-0000aP-UX for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56889) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrN1-00080N-61 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19: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-95-fgWvN9rVNAmqykP2quOaNg-1; Fri, 09 Oct 2020 08:19:32 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AFDA1835B75 for ; Fri, 9 Oct 2020 12:19:31 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id E048E5C1BB; Fri, 9 Oct 2020 12:19:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245974; 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=TvTbaOYB9tcrF5OV9v9aPrAsxIifa6CcQ04eGdYN+RA=; b=Z5pHo9HuPxKFtVVX3PBW2NJCH2jihmp6fIpp9shPEIrN1E4p9xqJxy3XRaJaoyNGWH/3dV /Wru66BWvAcFv7PLAMC6Gj2OanBnaFbFCExh5QA4QaFMORNT13ch48xwYSTy6CfeW2xgmk lftWwELPyxPmn+9HJn6fB3C/lnA+KKo= X-MC-Unique: fgWvN9rVNAmqykP2quOaNg-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 21/23] i386: use global kvm_state in hyperv_enabled() check Date: Fri, 9 Oct 2020 14:18:40 +0200 Message-Id: <20201009121842.1938010-22-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 fb6eff276caf..9191c5f18af5 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -714,8 +714,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 Sun Nov 16 23:04:00 2025 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=1602247127; cv=none; d=zohomail.com; s=zohoarc; b=kc/WRLOO9hyKUtMQgmqChe2UzZj2sh7FrlrIYtljvY9MrUpnUaJZmUsb0E9SBMgGVhBEAKs1zLf+tbWunjFcvcg2lHZ2Ns2qVP9VjwDo9F5D20diHjParybTCf3RuRos+XnCrki2DgAYDMU3FLM8iq+Z0ao31Kx1l6xbb5Y2Lhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247127; 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=xztyG79L4WZz3/XfQmASCFgqS3tqfERWok+izO0A6ew=; b=Tbkx5aZRv8RPh+Nuf6nzyaUoa4iMnFDaf2pBCS5O4nnmz/qFcnAeeS2IpKc3o0BbybxU93G0efBaznZ3QW04p8+FsKZHtjpLKEiAHrQj2LGeGMAkR/Wjj56JDSWnJ7nngDi+JSblxYWeyJdKeLEbLHUpW45TiOjYb2C2kVPh514= 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 1602247127005441.0665409288665; Fri, 9 Oct 2020 05:38:47 -0700 (PDT) Received: from localhost ([::1]:58426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrfZ-000307-HR for importer@patchew.org; Fri, 09 Oct 2020 08:38:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrN7-0000mT-JL for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22252) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrN5-00080d-MD for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:41 -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-21-QjN_jCw4MdywH_9blJZ2nQ-1; Fri, 09 Oct 2020 08:19:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 67FA98C2C4A for ; Fri, 9 Oct 2020 12:19:36 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B11F5C1BB; Fri, 9 Oct 2020 12:19:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245979; 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=xztyG79L4WZz3/XfQmASCFgqS3tqfERWok+izO0A6ew=; b=OA4/QSBMefMJzxTrMvxHNClHs7C+LJLC9gj2Nm20497U1ijZVgis30qwkuBbRF7gMH5sYU BrkwDdJ08qXovEPdFFOrpwxLxdyvFxMtCyO/cQGIc3hvxvYl0Bs6OJIAzC52HR1256glgy Lj+dflUOpBTDsekm8wktASP/1I5UVDg= X-MC-Unique: QjN_jCw4MdywH_9blJZ2nQ-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 22/23] i386: expand Hyper-V features during CPU feature expansion time Date: Fri, 9 Oct 2020 14:18:41 +0200 Message-Id: <20201009121842.1938010-23-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Eduardo Habkost , "Dr. David Alan Gilbert" 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 bfa3f5515aff..55706c8050fe 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6347,6 +6347,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 9191c5f18af5..da620f576725 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1215,13 +1215,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= ); @@ -1554,7 +1563,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 0fce4e51d2d6..38af4a967968 100644 --- a/target/i386/kvm_i386.h +++ b/target/i386/kvm_i386.h @@ -48,5 +48,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 From nobody Sun Nov 16 23:04:00 2025 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=1602247387; cv=none; d=zohomail.com; s=zohoarc; b=hxBac7SOk+JN2z4Lrue6cL3BnBFNnh1pboOlxZbOXL9GUesm6etRSaDnVzY1jh7IZdD1GKtl/zrevZY7HLck90Q2XETpWCqI3jolT85i5bIVCms/BnG+1bhMS1S7OIBPY/y+TCQXhf1eGfVXGEnKYQCzgq8s1YuJqxY7ntznerU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602247387; 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=Z6jxlRpTXoMd9qrS9LNSRXcgrL/IX3QBaQEh5lHu28I=; b=ibOwql1RNp1eQGw3NUiwi4WYkkhAAAnqW/UusGvxTZ8brdwlIjVc++UefBJzjN6AGUn6yOZGE1OHLNtQ3j8aBBrBTpBs8Kq3K6A4IfQ7vrQUlsdZDzQ3eiXKHf5Lc86YEfwjG7ygJQUGdjIv4aaHuW+RaMum6dpfKaf+6TuUHc0= 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 1602247387073979.6633515633578; Fri, 9 Oct 2020 05:43:07 -0700 (PDT) Received: from localhost ([::1]:41944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQrjl-0007qE-Rv for importer@patchew.org; Fri, 09 Oct 2020 08:43:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQrN9-0000sO-Or for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:44052) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQrN7-00080q-MW for qemu-devel@nongnu.org; Fri, 09 Oct 2020 08:19: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-302-fY3aMUHNP_arLYGFxa1ufw-1; Fri, 09 Oct 2020 08:19:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6CFD01029D20 for ; Fri, 9 Oct 2020 12:19:38 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id CACE55C1BB; Fri, 9 Oct 2020 12:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602245980; 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=Z6jxlRpTXoMd9qrS9LNSRXcgrL/IX3QBaQEh5lHu28I=; b=HUFrk4X0Tc/Vg0gAx+JqbYcKGepy5LcEWu4DbgHJ7AcMwz5u3hpwyqYTp/fc83+7Ayis/0 vtiQSqSiOYr23HnONFhol/WcEV4eeko/BASJBnhJQyqsV8yVSJgICIYY8v6FEU08POfJd0 kvQ3QEGiBjrJEwhtzo9T8UyxI22QK9I= X-MC-Unique: fY3aMUHNP_arLYGFxa1ufw-1 From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Subject: [PATCH RFC v3 23/23] i386: provide simple 'hyperv=on' option to x86 machine types Date: Fri, 9 Oct 2020 14:18:42 +0200 Message-Id: <20201009121842.1938010-24-vkuznets@redhat.com> In-Reply-To: <20201009121842.1938010-1-vkuznets@redhat.com> References: <20201009121842.1938010-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 , "Dr. David Alan Gilbert" 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" Enabling Hyper-V emulation for a Windows VM is a tiring experience as it requires listing all currently supported enlightenments ("hv_*" CPU features) explicitly. We do have a 'hv_passthrough' mode enabling everything but it can't be used in production as it prevents migration. Introduce a simple 'hyperv=3Don' option for all x86 machine types enabling all currently supported Hyper-V enlightenments. Later, when new enlightenments get implemented, we will be adding them to newer machine types only (by disabling them for legacy machine types) thus preserving migration. Signed-off-by: Vitaly Kuznetsov Reviewed-by: Eduardo Habkost --- docs/hyperv.txt | 8 ++++++++ hw/i386/x86.c | 30 ++++++++++++++++++++++++++++++ include/hw/i386/x86.h | 7 +++++++ target/i386/cpu.c | 14 ++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index 5df00da54fc4..1a76a07f8417 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -29,6 +29,14 @@ When any set of the Hyper-V enlightenments is enabled, Q= EMU changes hypervisor identification (CPUID 0x40000000..0x4000000A) to Hyper-V. KVM identificati= on and features are kept in leaves 0x40000100..0x40000101. =20 +Hyper-V enlightenments can be enabled in bulk by specifying 'hyperv=3Don' = to an +x86 machine type: + + qemu-system-x86_64 -machine q35,accel=3Dkvm,kernel-irqchip=3Dsplit,hyper= v=3Don ... + +Note, new enlightenments are only added to the latest (in-develompent) mac= hine +type, older machine types keep the list of the supported features intact to +safeguard migration. =20 3. Existing enlightenments =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D diff --git a/hw/i386/x86.c b/hw/i386/x86.c index 3137a2008588..eeecd4e3322f 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -1171,6 +1171,20 @@ static void x86_machine_set_acpi(Object *obj, Visito= r *v, const char *name, visit_type_OnOffAuto(v, name, &x86ms->acpi, errp); } =20 +static bool x86_machine_get_hyperv(Object *obj, Error **errp) +{ + X86MachineState *x86ms =3D X86_MACHINE(obj); + + return x86ms->hyperv_enabled; +} + +static void x86_machine_set_hyperv(Object *obj, bool value, Error **errp) +{ + X86MachineState *x86ms =3D X86_MACHINE(obj); + + x86ms->hyperv_enabled =3D value; +} + static void x86_machine_initfn(Object *obj) { X86MachineState *x86ms =3D X86_MACHINE(obj); @@ -1193,6 +1207,16 @@ static void x86_machine_class_init(ObjectClass *oc, = void *data) x86mc->save_tsc_khz =3D true; nc->nmi_monitor_handler =3D x86_nmi; =20 + /* Hyper-V features enabled with 'hyperv=3Don' */ + x86mc->hyperv_features =3D BIT(HYPERV_FEAT_RELAXED) | BIT(HYPERV_FEAT_= VAPIC) | + BIT(HYPERV_FEAT_TIME) | BIT(HYPERV_FEAT_CRASH) | + BIT(HYPERV_FEAT_RESET) | BIT(HYPERV_FEAT_VPINDEX) | + BIT(HYPERV_FEAT_RUNTIME) | BIT(HYPERV_FEAT_SYNIC) | + BIT(HYPERV_FEAT_STIMER) | BIT(HYPERV_FEAT_FREQUENCIES) | + BIT(HYPERV_FEAT_REENLIGHTENMENT) | BIT(HYPERV_FEAT_TLBFLUSH) | + BIT(HYPERV_FEAT_EVMCS) | BIT(HYPERV_FEAT_IPI) | + BIT(HYPERV_FEAT_STIMER_DIRECT); + object_class_property_add(oc, X86_MACHINE_SMM, "OnOffAuto", x86_machine_get_smm, x86_machine_set_smm, NULL, NULL); @@ -1204,6 +1228,12 @@ static void x86_machine_class_init(ObjectClass *oc, = void *data) NULL, NULL); object_class_property_set_description(oc, X86_MACHINE_ACPI, "Enable ACPI"); + + object_class_property_add_bool(oc, X86_MACHINE_HYPERV, + x86_machine_get_hyperv, x86_machine_set_hyperv); + + object_class_property_set_description(oc, X86_MACHINE_HYPERV, + "Enable Hyper-V enlightenments"); } =20 static const TypeInfo x86_machine_info =3D { diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h index d5dcf7a07fdc..2b989e5fc49d 100644 --- a/include/hw/i386/x86.h +++ b/include/hw/i386/x86.h @@ -38,6 +38,9 @@ struct X86MachineClass { bool save_tsc_khz; /* Enables contiguous-apic-ID mode */ bool compat_apic_id_mode; + + /* Hyper-V features enabled with 'hyperv=3Don' */ + uint64_t hyperv_features; }; =20 struct X86MachineState { @@ -70,10 +73,14 @@ struct X86MachineState { * will be translated to MSI messages in the address space. */ AddressSpace *ioapic_as; + + /* Hyper-V emulation */ + bool hyperv_enabled; }; =20 #define X86_MACHINE_SMM "smm" #define X86_MACHINE_ACPI "acpi" +#define X86_MACHINE_HYPERV "hyperv" =20 #define TYPE_X86_MACHINE MACHINE_TYPE_NAME("x86") OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 55706c8050fe..d0961c1838ad 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -53,6 +53,7 @@ #include "sysemu/tcg.h" #include "hw/qdev-properties.h" #include "hw/i386/topology.h" +#include "hw/i386/x86.h" #ifndef CONFIG_USER_ONLY #include "exec/address-spaces.h" #include "hw/i386/apic_internal.h" @@ -6409,8 +6410,21 @@ static void x86_cpu_filter_features(X86CPU *cpu, boo= l verbose) =20 static void x86_cpu_hyperv_realize(X86CPU *cpu) { + X86MachineState *x86ms =3D X86_MACHINE(qdev_get_machine()); + X86MachineClass *x86mc =3D X86_MACHINE_GET_CLASS(x86ms); + uint64_t feat; size_t len; =20 + if (x86ms->hyperv_enabled) { + feat =3D x86mc->hyperv_features; + /* Enlightened VMCS is only available on Intel/VMX */ + if (!cpu_has_vmx(&cpu->env)) { + feat &=3D ~BIT(HYPERV_FEAT_EVMCS); + } + + cpu->hyperv_features |=3D feat; + } + /* Hyper-V vendor id */ if (!cpu->hyperv_vendor) { object_property_set_str(OBJECT(cpu), "hv-vendor-id", "Microsoft Hv= ", --=20 2.25.4