From patchwork Fri Sep 21 08:22:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609423 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 8CF8D14DA for ; Fri, 21 Sep 2018 09:11:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 792892DDC9 for ; Fri, 21 Sep 2018 09:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 641812DD60; Fri, 21 Sep 2018 09:11:29 +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 A05E02D64A for ; Fri, 21 Sep 2018 09:11:28 +0000 (UTC) Received: from localhost ([::1]:54691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HTD-0003rW-Sy for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:11:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi9-00071L-VI for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi7-0002a7-Eb for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:49 -0400 Received: from mail-eopbgr70095.outbound.protection.outlook.com ([40.107.7.95]:44383 helo=EUR04-HE1-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 1g3Gi7-0002SR-5M for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:47 -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=WYmEmJ0Bmm1uSiVuwPDNY6U5Fpcp44y7Nak2PYkBQHo=; b=BD/lBwOsFPM9VSx9B3baSmZpNQlpsL6MENFx2LO2yXdrVn36nmav4cba4YXqGEfEs/tycgd+lcKaXohzDeKI0ZRc11jgwutwy8ij0L4aeGC4TB54i5c7hMRhxHWIdReHhWQlP1TEn3J39Pe02vZmsvCnFdY7r6YmYFq69l+a83M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) 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:22:44 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:17 +0300 Message-Id: <20180921082217.29481-11-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c58cbeb-0aba-451f-5cc8-08d61f9b6890 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:bJFnrs7rEKh1g6PRbqhir2dwL+/yanrW8eDE3mo5srCYjdnuyHe1phDDG7vF9t9mBBSXedNb1rzKSarQj0YiLEqnIJFw0I+bvbMyKjbcMNyKqpEMnw4hAppoVPTIXmUgfEtb5QozlaaDAYT3WQRf6EXwvXiD0O3RyGCjmzq5h0pwrtB/d2dYqwkMEHv/Zuj57gj5qUzZ8gC/lXKQtZ4Cc/95DD0mOjnafGrTnNexTGSCuqKHKuOzxnQpXj2kf29F; 25:Kr+tlHNVPrexuZnAvUOQcpv6sgmX8HbJQxNfSizn1O16jFjuNM+3bPQaB0hDwXz4gweTMLywD5o1EiaGVBYwtHjDE3ra9ekL09ouNc/LiLNqytSYw4r1s8uBmlVcAU+kLzMEWtcUuhgQbiJH+6BCP2auKDGbj9TrMbOP2L3H8b/emzUfXeVHVV5quCRbb93lAoBsuLLixr/9RcUluGbgSQ7qnWZ42za+amd2mUGKyxb1GghaKRccU0ie9xhxajNfwmN+sTD8kfSwx7N2ID+xXKw5ThyBvrfUj4vpuJs41UaAF7wVo/zfZZR7tkdHynfIMW6CS64V3KB+W1Lmjef9YA==; 31:WTPk2YDlxu5vvwG6Dwn9odf/TQLQes1fwHIUO5FcEpi9Rwtoy298nC9eHMQ9cDlOgoaYkbX9QMQ2Ll9oFn+g6MCWn/XC3Jzc53fCQMO3zLl2tbWthL11MzyK5V0CIJwhiZZnVggWhMidk9nnlYf1wp8lvbZpEQ9lpzOhkeBIghIdD5gDcuNjbx5j2aPuaHW+jYCdSdMqDAl9zHufq2bY5pPk4E9EQ0XbFGtH1jmz85s= X-MS-TrafficTypeDiagnostic: AM0PR08MB3588: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:MnDUQdjCC5qqvpWlP3m6+DooAlEJ2fyw4QpxjmDQYO/EM+CALQh1FKL+46aedeMDrd6wGfeC1OI23kCeRsIAzaYe4RaPj1U/kabGi0HtoVUKlITDnTk9i8zwEIzfWbuz6t8CYViBvvu5C+gSuJa/YAPZ0O+rsRLzpo/IDzPHHe/lQaPfIu2/eSGFIP23W3oMYOn2gyTi9m/vo5j+/1vEuctysc2R+5LsKCZgnTgtisCCUL5EMS42VzCNU6SS+Tp/XGxjkYIiZCBBEGzFI5pWyoYDkZmblLmx4WKWw4Sxn4ygZLig8HnYUziA/DKdxZBhT3aLM0G1so0wYakl4x70BWR8FHDlXkCQIXH2edHmwj4jEKxyIM+CsijDpC90VsrbsUjHOI1uv3NnnyfHM9DAez/wdPGwXTesnHEWpbykNNx/I84/HdysBzAUyUvpXPmdL5savbJjXu8H+jAWpmMJBXAvZ1YztusxuBVgEk6iH/u7gll4PjMF4K9//4gQyQG2; 4:ernmu8iJ+afH2OBrZ+qDWUpSQDPEOzovaolh8FLOPsssTfEOBR8KUxBgFn2eDbsKmUAWsLNamkrvg7JTasCF6nmXM3DME9ggMZ2XYsOvs0nyduNV2aog+Vc4ERo+uDZmQcZLnnDXT+Fj14ejsGU9cslaGmRDdOB0x263R0cO+zWu4YCSA+hIqcBLjULcNbGEPThq4d6HcRjI1aIPOs3aDvBYY1oXIpLRPIEoPDvamM9pfOqFSpyRNEFEPT9frIX2OPzMqwoFqV4WSx3ImvKDtA== 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)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(15650500001)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; 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; AM0PR08MB3588; 23:IaXNFF2veCV1OfTOljRYpwHL6N/DejMuH6r6fAmvK?= thTkc9NuiYVgeuia3kl/9AZR8So1BfdofxzMbPjMVkjx7hQi756V0XDJEksGcJRKWxx506z2s9ojBAr7svgMO5kocENcpLWP0GDY7TaU9F+kOmTbu2GWua5MyAJih7cQ52fXAkoQE/N90Vvp5yRxM9CnPpwFJveQmgjTKVZUBpeQh4dt7PU2Ehy3B3yNkFxFxDso5X+9b+8iLYXBtxPxCnfJVgE8nrWiEjxV3HpUNXx1t5WqEqr99ZbpxAWg0lYpvgfRqzTyqKk1+dDPRp2Ir+tDYMcf8ISm3aEDEs/l6ntR7Wwc4wYY022JxSSqO+UVCPjiZng6mlTlw1ct0BxaTTJ3CdcfU83LzaJhEgLD3M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b5ac5g5ktJzuGUbW71tyfiKpyk/s5bD/6wGwIzbE41zMtNV1HKXNMl+tO0emB0KXH/2tI4rnnOlxSVUmXO7VFACa6LdcuozYAn/NuNuhryWn1jDz31KmSmxHoDTPMB98iyS7OBBMmpk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:B90UYML0GKzDiu3hE6OEY9YTslwUTsDDu2ou4L5kuMNF5m/+UWO9B6xMx4xJ6O3cy8JVs/OU3O3HlA2sy3FA7zzf5I1H37E/Ic8mPe0ZBc7FpFD5/S2YyP2jtJnO7PvYiaUxSg259X0Zvj8yqnpn1rDRhb3J1mctwl5yaTY7d9Y= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:44.3097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c58cbeb-0aba-451f-5cc8-08d61f9b6890 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.95 Subject: [Qemu-devel] [PATCH 10/10] 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: 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 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 | 165 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 02ef606469..ee77bbac8b 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/queue.h" #include "hw/qdev.h" #include "hw/isa/isa.h" @@ -24,10 +25,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; @@ -38,7 +55,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, @@ -93,6 +114,133 @@ static void sint_route_set_sint(HypervTestDev *dev, hyperv_sint_route_set_sint(sint_route->sint_route); } +static void msg_retry(void *opaque) +{ + TestMsgConn *conn = opaque; + assert(!hyperv_post_msg(conn->sint_route, &conn->msg)); +} + +static void msg_cb(void *data, int status) +{ + TestMsgConn *conn = data; + + if (!status) { + return; + } + + assert(status == -EAGAIN); + + aio_bh_schedule_oneshot(qemu_get_aio_context(), msg_retry, conn); +} + +static uint16_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 vp_index, + 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(vp_index, 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_event_flag(conn->sint_route, conn->conn_id)); +} + +static void evt_conn_create(HypervTestDev *dev, uint8_t vp_index, + 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(vp_index, 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_event_flag_handler(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_event_flag_handler(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) { @@ -100,6 +248,7 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint8_t sint = data & 0xFF; uint8_t vp_index = (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: @@ -111,6 +260,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, vp_index, sint); break; + case HV_TEST_DEV_MSG_CONN_CREATE: + msg_conn_create(dev, vp_index, 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, vp_index, sint, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_DESTROY: + evt_conn_destroy(dev, conn_id); + break; default: break; } @@ -130,6 +291,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);