xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: Stefano Stabellini <sstabellini@kernel.org>, xen-devel@lists.xen.org
Cc: jgross@suse.com, Stefano Stabellini <stefano@aporeto.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 02/13] xen/pvcalls: implement frontend disconnect
Date: Fri, 11 Aug 2017 18:43:43 -0400	[thread overview]
Message-ID: <c9c13ab7-456a-4f2a-b63b-c45550f52f01@oracle.com> (raw)
In-Reply-To: <1501541855-7354-2-git-send-email-sstabellini@kernel.org>

On 07/31/2017 06:57 PM, Stefano Stabellini wrote:
> 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.
>
> 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 | 51 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 51 insertions(+)
>
> diff --git a/drivers/xen/pvcalls-front.c b/drivers/xen/pvcalls-front.c
> index a8d38c2..a126195 100644
> --- a/drivers/xen/pvcalls-front.c
> +++ b/drivers/xen/pvcalls-front.c
> @@ -20,6 +20,29 @@
>  #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 pvcallss_lock;

In the backend this is called socket_lock and (subjectively) it would
sound as a better name here too.

> +
> +	wait_queue_head_t inflight_req;
> +	struct xen_pvcalls_response rsp[PVCALLS_NR_REQ_PER_RING];
> +};
> +static struct xenbus_device *pvcalls_front_dev;
> +
> +static irqreturn_t pvcalls_front_event_handler(int irq, void *dev_id)
> +{
> +	return IRQ_HANDLED;
> +}
> +
>  static const struct xenbus_device_id pvcalls_front_ids[] = {
>  	{ "pvcalls" },
>  	{ "" }
> @@ -27,6 +50,34 @@
>  
>  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);
> +
> +	list_for_each_entry_safe(map, n, &bedata->socket_mappings, list) {
> +		mutex_lock(&map->active.in_mutex);
> +		mutex_lock(&map->active.out_mutex);
> +		pvcalls_front_free_map(bedata, map);
> +		mutex_unlock(&map->active.out_mutex);
> +		mutex_unlock(&map->active.in_mutex);
> +		kfree(map);

I think this is the same issue as the one discussed for some other patch
--- unlocking and then immediately freeing a lock.

> +	}
> +	list_for_each_entry_safe(map, n, &bedata->socketpass_mappings, list) {
> +		spin_lock(&bedata->pvcallss_lock);
> +		list_del_init(&map->list);
> +		spin_unlock(&bedata->pvcallss_lock);
> +		kfree(map);
> +	}
> +	if (bedata->irq > 0)
> +		unbind_from_irqhandler(bedata->irq, dev);
> +	if (bedata->ref >= 0)
> +		gnttab_end_foreign_access(bedata->ref, 0, 0);
> +	kfree(bedata->ring.sring);
> +	kfree(bedata);
> +	dev_set_drvdata(&dev->dev, NULL);
> +	xenbus_switch_state(dev, XenbusStateClosed);

Should we first move the state to Closed and then free things up? Or it
doesn't matter?

-boris

