From patchwork Mon May 15 20:36:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9727897 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 E33836028A for ; Mon, 15 May 2017 20:38:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE9D028644 for ; Mon, 15 May 2017 20:38:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B399528985; Mon, 15 May 2017 20:38:29 +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 2A76F28644 for ; Mon, 15 May 2017 20:38:29 +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 1dAMjd-0001JN-Ev; Mon, 15 May 2017 20:36:53 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dAMjb-0001HQ-Il for xen-devel@lists.xen.org; Mon, 15 May 2017 20:36:51 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id 86/85-03058-2611A195; Mon, 15 May 2017 20:36:50 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrNLMWRWlGSWpSXmKPExsVybKJssm6SoFS kwaLl3BZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8aSliXMBfNkKy5v+svSwDhVsouRi0NIoI1J YunhhaxdjJwcLAIOEod2XWbuYuTgYBSIkXjwwxokzCgQJjH58hKwEjYBQ4m/TzaxgdgiAtIS1 z5fZgSZwywwmVHi9btfzCAJYQFbie6GLqiZqhKLt98Ha+AVcJdo7N7OAmJLCMhJnDw2GayGEy j+evUKNqiDGCU+/r7CNIGRdwEjwypGjeLUorLUIl1DQ72kosz0jJLcxMwcXUMDM73c1OLixPT UnMSkYr3k/NxNjMCAYACCHYyflgUcYpTkYFIS5XVnl4oU4kvKT6nMSCzOiC8qzUktPsQow8Gh JMH7ix8oJ1iUmp5akZaZAwxNmLQEB4+SCO81kDRvcUFibnFmOkTqFKMux7ulH94zCbHk5eelS onzvgYpEgApyijNgxsBi5NLjLJSwryMQEcJ8RSkFuVmlqDKv2IU52BUEuZVEgCawpOZVwK36R XQEUxAR4S9FAc5oiQRISXVwLim1S4watKDPX8/aH5JdH/QqR+hbpPrcMLv+8/ML9KLFj4qr5v eVnln6XEPuRZWlgerm//6HfUTr83MNb/hdb3Cw+pgzcGKD2q5ZYcDF7DmBXR6zl/5Xrx6wf2z 2/ZtUfp/4XBNZqyVXMOlH7cOxqYpHerbU5of41anVVQdcPjaVubec/Pv7lZiKc5INNRiLipOB AC775eOjgIAAA== X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-8.tower-27.messagelabs.com!1494880608!92123128!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.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 49793 invoked from network); 15 May 2017 20:36:49 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 May 2017 20:36:49 -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 5613E239CE; Mon, 15 May 2017 20:36:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5613E239CE From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Mon, 15 May 2017 13:36:05 -0700 Message-Id: <1494880570-14209-13-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1494880570-14209-1-git-send-email-sstabellini@kernel.org> References: <1494880570-14209-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 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 removed the socket from its list. 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 | 94 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index d5b7412..22c6426 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -253,13 +253,105 @@ static int pvcalls_back_release_active(struct xenbus_device *dev, struct pvcalls_back_priv *priv, struct sock_mapping *map) { + struct pvcalls_ioworker *iow = + &pvcalls_back_global.ioworkers[map->data_worker]; + unsigned long flags; + bool in_loop = false; + + + disable_irq(map->irq); + if (map->sock->sk != NULL) { + lock_sock(map->sock->sk); + map->sock->sk->sk_user_data = NULL; + map->sock->sk->sk_data_ready = map->saved_data_ready; + release_sock(map->sock->sk); + } + + atomic_set(&map->release, 1); + + /* + * To avoid concurrency problems with ioworker, check if the socket + * has any outstanding io requests. If so, wait until the ioworker + * removes it from the list before proceeding. + */ + spin_lock_irqsave(&iow->lock, flags); + in_loop = !list_empty(&map->queue); + spin_unlock_irqrestore(&iow->lock, flags); + + if (in_loop) { + atomic_inc(&iow->io); + queue_work_on(map->data_worker, pvcalls_back_global.wq, + &iow->register_work); + while (atomic_read(&map->release) > 0) + cond_resched(); + } + + down_write(&priv->pvcallss_lock); + list_del(&map->list); + up_write(&priv->pvcallss_lock); + + xenbus_unmap_ring_vfree(dev, (void *)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_back_priv *priv, + struct sockpass_mapping *mappass) +{ + if (mappass->sock->sk != NULL) { + lock_sock(mappass->sock->sk); + mappass->sock->sk->sk_user_data = NULL; + mappass->sock->sk->sk_data_ready = mappass->saved_data_ready; + release_sock(mappass->sock->sk); + } + down_write(&priv->pvcallss_lock); + radix_tree_delete(&priv->socketpass_mappings, mappass->id); + sock_release(mappass->sock); + flush_workqueue(mappass->wq); + destroy_workqueue(mappass->wq); + kfree(mappass); + up_write(&priv->pvcallss_lock); + return 0; } static int pvcalls_back_release(struct xenbus_device *dev, struct xen_pvcalls_request *req) { - return 0; + struct pvcalls_back_priv *priv; + struct sock_mapping *map, *n; + struct sockpass_mapping *mappass; + int ret = 0; + struct xen_pvcalls_response *rsp; + + priv = dev_get_drvdata(&dev->dev); + + list_for_each_entry_safe(map, n, &priv->socket_mappings, list) { + if (map->id == req->u.release.id) { + ret = pvcalls_back_release_active(dev, priv, map); + goto out; + } + } + mappass = radix_tree_lookup(&priv->socketpass_mappings, + req->u.release.id); + if (mappass != NULL) { + ret = pvcalls_back_release_passive(dev, priv, mappass); + goto out; + } + +out: + rsp = RING_GET_RESPONSE(&priv->ring, priv->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 1; } static void __pvcalls_back_accept(struct work_struct *work)