From patchwork Tue Jun 6 18:19:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769551 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 EA82560364 for ; Tue, 6 Jun 2017 18:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E63A32654B for ; Tue, 6 Jun 2017 18:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAE1927FB8; Tue, 6 Jun 2017 18:23:58 +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 218C22654B for ; Tue, 6 Jun 2017 18:23:58 +0000 (UTC) Received: from localhost ([::1]:39634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ93-0008PV-3v for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:23:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5M-0005kw-3d for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5H-0007H7-Lc for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:08 -0400 Received: from mail-eopbgr30138.outbound.protection.outlook.com ([40.107.3.138]:64275 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 1dIJ5H-0007Ep-DE for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:03 -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=XDTgMCRmi+FCkOZ6AUH0wM9FqknKx7pKt3tfWkYrQHg=; b=KUcqYgkzsxsvphHXRm6YZPes1hufo5Q47+Hg8r881dN6uxLQ12sPwZARpW+iMSAtYaYM+Bgt0EtA6r0B5kqmGDYXLNfLYzf4NszKQ0EQC0GYk13uK1abT26+MBkAeRmuqc4WKz9Qm+FMfTR0gRH2X/4LlgSdAWeOzFxCyTU84ew= 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:00 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:32 +0300 Message-Id: <20170606181948.16238-8-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: 2653da02-3ba7-4c18-dab0-08d4ad08a57e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:jtXy3mxh3indcjPdWVhRxDsLKAgzc7DedF9CH7N8upas9aKzGBJPiwp3+XWBe0Z1ZJck9rDj2zBknjxfiVcNA56VDTuXQzH7AdZQzM0jUG87DT4x2GOt5AsaCxftvcO8zdG5bCSAEh9Ps77aCjXBiBkah5zZ9D72pswusy8cV+9QbE0kp3KN1tnH+W9nqs9JRQgMynLAfDiDLg333LE/T4MqEFiw9Tn998ooVdbho2SaZEeQ/HKY4rDXTrNxAJJtOhnYOtn/KCHhvV2f8ZR8ZOpk/9DJ5ZuwoW1w1ktEW/plhaGitojqIQhUSCA252RkgBJQb5aod9gSeOPCAy3JAg==; 25:8aPu5Fqin40+1pgaHu9wP1ZwAMwXfJ7bx0CuuCG8x6kStIJj7TXj6iVZpCvPJOfKRU1EV5n4c45uska7OqBGGU8ZkdAtbBpoZshSl1ICSX/jOhM/3XZ0EukbzTa4+2Y9t8FeLS6Js2H5TsQHmXiuXOtibJG87q/PwN/sgvKok8Z4IQQVOtI4AftZNAP2ZXSb4XW/3Jbl8ZlEJJuYnL/6vX3IybwP7blTs3N4qYqsxZ4xrqnuK4eWsZ4TNZl1NJgaWoTUkBumkmgiPRLa5cENx5IlwB9txQz4nU9dy1hT7gg80xTxEudXrljWAGmJ1EQhePutnpU/jLix/0MDvP64U+9KKH+/LrpBkLTELEDicb+X5nDmeEqHy8sfFnA23+vVBNWHNeeEM4uynkBc7oYabuILlxTRwLAQH0lpgBJW4pO+LA5J8Kk5Jes2QB5c7MYs5mupNjeKHBAEMxkxi7UaAdpBWL97zOtxqlsyhcHL0co= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:ncPTI2fUfA+Q9xfGvcoxj3bNenuQ+pP3/eHZ62bma+LckDmMQoLLC7Eo2JaLhQcfXmWXQJ/QZ8NKiE6gj8Uht/v1tvXqFNgq2+aa9vyIDoO1VYZw3zQgICikvTvo3wi7uwYeW07ZY2qgykooiKqCjk7HeyoRORen6HR4BxlqQVU0iQmwGKAiodZMl76GAPhdchhg2dvCI2AZhgTv/wdCnPXccbESyAGEDTLBl42f5MU=; 20:TiWeNMCQLQHpQH+8ma1rgQljWJb/gZMlg31VHO52I1kAObe2BrlE5goLsXcboRYl8/ULY7sFLIoSGUmDTgb3bzO+3L4nNvyQMOSYClbnu1ebPHhDMbUKOyZCEatsO7LPz590YBxjCjeiMaOmOp3wChOE9L3oHPynE/KrgDn9BI+ckGNLL4LVJd9HKSxFSclg9E+qilWLQxpKvkz53vPyaCQS1iwH0roG++4jLr0SbwpW2RZM9e5jHN6n/vG4rPqeu221LmnobH2azL1rbU6ghRjysN9Tr2WuWAAu+LVvTNkrVRmTsrui6ZpYERzS84nxFx4iGbnxCK9bTMCavvkyDKZnAyJEZiwx87xVO/PCTIxhp24SePeailteqvgv8whOQUpxo0uhSNgbmczEza9Rz00c6pOzTOhdz86eKuUoThU= 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:RAtUHPgtyg4u4H34e6IOIjd1tuH/SZviC0ePJikaQS?= =?us-ascii?Q?n/lW+sp5MB330uwLcWfmq2Fj/H5s6UrZ4vRLZ8CaYtmfNP7rmNZOLNeqoZCN?= =?us-ascii?Q?mfHdO1+0gUl4QPh+GRrbCwhjkRx6X6iH47q+n87Ux7dv1datpq+HeWWJOkh3?= =?us-ascii?Q?LJXwO+lB/Ocs09f/O/U6FgQ/icgSYNGEu96RRlZfRAGDKE4CI+NL2xx9xXpn?= =?us-ascii?Q?SjdyZX23XPx5qL0QVmAIK97IuZkmdUafGRNmgSxkW7LFiQbNbBZ999i/GT/p?= =?us-ascii?Q?RD4j62nUKqJ5aGm3dfQ6f/LwuMQ2pk/uxQazmrqoBfkHqVGxexMJIbcThLpI?= =?us-ascii?Q?r2HdSU9O+v9pTWXK8q62MuKUF0DFROtjIXnUbBA8gBxbrsgFL8NdtqsLe/9A?= =?us-ascii?Q?EepfqPAHq3PKbGcNC2ZEeIKqggmQ1zLLlvGzcSk24rGKXvyvK3S/MsWScs6t?= =?us-ascii?Q?pnff711cnfTrOkLzw+HYDIc/oyF77ABRXWdcO4EuPCgi+//c5L7tTMHB4EeO?= =?us-ascii?Q?IysIhO94zC1AqLgRishksFmIqF8txeKM9m9+iVY1f1TDw31t4gzQ3ftQsG6O?= =?us-ascii?Q?h266gsmkad60mBkUzIaAko/Hk5JJei22pr4h+EmEX4NyUTLTX9fe6sBRc5sz?= =?us-ascii?Q?amVkW1tMCzqovwvNXyVlgGipBLzSgrMqqe9MRP1jzYJb82LvQvBDPKpSuJ2p?= =?us-ascii?Q?DbeOiulS5gjRyJL2ZjDjjW3354xfi7XN4bO8EHlzn0os5CdKHpr85akzZLhx?= =?us-ascii?Q?7MhunH2v4WvmxJItTt7iwnPLwpK6cExMKVuxqto88xDH+U5QaBVuNF7gnyhB?= =?us-ascii?Q?D/XoU53yZHCbsMNofo/hhIOrKKdRNS9fG/QwxpklLEuPYICclzqWvH5FNxYn?= =?us-ascii?Q?Xy3oTEKc89DUlQsYNOrhsziQ8qZ+mjdBMKWcCYDYoGR2DSSSD73LFAX6r5v1?= =?us-ascii?Q?ggaowrbuCvxNqbzI0PK4NO5fPVtmOJQRfR0P6f77EChypFS6u1WObsACe0Qb?= =?us-ascii?Q?sx/9L/9Xo8Jv5bhSfLZ7BeRI6b5ybxPpniAIY7eDnG+jT4JT2m+bgoSEmh2J?= =?us-ascii?Q?rtePnL1YI3ZzAMYOA0R1OGXnQ2rQsJK9dw7T+OmHrQR2bMacVytE6QpBt4nu?= =?us-ascii?Q?FWtoanglH8hHngVoSS465r9AZ+Lwp3?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(48376002)(33646002)(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:LDnXzTDbu4uscFWFrPDPni/SStUWyRcWFbq1Zt5lo?= =?us-ascii?Q?5wYptQwfnYbSArlquQKmMjOmI27pYaQmn8cOiVCPiCJINEAEYbPBliN1OBlN?= =?us-ascii?Q?vZY5/pLleRmcwiaNa8VvMwUJcGPzHpNovHdoi0kvJFqgdyeRh1J3noLcfmT+?= =?us-ascii?Q?V6sZnaTNONMJ59NvvRwxY9pKar6y0U394dR+c0rqznrhw0sqkGddZb6hIz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dXVOF8gjBQViyIwBuqXetDP7rAp/9O1Unh83Yp8QMFSBBldCRkwcDZimeftl/zhI7d3+e1iNkgi4qWOwqHz2sgAUUyBy55zWqIbLMss; 24:X4CkXuAeC1g7/Tx1flZ0TFGx+GBsFp+s+r6064iusUAYw4uMBYwqlJ9k0Fb7H7ObwWUQ+lHj0DCM/EvFxdTWya19Tp3GN8E4Qdc+cji90i4= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:3Kr04AguqIpSDd7JHiJgpwesse6YGzMkh2+9N1Je4uF2n6Ci7gKDWA5EENZbxL+CgShiXc0GzFJC/tp21c7yfe20GbyEq75Lf41HL4Bk74QFVjURfGyx2Px6eSThfmk9+hvDiGMaJjBA7i934LL47z2xsZP4nvam9DHe03y8RATsh5jiWbiw5GhPLV68gl3yLlDI9utRaVKiLl6tO8SiTGa2iQOVSiOG/HYhhgMjmwpF8IdZYik8qe4hhzdXiyLm/NiXJfRJYIQPGnq0u6kMemPsuiK4Lp6DoDsvSbtahH0ZFE6ci25w7+4lvKziXwr15HfWGcTFde1Mch06aKYZsg==; 20:Om4vs2UAZj76I0wq0Cf6XP0wi1xOOGmQgbUN9cSgz5ZIB4d/PeIy6AqVa3lMnXXcm4LfhAyluENgbxyRDKXQx7pbyYr1ZgHF3mlgd2q3sGCiedKCs2fSQw1MAWF5IKX053qyFi//bAFrdk4sQuhEsMjWOoPIV7r4KZFC7A0H6IQ= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:00.6792 (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.138 Subject: [Qemu-devel] [PATCH 07/23] hyperv_testdev: refactor for readability 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 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. Signed-off-by: Roman Kagan --- hw/misc/hyperv_testdev.c | 113 ++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index dbd7cdd..da87630 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 cpu; + 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,73 @@ 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 cpu, 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->cpu = cpu; + sint_route->sint = sint; + + sint_route->sint_route = kvm_hv_sint_route_create(cpu, 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 vcpu_id, - uint32_t sint) +static TestSintRoute *sint_route_find(HypervTestDev *dev, + uint8_t cpu, 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->vcpu_id == vcpu_id && - sint_route->sint == sint) { - return i; + QLIST_FOREACH(sint_route, &dev->sint_routes, le) { + if (sint_route->cpu == cpu && 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 vcpu_id, uint32_t sint) +static void sint_route_destroy(HypervTestDev *dev, uint8_t cpu, 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(vcpu_id, 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, vcpu_id, 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, vcpu_id, 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, cpu, 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 cpu, uint8_t sint) +{ + TestSintRoute *sint_route; + + sint_route = sint_route_find(dev, cpu, 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 vcpu_id = (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, vcpu_id, sint); + break; case HV_TEST_DEV_SINT_ROUTE_DESTROY: - case HV_TEST_DEV_SINT_ROUTE_SET_SINT: { - uint8_t sint = data & 0xFF; - uint8_t vcpu_id = (data >> 8ULL) & 0xFF; - hv_synic_test_dev_control(dev, ctl, vcpu_id, sint); + sint_route_destroy(dev, vcpu_id, sint); + break; + case HV_TEST_DEV_SINT_ROUTE_SET_SINT: + sint_route_set_sint(dev, vcpu_id, sint); break; - } default: break; } @@ -139,7 +130,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);