From patchwork Thu Jun 15 19:09:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9790019 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 8F28B60325 for ; Thu, 15 Jun 2017 19:12:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FE2C28620 for ; Thu, 15 Jun 2017 19:12:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7491D28641; Thu, 15 Jun 2017 19:12:17 +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 E57CC28620 for ; Thu, 15 Jun 2017 19:12:16 +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 1dLa9Y-00017k-Af; Thu, 15 Jun 2017 19:10:00 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLa9X-000143-9t for xen-devel@lists.xen.org; Thu, 15 Jun 2017 19:09:59 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id F0/D1-03696-68BD2495; Thu, 15 Jun 2017 19:09:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVybKJssm7rbad Ig0X/rSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1ozTc06wF0yRqNj1/gZTA2OraBcjF4eQQBuT xPSVrUxdjBwcLAIOEv9mc4GYjAIxEg9+WHcxcgKZYRKTLy9hBbHZBAwl/j7ZxAZiiwhIS1z7f JkRZAyzwGRGidfvfjGDJISBxsw61wFWxCKgKvF5yxcwm1fATWLS9odMILaEgJzEyWOTwYZyAs XPdk9khbqHUeLNs6WsExh5FzAyrGJUL04tKkst0jXRSyrKTM8oyU3MzNE1NDDTy00tLk5MT81 JTCrWS87P3cQIDAYGINjB2H3Z/xCjJAeTkigvv5xTpBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ Xo1bQDnBotT01Iq0zBxgWMKkJTh4lER4p98ESvMWFyTmFmemQ6ROMepybFi9/guTEEtefl6ql DhvD8gMAZCijNI8uBGwGLnEKCslzMsIdJQQT0FqUW5mCar8K0ZxDkYlYV4HkCk8mXklcJteAR 3BBHRE0AUHkCNKEhFSUg2MqetXdJukhzaaK+5k3JbS+GSPl05zCe/0Oc9XK0q6WSkIvCtwnZ1 1/U47g4m/TNLy+SpO5yffOqL/h+fM4Y0yCiGL79TYParpaTU8vH9On3GVLKvYrS/5rRZ+dS8f BXL0323+ks+feNpl5X/9S3lbmtjN7bdeqfrzm03GYM67xEdXU/fYLT6mxFKckWioxVxUnAgAR D6bqowCAAA= X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-4.tower-27.messagelabs.com!1497553796!107104950!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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30572 invoked from network); 15 Jun 2017 19:09:57 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-4.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Jun 2017 19:09:57 -0000 Received: from localhost.localdomain (unknown [99.165.194.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB83A239C3; Thu, 15 Jun 2017 19:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB83A239C3 From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Thu, 15 Jun 2017 12:09:42 -0700 Message-Id: <1497553787-3709-13-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1497553787-3709-1-git-send-email-sstabellini@kernel.org> References: <1497553787-3709-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 v4 13/18] xen/pvcalls: implement release command 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 Release both active and passive sockets. For active sockets, make sure to avoid possible conflicts with the ioworker reading/writing to those sockets concurrently. Set map->release to let the ioworker know atomically that the socket will be released soon, then wait until the ioworker finishes (flush_work). Unmap indexes pages and data rings. Signed-off-by: Stefano Stabellini CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- drivers/xen/pvcalls-back.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index be85977..afc9575 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -266,12 +266,82 @@ static int pvcalls_back_release_active(struct xenbus_device *dev, struct pvcalls_fedata *fedata, struct sock_mapping *map) { + disable_irq(map->irq); + if (map->sock->sk != NULL) { + write_lock_bh(&map->sock->sk->sk_callback_lock); + map->sock->sk->sk_user_data = NULL; + map->sock->sk->sk_data_ready = map->saved_data_ready; + write_unlock_bh(&map->sock->sk->sk_callback_lock); + } + + atomic_set(&map->release, 1); + flush_work(&map->ioworker.register_work); + + down(&fedata->socket_lock); + list_del(&map->list); + up(&fedata->socket_lock); + + xenbus_unmap_ring_vfree(dev, map->bytes); + xenbus_unmap_ring_vfree(dev, (void *)map->ring); + unbind_from_irqhandler(map->irq, map); + + sock_release(map->sock); + kfree(map); + + return 0; +} + +static int pvcalls_back_release_passive(struct xenbus_device *dev, + struct pvcalls_fedata *fedata, + struct sockpass_mapping *mappass) +{ + if (mappass->sock->sk != NULL) { + write_lock_bh(&mappass->sock->sk->sk_callback_lock); + mappass->sock->sk->sk_user_data = NULL; + mappass->sock->sk->sk_data_ready = mappass->saved_data_ready; + write_unlock_bh(&mappass->sock->sk->sk_callback_lock); + } + down(&fedata->socket_lock); + radix_tree_delete(&fedata->socketpass_mappings, mappass->id); + sock_release(mappass->sock); + flush_workqueue(mappass->wq); + destroy_workqueue(mappass->wq); + kfree(mappass); + up(&fedata->socket_lock); + return 0; } static int pvcalls_back_release(struct xenbus_device *dev, struct xen_pvcalls_request *req) { + struct pvcalls_fedata *fedata; + struct sock_mapping *map, *n; + struct sockpass_mapping *mappass; + int ret = 0; + struct xen_pvcalls_response *rsp; + + fedata = dev_get_drvdata(&dev->dev); + + list_for_each_entry_safe(map, n, &fedata->socket_mappings, list) { + if (map->id == req->u.release.id) { + ret = pvcalls_back_release_active(dev, fedata, map); + goto out; + } + } + mappass = radix_tree_lookup(&fedata->socketpass_mappings, + req->u.release.id); + if (mappass != NULL) { + ret = pvcalls_back_release_passive(dev, fedata, mappass); + goto out; + } + +out: + rsp = RING_GET_RESPONSE(&fedata->ring, fedata->ring.rsp_prod_pvt++); + rsp->req_id = req->req_id; + rsp->u.release.id = req->u.release.id; + rsp->cmd = req->cmd; + rsp->ret = ret; return 0; }