All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Ostrovsky <boris.ostrovsky@oracle.com>
To: David Vrabel <david.vrabel@citrix.com>, xen-devel@lists.xenproject.org
Cc: Jenny Herbert <jennifer.herbert@citrix.com>
Subject: Re: [PATCH 09/14] xen/grant-table: add a mechanism to safely unmap pages that are in use
Date: Tue, 13 Jan 2015 18:31:44 -0500	[thread overview]
Message-ID: <54B5AAE0.1060503@oracle.com> (raw)
In-Reply-To: <1421077417-7162-10-git-send-email-david.vrabel@citrix.com>

On 01/12/2015 10:43 AM, David Vrabel wrote:
> From: Jenny Herbert <jennifer.herbert@citrix.com>
>
> Introduce gnttab_unmap_refs_async() that can be used to safely unmap
> pages that may be in use (ref count > 1).  If the pages are in use the
> unmap is deferred and retried later.  This polling is not very clever
> but it should be good enough if the cases where the delay is necessary
> are rare.
>
> The initial delay is 5 ms and is increased linearly on each subsequent
> retry (to reduce load if the page is in use for a long time).
>
> This is needed to allow block backends using grant mapping to safely
> use network storage (block or filesystem based such as iSCSI or NFS).
>
> The network storage driver may complete a block request whilst there
> is a queued network packet retry (because the ack from the remote end
> races with deciding to queue the retry).  The pages for the retried
> packet would be grant unmapped and the network driver (or hardware)
> would access the unmapped page.
>
> Signed-off-by: Jenny Herbert <jennifer.herbert@citrix.com>
> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
> ---
>   drivers/xen/grant-table.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
>   include/xen/grant_table.h |   18 ++++++++++++++++++
>   2 files changed, 62 insertions(+)
>
> diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
> index 9c7dc75..d9beffc 100644
> --- a/drivers/xen/grant-table.c
> +++ b/drivers/xen/grant-table.c
> @@ -42,6 +42,7 @@
>   #include <linux/io.h>
>   #include <linux/delay.h>
>   #include <linux/hardirq.h>
> +#include <linux/workqueue.h>
>   
>   #include <xen/xen.h>
>   #include <xen/interface/xen.h>
> @@ -817,6 +818,49 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
>   }
>   EXPORT_SYMBOL_GPL(gnttab_unmap_refs);
>   
> +#define GNTTAB_UNMAP_REFS_DELAY 5
> +
> +static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
> +
> +static void gnttab_unmap_work(struct work_struct *work)
> +{
> +	struct gntab_unmap_queue_data
> +		*unmap_data = container_of(work,
> +					   struct gntab_unmap_queue_data,
> +					   gnttab_work.work);
> +	if (unmap_data->age != UINT_MAX)
> +		unmap_data->age++;
> +	__gnttab_unmap_refs_async(unmap_data);

Should there be a termination condition if pages are never (for some 
definition of "never") released? Return -ETIMEDOUT in done()? Or at 
least print a warning once?

-boris

> +}
> +
> +static void __gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item)
> +{
> +	int ret;
> +	int pc;
> +
> +	for (pc = 0; pc < item->count; pc++) {
> +		if (page_count(item->pages[pc]) > 1) {
> +			unsigned long delay = GNTTAB_UNMAP_REFS_DELAY * (item->age + 1);
> +			schedule_delayed_work(&item->gnttab_work,
> +					      msecs_to_jiffies(delay));
> +			return;
> +		}
> +	}
> +
> +	ret = gnttab_unmap_refs(item->unmap_ops, item->kunmap_ops,
> +				item->pages, item->count);
> +	item->done(ret, item);
> +}
> +
> +void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item)
> +{
> +	INIT_DELAYED_WORK(&item->gnttab_work, gnttab_unmap_work);
> +	item->age = 0;
> +
> +	__gnttab_unmap_refs_async(item);
> +}
> +EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async);
> +
>   static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes)
>   {
>   	int rc;
> diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
> index d3bef56..143ca5f 100644
> --- a/include/xen/grant_table.h
> +++ b/include/xen/grant_table.h
> @@ -60,6 +60,22 @@ struct gnttab_free_callback {
>   	u16 count;
>   };
>   
> +struct gntab_unmap_queue_data;
> +
> +typedef void (*gnttab_unmap_refs_done)(int result, struct gntab_unmap_queue_data *data);
> +
> +struct gntab_unmap_queue_data
> +{
> +	struct delayed_work	gnttab_work;
> +	void *data;
> +	gnttab_unmap_refs_done	done;
> +	struct gnttab_unmap_grant_ref *unmap_ops;
> +	struct gnttab_unmap_grant_ref *kunmap_ops;
> +	struct page **pages;
> +	unsigned int count;
> +	unsigned int age;
> +};
> +
>   int gnttab_init(void);
>   int gnttab_suspend(void);
>   int gnttab_resume(void);
> @@ -174,6 +190,8 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
>   int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
>   		      struct gnttab_unmap_grant_ref *kunmap_ops,
>   		      struct page **pages, unsigned int count);
> +void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
> +
>   
>   /* Perform a batch of grant map/copy operations. Retry every batch slot
>    * for which the hypervisor returns GNTST_eagain. This is typically due

  reply	other threads:[~2015-01-13 23:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-12 15:43 [PATCHv2 00/14] xen: fix many long-standing grant mapping bugs David Vrabel
2015-01-12 15:43 ` [PATCH 01/14] mm: provide a find_page vma operation David Vrabel
2015-01-12 15:43 ` [PATCH 02/14] mm: add 'foreign' alias for the 'pinned' page flag David Vrabel
2015-01-12 15:43 ` [PATCH 03/14] xen/grant-table: pre-populate kernel unmap ops for xen_gnttab_unmap_refs() David Vrabel
2015-01-12 15:43 ` [PATCH 04/14] xen: remove scratch frames for ballooned pages and m2p override David Vrabel
2015-01-12 15:43 ` [PATCH 05/14] x86/xen: require ballooned pages for grant maps David Vrabel
2015-01-12 15:43 ` [PATCH 06/14] xen/grant-table: add helpers for allocating pages David Vrabel
2015-01-12 15:43 ` [PATCH 07/14] xen: mark grant mapped pages as foreign David Vrabel
2015-01-12 16:54   ` Ian Campbell
2015-01-12 16:56     ` David Vrabel
2015-01-13 22:46   ` Boris Ostrovsky
2015-01-12 15:43 ` [PATCH 08/14] xen-netback: use foreign page information from the pages themselves David Vrabel
2015-01-12 16:56   ` Ian Campbell
2015-01-12 17:16     ` David Vrabel
2015-01-12 17:20       ` Ian Campbell
2015-01-13 14:43   ` David Vrabel
2015-01-13 14:43   ` [Xen-devel] " David Vrabel
2015-01-13 21:57     ` David Miller
2015-01-13 21:57     ` [Xen-devel] " David Miller
2015-01-12 15:43 ` [PATCH 09/14] xen/grant-table: add a mechanism to safely unmap pages that are in use David Vrabel
2015-01-13 23:31   ` Boris Ostrovsky [this message]
2015-01-19 15:27     ` David Vrabel
2015-01-12 15:43 ` [PATCH 10/14] xen/gntdev: convert priv->lock to a mutex David Vrabel
2015-01-12 15:43 ` [PATCH 11/14] xen/gntdev: safely unmap grants in case they are still in use David Vrabel
2015-01-12 15:43 ` [PATCH 12/14] xen-blkback: " David Vrabel
2015-01-14 15:17   ` Boris Ostrovsky
2015-01-14 15:47   ` Boris Ostrovsky
2015-01-14 16:00     ` David Vrabel
2015-01-14 16:22       ` Boris Ostrovsky
2015-01-14 16:33         ` David Vrabel
2015-01-12 15:43 ` [PATCH 13/14] xen/gntdev: mark userspace PTEs as special on x86 PV guests David Vrabel
2015-01-12 15:43 ` [PATCH 14/14] xen/gntdev: provide find_page VMA operation David Vrabel
  -- strict thread matches above, loose matches on Subject: below --
2015-01-19 15:51 [PATCHv3 00/14] xen: fix many long-standing grant mapping bugs David Vrabel
2015-01-19 15:51 ` [PATCH 09/14] xen/grant-table: add a mechanism to safely unmap pages that are in use David Vrabel

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=54B5AAE0.1060503@oracle.com \
    --to=boris.ostrovsky@oracle.com \
    --cc=david.vrabel@citrix.com \
    --cc=jennifer.herbert@citrix.com \
    --cc=xen-devel@lists.xenproject.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.