direct-io.hg

changeset 11527:0bdd578c417f

[POWERPC] merge with xen-unstable.hg
Signed-off-by: Hollis Blanchard <hollisb@us.ibm.com>
author Hollis Blanchard <hollisb@us.ibm.com>
date Mon Sep 18 14:28:16 2006 -0500 (2006-09-18)
parents ce9c34c049c5 2b8dc69744e3
children 9061e1246906 ee4397571e44
files tools/debugger/gdb/gdbbuild
line diff
     1.1 --- a/buildconfigs/linux-defconfig_xen0_ia64	Mon Sep 18 09:23:51 2006 -0400
     1.2 +++ b/buildconfigs/linux-defconfig_xen0_ia64	Mon Sep 18 14:28:16 2006 -0500
     1.3 @@ -1,7 +1,7 @@
     1.4  #
     1.5  # Automatically generated make config: don't edit
     1.6  # Linux kernel version: 2.6.16.13-xen0
     1.7 -# Fri Jul 28 16:33:47 2006
     1.8 +# Fri Sep  1 11:03:26 2006
     1.9  #
    1.10  
    1.11  #
    1.12 @@ -1512,12 +1512,10 @@ CONFIG_HAVE_ARCH_ALLOC_SKB=y
    1.13  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    1.14  CONFIG_XEN_BALLOON=y
    1.15  CONFIG_XEN_SKBUFF=y
    1.16 -CONFIG_XEN_NETDEV_BACKEND=y
    1.17 -CONFIG_XEN_NETDEV_FRONTEND=y
    1.18  # CONFIG_XEN_DEVMEM is not set
    1.19  CONFIG_XEN_REBOOT=y
    1.20  # CONFIG_XEN_SMPBOOT is not set
    1.21 -CONFIG_XEN_INTERFACE_VERSION=0x00030202
    1.22 +CONFIG_XEN_INTERFACE_VERSION=0x00030203
    1.23  
    1.24  #
    1.25  # XEN
    1.26 @@ -1529,6 +1527,7 @@ CONFIG_XEN_XENBUS_DEV=y
    1.27  CONFIG_XEN_BACKEND=y
    1.28  CONFIG_XEN_BLKDEV_BACKEND=y
    1.29  # CONFIG_XEN_BLKDEV_TAP is not set
    1.30 +CONFIG_XEN_NETDEV_BACKEND=y
    1.31  # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
    1.32  CONFIG_XEN_NETDEV_LOOPBACK=y
    1.33  CONFIG_XEN_PCIDEV_BACKEND=y
    1.34 @@ -1538,6 +1537,7 @@ CONFIG_XEN_PCIDEV_BACKEND_SLOT=y
    1.35  # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
    1.36  # CONFIG_XEN_TPMDEV_BACKEND is not set
    1.37  CONFIG_XEN_BLKDEV_FRONTEND=y
    1.38 +CONFIG_XEN_NETDEV_FRONTEND=y
    1.39  # CONFIG_XEN_SCRUB_PAGES is not set
    1.40  CONFIG_XEN_DISABLE_SERIAL=y
    1.41  CONFIG_XEN_SYSFS=y
     2.1 --- a/buildconfigs/linux-defconfig_xenU_ia64	Mon Sep 18 09:23:51 2006 -0400
     2.2 +++ b/buildconfigs/linux-defconfig_xenU_ia64	Mon Sep 18 14:28:16 2006 -0500
     2.3 @@ -1,7 +1,7 @@
     2.4  #
     2.5  # Automatically generated make config: don't edit
     2.6  # Linux kernel version: 2.6.16.13-xenU
     2.7 -# Fri Jul 28 16:32:18 2006
     2.8 +# Fri Sep  1 10:50:54 2006
     2.9  #
    2.10  
    2.11  #
    2.12 @@ -1387,11 +1387,10 @@ CONFIG_HAVE_ARCH_ALLOC_SKB=y
    2.13  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    2.14  CONFIG_XEN_BALLOON=y
    2.15  CONFIG_XEN_SKBUFF=y
    2.16 -CONFIG_XEN_NETDEV_FRONTEND=y
    2.17  # CONFIG_XEN_DEVMEM is not set
    2.18  CONFIG_XEN_REBOOT=y
    2.19  # CONFIG_XEN_SMPBOOT is not set
    2.20 -CONFIG_XEN_INTERFACE_VERSION=0x00030202
    2.21 +CONFIG_XEN_INTERFACE_VERSION=0x00030203
    2.22  
    2.23  #
    2.24  # XEN
    2.25 @@ -1402,6 +1401,7 @@ CONFIG_XEN_PRIVCMD=y
    2.26  CONFIG_XEN_XENBUS_DEV=y
    2.27  # CONFIG_XEN_BACKEND is not set
    2.28  CONFIG_XEN_BLKDEV_FRONTEND=y
    2.29 +CONFIG_XEN_NETDEV_FRONTEND=y
    2.30  # CONFIG_XEN_SCRUB_PAGES is not set
    2.31  # CONFIG_XEN_DISABLE_SERIAL is not set
    2.32  CONFIG_XEN_SYSFS=y
     3.1 --- a/buildconfigs/linux-defconfig_xen_ia64	Mon Sep 18 09:23:51 2006 -0400
     3.2 +++ b/buildconfigs/linux-defconfig_xen_ia64	Mon Sep 18 14:28:16 2006 -0500
     3.3 @@ -1,7 +1,7 @@
     3.4  #
     3.5  # Automatically generated make config: don't edit
     3.6  # Linux kernel version: 2.6.16.13-xen
     3.7 -# Fri Jul 28 16:33:08 2006
     3.8 +# Fri Sep  1 10:58:55 2006
     3.9  #
    3.10  
    3.11  #
    3.12 @@ -1518,12 +1518,10 @@ CONFIG_HAVE_ARCH_ALLOC_SKB=y
    3.13  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    3.14  CONFIG_XEN_BALLOON=y
    3.15  CONFIG_XEN_SKBUFF=y
    3.16 -CONFIG_XEN_NETDEV_BACKEND=y
    3.17 -CONFIG_XEN_NETDEV_FRONTEND=y
    3.18  # CONFIG_XEN_DEVMEM is not set
    3.19  CONFIG_XEN_REBOOT=y
    3.20  # CONFIG_XEN_SMPBOOT is not set
    3.21 -CONFIG_XEN_INTERFACE_VERSION=0x00030202
    3.22 +CONFIG_XEN_INTERFACE_VERSION=0x00030203
    3.23  
    3.24  #
    3.25  # XEN
    3.26 @@ -1535,6 +1533,7 @@ CONFIG_XEN_XENBUS_DEV=y
    3.27  CONFIG_XEN_BACKEND=y
    3.28  CONFIG_XEN_BLKDEV_BACKEND=y
    3.29  # CONFIG_XEN_BLKDEV_TAP is not set
    3.30 +CONFIG_XEN_NETDEV_BACKEND=y
    3.31  # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
    3.32  CONFIG_XEN_NETDEV_LOOPBACK=y
    3.33  CONFIG_XEN_PCIDEV_BACKEND=y
    3.34 @@ -1544,6 +1543,7 @@ CONFIG_XEN_PCIDEV_BACKEND_SLOT=y
    3.35  # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
    3.36  # CONFIG_XEN_TPMDEV_BACKEND is not set
    3.37  CONFIG_XEN_BLKDEV_FRONTEND=y
    3.38 +CONFIG_XEN_NETDEV_FRONTEND=y
    3.39  # CONFIG_XEN_SCRUB_PAGES is not set
    3.40  CONFIG_XEN_DISABLE_SERIAL=y
    3.41  CONFIG_XEN_SYSFS=y
     4.1 --- a/docs/man/xm.pod.1	Mon Sep 18 09:23:51 2006 -0400
     4.2 +++ b/docs/man/xm.pod.1	Mon Sep 18 14:28:16 2006 -0500
     4.3 @@ -432,7 +432,6 @@ bug report.
     4.4  Sample xen domain info looks as follows (lines wrapped manually to
     4.5  make the man page more readable):
     4.6  
     4.7 - system                 : Linux
     4.8   host                   : talon
     4.9   release                : 2.6.12.6-xen0
    4.10   version                : #1 Mon Nov 14 14:26:26 EST 2005
    4.11 @@ -444,13 +443,14 @@ make the man page more readable):
    4.12   threads_per_core       : 1
    4.13   cpu_mhz                : 696
    4.14   hw_caps                : 0383fbff:00000000:00000000:00000040
    4.15 - memory                 : 767
    4.16 + total_memory           : 767
    4.17   free_memory            : 37
    4.18   xen_major              : 3
    4.19   xen_minor              : 0
    4.20   xen_extra              : -devel
    4.21   xen_caps               : xen-3.0-x86_32
    4.22 - xen_params             : virt_start=0xfc000000
    4.23 + xen_pagesize           : 4096
    4.24 + platform_params        : virt_start=0xfc000000
    4.25   xen_changeset          : Mon Nov 14 18:13:38 2005 +0100 
    4.26                            7793:090e44133d40
    4.27   cc_compiler            : gcc version 3.4.3 (Mandrakelinux 
    4.28 @@ -458,6 +458,7 @@ make the man page more readable):
    4.29   cc_compile_by          : sdague
    4.30   cc_compile_domain      : (none)
    4.31   cc_compile_date        : Mon Nov 14 14:16:48 EST 2005
    4.32 + xend_config_format     : 2
    4.33  
    4.34  B<FIELDS>
    4.35  
     5.1 --- a/docs/src/user.tex	Mon Sep 18 09:23:51 2006 -0400
     5.2 +++ b/docs/src/user.tex	Mon Sep 18 14:28:16 2006 -0500
     5.3 @@ -1654,26 +1654,58 @@ Now unmount (this is important!):
     5.4  
     5.5  In the configuration file set:
     5.6  \begin{quote}
     5.7 -  \verb_disk = ['file:/full/path/to/vm1disk,sda1,w']_
     5.8 +  \verb_disk = ['tap:aio:/full/path/to/vm1disk,sda1,w']_
     5.9  \end{quote}
    5.10  
    5.11  As the virtual machine writes to its `disk', the sparse file will be
    5.12  filled in and consume more space up to the original 2GB.
    5.13  
    5.14 -{\bf Note that file-backed VBDs may not be appropriate for backing
    5.15 -  I/O-intensive domains.}  File-backed VBDs are known to experience
    5.16 +{\em{Note:}} Users that have worked with file-backed VBDs on Xen in previous
    5.17 +versions will be interested to know that this support is now provided through
    5.18 +the blktap driver instead of the loopback driver.  This change results in
    5.19 +file-based block devices that are higher-performance, more scalable, and which
    5.20 +provide better safety properties for VBD data.  All that is required to update
    5.21 +your existing file-backed VM configurations is to change VBD configuration
    5.22 +lines from:
    5.23 +\begin{quote}
    5.24 +  \verb_disk = ['file:/full/path/to/vm1disk,sda1,w']_
    5.25 +\end{quote}
    5.26 +to:
    5.27 +\begin{quote}
    5.28 +  \verb_disk = ['tap:aio:/full/path/to/vm1disk,sda1,w']_
    5.29 +\end{quote}
    5.30 +
    5.31 +
    5.32 +\subsection{Loopback-mounted file-backed VBDs (deprecated)}
    5.33 +
    5.34 +{\em{{\bf{Note:}} Loopback mounted VBDs have now been replaced with
    5.35 +    blktap-based support for raw image files, as described above.  This
    5.36 +    section remains to detail a configuration that was used by older Xen
    5.37 +    versions.}}
    5.38 +
    5.39 +Raw image file-backed VBDs amy also be attached to VMs using the 
    5.40 +Linux loopback driver.  The only required change to the raw file 
    5.41 +instructions above are to specify the configuration entry as:
    5.42 +\begin{quote}
    5.43 +  \verb_disk = ['file:/full/path/to/vm1disk,sda1,w']_
    5.44 +\end{quote}
    5.45 +
    5.46 +{\bf Note that loopback file-backed VBDs may not be appropriate for backing
    5.47 +  I/O-intensive domains.}  This approach is known to experience
    5.48  substantial slowdowns under heavy I/O workloads, due to the I/O
    5.49  handling by the loopback block device used to support file-backed VBDs
    5.50 -in dom0.  Better I/O performance can be achieved by using either
    5.51 -LVM-backed VBDs (Section~\ref{s:using-lvm-backed-vbds}) or physical
    5.52 -devices as VBDs (Section~\ref{s:exporting-physical-devices-as-vbds}).
    5.53 -
    5.54 -Linux supports a maximum of eight file-backed VBDs across all domains
    5.55 -by default.  This limit can be statically increased by using the
    5.56 -\emph{max\_loop} module parameter if CONFIG\_BLK\_DEV\_LOOP is
    5.57 -compiled as a module in the dom0 kernel, or by using the
    5.58 -\emph{max\_loop=n} boot option if CONFIG\_BLK\_DEV\_LOOP is compiled
    5.59 -directly into the dom0 kernel.
    5.60 +in dom0.  Loopbach support remains for old Xen installations, and users
    5.61 +are strongly encouraged to use the blktap-based file support (using 
    5.62 +``{\tt{tap:aio}}'' as described above).
    5.63 +
    5.64 +Additionally, Linux supports a maximum of eight loopback file-backed 
    5.65 +VBDs across all domains by default.  This limit can be statically 
    5.66 +increased by using the \emph{max\_loop} module parameter if 
    5.67 +CONFIG\_BLK\_DEV\_LOOP is compiled as a module in the dom0 kernel, or 
    5.68 +by using the \emph{max\_loop=n} boot option if CONFIG\_BLK\_DEV\_LOOP 
    5.69 +is compiled directly into the dom0 kernel.  Again, users are encouraged
    5.70 +to use the blktap-based file support described above which scales to much 
    5.71 +larger number of active VBDs.
    5.72  
    5.73  
    5.74  \section{Using LVM-backed VBDs}
     6.1 --- a/extras/mini-os/Makefile	Mon Sep 18 09:23:51 2006 -0400
     6.2 +++ b/extras/mini-os/Makefile	Mon Sep 18 14:28:16 2006 -0500
     6.3 @@ -7,9 +7,12 @@ include $(XEN_ROOT)/Config.mk
     6.4  # Set TARGET_ARCH
     6.5  override TARGET_ARCH     := $(XEN_TARGET_ARCH)
     6.6  
     6.7 +XEN_INTERFACE_VERSION := 0x00030203
     6.8 +
     6.9  # NB. '-Wcast-qual' is nasty, so I omitted it.
    6.10  CFLAGS := -fno-builtin -Wall -Werror -Wredundant-decls -Wno-format
    6.11  CFLAGS += -Wstrict-prototypes -Wnested-externs -Wpointer-arith -Winline
    6.12 +CFLAGS += -D__XEN_INTERFACE_VERSION__=$(XEN_INTERFACE_VERSION)
    6.13  
    6.14  ASFLAGS = -D__ASSEMBLY__
    6.15  
     7.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Mon Sep 18 09:23:51 2006 -0400
     7.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/setup-xen.c	Mon Sep 18 14:28:16 2006 -0500
     7.3 @@ -1380,8 +1380,10 @@ legacy_init_iomem_resources(struct e820e
     7.4  			 *  so we try it repeatedly and let the resource manager
     7.5  			 *  test it.
     7.6  			 */
     7.7 +#ifndef CONFIG_XEN
     7.8  			request_resource(res, code_resource);
     7.9  			request_resource(res, data_resource);
    7.10 +#endif
    7.11  #ifdef CONFIG_KEXEC
    7.12  			request_resource(res, &crashk_res);
    7.13  #endif
    7.14 @@ -1454,11 +1456,8 @@ static void __init register_memory(void)
    7.15  	int	      i;
    7.16  
    7.17  	/* Nothing to do if not running in dom0. */
    7.18 -	if (!is_initial_xendomain()) {
    7.19 -		legacy_init_iomem_resources(e820.map, e820.nr_map,
    7.20 -					    &code_resource, &data_resource);
    7.21 +	if (!is_initial_xendomain())
    7.22  		return;
    7.23 -	}
    7.24  
    7.25  #ifdef CONFIG_XEN
    7.26  	machine_e820 = alloc_bootmem_low_pages(PAGE_SIZE);
     8.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Mon Sep 18 09:23:51 2006 -0400
     8.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/ioremap-xen.c	Mon Sep 18 14:28:16 2006 -0500
     8.3 @@ -22,15 +22,6 @@
     8.4  #define ISA_START_ADDRESS	0x0
     8.5  #define ISA_END_ADDRESS		0x100000
     8.6  
     8.7 -#if 0 /* not PAE safe */
     8.8 -/* These hacky macros avoid phys->machine translations. */
     8.9 -#define __direct_pte(x) ((pte_t) { (x) } )
    8.10 -#define __direct_mk_pte(page_nr,pgprot) \
    8.11 -  __direct_pte(((page_nr) << PAGE_SHIFT) | pgprot_val(pgprot))
    8.12 -#define direct_mk_pte_phys(physpage, pgprot) \
    8.13 -  __direct_mk_pte((physpage) >> PAGE_SHIFT, pgprot)
    8.14 -#endif
    8.15 -
    8.16  static int direct_remap_area_pte_fn(pte_t *pte, 
    8.17  				    struct page *pmd_page,
    8.18  				    unsigned long address, 
    8.19 @@ -66,17 +57,16 @@ static int __direct_remap_pfn_range(stru
    8.20  
    8.21  	for (i = 0; i < size; i += PAGE_SIZE) {
    8.22  		if ((v - u) == (PAGE_SIZE / sizeof(mmu_update_t))) {
    8.23 -			/* Fill in the PTE pointers. */
    8.24 +			/* Flush a full batch after filling in the PTE ptrs. */
    8.25  			rc = apply_to_page_range(mm, start_address, 
    8.26  						 address - start_address,
    8.27  						 direct_remap_area_pte_fn, &w);
    8.28  			if (rc)
    8.29  				goto out;
    8.30 -			w = u;
    8.31  			rc = -EFAULT;
    8.32  			if (HYPERVISOR_mmu_update(u, v - u, NULL, domid) < 0)
    8.33  				goto out;
    8.34 -			v = u;
    8.35 +			v = w = u;
    8.36  			start_address = address;
    8.37  		}
    8.38  
    8.39 @@ -92,7 +82,7 @@ static int __direct_remap_pfn_range(stru
    8.40  	}
    8.41  
    8.42  	if (v != u) {
    8.43 -		/* get the ptep's filled in */
    8.44 +		/* Final batch. */
    8.45  		rc = apply_to_page_range(mm, start_address,
    8.46  					 address - start_address,
    8.47  					 direct_remap_area_pte_fn, &w);
    8.48 @@ -179,32 +169,6 @@ int touch_pte_range(struct mm_struct *mm
    8.49  
    8.50  EXPORT_SYMBOL(touch_pte_range);
    8.51  
    8.52 -void *vm_map_xen_pages (unsigned long maddr, int vm_size, pgprot_t prot)
    8.53 -{
    8.54 -	int error;
    8.55 -       
    8.56 -	struct vm_struct *vma;
    8.57 -	vma = get_vm_area (vm_size, VM_IOREMAP);
    8.58 -      
    8.59 -	if (vma == NULL) {
    8.60 -		printk ("ioremap.c,vm_map_xen_pages(): "
    8.61 -			"Failed to get VMA area\n");
    8.62 -		return NULL;
    8.63 -	}
    8.64 -
    8.65 -	error = direct_kernel_remap_pfn_range((unsigned long) vma->addr,
    8.66 -					      maddr >> PAGE_SHIFT, vm_size,
    8.67 -					      prot, DOMID_SELF );
    8.68 -	if (error == 0) {
    8.69 -		return vma->addr;
    8.70 -	} else {
    8.71 -		printk ("ioremap.c,vm_map_xen_pages(): "
    8.72 -			"Failed to map xen shared pages into kernel space\n");
    8.73 -		return NULL;
    8.74 -	}
    8.75 -}
    8.76 -EXPORT_SYMBOL(vm_map_xen_pages);
    8.77 -
    8.78  /*
    8.79   * Does @address reside within a non-highmem page that is local to this virtual
    8.80   * machine (i.e., not an I/O page, nor a memory page belonging to another VM).
     9.1 --- a/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Mon Sep 18 09:23:51 2006 -0400
     9.2 +++ b/linux-2.6-xen-sparse/arch/i386/oprofile/xenoprof.c	Mon Sep 18 14:28:16 2006 -0500
     9.3 @@ -26,16 +26,17 @@
     9.4  #include <xen/evtchn.h>
     9.5  #include "op_counter.h"
     9.6  
     9.7 +#include <xen/driver_util.h>
     9.8  #include <xen/interface/xen.h>
     9.9  #include <xen/interface/xenoprof.h>
    9.10  #include <../../../drivers/oprofile/cpu_buffer.h>
    9.11  #include <../../../drivers/oprofile/event_buffer.h>
    9.12  
    9.13 +#define MAX_XENOPROF_SAMPLES 16
    9.14 +
    9.15  static int xenoprof_start(void);
    9.16  static void xenoprof_stop(void);
    9.17  
    9.18 -void * vm_map_xen_pages(unsigned long maddr, int vm_size, pgprot_t prot);
    9.19 -
    9.20  static int xenoprof_enabled = 0;
    9.21  static unsigned int num_events = 0;
    9.22  static int is_primary = 0;
    9.23 @@ -44,7 +45,7 @@ static int active_defined;
    9.24  /* sample buffers shared with Xen */
    9.25  xenoprof_buf_t * xenoprof_buf[MAX_VIRT_CPUS];
    9.26  /* Shared buffer area */
    9.27 -char * shared_buffer;
    9.28 +char * shared_buffer = NULL;
    9.29  /* Number of buffers in shared area (one per VCPU) */
    9.30  int nbuf;
    9.31  /* Mappings of VIRQ_XENOPROF to irq number (per cpu) */
    9.32 @@ -234,13 +235,57 @@ static int bind_virq(void)
    9.33  }
    9.34  
    9.35  
    9.36 +static int map_xenoprof_buffer(int max_samples)
    9.37 +{
    9.38 +	struct xenoprof_get_buffer get_buffer;
    9.39 +	struct xenoprof_buf *buf;
    9.40 +	int npages, ret, i;
    9.41 +	struct vm_struct *area;
    9.42 +
    9.43 +	if ( shared_buffer )
    9.44 +		return 0;
    9.45 +
    9.46 +	get_buffer.max_samples = max_samples;
    9.47 +
    9.48 +	if ( (ret = HYPERVISOR_xenoprof_op(XENOPROF_get_buffer, &get_buffer)) )
    9.49 +		return ret;
    9.50 +
    9.51 +	nbuf = get_buffer.nbuf;
    9.52 +	npages = (get_buffer.bufsize * nbuf - 1) / PAGE_SIZE + 1;
    9.53 +
    9.54 +	area = alloc_vm_area(npages * PAGE_SIZE);
    9.55 +	if (area == NULL)
    9.56 +		return -ENOMEM;
    9.57 +
    9.58 +	if ( (ret = direct_kernel_remap_pfn_range(
    9.59 +		      (unsigned long)area->addr,
    9.60 +		      get_buffer.buf_maddr >> PAGE_SHIFT,
    9.61 +		      npages * PAGE_SIZE, __pgprot(_KERNPG_TABLE), DOMID_SELF)) ) {
    9.62 +		vunmap(area->addr);
    9.63 +		return ret;
    9.64 +	}
    9.65 +
    9.66 +	shared_buffer = area->addr;
    9.67 +	for (i=0; i< nbuf; i++) {
    9.68 +		buf = (struct xenoprof_buf*) 
    9.69 +			&shared_buffer[i * get_buffer.bufsize];
    9.70 +		BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
    9.71 +		xenoprof_buf[buf->vcpu_id] = buf;
    9.72 +	}
    9.73 +
    9.74 +	return 0;
    9.75 +}
    9.76 +
    9.77 +
    9.78  static int xenoprof_setup(void)
    9.79  {
    9.80  	int ret;
    9.81  	int i;
    9.82  
    9.83 -	ret = bind_virq();
    9.84 -	if (ret)
    9.85 +	if ( (ret = map_xenoprof_buffer(MAX_XENOPROF_SAMPLES)) )
    9.86 +		return ret;
    9.87 +
    9.88 +	if ( (ret = bind_virq()) )
    9.89  		return ret;
    9.90  
    9.91  	if (is_primary) {
    9.92 @@ -373,9 +418,9 @@ static int xenoprof_set_passive(int * p_
    9.93  {
    9.94  	int ret;
    9.95  	int i, j;
    9.96 -	int vm_size;
    9.97  	int npages;
    9.98  	struct xenoprof_buf *buf;
    9.99 +	struct vm_struct *area;
   9.100  	pgprot_t prot = __pgprot(_KERNPG_TABLE);
   9.101  
   9.102  	if (!is_primary)
   9.103 @@ -391,20 +436,30 @@ static int xenoprof_set_passive(int * p_
   9.104  	for (i = 0; i < pdoms; i++) {
   9.105  		passive_domains[i].domain_id = p_domains[i];
   9.106  		passive_domains[i].max_samples = 2048;
   9.107 -		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive, &passive_domains[i]);
   9.108 +		ret = HYPERVISOR_xenoprof_op(XENOPROF_set_passive,
   9.109 +					     &passive_domains[i]);
   9.110  		if (ret)
   9.111 -			return ret;
   9.112 +			goto out;
   9.113  
   9.114  		npages = (passive_domains[i].bufsize * passive_domains[i].nbuf - 1) / PAGE_SIZE + 1;
   9.115 -		vm_size = npages * PAGE_SIZE;
   9.116  
   9.117 -		p_shared_buffer[i] = (char *)vm_map_xen_pages(passive_domains[i].buf_maddr,
   9.118 -							      vm_size, prot);
   9.119 -		if (!p_shared_buffer[i]) {
   9.120 +		area = alloc_vm_area(npages * PAGE_SIZE);
   9.121 +		if (area == NULL) {
   9.122  			ret = -ENOMEM;
   9.123  			goto out;
   9.124  		}
   9.125  
   9.126 +		ret = direct_kernel_remap_pfn_range(
   9.127 +			(unsigned long)area->addr,
   9.128 +			passive_domains[i].buf_maddr >> PAGE_SHIFT,
   9.129 +			npages * PAGE_SIZE, prot, DOMID_SELF);
   9.130 +		if (ret) {
   9.131 +			vunmap(area->addr);
   9.132 +			goto out;
   9.133 +		}
   9.134 +
   9.135 +		p_shared_buffer[i] = area->addr;
   9.136 +
   9.137  		for (j = 0; j < passive_domains[i].nbuf; j++) {
   9.138  			buf = (struct xenoprof_buf *)
   9.139  				&p_shared_buffer[i][j * passive_domains[i].bufsize];
   9.140 @@ -473,44 +528,19 @@ static int using_xenoprof;
   9.141  int __init oprofile_arch_init(struct oprofile_operations * ops)
   9.142  {
   9.143  	struct xenoprof_init init;
   9.144 -	struct xenoprof_buf * buf;
   9.145 -	int vm_size;
   9.146 -	int npages;
   9.147 -	int ret;
   9.148 -	int i;
   9.149 +	int ret, i;
   9.150  
   9.151 -	init.max_samples = 16;
   9.152  	ret = HYPERVISOR_xenoprof_op(XENOPROF_init, &init);
   9.153  
   9.154  	if (!ret) {
   9.155 -		pgprot_t prot = __pgprot(_KERNPG_TABLE);
   9.156 -
   9.157  		num_events = init.num_events;
   9.158  		is_primary = init.is_primary;
   9.159 -		nbuf = init.nbuf;
   9.160  
   9.161  		/* just in case - make sure we do not overflow event list 
   9.162 -                   (i.e. counter_config list) */
   9.163 +		   (i.e. counter_config list) */
   9.164  		if (num_events > OP_MAX_COUNTER)
   9.165  			num_events = OP_MAX_COUNTER;
   9.166  
   9.167 -		npages = (init.bufsize * nbuf - 1) / PAGE_SIZE + 1;
   9.168 -		vm_size = npages * PAGE_SIZE;
   9.169 -
   9.170 -		shared_buffer = (char *)vm_map_xen_pages(init.buf_maddr,
   9.171 -							 vm_size, prot);
   9.172 -		if (!shared_buffer) {
   9.173 -			ret = -ENOMEM;
   9.174 -			goto out;
   9.175 -		}
   9.176 -
   9.177 -		for (i=0; i< nbuf; i++) {
   9.178 -			buf = (struct xenoprof_buf*) 
   9.179 -				&shared_buffer[i * init.bufsize];
   9.180 -			BUG_ON(buf->vcpu_id >= MAX_VIRT_CPUS);
   9.181 -			xenoprof_buf[buf->vcpu_id] = buf;
   9.182 -		}
   9.183 -
   9.184  		/*  cpu_type is detected by Xen */
   9.185  		cpu_type[XENOPROF_CPU_TYPE_SIZE-1] = 0;
   9.186  		strncpy(cpu_type, init.cpu_type, XENOPROF_CPU_TYPE_SIZE - 1);
   9.187 @@ -525,7 +555,6 @@ int __init oprofile_arch_init(struct opr
   9.188  
   9.189  		active_defined = 0;
   9.190  	}
   9.191 - out:
   9.192  	printk(KERN_INFO "oprofile_arch_init: ret %d, events %d, "
   9.193  	       "is_primary %d\n", ret, num_events, is_primary);
   9.194  	return ret;
    10.1 --- a/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon Sep 18 09:23:51 2006 -0400
    10.2 +++ b/linux-2.6-xen-sparse/arch/ia64/Kconfig	Mon Sep 18 14:28:16 2006 -0500
    10.3 @@ -516,12 +516,6 @@ config XEN_BALLOON
    10.4  config XEN_SKBUFF
    10.5  	default y
    10.6  
    10.7 -config XEN_NETDEV_BACKEND
    10.8 -	default y
    10.9 -
   10.10 -config XEN_NETDEV_FRONTEND
   10.11 -	default y
   10.12 -
   10.13  config XEN_DEVMEM
   10.14  	default n
   10.15  
    11.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c	Mon Sep 18 09:23:51 2006 -0400
    11.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/e820-xen.c	Mon Sep 18 14:28:16 2006 -0500
    11.3 @@ -255,8 +255,10 @@ void __init e820_reserve_resources(struc
    11.4  			 *  so we try it repeatedly and let the resource manager
    11.5  			 *  test it.
    11.6  			 */
    11.7 +#ifndef CONFIG_XEN
    11.8  			request_resource(res, &code_resource);
    11.9  			request_resource(res, &data_resource);
   11.10 +#endif
   11.11  #ifdef CONFIG_KEXEC
   11.12  			request_resource(res, &crashk_res);
   11.13  #endif
    12.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon Sep 18 09:23:51 2006 -0400
    12.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Mon Sep 18 14:28:16 2006 -0500
    12.3 @@ -944,9 +944,10 @@ void __init setup_arch(char **cmdline_p)
    12.4  		BUG_ON(HYPERVISOR_memory_op(XENMEM_machine_memory_map, &memmap));
    12.5  
    12.6  		e820_reserve_resources(machine_e820, memmap.nr_entries);
    12.7 -	} else
    12.8 +	}
    12.9 +#else
   12.10 +	e820_reserve_resources(e820.map, e820.nr_map);
   12.11  #endif
   12.12 -	e820_reserve_resources(e820.map, e820.nr_map);
   12.13  
   12.14  	request_resource(&iomem_resource, &video_ram_resource);
   12.15  
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon Sep 18 09:23:51 2006 -0400
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c	Mon Sep 18 14:28:16 2006 -0500
    13.3 @@ -301,11 +301,11 @@ static void frontend_changed(struct xenb
    13.4  	struct backend_info *be = dev->dev.driver_data;
    13.5  	int err;
    13.6  
    13.7 -	DPRINTK("");
    13.8 +	DPRINTK("%s", xenbus_strstate(frontend_state));
    13.9  
   13.10  	switch (frontend_state) {
   13.11  	case XenbusStateInitialising:
   13.12 -		if (dev->state == XenbusStateClosing) {
   13.13 +		if (dev->state == XenbusStateClosed) {
   13.14  			printk("%s: %s: prepare for reconnect\n",
   13.15  			       __FUNCTION__, dev->nodename);
   13.16  			xenbus_switch_state(dev, XenbusStateInitWait);
   13.17 @@ -331,8 +331,12 @@ static void frontend_changed(struct xenb
   13.18  		xenbus_switch_state(dev, XenbusStateClosing);
   13.19  		break;
   13.20  
   13.21 +	case XenbusStateClosed:
   13.22 +		xenbus_switch_state(dev, XenbusStateClosed);
   13.23 +		if (xenbus_dev_is_online(dev))
   13.24 +			break;
   13.25 +		/* fall through if not online */
   13.26  	case XenbusStateUnknown:
   13.27 -	case XenbusStateClosed:
   13.28  		device_unregister(&dev->dev);
   13.29  		break;
   13.30  
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Mon Sep 18 09:23:51 2006 -0400
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Mon Sep 18 14:28:16 2006 -0500
    14.3 @@ -273,7 +273,7 @@ static void backend_changed(struct xenbu
    14.4  			xenbus_dev_fatal(dev, -ENODEV, "bdget failed");
    14.5  
    14.6  		down(&bd->bd_sem);
    14.7 -		if (info->users > 0)
    14.8 +		if (info->users > 0 && system_state == SYSTEM_RUNNING)
    14.9  			xenbus_dev_error(dev, -EBUSY,
   14.10  					 "Device in use; refusing to close");
   14.11  		else
   14.12 @@ -360,7 +360,7 @@ static void blkfront_closing(struct xenb
   14.13  
   14.14  	xlvbd_del(info);
   14.15  
   14.16 -	xenbus_switch_state(dev, XenbusStateClosed);
   14.17 +	xenbus_frontend_closed(dev);
   14.18  }
   14.19  
   14.20  
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Mon Sep 18 09:23:51 2006 -0400
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/common.h	Mon Sep 18 14:28:16 2006 -0500
    15.3 @@ -91,6 +91,7 @@ blkif_t *tap_alloc_blkif(domid_t domid);
    15.4  void tap_blkif_free(blkif_t *blkif);
    15.5  int tap_blkif_map(blkif_t *blkif, unsigned long shared_page, 
    15.6  		  unsigned int evtchn);
    15.7 +void tap_blkif_unmap(blkif_t *blkif);
    15.8  
    15.9  #define blkif_get(_b) (atomic_inc(&(_b)->refcnt))
   15.10  #define blkif_put(_b)					\
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon Sep 18 09:23:51 2006 -0400
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon Sep 18 14:28:16 2006 -0500
    16.3 @@ -135,20 +135,25 @@ int tap_blkif_map(blkif_t *blkif, unsign
    16.4  	return 0;
    16.5  }
    16.6  
    16.7 +void tap_blkif_unmap(blkif_t *blkif)
    16.8 +{
    16.9 +	if (blkif->irq) {
   16.10 +		unbind_from_irqhandler(blkif->irq, blkif);
   16.11 +		blkif->irq = 0;
   16.12 +	}
   16.13 +	if (blkif->blk_ring.sring) {
   16.14 +		unmap_frontend_page(blkif);
   16.15 +		free_vm_area(blkif->blk_ring_area);
   16.16 +		blkif->blk_ring.sring = NULL;
   16.17 +	}
   16.18 +}
   16.19 +
   16.20  void tap_blkif_free(blkif_t *blkif)
   16.21  {
   16.22  	atomic_dec(&blkif->refcnt);
   16.23  	wait_event(blkif->waiting_to_free, atomic_read(&blkif->refcnt) == 0);
   16.24  
   16.25 -	/* Already disconnected? */
   16.26 -	if (blkif->irq)
   16.27 -		unbind_from_irqhandler(blkif->irq, blkif);
   16.28 -
   16.29 -	if (blkif->blk_ring.sring) {
   16.30 -		unmap_frontend_page(blkif);
   16.31 -		free_vm_area(blkif->blk_ring_area);
   16.32 -	}
   16.33 -
   16.34 +	tap_blkif_unmap(blkif);
   16.35  	kmem_cache_free(blkif_cachep, blkif);
   16.36  }
   16.37  
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon Sep 18 09:23:51 2006 -0400
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/xenbus.c	Mon Sep 18 14:28:16 2006 -0500
    17.3 @@ -247,6 +247,11 @@ static void tap_frontend_changed(struct 
    17.4  
    17.5  	switch (frontend_state) {
    17.6  	case XenbusStateInitialising:
    17.7 +		if (dev->state == XenbusStateClosed) {
    17.8 +			printk("%s: %s: prepare for reconnect\n",
    17.9 +			       __FUNCTION__, dev->nodename);
   17.10 +			xenbus_switch_state(dev, XenbusStateInitWait);
   17.11 +		}
   17.12  		break;
   17.13  
   17.14  	case XenbusStateInitialised:
   17.15 @@ -264,11 +269,20 @@ static void tap_frontend_changed(struct 
   17.16  		break;
   17.17  
   17.18  	case XenbusStateClosing:
   17.19 +		if (be->blkif->xenblkd) {
   17.20 +			kthread_stop(be->blkif->xenblkd);
   17.21 +			be->blkif->xenblkd = NULL;
   17.22 +		}
   17.23 +		tap_blkif_unmap(be->blkif);
   17.24  		xenbus_switch_state(dev, XenbusStateClosing);
   17.25  		break;
   17.26  
   17.27 +	case XenbusStateClosed:
   17.28 +		xenbus_switch_state(dev, XenbusStateClosed);
   17.29 +		if (xenbus_dev_is_online(dev))
   17.30 +			break;
   17.31 +		/* fall through if not online */
   17.32  	case XenbusStateUnknown:
   17.33 -	case XenbusStateClosed:
   17.34  		device_unregister(&dev->dev);
   17.35  		break;
   17.36  
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Mon Sep 18 09:23:51 2006 -0400
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Mon Sep 18 14:28:16 2006 -0500
    18.3 @@ -182,17 +182,18 @@ static struct console kcons_info = {
    18.4  	.index	= -1,
    18.5  };
    18.6  
    18.7 -#define __RETCODE 0
    18.8  static int __init xen_console_init(void)
    18.9  {
   18.10  	if (!is_running_on_xen())
   18.11 -		return __RETCODE;
   18.12 +		goto out;
   18.13  
   18.14  	if (is_initial_xendomain()) {
   18.15  		if (xc_mode == XC_DEFAULT)
   18.16  			xc_mode = XC_SERIAL;
   18.17  		kcons_info.write = kcons_write_dom0;
   18.18  	} else {
   18.19 +		if (!xen_start_info->console.domU.evtchn)
   18.20 +			goto out;
   18.21  		if (xc_mode == XC_DEFAULT)
   18.22  			xc_mode = XC_TTY;
   18.23  		kcons_info.write = kcons_write;
   18.24 @@ -212,14 +213,15 @@ static int __init xen_console_init(void)
   18.25  		break;
   18.26  
   18.27  	default:
   18.28 -		return __RETCODE;
   18.29 +		goto out;
   18.30  	}
   18.31  
   18.32  	wbuf = alloc_bootmem(wbuf_size);
   18.33  
   18.34  	register_console(&kcons_info);
   18.35  
   18.36 -	return __RETCODE;
   18.37 + out:
   18.38 +	return 0;
   18.39  }
   18.40  console_initcall(xen_console_init);
   18.41  
   18.42 @@ -247,7 +249,9 @@ void xencons_force_flush(void)
   18.43  	int sz;
   18.44  
   18.45  	/* Emergency console is synchronous, so there's nothing to flush. */
   18.46 -	if (is_initial_xendomain())
   18.47 +	if (!is_running_on_xen() ||
   18.48 +	    is_initial_xendomain() ||
   18.49 +	    !xen_start_info->console.domU.evtchn)
   18.50  		return;
   18.51  
   18.52  	/* Spin until console data is flushed through to the daemon. */
   18.53 @@ -582,7 +586,11 @@ static int __init xencons_init(void)
   18.54  	if (xc_mode == XC_OFF)
   18.55  		return 0;
   18.56  
   18.57 -	xencons_ring_init();
   18.58 +	if (!is_initial_xendomain()) {
   18.59 +		rc = xencons_ring_init();
   18.60 +		if (rc)
   18.61 +			return rc;
   18.62 +	}
   18.63  
   18.64  	xencons_driver = alloc_tty_driver((xc_mode == XC_SERIAL) ?
   18.65  					  1 : MAX_NR_CONSOLES);
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Mon Sep 18 09:23:51 2006 -0400
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Mon Sep 18 14:28:16 2006 -0500
    19.3 @@ -110,24 +110,26 @@ static irqreturn_t handle_input(int irq,
    19.4  
    19.5  int xencons_ring_init(void)
    19.6  {
    19.7 -	int err;
    19.8 +	int irq;
    19.9  
   19.10  	if (xencons_irq)
   19.11  		unbind_from_irqhandler(xencons_irq, NULL);
   19.12  	xencons_irq = 0;
   19.13  
   19.14 -	if (!xen_start_info->console.domU.evtchn)
   19.15 -		return 0;
   19.16 +	if (!is_running_on_xen() ||
   19.17 +	    is_initial_xendomain() ||
   19.18 +	    !xen_start_info->console.domU.evtchn)
   19.19 +		return -ENODEV;
   19.20  
   19.21 -	err = bind_evtchn_to_irqhandler(
   19.22 +	irq = bind_evtchn_to_irqhandler(
   19.23  		xen_start_info->console.domU.evtchn,
   19.24  		handle_input, 0, "xencons", NULL);
   19.25 -	if (err <= 0) {
   19.26 -		printk(KERN_ERR "XEN console request irq failed %i\n", err);
   19.27 -		return err;
   19.28 +	if (irq < 0) {
   19.29 +		printk(KERN_ERR "XEN console request irq failed %i\n", irq);
   19.30 +		return irq;
   19.31  	}
   19.32  
   19.33 -	xencons_irq = err;
   19.34 +	xencons_irq = irq;
   19.35  
   19.36  	/* In case we have in-flight data after save/restore... */
   19.37  	notify_daemon();
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon Sep 18 09:23:51 2006 -0400
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Mon Sep 18 14:28:16 2006 -0500
    20.3 @@ -228,13 +228,13 @@ static void frontend_changed(struct xenb
    20.4  {
    20.5  	struct backend_info *be = dev->dev.driver_data;
    20.6  
    20.7 -	DPRINTK("");
    20.8 +	DPRINTK("%s", xenbus_strstate(frontend_state));
    20.9  
   20.10  	be->frontend_state = frontend_state;
   20.11  
   20.12  	switch (frontend_state) {
   20.13  	case XenbusStateInitialising:
   20.14 -		if (dev->state == XenbusStateClosing) {
   20.15 +		if (dev->state == XenbusStateClosed) {
   20.16  			printk("%s: %s: prepare for reconnect\n",
   20.17  			       __FUNCTION__, dev->nodename);
   20.18  			if (be->netif) {
   20.19 @@ -260,8 +260,12 @@ static void frontend_changed(struct xenb
   20.20  		xenbus_switch_state(dev, XenbusStateClosing);
   20.21  		break;
   20.22  
   20.23 +	case XenbusStateClosed:
   20.24 +		xenbus_switch_state(dev, XenbusStateClosed);
   20.25 +		if (xenbus_dev_is_online(dev))
   20.26 +			break;
   20.27 +		/* fall through if not online */
   20.28  	case XenbusStateUnknown:
   20.29 -	case XenbusStateClosed:
   20.30  		if (be->netif != NULL)
   20.31  			kobject_uevent(&dev->dev.kobj, KOBJ_OFFLINE);
   20.32  		device_unregister(&dev->dev);
   20.33 @@ -423,6 +427,14 @@ static int connect_rings(struct backend_
   20.34  		be->netif->dev->features |= NETIF_F_TSO;
   20.35  	}
   20.36  
   20.37 +	if (xenbus_scanf(XBT_NIL, dev->otherend, "feature-no-csum-offload",
   20.38 +			 "%d", &val) < 0)
   20.39 +		val = 0;
   20.40 +	if (val) {
   20.41 +		be->netif->features &= ~NETIF_F_IP_CSUM;
   20.42 +		be->netif->dev->features &= ~NETIF_F_IP_CSUM;
   20.43 +	}
   20.44 +
   20.45  	/* Map the shared frame, irq etc. */
   20.46  	err = netif_map(be->netif, tx_ring_ref, rx_ring_ref, evtchn);
   20.47  	if (err) {
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon Sep 18 09:23:51 2006 -0400
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon Sep 18 14:28:16 2006 -0500
    21.3 @@ -486,7 +486,7 @@ static void backend_changed(struct xenbu
    21.4  	struct netfront_info *np = dev->dev.driver_data;
    21.5  	struct net_device *netdev = np->netdev;
    21.6  
    21.7 -	DPRINTK("\n");
    21.8 +	DPRINTK("%s\n", xenbus_strstate(backend_state));
    21.9  
   21.10  	switch (backend_state) {
   21.11  	case XenbusStateInitialising:
   21.12 @@ -1936,11 +1936,10 @@ static void netfront_closing(struct xenb
   21.13  {
   21.14  	struct netfront_info *info = dev->dev.driver_data;
   21.15  
   21.16 -	DPRINTK("netfront_closing: %s removed\n", dev->nodename);
   21.17 +	DPRINTK("%s\n", dev->nodename);
   21.18  
   21.19  	close_netdev(info);
   21.20 -
   21.21 -	xenbus_switch_state(dev, XenbusStateClosed);
   21.22 +	xenbus_frontend_closed(dev);
   21.23  }
   21.24  
   21.25  
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Mon Sep 18 09:23:51 2006 -0400
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Mon Sep 18 14:28:16 2006 -0500
    22.3 @@ -132,4 +132,16 @@ int xenbus_unmap_ring(struct xenbus_devi
    22.4  }
    22.5  EXPORT_SYMBOL_GPL(xenbus_unmap_ring);
    22.6  
    22.7 +int xenbus_dev_is_online(struct xenbus_device *dev)
    22.8 +{
    22.9 +	int rc, val;
   22.10 +
   22.11 +	rc = xenbus_scanf(XBT_NIL, dev->nodename, "online", "%d", &val);
   22.12 +	if (rc != 1)
   22.13 +		val = 0; /* no online node present */
   22.14 +
   22.15 +	return val;
   22.16 +}
   22.17 +EXPORT_SYMBOL_GPL(xenbus_dev_is_online);
   22.18 +
   22.19  MODULE_LICENSE("Dual BSD/GPL");
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Mon Sep 18 09:23:51 2006 -0400
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Mon Sep 18 14:28:16 2006 -0500
    23.3 @@ -41,6 +41,20 @@ extern char *kasprintf(const char *fmt, 
    23.4  #define DPRINTK(fmt, args...) \
    23.5      pr_debug("xenbus_client (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args)
    23.6  
    23.7 +char *xenbus_strstate(enum xenbus_state state)
    23.8 +{
    23.9 +	static char *name[] = {
   23.10 +		[ XenbusStateUnknown      ] = "Unknown",
   23.11 +		[ XenbusStateInitialising ] = "Initialising",
   23.12 +		[ XenbusStateInitWait     ] = "InitWait",
   23.13 +		[ XenbusStateInitialised  ] = "Initialised",
   23.14 +		[ XenbusStateConnected    ] = "Connected",
   23.15 +		[ XenbusStateClosing      ] = "Closing",
   23.16 +		[ XenbusStateClosed	  ] = "Closed",
   23.17 +	};
   23.18 +	return (state < ARRAY_SIZE(name)) ? name[state] : "INVALID";
   23.19 +}
   23.20 +
   23.21  int xenbus_watch_path(struct xenbus_device *dev, const char *path,
   23.22  		      struct xenbus_watch *watch,
   23.23  		      void (*callback)(struct xenbus_watch *,
   23.24 @@ -124,6 +138,13 @@ int xenbus_switch_state(struct xenbus_de
   23.25  }
   23.26  EXPORT_SYMBOL_GPL(xenbus_switch_state);
   23.27  
   23.28 +int xenbus_frontend_closed(struct xenbus_device *dev)
   23.29 +{
   23.30 +	xenbus_switch_state(dev, XenbusStateClosed);
   23.31 +	complete(&dev->down);
   23.32 +	return 0;
   23.33 +}
   23.34 +EXPORT_SYMBOL_GPL(xenbus_frontend_closed);
   23.35  
   23.36  /**
   23.37   * Return the path to the error node for the given device, or NULL on failure.
    24.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon Sep 18 09:23:51 2006 -0400
    24.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon Sep 18 14:28:16 2006 -0500
    24.3 @@ -73,6 +73,7 @@ static int xenbus_probe_backend(const ch
    24.4  
    24.5  static int xenbus_dev_probe(struct device *_dev);
    24.6  static int xenbus_dev_remove(struct device *_dev);
    24.7 +static void xenbus_dev_shutdown(struct device *_dev);
    24.8  
    24.9  /* If something in array of ids matches this device, return it. */
   24.10  static const struct xenbus_device_id *
   24.11 @@ -192,6 +193,7 @@ static struct xen_bus_type xenbus_fronte
   24.12  		.match    = xenbus_match,
   24.13  		.probe    = xenbus_dev_probe,
   24.14  		.remove   = xenbus_dev_remove,
   24.15 +		.shutdown = xenbus_dev_shutdown,
   24.16  	},
   24.17  	.dev = {
   24.18  		.bus_id = "xen",
   24.19 @@ -246,6 +248,7 @@ static struct xen_bus_type xenbus_backen
   24.20  		.match    = xenbus_match,
   24.21  		.probe    = xenbus_dev_probe,
   24.22  		.remove   = xenbus_dev_remove,
   24.23 +//		.shutdown = xenbus_dev_shutdown,
   24.24  		.uevent   = xenbus_uevent_backend,
   24.25  	},
   24.26  	.dev = {
   24.27 @@ -316,8 +319,9 @@ static void otherend_changed(struct xenb
   24.28  
   24.29  	state = xenbus_read_driver_state(dev->otherend);
   24.30  
   24.31 -	DPRINTK("state is %d, %s, %s",
   24.32 -		state, dev->otherend_watch.node, vec[XS_WATCH_PATH]);
   24.33 +	DPRINTK("state is %d (%s), %s, %s", state, xenbus_strstate(state),
   24.34 +		dev->otherend_watch.node, vec[XS_WATCH_PATH]);
   24.35 +
   24.36  	if (drv->otherend_changed)
   24.37  		drv->otherend_changed(dev, state);
   24.38  }
   24.39 @@ -348,7 +352,7 @@ static int xenbus_dev_probe(struct devic
   24.40  	const struct xenbus_device_id *id;
   24.41  	int err;
   24.42  
   24.43 -	DPRINTK("");
   24.44 +	DPRINTK("%s", dev->nodename);
   24.45  
   24.46  	if (!drv->probe) {
   24.47  		err = -ENODEV;
   24.48 @@ -393,7 +397,7 @@ static int xenbus_dev_remove(struct devi
   24.49  	struct xenbus_device *dev = to_xenbus_device(_dev);
   24.50  	struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
   24.51  
   24.52 -	DPRINTK("");
   24.53 +	DPRINTK("%s", dev->nodename);
   24.54  
   24.55  	free_otherend_watch(dev);
   24.56  	free_otherend_details(dev);
   24.57 @@ -405,6 +409,27 @@ static int xenbus_dev_remove(struct devi
   24.58  	return 0;
   24.59  }
   24.60  
   24.61 +static void xenbus_dev_shutdown(struct device *_dev)
   24.62 +{
   24.63 +	struct xenbus_device *dev = to_xenbus_device(_dev);
   24.64 +	unsigned long timeout = 5*HZ;
   24.65 +
   24.66 +	DPRINTK("%s", dev->nodename);
   24.67 +
   24.68 +	get_device(&dev->dev);
   24.69 +	if (dev->state != XenbusStateConnected) {
   24.70 +		printk("%s: %s: %s != Connected, skipping\n", __FUNCTION__,
   24.71 +		       dev->nodename, xenbus_strstate(dev->state));
   24.72 +		goto out;
   24.73 +	}
   24.74 +	xenbus_switch_state(dev, XenbusStateClosing);
   24.75 +	timeout = wait_for_completion_timeout(&dev->down, timeout);
   24.76 +	if (!timeout)
   24.77 +		printk("%s: %s timeout closing device\n", __FUNCTION__, dev->nodename);
   24.78 + out:
   24.79 +	put_device(&dev->dev);
   24.80 +}
   24.81 +
   24.82  static int xenbus_register_driver_common(struct xenbus_driver *drv,
   24.83  					 struct xen_bus_type *bus)
   24.84  {
   24.85 @@ -587,6 +612,7 @@ static int xenbus_probe_node(struct xen_
   24.86  	tmpstring += strlen(tmpstring) + 1;
   24.87  	strcpy(tmpstring, type);
   24.88  	xendev->devicetype = tmpstring;
   24.89 +	init_completion(&xendev->down);
   24.90  
   24.91  	xendev->dev.parent = &bus->dev;
   24.92  	xendev->dev.bus = &bus->bus;
    25.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/dma-mapping.h	Mon Sep 18 09:23:51 2006 -0400
    25.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/dma-mapping.h	Mon Sep 18 14:28:16 2006 -0500
    25.3 @@ -84,7 +84,9 @@ dma_sync_sg_for_device(struct device *de
    25.4  #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir)	\
    25.5  	dma_sync_single_for_device(dev, dma_handle, size, dir)
    25.6  
    25.7 +#ifndef CONFIG_XEN
    25.8  #define dma_supported		platform_dma_supported
    25.9 +#endif
   25.10  
   25.11  static inline int
   25.12  dma_set_mask (struct device *dev, u64 mask)
    26.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Mon Sep 18 09:23:51 2006 -0400
    26.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Mon Sep 18 14:28:16 2006 -0500
    26.3 @@ -205,8 +205,12 @@ static inline int
    26.4  }
    26.5  
    26.6  #include <xen/interface/memory.h>
    26.7 +#ifdef CONFIG_VMX_GUEST
    26.8 +# define ia64_xenmem_reservation_op(op, xmr) (0)
    26.9 +#else
   26.10  int ia64_xenmem_reservation_op(unsigned long op,
   26.11  		   struct xen_memory_reservation* reservation__);
   26.12 +#endif
   26.13  static inline int
   26.14  HYPERVISOR_memory_op(
   26.15      unsigned int cmd, void *arg)
    27.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Mon Sep 18 09:23:51 2006 -0400
    27.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Mon Sep 18 14:28:16 2006 -0500
    27.3 @@ -33,13 +33,17 @@
    27.4  #ifndef __HYPERVISOR_H__
    27.5  #define __HYPERVISOR_H__
    27.6  
    27.7 -#if !defined(CONFIG_XEN) && !defined(CONFIG_VMX_GUEST)
    27.8 -#define is_running_on_xen()			(0)
    27.9 -#define HYPERVISOR_ioremap(offset, size)	(offset)
   27.10 -#else
   27.11 +#ifdef CONFIG_XEN
   27.12  extern int running_on_xen;
   27.13  #define is_running_on_xen()			(running_on_xen)
   27.14 -#endif
   27.15 +#else /* CONFIG_XEN */
   27.16 +# ifdef CONFIG_VMX_GUEST
   27.17 +#  define is_running_on_xen()			(1)
   27.18 +# else /* CONFIG_VMX_GUEST */
   27.19 +#  define is_running_on_xen()			(0)
   27.20 +#  define HYPERVISOR_ioremap(offset, size)	(offset)
   27.21 +# endif /* CONFIG_VMX_GUEST */
   27.22 +#endif /* CONFIG_XEN */
   27.23  
   27.24  #if defined(CONFIG_XEN) || defined(CONFIG_VMX_GUEST)
   27.25  #include <linux/config.h>
    28.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/machvec.h	Mon Sep 18 09:23:51 2006 -0400
    28.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/machvec.h	Mon Sep 18 14:28:16 2006 -0500
    28.3 @@ -247,21 +247,6 @@ extern void machvec_init (const char *na
    28.4  #  error Unknown configuration.  Update asm-ia64/machvec.h.
    28.5  # endif /* CONFIG_IA64_GENERIC */
    28.6  
    28.7 -#ifdef CONFIG_XEN
    28.8 -# define platform_dma_map_sg		dma_map_sg
    28.9 -# define platform_dma_unmap_sg		dma_unmap_sg
   28.10 -# define platform_dma_mapping_error	dma_mapping_error
   28.11 -# define platform_dma_supported		dma_supported
   28.12 -# define platform_dma_alloc_coherent	dma_alloc_coherent
   28.13 -# define platform_dma_free_coherent	dma_free_coherent
   28.14 -# define platform_dma_map_single	dma_map_single
   28.15 -# define platform_dma_unmap_single	dma_unmap_single
   28.16 -# define platform_dma_sync_single_for_cpu \
   28.17 -					dma_sync_single_for_cpu
   28.18 -# define platform_dma_sync_single_for_device \
   28.19 -					dma_sync_single_for_device
   28.20 -#endif
   28.21 -
   28.22  /*
   28.23   * Declare default routines which aren't declared anywhere else:
   28.24   */
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/machvec_dig.h	Mon Sep 18 14:28:16 2006 -0500
    29.3 @@ -0,0 +1,33 @@
    29.4 +#ifndef _ASM_IA64_MACHVEC_DIG_h
    29.5 +#define _ASM_IA64_MACHVEC_DIG_h
    29.6 +
    29.7 +extern ia64_mv_setup_t dig_setup;
    29.8 +extern ia64_mv_irq_init_t dig_irq_init;
    29.9 +
   29.10 +/*
   29.11 + * This stuff has dual use!
   29.12 + *
   29.13 + * For a generic kernel, the macros are used to initialize the
   29.14 + * platform's machvec structure.  When compiling a non-generic kernel,
   29.15 + * the macros are used directly.
   29.16 + */
   29.17 +#define platform_name		"dig"
   29.18 +#define platform_setup		dig_setup
   29.19 +#define platform_irq_init	dig_irq_init
   29.20 +
   29.21 +#ifdef CONFIG_XEN
   29.22 +# define platform_dma_map_sg		dma_map_sg
   29.23 +# define platform_dma_unmap_sg		dma_unmap_sg
   29.24 +# define platform_dma_mapping_error	dma_mapping_error
   29.25 +# define platform_dma_supported		dma_supported
   29.26 +# define platform_dma_alloc_coherent	dma_alloc_coherent
   29.27 +# define platform_dma_free_coherent	dma_free_coherent
   29.28 +# define platform_dma_map_single	dma_map_single
   29.29 +# define platform_dma_unmap_single	dma_unmap_single
   29.30 +# define platform_dma_sync_single_for_cpu \
   29.31 +					dma_sync_single_for_cpu
   29.32 +# define platform_dma_sync_single_for_device \
   29.33 +					dma_sync_single_for_device
   29.34 +#endif
   29.35 +
   29.36 +#endif /* _ASM_IA64_MACHVEC_DIG_h */
    30.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/maddr.h	Mon Sep 18 09:23:51 2006 -0400
    30.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/maddr.h	Mon Sep 18 14:28:16 2006 -0500
    30.3 @@ -81,7 +81,11 @@ mfn_to_local_pfn(unsigned long mfn)
    30.4  #define virt_to_machine(virt) __pa(virt) // for tpmfront.c
    30.5  
    30.6  #define set_phys_to_machine(pfn, mfn) do { } while (0)
    30.7 +#ifdef CONFIG_VMX_GUEST
    30.8 +extern void xen_machphys_update(unsigned long mfn, unsigned long pfn);
    30.9 +#else /* CONFIG_VMX_GUEST */
   30.10  #define xen_machphys_update(mfn, pfn) do { } while (0)
   30.11 +#endif /* CONFIG_VMX_GUEST */
   30.12  
   30.13  typedef unsigned long maddr_t;	// to compile netback, netfront
   30.14  
    31.1 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h	Mon Sep 18 09:23:51 2006 -0400
    31.2 +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h	Mon Sep 18 14:28:16 2006 -0500
    31.3 @@ -37,6 +37,7 @@
    31.4  #include <linux/device.h>
    31.5  #include <linux/notifier.h>
    31.6  #include <linux/mutex.h>
    31.7 +#include <linux/completion.h>
    31.8  #include <xen/interface/xen.h>
    31.9  #include <xen/interface/grant_table.h>
   31.10  #include <xen/interface/io/xenbus.h>
   31.11 @@ -74,6 +75,7 @@ struct xenbus_device {
   31.12  	struct xenbus_watch otherend_watch;
   31.13  	struct device dev;
   31.14  	enum xenbus_state state;
   31.15 +	struct completion down;
   31.16  };
   31.17  
   31.18  static inline struct xenbus_device *to_xenbus_device(struct device *dev)
   31.19 @@ -297,4 +299,8 @@ void xenbus_dev_fatal(struct xenbus_devi
   31.20  
   31.21  int __init xenbus_dev_init(void);
   31.22  
   31.23 +char *xenbus_strstate(enum xenbus_state state);
   31.24 +int xenbus_dev_is_online(struct xenbus_device *dev);
   31.25 +int xenbus_frontend_closed(struct xenbus_device *dev);
   31.26 +
   31.27  #endif /* _XEN_XENBUS_H */
    32.1 --- a/patches/linux-2.6.16.13/x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch	Mon Sep 18 09:23:51 2006 -0400
    32.2 +++ b/patches/linux-2.6.16.13/x86_64-put-note-sections-into-a-pt_note-segment-in-vmlinux.patch	Mon Sep 18 14:28:16 2006 -0500
    32.3 @@ -1,5 +1,3 @@
    32.4 -diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86_64/kernel/vmlinux.lds.S
    32.5 -index 7c4de31..ef418b3 100644
    32.6  --- a/arch/x86_64/kernel/vmlinux.lds.S
    32.7  +++ b/arch/x86_64/kernel/vmlinux.lds.S
    32.8  @@ -13,6 +13,12 @@ OUTPUT_FORMAT("elf64-x86-64", "elf64-x86
    32.9 @@ -24,7 +22,7 @@ index 7c4de31..ef418b3 100644
   32.10     				/* out-of-line lock text */
   32.11     .text.lock : AT(ADDR(.text.lock) - LOAD_OFFSET) { *(.text.lock) }
   32.12   
   32.13 -@@ -57,7 +63,7 @@ #endif
   32.14 +@@ -57,17 +63,10 @@ #endif
   32.15     .data : AT(ADDR(.data) - LOAD_OFFSET) {
   32.16   	*(.data)
   32.17   	CONSTRUCTORS
   32.18 @@ -33,7 +31,17 @@ index 7c4de31..ef418b3 100644
   32.19   
   32.20     _edata = .;			/* End of data section */
   32.21   
   32.22 -@@ -89,7 +95,7 @@ #define VVIRT_OFFSET (VSYSCALL_ADDR - VS
   32.23 +-  __bss_start = .;		/* BSS */
   32.24 +-  .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
   32.25 +-	*(.bss.page_aligned)	
   32.26 +-	*(.bss)
   32.27 +-	}
   32.28 +-  __bss_stop = .;
   32.29 +-
   32.30 +   . = ALIGN(PAGE_SIZE);
   32.31 +   . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
   32.32 +   .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
   32.33 +@@ -89,7 +88,7 @@ #define VVIRT_OFFSET (VSYSCALL_ADDR - VS
   32.34   #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET)
   32.35   
   32.36     . = VSYSCALL_ADDR;
   32.37 @@ -42,7 +50,7 @@ index 7c4de31..ef418b3 100644
   32.38     __vsyscall_0 = VSYSCALL_VIRT_ADDR;
   32.39   
   32.40     . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
   32.41 -@@ -132,7 +138,7 @@ #undef VVIRT
   32.42 +@@ -132,7 +131,7 @@ #undef VVIRT
   32.43     . = ALIGN(8192);		/* init_task */
   32.44     .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
   32.45   	*(.data.init_task)
   32.46 @@ -51,7 +59,22 @@ index 7c4de31..ef418b3 100644
   32.47   
   32.48     . = ALIGN(4096);
   32.49     .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
   32.50 -@@ -235,4 +241,6 @@ #endif
   32.51 +@@ -222,6 +221,14 @@ SECTIONS
   32.52 +   . = ALIGN(4096);
   32.53 +   __nosave_end = .;
   32.54 + 
   32.55 ++  __bss_start = .;		/* BSS */
   32.56 ++  . = ALIGN(4096);
   32.57 ++  .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
   32.58 ++	*(.bss.page_aligned)
   32.59 ++	*(.bss)
   32.60 ++	}
   32.61 ++  __bss_stop = .;
   32.62 ++
   32.63 +   _end = . ;
   32.64 + 
   32.65 +   /* Sections to be discarded */
   32.66 +@@ -235,4 +242,6 @@ #endif
   32.67     STABS_DEBUG
   32.68   
   32.69     DWARF_DEBUG
    33.1 --- a/tools/blktap/drivers/block-qcow.c	Mon Sep 18 09:23:51 2006 -0400
    33.2 +++ b/tools/blktap/drivers/block-qcow.c	Mon Sep 18 14:28:16 2006 -0500
    33.3 @@ -237,6 +237,25 @@ static uint32_t gen_cksum(char *ptr, int
    33.4  	return ret;
    33.5  }
    33.6  
    33.7 +static int get_filesize(char *filename, uint64_t *size, struct stat *st)
    33.8 +{
    33.9 +	int blockfd;
   33.10 +
   33.11 +	/*Set to the backing file size*/
   33.12 +	if(S_ISBLK(st->st_mode)) {
   33.13 +		blockfd = open(filename, O_RDONLY);
   33.14 +		if (blockfd < 0)
   33.15 +			return -1;
   33.16 +		if (ioctl(blockfd,BLKGETSIZE,size)!=0) {
   33.17 +			printf("Unable to get Block device size\n");
   33.18 +			close(blockfd);
   33.19 +			return -1;
   33.20 +		}
   33.21 +		close(blockfd);
   33.22 +	} else *size = (st->st_size >> SECTOR_SHIFT);	
   33.23 +	return 0;
   33.24 +}
   33.25 +
   33.26  static int qcow_set_key(struct td_state *bs, const char *key)
   33.27  {
   33.28  	struct tdqcow_state *s = (struct tdqcow_state *)bs->private;
   33.29 @@ -1204,12 +1223,14 @@ int qcow_create(const char *filename, ui
   33.30  			header_size += backing_filename_len;
   33.31  			
   33.32  			/*Set to the backing file size*/
   33.33 -			size = (st.st_size >> SECTOR_SHIFT);
   33.34 +			if(get_filesize(backing_filename, &size, &st)) {
   33.35 +				return -1;
   33.36 +			}
   33.37  			DPRINTF("Backing file size detected: %lld sectors" 
   33.38  				"(total %lld [%lld MB])\n", 
   33.39 -				(long long)total_size, 
   33.40 -				(long long)(total_size << SECTOR_SHIFT), 
   33.41 -				(long long)(total_size >> 11));
   33.42 +				(long long)size, 
   33.43 +				(long long)(size << SECTOR_SHIFT), 
   33.44 +				(long long)(size >> 11));
   33.45  		} else {
   33.46  			backing_file = NULL;
   33.47  			DPRINTF("Setting file size: %lld (total %lld)\n", 
    34.1 --- a/tools/blktap/drivers/tapdisk.c	Mon Sep 18 09:23:51 2006 -0400
    34.2 +++ b/tools/blktap/drivers/tapdisk.c	Mon Sep 18 14:28:16 2006 -0500
    34.3 @@ -127,18 +127,15 @@ void sig_handler(int sig)
    34.4  static inline int LOCAL_FD_SET(fd_set *readfds)
    34.5  {
    34.6  	fd_list_entry_t *ptr;
    34.7 -	int i;
    34.8  
    34.9  	ptr = fd_start;
   34.10  	while (ptr != NULL) {
   34.11  		if (ptr->tap_fd) {
   34.12  			FD_SET(ptr->tap_fd, readfds);
   34.13 -			for (i = 0; i < MAX_IOFD; i++) {
   34.14 -				if (ptr->io_fd[i]) 
   34.15 -					FD_SET(ptr->io_fd[i], readfds);
   34.16 -				maxfds = (ptr->io_fd[i] > maxfds ? 
   34.17 -					  ptr->io_fd[i]: maxfds);
   34.18 -			}
   34.19 +			if (ptr->io_fd[READ]) 
   34.20 +				FD_SET(ptr->io_fd[READ], readfds);
   34.21 +			maxfds = (ptr->io_fd[READ] > maxfds ? 
   34.22 +					ptr->io_fd[READ]: maxfds);
   34.23  			maxfds = (ptr->tap_fd > maxfds ? ptr->tap_fd: maxfds);
   34.24  		}
   34.25  		ptr = ptr->next;
   34.26 @@ -580,7 +577,7 @@ static void get_io_request(struct td_sta
   34.27  
   34.28  int main(int argc, char *argv[])
   34.29  {
   34.30 -	int len, msglen, ret, i;
   34.31 +	int len, msglen, ret;
   34.32  	char *p, *buf;
   34.33  	fd_set readfds, writefds;
   34.34  	struct timeval timeout;
   34.35 @@ -633,16 +630,14 @@ int main(int argc, char *argv[])
   34.36  			     (fd_set *) 0, &timeout);
   34.37  
   34.38  		if (ret > 0) 
   34.39 -                {
   34.40 +		{
   34.41  			ptr = fd_start;
   34.42  			while (ptr != NULL) {
   34.43  				if (FD_ISSET(ptr->tap_fd, &readfds)) 
   34.44  					get_io_request(ptr->s);
   34.45 -				for (i = 0; i < MAX_IOFD; i++) {
   34.46 -					if (ptr->io_fd[i] && 
   34.47 -					   FD_ISSET(ptr->io_fd[i], &readfds)) 
   34.48 -						io_done(ptr->s, i);
   34.49 -				}
   34.50 +				if (ptr->io_fd[READ] && 
   34.51 +						FD_ISSET(ptr->io_fd[READ], &readfds)) 
   34.52 +					io_done(ptr->s, READ);
   34.53  
   34.54  				ptr = ptr->next;
   34.55  			}
    35.1 --- a/tools/check/check_python	Mon Sep 18 09:23:51 2006 -0400
    35.2 +++ b/tools/check/check_python	Mon Sep 18 14:28:16 2006 -0500
    35.3 @@ -7,4 +7,4 @@ function error {
    35.4      exit 1
    35.5  }
    35.6  
    35.7 -python -V 2>&1 | cut -d ' ' -f 2 | grep -q -E '^2.2|^2.3|^2.4' || error
    35.8 +python -V 2>&1 | cut -d ' ' -f 2 | grep -q '^2.[2345]' || error
    36.1 --- a/tools/console/client/main.c	Mon Sep 18 09:23:51 2006 -0400
    36.2 +++ b/tools/console/client/main.c	Mon Sep 18 14:28:16 2006 -0500
    36.3 @@ -220,7 +220,8 @@ int main(int argc, char **argv)
    36.4  	   user friendly, we'll bail out here since no data will ever show
    36.5  	   up on domain-0. */
    36.6  	if (domid == 0) {
    36.7 -		err(errno, "Could not read tty from store");
    36.8 +		fprintf(stderr, "Can't specify Domain-0\n");
    36.9 +		exit(EINVAL);
   36.10  	}
   36.11  
   36.12  	/* Wait a little bit for tty to appear.  There is a race
    37.1 --- a/tools/console/daemon/io.c	Mon Sep 18 09:23:51 2006 -0400
    37.2 +++ b/tools/console/daemon/io.c	Mon Sep 18 14:28:16 2006 -0500
    37.3 @@ -293,12 +293,14 @@ static bool watch_domain(struct domain *
    37.4  	bool success;
    37.5  
    37.6  	sprintf(domid_str, "dom%u", dom->domid);
    37.7 -	if (watch)
    37.8 +	if (watch) {
    37.9  		success = xs_watch(xs, dom->conspath, domid_str);
   37.10 -	else
   37.11 +		if (success)
   37.12 +			domain_create_ring(dom);
   37.13 +	} else {
   37.14  		success = xs_unwatch(xs, dom->conspath, domid_str);
   37.15 -	if (success)
   37.16 -		domain_create_ring(dom);
   37.17 +	}
   37.18 +
   37.19  	return success;
   37.20  }
   37.21  
    38.1 --- a/tools/debugger/gdb/gdbbuild	Mon Sep 18 09:23:51 2006 -0400
    38.2 +++ b/tools/debugger/gdb/gdbbuild	Mon Sep 18 14:28:16 2006 -0500
    38.3 @@ -1,5 +1,7 @@
    38.4  #!/bin/sh
    38.5  
    38.6 +set -e
    38.7 +
    38.8  [ "$GDB_MIRROR" ] || GDB_MIRROR="ftp://ftp.gnu.org/gnu/gdb/"
    38.9  
   38.10  rm -rf gdb-6.2.1 gdb-6.2.1-linux-i386-xen
   38.11 @@ -18,7 +20,7 @@ cd gdb-6.2.1-linux-i386-xen
   38.12  if [ "$MAKE" ]; then
   38.13      $MAKE
   38.14  elif which gmake ; then
   38.15 -    gmake -j4 CFLAGS=-D__XEN_TOOLS__
   38.16 +    gmake -j4
   38.17  else
   38.18 -    make -j4 CFLAGS=-D__XEN_TOOLS__
   38.19 +    make -j4
   38.20  fi
    39.1 --- a/tools/examples/vtpm-common.sh	Mon Sep 18 09:23:51 2006 -0400
    39.2 +++ b/tools/examples/vtpm-common.sh	Mon Sep 18 14:28:16 2006 -0500
    39.3 @@ -48,6 +48,9 @@ else
    39.4  	function vtpm_migrate() {
    39.5  		echo "Error: vTPM migration accross machines not implemented."
    39.6  	}
    39.7 +	function vtpm_migrate_local() {
    39.8 +		echo "Error: local vTPM migration not supported"
    39.9 +	}
   39.10  	function vtpm_migrate_recover() {
   39.11  		true
   39.12  	}
   39.13 @@ -353,6 +356,8 @@ function vtpm_migration_step() {
   39.14  	local res=$(vtpm_isLocalAddress $1)
   39.15  	if [ "$res" == "0" ]; then
   39.16  		vtpm_migrate $1 $2 $3
   39.17 +	else
   39.18 +		vtpm_migrate_local
   39.19  	fi
   39.20  }
   39.21  
    40.1 --- a/tools/examples/vtpm-impl	Mon Sep 18 09:23:51 2006 -0400
    40.2 +++ b/tools/examples/vtpm-impl	Mon Sep 18 14:28:16 2006 -0500
    40.3 @@ -184,3 +184,6 @@ function vtpm_migrate_recover() {
    40.4   echo "Error: Recovery not supported yet" 
    40.5  }
    40.6  
    40.7 +function vtpm_migrate_local() {
    40.8 + echo "Error: local vTPM migration not supported"
    40.9 +}
    41.1 --- a/tools/libxc/xenctrl.h	Mon Sep 18 09:23:51 2006 -0400
    41.2 +++ b/tools/libxc/xenctrl.h	Mon Sep 18 14:28:16 2006 -0500
    41.3 @@ -9,6 +9,11 @@
    41.4  #ifndef XENCTRL_H
    41.5  #define XENCTRL_H
    41.6  
    41.7 +/* Tell the Xen public headers we are a user-space tools build. */
    41.8 +#ifndef __XEN_TOOLS__
    41.9 +#define __XEN_TOOLS__ 1
   41.10 +#endif
   41.11 +
   41.12  #include <stddef.h>
   41.13  #include <stdint.h>
   41.14  #include <sys/ptrace.h>
    42.1 --- a/tools/python/xen/web/SrvBase.py	Mon Sep 18 09:23:51 2006 -0400
    42.2 +++ b/tools/python/xen/web/SrvBase.py	Mon Sep 18 14:28:16 2006 -0500
    42.3 @@ -84,6 +84,7 @@ class SrvBase(resource.Resource):
    42.4              try:
    42.5                  return op_method(op, req)
    42.6              except Exception, exn:
    42.7 +                req.setResponseCode(http.INTERNAL_SERVER_ERROR, "Request failed: " + op)
    42.8                  log.exception("Request %s failed.", op)
    42.9                  if req.useSxp():
   42.10                      return ['xend.err', str(exn)]
    43.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Sep 18 09:23:51 2006 -0400
    43.2 +++ b/tools/python/xen/xend/XendDomain.py	Mon Sep 18 14:28:16 2006 -0500
    43.3 @@ -420,6 +420,10 @@ class XendDomain:
    43.4          """ The following call may raise a XendError exception """
    43.5          dominfo.testMigrateDevices(True, dst)
    43.6  
    43.7 +        if live:
    43.8 +            """ Make sure there's memory free for enabling shadow mode """
    43.9 +            dominfo.checkLiveMigrateMemory()
   43.10 +
   43.11          if port == 0:
   43.12              port = xroot.get_xend_relocation_port()
   43.13          try:
    44.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Sep 18 09:23:51 2006 -0400
    44.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Sep 18 14:28:16 2006 -0500
    44.3 @@ -49,6 +49,7 @@ from xen.xend.xenstore.xstransact import
    44.4  from xen.xend.xenstore.xsutil import GetDomainPath, IntroduceDomain
    44.5  from xen.xend.xenstore.xswatch import xswatch
    44.6  
    44.7 +from xen.xend import arch
    44.8  
    44.9  """Shutdown code for poweroff."""
   44.10  DOMAIN_POWEROFF = 0
   44.11 @@ -1087,6 +1088,15 @@ class XendDomainInfo:
   44.12      ## public:
   44.13  
   44.14      def destroyDevice(self, deviceClass, devid):
   44.15 +	if type(devid) is str:
   44.16 +	    devicePath = '%s/device/%s' % (self.dompath, deviceClass)
   44.17 +	    for entry in xstransact.List(devicePath):
   44.18 +		backend = xstransact.Read('%s/%s' % (devicePath, entry), "backend")
   44.19 +		devName = xstransact.Read(backend, "dev")
   44.20 +		if devName == devid:
   44.21 +		    # We found the integer matching our devid, use it instead
   44.22 +		    devid = entry
   44.23 +        	    break
   44.24          return self.getDeviceController(deviceClass).destroyDevice(devid)
   44.25  
   44.26  
   44.27 @@ -1285,28 +1295,37 @@ class XendDomainInfo:
   44.28                  for v in range(0, self.info['max_vcpu_id']+1):
   44.29                      xc.vcpu_setaffinity(self.domid, v, self.info['cpus'])
   44.30  
   44.31 +            # Use architecture- and image-specific calculations to determine
   44.32 +            # the various headrooms necessary, given the raw configured
   44.33 +            # values.
   44.34 +            # reservation, maxmem, memory, and shadow are all in KiB.
   44.35 +            reservation = self.image.getRequiredInitialReservation(
   44.36 +                self.info['memory'] * 1024)
   44.37 +            maxmem = self.image.getRequiredAvailableMemory(
   44.38 +                self.info['maxmem'] * 1024)
   44.39 +            memory = self.image.getRequiredAvailableMemory(
   44.40 +                self.info['memory'] * 1024)
   44.41 +            shadow = self.image.getRequiredShadowMemory(
   44.42 +                self.info['shadow_memory'] * 1024,
   44.43 +                self.info['maxmem'] * 1024)
   44.44 +
   44.45 +            # Round shadow up to a multiple of a MiB, as shadow_mem_control
   44.46 +            # takes MiB and we must not round down and end up under-providing.
   44.47 +            shadow = ((shadow + 1023) / 1024) * 1024
   44.48 +
   44.49              # set memory limit
   44.50 -            maxmem = self.image.getRequiredMemory(self.info['maxmem'] * 1024)
   44.51              xc.domain_setmaxmem(self.domid, maxmem)
   44.52  
   44.53 -            mem_kb = self.image.getRequiredMemory(self.info['memory'] * 1024)
   44.54 -
   44.55 -            # get the domain's shadow memory requirement
   44.56 -            shadow_kb = self.image.getRequiredShadowMemory(mem_kb)
   44.57 -            shadow_kb_req = self.info['shadow_memory'] * 1024
   44.58 -            if shadow_kb_req > shadow_kb:
   44.59 -                shadow_kb = shadow_kb_req
   44.60 -            shadow_mb = (shadow_kb + 1023) / 1024
   44.61 -
   44.62              # Make sure there's enough RAM available for the domain
   44.63 -            balloon.free(mem_kb + shadow_mb * 1024)
   44.64 +            balloon.free(memory + shadow)
   44.65  
   44.66              # Set up the shadow memory
   44.67 -            shadow_cur = xc.shadow_mem_control(self.domid, shadow_mb)
   44.68 +            shadow_cur = xc.shadow_mem_control(self.domid, shadow / 1024)
   44.69              self.info['shadow_memory'] = shadow_cur
   44.70  
   44.71 -            # initial memory allocation
   44.72 -            xc.domain_memory_increase_reservation(self.domid, mem_kb, 0, 0)
   44.73 +            # initial memory reservation
   44.74 +            xc.domain_memory_increase_reservation(self.domid, reservation, 0,
   44.75 +                                                  0)
   44.76  
   44.77              self.createChannels()
   44.78  
   44.79 @@ -1485,6 +1504,19 @@ class XendDomainInfo:
   44.80  
   44.81      ## public:
   44.82  
   44.83 +    def checkLiveMigrateMemory(self):
   44.84 +        """ Make sure there's enough memory to migrate this domain """
   44.85 +        overhead_kb = 0
   44.86 +        if arch.type == "x86":
   44.87 +            # 1MB per vcpu plus 4Kib/Mib of RAM.  This is higher than 
   44.88 +            # the minimum that Xen would allocate if no value were given.
   44.89 +            overhead_kb = self.info['vcpus'] * 1024 + self.info['maxmem'] * 4
   44.90 +            overhead_kb = ((overhead_kb + 1023) / 1024) * 1024
   44.91 +            # The domain might already have some shadow memory
   44.92 +            overhead_kb -= xc.shadow_mem_control(self.domid) * 1024
   44.93 +        if overhead_kb > 0:
   44.94 +            balloon.free(overhead_kb)
   44.95 +
   44.96      def testMigrateDevices(self, network, dst):
   44.97          """ Notify all device about intention of migration
   44.98          @raise: XendError for a device that cannot be migrated
    45.1 --- a/tools/python/xen/xend/image.py	Mon Sep 18 09:23:51 2006 -0400
    45.2 +++ b/tools/python/xen/xend/image.py	Mon Sep 18 14:28:16 2006 -0500
    45.3 @@ -143,12 +143,27 @@ class ImageHandler:
    45.4              raise VmError('Building domain failed: ostype=%s dom=%d err=%s'
    45.5                            % (self.ostype, self.vm.getDomid(), str(result)))
    45.6  
    45.7 -    def getRequiredMemory(self, mem_kb):
    45.8 +    def getRequiredAvailableMemory(self, mem_kb):
    45.9 +        """@param mem_kb The configured maxmem or memory, in KiB.
   45.10 +        @return The corresponding required amount of memory for the domain,
   45.11 +        also in KiB.  This is normally the given mem_kb, but architecture- or
   45.12 +        image-specific code may override this to add headroom where
   45.13 +        necessary."""
   45.14          return mem_kb
   45.15  
   45.16 -    def getRequiredShadowMemory(self, mem_kb):
   45.17 -        """@return The minimum shadow memory required, in KiB, for a domain 
   45.18 -        with mem_kb KiB of RAM."""
   45.19 +    def getRequiredInitialReservation(self, mem_kb):
   45.20 +        """@param mem_kb The configured memory, in KiB.
   45.21 +        @return The corresponding required amount of memory to be free, also
   45.22 +        in KiB. This is normally the same as getRequiredAvailableMemory, but
   45.23 +        architecture- or image-specific code may override this to
   45.24 +        add headroom where necessary."""
   45.25 +        return self.getRequiredAvailableMemory(mem_kb)
   45.26 +
   45.27 +    def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
   45.28 +        """@param shadow_mem_kb The configured shadow memory, in KiB.
   45.29 +        @param maxmem_kb The configured maxmem, in KiB.
   45.30 +        @return The corresponding required amount of shadow memory, also in
   45.31 +        KiB."""
   45.32          # PV domains don't need any shadow memory
   45.33          return 0
   45.34  
   45.35 @@ -418,13 +433,13 @@ class IA64_HVM_ImageHandler(HVMImageHand
   45.36  
   45.37      ostype = "hvm"
   45.38  
   45.39 -    def getRequiredMemory(self, mem_kb):
   45.40 +    def getRequiredAvailableMemory(self, mem_kb):
   45.41          page_kb = 16
   45.42          # ROM size for guest firmware, ioreq page and xenstore page
   45.43          extra_pages = 1024 + 2
   45.44          return mem_kb + extra_pages * page_kb
   45.45  
   45.46 -    def getRequiredShadowMemory(self, mem_kb):
   45.47 +    def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
   45.48          # Explicit shadow memory is not a concept 
   45.49          return 0
   45.50  
   45.51 @@ -432,19 +447,29 @@ class X86_HVM_ImageHandler(HVMImageHandl
   45.52  
   45.53      ostype = "hvm"
   45.54  
   45.55 -    def getRequiredMemory(self, mem_kb):
   45.56 +    def getRequiredAvailableMemory(self, mem_kb):
   45.57 +        # Add 8 MiB overhead for QEMU's video RAM.
   45.58 +        return self.getRequiredInitialReservation(mem_kb) + 8192
   45.59 +
   45.60 +    def getRequiredInitialReservation(self, mem_kb):
   45.61          page_kb = 4
   45.62          # This was derived emperically:
   45.63 -        #   2.4 MB overhead per 1024 MB RAM + 8 MB constant
   45.64 +        #   2.4 MB overhead per 1024 MB RAM
   45.65          #   + 4 to avoid low-memory condition
   45.66 -        extra_mb = (2.4/1024) * (mem_kb/1024.0) + 12;
   45.67 +        extra_mb = (2.4/1024) * (mem_kb/1024.0) + 4;
   45.68          extra_pages = int( math.ceil( extra_mb*1024 / page_kb ))
   45.69          return mem_kb + extra_pages * page_kb
   45.70  
   45.71 -    def getRequiredShadowMemory(self, mem_kb):
   45.72 +    def getRequiredShadowMemory(self, shadow_mem_kb, maxmem_kb):
   45.73 +        # The given value is the configured value -- we need to include the
   45.74 +        # overhead due to getRequiredInitialReservation.
   45.75 +        maxmem_kb = self.getRequiredInitialReservation(maxmem_kb)
   45.76 +
   45.77          # 1MB per vcpu plus 4Kib/Mib of RAM.  This is higher than 
   45.78          # the minimum that Xen would allocate if no value were given.
   45.79 -        return 1024 * self.vm.getVCpuCount() + mem_kb / 256
   45.80 +        return max(1024 * self.vm.getVCpuCount() + maxmem_kb / 256,
   45.81 +                   shadow_mem_kb)
   45.82 +
   45.83  
   45.84  _handlers = {
   45.85      "powerpc": {
    46.1 --- a/tools/python/xen/xend/server/DevController.py	Mon Sep 18 09:23:51 2006 -0400
    46.2 +++ b/tools/python/xen/xend/server/DevController.py	Mon Sep 18 14:28:16 2006 -0500
    46.3 @@ -207,6 +207,9 @@ class DevController:
    46.4  
    46.5          devid = int(devid)
    46.6  
    46.7 +        # Modify online status /before/ updating state (latter is watched by
    46.8 +        # drivers, so this ordering avoids a race).
    46.9 +        self.writeBackend(devid, 'online', "0")
   46.10          self.writeBackend(devid, 'state', str(xenbusState['Closing']))
   46.11  
   46.12  
   46.13 @@ -406,7 +409,8 @@ class DevController:
   46.14              'domain' : self.vm.getName(),
   46.15              'frontend' : frontpath,
   46.16              'frontend-id' : "%i" % self.vm.getDomid(),
   46.17 -            'state' : str(xenbusState['Initialising'])
   46.18 +            'state' : str(xenbusState['Initialising']),
   46.19 +            'online' : "1"
   46.20              })
   46.21  
   46.22          return (backpath, frontpath)
    47.1 --- a/tools/python/xen/xend/server/blkif.py	Mon Sep 18 09:23:51 2006 -0400
    47.2 +++ b/tools/python/xen/xend/server/blkif.py	Mon Sep 18 14:28:16 2006 -0500
    47.3 @@ -64,10 +64,14 @@ class BlkifController(DevController):
    47.4              except ValueError:
    47.5                  (typ, params) = ("", "")
    47.6  
    47.7 +        mode = sxp.child_value(config, 'mode', 'r')
    47.8 +        if mode not in ('r', 'w', 'w!'):
    47.9 +            raise VmError('Invalid mode')
   47.10 +
   47.11          back = { 'dev'    : dev,
   47.12                   'type'   : typ,
   47.13                   'params' : params,
   47.14 -                 'mode'   : sxp.child_value(config, 'mode', 'r')
   47.15 +                 'mode'   : mode
   47.16                 }
   47.17  
   47.18          if security.on():
    48.1 --- a/tools/python/xen/xend/server/pciquirk.py	Mon Sep 18 09:23:51 2006 -0400
    48.2 +++ b/tools/python/xen/xend/server/pciquirk.py	Mon Sep 18 14:28:16 2006 -0500
    48.3 @@ -1,5 +1,5 @@
    48.4  from xen.xend.XendLogging import log
    48.5 -from xen.xend.XendError import XendError
    48.6 +from xen.xend.XendError import XendError, VmError
    48.7  import sys
    48.8  import os.path
    48.9  from xen.xend.sxp import *
    49.1 --- a/tools/python/xen/xm/addlabel.py	Mon Sep 18 09:23:51 2006 -0400
    49.2 +++ b/tools/python/xen/xm/addlabel.py	Mon Sep 18 14:28:16 2006 -0500
    49.3 @@ -20,8 +20,6 @@
    49.4  """Labeling a domain configuration file or a resoruce.
    49.5  """
    49.6  import sys, os
    49.7 -import string
    49.8 -import traceback
    49.9  from xen.util import dictio
   49.10  from xen.util import security
   49.11  
   49.12 @@ -33,6 +31,7 @@ def usage():
   49.13      print "  resource. It derives the policy from the running hypervisor"
   49.14      print "  if it is not given (optional parameter). If a label already"
   49.15      print "  exists for the given domain or resource, then addlabel fails.\n"
   49.16 +    security.err("Usage")
   49.17  
   49.18  
   49.19  def validate_config_file(configfile):
   49.20 @@ -134,7 +133,6 @@ def main (argv):
   49.21                  for prefix in [".", "/etc/xen"]:
   49.22                      configfile = prefix + "/" + configfile
   49.23                      if os.path.isfile(configfile):
   49.24 -                        fd = open(configfile, "rb")
   49.25                          break
   49.26              if not validate_config_file(configfile):
   49.27                  usage()
   49.28 @@ -147,7 +145,7 @@ def main (argv):
   49.29              usage()
   49.30  
   49.31      except security.ACMError:
   49.32 -        traceback.print_exc(limit=1)
   49.33 +        sys.exit(-1)
   49.34  
   49.35  
   49.36  if __name__ == '__main__':
    50.1 --- a/tools/python/xen/xm/cfgbootpolicy.py	Mon Sep 18 09:23:51 2006 -0400
    50.2 +++ b/tools/python/xen/xm/cfgbootpolicy.py	Mon Sep 18 14:28:16 2006 -0500
    50.3 @@ -70,7 +70,7 @@ def determine_kernelversion(user_specifi
    50.4                  within_xen_title = 0
    50.5                  within_xen_entry = 0
    50.6      if len(version_list) > 1:
    50.7 -        err("Cannot decide between entries for kernels: " + version_list)
    50.8 +        err("Cannot decide between entries for kernels %s" % version_list)
    50.9      elif len(version_list) == 0:
   50.10          err("Cannot find a boot entry candidate (please create a Xen boot entry first).")
   50.11      else:
   50.12 @@ -87,7 +87,6 @@ def insert_policy(boot_file, kernel_vers
   50.13      within_xen_entry = 0
   50.14      insert_at_end_of_entry = 0
   50.15      path_prefix = ''
   50.16 -    done = False
   50.17      (tmp_fd, tmp_grub) = tempfile.mkstemp()
   50.18      #follow symlink since menue.lst might be linked to grub.conf
   50.19      if stat.S_ISLNK(os.lstat(boot_file)[stat.ST_MODE]):
   50.20 @@ -175,9 +174,10 @@ def main(argv):
   50.21          print "Boot entry created and \'%s\' copied to /boot" % (policy + ".bin")
   50.22  
   50.23      except ACMError:
   50.24 -        pass
   50.25 +        sys.exit(-1)
   50.26      except:
   50.27          traceback.print_exc(limit=1)
   50.28 +        sys.exit(-1)
   50.29  
   50.30  
   50.31  
    51.1 --- a/tools/python/xen/xm/create.py	Mon Sep 18 09:23:51 2006 -0400
    51.2 +++ b/tools/python/xen/xm/create.py	Mon Sep 18 14:28:16 2006 -0500
    51.3 @@ -1155,7 +1155,7 @@ def create_security_check(config):
    51.4          else:
    51.5              print "Checking resources: (skipped)"
    51.6      except security.ACMError:
    51.7 -        traceback.print_exc(limit=1)
    51.8 +        sys.exit(-1)
    51.9  
   51.10      return passed
   51.11  
   51.12 @@ -1169,11 +1169,14 @@ def main(argv):
   51.13      if not opts:
   51.14          return
   51.15  
   51.16 +    if type(config) == str:
   51.17 +            config = sxp.parse(file(config))[0]
   51.18 +
   51.19      if opts.vals.dryrun:
   51.20          PrettyPrint.prettyprint(config)
   51.21      else:
   51.22          if not create_security_check(config):
   51.23 -            print "Security configuration prevents domain from starting"
   51.24 +            err("Security configuration prevents domain from starting.")
   51.25          else:
   51.26              dom = make_domain(opts, config)
   51.27              if opts.vals.console_autoconnect:
    52.1 --- a/tools/python/xen/xm/dry-run.py	Mon Sep 18 09:23:51 2006 -0400
    52.2 +++ b/tools/python/xen/xm/dry-run.py	Mon Sep 18 14:28:16 2006 -0500
    52.3 @@ -18,6 +18,7 @@
    52.4  
    52.5  """Tests the security settings for a domain and its resources.
    52.6  """
    52.7 +import sys
    52.8  from xen.util import security
    52.9  from xen.xm import create
   52.10  from xen.xend import sxp
   52.11 @@ -28,14 +29,14 @@ def usage():
   52.12      print "to see if the domain created by the configfile can access"
   52.13      print "the resources.  The status of each resource is listed"
   52.14      print "individually along with the final security decision.\n"
   52.15 +    security.err("Usage")
   52.16  
   52.17  
   52.18  def main (argv):
   52.19 -    if len(argv) != 2:
   52.20 -        usage()
   52.21 -        return
   52.22 +    try:
   52.23 +        if len(argv) != 2:
   52.24 +            usage()
   52.25  
   52.26 -    try:
   52.27          passed = 0
   52.28          (opts, config) = create.parseCommandLine(argv)
   52.29          if create.check_domain_label(config, verbose=1):
   52.30 @@ -48,8 +49,10 @@ def main (argv):
   52.31              print "Dry Run: PASSED"
   52.32          else:
   52.33              print "Dry Run: FAILED"
   52.34 +            sys.exit(-1)
   52.35 +
   52.36      except security.ACMError:
   52.37 -        pass
   52.38 +        sys.exit(-1)
   52.39  
   52.40  
   52.41  if __name__ == '__main__':
    53.1 --- a/tools/python/xen/xm/dumppolicy.py	Mon Sep 18 09:23:51 2006 -0400
    53.2 +++ b/tools/python/xen/xm/dumppolicy.py	Mon Sep 18 14:28:16 2006 -0500
    53.3 @@ -18,7 +18,6 @@
    53.4  """Display currently enforced policy (low-level hypervisor representation).
    53.5  """
    53.6  import sys
    53.7 -import traceback
    53.8  from xen.util.security import ACMError, err, dump_policy
    53.9  
   53.10  
   53.11 @@ -31,12 +30,13 @@ def usage():
   53.12  
   53.13  def main(argv):
   53.14      try:
   53.15 +        if len(argv) != 1:
   53.16 +            usage()
   53.17 +
   53.18          dump_policy()
   53.19  
   53.20      except ACMError:
   53.21 -        pass
   53.22 -    except:
   53.23 -        traceback.print_exc(limit=1)
   53.24 +        sys.exit(-1)
   53.25  
   53.26  
   53.27  if __name__ == '__main__':
    54.1 --- a/tools/python/xen/xm/getlabel.py	Mon Sep 18 09:23:51 2006 -0400
    54.2 +++ b/tools/python/xen/xm/getlabel.py	Mon Sep 18 14:28:16 2006 -0500
    54.3 @@ -19,8 +19,6 @@
    54.4  """Show the label for a domain or resoruce.
    54.5  """
    54.6  import sys, os, re
    54.7 -import string
    54.8 -import traceback
    54.9  from xen.util import dictio
   54.10  from xen.util import security
   54.11  
   54.12 @@ -28,6 +26,7 @@ def usage():
   54.13      print "\nUsage: xm getlabel dom <configfile>"
   54.14      print "       xm getlabel res <resource>\n"
   54.15      print "  This program shows the label for a domain or resource.\n"
   54.16 +    security.err("Usage")
   54.17  
   54.18  
   54.19  def get_resource_label(resource):
   54.20 @@ -38,8 +37,7 @@ def get_resource_label(resource):
   54.21      try:
   54.22          access_control = dictio.dict_read("resources", file)
   54.23      except:
   54.24 -        print "Resource label file not found"
   54.25 -        return
   54.26 +        security.err("Resource label file not found")
   54.27  
   54.28      # get the entry and print label
   54.29      if access_control.has_key(resource):
   54.30 @@ -47,7 +45,7 @@ def get_resource_label(resource):
   54.31          label = access_control[resource][1]
   54.32          print "policy="+policy+",label="+label
   54.33      else:
   54.34 -        print "Resource not labeled"
   54.35 +        security.err("Resource not labeled")
   54.36  
   54.37  
   54.38  def get_domain_label(configfile):
   54.39 @@ -63,8 +61,7 @@ def get_domain_label(configfile):
   54.40                  fd = open(file, "rb")
   54.41                  break
   54.42      if not fd:
   54.43 -        print "Configuration file '"+configfile+"' not found."
   54.44 -        return
   54.45 +        security.err("Configuration file '"+configfile+"' not found.")
   54.46  
   54.47      # read in the domain config file, finding the label line
   54.48      ac_entry_re = re.compile("^access_control\s*=.*", re.IGNORECASE)
   54.49 @@ -82,8 +79,7 @@ def get_domain_label(configfile):
   54.50  
   54.51      # send error message if we didn't find anything
   54.52      if acline == "":
   54.53 -        print "Label does not exist in domain configuration file."
   54.54 -        return
   54.55 +        security.err("Domain not labeled")
   54.56  
   54.57      # print out the label
   54.58      (title, data) = acline.split("=", 1)
   54.59 @@ -94,19 +90,21 @@ def get_domain_label(configfile):
   54.60  
   54.61  
   54.62  def main (argv):
   54.63 -    if len(argv) != 3:
   54.64 -        usage()
   54.65 -        return
   54.66 +    try:
   54.67 +        if len(argv) != 3:
   54.68 +            usage()
   54.69  
   54.70 -    if argv[1].lower() == "dom":
   54.71 -        configfile = argv[2]
   54.72 -        get_domain_label(configfile)
   54.73 -    elif argv[1].lower() == "res":
   54.74 -        resource = argv[2]
   54.75 -        get_resource_label(resource)
   54.76 -    else:
   54.77 -        usage()
   54.78 +        if argv[1].lower() == "dom":
   54.79 +            configfile = argv[2]
   54.80 +            get_domain_label(configfile)
   54.81 +        elif argv[1].lower() == "res":
   54.82 +            resource = argv[2]
   54.83 +            get_resource_label(resource)
   54.84 +        else:
   54.85 +            usage()
   54.86  
   54.87 +    except security.ACMError:
   54.88 +        sys.exit(-1)
   54.89  
   54.90  if __name__ == '__main__':
   54.91      main(sys.argv)
    55.1 --- a/tools/python/xen/xm/labels.py	Mon Sep 18 09:23:51 2006 -0400
    55.2 +++ b/tools/python/xen/xm/labels.py	Mon Sep 18 14:28:16 2006 -0500
    55.3 @@ -70,10 +70,12 @@ def main(argv):
    55.4          labels.sort()
    55.5          for label in labels:
    55.6              print label
    55.7 +
    55.8      except ACMError:
    55.9 -        pass
   55.10 +        sys.exit(-1)
   55.11      except:
   55.12          traceback.print_exc(limit=1)
   55.13 +        sys.exit(-1)
   55.14  
   55.15  
   55.16  if __name__ == '__main__':
    56.1 --- a/tools/python/xen/xm/loadpolicy.py	Mon Sep 18 09:23:51 2006 -0400
    56.2 +++ b/tools/python/xen/xm/loadpolicy.py	Mon Sep 18 14:28:16 2006 -0500
    56.3 @@ -34,11 +34,12 @@ def main(argv):
    56.4          if len(argv) != 2:
    56.5              usage()
    56.6          load_policy(argv[1])
    56.7 +
    56.8      except ACMError:
    56.9 -        pass
   56.10 +        sys.exit(-1)
   56.11      except:
   56.12          traceback.print_exc(limit=1)
   56.13 -
   56.14 +        sys.exit(-1)
   56.15  
   56.16  
   56.17  if __name__ == '__main__':
    57.1 --- a/tools/python/xen/xm/makepolicy.py	Mon Sep 18 09:23:51 2006 -0400
    57.2 +++ b/tools/python/xen/xm/makepolicy.py	Mon Sep 18 14:28:16 2006 -0500
    57.3 @@ -37,9 +37,10 @@ def main(argv):
    57.4          make_policy(argv[1])
    57.5  
    57.6      except ACMError:
    57.7 -        pass
    57.8 +        sys.exit(-1)
    57.9      except:
   57.10          traceback.print_exc(limit=1)
   57.11 +        sys.exit(-1)
   57.12  
   57.13  
   57.14  
    58.1 --- a/tools/python/xen/xm/resources.py	Mon Sep 18 09:23:51 2006 -0400
    58.2 +++ b/tools/python/xen/xm/resources.py	Mon Sep 18 14:28:16 2006 -0500
    58.3 @@ -18,8 +18,7 @@
    58.4  
    58.5  """List the resource label information from the global resource label file
    58.6  """
    58.7 -import sys, os
    58.8 -import string
    58.9 +import sys
   58.10  from xen.util import dictio
   58.11  from xen.util import security
   58.12  
   58.13 @@ -27,6 +26,7 @@ def usage():
   58.14      print "\nUsage: xm resource\n"
   58.15      print "  This program lists information for each resource in the"
   58.16      print "  global resource label file\n"
   58.17 +    security.err("Usage")
   58.18  
   58.19  
   58.20  def print_resource_data(access_control):
   58.21 @@ -41,14 +41,19 @@ def print_resource_data(access_control):
   58.22  
   58.23  def main (argv):
   58.24      try:
   58.25 -        file = security.res_label_filename
   58.26 -        access_control = dictio.dict_read("resources", file)
   58.27 -    except:
   58.28 -        print "Resource file not found."
   58.29 -        return
   58.30 +        if len(argv) != 1:
   58.31 +            usage()
   58.32  
   58.33 -    print_resource_data(access_control)
   58.34 +        try:
   58.35 +            file = security.res_label_filename
   58.36 +            access_control = dictio.dict_read("resources", file)
   58.37 +        except:
   58.38 +            security.err("Error reading resource file.")
   58.39  
   58.40 +        print_resource_data(access_control)
   58.41 +
   58.42 +    except security.ACMError:
   58.43 +        sys.exit(-1)
   58.44  
   58.45  if __name__ == '__main__':
   58.46      main(sys.argv)
    59.1 --- a/tools/python/xen/xm/rmlabel.py	Mon Sep 18 09:23:51 2006 -0400
    59.2 +++ b/tools/python/xen/xm/rmlabel.py	Mon Sep 18 14:28:16 2006 -0500
    59.3 @@ -19,8 +19,6 @@
    59.4  """Remove a label from a domain configuration file or a resoruce.
    59.5  """
    59.6  import sys, os, re
    59.7 -import string
    59.8 -import traceback
    59.9  from xen.util import dictio
   59.10  from xen.util import security
   59.11  
   59.12 @@ -31,6 +29,7 @@ def usage():
   59.13      print "  for a domain or from the global resource label file for a"
   59.14      print "  resource. If the label does not exist for the given domain or"
   59.15      print "  resource, then rmlabel fails.\n"
   59.16 +    security.err("Usage")
   59.17  
   59.18  
   59.19  def rm_resource_label(resource):
   59.20 @@ -48,7 +47,7 @@ def rm_resource_label(resource):
   59.21          del access_control[resource]
   59.22          dictio.dict_write(access_control, "resources", file)
   59.23      else:
   59.24 -        security.err("Label does not exist in resource label file.")
   59.25 +        security.err("Resource not labeled.")
   59.26  
   59.27  
   59.28  def rm_domain_label(configfile):
   59.29 @@ -85,7 +84,7 @@ def rm_domain_label(configfile):
   59.30  
   59.31      # send error message if we didn't find anything to remove
   59.32      if not removed:
   59.33 -        security.err("Label does not exist in domain configuration file.")
   59.34 +        security.err("Domain not labeled.")
   59.35  
   59.36      # write the data back out to the file
   59.37      fd = open(file, "wb")
   59.38 @@ -97,7 +96,6 @@ def main (argv):
   59.39      try:
   59.40          if len(argv) != 3:
   59.41              usage()
   59.42 -            return
   59.43  
   59.44          if argv[1].lower() == "dom":
   59.45              configfile = argv[2]
   59.46 @@ -109,7 +107,7 @@ def main (argv):
   59.47              usage()
   59.48  
   59.49      except security.ACMError:
   59.50 -        traceback.print_exc(limit=1)
   59.51 +        sys.exit(-1)
   59.52  
   59.53  
   59.54  if __name__ == '__main__':
    60.1 --- a/tools/python/xen/xm/sysrq.py	Mon Sep 18 09:23:51 2006 -0400
    60.2 +++ b/tools/python/xen/xm/sysrq.py	Mon Sep 18 14:28:16 2006 -0500
    60.3 @@ -24,8 +24,9 @@ def main(argv):
    60.4          return
    60.5          
    60.6      # no options for the moment
    60.7 -    if len(args) < 1: opts.err('Missing domain')
    60.8 -    if len(args) < 2: opts.err('Missing sysrq character')
    60.9 +    if len(args) != 2:
   60.10 +        opts.usage()
   60.11 +        sys.exit(1)
   60.12      dom = args[0]
   60.13      req = ord(args[1][0])
   60.14      server.xend.domain.send_sysrq(dom, req)
    61.1 --- a/tools/python/xen/xm/tests/test_create.py	Mon Sep 18 09:23:51 2006 -0400
    61.2 +++ b/tools/python/xen/xm/tests/test_create.py	Mon Sep 18 14:28:16 2006 -0500
    61.3 @@ -51,6 +51,7 @@ class test_create(unittest.TestCase):
    61.4                   'path'      : '.:/etc/xen',
    61.5                   'builder'   : 'linux',
    61.6                   'nics'      : -1,
    61.7 +                 'vncunused' : 1,
    61.8                   'xauthority': xen.xm.create.get_xauthority(),
    61.9                   })
   61.10  
   61.11 @@ -101,6 +102,7 @@ on_crash    = 'destroy'
   61.12                   'path'        : '.:/etc/xen',
   61.13                   'builder'     : 'linux',
   61.14  
   61.15 +                 'vncunused'   : 1,
   61.16                   'xauthority'  : xen.xm.create.get_xauthority(),
   61.17                 })
   61.18  
   61.19 @@ -140,6 +142,7 @@ cpu_weight = 0.75
   61.20                   'builder'    : 'linux',
   61.21                   'nics'       : -1,
   61.22  
   61.23 +                 'vncunused'   : 1,
   61.24                   'xauthority' : xen.xm.create.get_xauthority(),
   61.25                   })
   61.26              
   61.27 @@ -182,6 +185,7 @@ ne2000=0
   61.28                                     xen.xm.create.VNC_BASE_PORT +
   61.29                                     xen.xm.create.choose_vnc_display())),
   61.30                   'vnc'         : 1,
   61.31 +                 'vncunused'   : 1,
   61.32                   'vncviewer'   : 1,
   61.33  
   61.34                   'xm_file'     : fname,
    62.1 --- a/tools/xenmon/xenmon.py	Mon Sep 18 09:23:51 2006 -0400
    62.2 +++ b/tools/xenmon/xenmon.py	Mon Sep 18 14:28:16 2006 -0500
    62.3 @@ -672,6 +672,9 @@ def main():
    62.4  
    62.5      parser = setup_cmdline_parser()
    62.6      (options, args) = parser.parse_args()
    62.7 +    if options.mspersample < 0:
    62.8 +        parser.error("option --ms_per_sample: invalid negative value: '%d'" %
    62.9 +                     options.mspersample)
   62.10      
   62.11      start_xenbaked()
   62.12      if options.live:
    63.1 --- a/unmodified_drivers/linux-2.6/mkbuildtree	Mon Sep 18 09:23:51 2006 -0400
    63.2 +++ b/unmodified_drivers/linux-2.6/mkbuildtree	Mon Sep 18 14:28:16 2006 -0500
    63.3 @@ -42,6 +42,12 @@ i[34567]86)
    63.4  	ln -sf ${XL}/include/asm-i386/mach-xen/asm/synch_bitops.h include/asm
    63.5  	ln -sf ${XL}/include/asm-i386/mach-xen/asm/maddr.h include/asm
    63.6  	;;
    63.7 +"ia64")
    63.8 +	ln -sf ${XL}/include/asm-ia64/hypervisor.h include/asm
    63.9 +	ln -sf ${XL}/include/asm-ia64/hypercall.h include/asm
   63.10 +	ln -sf ${XL}/include/asm-ia64/synch_bitops.h include/asm
   63.11 +	ln -sf ${XL}/include/asm-ia64/maddr.h include/asm
   63.12 +	;;
   63.13  *)
   63.14  	echo unknown architecture $uname
   63.15  	exit 1
    64.1 --- a/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Mon Sep 18 09:23:51 2006 -0400
    64.2 +++ b/unmodified_drivers/linux-2.6/platform-pci/platform-pci.c	Mon Sep 18 14:28:16 2006 -0500
    64.3 @@ -17,6 +17,7 @@
    64.4   * Place - Suite 330, Boston, MA 02111-1307 USA.
    64.5   *
    64.6   */
    64.7 +
    64.8  #include <linux/module.h>
    64.9  #include <linux/kernel.h>
   64.10  #include <linux/sched.h>
   64.11 @@ -25,6 +26,8 @@
   64.12  #include <linux/init.h>
   64.13  #include <linux/version.h>
   64.14  #include <linux/interrupt.h>
   64.15 +#include <linux/vmalloc.h>
   64.16 +#include <linux/mm.h>
   64.17  #include <asm/system.h>
   64.18  #include <asm/io.h>
   64.19  #include <asm/irq.h>
   64.20 @@ -47,7 +50,6 @@ MODULE_AUTHOR("ssmith@xensource.com");
   64.21  MODULE_DESCRIPTION("Xen platform PCI device");
   64.22  MODULE_LICENSE("GPL");
   64.23  
   64.24 -
   64.25  unsigned long *phys_to_machine_mapping;
   64.26  EXPORT_SYMBOL(phys_to_machine_mapping);
   64.27  
   64.28 @@ -115,10 +117,11 @@ unsigned long alloc_xen_mmio(unsigned lo
   64.29  	return addr;
   64.30  }
   64.31  
   64.32 +#ifndef __ia64__
   64.33  /* Lifted from hvmloader.c */
   64.34  static int get_hypercall_stubs(void)
   64.35  {
   64.36 -	uint32_t eax, ebx, ecx, edx, pages, msr, order, i;
   64.37 +	uint32_t eax, ebx, ecx, edx, pages, msr, i;
   64.38  	char signature[13];
   64.39  
   64.40  	cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
   64.41 @@ -141,25 +144,28 @@ static int get_hypercall_stubs(void)
   64.42  
   64.43  	cpuid(0x40000002, &pages, &msr, &ecx, &edx);
   64.44  
   64.45 -	i = pages - 1;
   64.46 -	for (order = 0; i != 0; order++)
   64.47 -		i >>= 1;
   64.48 +	printk(KERN_INFO "Hypercall area is %u pages.\n", pages);
   64.49  
   64.50 -	printk(KERN_INFO "Hypercall area is %u pages (order %u allocation)\n",
   64.51 -	       pages, order);
   64.52 -
   64.53 -	hypercall_stubs = (void *)__get_free_pages(GFP_KERNEL, order);
   64.54 +	/* Use __vmalloc() because vmalloc_exec() is not an exported symbol. */
   64.55 +	/* PAGE_KERNEL_EXEC also is not exported, hence we use PAGE_KERNEL. */
   64.56 +	/* hypercall_stubs = vmalloc_exec(pages * PAGE_SIZE); */
   64.57 +	hypercall_stubs = __vmalloc(pages * PAGE_SIZE,
   64.58 +				    GFP_KERNEL | __GFP_HIGHMEM,
   64.59 +				    __pgprot(__PAGE_KERNEL & ~_PAGE_NX));
   64.60  	if (hypercall_stubs == NULL)
   64.61  		return -ENOMEM;
   64.62  
   64.63 -	for (i = 0; i < pages; i++)
   64.64 -		wrmsrl(ebx,
   64.65 -		       virt_to_phys(hypercall_stubs) +	/* base address      */
   64.66 -		       (i << PAGE_SHIFT) +		/* offset of page @i */
   64.67 -		       i);				/* request page @i   */
   64.68 +	for (i = 0; i < pages; i++) {
   64.69 +		unsigned long pfn;
   64.70 +		pfn = vmalloc_to_pfn((char *)hypercall_stubs + i*PAGE_SIZE);
   64.71 +		wrmsrl(msr, ((u64)pfn << PAGE_SHIFT) + i);
   64.72 +	}
   64.73  
   64.74  	return 0;
   64.75  }
   64.76 +#else /* __ia64__ */
   64.77 +#define get_hypercall_stubs()	(0)
   64.78 +#endif
   64.79  
   64.80  static int __devinit platform_pci_init(struct pci_dev *pdev,
   64.81  				       const struct pci_device_id *ent)
   64.82 @@ -205,7 +211,6 @@ static int __devinit platform_pci_init(s
   64.83  	if (ret < 0)
   64.84  		goto out;
   64.85  
   64.86 -	
   64.87  	if ((ret = init_xen_info()))
   64.88  		goto out;
   64.89  
    65.1 --- a/xen/Makefile	Mon Sep 18 09:23:51 2006 -0400
    65.2 +++ b/xen/Makefile	Mon Sep 18 14:28:16 2006 -0500
    65.3 @@ -90,10 +90,9 @@ include/xen/acm_policy.h:
    65.4  	  echo "#endif") >$@
    65.5  
    65.6  # compile.h contains dynamic build info. Rebuilt on every 'make' invocation.
    65.7 -include/xen/compile.h: LANG=C
    65.8  include/xen/compile.h: include/xen/compile.h.in
    65.9 -	@sed -e 's/@@date@@/$(shell date)/g' \
   65.10 -	    -e 's/@@time@@/$(shell date +%T)/g' \
   65.11 +	@sed -e 's/@@date@@/$(shell LC_ALL=C date)/g' \
   65.12 +	    -e 's/@@time@@/$(shell LC_ALL=C date +%T)/g' \
   65.13  	    -e 's/@@whoami@@/$(shell whoami)/g' \
   65.14  	    -e 's/@@domain@@/$(shell ([ -x /bin/dnsdomainname ] && /bin/dnsdomainname) || ([ -x /bin/domainname ] && /bin/domainname || echo [unknown]))/g' \
   65.15  	    -e 's/@@hostname@@/$(shell hostname)/g' \
    66.1 --- a/xen/arch/ia64/vmx/mmio.c	Mon Sep 18 09:23:51 2006 -0400
    66.2 +++ b/xen/arch/ia64/vmx/mmio.c	Mon Sep 18 14:28:16 2006 -0500
    66.3 @@ -213,6 +213,7 @@ static void mmio_access(VCPU *vcpu, u64 
    66.4      iot=__gpfn_is_io(vcpu->domain, src_pa>>PAGE_SHIFT);
    66.5      v_plat = vmx_vcpu_get_plat(vcpu);
    66.6  
    66.7 +    perfc_incra(vmx_mmio_access, iot >> 56);
    66.8      switch (iot) {
    66.9      case GPFN_PIB:
   66.10          if(!dir)
    67.1 --- a/xen/arch/ia64/vmx/pal_emul.c	Mon Sep 18 09:23:51 2006 -0400
    67.2 +++ b/xen/arch/ia64/vmx/pal_emul.c	Mon Sep 18 14:28:16 2006 -0500
    67.3 @@ -389,6 +389,7 @@ pal_emul(VCPU *vcpu) {
    67.4  
    67.5  	vcpu_get_gr_nat(vcpu,28,&gr28);  //bank1
    67.6  
    67.7 +	perfc_incrc(vmx_pal_emul);
    67.8  	switch (gr28) {
    67.9  		case PAL_CACHE_FLUSH:
   67.10  			result = pal_cache_flush(vcpu);
    68.1 --- a/xen/arch/ia64/vmx/vmx_interrupt.c	Mon Sep 18 09:23:51 2006 -0400
    68.2 +++ b/xen/arch/ia64/vmx/vmx_interrupt.c	Mon Sep 18 14:28:16 2006 -0500
    68.3 @@ -92,6 +92,7 @@ inject_guest_interruption(VCPU *vcpu, u6
    68.4      u64 viva;
    68.5      REGS *regs;
    68.6      ISR pt_isr;
    68.7 +    perfc_incra(vmx_inject_guest_interruption, vec >> 8);
    68.8      regs=vcpu_regs(vcpu);
    68.9      // clear cr.isr.ri 
   68.10      pt_isr.val = VMX(vcpu,cr_isr);
    69.1 --- a/xen/arch/ia64/vmx/vmx_phy_mode.c	Mon Sep 18 09:23:51 2006 -0400
    69.2 +++ b/xen/arch/ia64/vmx/vmx_phy_mode.c	Mon Sep 18 14:28:16 2006 -0500
    69.3 @@ -262,6 +262,7 @@ switch_mm_mode(VCPU *vcpu, IA64_PSR old_
    69.4      int act;
    69.5      REGS * regs=vcpu_regs(vcpu);
    69.6      act = mm_switch_action(old_psr, new_psr);
    69.7 +    perfc_incra(vmx_switch_mm_mode, act);
    69.8      switch (act) {
    69.9      case SW_V2P:
   69.10  //        printf("V -> P mode transition: (0x%lx -> 0x%lx)\n",
    70.1 --- a/xen/arch/ia64/vmx/vmx_process.c	Mon Sep 18 09:23:51 2006 -0400
    70.2 +++ b/xen/arch/ia64/vmx/vmx_process.c	Mon Sep 18 14:28:16 2006 -0500
    70.3 @@ -115,6 +115,7 @@ vmx_ia64_handle_break (unsigned long ifa
    70.4      struct domain *d = current->domain;
    70.5      struct vcpu *v = current;
    70.6  
    70.7 +    perfc_incrc(vmx_ia64_handle_break);
    70.8  #ifdef CRASH_DEBUG
    70.9      if ((iim == 0 || iim == CDB_BREAK_NUM) && !user_mode(regs) &&
   70.10          IS_VMM_ADDRESS(regs->cr_iip)) {
    71.1 --- a/xen/arch/ia64/vmx/vmx_virt.c	Mon Sep 18 09:23:51 2006 -0400
    71.2 +++ b/xen/arch/ia64/vmx/vmx_virt.c	Mon Sep 18 14:28:16 2006 -0500
    71.3 @@ -1398,120 +1398,159 @@ if ( (cause == 0xff && opcode == 0x1e000
    71.4  
    71.5      switch(cause) {
    71.6      case EVENT_RSM:
    71.7 +        perfc_incrc(vmx_rsm);
    71.8          status=vmx_emul_rsm(vcpu, inst);
    71.9          break;
   71.10      case EVENT_SSM:
   71.11 +        perfc_incrc(vmx_ssm);
   71.12          status=vmx_emul_ssm(vcpu, inst);
   71.13          break;
   71.14      case EVENT_MOV_TO_PSR:
   71.15 +        perfc_incrc(vmx_mov_to_psr);
   71.16          status=vmx_emul_mov_to_psr(vcpu, inst);
   71.17          break;
   71.18      case EVENT_MOV_FROM_PSR:
   71.19 +        perfc_incrc(vmx_mov_from_psr);
   71.20          status=vmx_emul_mov_from_psr(vcpu, inst);
   71.21          break;
   71.22      case EVENT_MOV_FROM_CR:
   71.23 +        perfc_incrc(vmx_mov_from_cr);
   71.24          status=vmx_emul_mov_from_cr(vcpu, inst);
   71.25          break;
   71.26      case EVENT_MOV_TO_CR:
   71.27 +        perfc_incrc(vmx_mov_to_cr);
   71.28          status=vmx_emul_mov_to_cr(vcpu, inst);
   71.29          break;
   71.30      case EVENT_BSW_0:
   71.31 +        perfc_incrc(vmx_bsw0);
   71.32          status=vmx_emul_bsw0(vcpu, inst);
   71.33          break;
   71.34      case EVENT_BSW_1:
   71.35 +        perfc_incrc(vmx_bsw1);
   71.36          status=vmx_emul_bsw1(vcpu, inst);
   71.37          break;
   71.38      case EVENT_COVER:
   71.39 +        perfc_incrc(vmx_cover);
   71.40          status=vmx_emul_cover(vcpu, inst);
   71.41          break;
   71.42      case EVENT_RFI:
   71.43 +        perfc_incrc(vmx_rfi);
   71.44          status=vmx_emul_rfi(vcpu, inst);
   71.45          break;
   71.46      case EVENT_ITR_D:
   71.47 +        perfc_incrc(vmx_itr_d);
   71.48          status=vmx_emul_itr_d(vcpu, inst);
   71.49          break;
   71.50      case EVENT_ITR_I:
   71.51 +        perfc_incrc(vmx_itr_i);
   71.52          status=vmx_emul_itr_i(vcpu, inst);
   71.53          break;
   71.54      case EVENT_PTR_D:
   71.55 +        perfc_incrc(vmx_ptr_d);
   71.56          status=vmx_emul_ptr_d(vcpu, inst);
   71.57          break;
   71.58      case EVENT_PTR_I:
   71.59 +        perfc_incrc(vmx_ptr_i);
   71.60          status=vmx_emul_ptr_i(vcpu, inst);
   71.61          break;
   71.62      case EVENT_ITC_D:
   71.63 +        perfc_incrc(vmx_itc_d);
   71.64          status=vmx_emul_itc_d(vcpu, inst);
   71.65          break;
   71.66      case EVENT_ITC_I:
   71.67 +        perfc_incrc(vmx_itc_i);
   71.68          status=vmx_emul_itc_i(vcpu, inst);
   71.69          break;
   71.70      case EVENT_PTC_L:
   71.71 +        perfc_incrc(vmx_ptc_l);
   71.72          status=vmx_emul_ptc_l(vcpu, inst);
   71.73          break;
   71.74      case EVENT_PTC_G:
   71.75 +        perfc_incrc(vmx_ptc_g);
   71.76          status=vmx_emul_ptc_g(vcpu, inst);
   71.77          break;
   71.78      case EVENT_PTC_GA:
   71.79 +        perfc_incrc(vmx_ptc_ga);
   71.80          status=vmx_emul_ptc_ga(vcpu, inst);
   71.81          break;
   71.82      case EVENT_PTC_E:
   71.83 +        perfc_incrc(vmx_ptc_e);
   71.84          status=vmx_emul_ptc_e(vcpu, inst);
   71.85          break;
   71.86      case EVENT_MOV_TO_RR:
   71.87 +        perfc_incrc(vmx_mov_to_rr);
   71.88          status=vmx_emul_mov_to_rr(vcpu, inst);
   71.89          break;
   71.90      case EVENT_MOV_FROM_RR:
   71.91 +        perfc_incrc(vmx_mov_from_rr);
   71.92          status=vmx_emul_mov_from_rr(vcpu, inst);
   71.93          break;
   71.94      case EVENT_THASH:
   71.95 +        perfc_incrc(vmx_thash);
   71.96          status=vmx_emul_thash(vcpu, inst);
   71.97          break;
   71.98      case EVENT_TTAG:
   71.99 +        perfc_incrc(vmx_ttag);
  71.100          status=vmx_emul_ttag(vcpu, inst);
  71.101          break;
  71.102      case EVENT_TPA:
  71.103 +        perfc_incrc(vmx_tpa);
  71.104          status=vmx_emul_tpa(vcpu, inst);
  71.105          break;
  71.106      case EVENT_TAK:
  71.107 +        perfc_incrc(vmx_tak);
  71.108          status=vmx_emul_tak(vcpu, inst);
  71.109          break;
  71.110      case EVENT_MOV_TO_AR_IMM:
  71.111 +        perfc_incrc(vmx_mov_to_ar_imm);
  71.112          status=vmx_emul_mov_to_ar_imm(vcpu, inst);
  71.113          break;
  71.114      case EVENT_MOV_TO_AR:
  71.115 +        perfc_incrc(vmx_mov_to_ar_reg);
  71.116          status=vmx_emul_mov_to_ar_reg(vcpu, inst);
  71.117          break;
  71.118      case EVENT_MOV_FROM_AR:
  71.119 +        perfc_incrc(vmx_mov_from_ar_reg);
  71.120          status=vmx_emul_mov_from_ar_reg(vcpu, inst);
  71.121          break;
  71.122      case EVENT_MOV_TO_DBR:
  71.123 +        perfc_incrc(vmx_mov_to_dbr);
  71.124          status=vmx_emul_mov_to_dbr(vcpu, inst);
  71.125          break;
  71.126      case EVENT_MOV_TO_IBR:
  71.127 +        perfc_incrc(vmx_mov_to_ibr);
  71.128          status=vmx_emul_mov_to_ibr(vcpu, inst);
  71.129          break;
  71.130      case EVENT_MOV_TO_PMC:
  71.131 +        perfc_incrc(vmx_mov_to_pmc);
  71.132          status=vmx_emul_mov_to_pmc(vcpu, inst);
  71.133          break;
  71.134      case EVENT_MOV_TO_PMD:
  71.135 +        perfc_incrc(vmx_mov_to_pmd);
  71.136          status=vmx_emul_mov_to_pmd(vcpu, inst);
  71.137          break;
  71.138      case EVENT_MOV_TO_PKR:
  71.139 +        perfc_incrc(vmx_mov_to_pkr);
  71.140          status=vmx_emul_mov_to_pkr(vcpu, inst);
  71.141          break;
  71.142      case EVENT_MOV_FROM_DBR:
  71.143 +        perfc_incrc(vmx_mov_from_dbr);
  71.144          status=vmx_emul_mov_from_dbr(vcpu, inst);
  71.145          break;
  71.146      case EVENT_MOV_FROM_IBR:
  71.147 +        perfc_incrc(vmx_mov_from_ibr);
  71.148          status=vmx_emul_mov_from_ibr(vcpu, inst);
  71.149          break;
  71.150      case EVENT_MOV_FROM_PMC:
  71.151 +        perfc_incrc(vmx_mov_from_pmc);
  71.152          status=vmx_emul_mov_from_pmc(vcpu, inst);
  71.153          break;
  71.154      case EVENT_MOV_FROM_PKR:
  71.155 +        perfc_incrc(vmx_mov_from_pkr);
  71.156          status=vmx_emul_mov_from_pkr(vcpu, inst);
  71.157          break;
  71.158      case EVENT_MOV_FROM_CPUID:
  71.159 +        perfc_incrc(vmx_mov_from_cpuid);
  71.160          status=vmx_emul_mov_from_cpuid(vcpu, inst);
  71.161          break;
  71.162      case EVENT_VMSW:
    72.1 --- a/xen/arch/ia64/xen/dom_fw.c	Mon Sep 18 09:23:51 2006 -0400
    72.2 +++ b/xen/arch/ia64/xen/dom_fw.c	Mon Sep 18 14:28:16 2006 -0500
    72.3 @@ -816,9 +816,12 @@ dom_fw_init(struct domain *d,
    72.4  	                       FW_HYPERCALL_SAL_RETURN, 0, hypercalls_imva);
    72.5  
    72.6  	/* Fill in the FPSWA interface: */
    72.7 -	tables->fpswa_inf.revision = fpswa_interface->revision;
    72.8 -	dom_fpswa_hypercall_patch(d, hypercalls_imva);
    72.9 -	tables->fpswa_inf.fpswa = (void *)FW_HYPERCALL_FPSWA_ENTRY_PADDR;
   72.10 +	if (fpswa_interface) {
   72.11 +		tables->fpswa_inf.revision = fpswa_interface->revision;
   72.12 +		dom_fpswa_hypercall_patch(d, hypercalls_imva);
   72.13 +		tables->fpswa_inf.fpswa = 
   72.14 +		                       (void *)FW_HYPERCALL_FPSWA_ENTRY_PADDR;
   72.15 +	}
   72.16  
   72.17  	i = 0; /* Used by MAKE_MD */
   72.18  
   72.19 @@ -867,7 +870,8 @@ dom_fw_init(struct domain *d,
   72.20  	bp->console_info.num_rows = 25;
   72.21  	bp->console_info.orig_x = 0;
   72.22  	bp->console_info.orig_y = 24;
   72.23 -	bp->fpswa = FW_FIELD_MPA(fpswa_inf);
   72.24 +	if (fpswa_interface)
   72.25 +		bp->fpswa = FW_FIELD_MPA(fpswa_inf);
   72.26  }
   72.27  
   72.28  void dom_fw_setup(struct domain *d, unsigned long bp_mpa, unsigned long maxmem)
    73.1 --- a/xen/arch/ia64/xen/domain.c	Mon Sep 18 09:23:51 2006 -0400
    73.2 +++ b/xen/arch/ia64/xen/domain.c	Mon Sep 18 14:28:16 2006 -0500
    73.3 @@ -54,6 +54,7 @@ unsigned long dom0_align = 64*1024*1024;
    73.4  static unsigned int dom0_max_vcpus = 1;
    73.5  integer_param("dom0_max_vcpus", dom0_max_vcpus); 
    73.6  
    73.7 +extern int opt_dom0_vcpus_pin;
    73.8  extern unsigned long running_on_sim;
    73.9  
   73.10  extern char dom0_command_line[];
   73.11 @@ -1020,9 +1021,12 @@ int construct_dom0(struct domain *d,
   73.12  	    dom0_max_vcpus = MAX_VIRT_CPUS;
   73.13  	
   73.14  	printf ("Dom0 max_vcpus=%d\n", dom0_max_vcpus);
   73.15 -	for ( i = 1; i < dom0_max_vcpus; i++ )
   73.16 +	for ( i = 1; i < dom0_max_vcpus; i++ ) {
   73.17  	    if (alloc_vcpu(d, i, i) == NULL)
   73.18  		printf ("Cannot allocate dom0 vcpu %d\n", i);
   73.19 +	    else if (opt_dom0_vcpus_pin)
   73.20 +		d->vcpu[i]->cpu_affinity = cpumask_of_cpu(i);
   73.21 +	}
   73.22  
   73.23  	/* Copy the OS image. */
   73.24  	loaddomainelfimage(d,image_start);
    74.1 --- a/xen/arch/ia64/xen/fw_emul.c	Mon Sep 18 09:23:51 2006 -0400
    74.2 +++ b/xen/arch/ia64/xen/fw_emul.c	Mon Sep 18 14:28:16 2006 -0500
    74.3 @@ -395,28 +395,124 @@ efi_emulate_get_time(
    74.4  	unsigned long tv_addr, unsigned long tc_addr,
    74.5  	IA64FAULT *fault)
    74.6  {
    74.7 -	unsigned long tv = 0, tc = 0;
    74.8 +	unsigned long tv, tc = 0;
    74.9  	struct page_info *tv_page = NULL;
   74.10  	struct page_info *tc_page = NULL;
   74.11 -	efi_status_t status;
   74.12 +	efi_status_t status = 0;
   74.13  
   74.14  	//printf("efi_get_time(%016lx,%016lx) called\n", tv_addr, tc_addr);
   74.15  	tv = efi_translate_domain_addr(tv_addr, fault, &tv_page);
   74.16  	if (*fault != IA64_NO_FAULT)
   74.17 -		return 0;
   74.18 +		goto errout;
   74.19  	if (tc_addr) {
   74.20  		tc = efi_translate_domain_addr(tc_addr, fault, &tc_page);
   74.21 -		if (*fault != IA64_NO_FAULT) {
   74.22 -			put_page(tv_page);
   74.23 -			return 0;
   74.24 -		}
   74.25 +		if (*fault != IA64_NO_FAULT)
   74.26 +			goto errout;
   74.27  	}
   74.28 +
   74.29  	//printf("efi_get_time(%016lx,%016lx) translated to xen virtual address\n", tv, tc);
   74.30  	status = (*efi.get_time)((efi_time_t *) tv, (efi_time_cap_t *) tc);
   74.31  	//printf("efi_get_time returns %lx\n", status);
   74.32 +
   74.33 +errout:
   74.34  	if (tc_page != NULL)
   74.35  		put_page(tc_page);
   74.36 -	put_page(tv_page);
   74.37 +	if (tv_page != NULL)
   74.38 +		put_page(tv_page);
   74.39 +
   74.40 +	return status;
   74.41 +}
   74.42 +
   74.43 +static efi_status_t
   74.44 +efi_emulate_set_time(
   74.45 +	unsigned long tv_addr, IA64FAULT *fault)
   74.46 +{
   74.47 +	unsigned long tv;
   74.48 +	struct page_info *tv_page = NULL;
   74.49 +	efi_status_t status = 0;
   74.50 +
   74.51 +	if (current->domain != dom0)
   74.52 +		return EFI_UNSUPPORTED;
   74.53 +
   74.54 +	tv = efi_translate_domain_addr(tv_addr, fault, &tv_page);
   74.55 +	if (*fault != IA64_NO_FAULT)
   74.56 +		goto errout;
   74.57 +
   74.58 +	status = (*efi.set_time)((efi_time_t *)tv);
   74.59 +
   74.60 +errout:
   74.61 +	if (tv_page != NULL)
   74.62 +		put_page(tv_page);
   74.63 +
   74.64 +	return status;
   74.65 +}
   74.66 +
   74.67 +static efi_status_t
   74.68 +efi_emulate_get_wakeup_time(
   74.69 +	unsigned long e_addr, unsigned long p_addr,
   74.70 +	unsigned long tv_addr, IA64FAULT *fault)
   74.71 +{
   74.72 +	unsigned long enabled, pending, tv;
   74.73 +	struct page_info *e_page = NULL, *p_page = NULL,
   74.74 +	                 *tv_page = NULL;
   74.75 +	efi_status_t status = 0;
   74.76 +
   74.77 +	if (current->domain != dom0)
   74.78 +		return EFI_UNSUPPORTED;
   74.79 +
   74.80 +	if (!e_addr || !p_addr || !tv_addr)
   74.81 +		return EFI_INVALID_PARAMETER;
   74.82 +
   74.83 +	enabled = efi_translate_domain_addr(e_addr, fault, &e_page);
   74.84 +	if (*fault != IA64_NO_FAULT)
   74.85 +		goto errout;
   74.86 +	pending = efi_translate_domain_addr(p_addr, fault, &p_page);
   74.87 +	if (*fault != IA64_NO_FAULT)
   74.88 +		goto errout;
   74.89 +	tv = efi_translate_domain_addr(tv_addr, fault, &tv_page);
   74.90 +	if (*fault != IA64_NO_FAULT)
   74.91 +		goto errout;
   74.92 +
   74.93 +	status = (*efi.get_wakeup_time)((efi_bool_t *)enabled,
   74.94 +	                                (efi_bool_t *)pending,
   74.95 +	                                (efi_time_t *)tv);
   74.96 +
   74.97 +errout:
   74.98 +	if (e_page != NULL)
   74.99 +		put_page(e_page);
  74.100 +	if (p_page != NULL)
  74.101 +		put_page(p_page);
  74.102 +	if (tv_page != NULL)
  74.103 +		put_page(tv_page);
  74.104 +
  74.105 +	return status;
  74.106 +}
  74.107 +
  74.108 +static efi_status_t
  74.109 +efi_emulate_set_wakeup_time(
  74.110 +	unsigned long enabled, unsigned long tv_addr,
  74.111 +	IA64FAULT *fault)
  74.112 +{
  74.113 +	unsigned long tv = 0;
  74.114 +	struct page_info *tv_page = NULL;
  74.115 +	efi_status_t status = 0;
  74.116 +
  74.117 +	if (current->domain != dom0)
  74.118 +		return EFI_UNSUPPORTED;
  74.119 +
  74.120 +	if (tv_addr) {
  74.121 +		tv = efi_translate_domain_addr(tv_addr, fault, &tv_page);
  74.122 +		if (*fault != IA64_NO_FAULT)
  74.123 +			goto errout;
  74.124 +	}
  74.125 +
  74.126 +	status = (*efi.set_wakeup_time)((efi_bool_t)enabled,
  74.127 +	                                (efi_time_t *)tv);
  74.128 +
  74.129 +errout:
  74.130 +	if (tv_page != NULL)
  74.131 +		put_page(tv_page);
  74.132 +
  74.133  	return status;
  74.134  }
  74.135  
  74.136 @@ -663,6 +759,24 @@ efi_emulator (struct pt_regs *regs, IA64
  74.137  				vcpu_get_gr(v,33),
  74.138  				fault);
  74.139  		break;
  74.140 +	    case FW_HYPERCALL_EFI_SET_TIME:
  74.141 +		status = efi_emulate_set_time (
  74.142 +				vcpu_get_gr(v,32),
  74.143 +				fault);
  74.144 +		break;
  74.145 +	    case FW_HYPERCALL_EFI_GET_WAKEUP_TIME:
  74.146 +		status = efi_emulate_get_wakeup_time (
  74.147 +				vcpu_get_gr(v,32),
  74.148 +				vcpu_get_gr(v,33),
  74.149 +				vcpu_get_gr(v,34),
  74.150 +				fault);
  74.151 +		break;
  74.152 +	    case FW_HYPERCALL_EFI_SET_WAKEUP_TIME:
  74.153 +		status = efi_emulate_set_wakeup_time (
  74.154 +				vcpu_get_gr(v,32),
  74.155 +				vcpu_get_gr(v,33),
  74.156 +				fault);
  74.157 +		break;
  74.158  	    case FW_HYPERCALL_EFI_GET_VARIABLE:
  74.159  		status = efi_emulate_get_variable (
  74.160  				vcpu_get_gr(v,32),
  74.161 @@ -695,10 +809,6 @@ efi_emulator (struct pt_regs *regs, IA64
  74.162   				(u32) vcpu_get_gr(v,34),
  74.163  				(efi_memory_desc_t *) vcpu_get_gr(v,35));
  74.164  		break;
  74.165 -	    case FW_HYPERCALL_EFI_SET_TIME:
  74.166 -	    case FW_HYPERCALL_EFI_GET_WAKEUP_TIME:
  74.167 -	    case FW_HYPERCALL_EFI_SET_WAKEUP_TIME:
  74.168 -		// FIXME: need fixes in efi.h from 2.6.9
  74.169  	    case FW_HYPERCALL_EFI_GET_NEXT_HIGH_MONO_COUNT:
  74.170  		// FIXME: need fixes in efi.h from 2.6.9
  74.171  		status = EFI_UNSUPPORTED;
    75.1 --- a/xen/arch/ia64/xen/hypercall.c	Mon Sep 18 09:23:51 2006 -0400
    75.2 +++ b/xen/arch/ia64/xen/hypercall.c	Mon Sep 18 14:28:16 2006 -0500
    75.3 @@ -211,6 +211,7 @@ fw_hypercall (struct pt_regs *regs)
    75.4  	IA64FAULT fault; 
    75.5  	unsigned long index = regs->r2 & FW_HYPERCALL_NUM_MASK_HIGH;
    75.6  
    75.7 +	perfc_incra(fw_hypercall, index >> 8);
    75.8  	switch (index) {
    75.9  	    case FW_HYPERCALL_PAL_CALL:
   75.10  		//printf("*** PAL hypercall: index=%d\n",regs->r28);
    76.1 --- a/xen/arch/ia64/xen/mm.c	Mon Sep 18 09:23:51 2006 -0400
    76.2 +++ b/xen/arch/ia64/xen/mm.c	Mon Sep 18 14:28:16 2006 -0500
    76.3 @@ -173,6 +173,9 @@
    76.4  #include <asm/vcpu.h>
    76.5  #include <asm/shadow.h>
    76.6  #include <linux/efi.h>
    76.7 +#include <xen/guest_access.h>
    76.8 +#include <asm/page.h>
    76.9 +#include <public/memory.h>
   76.10  
   76.11  static void domain_page_flush(struct domain* d, unsigned long mpaddr,
   76.12                                unsigned long old_mfn, unsigned long new_mfn);
   76.13 @@ -1752,6 +1755,83 @@ int memory_is_conventional_ram(paddr_t p
   76.14      return (efi_mem_type(p) == EFI_CONVENTIONAL_MEMORY);
   76.15  }
   76.16  
   76.17 +
   76.18 +long
   76.19 +arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg)
   76.20 +{
   76.21 +    switch (op) {
   76.22 +    case XENMEM_add_to_physmap:
   76.23 +    {
   76.24 +        struct xen_add_to_physmap xatp;
   76.25 +        unsigned long prev_mfn, mfn = 0, gpfn;
   76.26 +        struct domain *d;
   76.27 +
   76.28 +        if (copy_from_guest(&xatp, arg, 1))
   76.29 +            return -EFAULT;
   76.30 +
   76.31 +        if (xatp.domid == DOMID_SELF) {
   76.32 +            d = current->domain;
   76.33 +            get_knownalive_domain(d);
   76.34 +        }
   76.35 +        else if (!IS_PRIV(current->domain))
   76.36 +            return -EPERM;
   76.37 +        else if ((d = find_domain_by_id(xatp.domid)) == NULL)
   76.38 +            return -ESRCH;
   76.39 +
   76.40 +        /* This hypercall is used for VT-i domain only */
   76.41 +        if (!VMX_DOMAIN(d->vcpu[0])) {
   76.42 +            put_domain(d);
   76.43 +            return -ENOSYS;
   76.44 +        }
   76.45 +
   76.46 +        switch (xatp.space) {
   76.47 +        case XENMAPSPACE_shared_info:
   76.48 +            if (xatp.idx == 0)
   76.49 +                mfn = virt_to_mfn(d->shared_info);
   76.50 +            break;
   76.51 +        case XENMAPSPACE_grant_table:
   76.52 +            if (xatp.idx < NR_GRANT_FRAMES)
   76.53 +                mfn = virt_to_mfn(d->grant_table->shared) + xatp.idx;
   76.54 +            break;
   76.55 +        default:
   76.56 +            break;
   76.57 +        }
   76.58 +
   76.59 +        LOCK_BIGLOCK(d);
   76.60 +
   76.61 +        /* Remove previously mapped page if it was present. */
   76.62 +        prev_mfn = gmfn_to_mfn(d, xatp.gpfn);
   76.63 +        if (prev_mfn && mfn_valid(prev_mfn)) {
   76.64 +            if (IS_XEN_HEAP_FRAME(mfn_to_page(prev_mfn)))
   76.65 +                /* Xen heap frames are simply unhooked from this phys slot. */
   76.66 +                guest_physmap_remove_page(d, xatp.gpfn, prev_mfn);
   76.67 +            else
   76.68 +                /* Normal domain memory is freed, to avoid leaking memory. */
   76.69 +                guest_remove_page(d, xatp.gpfn);
   76.70 +        }
   76.71 +
   76.72 +        /* Unmap from old location, if any. */
   76.73 +        gpfn = get_gpfn_from_mfn(mfn);
   76.74 +        if (gpfn != INVALID_M2P_ENTRY)
   76.75 +            guest_physmap_remove_page(d, gpfn, mfn);
   76.76 +
   76.77 +        /* Map at new location. */
   76.78 +        guest_physmap_add_page(d, xatp.gpfn, mfn);
   76.79 +
   76.80 +        UNLOCK_BIGLOCK(d);
   76.81 +        
   76.82 +        put_domain(d);
   76.83 +
   76.84 +        break;
   76.85 +    }
   76.86 +
   76.87 +    default:
   76.88 +        return -ENOSYS;
   76.89 +    }
   76.90 +
   76.91 +    return 0;
   76.92 +}
   76.93 +
   76.94  /*
   76.95   * Local variables:
   76.96   * mode: C
    77.1 --- a/xen/arch/ia64/xen/vhpt.c	Mon Sep 18 09:23:51 2006 -0400
    77.2 +++ b/xen/arch/ia64/xen/vhpt.c	Mon Sep 18 14:28:16 2006 -0500
    77.3 @@ -14,6 +14,7 @@
    77.4  #include <asm/page.h>
    77.5  #include <asm/vhpt.h>
    77.6  #include <asm/vcpu.h>
    77.7 +#include <asm/vmmu.h>
    77.8  
    77.9  /* Defined in tlb.c  */
   77.10  extern void ia64_global_tlb_purge(UINT64 start, UINT64 end, UINT64 nbits);
   77.11 @@ -131,15 +132,25 @@ void vhpt_init(void)
   77.12  
   77.13  void vcpu_flush_vtlb_all(struct vcpu *v)
   77.14  {
   77.15 -	/* First VCPU tlb.  */
   77.16 -	vcpu_purge_tr_entry(&PSCBX(v,dtlb));
   77.17 -	vcpu_purge_tr_entry(&PSCBX(v,itlb));
   77.18 +	if (VMX_DOMAIN(v)) {
   77.19 +		/* This code may be call for remapping shared_info and
   77.20 +		   grant_table share page from guest_physmap_remove_page()
   77.21 +		   in arch_memory_op() XENMEM_add_to_physmap to realize
   77.22 +		   PV-on-HVM feature. */
   77.23 +		/* Purge vTLB for VT-i domain */
   77.24 +		thash_purge_all(v);
   77.25 +	}
   77.26 +	else {
   77.27 +		/* First VCPU tlb.  */
   77.28 +		vcpu_purge_tr_entry(&PSCBX(v,dtlb));
   77.29 +		vcpu_purge_tr_entry(&PSCBX(v,itlb));
   77.30  
   77.31 -	/* Then VHPT.  */
   77.32 -	vhpt_flush ();
   77.33 +		/* Then VHPT.  */
   77.34 +		vhpt_flush();
   77.35  
   77.36 -	/* Then mTLB.  */
   77.37 -	local_flush_tlb_all ();
   77.38 +		/* Then mTLB.  */
   77.39 +		local_flush_tlb_all();
   77.40 +	}
   77.41  
   77.42  	/* We could clear bit in d->domain_dirty_cpumask only if domain d in
   77.43  	   not running on this processor.  There is currently no easy way to
    78.1 --- a/xen/arch/ia64/xen/xensetup.c	Mon Sep 18 09:23:51 2006 -0400
    78.2 +++ b/xen/arch/ia64/xen/xensetup.c	Mon Sep 18 14:28:16 2006 -0500
    78.3 @@ -49,6 +49,10 @@ extern void mem_init(void);
    78.4  extern void init_IRQ(void);
    78.5  extern void trap_init(void);
    78.6  
    78.7 +/* opt_dom0_vcpus_pin: If true, dom0 VCPUs are pinned. */
    78.8 +unsigned int opt_dom0_vcpus_pin = 0;
    78.9 +boolean_param("dom0_vcpus_pin", opt_dom0_vcpus_pin);
   78.10 +
   78.11  /* opt_nosmp: If true, secondary processors are ignored. */
   78.12  static int opt_nosmp = 0;
   78.13  boolean_param("nosmp", opt_nosmp);
   78.14 @@ -517,6 +521,10 @@ printk("num_online_cpus=%d, max_cpus=%d\
   78.15    			0) != 0)
   78.16          panic("Could not set up DOM0 guest OS\n");
   78.17  
   78.18 +    /* PIN domain0 VCPU 0 on CPU 0. */
   78.19 +    if (opt_dom0_vcpus_pin)
   78.20 +        dom0->vcpu[0]->cpu_affinity = cpumask_of_cpu(0);
   78.21 +
   78.22      if (!running_on_sim)  // slow on ski and pages are pre-initialized to zero
   78.23  	scrub_heap_pages();
   78.24  
    79.1 --- a/xen/arch/x86/Rules.mk	Mon Sep 18 09:23:51 2006 -0400
    79.2 +++ b/xen/arch/x86/Rules.mk	Mon Sep 18 14:28:16 2006 -0500
    79.3 @@ -42,6 +42,9 @@ endif
    79.4  ifeq ($(TARGET_SUBARCH),x86_64)
    79.5  CFLAGS  += -mno-red-zone -fpic -fno-reorder-blocks
    79.6  CFLAGS  += -fno-asynchronous-unwind-tables
    79.7 +# -fvisibility=hidden reduces -fpic cost, if it's available
    79.8 +CFLAGS  += $(shell $(CC) -v --help 2>&1 | grep " -fvisibility=" | \
    79.9 +             grep -q hidden && echo "-fvisibility=hidden")
   79.10  LDFLAGS += -m elf_x86_64
   79.11  x86_32 := n
   79.12  x86_64 := y
    80.1 --- a/xen/arch/x86/hvm/io.c	Mon Sep 18 09:23:51 2006 -0400
    80.2 +++ b/xen/arch/x86/hvm/io.c	Mon Sep 18 14:28:16 2006 -0500
    80.3 @@ -646,9 +646,13 @@ static void hvm_mmio_assist(struct cpu_u
    80.4          break;
    80.5  
    80.6      case INSTR_BT:
    80.7 -        index = operand_index(src);
    80.8 -        value = get_reg_value(size, index, 0, regs);
    80.9 -
   80.10 +        if ( src & REGISTER )
   80.11 +        {
   80.12 +            index = operand_index(src);
   80.13 +            value = get_reg_value(size, index, 0, regs);
   80.14 +        }
   80.15 +        else if ( src & IMMEDIATE )
   80.16 +            value = mmio_opp->immediate;
   80.17          if (p->u.data & (1 << (value & ((1 << 5) - 1))))
   80.18              regs->eflags |= X86_EFLAGS_CF;
   80.19          else
    81.1 --- a/xen/arch/x86/hvm/platform.c	Mon Sep 18 09:23:51 2006 -0400
    81.2 +++ b/xen/arch/x86/hvm/platform.c	Mon Sep 18 14:28:16 2006 -0500
    81.3 @@ -652,6 +652,23 @@ static int hvm_decode(int realmode, unsi
    81.4          instr->operand[1] = mk_operand(instr->op_size, 0, 0, MEMORY);
    81.5          return DECODE_success;
    81.6  
    81.7 +    case 0xBA:
    81.8 +        if (((opcode[1] >> 3) & 7) == 4) /* BT $imm8, m16/32/64 */
    81.9 +        {
   81.10 +            instr->instr = INSTR_BT;
   81.11 +            GET_OP_SIZE_FOR_NONEBYTE(instr->op_size);
   81.12 +            instr->immediate =
   81.13 +                    (signed char)get_immediate(realmode, opcode+1, BYTE);
   81.14 +            instr->operand[0] = mk_operand(BYTE, 0, 0, IMMEDIATE);
   81.15 +            instr->operand[1] = mk_operand(instr->op_size, 0, 0, MEMORY);
   81.16 +            return DECODE_success;
   81.17 +        }
   81.18 +        else
   81.19 +        {
   81.20 +            printf("0f %x, This opcode subtype isn't handled yet\n", *opcode);
   81.21 +            return DECODE_failure;
   81.22 +        }
   81.23 +
   81.24      default:
   81.25          printf("0f %x, This opcode isn't handled yet\n", *opcode);
   81.26          return DECODE_failure;
   81.27 @@ -1002,10 +1019,17 @@ void handle_mmio(unsigned long va, unsig
   81.28              mmio_opp->operand[0] = mmio_inst.operand[0]; /* bit offset */
   81.29              mmio_opp->operand[1] = mmio_inst.operand[1]; /* bit base */
   81.30  
   81.31 -            index = operand_index(mmio_inst.operand[0]);
   81.32 -            size = operand_size(mmio_inst.operand[0]);
   81.33 -            value = get_reg_value(size, index, 0, regs);
   81.34 -
   81.35 +            if ( mmio_inst.operand[0] & REGISTER )
   81.36 +            { 
   81.37 +                index = operand_index(mmio_inst.operand[0]);
   81.38 +                size = operand_size(mmio_inst.operand[0]);
   81.39 +                value = get_reg_value(size, index, 0, regs);
   81.40 +            }
   81.41 +            else if ( mmio_inst.operand[0] & IMMEDIATE )
   81.42 +            {
   81.43 +                mmio_opp->immediate = mmio_inst.immediate;
   81.44 +                value = mmio_inst.immediate;
   81.45 +            } 
   81.46              send_mmio_req(IOREQ_TYPE_COPY, gpa + (value >> 5), 1,
   81.47                            mmio_inst.op_size, 0, IOREQ_READ, 0);
   81.48              break;
    82.1 --- a/xen/arch/x86/hvm/svm/intr.c	Mon Sep 18 09:23:51 2006 -0400
    82.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Mon Sep 18 14:28:16 2006 -0500
    82.3 @@ -79,22 +79,22 @@ asmlinkage void svm_intr_assist(void)
    82.4      ASSERT(vmcb);
    82.5  
    82.6      /* Check if an Injection is active */
    82.7 -       /* Previous Interrupt delivery caused this Intercept? */
    82.8 -       if (vmcb->exitintinfo.fields.v && (vmcb->exitintinfo.fields.type == 0)) {
    82.9 -           v->arch.hvm_svm.saved_irq_vector = vmcb->exitintinfo.fields.vector;
   82.10 +    /* Previous Interrupt delivery caused this Intercept? */
   82.11 +    if (vmcb->exitintinfo.fields.v && (vmcb->exitintinfo.fields.type == 0)) {
   82.12 +        v->arch.hvm_svm.saved_irq_vector = vmcb->exitintinfo.fields.vector;
   82.13  //           printk("Injecting PF#: saving IRQ from ExitInfo\n");
   82.14 -           vmcb->exitintinfo.bytes = 0;
   82.15 -           re_injecting = 1;
   82.16 -       }
   82.17 +        vmcb->exitintinfo.bytes = 0;
   82.18 +        re_injecting = 1;
   82.19 +    }
   82.20  
   82.21      /* Guest's interrputs masked? */
   82.22      rflags = vmcb->rflags;
   82.23      if (irq_masked(rflags)) {
   82.24          HVM_DBG_LOG(DBG_LEVEL_1, "Guest IRQs masked: rflags: %lx", rflags);
   82.25 -       /* bail out, we won't be injecting an interrupt this time */
   82.26 -       return;
   82.27 +        /* bail out, we won't be injecting an interrupt this time */
   82.28 +        return;
   82.29      }
   82.30 -  
   82.31 +    
   82.32      /* Previous interrupt still pending? */
   82.33      if (vmcb->vintr.fields.irq) {
   82.34  //        printk("Re-injecting IRQ from Vintr\n");
   82.35 @@ -115,27 +115,24 @@ asmlinkage void svm_intr_assist(void)
   82.36        if ( v->vcpu_id == 0 )
   82.37           hvm_pic_assist(v);
   82.38  
   82.39 -      callback_irq = v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   82.40  
   82.41 -      /* Before we deal with PIT interrupts, let's check for
   82.42 -         interrupts set by the device model or paravirtualised event
   82.43 -         channel interrupts.
   82.44 -      */
   82.45 -      if ( cpu_has_pending_irq(v) ) {
   82.46 -           intr_vector = cpu_get_interrupt(v, &intr_type);
   82.47 +      if ( (v->vcpu_id == 0) && pt->enabled && pt->pending_intr_nr ) {
   82.48 +          pic_set_irq(pic, pt->irq, 0);
   82.49 +          pic_set_irq(pic, pt->irq, 1);
   82.50        }
   82.51 -      else  if ( callback_irq != 0 && local_events_need_delivery() ) {
   82.52 +
   82.53 +      callback_irq = v->domain->arch.hvm_domain.params[HVM_PARAM_CALLBACK_IRQ];
   82.54 +      if ( callback_irq != 0 &&
   82.55 +           local_events_need_delivery() ) {
   82.56            /*inject para-device call back irq*/
   82.57            v->vcpu_info->evtchn_upcall_mask = 1;
   82.58            pic_set_irq(pic, callback_irq, 0);
   82.59            pic_set_irq(pic, callback_irq, 1);
   82.60 -          intr_vector = callback_irq;
   82.61        }
   82.62 -      else  if ( (v->vcpu_id == 0) && pt->enabled && pt->pending_intr_nr ) {
   82.63 -          pic_set_irq(pic, pt->irq, 0);
   82.64 -          pic_set_irq(pic, pt->irq, 1);
   82.65 +
   82.66 +      if ( cpu_has_pending_irq(v) )
   82.67            intr_vector = cpu_get_interrupt(v, &intr_type);
   82.68 -      }
   82.69 +
   82.70      }
   82.71  
   82.72      /* have we got an interrupt to inject? */
    83.1 --- a/xen/arch/x86/hvm/svm/svm.c	Mon Sep 18 09:23:51 2006 -0400
    83.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Mon Sep 18 14:28:16 2006 -0500
    83.3 @@ -243,6 +243,7 @@ static void svm_store_cpu_guest_regs(
    83.4      {
    83.5          /* Returning the guest's regs */
    83.6          crs[0] = v->arch.hvm_svm.cpu_shadow_cr0;
    83.7 +        crs[2] = v->arch.hvm_svm.cpu_cr2;
    83.8          crs[3] = v->arch.hvm_svm.cpu_cr3;
    83.9          crs[4] = v->arch.hvm_svm.cpu_shadow_cr4;
   83.10      }
   83.11 @@ -2793,10 +2794,8 @@ asmlinkage void svm_vmexit_handler(struc
   83.12          break;
   83.13  
   83.14      case VMEXIT_INTR:
   83.15 -        raise_softirq(SCHEDULE_SOFTIRQ);
   83.16          break;
   83.17  
   83.18 -
   83.19      case VMEXIT_INVD:
   83.20          svm_vmexit_do_invd(vmcb);
   83.21          break;
    84.1 --- a/xen/arch/x86/hvm/vioapic.c	Mon Sep 18 09:23:51 2006 -0400
    84.2 +++ b/xen/arch/x86/hvm/vioapic.c	Mon Sep 18 14:28:16 2006 -0500
    84.3 @@ -362,21 +362,35 @@ static uint32_t ioapic_get_delivery_bitm
    84.4  
    84.5      ASSERT(s);
    84.6  
    84.7 -    if (dest_mode == 0) { /* Physical mode */
    84.8 -        for (i = 0; i < s->lapic_count; i++) {
    84.9 -            if (VLAPIC_ID(s->lapic_info[i]) == dest) {
   84.10 +    if ( dest_mode == 0 )
   84.11 +    {
   84.12 +        /* Physical mode. */
   84.13 +        for ( i = 0; i < s->lapic_count; i++ )
   84.14 +        {
   84.15 +            if ( VLAPIC_ID(s->lapic_info[i]) == dest )
   84.16 +            {
   84.17                  mask = 1 << i;
   84.18                  break;
   84.19              }
   84.20          }
   84.21 -    } else {
   84.22 -        /* logical destination. call match_logical_addr for each APIC. */
   84.23 -        if (dest != 0) {
   84.24 -            for (i=0; i< s->lapic_count; i++) {
   84.25 +
   84.26 +        /* Broadcast. */
   84.27 +        if ( dest == 0xFF )
   84.28 +        {
   84.29 +            for ( i = 0; i < s->lapic_count; i++ )
   84.30 +                mask |= ( 1 << i );
   84.31 +        }
   84.32 +    }
   84.33 +    else
   84.34 +    {
   84.35 +        /* Logical destination. Call match_logical_addr for each APIC. */
   84.36 +        if ( dest != 0 )
   84.37 +        {
   84.38 +            for ( i = 0; i < s->lapic_count; i++ )
   84.39 +            {
   84.40                  if ( s->lapic_info[i] &&
   84.41 -                     ioapic_match_logical_addr(s, i, dest) ) {
   84.42 +                     ioapic_match_logical_addr(s, i, dest) )
   84.43                      mask |= (1<<i);
   84.44 -                }
   84.45              }
   84.46          }
   84.47      }
    85.1 --- a/xen/arch/x86/hvm/vlapic.c	Mon Sep 18 09:23:51 2006 -0400
    85.2 +++ b/xen/arch/x86/hvm/vlapic.c	Mon Sep 18 14:28:16 2006 -0500
    85.3 @@ -66,12 +66,10 @@ int vlapic_find_highest_irr(struct vlapi
    85.4  {
    85.5      int result;
    85.6  
    85.7 -     result = find_highest_bit((unsigned long *)(vlapic->regs + APIC_IRR),
    85.8 -                               MAX_VECTOR);
    85.9 +    result = vlapic_find_highest_vector(vlapic->regs + APIC_IRR);
   85.10 +    ASSERT((result == -1) || (result >= 16));
   85.11  
   85.12 -     ASSERT( result == -1 || result >= 16);
   85.13 -
   85.14 -     return result;
   85.15 +    return result;
   85.16  }
   85.17  
   85.18  s_time_t get_apictime_scheduled(struct vcpu *v)
   85.19 @@ -89,10 +87,8 @@ int vlapic_find_highest_isr(struct vlapi
   85.20  {
   85.21      int result;
   85.22  
   85.23 -    result = find_highest_bit((unsigned long *)(vlapic->regs + APIC_ISR),
   85.24 -                               MAX_VECTOR);
   85.25 -
   85.26 -    ASSERT( result == -1 || result >= 16);
   85.27 +    result = vlapic_find_highest_vector(vlapic->regs + APIC_ISR);
   85.28 +    ASSERT((result == -1) || (result >= 16));
   85.29  
   85.30      return result;
   85.31  }
   85.32 @@ -221,7 +217,8 @@ static int vlapic_accept_irq(struct vcpu
   85.33          if ( unlikely(vlapic == NULL || !vlapic_enabled(vlapic)) )
   85.34              break;
   85.35  
   85.36 -        if ( test_and_set_bit(vector, vlapic->regs + APIC_IRR) && trig_mode)
   85.37 +        if ( vlapic_test_and_set_vector(vector, vlapic->regs + APIC_IRR) &&
   85.38 +             trig_mode)
   85.39          {
   85.40              HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
   85.41                    "level trig mode repeatedly for vector %d\n", vector);
   85.42 @@ -232,7 +229,7 @@ static int vlapic_accept_irq(struct vcpu
   85.43          {
   85.44              HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
   85.45                "level trig mode for vector %d\n", vector);
   85.46 -            set_bit(vector, vlapic->regs + APIC_TMR);
   85.47 +            vlapic_set_vector(vector, vlapic->regs + APIC_TMR);
   85.48          }
   85.49          hvm_prod_vcpu(v);
   85.50  
   85.51 @@ -358,10 +355,10 @@ void vlapic_EOI_set(struct vlapic *vlapi
   85.52      if ( vector == -1 )
   85.53          return ;
   85.54  
   85.55 -    clear_bit(vector, vlapic->regs + APIC_ISR);
   85.56 +    vlapic_clear_vector(vector, vlapic->regs + APIC_ISR);
   85.57      vlapic_update_ppr(vlapic);
   85.58  
   85.59 -    if ( test_and_clear_bit(vector, vlapic->regs + APIC_TMR) )
   85.60 +    if ( vlapic_test_and_clear_vector(vector, vlapic->regs + APIC_TMR) )
   85.61          ioapic_update_EOI(vlapic->domain, vector);
   85.62  }
   85.63  
   85.64 @@ -816,7 +813,7 @@ void vlapic_timer_fn(void *data)
   85.65  
   85.66      vlapic->timer_last_update = now;
   85.67  
   85.68 -    if ( test_and_set_bit(timer_vector, vlapic->regs + APIC_IRR ))
   85.69 +    if ( vlapic_test_and_set_vector(timer_vector, vlapic->regs + APIC_IRR) )
   85.70          vlapic->intr_pending_count[timer_vector]++;
   85.71  
   85.72      if ( vlapic_lvtt_period(vlapic) )
   85.73 @@ -893,7 +890,7 @@ int cpu_get_apic_interrupt(struct vcpu *
   85.74                  HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
   85.75                              "Sending an illegal vector 0x%x.", highest_irr);
   85.76  
   85.77 -                set_bit(err_vector, vlapic->regs + APIC_IRR);
   85.78 +                vlapic_set_vector(err_vector, vlapic->regs + APIC_IRR);
   85.79                  highest_irr = err_vector;
   85.80              }
   85.81  
   85.82 @@ -919,6 +916,20 @@ int cpu_has_apic_interrupt(struct vcpu* 
   85.83      return 0;
   85.84  }
   85.85  
   85.86 +/* check to see if there is pending interrupt  */
   85.87 +int cpu_has_pending_irq(struct vcpu *v)
   85.88 +{
   85.89 +    struct hvm_domain *plat = &v->domain->arch.hvm_domain;
   85.90 +
   85.91 +    /* APIC */
   85.92 +    if ( cpu_has_apic_interrupt(v) ) return 1;
   85.93 +    
   85.94 +    /* PIC */
   85.95 +    if ( !vlapic_accept_pic_intr(v) ) return 0;
   85.96 +
   85.97 +    return plat->interrupt_request;
   85.98 +}
   85.99 +
  85.100  void vlapic_post_injection(struct vcpu *v, int vector, int deliver_mode)
  85.101  {
  85.102      struct vlapic *vlapic = VLAPIC(v);
  85.103 @@ -929,15 +940,15 @@ void vlapic_post_injection(struct vcpu *
  85.104      switch ( deliver_mode ) {
  85.105      case APIC_DM_FIXED:
  85.106      case APIC_DM_LOWEST:
  85.107 -        set_bit(vector, vlapic->regs + APIC_ISR);
  85.108 -        clear_bit(vector, vlapic->regs + APIC_IRR);
  85.109 +        vlapic_set_vector(vector, vlapic->regs + APIC_ISR);
  85.110 +        vlapic_clear_vector(vector, vlapic->regs + APIC_IRR);
  85.111          vlapic_update_ppr(vlapic);
  85.112  
  85.113          if ( vector == vlapic_lvt_vector(vlapic, APIC_LVTT) )
  85.114          {
  85.115              vlapic->intr_pending_count[vector]--;
  85.116              if ( vlapic->intr_pending_count[vector] > 0 )
  85.117 -                test_and_set_bit(vector, vlapic->regs + APIC_IRR);
  85.118 +                vlapic_test_and_set_vector(vector, vlapic->regs + APIC_IRR);
  85.119          }
  85.120          break;
  85.121  
    86.1 --- a/xen/arch/x86/hvm/vmx/io.c	Mon Sep 18 09:23:51 2006 -0400
    86.2 +++ b/xen/arch/x86/hvm/vmx/io.c	Mon Sep 18 14:28:16 2006 -0500
    86.3 @@ -68,19 +68,6 @@ static inline int is_interruptibility_st
    86.4      return interruptibility;
    86.5  }
    86.6  
    86.7 -/* check to see if there is pending interrupt  */
    86.8 -int cpu_has_pending_irq(struct vcpu *v)
    86.9 -{
   86.10 -    struct hvm_domain *plat = &v->domain->arch.hvm_domain;
   86.11 -
   86.12 -    /* APIC */
   86.13 -    if ( cpu_has_apic_interrupt(v) ) return 1;
   86.14 -    
   86.15 -    /* PIC */
   86.16 -    if ( !vlapic_accept_pic_intr(v) ) return 0;
   86.17 -
   86.18 -    return plat->interrupt_request;
   86.19 -}
   86.20  
   86.21  asmlinkage void vmx_intr_assist(void)
   86.22  {
    87.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Mon Sep 18 09:23:51 2006 -0400
    87.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Mon Sep 18 14:28:16 2006 -0500
    87.3 @@ -46,6 +46,8 @@
    87.4  #include <asm/hvm/vpic.h>
    87.5  #include <asm/hvm/vlapic.h>
    87.6  
    87.7 +extern uint32_t vlapic_update_ppr(struct vlapic *vlapic);
    87.8 +
    87.9  static DEFINE_PER_CPU(unsigned long, trace_values[5]);
   87.10  #define TRACE_VMEXIT(index,value) this_cpu(trace_values)[index]=value
   87.11  
   87.12 @@ -518,6 +520,7 @@ static void vmx_store_cpu_guest_regs(
   87.13      if ( crs != NULL )
   87.14      {
   87.15          __vmread(CR0_READ_SHADOW, &crs[0]);
   87.16 +        crs[2] = v->arch.hvm_vmx.cpu_cr2;
   87.17          __vmread(GUEST_CR3, &crs[3]);
   87.18          __vmread(CR4_READ_SHADOW, &crs[4]);
   87.19      }
   87.20 @@ -953,8 +956,6 @@ static void vmx_vmexit_do_cpuid(struct c
   87.21                       bitmaskof(X86_FEATURE_MWAIT) );
   87.22  
   87.23              edx &= ~( bitmaskof(X86_FEATURE_HT)   |
   87.24 -                     bitmaskof(X86_FEATURE_MCA)   |
   87.25 -                     bitmaskof(X86_FEATURE_MCE)   |
   87.26                       bitmaskof(X86_FEATURE_ACPI)  |
   87.27                       bitmaskof(X86_FEATURE_ACC) );
   87.28          }
   87.29 @@ -1615,6 +1616,7 @@ static int mov_to_cr(int gp, int cr, str
   87.30      unsigned long value;
   87.31      unsigned long old_cr;
   87.32      struct vcpu *v = current;
   87.33 +    struct vlapic *vlapic = VLAPIC(v);
   87.34  
   87.35      switch ( gp ) {
   87.36      CASE_GET_REG(EAX, eax);
   87.37 @@ -1758,6 +1760,12 @@ static int mov_to_cr(int gp, int cr, str
   87.38              shadow_update_paging_modes(v);
   87.39          break;
   87.40      }
   87.41 +    case 8:
   87.42 +    {
   87.43 +        vlapic_set_reg(vlapic, APIC_TASKPRI, ((value & 0x0F) << 4));
   87.44 +        vlapic_update_ppr(vlapic);
   87.45 +        break;
   87.46 +    }
   87.47      default:
   87.48          printk("invalid cr: %d\n", gp);
   87.49          __hvm_bug(regs);
   87.50 @@ -1771,13 +1779,20 @@ static int mov_to_cr(int gp, int cr, str
   87.51   */
   87.52  static void mov_from_cr(int cr, int gp, struct cpu_user_regs *regs)
   87.53  {
   87.54 -    unsigned long value;
   87.55 +    unsigned long value = 0;
   87.56      struct vcpu *v = current;
   87.57 +    struct vlapic *vlapic = VLAPIC(v);
   87.58  
   87.59 -    if ( cr != 3 )
   87.60 +    if ( cr != 3 && cr != 8)
   87.61          __hvm_bug(regs);
   87.62  
   87.63 -    value = (unsigned long) v->arch.hvm_vmx.cpu_cr3;
   87.64 +    if ( cr == 3 )
   87.65 +        value = (unsigned long) v->arch.hvm_vmx.cpu_cr3;
   87.66 +    else if ( cr == 8 )
   87.67 +    {
   87.68 +        value = (unsigned long)vlapic_get_reg(vlapic, APIC_TASKPRI);
   87.69 +        value = (value & 0xF0) >> 4;
   87.70 +    }
   87.71  
   87.72      switch ( gp ) {
   87.73      CASE_SET_REG(EAX, eax);
   87.74 @@ -1888,7 +1903,7 @@ static inline void vmx_do_msr_read(struc
   87.75          }
   87.76  
   87.77          rdmsr_safe(regs->ecx, regs->eax, regs->edx);
   87.78 -        break;
   87.79 +        return;
   87.80      }
   87.81  
   87.82      regs->eax = msr_content & 0xFFFFFFFF;
    88.1 --- a/xen/arch/x86/mm/shadow/multi.c	Mon Sep 18 09:23:51 2006 -0400
    88.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Mon Sep 18 14:28:16 2006 -0500
    88.3 @@ -1792,8 +1792,10 @@ void sh_install_xen_entries_in_l2h(struc
    88.4          for ( i = 0; i < MACHPHYS_MBYTES>>1; i++ )
    88.5          {
    88.6              sl2e[shadow_l2_table_offset(RO_MPT_VIRT_START) + i] =
    88.7 -                shadow_l2e_from_mfn(_mfn(l3e_get_pfn(p2m[i])),
    88.8 -                                    __PAGE_HYPERVISOR);
    88.9 +                (l3e_get_flags(p2m[i]) & _PAGE_PRESENT)
   88.10 +                ? shadow_l2e_from_mfn(_mfn(l3e_get_pfn(p2m[i])),
   88.11 +                                      __PAGE_HYPERVISOR)
   88.12 +                : shadow_l2e_empty();
   88.13          }
   88.14          sh_unmap_domain_page(p2m);
   88.15      }
   88.16 @@ -2861,11 +2863,11 @@ static int sh_page_fault(struct vcpu *v,
   88.17      //      bunch of 4K maps.
   88.18      //
   88.19  
   88.20 +    shadow_lock(d);
   88.21 +
   88.22      SHADOW_PRINTK("d:v=%u:%u va=%#lx err=%u\n",
   88.23                     v->domain->domain_id, v->vcpu_id, va, regs->error_code);
   88.24      
   88.25 -    shadow_lock(d);
   88.26 -
   88.27      shadow_audit_tables(v);
   88.28                     
   88.29      if ( guest_walk_tables(v, va, &gw, 1) != 0 )
   88.30 @@ -3291,12 +3293,6 @@ sh_update_linear_entries(struct vcpu *v)
   88.31          {
   88.32              ml3e = __linear_l3_table;
   88.33              l3mfn = _mfn(l4e_get_pfn(__linear_l4_table[0]));
   88.34 -#if GUEST_PAGING_LEVELS == 2
   88.35 -            /* Shadow l3 tables are made up by update_cr3 */
   88.36 -            sl3e = v->arch.hvm_vcpu.hvm_lowmem_l3tab;
   88.37 -#else
   88.38 -            sl3e = v->arch.shadow_vtable;
   88.39 -#endif
   88.40          }
   88.41          else 
   88.42          {   
   88.43 @@ -3306,13 +3302,15 @@ sh_update_linear_entries(struct vcpu *v)
   88.44              l3mfn = _mfn(l4e_get_pfn(ml4e[0]));
   88.45              ml3e = sh_map_domain_page(l3mfn);
   88.46              sh_unmap_domain_page(ml4e);
   88.47 +        }
   88.48 +
   88.49  #if GUEST_PAGING_LEVELS == 2
   88.50 -            /* Shadow l3 tables are made up by update_cr3 */
   88.51 -            sl3e = v->arch.hvm_vcpu.hvm_lowmem_l3tab;
   88.52 +        /* Shadow l3 tables are made up by update_cr3 */
   88.53 +        sl3e = v->arch.hvm_vcpu.hvm_lowmem_l3tab;
   88.54  #else
   88.55 -            sl3e = sh_map_domain_page(pagetable_get_mfn(v->arch.shadow_table));
   88.56 +        /* Always safe to use shadow_vtable, because it's globally mapped */
   88.57 +        sl3e = v->arch.shadow_vtable;
   88.58  #endif
   88.59 -        }
   88.60  
   88.61          for ( i = 0; i < SHADOW_L3_PAGETABLE_ENTRIES; i++ )
   88.62          {
   88.63 @@ -3324,12 +3322,7 @@ sh_update_linear_entries(struct vcpu *v)
   88.64          }
   88.65  
   88.66          if ( v != current ) 
   88.67 -        {
   88.68              sh_unmap_domain_page(ml3e);
   88.69 -#if GUEST_PAGING_LEVELS != 2
   88.70 -            sh_unmap_domain_page(sl3e);
   88.71 -#endif
   88.72 -        }
   88.73      }
   88.74  
   88.75  #elif CONFIG_PAGING_LEVELS == 3
   88.76 @@ -3361,31 +3354,10 @@ sh_update_linear_entries(struct vcpu *v)
   88.77          
   88.78  #else /* GUEST_PAGING_LEVELS == 3 */
   88.79          
   88.80 -        /* Use local vcpu's mappings if we can; otherwise make new mappings */
   88.81 -        if ( v == current ) 
   88.82 -        {
   88.83 -            shadow_l3e = v->arch.shadow_vtable;
   88.84 -            if ( !shadow_mode_external(d) )
   88.85 -                guest_l3e = v->arch.guest_vtable;
   88.86 -        }
   88.87 -        else 
   88.88 -        {
   88.89 -            mfn_t smfn;
   88.90 -            int idx;
   88.91 -            
   88.92 -            /* Map the shadow l3 */
   88.93 -            smfn = pagetable_get_mfn(v->arch.shadow_table);
   88.94 -            idx = shadow_l3_index(&smfn, guest_index(v->arch.shadow_vtable));
   88.95 -            shadow_l3e = sh_map_domain_page(smfn);
   88.96 -            shadow_l3e += idx;
   88.97 -            if ( !shadow_mode_external(d) )
   88.98 -            {
   88.99 -                /* Also the guest l3 */
  88.100 -                mfn_t gmfn = pagetable_get_mfn(v->arch.guest_table); 
  88.101 -                guest_l3e = sh_map_domain_page(gmfn);
  88.102 -                guest_l3e += guest_index(v->arch.guest_vtable);
  88.103 -            }
  88.104 -        }
  88.105 +        /* Always safe to use *_vtable, because they're globally mapped */
  88.106 +        shadow_l3e = v->arch.shadow_vtable;
  88.107 +        guest_l3e = v->arch.guest_vtable;
  88.108 +
  88.109  #endif /* GUEST_PAGING_LEVELS */
  88.110          
  88.111          /* Choose where to write the entries, using linear maps if possible */
  88.112 @@ -3443,14 +3415,6 @@ sh_update_linear_entries(struct vcpu *v)
  88.113          if ( v != current || !shadow_mode_external(d) )
  88.114              sh_unmap_domain_page(l2e);
  88.115          
  88.116 -#if GUEST_PAGING_LEVELS == 3
  88.117 -        if ( v != current) 
  88.118 -        {
  88.119 -            sh_unmap_domain_page(shadow_l3e);
  88.120 -            if ( !shadow_mode_external(d) )
  88.121 -                sh_unmap_domain_page(guest_l3e);
  88.122 -        }
  88.123 -#endif
  88.124      }
  88.125  
  88.126  #elif CONFIG_PAGING_LEVELS == 2
  88.127 @@ -3601,7 +3565,7 @@ sh_detach_old_tables(struct vcpu *v)
  88.128           v->arch.shadow_vtable )
  88.129      {
  88.130          // Q: why does this need to use (un)map_domain_page_*global* ?
  88.131 -        //
  88.132 +        /* A: so sh_update_linear_entries can operate on other vcpus */
  88.133          sh_unmap_domain_page_global(v->arch.shadow_vtable);
  88.134          v->arch.shadow_vtable = NULL;
  88.135      }
    89.1 --- a/xen/arch/x86/oprofile/xenoprof.c	Mon Sep 18 09:23:51 2006 -0400
    89.2 +++ b/xen/arch/x86/oprofile/xenoprof.c	Mon Sep 18 14:28:16 2006 -0500
    89.3 @@ -437,54 +437,59 @@ void xenoprof_log_event(
    89.4  int xenoprof_op_init(XEN_GUEST_HANDLE(void) arg)
    89.5  {
    89.6      struct xenoprof_init xenoprof_init;
    89.7 -    int is_primary, num_events;
    89.8 -    struct domain *d = current->domain;
    89.9      int ret;
   89.10  
   89.11      if ( copy_from_guest(&xenoprof_init, arg, 1) )
   89.12          return -EFAULT;
   89.13  
   89.14 -    ret = nmi_init(&num_events, 
   89.15 -                   &is_primary, 
   89.16 -                   xenoprof_init.cpu_type);
   89.17 -    if ( ret < 0 )
   89.18 -        goto err;
   89.19 +    if ( (ret = nmi_init(&xenoprof_init.num_events, 
   89.20 +                         &xenoprof_init.is_primary, 
   89.21 +                         xenoprof_init.cpu_type)) )
   89.22 +        return ret;
   89.23  
   89.24 -    if ( is_primary )
   89.25 +    if ( copy_to_guest(arg, &xenoprof_init, 1) )
   89.26 +        return -EFAULT;
   89.27 +
   89.28 +    if ( xenoprof_init.is_primary )
   89.29          primary_profiler = current->domain;
   89.30  
   89.31 +    return 0;
   89.32 +}
   89.33 +
   89.34 +int xenoprof_op_get_buffer(XEN_GUEST_HANDLE(void) arg)
   89.35 +{
   89.36 +    struct xenoprof_get_buffer xenoprof_get_buffer;
   89.37 +    struct domain *d = current->domain;
   89.38 +    int ret;
   89.39 +
   89.40 +    if ( copy_from_guest(&xenoprof_get_buffer, arg, 1) )
   89.41 +        return -EFAULT;
   89.42 +
   89.43      /*
   89.44 -     * We allocate xenoprof struct and buffers only at first time xenoprof_init
   89.45 +     * We allocate xenoprof struct and buffers only at first time xenoprof_get_buffer
   89.46       * is called. Memory is then kept until domain is destroyed.
   89.47       */
   89.48      if ( (d->xenoprof == NULL) &&
   89.49 -         ((ret = alloc_xenoprof_struct(d, xenoprof_init.max_samples, 0)) < 0) )
   89.50 -        goto err;
   89.51 +         ((ret = alloc_xenoprof_struct(d, xenoprof_get_buffer.max_samples, 0)) < 0) )
   89.52 +        return ret;
   89.53  
   89.54      xenoprof_reset_buf(d);
   89.55  
   89.56      d->xenoprof->domain_type  = XENOPROF_DOMAIN_IGNORED;
   89.57      d->xenoprof->domain_ready = 0;
   89.58 -    d->xenoprof->is_primary = is_primary;
   89.59 -
   89.60 -    xenoprof_init.is_primary = is_primary;
   89.61 -    xenoprof_init.num_events = num_events;
   89.62 -    xenoprof_init.nbuf = d->xenoprof->nbuf;
   89.63 -    xenoprof_init.bufsize = d->xenoprof->bufsize;
   89.64 -    xenoprof_init.buf_maddr = __pa(d->xenoprof->rawbuf);
   89.65 +    if ( primary_profiler == current->domain )
   89.66 +        d->xenoprof->is_primary = 1;
   89.67 +    else
   89.68 +        d->xenoprof->is_primary = 0;
   89.69 +        
   89.70 +    xenoprof_get_buffer.nbuf = d->xenoprof->nbuf;
   89.71 +    xenoprof_get_buffer.bufsize = d->xenoprof->bufsize;
   89.72 +    xenoprof_get_buffer.buf_maddr = __pa(d->xenoprof->rawbuf);
   89.73  
   89.74 -    if ( copy_to_guest(arg, &xenoprof_init, 1) )
   89.75 -    {
   89.76 -        ret = -EFAULT;
   89.77 -        goto err;
   89.78 -    }
   89.79 +    if ( copy_to_guest(arg, &xenoprof_get_buffer, 1) )
   89.80 +        return -EFAULT;
   89.81  
   89.82 -    return ret;
   89.83 -
   89.84 - err:
   89.85 -    if ( primary_profiler == current->domain )
   89.86 -        primary_profiler = NULL;
   89.87 -    return ret;
   89.88 +    return 0;
   89.89  }
   89.90  
   89.91  #define PRIV_OP(op) ( (op == XENOPROF_set_active)       \
   89.92 @@ -512,6 +517,10 @@ int do_xenoprof_op(int op, XEN_GUEST_HAN
   89.93          ret = xenoprof_op_init(arg);
   89.94          break;
   89.95  
   89.96 +    case XENOPROF_get_buffer:
   89.97 +        ret = xenoprof_op_get_buffer(arg);
   89.98 +        break;
   89.99 +
  89.100      case XENOPROF_reset_active_list:
  89.101      {
  89.102          reset_active_list();
    90.1 --- a/xen/arch/x86/time.c	Mon Sep 18 09:23:51 2006 -0400
    90.2 +++ b/xen/arch/x86/time.c	Mon Sep 18 14:28:16 2006 -0500
    90.3 @@ -676,7 +676,7 @@ static inline void __update_vcpu_system_
    90.4      struct vcpu_time_info *u;
    90.5  
    90.6      t = &this_cpu(cpu_time);
    90.7 -    u = &v->domain->shared_info->vcpu_info[v->vcpu_id].time;
    90.8 +    u = &v->vcpu_info->time;
    90.9  
   90.10      version_update_begin(&u->version);
   90.11  
   90.12 @@ -690,7 +690,7 @@ static inline void __update_vcpu_system_
   90.13  
   90.14  void update_vcpu_system_time(struct vcpu *v)
   90.15  {
   90.16 -    if ( v->domain->shared_info->vcpu_info[v->vcpu_id].time.tsc_timestamp != 
   90.17 +    if ( v->vcpu_info->time.tsc_timestamp !=
   90.18           this_cpu(cpu_time).local_tsc_stamp )
   90.19          __update_vcpu_system_time(v);
   90.20  }
    91.1 --- a/xen/arch/x86/traps.c	Mon Sep 18 09:23:51 2006 -0400
    91.2 +++ b/xen/arch/x86/traps.c	Mon Sep 18 14:28:16 2006 -0500
    91.3 @@ -339,7 +339,6 @@ void show_execution_state(struct cpu_use
    91.4  asmlinkage void fatal_trap(int trapnr, struct cpu_user_regs *regs)
    91.5  {
    91.6      int cpu = smp_processor_id();
    91.7 -    unsigned long cr2;
    91.8      static char *trapstr[] = { 
    91.9          "divide error", "debug", "nmi", "bkpt", "overflow", "bounds", 
   91.10          "invalid opcode", "device not available", "double fault", 
   91.11 @@ -356,7 +355,7 @@ asmlinkage void fatal_trap(int trapnr, s
   91.12  
   91.13      if ( trapnr == TRAP_page_fault )
   91.14      {
   91.15 -        __asm__ __volatile__ ("mov %%cr2,%0" : "=r" (cr2) : );
   91.16 +        unsigned long cr2 = read_cr2();
   91.17          printk("Faulting linear address: %p\n", _p(cr2));
   91.18          show_page_walk(cr2);
   91.19      }
   91.20 @@ -911,7 +910,7 @@ asmlinkage int do_page_fault(struct cpu_
   91.21  
   91.22      ASSERT(!in_irq());
   91.23  
   91.24 -    __asm__ __volatile__ ("mov %%cr2,%0" : "=r" (addr) : );
   91.25 +    addr = read_cr2();
   91.26  
   91.27      DEBUGGER_trap_entry(TRAP_page_fault, regs);
   91.28  
   91.29 @@ -1004,7 +1003,21 @@ static inline int admin_io_okay(
   91.30  }
   91.31  
   91.32  /* Check admin limits. Silently fail the access if it is disallowed. */
   91.33 -#define inb_user(_p, _d, _r) (admin_io_okay(_p, 1, _d, _r) ? inb(_p) : ~0)
   91.34 +static inline unsigned char inb_user(
   91.35 +    unsigned int port, struct vcpu *v, struct cpu_user_regs *regs)
   91.36 +{
   91.37 +    /*
   91.38 +     * Allow read access to port 0x61. Bit 4 oscillates with period 30us, and
   91.39 +     * so it is often used for timing loops in BIOS code. This hack can go
   91.40 +     * away when we have separate read/write permission rangesets.
   91.41 +     * Note that we could emulate bit 4 instead of directly reading port 0x61,
   91.42 +     * but there's not really a good reason to do so.
   91.43 +     */
   91.44 +    if ( admin_io_okay(port, 1, v, regs) || (port == 0x61) )
   91.45 +        return inb(port);
   91.46 +    return ~0;
   91.47 +}
   91.48 +//#define inb_user(_p, _d, _r) (admin_io_okay(_p, 1, _d, _r) ? inb(_p) : ~0)
   91.49  #define inw_user(_p, _d, _r) (admin_io_okay(_p, 2, _d, _r) ? inw(_p) : ~0)
   91.50  #define inl_user(_p, _d, _r) (admin_io_okay(_p, 4, _d, _r) ? inl(_p) : ~0)
   91.51  #define outb_user(_v, _p, _d, _r) \
    92.1 --- a/xen/arch/x86/x86_32/traps.c	Mon Sep 18 09:23:51 2006 -0400
    92.2 +++ b/xen/arch/x86/x86_32/traps.c	Mon Sep 18 14:28:16 2006 -0500
    92.3 @@ -21,11 +21,28 @@
    92.4  /* All CPUs have their own IDT to allow int80 direct trap. */
    92.5  idt_entry_t *idt_tables[NR_CPUS] __read_mostly;
    92.6  
    92.7 +static void print_xen_info(void)
    92.8 +{
    92.9 +    char taint_str[TAINT_STRING_MAX_LEN];
   92.10 +    char debug = 'n', *arch = "x86_32";
   92.11 +
   92.12 +#ifndef NDEBUG
   92.13 +    debug = 'y';
   92.14 +#endif
   92.15 +
   92.16 +#ifdef CONFIG_X86_PAE
   92.17 +    arch = "x86_32p";
   92.18 +#endif
   92.19 +
   92.20 +    printk("----[ Xen-%d.%d%s  %s  debug=%c  %s ]----\n",
   92.21 +           xen_major_version(), xen_minor_version(), xen_extra_version(),
   92.22 +           arch, debug, print_tainted(taint_str));
   92.23 +}
   92.24 +
   92.25  void show_registers(struct cpu_user_regs *regs)
   92.26  {
   92.27      struct cpu_user_regs fault_regs = *regs;
   92.28      unsigned long fault_crs[8];
   92.29 -    char taint_str[TAINT_STRING_MAX_LEN];
   92.30      const char *context;
   92.31  
   92.32      if ( hvm_guest(current) && guest_mode(regs) )
   92.33 @@ -35,25 +52,29 @@ void show_registers(struct cpu_user_regs
   92.34      }
   92.35      else
   92.36      {
   92.37 -        context = guest_mode(regs) ? "guest" : "hypervisor";
   92.38 -
   92.39          if ( !guest_mode(regs) )
   92.40          {
   92.41 +            context = "hypervisor";
   92.42              fault_regs.esp = (unsigned long)&regs->esp;
   92.43              fault_regs.ss = read_segment_register(ss);
   92.44              fault_regs.ds = read_segment_register(ds);
   92.45              fault_regs.es = read_segment_register(es);
   92.46              fault_regs.fs = read_segment_register(fs);
   92.47              fault_regs.gs = read_segment_register(gs);
   92.48 +            fault_crs[2] = read_cr2();
   92.49 +        }
   92.50 +        else
   92.51 +        {
   92.52 +            context = "guest";
   92.53 +            fault_crs[2] = current->vcpu_info->arch.cr2;
   92.54          }
   92.55  
   92.56          fault_crs[0] = read_cr0();
   92.57          fault_crs[3] = read_cr3();
   92.58 +        fault_crs[4] = read_cr4();
   92.59      }
   92.60  
   92.61 -    printk("----[ Xen-%d.%d%s    %s ]----\n",
   92.62 -           xen_major_version(), xen_minor_version(), xen_extra_version(),
   92.63 -           print_tainted(taint_str));
   92.64 +    print_xen_info();
   92.65      printk("CPU:    %d\nEIP:    %04x:[<%08x>]",
   92.66             smp_processor_id(), fault_regs.cs, fault_regs.eip);
   92.67      if ( !guest_mode(regs) )
   92.68 @@ -63,7 +84,8 @@ void show_registers(struct cpu_user_regs
   92.69             fault_regs.eax, fault_regs.ebx, fault_regs.ecx, fault_regs.edx);
   92.70      printk("esi: %08x   edi: %08x   ebp: %08x   esp: %08x\n",
   92.71             fault_regs.esi, fault_regs.edi, fault_regs.ebp, fault_regs.esp);
   92.72 -    printk("cr0: %08lx   cr3: %08lx\n", fault_crs[0], fault_crs[3]);
   92.73 +    printk("cr0: %08lx   cr4: %08lx   cr3: %08lx   cr2: %08lx\n",
   92.74 +           fault_crs[0], fault_crs[4], fault_crs[3], fault_crs[2]);
   92.75      printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   "
   92.76             "ss: %04x   cs: %04x\n",
   92.77             fault_regs.ds, fault_regs.es, fault_regs.fs,
   92.78 @@ -125,7 +147,6 @@ asmlinkage void do_double_fault(void)
   92.79  {
   92.80      struct tss_struct *tss = &doublefault_tss;
   92.81      unsigned int cpu = ((tss->back_link>>3)-__FIRST_TSS_ENTRY)>>1;
   92.82 -    char taint_str[TAINT_STRING_MAX_LEN];
   92.83  
   92.84      watchdog_disable();
   92.85  
   92.86 @@ -133,9 +154,8 @@ asmlinkage void do_double_fault(void)
   92.87  
   92.88      /* Find information saved during fault and dump it to the console. */
   92.89      tss = &init_tss[cpu];
   92.90 -    printk("*** DOUBLE FAULT: Xen-%d.%d%s    %s\n",
   92.91 -           xen_major_version(), xen_minor_version(), xen_extra_version(),
   92.92 -           print_tainted(taint_str));
   92.93 +    printk("*** DOUBLE FAULT ***\n");
   92.94 +    print_xen_info();
   92.95      printk("CPU:    %d\nEIP:    %04x:[<%08x>]",
   92.96             cpu, tss->cs, tss->eip);
   92.97      print_symbol(" %s\n", tss->eip);
    93.1 --- a/xen/arch/x86/x86_64/mm.c	Mon Sep 18 09:23:51 2006 -0400
    93.2 +++ b/xen/arch/x86/x86_64/mm.c	Mon Sep 18 14:28:16 2006 -0500
    93.3 @@ -78,7 +78,7 @@ void __init paging_init(void)
    93.4  {
    93.5      unsigned long i, mpt_size;
    93.6      l3_pgentry_t *l3_ro_mpt;
    93.7 -    l2_pgentry_t *l2_ro_mpt;
    93.8 +    l2_pgentry_t *l2_ro_mpt = NULL;
    93.9      struct page_info *pg;
   93.10  
   93.11      /* Create user-accessible L2 directory to map the MPT for guests. */
   93.12 @@ -87,12 +87,6 @@ void __init paging_init(void)
   93.13      idle_pg_table[l4_table_offset(RO_MPT_VIRT_START)] =
   93.14          l4e_from_page(
   93.15              virt_to_page(l3_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
   93.16 -    l2_ro_mpt = alloc_xenheap_page();
   93.17 -    clear_page(l2_ro_mpt);
   93.18 -    l3_ro_mpt[l3_table_offset(RO_MPT_VIRT_START)] =
   93.19 -        l3e_from_page(
   93.20 -            virt_to_page(l2_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
   93.21 -    l2_ro_mpt += l2_table_offset(RO_MPT_VIRT_START);
   93.22  
   93.23      /*
   93.24       * Allocate and map the machine-to-phys table.
   93.25 @@ -110,10 +104,20 @@ void __init paging_init(void)
   93.26              PAGE_HYPERVISOR);
   93.27          memset((void *)(RDWR_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT)), 0x55,
   93.28                 1UL << L2_PAGETABLE_SHIFT);
   93.29 +        if ( !((unsigned long)l2_ro_mpt & ~PAGE_MASK) )
   93.30 +        {
   93.31 +            unsigned long va = RO_MPT_VIRT_START + (i << L2_PAGETABLE_SHIFT);
   93.32 +
   93.33 +            l2_ro_mpt = alloc_xenheap_page();
   93.34 +            clear_page(l2_ro_mpt);
   93.35 +            l3_ro_mpt[l3_table_offset(va)] =
   93.36 +                l3e_from_page(
   93.37 +                    virt_to_page(l2_ro_mpt), __PAGE_HYPERVISOR | _PAGE_USER);
   93.38 +            l2_ro_mpt += l2_table_offset(va);
   93.39 +        }
   93.40          /* NB. Cannot be GLOBAL as shadow_mode_translate reuses this area. */
   93.41          *l2_ro_mpt++ = l2e_from_page(
   93.42              pg, /*_PAGE_GLOBAL|*/_PAGE_PSE|_PAGE_USER|_PAGE_PRESENT);
   93.43 -        BUG_ON(((unsigned long)l2_ro_mpt & ~PAGE_MASK) == 0);
   93.44      }
   93.45  
   93.46      /* Set up linear page table mapping. */
    94.1 --- a/xen/arch/x86/x86_64/traps.c	Mon Sep 18 09:23:51 2006 -0400
    94.2 +++ b/xen/arch/x86/x86_64/traps.c	Mon Sep 18 14:28:16 2006 -0500
    94.3 @@ -21,11 +21,24 @@
    94.4  
    94.5  #include <public/callback.h>
    94.6  
    94.7 +static void print_xen_info(void)
    94.8 +{
    94.9 +    char taint_str[TAINT_STRING_MAX_LEN];
   94.10 +    char debug = 'n';
   94.11 +
   94.12 +#ifndef NDEBUG
   94.13 +    debug = 'y';
   94.14 +#endif
   94.15 +
   94.16 +    printk("----[ Xen-%d.%d%s  x86_64  debug=%c  %s ]----\n",
   94.17 +           xen_major_version(), xen_minor_version(), xen_extra_version(),
   94.18 +           debug, print_tainted(taint_str));
   94.19 +}
   94.20 +
   94.21  void show_registers(struct cpu_user_regs *regs)
   94.22  {
   94.23      struct cpu_user_regs fault_regs = *regs;
   94.24      unsigned long fault_crs[8];
   94.25 -    char taint_str[TAINT_STRING_MAX_LEN];
   94.26      const char *context;
   94.27  
   94.28      if ( hvm_guest(current) && guest_mode(regs) )
   94.29 @@ -35,18 +48,27 @@ void show_registers(struct cpu_user_regs
   94.30      }
   94.31      else
   94.32      {
   94.33 -        context = guest_mode(regs) ? "guest" : "hypervisor";
   94.34 +        if ( guest_mode(regs) )
   94.35 +        {
   94.36 +            context = "guest";
   94.37 +            fault_crs[2] = current->vcpu_info->arch.cr2;
   94.38 +        }
   94.39 +        else
   94.40 +        {
   94.41 +            context = "hypervisor";
   94.42 +            fault_crs[2] = read_cr2();
   94.43 +        }
   94.44 +
   94.45          fault_crs[0] = read_cr0();
   94.46          fault_crs[3] = read_cr3();
   94.47 +        fault_crs[4] = read_cr4();
   94.48          fault_regs.ds = read_segment_register(ds);
   94.49          fault_regs.es = read_segment_register(es);
   94.50          fault_regs.fs = read_segment_register(fs);
   94.51          fault_regs.gs = read_segment_register(gs);
   94.52      }
   94.53  
   94.54 -    printk("----[ Xen-%d.%d%s    %s ]----\n",
   94.55 -           xen_major_version(), xen_minor_version(), xen_extra_version(),
   94.56 -           print_tainted(taint_str));
   94.57 +    print_xen_info();
   94.58      printk("CPU:    %d\nRIP:    %04x:[<%016lx>]",
   94.59             smp_processor_id(), fault_regs.cs, fault_regs.rip);
   94.60      if ( !guest_mode(regs) )
   94.61 @@ -62,8 +84,9 @@ void show_registers(struct cpu_user_regs
   94.62             fault_regs.r9,  fault_regs.r10, fault_regs.r11);
   94.63      printk("r12: %016lx   r13: %016lx   r14: %016lx\n",
   94.64             fault_regs.r12, fault_regs.r13, fault_regs.r14);
   94.65 -    printk("r15: %016lx   cr0: %016lx   cr3: %016lx\n",
   94.66 -           fault_regs.r15, fault_crs[0], fault_crs[3]);
   94.67 +    printk("r15: %016lx   cr0: %016lx   cr4: %016lx\n",
   94.68 +           fault_regs.r15, fault_crs[0], fault_crs[4]);
   94.69 +    printk("cr3: %016lx   cr2: %016lx\n", fault_crs[3], fault_crs[2]);
   94.70      printk("ds: %04x   es: %04x   fs: %04x   gs: %04x   "
   94.71             "ss: %04x   cs: %04x\n",
   94.72             fault_regs.ds, fault_regs.es, fault_regs.fs,
   94.73 @@ -121,7 +144,6 @@ asmlinkage void double_fault(void);
   94.74  asmlinkage void do_double_fault(struct cpu_user_regs *regs)
   94.75  {
   94.76      unsigned int cpu, tr;
   94.77 -    char taint_str[TAINT_STRING_MAX_LEN];
   94.78  
   94.79      asm ( "str %0" : "=r" (tr) );
   94.80      cpu = ((tr >> 3) - __FIRST_TSS_ENTRY) >> 2;
   94.81 @@ -131,9 +153,8 @@ asmlinkage void do_double_fault(struct c
   94.82      console_force_unlock();
   94.83  
   94.84      /* Find information saved during fault and dump it to the console. */
   94.85 -    printk("*** DOUBLE FAULT: Xen-%d.%d%s    %s\n",
   94.86 -           xen_major_version(), xen_minor_version(), xen_extra_version(),
   94.87 -           print_tainted(taint_str));
   94.88 +    printk("*** DOUBLE FAULT ***\n");
   94.89 +    print_xen_info();
   94.90      printk("CPU:    %d\nRIP:    %04x:[<%016lx>]",
   94.91             cpu, regs->cs, regs->rip);
   94.92      print_symbol(" %s", regs->rip);
    95.1 --- a/xen/common/grant_table.c	Mon Sep 18 09:23:51 2006 -0400
    95.2 +++ b/xen/common/grant_table.c	Mon Sep 18 14:28:16 2006 -0500
    95.3 @@ -90,11 +90,8 @@ static void
    95.4      unsigned long  frame = 0;
    95.5      int            rc = GNTST_okay;
    95.6      struct active_grant_entry *act;
    95.7 -
    95.8 -    /* Entry details from @rd's shared grant table. */
    95.9      grant_entry_t *sha;
   95.10 -    domid_t        sdom;
   95.11 -    u16            sflags;
   95.12 +    union grant_combo scombo, prev_scombo, new_scombo;
   95.13  
   95.14      /*
   95.15       * We bound the number of times we retry CMPXCHG on memory locations that
   95.16 @@ -159,7 +156,10 @@ static void
   95.17  
   95.18          memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   95.19          for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   95.20 +        {
   95.21              new_mt[i].ref = i+1;
   95.22 +            new_mt[i].flags = 0;
   95.23 +        }
   95.24  
   95.25          free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   95.26          lgt->maptrack          = new_mt;
   95.27 @@ -175,12 +175,19 @@ static void
   95.28  
   95.29      spin_lock(&rd->grant_table->lock);
   95.30  
   95.31 +    /* If already pinned, check the active domid and avoid refcnt overflow. */
   95.32 +    if ( act->pin &&
   95.33 +         ((act->domid != ld->domain_id) ||
   95.34 +          (act->pin & 0x80808080U) != 0) )
   95.35 +        PIN_FAIL(unlock_out, GNTST_general_error,
   95.36 +                 "Bad domain (%d != %d), or risk of counter overflow %08x\n",
   95.37 +                 act->domid, ld->domain_id, act->pin);
   95.38 +
   95.39      if ( !act->pin ||
   95.40           (!(op->flags & GNTMAP_readonly) &&
   95.41            !(act->pin & (GNTPIN_hstw_mask|GNTPIN_devw_mask))) )
   95.42      {
   95.43 -        sflags = sha->flags;
   95.44 -        sdom   = sha->domid;
   95.45 +        scombo.word = *(u32 *)&sha->flags;
   95.46  
   95.47          /*
   95.48           * This loop attempts to set the access (reading/writing) flags
   95.49 @@ -190,33 +197,29 @@ static void
   95.50           */
   95.51          for ( ; ; )
   95.52          {
   95.53 -            union grant_combo scombo, prev_scombo, new_scombo;
   95.54 +            /* If not already pinned, check the grant domid and type. */
   95.55 +            if ( !act->pin &&
   95.56 +                 (((scombo.shorts.flags & GTF_type_mask) !=
   95.57 +                   GTF_permit_access) ||
   95.58 +                  (scombo.shorts.domid != ld->domain_id)) )
   95.59 +                 PIN_FAIL(unlock_out, GNTST_general_error,
   95.60 +                          "Bad flags (%x) or dom (%d). (expected dom %d)\n",
   95.61 +                          scombo.shorts.flags, scombo.shorts.domid,
   95.62 +                          ld->domain_id);
   95.63  
   95.64 -            if ( unlikely((sflags & GTF_type_mask) != GTF_permit_access) ||
   95.65 -                 unlikely(sdom != led->domain->domain_id) )
   95.66 -                PIN_FAIL(unlock_out, GNTST_general_error,
   95.67 -                         "Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
   95.68 -                         sflags, sdom, led->domain->domain_id);
   95.69 -
   95.70 -            /* Merge two 16-bit values into a 32-bit combined update. */
   95.71 -            scombo.shorts.flags = sflags;
   95.72 -            scombo.shorts.domid = sdom;
   95.73 -            
   95.74              new_scombo = scombo;
   95.75              new_scombo.shorts.flags |= GTF_reading;
   95.76  
   95.77              if ( !(op->flags & GNTMAP_readonly) )
   95.78              {
   95.79                  new_scombo.shorts.flags |= GTF_writing;
   95.80 -                if ( unlikely(sflags & GTF_readonly) )
   95.81 +                if ( unlikely(scombo.shorts.flags & GTF_readonly) )
   95.82                      PIN_FAIL(unlock_out, GNTST_general_error,
   95.83                               "Attempt to write-pin a r/o grant entry.\n");
   95.84              }
   95.85  
   95.86              prev_scombo.word = cmpxchg((u32 *)&sha->flags,
   95.87                                         scombo.word, new_scombo.word);
   95.88 -
   95.89 -            /* Did the combined update work (did we see what we expected?). */
   95.90              if ( likely(prev_scombo.word == scombo.word) )
   95.91                  break;
   95.92  
   95.93 @@ -224,20 +227,15 @@ static void
   95.94                  PIN_FAIL(unlock_out, GNTST_general_error,
   95.95                           "Shared grant entry is unstable.\n");
   95.96  
   95.97 -            /* Didn't see what we expected. Split out the seen flags & dom. */
   95.98 -            sflags = prev_scombo.shorts.flags;
   95.99 -            sdom   = prev_scombo.shorts.domid;
  95.100 +            scombo = prev_scombo;
  95.101          }
  95.102  
  95.103          if ( !act->pin )
  95.104          {
  95.105 -            act->domid = sdom;
  95.106 +            act->domid = scombo.shorts.domid;
  95.107              act->frame = gmfn_to_mfn(rd, sha->frame);
  95.108          }
  95.109      }
  95.110 -    else if ( (act->pin & 0x80808080U) != 0 )
  95.111 -        PIN_FAIL(unlock_out, ENOSPC,
  95.112 -                 "Risk of counter overflow %08x\n", act->pin);
  95.113  
  95.114      if ( op->flags & GNTMAP_device_map )
  95.115          act->pin += (op->flags & GNTMAP_readonly) ?
  95.116 @@ -545,9 +543,7 @@ gnttab_prepare_for_transfer(
  95.117  {
  95.118      struct grant_table *rgt;
  95.119      struct grant_entry *sha;
  95.120 -    domid_t             sdom;
  95.121 -    u16                 sflags;
  95.122 -    union grant_combo   scombo, prev_scombo, tmp_scombo;
  95.123 +    union grant_combo   scombo, prev_scombo, new_scombo;
  95.124      int                 retries = 0;
  95.125  
  95.126      if ( unlikely((rgt = rd->grant_table) == NULL) ||
  95.127 @@ -562,29 +558,24 @@ gnttab_prepare_for_transfer(
  95.128  
  95.129      sha = &rgt->shared[ref];
  95.130      
  95.131 -    sflags = sha->flags;
  95.132 -    sdom   = sha->domid;
  95.133 +    scombo.word = *(u32 *)&sha->flags;
  95.134  
  95.135      for ( ; ; )
  95.136      {
  95.137 -        if ( unlikely(sflags != GTF_accept_transfer) ||
  95.138 -             unlikely(sdom != ld->domain_id) )
  95.139 +        if ( unlikely(scombo.shorts.flags != GTF_accept_transfer) ||
  95.140 +             unlikely(scombo.shorts.domid != ld->domain_id) )
  95.141          {
  95.142              DPRINTK("Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
  95.143 -                    sflags, sdom, ld->domain_id);
  95.144 +                    scombo.shorts.flags, scombo.shorts.domid,
  95.145 +                    ld->domain_id);
  95.146              goto fail;
  95.147          }
  95.148  
  95.149 -        /* Merge two 16-bit values into a 32-bit combined update. */
  95.150 -        scombo.shorts.flags = sflags;
  95.151 -        scombo.shorts.domid = sdom;
  95.152 +        new_scombo = scombo;
  95.153 +        new_scombo.shorts.flags |= GTF_transfer_committed;
  95.154  
  95.155 -        tmp_scombo = scombo;
  95.156 -        tmp_scombo.shorts.flags |= GTF_transfer_committed;
  95.157          prev_scombo.word = cmpxchg((u32 *)&sha->flags,
  95.158 -                                   scombo.word, tmp_scombo.word);
  95.159 -
  95.160 -        /* Did the combined update work (did we see what we expected?). */
  95.161 +                                   scombo.word, new_scombo.word);
  95.162          if ( likely(prev_scombo.word == scombo.word) )
  95.163              break;
  95.164  
  95.165 @@ -594,9 +585,7 @@ gnttab_prepare_for_transfer(
  95.166              goto fail;
  95.167          }
  95.168  
  95.169 -        /* Didn't see what we expected. Split out the seen flags & dom. */
  95.170 -        sflags = prev_scombo.shorts.flags;
  95.171 -        sdom   = prev_scombo.shorts.domid;
  95.172 +        scombo = prev_scombo;
  95.173      }
  95.174  
  95.175      spin_unlock(&rgt->lock);
  95.176 @@ -734,16 +723,21 @@ static void
  95.177          gnttab_mark_dirty(rd, r_frame);
  95.178  
  95.179      spin_lock(&rd->grant_table->lock);
  95.180 +
  95.181      if ( readonly )
  95.182 +    {
  95.183          act->pin -= GNTPIN_hstr_inc;
  95.184 +    }
  95.185      else
  95.186 +    {
  95.187          act->pin -= GNTPIN_hstw_inc;
  95.188 -
  95.189 -    if ( !(act->pin & GNTPIN_hstw_mask) && !readonly )
  95.190 -        gnttab_clear_flag(_GTF_writing, &sha->flags);
  95.191 +        if ( !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask)) )
  95.192 +            gnttab_clear_flag(_GTF_writing, &sha->flags);
  95.193 +    }
  95.194  
  95.195      if ( !act->pin )
  95.196          gnttab_clear_flag(_GTF_reading, &sha->flags);
  95.197 +
  95.198      spin_unlock(&rd->grant_table->lock);
  95.199  }
  95.200  
  95.201 @@ -759,8 +753,7 @@ static int
  95.202      struct active_grant_entry *act;
  95.203      s16 rc = GNTST_okay;
  95.204      int retries = 0;
  95.205 -    u16 sflags;
  95.206 -    domid_t sdom;
  95.207 +    union grant_combo scombo, prev_scombo, new_scombo;
  95.208  
  95.209      if ( unlikely(gref >= NR_GRANT_ENTRIES) )
  95.210          PIN_FAIL(error_out, GNTST_bad_gntref,
  95.211 @@ -771,36 +764,42 @@ static int
  95.212  
  95.213      spin_lock(&rd->grant_table->lock);
  95.214      
  95.215 +    /* If already pinned, check the active domid and avoid refcnt overflow. */
  95.216 +    if ( act->pin &&
  95.217 +         ((act->domid != current->domain->domain_id) ||
  95.218 +          (act->pin & 0x80808080U) != 0) )
  95.219 +        PIN_FAIL(unlock_out, GNTST_general_error,
  95.220 +                 "Bad domain (%d != %d), or risk of counter overflow %08x\n",
  95.221 +                 act->domid, current->domain->domain_id, act->pin);
  95.222 +
  95.223      if ( !act->pin ||
  95.224 -         (!readonly && !(act->pin & GNTPIN_hstw_mask)) )
  95.225 +         (!readonly && !(act->pin & (GNTPIN_devw_mask|GNTPIN_hstw_mask))) )
  95.226      {
  95.227 -        sflags = sha->flags;
  95.228 -        sdom = sha->domid;
  95.229 +        scombo.word = *(u32 *)&sha->flags;
  95.230  
  95.231          for ( ; ; )
  95.232          {
  95.233 -            union grant_combo scombo, prev_scombo, new_scombo;
  95.234 +            /* If not already pinned, check the grant domid and type. */
  95.235 +            if ( !act->pin &&
  95.236 +                 (((scombo.shorts.flags & GTF_type_mask) !=
  95.237 +                   GTF_permit_access) ||
  95.238 +                  (scombo.shorts.domid != current->domain->domain_id)) )
  95.239 +                 PIN_FAIL(unlock_out, GNTST_general_error,
  95.240 +                          "Bad flags (%x) or dom (%d). (expected dom %d)\n",
  95.241 +                          scombo.shorts.flags, scombo.shorts.domid,
  95.242 +                          current->domain->domain_id);
  95.243  
  95.244 -            if ( unlikely((sflags & GTF_type_mask) != GTF_permit_access ||
  95.245 -                          sdom != current->domain->domain_id ) )
  95.246 -                PIN_FAIL(unlock_out, GNTST_general_error,
  95.247 -                         "Bad flags (%x) or dom (%d). (NB. expected dom %d)\n",
  95.248 -                         sflags, sdom, current->domain->domain_id);
  95.249 -
  95.250 -            /* Merge two 16-bit values into a 32-bit combined update. */
  95.251 -            scombo.shorts.flags = sflags;
  95.252 -            scombo.shorts.domid = sdom;
  95.253 -            
  95.254              new_scombo = scombo;
  95.255              new_scombo.shorts.flags |= GTF_reading;
  95.256  
  95.257              if ( !readonly )
  95.258              {
  95.259                  new_scombo.shorts.flags |= GTF_writing;
  95.260 -                if ( unlikely(sflags & GTF_readonly) )
  95.261 +                if ( unlikely(scombo.shorts.flags & GTF_readonly) )
  95.262                      PIN_FAIL(unlock_out, GNTST_general_error,
  95.263                               "Attempt to write-pin a r/o grant entry.\n");
  95.264              }
  95.265 +
  95.266              prev_scombo.word = cmpxchg((u32 *)&sha->flags,
  95.267                                         scombo.word, new_scombo.word);
  95.268              if ( likely(prev_scombo.word == scombo.word) )
  95.269 @@ -809,19 +808,16 @@ static int
  95.270              if ( retries++ == 4 )
  95.271                  PIN_FAIL(unlock_out, GNTST_general_error,
  95.272                           "Shared grant entry is unstable.\n");
  95.273 -            sflags = prev_scombo.shorts.flags;
  95.274 -            sdom = prev_scombo.shorts.flags;
  95.275 +
  95.276 +            scombo = prev_scombo;
  95.277          }
  95.278  
  95.279          if ( !act->pin )
  95.280          {
  95.281 -            act->domid = sdom;
  95.282 +            act->domid = scombo.shorts.domid;
  95.283              act->frame = gmfn_to_mfn(rd, sha->frame);
  95.284          }
  95.285      }
  95.286 -    else if ( (act->pin & 0x80808080U) != 0 )
  95.287 -        PIN_FAIL(unlock_out, ENOSPC,
  95.288 -                 "Risk of counter overflow %08x\n", act->pin);
  95.289  
  95.290      act->pin += readonly ? GNTPIN_hstr_inc : GNTPIN_hstw_inc;
  95.291  
    96.1 --- a/xen/common/perfc.c	Mon Sep 18 09:23:51 2006 -0400
    96.2 +++ b/xen/common/perfc.c	Mon Sep 18 14:28:16 2006 -0500
    96.3 @@ -136,8 +136,8 @@ static xen_sysctl_perfc_desc_t perfc_d[N
    96.4  static xen_sysctl_perfc_val_t *perfc_vals;
    96.5  static int               perfc_nbr_vals;
    96.6  static int               perfc_init = 0;
    96.7 -static int perfc_copy_info(XEN_GUEST_HANDLE_64(xen_sysctl_perfc_desc_t) desc,
    96.8 -                           XEN_GUEST_HANDLE_64(xen_sysctl_perfc_val_t) val)
    96.9 +static int perfc_copy_info(XEN_GUEST_HANDLE(xen_sysctl_perfc_desc_t) desc,
   96.10 +                           XEN_GUEST_HANDLE(xen_sysctl_perfc_val_t) val)
   96.11  {
   96.12      unsigned int i, j;
   96.13      unsigned int v = 0;
    97.1 --- a/xen/include/asm-ia64/mm.h	Mon Sep 18 09:23:51 2006 -0400
    97.2 +++ b/xen/include/asm-ia64/mm.h	Mon Sep 18 14:28:16 2006 -0500
    97.3 @@ -451,7 +451,6 @@ extern u64 translate_domain_pte(u64 ptev
    97.4  
    97.5  #define INVALID_M2P_ENTRY        (~0UL)
    97.6  #define VALID_M2P(_e)            (!((_e) & (1UL<<63)))
    97.7 -#define IS_INVALID_M2P_ENTRY(_e) (!VALID_M2P(_e))
    97.8  
    97.9  #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
   97.10  #define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
   97.11 @@ -495,7 +494,7 @@ extern u64 translate_domain_pte(u64 ptev
   97.12      ((gmfn_to_mfn((_d),(gpa)>>PAGE_SHIFT)<<PAGE_SHIFT)|((gpa)&~PAGE_MASK))
   97.13  
   97.14  /* Arch-specific portion of memory_op hypercall. */
   97.15 -#define arch_memory_op(op, arg) (-ENOSYS)
   97.16 +long arch_memory_op(int op, XEN_GUEST_HANDLE(void) arg);
   97.17  
   97.18  int steal_page(
   97.19      struct domain *d, struct page_info *page, unsigned int memflags);
    98.1 --- a/xen/include/asm-ia64/perfc_defn.h	Mon Sep 18 09:23:51 2006 -0400
    98.2 +++ b/xen/include/asm-ia64/perfc_defn.h	Mon Sep 18 14:28:16 2006 -0500
    98.3 @@ -35,6 +35,48 @@ PERFCOUNTER_ARRAY(mov_from_cr,        "p
    98.4  
    98.5  PERFCOUNTER_ARRAY(misc_privop,        "privop misc", 64)
    98.6  
    98.7 +// privileged instructions to fall into vmx_entry
    98.8 +PERFCOUNTER_CPU(vmx_rsm,              "vmx privop rsm")
    98.9 +PERFCOUNTER_CPU(vmx_ssm,              "vmx privop ssm")
   98.10 +PERFCOUNTER_CPU(vmx_mov_to_psr,       "vmx privop mov_to_psr")
   98.11 +PERFCOUNTER_CPU(vmx_mov_from_psr,     "vmx privop mov_from_psr")
   98.12 +PERFCOUNTER_CPU(vmx_mov_from_cr,      "vmx privop mov_from_cr")
   98.13 +PERFCOUNTER_CPU(vmx_mov_to_cr,        "vmx privop mov_to_cr")
   98.14 +PERFCOUNTER_CPU(vmx_bsw0,             "vmx privop bsw0")
   98.15 +PERFCOUNTER_CPU(vmx_bsw1,             "vmx privop bsw1")
   98.16 +PERFCOUNTER_CPU(vmx_cover,            "vmx privop cover")
   98.17 +PERFCOUNTER_CPU(vmx_rfi,              "vmx privop rfi")
   98.18 +PERFCOUNTER_CPU(vmx_itr_d,            "vmx privop itr_d")
   98.19 +PERFCOUNTER_CPU(vmx_itr_i,            "vmx privop itr_i")
   98.20 +PERFCOUNTER_CPU(vmx_ptr_d,            "vmx privop ptr_d")
   98.21 +PERFCOUNTER_CPU(vmx_ptr_i,            "vmx privop ptr_i")
   98.22 +PERFCOUNTER_CPU(vmx_itc_d,            "vmx privop itc_d")
   98.23 +PERFCOUNTER_CPU(vmx_itc_i,            "vmx privop itc_i")
   98.24 +PERFCOUNTER_CPU(vmx_ptc_l,            "vmx privop ptc_l")
   98.25 +PERFCOUNTER_CPU(vmx_ptc_g,            "vmx privop ptc_g")
   98.26 +PERFCOUNTER_CPU(vmx_ptc_ga,           "vmx privop ptc_ga")
   98.27 +PERFCOUNTER_CPU(vmx_ptc_e,            "vmx privop ptc_e")
   98.28 +PERFCOUNTER_CPU(vmx_mov_to_rr,        "vmx privop mov_to_rr")
   98.29 +PERFCOUNTER_CPU(vmx_mov_from_rr,      "vmx privop mov_from_rr")
   98.30 +PERFCOUNTER_CPU(vmx_thash,            "vmx privop thash")
   98.31 +PERFCOUNTER_CPU(vmx_ttag,             "vmx privop ttag")
   98.32 +PERFCOUNTER_CPU(vmx_tpa,              "vmx privop tpa")
   98.33 +PERFCOUNTER_CPU(vmx_tak,              "vmx privop tak")
   98.34 +PERFCOUNTER_CPU(vmx_mov_to_ar_imm,    "vmx privop mov_to_ar_imm")
   98.35 +PERFCOUNTER_CPU(vmx_mov_to_ar_reg,    "vmx privop mov_to_ar_reg")
   98.36 +PERFCOUNTER_CPU(vmx_mov_from_ar_reg,  "vmx privop mov_from_ar_reg")
   98.37 +PERFCOUNTER_CPU(vmx_mov_to_dbr,       "vmx privop mov_to_dbr")
   98.38 +PERFCOUNTER_CPU(vmx_mov_to_ibr,       "vmx privop mov_to_ibr")
   98.39 +PERFCOUNTER_CPU(vmx_mov_to_pmc,       "vmx privop mov_to_pmc")
   98.40 +PERFCOUNTER_CPU(vmx_mov_to_pmd,       "vmx privop mov_to_pmd")
   98.41 +PERFCOUNTER_CPU(vmx_mov_to_pkr,       "vmx privop mov_to_pkr")
   98.42 +PERFCOUNTER_CPU(vmx_mov_from_dbr,     "vmx privop mov_from_dbr")
   98.43 +PERFCOUNTER_CPU(vmx_mov_from_ibr,     "vmx privop mov_from_ibr")
   98.44 +PERFCOUNTER_CPU(vmx_mov_from_pmc,     "vmx privop mov_from_pmc")
   98.45 +PERFCOUNTER_CPU(vmx_mov_from_pkr,     "vmx privop mov_from_pkr")
   98.46 +PERFCOUNTER_CPU(vmx_mov_from_cpuid,   "vmx privop mov_from_cpuid")
   98.47 +
   98.48 +
   98.49  PERFCOUNTER_ARRAY(slow_hyperprivop,   "slow hyperprivops", HYPERPRIVOP_MAX + 1)
   98.50  PERFCOUNTER_ARRAY(fast_hyperprivop,   "fast hyperprivops", HYPERPRIVOP_MAX + 1)
   98.51  
   98.52 @@ -44,6 +86,14 @@ PERFCOUNTER_ARRAY(fast_reflect,       "f
   98.53  PERFSTATUS(vhpt_nbr_entries,          "nbr of entries per VHPT")
   98.54  PERFSTATUS_CPU(vhpt_valid_entries,    "nbr of valid entries in VHPT")
   98.55  
   98.56 +PERFCOUNTER_ARRAY(vmx_mmio_access,    "vmx_mmio_access", 8)
   98.57 +PERFCOUNTER_CPU(vmx_pal_emul,         "vmx_pal_emul")
   98.58 +PERFCOUNTER_ARRAY(vmx_switch_mm_mode, "vmx_switch_mm_mode", 8)
   98.59 +PERFCOUNTER_CPU(vmx_ia64_handle_break,"vmx_ia64_handle_break")
   98.60 +PERFCOUNTER_ARRAY(vmx_inject_guest_interruption,
   98.61 +                                      "vmx_inject_guest_interruption", 0x80)
   98.62 +PERFCOUNTER_ARRAY(fw_hypercall,       "fw_hypercall", 0x20)
   98.63 +
   98.64  #ifdef CONFIG_PRIVOP_ADDRS
   98.65  #ifndef PERFPRIVOPADDR
   98.66  #define PERFPRIVOPADDR(name) \
    99.1 --- a/xen/include/asm-x86/bitops.h	Mon Sep 18 09:23:51 2006 -0400
    99.2 +++ b/xen/include/asm-x86/bitops.h	Mon Sep 18 14:28:16 2006 -0500
    99.3 @@ -7,20 +7,19 @@
    99.4  
    99.5  #include <xen/config.h>
    99.6  
    99.7 -/*
    99.8 - * These have to be done with inline assembly: that way the bit-setting
    99.9 - * is guaranteed to be atomic. All bit operations return 0 if the bit
   99.10 - * was cleared before the operation and != 0 if it was not.
   99.11 - *
   99.12 - * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
   99.13 - */
   99.14 -
   99.15  #ifdef CONFIG_SMP
   99.16  #define LOCK_PREFIX "lock ; "
   99.17  #else
   99.18  #define LOCK_PREFIX ""
   99.19  #endif
   99.20  
   99.21 +/*
   99.22 + * We use the "+m" constraint because the memory operand is both read from
   99.23 + * and written to. Since the operand is in fact a word array, we also
   99.24 + * specify "memory" in the clobbers list to indicate that words other than
   99.25 + * the one directly addressed by the memory operand may be modified.
   99.26 + */
   99.27 +
   99.28  #define ADDR (*(volatile long *) addr)
   99.29  
   99.30  /**
   99.31 @@ -37,8 +36,8 @@ static __inline__ void set_bit(int nr, v
   99.32  {
   99.33  	__asm__ __volatile__( LOCK_PREFIX
   99.34  		"btsl %1,%0"
   99.35 -		:"=m" (ADDR)
   99.36 -		:"dIr" (nr));
   99.37 +		:"+m" (ADDR)
   99.38 +		:"dIr" (nr) : "memory");
   99.39  }
   99.40  
   99.41  /**
   99.42 @@ -54,8 +53,8 @@ static __inline__ void __set_bit(int nr,
   99.43  {
   99.44  	__asm__(
   99.45  		"btsl %1,%0"
   99.46 -		:"=m" (ADDR)
   99.47 -		:"dIr" (nr));
   99.48 +		:"+m" (ADDR)
   99.49 +		:"dIr" (nr) : "memory");
   99.50  }
   99.51  
   99.52  /**
   99.53 @@ -72,8 +71,8 @@ static __inline__ void clear_bit(int nr,
   99.54  {
   99.55  	__asm__ __volatile__( LOCK_PREFIX
   99.56  		"btrl %1,%0"
   99.57 -		:"=m" (ADDR)
   99.58 -		:"dIr" (nr));
   99.59 +		:"+m" (ADDR)
   99.60 +		:"dIr" (nr) : "memory");
   99.61  }
   99.62  
   99.63  /**
   99.64 @@ -89,8 +88,8 @@ static __inline__ void __clear_bit(int n
   99.65  {
   99.66  	__asm__(
   99.67  		"btrl %1,%0"
   99.68 -		:"=m" (ADDR)
   99.69 -		:"dIr" (nr));
   99.70 +		:"+m" (ADDR)
   99.71 +		:"dIr" (nr) : "memory");
   99.72  }
   99.73  
   99.74  #define smp_mb__before_clear_bit()	barrier()
   99.75 @@ -109,8 +108,8 @@ static __inline__ void __change_bit(int 
   99.76  {
   99.77  	__asm__ __volatile__(
   99.78  		"btcl %1,%0"
   99.79 -		:"=m" (ADDR)
   99.80 -		:"dIr" (nr));
   99.81 +		:"+m" (ADDR)
   99.82 +		:"dIr" (nr) : "memory");
   99.83  }
   99.84  
   99.85  /**
   99.86 @@ -126,8 +125,8 @@ static __inline__ void change_bit(int nr
   99.87  {
   99.88  	__asm__ __volatile__( LOCK_PREFIX
   99.89  		"btcl %1,%0"
   99.90 -		:"=m" (ADDR)
   99.91 -		:"dIr" (nr));
   99.92 +		:"+m" (ADDR)
   99.93 +		:"dIr" (nr) : "memory");
   99.94  }
   99.95  
   99.96  /**
   99.97 @@ -144,7 +143,7 @@ static __inline__ int test_and_set_bit(i
   99.98  
   99.99  	__asm__ __volatile__( LOCK_PREFIX
  99.100  		"btsl %2,%1\n\tsbbl %0,%0"
  99.101 -		:"=r" (oldbit),"=m" (ADDR)
  99.102 +		:"=r" (oldbit),"+m" (ADDR)
  99.103  		:"dIr" (nr) : "memory");
  99.104  	return oldbit;
  99.105  }
  99.106 @@ -164,8 +163,8 @@ static __inline__ int __test_and_set_bit
  99.107  
  99.108  	__asm__(
  99.109  		"btsl %2,%1\n\tsbbl %0,%0"
  99.110 -		:"=r" (oldbit),"=m" (ADDR)
  99.111 -		:"dIr" (nr));
  99.112 +		:"=r" (oldbit),"+m" (ADDR)
  99.113 +		:"dIr" (nr) : "memory");
  99.114  	return oldbit;
  99.115  }
  99.116  
  99.117 @@ -183,7 +182,7 @@ static __inline__ int test_and_clear_bit
  99.118  
  99.119  	__asm__ __volatile__( LOCK_PREFIX
  99.120  		"btrl %2,%1\n\tsbbl %0,%0"
  99.121 -		:"=r" (oldbit),"=m" (ADDR)
  99.122 +		:"=r" (oldbit),"+m" (ADDR)
  99.123  		:"dIr" (nr) : "memory");
  99.124  	return oldbit;
  99.125  }
  99.126 @@ -203,8 +202,8 @@ static __inline__ int __test_and_clear_b
  99.127  
  99.128  	__asm__(
  99.129  		"btrl %2,%1\n\tsbbl %0,%0"
  99.130 -		:"=r" (oldbit),"=m" (ADDR)
  99.131 -		:"dIr" (nr));
  99.132 +		:"=r" (oldbit),"+m" (ADDR)
  99.133 +		:"dIr" (nr) : "memory");
  99.134  	return oldbit;
  99.135  }
  99.136  
  99.137 @@ -215,7 +214,7 @@ static __inline__ int __test_and_change_
  99.138  
  99.139  	__asm__ __volatile__(
  99.140  		"btcl %2,%1\n\tsbbl %0,%0"
  99.141 -		:"=r" (oldbit),"=m" (ADDR)
  99.142 +		:"=r" (oldbit),"+m" (ADDR)
  99.143  		:"dIr" (nr) : "memory");
  99.144  	return oldbit;
  99.145  }
  99.146 @@ -234,7 +233,7 @@ static __inline__ int test_and_change_bi
  99.147  
  99.148  	__asm__ __volatile__( LOCK_PREFIX
  99.149  		"btcl %2,%1\n\tsbbl %0,%0"
  99.150 -		:"=r" (oldbit),"=m" (ADDR)
  99.151 +		:"=r" (oldbit),"+m" (ADDR)
  99.152  		:"dIr" (nr) : "memory");
  99.153  	return oldbit;
  99.154  }
  99.155 @@ -242,7 +241,7 @@ static __inline__ int test_and_change_bi
  99.156  
  99.157  static __inline__ int constant_test_bit(int nr, const volatile void * addr)
  99.158  {
  99.159 -	return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
  99.160 +	return ((1U << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
  99.161  }
  99.162  
  99.163  static __inline__ int variable_test_bit(int nr, volatile void * addr)
   100.1 --- a/xen/include/asm-x86/hvm/vlapic.h	Mon Sep 18 09:23:51 2006 -0400
   100.2 +++ b/xen/include/asm-x86/hvm/vlapic.h	Mon Sep 18 14:28:16 2006 -0500
   100.3 @@ -23,12 +23,28 @@
   100.4  #include <asm/msr.h>
   100.5  #include <public/hvm/ioreq.h>
   100.6  
   100.7 -static __inline__ int find_highest_bit(unsigned long *data, int nr_bits)
   100.8 +#define MAX_VECTOR      256
   100.9 +
  100.10 +#define VEC_POS(v) ((v)%32)
  100.11 +#define REG_POS(v) (((v)/32)* 0x10)
  100.12 +#define vlapic_test_and_set_vector(vec, bitmap)                 \
  100.13 +    test_and_set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
  100.14 +#define vlapic_test_and_clear_vector(vec, bitmap)               \
  100.15 +    test_and_clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
  100.16 +#define vlapic_set_vector(vec, bitmap)                          \
  100.17 +    set_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
  100.18 +#define vlapic_clear_vector(vec, bitmap)                        \
  100.19 +    clear_bit(VEC_POS(vec), (bitmap) + REG_POS(vec))
  100.20 +
  100.21 +static inline int vlapic_find_highest_vector(u32 *bitmap)
  100.22  {
  100.23 -    int length = BITS_TO_LONGS(nr_bits);
  100.24 -    while ( length && !data[--length] )
  100.25 +    int word_offset = MAX_VECTOR / 32;
  100.26 +
  100.27 +    /* Work backwards through the bitmap (first 32-bit word in every four). */
  100.28 +    while ( (word_offset != 0) && (bitmap[(--word_offset)*4] == 0) )
  100.29          continue;
  100.30 -    return (fls(data[length]) - 1) + (length * BITS_PER_LONG);
  100.31 +
  100.32 +    return (fls(bitmap[word_offset*4]) - 1) + (word_offset * 32);
  100.33  }
  100.34  
  100.35  #define VLAPIC(v)                       (v->arch.hvm_vcpu.vlapic)
  100.36 @@ -83,8 +99,6 @@ typedef struct direct_intr_info {
  100.37      int source[6];
  100.38  } direct_intr_info_t;
  100.39  
  100.40 -#define MAX_VECTOR      256
  100.41 -
  100.42  struct vlapic {
  100.43      uint32_t           status;
  100.44      uint32_t           vcpu_id;
  100.45 @@ -108,9 +122,9 @@ static inline int vlapic_set_irq(struct 
  100.46  {
  100.47      int ret;
  100.48  
  100.49 -    ret = test_and_set_bit(vec, vlapic->regs + APIC_IRR);
  100.50 +    ret = vlapic_test_and_set_vector(vec, vlapic->regs + APIC_IRR);
  100.51      if ( trig )
  100.52 -        set_bit(vec, vlapic->regs + APIC_TMR);
  100.53 +        vlapic_set_vector(vec, vlapic->regs + APIC_TMR);
  100.54  
  100.55      /* We may need to wake up target vcpu, besides set pending bit here */
  100.56      return ret;
   101.1 --- a/xen/include/asm-x86/mm.h	Mon Sep 18 09:23:51 2006 -0400
   101.2 +++ b/xen/include/asm-x86/mm.h	Mon Sep 18 14:28:16 2006 -0500
   101.3 @@ -338,7 +338,6 @@ int check_descriptor(struct desc_struct 
   101.4  #define machine_to_phys_mapping  ((unsigned long *)RDWR_MPT_VIRT_START)
   101.5  #define INVALID_M2P_ENTRY        (~0UL)
   101.6  #define VALID_M2P(_e)            (!((_e) & (1UL<<(BITS_PER_LONG-1))))
   101.7 -#define IS_INVALID_M2P_ENTRY(_e) (!VALID_M2P(_e))
   101.8  
   101.9  #define set_gpfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn))
  101.10  #define get_gpfn_from_mfn(mfn)      (machine_to_phys_mapping[(mfn)])
   102.1 --- a/xen/include/asm-x86/page.h	Mon Sep 18 09:23:51 2006 -0400
   102.2 +++ b/xen/include/asm-x86/page.h	Mon Sep 18 14:28:16 2006 -0500
   102.3 @@ -300,13 +300,6 @@ void setup_idle_pagetable(void);
   102.4  #define _PAGE_GNTTAB   0
   102.5  #endif
   102.6  
   102.7 -/*
   102.8 - * Disallow unused flag bits plus PAT, PSE and GLOBAL.
   102.9 - * Also disallow GNTTAB if we are using it for grant-table debugging.
  102.10 - * Permit the NX bit if the hardware supports it.
  102.11 - */
  102.12 -#define BASE_DISALLOW_MASK ((0xFFFFF180U | _PAGE_GNTTAB) & ~_PAGE_NX)
  102.13 -
  102.14  #define __PAGE_HYPERVISOR \
  102.15      (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED)
  102.16  #define __PAGE_HYPERVISOR_NOCACHE \
   103.1 --- a/xen/include/asm-x86/processor.h	Mon Sep 18 09:23:51 2006 -0400
   103.2 +++ b/xen/include/asm-x86/processor.h	Mon Sep 18 14:28:16 2006 -0500
   103.3 @@ -290,6 +290,13 @@ static inline void write_cr0(unsigned lo
   103.4  	__asm__("mov %0,%%cr0": :"r" ((unsigned long)val));
   103.5  }
   103.6  
   103.7 +static inline unsigned long read_cr2(void)
   103.8 +{
   103.9 +    unsigned long __cr2;
  103.10 +    __asm__("mov %%cr2,%0\n\t" :"=r" (__cr2));
  103.11 +    return __cr2;
  103.12 +}
  103.13 +
  103.14  static inline unsigned long read_cr4(void)
  103.15  {
  103.16      unsigned long __cr4;
   104.1 --- a/xen/include/asm-x86/x86_32/page-2level.h	Mon Sep 18 09:23:51 2006 -0400
   104.2 +++ b/xen/include/asm-x86/x86_32/page-2level.h	Mon Sep 18 14:28:16 2006 -0500
   104.3 @@ -53,7 +53,4 @@ typedef l2_pgentry_t root_pgentry_t;
   104.4  #define get_pte_flags(x) ((int)(x) & 0xFFF)
   104.5  #define put_pte_flags(x) ((intpte_t)((x) & 0xFFF))
   104.6  
   104.7 -#define L1_DISALLOW_MASK BASE_DISALLOW_MASK
   104.8 -#define L2_DISALLOW_MASK BASE_DISALLOW_MASK
   104.9 -
  104.10  #endif /* __X86_32_PAGE_2LEVEL_H__ */
   105.1 --- a/xen/include/asm-x86/x86_32/page-3level.h	Mon Sep 18 09:23:51 2006 -0400
   105.2 +++ b/xen/include/asm-x86/x86_32/page-3level.h	Mon Sep 18 14:28:16 2006 -0500
   105.3 @@ -66,8 +66,6 @@ typedef l3_pgentry_t root_pgentry_t;
   105.4  #define get_pte_flags(x) (((int)((x) >> 32) & ~0xFFF) | ((int)(x) & 0xFFF))
   105.5  #define put_pte_flags(x) (((intpte_t)((x) & ~0xFFF) << 32) | ((x) & 0xFFF))
   105.6  
   105.7 -#define L1_DISALLOW_MASK BASE_DISALLOW_MASK
   105.8 -#define L2_DISALLOW_MASK BASE_DISALLOW_MASK
   105.9  #define L3_DISALLOW_MASK 0xFFFFF1E6U /* must-be-zero */
  105.10  
  105.11  #endif /* __X86_32_PAGE_3LEVEL_H__ */
   106.1 --- a/xen/include/asm-x86/x86_32/page.h	Mon Sep 18 09:23:51 2006 -0400
   106.2 +++ b/xen/include/asm-x86/x86_32/page.h	Mon Sep 18 14:28:16 2006 -0500
   106.3 @@ -26,6 +26,15 @@ extern unsigned int PAGE_HYPERVISOR_NOCA
   106.4  #define GRANT_PTE_FLAGS \
   106.5      (_PAGE_PRESENT|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_GNTTAB)
   106.6  
   106.7 +/*
   106.8 + * Disallow unused flag bits plus PAT, PSE and GLOBAL.
   106.9 + * Permit the NX bit if the hardware supports it.
  106.10 + */
  106.11 +#define BASE_DISALLOW_MASK (0xFFFFF180U & ~_PAGE_NX)
  106.12 +
  106.13 +#define L1_DISALLOW_MASK (BASE_DISALLOW_MASK | _PAGE_GNTTAB)
  106.14 +#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK)
  106.15 +
  106.16  #endif /* __X86_32_PAGE_H__ */
  106.17  
  106.18  /*
   107.1 --- a/xen/include/asm-x86/x86_64/page.h	Mon Sep 18 09:23:51 2006 -0400
   107.2 +++ b/xen/include/asm-x86/x86_64/page.h	Mon Sep 18 14:28:16 2006 -0500
   107.3 @@ -75,8 +75,15 @@ typedef l4_pgentry_t root_pgentry_t;
   107.4  #define _PAGE_NX_BIT (1U<<23)
   107.5  #define _PAGE_NX     (cpu_has_nx ? _PAGE_NX_BIT : 0U)
   107.6  
   107.7 -#define L1_DISALLOW_MASK BASE_DISALLOW_MASK
   107.8 -#define L2_DISALLOW_MASK BASE_DISALLOW_MASK
   107.9 +/*
  107.10 + * Disallow unused flag bits plus PAT, PSE and GLOBAL.
  107.11 + * Permit the NX bit if the hardware supports it.
  107.12 + * Note that range [62:52] is available for software use on x86/64.
  107.13 + */
  107.14 +#define BASE_DISALLOW_MASK (0xFF000180U & ~_PAGE_NX)
  107.15 +
  107.16 +#define L1_DISALLOW_MASK (BASE_DISALLOW_MASK | _PAGE_GNTTAB)
  107.17 +#define L2_DISALLOW_MASK (BASE_DISALLOW_MASK)
  107.18  #define L3_DISALLOW_MASK (BASE_DISALLOW_MASK | 0x180U /* must-be-zero */)
  107.19  #define L4_DISALLOW_MASK (BASE_DISALLOW_MASK | 0x180U /* must-be-zero */)
  107.20  
   108.1 --- a/xen/include/public/arch-ia64.h	Mon Sep 18 09:23:51 2006 -0400
   108.2 +++ b/xen/include/public/arch-ia64.h	Mon Sep 18 14:28:16 2006 -0500
   108.3 @@ -18,15 +18,12 @@
   108.4  
   108.5  #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
   108.6  #define XEN_GUEST_HANDLE(name)          __guest_handle_ ## name
   108.7 -#define XEN_GUEST_HANDLE_64(name)       __guest_handle_ ## name
   108.8  #define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
   108.9  #ifdef __XEN_TOOLS__
  108.10  #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
  108.11  #endif
  108.12  
  108.13  #ifndef __ASSEMBLY__
  108.14 -typedef uint64_t uint64_aligned_t;
  108.15 -
  108.16  /* Guest handles for primitive C types. */
  108.17  __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
  108.18  __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
   109.1 --- a/xen/include/public/arch-powerpc.h	Mon Sep 18 09:23:51 2006 -0400
   109.2 +++ b/xen/include/public/arch-powerpc.h	Mon Sep 18 14:28:16 2006 -0500
   109.3 @@ -29,7 +29,6 @@
   109.4  
   109.5  #define DEFINE_XEN_GUEST_HANDLE(name) __DEFINE_XEN_GUEST_HANDLE(name, name)
   109.6  #define XEN_GUEST_HANDLE(name)        __guest_handle_ ## name
   109.7 -#define XEN_GUEST_HANDLE_64(name)     __guest_handle_ ## name
   109.8  #define set_xen_guest_handle(hnd, val) \
   109.9      do { \
  109.10          if (sizeof ((hnd).__pad)) \
  109.11 @@ -42,8 +41,6 @@
  109.12  #endif
  109.13  
  109.14  #ifndef __ASSEMBLY__
  109.15 -typedef uint64_t uint64_aligned_t;
  109.16 -
  109.17  /* Guest handles for primitive C types. */
  109.18  __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
  109.19  __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
   110.1 --- a/xen/include/public/arch-x86_32.h	Mon Sep 18 09:23:51 2006 -0400
   110.2 +++ b/xen/include/public/arch-x86_32.h	Mon Sep 18 14:28:16 2006 -0500
   110.3 @@ -28,14 +28,7 @@
   110.4  #endif
   110.5  
   110.6  /* Structural guest handles introduced in 0x00030201. */
   110.7 -#if (defined(__XEN__) || defined(__XEN_TOOLS__)) && !defined(__ASSEMBLY__)
   110.8 -typedef uint64_t __attribute__((aligned(8))) uint64_aligned_t;
   110.9 -#define __DEFINE_XEN_GUEST_HANDLE(name, type)                   \
  110.10 -    typedef struct { type *p; }                                 \
  110.11 -        __guest_handle_ ## name;                                \
  110.12 -    typedef struct { union { type *p; uint64_aligned_t q; }; }  \
  110.13 -        __guest_handle_64_ ## name
  110.14 -#elif __XEN_INTERFACE_VERSION__ >= 0x00030201
  110.15 +#if __XEN_INTERFACE_VERSION__ >= 0x00030201
  110.16  #define __DEFINE_XEN_GUEST_HANDLE(name, type) \
  110.17      typedef struct { type *p; } __guest_handle_ ## name
  110.18  #else
  110.19 @@ -45,15 +38,9 @@ typedef uint64_t __attribute__((aligned(
  110.20  
  110.21  #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
  110.22  #define XEN_GUEST_HANDLE(name)          __guest_handle_ ## name
  110.23 -#define XEN_GUEST_HANDLE_64(name)       __guest_handle_64_ ## name
  110.24 +#define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
  110.25  #ifdef __XEN_TOOLS__
  110.26  #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
  110.27 -#define set_xen_guest_handle(hnd, val)                      \
  110.28 -    do { if ( sizeof(hnd) == 8 ) *(uint64_t *)&(hnd) = 0;   \
  110.29 -         (hnd).p = val;                                     \
  110.30 -    } while ( 0 )
  110.31 -#else
  110.32 -#define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
  110.33  #endif
  110.34  
  110.35  #ifndef __ASSEMBLY__
   111.1 --- a/xen/include/public/arch-x86_64.h	Mon Sep 18 09:23:51 2006 -0400
   111.2 +++ b/xen/include/public/arch-x86_64.h	Mon Sep 18 14:28:16 2006 -0500
   111.3 @@ -39,15 +39,12 @@
   111.4  
   111.5  #define DEFINE_XEN_GUEST_HANDLE(name)   __DEFINE_XEN_GUEST_HANDLE(name, name)
   111.6  #define XEN_GUEST_HANDLE(name)          __guest_handle_ ## name
   111.7 -#define XEN_GUEST_HANDLE_64(name)       __guest_handle_ ## name
   111.8  #define set_xen_guest_handle(hnd, val)  do { (hnd).p = val; } while (0)
   111.9  #ifdef __XEN_TOOLS__
  111.10  #define get_xen_guest_handle(val, hnd)  do { val = (hnd).p; } while (0)
  111.11  #endif
  111.12  
  111.13  #ifndef __ASSEMBLY__
  111.14 -typedef uint64_t uint64_aligned_t;
  111.15 -
  111.16  /* Guest handles for primitive C types. */
  111.17  __DEFINE_XEN_GUEST_HANDLE(uchar, unsigned char);
  111.18  __DEFINE_XEN_GUEST_HANDLE(uint,  unsigned int);
   112.1 --- a/xen/include/public/domctl.h	Mon Sep 18 09:23:51 2006 -0400
   112.2 +++ b/xen/include/public/domctl.h	Mon Sep 18 14:28:16 2006 -0500
   112.3 @@ -16,12 +16,10 @@
   112.4  
   112.5  #include "xen.h"
   112.6  
   112.7 -#define XEN_DOMCTL_INTERFACE_VERSION 0x00000002
   112.8 -
   112.9 -#define uint64_t uint64_aligned_t
  112.10 +#define XEN_DOMCTL_INTERFACE_VERSION 0x00000003
  112.11  
  112.12  struct xenctl_cpumap {
  112.13 -    XEN_GUEST_HANDLE_64(uint8_t) bitmap;
  112.14 +    XEN_GUEST_HANDLE(uint8_t) bitmap;
  112.15      uint32_t nr_cpus;
  112.16  };
  112.17  
  112.18 @@ -76,7 +74,7 @@ struct xen_domctl_getmemlist {
  112.19      uint64_t max_pfns;
  112.20      /* Start index in guest's page list. */
  112.21      uint64_t start_pfn;
  112.22 -    XEN_GUEST_HANDLE_64(xen_pfn_t) buffer;
  112.23 +    XEN_GUEST_HANDLE(xen_pfn_t) buffer;
  112.24      /* OUT variables. */
  112.25      uint64_t num_pfns;
  112.26  };
  112.27 @@ -113,7 +111,7 @@ struct xen_domctl_getpageframeinfo2 {
  112.28      /* IN variables. */
  112.29      uint64_t num;
  112.30      /* IN/OUT variables. */
  112.31 -    XEN_GUEST_HANDLE_64(ulong) array;
  112.32 +    XEN_GUEST_HANDLE(ulong) array;
  112.33  };
  112.34  typedef struct xen_domctl_getpageframeinfo2 xen_domctl_getpageframeinfo2_t;
  112.35  DEFINE_XEN_GUEST_HANDLE(xen_domctl_getpageframeinfo2_t);
  112.36 @@ -187,7 +185,7 @@ struct xen_domctl_shadow_op {
  112.37      uint32_t       mb;       /* Shadow memory allocation in MB */
  112.38  
  112.39      /* OP_PEEK / OP_CLEAN */
  112.40 -    XEN_GUEST_HANDLE_64(ulong) dirty_bitmap;
  112.41 +    XEN_GUEST_HANDLE(ulong) dirty_bitmap;
  112.42      uint64_t       pages;    /* Size of buffer. Updated with actual size. */
  112.43      struct xen_domctl_shadow_op_stats stats;
  112.44  };
  112.45 @@ -207,8 +205,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_max_m
  112.46  #define XEN_DOMCTL_setvcpucontext    12
  112.47  #define XEN_DOMCTL_getvcpucontext    13
  112.48  struct xen_domctl_vcpucontext {
  112.49 -    uint32_t              vcpu;                     /* IN */
  112.50 -    XEN_GUEST_HANDLE_64(vcpu_guest_context_t) ctxt; /* IN/OUT */
  112.51 +    uint32_t              vcpu;                  /* IN */
  112.52 +    XEN_GUEST_HANDLE(vcpu_guest_context_t) ctxt; /* IN/OUT */
  112.53  };
  112.54  typedef struct xen_domctl_vcpucontext xen_domctl_vcpucontext_t;
  112.55  DEFINE_XEN_GUEST_HANDLE(xen_domctl_vcpucontext_t);
  112.56 @@ -381,8 +379,6 @@ struct xen_domctl {
  112.57  typedef struct xen_domctl xen_domctl_t;
  112.58  DEFINE_XEN_GUEST_HANDLE(xen_domctl_t);
  112.59  
  112.60 -#undef uint64_t
  112.61 -
  112.62  #endif /* __XEN_PUBLIC_DOMCTL_H__ */
  112.63  
  112.64  /*
   113.1 --- a/xen/include/public/sysctl.h	Mon Sep 18 09:23:51 2006 -0400
   113.2 +++ b/xen/include/public/sysctl.h	Mon Sep 18 14:28:16 2006 -0500
   113.3 @@ -16,9 +16,7 @@
   113.4  #include "xen.h"
   113.5  #include "domctl.h"
   113.6  
   113.7 -#define XEN_SYSCTL_INTERFACE_VERSION 0x00000001
   113.8 -
   113.9 -#define uint64_t uint64_aligned_t
  113.10 +#define XEN_SYSCTL_INTERFACE_VERSION 0x00000002
  113.11  
  113.12  /*
  113.13   * Read console content from Xen buffer ring.
  113.14 @@ -26,8 +24,8 @@
  113.15  #define XEN_SYSCTL_readconsole       1
  113.16  struct xen_sysctl_readconsole {
  113.17      /* IN variables. */
  113.18 -    uint32_t clear;                   /* Non-zero -> clear after reading. */
  113.19 -    XEN_GUEST_HANDLE_64(char) buffer; /* Buffer start */
  113.20 +    uint32_t clear;                /* Non-zero -> clear after reading. */
  113.21 +    XEN_GUEST_HANDLE(char) buffer; /* Buffer start */
  113.22      /* IN/OUT variables. */
  113.23      uint32_t count;            /* In: Buffer size;  Out: Used buffer size  */
  113.24  };
  113.25 @@ -105,9 +103,9 @@ struct xen_sysctl_perfc_op {
  113.26      uint32_t       nr_counters;       /*  number of counters description  */
  113.27      uint32_t       nr_vals;			  /*  number of values  */
  113.28      /* counter information (or NULL) */
  113.29 -    XEN_GUEST_HANDLE_64(xen_sysctl_perfc_desc_t) desc;
  113.30 +    XEN_GUEST_HANDLE(xen_sysctl_perfc_desc_t) desc;
  113.31      /* counter values (or NULL) */
  113.32 -    XEN_GUEST_HANDLE_64(xen_sysctl_perfc_val_t) val;
  113.33 +    XEN_GUEST_HANDLE(xen_sysctl_perfc_val_t) val;
  113.34  };
  113.35  typedef struct xen_sysctl_perfc_op xen_sysctl_perfc_op_t;
  113.36  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_perfc_op_t);
  113.37 @@ -117,7 +115,7 @@ struct xen_sysctl_getdomaininfolist {
  113.38      /* IN variables. */
  113.39      domid_t               first_domain;
  113.40      uint32_t              max_domains;
  113.41 -    XEN_GUEST_HANDLE_64(xen_domctl_getdomaininfo_t) buffer;
  113.42 +    XEN_GUEST_HANDLE(xen_domctl_getdomaininfo_t) buffer;
  113.43      /* OUT variables. */
  113.44      uint32_t              num_domains;
  113.45  };
  113.46 @@ -140,8 +138,6 @@ struct xen_sysctl {
  113.47  typedef struct xen_sysctl xen_sysctl_t;
  113.48  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_t);
  113.49  
  113.50 -#undef uint64_t
  113.51 -
  113.52  #endif /* __XEN_PUBLIC_SYSCTL_H__ */
  113.53  
  113.54  /*
   114.1 --- a/xen/include/public/xenoprof.h	Mon Sep 18 09:23:51 2006 -0400
   114.2 +++ b/xen/include/public/xenoprof.h	Mon Sep 18 14:28:16 2006 -0500
   114.3 @@ -28,6 +28,8 @@
   114.4  #define XENOPROF_disable_virq       11
   114.5  #define XENOPROF_release_counters   12
   114.6  #define XENOPROF_shutdown           13
   114.7 +#define XENOPROF_get_buffer         14
   114.8 +#define XENOPROF_last_op            14
   114.9  
  114.10  #define MAX_OPROF_EVENTS    32
  114.11  #define MAX_OPROF_DOMAINS   25	
  114.12 @@ -56,17 +58,22 @@ typedef struct xenoprof_buf xenoprof_buf
  114.13  DEFINE_XEN_GUEST_HANDLE(xenoprof_buf_t);
  114.14  
  114.15  struct xenoprof_init {
  114.16 -    int32_t  max_samples;
  114.17      int32_t  num_events;
  114.18      int32_t  is_primary;
  114.19 -    int32_t  nbuf;
  114.20 -    int32_t  bufsize;
  114.21 -    uint64_t buf_maddr;
  114.22      char cpu_type[XENOPROF_CPU_TYPE_SIZE];
  114.23  };
  114.24  typedef struct xenoprof_init xenoprof_init_t;
  114.25  DEFINE_XEN_GUEST_HANDLE(xenoprof_init_t);
  114.26  
  114.27 +struct xenoprof_get_buffer {
  114.28 +    int32_t  max_samples;
  114.29 +    int32_t  nbuf;
  114.30 +    int32_t  bufsize;
  114.31 +    uint64_t buf_maddr;
  114.32 +};
  114.33 +typedef struct xenoprof_get_buffer xenoprof_get_buffer_t;
  114.34 +DEFINE_XEN_GUEST_HANDLE(xenoprof_get_buffer_t);
  114.35 +
  114.36  struct xenoprof_counter {
  114.37      uint32_t ind;
  114.38      uint64_t count;
   115.1 --- a/xen/include/xen/compiler.h	Mon Sep 18 09:23:51 2006 -0400
   115.2 +++ b/xen/include/xen/compiler.h	Mon Sep 18 14:28:16 2006 -0500
   115.3 @@ -35,6 +35,11 @@
   115.4  #define offsetof(a,b) ((unsigned long)&(((a *)0)->b))
   115.5  #endif
   115.6  
   115.7 +#if defined(__x86_64__) && (__GNUC__ > 3)
   115.8 +/* Results in more efficient PIC code (no indirections through GOT or PLT). */
   115.9 +#pragma GCC visibility push(hidden)
  115.10 +#endif
  115.11 +
  115.12  /* This macro obfuscates arithmetic on a variable address so that gcc
  115.13     shouldn't recognize the original var, and make assumptions about it */
  115.14  /*