[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 3 of 6] Allocate an 8 byte buffer to contain the VM generation id and populate it



# HG changeset patch
# User Paul Durrant <paul.durrant@xxxxxxxxxx>
# Date 1322563734 0
# Node ID 58cdfa17fb8801ab0a9e8133e0ec2ad47a426f5d
# Parent  ec35c9c5a0c053532de953f59f7c8f28ba69167a
Allocate an 8 byte buffer to contain the VM generation id and populate it
at boot time with a value read from "platform/generation_id". Also add
code to libxl to populate this xenstore key with the value of a new
'generation_id' parameter in the VM config file.
Populate the ADDR package of VM_Gen_Counter ACPI device such that the first
integer evaluates to the low order 32 bits of the buffer address and the
second integer evaluates to the high order 32 bits of the buffer address.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/firmware/hvmloader/acpi/build.c
--- a/tools/firmware/hvmloader/acpi/build.c     Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/firmware/hvmloader/acpi/build.c     Tue Nov 29 10:48:54 2011 +0000
@@ -297,6 +297,20 @@ static int construct_secondary_tables(un
     return nr_tables;
 }
 
+unsigned long new_vm_gid(void)
+{
+    uint64_t gid;
+    unsigned char *buf;
+
+    buf = mem_alloc(8, 8);
+    if (!buf) return 0;
+
+    gid = strtoll(xenstore_read("platform/generation-id", "0"), NULL, 0);
+    *(uint64_t *)buf = gid;
+
+    return virt_to_phys(buf);    
+}
+
 void acpi_build_tables(struct acpi_config *config, unsigned int physical)
 {
     struct acpi_info *acpi_info;
@@ -309,6 +323,7 @@ void acpi_build_tables(struct acpi_confi
     unsigned char       *dsdt;
     unsigned long        secondary_tables[16];
     int                  nr_secondaries, i;
+    unsigned long        vm_gid_addr;
 
     /* Allocate and initialise the acpi info area. */
     mem_hole_populate_ram(ACPI_INFO_PHYSICAL_ADDRESS >> PAGE_SHIFT, 1);
@@ -421,12 +436,16 @@ void acpi_build_tables(struct acpi_confi
                  offsetof(struct acpi_20_rsdp, extended_checksum),
                  sizeof(struct acpi_20_rsdp));
 
+    vm_gid_addr = new_vm_gid();
+    if (!vm_gid_addr) goto oom;
+
     acpi_info->com1_present = uart_exists(0x3f8);
     acpi_info->com2_present = uart_exists(0x2f8);
     acpi_info->lpt1_present = lpt_exists(0x378);
     acpi_info->hpet_present = hpet_exists(ACPI_HPET_ADDRESS);
     acpi_info->pci_min = pci_mem_start;
     acpi_info->pci_len = pci_mem_end - pci_mem_start;
+    acpi_info->vm_gid_addr = vm_gid_addr;
 
     return;
 
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c   Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/firmware/hvmloader/util.c   Tue Nov 29 10:48:54 2011 +0000
@@ -205,6 +205,78 @@ strlen(const char *s)
     return i;
 }
 
+static inline int __digit(char c, int base)
+{
+    int d = -1;
+
+    if ( (c >= '0') && (c <= '9') )
+        d = c - '0';
+
+    if ( (c >= 'A') && (c <= 'Z') )
+        d = c - 'A' + 10;
+
+    if ( (c >= 'a') && (c <= 'z') )
+        d = c - 'a' + 10;
+
+    if (d >= base)
+        d = -1;
+
+    return d;
+}
+
+long long
+strtoll(const char *s, char **end, int base)
+{
+    long long v = 0;
+    int sign = 1;
+
+    while ( (*s != '\0') && isspace(*s) )
+        s++;
+
+    if ( *s == '\0' ) goto out;
+
+    if ( *s == '-' ) {
+        sign = -1;
+        s++;
+    } else {
+        if ( *s == '+' )
+            s++;
+    }
+
+    if ( *s == '\0' ) goto out;
+
+    if ( *s == '0' ) {
+        s++;
+        if ( *s == '\0' ) goto out;
+
+        if ( *s == 'x' ) {
+            if ( base != 0 && base != 16) goto out;
+            base = 16;
+            s++;
+        } else {
+            if ( base != 0 && base != 8) goto out;
+            base = 8;
+        }
+    } else {
+        if (base != 0 && base != 10) goto out;
+        base = 10;
+    }
+
+    while ( *s != '\0' ) {
+        int d = __digit(*s, base);
+
+        if ( d < 0 ) goto out;
+
+        v = (v * base) + d;
+        s++;
+    }
+
+out:
+    if (end) *end = (char *)s;
+
+    return sign * v;
+}
+
 void *
 memset(void *s, int c, unsigned n)
 {
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/firmware/hvmloader/util.h   Tue Nov 29 10:48:54 2011 +0000
@@ -152,6 +152,7 @@ int strncmp(const char *s1, const char *
 char *strcpy(char *dest, const char *src);
 char *strncpy(char *dest, const char *src, unsigned n);
 unsigned strlen(const char *s);
+long long strtoll(const char *s, char **end, int base);
 int memcmp(const void *s1, const void *s2, unsigned n);
 void *memcpy(void *dest, const void *src, unsigned n);
 void *memmove(void *dest, const void *src, unsigned n);
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/libxl/libxl_create.c        Tue Nov 29 10:48:54 2011 +0000
@@ -101,6 +101,7 @@ int libxl_init_build_info(libxl_ctx *ctx
         b_info->u.hvm.vpt_align = 1;
         b_info->u.hvm.timer_mode = 1;
         b_info->u.hvm.nested_hvm = 0;
+        b_info->u.hvm.generation_id = 0;
         break;
     case LIBXL_DOMAIN_TYPE_PV:
         b_info->u.pv.slack_memkb = 8 * 1024;
@@ -191,13 +192,15 @@ int libxl__domain_build(libxl__gc *gc,
         vments[4] = "start_time";
         vments[5] = libxl__sprintf(gc, "%lu.%02d", 
start_time.tv_sec,(int)start_time.tv_usec/10000);
 
-        localents = libxl__calloc(gc, 7, sizeof(char *));
+        localents = libxl__calloc(gc, 9, sizeof(char *));
         localents[0] = "platform/acpi";
         localents[1] = (info->u.hvm.acpi) ? "1" : "0";
         localents[2] = "platform/acpi_s3";
         localents[3] = (info->u.hvm.acpi_s3) ? "1" : "0";
         localents[4] = "platform/acpi_s4";
         localents[5] = (info->u.hvm.acpi_s4) ? "1" : "0";
+        localents[6] = "platform/generation-id";
+        localents[7] = libxl__sprintf(gc, "0x%llx", info->u.hvm.generation_id);
 
         break;
     case LIBXL_DOMAIN_TYPE_PV:
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/libxl/libxl_types.idl       Tue Nov 29 10:48:54 2011 +0000
@@ -176,6 +176,7 @@ libxl_domain_build_info = Struct("domain
                                        ("vpt_align", bool),
                                        ("timer_mode", integer),
                                        ("nested_hvm", bool),
+                                       ("generation_id", uint64),
                                        ])),
                  ("pv", Struct(None, [("kernel", libxl_file_reference),
                                       ("slack_memkb", uint32),
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/libxl/libxlu_cfg.c
--- a/tools/libxl/libxlu_cfg.c  Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/libxl/libxlu_cfg.c  Tue Nov 29 10:48:54 2011 +0000
@@ -232,7 +232,35 @@ int xlu_cfg_get_long(const XLU_Config *c
     return 0;
 }
 
+int xlu_cfg_get_long_long(const XLU_Config *cfg, const char *n,
+                          long long *value_r) {
+    long long ll;
+    XLU_ConfigSetting *set;
+    int e;
+    char *ep;
 
+    e= find_atom(cfg,n,&set);  if (e) return e;
+    errno= 0; ll= strtoll(set->values[0], &ep, 0);
+    e= errno;
+    if (errno) {
+        e= errno;
+        assert(e==EINVAL || e==ERANGE);
+        fprintf(cfg->report,
+                "%s:%d: warning: parameter `%s' could not be parsed"
+                " as a number: %s\n",
+                cfg->filename, set->lineno, n, strerror(e));
+        return e;
+    }
+    if (*ep || ep==set->values[0]) {
+        fprintf(cfg->report,
+                "%s:%d: warning: parameter `%s' is not a valid number\n",
+                cfg->filename, set->lineno, n);
+        return EINVAL;
+    }
+    *value_r= ll;
+    return 0;
+}
+ 
 int xlu_cfg_get_list(const XLU_Config *cfg, const char *n,
                      XLU_ConfigList **list_r, int *entries_r, int dont_warn) {
     XLU_ConfigSetting *set;
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/libxl/libxlutil.h
--- a/tools/libxl/libxlutil.h   Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/libxl/libxlutil.h   Tue Nov 29 10:48:54 2011 +0000
@@ -48,6 +48,7 @@ void xlu_cfg_destroy(XLU_Config*);
 int xlu_cfg_get_string(const XLU_Config*, const char *n, const char **value_r);
 int xlu_cfg_replace_string(const XLU_Config *cfg, const char *n, char 
**value_r); /* free/strdup version */
 int xlu_cfg_get_long(const XLU_Config*, const char *n, long *value_r);
+int xlu_cfg_get_long_long(const XLU_Config*, const char *n, long long 
*value_r);
 
 int xlu_cfg_get_list(const XLU_Config*, const char *n,
                      XLU_ConfigList **list_r /* may be 0 */,
diff -r ec35c9c5a0c0 -r 58cdfa17fb88 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Tue Nov 29 10:48:54 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Tue Nov 29 10:48:54 2011 +0000
@@ -355,6 +355,7 @@ static void printf_info(int domid,
         printf("\t\t\t(vpt_align %d)\n", b_info->u.hvm.vpt_align);
         printf("\t\t\t(timer_mode %d)\n", b_info->u.hvm.timer_mode);
         printf("\t\t\t(nestedhvm %d)\n", b_info->u.hvm.nested_hvm);
+        printf("\t\t\t(generation_id %llx)\n", b_info->u.hvm.generation_id);
 
         printf("\t\t\t(device_model %s)\n", dm_info->device_model ? : 
"default");
         printf("\t\t\t(videoram %d)\n", dm_info->videoram);
@@ -523,6 +524,7 @@ static void parse_config_data(const char
 {
     const char *buf;
     long l;
+    long long ll;
     XLU_Config *config;
     XLU_ConfigList *vbds, *nics, *pcis, *cvfbs, *cpuids;
     int pci_power_mgmt = 0;
@@ -699,6 +701,8 @@ static void parse_config_data(const char
             b_info->u.hvm.timer_mode = l;
         if (!xlu_cfg_get_long (config, "nestedhvm", &l))
             b_info->u.hvm.nested_hvm = l;
+        if (!xlu_cfg_get_long_long (config, "generation_id", &ll))
+            b_info->u.hvm.generation_id = ll;
         break;
     case LIBXL_DOMAIN_TYPE_PV:
     {

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.