From patchwork Thu Oct 26 19:11:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 10028723 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 2AF5760375 for ; Thu, 26 Oct 2017 19:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1ABD028EA0 for ; Thu, 26 Oct 2017 19:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F95228EA1; Thu, 26 Oct 2017 19:14:04 +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 7635028EA3 for ; Thu, 26 Oct 2017 19:14:03 +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 1e7nZP-0004xm-4Z; Thu, 26 Oct 2017 19:11:59 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e7nZN-0004wW-BT for xen-devel@lists.xen.org; Thu, 26 Oct 2017 19:11:57 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id FE/67-20813-C7332F95; Thu, 26 Oct 2017 19:11:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplkeJIrShJLcpLzFFi42I5NlE2WbfG+FO kwYItzBZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bsVauYC7ZIVXRO7mRtYNwr1sXIySEksI5J 4vJhRRCbRcBB4sySS2xdjBwcjAIxEg9+WIOEGQXCJCZfXsIKYrMJGEr8fbKJDcQWEZCWuPb5M mMXIxcHs8BkRonX734xgySEBVwktp/bxAgxU1XiwrwfYDN5BVwleherg4QlBOQkTh6bDDaTU8 BNYtqH6ywgc4QEWhgl1m3rZZzAyLuAkWEVo0ZxalFZapGuoYFeUlFmekZJbmJmDpBnppebWly cmJ6ak5hUrJecn7uJERgMDECwg/H4+7hDjJIcTEqivAx7PkQK8SXlp1RmJBZnxBeV5qQWH2KU 4eBQkuD9b/gpUkiwKDU9tSItMwcYljBpCQ4eJRFeY5A0b3FBYm5xZjpE6hSjJcexTZf/MHF03 LwLJJ/NfN3ALMSSl5+XKiXOexWkQQCkIaM0D24cLHYuMcpKCfMyAh0oxFOQWpSbWYIq/4pRnI NRSZhX3ghoCk9mXgnc1ldABzEBHdSk+gHkoJJEhJRUA6Nnwoz4buOFNx7I8URf3SPuuz1o/Yv Ts+9OVHNXPmtzr2etr9+5LsuXi3lfRGau3b7vxN7luZqbn9qUCU5+UJu0f3ZCjaSP64tTa25e 9j5rsbKEc5aDxZQ1v7O/duw9bPzKodf4zTku21c/v75oP1PGtuTxgi1T+uf5uM6TvrpotjST0 HE1paniSizFGYmGWsxFxYkAbDi55ZgCAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-10.tower-21.messagelabs.com!1509045114!72475496!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 24946 invoked from network); 26 Oct 2017 19:11:55 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-10.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 26 Oct 2017 19:11:55 -0000 Received: from localhost.localdomain (162-198-228-35.lightspeed.wlfrct.sbcglobal.net [162.198.228.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1CCED21933; Thu, 26 Oct 2017 19:11:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CCED21933 From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Thu, 26 Oct 2017 12:11:41 -0700 Message-Id: <1509045112-9807-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509045112-9807-1-git-send-email-sstabellini@kernel.org> References: <1509045112-9807-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 v7 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. Introduce a new struct sock_mapping to keep track of sockets. In this patch the struct sock_mapping is minimal, the fields will be added by the next patches. 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 Reviewed-by: Boris Ostrovsky --- drivers/xen/pvcalls-front.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c index a8d38c2..aae23d0 100644 --- a/drivers/xen/pvcalls-front.c +++ b/drivers/xen/pvcalls-front.c @@ -20,6 +20,51 @@ #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); \ +} + +struct sock_mapping { + bool active_socket; + struct list_head list; + struct socket *sock; +}; + +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) +{ +} + static const struct xenbus_device_id pvcalls_front_ids[] = { { "pvcalls" }, { "" } @@ -27,6 +72,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); + } 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; }