]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
libxendevicemodel: add ability to populate guest RAM regions
authorIan Campbell <ian.campbell@citrix.com>
Tue, 2 Feb 2016 16:50:47 +0000 (16:50 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 10 Feb 2016 17:09:53 +0000 (17:09 +0000)
XXX behaviour on partial success needs to be better defined (and/or
sane)

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
tools/libs/devicemodel/core.c
tools/libs/devicemodel/include/xendevicemodel.h
tools/libs/devicemodel/libxendevicemodel.map
tools/libs/devicemodel/private.h

index 361ea96604cb5e42cac403fcbaf1cb2b805bb0d1..5ac15d709473dc78a8bc01c84c4bbf90c6316c73 100644 (file)
@@ -162,6 +162,60 @@ int xendevicemodel_s3_awaken(xendevicemodel_handle *dm)
     return set_s3_state(dm, 0, "s3 awaken");
 }
 
+int xendevicemodel_populate_ram(xendevicemodel_handle *dm,
+                                xen_pfn_t start_gpfn, size_t nr_pages)
+{
+    xen_memory_reservation_t *arg = NULL;
+    xen_pfn_t *pfns = NULL;
+    size_t i, ret = -1;
+
+    arg = xencall_alloc_buffer(dm->call, sizeof(*arg));
+    if ( arg == NULL )
+    {
+        LOGE(ERROR, "unable to allocate memory for populate ram hypercall");
+        goto err;
+    }
+
+    pfns = xencall_alloc_buffer(dm->call, sizeof(*pfns) * nr_pages);
+    if ( pfns == NULL )
+    {
+        LOGE(ERROR, "unable to allocate memory for populate ram hypercall pfns");
+        goto err;
+    }
+
+    for (i = 0; i < nr_pages; i++)
+        pfns[i] = start_gpfn + i;
+
+    arg->domid = dm->domid;
+    arg->nr_extents   = nr_pages;
+    arg->extent_order = 0;
+    arg->mem_flags    = 0;
+    set_xen_guest_handle(arg->extent_start, pfns);
+
+    ret = xencall2(dm->call, __HYPERVISOR_memory_op,
+                   XENMEM_populate_physmap,
+                   (uintptr_t)arg);
+
+    if ( ret == nr_pages )
+        ret = 0; /* success */
+    else if ( ret >= 0 )
+    {
+        LOG(ERROR, "populate ram partial success %zd/%zd pages", ret, nr_pages);
+        ret = -1;
+        errno = -EBUSY;
+    }
+    else
+    {
+        LOGE(ERROR, "populate ram hypercall failed");
+        ret = -1;
+    }
+
+ err:
+    xencall_free_buffer(dm->call, pfns);
+    xencall_free_buffer(dm->call, arg);
+
+    return ret;
+}
 
 /*
  * Local variables:
index 991ea6327954166902875d62c9e39fd11e18cb9d..fde7b8d94229b7a0ae3c227469f769c6f413bb00 100644 (file)
@@ -137,6 +137,30 @@ int xendevicemodel_route_pci_intx_to_isa_irq(xendevicemodel_handle *dm,
 int xendevicemodel_set_isa_irq_level(xendevicemodel_handle *dm,
                                      uint8_t isa_irq, bool assert);
 
+/*
+ * Memory handling
+ * ===============
+ */
+
+/*
+ * Populate a region of guest physical address space with normal
+ * RAM. On success the entire region will have been populated and zero
+ * is returned.
+ *
+ * On failure -1 is returned and errno is set. The contents of the
+ * memory region is undefined and may contain partial success.
+ *
+ * Always logs on failure.
+ *
+ * XXX on partial failure xc_domain_populate_physmap_exact would
+ * return -1/EBUSY without undoing the partial success. This seems
+ * like a poor model to follow, note however that options for undoing
+ * are limited to de-populating the underlying area, which may not
+ * have been the initial state.
+ */
+int xendevicemodel_populate_ram(xendevicemodel_handle *dm,
+                                xen_pfn_t start_gpfn, size_t nr_pages);
+
 #endif
 /*
  * Local variables:
index 085a189bcabccf4a330ac2730a4625f3cd4e1b09..2ac9bfb1a93972b990da49d5724a1bd4d9bbd684 100644 (file)
@@ -12,5 +12,7 @@ VERS_1.0 {
                xendevicemodel_route_pci_intx_to_isa_irq;
                xendevicemodel_set_isa_irq_level;
 
+               xendevicemodel_populate_ram;
+
        local: *; /* Do not expose anything by default */
 };
index 93cf2ed48d9a84d763e940fa2e87979951e4ac03..b6b09dfdbf2375e4c5dd7a2d33b4ce8575cafdae 100644 (file)
@@ -7,6 +7,7 @@
 #include <xencall.h>
 
 #include <xen/sched.h>
+#include <xen/memory.h>
 #include <xen/hvm/params.h>
 
 struct xendevicemodel_handle {