> +	pvcalls_front_dev = NULL;
>  	return 0;
>  }
>  


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  parent reply	other threads:[~2017-08-11 22:43 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <alpine.DEB.2.10.1707311536460.22381@sstabellini-ThinkPad-X260>
2017-07-31 22:57 ` [PATCH v3 01/13] xen/pvcalls: introduce the pvcalls xenbus frontend Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 02/13] xen/pvcalls: implement frontend disconnect Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 03/13] xen/pvcalls: connect to the backend Stefano Stabellini
2017-08-11 22:55     ` Boris Ostrovsky
     [not found]     ` <4fbe7300-8934-ed6b-3868-443ae96c2ecb@oracle.com>
2017-09-09  0:14       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 04/13] xen/pvcalls: implement socket command and handle events Stefano Stabellini
2017-08-13  0:42     ` Boris Ostrovsky
     [not found]     ` <bac44a61-e6d2-72fe-a8b4-5dec0e23186f@oracle.com>
2017-09-08 23:20       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 05/13] xen/pvcalls: implement connect command Stefano Stabellini
2017-08-13  1:12     ` Boris Ostrovsky
     [not found]     ` <98a37ce0-468c-0938-a56d-31bbde177c91@oracle.com>
2017-09-08 21:23       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 06/13] xen/pvcalls: implement bind command Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 07/13] xen/pvcalls: implement listen command Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 08/13] xen/pvcalls: implement accept command Stefano Stabellini
2017-08-15  2:00     ` Boris Ostrovsky
     [not found]     ` <1a368546-fec3-7f10-cc1b-296e095c9ba1@oracle.com>
2017-08-15  2:04       ` Boris Ostrovsky
     [not found]       ` <37d72529-c8d4-96e1-422c-342a19af9055@oracle.com>
2017-09-08 21:58         ` Stefano Stabellini
2017-09-08 22:16       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 09/13] xen/pvcalls: implement sendmsg Stefano Stabellini
2017-08-15  2:31     ` Boris Ostrovsky
2017-09-08 23:48       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 10/13] xen/pvcalls: implement recvmsg Stefano Stabellini
2017-08-15  2:39     ` Boris Ostrovsky
2017-09-08 23:11       ` Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 11/13] xen/pvcalls: implement poll command Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 12/13] xen/pvcalls: implement release command Stefano Stabellini
2017-07-31 22:57   ` [PATCH v3 13/13] xen: introduce a Kconfig option to enable the pvcalls frontend Stefano Stabellini
2017-08-11 22:36   ` [PATCH v3 01/13] xen/pvcalls: introduce the pvcalls xenbus frontend Boris Ostrovsky
     [not found]   ` <1501541855-7354-2-git-send-email-sstabellini@kernel.org>
2017-08-11 22:43     ` Boris Ostrovsky [this message]
2017-09-09  0:07       ` [PATCH v3 02/13] xen/pvcalls: implement frontend disconnect Stefano Stabellini
     [not found]   ` <1501541855-7354-6-git-send-email-sstabellini@kernel.org>
2017-08-13  1:22     ` [PATCH v3 06/13] xen/pvcalls: implement bind command Boris Ostrovsky
     [not found]     ` <3591ec0c-1556-dd20-1cc9-092eb1792c42@oracle.com>
2017-09-08 21:46       ` Stefano Stabellini
     [not found]   ` <1501541855-7354-7-git-send-email-sstabellini@kernel.org>
2017-08-13  1:28     ` [PATCH v3 07/13] xen/pvcalls: implement listen command Boris Ostrovsky
     [not found]   ` <1501541855-7354-11-git-send-email-sstabellini@kernel.org>
2017-08-15 20:30     ` [PATCH v3 11/13] xen/pvcalls: implement poll command Boris Ostrovsky
     [not found]     ` <702cfa9c-5f14-07a3-63ba-93648ff66d9b@oracle.com>
2017-09-08 23:03       ` Stefano Stabellini
     [not found]       ` <alpine.DEB.2.10.1709081540330.19719@sstabellini-ThinkPad-X260>
2017-09-12 14:14         ` Boris Ostrovsky
     [not found]         ` <6c9613d8-8219-d06f-9095-fa57474ed518@oracle.com>
2017-09-12 22:17           ` Stefano Stabellini
     [not found]           ` <alpine.DEB.2.10.1709121502210.9439@sstabellini-ThinkPad-X260>
2017-09-12 23:04             ` Boris Ostrovsky
     [not found]             ` <73a6ae0f-077c-9d42-fd56-0738ccb30cec@oracle.com>
2017-09-12 23:13               ` Stefano Stabellini
     [not found]               ` <alpine.DEB.2.10.1709121610250.9439@sstabellini-ThinkPad-X260>
2017-09-12 23:18                 ` Stefano Stabellini
     [not found]   ` <1501541855-7354-12-git-send-email-sstabellini@kernel.org>
2017-08-15 20:44     ` [PATCH v3 12/13] xen/pvcalls: implement release command Boris Ostrovsky
     [not found]     ` <2fd1b3f3-28aa-1958-7522-766c7d92e8d3@oracle.com>
2017-09-08 23:09       ` Stefano Stabellini
2017-08-10 15:07 ` [PATCH v3 00/13] introduce the Xen PV Calls frontend Boris Ostrovsky
     [not found] ` <bbff3e92-e71a-f685-bae1-59521e6f2f99@oracle.com>
2017-08-10 18:15   ` 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=c9c13ab7-456a-4f2a-b63b-c45550f52f01@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sstabellini@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).