From patchwork Tue Oct 24 17:33:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 10025161 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 656DD60375 for ; Tue, 24 Oct 2017 17:35:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6234528A3B for ; Tue, 24 Oct 2017 17:35:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5759928A4F; Tue, 24 Oct 2017 17:35:43 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BEC1F28A3B for ; Tue, 24 Oct 2017 17:35:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e735G-0004Pk-A6; Tue, 24 Oct 2017 17:33:46 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e735E-0004Or-M3 for xen-devel@lists.xen.org; Tue, 24 Oct 2017 17:33:44 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id B2/2B-29298-7797FE95; Tue, 24 Oct 2017 17:33:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeJIrShJLcpLzFFi42I5NlE2Wbe88n2 kwdMLMhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8byXxwFRyQqZt/6xdLA+F2ki5GLQ0hgG5PE up3vWboYOThYBBwkPsyRATEZBWIkHvyw7mLkBDLDJCZfXsIKYrMJGEr8fbKJDcQWEZCWuPb5M iPIGGaByYwSr9/9YgZJCAu4SLxpOsgEYrMIqEocW3KSBcTmFXCT2N7znhHElhCQkzh5bDIryC 5OAXeJSxudIc5pZZToXr+FeQIj7wJGhlWMGsWpRWWpRbpGFnpJRZnpGSW5iZk5uoYGpnq5qcX FiempOYlJxXrJ+bmbGIGhUM/AwLiDsW+V3yFGSQ4mJVHegPT3kUJ8SfkplRmJxRnxRaU5qcWH GGU4OJQkeLsqgHKCRanpqRVpmTnAoIRJS3DwKInwngJJ8xYXJOYWZ6ZDpE4x2nMc23T5DxPHg p4bQLLj5l0g+Wzm6wZmIZa8/LxUKXHecJA2AZC2jNI8uKGwKLrEKCslzMvIwMAgxFOQWpSbWY Iq/4pRnINRSZh3CsgUnsy8Erjdr4DOYgI6S9b+DchZJYkIKakGxihh9eY7XfJO2cnLW++8a0q 3WBSqGGvzbsq95itTCwr+lM97VXIyZq/Y7qW3zmrOyE/jPvxzThqrZPuJS9c/Wm+7udzxR4zo ujKtY9Lzph/bfqv17+RLa26qG0vFOHcd4wy74OmXu91mwnbRP/dOmN3UvM207ugvy6rbG/xu9 aWGyP9h0+DOOKnEUpyRaKjFXFScCAANHDQBnQIAAA== X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-9.tower-206.messagelabs.com!1508866422!108574264!1 X-Originating-IP: [198.145.29.99] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6823 invoked from network); 24 Oct 2017 17:33:43 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 24 Oct 2017 17:33:43 -0000 Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (c-24-130-70-9.hsd1.ca.comcast.net [24.130.70.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2DE8D2192C; Tue, 24 Oct 2017 17:33:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DE8D2192C From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Tue, 24 Oct 2017 10:33:22 -0700 Message-Id: <1508866413-30141-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508866413-30141-1-git-send-email-sstabellini@kernel.org> References: <1508866413-30141-1-git-send-email-sstabellini@kernel.org> Cc: jgross@suse.com, Stefano Stabellini , boris.ostrovsky@oracle.com, sstabellini@kernel.org, linux-kernel@vger.kernel.org Subject: [Xen-devel] [PATCH v6 02/13] xen/pvcalls: implement frontend disconnect X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce a data structure named pvcalls_bedata. It contains pointers to the command ring, the event channel, a list of active sockets and a list of passive sockets. Lists accesses are protected by a spin_lock. Introduce a waitqueue to allow waiting for a response on commands sent to the backend. Introduce an array of struct xen_pvcalls_response to store commands responses. pvcalls_refcount is used to keep count of the outstanding pvcalls users. Only remove connections once the refcount is zero. Implement pvcalls frontend removal function. Go through the list of active and passive sockets and free them all, one at a time. Signed-off-by: Stefano Stabellini CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- drivers/xen/pvcalls-front.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c index a8d38c2..4babacf 100644 --- a/drivers/xen/pvcalls-front.c +++ b/drivers/xen/pvcalls-front.c @@ -20,6 +20,45 @@ #include #include +#define PVCALLS_INVALID_ID UINT_MAX +#define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER +#define PVCALLS_NR_RSP_PER_RING __CONST_RING_SIZE(xen_pvcalls, XEN_PAGE_SIZE) + +struct pvcalls_bedata { + struct xen_pvcalls_front_ring ring; + grant_ref_t ref; + int irq; + + struct list_head socket_mappings; + spinlock_t socket_lock; + + wait_queue_head_t inflight_req; + struct xen_pvcalls_response rsp[PVCALLS_NR_RSP_PER_RING]; +}; +/* Only one front/back connection supported. */ +static struct xenbus_device *pvcalls_front_dev; +static atomic_t pvcalls_refcount; + +/* first increment refcount, then proceed */ +#define pvcalls_enter() { \ + atomic_inc(&pvcalls_refcount); \ +} + +/* first complete other operations, then decrement refcount */ +#define pvcalls_exit() { \ + atomic_dec(&pvcalls_refcount); \ +} + +static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id) +{ + return IRQ_HANDLED; +} + +static void pvcalls_front_free_map(struct pvcalls_bedata *bedata, + struct sock_mapping *map, bool locked) +{ +} + static const struct xenbus_device_id pvcalls_front_ids[] = { { "pvcalls" }, { "" } @@ -27,6 +66,32 @@ static int pvcalls_front_remove(struct xenbus_device *dev) { + struct pvcalls_bedata *bedata; + struct sock_mapping *map = NULL, *n; + + bedata = dev_get_drvdata(&pvcalls_front_dev->dev); + dev_set_drvdata(&dev->dev, NULL); + pvcalls_front_dev = NULL; + if (bedata->irq >= 0) + unbind_from_irqhandler(bedata->irq, dev); + + smp_mb(); + while (atomic_read(&pvcalls_refcount) > 0) + cpu_relax(); + list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) { + if (map->active_socket) { + /* No need to lock, refcount is 0 */ + pvcalls_front_free_map(bedata, map, true); + } else { + list_del(&map->list); + kfree(map); + } + } + if (bedata->ref >= 0) + gnttab_end_foreign_access(bedata->ref, 0, 0); + kfree(bedata->ring.sring); + kfree(bedata); + xenbus_switch_state(dev, XenbusStateClosed); return 0; }