ia64/xen-unstable

changeset 6256:11f556cac45b

merge?
author cl349@firebug.cl.cam.ac.uk
date Thu Aug 18 18:55:13 2005 +0000 (2005-08-18)
parents 9471090bb8ec 978ce7f6a3eb
children 6d8c80499148
files linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/i386/mm/init.c linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/hypervisor.h linux-2.6-xen-sparse/include/asm-xen/xenbus.h tools/examples/network-bridge tools/python/xen/xm/create.py tools/python/xen/xm/main.py xen/arch/x86/mm.c xen/arch/x86/setup.c xen/arch/x86/traps.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/traps.c xen/drivers/char/console.c xen/include/asm-x86/e820.h xen/include/asm-x86/uaccess.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Thu Aug 18 18:54:38 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Thu Aug 18 18:55:13 2005 +0000
     1.3 @@ -541,7 +541,7 @@ CONFIG_IP_NF_MATCH_IPRANGE=m
     1.4  # CONFIG_IP_NF_MATCH_STATE is not set
     1.5  # CONFIG_IP_NF_MATCH_CONNTRACK is not set
     1.6  # CONFIG_IP_NF_MATCH_OWNER is not set
     1.7 -# CONFIG_IP_NF_MATCH_PHYSDEV is not set
     1.8 +CONFIG_IP_NF_MATCH_PHYSDEV=y
     1.9  # CONFIG_IP_NF_MATCH_ADDRTYPE is not set
    1.10  # CONFIG_IP_NF_MATCH_REALM is not set
    1.11  # CONFIG_IP_NF_MATCH_SCTP is not set
    1.12 @@ -689,7 +689,7 @@ CONFIG_E1000=y
    1.13  # CONFIG_HAMACHI is not set
    1.14  # CONFIG_YELLOWFIN is not set
    1.15  # CONFIG_R8169 is not set
    1.16 -# CONFIG_SK98LIN is not set
    1.17 +CONFIG_SK98LIN=y
    1.18  # CONFIG_VIA_VELOCITY is not set
    1.19  CONFIG_TIGON3=y
    1.20  # CONFIG_BNX2 is not set
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Thu Aug 18 18:54:38 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Thu Aug 18 18:55:13 2005 +0000
     2.3 @@ -480,7 +480,7 @@ CONFIG_IP_NF_MATCH_IPRANGE=m
     2.4  # CONFIG_IP_NF_MATCH_STATE is not set
     2.5  # CONFIG_IP_NF_MATCH_CONNTRACK is not set
     2.6  # CONFIG_IP_NF_MATCH_OWNER is not set
     2.7 -# CONFIG_IP_NF_MATCH_PHYSDEV is not set
     2.8 +CONFIG_IP_NF_MATCH_PHYSDEV=y
     2.9  # CONFIG_IP_NF_MATCH_ADDRTYPE is not set
    2.10  # CONFIG_IP_NF_MATCH_REALM is not set
    2.11  # CONFIG_IP_NF_MATCH_SCTP is not set
    2.12 @@ -611,7 +611,7 @@ CONFIG_E1000=y
    2.13  # CONFIG_HAMACHI is not set
    2.14  # CONFIG_YELLOWFIN is not set
    2.15  # CONFIG_R8169 is not set
    2.16 -# CONFIG_SK98LIN is not set
    2.17 +CONFIG_SK98LIN=y
    2.18  # CONFIG_VIA_VELOCITY is not set
    2.19  CONFIG_TIGON3=y
    2.20  # CONFIG_BNX2 is not set
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Thu Aug 18 18:54:38 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Thu Aug 18 18:55:13 2005 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4  #
     3.5  # Automatically generated make config: don't edit
     3.6 -# Linux kernel version: 2.6.12.4-xenU
     3.7 -# Mon Aug 15 19:25:22 2005
     3.8 +# Linux kernel version: 2.6.12-xenU
     3.9 +# Thu Aug 18 11:15:14 2005
    3.10  #
    3.11  CONFIG_XEN=y
    3.12  CONFIG_ARCH_XEN=y
    3.13 @@ -270,7 +270,10 @@ CONFIG_IP_ROUTE_FWMARK=y
    3.14  CONFIG_IP_ROUTE_MULTIPATH=y
    3.15  # CONFIG_IP_ROUTE_MULTIPATH_CACHED is not set
    3.16  CONFIG_IP_ROUTE_VERBOSE=y
    3.17 -# CONFIG_IP_PNP is not set
    3.18 +CONFIG_IP_PNP=y
    3.19 +CONFIG_IP_PNP_DHCP=y
    3.20 +CONFIG_IP_PNP_BOOTP=y
    3.21 +CONFIG_IP_PNP_RARP=y
    3.22  CONFIG_NET_IPIP=m
    3.23  CONFIG_NET_IPGRE=m
    3.24  CONFIG_NET_IPGRE_BROADCAST=y
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile	Thu Aug 18 18:54:38 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile	Thu Aug 18 18:55:13 2005 +0000
     4.3 @@ -44,7 +44,7 @@ c-obj-$(CONFIG_HPET_TIMER) 	+= time_hpet
     4.4  c-obj-$(CONFIG_EFI) 		+= efi.o efi_stub.o
     4.5  c-obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
     4.6  c-obj-$(CONFIG_SMP_ALTERNATIVES)+= smpalts.o
     4.7 -c-obj-$(CONFIG_SWIOTLB)		+= swiotlb.o
     4.8 +obj-$(CONFIG_SWIOTLB)		+= swiotlb.o
     4.9  
    4.10  EXTRA_AFLAGS   := -traditional
    4.11  
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c	Thu Aug 18 18:54:38 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c	Thu Aug 18 18:55:13 2005 +0000
     5.3 @@ -115,9 +115,6 @@ EXPORT_SYMBOL(__copy_from_user_ll);
     5.4  EXPORT_SYMBOL(__copy_to_user_ll);
     5.5  EXPORT_SYMBOL(strnlen_user);
     5.6  
     5.7 -EXPORT_SYMBOL(dma_alloc_coherent);
     5.8 -EXPORT_SYMBOL(dma_free_coherent);
     5.9 -
    5.10  #ifdef CONFIG_PCI
    5.11  EXPORT_SYMBOL(pci_mem_start);
    5.12  #endif
     6.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Thu Aug 18 18:54:38 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Thu Aug 18 18:55:13 2005 +0000
     6.3 @@ -24,13 +24,14 @@ struct dma_coherent_mem {
     6.4  	unsigned long	*bitmap;
     6.5  };
     6.6  
     6.7 -static void iommu_bug(void)
     6.8 -{
     6.9 -	printk(KERN_ALERT "Fatal DMA error! Please use 'swiotlb=force'\n");
    6.10 -	BUG();
    6.11 -}
    6.12 -
    6.13 -#define IOMMU_BUG_ON(test) do { if (unlikely(test)) iommu_bug(); } while(0)
    6.14 +#define IOMMU_BUG_ON(test)				\
    6.15 +do {							\
    6.16 +	if (unlikely(test)) {				\
    6.17 +		printk(KERN_ALERT "Fatal DMA error! "	\
    6.18 +		       "Please use 'swiotlb=force'\n");	\
    6.19 +		BUG();					\
    6.20 +	}						\
    6.21 +} while (0)
    6.22  
    6.23  int
    6.24  dma_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c	Thu Aug 18 18:54:38 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c	Thu Aug 18 18:55:13 2005 +0000
     7.3 @@ -49,13 +49,14 @@ int swiotlb_force;
     7.4   * swiotlb_sync_single_*, to see if the memory was in fact allocated by this
     7.5   * API.
     7.6   */
     7.7 -static char *io_tlb_start, *io_tlb_end;
     7.8 +static char *iotlb_virt_start, *iotlb_virt_end;
     7.9 +static dma_addr_t iotlb_bus_start, iotlb_bus_end;
    7.10  
    7.11  /*
    7.12 - * The number of IO TLB blocks (in groups of 64) betweeen io_tlb_start and
    7.13 - * io_tlb_end.  This is command line adjustable via setup_io_tlb_npages.
    7.14 + * The number of IO TLB blocks (in groups of 64) betweeen iotlb_virt_start and
    7.15 + * iotlb_virt_end.  This is command line adjustable via setup_io_tlb_npages.
    7.16   */
    7.17 -static unsigned long io_tlb_nslabs;
    7.18 +static unsigned long iotlb_nslabs;
    7.19  
    7.20  /*
    7.21   * When the IOMMU overflows we return a fallback buffer. This sets the size.
    7.22 @@ -88,11 +89,14 @@ static DEFINE_SPINLOCK(io_tlb_lock);
    7.23  static int __init
    7.24  setup_io_tlb_npages(char *str)
    7.25  {
    7.26 +	/* Unlike ia64, the size is aperture in megabytes, not 'slabs'! */
    7.27  	if (isdigit(*str)) {
    7.28 -		io_tlb_nslabs = simple_strtoul(str, &str, 0) <<
    7.29 -			(PAGE_SHIFT - IO_TLB_SHIFT);
    7.30 -		/* avoid tail segment of size < IO_TLB_SEGSIZE */
    7.31 -		io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
    7.32 +		iotlb_nslabs = simple_strtoul(str, &str, 0) <<
    7.33 +			(20 - IO_TLB_SHIFT);
    7.34 +		iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE);
    7.35 +		/* Round up to power of two (xen_create_contiguous_region). */
    7.36 +		while (iotlb_nslabs & (iotlb_nslabs-1))
    7.37 +			iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1);
    7.38  	}
    7.39  	if (*str == ',')
    7.40  		++str;
    7.41 @@ -114,45 +118,55 @@ setup_io_tlb_npages(char *str)
    7.42  void
    7.43  swiotlb_init_with_default_size (size_t default_size)
    7.44  {
    7.45 -	unsigned long i;
    7.46 +	unsigned long i, bytes;
    7.47  
    7.48 -	if (!io_tlb_nslabs) {
    7.49 -		io_tlb_nslabs = (default_size >> PAGE_SHIFT);
    7.50 -		io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
    7.51 +	if (!iotlb_nslabs) {
    7.52 +		iotlb_nslabs = (default_size >> IO_TLB_SHIFT);
    7.53 +		iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE);
    7.54 +		/* Round up to power of two (xen_create_contiguous_region). */
    7.55 +		while (iotlb_nslabs & (iotlb_nslabs-1))
    7.56 +			iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1);
    7.57  	}
    7.58  
    7.59 +	bytes = iotlb_nslabs * (1UL << IO_TLB_SHIFT);
    7.60 +
    7.61  	/*
    7.62  	 * Get IO TLB memory from the low pages
    7.63  	 */
    7.64 -	io_tlb_start = alloc_bootmem_low_pages(io_tlb_nslabs *
    7.65 -					       (1 << IO_TLB_SHIFT));
    7.66 -	if (!io_tlb_start)
    7.67 +	iotlb_virt_start = alloc_bootmem_low_pages(bytes);
    7.68 +	if (!iotlb_virt_start)
    7.69  		panic("Cannot allocate SWIOTLB buffer");
    7.70  
    7.71  	xen_create_contiguous_region(
    7.72 -		(unsigned long)io_tlb_start, 
    7.73 -		get_order(io_tlb_nslabs * (1 << IO_TLB_SHIFT)));
    7.74 +		(unsigned long)iotlb_virt_start, get_order(bytes));
    7.75  
    7.76 -	io_tlb_end = io_tlb_start + io_tlb_nslabs * (1 << IO_TLB_SHIFT);
    7.77 +	iotlb_virt_end = iotlb_virt_start + bytes;
    7.78  
    7.79  	/*
    7.80  	 * Allocate and initialize the free list array.  This array is used
    7.81  	 * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
    7.82 -	 * between io_tlb_start and io_tlb_end.
    7.83 +	 * between iotlb_virt_start and iotlb_virt_end.
    7.84  	 */
    7.85 -	io_tlb_list = alloc_bootmem(io_tlb_nslabs * sizeof(int));
    7.86 -	for (i = 0; i < io_tlb_nslabs; i++)
    7.87 +	io_tlb_list = alloc_bootmem(iotlb_nslabs * sizeof(int));
    7.88 +	for (i = 0; i < iotlb_nslabs; i++)
    7.89   		io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
    7.90  	io_tlb_index = 0;
    7.91  	io_tlb_orig_addr = alloc_bootmem(
    7.92 -		io_tlb_nslabs * sizeof(*io_tlb_orig_addr));
    7.93 +		iotlb_nslabs * sizeof(*io_tlb_orig_addr));
    7.94  
    7.95  	/*
    7.96  	 * Get the overflow emergency buffer
    7.97  	 */
    7.98  	io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
    7.99 -	printk(KERN_INFO "Placing software IO TLB between 0x%lx - 0x%lx\n",
   7.100 -	       virt_to_bus(io_tlb_start), virt_to_bus(io_tlb_end-1));
   7.101 +	iotlb_bus_start = virt_to_bus(iotlb_virt_start);
   7.102 +	iotlb_bus_end   = iotlb_bus_start + bytes;
   7.103 +	printk(KERN_INFO "Software IO TLB enabled: \n"
   7.104 +	       " Aperture:     %lu megabytes\n"
   7.105 +	       " Bus range:    0x%016lx - 0x%016lx\n"
   7.106 +	       " Kernel range: 0x%016lx - 0x%016lx\n",
   7.107 +	       bytes >> 20,
   7.108 +	       (unsigned long)iotlb_bus_start, (unsigned long)iotlb_bus_end,
   7.109 +	       (unsigned long)iotlb_virt_start, (unsigned long)iotlb_virt_end);
   7.110  }
   7.111  
   7.112  void
   7.113 @@ -240,7 +254,7 @@ map_single(struct device *hwdev, struct 
   7.114  	{
   7.115  		wrap = index = ALIGN(io_tlb_index, stride);
   7.116  
   7.117 -		if (index >= io_tlb_nslabs)
   7.118 +		if (index >= iotlb_nslabs)
   7.119  			wrap = index = 0;
   7.120  
   7.121  		do {
   7.122 @@ -260,7 +274,7 @@ map_single(struct device *hwdev, struct 
   7.123  				      IO_TLB_SEGSIZE -1) && io_tlb_list[i];
   7.124  				     i--)
   7.125  					io_tlb_list[i] = ++count;
   7.126 -				dma_addr = io_tlb_start +
   7.127 +				dma_addr = iotlb_virt_start +
   7.128  					(index << IO_TLB_SHIFT);
   7.129  
   7.130  				/*
   7.131 @@ -268,13 +282,13 @@ map_single(struct device *hwdev, struct 
   7.132  				 * the next round.
   7.133  				 */
   7.134  				io_tlb_index = 
   7.135 -					((index + nslots) < io_tlb_nslabs
   7.136 +					((index + nslots) < iotlb_nslabs
   7.137  					 ? (index + nslots) : 0);
   7.138  
   7.139  				goto found;
   7.140  			}
   7.141  			index += stride;
   7.142 -			if (index >= io_tlb_nslabs)
   7.143 +			if (index >= iotlb_nslabs)
   7.144  				index = 0;
   7.145  		} while (index != wrap);
   7.146  
   7.147 @@ -304,7 +318,7 @@ unmap_single(struct device *hwdev, char 
   7.148  {
   7.149  	unsigned long flags;
   7.150  	int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
   7.151 -	int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT;
   7.152 +	int index = (dma_addr - iotlb_virt_start) >> IO_TLB_SHIFT;
   7.153  	struct phys_addr buffer = io_tlb_orig_addr[index];
   7.154  
   7.155  	/*
   7.156 @@ -345,7 +359,7 @@ unmap_single(struct device *hwdev, char 
   7.157  static void
   7.158  sync_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
   7.159  {
   7.160 -	int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT;
   7.161 +	int index = (dma_addr - iotlb_virt_start) >> IO_TLB_SHIFT;
   7.162  	struct phys_addr buffer = io_tlb_orig_addr[index];
   7.163  	BUG_ON((dir != DMA_FROM_DEVICE) && (dir != DMA_TO_DEVICE));
   7.164  	__sync_single(buffer, dma_addr, size, dir);
   7.165 @@ -431,11 +445,9 @@ void
   7.166  swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size,
   7.167  		     int dir)
   7.168  {
   7.169 -	char *dma_addr = bus_to_virt(dev_addr);
   7.170 -
   7.171  	BUG_ON(dir == DMA_NONE);
   7.172 -	if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
   7.173 -		unmap_single(hwdev, dma_addr, size, dir);
   7.174 +	if ((dev_addr >= iotlb_bus_start) && (dev_addr < iotlb_bus_end))
   7.175 +		unmap_single(hwdev, bus_to_virt(dev_addr), size, dir);
   7.176  }
   7.177  
   7.178  /*
   7.179 @@ -452,22 +464,18 @@ void
   7.180  swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
   7.181  			    size_t size, int dir)
   7.182  {
   7.183 -	char *dma_addr = bus_to_virt(dev_addr);
   7.184 -
   7.185  	BUG_ON(dir == DMA_NONE);
   7.186 -	if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
   7.187 -		sync_single(hwdev, dma_addr, size, dir);
   7.188 +	if ((dev_addr >= iotlb_bus_start) && (dev_addr < iotlb_bus_end))
   7.189 +		sync_single(hwdev, bus_to_virt(dev_addr), size, dir);
   7.190  }
   7.191  
   7.192  void
   7.193  swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
   7.194  			       size_t size, int dir)
   7.195  {
   7.196 -	char *dma_addr = bus_to_virt(dev_addr);
   7.197 -
   7.198  	BUG_ON(dir == DMA_NONE);
   7.199 -	if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
   7.200 -		sync_single(hwdev, dma_addr, size, dir);
   7.201 +	if ((dev_addr >= iotlb_bus_start) && (dev_addr < iotlb_bus_end))
   7.202 +		sync_single(hwdev, bus_to_virt(dev_addr), size, dir);
   7.203  }
   7.204  
   7.205  /*
   7.206 @@ -603,11 +611,9 @@ void
   7.207  swiotlb_unmap_page(struct device *hwdev, dma_addr_t dma_address,
   7.208  		   size_t size, enum dma_data_direction direction)
   7.209  {
   7.210 -	char *dma_addr = bus_to_virt(dma_address);
   7.211 -
   7.212  	BUG_ON(direction == DMA_NONE);
   7.213 -	if (dma_addr >= io_tlb_start && dma_addr < io_tlb_end)
   7.214 -		unmap_single(hwdev, dma_addr, size, direction);
   7.215 +	if ((dma_address >= iotlb_bus_start) && (dma_address < iotlb_bus_end))
   7.216 +		unmap_single(hwdev, bus_to_virt(dma_address), size, direction);
   7.217  }
   7.218  
   7.219  int
     8.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Thu Aug 18 18:54:38 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Thu Aug 18 18:55:13 2005 +0000
     8.3 @@ -35,6 +35,7 @@
     8.4  #include <asm/pgtable.h>
     8.5  #include <asm-xen/hypervisor.h>
     8.6  #include <asm-xen/balloon.h>
     8.7 +#include <linux/module.h>
     8.8  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
     8.9  #include <linux/percpu.h>
    8.10  #include <asm/tlbflush.h>
    8.11 @@ -58,124 +59,124 @@
    8.12  #ifndef CONFIG_XEN_SHADOW_MODE
    8.13  void xen_l1_entry_update(pte_t *ptr, pte_t val)
    8.14  {
    8.15 -    mmu_update_t u;
    8.16 -    u.ptr = virt_to_machine(ptr);
    8.17 -    u.val = pte_val_ma(val);
    8.18 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.19 +	mmu_update_t u;
    8.20 +	u.ptr = virt_to_machine(ptr);
    8.21 +	u.val = pte_val_ma(val);
    8.22 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.23  }
    8.24  
    8.25  void xen_l2_entry_update(pmd_t *ptr, pmd_t val)
    8.26  {
    8.27 -    mmu_update_t u;
    8.28 -    u.ptr = virt_to_machine(ptr);
    8.29 -    u.val = pmd_val_ma(val);
    8.30 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.31 +	mmu_update_t u;
    8.32 +	u.ptr = virt_to_machine(ptr);
    8.33 +	u.val = pmd_val_ma(val);
    8.34 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.35  }
    8.36  
    8.37  #ifdef CONFIG_X86_PAE
    8.38  void xen_l3_entry_update(pud_t *ptr, pud_t val)
    8.39  {
    8.40 -    mmu_update_t u;
    8.41 -    u.ptr = virt_to_machine(ptr);
    8.42 -    u.val = pud_val_ma(val);
    8.43 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.44 +	mmu_update_t u;
    8.45 +	u.ptr = virt_to_machine(ptr);
    8.46 +	u.val = pud_val_ma(val);
    8.47 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.48  }
    8.49  #endif
    8.50  
    8.51  #ifdef CONFIG_X86_64
    8.52  void xen_l3_entry_update(pud_t *ptr, pud_t val)
    8.53  {
    8.54 -    mmu_update_t u;
    8.55 -    u.ptr = virt_to_machine(ptr);
    8.56 -    u.val = val.pud;
    8.57 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.58 +	mmu_update_t u;
    8.59 +	u.ptr = virt_to_machine(ptr);
    8.60 +	u.val = val.pud;
    8.61 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.62  }
    8.63  
    8.64  void xen_l4_entry_update(pgd_t *ptr, pgd_t val)
    8.65  {
    8.66 -    mmu_update_t u;
    8.67 -    u.ptr = virt_to_machine(ptr);
    8.68 -    u.val = val.pgd;
    8.69 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.70 +	mmu_update_t u;
    8.71 +	u.ptr = virt_to_machine(ptr);
    8.72 +	u.val = val.pgd;
    8.73 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.74  }
    8.75  #endif /* CONFIG_X86_64 */
    8.76  #endif /* CONFIG_XEN_SHADOW_MODE */
    8.77  
    8.78  void xen_machphys_update(unsigned long mfn, unsigned long pfn)
    8.79  {
    8.80 -    mmu_update_t u;
    8.81 -    u.ptr = (mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
    8.82 -    u.val = pfn;
    8.83 -    BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.84 +	mmu_update_t u;
    8.85 +	u.ptr = (mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
    8.86 +	u.val = pfn;
    8.87 +	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    8.88  }
    8.89  
    8.90  void xen_pt_switch(unsigned long ptr)
    8.91  {
    8.92 -    struct mmuext_op op;
    8.93 -    op.cmd = MMUEXT_NEW_BASEPTR;
    8.94 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
    8.95 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
    8.96 +	struct mmuext_op op;
    8.97 +	op.cmd = MMUEXT_NEW_BASEPTR;
    8.98 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
    8.99 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.100  }
   8.101  
   8.102  void xen_new_user_pt(unsigned long ptr)
   8.103  {
   8.104 -    struct mmuext_op op;
   8.105 -    op.cmd = MMUEXT_NEW_USER_BASEPTR;
   8.106 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.107 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.108 +	struct mmuext_op op;
   8.109 +	op.cmd = MMUEXT_NEW_USER_BASEPTR;
   8.110 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.111 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.112  }
   8.113  
   8.114  void xen_tlb_flush(void)
   8.115  {
   8.116 -    struct mmuext_op op;
   8.117 -    op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
   8.118 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.119 +	struct mmuext_op op;
   8.120 +	op.cmd = MMUEXT_TLB_FLUSH_LOCAL;
   8.121 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.122  }
   8.123  
   8.124  void xen_invlpg(unsigned long ptr)
   8.125  {
   8.126 -    struct mmuext_op op;
   8.127 -    op.cmd = MMUEXT_INVLPG_LOCAL;
   8.128 -    op.linear_addr = ptr & PAGE_MASK;
   8.129 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.130 +	struct mmuext_op op;
   8.131 +	op.cmd = MMUEXT_INVLPG_LOCAL;
   8.132 +	op.linear_addr = ptr & PAGE_MASK;
   8.133 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.134  }
   8.135  
   8.136  #ifdef CONFIG_SMP
   8.137  
   8.138  void xen_tlb_flush_all(void)
   8.139  {
   8.140 -    struct mmuext_op op;
   8.141 -    op.cmd = MMUEXT_TLB_FLUSH_ALL;
   8.142 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.143 +	struct mmuext_op op;
   8.144 +	op.cmd = MMUEXT_TLB_FLUSH_ALL;
   8.145 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.146  }
   8.147  
   8.148  void xen_tlb_flush_mask(cpumask_t *mask)
   8.149  {
   8.150 -    struct mmuext_op op;
   8.151 -    if ( cpus_empty(*mask) )
   8.152 -        return;
   8.153 -    op.cmd = MMUEXT_TLB_FLUSH_MULTI;
   8.154 -    op.vcpumask = mask->bits;
   8.155 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.156 +	struct mmuext_op op;
   8.157 +	if ( cpus_empty(*mask) )
   8.158 +		return;
   8.159 +	op.cmd = MMUEXT_TLB_FLUSH_MULTI;
   8.160 +	op.vcpumask = mask->bits;
   8.161 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.162  }
   8.163  
   8.164  void xen_invlpg_all(unsigned long ptr)
   8.165  {
   8.166 -    struct mmuext_op op;
   8.167 -    op.cmd = MMUEXT_INVLPG_ALL;
   8.168 -    op.linear_addr = ptr & PAGE_MASK;
   8.169 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.170 +	struct mmuext_op op;
   8.171 +	op.cmd = MMUEXT_INVLPG_ALL;
   8.172 +	op.linear_addr = ptr & PAGE_MASK;
   8.173 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.174  }
   8.175  
   8.176  void xen_invlpg_mask(cpumask_t *mask, unsigned long ptr)
   8.177  {
   8.178 -    struct mmuext_op op;
   8.179 -    if ( cpus_empty(*mask) )
   8.180 -        return;
   8.181 -    op.cmd = MMUEXT_INVLPG_MULTI;
   8.182 -    op.vcpumask = mask->bits;
   8.183 -    op.linear_addr = ptr & PAGE_MASK;
   8.184 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.185 +	struct mmuext_op op;
   8.186 +	if ( cpus_empty(*mask) )
   8.187 +		return;
   8.188 +	op.cmd = MMUEXT_INVLPG_MULTI;
   8.189 +	op.vcpumask = mask->bits;
   8.190 +	op.linear_addr = ptr & PAGE_MASK;
   8.191 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.192  }
   8.193  
   8.194  #endif /* CONFIG_SMP */
   8.195 @@ -183,222 +184,281 @@ void xen_invlpg_mask(cpumask_t *mask, un
   8.196  #ifndef CONFIG_XEN_SHADOW_MODE
   8.197  void xen_pgd_pin(unsigned long ptr)
   8.198  {
   8.199 -    struct mmuext_op op;
   8.200 +	struct mmuext_op op;
   8.201  #ifdef CONFIG_X86_64
   8.202 -    op.cmd = MMUEXT_PIN_L4_TABLE;
   8.203 +	op.cmd = MMUEXT_PIN_L4_TABLE;
   8.204  #elif defined(CONFIG_X86_PAE)
   8.205 -    op.cmd = MMUEXT_PIN_L3_TABLE;
   8.206 +	op.cmd = MMUEXT_PIN_L3_TABLE;
   8.207  #else
   8.208 -    op.cmd = MMUEXT_PIN_L2_TABLE;
   8.209 +	op.cmd = MMUEXT_PIN_L2_TABLE;
   8.210  #endif
   8.211 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.212 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.213 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.214 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.215  }
   8.216  
   8.217  void xen_pgd_unpin(unsigned long ptr)
   8.218  {
   8.219 -    struct mmuext_op op;
   8.220 -    op.cmd = MMUEXT_UNPIN_TABLE;
   8.221 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.222 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.223 +	struct mmuext_op op;
   8.224 +	op.cmd = MMUEXT_UNPIN_TABLE;
   8.225 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.226 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.227  }
   8.228  
   8.229  void xen_pte_pin(unsigned long ptr)
   8.230  {
   8.231 -    struct mmuext_op op;
   8.232 -    op.cmd = MMUEXT_PIN_L1_TABLE;
   8.233 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.234 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.235 +	struct mmuext_op op;
   8.236 +	op.cmd = MMUEXT_PIN_L1_TABLE;
   8.237 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.238 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.239  }
   8.240  
   8.241  void xen_pte_unpin(unsigned long ptr)
   8.242  {
   8.243 -    struct mmuext_op op;
   8.244 -    op.cmd = MMUEXT_UNPIN_TABLE;
   8.245 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.246 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.247 +	struct mmuext_op op;
   8.248 +	op.cmd = MMUEXT_UNPIN_TABLE;
   8.249 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.250 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.251  }
   8.252  
   8.253  #ifdef CONFIG_X86_64
   8.254  void xen_pud_pin(unsigned long ptr)
   8.255  {
   8.256 -    struct mmuext_op op;
   8.257 -    op.cmd = MMUEXT_PIN_L3_TABLE;
   8.258 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.259 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.260 +	struct mmuext_op op;
   8.261 +	op.cmd = MMUEXT_PIN_L3_TABLE;
   8.262 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.263 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.264  }
   8.265  
   8.266  void xen_pud_unpin(unsigned long ptr)
   8.267  {
   8.268 -    struct mmuext_op op;
   8.269 -    op.cmd = MMUEXT_UNPIN_TABLE;
   8.270 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.271 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.272 +	struct mmuext_op op;
   8.273 +	op.cmd = MMUEXT_UNPIN_TABLE;
   8.274 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.275 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.276  }
   8.277  
   8.278  void xen_pmd_pin(unsigned long ptr)
   8.279  {
   8.280 -    struct mmuext_op op;
   8.281 -    op.cmd = MMUEXT_PIN_L2_TABLE;
   8.282 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.283 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.284 +	struct mmuext_op op;
   8.285 +	op.cmd = MMUEXT_PIN_L2_TABLE;
   8.286 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.287 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.288  }
   8.289  
   8.290  void xen_pmd_unpin(unsigned long ptr)
   8.291  {
   8.292 -    struct mmuext_op op;
   8.293 -    op.cmd = MMUEXT_UNPIN_TABLE;
   8.294 -    op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.295 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.296 +	struct mmuext_op op;
   8.297 +	op.cmd = MMUEXT_UNPIN_TABLE;
   8.298 +	op.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   8.299 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.300  }
   8.301  #endif /* CONFIG_X86_64 */
   8.302  #endif /* CONFIG_XEN_SHADOW_MODE */
   8.303  
   8.304  void xen_set_ldt(unsigned long ptr, unsigned long len)
   8.305  {
   8.306 -    struct mmuext_op op;
   8.307 -    op.cmd = MMUEXT_SET_LDT;
   8.308 -    op.linear_addr = ptr;
   8.309 -    op.nr_ents = len;
   8.310 -    BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.311 +	struct mmuext_op op;
   8.312 +	op.cmd = MMUEXT_SET_LDT;
   8.313 +	op.linear_addr = ptr;
   8.314 +	op.nr_ents = len;
   8.315 +	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   8.316 +}
   8.317 +
   8.318 +/*
   8.319 + * Bitmap is indexed by page number. If bit is set, the page is part of a
   8.320 + * xen_create_contiguous_region() area of memory.
   8.321 + */
   8.322 +unsigned long *contiguous_bitmap;
   8.323 +
   8.324 +static void contiguous_bitmap_set(
   8.325 +	unsigned long first_page, unsigned long nr_pages)
   8.326 +{
   8.327 +	unsigned long start_off, end_off, curr_idx, end_idx;
   8.328 +
   8.329 +	curr_idx  = first_page / BITS_PER_LONG;
   8.330 +	start_off = first_page & (BITS_PER_LONG-1);
   8.331 +	end_idx   = (first_page + nr_pages) / BITS_PER_LONG;
   8.332 +	end_off   = (first_page + nr_pages) & (BITS_PER_LONG-1);
   8.333 +
   8.334 +	if (curr_idx == end_idx) {
   8.335 +		contiguous_bitmap[curr_idx] |=
   8.336 +			((1UL<<end_off)-1) & -(1UL<<start_off);
   8.337 +	} else {
   8.338 +		contiguous_bitmap[curr_idx] |= -(1UL<<start_off);
   8.339 +		while ( ++curr_idx < end_idx )
   8.340 +			contiguous_bitmap[curr_idx] = ~0UL;
   8.341 +		contiguous_bitmap[curr_idx] |= (1UL<<end_off)-1;
   8.342 +	}
   8.343 +}
   8.344 +
   8.345 +static void contiguous_bitmap_clear(
   8.346 +	unsigned long first_page, unsigned long nr_pages)
   8.347 +{
   8.348 +	unsigned long start_off, end_off, curr_idx, end_idx;
   8.349 +
   8.350 +	curr_idx  = first_page / BITS_PER_LONG;
   8.351 +	start_off = first_page & (BITS_PER_LONG-1);
   8.352 +	end_idx   = (first_page + nr_pages) / BITS_PER_LONG;
   8.353 +	end_off   = (first_page + nr_pages) & (BITS_PER_LONG-1);
   8.354 +
   8.355 +	if (curr_idx == end_idx) {
   8.356 +		contiguous_bitmap[curr_idx] &=
   8.357 +			-(1UL<<end_off) | ((1UL<<start_off)-1);
   8.358 +	} else {
   8.359 +		contiguous_bitmap[curr_idx] &= (1UL<<start_off)-1;
   8.360 +		while ( ++curr_idx != end_idx )
   8.361 +			contiguous_bitmap[curr_idx] = 0;
   8.362 +		contiguous_bitmap[curr_idx] &= -(1UL<<end_off);
   8.363 +	}
   8.364  }
   8.365  
   8.366  /* Ensure multi-page extents are contiguous in machine memory. */
   8.367  void xen_create_contiguous_region(unsigned long vstart, unsigned int order)
   8.368  {
   8.369 -    pgd_t         *pgd; 
   8.370 -    pud_t         *pud; 
   8.371 -    pmd_t         *pmd;
   8.372 -    pte_t         *pte;
   8.373 -    unsigned long  mfn, i, flags;
   8.374 +	pgd_t         *pgd; 
   8.375 +	pud_t         *pud; 
   8.376 +	pmd_t         *pmd;
   8.377 +	pte_t         *pte;
   8.378 +	unsigned long  mfn, i, flags;
   8.379  
   8.380 -    scrub_pages(vstart, 1 << order);
   8.381 +	scrub_pages(vstart, 1 << order);
   8.382  
   8.383 -    balloon_lock(flags);
   8.384 +	balloon_lock(flags);
   8.385  
   8.386 -    /* 1. Zap current PTEs, giving away the underlying pages. */
   8.387 -    for (i = 0; i < (1<<order); i++) {
   8.388 -        pgd = pgd_offset_k(vstart + (i*PAGE_SIZE));
   8.389 -        pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.390 -        pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.391 -        pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
   8.392 -        mfn = pte_mfn(*pte);
   8.393 -        BUG_ON(HYPERVISOR_update_va_mapping(
   8.394 -            vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
   8.395 -        phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.396 -            INVALID_P2M_ENTRY;
   8.397 -        BUG_ON(HYPERVISOR_dom_mem_op(
   8.398 -            MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
   8.399 -    }
   8.400 +	/* 1. Zap current PTEs, giving away the underlying pages. */
   8.401 +	for (i = 0; i < (1<<order); i++) {
   8.402 +		pgd = pgd_offset_k(vstart + (i*PAGE_SIZE));
   8.403 +		pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.404 +		pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.405 +		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
   8.406 +		mfn = pte_mfn(*pte);
   8.407 +		BUG_ON(HYPERVISOR_update_va_mapping(
   8.408 +			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
   8.409 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.410 +			INVALID_P2M_ENTRY;
   8.411 +		BUG_ON(HYPERVISOR_dom_mem_op(
   8.412 +			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
   8.413 +	}
   8.414  
   8.415 -    /* 2. Get a new contiguous memory extent. */
   8.416 -    BUG_ON(HYPERVISOR_dom_mem_op(
   8.417 -	       MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1);
   8.418 +	/* 2. Get a new contiguous memory extent. */
   8.419 +	BUG_ON(HYPERVISOR_dom_mem_op(
   8.420 +		MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1);
   8.421  
   8.422 -    /* 3. Map the new extent in place of old pages. */
   8.423 -    for (i = 0; i < (1<<order); i++) {
   8.424 -        BUG_ON(HYPERVISOR_update_va_mapping(
   8.425 -            vstart + (i*PAGE_SIZE),
   8.426 -            __pte_ma(((mfn+i)<<PAGE_SHIFT)|__PAGE_KERNEL), 0));
   8.427 -        xen_machphys_update(mfn+i, (__pa(vstart)>>PAGE_SHIFT)+i);
   8.428 -        phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn+i;
   8.429 -    }
   8.430 +	/* 3. Map the new extent in place of old pages. */
   8.431 +	for (i = 0; i < (1<<order); i++) {
   8.432 +		BUG_ON(HYPERVISOR_update_va_mapping(
   8.433 +			vstart + (i*PAGE_SIZE),
   8.434 +			pfn_pte_ma(mfn+i, PAGE_KERNEL), 0));
   8.435 +		xen_machphys_update(mfn+i, (__pa(vstart)>>PAGE_SHIFT)+i);
   8.436 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn+i;
   8.437 +	}
   8.438  
   8.439 -    flush_tlb_all();
   8.440 +	flush_tlb_all();
   8.441  
   8.442 -    balloon_unlock(flags);
   8.443 +	contiguous_bitmap_set(__pa(vstart) >> PAGE_SHIFT, 1UL << order);
   8.444 +
   8.445 +	balloon_unlock(flags);
   8.446  }
   8.447  
   8.448  void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order)
   8.449  {
   8.450 -    pgd_t         *pgd; 
   8.451 -    pud_t         *pud; 
   8.452 -    pmd_t         *pmd;
   8.453 -    pte_t         *pte;
   8.454 -    unsigned long  mfn, i, flags;
   8.455 +	pgd_t         *pgd; 
   8.456 +	pud_t         *pud; 
   8.457 +	pmd_t         *pmd;
   8.458 +	pte_t         *pte;
   8.459 +	unsigned long  mfn, i, flags;
   8.460  
   8.461 -    scrub_pages(vstart, 1 << order);
   8.462 +	scrub_pages(vstart, 1 << order);
   8.463  
   8.464 -    balloon_lock(flags);
   8.465 +	balloon_lock(flags);
   8.466 +
   8.467 +	contiguous_bitmap_clear(__pa(vstart) >> PAGE_SHIFT, 1UL << order);
   8.468  
   8.469 -    /* 1. Zap current PTEs, giving away the underlying pages. */
   8.470 -    for (i = 0; i < (1<<order); i++) {
   8.471 -        pgd = pgd_offset_k(vstart + (i*PAGE_SIZE));
   8.472 -        pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.473 -        pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.474 -        pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
   8.475 -        mfn = pte_mfn(*pte);
   8.476 -        BUG_ON(HYPERVISOR_update_va_mapping(
   8.477 -            vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
   8.478 -        phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.479 -            INVALID_P2M_ENTRY;
   8.480 -        BUG_ON(HYPERVISOR_dom_mem_op(
   8.481 -            MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
   8.482 -    }
   8.483 +	/* 1. Zap current PTEs, giving away the underlying pages. */
   8.484 +	for (i = 0; i < (1<<order); i++) {
   8.485 +		pgd = pgd_offset_k(vstart + (i*PAGE_SIZE));
   8.486 +		pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.487 +		pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.488 +		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE)));
   8.489 +		mfn = pte_mfn(*pte);
   8.490 +		BUG_ON(HYPERVISOR_update_va_mapping(
   8.491 +			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
   8.492 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.493 +			INVALID_P2M_ENTRY;
   8.494 +		BUG_ON(HYPERVISOR_dom_mem_op(
   8.495 +			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
   8.496 +	}
   8.497  
   8.498 -    /* 2. Map new pages in place of old pages. */
   8.499 -    for (i = 0; i < (1<<order); i++) {
   8.500 -        BUG_ON(HYPERVISOR_dom_mem_op(
   8.501 -            MEMOP_increase_reservation, &mfn, 1, 0) != 1);
   8.502 -        BUG_ON(HYPERVISOR_update_va_mapping(
   8.503 -            vstart + (i*PAGE_SIZE),
   8.504 -            __pte_ma((mfn<<PAGE_SHIFT)|__PAGE_KERNEL), 0));
   8.505 -        xen_machphys_update(mfn, (__pa(vstart)>>PAGE_SHIFT)+i);
   8.506 -        phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn;
   8.507 -    }
   8.508 +	/* 2. Map new pages in place of old pages. */
   8.509 +	for (i = 0; i < (1<<order); i++) {
   8.510 +		BUG_ON(HYPERVISOR_dom_mem_op(
   8.511 +			MEMOP_increase_reservation, &mfn, 1, 0) != 1);
   8.512 +		BUG_ON(HYPERVISOR_update_va_mapping(
   8.513 +			vstart + (i*PAGE_SIZE),
   8.514 +			pfn_pte_ma(mfn, PAGE_KERNEL), 0));
   8.515 +		xen_machphys_update(mfn, (__pa(vstart)>>PAGE_SHIFT)+i);
   8.516 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] = mfn;
   8.517 +	}
   8.518  
   8.519 -    flush_tlb_all();
   8.520 +	flush_tlb_all();
   8.521  
   8.522 -    balloon_unlock(flags);
   8.523 +	balloon_unlock(flags);
   8.524  }
   8.525  
   8.526 -#ifdef CONFIG_XEN_PHYSDEV_ACCESS
   8.527  
   8.528  unsigned long allocate_empty_lowmem_region(unsigned long pages)
   8.529  {
   8.530 -    pgd_t         *pgd;
   8.531 -    pud_t         *pud; 
   8.532 -    pmd_t         *pmd;
   8.533 -    pte_t         *pte;
   8.534 -    unsigned long *pfn_array;
   8.535 -    unsigned long  vstart;
   8.536 -    unsigned long  i;
   8.537 -    unsigned int   order = get_order(pages*PAGE_SIZE);
   8.538 +	pgd_t         *pgd;
   8.539 +	pud_t         *pud; 
   8.540 +	pmd_t         *pmd;
   8.541 +	pte_t         *pte;
   8.542 +	unsigned long *pfn_array;
   8.543 +	unsigned long  vstart;
   8.544 +	unsigned long  i;
   8.545 +	unsigned int   order = get_order(pages*PAGE_SIZE);
   8.546  
   8.547 -    vstart = __get_free_pages(GFP_KERNEL, order);
   8.548 -    if ( vstart == 0 )
   8.549 -        return 0UL;
   8.550 +	vstart = __get_free_pages(GFP_KERNEL, order);
   8.551 +	if (vstart == 0)
   8.552 +		return 0UL;
   8.553  
   8.554 -    scrub_pages(vstart, 1 << order);
   8.555 +	scrub_pages(vstart, 1 << order);
   8.556  
   8.557 -    pfn_array = vmalloc((1<<order) * sizeof(*pfn_array));
   8.558 -    if ( pfn_array == NULL )
   8.559 -        BUG();
   8.560 +	pfn_array = vmalloc((1<<order) * sizeof(*pfn_array));
   8.561 +	BUG_ON(pfn_array == NULL);
   8.562  
   8.563 -    for ( i = 0; i < (1<<order); i++ )
   8.564 -    {
   8.565 -        pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
   8.566 -        pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.567 -        pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.568 -        pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE))); 
   8.569 -        pfn_array[i] = pte_mfn(*pte);
   8.570 +	for (i = 0; i < (1<<order); i++) {
   8.571 +		pgd = pgd_offset_k(   (vstart + (i*PAGE_SIZE)));
   8.572 +		pud = pud_offset(pgd, (vstart + (i*PAGE_SIZE)));
   8.573 +		pmd = pmd_offset(pud, (vstart + (i*PAGE_SIZE)));
   8.574 +		pte = pte_offset_kernel(pmd, (vstart + (i*PAGE_SIZE))); 
   8.575 +		pfn_array[i] = pte_mfn(*pte);
   8.576  #ifdef CONFIG_X86_64
   8.577 -        xen_l1_entry_update(pte, __pte(0));
   8.578 +		xen_l1_entry_update(pte, __pte(0));
   8.579  #else
   8.580 -        BUG_ON(HYPERVISOR_update_va_mapping(vstart + (i*PAGE_SIZE), 
   8.581 -					    __pte_ma(0), 0));
   8.582 +		BUG_ON(HYPERVISOR_update_va_mapping(vstart + (i*PAGE_SIZE), 
   8.583 +						    __pte_ma(0), 0));
   8.584  #endif
   8.585 -        phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.586 -            INVALID_P2M_ENTRY;
   8.587 -    }
   8.588 +		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
   8.589 +			INVALID_P2M_ENTRY;
   8.590 +	}
   8.591  
   8.592 -    flush_tlb_all();
   8.593 +	flush_tlb_all();
   8.594  
   8.595 -    balloon_put_pages(pfn_array, 1 << order);
   8.596 +	balloon_put_pages(pfn_array, 1 << order);
   8.597  
   8.598 -    vfree(pfn_array);
   8.599 +	vfree(pfn_array);
   8.600  
   8.601 -    return vstart;
   8.602 +	return vstart;
   8.603  }
   8.604  
   8.605 -#endif /* CONFIG_XEN_PHYSDEV_ACCESS */
   8.606 +EXPORT_SYMBOL(allocate_empty_lowmem_region);
   8.607 +
   8.608 +/*
   8.609 + * Local variables:
   8.610 + *  c-file-style: "linux"
   8.611 + *  indent-tabs-mode: t
   8.612 + *  c-indent-level: 8
   8.613 + *  c-basic-offset: 8
   8.614 + *  tab-width: 8
   8.615 + * End:
   8.616 + */
     9.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Thu Aug 18 18:54:38 2005 +0000
     9.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c	Thu Aug 18 18:55:13 2005 +0000
     9.3 @@ -41,6 +41,8 @@
     9.4  #include <asm/sections.h>
     9.5  #include <asm-xen/hypervisor.h>
     9.6  
     9.7 +extern unsigned long *contiguous_bitmap;
     9.8 +
     9.9  #if defined(CONFIG_SWIOTLB)
    9.10  extern void swiotlb_init(void);
    9.11  int swiotlb;
    9.12 @@ -637,6 +639,11 @@ void __init mem_init(void)
    9.13  	int bad_ppro;
    9.14  	unsigned long pfn;
    9.15  
    9.16 +	contiguous_bitmap = alloc_bootmem_low_pages(
    9.17 +		(max_low_pfn + 2*BITS_PER_LONG) >> 3);
    9.18 +	BUG_ON(!contiguous_bitmap);
    9.19 +	memset(contiguous_bitmap, 0, (max_low_pfn + 2*BITS_PER_LONG) >> 3);
    9.20 +
    9.21  #if defined(CONFIG_SWIOTLB)
    9.22  	swiotlb_init();	
    9.23  #endif
    10.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c	Thu Aug 18 18:54:38 2005 +0000
    10.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c	Thu Aug 18 18:55:13 2005 +0000
    10.3 @@ -300,17 +300,17 @@ void __init bt_iounmap(void *addr, unsig
    10.4  
    10.5  
    10.6  static int direct_remap_area_pte_fn(pte_t *pte, 
    10.7 -                                    struct page *pte_page,
    10.8 -                                    unsigned long address, 
    10.9 -                                    void *data)
   10.10 +				    struct page *pte_page,
   10.11 +				    unsigned long address, 
   10.12 +				    void *data)
   10.13  {
   10.14 -        mmu_update_t **v = (mmu_update_t **)data;
   10.15 +	mmu_update_t **v = (mmu_update_t **)data;
   10.16  
   10.17 -        (*v)->ptr = (pfn_to_mfn(page_to_pfn(pte_page)) << PAGE_SHIFT)
   10.18 -                    | ((unsigned long)pte & ~PAGE_MASK);
   10.19 -        (*v)++;
   10.20 +	(*v)->ptr = ((physaddr_t)pfn_to_mfn(page_to_pfn(pte_page)) <<
   10.21 +		     PAGE_SHIFT) | ((unsigned long)pte & ~PAGE_MASK);
   10.22 +	(*v)++;
   10.23  
   10.24 -        return 0;
   10.25 +	return 0;
   10.26  }
   10.27  
   10.28  int direct_remap_area_pages(struct mm_struct *mm,
   10.29 @@ -397,6 +397,16 @@ int touch_pte_range(struct mm_struct *mm
   10.30  	}
   10.31  
   10.32  	return generic_page_range(mm, address, size, f, NULL);
   10.33 -}                 
   10.34 +} 
   10.35  
   10.36  EXPORT_SYMBOL(touch_pte_range);
   10.37 +
   10.38 +/*
   10.39 + * Local variables:
   10.40 + *  c-file-style: "linux"
   10.41 + *  indent-tabs-mode: t
   10.42 + *  c-indent-level: 8
   10.43 + *  c-basic-offset: 8
   10.44 + *  tab-width: 8
   10.45 + * End:
   10.46 + */
    11.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c	Thu Aug 18 18:54:38 2005 +0000
    11.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c	Thu Aug 18 18:55:13 2005 +0000
    11.3 @@ -5,8 +5,6 @@
    11.4  #include <linux/kernel.h>
    11.5  #include <linux/sched.h>
    11.6  #include <linux/slab.h>
    11.7 -#include <linux/string.h>
    11.8 -#include <linux/errno.h>
    11.9  #include <linux/netdevice.h>
   11.10  #include <linux/inetdevice.h>
   11.11  #include <linux/etherdevice.h>
   11.12 @@ -14,34 +12,86 @@
   11.13  #include <linux/init.h>
   11.14  #include <asm/io.h>
   11.15  #include <asm/page.h>
   11.16 -
   11.17 -EXPORT_SYMBOL(__dev_alloc_skb);
   11.18 +#include <asm-xen/hypervisor.h>
   11.19  
   11.20  /* Referenced in netback.c. */
   11.21  /*static*/ kmem_cache_t *skbuff_cachep;
   11.22  
   11.23 -/* Size must be cacheline-aligned (alloc_skb uses SKB_DATA_ALIGN). */
   11.24 -#define XEN_SKB_SIZE \
   11.25 -    ((PAGE_SIZE - sizeof(struct skb_shared_info)) & ~(SMP_CACHE_BYTES - 1))
   11.26 +#define MAX_SKBUFF_ORDER 2
   11.27 +static kmem_cache_t *skbuff_order_cachep[MAX_SKBUFF_ORDER + 1];
   11.28  
   11.29  struct sk_buff *__dev_alloc_skb(unsigned int length, int gfp_mask)
   11.30  {
   11.31 -    struct sk_buff *skb;
   11.32 -    skb = alloc_skb_from_cache(skbuff_cachep, length + 16, gfp_mask);
   11.33 -    if ( likely(skb != NULL) )
   11.34 -        skb_reserve(skb, 16);
   11.35 -    return skb;
   11.36 +	struct sk_buff *skb;
   11.37 +	int order;
   11.38 +
   11.39 +	length = SKB_DATA_ALIGN(length + 16);
   11.40 +	order = get_order(length + sizeof(struct skb_shared_info));
   11.41 +	if (order > MAX_SKBUFF_ORDER) {
   11.42 +		printk(KERN_ALERT "Attempt to allocate order %d skbuff. "
   11.43 +		       "Increase MAX_SKBUFF_ORDER.\n", order);
   11.44 +		return NULL;
   11.45 +	}
   11.46 +
   11.47 +	skb = alloc_skb_from_cache(
   11.48 +		skbuff_order_cachep[order], length, gfp_mask);
   11.49 +	if (skb != NULL)
   11.50 +		skb_reserve(skb, 16);
   11.51 +
   11.52 +	return skb;
   11.53  }
   11.54  
   11.55  static void skbuff_ctor(void *buf, kmem_cache_t *cachep, unsigned long unused)
   11.56  {
   11.57 -    scrub_pages(buf, 1);
   11.58 +	int order = 0;
   11.59 +
   11.60 +	while (skbuff_order_cachep[order] != cachep)
   11.61 +		order++;
   11.62 +
   11.63 +	if (order != 0)
   11.64 +		xen_create_contiguous_region((unsigned long)buf, order);
   11.65 +
   11.66 +	scrub_pages(buf, 1 << order);
   11.67 +}
   11.68 +
   11.69 +static void skbuff_dtor(void *buf, kmem_cache_t *cachep, unsigned long unused)
   11.70 +{
   11.71 +	int order = 0;
   11.72 +
   11.73 +	while (skbuff_order_cachep[order] != cachep)
   11.74 +		order++;
   11.75 +
   11.76 +	if (order != 0)
   11.77 +		xen_destroy_contiguous_region((unsigned long)buf, order);
   11.78  }
   11.79  
   11.80  static int __init skbuff_init(void)
   11.81  {
   11.82 -    skbuff_cachep = kmem_cache_create(
   11.83 -        "xen-skb", PAGE_SIZE, PAGE_SIZE, 0, skbuff_ctor, NULL);
   11.84 -    return 0;
   11.85 +	static char name[MAX_SKBUFF_ORDER + 1][20];
   11.86 +	unsigned long size;
   11.87 +	int order;
   11.88 +
   11.89 +	for (order = 0; order <= MAX_SKBUFF_ORDER; order++) {
   11.90 +		size = PAGE_SIZE << order;
   11.91 +		sprintf(name[order], "xen-skb-%lu", size);
   11.92 +		skbuff_order_cachep[order] = kmem_cache_create(
   11.93 +			name[order], size, size, 0, skbuff_ctor, skbuff_dtor);
   11.94 +	}
   11.95 +
   11.96 +	skbuff_cachep = skbuff_order_cachep[0];
   11.97 +
   11.98 +	return 0;
   11.99  }
  11.100  __initcall(skbuff_init);
  11.101 +
  11.102 +EXPORT_SYMBOL(__dev_alloc_skb);
  11.103 +
  11.104 +/*
  11.105 + * Local variables:
  11.106 + *  c-file-style: "linux"
  11.107 + *  indent-tabs-mode: t
  11.108 + *  c-indent-level: 8
  11.109 + *  c-basic-offset: 8
  11.110 + *  tab-width: 8
  11.111 + * End:
  11.112 + */
    12.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Thu Aug 18 18:54:38 2005 +0000
    12.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Thu Aug 18 18:55:13 2005 +0000
    12.3 @@ -426,16 +426,10 @@ static __init void parse_cmdline_early (
    12.4  #ifdef CONFIG_XEN
    12.5  static void __init contig_initmem_init(void)
    12.6  {
    12.7 -        unsigned long bootmap_size, bootmap; 
    12.8 -
    12.9 -        bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
   12.10 -        bootmap = start_pfn;
   12.11 -        bootmap_size = init_bootmem(bootmap, end_pfn);
   12.12 -        reserve_bootmem(bootmap, bootmap_size);
   12.13 -        
   12.14 -        free_bootmem(start_pfn << PAGE_SHIFT, (end_pfn - start_pfn) << PAGE_SHIFT);   
   12.15 -        reserve_bootmem(0, (PFN_PHYS(start_pfn) +
   12.16 -                            bootmap_size + PAGE_SIZE-1));
   12.17 +        unsigned long bootmap_size = init_bootmem(start_pfn, end_pfn);
   12.18 +        free_bootmem(0, end_pfn << PAGE_SHIFT);   
   12.19 +        /* XXX KAF: Why can't we leave low 1MB of memory free? */
   12.20 +        reserve_bootmem(0, (PFN_PHYS(start_pfn) + bootmap_size + PAGE_SIZE-1));
   12.21  }
   12.22  #else
   12.23  static void __init contig_initmem_init(void)
    13.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Thu Aug 18 18:54:38 2005 +0000
    13.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Thu Aug 18 18:55:13 2005 +0000
    13.3 @@ -250,7 +250,11 @@ static int vmalloc_fault(unsigned long a
    13.4  	   happen within a race in page table update. In the later
    13.5  	   case just flush. */
    13.6  
    13.7 -	pgd = pgd_offset(current->mm ?: &init_mm, address);
    13.8 +	/* On Xen the line below does not always work. Needs investigating! */
    13.9 +	/*pgd = pgd_offset(current->mm ?: &init_mm, address);*/
   13.10 +	pgd = (pgd_t *)per_cpu(cur_pgd, smp_processor_id());
   13.11 +	pgd += pgd_index(address);
   13.12 +
   13.13  	pgd_ref = pgd_offset_k(address);
   13.14  	if (pgd_none(*pgd_ref))
   13.15  		return -1;
    14.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Thu Aug 18 18:54:38 2005 +0000
    14.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Thu Aug 18 18:55:13 2005 +0000
    14.3 @@ -40,6 +40,12 @@
    14.4  #include <asm/proto.h>
    14.5  #include <asm/smp.h>
    14.6  
    14.7 +extern unsigned long *contiguous_bitmap;
    14.8 +
    14.9 +#if defined(CONFIG_SWIOTLB)
   14.10 +extern void swiotlb_init(void);
   14.11 +#endif
   14.12 +
   14.13  #ifndef Dprintk
   14.14  #define Dprintk(x...)
   14.15  #endif
   14.16 @@ -794,8 +800,12 @@ void __init mem_init(void)
   14.17  	int codesize, reservedpages, datasize, initsize;
   14.18  	int tmp;
   14.19  
   14.20 +	contiguous_bitmap = alloc_bootmem_low_pages(
   14.21 +		(end_pfn + 2*BITS_PER_LONG) >> 3);
   14.22 +	BUG_ON(!contiguous_bitmap);
   14.23 +	memset(contiguous_bitmap, 0, (end_pfn + 2*BITS_PER_LONG) >> 3);
   14.24 +
   14.25  #if defined(CONFIG_SWIOTLB)
   14.26 -	extern void swiotlb_init(void);
   14.27  	swiotlb_init();	
   14.28  #endif
   14.29  
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Aug 18 18:54:38 2005 +0000
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Thu Aug 18 18:55:13 2005 +0000
    15.3 @@ -213,9 +213,7 @@ static void balloon_process(void *unused
    15.4              {
    15.5                  BUG_ON(HYPERVISOR_update_va_mapping(
    15.6                      (unsigned long)__va(pfn << PAGE_SHIFT),
    15.7 -                    __pte_ma((mfn_list[i] << PAGE_SHIFT) |
    15.8 -                             pgprot_val(PAGE_KERNEL)),
    15.9 -                    0));
   15.10 +                    pfn_pte_ma(mfn_list[i], PAGE_KERNEL), 0));
   15.11              }
   15.12  
   15.13              /* Finally, relinquish the memory back to the system allocator. */
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Aug 18 18:54:38 2005 +0000
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Thu Aug 18 18:55:13 2005 +0000
    16.3 @@ -406,21 +406,15 @@ static void dispatch_probe(blkif_t *blki
    16.4  #endif
    16.5  
    16.6  
    16.7 -#ifdef CONFIG_XEN_BLKDEV_TAP_BE
    16.8      if ( HYPERVISOR_update_va_mapping_otherdomain(
    16.9          MMAP_VADDR(pending_idx, 0),
   16.10 -        (pte_t) { (req->frame_and_sects[0] & PAGE_MASK) | __PAGE_KERNEL },
   16.11 +        pfn_pte_ma(req->frame_and_sects[0] >> PAGE_SHIFT, PAGE_KERNEL),
   16.12 +#ifdef CONFIG_XEN_BLKDEV_TAP_BE
   16.13          0, (blkif->is_blktap ? ID_TO_DOM(req->id) : blkif->domid) ) )
   16.14 -        
   16.15 -        goto out;
   16.16  #else
   16.17 -    if ( HYPERVISOR_update_va_mapping_otherdomain(
   16.18 -        MMAP_VADDR(pending_idx, 0),
   16.19 -        (pte_t) { (req->frame_and_sects[0] & PAGE_MASK) | __PAGE_KERNEL },
   16.20 -        0, blkif->domid) ) 
   16.21 -        
   16.22 +        0, blkif->domid) )
   16.23 +#endif
   16.24          goto out;
   16.25 -#endif
   16.26  #endif /* endif CONFIG_XEN_BLKDEV_GRANT */
   16.27     
   16.28      rsp = vbd_probe(blkif, (vdisk_t *)MMAP_VADDR(pending_idx, 0), 
    18.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h	Thu Aug 18 18:54:38 2005 +0000
    18.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h	Thu Aug 18 18:55:13 2005 +0000
    18.3 @@ -26,7 +26,9 @@ address_needs_mapping(struct device *hwd
    18.4  static inline int
    18.5  range_straddles_page_boundary(void *p, size_t size)
    18.6  {
    18.7 -	return ((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE);
    18.8 +	extern unsigned long *contiguous_bitmap;
    18.9 +	return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) &&
   18.10 +		!test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap));
   18.11  }
   18.12  
   18.13  #define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
    19.1 --- a/linux-2.6-xen-sparse/include/asm-xen/hypervisor.h	Thu Aug 18 18:54:38 2005 +0000
    19.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/hypervisor.h	Thu Aug 18 18:55:13 2005 +0000
    19.3 @@ -137,10 +137,8 @@ void xen_invlpg_mask(cpumask_t *mask, un
    19.4  void xen_create_contiguous_region(unsigned long vstart, unsigned int order);
    19.5  void xen_destroy_contiguous_region(unsigned long vstart, unsigned int order);
    19.6  
    19.7 -#ifdef CONFIG_XEN_PHYSDEV_ACCESS
    19.8  /* Allocate a contiguous empty region of low memory. Return virtual start. */
    19.9  unsigned long allocate_empty_lowmem_region(unsigned long pages);
   19.10 -#endif
   19.11  
   19.12  #include <asm/hypercall.h>
   19.13  
    21.1 --- a/tools/examples/network-bridge	Thu Aug 18 18:54:38 2005 +0000
    21.2 +++ b/tools/examples/network-bridge	Thu Aug 18 18:55:13 2005 +0000
    21.3 @@ -51,7 +51,7 @@ for arg ; do export "${arg}" ; done
    21.4  
    21.5  bridge=${bridge:-xen-br0}
    21.6  netdev=${netdev:-eth0}
    21.7 -antispoof=${antispoof:-yes}
    21.8 +antispoof=${antispoof:-no}
    21.9  
   21.10  echo "*network $OP bridge=$bridge netdev=$netdev antispoof=$antispoof" >&2
   21.11  
    22.1 --- a/tools/python/xen/xm/create.py	Thu Aug 18 18:54:38 2005 +0000
    22.2 +++ b/tools/python/xen/xm/create.py	Thu Aug 18 18:55:13 2005 +0000
    22.3 @@ -23,6 +23,7 @@ import string
    22.4  import sys
    22.5  import socket
    22.6  import commands
    22.7 +import time
    22.8  
    22.9  import xen.lowlevel.xc
   22.10  
   22.11 @@ -674,18 +675,33 @@ def get_dom0_alloc():
   22.12      return 0
   22.13  
   22.14  def balloon_out(dom0_min_mem, opts):
   22.15 -    """Balloon out to get memory for domU, if necessarily"""
   22.16 +    """Balloon out memory from dom0 if necessary"""
   22.17      SLACK = 4
   22.18 +    timeout = 20 # 2s
   22.19 +    ret = 0
   22.20  
   22.21      xc = xen.lowlevel.xc.new()
   22.22      pinfo = xc.physinfo()
   22.23 -    free_mem = pinfo['free_pages']/256
   22.24 -    if free_mem < opts.vals.memory + SLACK:
   22.25 -        need_mem = opts.vals.memory + SLACK - free_mem
   22.26 -        cur_alloc = get_dom0_alloc()
   22.27 -        if cur_alloc - need_mem >= dom0_min_mem:
   22.28 -            server.xend_domain_mem_target_set(0, cur_alloc - need_mem)
   22.29 +    free_mem = pinfo['free_pages'] / 256
   22.30 +    domU_need_mem = opts.vals.memory + SLACK 
   22.31 +
   22.32 +    dom0_cur_alloc = get_dom0_alloc()
   22.33 +    dom0_new_alloc = dom0_cur_alloc - (domU_need_mem - free_mem)
   22.34 +
   22.35 +    if free_mem < domU_need_mem and dom0_new_alloc >= dom0_min_mem:
   22.36 +
   22.37 +        server.xend_domain_mem_target_set(0, dom0_new_alloc)
   22.38 +
   22.39 +        while dom0_cur_alloc > dom0_new_alloc and timeout > 0:
   22.40 +            time.sleep(0.1) # sleep 100ms
   22.41 +            dom0_cur_alloc = get_dom0_alloc()
   22.42 +            timeout -= 1
   22.43 +        
   22.44 +        if dom0_cur_alloc > dom0_new_alloc:
   22.45 +            ret = 1
   22.46 +    
   22.47      del xc
   22.48 +    return ret
   22.49  
   22.50  def main(argv):
   22.51      random.seed()
   22.52 @@ -717,7 +733,8 @@ def main(argv):
   22.53      else:
   22.54          dom0_min_mem = xroot.get_dom0_min_mem()
   22.55          if dom0_min_mem != 0:
   22.56 -            balloon_out(dom0_min_mem, opts)
   22.57 +            if balloon_out(dom0_min_mem, opts):
   22.58 +                return
   22.59  
   22.60          dom = make_domain(opts, config)
   22.61          if opts.vals.console_autoconnect:
    23.1 --- a/tools/python/xen/xm/main.py	Thu Aug 18 18:54:38 2005 +0000
    23.2 +++ b/tools/python/xen/xm/main.py	Thu Aug 18 18:55:13 2005 +0000
    23.3 @@ -200,7 +200,11 @@ def xm_migrate(args):
    23.4  def xm_list(args):
    23.5      use_long = 0
    23.6      show_vcpus = 0
    23.7 -    (options, params) = getopt(args, 'lv', ['long','vcpus'])
    23.8 +    try:
    23.9 +        (options, params) = getopt(args, 'lv', ['long','vcpus'])
   23.10 +    except GetoptError, opterr:
   23.11 +        err(opterr)
   23.12 +        sys.exit(1)
   23.13      
   23.14      n = len(params)
   23.15      for (k, v) in options:
    24.1 --- a/xen/arch/x86/mm.c	Thu Aug 18 18:54:38 2005 +0000
    24.2 +++ b/xen/arch/x86/mm.c	Thu Aug 18 18:55:13 2005 +0000
    24.3 @@ -3059,7 +3059,7 @@ static int ptwr_emulated_update(
    24.4      }
    24.5  
    24.6      /* Turn a sub-word access into a full-word access. */
    24.7 -    if (bytes != sizeof(physaddr_t))
    24.8 +    if ( bytes != sizeof(physaddr_t) )
    24.9      {
   24.10          int           rc;
   24.11          physaddr_t    full;
   24.12 @@ -3076,6 +3076,10 @@ static int ptwr_emulated_update(
   24.13          val  &= (((physaddr_t)1 << (bytes*8)) - 1);
   24.14          val <<= (offset)*8;
   24.15          val  |= full;
   24.16 +        /* Also fill in missing parts of the cmpxchg old value. */
   24.17 +        old  &= (((physaddr_t)1 << (bytes*8)) - 1);
   24.18 +        old <<= (offset)*8;
   24.19 +        old  |= full;
   24.20      }
   24.21  
   24.22      /* Read the PTE that maps the page being updated. */
   24.23 @@ -3111,7 +3115,7 @@ static int ptwr_emulated_update(
   24.24      if ( do_cmpxchg )
   24.25      {
   24.26          ol1e = l1e_from_intpte(old);
   24.27 -        if ( cmpxchg((unsigned long *)pl1e, old, val) != old )
   24.28 +        if ( cmpxchg((intpte_t *)pl1e, old, val) != old )
   24.29          {
   24.30              unmap_domain_page(pl1e);
   24.31              put_page_from_l1e(nl1e, d);
   24.32 @@ -3299,8 +3303,8 @@ int ptwr_do_page_fault(struct domain *d,
   24.33      
   24.34      /* Finally, make the p.t. page writable by the guest OS. */
   24.35      l1e_add_flags(pte, _PAGE_RW);
   24.36 -    if ( unlikely(__copy_to_user(&linear_pg_table[l1_linear_offset(addr)],
   24.37 -                                 &pte, sizeof(pte))) )
   24.38 +    if ( unlikely(__put_user(pte.l1,
   24.39 +                             &linear_pg_table[l1_linear_offset(addr)].l1)) )
   24.40      {
   24.41          MEM_LOG("ptwr: Could not update pte at %p", (unsigned long *)
   24.42                  &linear_pg_table[l1_linear_offset(addr)]);
    25.1 --- a/xen/arch/x86/setup.c	Thu Aug 18 18:54:38 2005 +0000
    25.2 +++ b/xen/arch/x86/setup.c	Thu Aug 18 18:55:13 2005 +0000
    25.3 @@ -244,6 +244,8 @@ static void __init start_of_day(void)
    25.4  
    25.5  #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
    25.6  
    25.7 +static struct e820entry e820_raw[E820MAX];
    25.8 +
    25.9  void __init __start_xen(multiboot_info_t *mbi)
   25.10  {
   25.11      char *cmdline;
   25.12 @@ -253,7 +255,6 @@ void __init __start_xen(multiboot_info_t
   25.13      unsigned long _initrd_start = 0, _initrd_len = 0;
   25.14      unsigned int initrdidx = 1;
   25.15      physaddr_t s, e;
   25.16 -    struct e820entry e820_raw[E820MAX];
   25.17      int i, e820_raw_nr = 0, bytes = 0;
   25.18      struct ns16550_defaults ns16550 = {
   25.19          .data_bits = 8,
    26.1 --- a/xen/arch/x86/traps.c	Thu Aug 18 18:54:38 2005 +0000
    26.2 +++ b/xen/arch/x86/traps.c	Thu Aug 18 18:55:13 2005 +0000
    26.3 @@ -159,10 +159,8 @@ void show_trace(unsigned long *esp)
    26.4          addr = *stack++;
    26.5          if ( is_kernel_text(addr) )
    26.6          {
    26.7 -            if ( (i != 0) && ((i % 6) == 0) )
    26.8 -                printk("\n   ");
    26.9              printk("[<%p>]", _p(addr));
   26.10 -            print_symbol(" %s\n", addr);
   26.11 +            print_symbol(" %s\n   ", addr);
   26.12              i++;
   26.13          }
   26.14      }
    27.1 --- a/xen/arch/x86/x86_32/traps.c	Thu Aug 18 18:54:38 2005 +0000
    27.2 +++ b/xen/arch/x86/x86_32/traps.c	Thu Aug 18 18:55:13 2005 +0000
    27.3 @@ -66,8 +66,9 @@ void show_registers(struct cpu_user_regs
    27.4  
    27.5      printk("CPU:    %d\nEIP:    %04lx:[<%08lx>]",
    27.6             smp_processor_id(), (unsigned long)0xffff & regs->cs, eip);
    27.7 -    print_symbol(" %s\n", eip);
    27.8 -    printk("EFLAGS: %08lx   CONTEXT: %s\n", eflags, context);
    27.9 +    if ( !GUEST_MODE(regs) )
   27.10 +        print_symbol(" %s", eip);
   27.11 +    printk("\nEFLAGS: %08lx   CONTEXT: %s\n", eflags, context);
   27.12      printk("eax: %08x   ebx: %08x   ecx: %08x   edx: %08x\n",
   27.13             regs->eax, regs->ebx, regs->ecx, regs->edx);
   27.14      printk("esi: %08x   edi: %08x   ebp: %08x   esp: %08lx\n",
    28.1 --- a/xen/arch/x86/x86_64/traps.c	Thu Aug 18 18:54:38 2005 +0000
    28.2 +++ b/xen/arch/x86/x86_64/traps.c	Thu Aug 18 18:55:13 2005 +0000
    28.3 @@ -17,8 +17,9 @@ void show_registers(struct cpu_user_regs
    28.4  {
    28.5      printk("CPU:    %d\nEIP:    %04x:[<%016lx>]",
    28.6             smp_processor_id(), 0xffff & regs->cs, regs->rip);
    28.7 -    print_symbol(" %s\n", regs->rip);
    28.8 -    printk("EFLAGS: %016lx\n", regs->eflags);
    28.9 +    if ( !GUEST_MODE(regs) )
   28.10 +        print_symbol(" %s", regs->rip);
   28.11 +    printk("\nEFLAGS: %016lx\n", regs->eflags);
   28.12      printk("rax: %016lx   rbx: %016lx   rcx: %016lx   rdx: %016lx\n",
   28.13             regs->rax, regs->rbx, regs->rcx, regs->rdx);
   28.14      printk("rsi: %016lx   rdi: %016lx   rbp: %016lx   rsp: %016lx\n",
    29.1 --- a/xen/drivers/char/console.c	Thu Aug 18 18:54:38 2005 +0000
    29.2 +++ b/xen/drivers/char/console.c	Thu Aug 18 18:55:13 2005 +0000
    29.3 @@ -652,8 +652,9 @@ static int __init debugtrace_init(void)
    29.4  void panic(const char *fmt, ...)
    29.5  {
    29.6      va_list args;
    29.7 -    char buf[128], cpustr[10];
    29.8 +    char buf[128];
    29.9      unsigned long flags;
   29.10 +    static spinlock_t lock = SPIN_LOCK_UNLOCKED;
   29.11      extern void machine_restart(char *);
   29.12      
   29.13      debugtrace_dump();
   29.14 @@ -665,16 +666,13 @@ void panic(const char *fmt, ...)
   29.15      debugger_trap_immediate();
   29.16  
   29.17      /* Spit out multiline message in one go. */
   29.18 -    spin_lock_irqsave(&console_lock, flags);
   29.19 -    __putstr("\n****************************************\n");
   29.20 -    __putstr("Panic on CPU");
   29.21 -    sprintf(cpustr, "%d", smp_processor_id());
   29.22 -    __putstr(cpustr);
   29.23 -    __putstr(":\n");
   29.24 -    __putstr(buf);
   29.25 -    __putstr("****************************************\n\n");
   29.26 -    __putstr("Reboot in five seconds...\n");
   29.27 -    spin_unlock_irqrestore(&console_lock, flags);
   29.28 +    spin_lock_irqsave(&lock, flags);
   29.29 +    printk("\n****************************************\n");
   29.30 +    printk("Panic on CPU %d:\n", smp_processor_id());
   29.31 +    printk(buf);
   29.32 +    printk("****************************************\n\n");
   29.33 +    printk("Reboot in five seconds...\n");
   29.34 +    spin_unlock_irqrestore(&lock, flags);
   29.35  
   29.36      watchdog_disable();
   29.37      mdelay(5000);
    30.1 --- a/xen/include/asm-x86/e820.h	Thu Aug 18 18:54:38 2005 +0000
    30.2 +++ b/xen/include/asm-x86/e820.h	Thu Aug 18 18:55:13 2005 +0000
    30.3 @@ -3,7 +3,7 @@
    30.4  
    30.5  #include <asm/page.h>
    30.6  
    30.7 -#define E820MAX	32
    30.8 +#define E820MAX	128
    30.9  
   30.10  #define E820_RAM          1
   30.11  #define E820_RESERVED     2
    31.1 --- a/xen/include/asm-x86/uaccess.h	Thu Aug 18 18:54:38 2005 +0000
    31.2 +++ b/xen/include/asm-x86/uaccess.h	Thu Aug 18 18:55:13 2005 +0000
    31.3 @@ -125,22 +125,20 @@ extern void __put_user_bad(void);
    31.4  	__pu_err;							\
    31.5  })							
    31.6  
    31.7 -#define __get_user_nocheck(x,ptr,size)				\
    31.8 -({								\
    31.9 -	long __gu_err, __gu_val;				\
   31.10 -	__get_user_size(__gu_val,(ptr),(size),__gu_err,-EFAULT);\
   31.11 -	(x) = (__typeof__(*(ptr)))__gu_val;			\
   31.12 -	__gu_err;						\
   31.13 +#define __get_user_nocheck(x,ptr,size)                          \
   31.14 +({                                                              \
   31.15 +	long __gu_err;                                          \
   31.16 +	__get_user_size((x),(ptr),(size),__gu_err,-EFAULT);     \
   31.17 +	__gu_err;                                               \
   31.18  })
   31.19  
   31.20 -#define __get_user_check(x,ptr,size)					\
   31.21 -({									\
   31.22 -	long __gu_err, __gu_val;					\
   31.23 -	__typeof__(*(ptr)) __user *__gu_addr = (ptr);			\
   31.24 -	__get_user_size(__gu_val,__gu_addr,(size),__gu_err,-EFAULT);	\
   31.25 -	(x) = (__typeof__(*(ptr)))__gu_val;				\
   31.26 -	if (!__addr_ok(__gu_addr)) __gu_err = -EFAULT;			\
   31.27 -	__gu_err;							\
   31.28 +#define __get_user_check(x,ptr,size)                            \
   31.29 +({                                                              \
   31.30 +	long __gu_err;                                          \
   31.31 +	__typeof__(*(ptr)) __user *__gu_addr = (ptr);           \
   31.32 +	__get_user_size((x),__gu_addr,(size),__gu_err,-EFAULT); \
   31.33 +	if (!__addr_ok(__gu_addr)) __gu_err = -EFAULT;          \
   31.34 +	__gu_err;                                               \
   31.35  })							
   31.36  
   31.37  struct __large_struct { unsigned long buf[100]; };