All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: xen-devel@lists.xen.org
Cc: linux-kernel@vger.kernel.org, sstabellini@kernel.org,
	jgross@suse.com, boris.ostrovsky@oracle.com,
	Stefano Stabellini <stefano@aporeto.com>
Subject: [PATCH v5 02/13] xen/pvcalls: implement frontend disconnect
Date: Fri,  6 Oct 2017 17:30:16 -0700	[thread overview]
Message-ID: <1507336227-20477-2-git-send-email-sstabellini@kernel.org> (raw)
In-Reply-To: <1507336227-20477-1-git-send-email-sstabellini@kernel.org>

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.

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 <stefano@aporeto.com>
CC: boris.ostrovsky@oracle.com
CC: jgross@suse.com
---
 drivers/xen/pvcalls-front.c | 67 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
index a8d38c2..d8b7a04 100644
--- a/drivers/xen/pvcalls-front.c
+++ b/drivers/xen/pvcalls-front.c
@@ -20,6 +20,46 @@
 #include <xen/xenbus.h>
 #include <xen/interface/io/pvcalls.h>
 
+#define PVCALLS_INVALID_ID UINT_MAX
+#define PVCALLS_RING_ORDER XENBUS_MAX_RING_GRANT_ORDER
+#define PVCALLS_NR_REQ_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;
+	struct list_head socketpass_mappings;
+	spinlock_t socket_lock;
+
+	wait_queue_head_t inflight_req;
+	struct xen_pvcalls_response rsp[PVCALLS_NR_REQ_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);      \
+}
+
+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 +67,33 @@
 
 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) {
+		pvcalls_front_free_map(bedata, map);
+		kfree(map);
+	}
+	list_for_each_entry_safe(map, n, &bedata->socketpass_mappings, list) {
+		spin_lock(&bedata->socket_lock);
+		list_del_init(&map->list);
+		spin_unlock(&bedata->socket_lock);
+		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;
 }
 
-- 
1.9.1

  parent reply	other threads:[~2017-10-07  0:30 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-07  0:30 [PATCH v5 00/13] introduce the Xen PV Calls frontend:wq Stefano Stabellini
2017-10-07  0:30 ` [PATCH v5 01/13] xen/pvcalls: introduce the pvcalls xenbus frontend Stefano Stabellini
2017-10-07  0:30   ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 02/13] xen/pvcalls: implement frontend disconnect Stefano Stabellini
2017-10-07  0:30   ` Stefano Stabellini [this message]
2017-10-17 16:01     ` Boris Ostrovsky
2017-10-17 16:01     ` Boris Ostrovsky
2017-10-23 22:44       ` Stefano Stabellini
2017-10-23 22:44       ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 03/13] xen/pvcalls: connect to the backend Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 04/13] xen/pvcalls: implement socket command and handle events Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-17 16:59     ` Boris Ostrovsky
2017-10-17 16:59     ` Boris Ostrovsky
2017-10-20  1:26       ` Stefano Stabellini
2017-10-20  1:26       ` Stefano Stabellini
2017-10-20 14:24         ` Boris Ostrovsky
2017-10-20 14:24         ` Boris Ostrovsky
2017-10-07  0:30   ` [PATCH v5 05/13] xen/pvcalls: implement connect command Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 06/13] xen/pvcalls: implement bind command Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-17 17:39     ` Boris Ostrovsky
2017-10-20  1:31       ` Stefano Stabellini
2017-10-20  1:31       ` Stefano Stabellini
2017-10-20 14:40         ` Boris Ostrovsky
2017-10-20 14:40         ` Boris Ostrovsky
2017-10-17 17:39     ` Boris Ostrovsky
2017-10-07  0:30   ` [PATCH v5 07/13] xen/pvcalls: implement listen command Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 08/13] xen/pvcalls: implement accept command Stefano Stabellini
2017-10-17 18:34     ` Boris Ostrovsky
2017-10-17 18:34     ` Boris Ostrovsky
2017-10-23 23:03       ` Stefano Stabellini
2017-10-24 13:52         ` Boris Ostrovsky
2017-10-24 16:42           ` Stefano Stabellini
2017-10-24 16:42           ` Stefano Stabellini
2017-10-24 13:52         ` Boris Ostrovsky
2017-10-23 23:03       ` Stefano Stabellini
2017-10-07  0:30   ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 09/13] xen/pvcalls: implement sendmsg Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-17 21:06     ` Boris Ostrovsky
2017-10-17 21:06     ` Boris Ostrovsky
2017-10-20  1:41       ` Stefano Stabellini
2017-10-20  1:41       ` Stefano Stabellini
2017-10-20 14:44         ` Boris Ostrovsky
2017-10-20 14:44         ` Boris Ostrovsky
2017-10-07  0:30   ` [PATCH v5 10/13] xen/pvcalls: implement recvmsg Stefano Stabellini
2017-10-07  0:30   ` Stefano Stabellini
2017-10-17 21:35     ` Boris Ostrovsky
2017-10-17 21:35     ` Boris Ostrovsky
2017-10-20  1:38       ` Stefano Stabellini
2017-10-20  1:38       ` Stefano Stabellini
2017-10-20 14:43         ` Boris Ostrovsky
2017-10-20 14:43         ` Boris Ostrovsky
2017-10-07  0:30   ` [PATCH v5 11/13] xen/pvcalls: implement poll command Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-17 22:15     ` Boris Ostrovsky
2017-10-17 22:15       ` Boris Ostrovsky
2017-10-23 23:06       ` Stefano Stabellini
2017-10-23 23:06       ` Stefano Stabellini
2017-10-24 14:02         ` Boris Ostrovsky
2017-10-24 14:02         ` Boris Ostrovsky
2017-10-07  0:30   ` [PATCH v5 12/13] xen/pvcalls: implement release command Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini
2017-10-24 14:17     ` Boris Ostrovsky
2017-10-24 14:17     ` Boris Ostrovsky
2017-10-24 17:17       ` Stefano Stabellini
2017-10-24 17:17       ` Stefano Stabellini
2017-10-07  0:30   ` [PATCH v5 13/13] xen: introduce a Kconfig option to enable the pvcalls frontend Stefano Stabellini
2017-10-07  0:30     ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1507336227-20477-2-git-send-email-sstabellini@kernel.org \
    --to=sstabellini@kernel.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stefano@aporeto.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.