Skip to contentSkip to conversation

libxl: write IO ABI for disk frontends

PATCH Applied Wei Liu 4 participants 18 messages Apr 25, 2013 – May 17, 2013

lore
Share & tools
lore

Wei Liu

author
#0 lore raw

PATCH v3 1/1 libxl: write IO ABI for disk frontends

This is a patch to forward-port a Xend behaviour. Xend writes IO ABI used for all frontends. Blkfront before 2.6.26 relies on this behaviour otherwise guest cannot boot when running in 32-on-64 mode. Blkfront after 2.6.26 writes that node itself, in which case it's just an overwrite to an existing node which should be OK.

In fact Xend writes the ABI for all frontends including console and vif. But nowadays only old disk frontends rely on that behaviour so that we only write the ABI for disk frontends in libxl, minimizing the impact.

Cc Ian Campbell <[email protected]>
Cc Roger Pau Monne <[email protected]>
Cc Valtteri Kiviniemi <[email protected]>
---
 tools/libxc/xc_dom_arm.c          |    7 +++++++
 tools/libxc/xc_dom_x86.c          |   34 ++++++++++++++++++++++++++++++++++
 tools/libxc/xenctrl.h             |   10 ++++++++++
 tools/libxl/libxl.c               |   28 ++++++++++++++++++++++++++++
 xen/include/public/io/protocols.h |    1 +
 5 files changed, 80 insertions(+)
tools/libxc/xc_dom_arm.c +7 -0
index 041832e..aaf35ca 100644
@@ -29,6 +29,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
 /* ------------------------------------------------------------------------ */
 /*
  * arm guests are hybrid and start off with paging disabled, therefore no
tools/libxc/xc_dom_x86.c +34 -0
index eb9ac07..84a8de6 100644
@@ -47,6 +47,40 @@
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    int ret;
+    uint32_t guest_width;
+    const char *protocol;
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd = XEN_DOMCTL_get_address_size;
+
+    ret = do_domctl(xch, &domctl);
+
+    if ( ret )
+        return NULL;
+
+    guest_width = domctl.u.address_size.size;
+
+    switch (guest_width) {
+    case 32: /* 32 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_32;
+        break;
+    case 64: /* 64 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_64;
+        break;
+    default:
+        protocol = NULL;
+    }
+
+    return protocol;
+}
+
 static unsigned long
 nr_page_tables(struct xc_dom_image *dom,
                xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
tools/libxc/xenctrl.h +10 -0
index 50853af..2f32151 100644
@@ -637,6 +637,16 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t size);
 
 /**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
  *
tools/libxl/libxl.c +28 -0
index 572c2c6..550c63d 100644
@@ -18,6 +18,8 @@
 
 #include "libxl_internal.h"
 
+#include <xen/io/protocols.h>
+
 #define PAGE_TO_MEMKB(pages) ((pages) * 4)
 #define BACKEND_STRING_SIZE 5
 
@@ -2037,6 +2039,14 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
     int rc;
     libxl_ctx *ctx = gc->owner;
     xs_transaction_t t = XBT_NULL;
+    const char *protocol = NULL;
+    char p[XEN_IO_PROTO_ABI_MAX_LEN+1];
+
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
 
     for (;;) {
         rc = libxl__xs_transaction_start(gc, &t);
@@ -2156,6 +2166,24 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            protocol = xc_domain_get_native_protocol(ctx->xch, domid);
+            if (protocol) {
+                strncpy(p, protocol, strlen(protocol));
+                p[strlen(protocol)] = 0;
+                flexarray_append(front, "protocol");
+                flexarray_append(front, p);
+            }
+        }
+
         libxl__device_generic_add(gc, t, device,
                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
xen/include/public/io/protocols.h +1 -0
index 80b196b..c2b949e 100644
@@ -26,6 +26,7 @@
 #define XEN_IO_PROTO_ABI_X86_32     "x86_32-abi"
 #define XEN_IO_PROTO_ABI_X86_64     "x86_64-abi"
 #define XEN_IO_PROTO_ABI_ARM        "arm-abi"
+#define XEN_IO_PROTO_ABI_MAX_LEN    10 /* maximum length of above strings */
 
 #if defined(__i386__)
 # define XEN_IO_PROTO_ABI_NATIVE XEN_IO_PROTO_ABI_X86_32
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 4 lines · Wei Liu
tools/libxl/libxl.c +0 -0
@@ -2156,6 +2166,24 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 

