From patchwork Fri Sep 21 08:20:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609351 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 EF3B51390 for ; Fri, 21 Sep 2018 08:51:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC5CF2DB2F for ; Fri, 21 Sep 2018 08:51:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CED4B2DB3F; Fri, 21 Sep 2018 08:51:51 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 983512DB2F for ; Fri, 21 Sep 2018 08:51:50 +0000 (UTC) Received: from localhost ([::1]:54562 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HAD-0001pg-Qu for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 04:51:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3GgO-0005Je-Bf for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:21:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3GgM-0006LB-C8 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:21:00 -0400 Received: from mail-am5eur02on0701.outbound.protection.outlook.com ([2a01:111:f400:fe07::701]:6116 helo=EUR02-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 1g3GgM-0006Hi-15 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:20:58 -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:X-MS-Exchange-SenderADCheck; bh=HlzwDhsh3G7QEWnbeCp1nzOadbCyF2DnMVqzazKEfXE=; b=YOABhFgxXubo+lScRKN50w9XEBHWVcpgY+zAV+RHa7++ARbBj/S0ShnDjWic7lEMIQl4t3U8asu165yg8pQK/Wr6BW7C9IOedIhj00+D3oSOyIFLVgYLkurYqDEJuJBCXQhlY/6n9+D1DPM292Bx7RxNsO1EJPu1C+LFLXU1wQw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3585.eurprd08.prod.outlook.com (2603:10a6:208:e1::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:20:53 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:20:39 +0300 Message-Id: <20180921082041.29380-4-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082041.29380-1-rkagan@virtuozzo.com> References: <20180921082041.29380-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: DB6P18901CA0005.EURP189.PROD.OUTLOOK.COM (2603:10a6:4:16::15) To AM0PR08MB3585.eurprd08.prod.outlook.com (2603:10a6:208:e1::26) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f3c46c78-bd71-4ba9-5e32-08d61f9b2671 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3585; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3585; 3:KDYoIOClPt8FDOh2yqNPrW4BSILCDbWLrKpf1xSgvesI5d+6jztOmZEEoNE7+Rhi9/TKG0F7l5vbOJYoZHwKor62yI1Y/T7FF75O/zMyKYiqAiG7gLlS/p/dkPHSvzcoF8QqWzwacC85wxgKWVOO54/5YxQMP+Kcxq05uI1x0O/R5cx9RN9LfYnNOv+gYk6DXXuSSHxXqjqZURRTbniGYEidmAtQkHiw3Qx7F1FxTVYGd256f0Tyy+QaBZaMrdEa; 25:T6z0iTQ2vmT+bdBccww65aZ1bNx3cMQYyvVtfMFdGvEmz4vJoJ0lX0s2Do+ipbulbkiapvqsBwjclIuQ6vSX6Q8sNGALT39XjzAFbtYx//HuHF7LgYH4Ai8nGKlNDA4IYj/MPptL7VWgQA7nqvj68zyE/zHNfHkxRBOzV6vOjNLdRvQwVSURVL42xLNfosbtZagpgSXLVCGrj3CU5srhU4aixUobJub4WJO/cbto9DNpdC0j26v4pcXr60J5GN4BTyDBCE/R8DgvWaOdX8lICVbxDTUYcA6LdPluR8VfLQWTo7pZFZughWbbVnNWEQ+egXD1Ah5XBseaMhtKSldEUg==; 31:ThYByILqGSjtP0/9yYtoyFEgO1+SmolbN2mRhj/0SU9dlB1V5AN5aLekoD/CHe9EUAZVe0ee9ULqF7qaJvpHoDGf3kMYdty5xd1MfluQnyPY2S0f3bAlIfyWMcVHpJ4mvTAEDXIIhb4zgFKPTDORv6pl1+N2zl30YW8FxMe4XTS3Omc9UdyHBvbM5ldj3KuFaJuqictBE5RKXzALyjfatHhhClrAbh9YYXCa9y9AV3s= X-MS-TrafficTypeDiagnostic: AM0PR08MB3585: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3585; 20:wTOhIOYIJsvSCkC0uH74JvCBhVZcpgKEgM5DtsKuh8DePvjmABw1o/qv9eOHaWlLDaoyxR/kCrKXt4l5lA13ZUE+H+ULhn/kW6Xxp6iOj7RpicDq6gFcqm3SCjZF57ajVoFvQtTRDALDtnEldh3T/R3IZvqiQs9Xb7iqifQqoe6g4r9DfJu2JSkcHDx7o6nnF9g8owGgkjpEfIPD6NPV3yzYW/7PbszPT7Z7eDzLA+lZyDCZ/KExv+EUFJEvBatEHufe3NC9+f2CA7/IBEUUwnTuaTLg2LuygpIm5ZFyR4dC/IrD4fe0YoDrilapmeatBIw+jgFCzgOJ7EH41kGhm4vdja0g/63RMg4znY9ncMVEPE3dxmBUzsr4m+/QCvbw80jXvX1VZQE3OhIp5COH1yP/kD4xEHiR3/lXolY8LuwZ0GEo0WRkD7oYc9Q3HmuSc+vASiOHmff/Mg4eE91Gdka6ifG8JxUz5T8TUJlJoq5LKIDFfmxFNTdLkEn4I7P3; 4:FQ1JDI7ld/nb+pXJtsymhz/bnYmxq/dqv+y7rbBvzK1EmddYjtLelEaYpH//6Ha65my8cp+LysZ+4ZQM1DzcG5C2vK1UAEN33ok4Y8tS1ZxQcezKpPXy3hNpIIM51x3UAxxf9Xy1ixe9jok+zQxY51hWrNAcMx+EZ+d5GcDg/No/t7+C3WYa8XppwoHzZMTkdLhk4o8cn8qFb1o68s10YyMwJcnl/LiNX2mJ03dmT3bgrOi+DG3VsO6mazpc2U1OIeKfii5lNFxfuUvGwXetfw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3231355)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3585; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3585; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(376002)(346002)(366004)(396003)(136003)(39850400004)(189003)(199004)(86362001)(6666003)(4326008)(2906002)(16586007)(7736002)(305945005)(50466002)(50226002)(16526019)(52116002)(51416003)(478600001)(6506007)(956004)(2616005)(8676002)(186003)(476003)(6916009)(54906003)(3846002)(48376002)(25786009)(6116002)(26005)(2351001)(386003)(316002)(47776003)(53936002)(5660300001)(36756003)(7416002)(105586002)(11346002)(66066001)(446003)(486006)(1076002)(6512007)(6486002)(68736007)(53416004)(81166006)(2361001)(97736004)(76176011)(8936002)(106356001)(81156014)(69596002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3585; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3585; 23:ECj/xcsRaDlxZTGd8sb2LjoXYJuMUaQBLOeYoN42b?= iEIk/d9eiws2+cWWtCoEGy/9W4YcK7ihodTuCbUDka/dgXtF/0LN5Cg5+Zt5Q0sfJFIfu9DzNa0NYRr11tsj7XjXoKMj2T0ybueyGzBx4E/SO/bGX7by1pH7yq/5aha/v2O02M3GssPwi2LMEBkQBxnqMDywEK1xVdNEELKN9Z8WdgZcNz86XqPGrhy7h6kfHXrphD4SRqwgbqur49lvrRqzDO7dYAB+elLR2vcO7LqerDmSRbWAqjqumJiO/lVf96e5ZndmBrM4OaILqQevzZxt8SG8FhR45PS6bsHF+8nbHUwsdcSnsEqaGCyq1fBu1IIGJU9lENzkp/02nXP8L5q5b/fYBVAaerVKFdu8ENNW2qTmh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3SQHm1P0Ge9YILv5Qc/fSvMzFr8Hy8CFfkjCebzBufd2HYOwrcByuO3mMwLZzlCcbRu9oQp8ylU06tJw+GHp+ SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3585; 20:/489zVFyv0sYlCeQAhHyVLgKhAq4lBbbohKouWkkM/xlpSW23LEzeeSRyXbhvZBxPQhgSPnZ+N8xTD6HM/lG0M4ayZAdJTX04E1Zu1i3up6hgY7zou927EGNKh2S/ZFVzXdlQOi2EoZ77ztmNkdYOOnuago+Z2U4dGBSgy24Kww= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:20:53.4001 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f3c46c78-bd71-4ba9-5e32-08d61f9b2671 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3585 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe07::701 Subject: [Qemu-devel] [PATCH 3/5] hyperv: factor out arch-independent API into hw/hyperv 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP A significant part of hyperv.c is not actually tied to x86, and can be moved to hw/. This will allow to maintain most of Hyper-V and VMBus target-independent, and to avoid conflicts with inclusion of arch-specific headers down the road in VMBus implementation. Also this stuff can now be opt-out with CONFIG_HYPERV. Signed-off-by: Roman Kagan --- {target/i386 => include/hw/hyperv}/hyperv.h | 21 ++-- target/i386/hyperv.h | 17 +-- {target/i386 => hw/hyperv}/hyperv.c | 76 ++---------- hw/misc/hyperv_testdev.c | 2 +- target/i386/hyperv.c | 127 +------------------- target/i386/kvm.c | 5 +- hw/Makefile.objs | 1 + hw/hyperv/Makefile.objs | 1 + 8 files changed, 28 insertions(+), 222 deletions(-) copy {target/i386 => include/hw/hyperv}/hyperv.h (59%) copy {target/i386 => hw/hyperv}/hyperv.c (65%) create mode 100644 hw/hyperv/Makefile.objs diff --git a/target/i386/hyperv.h b/include/hw/hyperv/hyperv.h similarity index 59% copy from target/i386/hyperv.h copy to include/hw/hyperv/hyperv.h index 8d4619c078..d6c8d78353 100644 --- a/target/i386/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -1,27 +1,20 @@ /* - * QEMU KVM Hyper-V support + * Hyper-V guest/hypervisor interaction * - * Copyright (C) 2015 Andrey Smetanin - * - * Authors: - * Andrey Smetanin + * Copyright (c) 2015-2018 Virtuozzo International GmbH. * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. - * */ -#ifndef TARGET_I386_HYPERV_H -#define TARGET_I386_HYPERV_H +#ifndef HW_HYPERV_HYPERV_H +#define HW_HYPERV_HYPERV_H -#include "cpu.h" -#include "sysemu/kvm.h" +#include "cpu-qom.h" typedef struct HvSintRoute HvSintRoute; typedef void (*HvSintAckClb)(void *data); -int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); - HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, HvSintAckClb sint_ack_clb, void *sint_ack_clb_data); @@ -30,9 +23,9 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route); int hyperv_sint_route_set_sint(HvSintRoute *sint_route); -static inline uint32_t hyperv_vp_index(X86CPU *cpu) +static inline uint32_t hyperv_vp_index(CPUState *cs) { - return CPU(cpu)->cpu_index; + return cs->cpu_index; } #endif diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 8d4619c078..5c49251ecb 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -16,23 +16,8 @@ #include "cpu.h" #include "sysemu/kvm.h" - -typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); +#include "hw/hyperv/hyperv.h" int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); -HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); -void hyperv_sint_route_ref(HvSintRoute *sint_route); -void hyperv_sint_route_unref(HvSintRoute *sint_route); - -int hyperv_sint_route_set_sint(HvSintRoute *sint_route); - -static inline uint32_t hyperv_vp_index(X86CPU *cpu) -{ - return CPU(cpu)->cpu_index; -} - #endif diff --git a/target/i386/hyperv.c b/hw/hyperv/hyperv.c similarity index 65% copy from target/i386/hyperv.c copy to hw/hyperv/hyperv.c index 68816642c9..97db87561e 100644 --- a/target/i386/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -1,24 +1,20 @@ /* - * QEMU KVM Hyper-V support + * Hyper-V guest/hypervisor interaction * - * Copyright (C) 2015 Andrey Smetanin - * - * Authors: - * Andrey Smetanin + * Copyright (c) 2015-2018 Virtuozzo International GmbH. * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. - * */ #include "qemu/osdep.h" #include "qemu/main-loop.h" -#include "hyperv.h" -#include "hyperv-proto.h" +#include "sysemu/kvm.h" +#include "hw/hyperv/hyperv.h" struct HvSintRoute { uint32_t sint; - X86CPU *cpu; + CPUState *cs; int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; @@ -27,57 +23,11 @@ struct HvSintRoute { unsigned refcount; }; -static X86CPU *hyperv_find_vcpu(uint32_t vp_index) -{ - X86CPU *cpu = X86_CPU(qemu_get_cpu(vp_index)); - assert(hyperv_vp_index(cpu) == vp_index); - return cpu; -} - -int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) +static CPUState *hyperv_find_vcpu(uint32_t vp_index) { - CPUX86State *env = &cpu->env; - - switch (exit->type) { - case KVM_EXIT_HYPERV_SYNIC: - if (!cpu->hyperv_synic) { - return -1; - } - - /* - * For now just track changes in SynIC control and msg/evt pages msr's. - * When SynIC messaging/events processing will be added in future - * here we will do messages queues flushing and pages remapping. - */ - switch (exit->u.synic.msr) { - case HV_X64_MSR_SCONTROL: - env->msr_hv_synic_control = exit->u.synic.control; - break; - case HV_X64_MSR_SIMP: - env->msr_hv_synic_msg_page = exit->u.synic.msg_page; - break; - case HV_X64_MSR_SIEFP: - env->msr_hv_synic_evt_page = exit->u.synic.evt_page; - break; - default: - return -1; - } - return 0; - case KVM_EXIT_HYPERV_HCALL: { - uint16_t code; - - code = exit->u.hcall.input & 0xffff; - switch (code) { - case HV_POST_MESSAGE: - case HV_SIGNAL_EVENT: - default: - exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; - return 0; - } - } - default: - return -1; - } + CPUState *cs = qemu_get_cpu(vp_index); + assert(hyperv_vp_index(cs) == vp_index); + return cs; } static void kvm_hv_sint_ack_handler(EventNotifier *notifier) @@ -95,10 +45,10 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, HvSintRoute *sint_route; EventNotifier *ack_notifier; int r, gsi; - X86CPU *cpu; + CPUState *cs; - cpu = hyperv_find_vcpu(vp_index); - if (!cpu) { + cs = hyperv_find_vcpu(vp_index); + if (!cs) { return NULL; } @@ -132,7 +82,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->cs = cs; sint_route->sint = sint; sint_route->refcount = 1; diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 8654b13d76..02ef606469 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -15,7 +15,7 @@ #include "qemu/queue.h" #include "hw/qdev.h" #include "hw/isa/isa.h" -#include "target/i386/hyperv.h" +#include "hw/hyperv/hyperv.h" typedef struct TestSintRoute { QLIST_ENTRY(TestSintRoute) le; diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 68816642c9..1eac727774 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -12,28 +12,10 @@ */ #include "qemu/osdep.h" -#include "qemu/main-loop.h" #include "hyperv.h" +#include "hw/hyperv/hyperv.h" #include "hyperv-proto.h" -struct HvSintRoute { - uint32_t sint; - X86CPU *cpu; - int gsi; - EventNotifier sint_set_notifier; - EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; - void *sint_ack_clb_data; - unsigned refcount; -}; - -static X86CPU *hyperv_find_vcpu(uint32_t vp_index) -{ - X86CPU *cpu = X86_CPU(qemu_get_cpu(vp_index)); - assert(hyperv_vp_index(cpu) == vp_index); - return cpu; -} - int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -79,110 +61,3 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } } - -static void kvm_hv_sint_ack_handler(EventNotifier *notifier) -{ - HvSintRoute *sint_route = container_of(notifier, HvSintRoute, - sint_ack_notifier); - event_notifier_test_and_clear(notifier); - sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); -} - -HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) -{ - HvSintRoute *sint_route; - EventNotifier *ack_notifier; - int r, gsi; - X86CPU *cpu; - - cpu = hyperv_find_vcpu(vp_index); - if (!cpu) { - return NULL; - } - - sint_route = g_new0(HvSintRoute, 1); - r = event_notifier_init(&sint_route->sint_set_notifier, false); - if (r) { - goto err; - } - - ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; - if (ack_notifier) { - r = event_notifier_init(ack_notifier, false); - if (r) { - goto err_sint_set_notifier; - } - - event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); - } - - gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); - if (gsi < 0) { - goto err_gsi; - } - - r = kvm_irqchip_add_irqfd_notifier_gsi(kvm_state, - &sint_route->sint_set_notifier, - ack_notifier, gsi); - if (r) { - goto err_irqfd; - } - 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->sint = sint; - sint_route->refcount = 1; - - return sint_route; - -err_irqfd: - kvm_irqchip_release_virq(kvm_state, gsi); -err_gsi: - if (ack_notifier) { - event_notifier_set_handler(ack_notifier, NULL); - event_notifier_cleanup(ack_notifier); - } -err_sint_set_notifier: - event_notifier_cleanup(&sint_route->sint_set_notifier); -err: - g_free(sint_route); - - return NULL; -} - -void hyperv_sint_route_ref(HvSintRoute *sint_route) -{ - sint_route->refcount++; -} - -void hyperv_sint_route_unref(HvSintRoute *sint_route) -{ - if (!sint_route) { - return; - } - - assert(sint_route->refcount > 0); - - if (--sint_route->refcount) { - return; - } - - kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, - &sint_route->sint_set_notifier, - sint_route->gsi); - kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - if (sint_route->sint_ack_clb) { - event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); - event_notifier_cleanup(&sint_route->sint_ack_notifier); - } - event_notifier_cleanup(&sint_route->sint_set_notifier); - g_free(sint_route); -} - -int hyperv_sint_route_set_sint(HvSintRoute *sint_route) -{ - return event_notifier_set(&sint_route->sint_set_notifier); -} diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 0b2a07d3a4..892d4f46c1 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -773,7 +773,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) } assert(ret == 1); - if (msr_data.entries[0].data != hyperv_vp_index(cpu)) { + if (msr_data.entries[0].data != hyperv_vp_index(CPU(cpu))) { error_report("kernel's vp_index != QEMU's vp_index"); return -ENXIO; } @@ -1937,7 +1937,8 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, HV_X64_MSR_VP_RUNTIME, env->msr_hv_runtime); } if (cpu->hyperv_vpindex && hv_vpindex_settable) { - kvm_msr_entry_add(cpu, HV_X64_MSR_VP_INDEX, hyperv_vp_index(cpu)); + kvm_msr_entry_add(cpu, HV_X64_MSR_VP_INDEX, + hyperv_vp_index(CPU(cpu))); } if (cpu->hyperv_synic) { int j; diff --git a/hw/Makefile.objs b/hw/Makefile.objs index a19c1417ed..b8f4675219 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -9,6 +9,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += cpu/ devices-dirs-$(CONFIG_SOFTMMU) += display/ devices-dirs-$(CONFIG_SOFTMMU) += dma/ devices-dirs-$(CONFIG_SOFTMMU) += gpio/ +devices-dirs-$(CONFIG_SOFTMMU) += hyperv/ devices-dirs-$(CONFIG_SOFTMMU) += i2c/ devices-dirs-$(CONFIG_SOFTMMU) += ide/ devices-dirs-$(CONFIG_SOFTMMU) += input/ diff --git a/hw/hyperv/Makefile.objs b/hw/hyperv/Makefile.objs new file mode 100644 index 0000000000..19928b726e --- /dev/null +++ b/hw/hyperv/Makefile.objs @@ -0,0 +1 @@ +obj-$(CONFIG_HYPERV) += hyperv.o