ia64/xen-unstable

changeset 13545:ff4f4596cb29

[HVM] Save/restore cleanups 05: save-format headers
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Sat Jan 20 11:17:42 2007 +0000 (2007-01-20)
parents 1fd5f1754cea
children 5dc5e6ba42d2
files xen/arch/x86/hvm/intercept.c xen/include/public/hvm/save.h
line diff
     1.1 --- a/xen/arch/x86/hvm/intercept.c	Sat Jan 20 11:17:41 2007 +0000
     1.2 +++ b/xen/arch/x86/hvm/intercept.c	Sat Jan 20 11:17:42 2007 +0000
     1.3 @@ -157,9 +157,6 @@ static inline void hvm_mmio_access(struc
     1.4      }
     1.5  }
     1.6  
     1.7 -/* save/restore support */
     1.8 -#define HVM_FILE_MAGIC   0x54381286
     1.9 -#define HVM_FILE_VERSION 0x00000001
    1.10  
    1.11  int hvm_register_savevm(struct domain *d,
    1.12                      const char *idstr,
    1.13 @@ -199,6 +196,7 @@ int hvm_save(struct vcpu *v, hvm_domain_
    1.14      uint32_t eax, ebx, ecx, edx;
    1.15      HVMStateEntry *se;
    1.16      char *chgset;
    1.17 +    struct hvm_save_header hdr;
    1.18  
    1.19      if (!is_hvm_vcpu(v)) {
    1.20          printk("hvm_save only for hvm guest!\n");
    1.21 @@ -206,8 +204,12 @@ int hvm_save(struct vcpu *v, hvm_domain_
    1.22      }
    1.23  
    1.24      memset(h, 0, sizeof(hvm_domain_context_t));
    1.25 -    hvm_put_32u(h, HVM_FILE_MAGIC);
    1.26 -    hvm_put_32u(h, HVM_FILE_VERSION);
    1.27 +
    1.28 +    hdr.magic = HVM_FILE_MAGIC;
    1.29 +    hdr.version = HVM_FILE_VERSION;
    1.30 +    cpuid(1, &eax, &ebx, &ecx, &edx);
    1.31 +    hdr.cpuid = eax;
    1.32 +    hvm_put_struct(h, &hdr);
    1.33  
    1.34      /* save xen changeset */
    1.35      chgset = strrchr(XEN_CHANGESET, ' ');
    1.36 @@ -220,10 +222,6 @@ int hvm_save(struct vcpu *v, hvm_domain_
    1.37      hvm_put_8u(h, len);
    1.38      hvm_put_buffer(h, chgset, len);
    1.39  
    1.40 -    /* save cpuid */
    1.41 -    cpuid(1, &eax, &ebx, &ecx, &edx);
    1.42 -    hvm_put_32u(h, eax);
    1.43 -
    1.44      for(se = v->domain->arch.hvm_domain.first_se; se != NULL; se = se->next) {
    1.45          /* ID string */
    1.46          len = strnlen(se->idstr, HVM_SE_IDSTR_LEN);
    1.47 @@ -274,13 +272,14 @@ static HVMStateEntry *find_se(struct dom
    1.48  
    1.49  int hvm_load(struct vcpu *v, hvm_domain_context_t *h)
    1.50  {
    1.51 -    uint32_t len, rec_len, rec_pos, magic, instance_id, version_id;
    1.52 +    uint32_t len, rec_len, rec_pos, instance_id, version_id;
    1.53      uint32_t eax, ebx, ecx, edx;
    1.54      HVMStateEntry *se;
    1.55      char idstr[HVM_SE_IDSTR_LEN];
    1.56      xen_changeset_info_t chgset;
    1.57      char *cur_chgset;
    1.58      int ret;
    1.59 +    struct hvm_save_header hdr;
    1.60  
    1.61      if (!is_hvm_vcpu(v)) {
    1.62          printk("hvm_load only for hvm guest!\n");
    1.63 @@ -294,18 +293,28 @@ int hvm_load(struct vcpu *v, hvm_domain_
    1.64  
    1.65      hvm_ctxt_seek(h, 0);
    1.66  
    1.67 -    magic = hvm_get_32u(h);
    1.68 -    if (magic != HVM_FILE_MAGIC) {
    1.69 +    hvm_get_struct(h, &hdr);
    1.70 +
    1.71 +    if (hdr.magic != HVM_FILE_MAGIC) {
    1.72          printk("HVM restore magic dismatch!\n");
    1.73          return -1;
    1.74      }
    1.75  
    1.76 -    magic = hvm_get_32u(h);
    1.77 -    if (magic != HVM_FILE_VERSION) {
    1.78 +    if (hdr.version != HVM_FILE_VERSION) {
    1.79          printk("HVM restore version dismatch!\n");
    1.80          return -1;
    1.81      }
    1.82  
    1.83 +    /* check cpuid */
    1.84 +    cpuid(1, &eax, &ebx, &ecx, &edx);
    1.85 +    /*TODO: need difine how big difference is acceptable */
    1.86 +    if (hdr.cpuid != eax)
    1.87 +        printk("warnings: try to restore hvm guest(0x%"PRIx32") "
    1.88 +               "on a different type processor(0x%"PRIx32").\n",
    1.89 +                hdr.cpuid,
    1.90 +                eax);
    1.91 +
    1.92 +
    1.93      /* check xen change set */
    1.94      cur_chgset = strrchr(XEN_CHANGESET, ' ');
    1.95      if ( cur_chgset )
    1.96 @@ -330,16 +339,6 @@ int hvm_load(struct vcpu *v, hvm_domain_
    1.97          printk("warnings: try to restore hvm guest when changeset is unavailable.\n");
    1.98  
    1.99  
   1.100 -    /* check cpuid */
   1.101 -    cpuid(1, &eax, &ebx, &ecx, &edx);
   1.102 -    ebx = hvm_get_32u(h);
   1.103 -    /*TODO: need difine how big difference is acceptable */
   1.104 -    if (ebx != eax)
   1.105 -        printk("warnings: try to restore hvm guest(0x%"PRIx32") "
   1.106 -               "on a different type processor(0x%"PRIx32").\n",
   1.107 -                ebx,
   1.108 -                eax);
   1.109 -
   1.110      while(1) {
   1.111          if (hvm_ctxt_end(h)) {
   1.112              break;
     2.1 --- a/xen/include/public/hvm/save.h	Sat Jan 20 11:17:41 2007 +0000
     2.2 +++ b/xen/include/public/hvm/save.h	Sat Jan 20 11:17:42 2007 +0000
     2.3 @@ -39,7 +39,20 @@
     2.4   * Internal mechanisms should be kept in Xen-private headers.
     2.5   */
     2.6  
     2.7 +/* 
     2.8 + * Save/restore header
     2.9 + */
    2.10  
    2.11 +#define HVM_SAVE_TYPE_HEADER 0
    2.12 +
    2.13 +#define HVM_FILE_MAGIC   0x54381286
    2.14 +#define HVM_FILE_VERSION 0x00000001
    2.15 +
    2.16 +struct hvm_save_header {
    2.17 +    uint32_t magic;
    2.18 +    uint32_t version;
    2.19 +    uint32_t cpuid;
    2.20 +};
    2.21  
    2.22  /*
    2.23   * Processor