tools/libxl/libxl.c static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2178

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            protocol = xc_domain_get_native_protocol(ctx->xch, domid);

You can declare protocol here instead of globally in the function. The = NULL is also redundant.

tools/libxl/libxl.c static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2183

Quoted 5 lines
tools/libxl/libxl.c +5 -0
+            if (protocol) {
+                strncpy(p, protocol, strlen(protocol));
+                p[strlen(protocol)] = 0;
+                flexarray_append(front, "protocol");
+                flexarray_append(front, p);

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Ian.

author
#2 lore raw
Quoted 25 lines · Ian Campbell
Quoted 4 lines · Wei Liu
(quoted diff) +0 -0
@@ -2156,6 +2166,24 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 

Review static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2178

Quoted 10 lines
(quoted diff) +10 -0
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            protocol = xc_domain_get_native_protocol(ctx->xch, domid);

You can declare protocol here instead of globally in the function. The = NULL is also redundant.

Review static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2183

Quoted 5 lines
(quoted diff) +5 -0
+            if (protocol) {
+                strncpy(p, protocol, strlen(protocol));
+                p[strlen(protocol)] = 0;
+                flexarray_append(front, "protocol");
+                flexarray_append(front, p);
Quoted 5 lines

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Oh thanks for the hint. This saves serveral lines of code. The (void *) argument of flexarray_append misled me. ;-)

Below is updated version of the patch. Casting "protocol" to (void *) is necessary to have it compiled. Otherwise gcc complains we discard the const quilifier.

Wei.

-----------8<--------
commit 7961cfe75b1282a2d27163a04ff268cedf4919b5

Author: Wei Liu <[email protected]>
Date:   Wed Apr 24 19:00:01 2013 +0100

libxl: write IO ABI for disk frontends

This is a patch to forward-port a Xend behaviour. Xend writes IO ABI used for all frontends. Blkfront before 2.6.26 relies on this behaviour otherwise guest cannot boot when running in 32-on-64 mode. Blkfront after 2.6.26 writes that node itself, in which case it's just an overwrite to an existing node which should be OK.

In fact Xend writes the ABI for all frontends including console and vif. But nowadays only old disk frontends rely on that behaviour so that we only write the ABI for disk frontends in libxl, minimizing the impact.

Cc Ian Campbell <[email protected]>
Cc Roger Pau Monne <[email protected]>
Cc Valtteri Kiviniemi <[email protected]>
tools/libxc/xc_dom_arm.c +7 -0
index 041832e..aaf35ca 100644
@@ -29,6 +29,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
 /* ------------------------------------------------------------------------ */
 /*
  * arm guests are hybrid and start off with paging disabled, therefore no
tools/libxc/xc_dom_x86.c +34 -0
index eb9ac07..84a8de6 100644
@@ -47,6 +47,40 @@
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    int ret;
+    uint32_t guest_width;
+    const char *protocol;
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd = XEN_DOMCTL_get_address_size;
+
+    ret = do_domctl(xch, &domctl);
+
+    if ( ret )
+        return NULL;
+
+    guest_width = domctl.u.address_size.size;
+
+    switch (guest_width) {
+    case 32: /* 32 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_32;
+        break;
+    case 64: /* 64 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_64;
+        break;
+    default:
+        protocol = NULL;
+    }
+
+    return protocol;
+}
+
 static unsigned long
 nr_page_tables(struct xc_dom_image *dom,
                xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
tools/libxc/xenctrl.h +10 -0
index 50853af..2f32151 100644
@@ -637,6 +637,16 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t size);
 
 /**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
  *
tools/libxl/libxl.c +23 -0
index 572c2c6..9013932 100644
@@ -2038,6 +2038,12 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
     libxl_ctx *ctx = gc->owner;
     xs_transaction_t t = XBT_NULL;
 
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     for (;;) {
         rc = libxl__xs_transaction_start(gc, &t);
         if (rc) goto out;
@@ -2156,6 +2162,23 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            const char *protocol =
+                xc_domain_get_native_protocol(ctx->xch, domid);
+            if (protocol) {
+                flexarray_append(front, "protocol");
+                flexarray_append(front, (void *)protocol);
+            }
+        }
+
         libxl__device_generic_add(gc, t, device,
                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
#3 lore raw
Quoted 32 lines · Wei Liu
Quoted 25 lines · Ian Campbell
Quoted 4 lines · Wei Liu
tools/libxl/libxl.c +0 -0
@@ -2156,6 +2166,24 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 

tools/libxl/libxl.c static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2178

Quoted 10 lines
tools/libxl/libxl.c +10 -0
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            protocol = xc_domain_get_native_protocol(ctx->xch, domid);

You can declare protocol here instead of globally in the function. The = NULL is also redundant.

Review static void device_disk_add(libxl__egc *egc, uint32_t domid, · line 2183

Quoted 5 lines
(quoted diff) +5 -0
+            if (protocol) {
+                strncpy(p, protocol, strlen(protocol));
+                p[strlen(protocol)] = 0;
+                flexarray_append(front, "protocol");
+                flexarray_append(front, p);
Quoted 5 lines

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Quoted 6 lines

Oh thanks for the hint. This saves serveral lines of code. The (void *) argument of flexarray_append misled me. ;-)

Below is updated version of the patch. Casting "protocol" to (void *) is necessary to have it compiled. Otherwise gcc complains we discard the const quilifier.

Oh, sorry, if this is the case the libxl__strdup(gc,protocol) is better than the cast. Sorry for misleading :-(

Now you mention it I do seem to recall trying to correctly constify flexarray's at one point and not quite being able to make it work.

Ian.

Quoted 151 lines

Wei.

-----------8<--------
commit 7961cfe75b1282a2d27163a04ff268cedf4919b5

Author: Wei Liu <[email protected]>
Date:   Wed Apr 24 19:00:01 2013 +0100

libxl: write IO ABI for disk frontends

This is a patch to forward-port a Xend behaviour. Xend writes IO ABI used for all frontends. Blkfront before 2.6.26 relies on this behaviour otherwise guest cannot boot when running in 32-on-64 mode. Blkfront after 2.6.26 writes that node itself, in which case it's just an overwrite to an existing node which should be OK.

In fact Xend writes the ABI for all frontends including console and vif. But nowadays only old disk frontends rely on that behaviour so that we only write the ABI for disk frontends in libxl, minimizing the impact.

Cc Ian Campbell <[email protected]>
Cc Roger Pau Monne <[email protected]>
Cc Valtteri Kiviniemi <[email protected]>
tools/libxc/xc_dom_arm.c +7 -0
index 041832e..aaf35ca 100644
@@ -29,6 +29,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
 /* ------------------------------------------------------------------------ */
 /*
  * arm guests are hybrid and start off with paging disabled, therefore no
tools/libxc/xc_dom_x86.c +34 -0
index eb9ac07..84a8de6 100644
@@ -47,6 +47,40 @@
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    int ret;
+    uint32_t guest_width;
+    const char *protocol;
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd = XEN_DOMCTL_get_address_size;
+
+    ret = do_domctl(xch, &domctl);
+
+    if ( ret )
+        return NULL;
+
+    guest_width = domctl.u.address_size.size;
+
+    switch (guest_width) {
+    case 32: /* 32 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_32;
+        break;
+    case 64: /* 64 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_64;
+        break;
+    default:
+        protocol = NULL;
+    }
+
+    return protocol;
+}
+
 static unsigned long
 nr_page_tables(struct xc_dom_image *dom,
                xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
tools/libxc/xenctrl.h +10 -0
index 50853af..2f32151 100644
@@ -637,6 +637,16 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t size);
 
 /**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
  *
tools/libxl/libxl.c +23 -0
index 572c2c6..9013932 100644
@@ -2038,6 +2038,12 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
     libxl_ctx *ctx = gc->owner;
     xs_transaction_t t = XBT_NULL;
 
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     for (;;) {
         rc = libxl__xs_transaction_start(gc, &t);
         if (rc) goto out;
@@ -2156,6 +2162,23 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            const char *protocol =
+                xc_domain_get_native_protocol(ctx->xch, domid);
+            if (protocol) {
+                flexarray_append(front, "protocol");
+                flexarray_append(front, (void *)protocol);
+            }
+        }
+
         libxl__device_generic_add(gc, t, device,
                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
author
#4 lore raw

On Fri, Apr 26, 2013 at 10:52:35AM +0100, Ian Campbell wrote:
[...]

Quoted 15 lines
Quoted 8 lines
Quoted 7 lines
Quoted 1 line

+ flexarray_append(front, p);

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Quoted 6 lines

Oh thanks for the hint. This saves serveral lines of code. The (void *) argument of flexarray_append misled me. ;-)

Below is updated version of the patch. Casting "protocol" to (void *) is necessary to have it compiled. Otherwise gcc complains we discard the const quilifier.

Quoted 6 lines

Oh, sorry, if this is the case the libxl__strdup(gc,protocol) is better than the cast. Sorry for misleading :-(

Now you mention it I do seem to recall trying to correctly constify flexarray's at one point and not quite being able to make it work.

Another version with libxl__strdup(). :-)

Wei.

-------8<--------
commit 60bfc42e4e4f5e0f7f025e4e67b32c61fef396d4

Author: Wei Liu <[email protected]>
Date:   Wed Apr 24 19:00:01 2013 +0100

libxl: write IO ABI for disk frontends

This is a patch to forward-port a Xend behaviour. Xend writes IO ABI used for all frontends. Blkfront before 2.6.26 relies on this behaviour otherwise guest cannot boot when running in 32-on-64 mode. Blkfront after 2.6.26 writes that node itself, in which case it's just an overwrite to an existing node which should be OK.

In fact Xend writes the ABI for all frontends including console and vif. But nowadays only old disk frontends rely on that behaviour so that we only write the ABI for disk frontends in libxl, minimizing the impact.

Cc Ian Campbell <[email protected]>
Cc Roger Pau Monne <[email protected]>
Cc Valtteri Kiviniemi <[email protected]>
tools/libxc/xc_dom_arm.c +7 -0
index 041832e..aaf35ca 100644
@@ -29,6 +29,13 @@
 #define CONSOLE_PFN_OFFSET 0
 #define XENSTORE_PFN_OFFSET 1
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    return XEN_IO_PROTO_ABI_ARM;
+}
+
 /* ------------------------------------------------------------------------ */
 /*
  * arm guests are hybrid and start off with paging disabled, therefore no
tools/libxc/xc_dom_x86.c +34 -0
index eb9ac07..84a8de6 100644
@@ -47,6 +47,40 @@
 #define round_down(addr, mask)   ((addr) & ~(mask))
 #define round_up(addr, mask)     ((addr) | (mask))
 
+/* get guest IO ABI protocol */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid)
+{
+    int ret;
+    uint32_t guest_width;
+    const char *protocol;
+    DECLARE_DOMCTL;
+
+    memset(&domctl, 0, sizeof(domctl));
+    domctl.domain = domid;
+    domctl.cmd = XEN_DOMCTL_get_address_size;
+
+    ret = do_domctl(xch, &domctl);
+
+    if ( ret )
+        return NULL;
+
+    guest_width = domctl.u.address_size.size;
+
+    switch (guest_width) {
+    case 32: /* 32 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_32;
+        break;
+    case 64: /* 64 bit guest */
+        protocol = XEN_IO_PROTO_ABI_X86_64;
+        break;
+    default:
+        protocol = NULL;
+    }
+
+    return protocol;
+}
+
 static unsigned long
 nr_page_tables(struct xc_dom_image *dom,
                xen_vaddr_t start, xen_vaddr_t end, unsigned long bits)
