[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] Xen backend support for paged out grant targets.


  • To: xen-devel@xxxxxxxxxxxxx, xen-devel@xxxxxxx
  • From: andres@xxxxxxxxxxxxxxxx
  • Date: Mon, 27 Aug 2012 12:51:27 -0400
  • Cc: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxx>, Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
  • Delivery-date: Mon, 27 Aug 2012 16:47:17 +0000
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=lagarcavilla.org; h=from:to:cc :subject:date:message-id; q=dns; s=lagarcavilla.org; b=udRV4dH+E rjyGjmOQgzagOO1VGUyXcICCC987numnBmSHNWmYfPvK94HZt2bBIltTl8EAz7Id Y3vREQMRnBmEArmT+5KpO006T3yDmBS9/XO3pUknV+Fxn0L9GWYrsJECjzFe4w69 LkyG32jetj6JBM136Q8kT5KoeDzsJy1wVs=
  • List-id: Xen developer discussion <xen-devel.lists.xen.org>

From: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>

Since Xen-4.2, hvm domains may have portions of their memory paged out. When a
foreign domain (such as dom0) attempts to map these frames, the map will
initially fail. The hypervisor returns a suitable errno, and kicks an
asynchronous page-in operation carried out by a helper. The foreign domain is
expected to retry the mapping operation until it eventually succeeds. The
foreign domain is not put to sleep because itself could be the one running the
pager assist (typical scenario for dom0).

This patch adds support for this mechanism for backend drivers using grant
mapping and copying operations. Specifically, this covers the blkback and
gntdev drivers (which map foregin grants), and the netback driver (which copies
foreign grants).

* Add GNTST_eagain, already exposed by Xen, to the grant interface.
* Add a retry method for grants that fail with GNTST_eagain (i.e. because the
  target foregin frame is paged out).
* Insert hooks with appropriate macro decorators in the aforementioned drivers.

The retry loop is only invoked if the grant operation status is GNTST_eagain.
It guarantees to leave a new status code different from GNTST_eagain. Any other
status code results in identical code execution as before.

The retry loop performs 256 attempts with increasing time intervals through a
32 second period. It uses msleep to yield while waiting for the next retry.

Signed-off-by: Andres Lagar-Cavilla <andres@xxxxxxxxxxxxxxxx>
---
 drivers/net/xen-netback/netback.c   |   13 +++++++++++++
 drivers/xen/grant-table.c           |   25 +++++++++++++++++++++++++
 drivers/xen/xenbus/xenbus_client.c  |    6 ++----
 include/xen/grant_table.h           |   25 +++++++++++++++++++++++++
 include/xen/interface/grant_table.h |    2 ++
 5 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/drivers/net/xen-netback/netback.c 
