Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754114AbdFNAqw (ORCPT ); Tue, 13 Jun 2017 20:46:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:32810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753947AbdFNAqu (ORCPT ); Tue, 13 Jun 2017 20:46:50 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 52253239A8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=sstabellini@kernel.org Date: Tue, 13 Jun 2017 17:46:48 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@sstabellini-ThinkPad-X260 To: Juergen Gross cc: Stefano Stabellini , xen-devel@lists.xen.org, linux-kernel@vger.kernel.org, boris.ostrovsky@oracle.com, Stefano Stabellini Subject: Re: [PATCH v3 09/18] xen/pvcalls: implement bind command In-Reply-To: Message-ID: References: <1496431915-20774-1-git-send-email-sstabellini@kernel.org> <1496431915-20774-9-git-send-email-sstabellini@kernel.org> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4042 Lines: 147 On Tue, 13 Jun 2017, Juergen Gross wrote: > On 02/06/17 21:31, Stefano Stabellini wrote: > > Allocate a socket. Track the allocated passive sockets with a new data > > structure named sockpass_mapping. It contains an unbound workqueue to > > schedule delayed work for the accept and poll commands. It also has a > > reqcopy field to be used to store a copy of a request for delayed work. > > Reads/writes to it are protected by a lock (the "copy_lock" spinlock). > > Initialize the workqueue in pvcalls_back_bind. > > > > Implement the bind command with inet_bind. > > > > The pass_sk_data_ready event handler will be added later. > > > > Signed-off-by: Stefano Stabellini > > CC: boris.ostrovsky@oracle.com > > CC: jgross@suse.com > > --- > > drivers/xen/pvcalls-back.c | 87 +++++++++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 86 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c > > index 3eb84ef..4a0cfa3 100644 > > --- a/drivers/xen/pvcalls-back.c > > +++ b/drivers/xen/pvcalls-back.c > > @@ -81,6 +81,18 @@ struct sock_mapping { > > struct pvcalls_ioworker ioworker; > > }; > > > > +struct sockpass_mapping { > > + struct list_head list; > > + struct pvcalls_fedata *priv; > > + struct socket *sock; > > + uint64_t id; > > + struct xen_pvcalls_request reqcopy; > > + spinlock_t copy_lock; > > + struct workqueue_struct *wq; > > + struct work_struct register_work; > > + void (*saved_data_ready)(struct sock *sk); > > +}; > > + > > static irqreturn_t pvcalls_back_conn_event(int irq, void *sock_map); > > static int pvcalls_back_release_active(struct xenbus_device *dev, > > struct pvcalls_fedata *priv, > > @@ -261,10 +273,83 @@ static int pvcalls_back_release(struct xenbus_device *dev, > > return 0; > > } > > > > +static void __pvcalls_back_accept(struct work_struct *work) > > +{ > > +} > > + > > +static void pvcalls_pass_sk_data_ready(struct sock *sock) > > +{ > > +} > > + > > static int pvcalls_back_bind(struct xenbus_device *dev, > > struct xen_pvcalls_request *req) > > { > > - return 0; > > + struct pvcalls_fedata *priv; > > + int ret, err; > > + struct socket *sock; > > + struct sockpass_mapping *map = NULL; > > Pointless initializer. I'll fix > > + struct xen_pvcalls_response *rsp; > > + > > + priv = dev_get_drvdata(&dev->dev); > > + > > + map = kzalloc(sizeof(*map), GFP_KERNEL); > > + if (map == NULL) { > > + ret = -ENOMEM; > > + goto out; > > + } > > + > > + INIT_WORK(&map->register_work, __pvcalls_back_accept); > > + spin_lock_init(&map->copy_lock); > > + map->wq = alloc_workqueue("pvcalls_wq", WQ_UNBOUND, 1); > > + if (!map->wq) { > > + ret = -ENOMEM; > > + kfree(map); > > + goto out; > > + } > > + > > + ret = sock_create(AF_INET, SOCK_STREAM, 0, &sock); > > + if (ret < 0) { > > + destroy_workqueue(map->wq); > > + kfree(map); > > + goto out; > > + } > > + > > + ret = inet_bind(sock, (struct sockaddr *)&req->u.bind.addr, > > + req->u.bind.len); > > + if (ret < 0) { > > + destroy_workqueue(map->wq); > > + kfree(map); > > sock_release()? OK > > + goto out; > > + } > > + > > + map->priv = priv; > > + map->sock = sock; > > + map->id = req->u.bind.id; > > + > > + down(&priv->socket_lock); > > + err = radix_tree_insert(&priv->socketpass_mappings, map->id, > > + map); > > + up(&priv->socket_lock); > > + if (err) { > > + ret = err; > > + destroy_workqueue(map->wq); > > + kfree(map); > > sock_release()? OK > > + goto out; > > + } > > + > > + write_lock_bh(&sock->sk->sk_callback_lock); > > + map->saved_data_ready = sock->sk->sk_data_ready; > > + sock->sk->sk_user_data = map; > > + sock->sk->sk_data_ready = pvcalls_pass_sk_data_ready; > > + write_unlock_bh(&sock->sk->sk_callback_lock); > > + > > +out: > > + rsp = RING_GET_RESPONSE(&priv->ring, priv->ring.rsp_prod_pvt++); > > + rsp->req_id = req->req_id; > > + rsp->cmd = req->cmd; > > + rsp->u.bind.id = req->u.bind.id; > > + rsp->ret = ret; > > + return ret; > > return 0? Yes