tools/libxc/xenctrl.h +10 -0
index 50853af..2f32151 100644
@@ -637,6 +637,16 @@ int xc_domain_hvm_setcontext(xc_interface *xch,
                              uint32_t size);
 
 /**
+ * This function will return guest IO ABI protocol
+ *
+ * @parm xch a handle to an open hypervisor interface
+ * @parm domid the domain to get IO ABI protocol for
+ * @return guest protocol on success, NULL on failure
+ */
+const char *xc_domain_get_native_protocol(xc_interface *xch,
+                                          uint32_t domid);
+
+/**
  * This function returns information about the execution context of a
  * particular vcpu of a domain.
  *
tools/libxl/libxl.c +23 -0
index 572c2c6..d371b88 100644
@@ -2038,6 +2038,12 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
     libxl_ctx *ctx = gc->owner;
     xs_transaction_t t = XBT_NULL;
 
+    libxl_domain_type type = libxl__domain_type(gc, domid);
+    if (type == LIBXL_DOMAIN_TYPE_INVALID) {
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
     for (;;) {
         rc = libxl__xs_transaction_start(gc, &t);
         if (rc) goto out;
@@ -2156,6 +2162,23 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid,
         flexarray_append(front, "device-type");
         flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
+        /*
+         * Old PV kernel disk frontends before 2.6.26 rely on tool stack to
+         * write disk native protocol to frontend node. Xend does this, port
+         * this behaviour to xl.
+         *
+         * New kernels write this node themselves. In that case it just
+         * overwrites an existing node which is OK.
+         */
+        if (type == LIBXL_DOMAIN_TYPE_PV) {
+            const char *protocol =
+                xc_domain_get_native_protocol(ctx->xch, domid);
+            if (protocol) {
+                flexarray_append(front, "protocol");
+                flexarray_append(front, libxl__strdup(gc, protocol));
+            }
+        }
+
         libxl__device_generic_add(gc, t, device,
                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
Acked-by
#5 lore raw
Quoted 17 lines · Wei Liu

On Fri, Apr 26, 2013 at 10:52:35AM +0100, Ian Campbell wrote:
[...]

Quoted 15 lines
Quoted 14 lines
Quoted 7 lines
Quoted 1 line

+ flexarray_append(front, p);

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Oh thanks for the hint. This saves serveral lines of code. The (void *) argument of flexarray_append misled me. ;-)