b/drivers/net/xen-netback/netback.c
index 682633b..063adf5 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -548,6 +548,8 @@ static int netbk_check_gop(struct xenvif *vif, int 
nr_meta_slots,
 
        for (i = 0; i < nr_meta_slots; i++) {
                copy_op = npo->copy + npo->copy_cons++;
+               if (copy_op->status == GNTST_eagain)
+                       gnttab_retry_eagain_copy(copy_op);
                if (copy_op->status != GNTST_okay) {
                        netdev_dbg(vif->dev,
                                   "Bad status %d from copy to DOM%d.\n",
@@ -976,6 +978,11 @@ static int xen_netbk_tx_check_gop(struct xen_netbk *netbk,
 
        /* Check status of header. */
        err = gop->status;
+       if (unlikely(err == GNTST_eagain))
+       {
+               gnttab_retry_eagain_copy(gop);
+               err = gop->status;
+       }
        if (unlikely(err)) {
                pending_ring_idx_t index;
                index = pending_index(netbk->pending_prod++);
@@ -1001,6 +1008,12 @@ static int xen_netbk_tx_check_gop(struct xen_netbk 
*netbk,
                        if (unlikely(err))
                                xen_netbk_idx_release(netbk, pending_idx);
                        continue;
+               } else {
+                       if (newerr == GNTST_eagain)
+                       {
+                               gnttab_retry_eagain_copy(gop);
+                               newerr = gop->status;
+                       }
                }
 
                /* Error on this fragment: respond to client with an error. */
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c
index eea81cf..2b62a63 100644
--- a/drivers/xen/grant-table.c
+++ b/drivers/xen/grant-table.c
@@ -38,6 +38,7 @@
 #include <linux/vmalloc.h>
 #include <linux/uaccess.h>
 #include <linux/io.h>
+#include <linux/delay.h>
 #include <linux/hardirq.h>
 
 #include <xen/xen.h>
@@ -823,6 +824,25 @@ unsigned int gnttab_max_grant_frames(void)
 }
 EXPORT_SYMBOL_GPL(gnttab_max_grant_frames);
 
+void
+gnttab_retry_eagain_gop(unsigned int cmd, void *gop, int16_t *status,
+                                               const char *func)
+{
+       u8 delay = 1;
+
+       do {
+               BUG_ON(HYPERVISOR_grant_table_op(cmd, gop, 1));
+               if (*status == GNTST_eagain)
+                       msleep(delay++);
+       } while ((*status == GNTST_eagain) && delay);
+
+       if (delay == 0) {
+               printk(KERN_ERR "%s: %s eagain grant\n", func, current->comm);
+               *status = GNTST_bad_page;
+       }
+}
+EXPORT_SYMBOL_GPL(gnttab_retry_eagain_gop);
+
 int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
                    struct gnttab_map_grant_ref *kmap_ops,
                    struct page **pages, unsigned int count)
@@ -836,6 +856,11 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
        if (ret)
                return ret;
 
+       /* Retry eagain maps */
+       for (i = 0; i < count; i++)
+               if (map_ops[i].status == GNTST_eagain)
+                       gnttab_retry_eagain_map(map_ops + i);
+
        if (xen_feature(XENFEAT_auto_translated_physmap))
                return ret;
 
diff --git a/drivers/xen/xenbus/xenbus_client.c 
b/drivers/xen/xenbus/xenbus_client.c
index b3e146e..749f6a3 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -490,8 +490,7 @@ static int xenbus_map_ring_valloc_pv(struct xenbus_device 
*dev,
 
        op.host_addr = arbitrary_virt_to_machine(pte).maddr;
 
-       if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
-               BUG();
+       gnttab_map_grant_no_eagain(&op);
 
        if (op.status != GNTST_okay) {
                free_vm_area(area);
@@ -572,8 +571,7 @@ int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
        gnttab_set_map_op(&op, (unsigned long)vaddr, GNTMAP_host_map, gnt_ref,
                          dev->otherend_id);
 
-       if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
-               BUG();
+       gnttab_map_grant_no_eagain(&op);
 
        if (op.status != GNTST_okay) {
                xenbus_dev_fatal(dev, op.status,
diff --git a/include/xen/grant_table.h b/include/xen/grant_table.h
index 11e27c3..0f75184 100644
--- a/include/xen/grant_table.h
+++ b/include/xen/grant_table.h
@@ -183,6 +183,31 @@ unsigned int gnttab_max_grant_frames(void);
 
 #define gnttab_map_vaddr(map) ((void *)(map.host_virt_addr))
 
+/* Retry a grant map/copy operation when the hypervisor returns GNTST_eagain.
+ * This is typically due to paged out target frames.
+ * Generic entry-point, use macro decorators below for specific grant
+ * operations.
+ * Will retry for 1, 2, ... 255 ms, i.e. 256 times during 32 seconds.
+ * Return value in *status guaranteed to no longer be GNTST_eagain. */
+void gnttab_retry_eagain_gop(unsigned int cmd, void *gop, int16_t *status,
+                             const char *func);
+
+#define gnttab_retry_eagain_map(_gop)                       \
+    gnttab_retry_eagain_gop(GNTTABOP_map_grant_ref, (_gop), \
+                            &(_gop)->status, __func__)
+
+#define gnttab_retry_eagain_copy(_gop)                  \
+    gnttab_retry_eagain_gop(GNTTABOP_copy, (_gop),      \
+                            &(_gop)->status, __func__)
+
+#define gnttab_map_grant_no_eagain(_gop)                                    \
+do {                                                                        \
+    if ( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, (_gop), 1))      \
+        BUG();                                                              \
+    if ((_gop)->status == GNTST_eagain)                                     \
+        gnttab_retry_eagain_map((_gop));                                    \
+} while(0)
+
 int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops,
                    struct gnttab_map_grant_ref *kmap_ops,
                    struct page **pages, unsigned int count);
diff --git a/include/xen/interface/grant_table.h 
b/include/xen/interface/grant_table.h
index 7da811b..66cb734 100644
--- a/include/xen/interface/grant_table.h
+++ b/include/xen/interface/grant_table.h
@@ -520,6 +520,7 @@ DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_version);
 #define GNTST_permission_denied (-8) /* Not enough privilege for operation.  */
 #define GNTST_bad_page         (-9) /* Specified page was invalid for op.    */
 #define GNTST_bad_copy_arg    (-10) /* copy arguments cross page boundary */
+#define GNTST_eagain          (-12) /* Retry.                                */
 
 #define GNTTABOP_error_msgs {                   \
     "okay",                                     \
@@ -533,6 +534,7 @@ DEFINE_GUEST_HANDLE_STRUCT(gnttab_get_version);
     "permission denied",                        \
     "bad page",                                 \
     "copy arguments cross page boundary"        \
+    "retry"                                     \
 }
 
 #endif /* __XEN_PUBLIC_GRANT_TABLE_H__ */
-- 
1.7.5.4


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


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.