From patchwork Tue Jun 6 18:19:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769611 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 83ACC6035D for ; Tue, 6 Jun 2017 18:38:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75CD92846F for ; Tue, 6 Jun 2017 18:38:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6769A28497; Tue, 6 Jun 2017 18:38:08 +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 8DF932846F for ; Tue, 6 Jun 2017 18:38:07 +0000 (UTC) Received: from localhost ([::1]:39699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJMk-0004UD-L0 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:38:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5X-00060V-Ga for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5T-0007Oa-6J for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:19 -0400 Received: from mail-eopbgr30103.outbound.protection.outlook.com ([40.107.3.103]:45293 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 1dIJ5S-0007Ny-RA for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:15 -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=CEdtW7zE1y/+rdGwvpgQSueZgkkMeFD/9TBipSKm17Q=; b=bLYxOw3H56syXtLHXTcyZA+vXRFWBhENVYo7HQIqNeiUvS831Sac5AT31jO6lbKmvYtT70HiiJatGN2ecjaTDQz+/RqQqfHvkolSLPNcgggVn53TaIr7X1Wwdbos6bmfo9WZqEH3qJxB2eo72wUme5Vgcag1iFRuwaX0RG+RdLQ= 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:12 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:42 +0300 Message-Id: <20170606181948.16238-18-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: ba4fc3cc-db4e-4e74-45e9-08d4ad08ac76 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:bdjlPw9O65IMdPZeIgy+Dz84n7P2bJONEg9C/GwbT/zFcC+/xf9Z0TngJTUqHteZPbNJbIk+mPI7Jx7Ie0CFj/jgoBlG8VO7CWgsjFvi7bN+5J/RYLMgvERWxKYh9g9BpJKGLlK8Zkp8maUgMGqAhBwLrKx0zj2O3oiaAxRCwwChYvC1oXomt5GmYnZGTpRllFDFMM3fiiTuvFSsU3sVFQaxKidwslV36ffiRdPv6KMUH86+Fo2Vdcm727WCPFwUKhujWwC2ySXj8KSUJi2YBnohd5obSYcG/qrAgVnfbXSctx5J2yuVQOfo64Osi0hD1aJicMAaVJ5Z2YWmAUmISg==; 25:4XSOAmUdtI50N0Bp4tmGzqwcZ+SFbLofXzhcal+XRizoJ2IeumHDq5CjYwFqDLtWmD7mdIroUDCa2P4KU8IlaieRj0vyqt7C3d1bG4mcpSfSNLFwAYmCgUx2xY2jH7RoOreFqBm0OcgINyK5joS8U+STdKBbeJzLTL+3RzpGsF8q+QnBFbP12zb4h0x/s0tlQiLGIpN2Aus0KkPcB0pHCKjFwOTT+bQsIMm2T+6jvGWQmE5+ZYvfpgZYouWjJmXF7A14rmxHtRaYKU+RcN5Thff7fWGJCeOssNETfVBq96jSKFz1UeIxIln8LhSrkI9X4g5kIYtW2D2O1t0aVmpHF6oYV0f+dsGwe/aeSwmBs+kXYY2fCNg5veC8fZUBkJ9AGaDctd9tlirmppWHWWf/GP8zhLImeawc+dufPdZJi/VQ0bLmvn/jCyzPfTsNJGhgynVWAEsmvfZtfjskpShxKwySomhl54xYQOc+vdFdkHI= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:E1ULoZyR1n7draP/rnwNZhYZs1ydvwf0rd1x65vGzOhjipN1MDXFwRgXZlcQsl7TzWNp26+5CUfjAoaFYtcAGVuJTJ0QR9vfgMuWMV5bTCrzgJmMzeHNC9Iaa3caytgHFznOrn0MMSbAWlqdTRCwYj7CO/Qo9FXVka+CUAggGvmuxyw621jIJzLqj2MxnZqLLDcF8j93dEdkzS6uLZIa3YjaCs6VbS724UpAd+rHUWU=; 20:KLmCBQBrmbnhzEINo/wI09GNSayzAbLfdLpFnMV/xHtY9tz7+uD0coI1r88LfVYTX6rgdJ/+A/K3+QBF2G1FDs5SNomi56FdahbrzfaKE9gEKK+phHLdZpofX8vZ9oE2p+yWa05b1noXwtww0ufY8wbpDWvVRAQZ3fhRXYAIMChlyGTxSLuWcKMJWom+yrPHZ1w6Cs8U6CWxjoqBjNef6QXEykrOYwMnrB+ivRmltBqhwBT6fq94PnHNQ4mvuPr1NHpc2U3MLbfqAWeig4oE5aGWgBdEkgeHqJDNX6x4tcVTt+sCzW+HdVwbIpkbE6cAL8DYD00Hr3SqzlY8xY8RlVqT6PtzWndrxEKd/kZK/SqLyquB90tBA63Arr7DB1VxDgQ3DXZUwT6lzC0kZrizbRbDd8KhU5eeiOVJPoT0NY4= 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:N1ZbalxG4+AN0nLS0MoS8ulMQsJUsvHstOsJF6E70O?= =?us-ascii?Q?wAOPEKkXuTkt1a8XV+jFioHG+2bM3CKbKgS6w3J8Ra9KsrNjyiaIXaTvIyRy?= =?us-ascii?Q?Ybb6cjGaErmyWxTLlo+nXkXzB/g7dAoeimlc8oSMHxdDYySWPGy8nXFBgUOd?= =?us-ascii?Q?KtPIoNGtIxcrdQrZbJ75tiLqMxGOrB+M12PjmdNvYtS/9eNvumjWy9Pmg2B3?= =?us-ascii?Q?UKitoP7sZjfttG/MfPpW6x4lHfYqhkbkXX1/Bqc8WemLv94XfSHGAMN3/YZq?= =?us-ascii?Q?Yvo+99YWuX52UsBAmkJSsfZG7neoYkYwdg4AJSedg1Mjk4ykAN9G2OanLhai?= =?us-ascii?Q?N1Pz9dYTi38o5iEng+ps3p6FIb03wiLS1WXGwq/2a0qwtIjY+1ooLd9h7wkm?= =?us-ascii?Q?waj4XKaxVMU9kqdJ4Tzm++herNB4d/F0H9zh/rdkGpTUUsgwiwxPAT+osg2v?= =?us-ascii?Q?mu48MHXKXIQjCHVEp/dCjWhKwOJ1Ol1kZX05K69H1rdEKDPPtWbZhrH3K7Hp?= =?us-ascii?Q?XrCKp1TDG9F/7tntflLWCxrpUV9x4C4lMVU2zZopdT7QjWb7D5x0duvYVloA?= =?us-ascii?Q?10d0Ji/Pe6Alo6nvOxnYjp49rKmU6eAPQXwWTuBfs+vjBuke3XHMt1bitvi6?= =?us-ascii?Q?6r6Vs3mgUDp93ciGygbde8UL4nKxcktvVDDgfwOTVVkMwGWN8fKDTWEBidqT?= =?us-ascii?Q?+eLvzbTcFDD9yXGWc8qOIXQDR3Ska8WZa64YIMkFd2Y+V+bLcu30WmUaQpBv?= =?us-ascii?Q?1Ss6c28ayCCxkm2rEpn6isbHE7EWh3YHo04pDg0WWMXY2n17dBxOcCMnJvK+?= =?us-ascii?Q?e7SOwxA5SxjrTct7R/CQ+jeLl7yQttZo3w+bTGfrDIw8YkKsuo8fU/ZvLz76?= =?us-ascii?Q?uMOKSWRvJ2AfL7lsOcASHjEJg6itWivR8KuaLEfCqdMk0+buwdDlibJZGeQm?= =?us-ascii?Q?XIeNRGcDaJPTXB+3E3VyKA7EmWt4wRmo6qpnsx/Z3jrbTX9YflqhwnkQZ2m4?= =?us-ascii?Q?P7n1qERE930hpWs5SGItGf/NPQup7wUn1v6i6fhmRwSD2nGTV+/PnGnFC4a3?= =?us-ascii?Q?0YxIRJvy5Qzbo2C3XMWJoZK8eTH+6uhIF7O0VGiRvSi7/dQZxKqDJlz72F7g?= =?us-ascii?Q?jcFilkdf/QmZhdsWGQOrkM8KdV74g1?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(48376002)(33646002)(15650500001)(36756003)(47776003)(6486002)(478600001)(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:Ub3dB685ckRMNDXt+4g7YdSUnNk6n9XBeuQELJAuf?= =?us-ascii?Q?Mm+9SNgPFk03R9DiVmcJmav3qOIExNWo1DTtz+n86pWZ1ss0N7/w7NJ3HYnH?= =?us-ascii?Q?i5rodpo07uxV0riMSeW57ba9ZdcjSVwv8NDFB7bWmoRwWQwIpFvcgP4Z28w5?= =?us-ascii?Q?T9SIRDfsr7FTsxTYE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RCH2iozF1Bp+uzQbNjino+IKDCuMo4ps/8KEkWUWfggL7tmNNRYb0mqLghpHqHWx1EpUdkDyD9x9myGOhYg/Q3yYYTusPnSWpQxa+pNtSbAeyxAYngTJcZr9mpwgkBbh6X+mkEJ061/TnYg/NIOx/P8vRTIGx6rKS; 24:PZEJ7MNEocQkahA3ppuA2E9fdVnrWHcADeKKtAYwsAWqPwmPlTz6oCmST7PerAZyHlpBar2tNtPH4hKRjE3I6Tmq2pgI3ooO0DUMVaFCL+E= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:9DfRti6rHaWq6S9huE3Ht9Hx1RXDt/zpGUSwwCVuk36vx/PXCKm0nNGgV9PrN1fnFp+noq7a8UDf59qGqw74UkhSxmtouyBlI/ynfDtgY+F0wevBhGkEHdLZmSOAjRvJ/2YWwBt+SKqQiJmUtj4fad5msSWDssphiJMb2REsmjGYSizEPaZx7loLQl7BxFM9usCkp+O04ZJRtt0gVztsv0eWuU8lSZlCsAC6oFG3MX9EJzeaS1+2z6h3BngDPu1gK9goyUAnZ2qAoLNjSvOiZzOy7BoiPkNxFCjfYmlurmbrWKER11NZrL9cszQd7/a9vXgqnQRYcYUnhp+iEteFcA==; 20:5HG2Zikpqv8Aqz6lVIhitadnzeJR88NybXFieBUMkgoID6y7WKeCwnke7UWDK7sj2HdD1lmhSKEjYDLyphANK6WFk+YM3IGV/NAUh71s7hxV/1mQyV1NdN0Paw2KnG1f0/xmvEYlY8nzKFaI5WqY+JvCnccPkuVSCH6b3v3Hg58= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:12.3514 (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.103 Subject: [Qemu-devel] [PATCH 17/23] hyperv: add synic message delivery 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 Add infrastructure to deliver SynIC messages to the guest SynIC message page. Note that KVM also may want to deliver (SynIC timer) messages to the same message slot. The problem is that the access to a SynIC message slot is controlled by the value of its .msg_type field which indicates if the slot is being owned by the hypervisor (zero) or by the guest (non-zero). This leaves no room for synchronizing multiple concurrent producers. The simplest way to deal with this for both KVM and QEMU is to only deliver messages in the vcpu thread. KVM already does this; this patch makes it for QEMU, too. Specifically, - add a function for posting messages, which only copies the message into the staging buffer if its free, and schedules a work on the corresponding vcpu to actually deliver it to the guest slot; - instead of a sint ack callback, set up the sint route with a message status callback. This function is called in a bh whenever there are updates to the message slot status: either the vcpu made definitive progress delivering the message from the staging buffer (succeeded or failed) or the guest issued EOM; the status is passed as an argument to the callback. Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 7 ++-- target/i386/hyperv.c | 116 ++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 14 deletions(-) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 9dd5ca0..fa3e988 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -19,13 +19,12 @@ #include "qemu/event_notifier.h" typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); +typedef void (*HvSintMsgCb)(void *data, int status); int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); + HvSintMsgCb cb, void *cb_data); void hyperv_sint_route_ref(HvSintRoute *sint_route); void hyperv_sint_route_unref(HvSintRoute *sint_route); @@ -38,4 +37,6 @@ void hyperv_synic_add(X86CPU *cpu); void hyperv_synic_reset(X86CPU *cpu); void hyperv_synic_update(X86CPU *cpu); +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); + #endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 165133a..0a7f9b1 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -44,8 +44,21 @@ struct HvSintRoute { int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; - void *sint_ack_clb_data; + + HvSintMsgCb msg_cb; + void *msg_cb_data; + QEMUBH *msg_bh; + struct hyperv_message *msg; + /* + * the state of the message staged in .msg: + * 0 - the staging area is not in use (after init or message + * successfully delivered to guest) + * -EBUSY - the staging area is being used in vcpu thread + * -EAGAIN - delivery attempt failed due to slot being busy, retry + * -EXXXX - error + */ + int msg_status; + unsigned refcount; }; @@ -112,6 +125,69 @@ static void synic_update(SynICState *synic) synic_update_evt_page_addr(synic); } +/* + * Worker to transfer the message from the staging area into the guest-owned + * message page in vcpu context, which guarantees serialization with both KVM + * vcpu and the guest cpu. + */ +static void cpu_post_msg(CPUState *cs, run_on_cpu_data data) +{ + int ret; + HvSintRoute *sint_route = data.host_ptr; + SynICState *synic = sint_route->synic; + struct hyperv_message *dst_msg; + + if (!synic->enabled || !synic->msg_page_addr) { + ret = -ENXIO; + goto notify; + } + + dst_msg = &synic->msg_page->slot[sint_route->sint]; + + if (dst_msg->header.message_type != HV_MESSAGE_NONE) { + dst_msg->header.message_flags |= HV_MESSAGE_FLAG_PENDING; + ret = -EAGAIN; + } else { + memcpy(dst_msg, sint_route->msg, sizeof(*dst_msg)); + ret = kvm_hv_sint_route_set_sint(sint_route); + } + + memory_region_set_dirty(&synic->msg_page_mr, 0, sizeof(*synic->msg_page)); + +notify: + sint_route->msg_status = ret; + /* notify the msg originator of the progress made; if the slot was busy we + * set msg_pending flag in it so it will be the guest who will do EOM and + * trigger the notification from KVM via sint_ack_notifier */ + if (ret != -EAGAIN) { + qemu_bh_schedule(sint_route->msg_bh); + } +} + +/* + * Post a Hyper-V message to the staging area, for delivery to guest in the + * vcpu thread. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *src_msg) +{ + int ret = sint_route->msg_status; + + assert(sint_route->msg_cb); + + if (ret == -EBUSY) { + return -EAGAIN; + } + if (ret) { + return ret; + } + + sint_route->msg_status = -EBUSY; + memcpy(sint_route->msg, src_msg, sizeof(*src_msg)); + + async_run_on_cpu(CPU(sint_route->synic->cpu), cpu_post_msg, + RUN_ON_CPU_HOST_PTR(sint_route)); + return 0; +} static void async_synic_update(CPUState *cs, run_on_cpu_data data) { @@ -164,17 +240,27 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) } } -static void kvm_hv_sint_ack_handler(EventNotifier *notifier) +static void 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); + + if (sint_route->msg_status == -EAGAIN) { + qemu_bh_schedule(sint_route->msg_bh); + } +} + +static void sint_msg_bh(void *opaque) +{ + HvSintRoute *sint_route = opaque; + int status = sint_route->msg_status; + sint_route->msg_status = 0; + sint_route->msg_cb(sint_route->msg_cb_data, status); } HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) + HvSintMsgCb cb, void *cb_data) { SynICState *synic; HvSintRoute *sint_route; @@ -189,14 +275,18 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, goto err; } - ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; + ack_notifier = cb ? &sint_route->sint_ack_notifier : NULL; if (ack_notifier) { + sint_route->msg = g_new(struct hyperv_message, 1); + 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); + event_notifier_set_handler(ack_notifier, sint_ack_handler); + + sint_route->msg_bh = qemu_bh_new(sint_msg_bh, sint_route); } gsi = kvm_irqchip_add_hv_sint_route(kvm_state, hyperv_vp_index(cpu), sint); @@ -211,8 +301,8 @@ HvSintRoute *hyperv_sint_route_new(X86CPU *cpu, uint32_t sint, 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->msg_cb = cb; + sint_route->msg_cb_data = cb_data; sint_route->synic = synic; sint_route->sint = sint; sint_route->refcount = 1; @@ -223,8 +313,10 @@ err_irqfd: kvm_irqchip_release_virq(kvm_state, gsi); err_gsi: if (ack_notifier) { + qemu_bh_delete(sint_route->msg_bh); event_notifier_set_handler(ack_notifier, NULL); event_notifier_cleanup(ack_notifier); + g_free(sint_route->msg); } err_sint_set_notifier: event_notifier_cleanup(&sint_route->sint_set_notifier); @@ -255,9 +347,11 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route) &sint_route->sint_set_notifier, sint_route->gsi); kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - if (sint_route->sint_ack_clb) { + if (sint_route->msg_cb) { + qemu_bh_delete(sint_route->msg_bh); event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); event_notifier_cleanup(&sint_route->sint_ack_notifier); + g_free(sint_route->msg); } event_notifier_cleanup(&sint_route->sint_set_notifier); g_free(sint_route);