Below is updated version of the patch. Casting "protocol" to (void *) is necessary to have it compiled. Otherwise gcc complains we discard the const quilifier.

Quoted 8 lines
Quoted 6 lines

Oh, sorry, if this is the case the libxl__strdup(gc,protocol) is better than the cast. Sorry for misleading :-(

Now you mention it I do seem to recall trying to correctly constify flexarray's at one point and not quite being able to make it work.

Another version with libxl__strdup(). :-)

Thanks!

George, this is on your tracking list and is a bug fix and/or a regression from Xend. Are you happy to give it a freeze exception?

Quoted 13 lines

-------8<--------
commit 60bfc42e4e4f5e0f7f025e4e67b32c61fef396d4

Author: Wei Liu <[email protected]>
Date:   Wed Apr 24 19:00:01 2013 +0100

libxl: write IO ABI for disk frontends

This is a patch to forward-port a Xend behaviour. Xend writes IO ABI used for all frontends. Blkfront before 2.6.26 relies on this behaviour otherwise guest cannot boot when running in 32-on-64 mode. Blkfront after 2.6.26 writes that node itself, in which case it's just an overwrite to an existing node which should be OK.

Quoted 6 lines

In fact Xend writes the ABI for all frontends including console and vif. But nowadays only old disk frontends rely on that behaviour so that we only write the ABI for disk frontends in libxl, minimizing the impact.

