From patchwork Tue Feb 6 20:30:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204063 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 E6DAF60247 for ; Tue, 6 Feb 2018 20:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D959F27F94 for ; Tue, 6 Feb 2018 20:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD488283E8; Tue, 6 Feb 2018 20:43:01 +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 5299E28D84 for ; Tue, 6 Feb 2018 20:41:38 +0000 (UTC) Received: from localhost ([::1]:59147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejA3d-0002iw-4j for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 15:41:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9tz-0000wr-5c for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9tv-0003Bi-Pm for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:39 -0500 Received: from mail-eopbgr00109.outbound.protection.outlook.com ([40.107.0.109]:52480 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 1ej9tu-00039t-S7 for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:35 -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=i0x+wtZkjAsg0L26jI0afzFxLxJRCL3lOphEs1hx0mY=; b=DgzT0eb7GiuJo20OrZvE/toYvMlWNbeXrntLAIMEpkORF/L6nxifg+6eh5iEZMSdQuBoHha1EuQP6RjH6MpyfdbG4/EbPBUcuDE6vl4eDha9aP6UfB122vLrviBOssdv1BxZxYiJEncMUBjD6CrEj9y1qsKvj0W6dRdePATTAQA= 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:31 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:29 +0300 Message-Id: <20180206203048.11096-16-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: 3f6c3688-94b0-4f0e-ad49-08d56da09c16 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:P0lks0n1n9t4lH6nGxm3bCpIR8Zqj7E2DvqghXfqiqabLMLkOg5zZ5X4PruBZAiQxdeSb53VW8RHaUy32gIhXiDnofWEdSnwpErtzi7oCqtrRsAns0adfmEI6NLSJYZz1T1CaYdY3+pbPkD2iBLa3t6geqEp8XEQYVbnqTM0lXkA67qe4FBz7Vn+VPUu5GBFOicS1ZFtFhhpsI46qYNjX7thZ8VVN/J58XDZGWA41Sug061DhKr6d3cO0s2mcqjB; 25:eIhej/Qp9x4kD9CWK1d8SC0NG/q7AzjnTUPb/OxfKRc3eGQLxBEx/p9sT/dxi7UAsJxKh3z8YY/lkVzVtREPDkgAcZTYyk4Is+9vzP2Cs79Gmi/h4SyOXmYb4f1ls9EUOm7JezpkqaXFZpHV2Y9txg2AajJYdei9t5Pg0Iyhi1xcP8iNvXCm9hk/KrrszbzdblP/zQmBrNGLcJpPvWT+l1LSRZOGKlsP3Nbcpew5IcZ5EsRdGqFBx5QqrEmzsn38kghJKcesGkwrKpS8Xjp0WZNPfG4xS0wLTpkVtRNe+WtXlKLuo5CHZmWIhY0GHuNNO02weuhTPmzGMuw69xJMpw==; 31:507T1NUhWrhrVa7MPINmUH27Rdimn4QUWRqdm5Q5KmDcU2tiOrY/u1PqSqx6RW7xgf70Wse22xkpeFAYzSu9qGXvBe6OhduvQc9TcQpgV+BhdqB/SX28LQIVfQv+hCPOmv5aR8MMeupWs+EuprdECoIgwoRBJb9ipiexrCUWU9i9QCS66ok7rqMtP0/9jAeQFX5JqbzSrVyuvNHtOHR2AxSwZDI4uuxlGJ/Ske3y9LE= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:u6G8+Q+ruyvjVwYWeasuaVsZqrvYGud9crJ67yuyDyfbyOGQz16Ofr3KBMyEJNktiH2gk/SUclvznGrL5cJ+v8SIQvdVw7U6QSw7JYRwkxeDlL12JPSy0XiW2GelvnY2RjIiLn+7/9rON5ClDlfAwS+83jQxiRVmwWnLB5qt4fPcIuz5iTE66s2miVd9GqfBdVbxq+AdV6F8Nfi67TjGXsSKQFfpQna8/qG/NpRwpVNOzpYXMFsr+ENpO/IUyVnJVCqwMdL2hszGUBrfHdmg9FgBqYB9mD7oqKwGIfND6OOfSKpjEVfecunEXy8F+vfJNlt36foolpnYENJdSmFeNm+ip+w4oVqayjKq7K1DP7N8JUjTqRKZM7o7Ay7DrCK0h2sqjzXrDR6f0B3Na180Uot7otuLqN79Dib4oGDnMM4=; 4:1GiccypZ2CZgildwSvBZXhhj580yiXnCWpfdgBNiiHrG7H6afUfyug657ZdytFdXMBtrndKxeLQlttx1a4h9jVvAkP9UWSA/c+MUV6LVjrWB7cSNYxyalK0j6jnuVSxw8J0Ja2Itpos1DHlopDwZlfp0iw0WWaSUkHzACptaOL8r2DF3z8a0sN9xYJMsmMUG3fiZHfrEKvi2aHwvNy+888T0vL5aXimh7vsUf+CKrvVQAyOKqoj6/4WzIBHVBFF0rd5DIeTna+sIEFsSu0+upw== 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)(1076002)(50226002)(8936002)(81156014)(5660300001)(8676002)(81166006)(7416002)(2950100002)(6916009)(76176011)(86362001)(68736007)(66066001)(15650500001)(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:0YbN7Hl69egw7u+EvuxDkasQcAQJE2kQ1NPl2Ya?= =?us-ascii?Q?GQTovgKs2hRBt2jPUUX7gcIdRwbMZzl+SUlAKu2ZX+rbA7OJEdUTDwQh8N1W?= =?us-ascii?Q?ndAA3tm9KFaCkNrxvxVX8fzznMHPbjQqFLusEFKUDUmNWNOjb5Mc05ZRxj/O?= =?us-ascii?Q?Th5GkU0QK6sP1k7v3OZafothqXvK7lyO98sgRhkn0zuCd3yvh32uc7gdDG9D?= =?us-ascii?Q?gRgnv45XZtnN738vmxE3gsQdRuBjTQaCMpwgolTw4k2vIquk/cfRYmRY3Y1J?= =?us-ascii?Q?Rd/iZWA2oxZ44RBvqSykpsqw6Nqz0TI2MLh2ttKu8yBXgDqN79jry4hMm+IW?= =?us-ascii?Q?KxJf74C8fNY6bxsym/m0h3939ktrHmAuaLY36UQ39JcGrT4afhS1AGg4mEHn?= =?us-ascii?Q?LzsQH6qMTDMqn2SPfLwljqWH1DBgoOMMiz37/1fpXEojfPnesnmwgVrMs8xA?= =?us-ascii?Q?1KXExJabGsIuzYfjTknOR1CqfC088h0hA84pMQFzUhCf2UGGJWafOzxIJ9i9?= =?us-ascii?Q?hKR7/wrc0NOiiGYOuEC3I0MUdmlvSbBeKuEh4rtsmEFq3CbPhbLdljQWt9vf?= =?us-ascii?Q?igOGyyQ5aJEPU+tkHMUjJjAEoWc+pfnXUHMkPcgnj4ivHl1EkllA8CBrP3f8?= =?us-ascii?Q?TkDCFKlRnRfW15Uu+6Ja3xputp7rfpdtcPXeQKMAuoHSUIX22dM/+uICKwM3?= =?us-ascii?Q?Pr6V59zMpWe77o8GiF3E6Pb2zwvk/W+u5EMt7zI9cmyDyp9R09JZoGX0PDbX?= =?us-ascii?Q?BxtHyHYziNxoh6WOBrrrmUDz+n0VFtD1QbxqD9FN6QiXVhac+87QVUpLREZ1?= =?us-ascii?Q?1Z+4fqTSQMBE7Rwy5iXupIWs3J23boMub/jev7wXh9owLfJUisF9oWzD59Jb?= =?us-ascii?Q?oZriegPZoKe35t9xQtiuUSsTFk1SgS3HCfqr3lfV6NLD3Hp7xAVWrfQG2me1?= =?us-ascii?Q?etze8N1DtI5XPe1Kl8IwucLPPvVGLYzepOkeiSig7fgQ9MxzQTQAb7ar3EG7?= =?us-ascii?Q?GiFRefBBv2KVa/mkeV2knHIwX7NrxCjRSyfqzHD5+vjxu1wfBlBDT2VOkOa9?= =?us-ascii?Q?oCUlaGvBWsUTVFBcw275XdzZFEnkAXhp/0/3QhcqUdSoO06sThMl6rzVarcf?= =?us-ascii?Q?M2ZlvDvr13P9+pA+cMJdQ8NXenwTdUxjTOwS2WwjM5xvv9dOWm8qzsKAJDCP?= =?us-ascii?Q?os32H7BcrtCXWUg3fhHPC9rxzfCLbikeSx6Co5Rtp/hiK7OYXBVLg9LuVW8P?= =?us-ascii?Q?sQRmaSJobpyz8cf5u74yVi0vxu6Np0d94EvnrQjqXLw85eP6xBux7ouN04fa?= =?us-ascii?Q?zSWBSA0+/8x15pHEAjj5sGq0=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:EFDuAMLQ6xk6hmrj5XXqBPixN7KzERcAGgxmDmOMb75hN9ge8qsm+wGvQLDZwuYCElIRRZhNJGa4i2XIVMp1VPdoKLMBJtxWwaugkPDCI6I9Q2N2DjScr72+YGK0vppS2XqucNvFsoRqvqRUIhnH6DsMyZ7QJJcwpq8SWRgAnQsmi/slmN3EmRbEYcNrj7CcGlFJaV8tHGtMDrQeAMYxev5LixyJ/VX9y5EMOL2rtlPnzvTE7SwZbUBBSRmo4K+H6ndycc1xbJLWWWge+IrFunNf83tNiL5KXS3Vr7+9NR/fmoSR/+2kVXtXdGh4cVtGfamnODy5y7dizcJr6ITxhotmHlQBwVBkvintOydnHhc=; 5:iOr8n5tn6NavAw7Kqrhf556xSa+iS7FAYMCDfrVvpPSXczqyX8l14MjT944jKalldYmdNWKY6HM8zrGPBX5BkQj9dw5EpURlQJYS6BdmKL3EA11FkJI2dp4URzxPjtT1mcDp0/HcXU71Md93SC1rhbpslDBp8vLOh4TgObjsB1s=; 24:1nDGsI8PRxKjkUMqs5eXKdXey6HUGFWeINWFuJHK2xT6++wUK5xs5Aphu/HjYPKz84zyVD9FVW1FWfUMAkq9+enKY3hYaEN0rZT0VX1he5A=; 7:KdR/7pNi+9ZD5q5uTvF1W4EjPhAo6ScAnGxncVhpXZgAIgdMXBeNZH/hCI3L7hcBh14p1NU4blbzEFdCRzT81QKsm3MTda91LY9AFSkRfS1UkgJuj6dOEzRza+PVp/q47ofVrrVov0ccoDab3VvvWEaRRANxWVhfvqFKaaXh/UxthHxGqpj7exvhAVhaxJajvThVolO1AgSusREd78iHva3Xlw5y/d0/mambVibPXySe4ml4FJOQYrpAF0C3uvu1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:ThlAdVS+vluW9BP6fkRnOVxxcNHy2mFKA7be2pQy5dfEOPZ6dQ6JDtj1fdtdlBiM6WJAK+6eh37czbrfGWjsVI1PM9x4e2ctQvPeiDv3Pji9rvLpGjjz7xWOQ7E6pI9gvcIYAQp6/zVSmiW8zOoHCtYiIkMGPYFOobV75JvwsvA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:31.4344 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3f6c3688-94b0-4f0e-ad49-08d56da09c16 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: 40.107.0.109 Subject: [Qemu-devel] [RFC PATCH 15/34] hyperv_testdev: add SynIC message and event testmodes 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 Add testmodes for SynIC messages and events. The message or event connection setup / teardown is initiated by the guest via new control codes written to the test device port. Then the test connections bounce the respective operations back to the guest, i.e. the incoming messages are posted or the incoming events are signaled on the configured vCPUs. Signed-off-by: Roman Kagan --- hw/misc/hyperv_testdev.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 1 deletion(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index fa435abbbf..79077789e1 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -13,12 +13,15 @@ #include "qemu/osdep.h" #include "qemu/queue.h" +#include "qemu/event_notifier.h" +#include "qemu/main-loop.h" #include #include "hw/hw.h" #include "hw/qdev.h" #include "hw/isa/isa.h" #include "sysemu/kvm.h" #include "target/i386/hyperv.h" +#include "target/i386/hyperv-proto.h" #include "kvm_i386.h" typedef struct TestSintRoute { @@ -28,10 +31,26 @@ typedef struct TestSintRoute { HvSintRoute *sint_route; } TestSintRoute; +typedef struct TestMsgConn { + QLIST_ENTRY(TestMsgConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + struct hyperv_message msg; +} TestMsgConn; + +typedef struct TestEvtConn { + QLIST_ENTRY(TestEvtConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + EventNotifier notifier; +} TestEvtConn; + struct HypervTestDev { ISADevice parent_obj; MemoryRegion sint_control; QLIST_HEAD(, TestSintRoute) sint_routes; + QLIST_HEAD(, TestMsgConn) msg_conns; + QLIST_HEAD(, TestEvtConn) evt_conns; }; typedef struct HypervTestDev HypervTestDev; @@ -42,7 +61,11 @@ typedef struct HypervTestDev HypervTestDev; enum { HV_TEST_DEV_SINT_ROUTE_CREATE = 1, HV_TEST_DEV_SINT_ROUTE_DESTROY, - HV_TEST_DEV_SINT_ROUTE_SET_SINT + HV_TEST_DEV_SINT_ROUTE_SET_SINT, + HV_TEST_DEV_MSG_CONN_CREATE, + HV_TEST_DEV_MSG_CONN_DESTROY, + HV_TEST_DEV_EVT_CONN_CREATE, + HV_TEST_DEV_EVT_CONN_DESTROY, }; static void sint_route_create(HypervTestDev *dev, uint8_t vpidx, uint8_t sint) @@ -95,6 +118,128 @@ static void sint_route_set_sint(HypervTestDev *dev, kvm_hv_sint_route_set_sint(sint_route->sint_route); } +static void msg_cb(void *data, int status) +{ + TestMsgConn *conn = data; + + assert(status == 0 || status == -EAGAIN); + + if (!status) { + return; + } + + /* no concurrent posting is expected so this should succeed */ + assert(!hyperv_post_msg(conn->sint_route, &conn->msg)); +} + +static uint64_t msg_handler(const struct hyperv_post_message_input *msg, + void *data) +{ + int ret; + TestMsgConn *conn = data; + + /* post the same message we've got */ + conn->msg.header.message_type = msg->message_type; + assert(msg->payload_size < sizeof(conn->msg.payload)); + conn->msg.header.payload_size = msg->payload_size; + memcpy(&conn->msg.payload, msg->payload, msg->payload_size); + + ret = hyperv_post_msg(conn->sint_route, &conn->msg); + + switch (ret) { + case 0: + return HV_STATUS_SUCCESS; + case -EAGAIN: + return HV_STATUS_INSUFFICIENT_BUFFERS; + default: + return HV_STATUS_INVALID_HYPERCALL_INPUT; + } +} + +static void msg_conn_create(HypervTestDev *dev, uint8_t vpidx, + uint8_t sint, uint8_t conn_id) +{ + TestMsgConn *conn; + + conn = g_new0(TestMsgConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vpidx, sint, msg_cb, conn); + assert(conn->sint_route); + + assert(!hyperv_set_msg_handler(conn->conn_id, msg_handler, conn)); + + QLIST_INSERT_HEAD(&dev->msg_conns, conn, le); +} + +static void msg_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestMsgConn *conn; + + QLIST_FOREACH(conn, &dev->msg_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_msg_handler(conn->conn_id, NULL, NULL); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + +static void evt_conn_handler(EventNotifier *notifier) +{ + TestEvtConn *conn = container_of(notifier, TestEvtConn, notifier); + + event_notifier_test_and_clear(notifier); + + /* signal the same event flag we've got */ + assert(!hyperv_set_evt_flag(conn->sint_route, conn->conn_id)); +} + +static void evt_conn_create(HypervTestDev *dev, uint8_t vpidx, + uint8_t sint, uint8_t conn_id) +{ + TestEvtConn *conn; + + conn = g_new0(TestEvtConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vpidx, sint, NULL, NULL); + assert(conn->sint_route); + + assert(!event_notifier_init(&conn->notifier, false)); + + event_notifier_set_handler(&conn->notifier, evt_conn_handler); + + assert(!hyperv_set_evt_notifier(conn_id, &conn->notifier)); + + QLIST_INSERT_HEAD(&dev->evt_conns, conn, le); +} + +static void evt_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestEvtConn *conn; + + QLIST_FOREACH(conn, &dev->evt_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_evt_notifier(conn->conn_id, NULL); + event_notifier_set_handler(&conn->notifier, NULL); + event_notifier_cleanup(&conn->notifier); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint32_t len) { @@ -102,6 +247,7 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint8_t sint = data & 0xFF; uint8_t vpidx = (data >> 8ULL) & 0xFF; uint8_t ctl = (data >> 16ULL) & 0xFF; + uint8_t conn_id = (data >> 24ULL) & 0xFF; switch (ctl) { case HV_TEST_DEV_SINT_ROUTE_CREATE: @@ -113,6 +259,18 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, case HV_TEST_DEV_SINT_ROUTE_SET_SINT: sint_route_set_sint(dev, vpidx, sint); break; + case HV_TEST_DEV_MSG_CONN_CREATE: + msg_conn_create(dev, vpidx, sint, conn_id); + break; + case HV_TEST_DEV_MSG_CONN_DESTROY: + msg_conn_destroy(dev, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_CREATE: + evt_conn_create(dev, vpidx, sint, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_DESTROY: + evt_conn_destroy(dev, conn_id); + break; default: break; } @@ -132,6 +290,8 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp) MemoryRegion *io = isa_address_space_io(isa); QLIST_INIT(&dev->sint_routes); + QLIST_INIT(&dev->msg_conns); + QLIST_INIT(&dev->evt_conns); memory_region_init_io(&dev->sint_control, OBJECT(dev), &synic_test_sint_ops, dev, "hyperv-testdev-ctl", 4);