]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
x86/hvm: provide XEN_DMOP_relocate_memory
authorRoss Lagerwall <ross.lagerwall@citrix.com>
Thu, 25 Jan 2018 11:24:14 +0000 (12:24 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 25 Jan 2018 11:24:14 +0000 (12:24 +0100)
Provide XEN_DMOP_relocate_memory, a limited version of
XENMEM_add_to_physmap to allow a deprivileged QEMU to move VRAM when a
guest programs its BAR. It is equivalent to XENMEM_add_to_physmap with
space == XENMAPSPACE_gmfn_range.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Reviewed-by: Paul Durrant <paul.durrant@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/dm.c
xen/include/public/hvm/dm_op.h
xen/include/xlat.lst

index a787f43737ab80637c693d260f317a30a0c3a54c..a5773e35f4462cfb60fd42832bdddd92db02bcc1 100644 (file)
@@ -640,6 +640,37 @@ static int dm_op(const struct dmop_args *op_args)
         break;
     }
 
+    case XEN_DMOP_relocate_memory:
+    {
+        struct xen_dm_op_relocate_memory *data = &op.u.relocate_memory;
+        struct xen_add_to_physmap xatp = {
+            .domid = op_args->domid,
+            .size = data->size,
+            .space = XENMAPSPACE_gmfn_range,
+            .idx = data->src_gfn,
+            .gpfn = data->dst_gfn,
+        };
+
+        if ( data->pad )
+        {
+            rc = -EINVAL;
+            break;
+        }
+
+        rc = xenmem_add_to_physmap(d, &xatp, 0);
+        if ( rc == 0 && data->size != xatp.size )
+            rc = xatp.size;
+        if ( rc > 0 )
+        {
+            data->size -= rc;
+            data->src_gfn += rc;
+            data->dst_gfn += rc;
+            const_op = false;
+            rc = -ERESTART;
+        }
+        break;
+    }
+
     default:
         rc = -EOPNOTSUPP;
         break;
@@ -669,6 +700,7 @@ CHECK_dm_op_set_mem_type;
 CHECK_dm_op_inject_event;
 CHECK_dm_op_inject_msi;
 CHECK_dm_op_remote_shutdown;
+CHECK_dm_op_relocate_memory;
 
 int compat_dm_op(domid_t domid,
                  unsigned int nr_bufs,
index e17308575a67fd903b4c69963b11b3d39602eb4f..837c53f1b59d0d3fb17f2a226fe68f0907e43034 100644 (file)
@@ -368,6 +368,24 @@ struct xen_dm_op_remote_shutdown {
                            /* (Other reason values are not blocked) */
 };
 
+/*
+ * XEN_DMOP_relocate_memory : Relocate GFNs for the specified guest.
+ *                            Identical to XENMEM_add_to_physmap with
+ *                            space == XENMAPSPACE_gmfn_range.
+ */
+#define XEN_DMOP_relocate_memory 17
+
+struct xen_dm_op_relocate_memory {
+    /* All fields are IN/OUT, with their OUT state undefined. */
+    /* Number of GFNs to process. */
+    uint32_t size;
+    uint32_t pad;
+    /* Starting GFN to relocate. */
+    uint64_aligned_t src_gfn;
+    /* Starting GFN where GFNs should be relocated. */
+    uint64_aligned_t dst_gfn;
+};
+
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
@@ -389,6 +407,7 @@ struct xen_dm_op {
         struct xen_dm_op_map_mem_type_to_ioreq_server
                 map_mem_type_to_ioreq_server;
         struct xen_dm_op_remote_shutdown remote_shutdown;
+        struct xen_dm_op_relocate_memory relocate_memory;
     } u;
 };
 
index 4346cbedcf2bd121d4010ad7847147203994292e..b3d00b7f46896e81a30a8ab25b67cce77ba6b653 100644 (file)
@@ -57,6 +57,7 @@
 ?      grant_entry_v2                  grant_table.h
 ?      gnttab_swap_grant_ref           grant_table.h
 !      dm_op_buf                       hvm/dm_op.h
+?      dm_op_relocate_memory           hvm/dm_op.h
 ?      dm_op_create_ioreq_server       hvm/dm_op.h
 ?      dm_op_destroy_ioreq_server      hvm/dm_op.h
 ?      dm_op_get_ioreq_server_info     hvm/dm_op.h