Cc Ian Campbell <[email protected]>

Ian.

#6 lore raw
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Wei Liu

On Fri, Apr 26, 2013 at 10:52:35AM +0100, Ian Campbell wrote:
[...]

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line

+ flexarray_append(front, p);

GCSPRINTF would be the right way to do this, but actually you can pass protocol directly to flexarray_append, that is fine since the flexarray never frees the values which it contains so they either need to be gc'd, string constants or managed manually.

Quoted 6 lines

Oh thanks for the hint. This saves serveral lines of code. The (void *) argument of flexarray_append misled me. ;-)

Below is updated version of the patch. Casting "protocol" to (void *) is necessary to have it compiled. Otherwise gcc complains we discard the const quilifier.

Oh, sorry, if this is the case the libxl__strdup(gc,protocol) is better than the cast. Sorry for misleading :-(

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

Now you mention it I do seem to recall trying to correctly constify flexarray's at one point and not quite being able to make it work.

Another version with libxl__strdup(). :-)

Thanks!

George, this is on your tracking list and is a bug fix and/or a regression from Xend. Are you happy to give it a freeze exception?

Yes, I think this is fine to go in.

-George

Applied
#7 lore raw
Quoted 5 lines
Quoted 3 lines

George, this is on your tracking list and is a bug fix and/or a regression from Xend. Are you happy to give it a freeze exception?

Yes, I think this is fine to go in.

Applied. Thanks

#8 lore raw

Hi,

I will test this patch now. Is this patch already included in xen-unstable?

- Valtteri

2013/4/26 Ian Campbell <[email protected]>

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

George, this is on your tracking list and is a bug fix and/or a regression from Xend. Are you happy to give it a freeze exception?

Yes, I think this is fine to go in.

Applied. Thanks

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

author
#9 lore raw
Quoted 4 lines · Valtteri Kiviniemi

Hi,

I will test this patch now. Is this patch already included in xen-unstable?

