From patchwork Fri Sep 21 08:18:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609297 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 5CD481390 for ; Fri, 21 Sep 2018 08:33:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C9A12DC39 for ; Fri, 21 Sep 2018 08:33:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4097B2DC74; Fri, 21 Sep 2018 08:33:52 +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 B54F42DC39 for ; Fri, 21 Sep 2018 08:33:51 +0000 (UTC) Received: from localhost ([::1]:54440 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gsp-0001Vk-12 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 04:33:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gee-0003nq-6F for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:19:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3GeY-0001tC-8S for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:19:10 -0400 Received: from mail-eopbgr60096.outbound.protection.outlook.com ([40.107.6.96]:37218 helo=EUR04-DB3-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 1g3GeT-0001PN-9c for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:19:02 -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=AcsYx8foBgvx/V5k28nBAbaWlzot46cEWIv+9d0O0rQ=; b=JgFiB9w+95YVZtr06VIvxYMJ4d/ro3oSEi7uTZQdn8X+hTNfbry/4VufFLNoKctueAh6Ai1QEyXRnn9S+gVeXYVng9b7/ciqsXljBbQ1TE7nOMkHuI+W3vqFXYg2CcqGr6lGDYn4AMwSUSPaAurpxjVaVMcSRBq/C4/F7/LPNzM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3586.eurprd08.prod.outlook.com (2603:10a6:208:e1::27) 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:18:57 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:18:35 +0300 Message-Id: <20180921081836.29230-8-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921081836.29230-1-rkagan@virtuozzo.com> References: <20180921081836.29230-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0009.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::19) To AM0PR08MB3586.eurprd08.prod.outlook.com (2603:10a6:208:e1::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df65d1fa-a8b6-46a7-5c44-08d61f9ae135 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3586; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3586; 3:oRYJAenL0qVLpKHNiVyVjONUa66LE8Lba/tAAOn34BXBdNQX/SFdMGodYIj8uMc+BFPA6Ro1/cC8zCB2ecgWcSmxR/G5xoOKe16RvVD7sfftzMvSWQ8L9gviAnlN5vE2IVTxNggl3iOMHkE7rWsR36OmUrOwQLSH1fJ9/vWdUBF5PYucU0/jMLqgNPqnuavEG5gcxAfkwt5knnH/VO0a2guPzaWko7gfaYCN0cy1uWfitok0oGMgO8hm22DIUg1H; 25:Vcz78wjwuOQZnLyBOqVvo9ot8gIk5nvCNMHExLsGWhfnARZ94yuuiYspeOBjoxuwnf8ZHTpCQc3Er8cr5e8XDe3OLCr6yC1ntSecRLj9wjGGhR+U0rA20aHeq5IWO84dh8u3uKUf4uaQbhZhYwvbJnoUC77WjAyUNOCXQxFdHxzpiVb4HJ1qucwzGAwYrBDQJFU0LTys0hUhY3Yy3ajquQ8ovvEG+8QGZMyQCaHguPr+u7ekuKR8quauaBNREsZI9wHc4ObE9/I6yJCfULz+h0hFqqyRpGy1PBIKO6R8tfPoDtD/0M6pHEXEDo5LjymEYFpFyj4CPBBHCWpLGnhNbQ==; 31:2/aLeIWp/WtQVqjPxHkPvocZ5nbsB55ylXqNMCrcPVDbDPuSzdZYem69Ro9Fm5RKzd3J1V5TtORBwvF67EBHs2ZiPXLfpjhlGtyU5UZCXuHFMdwx4h5rvYu6z7h4JQOqrWVsrxh+YlSSJHGPI9+dhHH71Kfz59ROHtHk4kbt4qlAcY4mjqGNvYQVe58OtbvTimZ9dOFB7cVrLKKcCMfl82R6hfJfqyMsHDJ4Z3yC4FM= X-MS-TrafficTypeDiagnostic: AM0PR08MB3586: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3586; 20:Z4+VCrHoPdbtldSR24gBnvJz6SjDEC6OX1n/YTy37IWQtV5j/950rQ0k9AvacKQhOlRCYq4YDwEEcOSYe6tTX5Xejm486JJ845JzoxWc2PwbnXAqA45NgDX0C8PjauLO0gcnna165hKw76Lr3sPqIKSj1JixJS/c7p5WvnDPFiTgqYlIDDiW1vlizZajh7D1fIvHu7yMDV6244iZVks2J3l4Gr4JfpxGRGiuB32pK4JcjVg6G+ntQQBTs/ElVS0Hj88N3oUyRcNMsIhhhD7KdWD7euss7PuMtR2dAjhXiroEIvHZ1bNQNP65+B6QHvJvjYHXdmhYoN/hTck97jp9t2GNHNQ8GGzFOuslOxbwmXkSkPuEibQP0/qCEhEUNnLUcKxL70vnd5n2/0epKuSc1UDn/SQb3vxykF5l8C4VxcnLNxzsacVgy1is32VHWISQzfL4ellta6+8iHtkW5soluje1Yt1eWKQ9leIa17y0pX5Bd4//DzPjeLhyREtKOR4; 4:QfyZaV3X8gItlJdnGgtVeAwdzdlbg2fSST6Mjmgi+kp/eFGBkYsiUWCtuUmcaj1Rlr/1C/d/Q5R/ZYB9kZNtO6s1DfuyoQCMDVH89/o6vGxVTr0qoxlV1pXDwcF1efM7ygWWnwSU+Y2LAx8TKD4zvM2kVWoRwsXAnnA6rkllKmetEGEWUks4wx50NCqrFrWwXNDNVGSkIg7fvjIr4ejIfiBfrGbg19/n4jen6KsSVZw06SIwpbKg9O+zrENRzQ5iejmdi32hJPHMXCbzskGbAjkK/zw318H1vOqc9PkWkMkaTNNYTmLu/1EQ3XWiCGfT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231355)(944501410)(52105095)(149027)(150027)(6041310)(20161123564045)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051); SRVR:AM0PR08MB3586; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3586; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6029001)(396003)(136003)(376002)(366004)(39850400004)(346002)(189003)(199004)(2906002)(81156014)(50466002)(51416003)(305945005)(25786009)(2361001)(478600001)(316002)(7416002)(54906003)(86362001)(16586007)(26005)(52116002)(48376002)(8936002)(36756003)(76176011)(186003)(50226002)(386003)(69596002)(2351001)(53416004)(106356001)(6486002)(11346002)(476003)(446003)(8676002)(16526019)(5660300001)(2616005)(956004)(6506007)(81166006)(68736007)(6116002)(1076002)(6666003)(486006)(105586002)(97736004)(4326008)(7736002)(3846002)(47776003)(6512007)(66066001)(6916009)(53936002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3586; 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; AM0PR08MB3586; 23:ukeK24LFoWFELVKEa3Dray43YCiONHOfBitpnXOOP?= C1JkrYmsBrS3lEL2DjSyrfsNKGQMii+L2kMeGQSJvTUtJWg5AyXA2JJLiSPH/bIQC5865w61HpCe51eUSZNpynfadoLE91gWsHEPfGocIUKihP4Yvc9I+Z3yK/qnMX8Q8d3FCUos2wKsJDstL4W9yocseBuZc/P/ZvFmCowjo0YEGEXqqJXWAxWCHz3VCnyCBxLLsiD0naREDBVQC6lfX9Yeb8R2fmS1/0/gVZFBvvNtsBd3kmDkMIabSQ6XG6sJb9Dex8Z79VM43ASd1qnxRE/9VfYjsNeo9+pujX3r8ml2FMdXNXbXZmMhWSGGiJ4brLg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bv1fNiBK5vLspEqWkmwl4UZzGyRHuxhfBoOMjqhmyJSm0+L0FADrJ3x8upday5bJERYJLosU9ydz5M631Bs/Rt3WIZbtWG7fDhhxZXRSVsq8PXZ3op+N SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3586; 20:MiBgCIBifJXmw4JVSBDmF/zVPPl6J77PJiCIo25VxHJujlDLvSC5B7dDToLfYlzZSwlY6nJ1JtRyrGSgz6Gmu11dUQKRA7JU3YnmIZHZz2s+W9TW9MNmQ/bHyMuPZyi7QiMjhULQCCFIw2+5jz+9IvC1/+h6zV611+CF+rv7gt0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:18:57.2048 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df65d1fa-a8b6-46a7-5c44-08d61f9ae135 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3586 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.6.96 Subject: [Qemu-devel] [PATCH v2 7/8] 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: 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 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 --- target/i386/hyperv.h | 10 +++++----- hw/misc/hyperv_testdev.c | 4 ++-- target/i386/hyperv.c | 25 +++++++++++++++++++++---- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index ab99047bf8..cdf44a7757 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -22,11 +22,11 @@ typedef void (*HvSintAckClb)(void *data); int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit); -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); int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 6f4fa2ab91..0d0776eb3c 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 = vp_index; sint_route->sint = sint; - sint_route->sint_route = kvm_hv_sint_route_create(vp_index, sint, NULL, NULL); + sint_route->sint_route = hyperv_sint_route_new(vp_index, sint, NULL, NULL); assert(sint_route->sint_route); QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); @@ -79,7 +79,7 @@ static void sint_route_destroy(HypervTestDev *dev, sint_route = 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); } diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 0ce8a7aa2f..4d8ef6f2da 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; }; uint32_t hyperv_vp_index(X86CPU *cpu) @@ -90,9 +91,9 @@ static void kvm_hv_sint_ack_handler(EventNotifier *notifier) sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); } -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 = sint_ack_clb_data; sint_route->cpu = cpu; sint_route->sint = sint; + sint_route->refcount = 1; return sint_route; @@ -154,8 +156,23 @@ err: return NULL; } -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);