Skip to contentSkip to conversation

New hypercall for device models

PATCH Superseded Paul Durrant 7 participants 39 messages Jan 12, 2017 – Jan 17, 2017

v3 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#22 lore raw

PATCH v3 2/8 dm_op: convert HVMOP_*ioreq_server*

In reply to Paul Durrant

The definitions of HVM_IOREQSRV_BUFIOREQ_* have to persist as they are already in use by callers of the libxc interface.

--

Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Daniel De Graaf <[email protected]>

v3:
- Fix pad check.

v2:
- Addressed several comments from Jan.

---
 tools/libxc/xc_domain.c          | 212 ++++++++++++++++---------------------
 xen/arch/x86/hvm/dm.c            |  89 ++++++++++++++++
 xen/arch/x86/hvm/hvm.c           | 219 ---------------------------------------
 xen/arch/x86/hvm/ioreq.c         |  36 +++----
 xen/include/asm-x86/hvm/domain.h |   3 +-
 xen/include/public/hvm/dm_op.h   | 153 +++++++++++++++++++++++++++
 xen/include/public/hvm/hvm_op.h  | 132 +----------------------
 xen/include/xsm/dummy.h          |   6 --
 xen/include/xsm/xsm.h            |   6 --
 xen/xsm/dummy.c                  |   1 -
 xen/xsm/flask/hooks.c            |   6 --
 11 files changed, 356 insertions(+), 507 deletions(-)
tools/libxc/xc_domain.c +92 -120
index 296b852..419a897 100644
@@ -1417,24 +1417,24 @@ int xc_hvm_create_ioreq_server(xc_interface *xch,
                                int handle_bufioreq,
                                ioservid_t *id)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_create_ioreq_server_t, arg);
+    struct xen_dm_op op;
+    struct xen_dm_op_create_ioreq_server *data;
     int rc;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->handle_bufioreq = handle_bufioreq;
+    op.op = XEN_DMOP_create_ioreq_server;
+    data = &op.u.create_ioreq_server;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_create_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->handle_bufioreq = handle_bufioreq;
+
+    rc = do_dm_op(xch, domid, 1, &op, sizeof(op));
+    if ( rc )
+        return rc;
 
-    *id = arg->id;
+    *id = data->id;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return 0;
 }
 
 int xc_hvm_get_ioreq_server_info(xc_interface *xch,
@@ -1444,84 +1444,71 @@ int xc_hvm_get_ioreq_server_info(xc_interface *xch,
                                  xen_pfn_t *bufioreq_pfn,
                                  evtchn_port_t *bufioreq_port)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_get_ioreq_server_info_t, arg);
+    struct xen_dm_op op;
+    struct xen_dm_op_get_ioreq_server_info *data;
     int rc;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
+    op.op = XEN_DMOP_get_ioreq_server_info;
+    data = &op.u.get_ioreq_server_info;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_get_ioreq_server_info,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
-    if ( rc != 0 )
-        goto done;
+    data->id = id;
+
+    rc = do_dm_op(xch, domid, 1, &op, sizeof(op));
+    if ( rc )
+        return rc;
 
     if ( ioreq_pfn )
-        *ioreq_pfn = arg->ioreq_pfn;
+        *ioreq_pfn = data->ioreq_pfn;
 
     if ( bufioreq_pfn )
-        *bufioreq_pfn = arg->bufioreq_pfn;
+        *bufioreq_pfn = data->bufioreq_pfn;
 
     if ( bufioreq_port )
-        *bufioreq_port = arg->bufioreq_port;
+        *bufioreq_port = data->bufioreq_port;
 
-done:
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return 0;
 }
 
 int xc_hvm_map_io_range_to_ioreq_server(xc_interface *xch, domid_t domid,
                                         ioservid_t id, int is_mmio,
                                         uint64_t start, uint64_t end)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_ioreq_server_range *data;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
-    arg->type = is_mmio ? HVMOP_IO_RANGE_MEMORY : HVMOP_IO_RANGE_PORT;
-    arg->start = start;
-    arg->end = end;
+    op.op = XEN_DMOP_map_io_range_to_ioreq_server;
+    data = &op.u.map_io_range_to_ioreq_server;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_map_io_range_to_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->id = id;
+    data->type = is_mmio ? XEN_DMOP_IO_RANGE_MEMORY : XEN_DMOP_IO_RANGE_PORT;
+    data->start = start;
+    data->end = end;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_hvm_unmap_io_range_from_ioreq_server(xc_interface *xch, domid_t domid,
                                             ioservid_t id, int is_mmio,
                                             uint64_t start, uint64_t end)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_ioreq_server_range *data;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
-    arg->type = is_mmio ? HVMOP_IO_RANGE_MEMORY : HVMOP_IO_RANGE_PORT;
-    arg->start = start;
-    arg->end = end;
+    op.op = XEN_DMOP_unmap_io_range_from_ioreq_server;
+    data = &op.u.unmap_io_range_from_ioreq_server;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_unmap_io_range_from_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->id = id;
+    data->type = is_mmio ? XEN_DMOP_IO_RANGE_MEMORY : XEN_DMOP_IO_RANGE_PORT;
+    data->start = start;
+    data->end = end;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid,
@@ -1529,37 +1516,32 @@ int xc_hvm_map_pcidev_to_ioreq_server(xc_interface *xch, domid_t domid,
                                       uint8_t bus, uint8_t device,
                                       uint8_t function)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_ioreq_server_range *data;
 
     if (device > 0x1f || function > 0x7) {
         errno = EINVAL;
         return -1;
     }
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
-    arg->type = HVMOP_IO_RANGE_PCI;
+    op.op = XEN_DMOP_map_io_range_to_ioreq_server;
+    data = &op.u.map_io_range_to_ioreq_server;
+
+    data->id = id;
+    data->type = XEN_DMOP_IO_RANGE_PCI;
 
     /*
      * The underlying hypercall will deal with ranges of PCI SBDF
      * but, for simplicity, the API only uses singletons.
      */
-    arg->start = arg->end = HVMOP_PCI_SBDF((uint64_t)segment,
-                                           (uint64_t)bus,
-                                           (uint64_t)device,
-                                           (uint64_t)function);
-
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_map_io_range_to_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->start = data->end = XEN_DMOP_PCI_SBDF((uint64_t)segment,
+                                                (uint64_t)bus,
+                                                (uint64_t)device,
+                                                (uint64_t)function);
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t domid,
@@ -1567,54 +1549,49 @@ int xc_hvm_unmap_pcidev_from_ioreq_server(xc_interface *xch, domid_t domid,
                                           uint8_t bus, uint8_t device,
                                           uint8_t function)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_io_range_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_ioreq_server_range *data;
 
     if (device > 0x1f || function > 0x7) {
         errno = EINVAL;
         return -1;
     }
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
-    arg->type = HVMOP_IO_RANGE_PCI;
-    arg->start = arg->end = HVMOP_PCI_SBDF((uint64_t)segment,
-                                           (uint64_t)bus,
-                                           (uint64_t)device,
-                                           (uint64_t)function);
-
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_unmap_io_range_from_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    op.op = XEN_DMOP_unmap_io_range_from_ioreq_server;
+    data = &op.u.unmap_io_range_from_ioreq_server;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    data->id = id;
+    data->type = XEN_DMOP_IO_RANGE_PCI;
+
+    /*
+     * The underlying hypercall will deal with ranges of PCI SBDF
+     * but, for simplicity, the API only uses singletons.
+     */
+    data->start = data->end = XEN_DMOP_PCI_SBDF((uint64_t)segment,
+                                                (uint64_t)bus,
+                                                (uint64_t)device,
+                                                (uint64_t)function);
+
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_hvm_destroy_ioreq_server(xc_interface *xch,
                                 domid_t domid,
                                 ioservid_t id)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_destroy_ioreq_server_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_destroy_ioreq_server *data;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
