From nobody Mon Feb 9 11:29:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539948010108778.0520960236622; Fri, 19 Oct 2018 04:20:10 -0700 (PDT) Received: from localhost ([::1]:48839 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDSp7-0001HV-3o for importer@patchew.org; Fri, 19 Oct 2018 07:20:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDSjt-0005QN-4J for qemu-devel@nongnu.org; Fri, 19 Oct 2018 07:14:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDSjr-0007sM-Ox for qemu-devel@nongnu.org; Fri, 19 Oct 2018 07:14:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gDSjr-0007q9-Gk for qemu-devel@nongnu.org; Fri, 19 Oct 2018 07:14:43 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5976C057E39; Fri, 19 Oct 2018 11:14:42 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.205.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C92C607CA; Fri, 19 Oct 2018 11:14:40 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 19 Oct 2018 13:14:32 +0200 Message-Id: <20181019111432.5040-3-vkuznets@redhat.com> In-Reply-To: <20181019111432.5040-1-vkuznets@redhat.com> References: <20181019111432.5040-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 19 Oct 2018 11:14:42 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] x86: hv_evmcs CPU flag support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Marcelo Tosatti , Roman Kagan , Eduardo Habkost , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Adds a new CPU flag to enable the Enlightened VMCS KVM feature. QEMU enables KVM_CAP_HYPERV_ENLIGHTENED_VMCS and gets back the version to be advertised in lower 16 bits of CPUID.0x4000000A:EAX. Suggested-by: Ladi Prosek Signed-off-by: Vitaly Kuznetsov --- target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/hyperv-proto.h | 3 +++ target/i386/kvm.c | 20 ++++++++++++++++++-- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index c88876dfe3..5c0e84fb99 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5564,6 +5564,7 @@ static Property x86_cpu_properties[] =3D { DEFINE_PROP_BOOL("hv-frequencies", X86CPU, hyperv_frequencies, false), DEFINE_PROP_BOOL("hv-reenlightenment", X86CPU, hyperv_reenlightenment,= false), DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), + DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), DEFINE_PROP_BOOL("kvm", X86CPU, expose_kvm, true), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 730c06f80a..013d953b57 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1382,6 +1382,7 @@ struct X86CPU { bool hyperv_frequencies; bool hyperv_reenlightenment; bool hyperv_tlbflush; + bool hyperv_evmcs; bool check_cpuid; bool enforce_cpuid; bool expose_kvm; diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index d6d5a79293..fcb0c416f8 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -18,7 +18,9 @@ #define HV_CPUID_FEATURES 0x40000003 #define HV_CPUID_ENLIGHTMENT_INFO 0x40000004 #define HV_CPUID_IMPLEMENT_LIMITS 0x40000005 +#define HV_CPUID_NESTED_FEATURES 0x4000000A #define HV_CPUID_MIN 0x40000005 +#define HV_CPUID_MIN_NESTED 0x4000000A #define HV_CPUID_MAX 0x4000ffff #define HV_HYPERVISOR_PRESENT_BIT 0x80000000 =20 @@ -59,6 +61,7 @@ #define HV_SYSTEM_RESET_RECOMMENDED (1u << 4) #define HV_RELAXED_TIMING_RECOMMENDED (1u << 5) #define HV_EX_PROCESSOR_MASKS_RECOMMENDED (1u << 11) +#define HV_ENLIGHTENED_VMCS_RECOMMENDED (1u << 14) =20 /* * Basic virtualized MSRs diff --git a/target/i386/kvm.c b/target/i386/kvm.c index a46ad102d8..8e383e7197 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -798,6 +798,7 @@ int kvm_arch_init_vcpu(CPUState *cs) uint32_t unused; struct kvm_cpuid_entry2 *c; uint32_t signature[3]; + uint16_t evmcs_version; int kvm_base =3D KVM_CPUID_SIGNATURE; int r; Error *local_err =3D NULL; @@ -841,7 +842,7 @@ int kvm_arch_init_vcpu(CPUState *cs) memset(signature, 0, 12); memcpy(signature, cpu->hyperv_vendor_id, len); } - c->eax =3D HV_CPUID_MIN; + c->eax =3D cpu->hyperv_evmcs ? HV_CPUID_MIN_NESTED : HV_CPUID_MIN; c->ebx =3D signature[0]; c->ecx =3D signature[1]; c->edx =3D signature[2]; @@ -888,7 +889,16 @@ int kvm_arch_init_vcpu(CPUState *cs) c->eax |=3D HV_REMOTE_TLB_FLUSH_RECOMMENDED; c->eax |=3D HV_EX_PROCESSOR_MASKS_RECOMMENDED; } - + if (cpu->hyperv_evmcs) { + if (kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, + (uintptr_t)&evmcs_version)) { + fprintf(stderr, "Hyper-V Enlightened VMCS " + "(requested by 'hv-evmcs' cpu flag) " + "is not supported by kernel\n"); + return -ENOSYS; + } + c->eax |=3D HV_ENLIGHTENED_VMCS_RECOMMENDED; + } c->ebx =3D cpu->hyperv_spinlock_attempts; =20 c =3D &cpuid_data.entries[cpuid_i++]; @@ -899,6 +909,12 @@ int kvm_arch_init_vcpu(CPUState *cs) =20 kvm_base =3D KVM_CPUID_SIGNATURE_NEXT; has_msr_hv_hypercall =3D true; + + if (cpu->hyperv_evmcs) { + c =3D &cpuid_data.entries[cpuid_i++]; + c->function =3D HV_CPUID_NESTED_FEATURES; + c->eax =3D evmcs_version; + } } =20 if (cpu->expose_kvm) { --=20 2.17.2