From patchwork Mon Jul 2 16:58:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10502117 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 B561860284 for ; Mon, 2 Jul 2018 17:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CC8E28D66 for ; Mon, 2 Jul 2018 17:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 909A228D6D; Mon, 2 Jul 2018 17:09:09 +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 ECA8E28D66 for ; Mon, 2 Jul 2018 17:09:08 +0000 (UTC) Received: from localhost ([::1]:34382 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa2K4-0006n7-5P for patchwork-qemu-devel@patchwork.kernel.org; Mon, 02 Jul 2018 13:09:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fa2AH-0007lr-5i for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:59:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fa2AD-00040c-9H for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:59:01 -0400 Received: from mail-db5eur01on0103.outbound.protection.outlook.com ([104.47.2.103]:6163 helo=EUR01-DB5-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 1fa2AC-0003zS-TO for qemu-devel@nongnu.org; Mon, 02 Jul 2018 12:58:57 -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=gP9QO3cA6DLSG290YmJ/C8r0B7D7AWYJm0+M+7ejm+o=; b=TzkvF1IRcKDzTNNKpa7aqbUhHBKz8YgDb5DlgwrXdUCnr17hkxgDOGfQ0MIBPXPdadNcHtq7Ec/+xtaoO6gTuEwZHkXbeghwYxdOm5O16cg75jl7gkRFOTN6SV1kqUvld8iOWcWyloVn10fMCg++CLOTDLDlhz0tf2nvTHBci5U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by DB6PR0801MB1974.eurprd08.prod.outlook.com (2603:10a6:4:75::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.906.26; Mon, 2 Jul 2018 16:58:52 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Mon, 2 Jul 2018 19:58:37 +0300 Message-Id: <20180702165842.11423-2-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180702165842.11423-1-rkagan@virtuozzo.com> References: <20180702165842.11423-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1PR08CA0234.eurprd08.prod.outlook.com (2603:10a6:802:15::43) To DB6PR0801MB1974.eurprd08.prod.outlook.com (2603:10a6:4:75::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f6ccd8f8-888f-4dfc-3ac3-08d5e03d1838 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600053)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1974; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1974; 3:nY/C9tL4ePCEL3AKChd/Y+y5/SOZ9nfnojCp/Arwv/YQyAmQvfw31P9iPkUOsBU7+b7nsifOpY4L5ztCYDq9tsG5YIzlWG+IK4OUYwoXcpWCfMV1ADsFTA0DjxL01Q1pf98vS8OYWDs03dYfFeRuu+H9s1G23ylUyty+96QvbSdkvH0CFkAbGgse9DHInZiEhGZIVV4czxsYMjfdC5UV8Ro5vjG3W0V/8cJXGmxeFUQoUSFplq9zBDkzoK0lp6QN; 25:HnnewR1+iNuT0j5JYoMHuxR7GNkOHi68gVzWrX6cuYkFLZ734Knsa6RJD0GDZpGZMpfugfJ718bUJmpgFeLR+dUsaGiUo0q74NA3qqFn+8DM/P/YuxndCrnZBFBBy8hul4quQKOiDzdisyiFk4fP+k+yYIAYL5B6j3qEOqs7nVeE7r9KngBOZF5pB/OTESGcIV/J2DD6SrIbQNkLuXovNOiwMtAuXVxHca+CEliJdzHRPoOVpmXUWYWpr4Lq/4ugEFK4JNal9u2/8X6bF8v4WV/IO8Yft4YCbeDMQec/0bgs9h0caFq1TSCbZ2Yaic7eDLPwc/xSaKraJel/So9W+A==; 31:TYEndU7WIqEI39Qsc7/BUZVpruzUQAs3awmWCCg0nTfdf2K3a4zlxI1CqnuGaoIdX3GjbvSYNXW6kWZRdgvEtmMjy4Q9N3Eyf1puA3leazgLGtjlfbo9C9ZZRn0PKEMFRwpET74HJXzewYMNmoJlUaOOU+XFnEyUuNETd+5Ptda5NwtsaTMRzKfpVq+fMso5DalD04j8Dcn3YuUYf0Bf2AQpMo39CSOD3mTx2h31Bes= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1974: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1974; 20:W7+uypzAp63sWDr//uiL70YbycvsQxXuN+fJL1lvQlfWlR0ugk+q5GGrzbkMVnZDSt+XgPZZHd5C8LgnmdX/YMrlXqlqpUFKv7D2OnUv8ufyplU3Vb1QVHnt5B177KAWPGBaN9UxRk6WRRTROWWz8UI3yx9/KICDKXKGeLv9JqFXV90N1+e3UZKgcj30KcZnOCcMijOC1YkeqiIQZ8kjJBZfSZnD6I/nyCjGyRRfegKftAVQcyuMYnXGqMFJNvg6ZC5CQPHUKgwRbNrKkum4LzX9l5pHGigns4wjg0x/OHAk7c0E/ssADTj7B2gG0qopHOsSOP37+boC2Bfk2MO3s/NIC6B4CKpzyA1gkRa6EPhSkSNOPD4gBxXGWb9JOzuvoZc4rMF9gbJBlzjwZFtNLice6bNFsMGwWMHhqRSN3IuEgJxsTqriM7i2qgh5yD/9d22Ges9En/NsQhdOmjUKVIkQaJOfZqGtUn7dFWIE/3nfBn5uaTsl+dC4+CzMGMEy; 4:144yksG9SQXUOkERkbZhuiGIodGEdB7rwiWso7+mPOzciJgrMJMELOKz288q2BdvVFxVZ4/TLiqdhzgaSqeqfmdIqchUmXNnpaIm2Rq98LJAjhhP75YcUCeaB0SC7mPJY6hUg9D6NNjNJRDMKKVP1OJv+x42q97MmK1cUHVw38xiZg0rgCHfUkOAWZrQpofqM9H4H7q9n2jCAq4uod1bjInQd5Cm3L6BwyGAiVA2brkOnsE8en6EqpFWwwvZoZ1Jg7hsTV8sCUS7AC6Mh2VeSA== 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)(3231254)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DB6PR0801MB1974; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1974; X-Forefront-PRVS: 07215D0470 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39850400004)(136003)(396003)(376002)(366004)(346002)(189003)(199004)(7736002)(26005)(53936002)(305945005)(4326008)(50466002)(39060400002)(478600001)(6506007)(386003)(186003)(6512007)(51416003)(6486002)(66066001)(47776003)(25786009)(76176011)(97736004)(2906002)(2351001)(52116002)(16526019)(11346002)(105586002)(36756003)(8936002)(69596002)(53416004)(3846002)(6116002)(106356001)(81156014)(81166006)(446003)(2361001)(7416002)(86362001)(54906003)(2616005)(6666003)(16586007)(956004)(316002)(486006)(48376002)(68736007)(1076002)(50226002)(8676002)(476003)(5660300001)(6916009); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1974; 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; DB6PR0801MB1974; 23:eQM2ecE3PVN0XQJiWH9RghfVkqaUpQFeRmkaaVF?= =?us-ascii?Q?9lxz8e0agFUDgEEdSjCjvdaJP+5Rqp/n3UwTpfNF4wzHCE3iGRU7rkdoyC23?= =?us-ascii?Q?QX238WSI/NdHTzT7D+O/E/jAUl391eM4VC5/gx4h5LPqeuUAY2TL9T0PfWZ2?= =?us-ascii?Q?CT7lf0caq5/Fl8V22BXtozcIZ392epQJOv9C4AYd2tE6l9VaGLMlEAaqcSwl?= =?us-ascii?Q?YbgmnRqPpkLH9cDaviA6JnTFJGR/igNwD1TEHfnlrLimzhUrXxts074Txkly?= =?us-ascii?Q?lePubAsKo0snnQGZz7kaSxn0iwZ/M3X/7aYl6nHftbJdequfsXLCjFMVBEkV?=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30Y5Q1cmRQvmxCqUaBGX+M1lxF/NUnt8vYvvb/H9MR0aa2D8K+5XaQJLr/mZU1wjIMhcFgr74FkZ/nE7qV+4Ln7C9OxVm1Wh6/Rr9l7BhWemtCLiSD+2BjIKTCclHiLu11qTZM9arLeJxmU9gtYtPebr9e8=; 24:buEhpynjvDOoMF2czYp9HEAuIfKMqVaa5PR0X+0jD5Dg2JtzLq4t+BnXcbh6IL4ldrYZoIqJPBgrAIgqu0gy2zpl66+yyJ/HCp/O90z5ZMQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1974; 7:hBNXv5GE8DomDO1x4P71Xqq0AI0Qi5VIdo2XycND9+rxh2Imf+c9RxgacNpiyIx1ry8rcI3abriabtc4siBu5ZwnI+0XSEoHmvu+8SNWa2nShHUiuAoVBsgWRW8WyTndaJc4re/xVf1On1b4CuBtseSZKbGbXcPYuO9nKyIsdXeBkz43+xmQ5uG7urMXl13u4bZhMNPegBnh+qwl3APZOITS8IQFs1z668AiDqjd74OvMsdKJgzP98Imx2/2Itq5; 20:OtKgoc5XbNar17J+QgekAvNWd2w/Y0hweGhZmZRnYleH6dBjkc8onFbhRLkTWn3Ki40shjF0lKRnYGqnOPPmNy5TT55RBTSWGV7RkMsGJN86dkPCDQjck+vHVX7c7CLYmgbXEyZip11Cv64C7qiX33mJqhhoTrYE/W4lBUTkq/I= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2018 16:58:52.9293 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6ccd8f8-888f-4dfc-3ac3-08d5e03d1838 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1974 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.103 Subject: [Qemu-devel] [PATCH 1/6] hyperv_testdev: refactor for better maintainability 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 , "Michael S. Tsirkin" , Konrad Rzeszutek Wilk , Venu Busireddy , Liran Alon , Igor Mammedov , Si-Wei Liu , Paolo Bonzini , Boris Ostrovsky , Karl Heubaum , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make hyperv_testdev slightly easier to follow and enhance in future. For that, put the hyperv sint routes (wrapped in a helper structure) on a linked list rather than a fixed-size array. Besides, this way HvSintRoute can be treated as an opaque structure, allowing for easier refactoring of the core Hyper-V SynIC code in followup pathches. Signed-off-by: Roman Kagan --- hw/misc/hyperv_testdev.c | 116 +++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index bf6bbfa8cf..de07d7e8c3 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/queue.h" #include #include "hw/hw.h" #include "hw/qdev.h" @@ -20,12 +21,17 @@ #include "target/i386/hyperv.h" #include "kvm_i386.h" -#define HV_TEST_DEV_MAX_SINT_ROUTES 64 +typedef struct TestSintRoute { + QLIST_ENTRY(TestSintRoute) le; + uint8_t vp_index; + uint8_t sint; + HvSintRoute *sint_route; +} TestSintRoute; struct HypervTestDev { ISADevice parent_obj; MemoryRegion sint_control; - HvSintRoute *sint_route[HV_TEST_DEV_MAX_SINT_ROUTES]; + QLIST_HEAD(, TestSintRoute) sint_routes; }; typedef struct HypervTestDev HypervTestDev; @@ -39,88 +45,76 @@ enum { HV_TEST_DEV_SINT_ROUTE_SET_SINT }; -static int alloc_sint_route_index(HypervTestDev *dev) +static void sint_route_create(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - int i; + TestSintRoute *sint_route; - for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) { - if (dev->sint_route[i] == NULL) { - return i; - } - } - return -1; -} + sint_route = g_new0(TestSintRoute, 1); + assert(sint_route); -static void free_sint_route_index(HypervTestDev *dev, int i) -{ - assert(i >= 0 && i < ARRAY_SIZE(dev->sint_route)); - dev->sint_route[i] = NULL; + sint_route->vp_index = vp_index; + sint_route->sint = sint; + + sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL); + assert(sint_route->sint_route); + + QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); } -static int find_sint_route_index(HypervTestDev *dev, uint32_t vp_index, - uint32_t sint) +static TestSintRoute *sint_route_find(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - HvSintRoute *sint_route; - int i; + TestSintRoute *sint_route; - for (i = 0; i < ARRAY_SIZE(dev->sint_route); i++) { - sint_route = dev->sint_route[i]; - if (sint_route && sint_route->vp_index == vp_index && - sint_route->sint == sint) { - return i; + QLIST_FOREACH(sint_route, &dev->sint_routes, le) { + if (sint_route->vp_index == vp_index && sint_route->sint == sint) { + return sint_route; } } - return -1; + assert(false); + return NULL; } -static void hv_synic_test_dev_control(HypervTestDev *dev, uint32_t ctl, - uint32_t vp_index, uint32_t sint) +static void sint_route_destroy(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) { - int i; - HvSintRoute *sint_route; + TestSintRoute *sint_route; - switch (ctl) { - case HV_TEST_DEV_SINT_ROUTE_CREATE: - i = alloc_sint_route_index(dev); - assert(i >= 0); - sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL); - assert(sint_route); - dev->sint_route[i] = sint_route; - break; - case HV_TEST_DEV_SINT_ROUTE_DESTROY: - i = find_sint_route_index(dev, vp_index, sint); - assert(i >= 0); - sint_route = dev->sint_route[i]; - kvm_hv_sint_route_destroy(sint_route); - free_sint_route_index(dev, i); - break; - case HV_TEST_DEV_SINT_ROUTE_SET_SINT: - i = find_sint_route_index(dev, vp_index, sint); - assert(i >= 0); - sint_route = dev->sint_route[i]; - kvm_hv_sint_route_set_sint(sint_route); - break; - default: - break; - } + sint_route = sint_route_find(dev, vp_index, sint); + QLIST_REMOVE(sint_route, le); + kvm_hv_sint_route_destroy(sint_route->sint_route); + g_free(sint_route); +} + +static void sint_route_set_sint(HypervTestDev *dev, + uint8_t vp_index, uint8_t sint) +{ + TestSintRoute *sint_route; + + sint_route = sint_route_find(dev, vp_index, sint); + + kvm_hv_sint_route_set_sint(sint_route->sint_route); } static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint32_t len) { HypervTestDev *dev = HYPERV_TEST_DEV(opaque); - uint8_t ctl; + uint8_t sint = data & 0xFF; + uint8_t vp_index = (data >> 8ULL) & 0xFF; + uint8_t ctl = (data >> 16ULL) & 0xFF; - ctl = (data >> 16ULL) & 0xFF; switch (ctl) { case HV_TEST_DEV_SINT_ROUTE_CREATE: + sint_route_create(dev, vp_index, sint); + break; case HV_TEST_DEV_SINT_ROUTE_DESTROY: - case HV_TEST_DEV_SINT_ROUTE_SET_SINT: { - uint8_t sint = data & 0xFF; - uint8_t vp_index = (data >> 8ULL) & 0xFF; - hv_synic_test_dev_control(dev, ctl, vp_index, sint); + sint_route_destroy(dev, vp_index, sint); + break; + case HV_TEST_DEV_SINT_ROUTE_SET_SINT: + sint_route_set_sint(dev, vp_index, sint); break; - } default: break; } @@ -139,7 +133,7 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp) HypervTestDev *dev = HYPERV_TEST_DEV(d); MemoryRegion *io = isa_address_space_io(isa); - memset(dev->sint_route, 0, sizeof(dev->sint_route)); + QLIST_INIT(&dev->sint_routes); memory_region_init_io(&dev->sint_control, OBJECT(dev), &synic_test_sint_ops, dev, "hyperv-testdev-ctl", 4);