Yes, it's in xen-4.3-rc1 now. I would encourage you help testing the up coming Xen-4.3-rcX.

Wei.

#10 lore raw

2013/5/16 Wei Liu <[email protected]>

Quoted 13 lines · Valtteri Kiviniemi
Quoted 3 lines

Hi,

I will test this patch now. Is this patch already included in

xen-unstable?

Quoted 1 line

Yes, it's in xen-4.3-rc1 now. I would encourage you help testing the up coming Xen-4.3-rcX.

Wei.

Hi,

Ok, thanks. I'm building 4.3.0-rc1 now on my test server and I will post results within 24 hours.

- Valtteri

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

#11 lore raw

2013/5/16 Valtteri Kiviniemi <[email protected]>

Quoted 16 lines

2013/5/16 Wei Liu <[email protected]>

Quoted 13 lines · Valtteri Kiviniemi
Quoted 3 lines

Hi,

I will test this patch now. Is this patch already included in

xen-unstable?

Quoted 1 line

Yes, it's in xen-4.3-rc1 now. I would encourage you help testing the up coming Xen-4.3-rcX.

Wei.

Quoted 7 lines

Hi,

Ok, thanks. I'm building 4.3.0-rc1 now on my test server and I will post results within 24 hours.

- Valtteri

Hi,

My 32bit debian etch with kernel 2.6.16.33-xen is now booting successfully with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

- Valtteri

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

author
#12 lore raw
Quoted 26 lines · Valtteri Kiviniemi

2013/5/16 Valtteri Kiviniemi <[email protected]>

Quoted 16 lines

2013/5/16 Wei Liu <[email protected]>

Quoted 13 lines · Valtteri Kiviniemi
Quoted 3 lines

Hi,

I will test this patch now. Is this patch already included in

xen-unstable?

Quoted 1 line

Yes, it's in xen-4.3-rc1 now. I would encourage you help testing the up coming Xen-4.3-rcX.

Wei.

Quoted 7 lines

Hi,

Ok, thanks. I'm building 4.3.0-rc1 now on my test server and I will post results within 24 hours.

- Valtteri

Quoted 6 lines

Hi,

My 32bit debian etch with kernel 2.6.16.33-xen is now booting successfully with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown

Thanks for testing.

Quoted 7 lines

etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

