direct-io.hg

changeset 14514:1584263f9fc5

merge with xen-unstable.hg
author awilliam@xenbuild2.aw
date Thu Mar 15 09:04:23 2007 -0600 (2007-03-15)
parents a230a1a167dc 809f36b1b685
children e014b94333aa
files xen/arch/ia64/xen/domain.c xen/include/asm-x86/hvm/svm/vmmcall.h
line diff
     1.1 --- a/buildconfigs/conf.linux-native/00_xen_to_native	Thu Mar 15 09:00:42 2007 -0600
     1.2 +++ b/buildconfigs/conf.linux-native/00_xen_to_native	Thu Mar 15 09:04:23 2007 -0600
     1.3 @@ -74,8 +74,10 @@ CONFIG_SERIAL_CORE_CONSOLE=y
     1.4  # CONFIG_XEN_DISABLE_SERIAL is not set
     1.5  # CONFIG_XEN_SYSFS is not set
     1.6  # CONFIG_XEN_COMPAT_030002_AND_LATER is not set
     1.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     1.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     1.9  # CONFIG_XEN_COMPAT_030002 is not set
    1.10 +# CONFIG_XEN_COMPAT_030004 is not set
    1.11  # CONFIG_HAVE_ARCH_ALLOC_SKB is not set
    1.12  # CONFIG_HAVE_ARCH_DEV_ALLOC_SKB is not set
    1.13  # CONFIG_NO_IDLE_HZ is not set
     2.1 --- a/buildconfigs/linux-defconfig_xen0_ia64	Thu Mar 15 09:00:42 2007 -0600
     2.2 +++ b/buildconfigs/linux-defconfig_xen0_ia64	Thu Mar 15 09:04:23 2007 -0600
     2.3 @@ -1647,8 +1647,10 @@ CONFIG_XEN_NETDEV_FRONTEND=y
     2.4  CONFIG_XEN_DISABLE_SERIAL=y
     2.5  CONFIG_XEN_SYSFS=y
     2.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     2.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     2.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     2.9  CONFIG_XEN_COMPAT_030002=y
    2.10 +CONFIG_XEN_COMPAT_030004=y
    2.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    2.12  CONFIG_NO_IDLE_HZ=y
    2.13  CONFIG_XEN_DEVMEM=y
     3.1 --- a/buildconfigs/linux-defconfig_xen0_x86_32	Thu Mar 15 09:00:42 2007 -0600
     3.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_32	Thu Mar 15 09:04:23 2007 -0600
     3.3 @@ -1411,8 +1411,10 @@ CONFIG_XEN_SCRUB_PAGES=y
     3.4  CONFIG_XEN_DISABLE_SERIAL=y
     3.5  CONFIG_XEN_SYSFS=y
     3.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     3.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     3.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     3.9  CONFIG_XEN_COMPAT_030002=y
    3.10 +CONFIG_XEN_COMPAT_030004=y
    3.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    3.12  CONFIG_NO_IDLE_HZ=y
    3.13  CONFIG_XEN_UTIL=y
     4.1 --- a/buildconfigs/linux-defconfig_xen0_x86_64	Thu Mar 15 09:00:42 2007 -0600
     4.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_64	Thu Mar 15 09:04:23 2007 -0600
     4.3 @@ -1361,8 +1361,10 @@ CONFIG_XEN_SCRUB_PAGES=y
     4.4  CONFIG_XEN_DISABLE_SERIAL=y
     4.5  CONFIG_XEN_SYSFS=y
     4.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     4.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     4.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     4.9  CONFIG_XEN_COMPAT_030002=y
    4.10 +CONFIG_XEN_COMPAT_030004=y
    4.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    4.12  CONFIG_NO_IDLE_HZ=y
    4.13  CONFIG_XEN_UTIL=y
     5.1 --- a/buildconfigs/linux-defconfig_xenU_ia64	Thu Mar 15 09:00:42 2007 -0600
     5.2 +++ b/buildconfigs/linux-defconfig_xenU_ia64	Thu Mar 15 09:04:23 2007 -0600
     5.3 @@ -1489,8 +1489,10 @@ CONFIG_XEN_KEYBOARD=y
     5.4  # CONFIG_XEN_DISABLE_SERIAL is not set
     5.5  CONFIG_XEN_SYSFS=y
     5.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     5.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     5.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     5.9  CONFIG_XEN_COMPAT_030002=y
    5.10 +CONFIG_XEN_COMPAT_030004=y
    5.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    5.12  CONFIG_NO_IDLE_HZ=y
    5.13  CONFIG_XEN_DEVMEM=y
     6.1 --- a/buildconfigs/linux-defconfig_xenU_x86_32	Thu Mar 15 09:00:42 2007 -0600
     6.2 +++ b/buildconfigs/linux-defconfig_xenU_x86_32	Thu Mar 15 09:04:23 2007 -0600
     6.3 @@ -920,8 +920,10 @@ CONFIG_XEN_SCRUB_PAGES=y
     6.4  CONFIG_XEN_DISABLE_SERIAL=y
     6.5  CONFIG_XEN_SYSFS=y
     6.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     6.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     6.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     6.9  CONFIG_XEN_COMPAT_030002=y
    6.10 +CONFIG_XEN_COMPAT_030004=y
    6.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    6.12  CONFIG_NO_IDLE_HZ=y
    6.13  CONFIG_XEN_UTIL=y
     7.1 --- a/buildconfigs/linux-defconfig_xenU_x86_64	Thu Mar 15 09:00:42 2007 -0600
     7.2 +++ b/buildconfigs/linux-defconfig_xenU_x86_64	Thu Mar 15 09:04:23 2007 -0600
     7.3 @@ -1216,8 +1216,10 @@ CONFIG_XEN_SCRUB_PAGES=y
     7.4  CONFIG_XEN_DISABLE_SERIAL=y
     7.5  CONFIG_XEN_SYSFS=y
     7.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     7.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     7.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     7.9  CONFIG_XEN_COMPAT_030002=y
    7.10 +CONFIG_XEN_COMPAT_030004=y
    7.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    7.12  CONFIG_NO_IDLE_HZ=y
    7.13  CONFIG_XEN_UTIL=y
     8.1 --- a/buildconfigs/linux-defconfig_xen_ia64	Thu Mar 15 09:00:42 2007 -0600
     8.2 +++ b/buildconfigs/linux-defconfig_xen_ia64	Thu Mar 15 09:04:23 2007 -0600
     8.3 @@ -1648,8 +1648,10 @@ CONFIG_XEN_KEYBOARD=y
     8.4  CONFIG_XEN_DISABLE_SERIAL=y
     8.5  CONFIG_XEN_SYSFS=y
     8.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     8.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     8.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     8.9  CONFIG_XEN_COMPAT_030002=y
    8.10 +CONFIG_XEN_COMPAT_030004=y
    8.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    8.12  CONFIG_NO_IDLE_HZ=y
    8.13  CONFIG_XEN_DEVMEM=y
     9.1 --- a/buildconfigs/linux-defconfig_xen_x86_32	Thu Mar 15 09:00:42 2007 -0600
     9.2 +++ b/buildconfigs/linux-defconfig_xen_x86_32	Thu Mar 15 09:04:23 2007 -0600
     9.3 @@ -3271,8 +3271,10 @@ CONFIG_XEN_SCRUB_PAGES=y
     9.4  CONFIG_XEN_DISABLE_SERIAL=y
     9.5  CONFIG_XEN_SYSFS=y
     9.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
     9.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
     9.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
     9.9  CONFIG_XEN_COMPAT_030002=y
    9.10 +CONFIG_XEN_COMPAT_030004=y
    9.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
    9.12  CONFIG_NO_IDLE_HZ=y
    9.13  CONFIG_XEN_UTIL=y
    10.1 --- a/buildconfigs/linux-defconfig_xen_x86_64	Thu Mar 15 09:00:42 2007 -0600
    10.2 +++ b/buildconfigs/linux-defconfig_xen_x86_64	Thu Mar 15 09:04:23 2007 -0600
    10.3 @@ -3101,8 +3101,10 @@ CONFIG_XEN_SCRUB_PAGES=y
    10.4  CONFIG_XEN_DISABLE_SERIAL=y
    10.5  CONFIG_XEN_SYSFS=y
    10.6  CONFIG_XEN_COMPAT_030002_AND_LATER=y
    10.7 +# CONFIG_XEN_COMPAT_030004_AND_LATER is not set
    10.8  # CONFIG_XEN_COMPAT_LATEST_ONLY is not set
    10.9  CONFIG_XEN_COMPAT_030002=y
   10.10 +CONFIG_XEN_COMPAT_030004=y
   10.11  CONFIG_HAVE_IRQ_IGNORE_UNHANDLED=y
   10.12  CONFIG_NO_IDLE_HZ=y
   10.13  CONFIG_XEN_UTIL=y
    11.1 --- a/docs/src/user.tex	Thu Mar 15 09:00:42 2007 -0600
    11.2 +++ b/docs/src/user.tex	Thu Mar 15 09:04:23 2007 -0600
    11.3 @@ -3179,6 +3179,11 @@ editing \path{grub.conf}.
    11.4    one of 80x25, 80x28, 80x30, 80x34, 80x43, 80x50, 80x60.
    11.5    \item[ keep ] Keep the VGA console even after domain 0 boots.
    11.6    \end{description}
    11.7 +\item [ console\_to\_ring ] Place guest console output into the
    11.8 +  hypervisor console ring buffer. This is disabled by default.
    11.9 +  When enabled, both hypervisor output and guest console output
   11.10 +  is available from the ring buffer. This can be useful for logging
   11.11 +  and/or remote presentation of console data.
   11.12  \item [ sync\_console ] Force synchronous console output. This is
   11.13    useful if you system fails unexpectedly before it has sent all
   11.14    available output to the console. In most cases Xen will
    12.1 --- a/docs/xen-api/todo.tex	Thu Mar 15 09:00:42 2007 -0600
    12.2 +++ b/docs/xen-api/todo.tex	Thu Mar 15 09:04:23 2007 -0600
    12.3 @@ -91,17 +91,10 @@ same subnet.
    12.4  
    12.5  \end{itemize}
    12.6  
    12.7 -\item TPM
    12.8 +\item ACM
    12.9  \begin{itemize}
   12.10  
   12.11 -\item Would it not be better to have a class TPM and a member TPMs ((TPM ref)
   12.12 -Set) containing an array of zero or one references to TPMs? I assume that
   12.13 -an empty array would make it clear that no TPM is associated with the VM
   12.14 -instead of encoding its existence into TPM/instance or TPM/backend
   12.15 -somehow. The current members instance and backend could then be moved into
   12.16 -the TPM class.
   12.17 -
   12.18 -\item Also a Xen system can be running an access control policy where each
   12.19 +\item A Xen system can be running an access control policy where each
   12.20  VM's run-time access to resources is restricted by the label it has been given
   12.21  compared to those of the resources. Currently a VM's configuration file may
   12.22  contain a line like access\_control[policy='$<$name of the system's
    13.1 --- a/docs/xen-api/xenapi-datamodel.tex	Thu Mar 15 09:00:42 2007 -0600
    13.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Thu Mar 15 09:04:23 2007 -0600
    13.3 @@ -1039,7 +1039,6 @@ Quals & Field & Type & Description \\
    13.4  $\mathit{RW}$ &  {\tt memory/dynamic\_max} & int & Dynamic maximum (bytes) \\
    13.5  $\mathit{RW}$ &  {\tt memory/dynamic\_min} & int & Dynamic minimum (bytes) \\
    13.6  $\mathit{RW}$ &  {\tt memory/static\_min} & int & Statically-set (i.e. absolute) mininum (bytes) \\
    13.7 -$\mathit{RW}$ &  {\tt VCPUs/policy} & string & the name of the VCPU scheduling policy to be applied \\
    13.8  $\mathit{RW}$ &  {\tt VCPUs/params} & (string $\rightarrow$ string) Map & configuration parameters for the selected VCPU policy \\
    13.9  $\mathit{RW}$ &  {\tt VCPUs/max} & int & Max number of VCPUs \\
   13.10  $\mathit{RW}$ &  {\tt VCPUs/at\_startup} & int & Boot number of VCPUs \\
   13.11 @@ -2178,72 +2177,6 @@ void
   13.12  \vspace{0.3cm}
   13.13  \vspace{0.3cm}
   13.14  \vspace{0.3cm}
   13.15 -\subsubsection{RPC name:~get\_VCPUs\_policy}
   13.16 -
   13.17 -{\bf Overview:} 
   13.18 -Get the VCPUs/policy field of the given VM.
   13.19 -
   13.20 - \noindent {\bf Signature:} 
   13.21 -\begin{verbatim} string get_VCPUs_policy (session_id s, VM ref self)\end{verbatim}
   13.22 -
   13.23 -
   13.24 -\noindent{\bf Arguments:}
   13.25 -
   13.26 - 
   13.27 -\vspace{0.3cm}
   13.28 -\begin{tabular}{|c|c|p{7cm}|}
   13.29 - \hline
   13.30 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   13.31 -{\tt VM ref } & self & reference to the object \\ \hline 
   13.32 -
   13.33 -\end{tabular}
   13.34 -
   13.35 -\vspace{0.3cm}
   13.36 -
   13.37 - \noindent {\bf Return Type:} 
   13.38 -{\tt 
   13.39 -string
   13.40 -}
   13.41 -
   13.42 -
   13.43 -value of the field
   13.44 -\vspace{0.3cm}
   13.45 -\vspace{0.3cm}
   13.46 -\vspace{0.3cm}
   13.47 -\subsubsection{RPC name:~set\_VCPUs\_policy}
   13.48 -
   13.49 -{\bf Overview:} 
   13.50 -Set the VCPUs/policy field of the given VM.
   13.51 -
   13.52 - \noindent {\bf Signature:} 
   13.53 -\begin{verbatim} void set_VCPUs_policy (session_id s, VM ref self, string value)\end{verbatim}
   13.54 -
   13.55 -
   13.56 -\noindent{\bf Arguments:}
   13.57 -
   13.58 - 
   13.59 -\vspace{0.3cm}
   13.60 -\begin{tabular}{|c|c|p{7cm}|}
   13.61 - \hline
   13.62 -{\bf type} & {\bf name} & {\bf description} \\ \hline
   13.63 -{\tt VM ref } & self & reference to the object \\ \hline 
   13.64 -
   13.65 -{\tt string } & value & New value to set \\ \hline 
   13.66 -
   13.67 -\end{tabular}
   13.68 -
   13.69 -\vspace{0.3cm}
   13.70 -
   13.71 - \noindent {\bf Return Type:} 
   13.72 -{\tt 
   13.73 -void
   13.74 -}
   13.75 -
   13.76 -
   13.77 -
   13.78 -\vspace{0.3cm}
   13.79 -\vspace{0.3cm}
   13.80 -\vspace{0.3cm}
   13.81  \subsubsection{RPC name:~get\_VCPUs\_params}
   13.82  
   13.83  {\bf Overview:} 
    14.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Thu Mar 15 09:00:42 2007 -0600
    14.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Thu Mar 15 09:04:23 2007 -0600
    14.3 @@ -1010,7 +1010,7 @@ static void stop_hz_timer(void)
    14.4  	singleshot.timeout_abs_ns = jiffies_to_st(j);
    14.5  	singleshot.flags = 0;
    14.6  	rc = HYPERVISOR_vcpu_op(VCPUOP_set_singleshot_timer, cpu, &singleshot);
    14.7 -#ifdef XEN_COMPAT_030004
    14.8 +#ifdef CONFIG_XEN_COMPAT_030004
    14.9  	if (rc) {
   14.10  		BUG_ON(rc != -ENOSYS);
   14.11  		rc = HYPERVISOR_set_timer_op(singleshot.timeout_abs_ns);
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Thu Mar 15 09:00:42 2007 -0600
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Thu Mar 15 09:04:23 2007 -0600
    15.3 @@ -299,7 +299,9 @@ static void tap_backend_changed(struct x
    15.4  	 * and disk info to xenstore
    15.5  	 */
    15.6  	err = xenbus_gather(XBT_NIL, dev->nodename, "info", "%lu", &info, 
    15.7 -			    NULL);	
    15.8 +			    NULL);
    15.9 +	if (XENBUS_EXIST_ERR(err))
   15.10 +		return;
   15.11  	if (err) {
   15.12  		xenbus_dev_error(dev, err, "getting info");
   15.13  		return;
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Thu Mar 15 09:00:42 2007 -0600
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/char/mem.c	Thu Mar 15 09:04:23 2007 -0600
    16.3 @@ -27,7 +27,7 @@
    16.4  #include <asm/hypervisor.h>
    16.5  
    16.6  #ifndef ARCH_HAS_VALID_PHYS_ADDR_RANGE
    16.7 -static inline int valid_phys_addr_range(unsigned long addr, size_t *count)
    16.8 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
    16.9  {
   16.10  	return 1;
   16.11  }
   16.12 @@ -44,7 +44,7 @@ static ssize_t read_mem(struct file * fi
   16.13  	ssize_t read = 0, sz;
   16.14  	void __iomem *v;
   16.15  
   16.16 -	if (!valid_phys_addr_range(p, &count))
   16.17 +	if (!valid_phys_addr_range(p, count))
   16.18  		return -EFAULT;
   16.19  
   16.20  	while (count > 0) {
   16.21 @@ -95,7 +95,7 @@ static ssize_t write_mem(struct file * f
   16.22  	ssize_t written = 0, sz;
   16.23  	void __iomem *v;
   16.24  
   16.25 -	if (!valid_phys_addr_range(p, &count))
   16.26 +	if (!valid_phys_addr_range(p, count))
   16.27  		return -EFAULT;
   16.28  
   16.29  	while (count > 0) {
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Thu Mar 15 09:00:42 2007 -0600
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Thu Mar 15 09:04:23 2007 -0600
    17.3 @@ -348,8 +348,11 @@ void xencons_rx(char *buf, unsigned len,
    17.4  #ifdef CONFIG_MAGIC_SYSRQ
    17.5  		if (sysrq_enabled) {
    17.6  			if (buf[i] == '\x0f') { /* ^O */
    17.7 -				sysrq_requested = jiffies;
    17.8 -				continue; /* don't print the sysrq key */
    17.9 +				if (!sysrq_requested) {
   17.10 +					sysrq_requested = jiffies;
   17.11 +					continue; /* don't print sysrq key */
   17.12 +				}
   17.13 +				sysrq_requested = 0;
   17.14  			} else if (sysrq_requested) {
   17.15  				unsigned long sysrq_timeout =
   17.16  					sysrq_requested + HZ*2;
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/machine_reboot.c	Thu Mar 15 09:00:42 2007 -0600
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/machine_reboot.c	Thu Mar 15 09:04:23 2007 -0600
    18.3 @@ -84,7 +84,7 @@ static void post_suspend(int suspend_can
    18.4  			pfn_to_mfn(xen_start_info->console.domU.mfn);
    18.5  	} else {
    18.6  #ifdef CONFIG_SMP
    18.7 -		cpu_initialized_map = cpumask_of_cpu(0);
    18.8 +		cpu_initialized_map = cpu_online_map;
    18.9  #endif
   18.10  	}
   18.11  
   18.12 @@ -180,20 +180,6 @@ static int take_machine_down(void *p_fas
   18.13  	time_resume();
   18.14  	local_irq_enable();
   18.15  
   18.16 -	if (fast_suspend && !suspend_cancelled) {
   18.17 -		/*
   18.18 -		 * In fast-suspend mode the APs may not be brought back online
   18.19 -		 * when we resume. In that case we do it here.
   18.20 -		 */
   18.21 -		for_each_online_cpu(cpu) {
   18.22 -			if (cpu == 0)
   18.23 -				continue;
   18.24 -			cpu_set_initialized(cpu);
   18.25 -			err = HYPERVISOR_vcpu_op(VCPUOP_up, cpu, NULL);
   18.26 -			BUG_ON(err);
   18.27 -		}
   18.28 -	}
   18.29 -
   18.30  	return suspend_cancelled;
   18.31  }
   18.32  
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Mar 15 09:00:42 2007 -0600
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Mar 15 09:04:23 2007 -0600
    19.3 @@ -110,6 +110,7 @@ static unsigned int alloc_index = 0;
    19.4  
    19.5  static inline unsigned long alloc_mfn(void)
    19.6  {
    19.7 +	BUG_ON(alloc_index == 0);
    19.8  	return mfn_list[--alloc_index];
    19.9  }
   19.10  
   19.11 @@ -552,6 +553,7 @@ static void net_rx_action(unsigned long 
   19.12  		*(int *)skb->cb = nr_frags;
   19.13  
   19.14  		if (!xen_feature(XENFEAT_auto_translated_physmap) &&
   19.15 +		    !((netif_t *)netdev_priv(skb->dev))->copying_receiver &&
   19.16  		    check_mfn(nr_frags + 1)) {
   19.17  			/* Memory squeeze? Back off for an arbitrary while. */
   19.18  			if ( net_ratelimit() )
    20.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pci.h	Thu Mar 15 09:00:42 2007 -0600
    20.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pci.h	Thu Mar 15 09:04:23 2007 -0600
    20.3 @@ -143,11 +143,4 @@ static inline void pci_dma_burst_advice(
    20.4  /* generic pci stuff */
    20.5  #include <asm-generic/pci.h>
    20.6  
    20.7 -/* On Xen we have to scan all functions since Xen hides bridges from
    20.8 - * us.  If a bridge is at fn=0 and that slot has a multifunction
    20.9 - * device, we won't find the additional devices without scanning all
   20.10 - * functions. */
   20.11 -#undef pcibios_scan_all_fns
   20.12 -#define pcibios_scan_all_fns(a, b)	1
   20.13 -
   20.14  #endif /* __i386_PCI_H */
    21.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h	Thu Mar 15 09:00:42 2007 -0600
    21.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pci.h	Thu Mar 15 09:04:23 2007 -0600
    21.3 @@ -163,11 +163,4 @@ static inline void pcibios_add_platform_
    21.4  #include <asm-generic/pci.h>
    21.5  #endif
    21.6  
    21.7 -/* On Xen we have to scan all functions since Xen hides bridges from
    21.8 - * us.  If a bridge is at fn=0 and that slot has a multifunction
    21.9 - * device, we won't find the additional devices without scanning all
   21.10 - * functions. */
   21.11 -#undef pcibios_scan_all_fns
   21.12 -#define pcibios_scan_all_fns(a, b)	1
   21.13 -
   21.14  #endif /* __x8664_PCI_H */
    22.1 --- a/linux-2.6-xen-sparse/kernel/kexec.c	Thu Mar 15 09:00:42 2007 -0600
    22.2 +++ b/linux-2.6-xen-sparse/kernel/kexec.c	Thu Mar 15 09:04:23 2007 -0600
    22.3 @@ -330,13 +330,27 @@ static int kimage_is_destination_range(s
    22.4  	return 0;
    22.5  }
    22.6  
    22.7 -static struct page *kimage_alloc_pages(gfp_t gfp_mask, unsigned int order)
    22.8 +static struct page *kimage_alloc_pages(gfp_t gfp_mask, unsigned int order, unsigned long limit)
    22.9  {
   22.10  	struct page *pages;
   22.11  
   22.12  	pages = alloc_pages(gfp_mask, order);
   22.13  	if (pages) {
   22.14  		unsigned int count, i;
   22.15 +#ifdef CONFIG_XEN
   22.16 +		int address_bits;
   22.17 +
   22.18 +		if (limit == ~0UL)
   22.19 +			address_bits = BITS_PER_LONG;
   22.20 +		else
   22.21 +			address_bits = long_log2(limit);
   22.22 +
   22.23 +		if (xen_create_contiguous_region((unsigned long)page_address(pages),
   22.24 +						 order, address_bits) < 0) {
   22.25 +			__free_pages(pages, order);
   22.26 +			return NULL;
   22.27 +		}
   22.28 +#endif
   22.29  		pages->mapping = NULL;
   22.30  		set_page_private(pages, order);
   22.31  		count = 1 << order;
   22.32 @@ -355,6 +369,9 @@ static void kimage_free_pages(struct pag
   22.33  	count = 1 << order;
   22.34  	for (i = 0; i < count; i++)
   22.35  		ClearPageReserved(page + i);
   22.36 +#ifdef CONFIG_XEN
   22.37 +	xen_destroy_contiguous_region((unsigned long)page_address(page), order);
   22.38 +#endif
   22.39  	__free_pages(page, order);
   22.40  }
   22.41  
   22.42 @@ -400,7 +417,7 @@ static struct page *kimage_alloc_normal_
   22.43  	do {
   22.44  		unsigned long pfn, epfn, addr, eaddr;
   22.45  
   22.46 -		pages = kimage_alloc_pages(GFP_KERNEL, order);
   22.47 +		pages = kimage_alloc_pages(GFP_KERNEL, order, KEXEC_CONTROL_MEMORY_LIMIT);
   22.48  		if (!pages)
   22.49  			break;
   22.50  		pfn   = kexec_page_to_pfn(pages);
   22.51 @@ -709,7 +726,7 @@ static struct page *kimage_alloc_page(st
   22.52  		kimage_entry_t *old;
   22.53  
   22.54  		/* Allocate a page, if we run out of memory give up */
   22.55 -		page = kimage_alloc_pages(gfp_mask, 0);
   22.56 +		page = kimage_alloc_pages(gfp_mask, 0, KEXEC_SOURCE_MEMORY_LIMIT);
   22.57  		if (!page)
   22.58  			return NULL;
   22.59  		/* If the page cannot be used file it away */
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/patches/linux-2.6.18/crash-kernel-32-on-64.patch	Thu Mar 15 09:04:23 2007 -0600
    23.3 @@ -0,0 +1,11 @@
    23.4 +--- pristine-linux-2.6.18/include/asm-i386/elf.h	2006-09-20 04:42:06.000000000 +0100
    23.5 ++++ linux-2.6.18-xen/include/asm-i386/elf.h	2007-03-14 16:42:30.000000000 +0000
    23.6 +@@ -36,7 +36,7 @@
    23.7 +  * This is used to ensure we don't load something for the wrong architecture.
    23.8 +  */
    23.9 + #define elf_check_arch(x) \
   23.10 +-	(((x)->e_machine == EM_386) || ((x)->e_machine == EM_486))
   23.11 ++	(((x)->e_machine == EM_386) || ((x)->e_machine == EM_486) || ((x)->e_machine == EM_X86_64))
   23.12 + 
   23.13 + /*
   23.14 +  * These are used to set parameters in the core dumps.
    24.1 --- a/patches/linux-2.6.18/series	Thu Mar 15 09:00:42 2007 -0600
    24.2 +++ b/patches/linux-2.6.18/series	Thu Mar 15 09:04:23 2007 -0600
    24.3 @@ -19,3 +19,4 @@ x86-elfnote-as-preprocessor-macro.patch
    24.4  fixaddr-top.patch
    24.5  git-c06cb8b1c4d25e5b4d7a2d7c2462619de1e0dbc4.patch
    24.6  softlockup-no-idle-hz.patch
    24.7 +crash-kernel-32-on-64.patch
    25.1 --- a/tools/firmware/Makefile	Thu Mar 15 09:00:42 2007 -0600
    25.2 +++ b/tools/firmware/Makefile	Thu Mar 15 09:04:23 2007 -0600
    25.3 @@ -14,10 +14,10 @@ SUBDIRS += hvmloader
    25.4  
    25.5  .PHONY: all
    25.6  all:
    25.7 -	@set -e; if ! `which bcc 1>/dev/null 2>/dev/null`; then \
    25.8 +	@set -e; if [ $$((`bcc -v 2>&1 | grep version | cut -d' ' -f 3 | awk -F. '{ printf "0x%02x%02x%02x", $$1, $$2, $$3}'`)) -lt $$((0x00100e)) ] ; then \
    25.9  	echo "***********************************************************"; \
   25.10 -	echo "WARNING: Install dev86 package to build firmware!"; \
   25.11 -	echo "         (http://www.cix.co.uk/~mayday)"; \
   25.12 +	echo "Require dev86 package version >= 0.16.14 to build firmware!"; \
   25.13 +	echo "(visit http://www.cix.co.uk/~mayday for more information)"; \
   25.14  	echo "***********************************************************"; \
   25.15  	else \
   25.16  	for subdir in $(SUBDIRS); do \
    26.1 --- a/tools/firmware/hvmloader/32bitbios_support.c	Thu Mar 15 09:00:42 2007 -0600
    26.2 +++ b/tools/firmware/hvmloader/32bitbios_support.c	Thu Mar 15 09:04:23 2007 -0600
    26.3 @@ -45,16 +45,11 @@ static int relocate_elf(unsigned char *e
    26.4          return -1;
    26.5      }
    26.6  
    26.7 -    for (i = 0; i < ehdr->e_shnum; i++) {
    26.8 -        if (!(shdr[i]).sh_flags & SHF_ALLOC) {
    26.9 -            shdr[i].sh_addr = 0;
   26.10 -            continue;
   26.11 -        }
   26.12 +    for (i = 0; i < ehdr->e_shnum; i++)
   26.13          shdr[i].sh_addr = (Elf32_Addr)&elfarray[shdr[i].sh_offset];
   26.14 -    }
   26.15  
   26.16      for (i = 0; i < ehdr->e_shnum; i++) {
   26.17 -        if (shdr[i].sh_type == SHT_REL && shdr[i].sh_addr != 0) {
   26.18 +        if (shdr[i].sh_type == SHT_REL) {
   26.19              Elf32_Shdr *targetsec = (Elf32_Shdr *)&(shdr[shdr[i].sh_info]);
   26.20              Elf32_Shdr *symtabsec = (Elf32_Shdr *)&(shdr[shdr[i].sh_link]);
   26.21              Elf32_Sym  *syms      = (Elf32_Sym *)symtabsec->sh_addr;
   26.22 @@ -62,6 +57,10 @@ static int relocate_elf(unsigned char *e
   26.23              unsigned char *code   = (unsigned char *)targetsec->sh_addr;
   26.24              int j;
   26.25  
   26.26 +            /* must not have been stripped */
   26.27 +            if (shdr[i].sh_size == 0)
   26.28 +                return -6;
   26.29 +
   26.30              for (j = 0; j < shdr[i].sh_size / sizeof(Elf32_Rel); j++) {
   26.31                  int idx           = ELF32_R_SYM(rels[j].r_info);
   26.32                  Elf32_Sym *symbol = &syms[idx];
    27.1 --- a/tools/firmware/hvmloader/acpi/acpi2_0.h	Thu Mar 15 09:00:42 2007 -0600
    27.2 +++ b/tools/firmware/hvmloader/acpi/acpi2_0.h	Thu Mar 15 09:04:23 2007 -0600
    27.3 @@ -49,8 +49,8 @@ struct acpi_header {
    27.4      uint32_t length;
    27.5      uint8_t  revision;
    27.6      uint8_t  checksum;
    27.7 -    uint8_t  oem_id[6];
    27.8 -    uint8_t  oem_table_id[8];
    27.9 +    char     oem_id[6];
   27.10 +    char     oem_table_id[8];
   27.11      uint32_t oem_revision;
   27.12      uint32_t creator_id;
   27.13      uint32_t creator_revision;
   27.14 @@ -90,7 +90,7 @@ struct acpi_20_generic_address {
   27.15  struct acpi_10_rsdp {
   27.16      uint64_t signature;
   27.17      uint8_t  checksum;
   27.18 -    uint8_t  oem_id[6];
   27.19 +    char     oem_id[6];
   27.20      uint8_t  reserved;
   27.21      uint32_t rsdt_address;
   27.22  };
   27.23 @@ -101,7 +101,7 @@ struct acpi_10_rsdp {
   27.24  struct acpi_20_rsdp {
   27.25      uint64_t signature;
   27.26      uint8_t  checksum;
   27.27 -    uint8_t  oem_id[6];
   27.28 +    char     oem_id[6];
   27.29      uint8_t  revision;
   27.30      uint32_t rsdt_address;
   27.31      uint32_t length;
   27.32 @@ -143,6 +143,51 @@ struct acpi_20_tcpa {
   27.33  #define ACPI_2_0_TCPA_LAML_SIZE (64*1024)
   27.34  
   27.35  /*
   27.36 + * Fixed ACPI Description Table Structure (FADT) in ACPI 1.0.
   27.37 + */
   27.38 +struct acpi_10_fadt {
   27.39 +    struct acpi_header header;
   27.40 +    uint32_t firmware_ctrl;
   27.41 +    uint32_t dsdt;
   27.42 +    uint8_t  reserved0;
   27.43 +    uint8_t  preferred_pm_profile;
   27.44 +    uint16_t sci_int;
   27.45 +    uint32_t smi_cmd;
   27.46 +    uint8_t  acpi_enable;
   27.47 +    uint8_t  acpi_disable;
   27.48 +    uint8_t  s4bios_req;
   27.49 +    uint8_t  pstate_cnt;
   27.50 +    uint32_t pm1a_evt_blk;
   27.51 +    uint32_t pm1b_evt_blk;
   27.52 +    uint32_t pm1a_cnt_blk;
   27.53 +    uint32_t pm1b_cnt_blk;
   27.54 +    uint32_t pm2_cnt_blk;
   27.55 +    uint32_t pm_tmr_blk;
   27.56 +    uint32_t gpe0_blk;
   27.57 +    uint32_t gpe1_blk;
   27.58 +    uint8_t  pm1_evt_len;
   27.59 +    uint8_t  pm1_cnt_len;
   27.60 +    uint8_t  pm2_cnt_len;
   27.61 +    uint8_t  pm_tmr_len;
   27.62 +    uint8_t  gpe0_blk_len;
   27.63 +    uint8_t  gpe1_blk_len;
   27.64 +    uint8_t  gpe1_base;
   27.65 +    uint8_t  cst_cnt;
   27.66 +    uint16_t p_lvl2_lat;
   27.67 +    uint16_t p_lvl3_lat;
   27.68 +    uint16_t flush_size;
   27.69 +    uint16_t flush_stride;
   27.70 +    uint8_t  duty_offset;
   27.71 +    uint8_t  duty_width;
   27.72 +    uint8_t  day_alrm;
   27.73 +    uint8_t  mon_alrm;
   27.74 +    uint8_t  century;
   27.75 +    uint16_t iapc_boot_arch;
   27.76 +    uint8_t  reserved1;
   27.77 +    uint32_t flags;
   27.78 +};
   27.79 +
   27.80 +/*
   27.81   * Fixed ACPI Description Table Structure (FADT).
   27.82   */
   27.83  struct acpi_20_fadt {
   27.84 @@ -345,6 +390,7 @@ struct acpi_20_madt_intsrcovr {
   27.85  #define ACPI_2_0_XSDT_REVISION 0x01
   27.86  #define ACPI_2_0_TCPA_REVISION 0x02
   27.87  #define ACPI_2_0_HPET_REVISION 0x01
   27.88 +#define ACPI_1_0_FADT_REVISION 0x01
   27.89  
   27.90  #pragma pack ()
   27.91  
    28.1 --- a/tools/firmware/hvmloader/acpi/build.c	Thu Mar 15 09:00:42 2007 -0600
    28.2 +++ b/tools/firmware/hvmloader/acpi/build.c	Thu Mar 15 09:04:23 2007 -0600
    28.3 @@ -22,7 +22,8 @@
    28.4  #include "../util.h"
    28.5  #include <xen/hvm/e820.h>
    28.6  
    28.7 -#define align16(sz) (((sz) + 15) & ~15)
    28.8 +#define align16(sz)        (((sz) + 15) & ~15)
    28.9 +#define fixed_strcpy(d, s) strncpy((d), (s), sizeof(d))
   28.10  
   28.11  extern struct acpi_20_rsdp Rsdp;
   28.12  extern struct acpi_20_rsdt Rsdt;
   28.13 @@ -57,8 +58,8 @@ int construct_madt(struct acpi_20_madt *
   28.14      memset(madt, 0, sizeof(*madt));
   28.15      madt->header.signature    = ACPI_2_0_MADT_SIGNATURE;
   28.16      madt->header.revision     = ACPI_2_0_MADT_REVISION;
   28.17 -    strncpy(madt->header.oem_id, ACPI_OEM_ID, 6);
   28.18 -    strncpy(madt->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
   28.19 +    fixed_strcpy(madt->header.oem_id, ACPI_OEM_ID);
   28.20 +    fixed_strcpy(madt->header.oem_table_id, ACPI_OEM_TABLE_ID);
   28.21      madt->header.oem_revision = ACPI_OEM_REVISION;
   28.22      madt->header.creator_id   = ACPI_CREATOR_ID;
   28.23      madt->header.creator_revision = ACPI_CREATOR_REVISION;
   28.24 @@ -131,8 +132,8 @@ int construct_hpet(struct acpi_20_hpet *
   28.25      memset(hpet, 0, sizeof(*hpet));
   28.26      hpet->header.signature    = ACPI_2_0_HPET_SIGNATURE;
   28.27      hpet->header.revision     = ACPI_2_0_HPET_REVISION;
   28.28 -    strncpy(hpet->header.oem_id, ACPI_OEM_ID, 6);
   28.29 -    strncpy(hpet->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
   28.30 +    fixed_strcpy(hpet->header.oem_id, ACPI_OEM_ID);
   28.31 +    fixed_strcpy(hpet->header.oem_table_id, ACPI_OEM_TABLE_ID);
   28.32      hpet->header.oem_revision = ACPI_OEM_REVISION;
   28.33      hpet->header.creator_id   = ACPI_CREATOR_ID;
   28.34      hpet->header.creator_revision = ACPI_CREATOR_REVISION;
   28.35 @@ -150,6 +151,7 @@ int construct_processor_objects(uint8_t 
   28.36  {
   28.37      static const char pdat[13] = { 0x5b, 0x83, 0x0b, 0x50, 0x52 };
   28.38      static const char hex[] = "0123456789ABCDEF";
   28.39 +    static const char pr_scope[] = "\\_PR_";
   28.40      unsigned int i, length, nr_cpus = get_vcpu_nr();
   28.41      struct acpi_header *hdr;
   28.42      uint8_t *p = buf;
   28.43 @@ -161,8 +163,8 @@ int construct_processor_objects(uint8_t 
   28.44      hdr = (struct acpi_header *)p;
   28.45      hdr->signature = ASCII32('S','S','D','T');
   28.46      hdr->revision  = 2;
   28.47 -    strncpy(hdr->oem_id, ACPI_OEM_ID, 6);
   28.48 -    strncpy(hdr->oem_table_id, ACPI_OEM_TABLE_ID, 8);
   28.49 +    fixed_strcpy(hdr->oem_id, ACPI_OEM_ID);
   28.50 +    fixed_strcpy(hdr->oem_table_id, ACPI_OEM_TABLE_ID);
   28.51      hdr->oem_revision = ACPI_OEM_REVISION;
   28.52      hdr->creator_id = ACPI_CREATOR_ID;
   28.53      hdr->creator_revision = ACPI_CREATOR_REVISION;
   28.54 @@ -176,7 +178,7 @@ int construct_processor_objects(uint8_t 
   28.55      *p++ = 0x10;
   28.56  
   28.57      /* PkgLength (includes length bytes!). */
   28.58 -    length = 1 + 5 + (nr_cpus * sizeof(pdat));
   28.59 +    length = 1 + strlen(pr_scope) + (nr_cpus * sizeof(pdat));
   28.60      if ( length <= 0x3f )
   28.61      {
   28.62          *p++ = length;
   28.63 @@ -195,8 +197,8 @@ int construct_processor_objects(uint8_t 
   28.64      }
   28.65  
   28.66      /* NameString */
   28.67 -    strncpy(p, "\\_PR_", 5);
   28.68 -    p += 5;
   28.69 +    strncpy(p, pr_scope, strlen(pr_scope));
   28.70 +    p += strlen(pr_scope);
   28.71  
   28.72      /*
   28.73       * 3. Processor Objects.
   28.74 @@ -263,8 +265,8 @@ int construct_secondary_tables(uint8_t *
   28.75          tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
   28.76          tcpa->header.length    = sizeof(*tcpa);
   28.77          tcpa->header.revision  = ACPI_2_0_TCPA_REVISION;
   28.78 -        strncpy(tcpa->header.oem_id, ACPI_OEM_ID, 6);
   28.79 -        strncpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
   28.80 +        fixed_strcpy(tcpa->header.oem_id, ACPI_OEM_ID);
   28.81 +        fixed_strcpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID);
   28.82          tcpa->header.oem_revision = ACPI_OEM_REVISION;
   28.83          tcpa->header.creator_id   = ACPI_CREATOR_ID;
   28.84          tcpa->header.creator_revision = ACPI_CREATOR_REVISION;
   28.85 @@ -291,6 +293,7 @@ int acpi_build_tables(uint8_t *buf)
   28.86      struct acpi_20_rsdt *rsdt;
   28.87      struct acpi_20_xsdt *xsdt;
   28.88      struct acpi_20_fadt *fadt;
   28.89 +    struct acpi_10_fadt *fadt_10;
   28.90      struct acpi_20_facs *facs;
   28.91      unsigned char       *dsdt;
   28.92      unsigned long        secondary_tables[16];
   28.93 @@ -304,6 +307,25 @@ int acpi_build_tables(uint8_t *buf)
   28.94      memcpy(dsdt, &AmlCode, DsdtLen);
   28.95      offset += align16(DsdtLen);
   28.96  
   28.97 +    /*
   28.98 +     * N.B. ACPI 1.0 operating systems may not handle FADT with revision 2
   28.99 +     * or above properly, notably Windows 2000, which tries to copy FADT
  28.100 +     * into a 116 bytes buffer thus causing an overflow. The solution is to
  28.101 +     * link the higher revision FADT with the XSDT only and introduce a
  28.102 +     * compatible revision 1 FADT that is linked with the RSDT. Refer to:
  28.103 +     *     http://www.acpi.info/presentations/S01USMOBS169_OS%20new.ppt
  28.104 +     */
  28.105 +    fadt_10 = (struct acpi_10_fadt *)&buf[offset];
  28.106 +    memcpy(fadt_10, &Fadt, sizeof(struct acpi_10_fadt));
  28.107 +    offset += align16(sizeof(struct acpi_10_fadt));
  28.108 +    fadt_10->header.length = sizeof(struct acpi_10_fadt);
  28.109 +    fadt_10->header.revision = ACPI_1_0_FADT_REVISION;
  28.110 +    fadt_10->dsdt          = (unsigned long)dsdt;
  28.111 +    fadt_10->firmware_ctrl = (unsigned long)facs;
  28.112 +    set_checksum(fadt_10,
  28.113 +                 offsetof(struct acpi_header, checksum),
  28.114 +                 sizeof(struct acpi_10_fadt));
  28.115 +
  28.116      fadt = (struct acpi_20_fadt *)&buf[offset];
  28.117      memcpy(fadt, &Fadt, sizeof(struct acpi_20_fadt));
  28.118      offset += align16(sizeof(struct acpi_20_fadt));
  28.119 @@ -330,7 +352,7 @@ int acpi_build_tables(uint8_t *buf)
  28.120  
  28.121      rsdt = (struct acpi_20_rsdt *)&buf[offset];
  28.122      memcpy(rsdt, &Rsdt, sizeof(struct acpi_header));
  28.123 -    rsdt->entry[0] = (unsigned long)fadt;
  28.124 +    rsdt->entry[0] = (unsigned long)fadt_10;
  28.125      for ( i = 0; secondary_tables[i]; i++ )
  28.126          rsdt->entry[i+1] = secondary_tables[i];
  28.127      rsdt->header.length = sizeof(struct acpi_header) + (i+1)*sizeof(uint32_t);
    29.1 --- a/tools/firmware/hvmloader/hvmloader.c	Thu Mar 15 09:00:42 2007 -0600
    29.2 +++ b/tools/firmware/hvmloader/hvmloader.c	Thu Mar 15 09:04:23 2007 -0600
    29.3 @@ -38,23 +38,53 @@
    29.4  #define VMXASSIST_PHYSICAL_ADDRESS    0x000D0000
    29.5  #define ROMBIOS_PHYSICAL_ADDRESS      0x000F0000
    29.6  
    29.7 -/* invoke SVM's paged realmode support */
    29.8 -#define SVM_VMMCALL_RESET_TO_REALMODE 0x80000001
    29.9 -
   29.10 -/*
   29.11 - * C runtime start off
   29.12 - */
   29.13  asm(
   29.14      "    .text                       \n"
   29.15      "    .globl _start               \n"
   29.16      "_start:                         \n"
   29.17 +    /* C runtime kickoff. */
   29.18      "    cld                         \n"
   29.19      "    cli                         \n"
   29.20 +    "    movl $stack_top,%esp        \n"
   29.21 +    "    movl %esp,%ebp              \n"
   29.22 +    "    call main                   \n"
   29.23 +    /* Relocate real-mode trampoline to 0x0. */
   29.24 +    "    mov  $trampoline_start,%esi \n"
   29.25 +    "    xor  %edi,%edi              \n"
   29.26 +    "    mov  $trampoline_end,%ecx   \n"
   29.27 +    "    sub  %esi,%ecx              \n"
   29.28 +    "    rep  movsb                  \n"
   29.29 +    /* Load real-mode compatible segment state (base 0x0000, limit 0xffff). */
   29.30      "    lgdt gdt_desr               \n"
   29.31 -    "    movl $stack_top, %esp       \n"
   29.32 -    "    movl %esp, %ebp             \n"
   29.33 -    "    call main                   \n"
   29.34 -    "    ud2                         \n"
   29.35 +    "    mov  $0x0010,%ax            \n"
   29.36 +    "    mov  %ax,%ds                \n"
   29.37 +    "    mov  %ax,%es                \n"
   29.38 +    "    mov  %ax,%fs                \n"
   29.39 +    "    mov  %ax,%gs                \n"
   29.40 +    "    mov  %ax,%ss                \n"
   29.41 +    /* Initialise all 32-bit GPRs to zero. */
   29.42 +    "    xor  %eax,%eax              \n"
   29.43 +    "    xor  %ebx,%ebx              \n"
   29.44 +    "    xor  %ecx,%ecx              \n"
   29.45 +    "    xor  %edx,%edx              \n"
   29.46 +    "    xor  %esp,%esp              \n"
   29.47 +    "    xor  %ebp,%ebp              \n"
   29.48 +    "    xor  %esi,%esi              \n"
   29.49 +    "    xor  %edi,%edi              \n"
   29.50 +    /* Enter real mode, reload all segment registers and IDT. */
   29.51 +    "    ljmp $0x8,$0x0              \n"
   29.52 +    "trampoline_start: .code16       \n"
   29.53 +    "    mov  %eax,%cr0              \n"
   29.54 +    "    ljmp $0,$1f-trampoline_start\n"
   29.55 +    "1:  mov  %ax,%ds                \n"
   29.56 +    "    mov  %ax,%es                \n"
   29.57 +    "    mov  %ax,%fs                \n"
   29.58 +    "    mov  %ax,%gs                \n"
   29.59 +    "    mov  %ax,%ss                \n"
   29.60 +    "    lidt 1f-trampoline_start    \n"
   29.61 +    "    ljmp $0xf000,$0xfff0        \n"
   29.62 +    "1:  .word 0x3ff,0,0             \n"
   29.63 +    "trampoline_end:   .code32       \n"
   29.64      "                                \n"
   29.65      "gdt_desr:                       \n"
   29.66      "    .word gdt_end - gdt - 1     \n"
   29.67 @@ -63,8 +93,8 @@ asm(
   29.68      "    .align 8                    \n"
   29.69      "gdt:                            \n"
   29.70      "    .quad 0x0000000000000000    \n"
   29.71 -    "    .quad 0x00CF92000000FFFF    \n"
   29.72 -    "    .quad 0x00CF9A000000FFFF    \n"
   29.73 +    "    .quad 0x00009a000000ffff    \n" /* Ring 0 code, base 0 limit 0xffff */
   29.74 +    "    .quad 0x000092000000ffff    \n" /* Ring 0 data, base 0 limit 0xffff */
   29.75      "gdt_end:                        \n"
   29.76      "                                \n"
   29.77      "    .bss                        \n"
   29.78 @@ -84,19 +114,6 @@ cirrus_check(void)
   29.79  }
   29.80  
   29.81  static int
   29.82 -vmmcall(int function, int edi, int esi, int edx, int ecx, int ebx)
   29.83 -{
   29.84 -    int eax;
   29.85 -
   29.86 -    __asm__ __volatile__ (
   29.87 -        ".byte 0x0F,0x01,0xD9"
   29.88 -        : "=a" (eax)
   29.89 -        : "a"(function),
   29.90 -        "b"(ebx), "c"(ecx), "d"(edx), "D"(edi), "S"(esi) );
   29.91 -    return eax;
   29.92 -}
   29.93 -
   29.94 -static int
   29.95  check_amd(void)
   29.96  {
   29.97      char id[12];
   29.98 @@ -349,13 +366,7 @@ int main(void)
   29.99          ASSERT((ACPI_PHYSICAL_ADDRESS + acpi_sz) <= 0xF0000);
  29.100      }
  29.101  
  29.102 -    if ( check_amd() )
  29.103 -    {
  29.104 -        /* AMD implies this is SVM */
  29.105 -        printf("SVM go ...\n");
  29.106 -        vmmcall(SVM_VMMCALL_RESET_TO_REALMODE, 0, 0, 0, 0, 0);
  29.107 -    }
  29.108 -    else
  29.109 +    if ( !check_amd() )
  29.110      {
  29.111          printf("Loading VMXAssist ...\n");
  29.112          memcpy((void *)VMXASSIST_PHYSICAL_ADDRESS,
  29.113 @@ -368,7 +379,7 @@ int main(void)
  29.114              );
  29.115      }
  29.116  
  29.117 -    printf("Failed to invoke ROMBIOS\n");
  29.118 +    printf("Invoking ROMBIOS ...\n");
  29.119      return 0;
  29.120  }
  29.121  
    30.1 --- a/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Thu Mar 15 09:00:42 2007 -0600
    30.2 +++ b/tools/firmware/rombios/32bit/tcgbios/tcgbios.c	Thu Mar 15 09:04:23 2007 -0600
    30.3 @@ -95,13 +95,15 @@ struct ptti_cust *TCG_CommandList[] = {
    30.4  };
    30.5  
    30.6  /* local function prototypes */
    30.7 -static void sha1(const unsigned char *data, uint32_t length, unsigned char *hash);
    30.8 +static void sha1(const unsigned char *data, uint32_t length,
    30.9 +                 unsigned char *hash);
   30.10  static uint32_t TCG_ShutdownPreBootInterface(uint32_t ebx);
   30.11  static uint32_t HashAll32(struct hai *hai, unsigned char *hash,
   30.12                            uint32_t magic, uint32_t ecx, uint32_t edx);
   30.13  static uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s,
   30.14                                       struct hleeo *hleeo,
   30.15 -                                     uint32_t magic, uint32_t ecx, uint32_t edx);
   30.16 +                                     uint32_t magic, uint32_t ecx,
   30.17 +                                     uint32_t edx);
   30.18  static uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo,
   30.19                                 uint32_t ebx, uint32_t ecx, uint32_t edx);
   30.20  static uint32_t PassThroughToTPM32(struct pttti *pttti, struct pttto *pttto,
   30.21 @@ -181,8 +183,7 @@ uint32_t MA_InitTPM(uint16_t startupcode
   30.22  }
   30.23  
   30.24  static
   30.25 -uint32_t MA_Transmit(unsigned char *cmdbuffer,
   30.26 -                     unsigned char *respbuffer,
   30.27 +uint32_t MA_Transmit(unsigned char *cmdbuffer, unsigned char *respbuffer,
   30.28                       uint32_t respbufferlen)
   30.29  {
   30.30  	uint32_t rc = 0;
   30.31 @@ -289,15 +290,14 @@ void tcpa_acpi_init(void)
   30.32  		uint32_t ctr = 0;
   30.33  		/* get RSDT from RSDP */
   30.34  		rsdt   = (struct acpi_20_rsdt *)rsdp->rsdt_address;
   30.35 -		/* rsdt may be anywhere in 32bit space */
   30.36  		length = rsdt->header.length;
   30.37  		off = 36;
   30.38  		while ((off + 3) < length) {
   30.39  			/* try all pointers to structures */
   30.40  			tcpa = (struct acpi_20_tcpa *)rsdt->entry[ctr];
   30.41  			/* valid TCPA ACPI table ? */
   30.42 -			if (ACPI_2_0_TCPA_SIGNATURE == tcpa->header.signature &&
   30.43 -			    acpi_validate_entry(&tcpa->header) == 0) {
   30.44 +			if (ACPI_2_0_TCPA_SIGNATURE == tcpa->header.signature
   30.45 +			    && acpi_validate_entry(&tcpa->header) == 0) {
   30.46  				found = 1;
   30.47  				break;
   30.48  			}
   30.49 @@ -311,7 +311,6 @@ void tcpa_acpi_init(void)
   30.50  		tcpa = 0;
   30.51  	}
   30.52  
   30.53 -	/* initialize the TCPA part of the EBDA with our data */
   30.54  	tcpa_acpi.tcpa_ptr = tcpa;
   30.55  	tcpa_acpi.lasa_last_ptr = 0;
   30.56  	tcpa_acpi.entry_count = 0;
   30.57 @@ -748,9 +747,7 @@ void tcpa_measure_post(Bit32u from, Bit3
   30.58  }
   30.59  
   30.60  static
   30.61 -uint32_t SendCommand32(uint32_t idx,
   30.62 -                     struct pttto *pttto,
   30.63 -                     uint32_t size_ptto)
   30.64 +uint32_t SendCommand32(uint32_t idx, struct pttto *pttto, uint32_t size_ptto)
   30.65  {
   30.66  	uint32_t rc = 0;
   30.67  	struct pttti *pttti = (struct pttti *)TCG_CommandList[idx];
   30.68 @@ -796,7 +793,8 @@ uint32_t tcpa_initialize_tpm(uint32_t ph
   30.69  	uint32_t pttto_size = sizeof(_pttto);
   30.70  
   30.71  	if (rc == 0) {
   30.72 -		rc = SendCommand32(IDX_CMD_TPM_Startup_0x01, pttto, pttto_size);
   30.73 +		rc = SendCommand32(IDX_CMD_TPM_Startup_0x01, pttto,
   30.74 +		                   pttto_size);
   30.75  	}
   30.76  
   30.77  	if (rc == 0 && physpres != 0) {
   30.78 @@ -884,11 +882,8 @@ uint32_t _TCG_TPM_Extend(unsigned char *
   30.79  
   30.80  
   30.81  static
   30.82 -uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s,
   30.83 -                            struct hleeo *hleeo,
   30.84 -                            uint32_t magic,
   30.85 -                            uint32_t ecx,
   30.86 -                            uint32_t edx)
   30.87 +uint32_t HashLogExtendEvent32(struct hleei_short *hleei_s, struct hleeo *hleeo,
   30.88 +                              uint32_t magic, uint32_t ecx, uint32_t edx)
   30.89  {
   30.90  	uint32_t rc = 0;
   30.91  	uint16_t size;
   30.92 @@ -978,11 +973,8 @@ uint32_t HashLogExtendEvent32(struct hle
   30.93  
   30.94  
   30.95  static
   30.96 -uint32_t PassThroughToTPM32(struct pttti *pttti,
   30.97 -                          struct pttto *pttto,
   30.98 -                          uint32_t magic,
   30.99 -                          uint32_t ecx,
  30.100 -                          uint32_t edx)
  30.101 +uint32_t PassThroughToTPM32(struct pttti *pttti, struct pttto *pttto,
  30.102 +                            uint32_t magic, uint32_t ecx, uint32_t edx)
  30.103  {
  30.104  	uint32_t rc = 0;
  30.105  	uint8_t *cmd32;
  30.106 @@ -1047,9 +1039,7 @@ uint32_t TCG_ShutdownPreBootInterface(ui
  30.107  
  30.108  static
  30.109  uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo,
  30.110 -                      uint32_t ebx,
  30.111 -                      uint32_t ecx,
  30.112 -                      uint32_t edx)
  30.113 +                        uint32_t ebx, uint32_t ecx, uint32_t edx)
  30.114  {
  30.115  	uint32_t rc = 0;
  30.116  	uint16_t size;
  30.117 @@ -1144,9 +1134,7 @@ uint32_t HashLogEvent32(struct hlei *hle
  30.118  
  30.119  static
  30.120  uint32_t HashAll32(struct hai *hai, unsigned char *hash,
  30.121 -                 uint32_t magic,
  30.122 -                 uint32_t ecx,
  30.123 -                 uint32_t edx)
  30.124 +                   uint32_t magic, uint32_t ecx, uint32_t edx)
  30.125  {
  30.126  	uint32_t rc = 0;
  30.127  
  30.128 @@ -1187,9 +1175,7 @@ uint32_t HashAll32(struct hai *hai, unsi
  30.129  
  30.130  static
  30.131  uint32_t TSS32(struct ti *ti, struct to *to,
  30.132 -             uint32_t ebx,
  30.133 -             uint32_t ecx,
  30.134 -             uint32_t edx)
  30.135 +               uint32_t ebx, uint32_t ecx, uint32_t edx)
  30.136  {
  30.137  	uint32_t rc = 0;
  30.138  	if (TCG_IsShutdownPreBootInterface() == 0) {
  30.139 @@ -1209,11 +1195,11 @@ uint32_t TSS32(struct ti *ti, struct to 
  30.140  
  30.141  static
  30.142  uint32_t CompactHashLogExtendEvent32(unsigned char *buffer,
  30.143 -                                   uint32_t info,
  30.144 -                                   uint32_t magic,
  30.145 -                                   uint32_t length,
  30.146 -                                   uint32_t pcrindex,
  30.147 -                                   uint32_t *edx_ptr)
  30.148 +                                     uint32_t info,
  30.149 +                                     uint32_t magic,
  30.150 +                                     uint32_t length,
  30.151 +                                     uint32_t pcrindex,
  30.152 +                                     uint32_t *edx_ptr)
  30.153  {
  30.154  	uint32_t rc = 0;
  30.155  	struct hleeo hleeo;
  30.156 @@ -1356,9 +1342,7 @@ void sha1_do(sha1_ctx *ctx, const unsign
  30.157  
  30.158  	/* treat data in 64-byte chunks */
  30.159  	for (offset = 0; length - offset >= 64; offset += 64) {
  30.160 -		/* copy into the 'w' array */
  30.161  		memcpy(w, data32 + offset, 64);
  30.162 -		/* hash the block in the 'w' array */
  30.163  		sha1_block((uint32_t *)w, ctx);
  30.164  		bits += (64 * 8);
  30.165  	}
  30.166 @@ -1408,7 +1392,8 @@ void sha1(const unsigned char *data, uin
  30.167  }
  30.168  
  30.169  
  30.170 -uint32_t TCGInterruptHandler(pushad_regs_t *regs, uint32_t esds, uint32_t flags_ptr)
  30.171 +uint32_t TCGInterruptHandler(pushad_regs_t *regs, uint32_t esds,
  30.172 +                             uint32_t flags_ptr)
  30.173  {
  30.174  	uint16_t DS = esds >> 16;
  30.175  	uint16_t ES = esds & 0xffff;
  30.176 @@ -1435,7 +1420,6 @@ uint32_t TCGInterruptHandler(pushad_regs
  30.177  			}
  30.178  		}
  30.179  		break;
  30.180 -
  30.181  	case 0x01:
  30.182  		regs->u.r32.eax =
  30.183  			HashLogExtendEvent32((struct hleei_short*)
    31.1 --- a/tools/firmware/rombios/32bitgateway.c	Thu Mar 15 09:00:42 2007 -0600
    31.2 +++ b/tools/firmware/rombios/32bitgateway.c	Thu Mar 15 09:04:23 2007 -0600
    31.3 @@ -153,26 +153,17 @@ realmode_gdtdesc:				;to be used in real
    31.4  
    31.5  switch_to_realmode:
    31.6      ; Implementation of switching from protected mode to real mode
    31.7 -    ; restores all registers and prepares cs, es, ds, ss to be used
    31.8 -    ; in real mode
    31.9 +    ; prepares cs, es, ds, ss to be used in real mode
   31.10 +    ; spills   eax
   31.11      START_PM_CODE
   31.12  
   31.13      ; need to fix up the stack to return in 16 bit mode
   31.14      ; currently the 32 bit return address is on the stack
   31.15 -    push bp					;pop@A1
   31.16 -    mov bp, sp
   31.17 -    push eax					;pop@X
   31.18 +    pop eax
   31.19 +    push ax
   31.20  
   31.21 -    mov eax, [bp]				; return address low 16bits
   31.22 -                  				; and 'bp' are being moved
   31.23 -    mov 2[bp], eax
   31.24 -
   31.25 -    pop eax					;@X
   31.26 -    add sp, #2					; adjust stack for 'lost' bytes
   31.27 -
   31.28 -    push eax					;pop@1
   31.29 -    push bx					;pop@2
   31.30 -    push si					;pop@3
   31.31 +    push bx					;pop@1
   31.32 +    push si					;pop@2
   31.33  
   31.34      call _ebda_ss_offset32			; get the offset of the ss
   31.35      mov bx, ax					; entry within the ebda.
   31.36 @@ -229,10 +220,8 @@ switch_to_realmode_goon_2:
   31.37  
   31.38      sti						; allow interrupts
   31.39  
   31.40 -    pop si					;@3
   31.41 -    pop bx					;@2
   31.42 -    pop eax					;@1
   31.43 -    pop bp					;@A1
   31.44 +    pop si					;@2
   31.45 +    pop bx					;@1
   31.46  
   31.47      ret
   31.48  
    32.1 --- a/tools/firmware/rombios/rombios.c	Thu Mar 15 09:00:42 2007 -0600
    32.2 +++ b/tools/firmware/rombios/rombios.c	Thu Mar 15 09:04:23 2007 -0600
    32.3 @@ -7792,10 +7792,11 @@ ASM_END
    32.4  
    32.5      bootdrv = (Bit8u)(status>>8);
    32.6      bootseg = read_word(ebda_seg,&EbdaData->cdemu.load_segment);
    32.7 -    /* Canonicalize bootseg:bootip */
    32.8  #if BX_TCGBIOS
    32.9      tcpa_add_bootdevice((Bit32u)1L, (Bit32u)0L);
   32.10  #endif
   32.11 +
   32.12 +    /* Canonicalize bootseg:bootip */
   32.13      bootip = (bootseg & 0x0fff) << 4;
   32.14      bootseg &= 0xf000;
   32.15      break;
   32.16 @@ -7812,8 +7813,6 @@ ASM_END
   32.17  #if BX_TCGBIOS
   32.18    tcpa_ipl((Bit32u)bootseg);               /* specs: 8.2.3 steps 4 and 5 */
   32.19  #endif
   32.20 -  /* Debugging info */
   32.21 -  printf("Booting from %x:%x\n", bootseg, bootip);
   32.22    
   32.23    /* Jump to the boot vector */
   32.24  ASM_START
    33.1 --- a/tools/firmware/rombios/tcgbios.c	Thu Mar 15 09:00:42 2007 -0600
    33.2 +++ b/tools/firmware/rombios/tcgbios.c	Thu Mar 15 09:04:23 2007 -0600
    33.3 @@ -228,6 +228,8 @@ int1a_function32(regs, ES, DS, FLAGS)
    33.4  {
    33.5  	Bit16u rc;
    33.6  
    33.7 +	BX_DEBUG_INT1A("int1a_32: AX=%04x\n", regs.u.r16.ax);
    33.8 +
    33.9  	switch (regs.u.r8.ah) {
   33.10  	case 0xbb:
   33.11  		/*
   33.12 @@ -256,8 +258,10 @@ int1a_function32(regs, ES, DS, FLAGS)
   33.13  		default:
   33.14  			SET_CF();
   33.15  		}
   33.16 +		break;
   33.17  	default:
   33.18  		SET_CF();
   33.19  		break;
   33.20  	}
   33.21 +	BX_DEBUG_INT1A("int1a_32: FLAGS=%04x\n", FLAGS);
   33.22  }
    34.1 --- a/tools/ioemu/hw/usb-hid.c	Thu Mar 15 09:00:42 2007 -0600
    34.2 +++ b/tools/ioemu/hw/usb-hid.c	Thu Mar 15 09:04:23 2007 -0600
    34.3 @@ -517,6 +517,49 @@ static void usb_mouse_handle_destroy(USB
    34.4      qemu_free(s);
    34.5  }
    34.6  
    34.7 +void usb_mouse_save(QEMUFile *f, void *opaque)
    34.8 +{
    34.9 +    USBMouseState *s = (USBMouseState*)opaque;
   34.10 +
   34.11 +    qemu_put_be32s(f, &s->dx);
   34.12 +    qemu_put_be32s(f, &s->dy);
   34.13 +    qemu_put_be32s(f, &s->dz);
   34.14 +    qemu_put_be32s(f, &s->buttons_state);
   34.15 +    qemu_put_be32s(f, &s->x);
   34.16 +    qemu_put_be32s(f, &s->y);
   34.17 +    qemu_put_be32s(f, &s->kind);
   34.18 +    qemu_put_be32s(f, &s->mouse_grabbed);
   34.19 +    qemu_put_be32s(f, &s->status_changed);
   34.20 +
   34.21 +}
   34.22 +
   34.23 +int usb_mouse_load(QEMUFile *f, void *opaque, int version_id)
   34.24 +{
   34.25 +    USBMouseState *s = (USBMouseState*)opaque;
   34.26 +
   34.27 +    if (version_id != 1)
   34.28 +        return -EINVAL;
   34.29 +
   34.30 +    qemu_get_be32s(f, &s->dx);
   34.31 +    qemu_get_be32s(f, &s->dy);
   34.32 +    qemu_get_be32s(f, &s->dz);
   34.33 +    qemu_get_be32s(f, &s->buttons_state);
   34.34 +    qemu_get_be32s(f, &s->x);
   34.35 +    qemu_get_be32s(f, &s->y);
   34.36 +    qemu_get_be32s(f, &s->kind);
   34.37 +    qemu_get_be32s(f, &s->mouse_grabbed);
   34.38 +    qemu_get_be32s(f, &s->status_changed);
   34.39 +
   34.40 +    if ( s->kind == USB_TABLET) {
   34.41 +        fprintf(logfile, "usb_mouse_load:add usb_tablet_event.\n");
   34.42 +        qemu_add_mouse_event_handler(usb_tablet_event, s, 1);
   34.43 +    } else if ( s->kind == USB_MOUSE) {
   34.44 +        fprintf(logfile, "usb_mouse_load:add usb_mouse_event.\n");
   34.45 +        qemu_add_mouse_event_handler(usb_mouse_event, s, 0);
   34.46 +    }
   34.47 +}
   34.48 +
   34.49 +
   34.50  USBDevice *usb_tablet_init(void)
   34.51  {
   34.52      USBMouseState *s;
   34.53 @@ -536,6 +579,8 @@ USBDevice *usb_tablet_init(void)
   34.54  
   34.55      pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
   34.56  
   34.57 +    register_savevm("USB tablet dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
   34.58 +
   34.59      return (USBDevice *)s;
   34.60  }
   34.61  
   34.62 @@ -558,5 +603,7 @@ USBDevice *usb_mouse_init(void)
   34.63  
   34.64      pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
   34.65  
   34.66 +    register_savevm("USB mouse dev", 0, 1, usb_mouse_save, usb_mouse_load, s);
   34.67 +
   34.68      return (USBDevice *)s;
   34.69  }
    35.1 --- a/tools/ioemu/hw/usb-ohci.c	Thu Mar 15 09:00:42 2007 -0600
    35.2 +++ b/tools/ioemu/hw/usb-ohci.c	Thu Mar 15 09:04:23 2007 -0600
    35.3 @@ -1186,5 +1186,7 @@ void usb_ohci_init(struct PCIBus *bus, i
    35.4          qemu_register_usb_port(&ohci->rhport[i].port, ohci, i, ohci_attach);
    35.5      }
    35.6  
    35.7 +    register_savevm("OHCI USB", 0, 1, generic_pci_save, generic_pci_load, ohci);
    35.8 +
    35.9      ohci_reset(ohci);
   35.10  }
    36.1 --- a/tools/ioemu/hw/usb-uhci.c	Thu Mar 15 09:00:42 2007 -0600
    36.2 +++ b/tools/ioemu/hw/usb-uhci.c	Thu Mar 15 09:04:23 2007 -0600
    36.3 @@ -658,6 +658,50 @@ static void uhci_map(PCIDevice *pci_dev,
    36.4      register_ioport_read(addr, 32, 1, uhci_ioport_readb, s);
    36.5  }
    36.6  
    36.7 +void uhci_usb_save(QEMUFile *f, void *opaque)
    36.8 +{
    36.9 +    int i;
   36.10 +    UHCIState *s = (UHCIState*)opaque;
   36.11 +
   36.12 +    qemu_put_be16s(f, &s->cmd);
   36.13 +    qemu_put_be16s(f, &s->status);
   36.14 +    qemu_put_be16s(f, &s->intr);
   36.15 +    qemu_put_be16s(f, &s->frnum);
   36.16 +    qemu_put_be32s(f, &s->fl_base_addr);
   36.17 +    qemu_put_8s(f, &s->sof_timing);
   36.18 +    qemu_put_8s(f, &s->status2);
   36.19 +
   36.20 +    for(i = 0; i < NB_PORTS; i++) {
   36.21 +        qemu_put_be16s(f, &s->ports[i].ctrl);
   36.22 +    }
   36.23 +
   36.24 +    qemu_put_timer(f, s->frame_timer);
   36.25 +}
   36.26 +
   36.27 +int uhci_usb_load(QEMUFile *f, void *opaque, int version_id)
   36.28 +{
   36.29 +    int i;
   36.30 +    UHCIState *s = (UHCIState*)opaque;
   36.31 +
   36.32 +    if (version_id != 1)
   36.33 +        return -EINVAL;
   36.34 +
   36.35 +    qemu_get_be16s(f, &s->cmd);
   36.36 +    qemu_get_be16s(f, &s->status);
   36.37 +    qemu_get_be16s(f, &s->intr);
   36.38 +    qemu_get_be16s(f, &s->frnum);
   36.39 +    qemu_get_be32s(f, &s->fl_base_addr);
   36.40 +    qemu_get_8s(f, &s->sof_timing);
   36.41 +    qemu_get_8s(f, &s->status2);
   36.42 +
   36.43 +    for(i = 0; i < NB_PORTS; i++) {
   36.44 +        qemu_get_be16s(f, &s->ports[i].ctrl);
   36.45 +    }
   36.46 +
   36.47 +    qemu_get_timer(f, s->frame_timer);
   36.48 +
   36.49 +}
   36.50 +
   36.51  void usb_uhci_init(PCIBus *bus, int devfn)
   36.52  {
   36.53      UHCIState *s;
   36.54 @@ -693,4 +737,8 @@ void usb_uhci_init(PCIBus *bus, int devf
   36.55         to rely on this.  */
   36.56      pci_register_io_region(&s->dev, 4, 0x20, 
   36.57                             PCI_ADDRESS_SPACE_IO, uhci_map);
   36.58 +
   36.59 +    register_savevm("UHCI_usb_pci", 0, 1, generic_pci_save, generic_pci_load, s);
   36.60 +
   36.61 +    register_savevm("UHCI usb controller", 0, 1, uhci_usb_save, uhci_usb_load, s);
   36.62  }
    37.1 --- a/tools/ioemu/hw/usb.c	Thu Mar 15 09:00:42 2007 -0600
    37.2 +++ b/tools/ioemu/hw/usb.c	Thu Mar 15 09:04:23 2007 -0600
    37.3 @@ -191,3 +191,43 @@ int set_usb_string(uint8_t *buf, const c
    37.4      }
    37.5      return q - buf;
    37.6  }
    37.7 +
    37.8 +void generic_usb_save(QEMUFile* f, void *opaque)
    37.9 +{
   37.10 +    USBDevice *s = (USBDevice*)opaque;
   37.11 +
   37.12 +    qemu_put_be32s(f, &s->speed);
   37.13 +    qemu_put_8s(f, &s->addr);
   37.14 +    qemu_put_be32s(f, &s->state);
   37.15 +
   37.16 +    qemu_put_buffer(f, s->setup_buf, 8);
   37.17 +    qemu_put_buffer(f, s->data_buf, 1024);
   37.18 +
   37.19 +    qemu_put_be32s(f, &s->remote_wakeup);
   37.20 +    qemu_put_be32s(f, &s->setup_state);
   37.21 +    qemu_put_be32s(f, &s->setup_len);
   37.22 +    qemu_put_be32s(f, &s->setup_index);
   37.23 +
   37.24 +}
   37.25 +
   37.26 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id)
   37.27 +{
   37.28 +    USBDevice *s = (USBDevice*)opaque;
   37.29 +
   37.30 +    if (version_id != 1)
   37.31 +        return -EINVAL;
   37.32 +
   37.33 +    qemu_get_be32s(f, &s->speed);
   37.34 +    qemu_get_8s(f, &s->addr);
   37.35 +    qemu_get_be32s(f, &s->state);
   37.36 +
   37.37 +    qemu_get_buffer(f, s->setup_buf, 8);
   37.38 +    qemu_get_buffer(f, s->data_buf, 1024);
   37.39 +
   37.40 +    qemu_get_be32s(f, &s->remote_wakeup);
   37.41 +    qemu_get_be32s(f, &s->setup_state);
   37.42 +    qemu_get_be32s(f, &s->setup_len);
   37.43 +    qemu_get_be32s(f, &s->setup_index);
   37.44 +
   37.45 +    return 0;
   37.46 +}
    38.1 --- a/tools/ioemu/hw/usb.h	Thu Mar 15 09:00:42 2007 -0600
    38.2 +++ b/tools/ioemu/hw/usb.h	Thu Mar 15 09:04:23 2007 -0600
    38.3 @@ -176,3 +176,9 @@ USBDevice *usb_tablet_init(void);
    38.4  
    38.5  /* usb-msd.c */
    38.6  USBDevice *usb_msd_init(const char *filename);
    38.7 +
    38.8 +/* usb.c */
    38.9 +void generic_usb_save(QEMUFile* f, void *opaque);
   38.10 +int generic_usb_load(QEMUFile* f, void *opaque, int version_id);
   38.11 +
   38.12 +
    39.1 --- a/tools/ioemu/vl.c	Thu Mar 15 09:00:42 2007 -0600
    39.2 +++ b/tools/ioemu/vl.c	Thu Mar 15 09:04:23 2007 -0600
    39.3 @@ -841,10 +841,22 @@ void qemu_get_timer(QEMUFile *f, QEMUTim
    39.4  #ifdef CONFIG_DM
    39.5  static void timer_save(QEMUFile *f, void *opaque)
    39.6  {
    39.7 +    /* need timer for save/restoe qemu_timer in usb_uhci */
    39.8 +    if (cpu_ticks_enabled) {
    39.9 +        hw_error("cannot save state if virtual timers are running");
   39.10 +    }
   39.11 +    qemu_put_be64s(f, &cpu_clock_offset);
   39.12  }
   39.13  
   39.14  static int timer_load(QEMUFile *f, void *opaque, int version_id)
   39.15  {
   39.16 +    if (version_id != 1)
   39.17 +        return -EINVAL;
   39.18 +    if (cpu_ticks_enabled) {
   39.19 +        return -EINVAL;
   39.20 +    }
   39.21 +
   39.22 +    qemu_get_be64s(f, &cpu_clock_offset);
   39.23      return 0;
   39.24  }
   39.25  #else  /* !CONFIG_DM */
   39.26 @@ -3900,6 +3912,7 @@ static int usb_device_add(const char *de
   39.27      const char *p;
   39.28      USBDevice *dev;
   39.29      USBPort *port;
   39.30 +    char usb_name[256] = "USB ";
   39.31  
   39.32      if (!free_usb_ports)
   39.33          return -1;
   39.34 @@ -3936,6 +3949,12 @@ static int usb_device_add(const char *de
   39.35      free_usb_ports = port->next;
   39.36      port->next = used_usb_ports;
   39.37      used_usb_ports = port;
   39.38 +
   39.39 +    pstrcpy(usb_name + strlen(usb_name), 
   39.40 +            sizeof(usb_name) - strlen(usb_name), 
   39.41 +            devname);
   39.42 +    register_savevm(usb_name, 0, 1, generic_usb_save, generic_usb_load, dev);
   39.43 +    
   39.44      usb_attach(port, dev);
   39.45      return 0;
   39.46  }
    40.1 --- a/tools/libxc/xc_dom_x86.c	Thu Mar 15 09:00:42 2007 -0600
    40.2 +++ b/tools/libxc/xc_dom_x86.c	Thu Mar 15 09:04:23 2007 -0600
    40.3 @@ -455,7 +455,7 @@ static int vcpu_x86_32(struct xc_dom_ima
    40.4      ctxt->kernel_ss = ctxt->user_regs.ss;
    40.5      ctxt->kernel_sp = ctxt->user_regs.esp;
    40.6  
    40.7 -    ctxt->flags = VGCF_in_kernel_X86_32;
    40.8 +    ctxt->flags = VGCF_in_kernel_X86_32 | VGCF_online_X86_32;
    40.9      if ( dom->parms.pae == 2 /* extended_cr3 */ ||
   40.10           dom->parms.pae == 3 /* bimodal */ )
   40.11          ctxt->vm_assist |= (1UL << VMASST_TYPE_pae_extended_cr3);
   40.12 @@ -494,7 +494,7 @@ static int vcpu_x86_64(struct xc_dom_ima
   40.13      ctxt->kernel_ss = ctxt->user_regs.ss;
   40.14      ctxt->kernel_sp = ctxt->user_regs.esp;
   40.15  
   40.16 -    ctxt->flags = VGCF_in_kernel_X86_64;
   40.17 +    ctxt->flags = VGCF_in_kernel_X86_64 | VGCF_online_X86_64;
   40.18      cr3_pfn = xc_dom_p2m_guest(dom, dom->pgtables_seg.pfn);
   40.19      ctxt->ctrlreg[3] = xen_pfn_to_cr3_x86_64(cr3_pfn);
   40.20      xc_dom_printf("%s: cr3: pfn 0x%" PRIpfn " mfn 0x%" PRIpfn "\n",
    41.1 --- a/tools/libxc/xc_hvm_build.c	Thu Mar 15 09:00:42 2007 -0600
    41.2 +++ b/tools/libxc/xc_hvm_build.c	Thu Mar 15 09:04:23 2007 -0600
    41.3 @@ -302,9 +302,15 @@ static int setup_guest(int xc_handle,
    41.4  
    41.5      /* Set [er]ip in the way that's right for Xen */
    41.6      if ( strstr(caps, "x86_64") )
    41.7 +    {
    41.8          ctxt->c64.user_regs.rip = elf_uval(&elf, elf.ehdr, e_entry); 
    41.9 +        ctxt->c64.flags = VGCF_online;
   41.10 +    }
   41.11      else
   41.12 +    {
   41.13          ctxt->c32.user_regs.eip = elf_uval(&elf, elf.ehdr, e_entry);
   41.14 +        ctxt->c32.flags = VGCF_online;
   41.15 +    }
   41.16  
   41.17      return 0;
   41.18  
   41.19 @@ -344,7 +350,7 @@ static int xc_hvm_build_internal(int xc_
   41.20  
   41.21      memset(&launch_domctl, 0, sizeof(launch_domctl));
   41.22      launch_domctl.domain = (domid_t)domid;
   41.23 -    launch_domctl.u.vcpucontext.vcpu   = 0;
   41.24 +    launch_domctl.u.vcpucontext.vcpu = 0;
   41.25      set_xen_guest_handle(launch_domctl.u.vcpucontext.ctxt, &ctxt.c);
   41.26      launch_domctl.cmd = XEN_DOMCTL_setvcpucontext;
   41.27      rc = xc_domctl(xc_handle, &launch_domctl);
    42.1 --- a/tools/libxc/xc_linux_restore.c	Thu Mar 15 09:00:42 2007 -0600
    42.2 +++ b/tools/libxc/xc_linux_restore.c	Thu Mar 15 09:04:23 2007 -0600
    42.3 @@ -189,6 +189,7 @@ int xc_linux_restore(int xc_handle, int 
    42.4  
    42.5      uint64_t vcpumap = 1ULL;
    42.6      unsigned int max_vcpu_id = 0;
    42.7 +    int new_ctxt_format = 0;
    42.8  
    42.9      max_pfn = nr_pfns;
   42.10  
   42.11 @@ -372,6 +373,7 @@ int xc_linux_restore(int xc_handle, int 
   42.12          }
   42.13  
   42.14          if (j == -2) {
   42.15 +            new_ctxt_format = 1;
   42.16              if (!read_exact(io_fd, &max_vcpu_id, sizeof(int)) ||
   42.17                  (max_vcpu_id >= 64) ||
   42.18                  !read_exact(io_fd, &vcpumap, sizeof(uint64_t))) {
   42.19 @@ -797,6 +799,9 @@ int xc_linux_restore(int xc_handle, int 
   42.20              goto out;
   42.21          }
   42.22  
   42.23 +        if ( !new_ctxt_format )
   42.24 +            ctxt.flags |= VGCF_online;
   42.25 +
   42.26          if (i == 0) {
   42.27              /*
   42.28               * Uncanonicalise the suspend-record frame number and poke
    43.1 --- a/tools/libxen/include/xen_vm.h	Thu Mar 15 09:00:42 2007 -0600
    43.2 +++ b/tools/libxen/include/xen_vm.h	Thu Mar 15 09:04:23 2007 -0600
    43.3 @@ -87,7 +87,6 @@ typedef struct xen_vm_record
    43.4      int64_t memory_dynamic_max;
    43.5      int64_t memory_dynamic_min;
    43.6      int64_t memory_static_min;
    43.7 -    char *vcpus_policy;
    43.8      xen_string_string_map *vcpus_params;
    43.9      int64_t vcpus_max;
   43.10      int64_t vcpus_at_startup;
   43.11 @@ -323,13 +322,6 @@ xen_vm_get_memory_static_min(xen_session
   43.12  
   43.13  
   43.14  /**
   43.15 - * Get the VCPUs/policy field of the given VM.
   43.16 - */
   43.17 -extern bool
   43.18 -xen_vm_get_vcpus_policy(xen_session *session, char **result, xen_vm vm);
   43.19 -
   43.20 -
   43.21 -/**
   43.22   * Get the VCPUs/params field of the given VM.
   43.23   */
   43.24  extern bool
   43.25 @@ -568,13 +560,6 @@ xen_vm_set_memory_static_min(xen_session
   43.26  
   43.27  
   43.28  /**
   43.29 - * Set the VCPUs/policy field of the given VM.
   43.30 - */
   43.31 -extern bool
   43.32 -xen_vm_set_vcpus_policy(xen_session *session, xen_vm vm, char *policy);
   43.33 -
   43.34 -
   43.35 -/**
   43.36   * Set the VCPUs/params field of the given VM.
   43.37   */
   43.38  extern bool
    44.1 --- a/tools/libxen/src/xen_vm.c	Thu Mar 15 09:00:42 2007 -0600
    44.2 +++ b/tools/libxen/src/xen_vm.c	Thu Mar 15 09:04:23 2007 -0600
    44.3 @@ -88,9 +88,6 @@ static const struct_member xen_vm_record
    44.4          { .key = "memory_static_min",
    44.5            .type = &abstract_type_int,
    44.6            .offset = offsetof(xen_vm_record, memory_static_min) },
    44.7 -        { .key = "VCPUs_policy",
    44.8 -          .type = &abstract_type_string,
    44.9 -          .offset = offsetof(xen_vm_record, vcpus_policy) },
   44.10          { .key = "VCPUs_params",
   44.11            .type = &abstract_type_string_string_map,
   44.12            .offset = offsetof(xen_vm_record, vcpus_params) },
   44.13 @@ -191,7 +188,6 @@ xen_vm_record_free(xen_vm_record *record
   44.14      free(record->name_description);
   44.15      xen_vdi_record_opt_free(record->suspend_vdi);
   44.16      xen_host_record_opt_free(record->resident_on);
   44.17 -    free(record->vcpus_policy);
   44.18      xen_string_string_map_free(record->vcpus_params);
   44.19      xen_console_record_opt_set_free(record->consoles);
   44.20      xen_vif_record_opt_set_free(record->vifs);
   44.21 @@ -498,23 +494,6 @@ xen_vm_get_memory_static_min(xen_session
   44.22  
   44.23  
   44.24  bool
   44.25 -xen_vm_get_vcpus_policy(xen_session *session, char **result, xen_vm vm)
   44.26 -{
   44.27 -    abstract_value param_values[] =
   44.28 -        {
   44.29 -            { .type = &abstract_type_string,
   44.30 -              .u.string_val = vm }
   44.31 -        };
   44.32 -
   44.33 -    abstract_type result_type = abstract_type_string;
   44.34 -
   44.35 -    *result = NULL;
   44.36 -    XEN_CALL_("VM.get_VCPUs_policy");
   44.37 -    return session->ok;
   44.38 -}
   44.39 -
   44.40 -
   44.41 -bool
   44.42  xen_vm_get_vcpus_params(xen_session *session, xen_string_string_map **result, xen_vm vm)
   44.43  {
   44.44      abstract_value param_values[] =
   44.45 @@ -1074,22 +1053,6 @@ xen_vm_set_memory_static_min(xen_session
   44.46  
   44.47  
   44.48  bool
   44.49 -xen_vm_set_vcpus_policy(xen_session *session, xen_vm vm, char *policy)
   44.50 -{
   44.51 -    abstract_value param_values[] =
   44.52 -        {
   44.53 -            { .type = &abstract_type_string,
   44.54 -              .u.string_val = vm },
   44.55 -            { .type = &abstract_type_string,
   44.56 -              .u.string_val = policy }
   44.57 -        };
   44.58 -
   44.59 -    xen_call_(session, "VM.set_VCPUs_policy", param_values, 2, NULL, NULL);
   44.60 -    return session->ok;
   44.61 -}
   44.62 -
   44.63 -
   44.64 -bool
   44.65  xen_vm_set_vcpus_params(xen_session *session, xen_vm vm, xen_string_string_map *params)
   44.66  {
   44.67      abstract_value param_values[] =
    45.1 --- a/tools/libxen/test/test_bindings.c	Thu Mar 15 09:00:42 2007 -0600
    45.2 +++ b/tools/libxen/test/test_bindings.c	Thu Mar 15 09:04:23 2007 -0600
    45.3 @@ -373,7 +373,6 @@ static xen_vm create_new_vm(xen_session 
    45.4              .memory_dynamic_max = 256,
    45.5              .memory_dynamic_min = 128,
    45.6              .memory_static_min = 128,
    45.7 -            .vcpus_policy = "credit",
    45.8              .vcpus_params = vcpus_params,
    45.9              .vcpus_max = 4,
   45.10              .vcpus_at_startup = 2,
    46.1 --- a/tools/python/xen/util/xmlrpclib2.py	Thu Mar 15 09:00:42 2007 -0600
    46.2 +++ b/tools/python/xen/util/xmlrpclib2.py	Thu Mar 15 09:04:23 2007 -0600
    46.3 @@ -200,6 +200,18 @@ class TCPXMLRPCServer(SocketServer.Threa
    46.4              else:
    46.5                  response = self._dispatch(method, params)
    46.6  
    46.7 +            if self.xenapi and \
    46.8 +               (response is None or
    46.9 +                not isinstance(response, dict) or
   46.10 +                'Status' not in response):
   46.11 +                log.exception('Internal error handling %s: Invalid result %s',
   46.12 +                              method, response)
   46.13 +                response = { "Status": "Failure",
   46.14 +                             "ErrorDescription":
   46.15 +                             ['INTERNAL_ERROR',
   46.16 +                              'Invalid result %s handling %s' %
   46.17 +                              (response, method)]}
   46.18 +
   46.19              # With either Unicode or normal strings, we can only transmit
   46.20              # \t, \n, \r, \u0020-\ud7ff, \ue000-\ufffd, and \u10000-\u10ffff
   46.21              # in an XML document.  xmlrpclib does not escape these values
    47.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Mar 15 09:00:42 2007 -0600
    47.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Mar 15 09:04:23 2007 -0600
    47.3 @@ -31,6 +31,7 @@ from xen.xend.XendError import *
    47.4  from xen.xend.XendClient import ERROR_INVALID_DOMAIN
    47.5  from xen.xend.XendLogging import log
    47.6  from xen.xend.XendTask import XendTask
    47.7 +from xen.xend.XendVMMetrics import XendVMMetrics
    47.8  
    47.9  from xen.xend.XendAPIConstants import *
   47.10  from xen.util.xmlrpclib2 import stringify
   47.11 @@ -192,6 +193,16 @@ def valid_vm(func):
   47.12             _check_ref(XendDomain.instance().is_valid_vm,
   47.13                        'VM', func, *args, **kwargs)
   47.14  
   47.15 +def valid_vm_metrics(func):
   47.16 +    """Decorator to verify if vm_metrics_ref is valid before calling method.
   47.17 +
   47.18 +    @param func: function with params: (self, session, vm_metrics_ref, ...)
   47.19 +    @rtype: callable object
   47.20 +    """    
   47.21 +    return lambda *args, **kwargs: \
   47.22 +           _check_ref(XendVMMetrics.is_valid_vm_metrics,
   47.23 +                      'VM_metrics', func, *args, **kwargs)
   47.24 +
   47.25  def valid_network(func):
   47.26      """Decorator to verify if network_ref is valid before calling method.
   47.27  
   47.28 @@ -400,6 +411,7 @@ class XendAPI(object):
   47.29              'host_metrics' : valid_host_metrics,
   47.30              'network'      : valid_network,
   47.31              'VM'           : valid_vm,
   47.32 +            'VM_metrics'   : valid_vm_metrics,
   47.33              'VBD'          : valid_vbd,
   47.34              'VBD_metrics'  : valid_vbd_metrics,
   47.35              'VIF'          : valid_vif,
   47.36 @@ -629,6 +641,7 @@ class XendAPI(object):
   47.37      host_attr_ro = ['software_version',
   47.38                      'resident_VMs',
   47.39                      'host_CPUs',
   47.40 +                    'cpu_configuration',
   47.41                      'metrics',
   47.42                      'capabilities',
   47.43                      'supported_bootloaders',
   47.44 @@ -638,6 +651,7 @@ class XendAPI(object):
   47.45                      'API_version_vendor_implementation']
   47.46      
   47.47      host_attr_rw = ['name_label',
   47.48 +                    'sched_policy',
   47.49                      'name_description',
   47.50                      'other_config']
   47.51  
   47.52 @@ -647,7 +661,8 @@ class XendAPI(object):
   47.53                      ('shutdown', None),
   47.54                      ('add_to_other_config', None),
   47.55                      ('remove_from_other_config', None),
   47.56 -                    ('dmesg', 'String')]
   47.57 +                    ('dmesg', 'String'),
   47.58 +                    ('get_log', 'String')]
   47.59      
   47.60      host_funcs = [('get_by_name_label', 'Set(host)')]
   47.61  
   47.62 @@ -700,7 +715,13 @@ class XendAPI(object):
   47.63          return xen_api_success(XendNode.instance().get_capabilities())
   47.64      def host_get_supported_bootloaders(self, session, host_ref):
   47.65          return xen_api_success(['pygrub'])
   47.66 -
   47.67 +    def host_get_sched_policy(self, _, host_ref):
   47.68 +        return xen_api_success(XendNode.instance().get_vcpus_policy())
   47.69 +    def host_set_sched_policy(self, _, host_ref, policy):
   47.70 +        return xen_api_todo()
   47.71 +    def host_get_cpu_configuration(self, _, host_ref):
   47.72 +        return xen_api_success(XendNode.instance().get_cpu_configuration())
   47.73 +    
   47.74      # object methods
   47.75      def host_disable(self, session, host_ref):
   47.76          XendDomain.instance().set_allow_new_domains(False)
   47.77 @@ -717,8 +738,16 @@ class XendAPI(object):
   47.78              return xen_api_error(XEND_ERROR_HOST_RUNNING)
   47.79          return xen_api_error(XEND_ERROR_UNSUPPORTED)        
   47.80  
   47.81 -    def host_dmesg(self, session, host_ref):
   47.82 -        return xen_api_success(XendDmesg.instance().info())
   47.83 +    def host_dmesg(self, session, host_ref, clear):
   47.84 +        if clear:
   47.85 +            return xen_api_success(XendDmesg.instance().clear())
   47.86 +        else:
   47.87 +            return xen_api_success(XendDmesg.instance().info())
   47.88 +
   47.89 +    def host_get_log(self, session, host_ref):
   47.90 +        log_file = open(XendLogging.getLogFilename())
   47.91 +        log_buffer = log_file.read()
   47.92 +        return xen_api_success(log_buffer)
   47.93  
   47.94      def host_get_record(self, session, host_ref):
   47.95          node = XendNode.instance()
   47.96 @@ -735,9 +764,11 @@ class XendAPI(object):
   47.97                    'other_config': node.other_config,
   47.98                    'resident_VMs': dom.get_domain_refs(),
   47.99                    'host_CPUs': node.get_host_cpu_refs(),
  47.100 +                  'cpu_configuration': node.get_cpu_configuration(),
  47.101                    'metrics': node.host_metrics_uuid,
  47.102                    'capabilities': node.get_capabilities(),
  47.103 -                  'supported_bootloaders': 'pygrub'}
  47.104 +                  'supported_bootloaders': 'pygrub',
  47.105 +                  'sched_policy': node.get_vcpus_policy()}
  47.106          return xen_api_success(record)
  47.107  
  47.108      # class methods
  47.109 @@ -759,7 +790,8 @@ class XendAPI(object):
  47.110                          'modelname',
  47.111                          'stepping',
  47.112                          'flags',
  47.113 -                        'utilisation']
  47.114 +                        'utilisation',
  47.115 +                        'features']
  47.116  
  47.117      # attributes
  47.118      def _host_cpu_get(self, ref, field):
  47.119 @@ -768,6 +800,8 @@ class XendAPI(object):
  47.120  
  47.121      def host_cpu_get_host(self, _, ref):
  47.122          return xen_api_success(XendNode.instance().uuid)
  47.123 +    def host_cpu_get_features(self, _, ref):
  47.124 +        return self._host_cpu_get(ref, 'features')
  47.125      def host_cpu_get_number(self, _, ref):
  47.126          return self._host_cpu_get(ref, 'number')
  47.127      def host_cpu_get_vendor(self, _, ref):
  47.128 @@ -990,11 +1024,9 @@ class XendAPI(object):
  47.129  
  47.130      VM_attr_ro = ['power_state',
  47.131                    'resident_on',
  47.132 -                  'memory_actual',
  47.133                    'memory_static_max',                  
  47.134                    'memory_static_min',
  47.135                    'VCPUs_number',
  47.136 -                  'VCPUs_utilisation',
  47.137                    'consoles',
  47.138                    'VIFs',
  47.139                    'VBDs',
  47.140 @@ -1002,6 +1034,7 @@ class XendAPI(object):
  47.141                    'tools_version',
  47.142                    'domid',
  47.143                    'is_control_domain',
  47.144 +                  'metrics'
  47.145                    ]
  47.146                    
  47.147      VM_attr_rw = ['name_label',
  47.148 @@ -1011,7 +1044,6 @@ class XendAPI(object):
  47.149                    'auto_power_on',
  47.150                    'memory_dynamic_max',
  47.151                    'memory_dynamic_min',
  47.152 -                  'VCPUs_policy',
  47.153                    'VCPUs_params',
  47.154                    'actions_after_shutdown',
  47.155                    'actions_after_reboot',
  47.156 @@ -1040,6 +1072,8 @@ class XendAPI(object):
  47.157                    ('resume', None),
  47.158                    ('add_to_HVM_boot_params', None),
  47.159                    ('remove_from_HVM_boot_params', None),
  47.160 +                  ('add_to_VCPUs_params', None),
  47.161 +                  ('remove_from_VCPUs_params', None),
  47.162                    ('add_to_platform', None),
  47.163                    ('remove_from_platform', None),
  47.164                    ('add_to_other_config', None),
  47.165 @@ -1058,7 +1092,6 @@ class XendAPI(object):
  47.166          'memory_dynamic_max',
  47.167          'memory_dynamic_min',
  47.168          'memory_static_min',
  47.169 -        'VCPUs_policy',
  47.170          'VCPUs_params',
  47.171          'actions_after_shutdown',
  47.172          'actions_after_reboot',
  47.173 @@ -1096,11 +1129,7 @@ class XendAPI(object):
  47.174      
  47.175      def VM_get_resident_on(self, session, vm_ref):
  47.176          return xen_api_success(XendNode.instance().uuid)
  47.177 -    
  47.178 -    def VM_get_memory_actual(self, session, vm_ref):
  47.179 -        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.180 -        return xen_api_todo() # unsupported by xc
  47.181 -    
  47.182 +       
  47.183      def VM_get_memory_static_max(self, session, vm_ref):
  47.184          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.185          return xen_api_success(dom.get_memory_static_max())
  47.186 @@ -1113,10 +1142,6 @@ class XendAPI(object):
  47.187          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.188          return xen_api_success(dom.getVCpuCount())
  47.189      
  47.190 -    def VM_get_VCPUs_utilisation(self, session, vm_ref):
  47.191 -        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.192 -        return xen_api_success(dom.get_vcpus_util())
  47.193 -    
  47.194      def VM_get_VIFs(self, session, vm_ref):
  47.195          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.196          return xen_api_success(dom.get_vifs())
  47.197 @@ -1137,6 +1162,10 @@ class XendAPI(object):
  47.198          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.199          return dom.get_tools_version()
  47.200  
  47.201 +    def VM_get_metrics(self, _, vm_ref):
  47.202 +        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.203 +        return xen_api_success(dom.get_metrics())
  47.204 +
  47.205      # attributes (rw)
  47.206      def VM_get_name_label(self, session, vm_ref):
  47.207          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.208 @@ -1160,11 +1189,7 @@ class XendAPI(object):
  47.209  
  47.210      def VM_get_memory_dynamic_min(self, session, vm_ref):
  47.211          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.212 -        return xen_api_success(dom.get_memory_dynamic_min())        
  47.213 -    
  47.214 -    def VM_get_VCPUs_policy(self, session, vm_ref):
  47.215 -        dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.216 -        return xen_api_success(dom.get_vcpus_policy())
  47.217 +        return xen_api_success(dom.get_memory_dynamic_min())
  47.218      
  47.219      def VM_get_VCPUs_params(self, session, vm_ref):
  47.220          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.221 @@ -1255,13 +1280,24 @@ class XendAPI(object):
  47.222          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.223          return xen_api_todo()
  47.224      
  47.225 -    def VM_set_VCPUs_policy(self, session, vm_ref, policy):
  47.226 +    def VM_set_VCPUs_params(self, session, vm_ref, value):
  47.227 +        return self.VM_set('vcpus_params', session, vm_ref, value)
  47.228 +
  47.229 +    def VM_add_to_VCPUs_params(self, session, vm_ref, key, value):
  47.230          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.231 -        return xen_api_todo()
  47.232 -    
  47.233 -    def VM_set_VCPUs_params(self, session, vm_ref, params):
  47.234 +        if 'vcpus_params' not in dom.info:
  47.235 +            dom.info['vcpus_params'] = {}
  47.236 +        dom.info['vcpus_params'][key] = value
  47.237 +        return self._VM_save(dom)
  47.238 +
  47.239 +    def VM_remove_from_VCPUs_params(self, session, vm_ref, key):
  47.240          dom = XendDomain.instance().get_vm_by_uuid(vm_ref)
  47.241 -        return xen_api_todo()
  47.242 +        if 'vcpus_params' in dom.info \
  47.243 +               and key in dom.info['vcpus_params']:
  47.244 +            del dom.info['vcpus_params'][key]
  47.245 +            return self._VM_save(dom)
  47.246 +        else:
  47.247 +            return xen_api_success_void()
  47.248      
  47.249      def VM_set_actions_after_shutdown(self, session, vm_ref, action):
  47.250          if action not in XEN_API_ON_NORMAL_EXIT:
  47.251 @@ -1401,11 +1437,8 @@ class XendAPI(object):
  47.252              'memory_static_max': xeninfo.get_memory_static_max(),
  47.253              'memory_dynamic_min': xeninfo.get_memory_dynamic_min(),
  47.254              'memory_dynamic_max': xeninfo.get_memory_dynamic_max(),
  47.255 -            'memory_actual': xeninfo.get_memory_static_min(),
  47.256 -            'VCPUs_policy': xeninfo.get_vcpus_policy(),
  47.257              'VCPUs_params': xeninfo.get_vcpus_params(),
  47.258              'VCPUs_number': xeninfo.getVCpuCount(),
  47.259 -            'VCPUs_utilisation': xeninfo.get_vcpus_util(),
  47.260              'actions_after_shutdown': xeninfo.get_on_shutdown(),
  47.261              'actions_after_reboot': xeninfo.get_on_reboot(),
  47.262              'actions_after_suspend': xeninfo.get_on_suspend(),
  47.263 @@ -1480,6 +1513,33 @@ class XendAPI(object):
  47.264          return XendTask.log_progress(0, 100, do_vm_func,
  47.265                                       "domain_unpause", vm_ref)
  47.266  
  47.267 +    # Xen API: Class VM_metrics
  47.268 +    # ----------------------------------------------------------------
  47.269 +
  47.270 +    VM_metrics_attr_ro = ['memory_actual',
  47.271 +                           'vcpus_number',
  47.272 +                           'vcpus_utilisation']
  47.273 +    VM_metrics_attr_rw = []
  47.274 +    VM_metrics_methods = []
  47.275 +
  47.276 +    def _VM_metrics_get(self, ref):
  47.277 +        return XendVMMetrics.get_by_uuid(ref)
  47.278 +
  47.279 +    def VM_metrics_get_all(self, _):
  47.280 +        return xen_api_success(XendVMMetrics.get_all())
  47.281 +
  47.282 +    def VM_metrics_get_record(self, _, ref):
  47.283 +        return xen_api_success(self._VM_metrics_get(ref).get_record())
  47.284 +
  47.285 +    def VM_metrics_get_memory_actual(self, _, ref):
  47.286 +        return xen_api_success(self._VM_metrics_get(ref).get_memory_actual())
  47.287 +
  47.288 +    def VM_metrics_get_vcpus_number(self, _, ref):
  47.289 +        return xen_api_success(self._VM_metrics_get(ref).get_vcpus_number())
  47.290 +
  47.291 +    def VM_metrics_get_vcpus_utilisation(self, _, ref):
  47.292 +        return xen_api_success(self._VM_metrics_get(ref).get_metrics_get_vcpus_utilisation())
  47.293 +
  47.294      # Xen API: Class VBD
  47.295      # ----------------------------------------------------------------
  47.296  
    48.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Thu Mar 15 09:00:42 2007 -0600
    48.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Thu Mar 15 09:04:23 2007 -0600
    48.3 @@ -9,6 +9,7 @@ import os
    48.4  import re
    48.5  import string
    48.6  import threading
    48.7 +import fcntl
    48.8  from struct import pack, unpack, calcsize
    48.9  
   48.10  from xen.util.xpopen import xPopen3
   48.11 @@ -73,13 +74,14 @@ def save(fd, dominfo, network, live, dst
   48.12          write_exact(fd, config, "could not write guest state file: config")
   48.13  
   48.14          image_cfg = dominfo.info.get('image', {})
   48.15 -        hvm = image_cfg.has_key('hvm')
   48.16 +        hvm = dominfo.info.is_hvm()
   48.17          stdvga = 0
   48.18  
   48.19          if hvm:
   48.20              log.info("save hvm domain")
   48.21 -            if image_cfg['hvm']['devices']['stdvga'] == 1:
   48.22 -                stdvga = 1
   48.23 +            if dominfo.info['platform'].has_key('stdvga'):
   48.24 +                if dominfo.info['platform']['stdvga'] == 1:
   48.25 +                    stdvga = 1
   48.26  
   48.27          # xc_save takes three customization parameters: maxit, max_f, and
   48.28          # flags the last controls whether or not save is 'live', while the
   48.29 @@ -188,11 +190,11 @@ def restore(xd, fd, dominfo = None, paus
   48.30  
   48.31      # if hvm, pass mem size to calculate the store_mfn
   48.32      image_cfg = dominfo.info.get('image', {})
   48.33 -    is_hvm  = image_cfg.has_key('hvm')
   48.34 +    is_hvm = dominfo.info.is_hvm()
   48.35      if is_hvm:
   48.36          hvm  = dominfo.info['memory_static_min']
   48.37 -        apic = dominfo.info['image']['hvm'].get('apic', 0)
   48.38 -        pae  = dominfo.info['image']['hvm'].get('pae',  0)
   48.39 +        apic = dominfo.info['platform'].get('apic', 0)
   48.40 +        pae  = dominfo.info['platform'].get('pae',  0)
   48.41          log.info("restore hvm domain %d, mem=%d, apic=%d, pae=%d",
   48.42                   dominfo.domid, hvm, apic, pae)
   48.43      else:
   48.44 @@ -229,6 +231,15 @@ def restore(xd, fd, dominfo = None, paus
   48.45  
   48.46          forkHelper(cmd, fd, handler.handler, True)
   48.47  
   48.48 +        # We don't want to pass this fd to any other children -- we 
   48.49 +        # might need to recover ths disk space that backs it.
   48.50 +        try:
   48.51 +            flags = fcntl.fcntl(fd, fcntl.F_GETFD)
   48.52 +            flags |= fcntl.FD_CLOEXEC
   48.53 +            fcntl.fcntl(fd, fcntl.F_SETFD, flags)
   48.54 +        except:
   48.55 +            pass
   48.56 +
   48.57          if handler.store_mfn is None:
   48.58              raise XendError('Could not read store MFN')
   48.59  
    49.1 --- a/tools/python/xen/xend/XendConfig.py	Thu Mar 15 09:00:42 2007 -0600
    49.2 +++ b/tools/python/xen/xend/XendConfig.py	Thu Mar 15 09:04:23 2007 -0600
    49.3 @@ -118,11 +118,12 @@ XENAPI_CFG_TO_LEGACY_CFG = {
    49.4  LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(XENAPI_CFG_TO_LEGACY_CFG)
    49.5  
    49.6  # Platform configuration keys.
    49.7 -XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'device_model', 'display', 'fda',
    49.8 -                        'fdb', 'keymap', 'isa', 'localtime', 'nographic',
    49.9 -                        'pae', 'serial', 'sdl', 'soundhw','stdvga', 'usb',
   49.10 -                        'usbdevice', 'vnc', 'vncconsole', 'vncdisplay',
   49.11 -                        'vnclisten', 'vncpasswd', 'vncunused', 'xauthority']
   49.12 +XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'display', 
   49.13 +                        'fda', 'fdb', 'keymap', 'isa', 'localtime',
   49.14 +                        'nographic', 'pae', 'serial', 'sdl',
   49.15 +                        'soundhw','stdvga', 'usb', 'usbdevice', 'vnc',
   49.16 +                        'vncconsole', 'vncdisplay', 'vnclisten',
   49.17 +                        'vncpasswd', 'vncunused', 'xauthority']
   49.18  
   49.19  # List of XendConfig configuration keys that have no direct equivalent
   49.20  # in the old world.
    50.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 15 09:00:42 2007 -0600
    50.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Mar 15 09:04:23 2007 -0600
    50.3 @@ -51,6 +51,8 @@ from xen.xend.xenstore.xswatch import xs
    50.4  from xen.xend.XendConstants import *
    50.5  from xen.xend.XendAPIConstants import *
    50.6  
    50.7 +from xen.xend.XendVMMetrics import XendVMMetrics
    50.8 +
    50.9  MIGRATE_TIMEOUT = 30.0
   50.10  BOOTLOADER_LOOPBACK_DEVICE = '/dev/xvdp'
   50.11  
   50.12 @@ -369,6 +371,8 @@ class XendDomainInfo:
   50.13              self._augmentInfo(priv)
   50.14  
   50.15          self._checkName(self.info['name_label'])
   50.16 +
   50.17 +        self.metrics = XendVMMetrics(uuid.createString(), self)
   50.18              
   50.19  
   50.20      #
   50.21 @@ -627,6 +631,10 @@ class XendDomainInfo:
   50.22          except RuntimeError, exn:
   50.23              raise XendError(str(exn))
   50.24  
   50.25 +
   50.26 +    def getDomInfo(self):
   50.27 +        return dom_get(self.domid)
   50.28 +
   50.29      #
   50.30      # internal functions ... TODO: re-categorised
   50.31      # 
   50.32 @@ -2037,15 +2045,6 @@ class XendDomainInfo:
   50.33          return self.info.get('memory_dynamic_max', 0)
   50.34      def get_memory_dynamic_min(self):
   50.35          return self.info.get('memory_dynamic_min', 0)
   50.36 -
   50.37 -    def get_vcpus_policy(self):
   50.38 -        sched_id = xc.sched_id_get()
   50.39 -        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
   50.40 -            return 'sedf'
   50.41 -        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
   50.42 -            return 'credit'
   50.43 -        else:
   50.44 -            return 'unknown'
   50.45      def get_vcpus_params(self):
   50.46          if self.getDomid() is None:
   50.47              return self.info['vcpus_params']
   50.48 @@ -2060,6 +2059,8 @@ class XendDomainInfo:
   50.49          return self.info.get('pci_bus', '')
   50.50      def get_tools_version(self):
   50.51          return self.info.get('tools_version', {})
   50.52 +    def get_metrics(self):
   50.53 +        return self.metrics.get_uuid();
   50.54      
   50.55      def get_on_shutdown(self):
   50.56          after_shutdown = self.info.get('actions_after_shutdown')
    51.1 --- a/tools/python/xen/xend/XendNode.py	Thu Mar 15 09:00:42 2007 -0600
    51.2 +++ b/tools/python/xen/xend/XendNode.py	Thu Mar 15 09:04:23 2007 -0600
    51.3 @@ -75,6 +75,11 @@ class XendNode:
    51.4              self.other_config = {}
    51.5              self.cpus = {}
    51.6              self.host_metrics_uuid = uuid.createString()
    51.7 +
    51.8 +        # put some arbitrary params in other_config as this
    51.9 +        # is directly exposed via XenAPI
   51.10 +        self.other_config["xen_pagesize"] = self.xeninfo_dict()["xen_pagesize"]
   51.11 +        self.other_config["platform_params"] = self.xeninfo_dict()["platform_params"]
   51.12              
   51.13          # load CPU UUIDs
   51.14          saved_cpus = self.state_store.load_state('cpu')
   51.15 @@ -353,14 +358,37 @@ class XendNode:
   51.16  
   51.17      def xen_version(self):
   51.18          info = self.xc.xeninfo()
   51.19 +
   51.20          try:
   51.21              from xen import VERSION
   51.22 -            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
   51.23 +            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
   51.24                      'Xend': VERSION}
   51.25          except (ImportError, AttributeError):
   51.26 -            return {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
   51.27 +            info = {'Xen': '%(xen_major)d.%(xen_minor)d' % info,
   51.28                      'Xend': '3.0.3'}
   51.29  
   51.30 +        # Add xend_config_format
   51.31 +        info.update(self.xendinfo_dict())
   51.32 +
   51.33 +        # Add version info about machine
   51.34 +        info.update(self.nodeinfo_dict())
   51.35 +
   51.36 +        # Add specific xen version info
   51.37 +        xeninfo_dict = self.xeninfo_dict()
   51.38 +
   51.39 +        info.update({
   51.40 +            "xen_major":         xeninfo_dict["xen_major"],
   51.41 +            "xen_minor":         xeninfo_dict["xen_minor"],
   51.42 +            "xen_extra":         xeninfo_dict["xen_extra"],
   51.43 +            "cc_compiler":       xeninfo_dict["cc_compiler"],
   51.44 +            "cc_compile_by":     xeninfo_dict["cc_compile_by"],
   51.45 +            "cc_compile_domain": xeninfo_dict["cc_compile_domain"],
   51.46 +            "cc_compile_date":   xeninfo_dict["cc_compile_date"],
   51.47 +            "xen_changeset":     xeninfo_dict["xen_changeset"]
   51.48 +            })
   51.49 +        
   51.50 +        return info
   51.51 +
   51.52      def get_name(self):
   51.53          return self.name
   51.54  
   51.55 @@ -415,6 +443,27 @@ class XendNode:
   51.56  
   51.57          return 0.0
   51.58  
   51.59 +    def get_vcpus_policy(self):
   51.60 +        sched_id = self.xc.sched_id_get()
   51.61 +        if sched_id == xen.lowlevel.xc.XEN_SCHEDULER_SEDF:
   51.62 +            return 'sedf'
   51.63 +        elif sched_id == xen.lowlevel.xc.XEN_SCHEDULER_CREDIT:
   51.64 +            return 'credit'
   51.65 +        else:
   51.66 +            return 'unknown'
   51.67 +
   51.68 +    def get_cpu_configuration(self):
   51.69 +        phys_info = self.physinfo_dict()
   51.70 +
   51.71 +        cpu_info = {
   51.72 +            "nr_nodes":         phys_info["nr_nodes"],
   51.73 +            "sockets_per_node": phys_info["sockets_per_node"],
   51.74 +            "cores_per_socket": phys_info["cores_per_socket"],
   51.75 +            "threads_per_core": phys_info["threads_per_core"]
   51.76 +            }
   51.77 +
   51.78 +        return cpu_info
   51.79 +    
   51.80      #
   51.81      # Network Functions
   51.82      #
    52.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    52.2 +++ b/tools/python/xen/xend/XendVMMetrics.py	Thu Mar 15 09:04:23 2007 -0600
    52.3 @@ -0,0 +1,70 @@
    52.4 +#============================================================================
    52.5 +# This library is free software; you can redistribute it and/or
    52.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    52.7 +# License as published by the Free Software Foundation.
    52.8 +#
    52.9 +# This library is distributed in the hope that it will be useful,
   52.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   52.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   52.12 +# Lesser General Public License for more details.
   52.13 +#
   52.14 +# You should have received a copy of the GNU Lesser General Public
   52.15 +# License along with this library; if not, write to the Free Software
   52.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   52.17 +#============================================================================
   52.18 +# Copyright (c) 2006-2007 Xensource Inc.
   52.19 +#============================================================================
   52.20 +
   52.21 +from xen.xend.XendLogging import log
   52.22 +
   52.23 +instances = {}
   52.24 +
   52.25 +class XendVMMetrics:
   52.26 +    """VM Metrics."""
   52.27 +
   52.28 +    def get_by_uuid(_, uuid):
   52.29 +        return instances[uuid]
   52.30 +
   52.31 +    get_by_uuid = classmethod(get_by_uuid)
   52.32 +
   52.33 +    def is_valid_vm_metrics(_, uuid):
   52.34 +        return uuid in instances
   52.35 +
   52.36 +    is_valid_vm_metrics = classmethod(is_valid_vm_metrics)
   52.37 +
   52.38 +    def get_all(_):
   52.39 +        return instances.keys()
   52.40 +
   52.41 +    get_all = classmethod(get_all)
   52.42 +   
   52.43 +    def __init__(self, uuid, xend_domain_instance):
   52.44 +        self.uuid = uuid
   52.45 +        self.xend_domain_instance = xend_domain_instance
   52.46 +        instances[uuid] = self
   52.47 +
   52.48 +    def get_uuid(self):
   52.49 +        return self.uuid
   52.50 +
   52.51 +    def get_memory_actual(self):
   52.52 +        return self.get_record()["memory_actual"]
   52.53 +
   52.54 +    def get_vcpus_number(self):
   52.55 +        return self.get_record()["vcpus_number"]
   52.56 +    
   52.57 +    def get_vcpus_utilisation(self):
   52.58 +        return self.xend_domain_instance.get_vcpus_util()
   52.59 +
   52.60 +    def get_record(self):
   52.61 +        domInfo = self.xend_domain_instance.getDomInfo()
   52.62 +        if domInfo:
   52.63 +            return { 'uuid'              : self.uuid,
   52.64 +                     'memory_actual'     : domInfo["mem_kb"] * 1024,
   52.65 +                     'vcpus_number'      : domInfo["online_vcpus"],
   52.66 +                     'vcpus_utilisation' : self.get_vcpus_utilisation()
   52.67 +                   }
   52.68 +        else:
   52.69 +            return { 'uuid'              : self.uuid,
   52.70 +                     'memory_actual'     : 0,
   52.71 +                     'vcpus_number'      : 0,
   52.72 +                     'vcpus_utilisation' : {}
   52.73 +                   }
    53.1 --- a/tools/python/xen/xend/image.py	Thu Mar 15 09:00:42 2007 -0600
    53.2 +++ b/tools/python/xen/xend/image.py	Thu Mar 15 09:04:23 2007 -0600
    53.3 @@ -392,7 +392,7 @@ class HVMImageHandler(ImageHandler):
    53.4          # Find RFB console device, and if it exists, make QEMU enable
    53.5          # the VNC console.
    53.6          #
    53.7 -        if vmConfig['platform'].get('nographic'):
    53.8 +        if int(vmConfig['platform'].get('nographic', 0)) != 0:
    53.9              # skip vnc init if nographic is set
   53.10              ret.append('-nographic')
   53.11              return ret
    54.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 15 09:00:42 2007 -0600
    54.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Mar 15 09:04:23 2007 -0600
    54.3 @@ -276,9 +276,12 @@ class Daemon:
    54.4              if not m:
    54.5                  return None
    54.6              modulename = m.group(1)
    54.7 -            if re.search('sxp.py', modulename):
    54.8 -                return None
    54.9 -            if re.search('SrvServer.py', modulename):
   54.10 +            if modulename.endswith('.pyc'):
   54.11 +                modulename = modulename[:-1]
   54.12 +            if modulename == 'sxp.py' or \
   54.13 +               modulename == 'XendLogging.py' or \
   54.14 +               modulename == 'XendMonitor.py' or \
   54.15 +               modulename == 'server/SrvServer.py':
   54.16                  return None
   54.17              self.traceindent += 1
   54.18              self.print_trace("> %s:%s\n"
    55.1 --- a/tools/python/xen/xend/server/vfbif.py	Thu Mar 15 09:00:42 2007 -0600
    55.2 +++ b/tools/python/xen/xend/server/vfbif.py	Thu Mar 15 09:04:23 2007 -0600
    55.3 @@ -46,7 +46,7 @@ class VfbifController(DevController):
    55.4  
    55.5      def createDevice(self, config):
    55.6          DevController.createDevice(self, config)
    55.7 -        if self.vm.info.get('HVM_boot_policy'):
    55.8 +        if self.vm.info.is_hvm():
    55.9              # is HVM, so qemu-dm will handle the vfb.
   55.10              return
   55.11          
    56.1 --- a/tools/python/xen/xm/XenAPI.py	Thu Mar 15 09:00:42 2007 -0600
    56.2 +++ b/tools/python/xen/xm/XenAPI.py	Thu Mar 15 09:04:23 2007 -0600
    56.3 @@ -155,7 +155,7 @@ class Session(xen.util.xmlrpclib2.Server
    56.4  
    56.5  def _parse_result(result):
    56.6      if type(result) != dict or 'Status' not in result:
    56.7 -        raise xmlrpclib.Fault(500, 'Missing Status in response from server' + result)
    56.8 +        raise xmlrpclib.Fault(500, 'Missing Status in response from server: ' + str(result))
    56.9      if result['Status'] == 'Success':
   56.10          if 'Value' in result:
   56.11              return result['Value']
    57.1 --- a/tools/python/xen/xm/addlabel.py	Thu Mar 15 09:00:42 2007 -0600
    57.2 +++ b/tools/python/xen/xm/addlabel.py	Thu Mar 15 09:04:23 2007 -0600
    57.3 @@ -17,7 +17,7 @@
    57.4  # Author: Bryan D. Payne <bdpayne@us.ibm.com>
    57.5  #============================================================================
    57.6  
    57.7 -"""Labeling a domain configuration file or a resoruce.
    57.8 +"""Labeling a domain configuration file or a resource.
    57.9  """
   57.10  import os
   57.11  import sys
    58.1 --- a/tools/python/xen/xm/main.py	Thu Mar 15 09:00:42 2007 -0600
    58.2 +++ b/tools/python/xen/xm/main.py	Thu Mar 15 09:04:23 2007 -0600
    58.3 @@ -139,7 +139,7 @@ SUBCOMMAND_HELP = {
    58.4                       'Send a trigger to a domain.'),
    58.5      'vcpu-list'   : ('[<Domain>]',
    58.6                       'List the VCPUs for a domain or all domains.'),
    58.7 -    'vcpu-pin'    : ('<Domain> <VCPU> <CPUs>',
    58.8 +    'vcpu-pin'    : ('<Domain> <VCPU> <CPUs|all>',
    58.9                       'Set which CPUs a VCPU can use.'),
   58.10      'vcpu-set'    : ('<Domain> <vCPUs>',
   58.11                       'Set the number of active VCPUs for allowed for the'
   58.12 @@ -557,7 +557,7 @@ class Shell(cmd.Cmd):
   58.13          if serverType == SERVER_XEN_API:
   58.14              res = server.xenapi._UNSUPPORTED_list_all_methods()
   58.15              for f in res:
   58.16 -                setattr(Shell, 'do_' + f, self.default)
   58.17 +                setattr(Shell, 'do_' + f + ' ', self.default)
   58.18  
   58.19      def preloop(self):
   58.20          cmd.Cmd.preloop(self)
   58.21 @@ -750,11 +750,14 @@ def parse_doms_info(info):
   58.22          }
   58.23  
   58.24  def check_sched_type(sched):
   58.25 -    current = 'unknown'
   58.26 -    for x in server.xend.node.info()[1:]:
   58.27 -        if len(x) > 1 and x[0] == 'xen_scheduler':
   58.28 -            current = x[1]
   58.29 -            break
   58.30 +    if serverType == SERVER_XEN_API:
   58.31 +        current = server.xenapi.host.get_sched_policy(server.xenapi.session.get_this_host())
   58.32 +    else:
   58.33 +        current = 'unknown'
   58.34 +        for x in server.xend.node.info()[1:]:
   58.35 +            if len(x) > 1 and x[0] == 'xen_scheduler':
   58.36 +                current = x[1]
   58.37 +                break
   58.38      if sched != current:
   58.39          err("Xen is running with the %s scheduler" % current)
   58.40          sys.exit(1)
   58.41 @@ -1084,7 +1087,10 @@ def xm_vcpu_pin(args):
   58.42  
   58.43      dom  = args[0]
   58.44      vcpu = args[1]
   58.45 -    cpumap = cpu_make_map(args[2])
   58.46 +    if args[2] == 'all':
   58.47 +        cpumap = cpu_make_map('0-63')
   58.48 +    else:
   58.49 +        cpumap = cpu_make_map(args[2])
   58.50      
   58.51      server.xend.domain.pincpu(dom, vcpu, cpumap)
   58.52  
   58.53 @@ -1092,49 +1098,69 @@ def xm_mem_max(args):
   58.54      arg_check(args, "mem-max", 2)
   58.55  
   58.56      dom = args[0]
   58.57 -    mem = int_unit(args[1], 'm')
   58.58  
   58.59 -    server.xend.domain.maxmem_set(dom, mem)
   58.60 +    if serverType == SERVER_XEN_API:
   58.61 +        mem = int_unit(args[1], 'k') * 1024
   58.62 +        server.xenapi.VM.set_memory_static_max(get_single_vm(dom), mem)
   58.63 +    else:
   58.64 +        mem = int_unit(args[1], 'm')
   58.65 +        server.xend.domain.maxmem_set(dom, mem)
   58.66      
   58.67  def xm_mem_set(args):
   58.68      arg_check(args, "mem-set", 2)
   58.69  
   58.70      dom = args[0]
   58.71 -    mem_target = int_unit(args[1], 'm')
   58.72  
   58.73 -    server.xend.domain.setMemoryTarget(dom, mem_target)
   58.74 +    if serverType == SERVER_XEN_API:
   58.75 +        mem_target = int_unit(args[1], 'k') * 1024
   58.76 +        server.xenapi.VM.set_memory_dynamic_max(get_single_vm(dom), mem_target)
   58.77 +        server.xenapi.VM.set_memory_dynamic_min(get_single_vm(dom), mem_target)
   58.78 +    else:
   58.79 +        mem_target = int_unit(args[1], 'm')
   58.80 +        server.xend.domain.setMemoryTarget(dom, mem_target)
   58.81      
   58.82  def xm_vcpu_set(args):
   58.83      arg_check(args, "vcpu-set", 2)
   58.84 -    
   58.85 -    server.xend.domain.setVCpuCount(args[0], int(args[1]))
   58.86 +
   58.87 +    dom = args[0]
   58.88 +    vcpus = int(args[1])
   58.89  
   58.90 +    if serverType == SERVER_XEN_API:
   58.91 +        server.xenapi.VM.set_vcpus_live(get_single_vm(dom), vcpus)
   58.92 +    else:
   58.93 +        server.xend.domain.setVCpuCount(dom, vcpus)
   58.94  
   58.95  def xm_destroy(args):
   58.96      arg_check(args, "destroy", 1)
   58.97  
   58.98      dom = args[0]
   58.99 +    
  58.100      if serverType == SERVER_XEN_API:
  58.101          server.xenapi.VM.hard_shutdown(get_single_vm(dom))
  58.102      else:
  58.103          server.xend.domain.destroy(dom)
  58.104  
  58.105 -
  58.106  def xm_domid(args):
  58.107      arg_check(args, "domid", 1)
  58.108  
  58.109      name = args[0]
  58.110  
  58.111 -    dom = server.xend.domain(name)
  58.112 -    print sxp.child_value(dom, 'domid')
  58.113 +    if serverType == SERVER_XEN_API:
  58.114 +        print server.xenapi.VM.get_domid(get_single_vm(name))
  58.115 +    else:
  58.116 +        dom = server.xend.domain(name)
  58.117 +        print sxp.child_value(dom, 'domid')
  58.118      
  58.119  def xm_domname(args):
  58.120      arg_check(args, "domname", 1)
  58.121  
  58.122      name = args[0]
  58.123 -
  58.124 -    dom = server.xend.domain(name)
  58.125 -    print sxp.child_value(dom, 'name')
  58.126 +    
  58.127 +    if serverType == SERVER_XEN_API:
  58.128 +        print server.xenapi.VM.get_name_label(get_single_vm(name))
  58.129 +    else:
  58.130 +        dom = server.xend.domain(name)
  58.131 +        print sxp.child_value(dom, 'name')
  58.132  
  58.133  def xm_sched_sedf(args):
  58.134      def ns_to_ms(val):
  58.135 @@ -1282,13 +1308,59 @@ def xm_sched_credit(args):
  58.136  def xm_info(args):
  58.137      arg_check(args, "info", 0)
  58.138  
  58.139 -    info = server.xend.node.info()
  58.140 -    
  58.141 -    for x in info[1:]:
  58.142 -        if len(x) < 2: 
  58.143 -            print "%-23s: (none)" % x[0]
  58.144 -        else: 
  58.145 -            print "%-23s:" % x[0], x[1]
  58.146 +    if serverType == SERVER_XEN_API:
  58.147 +
  58.148 +        # Need to fake out old style xm info as people rely on parsing it
  58.149 +        
  58.150 +        host_record = server.xenapi.host.get_record(
  58.151 +            server.xenapi.session.get_this_host())        
  58.152 +
  58.153 +        host_cpu_records = map(server.xenapi.host_cpu.get_record, host_record["host_CPUs"])
  58.154 +
  58.155 +        host_metrics_record = server.xenapi.host_metrics.get_record(host_record["metrics"])
  58.156 +
  58.157 +        info = {
  58.158 +            "host":              host_record["name_label"],
  58.159 +            "release":           host_record["software_version"]["release"],
  58.160 +            "version":           host_record["software_version"]["version"],
  58.161 +            "machine":           host_record["software_version"]["machine"],
  58.162 +            "nr_cpus":           len(host_record["host_CPUs"]),
  58.163 +            "nr_nodes":          host_record["cpu_configuration"]["nr_nodes"],
  58.164 +            "sockets_per_node":  host_record["cpu_configuration"]["sockets_per_node"],
  58.165 +            "cores_per_socket":  host_record["cpu_configuration"]["cores_per_socket"],
  58.166 +            "threads_per_core":  host_record["cpu_configuration"]["threads_per_core"],
  58.167 +            "cpu_mhz":           sum([int(host_cpu_record["speed"]) for host_cpu_record in host_cpu_records])
  58.168 +                                   / len(host_cpu_records),
  58.169 +            "hw_caps":           host_cpu_records[0]["features"],
  58.170 +            "total_memory":      int(host_metrics_record["memory_total"])/1024/1024,
  58.171 +            "free_memory":       int(host_metrics_record["memory_free"])/1024/1024,
  58.172 +            "xen_major":         host_record["software_version"]["xen_major"],
  58.173 +            "xen_minor":         host_record["software_version"]["xen_minor"],
  58.174 +            "xen_extra":         host_record["software_version"]["xen_extra"],
  58.175 +            "xen_caps":          " ".join(host_record["capabilities"]),
  58.176 +            "xen_scheduler":     host_record["sched_policy"],
  58.177 +            "xen_pagesize":      host_record["other_config"]["xen_pagesize"],
  58.178 +            "platform_params":   host_record["other_config"]["platform_params"],
  58.179 +            "xen_changeset":     host_record["software_version"]["xen_changeset"],
  58.180 +            "cc_compiler":       host_record["software_version"]["cc_compiler"],
  58.181 +            "cc_compile_by":     host_record["software_version"]["cc_compile_by"],
  58.182 +            "cc_compile_domain": host_record["software_version"]["cc_compile_domain"],
  58.183 +            "cc_compile_date":   host_record["software_version"]["cc_compile_date"],
  58.184 +            "xend_config_format":host_record["software_version"]["xend_config_format"]                                
  58.185 +        }
  58.186 +
  58.187 +        sorted = info.items()
  58.188 +        sorted.sort(lambda (x1,y1), (x2,y2): -cmp(x1,x2))
  58.189 +        
  58.190 +        for (k, v) in sorted:
  58.191 +           print "%-23s:" % k, v 
  58.192 +    else:
  58.193 +        info = server.xend.node.info()
  58.194 +        for x in info[1:]:
  58.195 +            if len(x) < 2: 
  58.196 +                print "%-23s: (none)" % x[0]
  58.197 +            else: 
  58.198 +                print "%-23s:" % x[0], x[1]
  58.199  
  58.200  def xm_console(args):
  58.201      arg_check(args, "console", 1, 2)
  58.202 @@ -1314,13 +1386,17 @@ def xm_console(args):
  58.203      dom = params[0]
  58.204  
  58.205      try:
  58.206 -        info = server.xend.domain(dom)
  58.207 +        if serverType == SERVER_XEN_API:
  58.208 +            domid = int(server.xenapi.VM.get_domid(get_single_vm(dom)))
  58.209 +        else:
  58.210 +            info = server.xend.domain(dom)
  58.211 +            domid = int(sxp.child_value(info, 'domid', '-1'))
  58.212      except:
  58.213          if quiet:
  58.214              sys.exit(1)
  58.215          else:
  58.216              raise
  58.217 -    domid = int(sxp.child_value(info, 'domid', '-1'))
  58.218 +        
  58.219      if domid == -1:
  58.220          if quiet:
  58.221              sys.exit(1)
  58.222 @@ -1428,17 +1504,33 @@ def xm_dmesg(args):
  58.223          err("No parameter required")
  58.224          usage('dmesg')
  58.225  
  58.226 -    if not use_clear:
  58.227 -        print server.xend.node.dmesg.info()
  58.228 +    if serverType == SERVER_XEN_API:
  58.229 +        if not use_clear:
  58.230 +            print server.xenapi.host.dmesg(
  58.231 +                server.xenapi.session.get_this_host(),0)
  58.232 +        else:
  58.233 +            server.xenapi.host.dmesg(
  58.234 +                server.xenapi.session.get_this_host(),1)
  58.235      else:
  58.236 -        server.xend.node.dmesg.clear()
  58.237 +        if not use_clear:
  58.238 +            print server.xend.node.dmesg.info()
  58.239 +        else:
  58.240 +            server.xend.node.dmesg.clear()
  58.241  
  58.242  def xm_log(args):
  58.243      arg_check(args, "log", 0)
  58.244 -    
  58.245 -    print server.xend.node.log()
  58.246 +
  58.247 +    if serverType == SERVER_XEN_API:
  58.248 +        print server.xenapi.host.get_log(
  58.249 +            server.xenapi.session.get_this_host())
  58.250 +    else:
  58.251 +        print server.xend.node.log()
  58.252  
  58.253  def xm_serve(args):
  58.254 +    if serverType == SERVER_XEN_API:
  58.255 +        print "Not supported with XenAPI"
  58.256 +        sys.exit(-1)
  58.257 +
  58.258      arg_check(args, "serve", 0)
  58.259  
  58.260      from fcntl import fcntl, F_SETFL
    59.1 --- a/tools/python/xen/xm/shutdown.py	Thu Mar 15 09:00:42 2007 -0600
    59.2 +++ b/tools/python/xen/xm/shutdown.py	Thu Mar 15 09:04:23 2007 -0600
    59.3 @@ -21,7 +21,8 @@ import time
    59.4  
    59.5  from xen.xend import sxp
    59.6  from opts import *
    59.7 -from main import server
    59.8 +from main import server, serverType, SERVER_XEN_API, get_single_vm
    59.9 +from xen.xend.XendAPIConstants import *
   59.10  
   59.11  gopts = Opts(use="""[options] [DOM]
   59.12  
   59.13 @@ -49,6 +50,9 @@ gopts.opt('reboot', short='R',
   59.14            use='Shutdown and reboot.')
   59.15  
   59.16  def wait_reboot(opts, doms, rcs):
   59.17 +    if serverType == SERVER_XEN_API:
   59.18 +	    opts.err("Cannot wait for reboot w/ XenAPI (yet)")
   59.19 +
   59.20      while doms:
   59.21          alive = server.xend.domains(0)
   59.22          reboot = []
   59.23 @@ -68,7 +72,12 @@ def wait_reboot(opts, doms, rcs):
   59.24  
   59.25  def wait_shutdown(opts, doms):
   59.26      while doms:
   59.27 -        alive = server.xend.domains(0)
   59.28 +        if serverType == SERVER_XEN_API:
   59.29 +		    alive = [dom for dom in server.xenapi.VM.get_all()
   59.30 +                     if server.xenapi.VM.get_power_state(dom) ==
   59.31 +                     XEN_API_VM_POWER_STATE[XEN_API_VM_POWER_STATE_RUNNING]]
   59.32 +        else:
   59.33 +            alive = server.xend.domains(0)
   59.34          dead = []
   59.35          for d in doms:
   59.36              if d in alive: continue
   59.37 @@ -82,8 +91,16 @@ def wait_shutdown(opts, doms):
   59.38  def shutdown(opts, doms, mode, wait):
   59.39      rcs = {}
   59.40      for d in doms:
   59.41 -        rcs[d] = server.xend.domain.getRestartCount(d)
   59.42 -        server.xend.domain.shutdown(d, mode)
   59.43 +		if serverType == SERVER_XEN_API:
   59.44 +			if mode == 'halt':
   59.45 +				server.xenapi.VM.clean_shutdown(d)
   59.46 +			if mode == 'reboot':
   59.47 +				server.xenapi.VM.clean_reboot(d)
   59.48 +			if mode == 'poweroff':
   59.49 +				server.xenapi.VM.clean_shutdown(d)				
   59.50 +		else:
   59.51 +			rcs[d] = server.xend.domain.getRestartCount(d)
   59.52 +			server.xend.domain.shutdown(d, mode)
   59.53  
   59.54      if wait:
   59.55          if mode == 'reboot':
   59.56 @@ -103,9 +120,13 @@ def shutdown_mode(opts):
   59.57          return 'poweroff'
   59.58  
   59.59  def main_all(opts, args):
   59.60 -    doms = server.xend.domains(0)
   59.61 -    dom0_name = sxp.child_value(server.xend.domain(0), 'name')
   59.62 -    doms.remove(dom0_name)
   59.63 +    if serverType == SERVER_XEN_API:
   59.64 +        doms = [dom for dom in server.xenapi.VM.get_all()
   59.65 +                if not server.xenapi.VM.get_is_control_domain(dom)]
   59.66 +    else:
   59.67 +        doms = server.xend.domains(0)
   59.68 +        dom0_name = sxp.child_value(server.xend.domain(0), 'name')
   59.69 +        doms.remove(dom0_name)
   59.70      mode = shutdown_mode(opts)  
   59.71      shutdown(opts, doms, mode, opts.vals.wait)
   59.72  
   59.73 @@ -113,6 +134,8 @@ def main_dom(opts, args):
   59.74      if len(args) == 0: opts.err('No domain parameter given')
   59.75      if len(args) >  1: opts.err('No multiple domain parameters allowed')
   59.76      dom = args[0]
   59.77 +    if serverType == SERVER_XEN_API:
   59.78 +		dom = get_single_vm(dom)
   59.79      mode = shutdown_mode(opts)  
   59.80      shutdown(opts, [ dom ], mode, opts.vals.wait)
   59.81      
    60.1 --- a/tools/xm-test/tests/destroy/01_destroy_basic_pos.py	Thu Mar 15 09:00:42 2007 -0600
    60.2 +++ b/tools/xm-test/tests/destroy/01_destroy_basic_pos.py	Thu Mar 15 09:04:23 2007 -0600
    60.3 @@ -37,4 +37,4 @@ if not re.search("proc", run["output"]):
    60.4  # destroy domain - positive test
    60.5  status, output = traceCommand("xm destroy %s" % domain.getName())
    60.6  if status != 0:
    60.7 -    FAIL("xm destroy returned invalud %i != 0" % status)
    60.8 +    FAIL("xm destroy returned invalid %i != 0" % status)
    61.1 --- a/tools/xm-test/tests/vtpm/09_vtpm-xapi.py	Thu Mar 15 09:00:42 2007 -0600
    61.2 +++ b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py	Thu Mar 15 09:04:23 2007 -0600
    61.3 @@ -91,7 +91,7 @@ if vtpm_uuid not in vm_vtpms:
    61.4  try:
    61.5      console = domain.start()
    61.6  except DomainError, e:
    61.7 -    FAIL("Unable to create domain (%s)" % domName)
    61.8 +    FAIL("Unable to create domain (%s)")
    61.9  
   61.10  try:
   61.11      console.sendInput("input")
    62.1 --- a/tools/xm-test/tests/vtpm/vtpm_utils.py	Thu Mar 15 09:00:42 2007 -0600
    62.2 +++ b/tools/xm-test/tests/vtpm/vtpm_utils.py	Thu Mar 15 09:04:23 2007 -0600
    62.3 @@ -8,7 +8,8 @@ from XmTestLib import *
    62.4  if ENABLE_HVM_SUPPORT:
    62.5      SKIP("vtpm tests not supported for HVM domains")
    62.6  
    62.7 -status, output = traceCommand("ps aux | grep vtpm_manager | grep -v grep")
    62.8 +status, output = traceCommand("COLUMNS=200 ; "
    62.9 +                              "ps aux | grep vtpm_manager | grep -v grep")
   62.10  if output == "":
   62.11      SKIP("virtual TPM manager must be started to run this test; might "
   62.12           "need /dev/tpm0")
    63.1 --- a/xen/arch/ia64/xen/domain.c	Thu Mar 15 09:00:42 2007 -0600
    63.2 +++ b/xen/arch/ia64/xen/domain.c	Thu Mar 15 09:04:23 2007 -0600
    63.3 @@ -676,8 +676,11 @@ int arch_set_info_guest(struct vcpu *v, 
    63.4  	/* This overrides some registers. */
    63.5  	vcpu_init_regs(v);
    63.6  
    63.7 -	/* Don't redo final setup */
    63.8 -	set_bit(_VCPUF_initialised, &v->vcpu_flags);
    63.9 +	/* Don't redo final setup. Auto-online VCPU0. */
   63.10 +	if (!test_and_set_bit(_VCPUF_initialised, &v->vcpu_flags) &&
   63.11 +	    (v->vcpu_id == 0))
   63.12 +		clear_bit(_VCPUF_down, &v->vcpu_flags);
   63.13 +
   63.14  	return 0;
   63.15  }
   63.16  
   63.17 @@ -1186,6 +1189,7 @@ int construct_dom0(struct domain *d,
   63.18  	printk("Dom0: 0x%lx\n", (u64)dom0);
   63.19  
   63.20  	set_bit(_VCPUF_initialised, &v->vcpu_flags);
   63.21 +	clear_bit(_VCPUF_down, &v->vcpu_flags);
   63.22  
   63.23  	/* Build firmware.
   63.24  	   Note: Linux kernel reserve memory used by start_info, so there is
    64.1 --- a/xen/arch/powerpc/domain.c	Thu Mar 15 09:00:42 2007 -0600
    64.2 +++ b/xen/arch/powerpc/domain.c	Thu Mar 15 09:04:23 2007 -0600
    64.3 @@ -168,7 +168,10 @@ int arch_set_info_guest(struct vcpu *v, 
    64.4      d->shared_info->wc_nsec = dom0->shared_info->wc_nsec;
    64.5      d->shared_info->arch.boot_timebase = dom0->shared_info->arch.boot_timebase;
    64.6  
    64.7 -    set_bit(_VCPUF_initialised, &v->vcpu_flags);
    64.8 +    /* Auto-online VCPU0 when it is initialised. */
    64.9 +    if ( !test_and_set_bit(_VCPUF_initialised, &v->vcpu_flags) &&
   64.10 +         (v->vcpu_id == 0) )
   64.11 +        clear_bit(_VCPUF_down, &v->vcpu_flags);
   64.12  
   64.13      cpu_init_vcpu(v);
   64.14  
    65.1 --- a/xen/arch/powerpc/domain_build.c	Thu Mar 15 09:00:42 2007 -0600
    65.2 +++ b/xen/arch/powerpc/domain_build.c	Thu Mar 15 09:04:23 2007 -0600
    65.3 @@ -274,6 +274,7 @@ int construct_dom0(struct domain *d,
    65.4      ofd_dom0_fixup(d, *ofh_tree + rma, cmdline, shared_info_addr);
    65.5  
    65.6      set_bit(_VCPUF_initialised, &v->vcpu_flags);
    65.7 +    clear_bit(_VCPUF_down, &v->vcpu_flags);
    65.8  
    65.9      rc = 0;
   65.10  
    66.1 --- a/xen/arch/x86/domain.c	Thu Mar 15 09:00:42 2007 -0600
    66.2 +++ b/xen/arch/x86/domain.c	Thu Mar 15 09:04:23 2007 -0600
    66.3 @@ -601,7 +601,7 @@ int arch_set_info_guest(
    66.4      }
    66.5  
    66.6      if ( test_bit(_VCPUF_initialised, &v->vcpu_flags) )
    66.7 -        return 0;
    66.8 +        goto out;
    66.9  
   66.10      memset(v->arch.guest_context.debugreg, 0,
   66.11             sizeof(v->arch.guest_context.debugreg));
   66.12 @@ -706,6 +706,11 @@ int arch_set_info_guest(
   66.13  
   66.14      update_cr3(v);
   66.15  
   66.16 + out:
   66.17 +    if ( flags & VGCF_online )
   66.18 +        clear_bit(_VCPUF_down, &v->vcpu_flags);
   66.19 +    else
   66.20 +        set_bit(_VCPUF_down, &v->vcpu_flags);
   66.21      return 0;
   66.22  #undef c
   66.23  }
   66.24 @@ -1381,7 +1386,8 @@ int hypercall_xlat_continuation(unsigned
   66.25  }
   66.26  #endif
   66.27  
   66.28 -static void relinquish_memory(struct domain *d, struct list_head *list)
   66.29 +static void relinquish_memory(struct domain *d, struct list_head *list,
   66.30 +                              unsigned long type)
   66.31  {
   66.32      struct list_head *ent;
   66.33      struct page_info  *page;
   66.34 @@ -1410,23 +1416,24 @@ static void relinquish_memory(struct dom
   66.35              put_page(page);
   66.36  
   66.37          /*
   66.38 -         * Forcibly invalidate base page tables at this point to break circular
   66.39 -         * 'linear page table' references. This is okay because MMU structures
   66.40 -         * are not shared across domains and this domain is now dead. Thus base
   66.41 -         * tables are not in use so a non-zero count means circular reference.
   66.42 +         * Forcibly invalidate top-most, still valid page tables at this point
   66.43 +         * to break circular 'linear page table' references. This is okay
   66.44 +         * because MMU structures are not shared across domains and this domain
   66.45 +         * is now dead. Thus top-most valid tables are not in use so a non-zero
   66.46 +         * count means circular reference.
   66.47           */
   66.48          y = page->u.inuse.type_info;
   66.49          for ( ; ; )
   66.50          {
   66.51              x = y;
   66.52              if ( likely((x & (PGT_type_mask|PGT_validated)) !=
   66.53 -                        (PGT_base_page_table|PGT_validated)) )
   66.54 +                        (type|PGT_validated)) )
   66.55                  break;
   66.56  
   66.57              y = cmpxchg(&page->u.inuse.type_info, x, x & ~PGT_validated);
   66.58              if ( likely(y == x) )
   66.59              {
   66.60 -                free_page_type(page, PGT_base_page_table);
   66.61 +                free_page_type(page, type);
   66.62                  break;
   66.63              }
   66.64          }
   66.65 @@ -1524,8 +1531,16 @@ void domain_relinquish_resources(struct 
   66.66          destroy_gdt(v);
   66.67  
   66.68      /* Relinquish every page of memory. */
   66.69 -    relinquish_memory(d, &d->xenpage_list);
   66.70 -    relinquish_memory(d, &d->page_list);
   66.71 +#if CONFIG_PAGING_LEVELS >= 4
   66.72 +    relinquish_memory(d, &d->xenpage_list, PGT_l4_page_table);
   66.73 +    relinquish_memory(d, &d->page_list, PGT_l4_page_table);
   66.74 +#endif
   66.75 +#if CONFIG_PAGING_LEVELS >= 3
   66.76 +    relinquish_memory(d, &d->xenpage_list, PGT_l3_page_table);
   66.77 +    relinquish_memory(d, &d->page_list, PGT_l3_page_table);
   66.78 +#endif
   66.79 +    relinquish_memory(d, &d->xenpage_list, PGT_l2_page_table);
   66.80 +    relinquish_memory(d, &d->page_list, PGT_l2_page_table);
   66.81  
   66.82      /* Free page used by xen oprofile buffer */
   66.83      free_xenoprof_pages(d);
    67.1 --- a/xen/arch/x86/domain_build.c	Thu Mar 15 09:00:42 2007 -0600
    67.2 +++ b/xen/arch/x86/domain_build.c	Thu Mar 15 09:04:23 2007 -0600
    67.3 @@ -902,6 +902,7 @@ int construct_dom0(struct domain *d,
    67.4      update_domain_wallclock_time(d);
    67.5  
    67.6      set_bit(_VCPUF_initialised, &v->vcpu_flags);
    67.7 +    clear_bit(_VCPUF_down, &v->vcpu_flags);
    67.8  
    67.9      /*
   67.10       * Initial register values:
    68.1 --- a/xen/arch/x86/domctl.c	Thu Mar 15 09:00:42 2007 -0600
    68.2 +++ b/xen/arch/x86/domctl.c	Thu Mar 15 09:04:23 2007 -0600
    68.3 @@ -450,6 +450,8 @@ void arch_get_info_guest(struct vcpu *v,
    68.4      c(flags &= ~(VGCF_i387_valid|VGCF_in_kernel));
    68.5      if ( test_bit(_VCPUF_fpu_initialised, &v->vcpu_flags) )
    68.6          c(flags |= VGCF_i387_valid);
    68.7 +    if ( !test_bit(_VCPUF_down, &v->vcpu_flags) )
    68.8 +        c(flags |= VGCF_online);
    68.9  
   68.10      if ( is_hvm_vcpu(v) )
   68.11      {
    69.1 --- a/xen/arch/x86/gdbstub.c	Thu Mar 15 09:00:42 2007 -0600
    69.2 +++ b/xen/arch/x86/gdbstub.c	Thu Mar 15 09:04:23 2007 -0600
    69.3 @@ -73,38 +73,16 @@ gdb_arch_read_reg(unsigned long regnum, 
    69.4  
    69.5  /* Like copy_from_user, but safe to call with interrupts disabled.
    69.6     Trust me, and don't look behind the curtain. */
    69.7 -unsigned 
    69.8 +unsigned int
    69.9  gdb_arch_copy_from_user(void *dest, const void *src, unsigned len)
   69.10  {
   69.11 -    int __d0, __d1, __d2;
   69.12 -    ASSERT(!local_irq_is_enabled());
   69.13 -    __asm__ __volatile__(
   69.14 -        "1: rep; movsb\n"
   69.15 -        "2:\n"
   69.16 -        ".section .fixup,\"ax\"\n"
   69.17 -        "3:     addl $4, %%esp\n"
   69.18 -        "       jmp 2b\n"
   69.19 -        ".previous\n"
   69.20 -        ".section __pre_ex_table,\"a\"\n"
   69.21 -        "   "__FIXUP_ALIGN"\n"
   69.22 -        "   "__FIXUP_WORD" 1b,3b\n"
   69.23 -        ".previous\n"
   69.24 -        ".section __ex_table,\"a\"\n"
   69.25 -        "   "__FIXUP_ALIGN"\n"
   69.26 -        "   "__FIXUP_WORD" 1b,2b\n"
   69.27 -        ".previous\n"
   69.28 -        : "=c"(__d2), "=D" (__d0), "=S" (__d1)
   69.29 -        : "0"(len), "1"(dest), "2"(src)
   69.30 -        : "memory");
   69.31 -    ASSERT(!local_irq_is_enabled());
   69.32 -    return __d2;
   69.33 +    return copy_from_user(dest, src, len);
   69.34  }
   69.35  
   69.36  unsigned int 
   69.37  gdb_arch_copy_to_user(void *dest, const void *src, unsigned len)
   69.38  {
   69.39 -    /* XXX  */
   69.40 -    return len;
   69.41 +    return copy_to_user(dest, src, len);
   69.42  }
   69.43  
   69.44  void 
    70.1 --- a/xen/arch/x86/hvm/svm/svm.c	Thu Mar 15 09:00:42 2007 -0600
    70.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Mar 15 09:04:23 2007 -0600
    70.3 @@ -43,7 +43,6 @@
    70.4  #include <asm/hvm/svm/svm.h>
    70.5  #include <asm/hvm/svm/vmcb.h>
    70.6  #include <asm/hvm/svm/emulate.h>
    70.7 -#include <asm/hvm/svm/vmmcall.h>
    70.8  #include <asm/hvm/svm/intr.h>
    70.9  #include <asm/x86_emulate.h>
   70.10  #include <public/sched.h>
   70.11 @@ -2591,65 +2590,6 @@ static int svm_do_vmmcall_reset_to_realm
   70.12  }
   70.13  
   70.14  
   70.15 -/*
   70.16 - * svm_do_vmmcall - SVM VMMCALL handler
   70.17 - *
   70.18 - * returns 0 on success, non-zero otherwise
   70.19 - */
   70.20 -static int svm_do_vmmcall(struct vcpu *v, struct cpu_user_regs *regs)
   70.21 -{
   70.22 -    struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
   70.23 -    int inst_len;
   70.24 -
   70.25 -    ASSERT(vmcb);
   70.26 -    ASSERT(regs);
   70.27 -
   70.28 -    inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL);
   70.29 -    ASSERT(inst_len > 0);
   70.30 -
   70.31 -    HVMTRACE_1D(VMMCALL, v, regs->eax);
   70.32 -
   70.33 -    if ( regs->eax & 0x80000000 )
   70.34 -    {
   70.35 -        /* VMMCALL sanity check */
   70.36 -        if ( vmcb->cpl > get_vmmcall_cpl(regs->edi) )
   70.37 -        {
   70.38 -            printk("VMMCALL CPL check failed\n");
   70.39 -            return -1;
   70.40 -        }
   70.41 -
   70.42 -        /* handle the request */
   70.43 -        switch ( regs->eax )
   70.44 -        {
   70.45 -        case VMMCALL_RESET_TO_REALMODE:
   70.46 -            if ( svm_do_vmmcall_reset_to_realmode(v, regs) )
   70.47 -            {
   70.48 -                printk("svm_do_vmmcall_reset_to_realmode() failed\n");
   70.49 -                return -1;
   70.50 -            }
   70.51 -            /* since we just reset the VMCB, return without adjusting
   70.52 -             * the eip */
   70.53 -            return 0;
   70.54 -
   70.55 -        case VMMCALL_DEBUG:
   70.56 -            printk("DEBUG features not implemented yet\n");
   70.57 -            break;
   70.58 -        default:
   70.59 -            break;
   70.60 -        }
   70.61 -
   70.62 -        hvm_print_line(v, regs->eax); /* provides the current domain */
   70.63 -    }
   70.64 -    else
   70.65 -    {
   70.66 -        hvm_do_hypercall(regs);
   70.67 -    }
   70.68 -
   70.69 -    __update_guest_eip(vmcb, inst_len);
   70.70 -    return 0;
   70.71 -}
   70.72 -
   70.73 -
   70.74  void svm_dump_inst(unsigned long eip)
   70.75  {
   70.76      u8 opcode[256];
   70.77 @@ -3152,9 +3092,14 @@ asmlinkage void svm_vmexit_handler(struc
   70.78          svm_handle_invlpg(1, regs);
   70.79          break;
   70.80  
   70.81 -    case VMEXIT_VMMCALL:
   70.82 -        svm_do_vmmcall(v, regs);
   70.83 +    case VMEXIT_VMMCALL: {
   70.84 +        int inst_len = __get_instruction_length(v, INSTR_VMCALL, NULL);
   70.85 +        ASSERT(inst_len > 0);
   70.86 +        HVMTRACE_1D(VMMCALL, v, regs->eax);
   70.87 +        __update_guest_eip(vmcb, inst_len);
   70.88 +        hvm_do_hypercall(regs);
   70.89          break;
   70.90 +    }
   70.91  
   70.92      case VMEXIT_CR0_READ:
   70.93          svm_cr_access(v, 0, TYPE_MOV_FROM_CR, regs);
    71.1 --- a/xen/arch/x86/hvm/vlapic.c	Thu Mar 15 09:00:42 2007 -0600
    71.2 +++ b/xen/arch/x86/hvm/vlapic.c	Thu Mar 15 09:04:23 2007 -0600
    71.3 @@ -195,8 +195,9 @@ int vlapic_match_logical_addr(struct vla
    71.4              result = 1;
    71.5          break;
    71.6      default:
    71.7 -        gdprintk(XENLOG_WARNING, "Bad DFR value for lapic of vcpu %d\n",
    71.8 -                 vlapic_vcpu(vlapic)->vcpu_id);
    71.9 +        gdprintk(XENLOG_WARNING, "Bad DFR value for lapic of vcpu %d: %08x\n",
   71.10 +                 vlapic_vcpu(vlapic)->vcpu_id,
   71.11 +                 vlapic_get_reg(vlapic, APIC_DFR));
   71.12          break;
   71.13      }
   71.14  
    72.1 --- a/xen/arch/x86/mm.c	Thu Mar 15 09:00:42 2007 -0600
    72.2 +++ b/xen/arch/x86/mm.c	Thu Mar 15 09:04:23 2007 -0600
    72.3 @@ -517,7 +517,6 @@ static int get_page_and_type_from_pagenr
    72.4      return 1;
    72.5  }
    72.6  
    72.7 -#ifndef CONFIG_X86_PAE /* We do not support guest linear mappings on PAE. */
    72.8  /*
    72.9   * We allow root tables to map each other (a.k.a. linear page tables). It
   72.10   * needs some special care with reference counts and access permissions:
   72.11 @@ -530,48 +529,48 @@ static int get_page_and_type_from_pagenr
   72.12   *     frame if it is mapped by a different root table. This is sufficient and
   72.13   *     also necessary to allow validation of a root table mapping itself.
   72.14   */
   72.15 -static int 
   72.16 -get_linear_pagetable(
   72.17 -    root_pgentry_t re, unsigned long re_pfn, struct domain *d)
   72.18 -{
   72.19 -    unsigned long x, y;
   72.20 -    struct page_info *page;
   72.21 -    unsigned long pfn;
   72.22 -
   72.23 -    if ( (root_get_flags(re) & _PAGE_RW) )
   72.24 -    {
   72.25 -        MEM_LOG("Attempt to create linear p.t. with write perms");
   72.26 -        return 0;
   72.27 -    }
   72.28 -
   72.29 -    if ( (pfn = root_get_pfn(re)) != re_pfn )
   72.30 -    {
   72.31 -        /* Make sure the mapped frame belongs to the correct domain. */
   72.32 -        if ( unlikely(!get_page_from_pagenr(pfn, d)) )
   72.33 -            return 0;
   72.34 -
   72.35 -        /*
   72.36 -         * Make sure that the mapped frame is an already-validated L2 table. 
   72.37 -         * If so, atomically increment the count (checking for overflow).
   72.38 -         */
   72.39 -        page = mfn_to_page(pfn);
   72.40 -        y = page->u.inuse.type_info;
   72.41 -        do {
   72.42 -            x = y;
   72.43 -            if ( unlikely((x & PGT_count_mask) == PGT_count_mask) ||
   72.44 -                 unlikely((x & (PGT_type_mask|PGT_validated)) != 
   72.45 -                          (PGT_root_page_table|PGT_validated)) )
   72.46 -            {
   72.47 -                put_page(page);
   72.48 -                return 0;
   72.49 -            }
   72.50 -        }
   72.51 -        while ( (y = cmpxchg(&page->u.inuse.type_info, x, x + 1)) != x );
   72.52 -    }
   72.53 -
   72.54 -    return 1;
   72.55 +#define define_get_linear_pagetable(level)                                  \
   72.56 +static int                                                                  \
   72.57 +get_##level##_linear_pagetable(                                             \
   72.58 +    level##_pgentry_t pde, unsigned long pde_pfn, struct domain *d)         \
   72.59 +{                                                                           \
   72.60 +    unsigned long x, y;                                                     \
   72.61 +    struct page_info *page;                                                 \
   72.62 +    unsigned long pfn;                                                      \
   72.63 +                                                                            \
   72.64 +    if ( (level##e_get_flags(pde) & _PAGE_RW) )                             \
   72.65 +    {                                                                       \
   72.66 +        MEM_LOG("Attempt to create linear p.t. with write perms");          \
   72.67 +        return 0;                                                           \
   72.68 +    }                                                                       \
   72.69 +                                                                            \
   72.70 +    if ( (pfn = level##e_get_pfn(pde)) != pde_pfn )                         \
   72.71 +    {                                                                       \
   72.72 +        /* Make sure the mapped frame belongs to the correct domain. */     \
   72.73 +        if ( unlikely(!get_page_from_pagenr(pfn, d)) )                      \
   72.74 +            return 0;                                                       \
   72.75 +                                                                            \
   72.76 +        /*                                                                  \
   72.77 +         * Ensure that the mapped frame is an already-validated page table. \
   72.78 +         * If so, atomically increment the count (checking for overflow).   \
   72.79 +         */                                                                 \
   72.80 +        page = mfn_to_page(pfn);                                            \
   72.81 +        y = page->u.inuse.type_info;                                        \
   72.82 +        do {                                                                \
   72.83 +            x = y;                                                          \
   72.84 +            if ( unlikely((x & PGT_count_mask) == PGT_count_mask) ||        \
   72.85 +                 unlikely((x & (PGT_type_mask|PGT_validated)) !=            \
   72.86 +                          (PGT_##level##_page_table|PGT_validated)) )       \
   72.87 +            {                                                               \
   72.88 +                put_page(page);                                             \
   72.89 +                return 0;                                                   \
   72.90 +            }                                                               \
   72.91 +        }                                                                   \
   72.92 +        while ( (y = cmpxchg(&page->u.inuse.type_info, x, x + 1)) != x );   \
   72.93 +    }                                                                       \
   72.94 +                                                                            \
   72.95 +    return 1;                                                               \
   72.96  }
   72.97 -#endif /* !CONFIG_X86_PAE */
   72.98  
   72.99  int
  72.100  get_page_from_l1e(
  72.101 @@ -633,7 +632,8 @@ get_page_from_l1e(
  72.102  
  72.103  
  72.104  /* NB. Virtual address 'l2e' maps to a machine address within frame 'pfn'. */
  72.105 -static int 
  72.106 +define_get_linear_pagetable(l2);
  72.107 +static int
  72.108  get_page_from_l2e(
  72.109      l2_pgentry_t l2e, unsigned long pfn, struct domain *d)
  72.110  {
  72.111 @@ -649,16 +649,16 @@ get_page_from_l2e(
  72.112      }
  72.113  
  72.114      rc = get_page_and_type_from_pagenr(l2e_get_pfn(l2e), PGT_l1_page_table, d);
  72.115 -#if CONFIG_PAGING_LEVELS == 2
  72.116      if ( unlikely(!rc) )
  72.117 -        rc = get_linear_pagetable(l2e, pfn, d);
  72.118 -#endif
  72.119 +        rc = get_l2_linear_pagetable(l2e, pfn, d);
  72.120 +
  72.121      return rc;
  72.122  }
  72.123  
  72.124  
  72.125  #if CONFIG_PAGING_LEVELS >= 3
  72.126 -static int 
  72.127 +define_get_linear_pagetable(l3);
  72.128 +static int
  72.129  get_page_from_l3e(
  72.130      l3_pgentry_t l3e, unsigned long pfn, struct domain *d)
  72.131  {
  72.132 @@ -674,12 +674,16 @@ get_page_from_l3e(
  72.133      }
  72.134  
  72.135      rc = get_page_and_type_from_pagenr(l3e_get_pfn(l3e), PGT_l2_page_table, d);
  72.136 +    if ( unlikely(!rc) )
  72.137 +        rc = get_l3_linear_pagetable(l3e, pfn, d);
  72.138 +
  72.139      return rc;
  72.140  }
  72.141  #endif /* 3 level */
  72.142  
  72.143  #if CONFIG_PAGING_LEVELS >= 4
  72.144 -static int 
  72.145 +define_get_linear_pagetable(l4);
  72.146 +static int
  72.147  get_page_from_l4e(
  72.148      l4_pgentry_t l4e, unsigned long pfn, struct domain *d)
  72.149  {
  72.150 @@ -695,9 +699,8 @@ get_page_from_l4e(
  72.151      }
  72.152  
  72.153      rc = get_page_and_type_from_pagenr(l4e_get_pfn(l4e), PGT_l3_page_table, d);
  72.154 -
  72.155      if ( unlikely(!rc) )
  72.156 -        rc = get_linear_pagetable(l4e, pfn, d);
  72.157 +        rc = get_l4_linear_pagetable(l4e, pfn, d);
  72.158  
  72.159      return rc;
  72.160  }
  72.161 @@ -2765,7 +2768,9 @@ int do_update_va_mapping(unsigned long v
  72.162              flush_tlb_one_mask(d->domain_dirty_cpumask, va);
  72.163              break;
  72.164          default:
  72.165 -            if ( unlikely(get_user(vmask, (unsigned long *)bmap_ptr)) )
  72.166 +            if ( unlikely(!IS_COMPAT(d) ?
  72.167 +                          get_user(vmask, (unsigned long *)bmap_ptr) :
  72.168 +                          get_user(vmask, (unsigned int *)bmap_ptr)) )
  72.169                  rc = -EFAULT;
  72.170              pmask = vcpumask_to_pcpumask(d, vmask);
  72.171              flush_tlb_one_mask(pmask, va);
    73.1 --- a/xen/arch/x86/mm/shadow/common.c	Thu Mar 15 09:00:42 2007 -0600
    73.2 +++ b/xen/arch/x86/mm/shadow/common.c	Thu Mar 15 09:04:23 2007 -0600
    73.3 @@ -2813,7 +2813,11 @@ shadow_write_p2m_entry(struct vcpu *v, u
    73.4         This is pretty heavy handed, but this is a rare operation
    73.5         (it might happen a dozen times during boot and then never
    73.6         again), so it doesn't matter too much. */
    73.7 -    shadow_blow_tables(d);
    73.8 +    if ( d->arch.paging.shadow.has_fast_mmio_entries )
    73.9 +    {
   73.10 +        shadow_blow_tables(d);
   73.11 +        d->arch.paging.shadow.has_fast_mmio_entries = 0;
   73.12 +    }
   73.13  #endif
   73.14  
   73.15      shadow_unlock(d);
    74.1 --- a/xen/arch/x86/mm/shadow/multi.c	Thu Mar 15 09:00:42 2007 -0600
    74.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Thu Mar 15 09:04:23 2007 -0600
    74.3 @@ -660,6 +660,8 @@ static always_inline void
    74.4      {
    74.5          /* Guest l1e maps MMIO space */
    74.6          *sp = sh_l1e_mmio(guest_l1e_get_gfn(*gp), gflags);
    74.7 +        if ( !d->arch.paging.shadow.has_fast_mmio_entries )
    74.8 +            d->arch.paging.shadow.has_fast_mmio_entries = 1;
    74.9          goto done;
   74.10      }
   74.11  
    75.1 --- a/xen/arch/x86/traps.c	Thu Mar 15 09:00:42 2007 -0600
    75.2 +++ b/xen/arch/x86/traps.c	Thu Mar 15 09:04:23 2007 -0600
    75.3 @@ -905,6 +905,10 @@ static int fixup_page_fault(unsigned lon
    75.4      struct vcpu   *v = current;
    75.5      struct domain *d = v->domain;
    75.6  
    75.7 +    /* No fixups in interrupt context or when interrupts are disabled. */
    75.8 +    if ( in_irq() || !(regs->eflags & X86_EFLAGS_IF) )
    75.9 +        return 0;
   75.10 +
   75.11      if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )
   75.12      {
   75.13          if ( paging_mode_external(d) && guest_mode(regs) )
   75.14 @@ -915,9 +919,6 @@ static int fixup_page_fault(unsigned lon
   75.15          return 0;
   75.16      }
   75.17  
   75.18 -    ASSERT(!in_irq());
   75.19 -    ASSERT(regs->eflags & X86_EFLAGS_IF);
   75.20 -
   75.21      if ( VM_ASSIST(d, VMASST_TYPE_writable_pagetables) &&
   75.22           guest_kernel_mode(v, regs) &&
   75.23           /* Do not check if access-protection fault since the page may 
    76.1 --- a/xen/arch/x86/x86_64/compat_kexec.S	Thu Mar 15 09:00:42 2007 -0600
    76.2 +++ b/xen/arch/x86/x86_64/compat_kexec.S	Thu Mar 15 09:04:23 2007 -0600
    76.3 @@ -103,13 +103,13 @@ compat_page_list:
    76.4  
    76.5          /*
    76.6           * These compat page tables contain an identity mapping of the
    76.7 -         * first 1G of the physical address space.
    76.8 +         * first 4G of the physical address space.
    76.9           */
   76.10  compat_pg_table:
   76.11          .long compat_pg_table_l2 + 0*PAGE_SIZE + 0x01 - __PAGE_OFFSET, 0
   76.12 -        .long 0, 0
   76.13 -        .long 0, 0
   76.14 -        .long 0, 0
   76.15 +        .long compat_pg_table_l2 + 1*PAGE_SIZE + 0x01 - __PAGE_OFFSET, 0
   76.16 +        .long compat_pg_table_l2 + 2*PAGE_SIZE + 0x01 - __PAGE_OFFSET, 0
   76.17 +        .long compat_pg_table_l2 + 3*PAGE_SIZE + 0x01 - __PAGE_OFFSET, 0
   76.18  
   76.19          .align 4096,0
   76.20  
   76.21 @@ -123,4 +123,7 @@ compat_pg_table_l2:
   76.22          .endif
   76.23          .endm
   76.24  
   76.25 -        identmap
   76.26 +        identmap 0x00000000
   76.27 +        identmap 0x40000000
   76.28 +        identmap 0x80000000
   76.29 +        identmap 0xc0000000
    77.1 --- a/xen/arch/x86/x86_emulate.c	Thu Mar 15 09:00:42 2007 -0600
    77.2 +++ b/xen/arch/x86/x86_emulate.c	Thu Mar 15 09:04:23 2007 -0600
    77.3 @@ -726,7 +726,7 @@ x86_emulate(
    77.4      uint8_t modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
    77.5      unsigned int op_bytes, def_op_bytes, ad_bytes, def_ad_bytes;
    77.6      unsigned int lock_prefix = 0, rep_prefix = 0;
    77.7 -    int rc = X86EMUL_OKAY;
    77.8 +    int override_seg = -1, rc = X86EMUL_OKAY;
    77.9      struct operand src, dst;
   77.10  
   77.11      /* Data operand effective address (usually computed from ModRM). */
   77.12 @@ -758,22 +758,22 @@ x86_emulate(
   77.13              ad_bytes = def_ad_bytes ^ (mode_64bit() ? 12 : 6);
   77.14              break;
   77.15          case 0x2e: /* CS override */
   77.16 -            ea.mem.seg = x86_seg_cs;
   77.17 +            override_seg = x86_seg_cs;
   77.18              break;
   77.19          case 0x3e: /* DS override */
   77.20 -            ea.mem.seg = x86_seg_ds;
   77.21 +            override_seg = x86_seg_ds;
   77.22              break;
   77.23          case 0x26: /* ES override */
   77.24 -            ea.mem.seg = x86_seg_es;
   77.25 +            override_seg = x86_seg_es;
   77.26              break;
   77.27          case 0x64: /* FS override */
   77.28 -            ea.mem.seg = x86_seg_fs;
   77.29 +            override_seg = x86_seg_fs;
   77.30              break;
   77.31          case 0x65: /* GS override */
   77.32 -            ea.mem.seg = x86_seg_gs;
   77.33 +            override_seg = x86_seg_gs;
   77.34              break;
   77.35          case 0x36: /* SS override */
   77.36 -            ea.mem.seg = x86_seg_ss;
   77.37 +            override_seg = x86_seg_ss;
   77.38              break;
   77.39          case 0xf0: /* LOCK */
   77.40              lock_prefix = 1;
   77.41 @@ -839,14 +839,35 @@ x86_emulate(
   77.42              /* 16-bit ModR/M decode. */
   77.43              switch ( modrm_rm )
   77.44              {
   77.45 -            case 0: ea.mem.off = _regs.ebx + _regs.esi; break;
   77.46 -            case 1: ea.mem.off = _regs.ebx + _regs.edi; break;
   77.47 -            case 2: ea.mem.off = _regs.ebp + _regs.esi; break;
   77.48 -            case 3: ea.mem.off = _regs.ebp + _regs.edi; break;
   77.49 -            case 4: ea.mem.off = _regs.esi; break;
   77.50 -            case 5: ea.mem.off = _regs.edi; break;
   77.51 -            case 6: ea.mem.off = _regs.ebp; break;
   77.52 -            case 7: ea.mem.off = _regs.ebx; break;
   77.53 +            case 0:
   77.54 +                ea.mem.off = _regs.ebx + _regs.esi;
   77.55 +                break;
   77.56 +            case 1:
   77.57 +                ea.mem.off = _regs.ebx + _regs.edi;
   77.58 +                break;
   77.59 +            case 2:
   77.60 +                ea.mem.seg = x86_seg_ss;
   77.61 +                ea.mem.off = _regs.ebp + _regs.esi;
   77.62 +                break;
   77.63 +            case 3:
   77.64 +                ea.mem.seg = x86_seg_ss;
   77.65 +                ea.mem.off = _regs.ebp + _regs.edi;
   77.66 +                break;
   77.67 +            case 4:
   77.68 +                ea.mem.off = _regs.esi;
   77.69 +                break;
   77.70 +            case 5:
   77.71 +                ea.mem.off = _regs.edi;
   77.72 +                break;
   77.73 +            case 6:
   77.74 +                if ( modrm_mod == 0 )
   77.75 +                    break;
   77.76 +                ea.mem.seg = x86_seg_ss;
   77.77 +                ea.mem.off = _regs.ebp;
   77.78 +                break;
   77.79 +            case 7:
   77.80 +                ea.mem.off = _regs.ebx;
   77.81 +                break;
   77.82              }
   77.83              switch ( modrm_mod )
   77.84              {
   77.85 @@ -876,10 +897,20 @@ x86_emulate(
   77.86                  ea.mem.off <<= (sib >> 6) & 3;
   77.87                  if ( (modrm_mod == 0) && ((sib_base & 7) == 5) )
   77.88                      ea.mem.off += insn_fetch_type(int32_t);
   77.89 -                else if ( (sib_base == 4) && !twobyte && (b == 0x8f) )
   77.90 -                    /* POP <rm> must have its EA calculated post increment. */
   77.91 -                    ea.mem.off += _regs.esp +
   77.92 -                        ((mode_64bit() && (op_bytes == 4)) ? 8 : op_bytes);
   77.93 +                else if ( sib_base == 4 )
   77.94 +                {
   77.95 +                    ea.mem.seg  = x86_seg_ss;
   77.96 +                    ea.mem.off += _regs.esp;
   77.97 +                    if ( !twobyte && (b == 0x8f) )
   77.98 +                        /* POP <rm> computes its EA post increment. */
   77.99 +                        ea.mem.off += ((mode_64bit() && (op_bytes == 4))
  77.100 +                                       ? 8 : op_bytes);
  77.101 +                }
  77.102 +                else if ( sib_base == 5 )
  77.103 +                {
  77.104 +                    ea.mem.seg  = x86_seg_ss;
  77.105 +                    ea.mem.off += _regs.ebp;
  77.106 +                }
  77.107                  else
  77.108                      ea.mem.off += *(long*)decode_register(sib_base, &_regs, 0);
  77.109              }
  77.110 @@ -887,6 +918,8 @@ x86_emulate(
  77.111              {
  77.112                  modrm_rm |= (rex_prefix & 1) << 3;
  77.113                  ea.mem.off = *(long *)decode_register(modrm_rm, &_regs, 0);
  77.114 +                if ( (modrm_rm == 5) && (modrm_mod != 0) )
  77.115 +                    ea.mem.seg = x86_seg_ss;
  77.116              }
  77.117              switch ( modrm_mod )
  77.118              {
  77.119 @@ -920,6 +953,9 @@ x86_emulate(
  77.120          }
  77.121      }
  77.122  
  77.123 +    if ( override_seg != -1 )
  77.124 +        ea.mem.seg = override_seg;
  77.125 +
  77.126      /* Special instructions do their own operand decoding. */
  77.127      if ( (d & DstMask) == ImplicitOps )
  77.128          goto special_insn;
    78.1 --- a/xen/common/domain.c	Thu Mar 15 09:00:42 2007 -0600
    78.2 +++ b/xen/common/domain.c	Thu Mar 15 09:04:23 2007 -0600
    78.3 @@ -102,7 +102,7 @@ struct vcpu *alloc_vcpu(
    78.4      v->runstate.state = is_idle_vcpu(v) ? RUNSTATE_running : RUNSTATE_offline;
    78.5      v->runstate.state_entry_time = NOW();
    78.6  
    78.7 -    if ( (vcpu_id != 0) && !is_idle_domain(d) )
    78.8 +    if ( !is_idle_domain(d) )
    78.9          set_bit(_VCPUF_down, &v->vcpu_flags);
   78.10  
   78.11      if ( sched_init_vcpu(v, cpu_id) != 0 )
    79.1 --- a/xen/common/domctl.c	Thu Mar 15 09:00:42 2007 -0600
    79.2 +++ b/xen/common/domctl.c	Thu Mar 15 09:04:23 2007 -0600
    79.3 @@ -268,18 +268,14 @@ long do_domctl(XEN_GUEST_HANDLE(xen_domc
    79.4      case XEN_DOMCTL_unpausedomain:
    79.5      {
    79.6          struct domain *d = rcu_lock_domain_by_id(op->domain);
    79.7 +
    79.8          ret = -ESRCH;
    79.9 -        if ( d != NULL )
   79.10 -        {
   79.11 -            ret = -EINVAL;
   79.12 -            if ( (d != current->domain) && (d->vcpu[0] != NULL) &&
   79.13 -                 test_bit(_VCPUF_initialised, &d->vcpu[0]->vcpu_flags) )
   79.14 -            {
   79.15 -                domain_unpause_by_systemcontroller(d);
   79.16 -                ret = 0;
   79.17 -            }
   79.18 -            rcu_unlock_domain(d);
   79.19 -        }
   79.20 +        if ( d == NULL )
   79.21 +            break;
   79.22 +
   79.23 +        domain_unpause_by_systemcontroller(d);
   79.24 +        rcu_unlock_domain(d);
   79.25 +        ret = 0;
   79.26      }
   79.27      break;
   79.28  
    80.1 --- a/xen/common/grant_table.c	Thu Mar 15 09:00:42 2007 -0600
    80.2 +++ b/xen/common/grant_table.c	Thu Mar 15 09:04:23 2007 -0600
    80.3 @@ -1392,8 +1392,7 @@ gnttab_release_mappings(
    80.4              {
    80.5                  BUG_ON(!(act->pin & GNTPIN_hstr_mask));
    80.6                  act->pin -= GNTPIN_hstr_inc;
    80.7 -                /* Done implicitly when page tables are destroyed. */
    80.8 -                /* put_page(mfn_to_page(act->frame)); */
    80.9 +                gnttab_release_put_page(mfn_to_page(act->frame));
   80.10              }
   80.11          }
   80.12          else
   80.13 @@ -1409,8 +1408,7 @@ gnttab_release_mappings(
   80.14              {
   80.15                  BUG_ON(!(act->pin & GNTPIN_hstw_mask));
   80.16                  act->pin -= GNTPIN_hstw_inc;
   80.17 -                /* Done implicitly when page tables are destroyed. */
   80.18 -                /* put_page_and_type(mfn_to_page(act->frame)); */
   80.19 +                gnttab_release_put_page_and_type(mfn_to_page(act->frame));
   80.20              }
   80.21  
   80.22              if ( (act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) == 0 )
    81.1 --- a/xen/drivers/char/console.c	Thu Mar 15 09:00:42 2007 -0600
    81.2 +++ b/xen/drivers/char/console.c	Thu Mar 15 09:04:23 2007 -0600
    81.3 @@ -48,6 +48,10 @@ string_param("conswitch", opt_conswitch)
    81.4  static int opt_sync_console;
    81.5  boolean_param("sync_console", opt_sync_console);
    81.6  
    81.7 +/* console_to_ring: send guest (incl. dom 0) console data to console ring. */
    81.8 +static int opt_console_to_ring;
    81.9 +boolean_param("console_to_ring", opt_console_to_ring);
   81.10 +
   81.11  #define CONRING_SIZE 16384
   81.12  #define CONRING_IDX_MASK(i) ((i)&(CONRING_SIZE-1))
   81.13  static char conring[CONRING_SIZE];
   81.14 @@ -329,7 +333,14 @@ static long guest_console_write(XEN_GUES
   81.15          sercon_puts(kbuf);
   81.16  
   81.17          for ( kptr = kbuf; *kptr != '\0'; kptr++ )
   81.18 +        {
   81.19              vga_putchar(*kptr);
   81.20 +            if ( opt_console_to_ring )
   81.21 +                putchar_console_ring(*kptr);
   81.22 +        }
   81.23 +
   81.24 +        if ( opt_console_to_ring )
   81.25 +            send_guest_global_virq(dom0, VIRQ_CON_RING);
   81.26  
   81.27          guest_handle_add_offset(buffer, kcount);
   81.28          count -= kcount;
    82.1 --- a/xen/include/asm-ia64/grant_table.h	Thu Mar 15 09:00:42 2007 -0600
    82.2 +++ b/xen/include/asm-ia64/grant_table.h	Thu Mar 15 09:04:23 2007 -0600
    82.3 @@ -64,4 +64,7 @@ static inline void gnttab_clear_flag(uns
    82.4  	clear_bit(nr, addr);
    82.5  }
    82.6  
    82.7 +#define gnttab_release_put_page(page)           put_page((page))
    82.8 +#define gnttab_release_put_page_and_type(page)  put_page_and_type((page))
    82.9 +
   82.10  #endif /* __ASM_GRANT_TABLE_H__ */
    83.1 --- a/xen/include/asm-powerpc/grant_table.h	Thu Mar 15 09:00:42 2007 -0600
    83.2 +++ b/xen/include/asm-powerpc/grant_table.h	Thu Mar 15 09:04:23 2007 -0600
    83.3 @@ -69,4 +69,17 @@ static inline uint cpu_foreign_map_order
    83.4      /* 16 GiB */
    83.5      return 34 - PAGE_SHIFT;
    83.6  }
    83.7 +
    83.8 +#if 0
    83.9 +/*
   83.10 + * without put_page()/put_page_and_type() page might be leaked.
   83.11 + * with put_page()/put_page_and_type() freed page might be accessed.
   83.12 + */
   83.13 +#define gnttab_release_put_page(page)           put_page((page))
   83.14 +#define gnttab_release_put_page_and_type(page)  put_page_and_type((page))
   83.15 +#else
   83.16 +#define gnttab_release_put_page(page)           do { } while (0)
   83.17 +#define gnttab_release_put_page_and_type(page)  do { } while (0)
   83.18 +#endif
   83.19 +
   83.20  #endif  /* __ASM_PPC_GRANT_TABLE_H__ */
    84.1 --- a/xen/include/asm-x86/domain.h	Thu Mar 15 09:00:42 2007 -0600
    84.2 +++ b/xen/include/asm-x86/domain.h	Thu Mar 15 09:04:23 2007 -0600
    84.3 @@ -79,6 +79,9 @@ struct shadow_domain {
    84.4      struct shadow_page_info **hash_table;
    84.5      int hash_walking;  /* Some function is walking the hash table */
    84.6  
    84.7 +    /* Fast MMIO path heuristic */
    84.8 +    int has_fast_mmio_entries;
    84.9 +
   84.10      /* Shadow log-dirty bitmap */
   84.11      unsigned long *dirty_bitmap;
   84.12      unsigned int dirty_bitmap_size;  /* in pages, bit per page */
    85.1 --- a/xen/include/asm-x86/grant_table.h	Thu Mar 15 09:00:42 2007 -0600
    85.2 +++ b/xen/include/asm-x86/grant_table.h	Thu Mar 15 09:04:23 2007 -0600
    85.3 @@ -38,4 +38,14 @@ static inline void gnttab_clear_flag(uns
    85.4      clear_bit(nr, addr);
    85.5  }
    85.6  
    85.7 +#define gnttab_release_put_page(page)                           \
    85.8 +    do {                                                        \
    85.9 +        /* Done implicitly when page tables are destroyed. */   \
   85.10 +    } while (0)
   85.11 +
   85.12 +#define gnttab_release_put_page_and_type(page)                  \
   85.13 +    do {                                                        \
   85.14 +        /* Done implicitly when page tables are destroyed. */   \
   85.15 +    } while (0)
   85.16 +
   85.17  #endif /* __ASM_GRANT_TABLE_H__ */
    86.1 --- a/xen/include/asm-x86/hvm/svm/vmmcall.h	Thu Mar 15 09:00:42 2007 -0600
    86.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    86.3 @@ -1,44 +0,0 @@
    86.4 -/*
    86.5 - * vmmcall.h: VMMCALL instruction support
    86.6 - *
    86.7 - * Travis Betak, travis.betak@amd.com
    86.8 - * Copyright (c) 2005, AMD Corporation.
    86.9 - *
   86.10 - * This program is free software; you can redistribute it and/or modify it
   86.11 - * under the terms and conditions of the GNU General Public License,
   86.12 - * version 2, as published by the Free Software Foundation.
   86.13 - *
   86.14 - * This program is distributed in the hope it will be useful, but WITHOUT
   86.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   86.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   86.17 - * more details.
   86.18 - *
   86.19 - * You should have received a copy of the GNU General Public License along with
   86.20 - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   86.21 - * Place - Suite 330, Boston, MA 02111-1307 USA.
   86.22 - *
   86.23 - */
   86.24 -
   86.25 -#ifndef __ASM_X86_HVM_SVM_VMMCALL_H__
   86.26 -#define __ASM_X86_HVM_SVM_VMMCALL_H__
   86.27 -
   86.28 -/* VMMCALL command fields */
   86.29 -#define VMMCALL_CODE_CPL_MASK     0x60000000
   86.30 -#define VMMCALL_CODE_MBZ_MASK     0x1FFF0000
   86.31 -#define VMMCALL_CODE_COMMAND_MASK 0x0000FFFF
   86.32 -
   86.33 -#define MAKE_VMMCALL_CODE(cpl,func) ((cpl << 29) | (func) | 0x80000000)
   86.34 -
   86.35 -/* CPL=0 VMMCALL Requests */
   86.36 -#define VMMCALL_RESET_TO_REALMODE   MAKE_VMMCALL_CODE(0,1)
   86.37 -
   86.38 -/* CPL=3 VMMCALL Requests */
   86.39 -#define VMMCALL_DEBUG           MAKE_VMMCALL_CODE(3,1)
   86.40 -
   86.41 -/* return the cpl required for the vmmcall cmd */
   86.42 -static inline int get_vmmcall_cpl(int cmd)
   86.43 -{
   86.44 -    return (cmd & VMMCALL_CODE_CPL_MASK) >> 29;
   86.45 -}
   86.46 -
   86.47 -#endif /* __ASM_X86_HVM_SVM_VMMCALL_H__ */
    87.1 --- a/xen/include/public/arch-x86/xen.h	Thu Mar 15 09:00:42 2007 -0600
    87.2 +++ b/xen/include/public/arch-x86/xen.h	Thu Mar 15 09:04:23 2007 -0600
    87.3 @@ -126,6 +126,8 @@ struct vcpu_guest_context {
    87.4  #define VGCF_failsafe_disables_events  (1<<_VGCF_failsafe_disables_events)
    87.5  #define _VGCF_syscall_disables_events  4
    87.6  #define VGCF_syscall_disables_events   (1<<_VGCF_syscall_disables_events)
    87.7 +#define _VGCF_online                   5
    87.8 +#define VGCF_online                    (1<<_VGCF_online)
    87.9      unsigned long flags;                    /* VGCF_* flags                 */
   87.10      struct cpu_user_regs user_regs;         /* User-level CPU registers     */
   87.11      struct trap_info trap_ctxt[256];        /* Virtual IDT                  */
    88.1 --- a/xen/include/public/foreign/structs.py	Thu Mar 15 09:00:42 2007 -0600
    88.2 +++ b/xen/include/public/foreign/structs.py	Thu Mar 15 09:04:23 2007 -0600
    88.3 @@ -41,6 +41,8 @@ defines = [ "__i386__",
    88.4              "VGCF_failsafe_disables_events",
    88.5              "_VGCF_syscall_disables_events",
    88.6              "VGCF_syscall_disables_events",
    88.7 +            "_VGCF_online",
    88.8 +            "VGCF_online",
    88.9  
   88.10              # ia64
   88.11              "VGCF_EXTRA_REGS",