From patchwork Fri Mar 29 14:18:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 10877183 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3E711575 for ; Fri, 29 Mar 2019 14:24:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8B4928F8F for ; Fri, 29 Mar 2019 14:24:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCD38290D4; Fri, 29 Mar 2019 14:24:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 52CB3290D0 for ; Fri, 29 Mar 2019 14:24:53 +0000 (UTC) Received: from localhost ([127.0.0.1]:54419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sRA-0004EX-3R for patchwork-qemu-devel@patchwork.kernel.org; Fri, 29 Mar 2019 10:24:52 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h9sQW-0003U0-Fd for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h9sQV-0006Eg-AF for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57030) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h9sQV-0006EC-05 for qemu-devel@nongnu.org; Fri, 29 Mar 2019 10:24:11 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E16F1F74D4; Fri, 29 Mar 2019 14:18:53 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 206EA1001E91; Fri, 29 Mar 2019 14:18:51 +0000 (UTC) From: Vitaly Kuznetsov To: qemu-devel@nongnu.org Date: Fri, 29 Mar 2019 15:18:32 +0100 Message-Id: <20190329141832.22882-9-vkuznets@redhat.com> In-Reply-To: <20190329141832.22882-1-vkuznets@redhat.com> References: <20190329141832.22882-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 29 Mar 2019 14:18:53 +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 8/8] i386/kvm: add support for Direct Mode for Hyper-V synthetic timers 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: Eduardo Habkost , Marcelo Tosatti , "Dr . David Alan Gilbert" , Roman Kagan , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hyper-V on KVM can only use Synthetic timers with Direct Mode (opting for an interrupt instead of VMBus message). This new capability is only announced in KVM_GET_SUPPORTED_HV_CPUID. Signed-off-by: Vitaly Kuznetsov --- docs/hyperv.txt | 10 ++++++++++ target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/hyperv-proto.h | 1 + target/i386/kvm.c | 15 +++++++++++++++ 5 files changed, 28 insertions(+) diff --git a/docs/hyperv.txt b/docs/hyperv.txt index d1299aba81..e1988ab648 100644 --- a/docs/hyperv.txt +++ b/docs/hyperv.txt @@ -173,6 +173,16 @@ without the feature to find out if enabling it is beneficial. Requires: hv-vapic +3.17. hv-stimer-direct +======================= +Hyper-V specification allows synthetic timer operation in two modes: "classic", +when expiration event is delivered as SynIC message and "direct", when the event +is delivered via normal interrupt. It is known that nested Hyper-V can only +use synthetic timers in direct mode and thus 'hv-stimer-direct' needs to be +enabled. + +Requires: hv-vpindex, hv-synic, hv-time, hv-stimer + 4. Development features ======================== diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4e01ad076e..ea3843ed0c 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5785,6 +5785,7 @@ static Property x86_cpu_properties[] = { DEFINE_PROP_BOOL("hv-tlbflush", X86CPU, hyperv_tlbflush, false), DEFINE_PROP_BOOL("hv-evmcs", X86CPU, hyperv_evmcs, false), DEFINE_PROP_BOOL("hv-ipi", X86CPU, hyperv_ipi, false), + DEFINE_PROP_BOOL("hv-stimer-direct", X86CPU, hyperv_stimer_direct, false), DEFINE_PROP_BOOL("hv-all", X86CPU, hyperv_all, false), DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, true), DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false), diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 9cd3a8bc2f..3f1ada3e39 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1396,6 +1396,7 @@ struct X86CPU { bool hyperv_tlbflush; bool hyperv_evmcs; bool hyperv_ipi; + bool hyperv_stimer_direct; bool hyperv_all; bool check_cpuid; bool enforce_cpuid; diff --git a/target/i386/hyperv-proto.h b/target/i386/hyperv-proto.h index c0272b3a01..cffac10b45 100644 --- a/target/i386/hyperv-proto.h +++ b/target/i386/hyperv-proto.h @@ -49,6 +49,7 @@ #define HV_GUEST_IDLE_STATE_AVAILABLE (1u << 5) #define HV_FREQUENCY_MSRS_AVAILABLE (1u << 8) #define HV_GUEST_CRASH_MSR_AVAILABLE (1u << 10) +#define HV_STIMER_DIRECT_MODE_AVAILABLE (1u << 19) /* * HV_CPUID_ENLIGHTMENT_INFO.EAX bits diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 976c1d570f..f3c73b7c4e 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -657,6 +657,7 @@ static bool hyperv_enabled(X86CPU *cpu) cpu->hyperv_reenlightenment || cpu->hyperv_tlbflush || cpu->hyperv_ipi || + cpu->hyperv_stimer_direct || cpu->hyperv_all); } @@ -832,6 +833,15 @@ static struct { {0} } }, + { + .name = "hv-stimer-direct", + .desc = "direct mode timers", + .flags = { + {.fw = FEAT_HYPERV_EDX, + .bits = HV_STIMER_DIRECT_MODE_AVAILABLE}, + {0} + } + }, }; static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) @@ -1178,6 +1188,8 @@ static int hyperv_handle_properties(CPUState *cs, r |= hv_cpuid_check_and_set(cs, cpuid, "hv-tlbflush", &cpu->hyperv_tlbflush); r |= hv_cpuid_check_and_set(cs, cpuid, "hv-ipi", &cpu->hyperv_ipi); + r |= hv_cpuid_check_and_set(cs, cpuid, "hv-stimer-direct", + &cpu->hyperv_stimer_direct); /* Dependencies */ if (cpu->hyperv_synic && !cpu->hyperv_synic_kvm_only && @@ -1198,6 +1210,9 @@ static int hyperv_handle_properties(CPUState *cs, if (cpu->hyperv_ipi && !cpu->hyperv_vpindex) { r |= hv_report_missing_dep(cpu, "hv-ipi", "hv-vpindex"); } + if (cpu->hyperv_stimer_direct && !cpu->hyperv_stimer) { + r |= hv_report_missing_dep(cpu, "hv-stimer-direct", "hv-stimer"); + } /* Not exposed by KVM but needed to make CPU hotplug in Windows work */ env->features[FEAT_HYPERV_EDX] |= HV_CPU_DYNAMIC_PARTITIONING_AVAILABLE;