From patchwork Tue Feb 6 20:30:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204061 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 A4C75605BA for ; Tue, 6 Feb 2018 20:43:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9555D286AC for ; Tue, 6 Feb 2018 20:43:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8918C28801; Tue, 6 Feb 2018 20:43:01 +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 C302A28DB8 for ; Tue, 6 Feb 2018 20:42:34 +0000 (UTC) Received: from localhost ([::1]:59150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejA4Y-0003bO-1X for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 15:42:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9ti-0000cr-Tg for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9tf-00033n-IA for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:22 -0500 Received: from mail-eopbgr00132.outbound.protection.outlook.com ([40.107.0.132]:64154 helo=EUR02-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 1ej9tf-00033F-8w for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:19 -0500 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=cidwh1PfMnxxC5x/lghrBpla90b3BAL8GHRo/8cJ7rE=; b=Qjn2yL5rVq1aYHU3N9TekCGnJBbHPqE566xaoogLmDzlQ+gBMfFtvTdWIRGAnbFa//RzeTn5mGscZW3ERonwhj5lCjpDUxbNV5Ogy0vWYwMQgWk8RhGK603E9D5DmWd4c7WcCUuBK5bpFoXc4mOI1shazI5WwqmumkJcNpv6ICU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 20:31:15 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:21 +0300 Message-Id: <20180206203048.11096-8-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180206203048.11096-1-rkagan@virtuozzo.com> References: <20180206203048.11096-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0301CA0008.eurprd03.prod.outlook.com (2603:10a6:3:76::18) To VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6177f66e-e7a0-4166-25e6-08d56da092d7 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB1983; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 3:leS1lEryHrDX1d5Tmx38JS1B+NIxOrXlS82tdHpBzwzKga/WEXDMyDVQMn/9rZNp+sPNcNFFm5zbh1Kg/v/9WGJcKhiXOCq4PlTjmEaDURite70bGHVgLYy6CwRFU7eCALWkyGel8LZhkG16ZxjB1muq225Ig9LdqTn2uipqq+18VLCLml8AyHBwU7UZMbYn42r6HMAS128HCFVLuXmX6PjIZSLROX7TT6OHI0Ft/EyUEKhk0uTMsqlnFTsnKa08; 25:wIWmOpz0AdMAjSfr0pk9AKZNDfrmCW2MvAbl1ZJIMij2no/NA2OZRZI9HqB4kYlVAeoDXB2oGG6ykx8RxvpKS21oiwoWKj1qMGbUDUV1KPxkU7qzQixhHdyvFEBjADLklf6ssOVeF7BTYgRmPTDzf32/EYJFHuoZXef+Xg/S0OJk0RU4CD91B8fJc61sigiuKrfPNNSnA5KECFKeYg2E4kvgaF5bAonsiWVvz0WV5tWkcF5Un7G8cW1owXD3jEt3Fya7B/wyMamPqmpoTEFHMgGgaPFxVPYw3HxRIzBMEsJefvKh2fTOmpHKejs9WQNbcoiQT2XWRLUwdKe8q3NYbQ==; 31:gHOzUEwnylYABMWds7/fSdnxXFYhH5McmmGcGcgQq3NOYfh7kEyJikXhLcJJcyVV5PekrLGDN/XyYtpv8iFdzTw4YStpmhGoIsYPHj1NAPtMz6/N7i3nn/LhKBqwMcZqZJ5IrUmD6dTFP9UpRGLwYiPevIEvuBupTEo9vaBHwrzcqmLzM27eLfW5MSzNTCE1Jg7hHPruv+iK8EsAEnmICLelFBiy4R9a4RiRSriigak= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:G74+txRC8K5IoAs1+i7msoQg76bDGaILAMUxCVmmUwkNLYHw49pEahr5Q4P/Wz+Dti9+pORYJ2ELKGNQmRuoj/D83buKduztiPq5mBHCipKYabrIQ5K2caNxhgzvYyikkuSVxaQycccMpxRGPb4R8/u63hD0xmZgNcn9tFf7LXC9DVfKqhzaeSXXEqhpUvqhmoHakZDO0ZjFp69hrzIMXoJHNUs5DzCjKG5NT/OMABVk7UMx42eUFIimrTJ4p0yWCla4VTRpLzTsnJEbjz3zom3NWRvsb08lXPSmtnFm/MgbdriBixX15uDm2vCQ1+2VdTgB3ODfy6R/XvbcslzYa2Zc/L8tP/Xl5riTpo0N7cGpYXADM+7wD3hVhDZXP9ps7Sr6NJ4alVk0A+8I0XFov7cVjfQEiWeHd+s/ZgEXIjc=; 4:ND4rSrRb/At7euXVjBm9IOaPXkoe/bX66Idn4i6zbNH6SMgL0L9AkdTejO/0CXrWfNoRrsTwf+P0yxLI0WNLzb/KS9QKJf7d2mJLGAHbIW6cB2Hcb+JwxTUG/PzGVKgDqHmJUtPSDQfvkMSgOZqePeVG/j5DYYpqTIoMbYIqTkSliQrN2HofAAGNrpDAnUXSBJzXj66Y9bW2LITNvwkOPEFakOCiM7K2GTLtaA9DJjw7Y9QOH6SEFrkDY8V6zzVF6I1aToP7OAItg3pnVSht0RD66iq6/HkzMTBtm3uWKN6fLUmHznUVjgOW7S9tUtWj X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(60795455431006); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231101)(2400082)(944501161)(10201501046)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0801MB1983; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1983; X-Forefront-PRVS: 0575F81B58 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6029001)(396003)(366004)(376002)(39380400002)(39850400004)(346002)(189003)(199004)(16586007)(53936002)(305945005)(54906003)(7736002)(3846002)(316002)(105586002)(2361001)(106356001)(2351001)(6116002)(1076002)(50226002)(8936002)(81156014)(5660300001)(8676002)(81166006)(7416002)(2950100002)(6666003)(6916009)(76176011)(86362001)(68736007)(66066001)(16526019)(47776003)(50466002)(4326008)(97736004)(26005)(6512007)(51416003)(2906002)(52116002)(386003)(6506007)(48376002)(55236004)(36756003)(53416004)(69596002)(6486002)(478600001)(186003)(25786009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1983; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1983; 23:5nRL9kPuwfDmRV2tqWQGA0+p57n1OHKIi9vO5Jp?= =?us-ascii?Q?cZ9ApXVV7lzkEng/fK/KSYva0yMXoJH7FztcvEMCZhNzF0xfQJa34O2EFu8q?= =?us-ascii?Q?dC3BiNhVipKrFYw/M0CESiknS5ia6WeDYScDyoJ35LbaUqMxf0PhPX61bq/v?= =?us-ascii?Q?toNP09TOX4CORlE6gIZfGgw5xQQlvrI5A5Uk/kvcq9Mt4jn/T6Via04OYB4s?= =?us-ascii?Q?r6Hr7v9oUwdsj4sZoQxhx9vn+O+I2qFZmXU64puYRgJTjPXNGUIzxkrbRskl?= =?us-ascii?Q?d/eFdRYLAJNk43mzVFS2UaMUHcU6q1P4oVvX3wTi/IV6wa6Af+9SyNx5T5II?= =?us-ascii?Q?WBsjV7cKPdSHcREDTQR89Si8jRYZBv/uAe1RaVDwyGlqp9qYqic7c4wxOtN0?= =?us-ascii?Q?QMgkmKRo6NQ/a6ytYDc96rsWOzGQsKA1ri+W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Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:hUvTcepOqtTp9SSrUUtq3r6DK+NM61L1t96wmZSGsJEsvEyoal+S7lkCA8x+o6BC4qhmOKRwQBq+y1fX6Tovlvn9GGuTpjAMQfyvIxgzXyOOg8sYmy3QIppsqQKa0dh+HZrv26J34VxU6YzdzJN7o77B+6N8widX5wswTMiKZddD1ZSFIzxtGoAgwKkgP18+GdFAhCIP0KXXsjhVPNbiTURQVR5yuFIcgj2+ZEWk05HNHup3ng28bV5TeJPgudy95ooqXVkKqrau0mfnzE4oqhNfPGkqatiUV+3lfvHwUQw7wBJv9r7yNEy0Sq8Zgho6yrUO1u8S+xzfWafax2r/HUOML+NnKXmPiGWh1xlvBjA=; 5:anirqnXjKAaR9MrptXchvIRBBFULnJhnT3UW0RiVe6oMG0tGXE3Qz9+Un3GYhGTm1OY7H9a/vE4sm7EreVtOFxEGDpvpiczk5TbKPZ9q0z8VMaYTWJqm4P8r5Ka8k4mzBBeTe/Lvhu051YwJ/nW9EXBJUPWu6pLCnN9IyJTEzOw=; 24:tv49Mmw//Nng25pGgjjwIZnH1SO87lNvISAK6EyNv58SlN5W7sYggeZ14FvM/U/sFTClDhLLMVQprNPZ/JIZvdMYkDn4ka/6K55p3WaLbm4=; 7:DZEwvUh1qW2l0jifO4XYt3//OhqztZAsWG4c+MY+ODIKS/Dnh1+ghP5n/KSfLfaXPk5zerzdvxsr5ZR++KsdT/o1xGbJdngxP+mxIWKzjAsMduwYoCrhMZWF5qEpgvy3DJaUZqxi6hOa4FypScc4Jh7s8Ss32IKzmisUXnEI+NgPgi89q4bh2+4XFKgJGt2MJHvE5gVQVy6Faw3EYCSrBIICaZgEl2BKG70IVyebPJ0ihfPzjtS6d1KIPrtHFNvB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:gjAD8czXawk+zv5iDf8THk1h8hYGanThf8U0Ls6eHBkv+KyzXvAqwVKkZOnO1zMFtiJomnb5+WllaxD3bgcJ4cySkQ/ABJgtebPCT/9VLKOBxtC1l6MbLGCs5CWJzR1TlMOQOSNj60NzFn3HQ272zvAdB6MccGWqPQBLa5O+2ko= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:15.9186 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6177f66e-e7a0-4166-25e6-08d56da092d7 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1983 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.132 Subject: [Qemu-devel] [RFC PATCH 07/34] 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: Ben Warren , Konrad Rzeszutek Wilk , Krish Sadhukhan , "Marcos E. Matsunaga" , Jan Dakinevich , Vadim Rozenfeld , "Denis V. Lunev" , si-wei liu , Paolo Bonzini , Vitaly Kuznetsov , Cathy Avery 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 93f7300dd6..af5fc05ea4 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -23,11 +23,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 827a8b1d82..fa435abbbf 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -55,7 +55,7 @@ static void sint_route_create(HypervTestDev *dev, uint8_t vpidx, uint8_t sint) sint_route->vpidx = vpidx; sint_route->sint = sint; - sint_route->sint_route = kvm_hv_sint_route_create(vpidx, sint, NULL, NULL); + sint_route->sint_route = hyperv_sint_route_new(vpidx, sint, NULL, NULL); assert(sint_route->sint_route); QLIST_INSERT_HEAD(&dev->sint_routes, sint_route, le); @@ -81,7 +81,7 @@ static void sint_route_destroy(HypervTestDev *dev, uint8_t vpidx, uint8_t sint) sint_route = sint_route_find(dev, vpidx, 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);