From patchwork Tue Feb 6 20:30:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204083 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 8C9AB601A1 for ; Tue, 6 Feb 2018 20:57:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81C2C28D71 for ; Tue, 6 Feb 2018 20:57:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 762E128D97; Tue, 6 Feb 2018 20:57:42 +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 8000528DB4 for ; Tue, 6 Feb 2018 20:57:41 +0000 (UTC) Received: from localhost ([::1]:33255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAJA-0002YN-4s for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 15:57:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9tm-0000hB-9Z for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9ti-000355-Sx for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:26 -0500 Received: from mail-db5eur01on0117.outbound.protection.outlook.com ([104.47.2.117]:9120 helo=EUR01-DB5-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 1ej9ti-00034X-EB for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:22 -0500 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=Iubieyzf+yvFEMw6IHwaWTU0oKVPkp8e9779DXMvWFQ=; b=R4/MQhCz7U8kvFqcYLwa9U08Nc1HMK8nlxIL5tNMoXU9EMuoYyxG+pXFb169oI/DtzDpzXj9xu0gU9XpTrWHW9cl/Bh1+SD66r3/xB35l7SIbreUY2fxie/3Upi4gta59l43ew2KP2ZiTHEHEuAarK/AnTorckwSdo8QxQ07ONo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 20:31:17 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:22 +0300 Message-Id: <20180206203048.11096-9-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180206203048.11096-1-rkagan@virtuozzo.com> References: <20180206203048.11096-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0301CA0008.eurprd03.prod.outlook.com (2603:10a6:3:76::18) To VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4ffb6a8c-ef60-4b99-eb05-08d56da094a0 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB1983; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 3:mCwb0gzN6L1A4WVMatyaBaJlubs1zU1DjiufG1G8SbQJVCZljwsuHSpjnXshzseMhkgy0FgRcRNOn3d7aOXexV6Pfgo6aWwYVoiK6T1ZxoBBn45PqxsClP72mUjxZIF7LaGpXFeU90vL7q9rJcChaadU71d15z8nutugqXdDpCb1DjJ0eTsyVrEmXXakUy4i5dBlaHCM5+AQtcJiFjgEihfrWYJ+P9CUJ2p9HpVv6pXuAXcM6GRNwzrOcXjVGg/1; 25:gddUmyGGFVQ17xO1Kce4JgMoDu/W24GaADNZjfvvHSusjuaaJ6zYWbsY6TARnDG9e1WfMlFrCYSG1ryeowRtBHk4J8wyxn44JIvLVwsl7qYU9oS6lIvFIxyG8NdE8K8pzRhozgIOh3yYvT0OlGK0ssuK2lq6aYHKbr+KZfL0UTzzzbyexQRodxnSKvnTVx8nvjvq52B6P/RdAccXdA6XY+c45pIja5ilHpklZ5881jX3z1d7T8xs8szbxj2UIyZuj1aJQvrAZMD67tLnVEi47VULN05VKZ8h1epGFoOD/fGK7alpFhOFGBSROSDbPse19cagstFpwTh/Nf/6879tQg==; 31:dDG8O+A3f3HFkGWJkG82EOwN4ScmUHM3gCK6Rjcinab7Dg9Vn8nSmviOrpI9z4oglZ5GaunqtlgQlz/MHimQWIYfCwp2v51WhWcNVDM6YrTrkWZ8a1c00GEqdd7sqrlbeda6vNgzzkLrofQpqSZtg0WT9p8yCAOICzVBjHDJuoTQN5P25uVP5cW8S/jt6BCtlndgfw6f86laKdjO3SHrFVFpwhiYBovW36PIOIqPu3c= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:g+KvSGYIb56hNj4RSnPzP7hppxNwwXXbSu2QrAfKBYnAJto6wUhPSIPfE9M/RpUdxq/6V7TzAetk+uvhXV9kw0ggF05ouj1/QSGzDfQ3mplLAs83HqawJU4SIOOrYQ33E2KFCjBXAlW9roIDA/dhSEqYUwF7etaeZoOZM+obkqlqviOfgnYEUc/IeHJZl0IIieLlvYBWPYSeKubx8tPovv9kQu2ZVSFDKqZWS7SiYEn8H0F+oE0e/2OrLQmSLqb+9mHAGjEeWjhdoBWcA3ttOZ3ZgOYYlg/AhCoNVrfvnhTjUHNMw5FQ46PBTJ7FjXDbMIFFGhs4zfAQ1NWUs3x8pGx0pO3jsGe+huYiB37+vuP6gYuf+oHKxKtZ6fomBlZ7xYmx6ZafjrMzxa/GVv7kye0TxJNiVRKZhQNWGOUORzA=; 4:TmrUAnnzSf8jLI4/zCPoYapgOU16gNCawKeJLcAoUg/og0BZfdPGO8dubyjAWRJYycTmwA8JH0IQpXduUuEp6W7paVV65bJKSrSN0o4EHVr2fgnUSwQ02NSs3QK6wsVMqPidcpTYk4pG2XB/22xWKlaP7ytwtYt97BhONr8XxKywzaiIplUWZwcpMX5KLu1Y7aZmHeYjRhfZd3vl7yY4dAZHCJ7xG+YoSxjoXaD8tlJfyB4GupoDIalqtMgc7NhTASVuBg8N7KZI8y5q3TfESg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231101)(2400082)(944501161)(10201501046)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0801MB1983; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1983; X-Forefront-PRVS: 0575F81B58 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(366004)(376002)(39380400002)(39850400004)(346002)(189003)(199004)(16586007)(53936002)(305945005)(54906003)(7736002)(3846002)(316002)(105586002)(2361001)(106356001)(2351001)(6116002)(5890100001)(1076002)(50226002)(8936002)(81156014)(5660300001)(8676002)(81166006)(7416002)(2950100002)(6666003)(6916009)(76176011)(86362001)(68736007)(66066001)(16526019)(47776003)(50466002)(4326008)(97736004)(26005)(6512007)(51416003)(2906002)(52116002)(386003)(6506007)(59450400001)(48376002)(55236004)(36756003)(53416004)(69596002)(6486002)(478600001)(186003)(25786009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1983; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1983; 23:G9+++HZ34oTGUOly/+wlF0O1EhHfDAXNEPKfaKy?= =?us-ascii?Q?AaIHdThq/EzGAGkJ7KvEt5eeHmX0hRf6/80KNbHDIYW5R9cWnuaq3EJKApe+?= =?us-ascii?Q?qUmNvSZNfLpGTMjC7E4huqL+SLqfBsDEdmfiAXkBOm1f/LJwyt/5F/+Xf8rH?= =?us-ascii?Q?iNEPCS4JLcnZ6GmwC1LxzzkN4dWIUx4EGaQeo/uUzknWqBksgwxoAjjbkKr3?= =?us-ascii?Q?QhdEfwFira0TyA0z8wu/SMGrBaLPFIMDR3PacOVWElS6wubi9dmpayjhf2fl?= =?us-ascii?Q?domGbqWlJVl4Nzy7Y5fP7nEcDqdNR88gNOyXUGuIEYHqtJ3EmpF62ftB2HFh?= =?us-ascii?Q?ZecgVvD1k2huTUmxKN7ZpvoVEAKfH33d0GcYlmJPwxruPFRbbYbgoAt5YJBU?= =?us-ascii?Q?SbxxWw0QgO8QFiqsjbcR9H66gmNtUUpI0mKIfjUskLmVZzbr7uJ17/KdzT7+?= =?us-ascii?Q?Q8TWPUA00oSsTtfVmt38Y/4lnn2xKv8cjtlbxeGaqdDqQPPJt0cy7k2v1T+0?= =?us-ascii?Q?5d9TpAiaCLKHSt2uctXg3UsNy4gqnAeNavT44gizm3KN/rcZaM9EbgIf30C1?= =?us-ascii?Q?W6TNxIqYxsAHpmX6NgHJkQWBJ36GCs3c6qtAH4TV7wePfNv+w712W7Rtf/Ry?= =?us-ascii?Q?rEN08tTEkG3a6bgMSNJQOiAd2lI5AtqdEe8K0dSiLmOzcseYaJl5MoL4gxh4?= =?us-ascii?Q?+I5DkXI0UnIlPIt1XS3nRY9CSfp0opfu+ULDK5xr01IlsIwP/c5AI3PD6Qol?= =?us-ascii?Q?QNZUtc5QI8qfT8KaOFo7xMHHIZkDO5M4ZOQrrux0xCh1btyuWibn6IJLQGQ7?= =?us-ascii?Q?icvAS6/GxaKtJ/goMjCs3eUmv4fBqQM+azYPBkC+HhbvWKNjGVcnVitvc1nn?= =?us-ascii?Q?f1zp393jWe8kXu5dmkl/OEPtcpS/9rT1qg89gNmJFuZs0gRj3ScHBBQn/vrc?= =?us-ascii?Q?xEWZZ9o3W1ssZ0HbrubpJM+sAWlvLjzUa+75r4z+QP4pw+1/qojtkZ4aIWbQ?= =?us-ascii?Q?PzqleK89iMFP44a9z0kGhe6jqnb3kW4aSpPsUkv43/DJz2Jzkzds00LidgjT?= =?us-ascii?Q?L6GP9I1hcvibGjw+lIoUZGL2qCzavmSpAdj3I7o9/jNAUbNsmkVHi3Sd14o0?= =?us-ascii?Q?CJ3zraQwJKLLzNN9bVtip9paZ7T7ygLPWmXhOko7jqrab5AfB8CHjsyD2mDq?= =?us-ascii?Q?L/CDRcBGm28xiYArOBw6LQWC8vENXfuVuephIygMBFIemx5Z4nPBwjWfnhv5?= =?us-ascii?Q?ME8MEfxTYwAY1ROrDhbXeppuaWReVtFiX4DmvIaIaCb2diG3SLBb9KIOn12d?= =?us-ascii?Q?uYQKkD/sWlpSxFqYMCjjw1wYB6/+16lIdWcj7atpR51DL?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:kbPexzHrBg/fdN3A767FbQREhjgDl3oTc3r1Zhz4gX3i6HmzR1V8hYAB4u/v40mFW3UjSNbadvUmL4J2XOQFz1qEwIsvSgGEZzdms5wihBYKMo65Fd5l0QSDQ9Pt/gtt/Li5eERP0qnazmHz4zRj1wjic47OeU/HntulT95zoY5iCGGQoV0sJ4mbbnOXGwjg6srl6CkR4IwjOPnmVLhmeK7m1fGtRfObOPW+/AqPXEKTxprpyU9K4dl8+FLxAnpssQUWE7BBF9kzPNUy4GCL+gb6ESymljNoSBjqlqtb20xg6IGsSHcukNwAtri1rMhvDcyrWmrCuOh2DSpCho+p8FnwczrP6shg+dD2tQsUUjQ=; 5:cmumNAf+ufJ5hhx2WjlOYWiU+ORJQCEwnzYmrho27G7wT6oZlg39WDovLtecGDnxjoM72TKYz79fQJY6Vtei8mwyBAKq4AKEa9nt3dsa93Iv3OeT2rdZG1eI07ON6L777Vyfap3A/cUY7pdKlQBvBzNJysd9ouims7j+OUyiec0=; 24:5B90ZiyFlyuIRSeVoEh+MpdpJEgBL4hkEGzKg0V3BVDgTYWHI3zvXu2mgTl6003rPY1yUKd115JouH2nJ2416tuQ5EzzTiWE64+3J/uibdc=; 7:l0kenCyDU48nX+dw9N3iwMT012Cnl2+Lh3lQFIVnr5PR22OVCOfYD7Q5hdkuDxYoLaftF3C9UMnzzhck3qHdLOKYXQ/JIgLyHtoH8GlVUPBLKOIeYtdcDglYjjo1Wt2ISheEDaRug5gHRca3s/RpLO2FJPdoofawIU9GcwuuwD3fSN+U0q+GGNjFPJjFtOpDFTgsi5Rhzfx64aOsdMfvA2g3qoOXz8C7jWau/ljyrRy9FOdmCq/G/bP+jtoVtH32 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:MehhxFYsZLczYN/DGuOTpWpjZvT6nLs3fWia5erRADnkt0CvJmH3VQuXauGXRfLhe76X981dntTjqGHfWHymrnXUXuAZC0zTQ94pJHIfkJS0tXBRwnVb7/Dtyu1L+fsJ3oIu1rvmhaesi2h6Jp6mZEgyHZstIgFQIJmsTtQHhe4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:17.1842 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4ffb6a8c-ef60-4b99-eb05-08d56da094a0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1983 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.117 Subject: [Qemu-devel] [RFC PATCH 08/34] hyperv: qom-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: Ben Warren , Konrad Rzeszutek Wilk , Krish Sadhukhan , "Marcos E. Matsunaga" , Jan Dakinevich , Vadim Rozenfeld , "Denis V. Lunev" , si-wei liu , Paolo Bonzini , Vitaly Kuznetsov , Cathy Avery 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 maintains its internal fields in sync with the respecitve msrs of the parent cpu (the fields will be used in followup patches). Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 4 ++ target/i386/hyperv.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++- target/i386/kvm.c | 14 ++++++- target/i386/machine.c | 9 ++++ 4 files changed, 134 insertions(+), 4 deletions(-) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index af5fc05ea4..20bbd7bb29 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 vp_index); +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 4d8ef6f2da..a27d33acb3 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,6 +142,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, HvSintAckClb sint_ack_clb, void *sint_ack_clb_data) { + SynICState *synic; HvSintRoute *sint_route; EventNotifier *ack_notifier; int r, gsi; @@ -105,6 +153,8 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, return NULL; } + synic = get_synic(cpu); + sint_route = g_new0(HvSintRoute, 1); r = event_notifier_init(&sint_route->sint_set_notifier, false); if (r) { @@ -135,7 +185,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, 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; @@ -189,3 +239,60 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route) { return event_notifier_set(&sint_route->sint_set_notifier); } + +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->realize = synic_realize; + dc->reset = synic_reset; + dc->user_creatable = false; +} + +void hyperv_synic_add(X86CPU *cpu) +{ + Object *obj; + + 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) +{ + device_reset(DEVICE(get_synic(cpu))); +} + +void hyperv_synic_update(X86CPU *cpu) +{ + 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 dfce60e5cf..84c5cc2131 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -665,8 +665,7 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_VP_RUNTIME_AVAILABLE; } if (cpu->hyperv_synic) { - if (!has_msr_hv_synic || - kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0)) { + if (!has_msr_hv_synic) { fprintf(stderr, "Hyper-V SynIC is not supported by kernel\n"); return -ENOSYS; } @@ -717,6 +716,15 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } + if (cpu->hyperv_synic) { + if (kvm_vcpu_enable_cap(CPU(cpu), KVM_CAP_HYPERV_SYNIC, 0)) { + fprintf(stderr, "failed to enable Hyper-V SynIC\n"); + return -ENOSYS; + } + + hyperv_synic_add(cpu); + } + return 0; } @@ -1107,6 +1115,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 361c05aedf..8c4baa2f79 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" @@ -653,11 +654,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),