From nobody Tue Feb 10 02:42:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1539896978284221.57600578650352; Thu, 18 Oct 2018 14:09:38 -0700 (PDT) Received: from localhost ([::1]:44705 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFY0-0005Jn-SX for importer@patchew.org; Thu, 18 Oct 2018 17:09:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyO-0007QR-S0 for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyN-0006QF-0p for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:48 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:40851) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyL-0006OC-HT for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:45 -0400 Received: by mail-wm1-x332.google.com with SMTP id z204-v6so1611202wmc.5 for ; Thu, 18 Oct 2018 13:32:45 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-231-174.clienti.tiscali.it. [78.12.231.174]) by smtp.gmail.com with ESMTPSA id a12-v6sm14270952wrr.71.2018.10.18.13.32.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=UdK6UDPvmtaTOv2jydA8I09aT3/1CVGdzfVcL+R6bxU=; b=WD9ZQIdagkiK+XXJOKVVPXMbcdKrbjnb9SYX4zHi7KK0NQDX6YePVl9MeYJ5TJTGdY FuMPqY30LH610nlxWCmXjsOM6GKAjsLLBF1498uLTp+aOYa/SwMG1bP9iuaedgbcyL+W eCMv/t92HbS/SYy55uW9a5N1gpqGLjIiC4o0upMibUhNtfGo+9gY39i1LzgQ7k1tKLE/ mHfn3EjlfSLL7KzmVxWcoTor44SzGSgSTapJ7XPElKPDsDV6g15XUfmUUOIU/EjnUWiF 8l5BNHrRdyw3+nICYq/8jxb7w5B0qeGRwr8s+xcJs4NM463dbBuMuDUVKf09v67Vqn3L Uhqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=UdK6UDPvmtaTOv2jydA8I09aT3/1CVGdzfVcL+R6bxU=; b=B84p+quN4v3NDRjYVcC+xQrMYmx5oPXm5WOLYS4rwM+y9yV44e5X5TJlakzrUkT1y6 yu9/PqzfLUwz3QjqFgc4pGV+Sl3xKlN87/sZbh8vTeIyvI9HZBqvpng1trwk62u0AUxB 3t74WbK16qdShHZ5+yzThIVnC3Ea7fxRqh0GijUKyI8Rz/gF+9RpBrrYjglsx7AlBbtH f1eaNOcVD4CNwqy1uRlUFqVhHNEVrodHyrdNQbXndJzJTvpEcuXn+lUOF67R24dp2Mt8 K3iZIGCUgCDT/SlsvO1T62+oObmh85HrrN5e6KNkztD0U5W+qqfxEJ3T34G72NufZlzs 5bVQ== X-Gm-Message-State: ABuFfogApLQlRono20KYWuiKcPBYdqgM6q8azaC1ZXVSSrJALeVr+UKt MGdPQbuXFvGDj4jm5AoielYj6Q3j X-Google-Smtp-Source: ACcGV63DAlE/GJl7XL9V8L5cZoElV7XlMp7qeRtwQISzK7iWdlqU38ggiB8lG9zqGBAaP3ZIGMQ/PA== X-Received: by 2002:a1c:a8c2:: with SMTP id r185-v6mr1866733wme.8.1539894763990; Thu, 18 Oct 2018 13:32:43 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:51 +0200 Message-Id: <1539894735-14232-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> References: <1539894735-14232-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::332 Subject: [Qemu-devel] [PULL 24/48] 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: Roman Kagan Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Roman Kagan 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 Message-Id: <20180921081836.29230-2-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- 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 7549f47..915d74e 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -12,6 +12,7 @@ */ =20 #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" =20 -#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; =20 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; =20 @@ -39,70 +45,56 @@ enum { HV_TEST_DEV_SINT_ROUTE_SET_SINT }; =20 -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; =20 - for (i =3D 0; i < ARRAY_SIZE(dev->sint_route); i++) { - if (dev->sint_route[i] =3D=3D NULL) { - return i; - } - } - return -1; -} + sint_route =3D g_new0(TestSintRoute, 1); + assert(sint_route); =20 -static void free_sint_route_index(HypervTestDev *dev, int i) -{ - assert(i >=3D 0 && i < ARRAY_SIZE(dev->sint_route)); - dev->sint_route[i] =3D NULL; + sint_route->vp_index =3D vp_index; + sint_route->sint =3D sint; + + sint_route->sint_route =3D kvm_hv_sint_route_create(vp_index, sint, NU= LL); + assert(sint_route->sint_route); + + QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); } =20 -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; =20 - for (i =3D 0; i < ARRAY_SIZE(dev->sint_route); i++) { - sint_route =3D dev->sint_route[i]; - if (sint_route && sint_route->vp_index =3D=3D vp_index && - sint_route->sint =3D=3D sint) { - return i; + QLIST_FOREACH(sint_route, &dev->sint_routes, le) { + if (sint_route->vp_index =3D=3D vp_index && sint_route->sint =3D= =3D sint) { + return sint_route; } } - return -1; + assert(false); + return NULL; } =20 -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; =20 - switch (ctl) { - case HV_TEST_DEV_SINT_ROUTE_CREATE: - i =3D alloc_sint_route_index(dev); - assert(i >=3D 0); - sint_route =3D kvm_hv_sint_route_create(vp_index, sint, NULL); - assert(sint_route); - dev->sint_route[i] =3D sint_route; - break; - case HV_TEST_DEV_SINT_ROUTE_DESTROY: - i =3D find_sint_route_index(dev, vp_index, sint); - assert(i >=3D 0); - sint_route =3D 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 =3D find_sint_route_index(dev, vp_index, sint); - assert(i >=3D 0); - sint_route =3D dev->sint_route[i]; - kvm_hv_sint_route_set_sint(sint_route); - break; - default: - break; - } + sint_route =3D 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 =3D sint_route_find(dev, vp_index, sint); + + kvm_hv_sint_route_set_sint(sint_route->sint_route); } =20 static uint64_t hv_test_dev_read(void *opaque, hwaddr addr, unsigned size) @@ -114,18 +106,20 @@ static void hv_test_dev_write(void *opaque, hwaddr ad= dr, uint64_t data, uint32_t len) { HypervTestDev *dev =3D HYPERV_TEST_DEV(opaque); - uint8_t ctl; + uint8_t sint =3D data & 0xFF; + uint8_t vp_index =3D (data >> 8ULL) & 0xFF; + uint8_t ctl =3D (data >> 16ULL) & 0xFF; =20 - ctl =3D (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 =3D data & 0xFF; - uint8_t vp_index =3D (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; } @@ -145,7 +139,7 @@ static void hv_test_dev_realizefn(DeviceState *d, Error= **errp) HypervTestDev *dev =3D HYPERV_TEST_DEV(d); MemoryRegion *io =3D isa_address_space_io(isa); =20 - 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); --=20 1.8.3.1