From patchwork Tue Jun 6 18:19:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5DEBD60364 for ; Tue, 6 Jun 2017 18:28:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5820522B1F for ; Tue, 6 Jun 2017 18:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C67227C05; Tue, 6 Jun 2017 18:28:39 +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=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A3E322B1F for ; Tue, 6 Jun 2017 18:28:38 +0000 (UTC) Received: from localhost ([::1]:39657 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJDZ-0004P1-5g for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:28:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5T-0005wV-MT for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5O-0007Ms-W8 for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:15 -0400 Received: from mail-eopbgr30107.outbound.protection.outlook.com ([40.107.3.107]:56200 helo=EUR03-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dIJ5O-0007MD-HC for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=n8JFAJcsmI3xXKslKQqOp8l4d0ywKxoBFHl6tMJh59w=; b=NP/YslfhHsoVArm6PHh7a0/qIA92p4Wl5nYXOS2bZqBO8MMJ57jffBt6BqqUKldM/zjDuJf4GUikyzK1YEQOHhGv8MBmaRZVn90Zt0QOuf57CqB6j2HjUBiy6iJj3v2PwsgPqUNmVzp6I758VZ10bo2xPiuaiSpNPwgiG/a2vhI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR08MB0847.eurprd08.prod.outlook.com (2a01:111:e400:5a05::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1143.10; Tue, 6 Jun 2017 18:20:07 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:38 +0300 Message-Id: <20170606181948.16238-14-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170606181948.16238-1-rkagan@virtuozzo.com> References: <20170606181948.16238-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::28) To VI1PR08MB0847.eurprd08.prod.outlook.com (2a01:111:e400:5a05::17) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB0847: X-MS-Office365-Filtering-Correlation-Id: 7907a14d-55be-47fe-13b2-08d4ad08a99f X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:ZFejphATjlDjUy03jGiZkq1XzWPw8u8xV3bU6I5PUxa0jSNEZ5i/uwf9IdXVAOsVvss6/a6HhZYTHSYseARPV3lgZWNUOwyc+TPFDBNtxSyB8hMk2o423szCwlRc6DGAQ+FpNXe9KDGxMCdzxN+8eTdkh5LJnKVX4sDsLvHI+HpjPzLAmeJD/YxIxZjNYqRHky+RYiFaL7f8BE3fqgcsgpNHWcldFXQZ9YIFwOZkMxYYrAxQXJbV6pkYvO9RSqjP2OuQszVI8wqcyJf8gn6YdirZWj8et3KKXb+xF2mGA6sYjLcwdR38yZRm3MmsrP7T3u1OphesAwQp4ILLoliC6w==; 25:E4JUdtxrbfUWY4BON9I9I4LQI+WGlxEZ2X2+PKjREY/SHqI14LjQM1BMv66lu818ZDQC9s0PmKSUrjjKS0GYqZ1Spg8vb44VfGlhRiKcHN2+8pkecgm7ceR7DiGCTnQv3FJiizQD2g1R/ZO8oitueRBpOENk3akk/jrKgs5PhpfODVWkryuSJZ+7WJej1HoUo6gNO3pQ27kUY9adXc/nRgixfnnB5nBDcOZINsK2zMqYngPwmUtX8DnVMdaKs6yZ+P1TkN69DxgJ6iJ7XiDpzH9bh6QS/NJkw6os3hXZ1PJJUSAOiSaTCuoNhol0ccWEOEMItAmb+5nYYdC5rUSt/i7Nlf1Yo5Xn7GZ9pc0rEgQ/gR4OpkkGyBCPnUBw43/dwcJ+uBm0H0g864VwTR71cHWwYDZiKrrXS5gjqV9g1S+06yUUqYnu6aeDneFOupClBDKGEJPT4Trsz/Y+sULaH8Ki6qVrv5kKYtOeWlDfXqE= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:bJ6T9bs8/xx5YnxOEGV+3TksujAcz2uxIXsEnPavY3uyQ87XNvNAAG8M2wYG7RPXkSMDXtBUCsPhOFv8JZeBeTPFjhXySyrpIYdNi9L7DlX8c7horUf42Igxq9eiUa0+DpZ4tpHqYRd3ufNK+p9eEXrTTLaxL0Zmewv9m2XoL3q+gk99i/S88pG8SnJMNR0Bs1Hpxvz1aq+7hjqL1p4dCXjyVNJwv7Glhug+t3XEJuQ=; 20:CVWZagDQIF0lioLvDVn8UWSqhPUVJ9zt6q3gAkBQ2Mot6doK5u94JeMBzkHIE7E0pGr18OT0DBhkzzp3OphLNeghWUMJtThgefIE9V0YA6U0P9O/Gju1pUR5FSGFAI/ZanVW73BPTnqNPARW6XLbKRtMKhitEj4nFFeiSFmGoBcORfGVXEwCYFBMrnOwa0VAKSTYIK2Sen46mpnhzv/QVk/TywfyHeClojpVI+2xBXQ7od2UMKOj7C1qQMvaF+e2CkCpNIxMaA3/STMgqNMWjsy8a5DEG6RAS3fv+4oTXiFfu1/ks1pYJADgIuLxENHBvoz4jjaXkegYfJP+tv/zlA/wPwS9w+SNvmjVhQ25AuX7xmUS4zddqX0l+RvBqm36NN034rP7KornISxbjMOBvnfEcEbwq/datNqDkgCZVIk= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123564025)(20161123555025)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR08MB0847; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0847; 4:zP2B6hUmpkuhXsHuHkO38+ZY3bzeJOGppyft8/EK38?= =?us-ascii?Q?cUDEHr8aIyOhjH1X+IzGYuagp5bqeOsmegutMBOGA5jDT1VVnORxtXAIftSl?= =?us-ascii?Q?pv8uFXPOhquorKmDcagfzqG1q6MC+6wk2IMrLYf7RIKCILf1noa0jg9HTSl/?= =?us-ascii?Q?A49YDLU8+1QDn7O9YrxsqesD+PMLPXFdYVIl9V9OrHqtbI3tLIQJVXXjpfaX?= =?us-ascii?Q?o/m4o70uF40H75yKkTAves3FbMEAqEMlvTNU8a4YhPGkykv5haT+4VAdgin2?= =?us-ascii?Q?DXXiA0p98IhH4UFRfFInl/ClzZAYKBymsyd+NELbyzmE71yA2eK7DYlOLoJV?= =?us-ascii?Q?61OSsk/TaVYm4w7rWIfF9Q2Ws6SnIAt3RmSpyZlqFQYiieSB4zmsClbpF12m?= =?us-ascii?Q?DH0Guex966BDk4QJRK6Jea2iv1f3nlGC+yKvDDnCs84xAXiKAB+LnjxIcgJw?= =?us-ascii?Q?FfyU7ZsXtze1VdsHNAQKNYVFpTI0mWUvDYHXwml7IrH93tYsoIbeUkOkBiRE?= =?us-ascii?Q?zL3CCuh8rCULDYM6xQ6r9aKj00E8t7QuwbUI4Z0jIhcjc7PZxjJEq9H+Rvjg?= =?us-ascii?Q?X9E2fWVlk1Iog1ISVpBbrRzJKaseHEOmranraWhj9rWEtyLpTemVO5YQfjjK?= =?us-ascii?Q?gAvy53trl1UX8jd6I3fok0SDlIJoWEwsr4j+gfC+EQR8LIxlCdCmHC2Ptyr2?= =?us-ascii?Q?aJ0hYA5RdcodWly0DxTyoMBRoRmX2oMNTP4jqnnjHJN62cVYIg41bO/PqMtq?= =?us-ascii?Q?v7d9Q6XOIqhrSceg6MeuUXDG6eQGgX8IWqvK3FHsztABQCwZCthCbYFos74F?= =?us-ascii?Q?oYSRRMdcJjF/scOJ41RxHW+qDaUcurBduHCXN35hKl9dDVtEoxZjQ9mZgBl5?= =?us-ascii?Q?R3xoylEtAUpRHP0E1OYtHv3A+8g62af1dyhAgQ/T96JemFexy8oaYxuJGqOV?= =?us-ascii?Q?pH6wWJT0LXoqz6Jme7buXKuhQO2gIDybeY4waw4tHDqynqJtk5W8nVhrZcUe?= =?us-ascii?Q?FsKVvhJ1mwB7vqCzIz33O7VxoPbE5RnIduO7lYX7S603V5ivkvgHSXGbG55O?= =?us-ascii?Q?XbG9T/hIXqbiz4xM6KWaQS3MkGILySagSL8OrFnLm+LjtTg7CGOvg8tPCFRE?= =?us-ascii?Q?YuK/TAstKOFa6Fj86Xfz8bQXfVRdeo?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(48376002)(33646002)(36756003)(47776003)(6486002)(478600001)(5890100001)(66066001)(5003940100001)(2361001)(2906002)(5660300001)(2351001)(50226002)(81166006)(8676002)(25786009)(1076002)(6512007)(6916009)(53416004)(76176999)(42186005)(189998001)(38730400002)(53936002)(4326008)(50986999)(107886003)(7736002)(110136004)(6666003)(6116002)(3846002)(54906002)(2950100002)(86362001)(6506006)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0847; H:rkaganb.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0847; 23:prosTusf9QZL2IHXzwiyzNhIOU1R7bzwx5880ixv6?= =?us-ascii?Q?I2zyWVbcMnGMuW6v6vw71YZsBjCaGZt8u6tjgNo+JpK9/1qD/JMyUZMsnE2O?= =?us-ascii?Q?uJ3+SPSGGwaNiX++B4DB4+W4MqC1QHTN/7dWEEs6Au9+NKSSKayXY7hEfvIM?= =?us-ascii?Q?0rT2F+pARR2g0Z/G0fIYSbsMp7whOreL61SeO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ipadUNfOOXmv6/c8CpzNYirldU9sNyozjovd3Ebn/8o5MJs36VumTexWSWE+gtuQvnGnFZSrrSdKRGUHxBxLVk184AYAKHgQgkBMwhaoXQOxvrTd76xm7nCWI/jnT4imhvZSt2iONlrqABm; 24:ZkcQ+QEmha2QaXll2jQFsvs/h1xnViTnkY26zQ8KV0UeQuN+SqApM4bIooZ7YcxzuyStCz06zQdczR3QeAMjD1KSZczueE8ESBFzf7Ifzbs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:J3WfbkgISoPSx0e95+rjn6CQKv4Mb5BbY4oKmceukvY0WhN4TrPSI8hnCkDlfevEvwcDeIv5JRrDL00UVGo9mOxD7PbeTVyFlBVWuseTWqUGZA+rOws8SqalnCtQwyJqBlo55C4yrb5a5BGukXELlD/tlaEvGcnyd/m8vKwWwLGCZBLwR2Nq8lOZNj3zt6UGJ5s9gsJH0/Zc6Wcum4LRabn0bNmvCDXMtOoYMeToB6Vl4OfDfvJVM2huYa0i7FIulEAAlHCzizqJUJn1FEPNMkmuUZlL1+G3+GpDOlPws0coT7PtJJpQov3fDOyOMXywxA3BQ+cZ690nd0u2qk8GWw==; 20:trSipn+Tng0/X2wQcQdy/FEVb45RM8l4TVWHo0Y0nCeQ9owdke+libDZQsPk1oXyndIhjaESz0KHFFmhek1Bi2ZyNFwHNc5aYSEn38js42qa+EW34LqYBPPhnC7DPQ8WwOaJG54cb2K8CN6dyKr/LE7C5MaLpZQHATzHPxY66Ec= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:07.5857 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0847 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.3.107 Subject: [Qemu-devel] [PATCH 13/23] hyperv: qdev-ify SynIC 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 , Evgeny Yakovlev , Eduardo Habkost , "Denis V . Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make Hyper-V SynIC a device which is attached as a child to X86CPU. For now it only makes SynIC visibile in the qom hierarchy and exposes a few properties which are maintained in sync with the respecitve msrs of the parent cpu. Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 4 ++ target/i386/hyperv.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++- target/i386/kvm.c | 5 ++ target/i386/machine.c | 9 ++++ 4 files changed, 147 insertions(+), 2 deletions(-) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index ca5a32d..9dd5ca0 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -34,4 +34,8 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); uint32_t hyperv_vp_index(X86CPU *cpu); X86CPU *hyperv_find_vcpu(uint32_t vcpu_id); +void hyperv_synic_add(X86CPU *cpu); +void hyperv_synic_reset(X86CPU *cpu); +void hyperv_synic_update(X86CPU *cpu); + #endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index ae67f82..2d9e9fe 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -13,12 +13,27 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include "qapi/error.h" +#include "hw/qdev-properties.h" #include "hyperv.h" #include "hyperv_proto.h" +typedef struct SynICState { + DeviceState parent_obj; + + X86CPU *cpu; + + bool enabled; + hwaddr msg_page_addr; + hwaddr evt_page_addr; +} SynICState; + +#define TYPE_SYNIC "hyperv-synic" +#define SYNIC(obj) OBJECT_CHECK(SynICState, (obj), TYPE_SYNIC) + struct HvSintRoute { uint32_t sint; - X86CPU *cpu; + SynICState *synic; int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; @@ -37,6 +52,37 @@ X86CPU *hyperv_find_vcpu(uint32_t vp_index) return X86_CPU(qemu_get_cpu(vp_index)); } +static SynICState *get_synic(X86CPU *cpu) +{ + SynICState *synic = + SYNIC(object_resolve_path_component(OBJECT(cpu), "synic")); + assert(synic); + return synic; +} + +static void synic_update_msg_page_addr(SynICState *synic) +{ + uint64_t msr = synic->cpu->env.msr_hv_synic_msg_page; + hwaddr new_addr = (msr & HV_SIMP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0; + + synic->msg_page_addr = new_addr; +} + +static void synic_update_evt_page_addr(SynICState *synic) +{ + uint64_t msr = synic->cpu->env.msr_hv_synic_evt_page; + hwaddr new_addr = (msr & HV_SIEFP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0; + + synic->evt_page_addr = new_addr; +} + +static void synic_update(SynICState *synic) +{ + synic->enabled = synic->cpu->env.msr_hv_synic_control & HV_SYNIC_ENABLE; + synic_update_msg_page_addr(synic); + synic_update_evt_page_addr(synic); +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -65,6 +111,7 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) default: return -1; } + synic_update(get_synic(cpu)); return 0; case KVM_EXIT_HYPERV_HCALL: { uint16_t code; @@ -95,10 +142,13 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, HvSintAckClb sint_ack_clb, void *sint_ack_clb_data) { + SynICState *synic; HvSintRoute *sint_route; EventNotifier *ack_notifier; int r, gsi; + synic = get_synic(cpu); + sint_route = g_new0(HvSintRoute, 1); r = event_notifier_init(&sint_route->sint_set_notifier, false); if (r) { @@ -129,7 +179,7 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, sint_route->gsi = gsi; sint_route->sint_ack_clb = sint_ack_clb; sint_route->sint_ack_clb_data = sint_ack_clb_data; - sint_route->cpu = cpu; + sint_route->synic = synic; sint_route->sint = sint; sint_route->refcount = 1; @@ -183,3 +233,80 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route) { return event_notifier_set(&sint_route->sint_set_notifier); } + +static Property synic_props[] = { + DEFINE_PROP_BOOL("enabled", SynICState, enabled, false), + DEFINE_PROP_UINT64("msg-page-addr", SynICState, msg_page_addr, 0), + DEFINE_PROP_UINT64("evt-page-addr", SynICState, evt_page_addr, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void synic_realize(DeviceState *dev, Error **errp) +{ + Object *obj = OBJECT(dev); + SynICState *synic = SYNIC(dev); + + synic->cpu = X86_CPU(obj->parent); +} + +static void synic_reset(DeviceState *dev) +{ + SynICState *synic = SYNIC(dev); + synic_update(synic); +} + +static void synic_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->props = synic_props; + dc->realize = synic_realize; + dc->reset = synic_reset; + dc->user_creatable = false; +} + +void hyperv_synic_add(X86CPU *cpu) +{ + Object *obj; + + if (!cpu->hyperv_synic) { + return; + } + + obj = object_new(TYPE_SYNIC); + object_property_add_child(OBJECT(cpu), "synic", obj, &error_abort); + object_unref(obj); + object_property_set_bool(obj, true, "realized", &error_abort); +} + +void hyperv_synic_reset(X86CPU *cpu) +{ + if (!cpu->hyperv_synic) { + return; + } + + device_reset(DEVICE(get_synic(cpu))); +} + +void hyperv_synic_update(X86CPU *cpu) +{ + if (!cpu->hyperv_synic) { + return; + } + + synic_update(get_synic(cpu)); +} + +static const TypeInfo synic_type_info = { + .name = TYPE_SYNIC, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SynICState), + .class_init = synic_class_init, +}; + +static void synic_register_types(void) +{ + type_register_static(&synic_type_info); +} + +type_init(synic_register_types) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index eb9cde4..433c912 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -688,6 +688,9 @@ static int hyperv_handle_properties(CPUState *cs) } env->features[FEAT_HYPERV_EAX] |= HV_SYNTIMERS_AVAILABLE; } + + hyperv_synic_add(cpu); + return 0; } @@ -1065,6 +1068,8 @@ void kvm_arch_reset_vcpu(X86CPU *cpu) for (i = 0; i < ARRAY_SIZE(env->msr_hv_synic_sint); i++) { env->msr_hv_synic_sint[i] = HV_SINT_MASKED; } + + hyperv_synic_reset(cpu); } } diff --git a/target/i386/machine.c b/target/i386/machine.c index eb00b19..8022c24 100644 --- a/target/i386/machine.c +++ b/target/i386/machine.c @@ -7,6 +7,7 @@ #include "hw/i386/pc.h" #include "hw/isa/isa.h" #include "migration/cpu.h" +#include "hyperv.h" #include "sysemu/kvm.h" @@ -633,11 +634,19 @@ static bool hyperv_synic_enable_needed(void *opaque) return false; } +static int hyperv_synic_post_load(void *opaque, int version_id) +{ + X86CPU *cpu = opaque; + hyperv_synic_update(cpu); + return 0; +} + static const VMStateDescription vmstate_msr_hyperv_synic = { .name = "cpu/msr_hyperv_synic", .version_id = 1, .minimum_version_id = 1, .needed = hyperv_synic_enable_needed, + .post_load = hyperv_synic_post_load, .fields = (VMStateField[]) { VMSTATE_UINT64(env.msr_hv_synic_control, X86CPU), VMSTATE_UINT64(env.msr_hv_synic_evt_page, X86CPU),