George, should this one be added to your list? (Just found out you're already in CC ;-) )

Wei.

#13 lore raw
Quoted 40 lines · Wei Liu
Quoted 26 lines · Valtteri Kiviniemi

2013/5/16 Valtteri Kiviniemi <[email protected]>

Quoted 16 lines

2013/5/16 Wei Liu <[email protected]>

Quoted 13 lines · Valtteri Kiviniemi
Quoted 3 lines

Hi,

I will test this patch now. Is this patch already included in

xen-unstable?

Quoted 1 line

Yes, it's in xen-4.3-rc1 now. I would encourage you help testing the up coming Xen-4.3-rcX.

Wei.

Quoted 7 lines

Hi,

Ok, thanks. I'm building 4.3.0-rc1 now on my test server and I will post results within 24 hours.

- Valtteri

Quoted 6 lines

Hi,

My 32bit debian etch with kernel 2.6.16.33-xen is now booting successfully with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown

Thanks for testing.

Quoted 4 lines

etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

Quoted 6 lines
Quoted 3 lines

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

George, should this one be added to your list? (Just found out you're already in CC ;-) )

...add "Linux 2.6.16.33 HOTPLUG config option is hard to find" to my list? I'm not sure that would be a 4.3 release blocker... :-)

-George

author
#14 lore raw

On Fri, May 17, 2013 at 09:56:38AM +0100, George Dunlap wrote:
[...]

Quoted 14 lines
Quoted 14 lines
Quoted 3 lines

with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown

Thanks for testing.

Quoted 7 lines

etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

Quoted 6 lines
Quoted 2 lines

George, should this one be added to your list? (Just found out you're already in CC ;-) )

...add "Linux 2.6.16.33 HOTPLUG config option is hard to find" to my list? I'm not sure that would be a 4.3 release blocker... :-)

I mean 'xl suspend' crashes with "Internal Error". Should not be a blocker, but at least worthy of making its way to known issues list? (if there is one).

Wei.

Quoted 1 line

-George

#15 lore raw
Quoted 19 lines · Wei Liu

On Fri, May 17, 2013 at 09:56:38AM +0100, George Dunlap wrote:
[...]

Quoted 17 lines
Quoted 16 lines
Quoted 3 lines

with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown

Thanks for testing.

Quoted 7 lines

etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

George, should this one be added to your list? (Just found out you're already in CC ;-) )

Quoted 7 lines
Quoted 3 lines

...add "Linux 2.6.16.33 HOTPLUG config option is hard to find" to my list? I'm not sure that would be a 4.3 release blocker... :-)

I mean 'xl suspend' crashes with "Internal Error". Should not be a blocker, but at least worthy of making its way to known issues list? (if there is one).

Well if it *fails* with "Internal Error" because there's an internal error, I'm not sure that's a bug. :-)

If Valtteri wants to post a proper bug report, with the listed output and a suggestion of what would be a better output, we can consider putting it on the list.

-George

author
#16 lore raw
Quoted 24 lines · George Dunlap
Quoted 23 lines · Wei Liu

On Fri, May 17, 2013 at 09:56:38AM +0100, George Dunlap wrote:
[...]

Quoted 20 lines
Quoted 10 lines
Quoted 3 lines

with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my legacy domU and all of them seemed to be working (reboot, pause, unpause, shutdown

Thanks for testing.

Quoted 4 lines

etc.) except suspend. Suspend crashes with "Internal error" and the guest console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

Quoted 6 lines
Quoted 3 lines

2.6.16.33 kernel does not seem to have cpu hotplug support, or then I just can find it in the kernel menuconfig.

George, should this one be added to your list? (Just found out you're already in CC ;-) )

...add "Linux 2.6.16.33 HOTPLUG config option is hard to find" to my list? I'm not sure that would be a 4.3 release blocker... :-)

Quoted 7 lines
Quoted 3 lines

I mean 'xl suspend' crashes with "Internal Error". Should not be a blocker, but at least worthy of making its way to known issues list? (if there is one).

Well if it *fails* with "Internal Error" because there's an internal error, I'm not sure that's a bug. :-)

The "crash" bugs me. If it is a normal exit that's fine.

Quoted 4 lines

If Valtteri wants to post a proper bug report, with the listed output and a suggestion of what would be a better output, we can consider putting it on the list.

Valtteri now it is up to you. :-)

Wei.

#17 lore raw

2013/5/17 Wei Liu <[email protected]>

Quoted 44 lines · George Dunlap
Quoted 5 lines · Wei Liu
Quoted 4 lines · George Dunlap

[...]

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

with Xen 4.3-rc1 and with xl tool stack. So the patch is working as intented. I also tested various xl commands and functions with my

legacy

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

domU and all of them seemed to be working (reboot, pause, unpause,

shutdown

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Thanks for testing.

Quoted 1 line

etc.) except suspend. Suspend crashes with "Internal error" and the

guest

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

console shows error message "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU".

2.6.16.33 kernel does not seem to have cpu hotplug support, or then

I just

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

can find it in the kernel menuconfig.

George, should this one be added to your list? (Just found out you're already in CC ;-) )

...add "Linux 2.6.16.33 HOTPLUG config option is hard to find" to my list? I'm not sure that would be a 4.3 release blocker... :-)

Quoted 7 lines
Quoted 3 lines

I mean 'xl suspend' crashes with "Internal Error". Should not be a blocker, but at least worthy of making its way to known issues list? (if there is one).

Well if it *fails* with "Internal Error" because there's an internal error, I'm not sure that's a bug. :-)

The "crash" bugs me. If it is a normal exit that's fine.

Quoted 4 lines

If Valtteri wants to post a proper bug report, with the listed output and a suggestion of what would be a better output, we can consider putting it on the list.

Quoted 5 lines

Valtteri now it is up to you. :-)

Wei.

Hi,

I'm now at holiday couple of weeks but after that I will double check my kernel config and post a proper bug report if needed. I just had this feeling that the pre 4.0 xen versions (for example xen 3.4 with 2.6.18 xenified kernel) handled the suspend differently and figured that maybe there is still something missing from xl toolstack. That 2.6.16 kernel is so old that I just assumed that it does not have cpu hotplug support and figured that maybe it is something that xl toolstack does not handle. But you are probably right, I'm just blind and missed the option in the menuconfig :)

Its hard to remember all the changes that has happened in Xen and Linux kernels and which options need to be enabled etc. But I will test it more thoroughly after my holiday.

- Valteri

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