Skip to contentSkip to conversation

vm_event: Add a new opcode to get VM_EVENT_INTERFACE_VERSION

PATCH Superseded Petre Pircalabu 2 participants 4 messages Feb 13, 2019 – Feb 14, 2019 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 vm_event: Add a new opcode to get VM_EVENT_INTERFACE_VERSION

Currently, the VM_EVENT_INTERFACE_VERSION is determined at runtime, by inspecting the corresponding field in a vm_event_request. This helper opcode will query the hypervisor supported version before the vm_event related structures and layout are set-up.

---
 tools/libxc/include/xenctrl.h |  5 +++++
 tools/libxc/xc_vm_event.c     | 18 +++++++++++++++++-
 xen/common/domctl.c           |  1 +
 xen/common/vm_event.c         | 15 ++++++++++++++-
 xen/include/public/domctl.h   | 17 +++++++++++++----
 5 files changed, 50 insertions(+), 6 deletions(-)
tools/libxc/include/xenctrl.h +5 -0
index 31cdda7..b801b85 100644
@@ -2003,6 +2003,11 @@ int xc_set_mem_access_multi(xc_interface *xch, uint32_t domain_id,
 int xc_get_mem_access(xc_interface *xch, uint32_t domain_id,
                       uint64_t pfn, xenmem_access_t *access);
 
+/*
+ * Returns the VM_EVENT_INTERFACE version.
+ */
+int xc_vm_event_get_interface_version(xc_interface *xch);
+
 /***
  * Monitor control operations.
  *
tools/libxc/xc_vm_event.c +17 -1
index 8674607..10ebc3c 100644
@@ -35,7 +35,7 @@ int xc_vm_event_control(xc_interface *xch, uint32_t domain_id, unsigned int op,
 
     rc = do_domctl(xch, &domctl);
     if ( !rc && port )
-        *port = domctl.u.vm_event_op.port;
+        *port = domctl.u.vm_event_op.u.enable.port;
     return rc;
 }
 
@@ -156,6 +156,22 @@ void *xc_vm_event_enable(xc_interface *xch, uint32_t domain_id, int param,
     return ring_page;
 }
 
+int xc_vm_event_get_interface_version(xc_interface *xch)
+{
+    DECLARE_DOMCTL;
+    int rc;
+
+    domctl.cmd = XEN_DOMCTL_vm_event_op;
+    domctl.domain = DOMID_INVALID;
+    domctl.u.vm_event_op.op = XEN_VM_EVENT_GET_INTERFACE_VERSION;
+    domctl.u.vm_event_op.mode = XEN_DOMCTL_VM_EVENT_OP_MONITOR;
+
+    rc = do_domctl(xch, &domctl);
+    if ( !rc )
+        rc = domctl.u.vm_event_op.u.get_interface_version.value;
+    return rc;
+}
+
 /*
  * Local variables:
  * mode: C
xen/common/domctl.c +1 -0
index d08b627..bade9a6 100644
@@ -392,6 +392,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
     switch ( op->cmd )
     {
     case XEN_DOMCTL_test_assign_device:
+    case XEN_DOMCTL_vm_event_op:
         if ( op->domain == DOMID_INVALID )
         {
     case XEN_DOMCTL_createdomain:
xen/common/vm_event.c +14 -1
index 26cfa2c..cbdade3 100644
@@ -88,7 +88,7 @@ static int vm_event_enable(
     if ( rc < 0 )
         goto err;
 
-    (*ved)->xen_port = vec->port = rc;
+    (*ved)->xen_port = vec->u.enable.port = rc;
 
     /* Prepare ring buffer */
     FRONT_RING_INIT(&(*ved)->front_ring,
@@ -592,6 +592,19 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,
 {
     int rc;
 
+    if ( vec->op == XEN_VM_EVENT_GET_INTERFACE_VERSION )
+    {
+        vec->u.get_interface_version.value = VM_EVENT_INTERFACE_VERSION;
+        return 0;
+    }
+
+    if ( unlikely(d == NULL) )
+    {
+        gdprintk(XENLOG_INFO,
+                 "Tried to do a memory event op on an invalid domain.\n");
+        return -EINVAL;
+    }
+
     rc = xsm_vm_event_control(XSM_PRIV, d, vec->mode, vec->op);
     if ( rc )
         return rc;
xen/include/public/domctl.h +13 -4
index 7e1cf21..f222d1e 100644
@@ -778,9 +778,10 @@ struct xen_domctl_gdbsx_domstatus {
  * to the hypervisor to pull responses (resume) from the given
  * ring.
  */
-#define XEN_VM_EVENT_ENABLE               0
-#define XEN_VM_EVENT_DISABLE              1
-#define XEN_VM_EVENT_RESUME               2
+#define XEN_VM_EVENT_ENABLE                 0
+#define XEN_VM_EVENT_DISABLE                1
+#define XEN_VM_EVENT_RESUME                 2
+#define XEN_VM_EVENT_GET_INTERFACE_VERSION  3
 
 /*
  * Domain memory paging
@@ -843,7 +844,15 @@ struct xen_domctl_vm_event_op {
     uint32_t       op;           /* XEN_VM_EVENT_* */
     uint32_t       mode;         /* XEN_DOMCTL_VM_EVENT_OP_* */
 
-    uint32_t port;              /* OUT: event channel for ring */
+    union {
+        struct {
+            uint32_t port;       /* OUT: event channel for ring */
+        } enable;
+
+        struct {
+            uint32_t value;
+        } get_interface_version;
+    } u;
 };
 
 /*
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 13.02.19 at 14:25, <[email protected]> wrote:
xen/common/vm_event.c +2 -0
@@ -592,6 +592,19 @@ int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec,
 {
     int rc;
 
+    if ( vec->op == XEN_VM_EVENT_GET_INTERFACE_VERSION )
+    {

xen/common/vm_event.c int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec, · line 606

Quoted 10 lines
xen/common/vm_event.c +10 -0
+        vec->u.get_interface_version.value = VM_EVENT_INTERFACE_VERSION;
+        return 0;
+    }
+
+    if ( unlikely(d == NULL) )
+    {
+        gdprintk(XENLOG_INFO,
+                 "Tried to do a memory event op on an invalid domain.\n");
+        return -EINVAL;
+    }

To be compatible with previous behavior you want to return -ESRCH here. I'm also unconvinced of the need to add a log message here - there was none before in that case. But I'm not a maintainer of this code.

xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 784

Quoted 13 lines
xen/include/public/domctl.h +4 -3
@@ -778,9 +778,10 @@ struct xen_domctl_gdbsx_domstatus {
  * to the hypervisor to pull responses (resume) from the given
  * ring.
  */
-#define XEN_VM_EVENT_ENABLE               0
-#define XEN_VM_EVENT_DISABLE              1
-#define XEN_VM_EVENT_RESUME               2
+#define XEN_VM_EVENT_ENABLE                 0
+#define XEN_VM_EVENT_DISABLE                1
+#define XEN_VM_EVENT_RESUME                 2
+#define XEN_VM_EVENT_GET_INTERFACE_VERSION  3

Perhaps just XEN_VM_EVENT_GET_VERSION?

xen/include/public/domctl.h struct xen_domctl_vm_event_op { · line 854

Quoted 13 lines
xen/include/public/domctl.h +8 -1
@@ -843,7 +844,15 @@ struct xen_domctl_vm_event_op {
     uint32_t       op;           /* XEN_VM_EVENT_* */
     uint32_t       mode;         /* XEN_DOMCTL_VM_EVENT_OP_* */
 
-    uint32_t port;              /* OUT: event channel for ring */
+    union {
+        struct {
+            uint32_t port;       /* OUT: event channel for ring */
+        } enable;
+
+        struct {
+            uint32_t value;
+        } get_interface_version;

Why the wrapper structs? Having just a "port" and "version" field inside the union would be good enough, wouldn't it? But even if you want to stick to that, the new structure's name could be simply "version", thus also allowing re-use for a hypothetical "set-version" operation (in case multiple versions would want/need to be supported going forward).

Jan

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

#3 lore raw
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 13.02.19 at 14:25, <[email protected]> wrote:
xen/common/vm_event.c +10 -0
@@ -592,6 +592,19 @@ int vm_event_domctl(struct domain *d, struct
 xen_domctl_vm_event_op *vec,
 {
     int rc;
 
+    if ( vec->op == XEN_VM_EVENT_GET_INTERFACE_VERSION )
+    {
+        vec->u.get_interface_version.value =
 VM_EVENT_INTERFACE_VERSION;
+        return 0;
+    }
+
+    if ( unlikely(d == NULL) )
+    {
+        gdprintk(XENLOG_INFO,
+                 "Tried to do a memory event op on an invalid
Quoted 8 lines

xen/common/vm_event.c int vm_event_domctl(struct domain *d, struct xen_domctl_vm_event_op *vec, · line 606

Quoted 3 lines
xen/common/vm_event.c +2 -0
 domain.\n");
+        return -EINVAL;
+    }

To be compatible with previous behavior you want to return -ESRCH here. I'm also unconvinced of the need to add a log message here - there was none before in that case. But I'm not a maintainer of this code.

I will update the patch and post a new version.

Quoted 16 lines
Quoted 4 lines

xen/include/public/domctl.h struct xen_domctl_gdbsx_domstatus { · line 784

Quoted 10 lines
xen/include/public/domctl.h +4 -3
@@ -778,9 +778,10 @@ struct xen_domctl_gdbsx_domstatus {
  * to the hypervisor to pull responses (resume) from the given
  * ring.
  */
-#define XEN_VM_EVENT_ENABLE               0
-#define XEN_VM_EVENT_DISABLE              1
-#define XEN_VM_EVENT_RESUME               2
+#define XEN_VM_EVENT_ENABLE                 0
+#define XEN_VM_EVENT_DISABLE                1
+#define XEN_VM_EVENT_RESUME                 2
+#define XEN_VM_EVENT_GET_INTERFACE_VERSION  3

Perhaps just XEN_VM_EVENT_GET_VERSION?

I agree, it's simpler. I have used "INTERFACE" only to match the VM_EVENT_INTERFACE_VERSION macro.

Quoted 5 lines
Quoted 5 lines
xen/include/public/domctl.h +0 -0
@@ -843,7 +844,15 @@ struct xen_domctl_vm_event_op {
     uint32_t       op;           /* XEN_VM_EVENT_* */
     uint32_t       mode;         /* XEN_DOMCTL_VM_EVENT_OP_* */
 
Quoted 16 lines

xen/include/public/domctl.h struct xen_domctl_vm_event_op { · line 854

Quoted 9 lines
xen/include/public/domctl.h +8 -1
-    uint32_t port;              /* OUT: event channel for ring */
+    union {
+        struct {
+            uint32_t port;       /* OUT: event channel for ring */
+        } enable;
+
+        struct {
+            uint32_t value;
+        } get_interface_version;

Why the wrapper structs? Having just a "port" and "version" field inside the union would be good enough, wouldn't it? But even if you want to stick to that, the new structure's name could be simply "version", thus also allowing re-use for a hypothetical "set-version" operation (in case multiple versions would want/need to be supported going forward).

I chose to wrap the "port" field in a structure because it's valid only for the XEN_VM_EVENT_ENABLE operation (I have used the wrapping structs in order to match the operation name).
The "version" domctl should only return the vm_event version (VM_EVENT_INTERFACE_VERSION is a macro and is defined at compile time). At least in this case I think the backward compatibility issues should be handled only at the client level (easier maintainance and deployment).

Many thanks for your comments,
Petre

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

#4 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 13.02.19 at 17:36, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 13.02.19 at 14:25, <[email protected]> wrote:
xen/include/public/domctl.h +0 -0
@@ -843,7 +844,15 @@ struct xen_domctl_vm_event_op {
     uint32_t       op;           /* XEN_VM_EVENT_* */
     uint32_t       mode;         /* XEN_DOMCTL_VM_EVENT_OP_* */
 
Quoted 16 lines

xen/include/public/domctl.h struct xen_domctl_vm_event_op { · line 854

Quoted 9 lines
xen/include/public/domctl.h +8 -1
-    uint32_t port;              /* OUT: event channel for ring */
+    union {
+        struct {
+            uint32_t port;       /* OUT: event channel for ring */
+        } enable;
+
+        struct {
+            uint32_t value;
+        } get_interface_version;

Why the wrapper structs? Having just a "port" and "version" field inside the union would be good enough, wouldn't it? But even if you want to stick to that, the new structure's name could be simply "version", thus also allowing re-use for a hypothetical "set-version" operation (in case multiple versions would want/need to be supported going forward).

Quoted 3 lines

I chose to wrap the "port" field in a structure because it's valid only for the XEN_VM_EVENT_ENABLE operation (I have used the wrapping structs in order to match the operation name).

I guessed as much. But there's nothing preventing the field for becoming applicable to some future sub-op.

Jan

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