ia64/xen-unstable

changeset 14659:e3dc8cea5bc0

[HVM] Save/restore: PV-on-HVM driver save/restore support
Signed-off-by: Zhai Edwin <edwin.zhai@intel.com>
author Tim Deegan <Tim.Deegan@xensource.com>
date Thu Mar 29 16:27:52 2007 +0000 (2007-03-29)
parents 2317e0cdd07d
children 3681f91a91e8
files linux-2.6-xen-sparse/drivers/xen/core/reboot.c tools/python/xen/lowlevel/xc/xc.c tools/python/xen/xend/XendConstants.py tools/python/xen/xend/XendDomainInfo.py unmodified_drivers/linux-2.6/platform-pci/platform-pci.c xen/arch/x86/hvm/hvm.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Thu Mar 29 15:33:32 2007 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Thu Mar 29 16:27:52 2007 +0000
     1.3 @@ -33,7 +33,24 @@ static DECLARE_WORK(shutdown_work, __shu
     1.4  #ifdef CONFIG_XEN
     1.5  int __xen_suspend(int fast_suspend);
     1.6  #else
     1.7 -#define __xen_suspend(fast_suspend) 0
     1.8 +extern void xenbus_suspend(void);
     1.9 +extern void xenbus_resume(void);
    1.10 +extern void platform_pci_suspend(void);
    1.11 +extern void platform_pci_resume(void);
    1.12 +int __xen_suspend(int fast_suspend)
    1.13 +{
    1.14 +	xenbus_suspend();
    1.15 +	platform_pci_suspend();
    1.16 +
    1.17 +	/* pvdrv sleep in this hyper-call when save */
    1.18 +	HYPERVISOR_shutdown(SHUTDOWN_suspend);
    1.19 +
    1.20 +	platform_pci_resume();
    1.21 +	xenbus_resume();
    1.22 +	printk("PV stuff on HVM resume successfully!\n");
    1.23 +
    1.24 +	return 0;
    1.25 +}
    1.26  #endif
    1.27  
    1.28  static int shutdown_process(void *__unused)
     2.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Thu Mar 29 15:33:32 2007 +0000
     2.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Thu Mar 29 16:27:52 2007 +0000
     2.3 @@ -467,6 +467,26 @@ static PyObject *pyxc_linux_build(XcObje
     2.4      return pyxc_error_to_exception();
     2.5  }
     2.6  
     2.7 +static PyObject *pyxc_get_hvm_param(XcObject *self,
     2.8 +                                    PyObject *args,
     2.9 +                                    PyObject *kwds)
    2.10 +{
    2.11 +    uint32_t dom;
    2.12 +    int param;
    2.13 +    unsigned long value;
    2.14 +
    2.15 +    static char *kwd_list[] = { "domid", "param", NULL }; 
    2.16 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i|i", kwd_list,
    2.17 +                                      &dom, &param) )
    2.18 +        return NULL;
    2.19 +
    2.20 +    if ( xc_get_hvm_param(self->xc_handle, dom, param, &value) != 0 )
    2.21 +        return pyxc_error_to_exception();
    2.22 +
    2.23 +    return Py_BuildValue("i", value);
    2.24 +
    2.25 +}
    2.26 +
    2.27  static PyObject *pyxc_hvm_build(XcObject *self,
    2.28                                  PyObject *args,
    2.29                                  PyObject *kwds)
    2.30 @@ -1225,6 +1245,14 @@ static PyMethodDef pyxc_methods[] = {
    2.31        " vcpus   [int, 1]:   Number of Virtual CPUS in domain.\n\n"
    2.32        "Returns: [int] 0 on success; -1 on error.\n" },
    2.33  
    2.34 +    { "hvm_get_param", 
    2.35 +      (PyCFunction)pyxc_get_hvm_param, 
    2.36 +      METH_VARARGS | METH_KEYWORDS, "\n"
    2.37 +      "get a parameter of HVM guest OS.\n"
    2.38 +      " dom     [int]:      Identifier of domain to build into.\n"
    2.39 +      " param   [int]:      No. of HVM param.\n"
    2.40 +      "Returns: [int] value of the param.\n" },
    2.41 +
    2.42      { "sched_id_get",
    2.43        (PyCFunction)pyxc_sched_id_get,
    2.44        METH_NOARGS, "\n"
     3.1 --- a/tools/python/xen/xend/XendConstants.py	Thu Mar 29 15:33:32 2007 +0000
     3.2 +++ b/tools/python/xen/xend/XendConstants.py	Thu Mar 29 16:27:52 2007 +0000
     3.3 @@ -37,6 +37,13 @@ DOMAIN_SHUTDOWN_REASONS = {
     3.4  REVERSE_DOMAIN_SHUTDOWN_REASONS = \
     3.5      dict([(y, x) for x, y in DOMAIN_SHUTDOWN_REASONS.items()])
     3.6  
     3.7 +HVM_PARAM_CALLBACK_IRQ = 0
     3.8 +HVM_PARAM_STORE_PFN    = 1
     3.9 +HVM_PARAM_STORE_EVTCHN = 2
    3.10 +HVM_PARAM_PAE_ENABLED  = 4
    3.11 +HVM_PARAM_IOREQ_PFN    = 5
    3.12 +HVM_PARAM_BUFIOREQ_PFN = 6
    3.13 +
    3.14  restart_modes = [
    3.15      "restart",
    3.16      "destroy",
     4.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 29 15:33:32 2007 +0000
     4.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 29 16:27:52 2007 +0000
     4.3 @@ -448,11 +448,12 @@ class XendDomainInfo:
     4.4          self._removeVm('xend/previous_restart_time')
     4.5          self.storeDom("control/shutdown", reason)
     4.6  
     4.7 -        ## shutdown hypercall for hvm domain desides xenstore write
     4.8 -        if self.info.is_hvm():
     4.9 -            for code in DOMAIN_SHUTDOWN_REASONS.keys():
    4.10 -                if DOMAIN_SHUTDOWN_REASONS[code] == reason:
    4.11 -                    break
    4.12 +        ## HVM domain shutdown itself if has PV driver,
    4.13 +        ## otherwise remote shutdown it
    4.14 +        hvm_pvdrv = xc.hvm_get_param(self.domid, HVM_PARAM_CALLBACK_IRQ)
    4.15 +        if self.info.is_hvm() and not hvm_pvdrv:
    4.16 +            code = REVERSE_DOMAIN_SHUTDOWN_REASONS[reason]
    4.17 +            log.info("HVM save:remote shutdown dom %d!", self.domid)
    4.18              xc.domain_shutdown(self.domid, code)
    4.19  
    4.20  
     5.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Thu Mar 29 15:33:32 2007 +0000
     5.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Thu Mar 29 16:27:52 2007 +0000
     5.3 @@ -36,6 +36,7 @@
     5.4  #include <asm/pgtable.h>
     5.5  #include <xen/interface/memory.h>
     5.6  #include <xen/features.h>
     5.7 +#include <xen/gnttab.h>
     5.8  #ifdef __ia64__
     5.9  #include <asm/xen/xencomm.h>
    5.10  #endif
    5.11 @@ -61,9 +62,11 @@ MODULE_LICENSE("GPL");
    5.12  unsigned long *phys_to_machine_mapping;
    5.13  EXPORT_SYMBOL(phys_to_machine_mapping);
    5.14  
    5.15 +static unsigned long shared_info_frame;
    5.16 +static uint64_t callback_via;
    5.17 +
    5.18  static int __devinit init_xen_info(void)
    5.19  {
    5.20 -	unsigned long shared_info_frame;
    5.21  	struct xen_add_to_physmap xatp;
    5.22  	extern void *shared_info_area;
    5.23  
    5.24 @@ -219,7 +222,6 @@ static int __devinit platform_pci_init(s
    5.25  	int i, ret;
    5.26  	long ioaddr, iolen;
    5.27  	long mmio_addr, mmio_len;
    5.28 -	uint64_t callback_via;
    5.29  
    5.30  	i = pci_enable_device(pdev);
    5.31  	if (i)
    5.32 @@ -303,6 +305,35 @@ static struct pci_driver platform_driver
    5.33  
    5.34  static int pci_device_registered;
    5.35  
    5.36 +void platform_pci_suspend(void)
    5.37 +{
    5.38 +	gnttab_suspend();
    5.39 +}
    5.40 +EXPORT_SYMBOL_GPL(platform_pci_suspend);
    5.41 +
    5.42 +void platform_pci_resume(void)
    5.43 +{
    5.44 +	struct xen_add_to_physmap xatp;
    5.45 +	phys_to_machine_mapping = NULL;
    5.46 +
    5.47 +	/* do 2 things for PV driver restore on HVM
    5.48 +	 * 1: rebuild share info
    5.49 +	 * 2: set callback irq again
    5.50 +	 */
    5.51 +	xatp.domid = DOMID_SELF;
    5.52 +	xatp.idx = 0;
    5.53 +	xatp.space = XENMAPSPACE_shared_info;
    5.54 +	xatp.gpfn = shared_info_frame;
    5.55 +	if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
    5.56 +		BUG();
    5.57 +
    5.58 +	if (( set_callback_via(callback_via)))
    5.59 +		printk("platform_pci_resume failure!\n");
    5.60 +
    5.61 +	gnttab_resume();
    5.62 +}
    5.63 +EXPORT_SYMBOL_GPL(platform_pci_resume);
    5.64 +
    5.65  static int __init platform_pci_module_init(void)
    5.66  {
    5.67  	int rc;
     6.1 --- a/xen/arch/x86/hvm/hvm.c	Thu Mar 29 15:33:32 2007 +0000
     6.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Mar 29 16:27:52 2007 +0000
     6.3 @@ -556,6 +556,7 @@ static hvm_hypercall_t *hvm_hypercall_ta
     6.4      HYPERCALL(multicall),
     6.5      HYPERCALL(xen_version),
     6.6      HYPERCALL(event_channel_op),
     6.7 +    HYPERCALL(sched_op),
     6.8      HYPERCALL(hvm_op)
     6.9  };
    6.10