From patchwork Tue Jun 6 18:19:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769615 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 DC62F6035D for ; Tue, 6 Jun 2017 18:39:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D27552847B for ; Tue, 6 Jun 2017 18:39:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C729E28497; Tue, 6 Jun 2017 18:39:56 +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 20E612847B for ; Tue, 6 Jun 2017 18:39:56 +0000 (UTC) Received: from localhost ([::1]:39704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJOV-0006bm-8Z for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:39:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5c-00064X-BV for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5X-0007Q6-Rd for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:24 -0400 Received: from mail-eopbgr30118.outbound.protection.outlook.com ([40.107.3.118]:59885 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 1dIJ5X-0007Pa-KA for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:19 -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=h4DxWe+pl3Kn0FY1qmqVeDonm+rJ3Fm/azgz9MUGmvQ=; b=ZdCVMKdYayzbmcoUWyBIK+OMKVnAnMw7vGocNdHUHsXwr6vyuiN4bSQDCpYrJ5D9ZqzLEOqo8VuyXp6sSzzd1WINVo6UsC5mf051fRjketlKc+D6sNypCWJKTywboKV2fzvjsVrpBLtcHtxucyZEZ7igI96G/JGWCkjN4bmOa50= 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:16 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:46 +0300 Message-Id: <20170606181948.16238-22-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: 73047b2f-a0f5-4f24-b5db-08d4ad08af0a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:cd2LOfJmZEWQDdyKg+QWumgLqRIKd/Gy7UZZxmESTn3ZB8nkXwmDcakC1kgY7vPSbqxkrGZoR4GgFrbetDkoMLC7qElesWodUjX15AQ/9iwf4m63Ypu2xKgJWG1CQt35DOmFRdZbtUE2eL27CaJpx9nGTCFXr8izEHaKxkFN5o2ZpXS6ImkHSwmbs+6zC5qL1GI1mmY+aeosneMNHcLwSGijTLoCKdcyunP6h2qbff+lckB32yCqyNqMqn3RpT9nc72/oIEZobFNm0dbyrxmNoctFONmwBB377SeOhrPCb+tjhohaiCZrr+WHEAYsOWhBxzPtZV7P75ylDTH2d+gaQ==; 25:MA4+bJ2ge0AgDPJ0Kbh2JJvTcAyq4njbM/DWA46hty/A1HWAnekDKzUejgy8P9OZKKS7K5dcYizvu/eAzzYDWDHJOSpPxVEorpSYFd5FRGgOfqe0gpsnRECu6r38CwbLEjH8nqhDrRa+GRKqXbTj4aifCq+vS/LCu5DhN6cddMfY6yJeDhu8e12t538T6rs4RNibrXooMK0IpIUbC9z6Ab+3hPbQeG5U0ipXJVDcUZ8DTQ8I/l0c/94flvK6GvbI+L2sv5vqueYCOIAJx2SN5PX2HFkS+5vocCAGtOIs/TCyaWpMr35gXByJZJ9aVfnU0fESI8GbujDhdNuxBdmseWd9fgpT0Ns8/RbmKgBk8zQT8xGrTXWH4oqZj6D7sNvBSR8JMM0g7/Lci51y3wH88/3GIdeviaxIZ2/bJGJ7ywvj0CI4iPqU94BbqFu8ULl4j6IxXO3kzt21lOxuPm11fTPrRV5FWF/+xbjqlVgcqsg= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:qs5AIkPpKiPS++VUBZmWLTcu9dZkrVwq7vRDK1Ze89+IY7+d7tvY/HkDnjvHWaCK5yfHS3Ui8MCE5dfCKC33DxOEiwCy0z8w0EBWqqnFpT/tAaMkulGlzFdvMAdkaFqp+8TWkyTrjCoftGNOoRlnpoaqknqICsqQe+J7BcDIBZL8trlV+pnadYvybbDQSSoNe6tr6o7cRLbQB2xVndUK/SDmhieRUj3h1HzHbNx4YHQ=; 20:e2LnnaTgLNrMkkPEO8oduPFDrhweY/F8SzlC+zkIaGyFQZrE8VJ99Lw9aNNzAHc5zIbX5DQnGWyR1b32ja8libZlcNZAVOSktI3xUG85w+OUCUeUbKwJdDLdHKmGw8RwNGxJqfKzQwJR/sUT3AxW8mLvWD7qZQPRzLDvtP3JOHJ07xvmSGBvqYAlefdJGJs9H256Va37/l1urdOFY+/bGedBUs5nJYpQ7FdNCbWE5cxG1TPLa9j8S/uh+baUkGj0I0LXvpryVtLMhskYZ01/2fFRqEl2ZwwsKT2CTkS0FaM9xZktXVF1fQAO/UJ/0UuOg2TxSmnqronrVdP50m3PDQgXja5hDGeSbrPznUIK0ZwOg70t81ZrYvh83tN83ljVpSKCix2CNyAfbLxcOHvRSeyG9o6S57i8Hu6r8BseRcY= 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:Bl/pPRUxIJ+ljuJ0iXG210PGCDpZUCe421biHa0f+l?= =?us-ascii?Q?uNGQTL3p0ycLaCT5MblTXVkBaRifU+7LynBB7JobmqCofJsz7tnhdPzOku+Y?= =?us-ascii?Q?tD3EyK070kextw1zwf6bzWjlN51dL+qrMAIYswvK32q+4N9CNrlfTC5eezZO?= =?us-ascii?Q?9LJLZ6YTuwiPmY6YTNq4aBsJTsiJNur30OFJ2QWe8Gy8SLOHYujat2eRQq9B?= =?us-ascii?Q?wGIdowvvFN5h6b9yrO3bjzKM2Bb4JrR8/Issgnxdg4XCyM9UzXoSOJIuzbk3?= =?us-ascii?Q?/U0zbpk+UuCEL1xHfNh3koZoZWsz+do3eHO0b4ir2kipIuWXnrHpML6luhDv?= =?us-ascii?Q?8UOW7UwUfcmmPmhV98hIFTSwyH93+/F+RY+IWWjzNq9rsnNxRljTBkBudhOr?= =?us-ascii?Q?fG6UiDr9e4cd3ffyZ912OI0TWt5b7Svrs0U9YcOSXRxl57NrObmzN4nyL7Gl?= =?us-ascii?Q?5S/vdTrqckA24ytgt5HvLrrgLQY/j4YspUA6w5o33MhNd9yxC+hITyBWY1vR?= =?us-ascii?Q?+Fz7N44gNR6bcS2r2K8C6CnZKCTEJM0UyRYKNlZrQeN02GQnu5jmLoHUb3TK?= =?us-ascii?Q?Sgczek2wFvxEj/Wxzw3W4NK0WSO5PD6JpF+DcM0lZYoljlxfIBs/tsooLmAi?= =?us-ascii?Q?pB535H71DyVqMSwrMA18mw06b63seLBfX8N3/2b3TlzPhxFGVaqJLfAlkYSU?= =?us-ascii?Q?KrlfDyFzBsCLfzBEyGdulhQXjs3SZjPiFcF5elZjyrhVz8xK7WBmcbCZ57sw?= =?us-ascii?Q?EMFSLVOylGzaMI+hWNKmSRHGK2zAngaHnExjg3kaPyN+CbPkMMlKqS1Bn9wJ?= =?us-ascii?Q?yAAj7QSVpT8GveemFKggB6YqfdZtkVDZZ7rAPvs934rxtNxk0kKwRcrAOobq?= =?us-ascii?Q?YutjwjJdfIsPLRps+OIppGuYGRBJTupTCUT+kHqZZJmuddnvIF+LV5hPIWb+?= =?us-ascii?Q?9jmm7trIOZrJXDyzveCtbyuQM/x9YqHQrlhUQAiR9cnW7USTxOX7dTlODstF?= =?us-ascii?Q?A6Eu1BRQDyBpOEkOgM9rgfl0FoVlgMheWA1WoXOPtSAZSTF812RMJl+28A9d?= =?us-ascii?Q?BMNWZg+cGIFOaoyKAgfUkgsV7ftA7FRBhqq7kF4QLL7RyXTKeZFN0GQrS1ZA?= =?us-ascii?Q?E/ZtdxELog/se7S9VMIUw0fo2C3bCY?= 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:nwa/IJCRdBZB1L4kNu+ymmc3t1c8ncskUdDHRfQy+?= =?us-ascii?Q?zbfkRy4tczpJomXy2AOx35tl+suJBoOcBZ6Ww6ShE43UXegP7AIzNWyJTwJX?= =?us-ascii?Q?WYb5wNacPFq1BHG3SiwV6XLFCpf7bc8Eu4Z+KcahsYJbpfxyHOYQKQ0Fl6ya?= =?us-ascii?Q?yDsapgtiqQWL51kENUDqArWSqKNJEl3dVrgtV+n6Vu3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A99MMxJWXiec+8PfaIIH3pnNlCgsmKHlpxmBSYXTF9aZrHgJg4moa4xdpsejdLHyGMLFFCg8MXXZnmIp3Li2NHox28SlZq7dkDS6LiTZMPO1gSfnV/fDL6n+hvlVM3; 24:DJTSTcZ2D7hAukgxXswo/lUDtq89x8S912aHz8i2FH8wn9eIt80uWfJLP0vB/PR654JFN55FG6qMDdKADAa09mPJxqWJTq8ZDnEzZqx7sH0= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:Rkf7hGtSuw71hXlBioWkgLyZPOhu43qjQ/O7av+Yn7pEpvyzCuos/vMKXzP/tjGs2TrtXvFu4LRJVa4XgTppoeNXqmZrYJ/x1pehhBNiLjag6rr0dRzWP8XdMs4eOh190vV5UZdIaG5QWLnIyyjy569b0Cz1+xfmwe3xTmJN94FkjhfQNTktyYUijBLcLmlwzKmAJxV3Yq+pX9mTWZAmM94doKblbPoNV203SG4aJvf8KKABH2+1sRp1GSzF673hPg/8TbPZNvzFYNu2jGqDs36rJeYtuerPCS8RvdwaBl04HPzyP5hjdjkHEeoIYPOdYwjKCXk4om5WRPmLGY4rHw==; 20:h5XUgU0nljlLvKOcTM9cwwDnKCp3XF6TmE2t8bEUl/UQ5hdR9YpDDaXb2FGsL9ObmeU9X4IChoWVSJOtuVKDZ7cHTm3qTMhvt7uI3YjM79d+GFp1c6aSmXN0DEVKfZB08zeyK3upRezojrGA39IwXUK4VkcbZ/yo5p1bWCedxh0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:16.6953 (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.118 Subject: [Qemu-devel] [PATCH 21/23] 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: 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 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 | 163 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 929bf4f..99d6d8a 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, X86CPU *cpu, uint8_t sint) @@ -94,6 +117,128 @@ static void sint_route_set_sint(HypervTestDev *dev, X86CPU *cpu, uint8_t sint) 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, X86CPU *cpu, + 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(cpu, 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, X86CPU *cpu, + 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(cpu, 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) { @@ -101,7 +246,9 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint8_t sint = data & 0xFF; uint8_t vcpu_id = (data >> 8ULL) & 0xFF; uint8_t ctl = (data >> 16ULL) & 0xFF; + uint8_t conn_id = (data >> 24ULL) & 0xFF; X86CPU *cpu = hyperv_find_vcpu(vcpu_id); + assert(cpu); switch (ctl) { @@ -114,6 +261,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, cpu, sint); break; + case HV_TEST_DEV_MSG_CONN_CREATE: + msg_conn_create(dev, cpu, 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, cpu, sint, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_DESTROY: + evt_conn_destroy(dev, conn_id); + break; default: break; } @@ -133,6 +292,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);