ia64/xen-unstable

changeset 14827:a839e331f06f

HVM: First attempt at domain-resume on save-failure.

Not working yet as we are a bit too keen to kill the qemu-dm process,
before we know that the save has been successful.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Apr 12 14:13:04 2007 +0100 (2007-04-12)
parents 8f7f29f718a6
children 41471cc650a2 1fa9b5f1df8f
files tools/libxc/xc_domain.c tools/libxc/xc_hvm_build.c tools/libxc/xc_resume.c tools/libxc/xenctrl.h tools/libxc/xenguest.h tools/python/xen/xend/image.py
line diff
     1.1 --- a/tools/libxc/xc_domain.c	Thu Apr 12 13:21:26 2007 +0100
     1.2 +++ b/tools/libxc/xc_domain.c	Thu Apr 12 14:13:04 2007 +0100
     1.3 @@ -8,6 +8,7 @@
     1.4  
     1.5  #include "xc_private.h"
     1.6  #include <xen/memory.h>
     1.7 +#include <xen/hvm/hvm_op.h>
     1.8  
     1.9  int xc_domain_create(int xc_handle,
    1.10                       uint32_t ssidref,
    1.11 @@ -657,6 +658,44 @@ int xc_domain_send_trigger(int xc_handle
    1.12      return do_domctl(xc_handle, &domctl);
    1.13  }
    1.14  
    1.15 +int xc_set_hvm_param(int handle, domid_t dom, int param, unsigned long value)
    1.16 +{
    1.17 +    DECLARE_HYPERCALL;
    1.18 +    xen_hvm_param_t arg;
    1.19 +    int rc;
    1.20 +
    1.21 +    hypercall.op     = __HYPERVISOR_hvm_op;
    1.22 +    hypercall.arg[0] = HVMOP_set_param;
    1.23 +    hypercall.arg[1] = (unsigned long)&arg;
    1.24 +    arg.domid = dom;
    1.25 +    arg.index = param;
    1.26 +    arg.value = value;
    1.27 +    if ( lock_pages(&arg, sizeof(arg)) != 0 )
    1.28 +        return -1;
    1.29 +    rc = do_xen_hypercall(handle, &hypercall);
    1.30 +    unlock_pages(&arg, sizeof(arg));
    1.31 +    return rc;
    1.32 +}
    1.33 +
    1.34 +int xc_get_hvm_param(int handle, domid_t dom, int param, unsigned long *value)
    1.35 +{
    1.36 +    DECLARE_HYPERCALL;
    1.37 +    xen_hvm_param_t arg;
    1.38 +    int rc;
    1.39 +
    1.40 +    hypercall.op     = __HYPERVISOR_hvm_op;
    1.41 +    hypercall.arg[0] = HVMOP_get_param;
    1.42 +    hypercall.arg[1] = (unsigned long)&arg;
    1.43 +    arg.domid = dom;
    1.44 +    arg.index = param;
    1.45 +    if ( lock_pages(&arg, sizeof(arg)) != 0 )
    1.46 +        return -1;
    1.47 +    rc = do_xen_hypercall(handle, &hypercall);
    1.48 +    unlock_pages(&arg, sizeof(arg));
    1.49 +    *value = arg.value;
    1.50 +    return rc;
    1.51 +}
    1.52 +
    1.53  /*
    1.54   * Local variables:
    1.55   * mode: C
     2.1 --- a/tools/libxc/xc_hvm_build.c	Thu Apr 12 13:21:26 2007 +0100
     2.2 +++ b/tools/libxc/xc_hvm_build.c	Thu Apr 12 14:13:04 2007 +0100
     2.3 @@ -29,47 +29,6 @@ typedef union
     2.4      vcpu_guest_context_t c;
     2.5  } vcpu_guest_context_either_t;
     2.6  
     2.7 -
     2.8 -int xc_set_hvm_param(
     2.9 -    int handle, domid_t dom, int param, unsigned long value)
    2.10 -{
    2.11 -    DECLARE_HYPERCALL;
    2.12 -    xen_hvm_param_t arg;
    2.13 -    int rc;
    2.14 -
    2.15 -    hypercall.op     = __HYPERVISOR_hvm_op;
    2.16 -    hypercall.arg[0] = HVMOP_set_param;
    2.17 -    hypercall.arg[1] = (unsigned long)&arg;
    2.18 -    arg.domid = dom;
    2.19 -    arg.index = param;
    2.20 -    arg.value = value;
    2.21 -    if ( lock_pages(&arg, sizeof(arg)) != 0 )
    2.22 -        return -1;
    2.23 -    rc = do_xen_hypercall(handle, &hypercall);
    2.24 -    unlock_pages(&arg, sizeof(arg));
    2.25 -    return rc;
    2.26 -}
    2.27 -
    2.28 -int xc_get_hvm_param(
    2.29 -    int handle, domid_t dom, int param, unsigned long *value)
    2.30 -{
    2.31 -    DECLARE_HYPERCALL;
    2.32 -    xen_hvm_param_t arg;
    2.33 -    int rc;
    2.34 -
    2.35 -    hypercall.op     = __HYPERVISOR_hvm_op;
    2.36 -    hypercall.arg[0] = HVMOP_get_param;
    2.37 -    hypercall.arg[1] = (unsigned long)&arg;
    2.38 -    arg.domid = dom;
    2.39 -    arg.index = param;
    2.40 -    if ( lock_pages(&arg, sizeof(arg)) != 0 )
    2.41 -        return -1;
    2.42 -    rc = do_xen_hypercall(handle, &hypercall);
    2.43 -    unlock_pages(&arg, sizeof(arg));
    2.44 -    *value = arg.value;
    2.45 -    return rc;
    2.46 -}
    2.47 -
    2.48  static void build_e820map(void *e820_page, unsigned long long mem_size)
    2.49  {
    2.50      struct e820entry *e820entry =
     3.1 --- a/tools/libxc/xc_resume.c	Thu Apr 12 13:21:26 2007 +0100
     3.2 +++ b/tools/libxc/xc_resume.c	Thu Apr 12 14:13:04 2007 +0100
     3.3 @@ -3,24 +3,71 @@
     3.4  #include "xg_save_restore.h"
     3.5  
     3.6  #if defined(__i386__) || defined(__x86_64__)
     3.7 +
     3.8 +#include <xen/foreign/x86_32.h>
     3.9 +#include <xen/foreign/x86_64.h>
    3.10 +#include <xen/hvm/params.h>
    3.11 +
    3.12 +/* Need to provide the right flavour of vcpu context for Xen */
    3.13 +typedef union
    3.14 +{
    3.15 +    vcpu_guest_context_x86_64_t c64;
    3.16 +    vcpu_guest_context_x86_32_t c32;   
    3.17 +    vcpu_guest_context_t c;
    3.18 +} vcpu_guest_context_either_t;
    3.19 +
    3.20  static int modify_returncode(int xc_handle, uint32_t domid)
    3.21  {
    3.22 -    vcpu_guest_context_t ctxt;
    3.23 +    vcpu_guest_context_either_t ctxt;
    3.24 +    xc_dominfo_t info;
    3.25 +    xen_capabilities_info_t caps;
    3.26      int rc;
    3.27  
    3.28 -    if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt)) != 0 )
    3.29 +    if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
    3.30 +    {
    3.31 +        PERROR("Could not get domain info");
    3.32 +        return -1;
    3.33 +    }
    3.34 +
    3.35 +    /* HVM guests without PV drivers do not have a return code to modify. */
    3.36 +    if ( info.hvm )
    3.37 +    {
    3.38 +        unsigned long irq = 0;
    3.39 +        xc_get_hvm_param(xc_handle, domid, HVM_PARAM_CALLBACK_IRQ, &irq);
    3.40 +        if ( !irq )
    3.41 +            return 0;
    3.42 +    }
    3.43 +
    3.44 +    if ( xc_version(xc_handle, XENVER_capabilities, &caps) != 0 )
    3.45 +    {
    3.46 +        PERROR("Could not get Xen capabilities\n");
    3.47 +        return -1;
    3.48 +    }
    3.49 +
    3.50 +    if ( (rc = xc_vcpu_getcontext(xc_handle, domid, 0, &ctxt.c)) != 0 )
    3.51          return rc;
    3.52 -    ctxt.user_regs.eax = 1;
    3.53 -    if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt)) != 0 )
    3.54 +
    3.55 +    if ( !info.hvm )
    3.56 +        ctxt.c.user_regs.eax = 1;
    3.57 +    else if ( strstr(caps, "x86_64") )
    3.58 +        ctxt.c64.user_regs.eax = 1;
    3.59 +    else
    3.60 +        ctxt.c32.user_regs.eax = 1;
    3.61 +
    3.62 +    if ( (rc = xc_vcpu_setcontext(xc_handle, domid, 0, &ctxt.c)) != 0 )
    3.63          return rc;
    3.64  
    3.65      return 0;
    3.66  }
    3.67 +
    3.68  #else
    3.69 +
    3.70  static int modify_returncode(int xc_handle, uint32_t domid)
    3.71  {
    3.72      return 0;
    3.73 +
    3.74  }
    3.75 +
    3.76  #endif
    3.77  
    3.78  static int xc_domain_resume_cooperative(int xc_handle, uint32_t domid)
    3.79 @@ -65,6 +112,12 @@ static int xc_domain_resume_any(int xc_h
    3.80       * (x86 only) Rewrite store_mfn and console_mfn back to MFN (from PFN).
    3.81       */
    3.82  #if defined(__i386__) || defined(__x86_64__)
    3.83 +    if ( info.hvm )
    3.84 +    {
    3.85 +        ERROR("Cannot resume uncooperative HVM guests");
    3.86 +        return rc;
    3.87 +    }
    3.88 +
    3.89      /* Map the shared info frame */
    3.90      shinfo = xc_map_foreign_range(xc_handle, domid, PAGE_SIZE,
    3.91                                    PROT_READ, info.shared_info_frame);
     4.1 --- a/tools/libxc/xenctrl.h	Thu Apr 12 13:21:26 2007 +0100
     4.2 +++ b/tools/libxc/xenctrl.h	Thu Apr 12 14:13:04 2007 +0100
     4.3 @@ -840,6 +840,9 @@ const char *xc_error_code_to_desc(int co
     4.4   */
     4.5  xc_error_handler xc_set_error_handler(xc_error_handler handler);
     4.6  
     4.7 +int xc_set_hvm_param(int handle, domid_t dom, int param, unsigned long value);
     4.8 +int xc_get_hvm_param(int handle, domid_t dom, int param, unsigned long *value);
     4.9 +
    4.10  /* PowerPC specific. */
    4.11  int xc_alloc_real_mode_area(int xc_handle,
    4.12                              uint32_t domid,
     5.1 --- a/tools/libxc/xenguest.h	Thu Apr 12 13:21:26 2007 +0100
     5.2 +++ b/tools/libxc/xenguest.h	Thu Apr 12 14:13:04 2007 +0100
     5.3 @@ -136,11 +136,6 @@ int xc_hvm_build_mem(int xc_handle,
     5.4                       const char *image_buffer,
     5.5                       unsigned long image_size);
     5.6  
     5.7 -int xc_set_hvm_param(
     5.8 -    int handle, domid_t dom, int param, unsigned long value);
     5.9 -int xc_get_hvm_param(
    5.10 -    int handle, domid_t dom, int param, unsigned long *value);
    5.11 -
    5.12  /* PowerPC specific. */
    5.13  int xc_prose_build(int xc_handle,
    5.14                     uint32_t domid,
     6.1 --- a/tools/python/xen/xend/image.py	Thu Apr 12 13:21:26 2007 +0100
     6.2 +++ b/tools/python/xen/xend/image.py	Thu Apr 12 14:13:04 2007 +0100
     6.3 @@ -284,14 +284,16 @@ class HVMImageHandler(ImageHandler):
     6.4          log.debug("acpi           = %d", self.acpi)
     6.5          log.debug("apic           = %d", self.apic)
     6.6  
     6.7 -        return xc.hvm_build(domid          = self.vm.getDomid(),
     6.8 -                            image          = self.kernel,
     6.9 -                            store_evtchn   = store_evtchn,
    6.10 -                            memsize        = mem_mb,
    6.11 -                            vcpus          = self.vm.getVCpuCount(),
    6.12 -                            pae            = self.pae,
    6.13 -                            acpi           = self.acpi,
    6.14 -                            apic           = self.apic)
    6.15 +        rc = xc.hvm_build(domid          = self.vm.getDomid(),
    6.16 +                          image          = self.kernel,
    6.17 +                          store_evtchn   = store_evtchn,
    6.18 +                          memsize        = mem_mb,
    6.19 +                          vcpus          = self.vm.getVCpuCount(),
    6.20 +                          pae            = self.pae,
    6.21 +                          acpi           = self.acpi,
    6.22 +                          apic           = self.apic)
    6.23 +        rc['notes'] = { 'SUSPEND_CANCEL': 1 }
    6.24 +        return rc
    6.25  
    6.26      # Return a list of cmd line args to the device models based on the
    6.27      # xm config file