From patchwork Thu Jun 22 19:14:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9805181 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 30BAF600C5 for ; Thu, 22 Jun 2017 19:16:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FA59285E1 for ; Thu, 22 Jun 2017 19:16:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 148402864C; Thu, 22 Jun 2017 19:16:48 +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 A68B726222 for ; Thu, 22 Jun 2017 19:16:47 +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 1dO7Yq-0007yP-6V; Thu, 22 Jun 2017 19:14:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dO7Yo-0007v8-BQ for xen-devel@lists.xen.org; Thu, 22 Jun 2017 19:14:34 +0000 Received: from [85.158.137.68] by server-14.bemta-3.messagelabs.com id CC/17-10689-9171C495; Thu, 22 Jun 2017 19:14:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRWlGSWpSXmKPExsVybKJssq6kuE+ kweYuFoslHxezODB6HN39mymAMYo1My8pvyKBNWPljpPsBZdlKprecDcwXpDoYuTiEBJoY5JY M3UeYxcjJweLgIPEtkO/mLoYOTgYBWIkHvywBgkzCoRJTL68hBXEZhMwlPj7ZBMbiC0iIC1x7 fNlRpA5zAKTGSVev/vFDJIQFrCR2DzhLRvETFWJrTPmsYHM5BVwk5j+Ug0kLCEgJ3Hy2GSwmZ wC7hJNzefYIO5pZ5To/fySfQIj7wJGhlWMGsWpRWWpRbpGFnpJRZnpGSW5iZk5uoYGxnq5qcX FiempOYlJxXrJ+bmbGIHBUM/AwLiDsf2E3yFGSQ4mJVHezcXekUJ8SfkplRmJxRnxRaU5qcWH GGU4OJQkeD+K+kQKCRalpqdWpGXmAMMSJi3BwaMkwvuFDyjNW1yQmFucmQ6ROsWoy7Fh9fovT EIsefl5qVLivLdBZgiAFGWU5sGNgMXIJUZZKWFeRgYGBiGegtSi3MwSVPlXjOIcjErCvCkiQF N4MvNK4Da9AjqCCeiIF0c8QI4oSURISTUwzmGe8v6ywK1ZzHEGT7/rTYo+sIcjWrPMy/CLWvO Ru/XNjfftjX7fq/W88OLC21lNd19t3HPq6oWp36dkpzyrEda6H8eVOO2Q3oy+tx3/LzKZSp2r OZHrb7N8DefuUAHnVbHBobu3TVoXntd0wUpSTm6Bp8OZLk6n4g875TtXfL//g4XdfHJznRJLc UaioRZzUXEiAJeATxWMAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-12.tower-31.messagelabs.com!1498158871!90177053!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 35606 invoked from network); 22 Jun 2017 19:14:32 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.99) by server-12.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Jun 2017 19:14:32 -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 0CBBA22B69; Thu, 22 Jun 2017 19:14:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CBBA22B69 From: Stefano Stabellini To: xen-devel@lists.xen.org Date: Thu, 22 Jun 2017 12:14:14 -0700 Message-Id: <1498158867-25426-5-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498158867-25426-1-git-send-email-sstabellini@kernel.org> References: <1498158867-25426-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 v5 05/18] xen/pvcalls: connect to a frontend 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 per-frontend data structure named pvcalls_fedata. It contains pointers to the command ring, its event channel, a list of active sockets and a tree of passive sockets (passing sockets need to be looked up from the id on listen, accept and poll commands, while active sockets only on release). It also has an unbound workqueue to schedule the work of parsing and executing commands on the command ring. socket_lock protects the two lists. In pvcalls_back_global, keep a list of connected frontends. Signed-off-by: Stefano Stabellini Reviewed-by: Boris Ostrovsky CC: boris.ostrovsky@oracle.com CC: jgross@suse.com --- drivers/xen/pvcalls-back.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/drivers/xen/pvcalls-back.c b/drivers/xen/pvcalls-back.c index 7bce750..e4c2e46 100644 --- a/drivers/xen/pvcalls-back.c +++ b/drivers/xen/pvcalls-back.c @@ -33,9 +33,101 @@ struct pvcalls_back_global { struct semaphore frontends_lock; } pvcalls_back_global; +/* + * Per-frontend data structure. It contains pointers to the command + * ring, its event channel, a list of active sockets and a tree of + * passive sockets. + */ +struct pvcalls_fedata { + struct list_head list; + struct xenbus_device *dev; + struct xen_pvcalls_sring *sring; + struct xen_pvcalls_back_ring ring; + int irq; + struct list_head socket_mappings; + struct radix_tree_root socketpass_mappings; + struct semaphore socket_lock; + struct workqueue_struct *wq; + struct work_struct register_work; +}; + +static void pvcalls_back_work(struct work_struct *work) +{ +} + +static irqreturn_t pvcalls_back_event(int irq, void *dev_id) +{ + return IRQ_HANDLED; +} + static int backend_connect(struct xenbus_device *dev) { + int err, evtchn; + grant_ref_t ring_ref; + struct pvcalls_fedata *fedata = NULL; + + fedata = kzalloc(sizeof(struct pvcalls_fedata), GFP_KERNEL); + if (!fedata) + return -ENOMEM; + + err = xenbus_scanf(XBT_NIL, dev->otherend, "port", "%u", + &evtchn); + if (err != 1) { + err = -EINVAL; + xenbus_dev_fatal(dev, err, "reading %s/event-channel", + dev->otherend); + goto error; + } + + err = xenbus_scanf(XBT_NIL, dev->otherend, "ring-ref", "%u", &ring_ref); + if (err != 1) { + err = -EINVAL; + xenbus_dev_fatal(dev, err, "reading %s/ring-ref", + dev->otherend); + goto error; + } + + err = bind_interdomain_evtchn_to_irqhandler(dev->otherend_id, evtchn, + pvcalls_back_event, 0, + "pvcalls-backend", dev); + if (err < 0) + goto error; + fedata->irq = err; + + fedata->wq = alloc_workqueue("pvcalls_back_wq", WQ_UNBOUND, 1); + if (!fedata->wq) { + err = -ENOMEM; + goto error; + } + + err = xenbus_map_ring_valloc(dev, &ring_ref, 1, (void**)&fedata->sring); + if (err < 0) + goto error; + + BACK_RING_INIT(&fedata->ring, fedata->sring, XEN_PAGE_SIZE * 1); + fedata->dev = dev; + + INIT_WORK(&fedata->register_work, pvcalls_back_work); + INIT_LIST_HEAD(&fedata->socket_mappings); + INIT_RADIX_TREE(&fedata->socketpass_mappings, GFP_KERNEL); + sema_init(&fedata->socket_lock, 1); + dev_set_drvdata(&dev->dev, fedata); + + down(&pvcalls_back_global.frontends_lock); + list_add_tail(&fedata->list, &pvcalls_back_global.frontends); + up(&pvcalls_back_global.frontends_lock); + queue_work(fedata->wq, &fedata->register_work); + return 0; + + error: + if (fedata->sring != NULL) + xenbus_unmap_ring_vfree(dev, fedata->sring); + if (fedata->wq) + destroy_workqueue(fedata->wq); + unbind_from_irqhandler(fedata->irq, dev); + kfree(fedata); + return err; } static int backend_disconnect(struct xenbus_device *dev)