+    op.op = XEN_DMOP_destroy_ioreq_server;
+    data = &op.u.destroy_ioreq_server;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_destroy_ioreq_server,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->id = id;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_hvm_set_ioreq_server_state(xc_interface *xch,
@@ -1622,23 +1599,18 @@ int xc_hvm_set_ioreq_server_state(xc_interface *xch,
                                   ioservid_t id,
                                   int enabled)
 {
-    DECLARE_HYPERCALL_BUFFER(xen_hvm_set_ioreq_server_state_t, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_set_ioreq_server_state *data;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-        return -1;
+    memset(&op, 0, sizeof(op));
 
-    arg->domid = domid;
-    arg->id = id;
-    arg->enabled = !!enabled;
+    op.op = XEN_DMOP_set_ioreq_server_state;
+    data = &op.u.set_ioreq_server_state;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_set_ioreq_server_state,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->id = id;
+    data->enabled = !!enabled;
 
-    xc_hypercall_buffer_free(xch, arg);
-    return rc;
+    return do_dm_op(xch, domid, 1, &op, sizeof(op));
 }
 
 int xc_domain_setdebugging(xc_interface *xch,
xen/arch/x86/hvm/dm.c +89 -0

97 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +0 -219

231 lines not on this page · raw message

xen/arch/x86/hvm/ioreq.c +18 -18
index 673a215..14dbb64 100644
@@ -514,9 +514,9 @@ static int hvm_ioreq_server_alloc_rangesets(struct hvm_ioreq_server *s,
         char *name;
 
         rc = asprintf(&name, "ioreq_server %d %s", s->id,
-                      (i == HVMOP_IO_RANGE_PORT) ? "port" :
-                      (i == HVMOP_IO_RANGE_MEMORY) ? "memory" :
-                      (i == HVMOP_IO_RANGE_PCI) ? "pci" :
+                      (i == XEN_DMOP_IO_RANGE_PORT) ? "port" :
+                      (i == XEN_DMOP_IO_RANGE_MEMORY) ? "memory" :
+                      (i == XEN_DMOP_IO_RANGE_PCI) ? "pci" :
                       "");
         if ( rc )
             goto fail;
@@ -834,9 +834,9 @@ int hvm_map_io_range_to_ioreq_server(struct domain *d, ioservid_t id,
 
             switch ( type )
             {
-            case HVMOP_IO_RANGE_PORT:
-            case HVMOP_IO_RANGE_MEMORY:
-            case HVMOP_IO_RANGE_PCI:
+            case XEN_DMOP_IO_RANGE_PORT:
+            case XEN_DMOP_IO_RANGE_MEMORY:
+            case XEN_DMOP_IO_RANGE_PCI:
                 r = s->range[type];
                 break;
 
@@ -886,9 +886,9 @@ int hvm_unmap_io_range_from_ioreq_server(struct domain *d, ioservid_t id,
 
             switch ( type )
             {
-            case HVMOP_IO_RANGE_PORT:
-            case HVMOP_IO_RANGE_MEMORY:
-            case HVMOP_IO_RANGE_PCI:
+            case XEN_DMOP_IO_RANGE_PORT:
+            case XEN_DMOP_IO_RANGE_MEMORY:
+            case XEN_DMOP_IO_RANGE_PCI:
                 r = s->range[type];
                 break;
 
@@ -1129,12 +1129,12 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
 
         /* PCI config data cycle */
 
-        sbdf = HVMOP_PCI_SBDF(0,
-                              PCI_BUS(CF8_BDF(cf8)),
-                              PCI_SLOT(CF8_BDF(cf8)),
-                              PCI_FUNC(CF8_BDF(cf8)));
+        sbdf = XEN_DMOP_PCI_SBDF(0,
+                                 PCI_BUS(CF8_BDF(cf8)),
+                                 PCI_SLOT(CF8_BDF(cf8)),
+                                 PCI_FUNC(CF8_BDF(cf8)));
 
-        type = HVMOP_IO_RANGE_PCI;
+        type = XEN_DMOP_IO_RANGE_PCI;
         addr = ((uint64_t)sbdf << 32) |
                CF8_ADDR_LO(cf8) |
                (p->addr & 3);
@@ -1153,7 +1153,7 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
     else
     {
         type = (p->type == IOREQ_TYPE_PIO) ?
-                HVMOP_IO_RANGE_PORT : HVMOP_IO_RANGE_MEMORY;
+                XEN_DMOP_IO_RANGE_PORT : XEN_DMOP_IO_RANGE_MEMORY;
         addr = p->addr;
     }
 
@@ -1175,19 +1175,19 @@ struct hvm_ioreq_server *hvm_select_ioreq_server(struct domain *d,
         {
             unsigned long end;
 
-        case HVMOP_IO_RANGE_PORT:
+        case XEN_DMOP_IO_RANGE_PORT:
             end = addr + p->size - 1;
             if ( rangeset_contains_range(r, addr, end) )
                 return s;
 
             break;
-        case HVMOP_IO_RANGE_MEMORY:
+        case XEN_DMOP_IO_RANGE_MEMORY:
             end = addr + (p->size * p->count) - 1;
             if ( rangeset_contains_range(r, addr, end) )
                 return s;
 
             break;
-        case HVMOP_IO_RANGE_PCI:
+        case XEN_DMOP_IO_RANGE_PCI:
             if ( rangeset_contains_singleton(r, addr >> 32) )
             {
                 p->type = IOREQ_TYPE_PCI_CONFIG;
xen/include/asm-x86/hvm/domain.h +2 -1
index d55d180..350f013 100644
@@ -33,6 +33,7 @@
 #include <public/hvm/params.h>
 #include <public/hvm/save.h>
 #include <public/hvm/hvm_op.h>
+#include <public/hvm/dm_op.h>
 
 struct hvm_ioreq_page {
     unsigned long gmfn;
@@ -47,7 +48,7 @@ struct hvm_ioreq_vcpu {
     bool_t           pending;
 };
 
-#define NR_IO_RANGE_TYPES (HVMOP_IO_RANGE_PCI + 1)
+#define NR_IO_RANGE_TYPES (XEN_DMOP_IO_RANGE_PCI + 1)
 #define MAX_NR_IO_RANGES  256
 
 struct hvm_ioreq_server {
xen/include/public/hvm/dm_op.h +153 -0

164 lines not on this page · raw message

xen/include/public/hvm/hvm_op.h +2 -130

146 lines not on this page · raw message

xen/include/xsm/dummy.h +0 -6
index b206f5a..9f7c174 100644
@@ -634,12 +634,6 @@ static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d)
     return xsm_default_action(action, current->domain, d);
 }
 
-static XSM_INLINE int xsm_hvm_ioreq_server(XSM_DEFAULT_ARG struct domain *d, int op)
-{
-    XSM_ASSERT_ACTION(XSM_DM_PRIV);
-    return xsm_default_action(action, current->domain, d);
-}
-
 static XSM_INLINE int xsm_mem_sharing_op(XSM_DEFAULT_ARG struct domain *d, struct domain *cd, int op)
 {
     XSM_ASSERT_ACTION(XSM_DM_PRIV);
xen/include/xsm/xsm.h +0 -6
index e2d336f..b5845a2 100644
@@ -166,7 +166,6 @@ struct xsm_operations {
     int (*hvm_set_isa_irq_level) (struct domain *d);
     int (*hvm_set_pci_link_route) (struct domain *d);
     int (*hvm_inject_msi) (struct domain *d);
-    int (*hvm_ioreq_server) (struct domain *d, int op);
     int (*mem_sharing_op) (struct domain *d, struct domain *cd, int op);
     int (*apic) (struct domain *d, int cmd);
     int (*memtype) (uint32_t access);
@@ -656,11 +655,6 @@ static inline int xsm_hvm_inject_msi (xsm_default_t def, struct domain *d)
     return xsm_ops->hvm_inject_msi(d);
 }
 
-static inline int xsm_hvm_ioreq_server (xsm_default_t def, struct domain *d, int op)
-{
-    return xsm_ops->hvm_ioreq_server(d, op);
-}
-
 static inline int xsm_mem_sharing_op (xsm_default_t def, struct domain *d, struct domain *cd, int op)
 {
     return xsm_ops->mem_sharing_op(d, cd, op);
xen/xsm/dummy.c +0 -1
index a082b28..d544ec1 100644
@@ -149,7 +149,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
     set_to_dummy_if_null(ops, hvm_set_isa_irq_level);
     set_to_dummy_if_null(ops, hvm_set_pci_link_route);
     set_to_dummy_if_null(ops, hvm_inject_msi);
-    set_to_dummy_if_null(ops, hvm_ioreq_server);
     set_to_dummy_if_null(ops, mem_sharing_op);
     set_to_dummy_if_null(ops, apic);
     set_to_dummy_if_null(ops, machine_memory_map);
xen/xsm/flask/hooks.c +0 -6
index 383dd4f..1ce8a36 100644
@@ -1525,11 +1525,6 @@ static int flask_hvm_inject_msi(struct domain *d)
     return current_has_perm(d, SECCLASS_HVM, HVM__SEND_IRQ);
 }
 
-static int flask_hvm_ioreq_server(struct domain *d, int op)
-{
-    return current_has_perm(d, SECCLASS_HVM, HVM__HVMCTL);
-}
-
 static int flask_mem_sharing_op(struct domain *d, struct domain *cd, int op)
 {
     int rc = current_has_perm(cd, SECCLASS_HVM, HVM__MEM_SHARING);
@@ -1808,7 +1803,6 @@ static struct xsm_operations flask_ops = {
     .hvm_set_isa_irq_level = flask_hvm_set_isa_irq_level,
     .hvm_set_pci_link_route = flask_hvm_set_pci_link_route,
     .hvm_inject_msi = flask_hvm_inject_msi,
-    .hvm_ioreq_server = flask_hvm_ioreq_server,
     .mem_sharing_op = flask_mem_sharing_op,
     .apic = flask_apic,
     .machine_memory_map = flask_machine_memory_map,
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#0 lore raw

v3 cover New hypercall for device models

Following on from the design submitted by Jennifer Herbert to the list [1] this series provides an implementation of __HYPERCALL_dm_op followed by patches based on Jan Beulich's previous HVMCTL series [2] to convert tools-only HVMOPs used by device models to DMOPs.

[1] https://lists.xenproject.org/archives/html/xen-devel/2016-09/msg01052.html
[2] https://lists.xenproject.org/archives/html/xen-devel/2016-06/msg02433.html

Paul Durrant (8):
public / x86: Introduce __HYPERCALL_dm_op...
dm_op: convert HVMOP_*ioreq_server*
dm_op: convert HVMOP_track_dirty_vram
dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level,

    and...

dm_op: convert HVMOP_modified_memory
dm_op: convert HVMOP_set_mem_type
dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi x86/hvm: serialize trap injecting producer and consumer

 docs/designs/dmop.markdown          | 158 +++++++++
 tools/flask/policy/modules/xen.if   |   8 +-
 tools/libxc/include/xenctrl.h       |  13 +-
 tools/libxc/xc_domain.c             | 212 +++++------
 tools/libxc/xc_misc.c               | 235 +++++--------
 tools/libxc/xc_private.c            |  70 ++++
 tools/libxc/xc_private.h            |   2 +
 xen/arch/x86/hvm/Makefile           |   1 +
 xen/arch/x86/hvm/dm.c               | 544 +++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c              | 677 +-----------------------------------
 xen/arch/x86/hvm/ioreq.c            |  36 +-
 xen/arch/x86/hvm/irq.c              |   7 +-
 xen/arch/x86/hypercall.c            |   2 +
 xen/arch/x86/mm/hap/hap.c           |   2 +-
 xen/arch/x86/mm/shadow/common.c     |   2 +-
 xen/include/asm-x86/hap.h           |   2 +-
 xen/include/asm-x86/hvm/domain.h    |   3 +-
 xen/include/asm-x86/hvm/hvm.h       |   3 +
 xen/include/asm-x86/shadow.h        |   2 +-
 xen/include/public/hvm/dm_op.h      | 373 ++++++++++++++++++++
 xen/include/public/hvm/hvm_op.h     | 230 +-----------
 xen/include/public/xen-compat.h     |   2 +-
 xen/include/public/xen.h            |   1 +
 xen/include/xen/hvm/irq.h           |   2 +-
 xen/include/xen/hypercall.h         |   7 +
 xen/include/xsm/dummy.h             |  36 +-
 xen/include/xsm/xsm.h               |  36 +-
 xen/xsm/dummy.c                     |   5 -
 xen/xsm/flask/hooks.c               |  37 +-
 xen/xsm/flask/policy/access_vectors |  15 +-
 30 files changed, 1409 insertions(+), 1314 deletions(-)
 create mode 100644 docs/designs/dmop.markdown
 create mode 100644 xen/arch/x86/hvm/dm.c
 create mode 100644 xen/include/public/hvm/dm_op.h
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

PATCH v3 1/8 public / x86: Introduce __HYPERCALL_dm_op...

...as a set of hypercalls to be used by a device model.

As stated in the new docs/designs/dm_op.markdown:

"The aim of DMOP is to prevent a compromised device model from compromising domains other then the one it is associated with. (And is therefore likely already compromised)."

See that file for further information.

This patch simply adds the boilerplate for the hypercall.

---

Cc Ian Jackson <[email protected]>
Cc Jennifer Herbert <[email protected]>
Cc Daniel De Graaf <[email protected]>
Cc Wei Liu <[email protected]>
Cc Andrew Cooper <[email protected]>

v3:
- Re-written large portions of dmop.markdown to remove references to previous proposals and make it a standalone design doc.

v2:
- Addressed several comments from Jan.
- Removed modification of __XEN_LATEST_INTERFACE_VERSION__ as it is not needed in this patch.

---
 docs/designs/dmop.markdown        | 158 ++++++++++++++++++++++++++++++++++++++
 tools/flask/policy/modules/xen.if |   2 +-
 tools/libxc/include/xenctrl.h     |   1 +
 tools/libxc/xc_private.c          |  70 +++++++++++++++++
 tools/libxc/xc_private.h          |   2 +
 xen/arch/x86/hvm/Makefile         |   1 +
 xen/arch/x86/hvm/dm.c             | 118 ++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c            |   1 +
 xen/arch/x86/hypercall.c          |   2 +
 xen/include/public/hvm/dm_op.h    |  71 +++++++++++++++++
 xen/include/public/xen.h          |   1 +
 xen/include/xen/hypercall.h       |   7 ++
 xen/include/xsm/dummy.h           |   6 ++
 xen/include/xsm/xsm.h             |   6 ++
 xen/xsm/flask/hooks.c             |   7 ++
 15 files changed, 452 insertions(+), 1 deletion(-)
 create mode 100644 docs/designs/dmop.markdown
 create mode 100644 xen/arch/x86/hvm/dm.c
 create mode 100644 xen/include/public/hvm/dm_op.h
docs/designs/dmop.markdown new file +158 -0
new file mode 100644
index 0000000..2a4bd16
@@ -0,0 +1,158 @@
+DMOP
+====
+
+Introduction
+------------
+
+The aim of DMOP is to prevent a compromised device model from compromising
+domains other then the one it is associated with. (And is therefore likely
+already compromised).
+
+The problem occurs when you a device model issues an hypercall that
+includes references to user memory other than the operation structure
+itself, such as with Track dirty VRAM (as used in VGA emulation).
+Is this case, the address of this other user memory needs to be vetted,
+to ensure it is not within restricted address ranges, such as kernel
+memory. The real problem comes down to how you would vet this address -
+the idea place to do this is within the privcmd driver, without privcmd
+having to have specific knowledge of the hypercall's semantics.
+
+The Design
+----------
+
+The privcmd driver implements a new restriction ioctl, which takes a domid
+parameter.  After that restriction ioctl is issued, the privcmd driver will
+permit only DMOP hypercalls, and only with the specified target domid.
+
+A DMOP hypercall consists of an array of buffers and lengths, with the
+first one containing the specific DMOP parameters. These can then reference
+further buffers from within in the array. Since the only user buffers
+passed are that found with that array, they can all can be audited by
+privcmd.
+
+The following code illustrates this idea:
+
+struct xen_dm_op {
+    uint32_t op;
+};
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};
+typedef struct xen_dm_op_buf xen_dm_op_buf_t;
+
+enum neg_errnoval
+HYPERVISOR_dm_op(domid_t domid,
+                 xen_dm_op_buf_t bufs[],
+                 unsigned int nr_bufs)
+
+@domid is the domain the hypercall operates on.
+@bufs points to an array of buffers where @bufs[0] contains a struct
+dm_op, describing the specific device model operation and its parameters.
+@bufs[1..] may be referenced in the parameters for the purposes of
+passing extra information to or from the domain.
+@nr_bufs is the number of buffers in the @bufs array.
+
+It is forbidden for the above struct (xen_dm_op) to contain any guest
+handles. If they are needed, they should instead be in
+HYPERVISOR_dm_op->bufs.
+
+Validation by privcmd driver
+----------------------------
+
+If the privcmd driver has been restricted to specific domain (using a
+ new ioctl), when it received an op, it will:
+
+1. Check hypercall is DMOP.
+
+2. Check domid == restricted domid.
+
+3. For each @nr_bufs in @bufs: Check @h and @size give a buffer
+   wholly in the user space part of the virtual address space. (e.g.
+   Linux will use access_ok()).
+
+
+Xen Implementation
+------------------
+
+Since a DMOP buffers need to be copied from or to the guest, functions for
+doing this would be written as below.  Note that care is taken to prevent
+damage from buffer under- or over-run situations.  If the DMOP is called
+with incorrectly sized buffers, zeros will be read, while extra is ignored.
+
+static int get_buf(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,
+                   unsigned int nr_bufs, unsigned int idx,
+                   struct xen_dm_op_buf *buf)
+{
+    if ( idx >= nr_bufs )
+        return -ENOENT;
+
+    return copy_from_guest_offset(buf, bufs, idx, 1) ? -EFAULT : 0;
+}
+
+static int copy_buf_from_guest(XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs,
+                               unsigned int nr_bufs, void *dst,
+                               unsigned int idx, size_t dst_size)
+{
+    struct xen_dm_op_buf buf;
+    size_t size;
+    int rc;
+
+    memset(dst, 0, dst_size);
+
+    rc = get_buf(bufs, nr_bufs, idx, &buf);
+    if ( rc )
+        return rc;
+
+    size = min_t(size_t, dst_size, buf.size);
+
+    return copy_from_guest(dst, buf.h, size) ? -EFAULT : 0;
+}
+
+static int copy_buf_to_guest(...)
+{
+    /* Similar to the above, except copying the the other
+       direction. */
+}
+
+This leaves do_dm_op easy to implement as below:
+
+long do_dm_op(domid_t domid,
+              unsigned int nr_bufs,
+              XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs)
+{
+    struct domain *d;
+    struct xen_dm_op op;
+    long rc;
+
+    rc = rcu_lock_remote_domain_by_id(domid, &d);
+    if ( rc )
+        return rc;
+
+    if ( !has_hvm_container_domain(d) )
+        goto out;
+
+    rc = xsm_dm_op(XSM_DM_PRIV, d);
+    if ( rc )
+        goto out;
+
+    rc = copy_buf_from_guest(bufs, nr_bufs, &op, 0, sizeof(op));
+    if ( rc )
+        goto out;
+
+    switch ( op.op )
+    {
+    default:
+        rc = -EOPNOTSUPP;
+        break;
+    }
+
+    if ( !rc )
+        rc = copy_buf_to_guest(bufs, nr_bufs, 0, &op, sizeof(op));
+
+ out:
+    rcu_unlock_domain(d);
+
+    return rc;
+}
tools/flask/policy/modules/xen.if +1 -1
index 1aca75d..f9254c2 100644
@@ -151,7 +151,7 @@ define(`device_model', `
 
 	allow $1 $2_target:domain { getdomaininfo shutdown };
 	allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack };
-	allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq };
+	allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm };
 ')
 
 # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/include/xenctrl.h +1 -0
index 4ab0f57..2ba46d7 100644
@@ -41,6 +41,7 @@
 #include <xen/sched.h>
 #include <xen/memory.h>
 #include <xen/grant_table.h>
+#include <xen/hvm/dm_op.h>
 #include <xen/hvm/params.h>
 #include <xen/xsm/flask_op.h>
 #include <xen/tmem.h>
tools/libxc/xc_private.c +70 -0

76 lines not on this page · raw message

tools/libxc/xc_private.h +2 -0
index 97445ae..f191320 100644
@@ -422,6 +422,8 @@ int xc_vm_event_control(xc_interface *xch, domid_t domain_id, unsigned int op,
 void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
                          uint32_t *port);
 
+int do_dm_op(xc_interface *xch, domid_t domid, unsigned int nr_bufs, ...);
+
 #endif /* __XC_PRIVATE_H__ */
 
 /*
xen/arch/x86/hvm/Makefile +1 -0
index f750d13..5869d1b 100644
@@ -2,6 +2,7 @@ subdir-y += svm
 subdir-y += vmx
 
 obj-y += asid.o
+obj-y += dm.o
 obj-y += emulate.o
 obj-y += hpet.o
 obj-y += hvm.o
xen/arch/x86/hvm/dm.c new file +118 -0

118 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +1 -0
index 9f74334..f362a42 100644
@@ -4234,6 +4234,7 @@ static const hypercall_table_t hvm_hypercall_table[] = {
     COMPAT_CALL(platform_op),
     COMPAT_CALL(mmuext_op),
     HYPERCALL(xenpmu_op),
+    HYPERCALL(dm_op),
     HYPERCALL(arch_1)
 };
 
xen/arch/x86/hypercall.c +2 -0
index 70a30a5..fb582d1 100644
@@ -66,6 +66,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(kexec_op, 2),
     ARGS(tmem_op, 1),
     ARGS(xenpmu_op, 2),
+    ARGS(dm_op, 3),
     ARGS(mca, 1),
     ARGS(arch_1, 1),
 };
@@ -128,6 +129,7 @@ static const hypercall_table_t pv_hypercall_table[] = {
     HYPERCALL(tmem_op),
 #endif
     HYPERCALL(xenpmu_op),
+    HYPERCALL(dm_op),
     HYPERCALL(mca),
     HYPERCALL(arch_1),
 };
xen/include/public/hvm/dm_op.h new file +71 -0

71 lines not on this page · raw message

xen/include/public/xen.h +1 -0
index 6593026..91ba8bb 100644
@@ -120,6 +120,7 @@ DEFINE_XEN_GUEST_HANDLE(xen_ulong_t);
 #define __HYPERVISOR_tmem_op              38
 #define __HYPERVISOR_xc_reserved_op       39 /* reserved for XenClient */
 #define __HYPERVISOR_xenpmu_op            40
+#define __HYPERVISOR_dm_op                41
 
 /* Architecture-specific hypercall definitions. */
 #define __HYPERVISOR_arch_0               48
xen/include/xen/hypercall.h +7 -0
index 207a0e8..fee78f7 100644
@@ -15,6 +15,7 @@
 #include <public/tmem.h>
 #include <public/version.h>
 #include <public/pmu.h>
+#include <public/hvm/dm_op.h>
 #include <asm/hypercall.h>
 #include <xsm/xsm.h>
 
@@ -141,6 +142,12 @@ do_xenoprof_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
 extern long
 do_xenpmu_op(unsigned int op, XEN_GUEST_HANDLE_PARAM(xen_pmu_params_t) arg);
 
+extern long
+do_dm_op(
+    domid_t domid,
+    unsigned int nr_bufs,
+    XEN_GUEST_HANDLE_PARAM(xen_dm_op_buf_t) bufs);
+
 #ifdef CONFIG_COMPAT
 
 extern int
xen/include/xsm/dummy.h +6 -0
index 95460af..b206f5a 100644
@@ -727,6 +727,12 @@ static XSM_INLINE int xsm_pmu_op (XSM_DEFAULT_ARG struct domain *d, unsigned int
     }
 }
 
+static XSM_INLINE int xsm_dm_op(XSM_DEFAULT_ARG struct domain *d)
+{
+    XSM_ASSERT_ACTION(XSM_DM_PRIV);
+    return xsm_default_action(action, current->domain, d);
+}
+
 #endif /* CONFIG_X86 */
 
 #include <public/version.h>
xen/include/xsm/xsm.h +6 -0
index 5dc59dd..e2d336f 100644
@@ -184,6 +184,7 @@ struct xsm_operations {
     int (*ioport_permission) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
     int (*ioport_mapping) (struct domain *d, uint32_t s, uint32_t e, uint8_t allow);
     int (*pmu_op) (struct domain *d, unsigned int op);
+    int (*dm_op) (struct domain *d);
 #endif
     int (*xen_version) (uint32_t cmd);
 };
@@ -722,6 +723,11 @@ static inline int xsm_pmu_op (xsm_default_t def, struct domain *d, unsigned int
     return xsm_ops->pmu_op(d, op);
 }
 
+static inline int xsm_dm_op(xsm_default_t def, struct domain *d)
+{
+    return xsm_ops->dm_op(d);
+}
+
 #endif /* CONFIG_X86 */
 
 static inline int xsm_xen_version (xsm_default_t def, uint32_t op)
xen/xsm/flask/hooks.c +7 -0
index 040a251..383dd4f 100644
@@ -1635,6 +1635,12 @@ static int flask_pmu_op (struct domain *d, unsigned int op)
         return -EPERM;
     }
 }
+
+static int flask_dm_op(struct domain *d)
+{
+    return current_has_perm(d, SECCLASS_HVM, HVM__DM);
+}
+
 #endif /* CONFIG_X86 */
 
 static int flask_xen_version (uint32_t op)
@@ -1814,6 +1820,7 @@ static struct xsm_operations flask_ops = {
     .ioport_permission = flask_ioport_permission,
     .ioport_mapping = flask_ioport_mapping,
     .pmu_op = flask_pmu_op,
+    .dm_op = flask_dm_op,
 #endif
     .xen_version = flask_xen_version,
 };
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#33 lore raw

PATCH v3 6/8 dm_op: convert HVMOP_set_mem_type

In reply to Paul Durrant

This patch removes the need for handling HVMOP restarts, so that infrastructure is removed.

NOTE: This patch also modifies the type of the 'nr' argument of
xc_hvm_set_mem_type() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

---

Cc Jan Beulich <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Daniel De Graaf <[email protected]>

v3:
- Addressed more comments from Jan.

v2:
- Addressed several comments from Jan.

---
 tools/libxc/include/xenctrl.h       |   2 +-
 tools/libxc/xc_misc.c               |  29 +++-----
 xen/arch/x86/hvm/dm.c               |  92 ++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c              | 136 +-----------------------------------
 xen/include/public/hvm/dm_op.h      |  22 ++++++
 xen/include/public/hvm/hvm_op.h     |  20 ------
 xen/xsm/flask/policy/access_vectors |   2 +-
 7 files changed, 127 insertions(+), 176 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
index a5c234f..13431bb 100644
@@ -1634,7 +1634,7 @@ int xc_hvm_modified_memory(
  * Allowed types are HVMMEM_ram_rw, HVMMEM_ram_ro, HVMMEM_mmio_dm
  */
 int xc_hvm_set_mem_type(
-    xc_interface *xch, domid_t dom, hvmmem_type_t memtype, uint64_t first_pfn, uint64_t nr);
+    xc_interface *xch, domid_t dom, hvmmem_type_t memtype, uint64_t first_pfn, uint32_t nr);
 
 /*
  * Injects a hardware/software CPU trap, to take effect the next time the HVM 
tools/libxc/xc_misc.c +10 -19
index 597df99..5b06d6b 100644
@@ -590,30 +590,21 @@ int xc_hvm_modified_memory(
 }
 
 int xc_hvm_set_mem_type(
-    xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t first_pfn, uint64_t nr)
+    xc_interface *xch, domid_t dom, hvmmem_type_t mem_type, uint64_t first_pfn, uint32_t nr)
 {
-    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_set_mem_type, arg);
-    int rc;
-
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-    {
-        PERROR("Could not allocate memory for xc_hvm_set_mem_type hypercall");
-        return -1;
-    }
+    struct xen_dm_op op;
+    struct xen_dm_op_set_mem_type *data;
 
-    arg->domid        = dom;
-    arg->hvmmem_type  = mem_type;
-    arg->first_pfn    = first_pfn;
-    arg->nr           = nr;
+    memset(&op, 0, sizeof(op));
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_set_mem_type,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    op.op = XEN_DMOP_set_mem_type;
+    data = &op.u.set_mem_type;
 
-    xc_hypercall_buffer_free(xch, arg);
+    data->mem_type = mem_type;
+    data->first_pfn = first_pfn;
+    data->nr = nr;
 
-    return rc;
+    return do_dm_op(xch, dom, 1, &op, sizeof(op));
 }
 
 int xc_hvm_inject_trap(
xen/arch/x86/hvm/dm.c +92 -0

104 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +1 -135

158 lines not on this page · raw message

xen/include/public/hvm/dm_op.h +22 -0
index 6a2fb39..4eab08b 100644
@@ -248,6 +248,27 @@ struct xen_dm_op_modified_memory {
     uint64_aligned_t first_pfn;
 };
 
+/*
+ * XEN_DMOP_set_mem_type: Notify that a region of memory is to be treated
+ *                        in a specific way. (See definition of
+ *                        hvmmem_type_t).
+ *
+ * NOTE: In the event of a continuation (return code -ERESTART), the
+ *       @first_pfn is set to the value of the pfn of the remaining
+ *       region and @nr reduced to the size of the remaining region.
+ */
+#define XEN_DMOP_set_mem_type 12
+
+struct xen_dm_op_set_mem_type {
+    /* IN - number of contiguous pages */
+    uint32_t nr;
+    /* IN - new hvmmem_type_t of region */
+    uint16_t mem_type;
+    uint16_t pad;
+    /* IN - first pfn in region */
+    uint64_aligned_t first_pfn;
+};
+
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
@@ -263,6 +284,7 @@ struct xen_dm_op {
         struct xen_dm_op_set_isa_irq_level set_isa_irq_level;
         struct xen_dm_op_set_pci_link_route set_pci_link_route;
         struct xen_dm_op_modified_memory modified_memory;
+        struct xen_dm_op_set_mem_type set_mem_type;
     } u;
 };
 
xen/include/public/hvm/hvm_op.h +0 -20
index 76e1b78..d7e2f12 100644
@@ -96,26 +96,6 @@ typedef enum {
     HVMMEM_ioreq_server
 } hvmmem_type_t;
 
-/* Following tools-only interfaces may change in future. */
-#if defined(__XEN__) || defined(__XEN_TOOLS__)
-
-#define HVMOP_set_mem_type    8
-/* Notify that a region of memory is to be treated in a specific way. */
-struct xen_hvm_set_mem_type {
-    /* Domain to be updated. */
-    domid_t domid;
-    /* Memory type */
-    uint16_t hvmmem_type;
-    /* Number of pages. */
-    uint32_t nr;
-    /* First pfn. */
-    uint64_aligned_t first_pfn;
-};
-typedef struct xen_hvm_set_mem_type xen_hvm_set_mem_type_t;
-DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_mem_type_t);
-
-#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */
-
 /* Hint from PV drivers for pagetable destruction. */
 #define HVMOP_pagetable_dying        9
 struct xen_hvm_pagetable_dying {
xen/xsm/flask/policy/access_vectors +1 -1
index 361e7aa..381f659 100644
@@ -262,7 +262,7 @@ class hvm
     bind_irq
 # XEN_DOMCTL_pin_mem_cacheattr
     cacheattr
-# HVMOP_get_mem_type, HVMOP_set_mem_type,
+# HVMOP_get_mem_type,
 # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying,
 # HVMOP_inject_trap
     hvmctl
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#24 lore raw

PATCH v3 3/8 dm_op: convert HVMOP_track_dirty_vram

In reply to Paul Durrant

The handle type passed to the underlying shadow and hap functions is changed for compatibility with the new hypercall buffer.

NOTE: This patch also modifies the type of the 'nr' parameter of
xc_hvm_track_dirty_vram() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

---

Cc Jan Beulich <[email protected]>
Cc Daniel De Graaf <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc George Dunlap <[email protected]>
Cc Tim Deegan <[email protected]>

v3:
- Check d->max_vcpus rather than d->vcpu, as requested by Jan.
- The handle type changes (from uint8 to void) are still necessary, hence omitting Jan's R-b until this is confirmed to be acceptable.

v2:
- Addressed several comments from Jan.

---
 tools/flask/policy/modules/xen.if   |  4 ++--
 tools/libxc/include/xenctrl.h       |  2 +-
 tools/libxc/xc_misc.c               | 32 +++++++++-----------------
 xen/arch/x86/hvm/dm.c               | 45 +++++++++++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c              | 41 ---------------------------------
 xen/arch/x86/mm/hap/hap.c           |  2 +-
 xen/arch/x86/mm/shadow/common.c     |  2 +-
 xen/include/asm-x86/hap.h           |  2 +-
 xen/include/asm-x86/shadow.h        |  2 +-
 xen/include/public/hvm/dm_op.h      | 18 +++++++++++++++
 xen/include/public/hvm/hvm_op.h     | 16 -------------
 xen/xsm/flask/hooks.c               |  3 ---
 xen/xsm/flask/policy/access_vectors |  2 --
 13 files changed, 80 insertions(+), 91 deletions(-)
tools/flask/policy/modules/xen.if +2 -2
index f9254c2..45e5b5f 100644
@@ -58,7 +58,7 @@ define(`create_domain_common', `
 	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
 	allow $1 $2:grant setup;
 	allow $1 $2:hvm { cacheattr getparam hvmctl irqlevel pciroute sethvmc
-			setparam pcilevel trackdirtyvram nested altp2mhvm altp2mhvm_op send_irq };
+			setparam pcilevel nested altp2mhvm altp2mhvm_op send_irq };
 ')
 
 # create_domain(priv, target)
@@ -151,7 +151,7 @@ define(`device_model', `
 
 	allow $1 $2_target:domain { getdomaininfo shutdown };
 	allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack };
-	allow $1 $2_target:hvm { getparam setparam trackdirtyvram hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm };
+	allow $1 $2_target:hvm { getparam setparam hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm };
 ')
 
 # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/include/xenctrl.h +1 -1
index 2ba46d7..c7ee412 100644
@@ -1620,7 +1620,7 @@ int xc_hvm_inject_msi(
  */
 int xc_hvm_track_dirty_vram(
     xc_interface *xch, domid_t dom,
-    uint64_t first_pfn, uint64_t nr,
+    uint64_t first_pfn, uint32_t nr,
     unsigned long *bitmap);
 
 /*
tools/libxc/xc_misc.c +10 -22
index 06e90de..4c41d41 100644
@@ -581,34 +581,22 @@ int xc_hvm_inject_msi(
 
 int xc_hvm_track_dirty_vram(
     xc_interface *xch, domid_t dom,
-    uint64_t first_pfn, uint64_t nr,
+    uint64_t first_pfn, uint32_t nr,
     unsigned long *dirty_bitmap)
 {
-    DECLARE_HYPERCALL_BOUNCE(dirty_bitmap, (nr+7) / 8, XC_HYPERCALL_BUFFER_BOUNCE_OUT);
-    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_track_dirty_vram, arg);
-    int rc;
+    struct xen_dm_op op;
+    struct xen_dm_op_track_dirty_vram *data;
 
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL || xc_hypercall_bounce_pre(xch, dirty_bitmap) )
-    {
-        PERROR("Could not bounce memory for xc_hvm_track_dirty_vram hypercall");
-        rc = -1;
-        goto out;
-    }
+    memset(&op, 0, sizeof(op));
 
-    arg->domid     = dom;
-    arg->first_pfn = first_pfn;
-    arg->nr        = nr;
-    set_xen_guest_handle(arg->dirty_bitmap, dirty_bitmap);
+    op.op = XEN_DMOP_track_dirty_vram;
+    data = &op.u.track_dirty_vram;
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_track_dirty_vram,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    data->first_pfn = first_pfn;
+    data->nr = nr;
 
-out:
-    xc_hypercall_buffer_free(xch, arg);
-    xc_hypercall_bounce_post(xch, dirty_bitmap);
-    return rc;
+    return do_dm_op(xch, dom, 2, &op, sizeof(op),
+                    dirty_bitmap, (nr + 7) / 8);
 }
 
 int xc_hvm_modified_memory(
xen/arch/x86/hvm/dm.c +45 -0

64 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +0 -41

47 lines not on this page · raw message

xen/arch/x86/mm/hap/hap.c +1 -1
index e6dc088..6dbb3cc 100644
@@ -68,7 +68,7 @@
 int hap_track_dirty_vram(struct domain *d,
                          unsigned long begin_pfn,
                          unsigned long nr,
-                         XEN_GUEST_HANDLE_64(uint8) guest_dirty_bitmap)
+                         XEN_GUEST_HANDLE_PARAM(void) guest_dirty_bitmap)
 {
     long rc = 0;
     struct sh_dirty_vram *dirty_vram;
xen/arch/x86/mm/shadow/common.c +1 -1
index 4113351..0079238 100644
@@ -3604,7 +3604,7 @@ static void sh_clean_dirty_bitmap(struct domain *d)
 int shadow_track_dirty_vram(struct domain *d,
                             unsigned long begin_pfn,
                             unsigned long nr,
-                            XEN_GUEST_HANDLE_64(uint8) guest_dirty_bitmap)
+                            XEN_GUEST_HANDLE_PARAM(void) guest_dirty_bitmap)
 {
     int rc = 0;
     unsigned long end_pfn = begin_pfn + nr;
xen/include/asm-x86/hap.h +1 -1
index dedb4b1..88587c4 100644
@@ -43,7 +43,7 @@ void  hap_vcpu_init(struct vcpu *v);
 int   hap_track_dirty_vram(struct domain *d,
                            unsigned long begin_pfn,
                            unsigned long nr,
-                           XEN_GUEST_HANDLE_64(uint8) dirty_bitmap);
+                           XEN_GUEST_HANDLE_PARAM(void) dirty_bitmap);
 
 extern const struct paging_mode *hap_paging_get_mode(struct vcpu *);
 int hap_set_allocation(struct domain *d, unsigned int pages, bool *preempted);
xen/include/asm-x86/shadow.h +1 -1
index bac952f..7e1ed3b 100644
@@ -63,7 +63,7 @@ int shadow_enable(struct domain *d, u32 mode);
 int shadow_track_dirty_vram(struct domain *d,
                             unsigned long first_pfn,
                             unsigned long nr,
-                            XEN_GUEST_HANDLE_64(uint8) dirty_bitmap);
+                            XEN_GUEST_HANDLE_PARAM(void) dirty_bitmap);
 
 /* Handler for shadow control ops: operations from user-space to enable
  * and disable ephemeral shadow modes (test mode and log-dirty mode) and
xen/include/public/hvm/dm_op.h +18 -0
index b5c7c29..fb9cf17 100644
@@ -174,6 +174,23 @@ struct xen_dm_op_destroy_ioreq_server {
     uint16_t pad;
 };
 
+/*
+ * XEN_DMOP_track_dirty_vram: Track modifications to the specified pfn
+ *                            range.
+ *
+ * NOTE: The bitmap passed back to the caller is passed in a
+ *       secondary buffer.
+ */
+#define XEN_DMOP_track_dirty_vram 7
+
+struct xen_dm_op_track_dirty_vram {
+    /* IN - number of pages to be tracked */
+    uint32_t nr;
+    uint32_t pad;
+    /* IN - first pfn to track */
+    uint64_aligned_t first_pfn;
+};
+
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
@@ -184,6 +201,7 @@ struct xen_dm_op {
         struct xen_dm_op_ioreq_server_range unmap_io_range_from_ioreq_server;
         struct xen_dm_op_set_ioreq_server_state set_ioreq_server_state;
         struct xen_dm_op_destroy_ioreq_server destroy_ioreq_server;
+        struct xen_dm_op_track_dirty_vram track_dirty_vram;
     } u;
 };
 
xen/include/public/hvm/hvm_op.h +0 -16
index 6fcd86d..47e836c 100644
@@ -95,22 +95,6 @@ typedef enum {
 /* Following tools-only interfaces may change in future. */
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 
-/* Track dirty VRAM. */
-#define HVMOP_track_dirty_vram    6
-struct xen_hvm_track_dirty_vram {
-    /* Domain to be tracked. */
-    domid_t  domid;
-    /* Number of pages to track. */
-    uint32_t nr;
-    /* First pfn to track. */
-    uint64_aligned_t first_pfn;
-    /* OUT variable. */
-    /* Dirty bitmap buffer. */
-    XEN_GUEST_HANDLE_64(uint8) dirty_bitmap;
-};
-typedef struct xen_hvm_track_dirty_vram xen_hvm_track_dirty_vram_t;
-DEFINE_XEN_GUEST_HANDLE(xen_hvm_track_dirty_vram_t);
-
 /* Notify that some pages got modified by the Device Model. */
 #define HVMOP_modified_memory    7
 struct xen_hvm_modified_memory {
xen/xsm/flask/hooks.c +0 -3
index 1ce8a36..a4272d7 100644
@@ -1180,9 +1180,6 @@ static int flask_hvm_param(struct domain *d, unsigned long op)
     case HVMOP_get_param:
         perm = HVM__GETPARAM;
         break;
-    case HVMOP_track_dirty_vram:
-        perm = HVM__TRACKDIRTYVRAM;
-        break;
     default:
         perm = HVM__HVMCTL;
     }
xen/xsm/flask/policy/access_vectors +0 -2
index 92e6da9..47ce589 100644
@@ -268,8 +268,6 @@ class hvm
     bind_irq
 # XEN_DOMCTL_pin_mem_cacheattr
     cacheattr
-# HVMOP_track_dirty_vram
-    trackdirtyvram
 # HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type,
 # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying,
 # HVMOP_inject_trap
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#30 lore raw

PATCH v3 5/8 dm_op: convert HVMOP_modified_memory

In reply to Paul Durrant

This patch introduces code to handle DMOP continuations.

NOTE: This patch also modifies the type of the 'nr' argument of
xc_hvm_modified_memory() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

---

Cc Jan Beulich <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>
Cc Daniel De Graaf <[email protected]>

v3:
- Addressed more comments from Jan.

v2:
- Addressed several comments from Jan, including...
- Added explanatory note on continuation handling

---
 tools/libxc/include/xenctrl.h       |  2 +-
 tools/libxc/xc_misc.c               | 27 +++++--------
 xen/arch/x86/hvm/dm.c               | 78 ++++++++++++++++++++++++++++++++++++-
 xen/arch/x86/hvm/hvm.c              | 60 ----------------------------
 xen/include/public/hvm/dm_op.h      | 19 +++++++++
 xen/include/public/hvm/hvm_op.h     | 13 -------
 xen/xsm/flask/policy/access_vectors |  2 +-
 7 files changed, 107 insertions(+), 94 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
index f819bf2..a5c234f 100644
@@ -1627,7 +1627,7 @@ int xc_hvm_track_dirty_vram(
  * Notify that some pages got modified by the Device Model
  */
 int xc_hvm_modified_memory(
-    xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr);
+    xc_interface *xch, domid_t dom, uint64_t first_pfn, uint32_t nr);
 
 /*
  * Set a range of memory to a specific type.
tools/libxc/xc_misc.c +9 -18
index ddea2bb..597df99 100644
@@ -573,29 +573,20 @@ int xc_hvm_track_dirty_vram(
 }
 
 int xc_hvm_modified_memory(
-    xc_interface *xch, domid_t dom, uint64_t first_pfn, uint64_t nr)
+    xc_interface *xch, domid_t dom, uint64_t first_pfn, uint32_t nr)
 {
-    DECLARE_HYPERCALL_BUFFER(struct xen_hvm_modified_memory, arg);
-    int rc;
-
-    arg = xc_hypercall_buffer_alloc(xch, arg, sizeof(*arg));
-    if ( arg == NULL )
-    {
-        PERROR("Could not allocate memory for xc_hvm_modified_memory hypercall");
-        return -1;
-    }
+    struct xen_dm_op op;
+    struct xen_dm_op_modified_memory *data;
 
-    arg->domid     = dom;
-    arg->first_pfn = first_pfn;
-    arg->nr        = nr;
+    memset(&op, 0, sizeof(op));
 
-    rc = xencall2(xch->xcall, __HYPERVISOR_hvm_op,
-                  HVMOP_modified_memory,
-                  HYPERCALL_BUFFER_AS_ARG(arg));
+    op.op = XEN_DMOP_modified_memory;
+    data = &op.u.modified_memory;
 
-    xc_hypercall_buffer_free(xch, arg);
+    data->first_pfn = first_pfn;
+    data->nr = nr;
 
-    return rc;
+    return do_dm_op(xch, dom, 1, &op, sizeof(op));
 }
 
 int xc_hvm_set_mem_type(
xen/arch/x86/hvm/dm.c +77 -1

112 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +0 -60

72 lines not on this page · raw message

xen/include/public/hvm/dm_op.h +19 -0
index 9743453..6a2fb39 100644
@@ -230,6 +230,24 @@ struct xen_dm_op_set_pci_link_route {
     uint8_t  isa_irq;
 };
 
+/*
+ * XEN_DMOP_modified_memory: Notify that a set of pages were modified by
+ *                           an emulator.
+ *
+ * NOTE: In the event of a continuation, the @first_pfn is set to the
+ *       value of the pfn of the remaining set of pages and @nr reduced
+ *       to the size of the remaining set.
+ */
+#define XEN_DMOP_modified_memory 11
+
+struct xen_dm_op_modified_memory {
+    /* IN - number of contiguous pages modified */
+    uint32_t nr;
+    uint32_t pad;
+    /* IN - first pfn modified */
+    uint64_aligned_t first_pfn;
+};
+
 struct xen_dm_op {
     uint32_t op;
     uint32_t pad;
@@ -244,6 +262,7 @@ struct xen_dm_op {
         struct xen_dm_op_set_pci_intx_level set_pci_intx_level;
         struct xen_dm_op_set_isa_irq_level set_isa_irq_level;
         struct xen_dm_op_set_pci_link_route set_pci_link_route;
+        struct xen_dm_op_modified_memory modified_memory;
     } u;
 };
 
xen/include/public/hvm/hvm_op.h +0 -13
index 7cf8d4d..76e1b78 100644
@@ -99,19 +99,6 @@ typedef enum {
 /* Following tools-only interfaces may change in future. */
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 
-/* Notify that some pages got modified by the Device Model. */
-#define HVMOP_modified_memory    7
-struct xen_hvm_modified_memory {
-    /* Domain to be updated. */
-    domid_t  domid;
-    /* Number of pages. */
-    uint32_t nr;
-    /* First pfn. */
-    uint64_aligned_t first_pfn;
-};
-typedef struct xen_hvm_modified_memory xen_hvm_modified_memory_t;
-DEFINE_XEN_GUEST_HANDLE(xen_hvm_modified_memory_t);
-
 #define HVMOP_set_mem_type    8
 /* Notify that a region of memory is to be treated in a specific way. */
 struct xen_hvm_set_mem_type {
xen/xsm/flask/policy/access_vectors +1 -1
index 2f0ed2d..361e7aa 100644
@@ -262,7 +262,7 @@ class hvm
     bind_irq
 # XEN_DOMCTL_pin_mem_cacheattr
     cacheattr
-# HVMOP_modified_memory, HVMOP_get_mem_type, HVMOP_set_mem_type,
+# HVMOP_get_mem_type, HVMOP_set_mem_type,
 # HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying,
 # HVMOP_inject_trap
     hvmctl
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#36 lore raw

PATCH v3 8/8 x86/hvm: serialize trap injecting producer and consumer

In reply to Paul Durrant

Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.

---
Cc: Andrew Cooper <[email protected]>

v3:
- Re-re-re-based after more changes.

v2:
- Re-re-based after Andrew's recent changes.

---
 xen/arch/x86/hvm/dm.c         | 5 ++++-
 xen/arch/x86/hvm/hvm.c        | 8 +++++---
 xen/include/asm-x86/hvm/hvm.h | 3 +++
 3 files changed, 12 insertions(+), 4 deletions(-)
xen/arch/x86/hvm/dm.c +4 -1
index 0a7e50a..e09c8e7 100644
@@ -286,13 +286,16 @@ static int inject_trap(struct domain *d, unsigned int vcpuid,
     if ( vcpuid >= d->max_vcpus || !(v = d->vcpu[vcpuid]) )
         return -EINVAL;
 
-    if ( v->arch.hvm_vcpu.inject_trap.vector != -1 )
+    if ( cmpxchg(&v->arch.hvm_vcpu.inject_trap.vector,
+                 HVM_TRAP_VECTOR_UNSET, HVM_TRAP_VECTOR_UPDATING) !=
+         HVM_TRAP_VECTOR_UNSET )
         return -EBUSY;
 
     v->arch.hvm_vcpu.inject_trap.type = type;
     v->arch.hvm_vcpu.inject_trap.insn_len = insn_len;
     v->arch.hvm_vcpu.inject_trap.error_code = error_code;
     v->arch.hvm_vcpu.inject_trap.cr2 = cr2;
+    smp_wmb();
     v->arch.hvm_vcpu.inject_trap.vector = vector;
 
     return 0;
xen/arch/x86/hvm/hvm.c +5 -3
index 8d42adc..441111b 100644
@@ -539,12 +539,14 @@ void hvm_do_resume(struct vcpu *v)
     }
 
     /* Inject pending hw/sw trap */
-    if ( v->arch.hvm_vcpu.inject_trap.vector != -1 )
+    if ( v->arch.hvm_vcpu.inject_trap.vector >= 0 )
     {
+        smp_rmb();
+
         if ( !hvm_event_pending(v) )
             hvm_inject_event(&v->arch.hvm_vcpu.inject_trap);
 
-        v->arch.hvm_vcpu.inject_trap.vector = -1;
+        v->arch.hvm_vcpu.inject_trap.vector = HVM_TRAP_VECTOR_UNSET;
     }
 
     if ( unlikely(v->arch.vm_event) && v->arch.monitor.next_interrupt_enabled )
@@ -1563,7 +1565,7 @@ int hvm_vcpu_initialise(struct vcpu *v)
         (void(*)(unsigned long))hvm_assert_evtchn_irq,
         (unsigned long)v);
 
-    v->arch.hvm_vcpu.inject_trap.vector = -1;
+    v->arch.hvm_vcpu.inject_trap.vector = HVM_TRAP_VECTOR_UNSET;
 
     if ( is_pvh_domain(d) )
     {
xen/include/asm-x86/hvm/hvm.h +3 -0
index 8c95c08..bcacee3 100644
@@ -77,6 +77,9 @@ enum hvm_intblk {
 #define HVM_HAP_SUPERPAGE_2MB   0x00000001
 #define HVM_HAP_SUPERPAGE_1GB   0x00000002
 
+#define HVM_TRAP_VECTOR_UNSET    (-1)
+#define HVM_TRAP_VECTOR_UPDATING (-2)
+
 /*
  * The hardware virtual machine (HVM) interface abstracts away from the
  * x86/x86_64 CPU virtualization assist specifics. Currently this interface
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#35 lore raw

PATCH v3 7/8 dm_op: convert HVMOP_inject_trap and HVMOP_inject_msi

In reply to Paul Durrant

NOTE: This patch also modifies the types of the 'vector', 'type' and
'insn_len' arguments of xc_hvm_inject_trap() from uint32_t to uint8_t. In practice the values passed were always truncated to 8 bits.

---

Cc Daniel De Graaf <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>

v3:
- Fixed prefixing and padding.

v2:
- Addressed several comments from Jan.

---
 tools/flask/policy/modules/xen.if   |  2 +-
 tools/libxc/include/xenctrl.h       |  4 +-
 tools/libxc/xc_misc.c               | 64 +++++++++++--------------------
 xen/arch/x86/hvm/dm.c               | 49 ++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c              | 76 -------------------------------------
 xen/include/public/hvm/dm_op.h      | 48 +++++++++++++++++++++++
 xen/include/public/hvm/hvm_op.h     | 45 ----------------------
 xen/include/xsm/dummy.h             |  6 ---
 xen/include/xsm/xsm.h               |  6 ---
 xen/xsm/dummy.c                     |  1 -
 xen/xsm/flask/hooks.c               |  6 ---
 xen/xsm/flask/policy/access_vectors |  5 +--
 12 files changed, 124 insertions(+), 188 deletions(-)
tools/flask/policy/modules/xen.if +1 -1
index 092a6c5..45e5cea 100644
@@ -151,7 +151,7 @@ define(`device_model', `
 
 	allow $1 $2_target:domain { getdomaininfo shutdown };
 	allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack };
-	allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr send_irq dm };
+	allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr dm };
 ')
 
 # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/include/xenctrl.h +2 -2
index 13431bb..539cc69 100644
@@ -1641,8 +1641,8 @@ int xc_hvm_set_mem_type(
  * resumes. 
  */
 int xc_hvm_inject_trap(
-    xc_interface *xch, domid_t dom, int vcpu, uint32_t vector,
-    uint32_t type, uint32_t error_code, uint32_t insn_len,
+    xc_interface *xch, domid_t dom, int vcpu, uint8_t vector,
+    uint8_t type, uint32_t error_code, uint8_t insn_len,
     uint64_t cr2);
 
 /*
tools/libxc/xc_misc.c +23 -41

87 lines not on this page · raw message

xen/arch/x86/hvm/dm.c +49 -0

61 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +0 -76

94 lines not on this page · raw message

xen/include/public/hvm/dm_op.h +48 -0

60 lines not on this page · raw message

xen/include/public/hvm/hvm_op.h +0 -45

57 lines not on this page · raw message

xen/include/xsm/dummy.h +0 -6
index d3de4b7..4b27ae7 100644
@@ -610,12 +610,6 @@ static XSM_INLINE int xsm_shadow_control(XSM_DEFAULT_ARG struct domain *d, uint3
     return xsm_default_action(action, current->domain, d);
 }
 
-static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d)
-{
-    XSM_ASSERT_ACTION(XSM_DM_PRIV);
-    return xsm_default_action(action, current->domain, d);
-}
-
 static XSM_INLINE int xsm_mem_sharing_op(XSM_DEFAULT_ARG struct domain *d, struct domain *cd, int op)
 {
     XSM_ASSERT_ACTION(XSM_DM_PRIV);
xen/include/xsm/xsm.h +0 -6
index 2e4a3ce..2cf7ac1 100644
@@ -162,7 +162,6 @@ struct xsm_operations {
 #ifdef CONFIG_X86
     int (*do_mca) (void);
     int (*shadow_control) (struct domain *d, uint32_t op);
-    int (*hvm_inject_msi) (struct domain *d);
     int (*mem_sharing_op) (struct domain *d, struct domain *cd, int op);
     int (*apic) (struct domain *d, int cmd);
     int (*memtype) (uint32_t access);
@@ -632,11 +631,6 @@ static inline int xsm_shadow_control (xsm_default_t def, struct domain *d, uint3
     return xsm_ops->shadow_control(d, op);
 }
 
-static inline int xsm_hvm_inject_msi (xsm_default_t def, struct domain *d)
-{
-    return xsm_ops->hvm_inject_msi(d);
-}
-
 static inline int xsm_mem_sharing_op (xsm_default_t def, struct domain *d, struct domain *cd, int op)
 {
     return xsm_ops->mem_sharing_op(d, cd, op);
xen/xsm/dummy.c +0 -1
index f1568dd..1f659c7 100644
@@ -145,7 +145,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
 #ifdef CONFIG_X86
     set_to_dummy_if_null(ops, do_mca);
     set_to_dummy_if_null(ops, shadow_control);
-    set_to_dummy_if_null(ops, hvm_inject_msi);
     set_to_dummy_if_null(ops, mem_sharing_op);
     set_to_dummy_if_null(ops, apic);
     set_to_dummy_if_null(ops, machine_memory_map);
xen/xsm/flask/hooks.c +0 -6
index 685cbfa..9332ca1 100644
@@ -1502,11 +1502,6 @@ static int flask_ioport_mapping(struct domain *d, uint32_t start, uint32_t end,
     return flask_ioport_permission(d, start, end, access);
 }
 
-static int flask_hvm_inject_msi(struct domain *d)
-{
-    return current_has_perm(d, SECCLASS_HVM, HVM__SEND_IRQ);
-}
-
 static int flask_mem_sharing_op(struct domain *d, struct domain *cd, int op)
 {
     int rc = current_has_perm(cd, SECCLASS_HVM, HVM__MEM_SHARING);
@@ -1784,7 +1779,6 @@ static struct xsm_operations flask_ops = {
     .hvm_set_pci_intx_level = flask_hvm_set_pci_intx_level,
     .hvm_set_isa_irq_level = flask_hvm_set_isa_irq_level,
     .hvm_set_pci_link_route = flask_hvm_set_pci_link_route,
-    .hvm_inject_msi = flask_hvm_inject_msi,
     .mem_sharing_op = flask_mem_sharing_op,
     .apic = flask_apic,
     .machine_memory_map = flask_machine_memory_map,
xen/xsm/flask/policy/access_vectors +1 -4
index 381f659..36a7df9 100644
@@ -263,8 +263,7 @@ class hvm
 # XEN_DOMCTL_pin_mem_cacheattr
     cacheattr
 # HVMOP_get_mem_type,
-# HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying,
-# HVMOP_inject_trap
+# HVMOP_set_mem_access, HVMOP_get_mem_access, HVMOP_pagetable_dying
     hvmctl
 # XEN_DOMCTL_mem_sharing_op and XENMEM_sharing_op_{share,add_physmap} with:
 #  source = the domain making the hypercall
@@ -272,8 +271,6 @@ class hvm
     mem_sharing
 # XEN_DOMCTL_audit_p2m
     audit_p2m
-# HVMOP_inject_msi
-    send_irq
 # checked in XENMEM_sharing_op_{share,add_physmap} with:
 #  source = domain whose memory is being shared
 #  target = client domain
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#29 lore raw

PATCH v3 4/8 dm_op: convert HVMOP_set_pci_intx_level, HVMOP_set_isa_irq_level, and...

In reply to Paul Durrant

... HVMOP_set_pci_link_route

These HVMOPs were exposed to guests so their definitions need to be preserved for compatibility. This patch therefore updates __XEN_LATEST_INTERFACE_VERSION__ to 0x00040900 and makes the HVMOP defintions conditional on __XEN_INTERFACE_VERSION__ less than that value.

NOTE: This patch also widens the 'domain' parameter of
xc_hvm_set_pci_intx_level() from a uint8_t to a uint16_t.

---

Cc Daniel De Graaf <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Andrew Cooper <[email protected]>

v3:
- Remove unnecessary padding.

v2:
- Interface version modification moved to this patch, where it is needed.
- Addressed several comments from Jan.

---
 tools/flask/policy/modules/xen.if   |   8 +--
 tools/libxc/include/xenctrl.h       |   2 +-
 tools/libxc/xc_misc.c               |  83 ++++++++--------------
 xen/arch/x86/hvm/dm.c               |  72 +++++++++++++++++++
 xen/arch/x86/hvm/hvm.c              | 136 ------------------------------------
 xen/arch/x86/hvm/irq.c              |   7 +-
 xen/include/public/hvm/dm_op.h      |  42 +++++++++++
 xen/include/public/hvm/hvm_op.h     |   4 ++
 xen/include/public/xen-compat.h     |   2 +-
 xen/include/xen/hvm/irq.h           |   2 +-
 xen/include/xsm/dummy.h             |  18 -----
 xen/include/xsm/xsm.h               |  18 -----
 xen/xsm/dummy.c                     |   3 -
 xen/xsm/flask/hooks.c               |  15 ----
 xen/xsm/flask/policy/access_vectors |   6 --
 15 files changed, 158 insertions(+), 260 deletions(-)
tools/flask/policy/modules/xen.if +4 -4
index 45e5b5f..092a6c5 100644
@@ -57,8 +57,8 @@ define(`create_domain_common', `
 	allow $1 $2:shadow enable;
 	allow $1 $2:mmu { map_read map_write adjust memorymap physmap pinpage mmuext_op updatemp };
 	allow $1 $2:grant setup;
-	allow $1 $2:hvm { cacheattr getparam hvmctl irqlevel pciroute sethvmc
-			setparam pcilevel nested altp2mhvm altp2mhvm_op send_irq };
+	allow $1 $2:hvm { cacheattr getparam hvmctl sethvmc
+			setparam nested altp2mhvm altp2mhvm_op send_irq };
 ')
 
 # create_domain(priv, target)
@@ -93,7 +93,7 @@ define(`manage_domain', `
 #   (inbound migration is the same as domain creation)
 define(`migrate_domain_out', `
 	allow $1 domxen_t:mmu map_read;
-	allow $1 $2:hvm { gethvmc getparam irqlevel };
+	allow $1 $2:hvm { gethvmc getparam };
 	allow $1 $2:mmu { stat pageinfo map_read };
 	allow $1 $2:domain { getaddrsize getvcpucontext pause destroy };
 	allow $1 $2:domain2 gettsc;
@@ -151,7 +151,7 @@ define(`device_model', `
 
 	allow $1 $2_target:domain { getdomaininfo shutdown };
 	allow $1 $2_target:mmu { map_read map_write adjust physmap target_hack };
-	allow $1 $2_target:hvm { getparam setparam hvmctl irqlevel pciroute pcilevel cacheattr send_irq dm };
+	allow $1 $2_target:hvm { getparam setparam hvmctl cacheattr send_irq dm };
 ')
 
 # make_device_model(priv, dm_dom, hvm_dom)
tools/libxc/include/xenctrl.h +1 -1
index c7ee412..f819bf2 100644
@@ -1594,7 +1594,7 @@ int xc_physdev_unmap_pirq(xc_interface *xch,
 
 int xc_hvm_set_pci_intx_level(
     xc_interface *xch, domid_t dom,
-    uint8_t domain, uint8_t bus, uint8_t device, uint8_t intx,
+    uint16_t domain, uint8_t bus, uint8_t device, uint8_t intx,
     unsigned int level);
 int xc_hvm_set_isa_irq_level(
     xc_interface *xch, domid_t dom,
tools/libxc/xc_misc.c +28 -55

114 lines not on this page · raw message

xen/arch/x86/hvm/dm.c +72 -0

84 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +0 -136

159 lines not on this page · raw message

xen/arch/x86/hvm/irq.c +5 -2
index e597114..265a620 100644
@@ -229,13 +229,14 @@ void hvm_assert_evtchn_irq(struct vcpu *v)
         hvm_set_callback_irq_level(v);
 }
 
-void hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
+int hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
 {
     struct hvm_irq *hvm_irq = &d->arch.hvm_domain.irq;
     u8 old_isa_irq;
     int i;
 
-    ASSERT((link <= 3) && (isa_irq <= 15));
+    if ( (link > 3) || (isa_irq > 15) )
+        return -EINVAL;
 
     spin_lock(&d->arch.hvm_domain.irq_lock);
 
@@ -273,6 +274,8 @@ void hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq)
 
     dprintk(XENLOG_G_INFO, "Dom%u PCI link %u changed %u -> %u\n",
             d->domain_id, link, old_isa_irq, isa_irq);
+
+    return 0;
 }
 
 int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data)
xen/include/public/hvm/dm_op.h +42 -0

54 lines not on this page · raw message

xen/include/public/hvm/hvm_op.h +4 -0
index 47e836c..7cf8d4d 100644
@@ -38,6 +38,8 @@ struct xen_hvm_param {
 typedef struct xen_hvm_param xen_hvm_param_t;
 DEFINE_XEN_GUEST_HANDLE(xen_hvm_param_t);
 
+#if __XEN_INTERFACE_VERSION__ < 0x00040900
+
 /* Set the logical level of one of a domain's PCI INTx wires. */
 #define HVMOP_set_pci_intx_level  2
 struct xen_hvm_set_pci_intx_level {
@@ -76,6 +78,8 @@ struct xen_hvm_set_pci_link_route {
 typedef struct xen_hvm_set_pci_link_route xen_hvm_set_pci_link_route_t;
 DEFINE_XEN_GUEST_HANDLE(xen_hvm_set_pci_link_route_t);
 
+#endif /* __XEN_INTERFACE_VERSION__ < 0x00040900 */
+
 /* Flushes all VCPU TLBs: @arg must be NULL. */
 #define HVMOP_flush_tlbs          5
 
xen/include/public/xen-compat.h +1 -1
index dd8a5c0..b673653 100644
@@ -27,7 +27,7 @@
 #ifndef __XEN_PUBLIC_XEN_COMPAT_H__
 #define __XEN_PUBLIC_XEN_COMPAT_H__
 
-#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040800
+#define __XEN_LATEST_INTERFACE_VERSION__ 0x00040900
 
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
 /* Xen is built with matching headers and implements the latest interface. */
xen/include/xen/hvm/irq.h +1 -1
index 4c9cb20..d3f8623 100644
@@ -122,7 +122,7 @@ void hvm_isa_irq_assert(
 void hvm_isa_irq_deassert(
     struct domain *d, unsigned int isa_irq);
 
-void hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq);
+int hvm_set_pci_link_route(struct domain *d, u8 link, u8 isa_irq);
 
 int hvm_inject_msi(struct domain *d, uint64_t addr, uint32_t data);
 
xen/include/xsm/dummy.h +0 -18
index 9f7c174..d3de4b7 100644
@@ -610,24 +610,6 @@ static XSM_INLINE int xsm_shadow_control(XSM_DEFAULT_ARG struct domain *d, uint3
     return xsm_default_action(action, current->domain, d);
 }
 
-static XSM_INLINE int xsm_hvm_set_pci_intx_level(XSM_DEFAULT_ARG struct domain *d)
-{
-    XSM_ASSERT_ACTION(XSM_DM_PRIV);
-    return xsm_default_action(action, current->domain, d);
-}
-
-static XSM_INLINE int xsm_hvm_set_isa_irq_level(XSM_DEFAULT_ARG struct domain *d)
-{
-    XSM_ASSERT_ACTION(XSM_DM_PRIV);
-    return xsm_default_action(action, current->domain, d);
-}
-
-static XSM_INLINE int xsm_hvm_set_pci_link_route(XSM_DEFAULT_ARG struct domain *d)
-{
-    XSM_ASSERT_ACTION(XSM_DM_PRIV);
-    return xsm_default_action(action, current->domain, d);
-}
-
 static XSM_INLINE int xsm_hvm_inject_msi(XSM_DEFAULT_ARG struct domain *d)
 {
     XSM_ASSERT_ACTION(XSM_DM_PRIV);
xen/include/xsm/xsm.h +0 -18
index b5845a2..2e4a3ce 100644
@@ -162,9 +162,6 @@ struct xsm_operations {
 #ifdef CONFIG_X86
     int (*do_mca) (void);
     int (*shadow_control) (struct domain *d, uint32_t op);
-    int (*hvm_set_pci_intx_level) (struct domain *d);
-    int (*hvm_set_isa_irq_level) (struct domain *d);
-    int (*hvm_set_pci_link_route) (struct domain *d);
     int (*hvm_inject_msi) (struct domain *d);
     int (*mem_sharing_op) (struct domain *d, struct domain *cd, int op);
     int (*apic) (struct domain *d, int cmd);
@@ -635,21 +632,6 @@ static inline int xsm_shadow_control (xsm_default_t def, struct domain *d, uint3
     return xsm_ops->shadow_control(d, op);
 }
 
-static inline int xsm_hvm_set_pci_intx_level (xsm_default_t def, struct domain *d)
-{
-    return xsm_ops->hvm_set_pci_intx_level(d);
-}
-
-static inline int xsm_hvm_set_isa_irq_level (xsm_default_t def, struct domain *d)
-{
-    return xsm_ops->hvm_set_isa_irq_level(d);
-}
-
-static inline int xsm_hvm_set_pci_link_route (xsm_default_t def, struct domain *d)
-{
-    return xsm_ops->hvm_set_pci_link_route(d);
-}
-
 static inline int xsm_hvm_inject_msi (xsm_default_t def, struct domain *d)
 {
     return xsm_ops->hvm_inject_msi(d);
xen/xsm/dummy.c +0 -3
index d544ec1..f1568dd 100644
@@ -145,9 +145,6 @@ void __init xsm_fixup_ops (struct xsm_operations *ops)
 #ifdef CONFIG_X86
     set_to_dummy_if_null(ops, do_mca);
     set_to_dummy_if_null(ops, shadow_control);
-    set_to_dummy_if_null(ops, hvm_set_pci_intx_level);
-    set_to_dummy_if_null(ops, hvm_set_isa_irq_level);
-    set_to_dummy_if_null(ops, hvm_set_pci_link_route);
     set_to_dummy_if_null(ops, hvm_inject_msi);
     set_to_dummy_if_null(ops, mem_sharing_op);
     set_to_dummy_if_null(ops, apic);
xen/xsm/flask/hooks.c +0 -15
index a4272d7..685cbfa 100644
@@ -1502,21 +1502,6 @@ static int flask_ioport_mapping(struct domain *d, uint32_t start, uint32_t end,
     return flask_ioport_permission(d, start, end, access);
 }
 
-static int flask_hvm_set_pci_intx_level(struct domain *d)
-{
-    return current_has_perm(d, SECCLASS_HVM, HVM__PCILEVEL);
-}
-
-static int flask_hvm_set_isa_irq_level(struct domain *d)
-{
-    return current_has_perm(d, SECCLASS_HVM, HVM__IRQLEVEL);
-}
-
-static int flask_hvm_set_pci_link_route(struct domain *d)
-{
-    return current_has_perm(d, SECCLASS_HVM, HVM__PCIROUTE);
-}
-
 static int flask_hvm_inject_msi(struct domain *d)
 {
     return current_has_perm(d, SECCLASS_HVM, HVM__SEND_IRQ);
xen/xsm/flask/policy/access_vectors +0 -6
index 47ce589..2f0ed2d 100644
@@ -259,12 +259,6 @@ class hvm
     setparam
 # HVMOP_get_param
     getparam
-# HVMOP_set_pci_intx_level (also needs hvmctl)
-    pcilevel
-# HVMOP_set_isa_irq_level
-    irqlevel
-# HVMOP_set_pci_link_route
-    pciroute
     bind_irq
 # XEN_DOMCTL_pin_mem_cacheattr
     cacheattr
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Paul Durrant
Quoted 90 lines · Paul Durrant

...as a set of hypercalls to be used by a device model.

As stated in the new docs/designs/dm_op.markdown:

"The aim of DMOP is to prevent a compromised device model from compromising domains other then the one it is associated with. (And is therefore likely already compromised)."

See that file for further information.

This patch simply adds the boilerplate for the hypercall.

---

Cc Ian Jackson <[email protected]>
Cc Jennifer Herbert <[email protected]>
Cc Daniel De Graaf <[email protected]>
Cc Wei Liu <[email protected]>
Cc Andrew Cooper <[email protected]>

v3:
- Re-written large portions of dmop.markdown to remove references to previous proposals and make it a standalone design doc.

v2:
- Addressed several comments from Jan.
- Removed modification of __XEN_LATEST_INTERFACE_VERSION__ as it is not needed in this patch.

---
 docs/designs/dmop.markdown        | 158 ++++++++++++++++++++++++++++++++++++++
 tools/flask/policy/modules/xen.if |   2 +-
 tools/libxc/include/xenctrl.h     |   1 +
 tools/libxc/xc_private.c          |  70 +++++++++++++++++
 tools/libxc/xc_private.h          |   2 +
 xen/arch/x86/hvm/Makefile         |   1 +
 xen/arch/x86/hvm/dm.c             | 118 ++++++++++++++++++++++++++++
 xen/arch/x86/hvm/hvm.c            |   1 +
 xen/arch/x86/hypercall.c          |   2 +
 xen/include/public/hvm/dm_op.h    |  71 +++++++++++++++++
 xen/include/public/xen.h          |   1 +
 xen/include/xen/hypercall.h       |   7 ++
 xen/include/xsm/dummy.h           |   6 ++
 xen/include/xsm/xsm.h             |   6 ++
 xen/xsm/flask/hooks.c             |   7 ++
 15 files changed, 452 insertions(+), 1 deletion(-)
 create mode 100644 docs/designs/dmop.markdown
 create mode 100644 xen/arch/x86/hvm/dm.c
 create mode 100644 xen/include/public/hvm/dm_op.h
docs/designs/dmop.markdown new file +32 -0
new file mode 100644
index 0000000..2a4bd16
@@ -0,0 +1,158 @@
+DMOP
+====
+
+Introduction
+------------
+
+The aim of DMOP is to prevent a compromised device model from compromising
+domains other then the one it is associated with. (And is therefore likely
+already compromised).
+
+The problem occurs when you a device model issues an hypercall that
+includes references to user memory other than the operation structure
+itself, such as with Track dirty VRAM (as used in VGA emulation).
+Is this case, the address of this other user memory needs to be vetted,
+to ensure it is not within restricted address ranges, such as kernel
+memory. The real problem comes down to how you would vet this address -
+the idea place to do this is within the privcmd driver, without privcmd
+having to have specific knowledge of the hypercall's semantics.
+
+The Design
+----------
+
+The privcmd driver implements a new restriction ioctl, which takes a domid
+parameter.  After that restriction ioctl is issued, the privcmd driver will
+permit only DMOP hypercalls, and only with the specified target domid.
+
+A DMOP hypercall consists of an array of buffers and lengths, with the
+first one containing the specific DMOP parameters. These can then reference
+further buffers from within in the array. Since the only user buffers
+passed are that found with that array, they can all can be audited by
+privcmd.
+

docs/designs/dmop.markdown line 42

Quoted 10 lines
docs/designs/dmop.markdown new file +10 -0
+The following code illustrates this idea:
+
+struct xen_dm_op {
+    uint32_t op;
+};
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 1 line

-----Original Message-----

[snip]

Quoted 21 lines

docs/designs/dmop.markdown line 42

Quoted 5 lines
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

Quoted 6 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there is no explicit support for DMOPs in privcmd. When explicit support is added then this can change and we can use a void ptr and size_t as you say.

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does indeed limit us and so using XEN_GUEST_HANDLE would indeed seem more sensible (and we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Let's see what Jan thinks.

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 10 lines
Quoted 10 lines

docs/designs/dmop.markdown line 42

Quoted 6 lines · On 12.01.17 at 17:10, <[email protected]> wrote:
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

Yes, padding needs to be added.

Quoted 11 lines
Quoted 11 lines

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Quoted 10 lines

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there is no explicit support for DMOPs in privcmd. When explicit support is added then this can change and we can use a void ptr and size_t as you say.

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does indeed limit us and so using XEN_GUEST_HANDLE would indeed seem more sensible (and we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Just like with other tools only interfaces, I think this should remain a 64-bit handle, to avoid (as you say, but wrongly in conjunction with a "normal" handle) the need for a compat wrapper.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#23 lore raw

Re: [PATCH v3 2/8] dm_op: convert HVMOP_*ioreq_server*

In reply to Paul Durrant
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

The definitions of HVM_IOREQSRV_BUFIOREQ_* have to persist as they are already in use by callers of the libxc interface.

--

That's an odd placement ...

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 8/8
#37 lore raw

Re: [PATCH v3 8/8] x86/hvm: serialize trap injecting producer and consumer

In reply to Paul Durrant
Quoted 10 lines · Paul Durrant

Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.

---
Cc: Andrew Cooper <[email protected]>

This looks fairly unrelated to the other dm changes. Given that it is a backport candidate, should it be pulled ahead of the move to dm.c? (I can make this happen on commit if we are in agreement).

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#38 lore raw

Re: [PATCH v3 8/8] x86/hvm: serialize trap injecting producer and consumer

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 17:28, <[email protected]> wrote:
Quoted 10 lines · Paul Durrant

Since injection works on a remote vCPU, and since there's no enforcement of the subject vCPU being paused, there's a potential race between the producing and consuming sides. Fix this by leveraging the vector field as synchronization variable.

---
Cc: Andrew Cooper <[email protected]>

Quoted 5 lines

This looks fairly unrelated to the other dm changes. Given that it is a backport candidate, should it be pulled ahead of the move to dm.c? (I can make this happen on commit if we are in agreement).

This indeed was the case from the very beginning of the HVMOP series, and I've never done the re-order because I had never expected it to take so long for the earlier patches to go in. And admittedly I was also too lazy (or should I say too busy, to make it sound better) to do that re-ordering, as the fix didn't seem important enough to bother (I'm not sure why you think this would be a backporting candidate, as I don't think this hypercall is used by anything that's in fully supported state).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 34 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 12 January 2017 16:29
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: Ian Jackson <[email protected]>; Jennifer Herbert <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: RE: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 10 lines
Quoted 10 lines

docs/designs/dmop.markdown line 42

Quoted 6 lines · On 12.01.17 at 17:10, <[email protected]> wrote:
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

Yes, padding needs to be added.

Quoted 11 lines
Quoted 11 lines

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Do we need to care about a 32-bit kernel for a tools-only hypercall? I thought a toolstack already had to be (at least) 64-bit to match Xen.

Paul

Quoted 15 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Quoted 3 lines

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there

is

Quoted 1 line

no explicit support for DMOPs in privcmd. When explicit support is added

then

Quoted 3 lines

this can change and we can use a void ptr and size_t as you say.

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does

indeed

Quoted 1 line

limit us and so using XEN_GUEST_HANDLE would indeed seem more

sensible (and

Quoted 8 lines
Quoted 2 lines

we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Just like with other tools only interfaces, I think this should remain a 64-bit handle, to avoid (as you say, but wrongly in conjunction with a "normal" handle) the need for a compat wrapper.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 21 lines
Quoted 21 lines
Quoted 1 line · On 13.01.17 at 10:05, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: 12 January 2017 16:29

Quoted 17 lines
Quoted 17 lines
Quoted 1 line · On 12.01.17 at 17:10, <[email protected]> wrote:

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 5 lines
Quoted 2 lines

But that won't cover a 32-bit kernel.

Do we need to care about a 32-bit kernel for a tools-only hypercall? I thought a toolstack already had to be (at least) 64-bit to match Xen.

Why would that be? Didn't XenServer for a long time run with a 32-bit Dom0 on top of a 64-bit Xen? See also domctl/sysctl.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Paul Durrant
Quoted 40 lines · Paul Durrant
Quoted 40 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 12 January 2017 16:29
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: Ian Jackson <[email protected]>; Jennifer Herbert <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>
Subject: RE: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 10 lines
Quoted 10 lines

docs/designs/dmop.markdown line 42

Quoted 6 lines · On 12.01.17 at 17:10, <[email protected]> wrote:
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

Yes, padding needs to be added.

Quoted 16 lines
Quoted 16 lines

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 5 lines
Quoted 2 lines

But that won't cover a 32-bit kernel.

Do we need to care about a 32-bit kernel for a tools-only hypercall? I thought a toolstack already had to be (at least) 64-bit to match Xen.

Toolstack can run on 32bit kernel on 64bit Xen.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 35 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 13 January 2017 10:31
To: Andrew Cooper <[email protected]>; Paul Durrant <[email protected]>
Cc: Ian Jackson <[email protected]>; Jennifer Herbert <[email protected]>; Wei Liu <[email protected]>; xen- [email protected]; Daniel DeGraaf <[email protected]>
Subject: RE: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 11 lines
Quoted 11 lines
Quoted 1 line · On 13.01.17 at 10:05, <[email protected]> wrote:

From: Jan Beulich [mailto:[email protected]]
Sent: 12 January 2017 16:29

Quoted 8 lines
Quoted 8 lines
Quoted 1 line · On 12.01.17 at 17:10, <[email protected]> wrote:

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

The kernel already has to parse this structure anyway, and will know

the

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Quoted 7 lines
Quoted 1 line

Do we need to care about a 32-bit kernel for a tools-only hypercall? I

thought

Quoted 1 line

a toolstack already had to be (at least) 64-bit to match Xen.

Why would that be? Didn't XenServer for a long time run with a 32-bit Dom0 on top of a 64-bit Xen? See also domctl/sysctl.

Ok, I thought the landscape had changed since then. If that's the case then a 64 bit handle seems sensible and I guess we have to deal with 128 bit when that happens.

Paul

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 3/8
#25 lore raw

Re: [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram

In reply to Paul Durrant
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

v3:
- Check d->max_vcpus rather than d->vcpu, as requested by Jan.
- The handle type changes (from uint8 to void) are still necessary, hence omitting Jan's R-b until this is confirmed to be acceptable.

Hmm, talk really was of the change from HANDLE_64() to HANDLE_PARAM(), which I see you also left as they were. In the end, if this builds I'm fine either way, and since you say you need to do the uint8 -> void change anyway, doing the 64 -> PARAM change at once is perhaps even a change to the better. So hypervisor parts

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#26 lore raw

Re: [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram

Quoted 16 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 13 January 2017 11:45
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Ian Jackson <[email protected]>; xen- [email protected]; Daniel De Graaf <[email protected]>; Tim (Xen.org) <[email protected]>
Subject: Re: [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

v3:
- Check d->max_vcpus rather than d->vcpu, as requested by Jan.
- The handle type changes (from uint8 to void) are still necessary, hence omitting Jan's R-b until this is confirmed to be acceptable.

Quoted 7 lines

Hmm, talk really was of the change from HANDLE_64() to HANDLE_PARAM(), which I see you also left as they were. In the end, if this builds I'm fine either way, and since you say you need to do the uint8 -> void change anyway, doing the 64 -> PARAM change at once is perhaps even a change to the better. So hypervisor parts

Ok. Thanks,

Paul

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 5/8
#31 lore raw

Re: [PATCH v3 5/8] dm_op: convert HVMOP_modified_memory

In reply to Paul Durrant
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

v3:
- Addressed more comments from Jan.

I'd have hoped you would extend these earlier comments to other applicable places, i.e. for this patch ...

Quoted 6 lines
xen/arch/x86/hvm/dm.c +6 -0
+static int modified_memory(struct domain *d, xen_pfn_t *first_pfn,
+                           unsigned int *nr)
+{
+    xen_pfn_t last_pfn = *first_pfn + *nr - 1;
+    unsigned int iter;
+    int rc;

xen/arch/x86/hvm/dm.c static int set_isa_irq_level(struct domain *d, uint8_t isa_irq, · line 161

Quoted 10 lines
xen/arch/x86/hvm/dm.c +10 -0
+
+    if ( (*first_pfn > last_pfn) ||
+         (last_pfn > domain_get_maximum_gpfn(d)) )
+        return -EINVAL;
+
+    if ( !paging_mode_log_dirty(d) )
+        return 0;
+
+    iter = 0;
+    rc = 0;

... here (these would again better be initializers of the respective variables). But anyway, hypervisor parts

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#32 lore raw

Re: [PATCH v3 5/8] dm_op: convert HVMOP_modified_memory

Quoted 35 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 13 January 2017 11:51
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; Ian Jackson <[email protected]>; [email protected]; Daniel De Graaf <[email protected]>
Subject: Re: [PATCH v3 5/8] dm_op: convert HVMOP_modified_memory

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

v3:
- Addressed more comments from Jan.

I'd have hoped you would extend these earlier comments to other applicable places, i.e. for this patch ...

Quoted 6 lines
xen/arch/x86/hvm/dm.c +6 -0
+static int modified_memory(struct domain *d, xen_pfn_t *first_pfn,
+                           unsigned int *nr)
+{
+    xen_pfn_t last_pfn = *first_pfn + *nr - 1;
+    unsigned int iter;
+    int rc;

xen/arch/x86/hvm/dm.c static int set_isa_irq_level(struct domain *d, uint8_t isa_irq, · line 161

Quoted 10 lines
xen/arch/x86/hvm/dm.c +10 -0
+
+    if ( (*first_pfn > last_pfn) ||
+         (last_pfn > domain_get_maximum_gpfn(d)) )
+        return -EINVAL;
+
+    if ( !paging_mode_log_dirty(d) )
+        return 0;
+
+    iter = 0;
+    rc = 0;

... here (these would again better be initializers of the respective variables). But anyway, hypervisor parts

Quoted 2 lines

Ok, I can make the change in v4... just waiting for Andrew's latest opinion on patch #1.

Paul

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v3 6/8
#34 lore raw

Re: [PATCH v3 6/8] dm_op: convert HVMOP_set_mem_type

In reply to Paul Durrant
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 12.01.17 at 15:58, <[email protected]> wrote:

This patch removes the need for handling HVMOP restarts, so that infrastructure is removed.

NOTE: This patch also modifies the type of the 'nr' argument of
xc_hvm_set_mem_type() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

Hypervisor parts

with the same remark as on the previous patch.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#9 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 22 lines · Jan Beulich
Quoted 9 lines
Quoted 9 lines

docs/designs/dmop.markdown line 42

Quoted 6 lines · On 12.01.17 at 17:10, <[email protected]> wrote:
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

Yes, padding needs to be added.

Quoted 11 lines
Quoted 11 lines

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Yes it will.

Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Quoted 6 lines
Quoted 6 lines

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there is no explicit support for DMOPs in privcmd. When explicit support is added then this can change and we can use a void ptr and size_t as you say.

Quoted 7 lines
Quoted 4 lines

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does indeed limit us and so using XEN_GUEST_HANDLE would indeed seem more sensible (and we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Just like with other tools only interfaces, I think this should remain a 64-bit handle, to avoid (as you say, but wrongly in conjunction with a "normal" handle) the need for a compat wrapper.

I disagree. It is a layering violation. (and apologies if this appears to rant, but it seems that all major development I do for Xen is removing layering violations which could have been more easily avoided if v1 had been designed more sensibly.)

The 64bit guest handle infrastructure has always been a kludge.

Xen and the kernel speak an ABI, which is based on the width of the kernel. These take a GUEST_HANDLE() as a wrapper around void *, to indicate the size of a pointer used by the kernel. Under this ABI, Xen is at least the width of the kernel, and must translate a smaller

The kernel and its userspace speak an ABI which is based on the width of userspace, and the kernel (for things other than privcmd) translates via its compat layer.

In hindsight it is obvious to see why this problem started; at the time it was introduced, everything was 32bit, and a short-cut between userspace and Xen was taken. In fact, its such a short-cut that any process with a privcmd handle can issue any hypercall, including the fun ones such as set_trap_table, update_va_mapping, or iret.

When 64bit support was added to Xen, this short-cut broke the userspace/kernel ABI expectation, because privcmd didn't actually translate its ABI (unlike everything else in the kernel). This results in a binary compatibility problem if the toolstack is compiled at a width different to the kernel it is running under.

The GUEST_HANDLE_64() is a hack around the problem to try and make the ABI from different width userspace appear the same, without fixing the underlying problem of privcmd.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#10 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 13.01.17 at 13:03, <[email protected]> wrote:
Quoted 22 lines · Jan Beulich
Quoted 9 lines
Quoted 9 lines

docs/designs/dmop.markdown line 42

Quoted 6 lines · On 12.01.17 at 17:10, <[email protected]> wrote:
docs/designs/dmop.markdown new file +5 -0
+
+struct xen_dm_op_buf {
+    XEN_GUEST_HANDLE_64(void) h;
+    uint32_t size;
+};

Sorry to quibble, but there is a problem here which has only just occurred to me. This ABI isn't futureproof, and has padding at the end which affects how the array is layed out.

Yes, padding needs to be added.

Quoted 11 lines
Quoted 11 lines

The userspace side should be

struct xen_dm_op_buf {
    void *h;
    size_t size;
}

which will work sensibly for 32bit and 64bit userspace, and futureproof (for when 128bit turns up). Its size is also a power of two which avoids alignment issues in the array.

Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Quoted 5 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there is no explicit support for DMOPs in privcmd. When explicit support is added then this can change and we can use a void ptr and size_t as you say.

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does indeed limit us and so using XEN_GUEST_HANDLE would indeed seem more sensible (and we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Quoted 8 lines
Quoted 3 lines

Just like with other tools only interfaces, I think this should remain a 64-bit handle, to avoid (as you say, but wrongly in conjunction with a "normal" handle) the need for a compat wrapper.

I disagree. It is a layering violation. (and apologies if this appears to rant, but it seems that all major development I do for Xen is removing layering violations which could have been more easily avoided if v1 had been designed more sensibly.)

Whether this is a layering violation really depends on the position you take: If tools only interfaces are meant to be a direct channel from user space to hypervisor, then the kernel has no business interposing a translation layer, the more that such a layer would need updating every time a new operation got added to that tools only interface. Even worse, the "tools only" property would be partially lost the moment the kernel had a valid reason to look at those structures.

Quoted 1 line

The 64bit guest handle infrastructure has always been a kludge.

It has been the better alternative to a compat translation layer first of all.

Quoted 8 lines

Xen and the kernel speak an ABI, which is based on the width of the kernel. These take a GUEST_HANDLE() as a wrapper around void *, to indicate the size of a pointer used by the kernel. Under this ABI, Xen is at least the width of the kernel, and must translate a smaller

The kernel and its userspace speak an ABI which is based on the width of userspace, and the kernel (for things other than privcmd) translates via its compat layer.

Which is a fuzzy thing by itself already, when you take into consideration processes running both 64- and 32-bit code.

Quoted 11 lines

In hindsight it is obvious to see why this problem started; at the time it was introduced, everything was 32bit, and a short-cut between userspace and Xen was taken. In fact, its such a short-cut that any process with a privcmd handle can issue any hypercall, including the fun ones such as set_trap_table, update_va_mapping, or iret.

When 64bit support was added to Xen, this short-cut broke the userspace/kernel ABI expectation, because privcmd didn't actually translate its ABI (unlike everything else in the kernel). This results in a binary compatibility problem if the toolstack is compiled at a width different to the kernel it is running under.

Hmm, I don't think I agree here. For one, the privcmd compat was, afaict, lost with the transition to pv-ops. But that layer (I dare to say "of course") was concerned only with translating its own interface structures (i.e. the ioctl ones). The interface structures of the actual hypercalls were opaque as you say, and (see my remark earlier on) validly so imo.

Furthermore I'm not sure we want to make dmop inconsistent with domctl/sysctl. I'd be curious to know how you would envision a clean interface to look like, without requiring a translation layer anywhere.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v3 3/8
#27 lore raw

Re: [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram

In reply to Paul Durrant
Quoted 9 lines · Paul Durrant

The handle type passed to the underlying shadow and hap functions is changed for compatibility with the new hypercall buffer.

NOTE: This patch also modifies the type of the 'nr' parameter of
xc_hvm_track_dirty_vram() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Acked-by on v3 3/8
#28 lore raw

Re: [PATCH v3 3/8] dm_op: convert HVMOP_track_dirty_vram

In reply to Paul Durrant
Quoted 9 lines · Paul Durrant

The handle type passed to the underlying shadow and hap functions is changed for compatibility with the new hypercall buffer.

NOTE: This patch also modifies the type of the 'nr' parameter of
xc_hvm_track_dirty_vram() from uint64_t to uint32_t. In practice the value passed was always truncated to 32 bits.

mm-bits:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#11 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 8 lines · Jan Beulich
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Quoted 17 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

As discussed...

xen_dm_op_buf is currently used directly in the tools code because there is no explicit support for DMOPs in privcmd. When explicit support is added then this can change and we can use a void ptr and size_t as you say.

For the privcmd -> Xen interface that using XEN_GUEST_HANDLE_64 does indeed limit us and so using XEN_GUEST_HANDLE would indeed seem more sensible (and we won't need a 32-bit compat wrapper for DMOP because it's a tools-only hypercall).

Quoted 7 lines
Quoted 3 lines

Just like with other tools only interfaces, I think this should remain a 64-bit handle, to avoid (as you say, but wrongly in conjunction with a "normal" handle) the need for a compat wrapper.

I disagree. It is a layering violation. (and apologies if this appears to rant, but it seems that all major development I do for Xen is removing layering violations which could have been more easily avoided if v1 had been designed more sensibly.)

Quoted 6 lines

Whether this is a layering violation really depends on the position you take: If tools only interfaces are meant to be a direct channel from user space to hypervisor, then the kernel has no business interposing a translation layer, the more that such a layer would need updating every time a new operation got added to that tools only interface.

"tools-only" is an illusion. Hypercalls are a kernel-only operation, and are interpreted with an ABI determined by the width of the kernel.

It is for this precise reason that a 32bit toolstack under a 64bit kernel doesn't function correctly.

Despite privcmd's implementation being a straight "throw it over the wall to Xen", the hypercall ABI is strictly between Xen and the kernel, not Xen and the toolstack.

Quoted 3 lines

Even worse, the "tools only" property would
be partially lost the moment the kernel had a valid reason to look at those structures.

This is an ABI which, by its very design, *must* be inspected and audited by the kernel. dmop cannot be a "tools interface" like domctl/sysctl/etc.

The userspace/kernel interaction is going to be in terms of void * and size_t's, so the kernel can sensibly audit the memory ranges.

Quoted 3 lines
Quoted 1 line

The 64bit guest handle infrastructure has always been a kludge.

It has been the better alternative to a compat translation layer first of all.

I disagree on calling it better.

In a hypothetical world x86_128 world, how would the current scheme function? How would you distinguish a piece of 128bit userspace from a 64 or 32bit userspace under a 128bit kernel?

Quoted 11 lines
Quoted 9 lines

Xen and the kernel speak an ABI, which is based on the width of the kernel. These take a GUEST_HANDLE() as a wrapper around void *, to indicate the size of a pointer used by the kernel. Under this ABI, Xen is at least the width of the kernel, and must translate a smaller

The kernel and its userspace speak an ABI which is based on the width of userspace, and the kernel (for things other than privcmd) translates via its compat layer.

Which is a fuzzy thing by itself already, when you take into consideration processes running both 64- and 32-bit code.

It is only fuzzy because we don't have a rational layer separation to start with.

If you really don't want the kernel inspecting the internal content of the call (which, is a property I do agree with), then the correct ABI would have been to wrap userspace hypercalls (multicall style) indicating the ABI with which userspace was compiled. This would at least allow Xen to interpret the contents in an unambiguous manner.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#12 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Quoted 8 lines
Quoted 2 lines

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Or maybe I'm simply not getting what you mean to put in place here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#13 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 40 lines

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: 16 January 2017 16:17
To: Andrew Cooper <[email protected]>
Cc: Ian Jackson <[email protected]>; Jennifer Herbert <[email protected]>; Paul Durrant <[email protected]>; Wei Liu <[email protected]>; [email protected]; Daniel DeGraaf <[email protected]>
Subject: Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

The kernel already has to parse this structure anyway, and will know

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding

on

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to Xen, which covers the 32bit userspace under a 64bit kernel

problem,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

in a way which won't break the hypercall ABI when 128bit comes

along.

Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

Quoted 8 lines
Quoted 2 lines

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Or maybe I'm simply not getting what you mean to put in place here.

<sigh> If we don't want to bake 64-bit pointers into the ABI then I guess a compat layer is the only way. Guess I'll go and stare at macros until my brain explodes...

Paul

Quoted 1 line

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#14 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 18:07, <[email protected]> wrote:

<sigh> If we don't want to bake 64-bit pointers into the ABI then I guess a compat layer is the only way. Guess I'll go and stare at macros until my brain explodes...

Well, before you do I'd really hope for Andrew to provide us (or at least me, if everyone else is seeing the obvious) with a concrete example of how he wants the interface to be designed cleanly and 128-bit-ready (yet without the use of pointer types, which we've always avoided to use in the public interface).

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#15 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

This is because our compat handling is particularly ugly (partially because our ABI has varying-size fields at random places in the middle of structures). Not because a compat layer is the wrong thing to do.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

Quoted 7 lines
Quoted 5 lines

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

Quoted 1 line

Or maybe I'm simply not getting what you mean to put in place here.

The interface should be in terms of void * (and where appropriate, size_t), from the guests point of view, and is what a plain GUEST_HANDLE() gives you.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#16 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 29 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

This is because our compat handling is particularly ugly (partially because our ABI has varying-size fields at random places in the middle of structures). Not because a compat layer is the wrong thing to do.

Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

Are we running so low on hypercall numbers that "burning" them when the dominant bit width doubles in size is going to be an issue?

Actually I don't think that it will be possible to run out of hypercalls by duplicating them all every time the word size doubles -- as when that happens, the maximum hypercall number will exponentially increase as well.

-George

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#19 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Andrew Cooper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 17.01.17 at 12:22, <[email protected]> wrote:
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

But that won't cover a 32-bit kernel.

Yes it will.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

This is because our compat handling is particularly ugly (partially because our ABI has varying-size fields at random places in the middle of structures). Not because a compat layer is the wrong thing to do.

Well, I disagree. The best possible solution is no translation layers, as they're only a source of possible extra mistakes.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

With wider machine word width the number space of hypercalls widens too, so I would not be worried at all using new hypercall numbers, or even wholesale new hypercall number ranges.

Quoted 5 lines
Quoted 1 line

Or maybe I'm simply not getting what you mean to put in place here.

The interface should be in terms of void * (and where appropriate, size_t), from the guests point of view, and is what a plain GUEST_HANDLE() gives you.

As said - that'll further break 32-bit tool stacks on 64-bit kernels. As much as you say we should try to avoid making it harder to accommodate a hypothetical 128-bit architecture, I think I can validly demand that the 32-bit tool stack on 64-bit kernel case should not be broken further than it already is (as you say; certain things surely work quite okay). Instead such known brokenness should be fixed, the more that for several years we've been "successfully" ignoring the x32 ABI with our libraries and the public interface as a whole.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#17 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to George Dunlap
Quoted 31 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

This is because our compat handling is particularly ugly (partially because our ABI has varying-size fields at random places in the middle of structures). Not because a compat layer is the wrong thing to do.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

Are we running so low on hypercall numbers that "burning" them when the dominant bit width doubles in size is going to be an issue?

There is a fixed ABI of 63 hypercalls.

This can compatibly be extend up to 255 (the amount of extra room in the hypercall page), but no further, as c/s 2a33551d in 2008 added:

/*
* Leaf 3 (0x40000002)
* EAX: Number of hypercall transfer pages. This register is always
guaranteed
* to specify one hypercall page.

to our public ABI.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#20 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Jan Beulich
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

With wider machine word width the number space of hypercalls widens too, so I would not be worried at all using new hypercall numbers, or even wholesale new hypercall number ranges.

I will leave this to the other fork of the thread, but our hypercall space does extend. It is currently fixed at an absolute maximum of 4k/32.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

Or maybe I'm simply not getting what you mean to put in place here.

The interface should be in terms of void * (and where appropriate, size_t), from the guests point of view, and is what a plain GUEST_HANDLE() gives you.

As said - that'll further break 32-bit tool stacks on 64-bit kernels.

dmop is not a tool api. It can only be issued by a kernel, after the kernel has audited the internals.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#21 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 17.01.17 at 16:13, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

Quoted 7 lines
Quoted 5 lines

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

Quoted 6 lines
Quoted 3 lines

With wider machine word width the number space of hypercalls widens too, so I would not be worried at all using new hypercall numbers, or even wholesale new hypercall number ranges.

I will leave this to the other fork of the thread, but our hypercall space does extend. It is currently fixed at an absolute maximum of 4k/32.

If we were to introduce a new range, we'd likely still fit the stubs all in one page, just that the numbers the stubs put into whatever the equivalent of %rax would be would then have some higher bit set.

Quoted 8 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

Or maybe I'm simply not getting what you mean to put in place here.

The interface should be in terms of void * (and where appropriate, size_t), from the guests point of view, and is what a plain GUEST_HANDLE() gives you.

As said - that'll further break 32-bit tool stacks on 64-bit kernels.

dmop is not a tool api. It can only be issued by a kernel, after the kernel has audited the internals.

To me qemu, for which the interface is mainly being made (hence the naming of it), is very much a tool. And fundamentally I don't see anything wrong with using a 32-bit qemu binary.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#18 lore raw

Re: [PATCH v3 1/8] public / x86: Introduce __HYPERCALL_dm_op...

In reply to Andrew Cooper
Quoted 46 lines
Quoted 1 line
Quoted 1 line · On 17.01.17 at 16:06, <[email protected]> wrote:
Quoted 31 lines · George Dunlap
Quoted 29 lines · Andrew Cooper
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 16.01.17 at 17:05, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The kernel already has to parse this structure anyway, and will know the bitness of its userspace process. We could easily (at this point) require the kernel to turn it into the kernels bitness for forwarding on to Xen, which covers the 32bit userspace under a 64bit kernel problem, in a way which won't break the hypercall ABI when 128bit comes along.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line

But that won't cover a 32-bit kernel.

Yes it will.

How that, without a compat translation layer in Xen?

Why shouldn't there be a compat layer?

Because the compat layer we have is kind of ugly to maintain. Hence I would expect additions to it to not make the situation any better.

This is because our compat handling is particularly ugly (partially because our ABI has varying-size fields at random places in the middle of structures). Not because a compat layer is the wrong thing to do.

Quoted 11 lines
Quoted 11 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

And I'm not sure we really need to bother considering hypothetical 128-bit architectures at this point in time.

Because considering this case will avoid us painting ourselves into a corner.

Why would we consider this case here, when all other part of the public interface don't do so?

This is asking why we should continue to shoot ourselves in the foot, ABI wise, rather than trying to do something better.

And the answer is that I'd prefer that we started fixing the problem, rather than making it worse.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Okay, so 128 bit handles then. But wait, we should be prepared for 256-bit environments to, so 256-bit handles then. But wait, ...

Precisely. A fixed bit width doesn't work, and cannot work going forwards. Using a fixed bitsize will force is to burn a hypercall number every time we want to implement this ABI at a larger bit size.

Are we running so low on hypercall numbers that "burning" them when the dominant bit width doubles in size is going to be an issue?

There is a fixed ABI of 63 hypercalls.

This can compatibly be extend up to 255 (the amount of extra room in the hypercall page), but no further, as c/s 2a33551d in 2008 added:

Quoted 7 lines

/*
* Leaf 3 (0x40000002)
* EAX: Number of hypercall transfer pages. This register is always
guaranteed
* to specify one hypercall page.

to our public ABI.

As said in the other reply - there's nothing keeping us from making the hypervisor fill stub N such that it passes N+0x1000 as hypercall number.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel