Skip to contentSkip to conversation

add iomem option to xl

PATCH In review Matthew Fioravante 2 participants 3 messages Sep 18, 2012 – Sep 19, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 3/6 add iomem option to xl

This patch adds a new option for xen config files for directly mapping hardware io memory into a vm.

iomem=['pagenum,size',..]

Where pagenum is the page number and size is the number of page. example (for a tpm:
iomem=['fed40,5']

Signed off by Matthew Fioravante [email protected]

tools/libxl/libxl.h +1 -1
@@ -477,7 +477,7 @@ typedef struct {
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
 
-    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs, num_vtpms;
+    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs,

num_vtpms, num_iorngs;

     libxl_device_disk *disks;
     libxl_device_nic *vifs;
@@ -485,6 +485,7 @@ typedef struct {
     libxl_device_vfb *vfbs;
     libxl_device_vkb *vkbs;
     libxl_device_vtpm *vtpms;

+ libxl_iomem_range *iorngs;

     libxl_action_on_shutdown on_poweroff;
     libxl_action_on_shutdown on_reboot;
tools/libxl/libxl_create.c +0 -0
@@ -58,6 +58,10 @@ void libxl_domain_config_dispose(libxl_domain_config

*d_config)

        libxl_device_vtpm_dispose(&d_config->vtpms[i]);
     free(d_config->vtpms);

+ for (i=0; i<d_config->num_iorngs; i++)
+ libxl_iomem_range_dispose(&d_config->iorngs[i]);
+ free(d_config->iorngs);
+

     libxl_domain_create_info_dispose(&d_config->c_info);
     libxl_domain_build_info_dispose(&d_config->b_info);

}
@@ -718,6 +722,15 @@ static void domcreate_bootloader_done(libxl__egc *egc,

     store_libxl_entry(gc, domid, &d_config->b_info);

+ for (i = 0; i < d_config->num_iorngs; i++) {
+ ret = xc_domain_iomem_permission(ctx->xch, domid,
d_config->iorngs[i].start, d_config->iorngs[i].length, d_config->iorngs[i].allow);
+ if (ret) {
+ LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+ "cannot add iomem range %d to domain: %d", i, ret);
+ ret = ERROR_FAIL;
+ goto error_out;
+ }
+ }

     for (i = 0; i < d_config->num_disks; i++) {
         ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]);
         if (ret) {
tools/libxl/libxl_types.idl +6 -0
@@ -317,6 +317,12 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ], dir=DIR_IN
 )
 
+libxl_iomem_range = Struct("iomem_range", [
+    ("start", uint64),
+    ("length", uint64),
+    ("allow", bool),
+]);
+
 libxl_device_vfb = Struct("device_vfb", [
     ("backend_domid", libxl_domid),
     ("devid",         libxl_devid),
tools/libxl/xl_cmdimpl.c +1 -1
@@ -560,7 +560,7 @@ static void parse_config_data(const char *config_source,
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms;
+    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms,
*iomems;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int pci_permissive = 0;
@@ -1145,6 +1145,42 @@ skip_vfb:
             libxl_defbool_set(&b_info->u.pv.e820_host, true);
     }

+ if(!xlu_cfg_get_list(config, "iomem", &iomems, 0, 0)) {
+ int i;
+ for(i =0; (buf = xlu_cfg_get_listitem(iomems, i)) != NULL; ++i) {

+          libxl_iomem_range *iorng;
+          char* buf2 = strdup(buf);
+          char *st, *len, *al;

+
+ d_config->iorngs = realloc(d_config->iorngs,
sizeof(libxl_iomem_range) * (d_config->num_iorngs + 1));
+ iorng = d_config->iorngs + d_config->num_iorngs;
+
+ libxl_iomem_range_init(iorng);
+

+          st = strtok(buf2, ",");
+          len = strtok(NULL, ",");
+          al = strtok(NULL, ",");
+
+          if(st == NULL || len == NULL ||
+                sscanf(st, "%" PRIx64, &iorng->start) != 1 ||
+                sscanf(len, "%" PRIu64, &iorng->length) != 1 ||
+                (al != NULL && ((al[0] != '1' && al[0] != '0') || al[1]
!= '\0'))
+            ) {
+             fprintf(stderr, "Malformed iomem specification!\n");
+             free(buf2);
+             exit(1);

+ }
+ if(al != NULL) {
+ iorng->allow = al[0] - '0';
+ } else {
+ iorng->allow = 1;
+ }
+
+ free(buf2);
+ d_config->num_iorngs++;
+ }
+ }
+

     switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
     case 0:
         {
Signature · 1 line
1.7.4.4

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

#1 lore raw
Quoted 8 lines · Matthew Fioravante

This patch adds a new option for xen config files for directly mapping hardware io memory into a vm.

iomem=['pagenum,size',..]

Where pagenum is the page number and size is the number of page. example (for a tpm:
iomem=['fed40,5']

Please can you patch the docs too.

Your implementation seems to also support a third field "allow"?

Did xm/xend have similar functionality? Is this compatible with the syntax?

Also this patch is whitespace mangled again I'm afraid (I expect they all are so I'll stop mentioning it)

Quoted 131 lines

Signed off by Matthew Fioravante [email protected]

tools/libxl/libxl.h +1 -1
@@ -477,7 +477,7 @@ typedef struct {
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
 
-    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs, num_vtpms;
+    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs,
 num_vtpms, num_iorngs;
 
     libxl_device_disk *disks;
     libxl_device_nic *vifs;
tools/libxl/libxl.h +1 -0
@@ -485,6 +485,7 @@ typedef struct {
     libxl_device_vfb *vfbs;
     libxl_device_vkb *vkbs;
     libxl_device_vtpm *vtpms;
+    libxl_iomem_range *iorngs;
 
     libxl_action_on_shutdown on_poweroff;
     libxl_action_on_shutdown on_reboot;
tools/libxl/libxl_create.c +4 -0
@@ -58,6 +58,10 @@ void libxl_domain_config_dispose(libxl_domain_config
 *d_config)
        libxl_device_vtpm_dispose(&d_config->vtpms[i]);
     free(d_config->vtpms);
 
+    for (i=0; i<d_config->num_iorngs; i++)
+       libxl_iomem_range_dispose(&d_config->iorngs[i]);
+    free(d_config->iorngs);
+
     libxl_domain_create_info_dispose(&d_config->c_info);
     libxl_domain_build_info_dispose(&d_config->b_info);

}

tools/libxl/libxl_create.c +9 -0
@@ -718,6 +722,15 @@ static void domcreate_bootloader_done(libxl__egc *egc,
 
     store_libxl_entry(gc, domid, &d_config->b_info);
 
+    for (i = 0; i < d_config->num_iorngs; i++) {
+        ret = xc_domain_iomem_permission(ctx->xch, domid,
 d_config->iorngs[i].start, d_config->iorngs[i].length,
 d_config->iorngs[i].allow);
+        if (ret) {
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                       "cannot add iomem range %d to domain: %d", i, ret);
+            ret = ERROR_FAIL;
+            goto error_out;
+        }
+    }
     for (i = 0; i < d_config->num_disks; i++) {
         ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]);
         if (ret) {
tools/libxl/libxl_types.idl +6 -0
@@ -317,6 +317,12 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ], dir=DIR_IN
 )
 
+libxl_iomem_range = Struct("iomem_range", [
+    ("start", uint64),
+    ("length", uint64),
+    ("allow", bool),
+]);
+
 libxl_device_vfb = Struct("device_vfb", [
     ("backend_domid", libxl_domid),
     ("devid",         libxl_devid),
tools/libxl/xl_cmdimpl.c +1 -1
@@ -560,7 +560,7 @@ static void parse_config_data(const char *config_source,
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms;
+    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms,
 *iomems;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int pci_permissive = 0;
tools/libxl/xl_cmdimpl.c +36 -0
@@ -1145,6 +1145,42 @@ skip_vfb:
             libxl_defbool_set(&b_info->u.pv.e820_host, true);
     }
 
+    if(!xlu_cfg_get_list(config, "iomem", &iomems, 0, 0)) {
+       int i;
+       for(i =0; (buf = xlu_cfg_get_listitem(iomems, i)) != NULL; ++i) {
+          libxl_iomem_range *iorng;
+          char* buf2 = strdup(buf);
+          char *st, *len, *al;
+
+          d_config->iorngs = realloc(d_config->iorngs,
 sizeof(libxl_iomem_range) * (d_config->num_iorngs + 1));
+          iorng = d_config->iorngs + d_config->num_iorngs;
+
+          libxl_iomem_range_init(iorng);
+
+          st = strtok(buf2, ",");
+          len = strtok(NULL, ",");
+          al = strtok(NULL, ",");
+
+          if(st == NULL || len == NULL ||
+                sscanf(st, "%" PRIx64, &iorng->start) != 1 ||
+                sscanf(len, "%" PRIu64, &iorng->length) != 1 ||
+                (al != NULL && ((al[0] != '1' && al[0] != '0') || al[1]
 != '\0'))
+            ) {
+             fprintf(stderr, "Malformed iomem specification!\n");
+             free(buf2);
+             exit(1);
+          }
+          if(al != NULL) {
+             iorng->allow = al[0] - '0';
+          } else {
+             iorng->allow = 1;
+          }
+
+          free(buf2);
+          d_config->num_iorngs++;
+       }
+    }
+
     switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
     case 0:
         {
#2 lore raw

Sorry I forgot about the allow boolean, and yes its compatible with xm in terms of how ioport and irq are implemented.

Quoted 141 lines · Ian Campbell
Quoted 8 lines · Matthew Fioravante

This patch adds a new option for xen config files for directly mapping hardware io memory into a vm.

iomem=['pagenum,size',..]

Where pagenum is the page number and size is the number of page. example (for a tpm:
iomem=['fed40,5']

Please can you patch the docs too.

Your implementation seems to also support a third field "allow"?

Did xm/xend have similar functionality? Is this compatible with the syntax?

Also this patch is whitespace mangled again I'm afraid (I expect they all are so I'll stop mentioning it)

Quoted 122 lines

Signed off by Matthew Fioravante [email protected]

tools/libxl/libxl.h +1 -1
@@ -477,7 +477,7 @@ typedef struct {
     libxl_domain_create_info c_info;
     libxl_domain_build_info b_info;
 
-    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs, num_vtpms;
+    int num_disks, num_vifs, num_pcidevs, num_vfbs, num_vkbs,
 num_vtpms, num_iorngs;
 
     libxl_device_disk *disks;
     libxl_device_nic *vifs;
tools/libxl/libxl.h +1 -0
@@ -485,6 +485,7 @@ typedef struct {
     libxl_device_vfb *vfbs;
     libxl_device_vkb *vkbs;
     libxl_device_vtpm *vtpms;
+    libxl_iomem_range *iorngs;
 
     libxl_action_on_shutdown on_poweroff;
     libxl_action_on_shutdown on_reboot;
tools/libxl/libxl_create.c +4 -0
@@ -58,6 +58,10 @@ void libxl_domain_config_dispose(libxl_domain_config
 *d_config)
        libxl_device_vtpm_dispose(&d_config->vtpms[i]);
     free(d_config->vtpms);
 
+    for (i=0; i<d_config->num_iorngs; i++)
+       libxl_iomem_range_dispose(&d_config->iorngs[i]);
+    free(d_config->iorngs);
+
     libxl_domain_create_info_dispose(&d_config->c_info);
     libxl_domain_build_info_dispose(&d_config->b_info);

}

tools/libxl/libxl_create.c +9 -0
@@ -718,6 +722,15 @@ static void domcreate_bootloader_done(libxl__egc *egc,
 
     store_libxl_entry(gc, domid, &d_config->b_info);
 
+    for (i = 0; i < d_config->num_iorngs; i++) {
+        ret = xc_domain_iomem_permission(ctx->xch, domid,
 d_config->iorngs[i].start, d_config->iorngs[i].length,
 d_config->iorngs[i].allow);
+        if (ret) {
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
+                       "cannot add iomem range %d to domain: %d", i, ret);
+            ret = ERROR_FAIL;
+            goto error_out;
+        }
+    }
     for (i = 0; i < d_config->num_disks; i++) {
         ret = libxl_device_disk_add(ctx, domid, &d_config->disks[i]);
         if (ret) {
tools/libxl/libxl_types.idl +6 -0
@@ -317,6 +317,12 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ], dir=DIR_IN
 )
 
+libxl_iomem_range = Struct("iomem_range", [
+    ("start", uint64),
+    ("length", uint64),
+    ("allow", bool),
+]);
+
 libxl_device_vfb = Struct("device_vfb", [
     ("backend_domid", libxl_domid),
     ("devid",         libxl_devid),
tools/libxl/xl_cmdimpl.c +1 -1
@@ -560,7 +560,7 @@ static void parse_config_data(const char *config_source,
     const char *buf;
     long l;
     XLU_Config *config;
-    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms;
+    XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms,
 *iomems;
     int pci_power_mgmt = 0;
     int pci_msitranslate = 1;
     int pci_permissive = 0;
tools/libxl/xl_cmdimpl.c +31 -0
@@ -1145,6 +1145,42 @@ skip_vfb:
             libxl_defbool_set(&b_info->u.pv.e820_host, true);
     }
 
+    if(!xlu_cfg_get_list(config, "iomem", &iomems, 0, 0)) {
+       int i;
+       for(i =0; (buf = xlu_cfg_get_listitem(iomems, i)) != NULL; ++i) {
+          libxl_iomem_range *iorng;
+          char* buf2 = strdup(buf);
+          char *st, *len, *al;
+
+          d_config->iorngs = realloc(d_config->iorngs,
 sizeof(libxl_iomem_range) * (d_config->num_iorngs + 1));
+          iorng = d_config->iorngs + d_config->num_iorngs;
+
+          libxl_iomem_range_init(iorng);
+
+          st = strtok(buf2, ",");
+          len = strtok(NULL, ",");
+          al = strtok(NULL, ",");
+
+          if(st == NULL || len == NULL ||
+                sscanf(st, "%" PRIx64, &iorng->start) != 1 ||
+                sscanf(len, "%" PRIu64, &iorng->length) != 1 ||
+                (al != NULL && ((al[0] != '1' && al[0] != '0') || al[1]
 != '\0'))
+            ) {
+             fprintf(stderr, "Malformed iomem specification!\n");
+             free(buf2);
+             exit(1);
+          }
+          if(al != NULL) {
+             iorng->allow = al[0] - '0';
+          } else {
+             iorng->allow = 1;
+          }
+
Quoted 9 lines
Quoted 8 lines
tools/libxl/xl_cmdimpl.c +5 -0
+          free(buf2);
+          d_config->num_iorngs++;
+       }
+    }
+
     switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) {
     case 0:
         {

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