From nobody Mon Feb 9 17:24:04 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 153989830016467.22650490319438; Thu, 18 Oct 2018 14:31:40 -0700 (PDT) Received: from localhost ([::1]:44846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDFtL-0000BB-0e for importer@patchew.org; Thu, 18 Oct 2018 17:31:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gDEyU-0007Y5-NM for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gDEyR-0006VC-PO for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:54 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:34195) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gDEyR-0006UL-Hr for qemu-devel@nongnu.org; Thu, 18 Oct 2018 16:32:51 -0400 Received: by mail-wr1-x431.google.com with SMTP id l6-v6so34705513wrt.1 for ; Thu, 18 Oct 2018 13:32:51 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Oct 2018 13:32:49 -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=Gl5IfXSxMqWRiof4r+tdOTzPmAW5QBMoGSHXsK25mxI=; b=usXoxc9T3QKHtpW/MolNlG7g1bxeXHzA3dQCW2yw+Pj/FyynHhAnuS0RQortymhnWm DhB+vnylHiwM9kaMCxLL/MFHjjFF/Gzt7lpuOztoxIgea5XBR+8ISaP7p9+mbXwU5v2Y 8byD5oXNz7PT1fo4hxyI6y6vBKvFBKnZTvm9Rdg2B6Se5LcUVoRtDCVBLHjm4Gujxl6/ yBBVFqbUlTzB2hdZ6/mQ0Ps6svkfFYwvHGs/MxkIwN7HsBehqypN81NxU2n5qGmCH9yn Mu44HqNIX1nnJuUWj76e1KR1y2t18BbpDG1fR2ZjT3d/A/LjBBBGQGSw8cBsG2CEHfSV rV2Q== 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=Gl5IfXSxMqWRiof4r+tdOTzPmAW5QBMoGSHXsK25mxI=; b=E3fc0P4ma+S4mVN2TO97uAhKIjRuzhWB+aiyjhoMwtXSlpdeA50Gk3gnoegBRSly00 zjEDmI2wMErTOB6lOss9QcFTWZlRQKAsnzrIRVIVz04SH3VDkrqMz2WQPBYKusgYL5Gp tvvIIDCrWPuf5Cnicd53N2UgeMfZXrrUWWuzlDjnM2E7Yi6ZbY1Z0Z09VVwss3oxotYe Bizi+a9OWKinilZRIDjhTZ4BXfeLRaBJKdmzM30fvbUJcixph3RIhik6PXu5CeyAQfrU 2PMkLyM8/DXgJVf3GDzh6IN4EjP5UdxkzsnzXPjdGwYih7A2oJl4/WJZeJ4dwL1W/uxM rfAQ== X-Gm-Message-State: ABuFfojgOsP5aPC/x8kCklQefSqlInCzxYiFAiAo9OPigtxCQoVih4FH XIwczcs5FbKpht2w86/Sd0JQsAla X-Google-Smtp-Source: ACcGV61a4yKrENnGLDJ/bS+Jga5JxTq+9CoERpc+pE534lvW33KucSUw07nJk20BsRWFlSd37FfsgA== X-Received: by 2002:a5d:480b:: with SMTP id l11-v6mr31957979wrq.28.1539894770018; Thu, 18 Oct 2018 13:32:50 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2018 22:31:57 +0200 Message-Id: <1539894735-14232-31-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::431 Subject: [Qemu-devel] [PULL 30/48] hyperv: make HvSintRoute reference-counted 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 Multiple entities (e.g. VMBus devices) can use the same SINT route. To make their lives easier in maintaining SINT route ownership, make it reference-counted. Adjust the respective API names accordingly. Signed-off-by: Roman Kagan Message-Id: <20180921081836.29230-8-rkagan@virtuozzo.com> Signed-off-by: Paolo Bonzini --- hw/misc/hyperv_testdev.c | 4 ++-- target/i386/hyperv.c | 25 +++++++++++++++++++++---- target/i386/hyperv.h | 10 +++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 1f32d3c..dbf4e7e 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -52,7 +52,7 @@ static void sint_route_create(HypervTestDev *dev, sint_route->vp_index =3D vp_index; sint_route->sint =3D sint; =20 - sint_route->sint_route =3D kvm_hv_sint_route_create(vp_index, sint, NU= LL, NULL); + sint_route->sint_route =3D hyperv_sint_route_new(vp_index, sint, NULL,= NULL); assert(sint_route->sint_route); =20 QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); @@ -79,7 +79,7 @@ static void sint_route_destroy(HypervTestDev *dev, =20 sint_route =3D sint_route_find(dev, vp_index, sint); QLIST_REMOVE(sint_route, le); - kvm_hv_sint_route_destroy(sint_route->sint_route); + hyperv_sint_route_unref(sint_route->sint_route); g_free(sint_route); } =20 diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 0ce8a7a..4d8ef6f 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -24,6 +24,7 @@ struct HvSintRoute { EventNotifier sint_ack_notifier; HvSintAckClb sint_ack_clb; void *sint_ack_clb_data; + unsigned refcount; }; =20 uint32_t hyperv_vp_index(X86CPU *cpu) @@ -90,9 +91,9 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifi= er) sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); } =20 -HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data) { HvSintRoute *sint_route; EventNotifier *ack_notifier; @@ -136,6 +137,7 @@ HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index= , uint32_t sint, sint_route->sint_ack_clb_data =3D sint_ack_clb_data; sint_route->cpu =3D cpu; sint_route->sint =3D sint; + sint_route->refcount =3D 1; =20 return sint_route; =20 @@ -154,8 +156,23 @@ err: return NULL; } =20 -void kvm_hv_sint_route_destroy(HvSintRoute *sint_route) +void hyperv_sint_route_ref(HvSintRoute *sint_route) { + sint_route->refcount++; +} + +void hyperv_sint_route_unref(HvSintRoute *sint_route) +{ + if (!sint_route) { + return; + } + + assert(sint_route->refcount > 0); + + if (--sint_route->refcount) { + return; + } + kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &sint_route->sint_set_notifier, sint_route->gsi); diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index ab99047..cdf44a7 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -22,11 +22,11 @@ typedef void (*HvSintAckClb)(void *data); =20 int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); =20 -HvSintRoute *kvm_hv_sint_route_create(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); - -void kvm_hv_sint_route_destroy(HvSintRoute *sint_route); +HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, + HvSintAckClb sint_ack_clb, + void *sint_ack_clb_data); +void hyperv_sint_route_ref(HvSintRoute *sint_route); +void hyperv_sint_route_unref(HvSintRoute *sint_route); =20 int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); =20 --=20 1.8.3.1