ia64/xen-unstable

changeset 9263:0ed4a312765b

merge
author awilliam@xenbuild.aw
date Tue Mar 14 13:50:35 2006 -0700 (2006-03-14)
parents dc50cdd66c5c c445d4a0dd76
children 911c04274f14
files linux-2.6-xen-sparse/include/asm-ia64/hypercall.h tools/libxc/xc_linux_build.c tools/xm-test/tests/sedf/01_sedf_multi_pos.py xen/arch/ia64/vmx/vmx_hypercall.c xen/arch/ia64/xen/process.c xen/include/asm-ia64/mm.h
line diff
     1.1 --- a/Config.mk	Tue Mar 14 13:10:21 2006 -0700
     1.2 +++ b/Config.mk	Tue Mar 14 13:50:35 2006 -0700
     1.3 @@ -1,5 +1,8 @@
     1.4  # -*- mode: Makefile; -*-
     1.5  
     1.6 +# A debug build of Xen and tools?
     1.7 +debug ?= n
     1.8 +
     1.9  # Currently supported architectures: x86_32, x86_64
    1.10  XEN_COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
    1.11  XEN_TARGET_ARCH     ?= $(XEN_COMPILE_ARCH)
    1.12 @@ -27,6 +30,22 @@ INSTALL_DIR  = $(INSTALL) -d -m0755
    1.13  INSTALL_DATA = $(INSTALL) -m0644
    1.14  INSTALL_PROG = $(INSTALL) -m0755
    1.15  
    1.16 +ifneq ($(debug),y)
    1.17 +# Optimisation flags are overridable
    1.18 +CFLAGS    ?= -O2 -fomit-frame-pointer
    1.19 +CFLAGS    += -DNDEBUG
    1.20 +else
    1.21 +CFLAGS    += -g
    1.22 +endif
    1.23 +
    1.24 +ifeq ($(XEN_TARGET_ARCH),x86_32)
    1.25 +CFLAGS  += -m32 -march=i686
    1.26 +endif
    1.27 +
    1.28 +ifeq ($(XEN_TARGET_ARCH),x86_64)
    1.29 +CFLAGS  += -m64
    1.30 +endif
    1.31 +
    1.32  ifeq ($(XEN_TARGET_ARCH),x86_64)
    1.33  LIBDIR = lib64
    1.34  else
    1.35 @@ -40,6 +59,8 @@ endif
    1.36  
    1.37  test-gcc-flag = $(shell $(1) -v --help 2>&1 | grep -q " $(2) " && echo $(2))
    1.38  
    1.39 +CFLAGS += -Wall -Wstrict-prototypes
    1.40 +
    1.41  HOSTCFLAGS += $(call test-gcc-flag,$(HOSTCC),-Wdeclaration-after-statement)
    1.42  CFLAGS     += $(call test-gcc-flag,$(CC),-Wdeclaration-after-statement)
    1.43  
     2.1 --- a/buildconfigs/linux-defconfig_xen0_x86_64	Tue Mar 14 13:10:21 2006 -0700
     2.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_64	Tue Mar 14 13:50:35 2006 -0700
     2.3 @@ -108,6 +108,7 @@ CONFIG_MICROCODE=y
     2.4  CONFIG_X86_IO_APIC=y
     2.5  CONFIG_X86_XEN_GENAPIC=y
     2.6  CONFIG_X86_LOCAL_APIC=y
     2.7 +CONFIG_MTRR=y
     2.8  # CONFIG_SMP is not set
     2.9  CONFIG_PREEMPT_NONE=y
    2.10  # CONFIG_PREEMPT_VOLUNTARY is not set
     3.1 --- a/buildconfigs/linux-defconfig_xen_x86_64	Tue Mar 14 13:10:21 2006 -0700
     3.2 +++ b/buildconfigs/linux-defconfig_xen_x86_64	Tue Mar 14 13:50:35 2006 -0700
     3.3 @@ -111,6 +111,7 @@ CONFIG_MICROCODE=y
     3.4  CONFIG_X86_IO_APIC=y
     3.5  CONFIG_X86_XEN_GENAPIC=y
     3.6  CONFIG_X86_LOCAL_APIC=y
     3.7 +CONFIG_MTRR=y
     3.8  CONFIG_SMP=y
     3.9  CONFIG_PREEMPT_NONE=y
    3.10  # CONFIG_PREEMPT_VOLUNTARY is not set
     4.1 --- a/extras/mini-os/Makefile	Tue Mar 14 13:10:21 2006 -0700
     4.2 +++ b/extras/mini-os/Makefile	Tue Mar 14 13:50:35 2006 -0700
     4.3 @@ -32,6 +32,7 @@ OBJS := $(TARGET_ARCH).o
     4.4  OBJS += $(patsubst %.c,%.o,$(wildcard *.c))
     4.5  OBJS += $(patsubst %.c,%.o,$(wildcard lib/*.c))
     4.6  OBJS += $(patsubst %.c,%.o,$(wildcard xenbus/*.c))
     4.7 +#OBJS += $(patsubst %.c,%.o,$(wildcard console/*.c))
     4.8  										   
     4.9  HDRS := $(wildcard include/*.h)
    4.10  HDRS += $(wildcard include/xen/*.h)
     5.1 --- a/extras/mini-os/domain_config	Tue Mar 14 13:10:21 2006 -0700
     5.2 +++ b/extras/mini-os/domain_config	Tue Mar 14 13:50:35 2006 -0700
     5.3 @@ -15,3 +15,5 @@ memory = 32
     5.4  
     5.5  # A name for your domain. All domains must have different names.
     5.6  name = "Mini-OS"
     5.7 +
     5.8 +on_crash = 'destroy'
     6.1 --- a/extras/mini-os/include/lib.h	Tue Mar 14 13:10:21 2006 -0700
     6.2 +++ b/extras/mini-os/include/lib.h	Tue Mar 14 13:50:35 2006 -0700
     6.3 @@ -57,6 +57,7 @@
     6.4  
     6.5  #include <stdarg.h>
     6.6  
     6.7 +
     6.8  /* printing */
     6.9  #define printk  printf
    6.10  #define kprintf printf
     7.1 --- a/extras/mini-os/include/mm.h	Tue Mar 14 13:10:21 2006 -0700
     7.2 +++ b/extras/mini-os/include/mm.h	Tue Mar 14 13:50:35 2006 -0700
     7.3 @@ -25,18 +25,34 @@
     7.4  #ifndef _MM_H_
     7.5  #define _MM_H_
     7.6  
     7.7 -#ifdef __i386__
     7.8 +#if defined(__i386__)
     7.9  #include <xen/arch-x86_32.h>
    7.10 +#elif defined(__x86_64__)
    7.11 +#include <xen/arch-x86_64.h>
    7.12 +#else
    7.13 +#error "Unsupported architecture"
    7.14  #endif
    7.15  
    7.16 -#ifdef __x86_64__
    7.17 -#include <xen/arch-x86_64.h>
    7.18 -#endif
    7.19 +#include <lib.h>
    7.20  
    7.21 -
    7.22 -#ifdef __x86_64__
    7.23 +#define L1_FRAME                1
    7.24 +#define L2_FRAME                2
    7.25 +#define L3_FRAME                3
    7.26  
    7.27  #define L1_PAGETABLE_SHIFT      12
    7.28 +
    7.29 +#if defined(__i386__)
    7.30 +
    7.31 +#define L2_PAGETABLE_SHIFT      22
    7.32 +
    7.33 +#define L1_PAGETABLE_ENTRIES    1024
    7.34 +#define L2_PAGETABLE_ENTRIES    1024
    7.35 +
    7.36 +#define PADDR_BITS              32
    7.37 +#define PADDR_MASK              (~0UL)
    7.38 +
    7.39 +#elif defined(__x86_64__)
    7.40 +
    7.41  #define L2_PAGETABLE_SHIFT      21
    7.42  #define L3_PAGETABLE_SHIFT      30
    7.43  #define L4_PAGETABLE_SHIFT      39
    7.44 @@ -52,29 +68,29 @@
    7.45  #define PADDR_MASK              ((1UL << PADDR_BITS)-1)
    7.46  #define VADDR_MASK              ((1UL << VADDR_BITS)-1)
    7.47  
    7.48 -#define pte_to_mfn(_pte) (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT)
    7.49 +/* Get physical address of page mapped by pte (paddr_t). */
    7.50 +#define l1e_get_paddr(x)           \
    7.51 +    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
    7.52 +#define l2e_get_paddr(x)           \
    7.53 +    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
    7.54 +#define l3e_get_paddr(x)           \
    7.55 +    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
    7.56 +#define l4e_get_paddr(x)           \
    7.57 +    ((unsigned long)(((x) & (PADDR_MASK&PAGE_MASK))))
    7.58 +
    7.59 +#define L2_MASK  ((1UL << L3_PAGETABLE_SHIFT) - 1)
    7.60 +#define L3_MASK  ((1UL << L4_PAGETABLE_SHIFT) - 1)
    7.61  
    7.62  #endif
    7.63  
    7.64 -
    7.65 -
    7.66 -#ifdef __i386__
    7.67 -
    7.68 -#define L1_PAGETABLE_SHIFT      12
    7.69 -#define L2_PAGETABLE_SHIFT      22
    7.70 -
    7.71 -#define L1_PAGETABLE_ENTRIES    1024
    7.72 -#define L2_PAGETABLE_ENTRIES    1024
    7.73 -
    7.74 -#elif defined(__x86_64__)
    7.75 -#endif
    7.76 +#define L1_MASK  ((1UL << L2_PAGETABLE_SHIFT) - 1)
    7.77  
    7.78  /* Given a virtual address, get an entry offset into a page table. */
    7.79  #define l1_table_offset(_a) \
    7.80    (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
    7.81  #define l2_table_offset(_a) \
    7.82    (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
    7.83 -#ifdef __x86_64__
    7.84 +#if defined(__x86_64__)
    7.85  #define l3_table_offset(_a) \
    7.86    (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
    7.87  #define l4_table_offset(_a) \
    7.88 @@ -92,8 +108,15 @@
    7.89  #define _PAGE_PSE      0x080UL
    7.90  #define _PAGE_GLOBAL   0x100UL
    7.91  
    7.92 -#define L1_PROT (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED)
    7.93 -#define L2_PROT (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_USER)
    7.94 +#if defined(__i386__)
    7.95 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
    7.96 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY |_PAGE_USER)
    7.97 +#elif defined(__x86_64__)
    7.98 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
    7.99 +#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   7.100 +#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   7.101 +#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
   7.102 +#endif
   7.103  
   7.104  #define PAGE_SIZE       (1UL << L1_PAGETABLE_SHIFT)
   7.105  #define PAGE_SHIFT      L1_PAGETABLE_SHIFT
   7.106 @@ -124,9 +147,9 @@ static __inline__ unsigned long machine_
   7.107      return phys;
   7.108  }
   7.109  
   7.110 -#ifdef __x86_64__
   7.111 +#if defined(__x86_64__)
   7.112  #define VIRT_START              0xFFFFFFFF00000000UL
   7.113 -#else
   7.114 +#elif defined(__i386__)
   7.115  #define VIRT_START              0xC0000000UL
   7.116  #endif
   7.117  
   7.118 @@ -136,6 +159,11 @@ static __inline__ unsigned long machine_
   7.119  #define virt_to_pfn(_virt)         (PFN_DOWN(to_phys(_virt)))
   7.120  #define mach_to_virt(_mach)        (to_virt(machine_to_phys(_mach)))
   7.121  #define mfn_to_virt(_mfn)          (mach_to_virt(_mfn << PAGE_SHIFT))
   7.122 +#define pfn_to_virt(_pfn)          (to_virt(_pfn << PAGE_SHIFT))
   7.123 +
   7.124 +/* Pagetable walking. */
   7.125 +#define pte_to_mfn(_pte)           (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT)
   7.126 +#define pte_to_virt(_pte)          to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT)
   7.127  
   7.128  void init_mm(void);
   7.129  unsigned long alloc_pages(int order);
     8.1 --- a/extras/mini-os/include/os.h	Tue Mar 14 13:10:21 2006 -0700
     8.2 +++ b/extras/mini-os/include/os.h	Tue Mar 14 13:50:35 2006 -0700
     8.3 @@ -59,6 +59,8 @@ extern shared_info_t *HYPERVISOR_shared_
     8.4  
     8.5  void trap_init(void);
     8.6  
     8.7 +
     8.8 +
     8.9  /* 
    8.10   * The use of 'barrier' in the following reflects their use as local-lock
    8.11   * operations. Reentrancy must be prevented (e.g., __cli()) /before/ following
     9.1 --- a/extras/mini-os/mm.c	Tue Mar 14 13:10:21 2006 -0700
     9.2 +++ b/extras/mini-os/mm.c	Tue Mar 14 13:50:35 2006 -0700
     9.3 @@ -51,7 +51,8 @@
     9.4  unsigned long *phys_to_machine_mapping;
     9.5  extern char *stack;
     9.6  extern char _text, _etext, _edata, _end;
     9.7 -
     9.8 +extern void do_exit(void);
     9.9 +extern void page_walk(unsigned long virt_addr);
    9.10  
    9.11  /*********************
    9.12   * ALLOCATION BITMAP
    9.13 @@ -64,7 +65,6 @@ static unsigned long *alloc_bitmap;
    9.14  #define allocated_in_map(_pn) \
    9.15  (alloc_bitmap[(_pn)/PAGES_PER_MAPWORD] & (1<<((_pn)&(PAGES_PER_MAPWORD-1))))
    9.16  
    9.17 -
    9.18  /*
    9.19   * Hint regarding bitwise arithmetic in map_{alloc,free}:
    9.20   *  -(1<<n)  sets all bits >= n. 
    9.21 @@ -208,7 +208,6 @@ static void init_page_allocator(unsigned
    9.22      unsigned long range, bitmap_size;
    9.23      chunk_head_t *ch;
    9.24      chunk_tail_t *ct;
    9.25 -
    9.26      for ( i = 0; i < FREELIST_SIZE; i++ )
    9.27      {
    9.28          free_head[i]       = &free_tail[i];
    9.29 @@ -366,106 +365,181 @@ void free_pages(void *pointer, int order
    9.30      free_head[order] = freed_ch;   
    9.31     
    9.32  }
    9.33 -void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
    9.34 -{
    9.35 -    unsigned long pfn_to_map, pt_frame;
    9.36 -    unsigned long mach_ptd, max_mach_ptd;
    9.37 -    int count;
    9.38 -    unsigned long mach_pte, virt_pte;
    9.39 -    unsigned long *ptd = (unsigned long *)start_info.pt_base;
    9.40 -    mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
    9.41 +
    9.42 +
    9.43 +void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
    9.44 +                                unsigned long offset, unsigned long level)
    9.45 +{   
    9.46 +    unsigned long *tab = (unsigned long *)start_info.pt_base;
    9.47 +    unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
    9.48 +    unsigned long prot_e, prot_t, pincmd;
    9.49 +    mmu_update_t mmu_updates[0];
    9.50      struct mmuext_op pin_request;
    9.51      
    9.52 -    /* Firstly work out what is the first pfn that is not yet in page tables
    9.53 -       NB. Assuming that builder fills whole pt_frames (which it does at the
    9.54 -       moment)
    9.55 -     */  
    9.56 -    pfn_to_map = (start_info.nr_pt_frames - 1) * L1_PAGETABLE_ENTRIES;
    9.57 -    DEBUG("start_pfn=%ld, first pfn_to_map %ld, max_pfn=%ld", 
    9.58 -            *start_pfn, pfn_to_map, *max_pfn);
    9.59 +    DEBUG("Allocating new L%d pt frame for pt_pfn=%lx, "
    9.60 +           "prev_l_mfn=%lx, offset=%lx\n", 
    9.61 +           level, *pt_pfn, prev_l_mfn, offset);
    9.62  
    9.63 -    /* Machine address of page table directory */
    9.64 -    mach_ptd = phys_to_machine(to_phys(start_info.pt_base));
    9.65 -    mach_ptd += sizeof(void *) * 
    9.66 -        l2_table_offset((unsigned long)to_virt(PFN_PHYS(pfn_to_map)));
    9.67 -  
    9.68 -    max_mach_ptd = sizeof(void *) * 
    9.69 -        l2_table_offset((unsigned long)to_virt(PFN_PHYS(*max_pfn)));
    9.70 -    
    9.71 -    /* Check that we are not trying to access Xen region */
    9.72 -    if(max_mach_ptd > sizeof(void *) * l2_table_offset(HYPERVISOR_VIRT_START))
    9.73 +    if (level == L1_FRAME)
    9.74 +    {
    9.75 +         prot_e = L1_PROT;
    9.76 +         prot_t = L2_PROT;
    9.77 +         pincmd = MMUEXT_PIN_L1_TABLE;
    9.78 +    }
    9.79 +#if (defined __x86_64__)
    9.80 +    else if (level == L2_FRAME)
    9.81      {
    9.82 -        printk("WARNING: mini-os will not use all the memory supplied\n");
    9.83 -        max_mach_ptd = sizeof(void *) * l2_table_offset(HYPERVISOR_VIRT_START);
    9.84 -        *max_pfn = virt_to_pfn(HYPERVISOR_VIRT_START - PAGE_SIZE);
    9.85 +         prot_e = L2_PROT;
    9.86 +         prot_t = L3_PROT;
    9.87 +         pincmd = MMUEXT_PIN_L2_TABLE;
    9.88      }
    9.89 -    max_mach_ptd += phys_to_machine(to_phys(start_info.pt_base));
    9.90 -    DEBUG("Max_mach_ptd 0x%lx", max_mach_ptd); 
    9.91 -   
    9.92 -    pt_frame = *start_pfn;
    9.93 -    /* Should not happen - no empty, mapped pages */
    9.94 -    if(pt_frame >= pfn_to_map)
    9.95 +    else if (level == L3_FRAME)
    9.96      {
    9.97 -        printk("ERROR: Not even a single empty, mapped page\n");
    9.98 -        *(int*)0=0;
    9.99 +         prot_e = L3_PROT;
   9.100 +         prot_t = L4_PROT;
   9.101 +         pincmd = MMUEXT_PIN_L3_TABLE;
   9.102      }
   9.103 -    
   9.104 -    while(mach_ptd < max_mach_ptd)
   9.105 +#endif
   9.106 +    else
   9.107      {
   9.108 -        /* Correct protection needs to be set for the new page table frame */
   9.109 -        virt_pte = (unsigned long)to_virt(PFN_PHYS(pt_frame));
   9.110 -        mach_pte = ptd[l2_table_offset(virt_pte)] & ~(PAGE_SIZE-1);
   9.111 -        mach_pte += sizeof(void *) * l1_table_offset(virt_pte);
   9.112 -        DEBUG("New page table page: pfn=0x%lx, mfn=0x%lx, virt_pte=0x%lx, "
   9.113 -                "mach_pte=0x%lx", pt_frame, pfn_to_mfn(pt_frame), 
   9.114 -                virt_pte, mach_pte);
   9.115 -        
   9.116 -        /* Update the entry */
   9.117 -        mmu_updates[0].ptr = mach_pte;
   9.118 -        mmu_updates[0].val = pfn_to_mfn(pt_frame) << PAGE_SHIFT | 
   9.119 -                                                    (L1_PROT & ~_PAGE_RW);
   9.120 -        if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0)
   9.121 -        {
   9.122 -            printk("PTE for new page table page could not be updated\n");
   9.123 -            *(int*)0=0;
   9.124 -        }
   9.125 -        
   9.126 -        /* Pin the page to provide correct protection */
   9.127 -        pin_request.cmd = MMUEXT_PIN_L1_TABLE;
   9.128 -        pin_request.arg1.mfn = pfn_to_mfn(pt_frame);
   9.129 -        if(HYPERVISOR_mmuext_op(&pin_request, 1, NULL, DOMID_SELF) < 0)
   9.130 -        {
   9.131 -            printk("ERROR: pinning failed\n");
   9.132 -            *(int*)0=0;
   9.133 -        }
   9.134 -        
   9.135 -        /* Now fill the new page table page with entries.
   9.136 -           Update the page directory as well. */
   9.137 -        count = 0;
   9.138 -        mmu_updates[count].ptr = mach_ptd;
   9.139 -        mmu_updates[count].val = pfn_to_mfn(pt_frame) << PAGE_SHIFT |
   9.140 -                                                         L2_PROT;
   9.141 -        count++;
   9.142 -        mach_ptd += sizeof(void *);
   9.143 -        mach_pte = phys_to_machine(PFN_PHYS(pt_frame++));
   9.144 -        
   9.145 -        for(;count <= L1_PAGETABLE_ENTRIES && pfn_to_map <= *max_pfn; count++)
   9.146 -        {
   9.147 -            mmu_updates[count].ptr = mach_pte;
   9.148 -            mmu_updates[count].val = 
   9.149 -                pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
   9.150 -            if(count == 1) DEBUG("mach_pte 0x%lx", mach_pte);
   9.151 -            mach_pte += sizeof(void *);
   9.152 -        }
   9.153 -        if(HYPERVISOR_mmu_update(mmu_updates, count, NULL, DOMID_SELF) < 0) 
   9.154 -        {            
   9.155 -            printk("ERROR: mmu_update failed\n");
   9.156 -            *(int*)0=0;
   9.157 -        }
   9.158 -        (*start_pfn)++;
   9.159 +         printk("new_pt_frame() called with invalid level number %d\n", level);
   9.160 +         do_exit();
   9.161 +    }    
   9.162 +
   9.163 +    /* Update the entry */
   9.164 +#if (defined __x86_64__)
   9.165 +    tab = pte_to_virt(tab[l4_table_offset(pt_page)]);
   9.166 +    tab = pte_to_virt(tab[l3_table_offset(pt_page)]);
   9.167 +#endif
   9.168 +    mmu_updates[0].ptr = (tab[l2_table_offset(pt_page)] & PAGE_MASK) + 
   9.169 +                         sizeof(void *)* l1_table_offset(pt_page);
   9.170 +    mmu_updates[0].val = pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | 
   9.171 +                         (prot_e & ~_PAGE_RW);
   9.172 +    if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0)
   9.173 +    {
   9.174 +         printk("PTE for new page table page could not be updated\n");
   9.175 +         do_exit();
   9.176 +    }
   9.177 +                        
   9.178 +    /* Pin the page to provide correct protection */
   9.179 +    pin_request.cmd = pincmd;
   9.180 +    pin_request.arg1.mfn = pfn_to_mfn(*pt_pfn);
   9.181 +    if(HYPERVISOR_mmuext_op(&pin_request, 1, NULL, DOMID_SELF) < 0)
   9.182 +    {
   9.183 +        printk("ERROR: pinning failed\n");
   9.184 +        do_exit();
   9.185 +    }
   9.186 +
   9.187 +    /* Now fill the new page table page with entries.
   9.188 +       Update the page directory as well. */
   9.189 +    mmu_updates[0].ptr = (prev_l_mfn << PAGE_SHIFT) + sizeof(void *) * offset;
   9.190 +    mmu_updates[0].val = pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
   9.191 +    if(HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF) < 0) 
   9.192 +    {            
   9.193 +       printk("ERROR: mmu_update failed\n");
   9.194 +       do_exit();
   9.195      }
   9.196  
   9.197 -    *start_pfn = pt_frame;
   9.198 +    *pt_pfn += 1;
   9.199 +}
   9.200 +
   9.201 +void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
   9.202 +{
   9.203 +    unsigned long start_address, end_address;
   9.204 +    unsigned long pfn_to_map, pt_pfn = *start_pfn;
   9.205 +    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
   9.206 +    unsigned long *tab = (unsigned long *)start_info.pt_base;
   9.207 +    unsigned long mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
   9.208 +    unsigned long page, offset;
   9.209 +    int count = 0;
   9.210 +
   9.211 +#if defined(__x86_64__)
   9.212 +    pfn_to_map = (start_info.nr_pt_frames - 3) * L1_PAGETABLE_ENTRIES;
   9.213 +#else
   9.214 +    pfn_to_map = (start_info.nr_pt_frames - 1) * L1_PAGETABLE_ENTRIES;
   9.215 +#endif
   9.216 +    start_address = (unsigned long)pfn_to_virt(pfn_to_map);
   9.217 +    end_address = (unsigned long)pfn_to_virt(*max_pfn);
   9.218 +    
   9.219 +    /* We worked out the virtual memory range to map, now mapping loop */
   9.220 +    printk("Mapping memory range 0x%lx - 0x%lx\n", start_address, end_address);
   9.221 +
   9.222 +    while(start_address < end_address)
   9.223 +    {
   9.224 +        tab = (unsigned long *)start_info.pt_base;
   9.225 +        mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
   9.226 +
   9.227 +#if defined(__x86_64__)
   9.228 +        offset = l4_table_offset(start_address);
   9.229 +        /* Need new L3 pt frame */
   9.230 +        if(!(start_address & L3_MASK)) 
   9.231 +            new_pt_frame(&pt_pfn, mfn, offset, L3_FRAME);
   9.232 +        
   9.233 +        page = tab[offset];
   9.234 +        mfn = pte_to_mfn(page);
   9.235 +        tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
   9.236 +        offset = l3_table_offset(start_address);
   9.237 +        /* Need new L2 pt frame */
   9.238 +        if(!(start_address & L2_MASK)) 
   9.239 +            new_pt_frame(&pt_pfn, mfn, offset, L2_FRAME);
   9.240 +
   9.241 +        page = tab[offset];
   9.242 +        mfn = pte_to_mfn(page);
   9.243 +        tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
   9.244 +#endif
   9.245 +        offset = l2_table_offset(start_address);        
   9.246 +        /* Need new L1 pt frame */
   9.247 +        if(!(start_address & L1_MASK)) 
   9.248 +            new_pt_frame(&pt_pfn, mfn, offset, L1_FRAME);
   9.249 +       
   9.250 +        page = tab[offset];
   9.251 +        mfn = pte_to_mfn(page);
   9.252 +        offset = l1_table_offset(start_address);
   9.253 +
   9.254 +        mmu_updates[count].ptr = (mfn << PAGE_SHIFT) + sizeof(void *) * offset;
   9.255 +        mmu_updates[count].val = 
   9.256 +            pfn_to_mfn(pfn_to_map++) << PAGE_SHIFT | L1_PROT;
   9.257 +        count++;
   9.258 +        if (count == L1_PAGETABLE_ENTRIES || pfn_to_map == *max_pfn)
   9.259 +        {
   9.260 +            if(HYPERVISOR_mmu_update(mmu_updates, count, NULL, DOMID_SELF) < 0)
   9.261 +            {
   9.262 +                printk("PTE could not be updated\n");
   9.263 +                do_exit();
   9.264 +            }
   9.265 +            count = 0;
   9.266 +        }
   9.267 +        start_address += PAGE_SIZE;
   9.268 +    }
   9.269 +
   9.270 +    *start_pfn = pt_pfn;
   9.271 +}
   9.272 +
   9.273 +
   9.274 +void mem_test(unsigned long *start_add, unsigned long *end_add)
   9.275 +{
   9.276 +    unsigned long mask = 0x10000;
   9.277 +    unsigned long *pointer;
   9.278 +
   9.279 +    for(pointer = start_add; pointer < end_add; pointer++)
   9.280 +    {
   9.281 +        if(!(((unsigned long)pointer) & 0xfffff))
   9.282 +        {
   9.283 +            printk("Writing to %lx\n", pointer);
   9.284 +            page_walk((unsigned long)pointer);
   9.285 +        }
   9.286 +        *pointer = (unsigned long)pointer & ~mask;
   9.287 +    }
   9.288 +
   9.289 +    for(pointer = start_add; pointer < end_add; pointer++)
   9.290 +    {
   9.291 +        if(((unsigned long)pointer & ~mask) != *pointer)
   9.292 +            printk("Read error at 0x%lx. Read: 0x%lx, should read 0x%lx\n",
   9.293 +                (unsigned long)pointer, 
   9.294 +                *pointer, 
   9.295 +                ((unsigned long)pointer & ~mask));
   9.296 +    }
   9.297 +
   9.298  }
   9.299  
   9.300  void init_mm(void)
   9.301 @@ -485,23 +559,21 @@ void init_mm(void)
   9.302      phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
   9.303     
   9.304      /* First page follows page table pages and 3 more pages (store page etc) */
   9.305 -    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames + 3;
   9.306 +    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + 
   9.307 +                start_info.nr_pt_frames + 3;
   9.308      max_pfn = start_info.nr_pages;
   9.309 -
   9.310 +   
   9.311      printk("  start_pfn:    %lx\n", start_pfn);
   9.312      printk("  max_pfn:      %lx\n", max_pfn);
   9.313  
   9.314 -
   9.315 -#ifdef __i386__
   9.316      build_pagetable(&start_pfn, &max_pfn);
   9.317 -#endif
   9.318 -
   9.319 +    
   9.320      /*
   9.321       * now we can initialise the page allocator
   9.322       */
   9.323      printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
   9.324             (u_long)to_virt(PFN_PHYS(start_pfn)), PFN_PHYS(start_pfn), 
   9.325             (u_long)to_virt(PFN_PHYS(max_pfn)), PFN_PHYS(max_pfn));
   9.326 -    init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));   
   9.327 +    init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
   9.328      printk("MM: done\n");
   9.329  }
    10.1 --- a/extras/mini-os/traps.c	Tue Mar 14 13:10:21 2006 -0700
    10.2 +++ b/extras/mini-os/traps.c	Tue Mar 14 13:50:35 2006 -0700
    10.3 @@ -70,6 +70,30 @@ DO_ERROR(12, "stack segment", stack_segm
    10.4  DO_ERROR_INFO(17, "alignment check", alignment_check, BUS_ADRALN, 0)
    10.5  DO_ERROR(18, "machine check", machine_check)
    10.6  
    10.7 +void page_walk(unsigned long virt_address)
    10.8 +{
    10.9 +        unsigned long *tab = (unsigned long *)start_info.pt_base;
   10.10 +        unsigned long addr = virt_address, page;
   10.11 +        printk("Pagetable walk from virt %lx, base %lx:\n", virt_address, start_info.pt_base);
   10.12 +    
   10.13 +#if defined(__x86_64__)
   10.14 +        page = tab[l4_table_offset(addr)];
   10.15 +        tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   10.16 +        printk(" L4 = %p (%p)  [offset = %lx]\n", page, tab, l4_table_offset(addr));
   10.17 +
   10.18 +        page = tab[l3_table_offset(addr)];
   10.19 +        tab = to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   10.20 +        printk("  L3 = %p (%p)  [offset = %lx]\n", page, tab, l3_table_offset(addr));
   10.21 +#endif
   10.22 +        page = tab[l2_table_offset(addr)];
   10.23 +        tab =  to_virt(mfn_to_pfn(pte_to_mfn(page)) << PAGE_SHIFT);
   10.24 +        printk("   L2 = %p (%p)  [offset = %lx]\n", page, tab, l2_table_offset(addr));
   10.25 +        
   10.26 +        page = tab[l1_table_offset(addr)];
   10.27 +        printk("    L1 = %p (%p)  [offset = %lx]\n", page, tab, l1_table_offset(addr));
   10.28 +
   10.29 +}
   10.30 +
   10.31  void do_page_fault(struct pt_regs *regs, unsigned long error_code,
   10.32  								                     unsigned long addr)
   10.33  {
    11.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c	Tue Mar 14 13:10:21 2006 -0700
    11.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/cpu/mtrr/main-xen.c	Tue Mar 14 13:50:35 2006 -0700
    11.3 @@ -8,6 +8,8 @@
    11.4  #include <asm/mtrr.h>
    11.5  #include "mtrr.h"
    11.6  
    11.7 +static DECLARE_MUTEX(mtrr_sem);
    11.8 +
    11.9  void generic_get_mtrr(unsigned int reg, unsigned long *base,
   11.10  		      unsigned int *size, mtrr_type * type)
   11.11  {
   11.12 @@ -63,12 +65,15 @@ int mtrr_add_page(unsigned long base, un
   11.13  	int error;
   11.14  	dom0_op_t op;
   11.15  
   11.16 +	down(&mtrr_sem);
   11.17 +
   11.18  	op.cmd = DOM0_ADD_MEMTYPE;
   11.19  	op.u.add_memtype.mfn     = base;
   11.20  	op.u.add_memtype.nr_mfns = size;
   11.21  	op.u.add_memtype.type    = type;
   11.22  	error = HYPERVISOR_dom0_op(&op);
   11.23  	if (error) {
   11.24 +		up(&mtrr_sem);
   11.25  		BUG_ON(error > 0);
   11.26  		return error;
   11.27  	}
   11.28 @@ -76,6 +81,8 @@ int mtrr_add_page(unsigned long base, un
   11.29  	if (increment)
   11.30  		++usage_table[op.u.add_memtype.reg];
   11.31  
   11.32 +	up(&mtrr_sem);
   11.33 +
   11.34  	return op.u.add_memtype.reg;
   11.35  }
   11.36  
   11.37 @@ -104,17 +111,18 @@ mtrr_add(unsigned long base, unsigned lo
   11.38  
   11.39  int mtrr_del_page(int reg, unsigned long base, unsigned long size)
   11.40  {
   11.41 -	int i, max;
   11.42 +	unsigned i;
   11.43  	mtrr_type ltype;
   11.44  	unsigned long lbase;
   11.45  	unsigned int lsize;
   11.46  	int error = -EINVAL;
   11.47  	dom0_op_t op;
   11.48  
   11.49 -	max = num_var_ranges;
   11.50 +	down(&mtrr_sem);
   11.51 +
   11.52  	if (reg < 0) {
   11.53  		/*  Search for existing MTRR  */
   11.54 -		for (i = 0; i < max; ++i) {
   11.55 +		for (i = 0; i < num_var_ranges; ++i) {
   11.56  			mtrr_if->get(i, &lbase, &lsize, &ltype);
   11.57  			if (lbase == base && lsize == size) {
   11.58  				reg = i;
   11.59 @@ -143,6 +151,7 @@ int mtrr_del_page(int reg, unsigned long
   11.60  	}
   11.61  	error = reg;
   11.62   out:
   11.63 +	up(&mtrr_sem);
   11.64  	return error;
   11.65  }
   11.66  
    12.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/entry-xen.S	Tue Mar 14 13:10:21 2006 -0700
    12.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/entry-xen.S	Tue Mar 14 13:50:35 2006 -0700
    12.3 @@ -79,6 +79,10 @@ VM_MASK		= 0x00020000
    12.4  /* Pseudo-eflags. */
    12.5  NMI_MASK	= 0x80000000
    12.6  
    12.7 +#ifndef CONFIG_XEN
    12.8 +#define DISABLE_INTERRUPTS	cli
    12.9 +#define ENABLE_INTERRUPTS	sti
   12.10 +#else
   12.11  /* Offsets into shared_info_t. */
   12.12  #define evtchn_upcall_pending		/* 0 */
   12.13  #define evtchn_upcall_mask		1
   12.14 @@ -86,33 +90,24 @@ NMI_MASK	= 0x80000000
   12.15  #define sizeof_vcpu_shift		6
   12.16  
   12.17  #ifdef CONFIG_SMP
   12.18 -#define preempt_disable(reg)	incl TI_preempt_count(reg)
   12.19 -#define preempt_enable(reg)	decl TI_preempt_count(reg)
   12.20 -#define XEN_GET_VCPU_INFO(reg)	preempt_disable(%ebp)			; \
   12.21 -				movl TI_cpu(%ebp),reg			; \
   12.22 -				shl  $sizeof_vcpu_shift,reg		; \
   12.23 -				addl HYPERVISOR_shared_info,reg
   12.24 -#define XEN_PUT_VCPU_INFO(reg) preempt_enable(%ebp)
   12.25 -#define XEN_PUT_VCPU_INFO_fixup .byte 0xff,0xff,0xff
   12.26 +#define GET_VCPU_INFO		movl TI_cpu(%ebp),%esi			; \
   12.27 +				shl  $sizeof_vcpu_shift,%esi		; \
   12.28 +				addl HYPERVISOR_shared_info,%esi
   12.29  #else
   12.30 -#define XEN_GET_VCPU_INFO(reg) movl HYPERVISOR_shared_info,reg
   12.31 -#define XEN_PUT_VCPU_INFO(reg)
   12.32 -#define XEN_PUT_VCPU_INFO_fixup
   12.33 +#define GET_VCPU_INFO		movl HYPERVISOR_shared_info,%esi
   12.34  #endif
   12.35  
   12.36 -#define XEN_LOCKED_BLOCK_EVENTS(reg)	movb $1,evtchn_upcall_mask(reg)
   12.37 -#define XEN_LOCKED_UNBLOCK_EVENTS(reg)	movb $0,evtchn_upcall_mask(reg)
   12.38 -#define XEN_BLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
   12.39 -				XEN_LOCKED_BLOCK_EVENTS(reg)		; \
   12.40 -    				XEN_PUT_VCPU_INFO(reg)
   12.41 -#define XEN_UNBLOCK_EVENTS(reg)	XEN_GET_VCPU_INFO(reg)			; \
   12.42 -				XEN_LOCKED_UNBLOCK_EVENTS(reg)		; \
   12.43 -    				XEN_PUT_VCPU_INFO(reg)
   12.44 -#define XEN_TEST_PENDING(reg)	testb $0xFF,evtchn_upcall_pending(reg)
   12.45 +#define __DISABLE_INTERRUPTS	movb $1,evtchn_upcall_mask(%esi)
   12.46 +#define __ENABLE_INTERRUPTS	movb $0,evtchn_upcall_mask(%esi)
   12.47 +#define DISABLE_INTERRUPTS	GET_VCPU_INFO				; \
   12.48 +				__DISABLE_INTERRUPTS
   12.49 +#define ENABLE_INTERRUPTS	GET_VCPU_INFO				; \
   12.50 +				__ENABLE_INTERRUPTS
   12.51 +#define __TEST_PENDING		testb $0xFF,evtchn_upcall_pending(%esi)
   12.52 +#endif
   12.53  
   12.54  #ifdef CONFIG_PREEMPT
   12.55 -#define preempt_stop		GET_THREAD_INFO(%ebp)			; \
   12.56 -				XEN_BLOCK_EVENTS(%esi)
   12.57 +#define preempt_stop		cli
   12.58  #else
   12.59  #define preempt_stop
   12.60  #define resume_kernel		restore_nocheck
   12.61 @@ -159,21 +154,6 @@ 4:	movl $0,(%esp);	\
   12.62  .previous
   12.63  
   12.64  
   12.65 -#define RESTORE_ALL	\
   12.66 -	RESTORE_REGS	\
   12.67 -	addl $4, %esp;	\
   12.68 -1:	iret;		\
   12.69 -.section .fixup,"ax";   \
   12.70 -2:	pushl $0;	\
   12.71 -	pushl $do_iret_error;	\
   12.72 -	jmp error_code;	\
   12.73 -.previous;		\
   12.74 -.section __ex_table,"a";\
   12.75 -	.align 4;	\
   12.76 -	.long 1b,2b;	\
   12.77 -.previous
   12.78 -
   12.79 -
   12.80  ENTRY(ret_from_fork)
   12.81  	pushl %eax
   12.82  	call schedule_tail
   12.83 @@ -199,7 +179,7 @@ ret_from_intr:
   12.84  	testl $(VM_MASK | 2), %eax
   12.85  	jz resume_kernel
   12.86  ENTRY(resume_userspace)
   12.87 -	XEN_BLOCK_EVENTS(%esi)		# make sure we don't miss an interrupt
   12.88 +	DISABLE_INTERRUPTS		# make sure we don't miss an interrupt
   12.89  					# setting need_resched or sigpending
   12.90  					# between sampling and the iret
   12.91  	movl TI_flags(%ebp), %ecx
   12.92 @@ -210,15 +190,15 @@ ENTRY(resume_userspace)
   12.93  
   12.94  #ifdef CONFIG_PREEMPT
   12.95  ENTRY(resume_kernel)
   12.96 -	XEN_BLOCK_EVENTS(%esi)
   12.97 +	cli
   12.98  	cmpl $0,TI_preempt_count(%ebp)	# non-zero preempt_count ?
   12.99  	jnz restore_nocheck
  12.100  need_resched:
  12.101  	movl TI_flags(%ebp), %ecx	# need_resched set ?
  12.102  	testb $_TIF_NEED_RESCHED, %cl
  12.103  	jz restore_all
  12.104 -	testb $0xFF,EVENT_MASK(%esp)	# interrupts off (exception path) ?
  12.105 -	jnz restore_all
  12.106 +	testl $IF_MASK,EFLAGS(%esp)     # interrupts off (exception path) ?
  12.107 +	jz restore_all
  12.108  	call preempt_schedule_irq
  12.109  	jmp need_resched
  12.110  #endif
  12.111 @@ -289,7 +269,7 @@ syscall_call:
  12.112  	call *sys_call_table(,%eax,4)
  12.113  	movl %eax,EAX(%esp)		# store the return value
  12.114  syscall_exit:
  12.115 -	XEN_BLOCK_EVENTS(%esi)		# make sure we don't miss an interrupt
  12.116 +	DISABLE_INTERRUPTS		# make sure we don't miss an interrupt
  12.117  					# setting need_resched or sigpending
  12.118  					# between sampling and the iret
  12.119  	movl TI_flags(%ebp), %ecx
  12.120 @@ -297,7 +277,7 @@ syscall_exit:
  12.121  	jne syscall_exit_work
  12.122  
  12.123  restore_all:
  12.124 -#if 0 /* XEN */
  12.125 +#ifndef CONFIG_XEN
  12.126  	movl EFLAGS(%esp), %eax		# mix EFLAGS, SS and CS
  12.127  	# Warning: OLDSS(%esp) contains the wrong/random values if we
  12.128  	# are returning to the kernel.
  12.129 @@ -307,22 +287,26 @@ restore_all:
  12.130  	andl $(VM_MASK | (4 << 8) | 3), %eax
  12.131  	cmpl $((4 << 8) | 3), %eax
  12.132  	je ldt_ss			# returning to user-space with LDT SS
  12.133 -#endif /* XEN */
  12.134 +restore_nocheck:
  12.135 +#else
  12.136  restore_nocheck:
  12.137  	testl $(VM_MASK|NMI_MASK), EFLAGS(%esp)
  12.138  	jnz hypervisor_iret
  12.139  	movb EVENT_MASK(%esp), %al
  12.140  	notb %al			# %al == ~saved_mask
  12.141 -	XEN_GET_VCPU_INFO(%esi)
  12.142 +	GET_VCPU_INFO
  12.143  	andb evtchn_upcall_mask(%esi),%al
  12.144  	andb $1,%al			# %al == mask & ~saved_mask
  12.145  	jnz restore_all_enable_events	#     != 0 => reenable event delivery
  12.146 -	XEN_PUT_VCPU_INFO(%esi)
  12.147 +#endif
  12.148  	RESTORE_REGS
  12.149  	addl $4, %esp
  12.150  1:	iret
  12.151  .section .fixup,"ax"
  12.152  iret_exc:
  12.153 +#ifndef CONFIG_XEN
  12.154 +	sti
  12.155 +#endif
  12.156  	pushl $0			# no error code
  12.157  	pushl $do_iret_error
  12.158  	jmp error_code
  12.159 @@ -332,13 +316,7 @@ iret_exc:
  12.160  	.long 1b,iret_exc
  12.161  .previous
  12.162  
  12.163 -hypervisor_iret:
  12.164 -	andl $~NMI_MASK, EFLAGS(%esp)
  12.165 -	RESTORE_REGS
  12.166 -	addl $4, %esp
  12.167 -	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
  12.168 -
  12.169 -#if 0 /* XEN */
  12.170 +#ifndef CONFIG_XEN
  12.171  ldt_ss:
  12.172  	larl OLDSS(%esp), %eax
  12.173  	jnz restore_nocheck
  12.174 @@ -363,7 +341,13 @@ 1:	iret
  12.175  	.align 4
  12.176  	.long 1b,iret_exc
  12.177  .previous
  12.178 -#endif /* XEN */
  12.179 +#else
  12.180 +hypervisor_iret:
  12.181 +	andl $~NMI_MASK, EFLAGS(%esp)
  12.182 +	RESTORE_REGS
  12.183 +	addl $4, %esp
  12.184 +	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
  12.185 +#endif
  12.186  
  12.187  	# perform work that needs to be done immediately before resumption
  12.188  	ALIGN
  12.189 @@ -372,7 +356,7 @@ work_pending:
  12.190  	jz work_notifysig
  12.191  work_resched:
  12.192  	call schedule
  12.193 -	XEN_BLOCK_EVENTS(%esi)		# make sure we don't miss an interrupt
  12.194 +	DISABLE_INTERRUPTS		# make sure we don't miss an interrupt
  12.195  					# setting need_resched or sigpending
  12.196  					# between sampling and the iret
  12.197  	movl TI_flags(%ebp), %ecx
  12.198 @@ -424,7 +408,7 @@ syscall_trace_entry:
  12.199  syscall_exit_work:
  12.200  	testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
  12.201  	jz work_pending
  12.202 -	XEN_UNBLOCK_EVENTS(%esi)	# could let do_syscall_trace() call
  12.203 +	ENABLE_INTERRUPTS		# could let do_syscall_trace() call
  12.204  					# schedule() instead
  12.205  	movl %esp, %eax
  12.206  	movl $1, %edx
  12.207 @@ -444,7 +428,7 @@ syscall_badsys:
  12.208  	movl $-ENOSYS,EAX(%esp)
  12.209  	jmp resume_userspace
  12.210  
  12.211 -#if 0 /* XEN */
  12.212 +#ifndef CONFIG_XEN
  12.213  #define FIXUP_ESPFIX_STACK \
  12.214  	movl %esp, %eax; \
  12.215  	/* switch to 32bit stack using the pointer on top of 16bit stack */ \
  12.216 @@ -503,7 +487,9 @@ ENTRY(name)				\
  12.217  
  12.218  /* The include is where all of the SMP etc. interrupts come from */
  12.219  #include "entry_arch.h"
  12.220 -#endif /* XEN */
  12.221 +#else
  12.222 +#define UNWIND_ESPFIX_STACK
  12.223 +#endif
  12.224  
  12.225  ENTRY(divide_error)
  12.226  	pushl $0			# no error code
  12.227 @@ -522,7 +508,7 @@ error_code:
  12.228  	pushl %ebx
  12.229  	cld
  12.230  	pushl %es
  12.231 -#	UNWIND_ESPFIX_STACK
  12.232 +	UNWIND_ESPFIX_STACK
  12.233  	popl %ecx
  12.234  	movl ES(%esp), %edi		# get the function address
  12.235  	movl ORIG_EAX(%esp), %edx	# get the error code
  12.236 @@ -535,6 +521,7 @@ error_code:
  12.237  	call *%edi
  12.238  	jmp ret_from_exception
  12.239  
  12.240 +#ifdef CONFIG_XEN
  12.241  # A note on the "critical region" in our callback handler.
  12.242  # We want to avoid stacking callback handlers due to events occurring
  12.243  # during handling of the last event. To do this, we keep events disabled
  12.244 @@ -560,15 +547,24 @@ 11:	push %esp
  12.245  	jmp  ret_from_intr
  12.246  
  12.247          ALIGN
  12.248 -restore_all_enable_events:  
  12.249 -	XEN_LOCKED_UNBLOCK_EVENTS(%esi)
  12.250 +restore_all_enable_events:
  12.251 +	__ENABLE_INTERRUPTS
  12.252  scrit:	/**** START OF CRITICAL REGION ****/
  12.253 -	XEN_TEST_PENDING(%esi)
  12.254 +	__TEST_PENDING
  12.255  	jnz  14f			# process more events if necessary...
  12.256 -	XEN_PUT_VCPU_INFO(%esi)
  12.257 -	RESTORE_ALL
  12.258 -14:	XEN_LOCKED_BLOCK_EVENTS(%esi)
  12.259 -	XEN_PUT_VCPU_INFO(%esi)
  12.260 +	RESTORE_REGS
  12.261 +	addl $4, %esp
  12.262 +1:	iret
  12.263 +.section .fixup,"ax"
  12.264 +2:	pushl $0
  12.265 +	pushl $do_iret_error
  12.266 +	jmp error_code
  12.267 +.previous
  12.268 +.section __ex_table,"a"
  12.269 +	.align 4
  12.270 +	.long 1b,2b
  12.271 +.previous
  12.272 +14:	__DISABLE_INTERRUPTS
  12.273  	jmp  11b
  12.274  ecrit:  /**** END OF CRITICAL REGION ****/
  12.275  # [How we do the fixup]. We want to merge the current stack frame with the
  12.276 @@ -577,14 +573,13 @@ ecrit:  /**** END OF CRITICAL REGION ***
  12.277  # registers are in each frame. We do this quickly using the lookup table
  12.278  # 'critical_fixup_table'. For each byte offset in the critical region, it
  12.279  # provides the number of bytes which have already been popped from the
  12.280 -# interrupted stack frame. 
  12.281 +# interrupted stack frame.
  12.282  critical_region_fixup:
  12.283  	addl $critical_fixup_table-scrit,%eax
  12.284  	movzbl (%eax),%eax		# %eax contains num bytes popped
  12.285  	cmpb $0xff,%al                  # 0xff => vcpu_info critical region
  12.286  	jne  15f
  12.287  	GET_THREAD_INFO(%ebp)
  12.288 -	XEN_PUT_VCPU_INFO(%esi)         # abort vcpu_info critical region
  12.289          xorl %eax,%eax
  12.290  15:	mov  %esp,%esi
  12.291  	add  %eax,%esi			# %esi points at end of src region
  12.292 @@ -602,9 +597,8 @@ 17:	movl %edi,%esp			# final %edi is top
  12.293  	jmp  11b
  12.294  
  12.295  critical_fixup_table:
  12.296 -	.byte 0xff,0xff,0xff		# testb $0xff,(%esi) = XEN_TEST_PENDING
  12.297 +	.byte 0xff,0xff,0xff		# testb $0xff,(%esi) = __TEST_PENDING
  12.298  	.byte 0xff,0xff			# jnz  14f
  12.299 -	XEN_PUT_VCPU_INFO_fixup
  12.300  	.byte 0x00			# pop  %ebx
  12.301  	.byte 0x04			# pop  %ecx
  12.302  	.byte 0x08			# pop  %edx
  12.303 @@ -617,7 +611,6 @@ critical_fixup_table:
  12.304  	.byte 0x24,0x24,0x24		# add  $4,%esp
  12.305  	.byte 0x28			# iret
  12.306  	.byte 0xff,0xff,0xff,0xff	# movb $1,1(%esi)
  12.307 -	XEN_PUT_VCPU_INFO_fixup
  12.308  	.byte 0x00,0x00			# jmp  11b
  12.309  
  12.310  # Hypervisor uses this for application faults while it executes.
  12.311 @@ -646,6 +639,7 @@ 9:	movl $0,(%esp);	\
  12.312  	.long 3b,8b;	\
  12.313  	.long 4b,9b;	\
  12.314  .previous
  12.315 +#endif
  12.316  
  12.317  ENTRY(coprocessor_error)
  12.318  	pushl $0
  12.319 @@ -660,7 +654,17 @@ ENTRY(simd_coprocessor_error)
  12.320  ENTRY(device_not_available)
  12.321  	pushl $-1			# mark this as an int
  12.322  	SAVE_ALL
  12.323 -	#preempt_stop /* This is already an interrupt gate on Xen. */
  12.324 +#ifndef CONFIG_XEN
  12.325 +	movl %cr0, %eax
  12.326 +	testl $0x4, %eax		# EM (math emulation bit)
  12.327 +	je device_available_emulate
  12.328 +	pushl $0			# temporary storage for ORIG_EIP
  12.329 +	call math_emulate
  12.330 +	addl $4, %esp
  12.331 +	jmp ret_from_exception
  12.332 +device_available_emulate:
  12.333 +#endif
  12.334 +	preempt_stop
  12.335  	call math_state_restore
  12.336  	jmp ret_from_exception
  12.337  
  12.338 @@ -703,16 +707,7 @@ debug_stack_correct:
  12.339  	jmp ret_from_exception
  12.340  	.previous .text
  12.341  
  12.342 -ENTRY(nmi)
  12.343 -	pushl %eax
  12.344 -	SAVE_ALL
  12.345 -	xorl %edx,%edx		# zero error code
  12.346 -	movl %esp,%eax		# pt_regs pointer
  12.347 -	call do_nmi
  12.348 -	orl  $NMI_MASK, EFLAGS(%esp)
  12.349 -	jmp restore_all
  12.350 -
  12.351 -#if 0 /* XEN */
  12.352 +#ifndef CONFIG_XEN
  12.353  /*
  12.354   * NMI is doubly nasty. It can happen _while_ we're handling
  12.355   * a debug fault, and the debug fault hasn't yet been able to
  12.356 @@ -783,7 +778,16 @@ 1:	iret
  12.357  	.align 4
  12.358  	.long 1b,iret_exc
  12.359  .previous
  12.360 -#endif /* XEN */
  12.361 +#else
  12.362 +ENTRY(nmi)
  12.363 +	pushl %eax
  12.364 +	SAVE_ALL
  12.365 +	xorl %edx,%edx		# zero error code
  12.366 +	movl %esp,%eax		# pt_regs pointer
  12.367 +	call do_nmi
  12.368 +	orl  $NMI_MASK, EFLAGS(%esp)
  12.369 +	jmp restore_all
  12.370 +#endif
  12.371  
  12.372  KPROBE_ENTRY(int3)
  12.373  	pushl $-1			# mark this as an int
    13.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S	Tue Mar 14 13:10:21 2006 -0700
    13.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/head-xen.S	Tue Mar 14 13:50:35 2006 -0700
    13.3 @@ -30,8 +30,6 @@ ENTRY(startup_32)
    13.4  	/* Set up the stack pointer */
    13.5  	movl $(init_thread_union+THREAD_SIZE),%esp
    13.6  
    13.7 -checkCPUtype:
    13.8 -
    13.9  	/* get vendor info */
   13.10  	xorl %eax,%eax			# call CPUID with 0 -> return vendor ID
   13.11  	cpuid
    14.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c	Tue Mar 14 13:10:21 2006 -0700
    14.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/process-xen.c	Tue Mar 14 13:50:35 2006 -0700
    14.3 @@ -107,9 +107,9 @@ void xen_idle(void)
    14.4  {
    14.5  	local_irq_disable();
    14.6  
    14.7 -	if (need_resched()) {
    14.8 +	if (need_resched())
    14.9  		local_irq_enable();
   14.10 -	} else {
   14.11 +	else {
   14.12  		clear_thread_flag(TIF_POLLING_NRFLAG);
   14.13  		smp_mb__after_clear_bit();
   14.14  		stop_hz_timer();
    15.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Tue Mar 14 13:10:21 2006 -0700
    15.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/time-xen.c	Tue Mar 14 13:50:35 2006 -0700
    15.3 @@ -157,18 +157,26 @@ static int __init __independent_wallcloc
    15.4  }
    15.5  __setup("independent_wallclock", __independent_wallclock);
    15.6  
    15.7 +/* Permitted clock jitter, in usecs, beyond which a warning will be printed. */
    15.8 +static unsigned long permitted_clock_jitter = 10000UL;
    15.9 +static int __init __permitted_clock_jitter(char *str)
   15.10 +{
   15.11 +	permitted_clock_jitter = simple_strtoul(str, NULL, 0);
   15.12 +	return 1;
   15.13 +}
   15.14 +__setup("permitted_clock_jitter=", __permitted_clock_jitter);
   15.15 +
   15.16  int tsc_disable __devinitdata = 0;
   15.17  
   15.18  static void delay_tsc(unsigned long loops)
   15.19  {
   15.20  	unsigned long bclock, now;
   15.21 -	
   15.22 +
   15.23  	rdtscl(bclock);
   15.24 -	do
   15.25 -	{
   15.26 +	do {
   15.27  		rep_nop();
   15.28  		rdtscl(now);
   15.29 -	} while ((now-bclock) < loops);
   15.30 +	} while ((now - bclock) < loops);
   15.31  }
   15.32  
   15.33  struct timer_opts timer_tsc = {
   15.34 @@ -187,7 +195,7 @@ static inline u64 scale_delta(u64 delta,
   15.35  	u32 tmp1, tmp2;
   15.36  #endif
   15.37  
   15.38 -	if ( shift < 0 )
   15.39 +	if (shift < 0)
   15.40  		delta >>= -shift;
   15.41  	else
   15.42  		delta <<= shift;
   15.43 @@ -226,7 +234,7 @@ void init_cpu_khz(void)
   15.44  	struct vcpu_time_info *info;
   15.45  	info = &HYPERVISOR_shared_info->vcpu_info[0].time;
   15.46  	do_div(__cpu_khz, info->tsc_to_system_mul);
   15.47 -	if ( info->tsc_shift < 0 )
   15.48 +	if (info->tsc_shift < 0)
   15.49  		cpu_khz = __cpu_khz << -info->tsc_shift;
   15.50  	else
   15.51  		cpu_khz = __cpu_khz >> info->tsc_shift;
   15.52 @@ -284,8 +292,7 @@ static void update_wallclock(void)
   15.53  		shadow_tv.tv_sec  = s->wc_sec;
   15.54  		shadow_tv.tv_nsec = s->wc_nsec;
   15.55  		rmb();
   15.56 -	}
   15.57 -	while ((s->wc_version & 1) | (shadow_tv_version ^ s->wc_version));
   15.58 +	} while ((s->wc_version & 1) | (shadow_tv_version ^ s->wc_version));
   15.59  
   15.60  	if (!independent_wallclock)
   15.61  		__update_wallclock(shadow_tv.tv_sec, shadow_tv.tv_nsec);
   15.62 @@ -312,8 +319,7 @@ static void get_time_values_from_xen(voi
   15.63  		dst->tsc_to_nsec_mul   = src->tsc_to_system_mul;
   15.64  		dst->tsc_shift         = src->tsc_shift;
   15.65  		rmb();
   15.66 -	}
   15.67 -	while ((src->version & 1) | (dst->version ^ src->version));
   15.68 +	} while ((src->version & 1) | (dst->version ^ src->version));
   15.69  
   15.70  	dst->tsc_to_usec_mul = dst->tsc_to_nsec_mul / 1000;
   15.71  }
   15.72 @@ -324,8 +330,9 @@ static inline int time_values_up_to_date
   15.73  	struct shadow_time_info *dst;
   15.74  
   15.75  	src = &HYPERVISOR_shared_info->vcpu_info[cpu].time;
   15.76 -	dst = &per_cpu(shadow_time, cpu); 
   15.77 +	dst = &per_cpu(shadow_time, cpu);
   15.78  
   15.79 +	rmb();
   15.80  	return (dst->version == src->version);
   15.81  }
   15.82  
   15.83 @@ -454,7 +461,7 @@ int do_settimeofday(struct timespec *tv)
   15.84  	 * overflows. If that were to happen then our shadow time values would
   15.85  	 * be stale, so we can retry with fresh ones.
   15.86  	 */
   15.87 -	for ( ; ; ) {
   15.88 +	for (;;) {
   15.89  		nsec = tv->tv_nsec - get_nsec_offset(shadow);
   15.90  		if (time_values_up_to_date(cpu))
   15.91  			break;
   15.92 @@ -552,11 +559,11 @@ unsigned long long monotonic_clock(void)
   15.93  
   15.94  	do {
   15.95  		local_time_version = shadow->version;
   15.96 -		smp_rmb();
   15.97 +		barrier();
   15.98  		time = shadow->system_timestamp + get_nsec_offset(shadow);
   15.99  		if (!time_values_up_to_date(cpu))
  15.100  			get_time_values_from_xen();
  15.101 -		smp_rmb();
  15.102 +		barrier();
  15.103  	} while (local_time_version != shadow->version);
  15.104  
  15.105  	put_cpu();
  15.106 @@ -614,7 +621,7 @@ irqreturn_t timer_interrupt(int irq, voi
  15.107  		get_time_values_from_xen();
  15.108  
  15.109  		/* Obtain a consistent snapshot of elapsed wallclock cycles. */
  15.110 -		delta = delta_cpu = 
  15.111 +		delta = delta_cpu =
  15.112  			shadow->system_timestamp + get_nsec_offset(shadow);
  15.113  		delta     -= processed_system_time;
  15.114  		delta_cpu -= per_cpu(processed_system_time, cpu);
  15.115 @@ -633,13 +640,13 @@ irqreturn_t timer_interrupt(int irq, voi
  15.116  				per_cpu(processed_blocked_time, cpu);
  15.117  			barrier();
  15.118  		} while (sched_time != runstate->state_entry_time);
  15.119 -	}
  15.120 -	while (!time_values_up_to_date(cpu));
  15.121 +	} while (!time_values_up_to_date(cpu));
  15.122  
  15.123 -	if ((unlikely(delta < -1000000LL) || unlikely(delta_cpu < 0))
  15.124 +	if ((unlikely(delta < -(s64)permitted_clock_jitter) ||
  15.125 +	     unlikely(delta_cpu < -(s64)permitted_clock_jitter))
  15.126  	    && printk_ratelimit()) {
  15.127  		printk("Timer ISR/%d: Time went backwards: "
  15.128 -		       "delta=%lld cpu_delta=%lld shadow=%lld "
  15.129 +		       "delta=%lld delta_cpu=%lld shadow=%lld "
  15.130  		       "off=%lld processed=%lld cpu_processed=%lld\n",
  15.131  		       cpu, delta, delta_cpu, shadow->system_timestamp,
  15.132  		       (s64)get_nsec_offset(shadow),
  15.133 @@ -669,8 +676,10 @@ irqreturn_t timer_interrupt(int irq, voi
  15.134  	 * HACK: Passing NULL to account_steal_time()
  15.135  	 * ensures that the ticks are accounted as stolen.
  15.136  	 */
  15.137 -	if (stolen > 0) {
  15.138 +	if ((stolen > 0) && (delta_cpu > 0)) {
  15.139  		delta_cpu -= stolen;
  15.140 +		if (unlikely(delta_cpu < 0))
  15.141 +			stolen += delta_cpu; /* clamp local-time progress */
  15.142  		do_div(stolen, NS_PER_TICK);
  15.143  		per_cpu(processed_stolen_time, cpu) += stolen * NS_PER_TICK;
  15.144  		per_cpu(processed_system_time, cpu) += stolen * NS_PER_TICK;
  15.145 @@ -682,8 +691,10 @@ irqreturn_t timer_interrupt(int irq, voi
  15.146  	 * HACK: Passing idle_task to account_steal_time()
  15.147  	 * ensures that the ticks are accounted as idle/wait.
  15.148  	 */
  15.149 -	if (blocked > 0) {
  15.150 +	if ((blocked > 0) && (delta_cpu > 0)) {
  15.151  		delta_cpu -= blocked;
  15.152 +		if (unlikely(delta_cpu < 0))
  15.153 +			blocked += delta_cpu; /* clamp local-time progress */
  15.154  		do_div(blocked, NS_PER_TICK);
  15.155  		per_cpu(processed_blocked_time, cpu) += blocked * NS_PER_TICK;
  15.156  		per_cpu(processed_system_time, cpu)  += blocked * NS_PER_TICK;
  15.157 @@ -938,7 +949,7 @@ void __init time_init(void)
  15.158  }
  15.159  
  15.160  /* Convert jiffies to system time. */
  15.161 -static inline u64 jiffies_to_st(unsigned long j) 
  15.162 +u64 jiffies_to_st(unsigned long j)
  15.163  {
  15.164  	unsigned long seq;
  15.165  	long delta;
  15.166 @@ -949,13 +960,14 @@ static inline u64 jiffies_to_st(unsigned
  15.167  		delta = j - jiffies;
  15.168  		/* NB. The next check can trigger in some wrap-around cases,
  15.169  		 * but that's ok: we'll just end up with a shorter timeout. */
  15.170 -		if (delta < 1) 
  15.171 +		if (delta < 1)
  15.172  			delta = 1;
  15.173  		st = processed_system_time + (delta * (u64)NS_PER_TICK);
  15.174  	} while (read_seqretry(&xtime_lock, seq));
  15.175  
  15.176  	return st;
  15.177  }
  15.178 +EXPORT_SYMBOL(jiffies_to_st);
  15.179  
  15.180  /*
  15.181   * stop_hz_timer / start_hz_timer - enter/exit 'tickless mode' on an idle cpu
  15.182 @@ -965,7 +977,7 @@ void stop_hz_timer(void)
  15.183  {
  15.184  	unsigned int cpu = smp_processor_id();
  15.185  	unsigned long j;
  15.186 -	
  15.187 +
  15.188  	/* We must do this /before/ checking rcu_pending(). */
  15.189  	cpu_set(cpu, nohz_cpu_mask);
  15.190  	smp_mb();
  15.191 @@ -1012,7 +1024,7 @@ void local_setup_timer(unsigned int cpu)
  15.192  	do {
  15.193  		seq = read_seqbegin(&xtime_lock);
  15.194  		/* Use cpu0 timestamp: cpu's shadow is not initialised yet. */
  15.195 -		per_cpu(processed_system_time, cpu) = 
  15.196 +		per_cpu(processed_system_time, cpu) =
  15.197  			per_cpu(shadow_time, 0).system_timestamp;
  15.198  		init_missing_ticks_accounting(cpu);
  15.199  	} while (read_seqretry(&xtime_lock, seq));
  15.200 @@ -1041,13 +1053,31 @@ void local_teardown_timer(unsigned int c
  15.201   * now however.
  15.202   */
  15.203  static ctl_table xen_subtable[] = {
  15.204 -	{1, "independent_wallclock", &independent_wallclock,
  15.205 -	 sizeof(independent_wallclock), 0644, NULL, proc_dointvec},
  15.206 -	{0}
  15.207 +	{
  15.208 +		.ctl_name	= 1,
  15.209 +		.procname	= "independent_wallclock",
  15.210 +		.data		= &independent_wallclock,
  15.211 +		.maxlen		= sizeof(independent_wallclock),
  15.212 +		.mode		= 0644,
  15.213 +		.proc_handler	= proc_dointvec
  15.214 +	},
  15.215 +	{
  15.216 +		.ctl_name	= 2,
  15.217 +		.procname	= "permitted_clock_jitter",
  15.218 +		.data		= &permitted_clock_jitter,
  15.219 +		.maxlen		= sizeof(permitted_clock_jitter),
  15.220 +		.mode		= 0644,
  15.221 +		.proc_handler	= proc_doulongvec_minmax
  15.222 +	},
  15.223 +	{ 0 }
  15.224  };
  15.225  static ctl_table xen_table[] = {
  15.226 -	{123, "xen", NULL, 0, 0555, xen_subtable},
  15.227 -	{0}
  15.228 +	{
  15.229 +		.ctl_name	= 123,
  15.230 +		.procname	= "xen",
  15.231 +		.mode		= 0555,
  15.232 +		.child		= xen_subtable},
  15.233 +	{ 0 }
  15.234  };
  15.235  static int __init xen_sysctl_init(void)
  15.236  {
    16.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Tue Mar 14 13:10:21 2006 -0700
    16.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Tue Mar 14 13:50:35 2006 -0700
    16.3 @@ -201,56 +201,6 @@ void xen_pgd_unpin(unsigned long ptr)
    16.4  	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
    16.5  }
    16.6  
    16.7 -void xen_pte_pin(unsigned long ptr)
    16.8 -{
    16.9 -	struct mmuext_op op;
   16.10 -	op.cmd = MMUEXT_PIN_L1_TABLE;
   16.11 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.12 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.13 -}
   16.14 -
   16.15 -void xen_pte_unpin(unsigned long ptr)
   16.16 -{
   16.17 -	struct mmuext_op op;
   16.18 -	op.cmd = MMUEXT_UNPIN_TABLE;
   16.19 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.20 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.21 -}
   16.22 -
   16.23 -#ifdef CONFIG_X86_64
   16.24 -void xen_pud_pin(unsigned long ptr)
   16.25 -{
   16.26 -	struct mmuext_op op;
   16.27 -	op.cmd = MMUEXT_PIN_L3_TABLE;
   16.28 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.29 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.30 -}
   16.31 -
   16.32 -void xen_pud_unpin(unsigned long ptr)
   16.33 -{
   16.34 -	struct mmuext_op op;
   16.35 -	op.cmd = MMUEXT_UNPIN_TABLE;
   16.36 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.37 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.38 -}
   16.39 -
   16.40 -void xen_pmd_pin(unsigned long ptr)
   16.41 -{
   16.42 -	struct mmuext_op op;
   16.43 -	op.cmd = MMUEXT_PIN_L2_TABLE;
   16.44 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.45 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.46 -}
   16.47 -
   16.48 -void xen_pmd_unpin(unsigned long ptr)
   16.49 -{
   16.50 -	struct mmuext_op op;
   16.51 -	op.cmd = MMUEXT_UNPIN_TABLE;
   16.52 -	op.arg1.mfn = pfn_to_mfn(ptr >> PAGE_SHIFT);
   16.53 -	BUG_ON(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
   16.54 -}
   16.55 -#endif /* CONFIG_X86_64 */
   16.56 -
   16.57  void xen_set_ldt(unsigned long ptr, unsigned long len)
   16.58  {
   16.59  	struct mmuext_op op;
    17.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c	Tue Mar 14 13:10:21 2006 -0700
    17.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/init-xen.c	Tue Mar 14 13:50:35 2006 -0700
    17.3 @@ -556,10 +556,15 @@ void __init paging_init(void)
    17.4  
    17.5  	kmap_init();
    17.6  
    17.7 -	/* Switch to the real shared_info page, and clear the dummy page. */
    17.8 -	set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info);
    17.9 -	HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
   17.10 -	memset(empty_zero_page, 0, sizeof(empty_zero_page));
   17.11 +	if (!xen_feature(XENFEAT_auto_translated_physmap) ||
   17.12 +	    xen_start_info->shared_info >= xen_start_info->nr_pages) {
   17.13 +		/* Switch to the real shared_info page, and clear the
   17.14 +		 * dummy page. */
   17.15 +		set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info);
   17.16 +		HYPERVISOR_shared_info =
   17.17 +			(shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
   17.18 +		memset(empty_zero_page, 0, sizeof(empty_zero_page));
   17.19 +	}
   17.20  
   17.21  	/* Setup mapping of lower 1st MB */
   17.22  	for (i = 0; i < NR_FIX_ISAMAPS; i++)
    18.1 --- a/linux-2.6-xen-sparse/arch/x86_64/Kconfig	Tue Mar 14 13:10:21 2006 -0700
    18.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/Kconfig	Tue Mar 14 13:50:35 2006 -0700
    18.3 @@ -222,7 +222,7 @@ config X86_LOCAL_APIC
    18.4  
    18.5  config MTRR
    18.6  	bool "MTRR (Memory Type Range Register) support"
    18.7 -	depends on !X86_64_XEN
    18.8 +	depends on !XEN_UNPRIVILEGED_GUEST
    18.9  	---help---
   18.10  	  On Intel P6 family processors (Pentium Pro, Pentium II and later)
   18.11  	  the Memory Type Range Registers (MTRRs) may be used to control
    19.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c	Tue Mar 14 13:10:21 2006 -0700
    19.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/process-xen.c	Tue Mar 14 13:50:35 2006 -0700
    19.3 @@ -124,9 +124,9 @@ void xen_idle(void)
    19.4  {
    19.5  	local_irq_disable();
    19.6  
    19.7 -	if (need_resched()) {
    19.8 +	if (need_resched())
    19.9  		local_irq_enable();
   19.10 -	} else {
   19.11 +	else {
   19.12  		clear_thread_flag(TIF_POLLING_NRFLAG);
   19.13  		smp_mb__after_clear_bit();
   19.14  		stop_hz_timer();
    20.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Tue Mar 14 13:10:21 2006 -0700
    20.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/setup-xen.c	Tue Mar 14 13:50:35 2006 -0700
    20.3 @@ -664,6 +664,13 @@ void __init setup_arch(char **cmdline_p)
    20.4  
    20.5  	setup_xen_features();
    20.6  
    20.7 +	if (xen_feature(XENFEAT_auto_translated_physmap) &&
    20.8 +	    xen_start_info->shared_info < xen_start_info->nr_pages) {
    20.9 +		HYPERVISOR_shared_info =
   20.10 +			(shared_info_t *)__va(xen_start_info->shared_info);
   20.11 +		memset(empty_zero_page, 0, sizeof(empty_zero_page));
   20.12 +	}
   20.13 +
   20.14  	HYPERVISOR_vm_assist(VMASST_CMD_enable,
   20.15  			     VMASST_TYPE_writable_pagetables);
   20.16  
    21.1 --- a/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Tue Mar 14 13:10:21 2006 -0700
    21.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/mm/init-xen.c	Tue Mar 14 13:50:35 2006 -0700
    21.3 @@ -244,7 +244,6 @@ static void set_pte_phys(unsigned long v
    21.4  	if (pud_none(*pud)) {
    21.5  		pmd = (pmd_t *) spp_getpage(); 
    21.6  		make_page_readonly(pmd, XENFEAT_writable_page_tables);
    21.7 -		xen_pmd_pin(__pa(pmd));
    21.8  		set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER));
    21.9  		if (pmd != pmd_offset(pud, 0)) {
   21.10  			printk("PAGETABLE BUG #01! %p <-> %p\n", pmd, pmd_offset(pud,0));
   21.11 @@ -255,7 +254,6 @@ static void set_pte_phys(unsigned long v
   21.12  	if (pmd_none(*pmd)) {
   21.13  		pte = (pte_t *) spp_getpage();
   21.14  		make_page_readonly(pte, XENFEAT_writable_page_tables);
   21.15 -		xen_pte_pin(__pa(pte));
   21.16  		set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE | _PAGE_USER));
   21.17  		if (pte != pte_offset_kernel(pmd, 0)) {
   21.18  			printk("PAGETABLE BUG #02!\n");
   21.19 @@ -297,7 +295,6 @@ static void set_pte_phys_ma(unsigned lon
   21.20  
   21.21  		pmd = (pmd_t *) spp_getpage(); 
   21.22  		make_page_readonly(pmd, XENFEAT_writable_page_tables);
   21.23 -		xen_pmd_pin(__pa(pmd));
   21.24  
   21.25  		set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE | _PAGE_USER));
   21.26  
   21.27 @@ -311,7 +308,6 @@ static void set_pte_phys_ma(unsigned lon
   21.28  	if (pmd_none(*pmd)) {
   21.29  		pte = (pte_t *) spp_getpage();
   21.30  		make_page_readonly(pte, XENFEAT_writable_page_tables);
   21.31 -		xen_pte_pin(__pa(pte));
   21.32  
   21.33  		set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE | _PAGE_USER));
   21.34  		if (pte != pte_offset_kernel(pmd, 0)) {
   21.35 @@ -461,7 +457,6 @@ phys_pmd_init(pmd_t *pmd, unsigned long 
   21.36  		}
   21.37  		pte = pte_save;
   21.38  		early_make_page_readonly(pte, XENFEAT_writable_page_tables);
   21.39 -		xen_pte_pin(pte_phys);
   21.40  		set_pmd(pmd, __pmd(pte_phys | _KERNPG_TABLE));
   21.41  	}
   21.42  }
   21.43 @@ -500,7 +495,6 @@ static void __meminit phys_pud_init(pud_
   21.44  
   21.45  		pmd = alloc_static_page(&pmd_phys);
   21.46  		early_make_page_readonly(pmd, XENFEAT_writable_page_tables);
   21.47 -		xen_pmd_pin(pmd_phys);
   21.48  		spin_lock(&init_mm.page_table_lock);
   21.49  		set_pud(pud, __pud(pmd_phys | _KERNPG_TABLE));
   21.50  		phys_pmd_init(pmd, paddr, end);
   21.51 @@ -545,9 +539,6 @@ void __init xen_init_pt(void)
   21.52  
   21.53  	xen_pgd_pin(__pa_symbol(init_level4_pgt));
   21.54  	xen_pgd_pin(__pa_symbol(init_level4_user_pgt));
   21.55 -	xen_pud_pin(__pa_symbol(level3_kernel_pgt));
   21.56 -	xen_pud_pin(__pa_symbol(level3_user_pgt));
   21.57 -	xen_pmd_pin(__pa_symbol(level2_kernel_pgt));
   21.58  
   21.59  	set_pgd((pgd_t *)(init_level4_user_pgt + 511), 
   21.60  		mk_kernel_pgd(__pa_symbol(level3_user_pgt)));
   21.61 @@ -581,7 +572,6 @@ void __init extend_init_mapping(void)
   21.62  			pte_page = alloc_static_page(&phys);
   21.63  			early_make_page_readonly(
   21.64  				pte_page, XENFEAT_writable_page_tables);
   21.65 -			xen_pte_pin(phys);
   21.66  			set_pmd(pmd, __pmd(phys | _KERNPG_TABLE | _PAGE_USER));
   21.67  		} else {
   21.68  			addr = page[pmd_index(va)];
   21.69 @@ -662,7 +652,6 @@ void __meminit init_memory_mapping(unsig
   21.70  			pud = alloc_static_page(&pud_phys);
   21.71  			early_make_page_readonly(pud, XENFEAT_writable_page_tables);
   21.72  		}
   21.73 -		xen_pud_pin(pud_phys);
   21.74  		next = start + PGDIR_SIZE;
   21.75  		if (next > end) 
   21.76  			next = end; 
   21.77 @@ -757,10 +746,16 @@ void __init paging_init(void)
   21.78  	free_area_init_node(0, NODE_DATA(0), zones,
   21.79  			    __pa(PAGE_OFFSET) >> PAGE_SHIFT, holes);
   21.80  
   21.81 -	set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info);
   21.82 -	HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
   21.83 +	if (!xen_feature(XENFEAT_auto_translated_physmap) ||
   21.84 +	    xen_start_info->shared_info >= xen_start_info->nr_pages) {
   21.85 +		/* Switch to the real shared_info page, and clear the
   21.86 +		 * dummy page. */
   21.87 +		set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info);
   21.88 +		HYPERVISOR_shared_info =
   21.89 +			(shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
   21.90 +		memset(empty_zero_page, 0, sizeof(empty_zero_page));
   21.91 +	}
   21.92  
   21.93 -	memset(empty_zero_page, 0, sizeof(empty_zero_page));
   21.94  	init_mm.context.pinned = 1;
   21.95  
   21.96  	/* Setup mapping of lower 1st MB */
   21.97 @@ -937,7 +932,6 @@ void free_initmem(void)
   21.98  		ClearPageReserved(virt_to_page(addr));
   21.99  		set_page_count(virt_to_page(addr), 1);
  21.100  		memset((void *)(addr & ~(PAGE_SIZE-1)), 0xcc, PAGE_SIZE); 
  21.101 -		xen_pte_unpin(__pa(addr));
  21.102  		make_page_writable(
  21.103  			__va(__pa(addr)), XENFEAT_writable_page_tables);
  21.104  		/*
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/Kconfig	Tue Mar 14 13:10:21 2006 -0700
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig	Tue Mar 14 13:50:35 2006 -0700
    22.3 @@ -30,12 +30,14 @@ config XEN_UNPRIVILEGED_GUEST
    22.4  	default !XEN_PRIVILEGED_GUEST
    22.5  
    22.6  config XEN_PCIDEV_BACKEND
    22.7 -	bool "PCI device backend driver"
    22.8 -	select PCI
    22.9 -	default y if XEN_PRIVILEGED_GUEST
   22.10 +	tristate "PCI device backend driver"
   22.11 +	depends PCI
   22.12 +	default XEN_PRIVILEGED_GUEST
   22.13  	help
   22.14  	  The PCI device backend driver allows the kernel to export arbitrary
   22.15 -	  PCI devices to other guests.
   22.16 +	  PCI devices to other guests. If you select this to be a module, you
   22.17 +	  will need to make sure no other driver has bound to the device(s)
   22.18 +	  you want to make visible to other guests.
   22.19  
   22.20  choice
   22.21  	prompt "PCI Backend Mode"
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Mar 14 13:10:21 2006 -0700
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Mar 14 13:50:35 2006 -0700
    23.3 @@ -468,6 +468,7 @@ static int __init balloon_init(void)
    23.4  		return -1;
    23.5  
    23.6  	current_pages = min(xen_start_info->nr_pages, max_pfn);
    23.7 +	totalram_pages = current_pages;
    23.8  	target_pages  = current_pages;
    23.9  	balloon_low   = 0;
   23.10  	balloon_high  = 0;
   23.11 @@ -547,6 +548,7 @@ struct page *balloon_alloc_empty_page_ra
   23.12  		&init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL);
   23.13  	BUG_ON(ret);
   23.14  	current_pages -= 1UL << order;
   23.15 +	totalram_pages = current_pages;
   23.16  	balloon_unlock(flags);
   23.17  
   23.18  	schedule_work(&balloon_worker);
    24.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Tue Mar 14 13:10:21 2006 -0700
    24.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Tue Mar 14 13:50:35 2006 -0700
    24.3 @@ -95,21 +95,17 @@ static int blkfront_probe(struct xenbus_
    24.4  		xenbus_dev_fatal(dev, -ENOMEM, "allocating info structure");
    24.5  		return -ENOMEM;
    24.6  	}
    24.7 +
    24.8 +	memset(info, 0, sizeof(*info));
    24.9  	info->xbdev = dev;
   24.10  	info->vdevice = vdevice;
   24.11  	info->connected = BLKIF_STATE_DISCONNECTED;
   24.12 -	info->mi = NULL;
   24.13 -	info->gd = NULL;
   24.14  	INIT_WORK(&info->work, blkif_restart_queue, (void *)info);
   24.15  
   24.16 -	info->shadow_free = 0;
   24.17 -	memset(info->shadow, 0, sizeof(info->shadow));
   24.18  	for (i = 0; i < BLK_RING_SIZE; i++)
   24.19  		info->shadow[i].req.id = i+1;
   24.20  	info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff;
   24.21  
   24.22 -	info->users = 0;
   24.23 -
   24.24  	/* Front end dir is a number, which is used as the id. */
   24.25  	info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0);
   24.26  	dev->data = info;
   24.27 @@ -182,9 +178,8 @@ again:
   24.28  	}
   24.29  
   24.30  	err = xenbus_switch_state(dev, xbt, XenbusStateInitialised);
   24.31 -	if (err) {
   24.32 +	if (err)
   24.33  		goto abort_transaction;
   24.34 -	}
   24.35  
   24.36  	err = xenbus_transaction_end(xbt, 0);
   24.37  	if (err) {
   24.38 @@ -295,17 +290,17 @@ static void backend_changed(struct xenbu
   24.39  /* ** Connection ** */
   24.40  
   24.41  
   24.42 -/* 
   24.43 -** Invoked when the backend is finally 'ready' (and has told produced 
   24.44 -** the details about the physical device - #sectors, size, etc). 
   24.45 -*/
   24.46 +/*
   24.47 + * Invoked when the backend is finally 'ready' (and has told produced
   24.48 + * the details about the physical device - #sectors, size, etc).
   24.49 + */
   24.50  static void connect(struct blkfront_info *info)
   24.51  {
   24.52  	unsigned long sectors, sector_size;
   24.53  	unsigned int binfo;
   24.54  	int err;
   24.55  
   24.56 -        if( (info->connected == BLKIF_STATE_CONNECTED) || 
   24.57 +	if ((info->connected == BLKIF_STATE_CONNECTED) ||
   24.58  	    (info->connected == BLKIF_STATE_SUSPENDED) )
   24.59  		return;
   24.60  
   24.61 @@ -330,7 +325,7 @@ static void connect(struct blkfront_info
   24.62  		return;
   24.63  	}
   24.64  
   24.65 -	(void)xenbus_switch_state(info->xbdev, XBT_NULL, XenbusStateConnected); 
   24.66 +	(void)xenbus_switch_state(info->xbdev, XBT_NULL, XenbusStateConnected);
   24.67  
   24.68  	/* Kick pending requests. */
   24.69  	spin_lock_irq(&blkif_io_lock);
   24.70 @@ -353,11 +348,7 @@ static void blkfront_closing(struct xenb
   24.71  
   24.72  	DPRINTK("blkfront_closing: %s removed\n", dev->nodename);
   24.73  
   24.74 -	if (info->mi) {
   24.75 -		DPRINTK("Calling xlvbd_del\n");
   24.76 -		xlvbd_del(info);
   24.77 -		info->mi = NULL;
   24.78 -	}
   24.79 +	xlvbd_del(info);
   24.80  
   24.81  	xenbus_switch_state(dev, XBT_NULL, XenbusStateClosed);
   24.82  }
   24.83 @@ -463,8 +454,7 @@ int blkif_ioctl(struct inode *inode, str
   24.84  	DPRINTK_IOCTL("command: 0x%x, argument: 0x%lx, dev: 0x%04x\n",
   24.85  		      command, (long)argument, inode->i_rdev);
   24.86  
   24.87 -	switch ( command )
   24.88 -	{
   24.89 +	switch (command) {
   24.90  	case HDIO_GETGEO:
   24.91  		/* return ENOSYS to use defaults */
   24.92  		return -ENOSYS;
   24.93 @@ -490,7 +480,7 @@ int blkif_ioctl(struct inode *inode, str
   24.94   * blkif_queue_request
   24.95   *
   24.96   * request block io
   24.97 - * 
   24.98 + *
   24.99   * id: for guest use only.
  24.100   * operation: BLKIF_OP_{READ,WRITE,PROBE}
  24.101   * buffer: buffer to read/write into. this should be a
  24.102 @@ -557,7 +547,7 @@ static int blkif_queue_request(struct re
  24.103  			ring_req->seg[ring_req->nr_segments] =
  24.104  				(struct blkif_request_segment) {
  24.105  					.gref       = ref,
  24.106 -					.first_sect = fsect, 
  24.107 +					.first_sect = fsect,
  24.108  					.last_sect  = lsect };
  24.109  
  24.110  			ring_req->nr_segments++;
  24.111 @@ -679,9 +669,8 @@ static irqreturn_t blkif_int(int irq, vo
  24.112  		RING_FINAL_CHECK_FOR_RESPONSES(&info->ring, more_to_do);
  24.113  		if (more_to_do)
  24.114  			goto again;
  24.115 -	} else {
  24.116 +	} else
  24.117  		info->ring.sring->rsp_event = i + 1;
  24.118 -	}
  24.119  
  24.120  	kick_pending_request_queues(info);
  24.121  
  24.122 @@ -694,8 +683,8 @@ static void blkif_free(struct blkfront_i
  24.123  {
  24.124  	/* Prevent new requests being issued until we fix things up. */
  24.125  	spin_lock_irq(&blkif_io_lock);
  24.126 -	info->connected = suspend ? 
  24.127 -		BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED; 
  24.128 +	info->connected = suspend ?
  24.129 +		BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED;
  24.130  	spin_unlock_irq(&blkif_io_lock);
  24.131  
  24.132  	/* Free resources associated with old device channel. */
  24.133 @@ -706,7 +695,7 @@ static void blkif_free(struct blkfront_i
  24.134  		info->ring.sring = NULL;
  24.135  	}
  24.136  	if (info->irq)
  24.137 -		unbind_from_irqhandler(info->irq, info); 
  24.138 +		unbind_from_irqhandler(info->irq, info);
  24.139  	info->evtchn = info->irq = 0;
  24.140  
  24.141  }
  24.142 @@ -767,11 +756,11 @@ static void blkif_recover(struct blkfron
  24.143  
  24.144  	kfree(copy);
  24.145  
  24.146 -	(void)xenbus_switch_state(info->xbdev, XBT_NULL, XenbusStateConnected); 
  24.147 -	
  24.148 +	(void)xenbus_switch_state(info->xbdev, XBT_NULL, XenbusStateConnected);
  24.149 +
  24.150  	/* Now safe for us to use the shared ring */
  24.151  	spin_lock_irq(&blkif_io_lock);
  24.152 -        info->connected = BLKIF_STATE_CONNECTED;
  24.153 +	info->connected = BLKIF_STATE_CONNECTED;
  24.154  	spin_unlock_irq(&blkif_io_lock);
  24.155  
  24.156  	/* Send off requeued requests */
    25.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Tue Mar 14 13:10:21 2006 -0700
    25.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h	Tue Mar 14 13:50:35 2006 -0700
    25.3 @@ -55,24 +55,24 @@
    25.4  #include <asm/atomic.h>
    25.5  #include <asm/uaccess.h>
    25.6  
    25.7 -#if 1 
    25.8 +#if 1
    25.9  #define IPRINTK(fmt, args...) \
   25.10      printk(KERN_INFO "xen_blk: " fmt, ##args)
   25.11  #else
   25.12  #define IPRINTK(fmt, args...) ((void)0)
   25.13  #endif
   25.14  
   25.15 -#if 1 
   25.16 +#if 1
   25.17  #define WPRINTK(fmt, args...) \
   25.18      printk(KERN_WARNING "xen_blk: " fmt, ##args)
   25.19  #else
   25.20  #define WPRINTK(fmt, args...) ((void)0)
   25.21  #endif
   25.22 - 
   25.23 -#define DPRINTK(_f, _a...) pr_debug ( _f , ## _a )
   25.24 +
   25.25 +#define DPRINTK(_f, _a...) pr_debug(_f, ## _a)
   25.26  
   25.27  #if 0
   25.28 -#define DPRINTK_IOCTL(_f, _a...) printk ( KERN_ALERT _f , ## _a )
   25.29 +#define DPRINTK_IOCTL(_f, _a...) printk(KERN_ALERT _f, ## _a)
   25.30  #else
   25.31  #define DPRINTK_IOCTL(_f, _a...) ((void)0)
   25.32  #endif
   25.33 @@ -139,7 +139,7 @@ extern int blkif_ioctl(struct inode *ino
   25.34                         unsigned command, unsigned long argument);
   25.35  extern int blkif_check(dev_t dev);
   25.36  extern int blkif_revalidate(dev_t dev);
   25.37 -extern void do_blkif_request (request_queue_t *rq); 
   25.38 +extern void do_blkif_request (request_queue_t *rq);
   25.39  
   25.40  /* Virtual block-device subsystem. */
   25.41  /* Note that xlvbd_add doesn't call add_disk for you: you're expected
    26.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Tue Mar 14 13:10:21 2006 -0700
    26.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c	Tue Mar 14 13:50:35 2006 -0700
    26.3 @@ -216,6 +216,10 @@ xlvbd_alloc_gendisk(int minor, blkif_sec
    26.4  	int nr_minors = 1;
    26.5  	int err = -ENODEV;
    26.6  
    26.7 +	BUG_ON(info->gd != NULL);
    26.8 +	BUG_ON(info->mi != NULL);
    26.9 +	BUG_ON(info->rq != NULL);
   26.10 +
   26.11  	mi = xlbd_get_major_info(vdevice);
   26.12  	if (mi == NULL)
   26.13  		goto out;
   26.14 @@ -268,6 +272,7 @@ xlvbd_alloc_gendisk(int minor, blkif_sec
   26.15   out:
   26.16  	if (mi)
   26.17  		xlbd_put_major_info(mi);
   26.18 +	info->mi = NULL;
   26.19  	return err;
   26.20  }
   26.21  
   26.22 @@ -294,22 +299,20 @@ xlvbd_add(blkif_sector_t capacity, int v
   26.23  void
   26.24  xlvbd_del(struct blkfront_info *info)
   26.25  {
   26.26 -	struct block_device *bd;
   26.27 -
   26.28 -	bd = bdget(info->dev);
   26.29 -	if (bd == NULL)
   26.30 +	if (info->mi == NULL)
   26.31  		return;
   26.32  
   26.33 -	if (info->gd == NULL)
   26.34 -		return;
   26.35 -
   26.36 +	BUG_ON(info->gd == NULL);
   26.37  	del_gendisk(info->gd);
   26.38  	put_disk(info->gd);
   26.39 +	info->gd = NULL;
   26.40 +
   26.41  	xlbd_put_major_info(info->mi);
   26.42  	info->mi = NULL;
   26.43 +
   26.44 +	BUG_ON(info->rq == NULL);
   26.45  	blk_cleanup_queue(info->rq);
   26.46 -
   26.47 -	bdput(bd);
   26.48 +	info->rq = NULL;
   26.49  }
   26.50  
   26.51  /*
    27.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/console.c	Tue Mar 14 13:10:21 2006 -0700
    27.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/console.c	Tue Mar 14 13:50:35 2006 -0700
    27.3 @@ -85,8 +85,7 @@ static int __init xencons_setup(char *st
    27.4  	else if (!strncmp(str, "off", 3))
    27.5  		xc_mode = XC_OFF;
    27.6  
    27.7 -	switch ( xc_mode )
    27.8 -	{
    27.9 +	switch (xc_mode) {
   27.10  	case XC_SERIAL:
   27.11  		n = simple_strtol(str+4, &q, 10);
   27.12  		if (q > (str + 4))
   27.13 @@ -227,7 +226,7 @@ asmlinkage int xprintk(const char *fmt, 
   27.14  	va_list args;
   27.15  	int printk_len;
   27.16  	static char printk_buf[1024];
   27.17 -    
   27.18 +
   27.19  	/* Emit the output into the temporary buffer */
   27.20  	va_start(args, fmt);
   27.21  	printk_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args);
   27.22 @@ -485,7 +484,7 @@ static void xencons_flush_chars(struct t
   27.23  
   27.24  	spin_lock_irqsave(&xencons_lock, flags);
   27.25  	__xencons_tx_flush();
   27.26 -	spin_unlock_irqrestore(&xencons_lock, flags);    
   27.27 +	spin_unlock_irqrestore(&xencons_lock, flags);
   27.28  }
   27.29  
   27.30  static void xencons_wait_until_sent(struct tty_struct *tty, int timeout)
   27.31 @@ -495,17 +494,15 @@ static void xencons_wait_until_sent(stru
   27.32  	if (TTY_INDEX(tty) != 0)
   27.33  		return;
   27.34  
   27.35 -	while (DRV(tty->driver)->chars_in_buffer(tty))
   27.36 -	{
   27.37 +	while (DRV(tty->driver)->chars_in_buffer(tty)) {
   27.38  		set_current_state(TASK_INTERRUPTIBLE);
   27.39  		schedule_timeout(1);
   27.40  		if (signal_pending(current))
   27.41  			break;
   27.42 -		if ( (timeout != 0) &&
   27.43 -		     time_after(jiffies, orig_jiffies + timeout) )
   27.44 +		if (timeout && time_after(jiffies, orig_jiffies + timeout))
   27.45  			break;
   27.46  	}
   27.47 -    
   27.48 +
   27.49  	set_current_state(TASK_RUNNING);
   27.50  }
   27.51  
   27.52 @@ -521,7 +518,7 @@ static int xencons_open(struct tty_struc
   27.53  	if (xencons_tty == NULL)
   27.54  		xencons_tty = tty;
   27.55  	__xencons_tx_flush();
   27.56 -	spin_unlock_irqrestore(&xencons_lock, flags);    
   27.57 +	spin_unlock_irqrestore(&xencons_lock, flags);
   27.58  
   27.59  	return 0;
   27.60  }
   27.61 @@ -543,7 +540,7 @@ static void xencons_close(struct tty_str
   27.62  		tty->closing = 0;
   27.63  		spin_lock_irqsave(&xencons_lock, flags);
   27.64  		xencons_tty = NULL;
   27.65 -		spin_unlock_irqrestore(&xencons_lock, flags);    
   27.66 +		spin_unlock_irqrestore(&xencons_lock, flags);
   27.67  	}
   27.68  }
   27.69  
   27.70 @@ -574,7 +571,7 @@ static int __init xencons_init(void)
   27.71  
   27.72  	xencons_ring_init();
   27.73  
   27.74 -	xencons_driver = alloc_tty_driver((xc_mode == XC_SERIAL) ? 
   27.75 +	xencons_driver = alloc_tty_driver((xc_mode == XC_SERIAL) ?
   27.76  					  1 : MAX_NR_CONSOLES);
   27.77  	if (xencons_driver == NULL)
   27.78  		return -ENOMEM;
   27.79 @@ -584,15 +581,14 @@ static int __init xencons_init(void)
   27.80  	DRV(xencons_driver)->type            = TTY_DRIVER_TYPE_SERIAL;
   27.81  	DRV(xencons_driver)->subtype         = SERIAL_TYPE_NORMAL;
   27.82  	DRV(xencons_driver)->init_termios    = tty_std_termios;
   27.83 -	DRV(xencons_driver)->flags           = 
   27.84 +	DRV(xencons_driver)->flags           =
   27.85  		TTY_DRIVER_REAL_RAW |
   27.86  		TTY_DRIVER_RESET_TERMIOS |
   27.87  		TTY_DRIVER_NO_DEVFS;
   27.88  	DRV(xencons_driver)->termios         = xencons_termios;
   27.89  	DRV(xencons_driver)->termios_locked  = xencons_termios_locked;
   27.90  
   27.91 -	if (xc_mode == XC_SERIAL)
   27.92 -	{
   27.93 +	if (xc_mode == XC_SERIAL) {
   27.94  		DRV(xencons_driver)->name        = "ttyS";
   27.95  		DRV(xencons_driver)->minor_start = 64 + xc_num;
   27.96  		DRV(xencons_driver)->name_base   = 0 + xc_num;
   27.97 @@ -630,7 +626,7 @@ static int __init xencons_init(void)
   27.98  	printk("Xen virtual console successfully installed as %s%d\n",
   27.99  	       DRV(xencons_driver)->name,
  27.100  	       DRV(xencons_driver)->name_base );
  27.101 -    
  27.102 +
  27.103  	return 0;
  27.104  }
  27.105  
    28.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Tue Mar 14 13:10:21 2006 -0700
    28.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Tue Mar 14 13:50:35 2006 -0700
    28.3 @@ -55,7 +55,7 @@ int xencons_ring_send(const char *data, 
    28.4  	notify_daemon();
    28.5  
    28.6  	return sent;
    28.7 -}	
    28.8 +}
    28.9  
   28.10  static irqreturn_t handle_input(int irq, void *unused, struct pt_regs *regs)
   28.11  {
    29.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Tue Mar 14 13:10:21 2006 -0700
    29.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Tue Mar 14 13:50:35 2006 -0700
    29.3 @@ -72,7 +72,7 @@ DEFINE_PER_CPU(int, virq_to_irq[NR_VIRQS
    29.4  
    29.5  /* IRQ <-> IPI mapping. */
    29.6  #ifndef NR_IPIS
    29.7 -#define NR_IPIS 1 
    29.8 +#define NR_IPIS 1
    29.9  #endif
   29.10  DEFINE_PER_CPU(int, ipi_to_irq[NR_IPIS]);
   29.11  
   29.12 @@ -209,7 +209,7 @@ static int bind_evtchn_to_irq(unsigned i
   29.13  	irq_bindcount[irq]++;
   29.14  
   29.15  	spin_unlock(&irq_mapping_update_lock);
   29.16 -    
   29.17 +
   29.18  	return irq;
   29.19  }
   29.20  
   29.21 @@ -238,7 +238,7 @@ static int bind_virq_to_irq(unsigned int
   29.22  	irq_bindcount[irq]++;
   29.23  
   29.24  	spin_unlock(&irq_mapping_update_lock);
   29.25 -    
   29.26 +
   29.27  	return irq;
   29.28  }
   29.29  
   29.30 @@ -535,9 +535,9 @@ static unsigned int startup_pirq(unsigne
   29.31  	/* NB. We are happy to share unless we are probing. */
   29.32  	op.u.bind_pirq.flags = probing_irq(irq) ? 0 : BIND_PIRQ__WILL_SHARE;
   29.33  	if (HYPERVISOR_event_channel_op(&op) != 0) {
   29.34 -		if ( !probing_irq(irq) )
   29.35 -			printk(KERN_INFO "Failed to obtain physical "
   29.36 -			       "IRQ %d\n", irq);
   29.37 +		if (!probing_irq(irq))
   29.38 +			printk(KERN_INFO "Failed to obtain physical IRQ %d\n",
   29.39 +			       irq);
   29.40  		return 0;
   29.41  	}
   29.42  	evtchn = op.u.bind_pirq.port;
   29.43 @@ -669,7 +669,7 @@ void unmask_evtchn(int port)
   29.44  	 * like a real IO-APIC we 'lose the interrupt edge' if the channel is
   29.45  	 * masked.
   29.46  	 */
   29.47 -	if (synch_test_bit(port, &s->evtchn_pending[0]) && 
   29.48 +	if (synch_test_bit(port, &s->evtchn_pending[0]) &&
   29.49  	    !synch_test_and_set_bit(port / BITS_PER_LONG,
   29.50  				    &vcpu_info->evtchn_pending_sel)) {
   29.51  		vcpu_info->evtchn_upcall_pending = 1;
   29.52 @@ -722,7 +722,7 @@ void irq_resume(void)
   29.53  		op.u.bind_virq.vcpu = 0;
   29.54  		BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
   29.55  		evtchn = op.u.bind_virq.port;
   29.56 -        
   29.57 +
   29.58  		/* Record the new mapping. */
   29.59  		evtchn_to_irq[evtchn] = irq;
   29.60  		irq_info[irq] = mk_irq_info(IRQT_VIRQ, virq, evtchn);
   29.61 @@ -744,7 +744,7 @@ void irq_resume(void)
   29.62  		op.u.bind_ipi.vcpu = 0;
   29.63  		BUG_ON(HYPERVISOR_event_channel_op(&op) != 0);
   29.64  		evtchn = op.u.bind_ipi.port;
   29.65 -        
   29.66 +
   29.67  		/* Record the new mapping. */
   29.68  		evtchn_to_irq[evtchn] = irq;
   29.69  		irq_info[irq] = mk_irq_info(IRQT_IPI, ipi, evtchn);
   29.70 @@ -794,8 +794,7 @@ void __init init_IRQ(void)
   29.71  	}
   29.72  
   29.73  	/* Phys IRQ space is statically bound (1:1 mapping). Nail refcnts. */
   29.74 -	for (i = 0; i < NR_PIRQS; i++)
   29.75 -	{
   29.76 +	for (i = 0; i < NR_PIRQS; i++) {
   29.77  		irq_bindcount[pirq_to_irq(i)] = 1;
   29.78  
   29.79  #ifdef RTC_IRQ
    30.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/features.c	Tue Mar 14 13:10:21 2006 -0700
    30.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/features.c	Tue Mar 14 13:50:35 2006 -0700
    30.3 @@ -19,7 +19,7 @@ void setup_xen_features(void)
    30.4  	xen_feature_info_t fi;
    30.5  	int i, j;
    30.6  
    30.7 -	for (i=0; i<XENFEAT_NR_SUBMAPS; i++) {
    30.8 +	for (i = 0; i < XENFEAT_NR_SUBMAPS; i++) {
    30.9  		fi.submap_idx = i;
   30.10  		if (HYPERVISOR_xen_version(XENVER_get_features, &fi) < 0)
   30.11  			break;
    31.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Tue Mar 14 13:10:21 2006 -0700
    31.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Tue Mar 14 13:50:35 2006 -0700
    31.3 @@ -31,6 +31,8 @@
    31.4  #include <linux/config.h>
    31.5  #include <linux/module.h>
    31.6  #include <linux/sched.h>
    31.7 +#include <linux/mm.h>
    31.8 +#include <linux/vmalloc.h>
    31.9  #include <asm/pgtable.h>
   31.10  #include <xen/interface/xen.h>
   31.11  #include <asm/fixmap.h>
   31.12 @@ -40,7 +42,7 @@
   31.13  
   31.14  #if 1
   31.15  #define ASSERT(_p)							      \
   31.16 -	if ( !(_p) ) { printk(KERN_ALERT"Assertion '%s': line %d, file %s\n", \
   31.17 +	if (!(_p)) { printk(KERN_ALERT"Assertion '%s': line %d, file %s\n",   \
   31.18  	#_p , __LINE__, __FILE__); *(int*)0=0; }
   31.19  #else
   31.20  #define ASSERT(_p) ((void)0)
   31.21 @@ -77,7 +79,7 @@ static int gnttab_free_count;
   31.22  static grant_ref_t gnttab_free_head;
   31.23  static spinlock_t gnttab_list_lock = SPIN_LOCK_UNLOCKED;
   31.24  
   31.25 -static grant_entry_t *shared;
   31.26 +static grant_entry_t *shared = NULL;
   31.27  
   31.28  static struct gnttab_free_callback *gnttab_free_callback_list = NULL;
   31.29  
   31.30 @@ -152,7 +154,7 @@ int
   31.31  gnttab_grant_foreign_access(domid_t domid, unsigned long frame, int readonly)
   31.32  {
   31.33  	int ref;
   31.34 -    
   31.35 +
   31.36  	if (unlikely((ref = get_free_entry()) == -1))
   31.37  		return -ENOSPC;
   31.38  
   31.39 @@ -192,13 +194,12 @@ gnttab_end_foreign_access_ref(grant_ref_
   31.40  
   31.41  	nflags = shared[ref].flags;
   31.42  	do {
   31.43 -		if ( (flags = nflags) & (GTF_reading|GTF_writing) ) {
   31.44 +		if ((flags = nflags) & (GTF_reading|GTF_writing)) {
   31.45  			printk(KERN_ALERT "WARNING: g.e. still in use!\n");
   31.46  			return 0;
   31.47  		}
   31.48 -	}
   31.49 -	while ((nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) !=
   31.50 -	       flags);
   31.51 +	} while ((nflags = synch_cmpxchg(&shared[ref].flags, flags, 0)) !=
   31.52 +		 flags);
   31.53  
   31.54  	return 1;
   31.55  }
   31.56 @@ -211,8 +212,7 @@ gnttab_end_foreign_access(grant_ref_t re
   31.57  		if (page != 0) {
   31.58  			free_page(page);
   31.59  		}
   31.60 -	}
   31.61 -	else {
   31.62 +	} else {
   31.63  		/* XXX This needs to be fixed so that the ref and page are
   31.64  		   placed on a list to be freed up later. */
   31.65  		printk(KERN_WARNING
   31.66 @@ -253,7 +253,7 @@ gnttab_end_foreign_transfer_ref(grant_re
   31.67           * reference and return failure (== 0).
   31.68           */
   31.69  	while (!((flags = shared[ref].flags) & GTF_transfer_committed)) {
   31.70 -		if ( synch_cmpxchg(&shared[ref].flags, flags, 0) == flags )
   31.71 +		if (synch_cmpxchg(&shared[ref].flags, flags, 0) == flags)
   31.72  			return 0;
   31.73  		cpu_relax();
   31.74  	}
   31.75 @@ -356,12 +356,35 @@ gnttab_request_free_callback(struct gntt
   31.76  	spin_unlock_irqrestore(&gnttab_list_lock, flags);
   31.77  }
   31.78  
   31.79 +#ifndef __ia64__
   31.80 +static int map_pte_fn(pte_t *pte, struct page *pte_page,
   31.81 +		      unsigned long addr, void *data)
   31.82 +{
   31.83 +	unsigned long **frames = (unsigned long **)data;
   31.84 +
   31.85 +	set_pte_at(&init_mm, addr, pte, pfn_pte_ma((*frames)[0], PAGE_KERNEL));
   31.86 +	(*frames)++;
   31.87 +	return 0;
   31.88 +}
   31.89 +
   31.90 +static int unmap_pte_fn(pte_t *pte, struct page *pte_page,
   31.91 +		      unsigned long addr, void *data)
   31.92 +{
   31.93 +
   31.94 +	set_pte_at(&init_mm, addr, pte, __pte(0));
   31.95 +	return 0;
   31.96 +}
   31.97 +#endif
   31.98 +
   31.99  int
  31.100  gnttab_resume(void)
  31.101  {
  31.102  	gnttab_setup_table_t setup;
  31.103 -	unsigned long        frames[NR_GRANT_FRAMES];
  31.104 -	int                  i;
  31.105 +	unsigned long frames[NR_GRANT_FRAMES];
  31.106 +#ifndef __ia64__
  31.107 +	void *pframes = frames;
  31.108 +	struct vm_struct *area;
  31.109 +#endif
  31.110  
  31.111  	setup.dom        = DOMID_SELF;
  31.112  	setup.nr_frames  = NR_GRANT_FRAMES;
  31.113 @@ -370,12 +393,18 @@ gnttab_resume(void)
  31.114  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1));
  31.115  	BUG_ON(setup.status != 0);
  31.116  
  31.117 -#ifdef __ia64__
  31.118 +#ifndef __ia64__
  31.119 +	if (shared == NULL) {
  31.120 +		area = get_vm_area(PAGE_SIZE * NR_GRANT_FRAMES, VM_IOREMAP);
  31.121 +		BUG_ON(area == NULL);
  31.122 +		shared = area->addr;
  31.123 +	}
  31.124 +	BUG_ON(generic_page_range(&init_mm, (unsigned long)shared,
  31.125 +				  PAGE_SIZE * NR_GRANT_FRAMES,
  31.126 +				  map_pte_fn, &pframes));
  31.127 +#else
  31.128  	shared = __va(frames[0] << PAGE_SHIFT);
  31.129  	printk("grant table at %p\n", shared);
  31.130 -#else
  31.131 -	for (i = 0; i < NR_GRANT_FRAMES; i++)
  31.132 -		set_fixmap(FIX_GNTTAB_END - i, frames[i] << PAGE_SHIFT);
  31.133  #endif
  31.134  
  31.135  	return 0;
  31.136 @@ -384,10 +413,12 @@ gnttab_resume(void)
  31.137  int
  31.138  gnttab_suspend(void)
  31.139  {
  31.140 -	int i;
  31.141  
  31.142 -	for (i = 0; i < NR_GRANT_FRAMES; i++)
  31.143 -		clear_fixmap(FIX_GNTTAB_END - i);
  31.144 +#ifndef __ia64__
  31.145 +	generic_page_range(&init_mm, (unsigned long)shared,
  31.146 +			   PAGE_SIZE * NR_GRANT_FRAMES,
  31.147 +			   unmap_pte_fn, NULL);
  31.148 +#endif
  31.149  
  31.150  	return 0;
  31.151  }
  31.152 @@ -402,10 +433,6 @@ gnttab_init(void)
  31.153  
  31.154  	BUG_ON(gnttab_resume());
  31.155  
  31.156 -#ifndef __ia64__
  31.157 -	shared = (grant_entry_t *)fix_to_virt(FIX_GNTTAB_END);
  31.158 -#endif
  31.159 -
  31.160  	for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
  31.161  		gnttab_list[i] = i + 1;
  31.162  	gnttab_free_count = NR_GRANT_ENTRIES - NR_RESERVED_ENTRIES;
    32.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Tue Mar 14 13:10:21 2006 -0700
    32.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/reboot.c	Tue Mar 14 13:50:35 2006 -0700
    32.3 @@ -29,10 +29,11 @@ EXPORT_SYMBOL(pm_power_off);
    32.4  #define SHUTDOWN_POWEROFF  0
    32.5  #define SHUTDOWN_REBOOT    1
    32.6  #define SHUTDOWN_SUSPEND   2
    32.7 -// Code 3 is SHUTDOWN_CRASH, which we don't use because the domain can only
    32.8 -// report a crash, not be instructed to crash!
    32.9 -// HALT is the same as POWEROFF, as far as we're concerned.  The tools use
   32.10 -// the distinction when we return the reason code to them.
   32.11 +/* Code 3 is SHUTDOWN_CRASH, which we don't use because the domain can only
   32.12 + * report a crash, not be instructed to crash!
   32.13 + * HALT is the same as POWEROFF, as far as we're concerned.  The tools use
   32.14 + * the distinction when we return the reason code to them.
   32.15 + */
   32.16  #define SHUTDOWN_HALT      4
   32.17  
   32.18  void machine_emergency_restart(void)
   32.19 @@ -84,14 +85,14 @@ static int __do_suspend(void *ignore)
   32.20  {
   32.21  	int i, j, k, fpp;
   32.22  
   32.23 -	extern int gnttab_suspend(void);
   32.24 -	extern int gnttab_resume(void);
   32.25 -
   32.26 -	extern void time_resume(void);
   32.27  	extern unsigned long max_pfn;
   32.28  	extern unsigned long *pfn_to_mfn_frame_list_list;
   32.29  	extern unsigned long *pfn_to_mfn_frame_list[];
   32.30  
   32.31 +	extern int gnttab_suspend(void);
   32.32 +	extern int gnttab_resume(void);
   32.33 +	extern void time_resume(void);
   32.34 +
   32.35  #ifdef CONFIG_SMP
   32.36  	cpumask_t prev_online_cpus;
   32.37  	int vcpu_prepare(int vcpu);
   32.38 @@ -167,26 +168,26 @@ static int __do_suspend(void *ignore)
   32.39  	 */
   32.40  	HYPERVISOR_suspend(virt_to_mfn(xen_start_info));
   32.41  
   32.42 -	shutting_down = SHUTDOWN_INVALID; 
   32.43 +	shutting_down = SHUTDOWN_INVALID;
   32.44  
   32.45  	set_fixmap(FIX_SHARED_INFO, xen_start_info->shared_info);
   32.46  
   32.47  	HYPERVISOR_shared_info = (shared_info_t *)fix_to_virt(FIX_SHARED_INFO);
   32.48  
   32.49  	memset(empty_zero_page, 0, PAGE_SIZE);
   32.50 -	     
   32.51 +
   32.52  	HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list =
   32.53  		virt_to_mfn(pfn_to_mfn_frame_list_list);
   32.54 -  
   32.55 +
   32.56  	fpp = PAGE_SIZE/sizeof(unsigned long);
   32.57  	for (i = 0, j = 0, k = -1; i < max_pfn; i += fpp, j++) {
   32.58  		if ((j % fpp) == 0) {
   32.59  			k++;
   32.60 -			pfn_to_mfn_frame_list_list[k] = 
   32.61 +			pfn_to_mfn_frame_list_list[k] =
   32.62  				virt_to_mfn(pfn_to_mfn_frame_list[k]);
   32.63  			j = 0;
   32.64  		}
   32.65 -		pfn_to_mfn_frame_list[k][j] = 
   32.66 +		pfn_to_mfn_frame_list[k][j] =
   32.67  			virt_to_mfn(&phys_to_machine_mapping[i]);
   32.68  	}
   32.69  	HYPERVISOR_shared_info->arch.max_pfn = max_pfn;
   32.70 @@ -207,7 +208,7 @@ static int __do_suspend(void *ignore)
   32.71  
   32.72  #endif
   32.73  
   32.74 -	/* 
   32.75 +	/*
   32.76  	 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise
   32.77  	 * the VCPU hotplug callback can race with our vcpu_prepare
   32.78  	 */
   32.79 @@ -231,7 +232,7 @@ static int __do_suspend(void *ignore)
   32.80  
   32.81  static int shutdown_process(void *__unused)
   32.82  {
   32.83 -	static char *envp[] = { "HOME=/", "TERM=linux", 
   32.84 +	static char *envp[] = { "HOME=/", "TERM=linux",
   32.85  				"PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
   32.86  	static char *restart_argv[]  = { "/sbin/reboot", NULL };
   32.87  	static char *poweroff_argv[] = { "/sbin/poweroff", NULL };
   32.88 @@ -291,7 +292,7 @@ static void __shutdown_handler(void *unu
   32.89  	else
   32.90  		err = kthread_create_on_cpu(__do_suspend, NULL, "suspend", 0);
   32.91  
   32.92 -	if ( err < 0 ) {
   32.93 +	if (err < 0) {
   32.94  		printk(KERN_WARNING "Error creating shutdown process (%d): "
   32.95  		       "retrying...\n", -err);
   32.96  		schedule_delayed_work(&shutdown_work, HZ/2);
   32.97 @@ -406,14 +407,12 @@ static int setup_shutdown_watcher(struct
   32.98  	err2 = register_xenbus_watch(&sysrq_watch);
   32.99  #endif
  32.100  
  32.101 -	if (err1) {
  32.102 +	if (err1)
  32.103  		printk(KERN_ERR "Failed to set shutdown watcher\n");
  32.104 -	}
  32.105 -    
  32.106 +
  32.107  #ifdef CONFIG_MAGIC_SYSRQ
  32.108 -	if (err2) {
  32.109 +	if (err2)
  32.110  		printk(KERN_ERR "Failed to set sysrq watcher\n");
  32.111 -	}
  32.112  #endif
  32.113  
  32.114  	return NOTIFY_DONE;
  32.115 @@ -421,11 +420,11 @@ static int setup_shutdown_watcher(struct
  32.116  
  32.117  static int __init setup_shutdown_event(void)
  32.118  {
  32.119 -    
  32.120 +
  32.121  	xenstore_notifier.notifier_call = setup_shutdown_watcher;
  32.122  
  32.123  	register_xenstore_notifier(&xenstore_notifier);
  32.124 -    
  32.125 +
  32.126  	return 0;
  32.127  }
  32.128  
    33.1 --- a/linux-2.6-xen-sparse/drivers/xen/net_driver_util.c	Tue Mar 14 13:10:21 2006 -0700
    33.2 +++ b/linux-2.6-xen-sparse/drivers/xen/net_driver_util.c	Tue Mar 14 13:50:35 2006 -0700
    33.3 @@ -40,9 +40,8 @@ int xen_net_read_mac(struct xenbus_devic
    33.4  	int i;
    33.5  	char *e;
    33.6  	char *macstr = xenbus_read(XBT_NULL, dev->nodename, "mac", NULL);
    33.7 -	if (IS_ERR(macstr)) {
    33.8 +	if (IS_ERR(macstr))
    33.9  		return PTR_ERR(macstr);
   33.10 -	}
   33.11  	s = macstr;
   33.12  	for (i = 0; i < ETH_ALEN; i++) {
   33.13  		mac[i] = simple_strtoul(s, &e, 16);
    34.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Mar 14 13:10:21 2006 -0700
    34.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Mar 14 13:50:35 2006 -0700
    34.3 @@ -91,7 +91,7 @@ struct netfront_info
    34.4  
    34.5  	struct net_device_stats stats;
    34.6  	unsigned int tx_full;
    34.7 -    
    34.8 +
    34.9  	netif_tx_front_ring_t tx;
   34.10  	netif_rx_front_ring_t rx;
   34.11  
   34.12 @@ -129,9 +129,9 @@ struct netfront_info
   34.13  	struct sk_buff *rx_skbs[NET_RX_RING_SIZE+1];
   34.14  
   34.15  	grant_ref_t gref_tx_head;
   34.16 -	grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1]; 
   34.17 +	grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1];
   34.18  	grant_ref_t gref_rx_head;
   34.19 -	grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1]; 
   34.20 +	grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1];
   34.21  
   34.22  	struct xenbus_device *xbdev;
   34.23  	int tx_ring_ref;
   34.24 @@ -433,7 +433,7 @@ static int send_fake_arp(struct net_devi
   34.25  
   34.26  	skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
   34.27  			 dst_ip, dev, src_ip,
   34.28 -			 /*dst_hw*/ NULL, /*src_hw*/ NULL, 
   34.29 +			 /*dst_hw*/ NULL, /*src_hw*/ NULL,
   34.30  			 /*target_hw*/ dev->dev_addr);
   34.31  	if (skb == NULL)
   34.32  		return -ENOMEM;
   34.33 @@ -480,7 +480,7 @@ static void network_tx_buf_gc(struct net
   34.34  				printk(KERN_ALERT "network_tx_buf_gc: warning "
   34.35  				       "-- grant still in use by backend "
   34.36  				       "domain.\n");
   34.37 -				goto out; 
   34.38 +				goto out;
   34.39  			}
   34.40  			gnttab_end_foreign_access_ref(
   34.41  				np->grant_tx_ref[id], GNTMAP_readonly);
   34.42 @@ -490,9 +490,9 @@ static void network_tx_buf_gc(struct net
   34.43  			ADD_ID_TO_FREELIST(np->tx_skbs, id);
   34.44  			dev_kfree_skb_irq(skb);
   34.45  		}
   34.46 -        
   34.47 +
   34.48  		np->tx.rsp_cons = prod;
   34.49 -        
   34.50 +
   34.51  		/*
   34.52  		 * Set a new event, then check for race with update of tx_cons.
   34.53  		 * Note that it is essential to schedule a callback, no matter
   34.54 @@ -506,7 +506,7 @@ static void network_tx_buf_gc(struct net
   34.55  		mb();
   34.56  	} while (prod != np->tx.sring->rsp_prod);
   34.57  
   34.58 - out: 
   34.59 + out:
   34.60  	if (np->tx_full &&
   34.61  	    ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE)) {
   34.62  		np->tx_full = 0;
   34.63 @@ -582,7 +582,7 @@ static void network_alloc_rx_buffers(str
   34.64  		id = GET_ID_FROM_FREELIST(np->rx_skbs);
   34.65  
   34.66  		np->rx_skbs[id] = skb;
   34.67 -        
   34.68 +
   34.69  		RING_GET_REQUEST(&np->rx, req_prod + i)->id = id;
   34.70  		ref = gnttab_claim_grant_reference(&np->gref_rx_head);
   34.71  		BUG_ON((signed short)ref < 0);
   34.72 @@ -628,11 +628,10 @@ static void network_alloc_rx_buffers(str
   34.73  		/* Check return status of HYPERVISOR_memory_op(). */
   34.74  		if (unlikely(rx_mcl[i].result != i))
   34.75  			panic("Unable to reduce memory reservation\n");
   34.76 -	} else {
   34.77 +	} else
   34.78  		if (HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   34.79  					 &reservation) != i)
   34.80  			panic("Unable to reduce memory reservation\n");
   34.81 -	}
   34.82  
   34.83  	/* Above is a suitable barrier to ensure backend will see requests. */
   34.84  	np->rx.req_prod_pvt = req_prod + i;
   34.85 @@ -668,7 +667,7 @@ static int network_start_xmit(struct sk_
   34.86  		dev_kfree_skb(skb);
   34.87  		skb = nskb;
   34.88  	}
   34.89 -    
   34.90 +
   34.91  	spin_lock_irq(&np->tx_lock);
   34.92  
   34.93  	if (np->backend_state != BEST_CONNECTED) {
   34.94 @@ -765,7 +764,7 @@ static int netif_poll(struct net_device 
   34.95  	rp = np->rx.sring->rsp_prod;
   34.96  	rmb(); /* Ensure we see queued responses up to 'rp'. */
   34.97  
   34.98 -	for (i = np->rx.rsp_cons, work_done = 0; 
   34.99 +	for (i = np->rx.rsp_cons, work_done = 0;
  34.100  	     (i != rp) && (work_done < budget);
  34.101  	     i++, work_done++) {
  34.102  		rx = RING_GET_RESPONSE(&np->rx, i);
  34.103 @@ -807,7 +806,7 @@ static int netif_poll(struct net_device 
  34.104  		skb->len  = rx->status;
  34.105  		skb->tail = skb->data + skb->len;
  34.106  
  34.107 -		if ( rx->flags & NETRXF_csum_valid )
  34.108 +		if (rx->flags & NETRXF_csum_valid)
  34.109  			skb->ip_summed = CHECKSUM_UNNECESSARY;
  34.110  
  34.111  		np->stats.rx_packets++;
  34.112 @@ -862,7 +861,7 @@ static int netif_poll(struct net_device 
  34.113  		 * Enough room in skbuff for the data we were passed? Also,
  34.114  		 * Linux expects at least 16 bytes headroom in each rx buffer.
  34.115  		 */
  34.116 -		if (unlikely(skb->tail > skb->end) || 
  34.117 +		if (unlikely(skb->tail > skb->end) ||
  34.118  		    unlikely((skb->data - skb->head) < 16)) {
  34.119  			if (net_ratelimit()) {
  34.120  				if (skb->tail > skb->end)
  34.121 @@ -894,7 +893,7 @@ static int netif_poll(struct net_device 
  34.122  			if ((skb = nskb) == NULL)
  34.123  				continue;
  34.124  		}
  34.125 -        
  34.126 +
  34.127  		/* Set the shinfo area, which is hidden behind the data. */
  34.128  		init_skb_shinfo(skb);
  34.129  		/* Ethernet work: Delayed to here as it peeks the header. */
  34.130 @@ -995,9 +994,9 @@ static void network_connect(struct net_d
  34.131  
  34.132  		tx->id = i;
  34.133  		gnttab_grant_foreign_access_ref(
  34.134 -			np->grant_tx_ref[i], np->xbdev->otherend_id, 
  34.135 +			np->grant_tx_ref[i], np->xbdev->otherend_id,
  34.136  			virt_to_mfn(np->tx_skbs[i]->data),
  34.137 -			GNTMAP_readonly); 
  34.138 +			GNTMAP_readonly);
  34.139  		tx->gref = np->grant_tx_ref[i];
  34.140  		tx->offset = (unsigned long)skb->data & ~PAGE_MASK;
  34.141  		tx->size = skb->len;
  34.142 @@ -1012,7 +1011,7 @@ static void network_connect(struct net_d
  34.143  	RING_PUSH_REQUESTS(&np->tx);
  34.144  
  34.145  	/* Rebuild the RX buffer freelist and the RX ring itself. */
  34.146 -	for (requeue_idx = 0, i = 1; i <= NET_RX_RING_SIZE; i++) { 
  34.147 +	for (requeue_idx = 0, i = 1; i <= NET_RX_RING_SIZE; i++) {
  34.148  		if ((unsigned long)np->rx_skbs[i] < __PAGE_OFFSET)
  34.149  			continue;
  34.150  		gnttab_grant_foreign_transfer_ref(
  34.151 @@ -1021,7 +1020,7 @@ static void network_connect(struct net_d
  34.152  		RING_GET_REQUEST(&np->rx, requeue_idx)->gref =
  34.153  			np->grant_rx_ref[i];
  34.154  		RING_GET_REQUEST(&np->rx, requeue_idx)->id = i;
  34.155 -		requeue_idx++; 
  34.156 +		requeue_idx++;
  34.157  	}
  34.158  
  34.159  	np->rx.req_prod_pvt = requeue_idx;
  34.160 @@ -1055,9 +1054,8 @@ static void show_device(struct netfront_
  34.161  			np->evtchn,
  34.162  			np->tx,
  34.163  			np->rx);
  34.164 -	} else {
  34.165 +	} else
  34.166  		IPRINTK("<vif NULL>\n");
  34.167 -	}
  34.168  #endif
  34.169  }
  34.170  
  34.171 @@ -1150,7 +1148,7 @@ static int create_netdev(int handle, str
  34.172  	SET_ETHTOOL_OPS(netdev, &network_ethtool_ops);
  34.173  	SET_MODULE_OWNER(netdev);
  34.174  	SET_NETDEV_DEV(netdev, &dev->dev);
  34.175 -    
  34.176 +
  34.177  	if ((err = register_netdev(netdev)) != 0) {
  34.178  		printk(KERN_WARNING "%s> register_netdev err=%d\n",
  34.179  		       __FUNCTION__, err);
  34.180 @@ -1181,16 +1179,16 @@ static int create_netdev(int handle, str
  34.181   * We use this notifier to send out a fake ARP reply to reset switches and
  34.182   * router ARP caches when an IP interface is brought up on a VIF.
  34.183   */
  34.184 -static int 
  34.185 +static int
  34.186  inetdev_notify(struct notifier_block *this, unsigned long event, void *ptr)
  34.187  {
  34.188 -	struct in_ifaddr  *ifa = (struct in_ifaddr *)ptr; 
  34.189 +	struct in_ifaddr  *ifa = (struct in_ifaddr *)ptr;
  34.190  	struct net_device *dev = ifa->ifa_dev->dev;
  34.191  
  34.192  	/* UP event and is it one of our devices? */
  34.193  	if (event == NETDEV_UP && dev->open == network_open)
  34.194  		(void)send_fake_arp(dev);
  34.195 -        
  34.196 +
  34.197  	return NOTIFY_DONE;
  34.198  }
  34.199  
  34.200 @@ -1336,8 +1334,8 @@ static void netif_exit(void)
  34.201  module_exit(netif_exit);
  34.202  
  34.203  MODULE_LICENSE("Dual BSD/GPL");
  34.204 - 
  34.205 - 
  34.206 +
  34.207 +
  34.208  /* ** /proc **/
  34.209  
  34.210  
  34.211 @@ -1354,9 +1352,8 @@ static int xennet_proc_read(
  34.212  		(struct net_device *)((unsigned long)data & ~3UL);
  34.213  	struct netfront_info *np = netdev_priv(dev);
  34.214  	int len = 0, which_target = (long)data & 3;
  34.215 -    
  34.216 -	switch (which_target)
  34.217 -	{
  34.218 +
  34.219 +	switch (which_target) {
  34.220  	case TARGET_MIN:
  34.221  		len = sprintf(page, "%d\n", np->rx_min_target);
  34.222  		break;
  34.223 @@ -1403,8 +1400,7 @@ static int xennet_proc_write(
  34.224  
  34.225  	spin_lock(&np->rx_lock);
  34.226  
  34.227 -	switch (which_target)
  34.228 -	{
  34.229 +	switch (which_target) {
  34.230  	case TARGET_MIN:
  34.231  		if (target > np->rx_max_target)
  34.232  			np->rx_max_target = target;
    35.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile	Tue Mar 14 13:10:21 2006 -0700
    35.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile	Tue Mar 14 13:50:35 2006 -0700
    35.3 @@ -1,9 +1,9 @@
    35.4 -obj-y += pciback.o
    35.5 +obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pciback.o
    35.6  
    35.7  pciback-y := pci_stub.o pciback_ops.o xenbus.o
    35.8  pciback-y += conf_space.o conf_space_header.o
    35.9 -pciback-${CONFIG_XEN_PCIDEV_BACKEND_VPCI} += vpci.o
   35.10 -pciback-${CONFIG_XEN_PCIDEV_BACKEND_PASS} += passthrough.o
   35.11 +pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
   35.12 +pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
   35.13  
   35.14  ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y)
   35.15  EXTRA_CFLAGS += -DDEBUG
    36.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.c	Tue Mar 14 13:10:21 2006 -0700
    36.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space.c	Tue Mar 14 13:50:35 2006 -0700
    36.3 @@ -14,6 +14,9 @@
    36.4  #include "pciback.h"
    36.5  #include "conf_space.h"
    36.6  
    36.7 +static int permissive = 0;
    36.8 +module_param(permissive, bool, 0644);
    36.9 +
   36.10  #define DEFINE_PCI_CONFIG(op,size,type) 					\
   36.11  int pciback_##op##_config_##size 							\
   36.12  (struct pci_dev *dev, int offset, type value, void *data)	\
   36.13 @@ -198,7 +201,7 @@ int pciback_config_read(struct pci_dev *
   36.14  
   36.15  int pciback_config_write(struct pci_dev *dev, int offset, int size, u32 value)
   36.16  {
   36.17 -	int err = 0;
   36.18 +	int err = 0, handled = 0;
   36.19  	struct pciback_dev_data *dev_data = pci_get_drvdata(dev);
   36.20  	struct config_field_entry *cfg_entry;
   36.21  	struct config_field *field;
   36.22 @@ -233,6 +236,21 @@ int pciback_config_write(struct pci_dev 
   36.23  					      field_start - req_start);
   36.24  
   36.25  			err = conf_space_write(dev, cfg_entry, offset, tmp_val);
   36.26 +			handled = 1;
   36.27 +		}
   36.28 +	}
   36.29 +
   36.30 +	if (!handled && !err && permissive) {
   36.31 +		switch (size) {
   36.32 +		case 1:
   36.33 +			err = pci_write_config_byte(dev, offset, (u8)value);
   36.34 +			break;
   36.35 +		case 2:
   36.36 +			err = pci_write_config_word(dev, offset, (u16)value);
   36.37 +			break;
   36.38 +		case 4:
   36.39 +			err = pci_write_config_dword(dev, offset, (u32)value);
   36.40 +			break;
   36.41  		}
   36.42  	}
   36.43  
    37.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c	Tue Mar 14 13:10:21 2006 -0700
    37.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/conf_space_header.c	Tue Mar 14 13:50:35 2006 -0700
    37.3 @@ -24,21 +24,19 @@ static int command_write(struct pci_dev 
    37.4  		if (unlikely(verbose_request))
    37.5  			printk(KERN_DEBUG "pciback: %s: enable\n",
    37.6  			       pci_name(dev));
    37.7 -		dev->is_enabled = 1;
    37.8 -		pcibios_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1);
    37.9 +		pci_enable_device(dev);
   37.10  	} else if (dev->is_enabled && !is_enable_cmd(value)) {
   37.11  		if (unlikely(verbose_request))
   37.12  			printk(KERN_DEBUG "pciback: %s: disable\n",
   37.13  			       pci_name(dev));
   37.14 -		pciback_disable_device(dev);
   37.15 +		pci_disable_device(dev);
   37.16  	}
   37.17  
   37.18  	if (!dev->is_busmaster && is_master_cmd(value)) {
   37.19  		if (unlikely(verbose_request))
   37.20  			printk(KERN_DEBUG "pciback: %s: set bus master\n",
   37.21  			       pci_name(dev));
   37.22 -		dev->is_busmaster = 1;
   37.23 -		pcibios_set_master(dev);
   37.24 +		pci_set_master(dev);
   37.25  	}
   37.26  
   37.27  	if (value & PCI_COMMAND_INVALIDATE) {
    38.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c	Tue Mar 14 13:10:21 2006 -0700
    38.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pci_stub.c	Tue Mar 14 13:50:35 2006 -0700
    38.3 @@ -208,8 +208,6 @@ static int __init pcistub_init_devices_l
    38.4  	return 0;
    38.5  }
    38.6  
    38.7 -device_initcall(pcistub_init_devices_late);
    38.8 -
    38.9  static int __devinit pcistub_seize(struct pci_dev *dev)
   38.10  {
   38.11  	struct pci_stub_device *psdev;
   38.12 @@ -367,6 +365,7 @@ static int __init pcistub_init(void)
   38.13  	return -EINVAL;
   38.14  }
   38.15  
   38.16 +#ifndef MODULE
   38.17  /*
   38.18   * fs_initcall happens before device_initcall
   38.19   * so pciback *should* get called first (b/c we 
   38.20 @@ -375,3 +374,34 @@ static int __init pcistub_init(void)
   38.21   * driver to register)
   38.22   */
   38.23  fs_initcall(pcistub_init);
   38.24 +#endif
   38.25 +
   38.26 +static int __init pciback_init(void)
   38.27 +{
   38.28 +#ifdef MODULE
   38.29 +	int err;
   38.30 +
   38.31 +	err = pcistub_init();
   38.32 +	if (err < 0)
   38.33 +		return err;
   38.34 +#endif
   38.35 +
   38.36 +	if (list_empty(&pci_stub_device_ids))
   38.37 +		return -ENODEV;
   38.38 +	pcistub_init_devices_late();
   38.39 +	pciback_xenbus_register();
   38.40 +
   38.41 +	__unsafe(THIS_MODULE);
   38.42 +
   38.43 +	return 0;
   38.44 +}
   38.45 +
   38.46 +static void pciback_cleanup(void)
   38.47 +{
   38.48 +	BUG();
   38.49 +}
   38.50 +
   38.51 +module_init(pciback_init);
   38.52 +module_exit(pciback_cleanup);
   38.53 +
   38.54 +MODULE_LICENSE("Dual BSD/GPL");
    39.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h	Tue Mar 14 13:10:21 2006 -0700
    39.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback.h	Tue Mar 14 13:50:35 2006 -0700
    39.3 @@ -43,7 +43,6 @@ struct pci_dev *pcistub_get_pci_dev(stru
    39.4  void pcistub_put_pci_dev(struct pci_dev *dev);
    39.5  
    39.6  /* Ensure a device is turned off or reset */
    39.7 -void pciback_disable_device(struct pci_dev *dev);
    39.8  void pciback_reset_device(struct pci_dev *pdev);
    39.9  
   39.10  /* Access a virtual configuration space for a PCI device */
   39.11 @@ -69,5 +68,7 @@ void pciback_release_devices(struct pcib
   39.12  /* Handles events from front-end */
   39.13  irqreturn_t pciback_handle_event(int irq, void *dev_id, struct pt_regs *regs);
   39.14  
   39.15 +int pciback_xenbus_register(void);
   39.16 +
   39.17  extern int verbose_request;
   39.18  #endif
    40.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c	Tue Mar 14 13:10:21 2006 -0700
    40.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/pciback_ops.c	Tue Mar 14 13:50:35 2006 -0700
    40.3 @@ -5,22 +5,12 @@
    40.4   */
    40.5  #include <linux/module.h>
    40.6  #include <asm/bitops.h>
    40.7 +#include <xen/evtchn.h>
    40.8  #include "pciback.h"
    40.9  
   40.10  int verbose_request = 0;
   40.11  module_param(verbose_request, int, 0644);
   40.12  
   40.13 -/* For those architectures without a pcibios_disable_device */
   40.14 -void __attribute__ ((weak)) pcibios_disable_device(struct pci_dev *dev) { }
   40.15 -
   40.16 -void pciback_disable_device(struct pci_dev *dev)
   40.17 -{
   40.18 -	if (dev->is_enabled) {
   40.19 -		dev->is_enabled = 0;
   40.20 -		pcibios_disable_device(dev);
   40.21 -	}
   40.22 -}
   40.23 -
   40.24  /* Ensure a device is "turned off" and ready to be exported.
   40.25   * This also sets up the device's private data to keep track of what should
   40.26   * be in the base address registers (BARs) so that we can keep the
   40.27 @@ -32,7 +22,7 @@ void pciback_reset_device(struct pci_dev
   40.28  
   40.29  	/* Disable devices (but not bridges) */
   40.30  	if (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) {
   40.31 -		pciback_disable_device(dev);
   40.32 +		pci_disable_device(dev);
   40.33  
   40.34  		pci_write_config_word(dev, PCI_COMMAND, 0);
   40.35  
   40.36 @@ -78,6 +68,7 @@ irqreturn_t pciback_handle_event(int irq
   40.37  
   40.38  	wmb();
   40.39  	clear_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags);
   40.40 +	notify_remote_via_irq(pdev->evtchn_irq);
   40.41  
   40.42        out:
   40.43  	return IRQ_HANDLED;
    41.1 --- a/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c	Tue Mar 14 13:10:21 2006 -0700
    41.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pciback/xenbus.c	Tue Mar 14 13:50:35 2006 -0700
    41.3 @@ -430,10 +430,7 @@ static struct xenbus_driver xenbus_pciba
    41.4  	.otherend_changed 	= pciback_frontend_changed,
    41.5  };
    41.6  
    41.7 -static __init int pciback_xenbus_register(void)
    41.8 +int __init pciback_xenbus_register(void)
    41.9  {
   41.10  	return xenbus_register_backend(&xenbus_pciback_driver);
   41.11  }
   41.12 -
   41.13 -/* Must only initialize our xenbus driver after the pcistub driver */
   41.14 -device_initcall(pciback_xenbus_register);
    42.1 --- a/linux-2.6-xen-sparse/drivers/xen/pcifront/pci.c	Tue Mar 14 13:10:21 2006 -0700
    42.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pcifront/pci.c	Tue Mar 14 13:50:35 2006 -0700
    42.3 @@ -18,8 +18,10 @@ int pcifront_connect(struct pcifront_dev
    42.4  
    42.5  	spin_lock(&pcifront_dev_lock);
    42.6  
    42.7 -	if (!pcifront_dev)
    42.8 +	if (!pcifront_dev) {
    42.9  		dev_info(&pdev->xdev->dev, "Installing PCI frontend\n");
   42.10 +		pcifront_dev = pdev;
   42.11 +	}
   42.12  	else {
   42.13  		dev_err(&pdev->xdev->dev, "PCI frontend already installed!\n");
   42.14  		err = -EEXIST;
    43.1 --- a/linux-2.6-xen-sparse/drivers/xen/pcifront/pci_op.c	Tue Mar 14 13:10:21 2006 -0700
    43.2 +++ b/linux-2.6-xen-sparse/drivers/xen/pcifront/pci_op.c	Tue Mar 14 13:50:35 2006 -0700
    43.3 @@ -40,9 +40,8 @@ static int do_pci_op(struct pcifront_dev
    43.4  {
    43.5  	int err = 0;
    43.6  	struct xen_pci_op *active_op = &pdev->sh_info->op;
    43.7 -	unsigned long irq_flags;
    43.8 -
    43.9 -	unsigned int volatile ttl = (1U << 29);
   43.10 +	unsigned long irq_flags, poll_end;
   43.11 +	evtchn_port_t port = pdev->evtchn;
   43.12  
   43.13  	spin_lock_irqsave(&pdev->sh_info_lock, irq_flags);
   43.14  
   43.15 @@ -51,14 +50,17 @@ static int do_pci_op(struct pcifront_dev
   43.16  	/* Go */
   43.17  	wmb();
   43.18  	set_bit(_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags);
   43.19 -	notify_remote_via_evtchn(pdev->evtchn);
   43.20 +	notify_remote_via_evtchn(port);
   43.21 +
   43.22 +	poll_end = jiffies + 5*HZ;
   43.23 +	clear_evtchn(port);
   43.24  
   43.25 -	/* IRQs are disabled for the pci config. space reads/writes,
   43.26 -	 * which means no event channel to notify us that the backend
   43.27 -	 * is done so spin while waiting for the answer */
   43.28 -	while (test_bit
   43.29 -	       (_XEN_PCIF_active, (unsigned long *)&pdev->sh_info->flags)) {
   43.30 -		if (!ttl) {
   43.31 +	while (test_bit(_XEN_PCIF_active,
   43.32 +			(unsigned long *)&pdev->sh_info->flags)) {
   43.33 +		if (HYPERVISOR_poll(&port, 1, poll_end))
   43.34 +			BUG();
   43.35 +		clear_evtchn(port);
   43.36 +		if (time_after(jiffies, poll_end)) {
   43.37  			dev_err(&pdev->xdev->dev,
   43.38  				"pciback not responding!!!\n");
   43.39  			clear_bit(_XEN_PCIF_active,
   43.40 @@ -66,7 +68,6 @@ static int do_pci_op(struct pcifront_dev
   43.41  			err = XEN_PCI_ERR_dev_not_found;
   43.42  			goto out;
   43.43  		}
   43.44 -		ttl--;
   43.45  	}
   43.46  
   43.47  	memcpy(op, active_op, sizeof(struct xen_pci_op));
    44.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Tue Mar 14 13:10:21 2006 -0700
    44.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Tue Mar 14 13:50:35 2006 -0700
    44.3 @@ -310,7 +310,8 @@ again:
    44.4  		goto abort_transaction;
    44.5  	}
    44.6  
    44.7 -	err = xenbus_switch_state(dev, xbt, XenbusStateInitialised);
    44.8 +	err = xenbus_printf(xbt, dev->nodename,
    44.9 +	                    "state", "%d", XenbusStateInitialised);
   44.10  	if (err) {
   44.11  		goto abort_transaction;
   44.12  	}
    45.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Tue Mar 14 13:10:21 2006 -0700
    45.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/Makefile	Tue Mar 14 13:50:35 2006 -0700
    45.3 @@ -1,8 +1,8 @@
    45.4  obj-y	+= xenbus.o
    45.5  
    45.6  xenbus-objs =
    45.7 -xenbus-objs += xenbus_client.o 
    45.8 +xenbus-objs += xenbus_client.o
    45.9  xenbus-objs += xenbus_comms.o
   45.10  xenbus-objs += xenbus_xs.o
   45.11 -xenbus-objs += xenbus_probe.o 
   45.12 -xenbus-objs += xenbus_dev.o 
   45.13 +xenbus-objs += xenbus_probe.o
   45.14 +xenbus-objs += xenbus_dev.o
    46.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Tue Mar 14 13:10:21 2006 -0700
    46.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_client.c	Tue Mar 14 13:50:35 2006 -0700
    46.3 @@ -39,7 +39,7 @@ extern char *kasprintf(const char *fmt, 
    46.4      pr_debug("xenbus_client (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args)
    46.5  
    46.6  int xenbus_watch_path(struct xenbus_device *dev, const char *path,
    46.7 -		      struct xenbus_watch *watch, 
    46.8 +		      struct xenbus_watch *watch,
    46.9  		      void (*callback)(struct xenbus_watch *,
   46.10  				       const char **, unsigned int))
   46.11  {
   46.12 @@ -62,7 +62,7 @@ EXPORT_SYMBOL(xenbus_watch_path);
   46.13  
   46.14  
   46.15  int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
   46.16 -		       const char *path2, struct xenbus_watch *watch, 
   46.17 +		       const char *path2, struct xenbus_watch *watch,
   46.18  		       void (*callback)(struct xenbus_watch *,
   46.19  					const char **, unsigned int))
   46.20  {
   46.21 @@ -74,9 +74,8 @@ int xenbus_watch_path2(struct xenbus_dev
   46.22  	}
   46.23  	err = xenbus_watch_path(dev, state, watch, callback);
   46.24  
   46.25 -	if (err) {
   46.26 +	if (err)
   46.27  		kfree(state);
   46.28 -	}
   46.29  	return err;
   46.30  }
   46.31  EXPORT_SYMBOL(xenbus_watch_path2);
   46.32 @@ -190,7 +189,7 @@ void xenbus_dev_fatal(struct xenbus_devi
   46.33  	va_start(ap, fmt);
   46.34  	_dev_error(dev, err, fmt, ap);
   46.35  	va_end(ap);
   46.36 -	
   46.37 +
   46.38  	xenbus_switch_state(dev, XBT_NULL, XenbusStateClosing);
   46.39  }
   46.40  EXPORT_SYMBOL(xenbus_dev_fatal);
   46.41 @@ -213,7 +212,6 @@ int xenbus_alloc_evtchn(struct xenbus_de
   46.42  		.u.alloc_unbound.dom = DOMID_SELF,
   46.43  		.u.alloc_unbound.remote_dom = dev->otherend_id
   46.44  	};
   46.45 -
   46.46  	int err = HYPERVISOR_event_channel_op(&op);
   46.47  	if (err)
   46.48  		xenbus_dev_fatal(dev, err, "allocating event channel");
   46.49 @@ -231,7 +229,6 @@ int xenbus_bind_evtchn(struct xenbus_dev
   46.50  		.u.bind_interdomain.remote_dom = dev->otherend_id,
   46.51  		.u.bind_interdomain.remote_port = remote_port,
   46.52  	};
   46.53 -
   46.54  	int err = HYPERVISOR_event_channel_op(&op);
   46.55  	if (err)
   46.56  		xenbus_dev_fatal(dev, err,
   46.57 @@ -388,7 +385,6 @@ EXPORT_SYMBOL(xenbus_unmap_ring);
   46.58  XenbusState xenbus_read_driver_state(const char *path)
   46.59  {
   46.60  	XenbusState result;
   46.61 -
   46.62  	int err = xenbus_gather(XBT_NULL, path, "state", "%d", &result, NULL);
   46.63  	if (err)
   46.64  		result = XenbusStateClosed;
    47.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Tue Mar 14 13:10:21 2006 -0700
    47.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Tue Mar 14 13:50:35 2006 -0700
    47.3 @@ -38,8 +38,8 @@
    47.4  
    47.5  static int xenbus_irq;
    47.6  
    47.7 -extern void xenbus_probe(void *); 
    47.8 -extern int xenstored_ready; 
    47.9 +extern void xenbus_probe(void *);
   47.10 +extern int xenstored_ready;
   47.11  static DECLARE_WORK(probe_work, xenbus_probe, NULL);
   47.12  
   47.13  DECLARE_WAIT_QUEUE_HEAD(xb_waitq);
   47.14 @@ -52,9 +52,9 @@ static inline struct xenstore_domain_int
   47.15  static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs)
   47.16  {
   47.17  	if (unlikely(xenstored_ready == 0)) {
   47.18 -		xenstored_ready = 1; 
   47.19 -		schedule_work(&probe_work); 
   47.20 -	} 
   47.21 +		xenstored_ready = 1;
   47.22 +		schedule_work(&probe_work);
   47.23 +	}
   47.24  
   47.25  	wake_up(&xb_waitq);
   47.26  	return IRQ_HANDLED;
    48.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Mar 14 13:10:21 2006 -0700
    48.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Mar 14 13:50:35 2006 -0700
    48.3 @@ -366,7 +366,6 @@ fail:
    48.4  	xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename);
    48.5  	xenbus_switch_state(dev, XBT_NULL, XenbusStateClosed);
    48.6  	return -ENODEV;
    48.7 -	
    48.8  }
    48.9  
   48.10  static int xenbus_dev_remove(struct device *_dev)
   48.11 @@ -495,9 +494,8 @@ static void xenbus_dev_free(struct xenbu
   48.12  
   48.13  static void xenbus_dev_release(struct device *dev)
   48.14  {
   48.15 -	if (dev) {
   48.16 +	if (dev)
   48.17  		xenbus_dev_free(to_xenbus_device(dev));
   48.18 -	}
   48.19  }
   48.20  
   48.21  /* Simplified asprintf. */
   48.22 @@ -600,7 +598,7 @@ static int xenbus_probe_frontend(const c
   48.23  	nodename = kasprintf("%s/%s/%s", xenbus_frontend.root, type, name);
   48.24  	if (!nodename)
   48.25  		return -ENOMEM;
   48.26 -	
   48.27 +
   48.28  	DPRINTK("%s", nodename);
   48.29  
   48.30  	err = xenbus_probe_node(&xenbus_frontend, type, nodename);
   48.31 @@ -959,9 +957,8 @@ static int xsd_kva_mmap(struct file *fil
   48.32  	if ((size > PAGE_SIZE) || (vma->vm_pgoff != 0))
   48.33  		return -EINVAL;
   48.34  
   48.35 -	vma->vm_pgoff = mfn_to_pfn(xen_start_info->store_mfn);
   48.36 -
   48.37 -	if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
   48.38 +	if (remap_pfn_range(vma, vma->vm_start,
   48.39 +			    mfn_to_pfn(xen_start_info->store_mfn),
   48.40  			    size, vma->vm_page_prot))
   48.41  		return -EAGAIN;
   48.42  
   48.43 @@ -972,6 +969,7 @@ static int xsd_kva_read(char *page, char
   48.44                          int count, int *eof, void *data)
   48.45  {
   48.46  	int len;
   48.47 +
   48.48  	len  = sprintf(page, "0x%p", mfn_to_virt(xen_start_info->store_mfn));
   48.49  	*eof = 1;
   48.50  	return len;
   48.51 @@ -1006,8 +1004,8 @@ static int __init xenbus_probe_init(void
   48.52  	device_register(&xenbus_backend.dev);
   48.53  
   48.54  	/*
   48.55 -	** Domain0 doesn't have a store_evtchn or store_mfn yet.
   48.56 -	*/
   48.57 +	 * Domain0 doesn't have a store_evtchn or store_mfn yet.
   48.58 +	 */
   48.59  	dom0 = (xen_start_info->store_evtchn == 0);
   48.60  
   48.61  	if (dom0) {
   48.62 @@ -1029,7 +1027,7 @@ static int __init xenbus_probe_init(void
   48.63  		xen_start_info->store_mfn =
   48.64  			pfn_to_mfn(virt_to_phys((void *)page) >>
   48.65  				   PAGE_SHIFT);
   48.66 -		
   48.67 +
   48.68  		/* Next allocate a local port which xenstored can bind to */
   48.69  		op.cmd = EVTCHNOP_alloc_unbound;
   48.70  		op.u.alloc_unbound.dom        = DOMID_SELF;
   48.71 @@ -1040,14 +1038,16 @@ static int __init xenbus_probe_init(void
   48.72  		xen_start_info->store_evtchn = op.u.alloc_unbound.port;
   48.73  
   48.74  		/* And finally publish the above info in /proc/xen */
   48.75 -		if ((xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0400))) {
   48.76 +		xsd_kva_intf = create_xen_proc_entry("xsd_kva", 0600);
   48.77 +		if (xsd_kva_intf) {
   48.78  			memcpy(&xsd_kva_fops, xsd_kva_intf->proc_fops,
   48.79  			       sizeof(xsd_kva_fops));
   48.80  			xsd_kva_fops.mmap = xsd_kva_mmap;
   48.81  			xsd_kva_intf->proc_fops = &xsd_kva_fops;
   48.82  			xsd_kva_intf->read_proc = xsd_kva_read;
   48.83  		}
   48.84 -		if ((xsd_port_intf = create_xen_proc_entry("xsd_port", 0400)))
   48.85 +		xsd_port_intf = create_xen_proc_entry("xsd_port", 0400);
   48.86 +		if (xsd_port_intf)
   48.87  			xsd_port_intf->read_proc = xsd_port_read;
   48.88  	}
   48.89  
    49.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Mar 14 13:10:21 2006 -0700
    49.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Mar 14 13:50:35 2006 -0700
    49.3 @@ -176,9 +176,8 @@ void *xenbus_dev_request_and_reply(struc
    49.4  	if (err) {
    49.5  		msg->type = XS_ERROR;
    49.6  		ret = ERR_PTR(err);
    49.7 -	} else {
    49.8 +	} else
    49.9  		ret = read_reply(&msg->type, &msg->len);
   49.10 -	}
   49.11  
   49.12  	up(&xs_state.request_mutex);
   49.13  
   49.14 @@ -275,7 +274,7 @@ static unsigned int count_strings(const 
   49.15  	return num;
   49.16  }
   49.17  
   49.18 -/* Return the path to dir with /name appended. Buffer must be kfree()'ed. */ 
   49.19 +/* Return the path to dir with /name appended. Buffer must be kfree()'ed. */
   49.20  static char *join(const char *dir, const char *name)
   49.21  {
   49.22  	char *buffer;
    50.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/fixmap.h	Tue Mar 14 13:10:21 2006 -0700
    50.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/fixmap.h	Tue Mar 14 13:50:35 2006 -0700
    50.3 @@ -84,8 +84,6 @@ enum fixed_addresses {
    50.4  	FIX_PCIE_MCFG,
    50.5  #endif
    50.6  	FIX_SHARED_INFO,
    50.7 -	FIX_GNTTAB_BEGIN,
    50.8 -	FIX_GNTTAB_END = FIX_GNTTAB_BEGIN + NR_GRANT_FRAMES - 1,
    50.9  #define NR_FIX_ISAMAPS	256
   50.10  	FIX_ISAMAP_END,
   50.11  	FIX_ISAMAP_BEGIN = FIX_ISAMAP_END + NR_FIX_ISAMAPS - 1,
    51.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Tue Mar 14 13:10:21 2006 -0700
    51.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypercall.h	Tue Mar 14 13:50:35 2006 -0700
    51.3 @@ -33,6 +33,7 @@
    51.4  #include <xen/interface/xen.h>
    51.5  #include <xen/interface/sched.h>
    51.6  #include <xen/interface/nmi.h>
    51.7 +#include <linux/errno.h>
    51.8  
    51.9  #define __STR(x) #x
   51.10  #define STR(x) __STR(x)
   51.11 @@ -169,6 +170,31 @@ HYPERVISOR_sched_op(
   51.12  	return _hypercall2(int, sched_op, cmd, arg);
   51.13  }
   51.14  
   51.15 +static inline int
   51.16 +HYPERVISOR_sched_op_new(
   51.17 +	int cmd, void *arg)
   51.18 +{
   51.19 +	return _hypercall2(int, sched_op_new, cmd, arg);
   51.20 +}
   51.21 +
   51.22 +static inline int
   51.23 +HYPERVISOR_poll(
   51.24 +	evtchn_port_t *ports, unsigned int nr_ports, u64 timeout)
   51.25 +{
   51.26 +	struct sched_poll sched_poll = {
   51.27 +		.ports = ports,
   51.28 +		.nr_ports = nr_ports,
   51.29 +		.timeout = jiffies_to_st(timeout)
   51.30 +	};
   51.31 +
   51.32 +	int rc = HYPERVISOR_sched_op_new(SCHEDOP_poll, &sched_poll);
   51.33 +
   51.34 +	if (rc == -ENOSYS)
   51.35 +		rc = HYPERVISOR_sched_op(SCHEDOP_yield, 0);
   51.36 +
   51.37 +	return rc;
   51.38 +}
   51.39 +
   51.40  static inline long
   51.41  HYPERVISOR_set_timer_op(
   51.42  	u64 timeout)
   51.43 @@ -304,8 +330,7 @@ HYPERVISOR_suspend(
   51.44  
   51.45  static inline int
   51.46  HYPERVISOR_nmi_op(
   51.47 -	unsigned long op,
   51.48 -	unsigned long arg)
   51.49 +	unsigned long op, void *arg)
   51.50  {
   51.51  	return _hypercall2(int, nmi_op, op, arg);
   51.52  }
    52.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Tue Mar 14 13:10:21 2006 -0700
    52.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Tue Mar 14 13:50:35 2006 -0700
    52.3 @@ -79,12 +79,6 @@ void xen_l3_entry_update(pud_t *ptr, pud
    52.4  void xen_l4_entry_update(pgd_t *ptr, pgd_t val); /* x86_64 only */
    52.5  void xen_pgd_pin(unsigned long ptr);
    52.6  void xen_pgd_unpin(unsigned long ptr);
    52.7 -void xen_pud_pin(unsigned long ptr); /* x86_64 only */
    52.8 -void xen_pud_unpin(unsigned long ptr); /* x86_64 only */
    52.9 -void xen_pmd_pin(unsigned long ptr); /* x86_64 only */
   52.10 -void xen_pmd_unpin(unsigned long ptr); /* x86_64 only */
   52.11 -void xen_pte_pin(unsigned long ptr);
   52.12 -void xen_pte_unpin(unsigned long ptr);
   52.13  
   52.14  void xen_set_ldt(unsigned long ptr, unsigned long bytes);
   52.15  void xen_machphys_update(unsigned long mfn, unsigned long pfn);
   52.16 @@ -103,6 +97,9 @@ int xen_create_contiguous_region(
   52.17  void xen_destroy_contiguous_region(
   52.18      unsigned long vstart, unsigned int order);
   52.19  
   52.20 +/* Turn jiffies into Xen system time. */
   52.21 +u64 jiffies_to_st(unsigned long jiffies);
   52.22 +
   52.23  #include <asm/hypercall.h>
   52.24  
   52.25  #if defined(CONFIG_X86_64)
    53.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Tue Mar 14 13:10:21 2006 -0700
    53.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/page.h	Tue Mar 14 13:50:35 2006 -0700
    53.3 @@ -71,7 +71,8 @@ static inline unsigned long pfn_to_mfn(u
    53.4  {
    53.5  	if (xen_feature(XENFEAT_auto_translated_physmap))
    53.6  		return pfn;
    53.7 -	return phys_to_machine_mapping[(unsigned int)(pfn)] & ~FOREIGN_FRAME_BIT;
    53.8 +	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    53.9 +		~FOREIGN_FRAME_BIT;
   53.10  }
   53.11  
   53.12  static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    54.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h	Tue Mar 14 13:10:21 2006 -0700
    54.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable-3level.h	Tue Mar 14 13:50:35 2006 -0700
    54.3 @@ -131,8 +131,8 @@ static inline int pte_none(pte_t pte)
    54.4  	return !pte.pte_low && !pte.pte_high;
    54.5  }
    54.6  
    54.7 -#define pte_mfn(_pte) ( ((_pte).pte_low >> PAGE_SHIFT) |\
    54.8 -		        (((_pte).pte_high & 0xfff) << (32-PAGE_SHIFT)) )
    54.9 +#define pte_mfn(_pte) (((_pte).pte_low >> PAGE_SHIFT) |\
   54.10 +		       (((_pte).pte_high & 0xfff) << (32-PAGE_SHIFT)))
   54.11  #define pte_pfn(_pte) mfn_to_local_pfn(pte_mfn(_pte))
   54.12  
   54.13  extern unsigned long long __supported_pte_mask;
    55.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable.h	Tue Mar 14 13:10:21 2006 -0700
    55.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/pgtable.h	Tue Mar 14 13:50:35 2006 -0700
    55.3 @@ -272,7 +272,16 @@ static inline pte_t ptep_get_and_clear_f
    55.4  	pte_t pte;
    55.5  	if (full) {
    55.6  		pte = *ptep;
    55.7 +#ifdef CONFIG_X86_PAE
    55.8 +		/* Cannot do this in a single step, as the compiler may
    55.9 +		   issue the two stores in either order, but the hypervisor
   55.10 +		   must not see the high part before the low one. */
   55.11 +		ptep->pte_low = 0;
   55.12 +		barrier();
   55.13 +		ptep->pte_high = 0;
   55.14 +#else
   55.15  		*ptep = __pte(0);
   55.16 +#endif
   55.17  	} else {
   55.18  		pte = ptep_get_and_clear(mm, addr, ptep);
   55.19  	}
    56.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h	Tue Mar 14 13:10:21 2006 -0700
    56.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/system.h	Tue Mar 14 13:50:35 2006 -0700
    56.3 @@ -596,7 +596,7 @@ do {									\
    56.4  	_vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];		\
    56.5  	_vcpu->evtchn_upcall_mask = 0;					\
    56.6  	barrier(); /* unmask then check (avoid races) */		\
    56.7 -	if ( unlikely(_vcpu->evtchn_upcall_pending) )			\
    56.8 +	if (unlikely(_vcpu->evtchn_upcall_pending))			\
    56.9  		force_evtchn_callback();				\
   56.10  	preempt_enable();						\
   56.11  } while (0)
   56.12 @@ -618,7 +618,7 @@ do {									\
   56.13  	_vcpu = &HYPERVISOR_shared_info->vcpu_info[__vcpu_id];		\
   56.14  	if ((_vcpu->evtchn_upcall_mask = (x)) == 0) {			\
   56.15  		barrier(); /* unmask then check (avoid races) */	\
   56.16 -		if ( unlikely(_vcpu->evtchn_upcall_pending) )		\
   56.17 +		if (unlikely(_vcpu->evtchn_upcall_pending))		\
   56.18  			force_evtchn_callback();			\
   56.19  		preempt_enable();					\
   56.20  	} else								\
    57.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/setup_arch_post.h	Tue Mar 14 13:10:21 2006 -0700
    57.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/setup_arch_post.h	Tue Mar 14 13:50:35 2006 -0700
    57.3 @@ -35,12 +35,21 @@ extern void nmi(void);
    57.4  static void __init machine_specific_arch_setup(void)
    57.5  {
    57.6  	struct xen_platform_parameters pp;
    57.7 +	struct xennmi_callback cb;
    57.8 +
    57.9 +	if (xen_feature(XENFEAT_auto_translated_physmap) &&
   57.10 +	    xen_start_info->shared_info < xen_start_info->nr_pages) {
   57.11 +		HYPERVISOR_shared_info =
   57.12 +			(shared_info_t *)__va(xen_start_info->shared_info);
   57.13 +		memset(empty_zero_page, 0, sizeof(empty_zero_page));
   57.14 +	}
   57.15  
   57.16  	HYPERVISOR_set_callbacks(
   57.17  	    __KERNEL_CS, (unsigned long)hypervisor_callback,
   57.18  	    __KERNEL_CS, (unsigned long)failsafe_callback);
   57.19  
   57.20 -	HYPERVISOR_nmi_op(XENNMI_register_callback, (unsigned long)&nmi);
   57.21 +	cb.handler_address = (unsigned long)&nmi;
   57.22 +	HYPERVISOR_nmi_op(XENNMI_register_callback, &cb);
   57.23  
   57.24  	machine_specific_modify_cpu_capabilities(&boot_cpu_data);
   57.25  
    58.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Tue Mar 14 13:10:21 2006 -0700
    58.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypercall.h	Tue Mar 14 13:50:35 2006 -0700
    58.3 @@ -33,6 +33,7 @@
    58.4  #include <xen/interface/xen.h>
    58.5  #include <xen/interface/sched.h>
    58.6  #include <xen/interface/dom0_ops.h>
    58.7 +#include <linux/errno.h>
    58.8  
    58.9  /* FIXME: temp place to hold these page related macros */
   58.10  #include <asm/page.h>
   58.11 @@ -166,6 +167,31 @@ HYPERVISOR_sched_op(
   58.12  	return _hypercall2(int, sched_op, cmd, arg);
   58.13  }
   58.14  
   58.15 +static inline int
   58.16 +HYPERVISOR_sched_op_new(
   58.17 +	int cmd, void *arg)
   58.18 +{
   58.19 +	return _hypercall2(int, sched_op_new, cmd, arg);
   58.20 +}
   58.21 +
   58.22 +static inline int
   58.23 +HYPERVISOR_poll(
   58.24 +	evtchn_port_t *ports, unsigned int nr_ports, unsigned long timeout)
   58.25 +{
   58.26 +	struct sched_poll sched_poll = {
   58.27 +		.ports = ports,
   58.28 +		.nr_ports = nr_ports,
   58.29 +		.timeout = jiffies_to_st(timeout)
   58.30 +	};
   58.31 +
   58.32 +	int rc = HYPERVISOR_sched_op_new(SCHEDOP_poll, &sched_poll);
   58.33 +
   58.34 +	if (rc == -ENOSYS)
   58.35 +		rc = HYPERVISOR_sched_op(SCHEDOP_yield, 0);
   58.36 +
   58.37 +	return rc;
   58.38 +}
   58.39 +
   58.40  static inline long
   58.41  HYPERVISOR_set_timer_op(
   58.42      u64 timeout)
    59.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Tue Mar 14 13:10:21 2006 -0700
    59.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/hypervisor.h	Tue Mar 14 13:50:35 2006 -0700
    59.3 @@ -44,6 +44,9 @@ extern start_info_t *xen_start_info;
    59.4  
    59.5  void force_evtchn_callback(void);
    59.6  
    59.7 +/* Turn jiffies into Xen system time. XXX Implement me. */
    59.8 +#define jiffies_to_st(j)	0
    59.9 +
   59.10  #include <asm/hypercall.h>
   59.11  
   59.12  // for drivers/xen/privcmd/privcmd.c
    60.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/fixmap.h	Tue Mar 14 13:10:21 2006 -0700
    60.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/fixmap.h	Tue Mar 14 13:50:35 2006 -0700
    60.3 @@ -52,8 +52,6 @@ enum fixed_addresses {
    60.4  	FIX_ACPI_END = FIX_ACPI_BEGIN + FIX_ACPI_PAGES - 1,
    60.5  #endif
    60.6  	FIX_SHARED_INFO,
    60.7 -	FIX_GNTTAB_BEGIN,
    60.8 -	FIX_GNTTAB_END = FIX_GNTTAB_BEGIN + NR_GRANT_FRAMES - 1,
    60.9  #define NR_FIX_ISAMAPS	256
   60.10  	FIX_ISAMAP_END,
   60.11  	FIX_ISAMAP_BEGIN = FIX_ISAMAP_END + NR_FIX_ISAMAPS - 1,
    61.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Tue Mar 14 13:10:21 2006 -0700
    61.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/hypercall.h	Tue Mar 14 13:50:35 2006 -0700
    61.3 @@ -36,6 +36,8 @@
    61.4  
    61.5  #include <xen/interface/xen.h>
    61.6  #include <xen/interface/sched.h>
    61.7 +#include <xen/interface/nmi.h>
    61.8 +#include <linux/errno.h>
    61.9  
   61.10  #define __STR(x) #x
   61.11  #define STR(x) __STR(x)
   61.12 @@ -173,6 +175,31 @@ HYPERVISOR_sched_op(
   61.13  	return _hypercall2(int, sched_op, cmd, arg);
   61.14  }
   61.15  
   61.16 +static inline int
   61.17 +HYPERVISOR_sched_op_new(
   61.18 +	int cmd, void *arg)
   61.19 +{
   61.20 +	return _hypercall2(int, sched_op_new, cmd, arg);
   61.21 +}
   61.22 +
   61.23 +static inline int
   61.24 +HYPERVISOR_poll(
   61.25 +	evtchn_port_t *ports, unsigned int nr_ports, u64 timeout)
   61.26 +{
   61.27 +	struct sched_poll sched_poll = {
   61.28 +		.ports = ports,
   61.29 +		.nr_ports = nr_ports,
   61.30 +		.timeout = jiffies_to_st(timeout)
   61.31 +	};
   61.32 +
   61.33 +	int rc = HYPERVISOR_sched_op_new(SCHEDOP_poll, &sched_poll);
   61.34 +
   61.35 +	if (rc == -ENOSYS)
   61.36 +		rc = HYPERVISOR_sched_op(SCHEDOP_yield, 0);
   61.37 +
   61.38 +	return rc;
   61.39 +}
   61.40 +
   61.41  static inline long
   61.42  HYPERVISOR_set_timer_op(
   61.43  	u64 timeout)
   61.44 @@ -304,8 +331,7 @@ HYPERVISOR_suspend(
   61.45  
   61.46  static inline int
   61.47  HYPERVISOR_nmi_op(
   61.48 -	unsigned long op,
   61.49 -	unsigned long arg)
   61.50 +	unsigned long op, void *arg)
   61.51  {
   61.52  	return _hypercall2(int, nmi_op, op, arg);
   61.53  }
    62.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Tue Mar 14 13:10:21 2006 -0700
    62.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/page.h	Tue Mar 14 13:50:35 2006 -0700
    62.3 @@ -89,7 +89,8 @@ static inline unsigned long pfn_to_mfn(u
    62.4  {
    62.5  	if (xen_feature(XENFEAT_auto_translated_physmap))
    62.6  		return pfn;
    62.7 -	return phys_to_machine_mapping[(unsigned int)(pfn)] & ~FOREIGN_FRAME_BIT;
    62.8 +	return phys_to_machine_mapping[(unsigned int)(pfn)] &
    62.9 +		~FOREIGN_FRAME_BIT;
   62.10  }
   62.11  
   62.12  static inline int phys_to_machine_mapping_valid(unsigned long pfn)
    63.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgalloc.h	Tue Mar 14 13:10:21 2006 -0700
    63.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/asm/pgalloc.h	Tue Mar 14 13:50:35 2006 -0700
    63.3 @@ -181,7 +181,6 @@ static inline struct page *pte_alloc_one
    63.4  static inline void pte_free_kernel(pte_t *pte)
    63.5  {
    63.6  	BUG_ON((unsigned long)pte & (PAGE_SIZE-1));
    63.7 -        xen_pte_unpin(__pa(pte));
    63.8          make_page_writable(pte, XENFEAT_writable_page_tables);
    63.9  	free_page((unsigned long)pte); 
   63.10  }
    64.1 --- a/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/setup_arch_post.h	Tue Mar 14 13:10:21 2006 -0700
    64.2 +++ b/linux-2.6-xen-sparse/include/asm-x86_64/mach-xen/setup_arch_post.h	Tue Mar 14 13:50:35 2006 -0700
    64.3 @@ -23,13 +23,18 @@ extern void nmi(void);
    64.4  
    64.5  static void __init machine_specific_arch_setup(void)
    64.6  {
    64.7 +#ifdef CONFIG_X86_LOCAL_APIC
    64.8 +	struct xennmi_callback cb;
    64.9 +#endif
   64.10 +
   64.11  	HYPERVISOR_set_callbacks(
   64.12                  (unsigned long) hypervisor_callback,
   64.13                  (unsigned long) failsafe_callback,
   64.14                  (unsigned long) system_call);
   64.15  
   64.16  #ifdef CONFIG_X86_LOCAL_APIC
   64.17 -	HYPERVISOR_nmi_op(XENNMI_register_callback, (unsigned long)&nmi);
   64.18 +	cb.handler_address = (unsigned long)&nmi;
   64.19 +	HYPERVISOR_nmi_op(XENNMI_register_callback, &cb);
   64.20  #endif
   64.21  
   64.22  	machine_specific_modify_cpu_capabilities(&boot_cpu_data);
    65.1 --- a/linux-2.6-xen-sparse/include/linux/mm.h	Tue Mar 14 13:10:21 2006 -0700
    65.2 +++ b/linux-2.6-xen-sparse/include/linux/mm.h	Tue Mar 14 13:50:35 2006 -0700
    65.3 @@ -1020,9 +1020,9 @@ struct page *follow_page(struct vm_area_
    65.4  #define FOLL_ANON	0x08	/* give ZERO_PAGE if no pgtable */
    65.5  
    65.6  #ifdef CONFIG_XEN
    65.7 -typedef int (*pte_fn_t)(pte_t *pte, struct page *pte_page, unsigned long addr, 
    65.8 +typedef int (*pte_fn_t)(pte_t *pte, struct page *pte_page, unsigned long addr,
    65.9                          void *data);
   65.10 -extern int generic_page_range(struct mm_struct *mm, unsigned long address, 
   65.11 +extern int generic_page_range(struct mm_struct *mm, unsigned long address,
   65.12                                unsigned long size, pte_fn_t fn, void *data);
   65.13  #endif
   65.14  
    66.1 --- a/linux-2.6-xen-sparse/include/xen/xenbus.h	Tue Mar 14 13:10:21 2006 -0700
    66.2 +++ b/linux-2.6-xen-sparse/include/xen/xenbus.h	Tue Mar 14 13:50:35 2006 -0700
    66.3 @@ -28,8 +28,8 @@
    66.4   * IN THE SOFTWARE.
    66.5   */
    66.6  
    66.7 -#ifndef _ASM_XEN_XENBUS_H
    66.8 -#define _ASM_XEN_XENBUS_H
    66.9 +#ifndef _XEN_XENBUS_H
   66.10 +#define _XEN_XENBUS_H
   66.11  
   66.12  #include <linux/device.h>
   66.13  #include <linux/notifier.h>
   66.14 @@ -170,7 +170,7 @@ void xenbus_resume(void);
   66.15   * be saved in the store.
   66.16   */
   66.17  int xenbus_watch_path(struct xenbus_device *dev, const char *path,
   66.18 -		      struct xenbus_watch *watch, 
   66.19 +		      struct xenbus_watch *watch,
   66.20  		      void (*callback)(struct xenbus_watch *,
   66.21  				       const char **, unsigned int));
   66.22  
   66.23 @@ -185,7 +185,7 @@ int xenbus_watch_path(struct xenbus_devi
   66.24   * saved in the store.
   66.25   */
   66.26  int xenbus_watch_path2(struct xenbus_device *dev, const char *path,
   66.27 -		       const char *path2, struct xenbus_watch *watch, 
   66.28 +		       const char *path2, struct xenbus_watch *watch,
   66.29  		       void (*callback)(struct xenbus_watch *,
   66.30  					const char **, unsigned int));
   66.31  
   66.32 @@ -216,8 +216,8 @@ int xenbus_grant_ring(struct xenbus_devi
   66.33   * page to that address, and sets *vaddr to that address.
   66.34   * xenbus_map_ring does not allocate the virtual address space (you must do
   66.35   * this yourself!). It only maps in the page to the specified address.
   66.36 - * Returns 0 on success, and GNTST_* (see xen/include/public/grant_table.h) or
   66.37 - * -ENOMEM on error. If an error is returned, device will switch to
   66.38 + * Returns 0 on success, and GNTST_* (see xen/include/interface/grant_table.h)
   66.39 + * or -ENOMEM on error. If an error is returned, device will switch to
   66.40   * XenbusStateClosing and the error message will be saved in XenStore.
   66.41   */
   66.42  int xenbus_map_ring_valloc(struct xenbus_device *dev,
   66.43 @@ -231,7 +231,7 @@ int xenbus_map_ring(struct xenbus_device
   66.44   * Use xenbus_unmap_ring_vfree if you mapped in your memory with
   66.45   * xenbus_map_ring_valloc (it will free the virtual address space).
   66.46   * Returns 0 on success and returns GNTST_* on error
   66.47 - * (see xen/include/public/grant_table.h).
   66.48 + * (see xen/include/interface/grant_table.h).
   66.49   */
   66.50  int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr);
   66.51  int xenbus_unmap_ring(struct xenbus_device *dev,
   66.52 @@ -285,7 +285,7 @@ void xenbus_dev_fatal(struct xenbus_devi
   66.53  		      ...);
   66.54  
   66.55  
   66.56 -#endif /* _ASM_XEN_XENBUS_H */
   66.57 +#endif /* _XEN_XENBUS_H */
   66.58  
   66.59  /*
   66.60   * Local variables:
    67.1 --- a/tools/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
    67.2 +++ b/tools/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
    67.3 @@ -10,16 +10,6 @@ XEN_LIBXC          = $(XEN_ROOT)/tools/l
    67.4  XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
    67.5  XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
    67.6  
    67.7 -ifeq ($(XEN_TARGET_ARCH),x86_32)
    67.8 -CFLAGS  += -m32 -march=i686
    67.9 -LDFLAGS += -m32
   67.10 -endif
   67.11 -
   67.12 -ifeq ($(XEN_TARGET_ARCH),x86_64)
   67.13 -CFLAGS  += -m64
   67.14 -LDFLAGS += -m64
   67.15 -endif
   67.16 -
   67.17  X11_LDPATH = -L/usr/X11R6/$(LIBDIR)
   67.18  
   67.19  %.opic: %.c
    68.1 --- a/tools/blktap/Makefile	Tue Mar 14 13:10:21 2006 -0700
    68.2 +++ b/tools/blktap/Makefile	Tue Mar 14 13:50:35 2006 -0700
    68.3 @@ -22,11 +22,8 @@ LIBS     := -lpthread -lz
    68.4  SRCS     :=
    68.5  SRCS     += blktaplib.c xenbus.c blkif.c
    68.6  
    68.7 -CFLAGS   += -Wall
    68.8  CFLAGS   += -Werror
    68.9  CFLAGS   += -Wno-unused
   68.10 -#CFLAGS   += -O3
   68.11 -CFLAGS   += -g3
   68.12  CFLAGS   += -fno-strict-aliasing
   68.13  CFLAGS   += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
   68.14  # get asprintf():
    69.1 --- a/tools/blktap/parallax/Makefile	Tue Mar 14 13:10:21 2006 -0700
    69.2 +++ b/tools/blktap/parallax/Makefile	Tue Mar 14 13:50:35 2006 -0700
    69.3 @@ -31,11 +31,8 @@ VDI_TOOLS += vdi_fill
    69.4  VDI_TOOLS += vdi_tree
    69.5  VDI_TOOLS += vdi_validate
    69.6  
    69.7 -CFLAGS   += -Wall
    69.8  CFLAGS   += -Werror
    69.9  CFLAGS   += -Wno-unused
   69.10 -#CFLAGS   += -O3
   69.11 -CFLAGS   += -g3
   69.12  CFLAGS   += -fno-strict-aliasing
   69.13  CFLAGS   += $(INCLUDES)
   69.14  CFLAGS   += -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
   69.15 @@ -58,7 +55,7 @@ parallax: $(PLX_SRCS)
   69.16  	$(CC) $(CFLAGS) -o parallax -L.. $(LDFLAGS) $(PLX_SRCS)
   69.17  
   69.18  ${VDI_TOOLS}: %: %.c $(VDI_SRCS)
   69.19 -	$(CC) $(CFLAGS) -g3 -o $@ $@.c $(LDFLAGS) $(VDI_SRCS)
   69.20 +	$(CC) $(CFLAGS) -o $@ $@.c $(LDFLAGS) $(VDI_SRCS)
   69.21  
   69.22  .PHONY: TAGS clean install rpm
   69.23 --include $(DEPS)
   69.24 \ No newline at end of file
   69.25 +-include $(DEPS)
    70.1 --- a/tools/blktap/ublkback/Makefile	Tue Mar 14 13:10:21 2006 -0700
    70.2 +++ b/tools/blktap/ublkback/Makefile	Tue Mar 14 13:50:35 2006 -0700
    70.3 @@ -9,11 +9,8 @@ INSTALL_PROG = $(INSTALL) -m0755
    70.4  IBIN         = ublkback
    70.5  INSTALL_DIR  = /usr/sbin
    70.6  
    70.7 -CFLAGS   += -Wall
    70.8  CFLAGS   += -Werror
    70.9  CFLAGS   += -Wno-unused
   70.10 -#CFLAGS   += -O3
   70.11 -CFLAGS   += -g3
   70.12  CFLAGS   += -fno-strict-aliasing
   70.13  CFLAGS   += -I $(XEN_LIBXC)
   70.14  CFLAGS   += $(INCLUDES) -I.
    71.1 --- a/tools/console/Makefile	Tue Mar 14 13:10:21 2006 -0700
    71.2 +++ b/tools/console/Makefile	Tue Mar 14 13:50:35 2006 -0700
    71.3 @@ -9,7 +9,7 @@ INSTALL         = install
    71.4  INSTALL_PROG    = $(INSTALL) -m0755
    71.5  INSTALL_DIR     = $(INSTALL) -d -m0755
    71.6  
    71.7 -CFLAGS  += -Wall -Werror -g3
    71.8 +CFLAGS  += -Werror -g
    71.9  
   71.10  CFLAGS  += -I $(XEN_LIBXC)
   71.11  CFLAGS  += -I $(XEN_XENSTORE)
    72.1 --- a/tools/console/testsuite/Makefile	Tue Mar 14 13:10:21 2006 -0700
    72.2 +++ b/tools/console/testsuite/Makefile	Tue Mar 14 13:50:35 2006 -0700
    72.3 @@ -1,5 +1,6 @@
    72.4 -CFLAGS=-g -Wall
    72.5 -CC=gcc
    72.6 +XEN_ROOT = ../../..
    72.7 +include $(XEN_ROOT)/tools/Rules.mk
    72.8 +
    72.9  LDFLAGS=-static
   72.10  
   72.11  all: console-dom0 console-domU procpipe
    73.1 --- a/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Tue Mar 14 13:10:21 2006 -0700
    73.2 +++ b/tools/debugger/gdb/gdb-6.2.1-xen-sparse/gdb/gdbserver/linux-xen-low.c	Tue Mar 14 13:50:35 2006 -0700
    73.3 @@ -229,8 +229,6 @@ linux_wait (char *status)
    73.4    if (xc_waitdomain(xc_handle, current_domid, &w, 0))
    73.5        return -1;
    73.6    
    73.7 -  linux_set_inferior();
    73.8 -
    73.9    *status = 'T';
   73.10    if (expect_signal)
   73.11        return expect_signal;
    74.1 --- a/tools/debugger/libxendebug/Makefile	Tue Mar 14 13:10:21 2006 -0700
    74.2 +++ b/tools/debugger/libxendebug/Makefile	Tue Mar 14 13:50:35 2006 -0700
    74.3 @@ -7,14 +7,12 @@ INSTALL_DIR	= $(INSTALL) -d -m0755
    74.4  MAJOR    = 3.0
    74.5  MINOR    = 0
    74.6  
    74.7 -CC       = gcc
    74.8 -
    74.9  XEN_ROOT = ../../..
   74.10  include $(XEN_ROOT)/tools/Rules.mk
   74.11  
   74.12  SRCS     := xendebug.c
   74.13  
   74.14 -CFLAGS   += -Wall -Werror -O3 -fno-strict-aliasing
   74.15 +CFLAGS   += -Werror -fno-strict-aliasing
   74.16  CFLAGS   += $(INCLUDES) -I. -I$(XEN_ROOT)/tools/libxc
   74.17  # Get gcc to generate the dependencies for us.
   74.18  CFLAGS   += -Wp,-MD,.$(@F).d
    75.1 --- a/tools/debugger/pdb/Makefile	Tue Mar 14 13:10:21 2006 -0700
    75.2 +++ b/tools/debugger/pdb/Makefile	Tue Mar 14 13:50:35 2006 -0700
    75.3 @@ -20,7 +20,6 @@ INCLUDES   += -I ./linux-2.6-module
    75.4  INCLUDES   += -I $(OCAML_ROOT)/lib/ocaml
    75.5  
    75.6  CFLAGS     += $(INCLUDES)
    75.7 -CFLAGS     += -Wall
    75.8  CFLAGS     += -Werror
    75.9  CFLAGS     += -g
   75.10  
    76.1 --- a/tools/firmware/acpi/Makefile	Tue Mar 14 13:10:21 2006 -0700
    76.2 +++ b/tools/firmware/acpi/Makefile	Tue Mar 14 13:50:35 2006 -0700
    76.3 @@ -16,11 +16,12 @@
    76.4  # *
    76.5  # */
    76.6  #
    76.7 +
    76.8 +XEN_ROOT = ../../..
    76.9 +include $(XEN_ROOT)/tools/Rules.mk
   76.10 +
   76.11  # Compiler flag
   76.12 -CFLAG=-I. -I../../libxc
   76.13 -	
   76.14 -# Compiler tool	
   76.15 -CC=gcc
   76.16 +HOSTCFLAGS += -I. -I../../libxc
   76.17  
   76.18  # TARGET
   76.19  C_SRC=$(shell ls *.c)
   76.20 @@ -33,7 +34,7 @@ IASL_URL=http://developer.intel.com/tech
   76.21  
   76.22  vpath iasl $(PATH)
   76.23  all:$(ACPI_BIN)
   76.24 -	
   76.25 +
   76.26  acpi_dsdt.c:acpi_dsdt.asl
   76.27  	$(MAKE) iasl
   76.28  	iasl -oa -tc acpi_dsdt.asl
   76.29 @@ -54,15 +55,13 @@ iasl:
   76.30  	install $(IASL_VER)/compiler/iasl /usr/bin/iasl
   76.31  
   76.32  $(ACPI_GEN):$(C_SRC) $(H_SRC) acpi_dsdt.c
   76.33 -	$(CC) -o $(ACPI_GEN) $(CFLAG) $(shell ls *.c)
   76.34 +	$(HOSTCC) -o $(ACPI_GEN) $(HOSTCFLAGS) $(shell ls *.c)
   76.35  
   76.36  $(ACPI_BIN):$(ACPI_GEN)
   76.37  	./$(ACPI_GEN) $(ACPI_BIN)
   76.38 -	
   76.39 +
   76.40  clean:
   76.41  	rm -rf *.o $(ACPI_GEN) $(ACPI_BIN) $(IASL_VER) 
   76.42 -#   rm -f acpi_dsdt.c
   76.43  	rm -rf  $(IASL_VER).tar.gz
   76.44 -install:all
   76.45 -		
   76.46 -	
   76.47 +
   76.48 +install: all
    77.1 --- a/tools/ioemu/Makefile	Tue Mar 14 13:10:21 2006 -0700
    77.2 +++ b/tools/ioemu/Makefile	Tue Mar 14 13:50:35 2006 -0700
    77.3 @@ -3,7 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
    77.4  
    77.5  -include config-host.mak
    77.6  
    77.7 -CFLAGS+=-Wall -O2 -g -fno-strict-aliasing 
    77.8 +CFLAGS+=-g -fno-strict-aliasing 
    77.9  ifdef CONFIG_DARWIN
   77.10  CFLAGS+= -mdynamic-no-pic
   77.11  endif
    78.1 --- a/tools/ioemu/configure	Tue Mar 14 13:10:21 2006 -0700
    78.2 +++ b/tools/ioemu/configure	Tue Mar 14 13:50:35 2006 -0700
    78.3 @@ -392,17 +392,17 @@ echo "docdir=$docdir" >> $config_mak
    78.4  echo "configdir=$configdir" >> $config_mak
    78.5  echo "LIBDIR=$libdir" >> $config_mak
    78.6  echo "#define CONFIG_QEMU_SHAREDIR \"$datadir\"" >> $config_h
    78.7 -echo "MAKE=$make" >> $config_mak
    78.8 -echo "CC=$cc" >> $config_mak
    78.9 -if test "$have_gcc3_options" = "yes" ; then
   78.10 -  echo "HAVE_GCC3_OPTIONS=yes" >> $config_mak
   78.11 -fi
   78.12 -echo "HOST_CC=$host_cc" >> $config_mak
   78.13 -echo "AR=$ar" >> $config_mak
   78.14 -echo "STRIP=$strip -s -R .comment -R .note" >> $config_mak
   78.15 -echo "CFLAGS=$CFLAGS" >> $config_mak
   78.16 -echo "LDFLAGS=$LDFLAGS" >> $config_mak
   78.17 -echo "EXESUF=$EXESUF" >> $config_mak
   78.18 +#echo "MAKE=$make" >> $config_mak
   78.19 +#echo "CC=$cc" >> $config_mak
   78.20 +#if test "$have_gcc3_options" = "yes" ; then
   78.21 +#  echo "HAVE_GCC3_OPTIONS=yes" >> $config_mak
   78.22 +#fi
   78.23 +#echo "HOST_CC=$host_cc" >> $config_mak
   78.24 +#echo "AR=$ar" >> $config_mak
   78.25 +#echo "STRIP=$strip -s -R .comment -R .note" >> $config_mak
   78.26 +#echo "CFLAGS=$CFLAGS" >> $config_mak
   78.27 +#echo "LDFLAGS=$LDFLAGS" >> $config_mak
   78.28 +#echo "EXESUF=$EXESUF" >> $config_mak
   78.29  
   78.30  if test "$bigendian" = "yes" ; then
   78.31    echo "WORDS_BIGENDIAN=yes" >> $config_mak
    79.1 --- a/tools/ioemu/monitor.c	Tue Mar 14 13:10:21 2006 -0700
    79.2 +++ b/tools/ioemu/monitor.c	Tue Mar 14 13:50:35 2006 -0700
    79.3 @@ -407,6 +407,7 @@ static int eject_device(BlockDriverState
    79.4  
    79.5  static void do_eject(int force, const char *filename)
    79.6  {
    79.7 +    char cmd[1024];
    79.8      BlockDriverState *bs;
    79.9  
   79.10      bs = bdrv_find(filename);
   79.11 @@ -415,6 +416,9 @@ static void do_eject(int force, const ch
   79.12          return;
   79.13      }
   79.14      eject_device(bs, force);
   79.15 +    sprintf(cmd, "eject %s", filename);
   79.16 +    system(cmd);
   79.17 +
   79.18  }
   79.19  
   79.20  static void do_change(const char *device, const char *filename)
    80.1 --- a/tools/ioemu/target-i386-dm/Makefile	Tue Mar 14 13:10:21 2006 -0700
    80.2 +++ b/tools/ioemu/target-i386-dm/Makefile	Tue Mar 14 13:50:35 2006 -0700
    80.3 @@ -13,7 +13,7 @@ ifdef CONFIG_USER_ONLY
    80.4  VPATH+=:$(SRC_PATH)/linux-user
    80.5  DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
    80.6  endif
    80.7 -CFLAGS+=-Wall -O2 -g -fno-strict-aliasing
    80.8 +CFLAGS+=-g -fno-strict-aliasing
    80.9  LDFLAGS=-g
   80.10  LIBS=
   80.11  HELPER_CFLAGS=$(CFLAGS)
   80.12 @@ -99,7 +99,6 @@ LDFLAGS+=-static
   80.13  endif
   80.14  
   80.15  ifeq ($(ARCH),i386)
   80.16 -CFLAGS+=-fomit-frame-pointer
   80.17  OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
   80.18  ifeq ($(HAVE_GCC3_OPTIONS),yes)
   80.19  OP_CFLAGS+= -falign-functions=0 -fno-gcse
   80.20 @@ -236,7 +235,7 @@ endif
   80.21  all: $(PROGS)
   80.22  
   80.23  $(QEMU_USER): $(OBJS)
   80.24 -	$(CC) $(LDFLAGS) -o $@ $^  $(LIBS)
   80.25 +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^  $(LIBS)
   80.26  ifeq ($(ARCH),alpha)
   80.27  # Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
   80.28  # the address space (31 bit so sign extending doesn't matter)
   80.29 @@ -312,7 +311,7 @@ endif
   80.30  endif
   80.31  
   80.32  $(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
   80.33 -	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VNC_LIBS) $(VL_LIBS) -lpthread
   80.34 +	$(CC) $(CFLAGS) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(VNC_LIBS) $(VL_LIBS) -lpthread
   80.35  
   80.36  vnc.o: vnc.c keyboard_rdesktop.c
   80.37  	$(CC) $(CFLAGS) $(DEFINES) $(VNC_CFLAGS) -c -o $@ $<
    81.1 --- a/tools/ioemu/vl.h	Tue Mar 14 13:10:21 2006 -0700
    81.2 +++ b/tools/ioemu/vl.h	Tue Mar 14 13:50:35 2006 -0700
    81.3 @@ -697,7 +697,7 @@ void lance_init(NetDriverState *nd, int 
    81.4  void tcx_init(DisplayState *ds, uint32_t addr);
    81.5  
    81.6  /* sched.c */
    81.7 -void sched_init();
    81.8 +void sched_init(uint32_t, uint32_t);
    81.9  
   81.10  /* magic-load.c */
   81.11  void magic_init(const char *kfn, int kloadaddr, uint32_t addr);
   81.12 @@ -799,7 +799,7 @@ void readline_start(const char *prompt, 
   81.13  
   81.14  int gdbserver_start(int port);
   81.15  void update_select_wakeup_events(void);
   81.16 -void tun_receive_handler();
   81.17 +void tun_receive_handler(fd_set *);
   81.18  
   81.19  extern char domain_name[];
   81.20  #endif /* VL_H */
    82.1 --- a/tools/libxc/Makefile	Tue Mar 14 13:10:21 2006 -0700
    82.2 +++ b/tools/libxc/Makefile	Tue Mar 14 13:50:35 2006 -0700
    82.3 @@ -7,8 +7,6 @@ INSTALL_DIR	= $(INSTALL) -d -m0755
    82.4  MAJOR    = 3.0
    82.5  MINOR    = 0
    82.6  
    82.7 -CC       = gcc
    82.8 -
    82.9  XEN_ROOT = ../..
   82.10  include $(XEN_ROOT)/tools/Rules.mk
   82.11  
   82.12 @@ -48,9 +46,7 @@ BUILD_SRCS += xc_linux_save.c
   82.13  BUILD_SRCS += xc_hvm_build.c
   82.14  endif
   82.15  
   82.16 -CFLAGS   += -Wall
   82.17  CFLAGS   += -Werror
   82.18 -CFLAGS   += -O3
   82.19  CFLAGS   += -fno-strict-aliasing
   82.20  CFLAGS   += $(INCLUDES) -I.
   82.21  
    83.1 --- a/tools/libxc/xc_core.c	Tue Mar 14 13:10:21 2006 -0700
    83.2 +++ b/tools/libxc/xc_core.c	Tue Mar 14 13:50:35 2006 -0700
    83.3 @@ -6,18 +6,17 @@
    83.4  #include <zlib.h>
    83.5  
    83.6  /* number of pages to write at a time */
    83.7 -#define DUMP_INCREMENT 4 * 1024
    83.8 +#define DUMP_INCREMENT (4 * 1024)
    83.9  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
   83.10  
   83.11  static int
   83.12  copy_from_domain_page(int xc_handle,
   83.13                        uint32_t domid,
   83.14 -                      unsigned long *page_array,
   83.15 -                      unsigned long src_pfn,
   83.16 +                      unsigned long mfn,
   83.17                        void *dst_page)
   83.18  {
   83.19      void *vaddr = xc_map_foreign_range(
   83.20 -        xc_handle, domid, PAGE_SIZE, PROT_READ, page_array[src_pfn]);
   83.21 +        xc_handle, domid, PAGE_SIZE, PROT_READ, mfn);
   83.22      if ( vaddr == NULL )
   83.23          return -1;
   83.24      memcpy(dst_page, vaddr, PAGE_SIZE);
   83.25 @@ -26,93 +25,152 @@ copy_from_domain_page(int xc_handle,
   83.26  }
   83.27  
   83.28  int 
   83.29 +xc_domain_dumpcore_via_callback(int xc_handle,
   83.30 +                                uint32_t domid,
   83.31 +                                void *args,
   83.32 +                                dumpcore_rtn_t dump_rtn)
   83.33 +{
   83.34 +    unsigned long nr_pages;
   83.35 +    unsigned long *page_array = NULL;
   83.36 +    xc_dominfo_t info;
   83.37 +    int i, nr_vcpus = 0;
   83.38 +    char *dump_mem, *dump_mem_start = NULL;
   83.39 +    struct xc_core_header header;
   83.40 +    vcpu_guest_context_t  ctxt[MAX_VIRT_CPUS];
   83.41 +    char dummy[PAGE_SIZE];
   83.42 +    int dummy_len;
   83.43 +    int sts;
   83.44 +
   83.45 +    if ( (dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL )
   83.46 +    {
   83.47 +        PERROR("Could not allocate dump_mem");
   83.48 +        goto error_out;
   83.49 +    }
   83.50 + 
   83.51 +    if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
   83.52 +    {
   83.53 +        PERROR("Could not get info for domain");
   83.54 +        goto error_out;
   83.55 +    }
   83.56 + 
   83.57 +    if ( domid != info.domid )
   83.58 +    {
   83.59 +        PERROR("Domain %d does not exist", domid);
   83.60 +        goto error_out;
   83.61 +    }
   83.62 +
   83.63 +    for ( i = 0; i <= info.max_vcpu_id; i++ )
   83.64 +        if ( xc_vcpu_getcontext(xc_handle, domid, i, &ctxt[nr_vcpus]) == 0)
   83.65 +            nr_vcpus++;
   83.66 + 
   83.67 +    nr_pages = info.nr_pages;
   83.68 +
   83.69 +    header.xch_magic = XC_CORE_MAGIC; 
   83.70 +    header.xch_nr_vcpus = nr_vcpus;
   83.71 +    header.xch_nr_pages = nr_pages;
   83.72 +    header.xch_ctxt_offset = sizeof(struct xc_core_header);
   83.73 +    header.xch_index_offset = sizeof(struct xc_core_header) +
   83.74 +        sizeof(vcpu_guest_context_t)*nr_vcpus;
   83.75 +    dummy_len = (sizeof(struct xc_core_header) +
   83.76 +                 (sizeof(vcpu_guest_context_t) * nr_vcpus) +
   83.77 +                 (nr_pages * sizeof(unsigned long)));
   83.78 +    header.xch_pages_offset = round_pgup(dummy_len);
   83.79 +    
   83.80 +    sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
   83.81 +    if ( sts != 0 )
   83.82 +        goto error_out;
   83.83 +
   83.84 +    sts = dump_rtn(args, (char *)&ctxt, sizeof(ctxt[0]) * nr_vcpus);
   83.85 +    if ( sts != 0 )
   83.86 +        goto error_out;
   83.87 +
   83.88 +    if ( (page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL )
   83.89 +    {
   83.90 +        printf("Could not allocate memory\n");
   83.91 +        goto error_out;
   83.92 +    }
   83.93 +    if ( xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages )
   83.94 +    {
   83.95 +        printf("Could not get the page frame list\n");
   83.96 +        goto error_out;
   83.97 +    }
   83.98 +    sts = dump_rtn(args, (char *)page_array, nr_pages * sizeof(unsigned long));
   83.99 +    if ( sts != 0 )
  83.100 +        goto error_out;
  83.101 +
  83.102 +    /* Pad the output data to page alignment. */
  83.103 +    memset(dummy, 0, PAGE_SIZE);
  83.104 +    sts = dump_rtn(args, dummy, header.xch_pages_offset - dummy_len);
  83.105 +    if ( sts != 0 )
  83.106 +        goto error_out;
  83.107 +
  83.108 +    for ( dump_mem = dump_mem_start, i = 0; i < nr_pages; i++ )
  83.109 +    {
  83.110 +        copy_from_domain_page(xc_handle, domid, page_array[i], dump_mem);
  83.111 +        dump_mem += PAGE_SIZE;
  83.112 +        if ( ((i + 1) % DUMP_INCREMENT == 0) || ((i + 1) == nr_pages) )
  83.113 +        {
  83.114 +            sts = dump_rtn(args, dump_mem_start, dump_mem - dump_mem_start);
  83.115 +            if ( sts != 0 )
  83.116 +                goto error_out;
  83.117 +            dump_mem = dump_mem_start;
  83.118 +        }
  83.119 +    }
  83.120 +
  83.121 +    free(dump_mem_start);
  83.122 +    free(page_array);
  83.123 +    return 0;
  83.124 +
  83.125 + error_out:
  83.126 +    free(dump_mem_start);
  83.127 +    free(page_array);
  83.128 +    return -1;
  83.129 +}
  83.130 +
  83.131 +/* Callback args for writing to a local dump file. */
  83.132 +struct dump_args {
  83.133 +    int     fd;
  83.134 +};
  83.135 +
  83.136 +/* Callback routine for writing to a local dump file. */
  83.137 +static int local_file_dump(void *args, char *buffer, unsigned int length)
  83.138 +{
  83.139 +    struct dump_args *da = args;
  83.140 +    int bytes, offset;
  83.141 +
  83.142 +    for ( offset = 0; offset < length; offset += bytes )
  83.143 +    {
  83.144 +        bytes = write(da->fd, &buffer[offset], length-offset);
  83.145 +        if ( bytes <= 0 )
  83.146 +        {
  83.147 +            PERROR("Failed to write buffer: %s", strerror(errno));
  83.148 +            return -errno;
  83.149 +        }
  83.150 +    }
  83.151 +
  83.152 +    return 0;
  83.153 +}
  83.154 +
  83.155 +int 
  83.156  xc_domain_dumpcore(int xc_handle,
  83.157                     uint32_t domid,
  83.158                     const char *corename)
  83.159  {
  83.160 -    unsigned long nr_pages;
  83.161 -    unsigned long *page_array;
  83.162 -    xc_dominfo_t info;
  83.163 -    int i, nr_vcpus = 0, dump_fd;
  83.164 -    char *dump_mem, *dump_mem_start = NULL;
  83.165 -    struct xc_core_header header;
  83.166 -    vcpu_guest_context_t  ctxt[MAX_VIRT_CPUS];
  83.167 +    struct dump_args da;
  83.168 +    int sts;
  83.169  
  83.170 - 
  83.171 -    if ((dump_fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0) {
  83.172 +    if ( (da.fd = open(corename, O_CREAT|O_RDWR, S_IWUSR|S_IRUSR)) < 0 )
  83.173 +    {
  83.174          PERROR("Could not open corefile %s: %s", corename, strerror(errno));
  83.175 -        goto error_out;
  83.176 -    }
  83.177 - 
  83.178 -    if ((dump_mem_start = malloc(DUMP_INCREMENT*PAGE_SIZE)) == NULL) {
  83.179 -        PERROR("Could not allocate dump_mem");
  83.180 -        goto error_out;
  83.181 -    }
  83.182 - 
  83.183 -    if (xc_domain_getinfo(xc_handle, domid, 1, &info) != 1) {
  83.184 -        PERROR("Could not get info for domain");
  83.185 -        goto error_out;
  83.186 +        return -errno;
  83.187      }
  83.188   
  83.189 -    for (i = 0; i < info.max_vcpu_id; i++)
  83.190 -        if (xc_vcpu_getcontext(xc_handle, domid,
  83.191 -                                       i, &ctxt[nr_vcpus]) == 0)
  83.192 -            nr_vcpus++;
  83.193 - 
  83.194 -    nr_pages = info.nr_pages;
  83.195 -
  83.196 -    header.xch_magic = XC_CORE_MAGIC;
  83.197 -    header.xch_nr_vcpus = nr_vcpus;
  83.198 -    header.xch_nr_pages = nr_pages;
  83.199 -    header.xch_ctxt_offset = sizeof(struct xc_core_header);
  83.200 -    header.xch_index_offset = sizeof(struct xc_core_header) +
  83.201 -        sizeof(vcpu_guest_context_t)*nr_vcpus;
  83.202 -    header.xch_pages_offset = round_pgup(sizeof(struct xc_core_header) +
  83.203 -                                         (sizeof(vcpu_guest_context_t) * nr_vcpus) +
  83.204 -                                         (nr_pages * sizeof(unsigned long)));
  83.205 -
  83.206 -    if (write(dump_fd, &header, sizeof(struct xc_core_header)) < 0 ||
  83.207 -        write(dump_fd, &ctxt, sizeof(ctxt[0]) * nr_vcpus) < 0)
  83.208 -    {
  83.209 -        PERROR("write failed");
  83.210 -        goto error_out;
  83.211 -    }
  83.212 +    sts = xc_domain_dumpcore_via_callback(
  83.213 +        xc_handle, domid, &da, &local_file_dump);
  83.214  
  83.215 -    if ((page_array = malloc(nr_pages * sizeof(unsigned long))) == NULL) {
  83.216 -        printf("Could not allocate memory\n");
  83.217 -        goto error_out;
  83.218 -    }
  83.219 -    if (xc_get_pfn_list(xc_handle, domid, page_array, nr_pages) != nr_pages) {
  83.220 -        printf("Could not get the page frame list\n");
  83.221 -        goto error_out;
  83.222 -    }
  83.223 -    if (write(dump_fd, page_array, nr_pages * sizeof(unsigned long)) < 0)
  83.224 -    {
  83.225 -        PERROR("write failed");
  83.226 -        goto error_out;
  83.227 -    }
  83.228 -    lseek(dump_fd, header.xch_pages_offset, SEEK_SET);
  83.229 -    for (dump_mem = dump_mem_start, i = 0; i < nr_pages; i++) {
  83.230 -        copy_from_domain_page(xc_handle, domid, page_array, i, dump_mem);
  83.231 -        dump_mem += PAGE_SIZE;
  83.232 -        if (((i + 1) % DUMP_INCREMENT == 0) || (i + 1) == nr_pages) {
  83.233 -            if (write(dump_fd, dump_mem_start, dump_mem - dump_mem_start) < 
  83.234 -                dump_mem - dump_mem_start) {
  83.235 -                PERROR("Partial write, file system full?");
  83.236 -                goto error_out;
  83.237 -            }
  83.238 -            dump_mem = dump_mem_start;
  83.239 -        }
  83.240 -    }
  83.241 +    close(da.fd);
  83.242  
  83.243 -    close(dump_fd);
  83.244 -    free(dump_mem_start);
  83.245 -    return 0;
  83.246 - error_out:
  83.247 -    if (dump_fd != -1)
  83.248 -        close(dump_fd);
  83.249 -    free(dump_mem_start);
  83.250 -    return -1;
  83.251 +    return sts;
  83.252  }
  83.253  
  83.254  /*
    84.1 --- a/tools/libxc/xc_hvm_build.c	Tue Mar 14 13:10:21 2006 -0700
    84.2 +++ b/tools/libxc/xc_hvm_build.c	Tue Mar 14 13:50:35 2006 -0700
    84.3 @@ -132,7 +132,7 @@ set_hvm_info_checksum(struct hvm_info_ta
    84.4  }
    84.5  
    84.6  /*
    84.7 - * Use E820 reserved memory 0x9F800 to pass HVM info to vmxloader
    84.8 + * Use E820 reserved memory 0x9F800 to pass HVM info to hvmloader
    84.9   * hvmloader will use this info to set BIOS accordingly
   84.10   */
   84.11  static int set_hvm_info(int xc_handle, uint32_t dom,
   84.12 @@ -338,25 +338,30 @@ static int setup_guest(int xc_handle,
   84.13      return -1;
   84.14  }
   84.15  
   84.16 -int xc_hvm_build(int xc_handle,
   84.17 -                 uint32_t domid,
   84.18 -                 int memsize,
   84.19 -                 const char *image_name,
   84.20 -                 unsigned int vcpus,
   84.21 -                 unsigned int pae,
   84.22 -                 unsigned int acpi,
   84.23 -                 unsigned int apic,
   84.24 -                 unsigned int store_evtchn,
   84.25 -                 unsigned long *store_mfn)
   84.26 +static int xc_hvm_build_internal(int xc_handle,
   84.27 +                                 uint32_t domid,
   84.28 +                                 int memsize,
   84.29 +                                 char *image,
   84.30 +                                 unsigned long image_size,
   84.31 +                                 unsigned int vcpus,
   84.32 +                                 unsigned int pae,
   84.33 +                                 unsigned int acpi,
   84.34 +                                 unsigned int apic,
   84.35 +                                 unsigned int store_evtchn,
   84.36 +                                 unsigned long *store_mfn)
   84.37  {
   84.38      dom0_op_t launch_op, op;
   84.39      int rc, i;
   84.40      vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
   84.41      unsigned long nr_pages;
   84.42 -    char         *image = NULL;
   84.43 -    unsigned long image_size;
   84.44      xen_capabilities_info_t xen_caps;
   84.45  
   84.46 +    if ( (image == NULL) || (image_size == 0) )
   84.47 +    {
   84.48 +        ERROR("Image required");
   84.49 +        goto error_out;
   84.50 +    }
   84.51 +
   84.52      if ( (rc = xc_version(xc_handle, XENVER_capabilities, &xen_caps)) != 0 )
   84.53      {
   84.54          PERROR("Failed to get xen version info");
   84.55 @@ -376,9 +381,6 @@ int xc_hvm_build(int xc_handle,
   84.56          goto error_out;
   84.57      }
   84.58  
   84.59 -    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
   84.60 -        goto error_out;
   84.61 -
   84.62      if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
   84.63      {
   84.64          PERROR("%s: ctxt mlock failed", __func__);
   84.65 @@ -405,8 +407,6 @@ int xc_hvm_build(int xc_handle,
   84.66          goto error_out;
   84.67      }
   84.68  
   84.69 -    free(image);
   84.70 -
   84.71      /* FPU is set up to default initial state. */
   84.72      memset(&ctxt->fpu_ctxt, 0, sizeof(ctxt->fpu_ctxt));
   84.73  
   84.74 @@ -450,7 +450,6 @@ int xc_hvm_build(int xc_handle,
   84.75      return rc;
   84.76  
   84.77   error_out:
   84.78 -    free(image);
   84.79      return -1;
   84.80  }
   84.81  
   84.82 @@ -580,6 +579,92 @@ loadelfimage(
   84.83      return 0;
   84.84  }
   84.85  
   84.86 +/* xc_hvm_build
   84.87 + *
   84.88 + * Create a domain for a virtualized Linux, using files/filenames
   84.89 + *
   84.90 + */
   84.91 +
   84.92 +int xc_hvm_build(int xc_handle,
   84.93 +                 uint32_t domid,
   84.94 +                 int memsize,
   84.95 +                 const char *image_name,
   84.96 +                 unsigned int vcpus,
   84.97 +                 unsigned int pae,
   84.98 +                 unsigned int acpi,
   84.99 +                 unsigned int apic,
  84.100 +                 unsigned int store_evtchn,
  84.101 +                 unsigned long *store_mfn)
  84.102 +{
  84.103 +    char *image;
  84.104 +    int  sts;
  84.105 +    unsigned long image_size;
  84.106 +
  84.107 +    if ( (image_name == NULL) ||
  84.108 +         ((image = xc_read_image(image_name, &image_size)) == NULL) )
  84.109 +        return -1;
  84.110 +
  84.111 +    sts = xc_hvm_build_internal(xc_handle, domid, memsize,
  84.112 +                                image, image_size,
  84.113 +                                vcpus, pae, acpi, apic,
  84.114 +                                store_evtchn, store_mfn);
  84.115 +
  84.116 +    free(image);
  84.117 +
  84.118 +    return sts;
  84.119 +}
  84.120 +
  84.121 +/* xc_hvm_build_mem
  84.122 + *
  84.123 + * Create a domain for a virtualized Linux, using buffers
  84.124 + *
  84.125 + */
  84.126 +
  84.127 +int xc_hvm_build_mem(int xc_handle,
  84.128 +                     uint32_t domid,
  84.129 +                     int memsize,
  84.130 +                     const char *image_buffer,
  84.131 +                     unsigned long image_size,
  84.132 +                     unsigned int vcpus,
  84.133 +                     unsigned int pae,
  84.134 +                     unsigned int acpi,
  84.135 +                     unsigned int apic,
  84.136 +                     unsigned int store_evtchn,
  84.137 +                     unsigned long *store_mfn)
  84.138 +{
  84.139 +    int           sts;
  84.140 +    unsigned long img_len;
  84.141 +    char         *img;
  84.142 +
  84.143 +    /* Validate that there is a kernel buffer */
  84.144 +
  84.145 +    if ( (image_buffer == NULL) || (image_size == 0) )
  84.146 +    {
  84.147 +        ERROR("kernel image buffer not present");
  84.148 +        return -1;
  84.149 +    }
  84.150 +
  84.151 +    img = xc_inflate_buffer(image_buffer, image_size, &img_len);
  84.152 +    if (img == NULL)
  84.153 +    {
  84.154 +        ERROR("unable to inflate ram disk buffer");
  84.155 +        return -1;
  84.156 +    }
  84.157 +
  84.158 +    sts = xc_hvm_build_internal(xc_handle, domid, memsize,
  84.159 +                                img, img_len,
  84.160 +                                vcpus, pae, acpi, apic,
  84.161 +                                store_evtchn, store_mfn);
  84.162 +
  84.163 +    /* xc_inflate_buffer may return the original buffer pointer (for
  84.164 +       for already inflated buffers), so exercise some care in freeing */
  84.165 +
  84.166 +    if ( (img != NULL) && (img != image_buffer) )
  84.167 +        free(img);
  84.168 +
  84.169 +    return sts;
  84.170 +}
  84.171 +
  84.172  /*
  84.173   * Local variables:
  84.174   * mode: C
    85.1 --- a/tools/libxc/xc_ia64_stubs.c	Tue Mar 14 13:10:21 2006 -0700
    85.2 +++ b/tools/libxc/xc_ia64_stubs.c	Tue Mar 14 13:50:35 2006 -0700
    85.3 @@ -658,7 +658,7 @@ int xc_hvm_build(int xc_handle,
    85.4          goto error_out;
    85.5      }
    85.6  
    85.7 -    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL ){
    85.8 +    if ( (image = xc_read_image(image_name, &image_size)) == NULL ){
    85.9          PERROR("Could not read guest firmware image %s",image_name);
   85.10          goto error_out;
   85.11      }
    86.1 --- a/tools/libxc/xc_linux_build.c	Tue Mar 14 13:10:21 2006 -0700
    86.2 +++ b/tools/libxc/xc_linux_build.c	Tue Mar 14 13:50:35 2006 -0700
    86.3 @@ -46,6 +46,15 @@
    86.4  #define probe_aout9(image,image_size,load_funcs) 1
    86.5  #endif
    86.6  
    86.7 +struct initrd_info {
    86.8 +    enum { INITRD_none, INITRD_file, INITRD_mem } type;
    86.9 +    unsigned long len;
   86.10 +    union {
   86.11 +        gzFile file_handle;
   86.12 +        char *mem_addr;
   86.13 +    } u;
   86.14 +};
   86.15 +
   86.16  static const char *feature_names[XENFEAT_NR_SUBMAPS*32] = {
   86.17      [XENFEAT_writable_page_tables]       = "writable_page_tables",
   86.18      [XENFEAT_writable_descriptor_tables] = "writable_descriptor_tables",
   86.19 @@ -117,7 +126,7 @@ static int parse_features(
   86.20      return -EINVAL;
   86.21  }
   86.22  
   86.23 -static int probeimageformat(char *image,
   86.24 +static int probeimageformat(const char *image,
   86.25                              unsigned long image_size,
   86.26                              struct load_funcs *load_funcs)
   86.27  {
   86.28 @@ -132,6 +141,42 @@ static int probeimageformat(char *image,
   86.29      return 0;
   86.30  }
   86.31  
   86.32 +int load_initrd(int xc_handle, domid_t dom,
   86.33 +                struct initrd_info *initrd,
   86.34 +                unsigned long physbase,
   86.35 +                unsigned long *phys_to_mach)
   86.36 +{
   86.37 +    char page[PAGE_SIZE];
   86.38 +    unsigned long pfn_start, pfn, nr_pages;
   86.39 +
   86.40 +    if ( initrd->type == INITRD_none )
   86.41 +        return 0;
   86.42 +
   86.43 +    pfn_start = physbase >> PAGE_SHIFT;
   86.44 +    nr_pages  = (initrd->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
   86.45 +
   86.46 +    for ( pfn = pfn_start; pfn < (pfn_start + nr_pages); pfn++ )
   86.47 +    {
   86.48 +        if ( initrd->type == INITRD_mem )
   86.49 +        {
   86.50 +            xc_copy_to_domain_page(
   86.51 +                xc_handle, dom, phys_to_mach[pfn],
   86.52 +                &initrd->u.mem_addr[(pfn - pfn_start) << PAGE_SHIFT]);
   86.53 +        }
   86.54 +        else
   86.55 +        {
   86.56 +            if ( gzread(initrd->u.file_handle, page, PAGE_SIZE) == -1 )
   86.57 +            {
   86.58 +                PERROR("Error reading initrd image, could not");
   86.59 +                return -EINVAL;
   86.60 +            }
   86.61 +            xc_copy_to_domain_page(xc_handle, dom, phys_to_mach[pfn], page);
   86.62 +        }
   86.63 +    }
   86.64 +
   86.65 +    return 0;
   86.66 +}
   86.67 +
   86.68  #define alloc_pt(ltab, vltab, pltab)                                    \
   86.69  do {                                                                    \
   86.70      pltab = ppt_alloc++;                                                \
   86.71 @@ -406,8 +451,8 @@ extern unsigned long xc_ia64_fpsr_defaul
   86.72  
   86.73  static int setup_guest(int xc_handle,
   86.74                         uint32_t dom,
   86.75 -                       char *image, unsigned long image_size,
   86.76 -                       gzFile initrd_gfd, unsigned long initrd_len,
   86.77 +                       const char *image, unsigned long image_size,
   86.78 +                       struct initrd_info *initrd,
   86.79                         unsigned long nr_pages,
   86.80                         unsigned long *pvsi, unsigned long *pvke,
   86.81                         unsigned long *pvss, vcpu_guest_context_t *ctxt,
   86.82 @@ -427,7 +472,6 @@ static int setup_guest(int xc_handle,
   86.83      unsigned long start_page, pgnr;
   86.84      start_info_t *start_info;
   86.85      int rc;
   86.86 -    unsigned long i;
   86.87  
   86.88      rc = probeimageformat(image, image_size, &load_funcs);
   86.89      if ( rc != 0 )
   86.90 @@ -441,7 +485,7 @@ static int setup_guest(int xc_handle,
   86.91  
   86.92      dsi.v_start      = round_pgdown(dsi.v_start);
   86.93      vinitrd_start    = round_pgup(dsi.v_end);
   86.94 -    vinitrd_end      = vinitrd_start + initrd_len;
   86.95 +    vinitrd_end      = vinitrd_start + initrd->len;
   86.96      v_end            = round_pgup(vinitrd_end);
   86.97  
   86.98      start_page = dsi.v_start >> PAGE_SHIFT;
   86.99 @@ -452,7 +496,8 @@ static int setup_guest(int xc_handle,
  86.100          goto error_out;
  86.101      }
  86.102  
  86.103 -    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array, start_page, pgnr) != pgnr )
  86.104 +    if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
  86.105 +                              start_page, pgnr) != pgnr )
  86.106      {
  86.107          PERROR("Could not get the page frame list");
  86.108          goto error_out;
  86.109 @@ -472,23 +517,9 @@ static int setup_guest(int xc_handle,
  86.110      (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
  86.111                             &dsi);
  86.112  
  86.113 -    /* Load the initial ramdisk image. */
  86.114 -    if ( initrd_len != 0 )
  86.115 -    {
  86.116 -        for ( i = (vinitrd_start - dsi.v_start);
  86.117 -              i < (vinitrd_end - dsi.v_start); i += PAGE_SIZE )
  86.118 -        {
  86.119 -            char page[PAGE_SIZE];
  86.120 -            if ( gzread(initrd_gfd, page, PAGE_SIZE) == -1 )
  86.121 -            {
  86.122 -                PERROR("Error reading initrd image, could not");
  86.123 -                goto error_out;
  86.124 -            }
  86.125 -            xc_copy_to_domain_page(xc_handle, dom,
  86.126 -                                   page_array[i>>PAGE_SHIFT], page);
  86.127 -        }
  86.128 -    }
  86.129 -
  86.130 +    if ( load_initrd(xc_handle, dom, initrd,
  86.131 +                     vinitrd_start - dsi.v_start, page_array) )
  86.132 +        goto error_out;
  86.133  
  86.134      *pvke = dsi.v_kernentry;
  86.135  
  86.136 @@ -522,11 +553,11 @@ static int setup_guest(int xc_handle,
  86.137      start_info->store_evtchn = store_evtchn;
  86.138      start_info->console_mfn   = nr_pages - 1;
  86.139      start_info->console_evtchn = console_evtchn;
  86.140 -    start_info->nr_pages       = nr_pages;	// FIXME?: nr_pages - 2 ????
  86.141 -    if ( initrd_len != 0 )
  86.142 +    start_info->nr_pages       = nr_pages; // FIXME?: nr_pages - 2 ????
  86.143 +    if ( initrd->len != 0 )
  86.144      {
  86.145          ctxt->initrd.start    = vinitrd_start;
  86.146 -        ctxt->initrd.size     = initrd_len;
  86.147 +        ctxt->initrd.size     = initrd->len;
  86.148      }
  86.149      else
  86.150      {
  86.151 @@ -550,8 +581,8 @@ static int setup_guest(int xc_handle,
  86.152  #else /* x86 */
  86.153  static int setup_guest(int xc_handle,
  86.154                         uint32_t dom,
  86.155 -                       char *image, unsigned long image_size,
  86.156 -                       gzFile initrd_gfd, unsigned long initrd_len,
  86.157 +                       const char *image, unsigned long image_size,
  86.158 +                       struct initrd_info *initrd,
  86.159                         unsigned long nr_pages,
  86.160                         unsigned long *pvsi, unsigned long *pvke,
  86.161                         unsigned long *pvss, vcpu_guest_context_t *ctxt,
  86.162 @@ -578,15 +609,11 @@ static int setup_guest(int xc_handle,
  86.163      struct load_funcs load_funcs;
  86.164      struct domain_setup_info dsi;
  86.165      unsigned long vinitrd_start;
  86.166 -    unsigned long vinitrd_end;
  86.167      unsigned long vphysmap_start;
  86.168 -    unsigned long vphysmap_end;
  86.169      unsigned long vstartinfo_start;
  86.170 -    unsigned long vstartinfo_end;
  86.171      unsigned long vstoreinfo_start;
  86.172 -    unsigned long vstoreinfo_end;
  86.173      unsigned long vconsole_start;
  86.174 -    unsigned long vconsole_end;
  86.175 +    unsigned long vsharedinfo_start = 0; /* XXX gcc */
  86.176      unsigned long vstack_start;
  86.177      unsigned long vstack_end;
  86.178      unsigned long vpt_start;
  86.179 @@ -612,6 +639,34 @@ static int setup_guest(int xc_handle,
  86.180          goto error_out;
  86.181      }
  86.182  
  86.183 +    /* Parse and validate kernel features. */
  86.184 +    p = strstr(dsi.xen_guest_string, "FEATURES=");
  86.185 +    if ( p != NULL )
  86.186 +    {
  86.187 +        if ( !parse_features(p + strlen("FEATURES="),
  86.188 +                             supported_features,
  86.189 +                             required_features) )
  86.190 +        {
  86.191 +            ERROR("Failed to parse guest kernel features.\n");
  86.192 +            goto error_out;
  86.193 +        }
  86.194 +
  86.195 +        printf("Supported features  = { %08x }.\n", supported_features[0]);
  86.196 +        printf("Required features   = { %08x }.\n", required_features[0]);
  86.197 +    }
  86.198 +
  86.199 +    for ( i = 0; i < XENFEAT_NR_SUBMAPS; i++ )
  86.200 +    {
  86.201 +        if ( (supported_features[i]&required_features[i]) != required_features[i] )
  86.202 +        {
  86.203 +            ERROR("Guest kernel does not support a required feature.\n");
  86.204 +            goto error_out;
  86.205 +        }
  86.206 +    }
  86.207 +
  86.208 +    shadow_mode_enabled = test_feature_bit(XENFEAT_auto_translated_physmap,
  86.209 +                                           required_features);
  86.210 +
  86.211      /*
  86.212       * Why do we need this? The number of page-table frames depends on the 
  86.213       * size of the bootstrap address space. But the size of the address space 
  86.214 @@ -619,17 +674,22 @@ static int setup_guest(int xc_handle,
  86.215       * read-only). We have a pair of simultaneous equations in two unknowns, 
  86.216       * which we solve by exhaustive search.
  86.217       */
  86.218 -    vinitrd_start    = round_pgup(dsi.v_end);
  86.219 -    vinitrd_end      = vinitrd_start + initrd_len;
  86.220 -    vphysmap_start   = round_pgup(vinitrd_end);
  86.221 -    vphysmap_end     = vphysmap_start + (nr_pages * sizeof(unsigned long));
  86.222 -    vstartinfo_start = round_pgup(vphysmap_end);
  86.223 -    vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
  86.224 -    vstoreinfo_start = vstartinfo_end;
  86.225 -    vstoreinfo_end   = vstoreinfo_start + PAGE_SIZE;
  86.226 -    vconsole_start   = vstoreinfo_end;
  86.227 -    vconsole_end     = vconsole_start + PAGE_SIZE;
  86.228 -    vpt_start        = vconsole_end; 
  86.229 +    v_end = round_pgup(dsi.v_end);
  86.230 +    vinitrd_start = v_end;
  86.231 +    v_end += round_pgup(initrd->len);
  86.232 +    vphysmap_start = v_end;
  86.233 +    v_end += round_pgup(nr_pages * sizeof(unsigned long));
  86.234 +    vstartinfo_start = v_end;
  86.235 +    v_end += PAGE_SIZE;
  86.236 +    vstoreinfo_start = v_end;
  86.237 +    v_end += PAGE_SIZE;
  86.238 +    vconsole_start = v_end;
  86.239 +    v_end += PAGE_SIZE;
  86.240 +    if ( shadow_mode_enabled ) {
  86.241 +        vsharedinfo_start = v_end;
  86.242 +        v_end += PAGE_SIZE;
  86.243 +    }
  86.244 +    vpt_start = v_end;
  86.245  
  86.246      for ( nr_pt_pages = 2; ; nr_pt_pages++ )
  86.247      {
  86.248 @@ -669,26 +729,22 @@ static int setup_guest(int xc_handle,
  86.249  
  86.250  #define _p(a) ((void *) (a))
  86.251  
  86.252 -    printf("VIRTUAL MEMORY ARRANGEMENT:\n"
  86.253 -           " Loaded kernel: %p->%p\n"
  86.254 -           " Init. ramdisk: %p->%p\n"
  86.255 -           " Phys-Mach map: %p->%p\n"
  86.256 -           " Start info:    %p->%p\n"
  86.257 -           " Store page:    %p->%p\n"
  86.258 -           " Console page:  %p->%p\n"
  86.259 -           " Page tables:   %p->%p\n"
  86.260 -           " Boot stack:    %p->%p\n"
  86.261 -           " TOTAL:         %p->%p\n",
  86.262 -           _p(dsi.v_kernstart), _p(dsi.v_kernend), 
  86.263 -           _p(vinitrd_start), _p(vinitrd_end),
  86.264 -           _p(vphysmap_start), _p(vphysmap_end),
  86.265 -           _p(vstartinfo_start), _p(vstartinfo_end),
  86.266 -           _p(vstoreinfo_start), _p(vstoreinfo_end),
  86.267 -           _p(vconsole_start), _p(vconsole_end),
  86.268 -           _p(vpt_start), _p(vpt_end),
  86.269 -           _p(vstack_start), _p(vstack_end),
  86.270 -           _p(dsi.v_start), _p(v_end));
  86.271 -    printf(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry));
  86.272 +    printf("VIRTUAL MEMORY ARRANGEMENT:\n");
  86.273 +    printf(" Loaded kernel:    %p->%p\n", _p(dsi.v_kernstart),
  86.274 +           _p(dsi.v_kernend));
  86.275 +    if ( initrd->len )
  86.276 +        printf(" Initial ramdisk:  %p->%p\n", _p(vinitrd_start),
  86.277 +               _p(vinitrd_start + initrd->len));
  86.278 +    printf(" Phys-Mach map:    %p\n", _p(vphysmap_start));
  86.279 +    printf(" Start info:       %p\n", _p(vstartinfo_start));
  86.280 +    printf(" Store page:       %p\n", _p(vstoreinfo_start));
  86.281 +    printf(" Console page:     %p\n", _p(vconsole_start));
  86.282 +    if ( shadow_mode_enabled )
  86.283 +        printf(" Shared Info page: %p\n", _p(vsharedinfo_start));
  86.284 +    printf(" Page tables:      %p\n", _p(vpt_start));
  86.285 +    printf(" Boot stack:       %p\n", _p(vstack_start));
  86.286 +    printf(" TOTAL:            %p->%p\n", _p(dsi.v_start), _p(v_end));
  86.287 +    printf(" ENTRY ADDRESS:    %p\n", _p(dsi.v_kernentry));
  86.288  
  86.289      if ( ((v_end - dsi.v_start)>>PAGE_SHIFT) > nr_pages )
  86.290      {
  86.291 @@ -710,54 +766,13 @@ static int setup_guest(int xc_handle,
  86.292          goto error_out;
  86.293      }
  86.294  
  86.295 -    (load_funcs.loadimage)(image, image_size, xc_handle, dom, page_array,
  86.296 +    (load_funcs.loadimage)(image, image_size,
  86.297 +                           xc_handle, dom, page_array,
  86.298                             &dsi);
  86.299  
  86.300 -    /* Parse and validate kernel features. */
  86.301 -    p = strstr(dsi.xen_guest_string, "FEATURES=");
  86.302 -    if ( p != NULL )
  86.303 -    {
  86.304 -        if ( !parse_features(p + strlen("FEATURES="),
  86.305 -                             supported_features,
  86.306 -                             required_features) )
  86.307 -        {
  86.308 -            ERROR("Failed to parse guest kernel features.\n");
  86.309 -            goto error_out;
  86.310 -        }
  86.311 -
  86.312 -        fprintf(stderr, "Supported features  = { %08x }.\n",
  86.313 -                supported_features[0]);
  86.314 -        fprintf(stderr, "Required features   = { %08x }.\n",
  86.315 -                required_features[0]);
  86.316 -    }
  86.317 -
  86.318 -    for ( i = 0; i < XENFEAT_NR_SUBMAPS; i++ )
  86.319 -    {
  86.320 -        if ( (supported_features[i]&required_features[i]) != required_features[i] )
  86.321 -        {
  86.322 -            ERROR("Guest kernel does not support a required feature.\n");
  86.323 -            goto error_out;
  86.324 -        }
  86.325 -    }
  86.326 -
  86.327 -    shadow_mode_enabled = test_feature_bit(XENFEAT_auto_translated_physmap, required_features);
  86.328 -
  86.329 -    /* Load the initial ramdisk image. */
  86.330 -    if ( initrd_len != 0 )
  86.331 -    {
  86.332 -        for ( i = (vinitrd_start - dsi.v_start); 
  86.333 -              i < (vinitrd_end - dsi.v_start); i += PAGE_SIZE )
  86.334 -        {
  86.335 -            char page[PAGE_SIZE];
  86.336 -            if ( gzread(initrd_gfd, page, PAGE_SIZE) == -1 )
  86.337 -            {
  86.338 -                PERROR("Error reading initrd image, could not");
  86.339 -                goto error_out;
  86.340 -            }
  86.341 -            xc_copy_to_domain_page(xc_handle, dom,
  86.342 -                                   page_array[i>>PAGE_SHIFT], page);
  86.343 -        }
  86.344 -    }
  86.345 +    if ( load_initrd(xc_handle, dom, initrd,
  86.346 +                     vinitrd_start - dsi.v_start, page_array) )
  86.347 +        goto error_out;
  86.348  
  86.349      /* setup page tables */
  86.350  #if defined(__i386__)
  86.351 @@ -851,7 +866,7 @@ static int setup_guest(int xc_handle,
  86.352  
  86.353      if ( shadow_mode_enabled )
  86.354      {
  86.355 -        struct xen_reserved_phys_area xrpa;
  86.356 +        struct xen_add_to_physmap xatp;
  86.357  
  86.358          /* Enable shadow translate mode */
  86.359          if ( xc_shadow_control(xc_handle, dom,
  86.360 @@ -862,17 +877,36 @@ static int setup_guest(int xc_handle,
  86.361              goto error_out;
  86.362          }
  86.363  
  86.364 -        /* Find the shared info frame.  It's guaranteed to be at the
  86.365 -           start of the PFN hole. */
  86.366 -        xrpa.domid = dom;
  86.367 -        xrpa.idx   = 0;
  86.368 -        rc = xc_memory_op(xc_handle, XENMEM_reserved_phys_area, &xrpa);
  86.369 +        guest_shared_info_mfn = (vsharedinfo_start-dsi.v_start) >> PAGE_SHIFT;
  86.370 +
  86.371 +        /* Map shared info frame into guest physmap. */
  86.372 +        xatp.domid = dom;
  86.373 +        xatp.space = XENMAPSPACE_shared_info;
  86.374 +        xatp.idx   = 0;
  86.375 +        xatp.gpfn  = guest_shared_info_mfn;
  86.376 +        rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
  86.377          if ( rc != 0 )
  86.378          {
  86.379 -            PERROR("Cannot find shared info pfn");
  86.380 +            PERROR("Cannot map shared info pfn");
  86.381              goto error_out;
  86.382          }
  86.383 -        guest_shared_info_mfn = xrpa.first_gpfn;
  86.384 +
  86.385 +        /* Map grant table frames into guest physmap. */
  86.386 +        for ( i = 0; ; i++ )
  86.387 +        {
  86.388 +            xatp.domid = dom;
  86.389 +            xatp.space = XENMAPSPACE_grant_table;
  86.390 +            xatp.idx   = i;
  86.391 +            xatp.gpfn  = nr_pages + i;
  86.392 +            rc = xc_memory_op(xc_handle, XENMEM_add_to_physmap, &xatp);
  86.393 +            if ( rc != 0 )
  86.394 +            {
  86.395 +                if ( errno == EINVAL )
  86.396 +                    break; /* done all grant tables */
  86.397 +                PERROR("Cannot map grant table pfn");
  86.398 +                goto error_out;
  86.399 +            }
  86.400 +        }
  86.401      }
  86.402      else
  86.403      {
  86.404 @@ -914,10 +948,10 @@ static int setup_guest(int xc_handle,
  86.405      start_info->store_evtchn = store_evtchn;
  86.406      start_info->console_mfn   = guest_console_mfn;
  86.407      start_info->console_evtchn = console_evtchn;
  86.408 -    if ( initrd_len != 0 )
  86.409 +    if ( initrd->len != 0 )
  86.410      {
  86.411          start_info->mod_start    = vinitrd_start;
  86.412 -        start_info->mod_len      = initrd_len;
  86.413 +        start_info->mod_len      = initrd->len;
  86.414      }
  86.415      if ( cmdline != NULL )
  86.416      { 
  86.417 @@ -970,27 +1004,24 @@ static int setup_guest(int xc_handle,
  86.418  }
  86.419  #endif
  86.420  
  86.421 -int xc_linux_build(int xc_handle,
  86.422 -                   uint32_t domid,
  86.423 -                   const char *image_name,
  86.424 -                   const char *ramdisk_name,
  86.425 -                   const char *cmdline,
  86.426 -                   const char *features,
  86.427 -                   unsigned long flags,
  86.428 -                   unsigned int store_evtchn,
  86.429 -                   unsigned long *store_mfn,
  86.430 -                   unsigned int console_evtchn,
  86.431 -                   unsigned long *console_mfn)
  86.432 +static int xc_linux_build_internal(int xc_handle,
  86.433 +                                   uint32_t domid,
  86.434 +                                   char *image,
  86.435 +                                   unsigned long image_size,
  86.436 +                                   struct initrd_info *initrd,
  86.437 +                                   const char *cmdline,
  86.438 +                                   const char *features,
  86.439 +                                   unsigned long flags,
  86.440 +                                   unsigned int store_evtchn,
  86.441 +                                   unsigned long *store_mfn,
  86.442 +                                   unsigned int console_evtchn,
  86.443 +                                   unsigned long *console_mfn)
  86.444  {
  86.445      dom0_op_t launch_op;
  86.446      DECLARE_DOM0_OP;
  86.447 -    int initrd_fd = -1;
  86.448 -    gzFile initrd_gfd = NULL;
  86.449      int rc, i;
  86.450      vcpu_guest_context_t st_ctxt, *ctxt = &st_ctxt;
  86.451      unsigned long nr_pages;
  86.452 -    char         *image = NULL;
  86.453 -    unsigned long image_size, initrd_size=0;
  86.454      unsigned long vstartinfo_start, vkern_entry, vstack_start;
  86.455      uint32_t      features_bitmap[XENFEAT_NR_SUBMAPS] = { 0, };
  86.456  
  86.457 @@ -1009,26 +1040,6 @@ int xc_linux_build(int xc_handle,
  86.458          goto error_out;
  86.459      }
  86.460  
  86.461 -    if ( (image = xc_read_kernel_image(image_name, &image_size)) == NULL )
  86.462 -        goto error_out;
  86.463 -
  86.464 -    if ( (ramdisk_name != NULL) && (strlen(ramdisk_name) != 0) )
  86.465 -    {
  86.466 -        if ( (initrd_fd = open(ramdisk_name, O_RDONLY)) < 0 )
  86.467 -        {
  86.468 -            PERROR("Could not open the initial ramdisk image");
  86.469 -            goto error_out;
  86.470 -        }
  86.471 -
  86.472 -        initrd_size = xc_get_filesz(initrd_fd);
  86.473 -
  86.474 -        if ( (initrd_gfd = gzdopen(initrd_fd, "rb")) == NULL )
  86.475 -        {
  86.476 -            PERROR("Could not allocate decompression state for initrd");
  86.477 -            goto error_out;
  86.478 -        }
  86.479 -    }
  86.480 -
  86.481  #ifdef VALGRIND
  86.482      memset(&st_ctxt, 0, sizeof(st_ctxt));
  86.483  #endif
  86.484 @@ -1051,7 +1062,8 @@ int xc_linux_build(int xc_handle,
  86.485      memset(ctxt, 0, sizeof(*ctxt));
  86.486  
  86.487      if ( setup_guest(xc_handle, domid, image, image_size, 
  86.488 -                     initrd_gfd, initrd_size, nr_pages, 
  86.489 +                     initrd,
  86.490 +                     nr_pages, 
  86.491                       &vstartinfo_start, &vkern_entry,
  86.492                       &vstack_start, ctxt, cmdline,
  86.493                       op.u.getdomaininfo.shared_info_frame,
  86.494 @@ -1063,12 +1075,6 @@ int xc_linux_build(int xc_handle,
  86.495          goto error_out;
  86.496      }
  86.497  
  86.498 -    if ( initrd_fd >= 0 )
  86.499 -        close(initrd_fd);
  86.500 -    if ( initrd_gfd )
  86.501 -        gzclose(initrd_gfd);
  86.502 -    free(image);
  86.503 -
  86.504  #ifdef __ia64__
  86.505      /* based on new_thread in xen/arch/ia64/domain.c */
  86.506      ctxt->flags = 0;
  86.507 @@ -1154,12 +1160,129 @@ int xc_linux_build(int xc_handle,
  86.508      return rc;
  86.509  
  86.510   error_out:
  86.511 -    if ( initrd_gfd != NULL )
  86.512 -        gzclose(initrd_gfd);
  86.513 -    else if ( initrd_fd >= 0 )
  86.514 -        close(initrd_fd);
  86.515 +    return -1;
  86.516 +}
  86.517 +
  86.518 +int xc_linux_build_mem(int xc_handle,
  86.519 +                       uint32_t domid,
  86.520 +                       const char *image_buffer,
  86.521 +                       unsigned long image_size,
  86.522 +                       const char *initrd,
  86.523 +                       unsigned long initrd_len,
  86.524 +                       const char *cmdline,
  86.525 +                       const char *features,
  86.526 +                       unsigned long flags,
  86.527 +                       unsigned int store_evtchn,
  86.528 +                       unsigned long *store_mfn,
  86.529 +                       unsigned int console_evtchn,
  86.530 +                       unsigned long *console_mfn)
  86.531 +{
  86.532 +    int            sts;
  86.533 +    char          *img_buf;
  86.534 +    unsigned long  img_len;
  86.535 +    struct initrd_info initrd_info = { .type = INITRD_none };
  86.536 +
  86.537 +    /* A kernel buffer is required */
  86.538 +    if ( (image_buffer == NULL) || (image_size == 0) )
  86.539 +    {
  86.540 +        ERROR("kernel image buffer not present");
  86.541 +        return -1;
  86.542 +    }
  86.543 +
  86.544 +    /* If it's gzipped, inflate it;  otherwise, use as is */
  86.545 +    /* xc_inflate_buffer may return the same buffer pointer if */
  86.546 +    /* the buffer is already inflated */
  86.547 +    img_buf = xc_inflate_buffer(image_buffer, image_size, &img_len);
  86.548 +    if ( img_buf == NULL )
  86.549 +    {
  86.550 +        ERROR("unable to inflate kernel image buffer");
  86.551 +        return -1;
  86.552 +    }
  86.553 +
  86.554 +    /* RAM disks are optional; if we get one, inflate it */
  86.555 +    if ( initrd != NULL )
  86.556 +    {
  86.557 +        initrd_info.type = INITRD_mem;
  86.558 +        initrd_info.u.mem_addr = xc_inflate_buffer(
  86.559 +            initrd, initrd_len, &initrd_info.len);
  86.560 +        if ( initrd_info.u.mem_addr == NULL )
  86.561 +        {
  86.562 +            ERROR("unable to inflate ram disk buffer");
  86.563 +            sts = -1;
  86.564 +            goto out;
  86.565 +        }
  86.566 +    }
  86.567 +
  86.568 +    sts = xc_linux_build_internal(xc_handle, domid, img_buf, img_len,
  86.569 +                                  &initrd_info, cmdline, features, flags,
  86.570 +                                  store_evtchn, store_mfn,
  86.571 +                                  console_evtchn, console_mfn);
  86.572 +
  86.573 + out:
  86.574 +    /* The inflation routines may pass back the same buffer so be */
  86.575 +    /* sure that we have a buffer and that it's not the one passed in. */
  86.576 +    /* Don't unnecessarily annoy/surprise/confound the caller */
  86.577 +    if ( (img_buf != NULL) && (img_buf != image_buffer) )
  86.578 +        free(img_buf);
  86.579 +    if ( (initrd_info.u.mem_addr != NULL) &&
  86.580 +         (initrd_info.u.mem_addr != initrd) )
  86.581 +        free(initrd_info.u.mem_addr);
  86.582 +
  86.583 +    return sts;
  86.584 +}
  86.585 +
  86.586 +int xc_linux_build(int xc_handle,
  86.587 +                   uint32_t domid,
  86.588 +                   const char *image_name,
  86.589 +                   const char *initrd_name,
  86.590 +                   const char *cmdline,
  86.591 +                   const char *features,
  86.592 +                   unsigned long flags,
  86.593 +                   unsigned int store_evtchn,
  86.594 +                   unsigned long *store_mfn,
  86.595 +                   unsigned int console_evtchn,
  86.596 +                   unsigned long *console_mfn)
  86.597 +{
  86.598 +    char *image = NULL;
  86.599 +    unsigned long image_size;
  86.600 +    struct initrd_info initrd_info = { .type = INITRD_none };
  86.601 +    int fd = -1, sts = -1;
  86.602 +
  86.603 +    if ( (image_name == NULL) ||
  86.604 +         ((image = xc_read_image(image_name, &image_size)) == NULL ))
  86.605 +        return -1;
  86.606 +
  86.607 +    if ( (initrd_name != NULL) && (strlen(initrd_name) != 0) )
  86.608 +    {
  86.609 +        initrd_info.type = INITRD_file;
  86.610 +
  86.611 +        if ( (fd = open(initrd_name, O_RDONLY)) < 0 )
  86.612 +        {
  86.613 +            PERROR("Could not open the initial ramdisk image");
  86.614 +            goto error_out;
  86.615 +        }
  86.616 +
  86.617 +        initrd_info.len = xc_get_filesz(fd);
  86.618 +        if ( (initrd_info.u.file_handle = gzdopen(fd, "rb")) == NULL )
  86.619 +        {
  86.620 +            PERROR("Could not allocate decompression state for initrd");
  86.621 +            goto error_out;
  86.622 +        }
  86.623 +    }
  86.624 +
  86.625 +    sts = xc_linux_build_internal(xc_handle, domid, image, image_size,
  86.626 +                                  &initrd_info, cmdline, features, flags,
  86.627 +                                  store_evtchn, store_mfn,
  86.628 +                                  console_evtchn, console_mfn);
  86.629 +
  86.630 + error_out:
  86.631      free(image);
  86.632 -    return -1;
  86.633 +    if ( fd >= 0 )
  86.634 +        close(fd);
  86.635 +    if ( initrd_info.u.file_handle )
  86.636 +        gzclose(initrd_info.u.file_handle);
  86.637 +
  86.638 +    return sts;
  86.639  }
  86.640  
  86.641  /*
    87.1 --- a/tools/libxc/xc_load_aout9.c	Tue Mar 14 13:10:21 2006 -0700
    87.2 +++ b/tools/libxc/xc_load_aout9.c	Tue Mar 14 13:50:35 2006 -0700
    87.3 @@ -12,20 +12,19 @@
    87.4  #error "Unsupported architecture"
    87.5  #endif
    87.6  
    87.7 -
    87.8  #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
    87.9  #define KZERO             0x80000000
   87.10  #define KOFFSET(_p)       ((_p)&~KZERO)
   87.11  
   87.12 -static int parseaout9image(char *, unsigned long, struct domain_setup_info *);
   87.13 -static int loadaout9image(char *, unsigned long, int, uint32_t, unsigned long *, struct domain_setup_info *);
   87.14 -static void copyout(int, uint32_t, unsigned long *, unsigned long, void *, int);
   87.15 -struct Exec *get_header(char *, unsigned long, struct Exec *);
   87.16 +static int parseaout9image(const char *, unsigned long, struct domain_setup_info *);
   87.17 +static int loadaout9image(const char *, unsigned long, int, uint32_t, unsigned long *, struct domain_setup_info *);
   87.18 +static void copyout(int, uint32_t, unsigned long *, unsigned long, const char *, int);
   87.19 +struct Exec *get_header(const char *, unsigned long, struct Exec *);
   87.20  
   87.21  
   87.22  int 
   87.23  probe_aout9(
   87.24 -    char *image,
   87.25 +    const char *image,
   87.26      unsigned long image_size,
   87.27      struct load_funcs *load_funcs)
   87.28  {
   87.29 @@ -43,7 +42,7 @@ probe_aout9(
   87.30  
   87.31  static int 
   87.32  parseaout9image(
   87.33 -    char *image,
   87.34 +    const char *image,
   87.35      unsigned long image_size,
   87.36      struct domain_setup_info *dsi)
   87.37  {
   87.38 @@ -77,7 +76,7 @@ parseaout9image(
   87.39  
   87.40  static int 
   87.41  loadaout9image(
   87.42 -    char *image,
   87.43 +    const char *image,
   87.44      unsigned long image_size,
   87.45      int xch, uint32_t dom,
   87.46      unsigned long *parray,
   87.47 @@ -111,7 +110,7 @@ copyout(
   87.48      int xch, uint32_t dom,
   87.49      unsigned long *parray,
   87.50      unsigned long addr,
   87.51 -    void *buf,
   87.52 +    const char *buf,
   87.53      int sz)
   87.54  {
   87.55      unsigned long pgoff, chunksz, off;
   87.56 @@ -143,7 +142,7 @@ copyout(
   87.57   */
   87.58  struct Exec *
   87.59  get_header(
   87.60 -    char *image,
   87.61 +    const char *image,
   87.62      unsigned long image_size,
   87.63      struct Exec *ehdr)
   87.64  {
    88.1 --- a/tools/libxc/xc_load_bin.c	Tue Mar 14 13:10:21 2006 -0700
    88.2 +++ b/tools/libxc/xc_load_bin.c	Tue Mar 14 13:50:35 2006 -0700
    88.3 @@ -99,23 +99,22 @@ struct xen_bin_image_table
    88.4  #define FLAGS_REQUIRED XEN_REACTOS_FLAG_ADDRSVALID
    88.5  
    88.6  static struct xen_bin_image_table *
    88.7 -findtable(char *image, unsigned long image_size);
    88.8 +findtable(const char *image, unsigned long image_size);
    88.9  static int
   88.10  parsebinimage(
   88.11 -    char *image, unsigned long image_size, struct domain_setup_info *dsi);
   88.12 +    const char *image, unsigned long image_size,
   88.13 +    struct domain_setup_info *dsi);
   88.14  static int
   88.15  loadbinimage(
   88.16 -    char *image, unsigned long image_size, int xch, uint32_t dom,
   88.17 +    const char *image, unsigned long image_size, int xch, uint32_t dom,
   88.18      unsigned long *parray, struct domain_setup_info *dsi);
   88.19  
   88.20 -int probe_bin(char *image,
   88.21 +int probe_bin(const char *image,
   88.22                unsigned long image_size,
   88.23                struct load_funcs *load_funcs)
   88.24  {
   88.25 -    if ( NULL == findtable(image, image_size) )
   88.26 -    {
   88.27 +    if ( findtable(image, image_size) == NULL )
   88.28          return -EINVAL;
   88.29 -    }
   88.30  
   88.31      load_funcs->parseimage = parsebinimage;
   88.32      load_funcs->loadimage = loadbinimage;
   88.33 @@ -124,7 +123,7 @@ int probe_bin(char *image,
   88.34  }
   88.35  
   88.36  static struct xen_bin_image_table *
   88.37 -findtable(char *image, unsigned long image_size)
   88.38 +findtable(const char *image, unsigned long image_size)
   88.39  {
   88.40      struct xen_bin_image_table *table;
   88.41      unsigned long *probe_ptr;
   88.42 @@ -133,15 +132,12 @@ findtable(char *image, unsigned long ima
   88.43  
   88.44      /* Don't go outside the image */
   88.45      if ( image_size < sizeof(struct xen_bin_image_table) )
   88.46 -    {
   88.47          return NULL;
   88.48 -    }
   88.49 +
   88.50      probe_count = image_size;
   88.51      /* Restrict to first 8k */
   88.52 -    if ( 8192 < probe_count )
   88.53 -    {
   88.54 +    if ( probe_count > 8192 )
   88.55          probe_count = 8192;
   88.56 -    }
   88.57      probe_count = (probe_count - sizeof(struct xen_bin_image_table)) /
   88.58                    sizeof(unsigned long);
   88.59  
   88.60 @@ -165,7 +161,7 @@ findtable(char *image, unsigned long ima
   88.61      return NULL;
   88.62  }
   88.63  
   88.64 -static int parsebinimage(char *image, 
   88.65 +static int parsebinimage(const char *image, 
   88.66                           unsigned long image_size,
   88.67                           struct domain_setup_info *dsi)
   88.68  {
   88.69 @@ -238,7 +234,7 @@ static int parsebinimage(char *image,
   88.70  
   88.71  static int
   88.72  loadbinimage(
   88.73 -    char *image, unsigned long image_size, int xch, uint32_t dom,
   88.74 +    const char *image, unsigned long image_size, int xch, uint32_t dom,
   88.75      unsigned long *parray, struct domain_setup_info *dsi)
   88.76  {
   88.77      unsigned long size;
    89.1 --- a/tools/libxc/xc_load_elf.c	Tue Mar 14 13:10:21 2006 -0700
    89.2 +++ b/tools/libxc/xc_load_elf.c	Tue Mar 14 13:50:35 2006 -0700
    89.3 @@ -19,26 +19,25 @@
    89.4  
    89.5  static int
    89.6  parseelfimage(
    89.7 -    char *image, unsigned long image_size, struct domain_setup_info *dsi);
    89.8 +    const char *image, unsigned long image_size,
    89.9 +    struct domain_setup_info *dsi);
   89.10  static int
   89.11  loadelfimage(
   89.12 -    char *image, unsigned long image_size, int xch, uint32_t dom,
   89.13 +    const char *image, unsigned long image_size, int xch, uint32_t dom,
   89.14      unsigned long *parray, struct domain_setup_info *dsi);
   89.15  static int
   89.16  loadelfsymtab(
   89.17 -    char *image, int xch, uint32_t dom, unsigned long *parray,
   89.18 +    const char *image, int xch, uint32_t dom, unsigned long *parray,
   89.19      struct domain_setup_info *dsi);
   89.20  
   89.21 -int probe_elf(char *image,
   89.22 +int probe_elf(const char *image,
   89.23                unsigned long image_size,
   89.24                struct load_funcs *load_funcs)
   89.25  {
   89.26      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
   89.27  
   89.28      if ( !IS_ELF(*ehdr) )
   89.29 -    {
   89.30          return -EINVAL;
   89.31 -    }
   89.32  
   89.33      load_funcs->parseimage = parseelfimage;
   89.34      load_funcs->loadimage = loadelfimage;
   89.35 @@ -52,7 +51,7 @@ static inline int is_loadable_phdr(Elf_P
   89.36              ((phdr->p_flags & (PF_W|PF_X)) != 0));
   89.37  }
   89.38  
   89.39 -static int parseelfimage(char *image, 
   89.40 +static int parseelfimage(const char *image, 
   89.41                           unsigned long elfsize,
   89.42                           struct domain_setup_info *dsi)
   89.43  {
   89.44 @@ -60,7 +59,8 @@ static int parseelfimage(char *image,
   89.45      Elf_Phdr *phdr;
   89.46      Elf_Shdr *shdr;
   89.47      unsigned long kernstart = ~0UL, kernend=0UL;
   89.48 -    char *shstrtab, *guestinfo=NULL, *p;
   89.49 +    const char *shstrtab;
   89.50 +    char *guestinfo=NULL, *p;
   89.51      int h;
   89.52  
   89.53      if ( !IS_ELF(*ehdr) )
   89.54 @@ -98,7 +98,7 @@ static int parseelfimage(char *image,
   89.55          if ( strcmp(&shstrtab[shdr->sh_name], "__xen_guest") != 0 )
   89.56              continue;
   89.57  
   89.58 -        guestinfo = image + shdr->sh_offset;
   89.59 +        guestinfo = (char *)image + shdr->sh_offset;
   89.60  
   89.61          if ( (strstr(guestinfo, "LOADER=generic") == NULL) &&
   89.62               (strstr(guestinfo, "GUEST_OS=linux") == NULL) )
   89.63 @@ -171,7 +171,7 @@ static int parseelfimage(char *image,
   89.64  
   89.65  static int
   89.66  loadelfimage(
   89.67 -    char *image, unsigned long elfsize, int xch, uint32_t dom,
   89.68 +    const char *image, unsigned long elfsize, int xch, uint32_t dom,
   89.69      unsigned long *parray, struct domain_setup_info *dsi)
   89.70  {
   89.71      Elf_Ehdr *ehdr = (Elf_Ehdr *)image;
   89.72 @@ -222,7 +222,7 @@ loadelfimage(
   89.73  
   89.74  static int
   89.75  loadelfsymtab(
   89.76 -    char *image, int xch, uint32_t dom, unsigned long *parray,
   89.77 +    const char *image, int xch, uint32_t dom, unsigned long *parray,
   89.78      struct domain_setup_info *dsi)
   89.79  {
   89.80      Elf_Ehdr *ehdr = (Elf_Ehdr *)image, *sym_ehdr;
   89.81 @@ -271,8 +271,9 @@ loadelfsymtab(
   89.82               (shdr[h].sh_type == SHT_SYMTAB) )
   89.83          {
   89.84              if ( parray != NULL )
   89.85 -                xc_map_memcpy(maxva, image + shdr[h].sh_offset, shdr[h].sh_size,
   89.86 -                           xch, dom, parray, dsi->v_start);
   89.87 +                xc_map_memcpy(maxva, image + shdr[h].sh_offset,
   89.88 +                              shdr[h].sh_size,
   89.89 +                              xch, dom, parray, dsi->v_start);
   89.90  
   89.91              /* Mangled to be based on ELF header location. */
   89.92              shdr[h].sh_offset = maxva - dsi->symtab_addr;
    90.1 --- a/tools/libxc/xc_private.c	Tue Mar 14 13:10:21 2006 -0700
    90.2 +++ b/tools/libxc/xc_private.c	Tue Mar 14 13:50:35 2006 -0700
    90.3 @@ -231,8 +231,8 @@ int xc_memory_op(int xc_handle,
    90.4              goto out1;
    90.5          }
    90.6          break;
    90.7 -    case XENMEM_reserved_phys_area:
    90.8 -        if ( mlock(arg, sizeof(struct xen_reserved_phys_area)) )
    90.9 +    case XENMEM_add_to_physmap:
   90.10 +        if ( mlock(arg, sizeof(struct xen_add_to_physmap)) )
   90.11          {
   90.12              PERROR("Could not mlock");
   90.13              goto out1;
   90.14 @@ -277,8 +277,8 @@ int xc_memory_op(int xc_handle,
   90.15          safe_munlock(xmml->extent_start,
   90.16                       xmml->max_extents * sizeof(unsigned long));
   90.17          break;
   90.18 -    case XENMEM_reserved_phys_area:
   90.19 -        safe_munlock(arg, sizeof(struct xen_reserved_phys_area));
   90.20 +    case XENMEM_add_to_physmap:
   90.21 +        safe_munlock(arg, sizeof(struct xen_add_to_physmap));
   90.22          break;
   90.23      case XENMEM_translate_gpfn_list:
   90.24              safe_munlock(trans->mfn_list, trans->nr_gpfns * sizeof(long));
   90.25 @@ -364,7 +364,7 @@ long xc_get_tot_pages(int xc_handle, uin
   90.26  int xc_copy_to_domain_page(int xc_handle,
   90.27                             uint32_t domid,
   90.28                             unsigned long dst_pfn, 
   90.29 -                           void *src_page)
   90.30 +                           const char *src_page)
   90.31  {
   90.32      void *vaddr = xc_map_foreign_range(
   90.33          xc_handle, domid, PAGE_SIZE, PROT_WRITE, dst_pfn);
   90.34 @@ -410,7 +410,7 @@ unsigned long xc_get_filesz(int fd)
   90.35      return sz;
   90.36  }
   90.37  
   90.38 -void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
   90.39 +void xc_map_memcpy(unsigned long dst, const char *src, unsigned long size,
   90.40                     int xch, uint32_t dom, unsigned long *parray,
   90.41                     unsigned long vstart)
   90.42  {
    91.1 --- a/tools/libxc/xc_ptrace.c	Tue Mar 14 13:10:21 2006 -0700
    91.2 +++ b/tools/libxc/xc_ptrace.c	Tue Mar 14 13:50:35 2006 -0700
    91.3 @@ -1,6 +1,5 @@
    91.4  #define XC_PTRACE_PRIVATE
    91.5  
    91.6 -
    91.7  #include <sys/ptrace.h>
    91.8  #include <sys/wait.h>
    91.9  #include <time.h>
   91.10 @@ -9,6 +8,36 @@
   91.11  #include "xg_private.h"
   91.12  #include "xc_ptrace.h"
   91.13  
   91.14 +#ifdef DEBUG
   91.15 +static char *ptrace_names[] = {
   91.16 +    "PTRACE_TRACEME",
   91.17 +    "PTRACE_PEEKTEXT",
   91.18 +    "PTRACE_PEEKDATA",
   91.19 +    "PTRACE_PEEKUSER",
   91.20 +    "PTRACE_POKETEXT",
   91.21 +    "PTRACE_POKEDATA",
   91.22 +    "PTRACE_POKEUSER",
   91.23 +    "PTRACE_CONT",
   91.24 +    "PTRACE_KILL",
   91.25 +    "PTRACE_SINGLESTEP",
   91.26 +    "PTRACE_INVALID",
   91.27 +    "PTRACE_INVALID",
   91.28 +    "PTRACE_GETREGS",
   91.29 +    "PTRACE_SETREGS",
   91.30 +    "PTRACE_GETFPREGS",
   91.31 +    "PTRACE_SETFPREGS",
   91.32 +    "PTRACE_ATTACH",
   91.33 +    "PTRACE_DETACH",
   91.34 +    "PTRACE_GETFPXREGS",
   91.35 +    "PTRACE_SETFPXREGS",
   91.36 +    "PTRACE_INVALID",
   91.37 +    "PTRACE_INVALID",
   91.38 +    "PTRACE_INVALID",
   91.39 +    "PTRACE_INVALID",
   91.40 +    "PTRACE_SYSCALL",
   91.41 +};
   91.42 +#endif
   91.43 +
   91.44  /* XXX application state */
   91.45  static long                     nr_pages = 0;
   91.46  static unsigned long           *page_array = NULL;
    92.1 --- a/tools/libxc/xc_ptrace.h	Tue Mar 14 13:10:21 2006 -0700
    92.2 +++ b/tools/libxc/xc_ptrace.h	Tue Mar 14 13:50:35 2006 -0700
    92.3 @@ -10,8 +10,6 @@
    92.4  #define PDRSHIFT        22
    92.5  #define PSL_T  0x00000100 /* trace enable bit */
    92.6  
    92.7 -extern const char const * ptrace_names[];
    92.8 -
    92.9  struct gdb_regs {
   92.10      long ebx; /* 0 */
   92.11      long ecx; /* 4 */
    93.1 --- a/tools/libxc/xenctrl.h	Tue Mar 14 13:10:21 2006 -0700
    93.2 +++ b/tools/libxc/xenctrl.h	Tue Mar 14 13:50:35 2006 -0700
    93.3 @@ -139,10 +139,28 @@ int xc_domain_create(int xc_handle,
    93.4                       uint32_t *pdomid);
    93.5  
    93.6  
    93.7 +/* Functions to produce a dump of a given domain
    93.8 + *  xc_domain_dumpcore - produces a dump to a specified file
    93.9 + *  xc_domain_dumpcore_via_callback - produces a dump, using a specified
   93.10 + *                                    callback function
   93.11 + */
   93.12  int xc_domain_dumpcore(int xc_handle, 
   93.13                         uint32_t domid,
   93.14                         const char *corename);
   93.15  
   93.16 +/* Define the callback function type for xc_domain_dumpcore_via_callback.
   93.17 + *
   93.18 + * This function is called by the coredump code for every "write",
   93.19 + * and passes an opaque object for the use of the function and
   93.20 + * created by the caller of xc_domain_dumpcore_via_callback.
   93.21 + */
   93.22 +typedef int (dumpcore_rtn_t)(void *arg, char *buffer, unsigned int length);
   93.23 +
   93.24 +int xc_domain_dumpcore_via_callback(int xc_handle, 
   93.25 +                                    uint32_t domid,
   93.26 +                                    void *arg,
   93.27 +                                    dumpcore_rtn_t dump_rtn);
   93.28 +
   93.29  /*
   93.30   * This function sets the maximum number of vcpus that a domain may create.
   93.31   *
   93.32 @@ -372,13 +390,13 @@ int xc_domain_memory_increase_reservatio
   93.33                                            unsigned long nr_extents,
   93.34                                            unsigned int extent_order,
   93.35                                            unsigned int address_bits,
   93.36 -					  unsigned long *extent_start);
   93.37 +                                          unsigned long *extent_start);
   93.38  
   93.39  int xc_domain_memory_decrease_reservation(int xc_handle,
   93.40                                            uint32_t domid, 
   93.41                                            unsigned long nr_extents,
   93.42                                            unsigned int extent_order,
   93.43 -					  unsigned long *extent_start);
   93.44 +                                          unsigned long *extent_start);
   93.45  
   93.46  int xc_domain_memory_populate_physmap(int xc_handle,
   93.47                                        uint32_t domid,
   93.48 @@ -411,7 +429,7 @@ int xc_domain_iomem_permission(int xc_ha
   93.49                                 uint8_t allow_access);
   93.50  
   93.51  unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, 
   93.52 -				    unsigned long mfn);
   93.53 +                                    unsigned long mfn);
   93.54  
   93.55  typedef dom0_perfc_desc_t xc_perfc_desc_t;
   93.56  /* IMPORTANT: The caller is responsible for mlock()'ing the @desc array. */
   93.57 @@ -457,7 +475,7 @@ void *xc_map_foreign_batch(int xc_handle
   93.58   * @parm virt the virtual address to translate
   93.59   */
   93.60  unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
   93.61 -					   int vcpu, unsigned long long virt);
   93.62 +                                           int vcpu, unsigned long long virt);
   93.63  
   93.64  int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf, 
   93.65                      unsigned long max_pfns);
   93.66 @@ -467,7 +485,7 @@ int xc_ia64_get_pfn_list(int xc_handle, 
   93.67                           unsigned int start_page, unsigned int nr_pages);
   93.68  
   93.69  int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
   93.70 -			   unsigned long dst_pfn, void *src_page);
   93.71 +                           unsigned long dst_pfn, const char *src_page);
   93.72  
   93.73  int xc_clear_domain_page(int xc_handle, uint32_t domid,
   93.74                           unsigned long dst_pfn);
   93.75 @@ -478,7 +496,7 @@ int xc_ia64_copy_to_domain_pages(int xc_
   93.76  long xc_get_max_pages(int xc_handle, uint32_t domid);
   93.77  
   93.78  int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
   93.79 -		 domid_t dom);
   93.80 +                 domid_t dom);
   93.81  
   93.82  int xc_memory_op(int xc_handle, int cmd, void *arg);
   93.83  
    94.1 --- a/tools/libxc/xenguest.h	Tue Mar 14 13:10:21 2006 -0700
    94.2 +++ b/tools/libxc/xenguest.h	Tue Mar 14 13:50:35 2006 -0700
    94.3 @@ -42,6 +42,22 @@ int xc_linux_restore(int xc_handle, int 
    94.4                       unsigned long *store_mfn, unsigned int console_evtchn,
    94.5                       unsigned long *console_mfn);
    94.6  
    94.7 +/**
    94.8 + * This function will create a domain for a paravirtualized Linux
    94.9 + * using file names pointing to kernel and ramdisk
   94.10 + *
   94.11 + * @parm xc_handle a handle to an open hypervisor interface
   94.12 + * @parm domid the id of the domain
   94.13 + * @param image_name name of the kernel image file
   94.14 + * @param ramdisk_name name of the ramdisk image file
   94.15 + * @parm cmdline command line string
   94.16 + * @parm flags domain creation flags
   94.17 + * @parm store_evtchn the store event channel for this domain to use
   94.18 + * @parm store_mfn returned with the mfn of the store page
   94.19 + * @parm console_evtchn the console event channel for this domain to use
   94.20 + * @parm conole_mfn returned with the mfn of the console page
   94.21 + * @return 0 on success, -1 on failure
   94.22 + */
   94.23  int xc_linux_build(int xc_handle,
   94.24                     uint32_t domid,
   94.25                     const char *image_name,
   94.26 @@ -54,6 +70,38 @@ int xc_linux_build(int xc_handle,
   94.27                     unsigned int console_evtchn,
   94.28                     unsigned long *console_mfn);
   94.29  
   94.30 +/**
   94.31 + * This function will create a domain for a paravirtualized Linux
   94.32 + * using buffers for kernel and initrd
   94.33 + *
   94.34 + * @param xc_handle a handle to an open hypervisor interface
   94.35 + * @param domid the id of the domain
   94.36 + * @param image_buffer buffer containing kernel image
   94.37 + * @param image_size size of the kernel image buffer
   94.38 + * @param initrd_buffer name of the ramdisk image file
   94.39 + * @param initrd_size size of the ramdisk buffer
   94.40 + * @param cmdline command line string
   94.41 + * @param flags domain creation flags
   94.42 + * @param store_evtchn the store event channel for this domain to use
   94.43 + * @param store_mfn returned with the mfn of the store page
   94.44 + * @param console_evtchn the console event channel for this domain to use
   94.45 + * @param conole_mfn returned with the mfn of the console page
   94.46 + * @return 0 on success, -1 on failure
   94.47 + */
   94.48 +int xc_linux_build_mem(int xc_handle,
   94.49 +                       uint32_t domid,
   94.50 +                       const char *image_buffer,
   94.51 +                       unsigned long image_size,
   94.52 +                       const char *initrd_buffer,
   94.53 +                       unsigned long initrd_size,
   94.54 +                       const char *cmdline,
   94.55 +                       const char *features,
   94.56 +                       unsigned long flags,
   94.57 +                       unsigned int store_evtchn,
   94.58 +                       unsigned long *store_mfn,
   94.59 +                       unsigned int console_evtchn,
   94.60 +                       unsigned long *console_mfn);
   94.61 +
   94.62  int xc_hvm_build(int xc_handle,
   94.63                   uint32_t domid,
   94.64                   int memsize,
   94.65 @@ -65,4 +113,16 @@ int xc_hvm_build(int xc_handle,
   94.66                   unsigned int store_evtchn,
   94.67                   unsigned long *store_mfn);
   94.68  
   94.69 -#endif // XENGUEST_H
   94.70 +int xc_hvm_build_mem(int xc_handle,
   94.71 +                     uint32_t domid,
   94.72 +                     int memsize,
   94.73 +                     const char *image_buffer,
   94.74 +                     unsigned long image_size,
   94.75 +                     unsigned int vcpus,
   94.76 +                     unsigned int pae,
   94.77 +                     unsigned int acpi,
   94.78 +                     unsigned int apic,
   94.79 +                     unsigned int store_evtchn,
   94.80 +                     unsigned long *store_mfn);
   94.81 +
   94.82 +#endif /* XENGUEST_H */
    95.1 --- a/tools/libxc/xg_private.c	Tue Mar 14 13:10:21 2006 -0700
    95.2 +++ b/tools/libxc/xg_private.c	Tue Mar 14 13:50:35 2006 -0700
    95.3 @@ -10,15 +10,15 @@
    95.4  
    95.5  #include "xg_private.h"
    95.6  
    95.7 -char *xc_read_kernel_image(const char *filename, unsigned long *size)
    95.8 +char *xc_read_image(const char *filename, unsigned long *size)
    95.9  {
   95.10      int kernel_fd = -1;
   95.11      gzFile kernel_gfd = NULL;
   95.12      char *image = NULL;
   95.13      unsigned int bytes;
   95.14  
   95.15 -    if ( filename == NULL )
   95.16 -        goto out;
   95.17 +    if ( (filename == NULL) || (size == NULL) )
   95.18 +        return NULL;
   95.19  
   95.20      if ( (kernel_fd = open(filename, O_RDONLY)) < 0 )
   95.21      {
   95.22 @@ -60,6 +60,62 @@ char *xc_read_kernel_image(const char *f
   95.23      return image;
   95.24  }
   95.25  
   95.26 +char *xc_inflate_buffer(const char *in_buf, unsigned long in_size,
   95.27 +                        unsigned long *out_size)
   95.28 +{
   95.29 +    int           sts;
   95.30 +    z_stream      zStream;
   95.31 +    unsigned long out_len;
   95.32 +    char         *out_buf;
   95.33 +
   95.34 +    /* Not compressed? Then return the original buffer. */
   95.35 +    if ( ((unsigned char)in_buf[0] != 0x1F) ||
   95.36 +         ((unsigned char)in_buf[1] != 0x8B) )
   95.37 +    {
   95.38 +        if ( out_size != NULL )
   95.39 +            *out_size = in_size;
   95.40 +        return (char *)in_buf;
   95.41 +    }
   95.42 +
   95.43 +    out_len = in_buf[in_size-4] +
   95.44 +        (256 * (in_buf[in_size-3] +
   95.45 +                (256 * (in_buf[in_size-2] +
   95.46 +                        (256 * in_buf[in_size-1])))));
   95.47 +    bzero(&zStream, sizeof(zStream));
   95.48 +    out_buf = malloc(out_len + 16);        /* Leave a little extra space */
   95.49 +    if ( out_buf == NULL )
   95.50 +    {
   95.51 +        ERROR("Error mallocing buffer\n");
   95.52 +        return NULL;
   95.53 +    }
   95.54 +
   95.55 +    zStream.next_in = (unsigned char *)in_buf;
   95.56 +    zStream.avail_in = in_size;
   95.57 +    zStream.next_out = (unsigned char *)out_buf;
   95.58 +    zStream.avail_out = out_len+16;
   95.59 +    sts = inflateInit2(&zStream, (MAX_WBITS+32)); /* +32 means "handle gzip" */
   95.60 +    if ( sts != Z_OK )
   95.61 +    {
   95.62 +        ERROR("inflateInit failed, sts %d\n", sts);
   95.63 +        free(out_buf);
   95.64 +        return NULL;
   95.65 +    }
   95.66 +
   95.67 +    /* Inflate in one pass/call */
   95.68 +    sts = inflate(&zStream, Z_FINISH);
   95.69 +    if ( sts != Z_STREAM_END )
   95.70 +    {
   95.71 +        ERROR("inflate failed, sts %d\n", sts);
   95.72 +        free(out_buf);
   95.73 +        return NULL;
   95.74 +    }
   95.75 +
   95.76 +    if ( out_size != NULL )
   95.77 +        *out_size = out_len;
   95.78 +
   95.79 +    return out_buf;
   95.80 +}
   95.81 +
   95.82  /*******************/
   95.83  
   95.84  int pin_table(
   95.85 @@ -77,7 +133,7 @@ int pin_table(
   95.86  }
   95.87  
   95.88  /* This is shared between save and restore, and may generally be useful. */
   95.89 -unsigned long csum_page (void * page)
   95.90 +unsigned long csum_page(void *page)
   95.91  {
   95.92      int i;
   95.93      unsigned long *p = page;
    96.1 --- a/tools/libxc/xg_private.h	Tue Mar 14 13:10:21 2006 -0700
    96.2 +++ b/tools/libxc/xg_private.h	Tue Mar 14 13:50:35 2006 -0700
    96.3 @@ -26,7 +26,11 @@
    96.4  #endif
    96.5  
    96.6  
    96.7 -char *xc_read_kernel_image(const char *filename, unsigned long *size);
    96.8 +char *xc_read_image(const char *filename, unsigned long *size);
    96.9 +char *xc_inflate_buffer(const char *in_buf,
   96.10 +                        unsigned long in_size,
   96.11 +                        unsigned long *out_size);
   96.12 +
   96.13  unsigned long csum_page (void * page);
   96.14  
   96.15  #define _PAGE_PRESENT   0x001
   96.16 @@ -89,7 +93,7 @@ typedef unsigned long l4_pgentry_t;
   96.17  #define l2_table_offset_pae(_a) \
   96.18    (((_a) >> L2_PAGETABLE_SHIFT_PAE) & (L2_PAGETABLE_ENTRIES_PAE - 1))
   96.19  #define l3_table_offset_pae(_a) \
   96.20 -	(((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
   96.21 +  (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
   96.22  
   96.23  #if defined(__i386__)
   96.24  #define l1_table_offset(_a) \
   96.25 @@ -102,9 +106,9 @@ typedef unsigned long l4_pgentry_t;
   96.26  #define l2_table_offset(_a) \
   96.27    (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
   96.28  #define l3_table_offset(_a) \
   96.29 -	(((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   96.30 +  (((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
   96.31  #define l4_table_offset(_a) \
   96.32 -	(((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
   96.33 +  (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
   96.34  #endif
   96.35  
   96.36  #define ERROR(_m, _a...)                                \
   96.37 @@ -141,11 +145,12 @@ struct domain_setup_info
   96.38      char *xen_guest_string;
   96.39  };
   96.40  
   96.41 -typedef int (*parseimagefunc)(char *image, unsigned long image_size,
   96.42 -			      struct domain_setup_info *dsi);
   96.43 -typedef int (*loadimagefunc)(char *image, unsigned long image_size, int xch,
   96.44 -			     uint32_t dom, unsigned long *parray,
   96.45 -			     struct domain_setup_info *dsi);
   96.46 +typedef int (*parseimagefunc)(const char *image, unsigned long image_size,
   96.47 +                              struct domain_setup_info *dsi);
   96.48 +typedef int (*loadimagefunc)(const char *image, unsigned long image_size,
   96.49 +                             int xch,
   96.50 +                             uint32_t dom, unsigned long *parray,
   96.51 +                             struct domain_setup_info *dsi);
   96.52  
   96.53  struct load_funcs
   96.54  {
   96.55 @@ -167,21 +172,24 @@ typedef struct mfn_mapper {
   96.56  } mfn_mapper_t;
   96.57  
   96.58  int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
   96.59 -                            unsigned long dst_pfn, void *src_page);
   96.60 +                            unsigned long dst_pfn, const char *src_page);
   96.61  
   96.62  unsigned long xc_get_filesz(int fd);
   96.63  
   96.64 -void xc_map_memcpy(unsigned long dst, char *src, unsigned long size,
   96.65 +void xc_map_memcpy(unsigned long dst, const char *src, unsigned long size,
   96.66                     int xch, uint32_t dom, unsigned long *parray,
   96.67                     unsigned long vstart);
   96.68  
   96.69  int pin_table(int xc_handle, unsigned int type, unsigned long mfn,
   96.70 -	      domid_t dom);
   96.71 +              domid_t dom);
   96.72  
   96.73  /* image loading */
   96.74 -int probe_elf(char *image, unsigned long image_size, struct load_funcs *funcs);
   96.75 -int probe_bin(char *image, unsigned long image_size, struct load_funcs *funcs);
   96.76 -int probe_aout9(char *image, unsigned long image_size, struct load_funcs *funcs);
   96.77 +int probe_elf(const char *image, unsigned long image_size,
   96.78 +              struct load_funcs *funcs);
   96.79 +int probe_bin(const char *image, unsigned long image_size,
   96.80 +              struct load_funcs *funcs);
   96.81 +int probe_aout9(const char *image, unsigned long image_size,
   96.82 +                struct load_funcs *funcs);
   96.83  
   96.84  #endif
   96.85  
    97.1 --- a/tools/misc/Makefile	Tue Mar 14 13:10:21 2006 -0700
    97.2 +++ b/tools/misc/Makefile	Tue Mar 14 13:50:35 2006 -0700
    97.3 @@ -5,7 +5,7 @@ INSTALL_DIR	= $(INSTALL) -d -m0755
    97.4  XEN_ROOT=../..
    97.5  include $(XEN_ROOT)/tools/Rules.mk
    97.6  
    97.7 -CFLAGS   += -Wall -Werror -O3 
    97.8 +CFLAGS   += -Werror
    97.9  
   97.10  INCLUDES += -I $(XEN_XC)
   97.11  INCLUDES += -I $(XEN_LIBXC)
    98.1 --- a/tools/misc/cpuperf/Makefile	Tue Mar 14 13:10:21 2006 -0700
    98.2 +++ b/tools/misc/cpuperf/Makefile	Tue Mar 14 13:50:35 2006 -0700
    98.3 @@ -17,8 +17,6 @@ INSTALL_DIR	= $(INSTALL) -d -m0755
    98.4  XEN_ROOT=../../..
    98.5  include $(XEN_ROOT)/tools/Rules.mk
    98.6  
    98.7 -CFLAGS      += -Wall -O3 
    98.8 -
    98.9  HDRS         = $(wildcard *.h)
   98.10  SRCS         = $(wildcard *.c)
   98.11  OBJS         = $(patsubst %.c,%.o,$(SRCS))
    99.1 --- a/tools/misc/cpuperf/cpuperf_xeno.h	Tue Mar 14 13:10:21 2006 -0700
    99.2 +++ b/tools/misc/cpuperf/cpuperf_xeno.h	Tue Mar 14 13:50:35 2006 -0700
    99.3 @@ -13,7 +13,7 @@
    99.4  
    99.5  static int xc_handle;
    99.6  
    99.7 -void xen_init()
    99.8 +void xen_init(void)
    99.9  {
   99.10      if ( (xc_handle = xc_interface_open()) == -1 )
   99.11      {
   99.12 @@ -24,12 +24,12 @@ void xen_init()
   99.13  
   99.14  }
   99.15  
   99.16 -void dom0_wrmsr( int cpu_mask, int msr, unsigned int low, unsigned int high )
   99.17 +void dom0_wrmsr(int cpu_mask, int msr, unsigned int low, unsigned int high)
   99.18  {
   99.19      xc_msr_write (xc_handle, cpu_mask, msr, low, high);
   99.20  }
   99.21  
   99.22 -unsigned long long dom0_rdmsr( int cpu_mask, int msr )
   99.23 +unsigned long long dom0_rdmsr(int cpu_mask, int msr)
   99.24  {
   99.25      return xc_msr_read(xc_handle, cpu_mask, msr);
   99.26  }
   100.1 --- a/tools/misc/lomount/Makefile	Tue Mar 14 13:10:21 2006 -0700
   100.2 +++ b/tools/misc/lomount/Makefile	Tue Mar 14 13:50:35 2006 -0700
   100.3 @@ -6,7 +6,7 @@ INSTALL_DATA	= $(INSTALL) -m0644
   100.4  XEN_ROOT=../../..
   100.5  include $(XEN_ROOT)/tools/Rules.mk
   100.6  
   100.7 -CFLAGS  += -Wall -Werror -O3
   100.8 +CFLAGS  += -Werror
   100.9  
  100.10  HDRS     = $(wildcard *.h)
  100.11  OBJS     = $(patsubst %.c,%.o,$(wildcard *.c))
   101.1 --- a/tools/misc/lomount/lomount.c	Tue Mar 14 13:10:21 2006 -0700
   101.2 +++ b/tools/misc/lomount/lomount.c	Tue Mar 14 13:50:35 2006 -0700
   101.3 @@ -195,7 +195,7 @@ done:
   101.4  	return fail;
   101.5  }
   101.6  
   101.7 -void usage()
   101.8 +void usage(void)
   101.9  {
  101.10  	fprintf(stderr, "You must specify at least -diskimage and -partition.\n");
  101.11  	fprintf(stderr, "All other arguments are passed through to 'mount'.\n");
   102.1 --- a/tools/misc/mbootpack/Makefile	Tue Mar 14 13:10:21 2006 -0700
   102.2 +++ b/tools/misc/mbootpack/Makefile	Tue Mar 14 13:50:35 2006 -0700
   102.3 @@ -20,10 +20,8 @@ GDB	:= gdb
   102.4  INCS	:= -I. -I-
   102.5  DEFS	:= 
   102.6  LDFLAGS	:= 
   102.7 -CFLAGS	:= -Wall -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
   102.8 -CFLAGS	+= -Wmissing-prototypes
   102.9 -#CFLAGS	+= -pipe -g -O0 -Wcast-align
  102.10 -CFLAGS	+= -pipe -O3 
  102.11 +CFLAGS	+= -Wpointer-arith -Wcast-qual -Wno-unused -Wno-format
  102.12 +CFLAGS	+= -Wmissing-prototypes -pipe
  102.13  
  102.14  #  What object files need building for the program
  102.15  OBJS	:= mbootpack.o buildimage.o
  102.16 @@ -33,7 +31,7 @@ DEPFLAGS = -Wp,-MD,.$(@F).d
  102.17  DEPS     = .*.d
  102.18  
  102.19  mbootpack: $(OBJS)
  102.20 -	$(HOSTCC) -o $@ $(filter-out %.a, $^) $(LDFLAGS)
  102.21 +	$(HOSTCC) -o $@ $(filter-out %.a, $^)
  102.22  
  102.23  clean:
  102.24  	$(RM) mbootpack *.o $(DEPS) bootsect setup bzimage_header.c bin2c
   103.1 --- a/tools/misc/miniterm/Makefile	Tue Mar 14 13:10:21 2006 -0700
   103.2 +++ b/tools/misc/miniterm/Makefile	Tue Mar 14 13:50:35 2006 -0700
   103.3 @@ -1,9 +1,10 @@
   103.4 +XEN_ROOT:=../../..
   103.5 +include $(XEN_ROOT)/tools/Rules.mk
   103.6 +
   103.7  INSTALL		= install
   103.8  INSTALL_PROG	= $(INSTALL) -m0755
   103.9  INSTALL_DIR	= $(INSTALL) -d -m0755
  103.10  
  103.11 -CC     = gcc
  103.12 -CFLAGS = -Wall -O3
  103.13  TARGET = miniterm
  103.14  
  103.15  all: $(TARGET)
  103.16 @@ -16,4 +17,4 @@ clean:
  103.17  	$(RM) *.o $(TARGET) *~
  103.18  
  103.19  $(TARGET): $(TARGET).c
  103.20 -	$(CC) $(CFLAGS) -o $@ $<
  103.21 +	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
   104.1 --- a/tools/misc/nsplitd/Makefile	Tue Mar 14 13:10:21 2006 -0700
   104.2 +++ b/tools/misc/nsplitd/Makefile	Tue Mar 14 13:50:35 2006 -0700
   104.3 @@ -1,6 +1,6 @@
   104.4 +XEN_ROOT := ../../..
   104.5 +include $(XEN_ROOT)/tools/Rules.mk
   104.6  
   104.7 -CC     = gcc
   104.8 -CFLAGS = -Wall -O3
   104.9  CFILES = $(wildcard *.c)
  104.10  
  104.11  HDRS     = $(wildcard *.h)
  104.12 @@ -16,7 +16,7 @@ clean:
  104.13  	$(RM) *.o $(TARGET) *~
  104.14  
  104.15  $(TARGET): $(OBJS)
  104.16 -	$(CC) $(CFLAGS) -o $@ $^
  104.17 +	$(HOSTCC) $(HOSTCFLAGS) -o $@ $^
  104.18  
  104.19  %.o: %.c $(HDRS) Makefile
  104.20 -	$(CC) $(CFLAGS) -c -o $@ $<
  104.21 +	$(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
   105.1 --- a/tools/misc/xc_shadow.c	Tue Mar 14 13:10:21 2006 -0700
   105.2 +++ b/tools/misc/xc_shadow.c	Tue Mar 14 13:50:35 2006 -0700
   105.3 @@ -18,7 +18,7 @@
   105.4  #include <errno.h>
   105.5  #include <string.h>
   105.6  
   105.7 -void usage()
   105.8 +void usage(void)
   105.9  {
  105.10      printf("xc_shadow: -[0|1|2]\n");
  105.11      printf("    set shadow mode\n");
  105.12 @@ -28,7 +28,7 @@ void usage()
  105.13  int main(int argc, char *argv[])
  105.14  {
  105.15      int xc_handle;
  105.16 -    int mode;
  105.17 +    int mode = 0;
  105.18  
  105.19      if ( argc > 1 )
  105.20      {
   106.1 --- a/tools/python/Makefile	Tue Mar 14 13:10:21 2006 -0700
   106.2 +++ b/tools/python/Makefile	Tue Mar 14 13:50:35 2006 -0700
   106.3 @@ -9,10 +9,10 @@ build:
   106.4  
   106.5  ifndef XEN_PYTHON_NATIVE_INSTALL
   106.6  install: all
   106.7 -	CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr"
   106.8 +	CFLAGS="$(CFLAGS)" python setup.py install --home="$(DESTDIR)/usr" --force
   106.9  else
  106.10  install: all
  106.11 -	CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)"
  106.12 +	CFLAGS="$(CFLAGS)" python setup.py install --root="$(DESTDIR)" --force
  106.13  endif
  106.14  
  106.15  test:
   107.1 --- a/tools/python/xen/web/httpserver.py	Tue Mar 14 13:10:21 2006 -0700
   107.2 +++ b/tools/python/xen/web/httpserver.py	Tue Mar 14 13:50:35 2006 -0700
   107.3 @@ -13,7 +13,9 @@
   107.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   107.5  #============================================================================
   107.6  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
   107.7 +# Copyright (C) 2006 XenSource Ltd.
   107.8  #============================================================================
   107.9 +
  107.10  import threading
  107.11  
  107.12  import string
  107.13 @@ -28,6 +30,7 @@ from xen.xend.Args import ArgError
  107.14  from xen.xend.XendError import XendError
  107.15  
  107.16  import http
  107.17 +import unix
  107.18  from resource import Resource, ErrorPage
  107.19  from SrvDir import SrvDir
  107.20  
  107.21 @@ -267,31 +270,28 @@ class HttpServer:
  107.22  
  107.23      closed = False
  107.24  
  107.25 -    def __init__(self, interface='', port=8080, root=None):
  107.26 -        if root is None:
  107.27 -            root = SrvDir()
  107.28 +    def __init__(self, root, interface, port=8080):
  107.29 +        self.root = root
  107.30          self.interface = interface
  107.31          self.port = port
  107.32 -        self.root = root
  107.33          # ready indicates when we are ready to begin accept connections
  107.34          # it should be set after a successful bind
  107.35          self.ready = False
  107.36  
  107.37 -    def getRoot(self):
  107.38 -        return self.root
  107.39 -
  107.40 -    def getPort(self):
  107.41 -        return self.port
  107.42 -
  107.43      def run(self):
  107.44          self.bind()
  107.45          self.listen()
  107.46          self.ready = True
  107.47 -        self.requestLoop()
  107.48 +
  107.49 +        while not self.closed:
  107.50 +            (sock, addr) = self.accept()
  107.51 +            self.processRequest(sock, addr)
  107.52 +
  107.53  
  107.54      def stop(self):
  107.55          self.close()
  107.56  
  107.57 +
  107.58      def bind(self):
  107.59          self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  107.60          self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  107.61 @@ -303,10 +303,6 @@ class HttpServer:
  107.62      def accept(self):
  107.63          return self.socket.accept()
  107.64  
  107.65 -    def requestLoop(self):
  107.66 -        while not self.closed:
  107.67 -            self.acceptRequest()
  107.68 -
  107.69      def close(self):
  107.70          self.closed = True
  107.71          try:
  107.72 @@ -314,13 +310,6 @@ class HttpServer:
  107.73          except:
  107.74              pass
  107.75  
  107.76 -    def acceptRequest(self):
  107.77 -        try:
  107.78 -            (sock, addr) = self.accept()
  107.79 -            self.processRequest(sock, addr)
  107.80 -        except socket.error:
  107.81 -            return
  107.82 -
  107.83      def processRequest(self, sock, addr):
  107.84          try:
  107.85              rp = RequestProcessor(self, sock, addr)
  107.86 @@ -340,23 +329,12 @@ class HttpServer:
  107.87      def getResource(self, req):
  107.88          return self.root.getRequestResource(req)
  107.89  
  107.90 +
  107.91  class UnixHttpServer(HttpServer):
  107.92  
  107.93 -    def __init__(self, path=None, root=None):
  107.94 -        HttpServer.__init__(self, interface='localhost', root=root)
  107.95 +    def __init__(self, root, path):
  107.96 +        HttpServer.__init__(self, root, 'localhost')
  107.97          self.path = path
  107.98          
  107.99      def bind(self):
 107.100 -        pathdir = os.path.dirname(self.path)
 107.101 -        if not os.path.exists(pathdir):
 107.102 -            os.makedirs(pathdir)
 107.103 -        else:
 107.104 -            try:
 107.105 -                os.unlink(self.path)
 107.106 -            except SystemExit:
 107.107 -                raise
 107.108 -            except Exception, ex:
 107.109 -                pass
 107.110 -        self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 107.111 -        #self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
 107.112 -        self.socket.bind(self.path)
 107.113 +        self.socket = unix.bind(self.path)
   108.1 --- a/tools/python/xen/web/unix.py	Tue Mar 14 13:10:21 2006 -0700
   108.2 +++ b/tools/python/xen/web/unix.py	Tue Mar 14 13:50:35 2006 -0700
   108.3 @@ -13,17 +13,36 @@
   108.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   108.5  #============================================================================
   108.6  # Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
   108.7 -# Copyright (C) 2005 XenSource Ltd.
   108.8 +# Copyright (C) 2005-2006 XenSource Ltd.
   108.9  #============================================================================
  108.10  
  108.11  
  108.12 -import socket
  108.13  import os
  108.14  import os.path
  108.15 +import socket
  108.16 +import stat
  108.17  
  108.18  import connection
  108.19  
  108.20  
  108.21 +def bind(path):
  108.22 +    """Create a Unix socket, and bind it to the given path.  The socket is
  108.23 +created such that only the current user may access it."""
  108.24 +
  108.25 +    parent = os.path.dirname(path)
  108.26 +    if os.path.exists(parent):
  108.27 +        os.chown(parent, os.geteuid(), os.getegid())
  108.28 +        os.chmod(parent, stat.S_IRWXU)
  108.29 +        if os.path.exists(path):
  108.30 +            os.unlink(path)
  108.31 +    else:
  108.32 +        os.makedirs(parent, stat.S_IRWXU)
  108.33 +
  108.34 +    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  108.35 +    sock.bind(path)
  108.36 +    return sock
  108.37 +
  108.38 +
  108.39  class UnixListener(connection.SocketListener):
  108.40      def __init__(self, path, protocol_class):
  108.41          self.path = path
  108.42 @@ -31,19 +50,7 @@ class UnixListener(connection.SocketList
  108.43  
  108.44  
  108.45      def createSocket(self):
  108.46 -        pathdir = os.path.dirname(self.path)
  108.47 -        if not os.path.exists(pathdir):
  108.48 -            os.makedirs(pathdir)
  108.49 -        else:
  108.50 -            try:
  108.51 -                os.unlink(self.path)
  108.52 -            except SystemExit:
  108.53 -                raise
  108.54 -            except Exception, ex:
  108.55 -                pass
  108.56 -        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
  108.57 -        sock.bind(self.path)
  108.58 -        return sock
  108.59 +        return bind(self.path)
  108.60  
  108.61  
  108.62      def acceptConnection(self, sock, _):
   109.1 --- a/tools/python/xen/xend/XendDomain.py	Tue Mar 14 13:10:21 2006 -0700
   109.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Mar 14 13:50:35 2006 -0700
   109.3 @@ -487,7 +487,17 @@ class XendDomain:
   109.4          """
   109.5          dominfo = self.domain_lookup(domid)
   109.6          try:
   109.7 -            return xc.sedf_domain_get(dominfo.getDomid())
   109.8 +            
   109.9 +            sedf_info = xc.sedf_domain_get(dominfo.getDomid())
  109.10 +            # return sxpr
  109.11 +            return ['sedf',
  109.12 +                    ['domain',    sedf_info['domain']],
  109.13 +                    ['period',    sedf_info['period']],
  109.14 +                    ['slice',     sedf_info['slice']],
  109.15 +                    ['latency',   sedf_info['latency']],
  109.16 +                    ['extratime', sedf_info['extratime']],
  109.17 +                    ['weight',    sedf_info['weight']]]
  109.18 +
  109.19          except Exception, ex:
  109.20              raise XendError(str(ex))
  109.21  
   110.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Tue Mar 14 13:10:21 2006 -0700
   110.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Mar 14 13:50:35 2006 -0700
   110.3 @@ -1580,10 +1580,11 @@ def addControllerClass(device_class, cls
   110.4      controllerClasses[device_class] = cls
   110.5  
   110.6  
   110.7 -from xen.xend.server import blkif, netif, tpmif, pciif, iopif, usbif
   110.8 +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif
   110.9  addControllerClass('vbd',  blkif.BlkifController)
  110.10  addControllerClass('vif',  netif.NetifController)
  110.11  addControllerClass('vtpm', tpmif.TPMifController)
  110.12  addControllerClass('pci',  pciif.PciController)
  110.13  addControllerClass('ioports', iopif.IOPortsController)
  110.14 +addControllerClass('irq',  irqif.IRQController)
  110.15  addControllerClass('usb',  usbif.UsbifController)
   111.1 --- a/tools/python/xen/xend/XendLogging.py	Tue Mar 14 13:10:21 2006 -0700
   111.2 +++ b/tools/python/xen/xend/XendLogging.py	Tue Mar 14 13:50:35 2006 -0700
   111.3 @@ -13,7 +13,7 @@
   111.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   111.5  #============================================================================
   111.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
   111.7 -# Copyright (C) 2005 XenSource Ltd
   111.8 +# Copyright (C) 2005, 2006 XenSource Ltd.
   111.9  #============================================================================
  111.10  
  111.11  
  111.12 @@ -22,9 +22,10 @@ import types
  111.13  import logging
  111.14  import logging.handlers
  111.15  
  111.16 +from xen.xend.server import params
  111.17  
  111.18 -__all__ = [ 'log', 'init', 'getLogFilename', 'addLogStderr',
  111.19 -            'removeLogStderr' ]
  111.20 +
  111.21 +__all__ = [ 'log', 'init', 'getLogFilename' ]
  111.22  
  111.23  
  111.24  if not 'TRACE' in logging.__dict__:
  111.25 @@ -38,37 +39,28 @@ if not 'TRACE' in logging.__dict__:
  111.26  log = logging.getLogger("xend")
  111.27  
  111.28  
  111.29 -DEFAULT_MAX_BYTES = 1 << 20  # 1MB
  111.30 -DEFAULT_BACKUP_COUNT = 5
  111.31 +MAX_BYTES = 1 << 20  # 1MB
  111.32 +BACKUP_COUNT = 5
  111.33  
  111.34  STDERR_FORMAT = "[%(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
  111.35  LOGFILE_FORMAT = "[%(asctime)s %(name)s] %(levelname)s (%(module)s:%(lineno)d) %(message)s"
  111.36  DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
  111.37  
  111.38  
  111.39 -stderrHandler = logging.StreamHandler()
  111.40 -stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT, DATE_FORMAT))
  111.41 -
  111.42  logfilename = None
  111.43  
  111.44  
  111.45 -def init(filename, level=logging.INFO, maxBytes=None, backupCount=None):
  111.46 -    """Initialise logging. Logs to 'filename' by default, but does not log to
  111.47 -    stderr unless addLogStderr() is called.
  111.48 +def init(filename, level):
  111.49 +    """Initialise logging.  Logs to the given filename, and logs to stderr if
  111.50 +    XEND_DEBUG is set.
  111.51      """
  111.52  
  111.53      global logfilename
  111.54  
  111.55      def openFileHandler(fname):
  111.56 -        return logging.handlers.RotatingFileHandler(fname,
  111.57 -                                                    mode='a',
  111.58 -                                                    maxBytes=maxBytes,
  111.59 -                                                    backupCount=backupCount)
  111.60 -
  111.61 -    if not maxBytes:
  111.62 -        maxBytes = DEFAULT_MAX_BYTES
  111.63 -    if not backupCount:
  111.64 -        backupCount = DEFAULT_BACKUP_COUNT
  111.65 +        return logging.handlers.RotatingFileHandler(fname, mode = 'a',
  111.66 +                                                    maxBytes = MAX_BYTES,
  111.67 +                                                    backupCount = BACKUP_COUNT)
  111.68  
  111.69      # Rather unintuitively, getLevelName will get the number corresponding to
  111.70      # a level name, as well as getting the name corresponding to a level
  111.71 @@ -89,16 +81,12 @@ def init(filename, level=logging.INFO, m
  111.72      fileHandler.setFormatter(logging.Formatter(LOGFILE_FORMAT, DATE_FORMAT))
  111.73      log.addHandler(fileHandler)
  111.74  
  111.75 +    if params.XEND_DEBUG:
  111.76 +        stderrHandler = logging.StreamHandler()
  111.77 +        stderrHandler.setFormatter(logging.Formatter(STDERR_FORMAT,
  111.78 +                                                     DATE_FORMAT))
  111.79 +        log.addHandler(stderrHandler)
  111.80 +
  111.81  
  111.82  def getLogFilename():
  111.83      return logfilename
  111.84 -
  111.85 -
  111.86 -def addLogStderr():
  111.87 -    """Add logging to stderr."""
  111.88 -    log.addHandler(stderrHandler)
  111.89 -
  111.90 -
  111.91 -def removeLogStderr():
  111.92 -    """Remove logging to stderr."""
  111.93 -    log.removeHandler(stderrHandler)
   112.1 --- a/tools/python/xen/xend/XendRoot.py	Tue Mar 14 13:10:21 2006 -0700
   112.2 +++ b/tools/python/xen/xend/XendRoot.py	Tue Mar 14 13:50:35 2006 -0700
   112.3 @@ -102,15 +102,14 @@ class XendRoot:
   112.4          """
   112.5          print >>sys.stderr, "xend [ERROR]", fmt % args
   112.6  
   112.7 +
   112.8      def configure(self):
   112.9          self.set_config()
  112.10 -        logfile = self.get_config_value("logfile", self.logfile_default)
  112.11 -        loglevel = self.get_config_value("loglevel", self.loglevel_default)
  112.12 -        XendLogging.init(logfile, level = loglevel)
  112.13 +        XendLogging.init(self.get_config_value("logfile",
  112.14 +                                               self.logfile_default),
  112.15 +                         self.get_config_value("loglevel",
  112.16 +                                               self.loglevel_default))
  112.17  
  112.18 -        from xen.xend.server import params
  112.19 -        if params.XEND_DEBUG:
  112.20 -            XendLogging.addLogStderr()
  112.21  
  112.22      def set_config(self):
  112.23          """If the config file exists, read it. If not, ignore it.
   113.1 --- a/tools/python/xen/xend/balloon.py	Tue Mar 14 13:10:21 2006 -0700
   113.2 +++ b/tools/python/xen/xend/balloon.py	Tue Mar 14 13:50:35 2006 -0700
   113.3 @@ -27,7 +27,8 @@ from XendLogging import log
   113.4  from XendError import VmError
   113.5  
   113.6  
   113.7 -PROC_XEN_BALLOON = "/proc/xen/balloon"
   113.8 +PROC_XEN_BALLOON = '/proc/xen/balloon'
   113.9 +
  113.10  BALLOON_OUT_SLACK = 1 # MiB.  We need this because the physinfo details are
  113.11                        # rounded.
  113.12  RETRY_LIMIT = 10
  113.13 @@ -39,6 +40,47 @@ RETRY_LIMIT = 10
  113.14  # such requirements.
  113.15  SLEEP_TIME_GROWTH = 0.1
  113.16  
  113.17 +# A mapping between easy-to-remember labels and the more verbose
  113.18 +# label actually shown in the PROC_XEN_BALLOON file.
  113.19 +labels = { 'current'      : 'Current allocation',
  113.20 +           'target'       : 'Requested target',
  113.21 +           'low-balloon'  : 'Low-mem balloon',
  113.22 +           'high-balloon' : 'High-mem balloon',
  113.23 +           'limit'        : 'Xen hard limit' }
  113.24 +
  113.25 +def _get_proc_balloon(label):
  113.26 +    """Returns the value for the named label.  Returns None if the label was
  113.27 +       not found or the value was non-numeric."""
  113.28 +
  113.29 +    f = file(PROC_XEN_BALLOON, 'r')
  113.30 +    try:
  113.31 +        for line in f:
  113.32 +            keyvalue = line.split(':')
  113.33 +            if keyvalue[0] == label:
  113.34 +                values = keyvalue[1].split()
  113.35 +                if values[0].isdigit():
  113.36 +                    return int(values[0])
  113.37 +                else:
  113.38 +                    return None
  113.39 +        return None
  113.40 +    finally:
  113.41 +        f.close()
  113.42 +
  113.43 +def get_dom0_current_alloc():
  113.44 +    """Returns the current memory allocation (in MiB) of dom0."""
  113.45 +
  113.46 +    kb = _get_proc_balloon(labels['current'])
  113.47 +    if kb == None:
  113.48 +        raise VmError('Failed to query current memory allocation of dom0.')
  113.49 +    return kb / 1024
  113.50 +
  113.51 +def get_dom0_target_alloc():
  113.52 +    """Returns the target memory allocation (in MiB) of dom0."""
  113.53 +
  113.54 +    kb = _get_proc_balloon(labels['target'])
  113.55 +    if kb == None:
  113.56 +        raise VmError('Failed to query target memory allocation of dom0.')
  113.57 +    return kb / 1024
  113.58  
  113.59  def free(required):
  113.60      """Balloon out memory from the privileged domain so that there is the
  113.61 @@ -88,7 +130,7 @@ def free(required):
  113.62                  log.debug("Balloon: free %d; need %d.", free_mem, need_mem)
  113.63  
  113.64              if dom0_min_mem > 0:
  113.65 -                dom0_alloc = _get_dom0_alloc()
  113.66 +                dom0_alloc = get_dom0_current_alloc()
  113.67                  new_alloc = dom0_alloc - (need_mem - free_mem)
  113.68  
  113.69                  if (new_alloc >= dom0_min_mem and
  113.70 @@ -121,20 +163,3 @@ def free(required):
  113.71  
  113.72      finally:
  113.73          del xc
  113.74 -
  113.75 -
  113.76 -def _get_dom0_alloc():
  113.77 -    """Return current allocation memory of dom0 (in MiB). Return 0 on error"""
  113.78 -
  113.79 -    f = file(PROC_XEN_BALLOON, 'r')
  113.80 -    try:
  113.81 -        line = f.readline()
  113.82 -        for x in line.split():
  113.83 -            for n in x:
  113.84 -                if not n.isdigit():
  113.85 -                    break
  113.86 -            else:
  113.87 -                return int(x) / 1024
  113.88 -        return 0
  113.89 -    finally:
  113.90 -        f.close()
   114.1 --- a/tools/python/xen/xend/server/SrvServer.py	Tue Mar 14 13:10:21 2006 -0700
   114.2 +++ b/tools/python/xen/xend/server/SrvServer.py	Tue Mar 14 13:50:35 2006 -0700
   114.3 @@ -13,6 +13,7 @@
   114.4  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   114.5  #============================================================================
   114.6  # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
   114.7 +# Copyright (C) 2006 XenSource Ltd.
   114.8  #============================================================================
   114.9  
  114.10  """Example xend HTTP
  114.11 @@ -106,11 +107,11 @@ def create():
  114.12      root.putChild('xend', SrvRoot())
  114.13      servers = XendServers()
  114.14      if xroot.get_xend_http_server():
  114.15 -        port = xroot.get_xend_port()
  114.16 -        interface = xroot.get_xend_address()
  114.17 -        servers.add(HttpServer(root=root, interface=interface, port=port))
  114.18 +        servers.add(HttpServer(root,
  114.19 +                               xroot.get_xend_address(),
  114.20 +                               xroot.get_xend_port()))
  114.21      if xroot.get_xend_unix_server():
  114.22          path = xroot.get_xend_unix_path()
  114.23          log.info('unix path=' + path)
  114.24 -        servers.add(UnixHttpServer(path=path, root=root))
  114.25 +        servers.add(UnixHttpServer(root, path))
  114.26      return servers
   115.1 --- a/tools/python/xen/xend/server/iopif.py	Tue Mar 14 13:10:21 2006 -0700
   115.2 +++ b/tools/python/xen/xend/server/iopif.py	Tue Mar 14 13:50:35 2006 -0700
   115.3 @@ -83,4 +83,4 @@ class IOPortsController(DevController):
   115.4                  'ioports: Failed to configure legacy i/o range: %s - %s' %
   115.5                  (io_from, io_to))
   115.6  
   115.7 -        return (dev, {}, {})
   115.8 +        return (None, {}, {})
   116.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   116.2 +++ b/tools/python/xen/xend/server/irqif.py	Tue Mar 14 13:50:35 2006 -0700
   116.3 @@ -0,0 +1,73 @@
   116.4 +#============================================================================
   116.5 +# This library is free software; you can redistribute it and/or
   116.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
   116.7 +# License as published by the Free Software Foundation.
   116.8 +#
   116.9 +# This library is distributed in the hope that it will be useful,
  116.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  116.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  116.12 +# Lesser General Public License for more details.
  116.13 +#
  116.14 +# You should have received a copy of the GNU Lesser General Public
  116.15 +# License along with this library; if not, write to the Free Software
  116.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  116.17 +#============================================================================
  116.18 +# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
  116.19 +# Copyright (C) 2005 XenSource Ltd
  116.20 +# Copyright (C) 2005 Jody Belka
  116.21 +#============================================================================
  116.22 +# This code based on tools/python/xen/xend/server/iopif.py and modified
  116.23 +# to handle interrupts
  116.24 +#============================================================================
  116.25 +
  116.26 +
  116.27 +import types
  116.28 +
  116.29 +import xen.lowlevel.xc;
  116.30 +
  116.31 +from xen.xend import sxp
  116.32 +from xen.xend.XendError import VmError
  116.33 +
  116.34 +from xen.xend.server.DevController import DevController
  116.35 +
  116.36 +
  116.37 +xc = xen.lowlevel.xc.xc()
  116.38 +
  116.39 +
  116.40 +class IRQController(DevController):
  116.41 +
  116.42 +    def __init__(self, vm):
  116.43 +        DevController.__init__(self, vm)
  116.44 +
  116.45 +
  116.46 +    def getDeviceDetails(self, config):
  116.47 +        """@see DevController.getDeviceDetails"""
  116.48 +
  116.49 +        def get_param(field):
  116.50 +            try:
  116.51 +                val = sxp.child_value(config, field)
  116.52 +
  116.53 +                if not val:
  116.54 +                    raise VmError('irq: Missing %s config setting' % field)
  116.55 +
  116.56 +                if isinstance(val, types.StringType):
  116.57 +                    return int(val,10)
  116.58 +                    radix = 10
  116.59 +                else:
  116.60 +                    return val
  116.61 +            except:
  116.62 +                raise VmError('irq: Invalid config setting %s: %s' %
  116.63 +                              (field, val))
  116.64 +       
  116.65 +        pirq = get_param('irq')
  116.66 +
  116.67 +        rc = xc.domain_irq_permission(dom          = self.getDomid(),
  116.68 +                                      pirq         = pirq,
  116.69 +                                      allow_access = True)
  116.70 +
  116.71 +        if rc < 0:
  116.72 +            #todo non-fatal
  116.73 +            raise VmError(
  116.74 +                'irq: Failed to configure irq: %d' % (pirq))
  116.75 +
  116.76 +        return (None, {}, {})
   117.1 --- a/tools/python/xen/xend/server/netif.py	Tue Mar 14 13:10:21 2006 -0700
   117.2 +++ b/tools/python/xen/xend/server/netif.py	Tue Mar 14 13:50:35 2006 -0700
   117.3 @@ -72,8 +72,6 @@ class NetifController(DevController):
   117.4                                sxp.child_value(config, 'script',
   117.5                                                xroot.get_vif_script()))
   117.6          typ = sxp.child_value(config, 'type')
   117.7 -        if typ == 'ioemu':
   117.8 -            return (None,{},{})
   117.9          bridge  = sxp.child_value(config, 'bridge')
  117.10          mac     = sxp.child_value(config, 'mac')
  117.11          vifname = sxp.child_value(config, 'vifname')
  117.12 @@ -87,6 +85,13 @@ class NetifController(DevController):
  117.13          back = { 'script' : script,
  117.14                   'mac'    : mac,
  117.15                   'handle' : "%i" % devid }
  117.16 +
  117.17 +        if typ == 'ioemu':
  117.18 +            front = {}
  117.19 +            back['type'] = 'ioemu'
  117.20 +        else:
  117.21 +            front = { 'handle' : "%i" % devid,
  117.22 +                      'mac'    : mac }
  117.23          if ipaddr:
  117.24              back['ip'] = ' '.join(ipaddr)
  117.25          if bridge:
  117.26 @@ -94,9 +99,6 @@ class NetifController(DevController):
  117.27          if vifname:
  117.28              back['vifname'] = vifname
  117.29  
  117.30 -        front = { 'handle' : "%i" % devid,
  117.31 -                  'mac'    : mac }
  117.32 -
  117.33          return (devid, back, front)
  117.34  
  117.35  
   118.1 --- a/tools/python/xen/xm/create.py	Tue Mar 14 13:10:21 2006 -0700
   118.2 +++ b/tools/python/xen/xm/create.py	Tue Mar 14 13:50:35 2006 -0700
   118.3 @@ -252,15 +252,21 @@ gopts.var('disk', val='phy:DEV,VDEV,MODE
   118.4  gopts.var('pci', val='BUS:DEV.FUNC',
   118.5            fn=append_value, default=[],
   118.6            use="""Add a PCI device to a domain, using given params (in hex).
   118.7 -         For example '-pci c0:02.1a'.
   118.8 +         For example 'pci=c0:02.1a'.
   118.9           The option may be repeated to add more than one pci device.""")
  118.10  
  118.11  gopts.var('ioports', val='FROM[-TO]',
  118.12            fn=append_value, default=[],
  118.13            use="""Add a legacy I/O range to a domain, using given params (in hex).
  118.14 -         For example '-ioports 02f8-02ff'.
  118.15 +         For example 'ioports=02f8-02ff'.
  118.16           The option may be repeated to add more than one i/o range.""")
  118.17  
  118.18 +gopts.var('irq', val='IRQ',
  118.19 +          fn=append_value, default=[],
  118.20 +          use="""Add an IRQ (interrupt line) to a domain.
  118.21 +         For example 'irq=7'.
  118.22 +         This option may be repeated to add more than one IRQ.""")
  118.23 +
  118.24  gopts.var('usb', val='PATH',
  118.25            fn=append_value, default=[],
  118.26            use="""Add a physical USB port to a domain, as specified by the path
  118.27 @@ -488,6 +494,13 @@ def configure_ioports(config_devs, vals)
  118.28          config_ioports = ['ioports', ['from', io_from], ['to', io_to]]
  118.29          config_devs.append(['device', config_ioports])
  118.30  
  118.31 +def configure_irq(config_devs, vals):
  118.32 +    """Create the config for irqs.
  118.33 +    """
  118.34 +    for irq in vals.irq:
  118.35 +        config_irq = ['irq', ['irq', irq]]
  118.36 +        config_devs.append(['device', config_irq])
  118.37 +
  118.38  def configure_usb(config_devs, vals):
  118.39      for path in vals.usb:
  118.40          config_usb = ['usb', ['path', path]]
  118.41 @@ -615,6 +628,7 @@ def make_config(vals):
  118.42      configure_disks(config_devs, vals)
  118.43      configure_pci(config_devs, vals)
  118.44      configure_ioports(config_devs, vals)
  118.45 +    configure_irq(config_devs, vals)
  118.46      configure_vifs(config_devs, vals)
  118.47      configure_usb(config_devs, vals)
  118.48      configure_vtpm(config_devs, vals)
   119.1 --- a/tools/python/xen/xm/main.py	Tue Mar 14 13:10:21 2006 -0700
   119.2 +++ b/tools/python/xen/xm/main.py	Tue Mar 14 13:50:35 2006 -0700
   119.3 @@ -83,7 +83,18 @@ sched_bvt_help = """sched-bvt <Parameter
   119.4                                      parameters"""
   119.5  sched_bvt_ctxallow_help = """sched-bvt-ctxallow <Allow>       Set the BVT scheduler context switch
   119.6                                      allowance"""
   119.7 -sched_sedf_help = "sched-sedf <Parameters>          Set simple EDF parameters"
   119.8 +sched_sedf_help = "sched-sedf [DOM] [OPTIONS]       Show|Set simple EDF parameters\n" + \
   119.9 +"              -p, --period          Relative deadline(ms).\n\
  119.10 +              -s, --slice           Worst-case execution time(ms)\n\
  119.11 +                                    (slice < period).\n\
  119.12 +              -l, --latency         scaled period(ms) in case the domain\n\
  119.13 +                                    is doing heavy I/O.\n\
  119.14 +              -e, --extra           flag (0/1) which controls whether the\n\
  119.15 +                                    domain can run in extra-time\n\
  119.16 +              -w, --weight          mutually exclusive with period/slice and\n\
  119.17 +                                    specifies another way of setting a domain's\n\
  119.18 +                                    cpu period/slice."
  119.19 +
  119.20  block_attach_help = """block-attach <DomId> <BackDev> <FrontDev> <Mode>
  119.21                  [BackDomId]         Create a new virtual block device"""
  119.22  block_detach_help = """block-detach  <DomId> <DevId>    Destroy a domain's virtual block device,
  119.23 @@ -148,8 +159,7 @@ domain_commands = [
  119.24  host_commands = [
  119.25      "dmesg",
  119.26      "info",
  119.27 -    "log",
  119.28 -    "top",
  119.29 +    "log"
  119.30      ]
  119.31  
  119.32  scheduler_commands = [
  119.33 @@ -377,6 +387,20 @@ def parse_doms_info(info):
  119.34          }
  119.35  
  119.36  
  119.37 +def parse_sedf_info(info):
  119.38 +    def get_info(n, t, d):
  119.39 +        return t(sxp.child_value(info, n, d))
  119.40 +
  119.41 +    return {
  119.42 +        'dom'      : get_info('domain',        int,   -1),
  119.43 +        'period'   : get_info('period',        int,   -1),
  119.44 +        'slice'    : get_info('slice',         int,   -1),
  119.45 +        'latency'  : get_info('latency',       int,   -1),
  119.46 +        'extratime': get_info('extratime',     int,   -1),
  119.47 +        'weight'   : get_info('weight',        int,   -1),
  119.48 +        }
  119.49 +
  119.50 +
  119.51  def xm_brief_list(doms):
  119.52      print 'Name                              ID Mem(MiB) VCPUs State  Time(s)'
  119.53      for dom in doms:
  119.54 @@ -617,12 +641,86 @@ def xm_sched_bvt_ctxallow(args):
  119.55      server.xend_node_cpu_bvt_slice_set(slice)
  119.56  
  119.57  def xm_sched_sedf(args):
  119.58 -    arg_check(args, "sched-sedf", 6)
  119.59 +    def ns_to_ms(val):
  119.60 +        return float(val) * 0.000001
  119.61 +    
  119.62 +    def ms_to_ns(val):
  119.63 +        return (float(val) / 0.000001)
  119.64 +
  119.65 +    def print_sedf(info):
  119.66 +        info['period']  = ns_to_ms(info['period'])
  119.67 +        info['slice']   = ns_to_ms(info['slice'])
  119.68 +        info['latency'] = ns_to_ms(info['latency'])
  119.69 +        print( ("%(name)-32s %(dom)3d %(period)9.1f %(slice)9.1f" +
  119.70 +                " %(latency)7.1f %(extratime)6d %(weight)6d") % info)
  119.71 +
  119.72 +    def domid_match(domid, info):
  119.73 +        return domid is None or domid == info['name'] or domid == str(info['dom'])
  119.74 +
  119.75 +    # we want to just display current info if no parameters are passed
  119.76 +    if len(args) == 0:
  119.77 +        domid = None
  119.78 +    else:
  119.79 +        # we expect at least a domain id (name or number)
  119.80 +        # and at most a domid up to 5 options with values
  119.81 +        arg_check(args, "sched-sedf", 1, 11)
  119.82 +        domid = args[0]
  119.83 +        # drop domid from args since get_opt doesn't recognize it
  119.84 +        args = args[1:] 
  119.85 +
  119.86 +    opts = {}
  119.87 +    try:
  119.88 +        (options, params) = getopt.gnu_getopt(args, 'p:s:l:e:w:',
  119.89 +            ['period=', 'slice=', 'latency=', 'extratime=', 'weight='])
  119.90 +    except getopt.GetoptError, opterr:
  119.91 +        err(opterr)
  119.92 +        sys.exit(1)
  119.93      
  119.94 -    dom = args[0]
  119.95 -    v = map(int, args[1:6])
  119.96 +    # convert to nanoseconds if needed 
  119.97 +    for (k, v) in options:
  119.98 +        if k in ['-p', '--period']:
  119.99 +            opts['period'] = ms_to_ns(v)
 119.100 +        elif k in ['-s', '--slice']:
 119.101 +            opts['slice'] = ms_to_ns(v)
 119.102 +        elif k in ['-l', '--latency']:
 119.103 +            opts['latency'] = ms_to_ns(v)
 119.104 +        elif k in ['-e', '--extratime']:
 119.105 +            opts['extratime'] = v
 119.106 +        elif k in ['-w', '--weight']:
 119.107 +            opts['weight'] = v
 119.108 +
 119.109 +    # print header if we aren't setting any parameters
 119.110 +    if len(opts.keys()) == 0:
 119.111 +        print '%-33s %-2s %-4s %-4s %-7s %-5s %-6s'%('Name','ID','Period(ms)',
 119.112 +                                                     'Slice(ms)', 'Lat(ms)',
 119.113 +                                                     'Extra','Weight')
 119.114 +
 119.115      from xen.xend.XendClient import server
 119.116 -    server.xend_domain_cpu_sedf_set(dom, *v)
 119.117 +    doms = filter(lambda x : domid_match(domid, x),
 119.118 +                        [parse_doms_info(dom) for dom in getDomains("")])
 119.119 +    for d in doms:
 119.120 +        # fetch current values so as not to clobber them
 119.121 +        sedf_info = \
 119.122 +            parse_sedf_info(server.xend_domain_cpu_sedf_get(d['dom']))
 119.123 +        sedf_info['name'] = d['name']
 119.124 +
 119.125 +        # update values in case of call to set
 119.126 +        if len(opts.keys()) > 0:
 119.127 +            for k in opts.keys():
 119.128 +                sedf_info[k]=opts[k]
 119.129 +         
 119.130 +            # send the update, converting user input
 119.131 +            v = map(int, [sedf_info['period'], sedf_info['slice'],
 119.132 +                          sedf_info['latency'],sedf_info['extratime'], 
 119.133 +                          sedf_info['weight']])
 119.134 +            rv = server.xend_domain_cpu_sedf_set(d['dom'], *v)
 119.135 +            if int(rv) != 0:
 119.136 +                err("Failed to set sedf parameters (rv=%d)."%(rv))
 119.137 +
 119.138 +        # not setting values, display info
 119.139 +        else:
 119.140 +            print_sedf(sedf_info)
 119.141 +
 119.142  
 119.143  def xm_info(args):
 119.144      arg_check(args, "info", 0)
   120.1 --- a/tools/security/Makefile	Tue Mar 14 13:10:21 2006 -0700
   120.2 +++ b/tools/security/Makefile	Tue Mar 14 13:50:35 2006 -0700
   120.3 @@ -1,9 +1,7 @@
   120.4  XEN_ROOT = ../..
   120.5  include $(XEN_ROOT)/tools/Rules.mk
   120.6  
   120.7 -CFLAGS   += -Wall
   120.8  CFLAGS   += -Werror
   120.9 -CFLAGS   += -O3
  120.10  CFLAGS   += -fno-strict-aliasing
  120.11  CFLAGS   += -I.
  120.12  
   121.1 --- a/tools/vnet/libxutil/Makefile	Tue Mar 14 13:10:21 2006 -0700
   121.2 +++ b/tools/vnet/libxutil/Makefile	Tue Mar 14 13:50:35 2006 -0700
   121.3 @@ -29,8 +29,7 @@ LIB_SRCS += util.c
   121.4  LIB_OBJS := $(LIB_SRCS:.c=.o)
   121.5  PIC_OBJS := $(LIB_SRCS:.c=.opic)
   121.6  
   121.7 -CFLAGS   += -Wall -Werror -O3 -fno-strict-aliasing
   121.8 -CFLAGS   += -g
   121.9 +CFLAGS   += -Werror -fno-strict-aliasing
  121.10  
  121.11  # Get gcc to generate the dependencies for us.
  121.12  CFLAGS   += -Wp,-MD,.$(@F).d
   122.1 --- a/tools/vnet/vnetd/Makefile	Tue Mar 14 13:10:21 2006 -0700
   122.2 +++ b/tools/vnet/vnetd/Makefile	Tue Mar 14 13:50:35 2006 -0700
   122.3 @@ -42,9 +42,6 @@ CPPFLAGS += -D USE_GC
   122.4  CPPFLAGS += -D __ARCH_I386_ATOMIC__
   122.5  
   122.6  #----------------------------------------------------------------------------
   122.7 -CFLAGS += -g
   122.8 -CFLAGS += -O2
   122.9 -CFLAGS += -Wall
  122.10  CFLAGS += $(INCLUDES) $(LIBS)
  122.11  
  122.12  LDFLAGS += $(LIBS)
   123.1 --- a/tools/vtpm/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
   123.2 +++ b/tools/vtpm/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
   123.3 @@ -14,7 +14,7 @@ INSTALL_DIR     = $(INSTALL) -d -m0755
   123.4  TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
   123.5  
   123.6  # General compiler flags
   123.7 -CFLAGS   = -Wall -Werror -g3 -I.
   123.8 +CFLAGS   = -Werror -g3 -I.
   123.9  
  123.10  # For generating dependencies
  123.11  CFLAGS	+= -Wp,-MD,.$(@F).d
   124.1 --- a/tools/vtpm_manager/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
   124.2 +++ b/tools/vtpm_manager/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
   124.3 @@ -14,7 +14,7 @@ INSTALL_DIR     = $(INSTALL) -d -m0755
   124.4  TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin
   124.5  
   124.6  # General compiler flags
   124.7 -CFLAGS	= -Wall -Werror -g3 -I.
   124.8 +CFLAGS	= -Werror -g3 -I.
   124.9  
  124.10  # For generating dependencies
  124.11  CFLAGS	+= -Wp,-MD,.$(@F).d
   125.1 --- a/tools/vtpm_manager/manager/Makefile	Tue Mar 14 13:10:21 2006 -0700
   125.2 +++ b/tools/vtpm_manager/manager/Makefile	Tue Mar 14 13:50:35 2006 -0700
   125.3 @@ -20,7 +20,7 @@ mrproper: clean
   125.4  	rm -f $(BIN) *~
   125.5  
   125.6  $(BIN): $(OBJS)
   125.7 -	$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
   125.8 +	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@
   125.9  
  125.10  # libraries
  125.11  LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a
   126.1 --- a/tools/xcutils/Makefile	Tue Mar 14 13:10:21 2006 -0700
   126.2 +++ b/tools/xcutils/Makefile	Tue Mar 14 13:50:35 2006 -0700
   126.3 @@ -19,7 +19,7 @@ PROGRAMS_INSTALL_DIR = /usr/$(LIBDIR)/xe
   126.4  
   126.5  INCLUDES += -I $(XEN_LIBXC)
   126.6  
   126.7 -CFLAGS += -Wall -Werror -O3 -fno-strict-aliasing
   126.8 +CFLAGS += -Werror -fno-strict-aliasing
   126.9  CFLAGS += $(INCLUDES)
  126.10  
  126.11  # Make gcc generate dependencies.
   127.1 --- a/tools/xenmon/Makefile	Tue Mar 14 13:10:21 2006 -0700
   127.2 +++ b/tools/xenmon/Makefile	Tue Mar 14 13:50:35 2006 -0700
   127.3 @@ -20,7 +20,7 @@ sbindir=/usr/sbin
   127.4  XEN_ROOT=../..
   127.5  include $(XEN_ROOT)/tools/Rules.mk
   127.6  
   127.7 -CFLAGS += -Wall -Werror -g
   127.8 +CFLAGS  += -Werror -g
   127.9  CFLAGS  += -I $(XEN_XC)
  127.10  CFLAGS  += -I $(XEN_LIBXC)
  127.11  LDFLAGS += -L $(XEN_LIBXC)
   128.1 --- a/tools/xenmon/xenbaked.c	Tue Mar 14 13:10:21 2006 -0700
   128.2 +++ b/tools/xenmon/xenbaked.c	Tue Mar 14 13:50:35 2006 -0700
   128.3 @@ -299,7 +299,7 @@ struct t_buf *map_tbufs(unsigned long tb
   128.4          exit(EXIT_FAILURE);
   128.5      }
   128.6  
   128.7 -    tbufs_mapped = xc_map_foreign_range(xc_handle, 0 /* Dom 0 ID */,
   128.8 +    tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN,
   128.9                                          size * num, PROT_READ | PROT_WRITE,
  128.10                                          tbufs_mfn);
  128.11  
  128.12 @@ -379,7 +379,7 @@ struct t_rec **init_rec_ptrs(struct t_bu
  128.13  /**
  128.14   * get_num_cpus - get the number of logical CPUs
  128.15   */
  128.16 -unsigned int get_num_cpus()
  128.17 +unsigned int get_num_cpus(void)
  128.18  {
  128.19      dom0_op_t op;
  128.20      int xc_handle = xc_interface_open();
  128.21 @@ -409,7 +409,7 @@ unsigned int get_num_cpus()
  128.22  /**
  128.23   * monitor_tbufs - monitor the contents of tbufs
  128.24   */
  128.25 -int monitor_tbufs()
  128.26 +int monitor_tbufs(void)
  128.27  {
  128.28      int i;
  128.29      extern void process_record(int, struct t_rec *);
   129.1 --- a/tools/xenmon/xenmon.py	Tue Mar 14 13:10:21 2006 -0700
   129.2 +++ b/tools/xenmon/xenmon.py	Tue Mar 14 13:50:35 2006 -0700
   129.3 @@ -452,6 +452,12 @@ def show_livestats():
   129.4          if c == ord('c'):
   129.5              cpu = (cpu + 1) % ncpu
   129.6  
   129.7 +        # n/p = cycle to the next/previous CPU
   129.8 +        if c == ord('n'):
   129.9 +            cpu = (cpu + 1) % ncpu
  129.10 +        if c == ord('p'):
  129.11 +            cpu = (cpu - 1) % ncpu
  129.12 +
  129.13          stdscr.erase()
  129.14  
  129.15      _c.nocbreak()
  129.16 @@ -502,6 +508,7 @@ def writelog():
  129.17      shm = mmap.mmap(shmf.fileno(), QOS_DATA_SIZE)
  129.18  
  129.19      interval = 0
  129.20 +    curr = last = time.time()
  129.21      outfiles = {}
  129.22      for dom in range(0, NDOMAINS):
  129.23          outfiles[dom] = Delayed("%s-dom%d.log" % (options.prefix, dom), 'w')
  129.24 @@ -561,9 +568,10 @@ def writelog():
  129.25                                       h1[dom][4], 
  129.26                                       h1[dom][5][0], h1[dom][5][1]))
  129.27                      outfiles[dom].flush()
  129.28 -
  129.29 -        interval += options.interval
  129.30 -        time.sleep(1)
  129.31 +            curr = time.time()
  129.32 +            interval += (curr - last) * 1000
  129.33 +            last = curr
  129.34 +        time.sleep(options.interval / 1000.0)
  129.35  
  129.36      for dom in range(0, NDOMAINS):
  129.37          outfiles[dom].close()
   130.1 --- a/tools/xenstat/libxenstat/Makefile	Tue Mar 14 13:10:21 2006 -0700
   130.2 +++ b/tools/xenstat/libxenstat/Makefile	Tue Mar 14 13:50:35 2006 -0700
   130.3 @@ -48,7 +48,7 @@ all: $(LIB)
   130.4  	$(RANLIB) $@
   130.5  
   130.6  $(SHLIB): $(OBJECTS)
   130.7 -	$(CC) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS)
   130.8 +	$(CC) $(CFLAGS) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS)
   130.9  
  130.10  src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h
  130.11  	$(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
   131.1 --- a/tools/xenstat/libxenstat/src/xen-interface.c	Tue Mar 14 13:10:21 2006 -0700
   131.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.c	Tue Mar 14 13:50:35 2006 -0700
   131.3 @@ -31,7 +31,7 @@ struct xi_handle {
   131.4  
   131.5  /* Initialize for xen-interface.  Returns a handle to be used with subsequent
   131.6   * calls to the xen-interface functions or NULL if an error occurs. */
   131.7 -xi_handle *xi_init()
   131.8 +xi_handle *xi_init(void)
   131.9  {
  131.10  	xi_handle *handle;
  131.11  
   132.1 --- a/tools/xenstat/libxenstat/src/xen-interface.h	Tue Mar 14 13:10:21 2006 -0700
   132.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.h	Tue Mar 14 13:50:35 2006 -0700
   132.3 @@ -26,7 +26,7 @@ typedef struct xi_handle xi_handle;
   132.4  
   132.5  /* Initialize for xen-interface.  Returns a handle to be used with subsequent
   132.6   * calls to the xen-interface functions or NULL if an error occurs. */
   132.7 -xi_handle *xi_init();
   132.8 +xi_handle *xi_init(void);
   132.9  
  132.10  /* Release the handle to libxc, free resources, etc. */
  132.11  void xi_uninit(xi_handle *handle);
   133.1 --- a/tools/xenstat/libxenstat/src/xenstat.c	Tue Mar 14 13:10:21 2006 -0700
   133.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Tue Mar 14 13:50:35 2006 -0700
   133.3 @@ -129,7 +129,7 @@ static xenstat_collector collectors[] = 
   133.4  /*
   133.5   * libxenstat API
   133.6   */
   133.7 -xenstat_handle *xenstat_init()
   133.8 +xenstat_handle *xenstat_init(void)
   133.9  {
  133.10  	xenstat_handle *handle;
  133.11  
   134.1 --- a/tools/xenstat/libxenstat/src/xenstat.h	Tue Mar 14 13:10:21 2006 -0700
   134.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h	Tue Mar 14 13:50:35 2006 -0700
   134.3 @@ -26,7 +26,7 @@ typedef struct xenstat_network xenstat_n
   134.4  
   134.5  /* Initialize the xenstat library.  Returns a handle to be used with
   134.6   * subsequent calls to the xenstat library, or NULL if an error occurs. */
   134.7 -xenstat_handle *xenstat_init();
   134.8 +xenstat_handle *xenstat_init(void);
   134.9  
  134.10  /* Release the handle to libxc, free resources, etc. */
  134.11  void xenstat_uninit(xenstat_handle * handle);
   135.1 --- a/tools/xenstore/Makefile	Tue Mar 14 13:10:21 2006 -0700
   135.2 +++ b/tools/xenstore/Makefile	Tue Mar 14 13:50:35 2006 -0700
   135.3 @@ -12,7 +12,7 @@ BASECFLAGS=-Wall -g -Werror
   135.4  # Make gcc generate dependencies.
   135.5  BASECFLAGS += -Wp,-MD,.$(@F).d
   135.6  PROG_DEP = .*.d
   135.7 -BASECFLAGS+= -O3 $(PROFILE)
   135.8 +BASECFLAGS+= $(PROFILE)
   135.9  #BASECFLAGS+= -I$(XEN_ROOT)/tools
  135.10  BASECFLAGS+= -I$(XEN_ROOT)/tools/libxc
  135.11  BASECFLAGS+= -I.
   136.1 --- a/tools/xenstore/xenstored_core.c	Tue Mar 14 13:10:21 2006 -0700
   136.2 +++ b/tools/xenstore/xenstored_core.c	Tue Mar 14 13:50:35 2006 -0700
   136.3 @@ -66,7 +66,7 @@ static char *tracefile = NULL;
   136.4  static TDB_CONTEXT *tdb_ctx;
   136.5  
   136.6  static void corrupt(struct connection *conn, const char *fmt, ...);
   136.7 -static void check_store();
   136.8 +static void check_store(void);
   136.9  
  136.10  #define log(...)							\
  136.11  	do {								\
  136.12 @@ -238,7 +238,7 @@ static void trigger_reopen_log(int signa
  136.13  }
  136.14  
  136.15  
  136.16 -static void reopen_log()
  136.17 +static void reopen_log(void)
  136.18  {
  136.19  	if (tracefile) {
  136.20  		if (tracefd > 0)
  136.21 @@ -1612,7 +1612,7 @@ static void clean_store(struct hashtable
  136.22  }
  136.23  
  136.24  
  136.25 -static void check_store()
  136.26 +static void check_store(void)
  136.27  {
  136.28  	char * root = talloc_strdup(NULL, "/");
  136.29  	struct hashtable * reachable =
   137.1 --- a/tools/xentrace/Makefile	Tue Mar 14 13:10:21 2006 -0700
   137.2 +++ b/tools/xentrace/Makefile	Tue Mar 14 13:50:35 2006 -0700
   137.3 @@ -6,7 +6,7 @@ INSTALL_DATA	= $(INSTALL) -m0644
   137.4  XEN_ROOT=../..
   137.5  include $(XEN_ROOT)/tools/Rules.mk
   137.6  
   137.7 -CFLAGS  += -Wall -Werror -O3
   137.8 +CFLAGS  += -Werror
   137.9  
  137.10  CFLAGS  += -I $(XEN_XC)
  137.11  CFLAGS  += -I $(XEN_LIBXC)
   138.1 --- a/tools/xentrace/xentrace.c	Tue Mar 14 13:10:21 2006 -0700
   138.2 +++ b/tools/xentrace/xentrace.c	Tue Mar 14 13:50:35 2006 -0700
   138.3 @@ -144,7 +144,7 @@ struct t_buf *map_tbufs(unsigned long tb
   138.4          exit(EXIT_FAILURE);
   138.5      }
   138.6  
   138.7 -    tbufs_mapped = xc_map_foreign_range(xc_handle, 0 /* Dom 0 ID */,
   138.8 +    tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN,
   138.9                                          size * num, PROT_READ | PROT_WRITE,
  138.10                                          tbufs_mfn);
  138.11  
  138.12 @@ -258,7 +258,7 @@ struct t_rec **init_rec_ptrs(struct t_bu
  138.13  /**
  138.14   * get_num_cpus - get the number of logical CPUs
  138.15   */
  138.16 -unsigned int get_num_cpus()
  138.17 +unsigned int get_num_cpus(void)
  138.18  {
  138.19      dom0_op_t op;
  138.20      int xc_handle = xc_interface_open();
   139.1 --- a/tools/xm-test/README	Tue Mar 14 13:10:21 2006 -0700
   139.2 +++ b/tools/xm-test/README	Tue Mar 14 13:50:35 2006 -0700
   139.3 @@ -120,8 +120,9 @@ To run the full test suite, do the follo
   139.4     # ./runtest.sh <logfile>
   139.5  
   139.6  This will run all tests, as well as generate and submit a report at
   139.7 -the end.  All output files will begin with "<logfile>."  If you wish to
   139.8 -prevent submission of a report, add "-d" to the command line like this:
   139.9 +the end. All output files will begin with "<logfile>."
  139.10 +If you wish to prevent submission of a report, add "-d" to the 
  139.11 +command line like this:
  139.12  
  139.13     # ./runtest.sh -d <logfile>
  139.14  
  139.15 @@ -131,15 +132,19 @@ submit the report at a later time.  To d
  139.16  
  139.17     # ./runtest.sh -s <logfile>
  139.18  
  139.19 -For people needing a quick test run instead the full suite, a quick
  139.20 -mode has been added that will attempt to run a representative subset
  139.21 -of tests.  This is not a substitute for the whole suite, but will
  139.22 -verify that some of the major functions of xen and xm are working:
  139.23 +Group test sets are supported in xm-test. This is form of layering of 
  139.24 +tests groups/cases/tests. In the framework directory "grouptest",
  139.25 +files exist for group processing. The user can add groups, casenames
  139.26 +and test lists as required. Default group run is "grouptest/default".
  139.27 +
  139.28 +   # ./runtest.sh -g <groupname> <logfile>
  139.29  
  139.30 -   # ./runtest.sh -q <logfile>
  139.31 +* NOTE: There is a quick set of tests in group mode, that was added to
  139.32 +run certain casenames and tests. It is not a substitute for the full
  139.33 +xm-test test suite.
  139.34 +   # ./runtest.sh -g quick <logfile>
  139.35  
  139.36 -Because of the current structure of the reporting software, submission
  139.37 -of quick test run results is not supported.
  139.38 +
  139.39  
  139.40  It may be desirable to run a specific test group.  This can be
  139.41  accomplished by doing the following:
   140.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   140.2 +++ b/tools/xm-test/grouptest/create	Tue Mar 14 13:50:35 2006 -0700
   140.3 @@ -0,0 +1,1 @@
   140.4 +create
   141.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   141.2 +++ b/tools/xm-test/grouptest/default	Tue Mar 14 13:50:35 2006 -0700
   141.3 @@ -0,0 +1,29 @@
   141.4 +block-create
   141.5 +block-destroy
   141.6 +block-list
   141.7 +console
   141.8 +create
   141.9 +destroy
  141.10 +dmesg
  141.11 +domid
  141.12 +domname
  141.13 +enforce_dom0_cpus
  141.14 +help
  141.15 +info
  141.16 +list
  141.17 +memmax
  141.18 +memset
  141.19 +migrate
  141.20 +network
  141.21 +network-attach
  141.22 +pause
  141.23 +reboot
  141.24 +restore
  141.25 +save
  141.26 +sedf
  141.27 +shutdown
  141.28 +sysrq
  141.29 +unpause
  141.30 +vcpu-disable
  141.31 +vcpu-pin
  141.32 +vtpm
   142.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   142.2 +++ b/tools/xm-test/grouptest/quick	Tue Mar 14 13:50:35 2006 -0700
   142.3 @@ -0,0 +1,4 @@
   142.4 +create 01_create_basic_pos.test 07_create_mem64_pos.test 10_create_fastdestroy.test 14_create_blockroot_pos.test
   142.5 +unpause 01_unpause_basic_pos.test
   142.6 +memset 01_memset_basic_pos.test 03_memset_random_pos.test
   142.7 +help 06_help_allcmds.test
   143.1 --- a/tools/xm-test/lib/XmTestLib/Test.py	Tue Mar 14 13:10:21 2006 -0700
   143.2 +++ b/tools/xm-test/lib/XmTestLib/Test.py	Tue Mar 14 13:50:35 2006 -0700
   143.3 @@ -32,6 +32,7 @@ import pty
   143.4  import select
   143.5  import signal
   143.6  import re
   143.7 +import glob
   143.8  
   143.9  TEST_PASS = 0
  143.10  TEST_FAIL = 255
  143.11 @@ -184,7 +185,16 @@ def isConsoleDead():
  143.12      domain.destroy()
  143.13  
  143.14      return False
  143.15 -    
  143.16 +
  143.17 +#
  143.18 +# We currently can only load as many concurrent HVM domains as loop 
  143.19 +# devices, need to find how many devices the system has.
  143.20 +def getMaxHVMDomains():
  143.21 +    nodes = glob.glob("/dev/loop*")
  143.22 +    maxd = len(nodes)
  143.23 +
  143.24 +    return maxd
  143.25 +
  143.26  
  143.27  if __name__ == "__main__":
  143.28  
   144.1 --- a/tools/xm-test/runtest.sh	Tue Mar 14 13:10:21 2006 -0700
   144.2 +++ b/tools/xm-test/runtest.sh	Tue Mar 14 13:50:35 2006 -0700
   144.3 @@ -1,4 +1,4 @@
   144.4 -#!/bin/sh
   144.5 +#!/bin/sh 
   144.6  
   144.7  ##
   144.8  ## Test driver script
   144.9 @@ -11,7 +11,7 @@ usage() {
  144.10      echo "  Where opts are:"
  144.11      echo "  -d          : do not submit a report for this run"
  144.12      echo "  -b          : do not ask any questions (batch mode)"
  144.13 -    echo "  -q          : run a quick test set"
  144.14 +    echo "  -g          : run a group test set"
  144.15      echo "  -e <email>  : set email address for report"
  144.16      echo "  -s <report> : just submit report <report>"
  144.17      echo "  -h | --help : show this help"
  144.18 @@ -92,12 +92,13 @@ runnable_tests() {
  144.19      echo "Running sanity checks..."
  144.20      make -C tests/_sanity check 2>&1 | grep REASON
  144.21      if [ $? -eq 0 ]; then
  144.22 -	echo "Sanity checks failed"
  144.23 -	exit 1
  144.24 +        echo "Sanity checks failed"
  144.25 +        exit 1
  144.26      fi
  144.27  
  144.28  }
  144.29  
  144.30 +
  144.31  # Get contact info if needed
  144.32  get_contact_info() {
  144.33      
  144.34 @@ -128,26 +129,21 @@ get_contact_info() {
  144.35  
  144.36  # Run the tests
  144.37  run_tests() {
  144.38 -    output=$1
  144.39 -    echo Running real tests...
  144.40 -    TEST_VERBOSE=1 make -k check > $output 2>&1
  144.41 -}
  144.42 -
  144.43 -run_tests_quick() {
  144.44 -
  144.45 -    output=$1
  144.46 +    groupentered=$1
  144.47 +    output=$2
  144.48  
  144.49 -    create_tests="01_create_basic_pos.test 07_create_mem64_pos.test 10_create_fastdestroy.test 14_create_blockroot_pos.test"
  144.50 -    unpause_tests="01_unpause_basic_pos.test"
  144.51 -    memset_tests="01_memset_basic_pos.test 03_memset_random_pos.test"
  144.52 -    help_tests="06_help_allcmds.test"
  144.53 -    testgroups="create unpause memset help"
  144.54 +    exec <  grouptest/$groupentered
  144.55 +    while read casename testlist; do
  144.56 +       echo Running $casename tests...
  144.57 +       echo "*** case $casename from group $groupentered" >> $output
  144.58 +       if [ -z "$testlist" ]; then
  144.59 +          echo "*** Running tests for case $casename" >> $output
  144.60 +          (cd tests/$casename && TEST_VERBOSE=1 make -k check) >> $output 2>&1
  144.61 +       else
  144.62 +          echo "*** Running tests $testlist from case $casename" >> $output
  144.63 +          (cd tests/$casename && TEST_VERBOSE=1 make -k check TESTS="$testlist") >> $output 2>&1
  144.64 +       fi
  144.65  
  144.66 -    echo "*** Quick test" > $output
  144.67 -    for group in $testgroups; do
  144.68 -	eval $(echo list=\$${group}_tests)
  144.69 -	echo "*** Running tests [$list] from $group"
  144.70 -	(cd tests/$group && TEST_VERBOSE=1 make -k check TESTS="$list") >> $output 2>&1
  144.71      done
  144.72  
  144.73  }
  144.74 @@ -195,6 +191,7 @@ MAXFAIL=10
  144.75  report=yes
  144.76  batch=no
  144.77  run=yes
  144.78 +GROUPENTERED=default
  144.79  
  144.80  # Resolve options
  144.81  while [ $# -gt 0 ]
  144.82 @@ -213,8 +210,13 @@ while [ $# -gt 0 ]
  144.83  	  echo $1 > contact_info
  144.84  	  echo "(Email set to $1)"
  144.85  	  ;;
  144.86 -      -q)
  144.87 -	  run=quick
  144.88 +      -g)
  144.89 +	  shift
  144.90 +          GROUPENTERED=$1
  144.91 +          if [ ! -f grouptest/$GROUPENTERED ]; then
  144.92 +             echo "No file for group $GROUPENTERED"
  144.93 +             exit 1
  144.94 +          fi
  144.95  	  ;;
  144.96        -s)
  144.97  	  run=no
  144.98 @@ -265,18 +267,15 @@ fi
  144.99  if [ "$run" != "no" ]; then
 144.100      runnable_tests
 144.101      make_environment_report $OSREPORTTEMP $PROGREPORTTEMP
 144.102 -    if [ "$run" = "yes" ]; then
 144.103 -	run_tests $OUTPUT
 144.104 -    else
 144.105 -	run_tests_quick $OUTPUT
 144.106 -    fi
 144.107 +    run_tests $GROUPENTERED $OUTPUT
 144.108      make_text_reports $PASSFAIL $FAILURES $OUTPUT $TXTREPORT
 144.109      make_result_report $OUTPUT $RESULTREPORTTEMP
 144.110      cat $OSREPORTTEMP $PROGREPORTTEMP $RESULTREPORTTEMP > $XMLREPORT
 144.111      rm $OSREPORTTEMP $PROGREPORTTEMP $RESULTREPORTTEMP
 144.112 +
 144.113  fi
 144.114  
 144.115 -if [ "$report" = "yes" ] && [ "$run" = "yes" ]; then
 144.116 +if [ "$report" = "yes" ]; then
 144.117      if [ ! -f "$XMLREPORT" ]; then
 144.118  	echo "No such file: $XMLREPORT"
 144.119  	exit 1
   145.1 --- a/tools/xm-test/tests/create/11_create_concurrent_pos.py	Tue Mar 14 13:10:21 2006 -0700
   145.2 +++ b/tools/xm-test/tests/create/11_create_concurrent_pos.py	Tue Mar 14 13:50:35 2006 -0700
   145.3 @@ -8,8 +8,14 @@ from XmTestLib import *
   145.4  import time
   145.5  import random
   145.6  
   145.7 -MIN_DOMS    = 10
   145.8 -MAX_DOMS    = 50
   145.9 +if ENABLE_HVM_SUPPORT:
  145.10 +    MAX_DOMS = getMaxHVMDomains()
  145.11 +    if MAX_DOMS > 50:
  145.12 +        MAX_DOMS = 50
  145.13 +else:
  145.14 +    MAX_DOMS = 50
  145.15 +
  145.16 +MIN_DOMS    = 5
  145.17  MEM_PER_DOM = 24
  145.18  
  145.19  domains = []
   146.1 --- a/tools/xm-test/tests/create/13_create_multinic_pos.py	Tue Mar 14 13:10:21 2006 -0700
   146.2 +++ b/tools/xm-test/tests/create/13_create_multinic_pos.py	Tue Mar 14 13:50:35 2006 -0700
   146.3 @@ -5,8 +5,16 @@
   146.4  
   146.5  from XmTestLib import *
   146.6  
   146.7 -for i in range(0,10):
   146.8 -    config = {"vif": ['' for _ in range(0, i)]}
   146.9 +# The current device model, qemu-dm, only supports 8 MAX_NICS currently.
  146.10 +if ENABLE_HVM_SUPPORT:
  146.11 +    MAX_NICS = 8
  146.12 +    nic = "type=ioemu, bridge=xenbr0"
  146.13 +else:
  146.14 +    MAX_NICS = 10
  146.15 +    nic = ''
  146.16 +
  146.17 +for i in range(0,MAX_NICS):
  146.18 +    config = {"vif": [ nic ] * i}
  146.19      domain = XmTestDomain(extraConfig=config)
  146.20  
  146.21      try:
   147.1 --- a/tools/xm-test/tests/list/06_list_nonroot.py	Tue Mar 14 13:10:21 2006 -0700
   147.2 +++ b/tools/xm-test/tests/list/06_list_nonroot.py	Tue Mar 14 13:50:35 2006 -0700
   147.3 @@ -12,4 +12,4 @@ status, output = traceCommand("xm list")
   147.4  eyecatcher = "Error: Most commands need root access"
   147.5  where = output.find(eyecatcher)
   147.6  if where == -1:
   147.7 -    FAIL("xm help: didn't see the root hint, saw %s" % output)
   147.8 +    FAIL("xm list: didn't see the root hint, saw %s" % output)
   148.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.2 +++ b/tools/xm-test/tests/network/03_network_local_tcp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   148.3 @@ -0,0 +1,95 @@
   148.4 +#!/usr/bin/python
   148.5 +
   148.6 +# Copyright (C) International Business Machines Corp., 2006
   148.7 +# Author:  <dykman@us.ibm.com>
   148.8 +
   148.9 +# TCP tests on local interfaces.
  148.10 +#  - creates a single guest domain
  148.11 +#  - sets up a single NIC
  148.12 +#  - conducts hping tcp tests to the local loopback and IP address
  148.13 +
  148.14 +# hping2 127.0.0.1 -c 1 -d $size
  148.15 +# hping2 $local_IP -c 1 -d $size
  148.16 +#   where $size = 1, 48, 64, 512, 1440, 1448, 1500, 1505,
  148.17 +#                 4096, 4192, 32767, 65507, 65508
  148.18 +
  148.19 +
  148.20 +trysizes = [ 1, 48, 64, 512, 1440, 1448, 1500, 1505, 4096, 4192, 
  148.21 +              32767, 65495 ]
  148.22 +
  148.23 +
  148.24 +from XmTestLib import *
  148.25 +rc = 0
  148.26 +
  148.27 +Net = XmNetwork()
  148.28 +
  148.29 +try:
  148.30 +    # read an IP address from the config
  148.31 +    ip   = Net.ip("dom1", "eth0")
  148.32 +    mask = Net.mask("dom1", "eth0")
  148.33 +except NetworkError, e:
  148.34 +    FAIL(str(e))
  148.35 +
  148.36 +# Fire up a guest domain w/1 nic
  148.37 +if ENABLE_HVM_SUPPORT:
  148.38 +    brg = "xenbr0"
  148.39 +    config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
  148.40 +else:
  148.41 +    brg = None
  148.42 +    config = {"vif" : ['ip=%s' % ip]}
  148.43 +
  148.44 +domain = XmTestDomain(extraConfig=config)
  148.45 +try:
  148.46 +    domain.start()
  148.47 +except DomainError, e:
  148.48 +    if verbose:
  148.49 +        print "Failed to create test domain because:"
  148.50 +        print e.extra
  148.51 +    FAIL(str(e))
  148.52 +
  148.53 +
  148.54 +# Attach a console
  148.55 +try:
  148.56 +    console = XmConsole(domain.getName(), historySaveCmds=True)
  148.57 +except ConsoleError, e:
  148.58 +    FAIL(str(e))
  148.59 +
  148.60 +try:
  148.61 +    # Activate the console
  148.62 +    console.sendInput("bhs")
  148.63 +
  148.64 +    # Bring up the "lo" interface.
  148.65 +    console.runCmd("ifconfig lo 127.0.0.1")
  148.66 +
  148.67 +    console.runCmd("ifconfig eth0 inet "+ip+" netmask "+mask+" up")
  148.68 +
  148.69 +    # First do loopback 
  148.70 +    lofails=""
  148.71 +    for size in trysizes:
  148.72 +        out = console.runCmd("hping2 127.0.0.1 -E /dev/urandom -q -c 20 " 
  148.73 +              + "--fast -d " + str(size))
  148.74 +        if out["return"]:
  148.75 +            lofails += " " + str(size)
  148.76 +
  148.77 +    # Next comes eth0
  148.78 +    eth0fails=""
  148.79 +    for size in trysizes:
  148.80 +        out = console.runCmd("hping2 " + ip + " -E /dev/urandom -q -c 20 "
  148.81 +              + "--fast -d "+ str(size))
  148.82 +        if out["return"]:
  148.83 +            eth0fails += " " + str(size) 
  148.84 +except ConsoleError, e:
  148.85 +        FAIL(str(e))
  148.86 +except NetworkError, e:
  148.87 +        FAIL(str(e))
  148.88 +
  148.89 +
  148.90 +# Tally up failures
  148.91 +failures=""
  148.92 +if len(lofails):
  148.93 +        failures += "TCP hping2 over loopback failed for size" + lofails + ". "
  148.94 +if len(eth0fails):
  148.95 +        failures += "TCP hping2 over eth0 failed for size" + eth0fails + "."
  148.96 +if len(failures):
  148.97 +    FAIL(failures)
  148.98 +
   149.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   149.2 +++ b/tools/xm-test/tests/network/04_network_local_udp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   149.3 @@ -0,0 +1,96 @@
   149.4 +#!/usr/bin/python
   149.5 +
   149.6 +# Copyright (C) International Business Machines Corp., 2006
   149.7 +# Author:  <dykman@us.ibm.com>
   149.8 +
   149.9 +# UDP tests on local interfaces.
  149.10 +#  - creates a single guest domain
  149.11 +#  - sets up a single NIC
  149.12 +#  - conducts hping udp tests to the local loopback and IP address
  149.13 +
  149.14 +# hping2 127.0.0.1 -2 -c 1 -d $size
  149.15 +# hping2 $local_IP -2 -c 1 -d $size
  149.16 +#   where $size = 1, 48, 64, 512, 1440, 1448, 1500, 1505,
  149.17 +#                 4096, 4192, 32767, 65507, 65508
  149.18 +
  149.19 +
  149.20 +trysizes = [ 1, 48, 64, 512, 1440, 1448, 1500, 1505, 4096, 4192, 
  149.21 +              32767, 65495 ]
  149.22 +
  149.23 +from XmTestLib import *
  149.24 +rc = 0
  149.25 +
  149.26 +Net = XmNetwork()
  149.27 +
  149.28 +try:
  149.29 +    # read an IP address from the config
  149.30 +    ip   = Net.ip("dom1", "eth0")
  149.31 +    mask = Net.mask("dom1", "eth0")
  149.32 +except NetworkError, e:
  149.33 +    FAIL(str(e))
  149.34 +
  149.35 +# Fire up a guest domain w/1 nic
  149.36 +if ENABLE_HVM_SUPPORT:
  149.37 +    brg = "xenbr0"
  149.38 +    config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
  149.39 +else:
  149.40 +    brg = None
  149.41 +    config = {"vif" : ['ip=%s' % ip]}
  149.42 +
  149.43 +domain = XmTestDomain(extraConfig=config)
  149.44 +try:
  149.45 +    domain.start()
  149.46 +except DomainError, e:
  149.47 +    if verbose:
  149.48 +        print "Failed to create test domain because:"
  149.49 +        print e.extra
  149.50 +    FAIL(str(e))
  149.51 +
  149.52 +
  149.53 +# Attach a console
  149.54 +try:
  149.55 +    console = XmConsole(domain.getName(), historySaveCmds=True)
  149.56 +except ConsoleError, e:
  149.57 +    FAIL(str(e))
  149.58 +
  149.59 +try:
  149.60 +    # Activate the console
  149.61 +    console.sendInput("bhs")
  149.62 +
  149.63 +    # Bring up the "lo" interface.
  149.64 +    console.runCmd("ifconfig lo 127.0.0.1")
  149.65 +
  149.66 +    console.runCmd("ifconfig eth0 inet "+ip+" netmask "+mask+" up")
  149.67 +
  149.68 +    # First do loopback 
  149.69 +    lofails=""
  149.70 +    for size in trysizes:
  149.71 +        out = console.runCmd("hping2 127.0.0.1 -E /dev/urandom -2 -q -c 20 "
  149.72 +              + "--fast -d " + str(size))
  149.73 +        if out["return"]:
  149.74 +            lofails += " " + str(size)
  149.75 +            print out["output"]
  149.76 +
  149.77 +    # Next comes eth0
  149.78 +    eth0fails=""
  149.79 +    for size in trysizes:
  149.80 +        out = console.runCmd("hping2 " + ip + " -E /dev/urandom -2 -q -c 20 "
  149.81 +              + "--fast -d " + str(size))
  149.82 +        if out["return"]:
  149.83 +            eth0fails += " " + str(size) 
  149.84 +            print out["output"]
  149.85 +except ConsoleError, e:
  149.86 +        FAIL(str(e))
  149.87 +except NetworkError, e:
  149.88 +        FAIL(str(e))
  149.89 +
  149.90 +
  149.91 +# Tally up failures
  149.92 +failures=""
  149.93 +if len(lofails):
  149.94 +        failures += "UDP hping2 over loopback failed for size" + lofails + ". "
  149.95 +if len(eth0fails):
  149.96 +        failures += "UDP hping2 over eth0 failed for size" + eth0fails + "."
  149.97 +if len(failures):
  149.98 +    FAIL(failures)
  149.99 +
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/tools/xm-test/tests/network/06_network_dom0_tcp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   150.3 @@ -0,0 +1,81 @@
   150.4 +#!/usr/bin/python
   150.5 +
   150.6 +# Copyright (C) International Business Machines Corp., 2006
   150.7 +# Author:  <dykman@us.ibm.com>
   150.8 +
   150.9 +# TCP tests to dom0.
  150.10 +#  - determines dom0 network
  150.11 +#  - creates a single guest domain
  150.12 +#  - sets up a single NIC on same subnet as dom0
  150.13 +#  - conducts hping2 tcp tests to the dom0 IP address
  150.14 +
  150.15 +# hping2 $dom0_IP -c 1 -d $size
  150.16 +#   where $size = 1, 48, 64, 512, 1440, 1448, 1500, 1505,
  150.17 +#                 4096, 4192, 32767, 65507, 65508
  150.18 +
  150.19 +trysizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192, 
  150.20 +                32767, 65495 ]
  150.21 +
  150.22 +
  150.23 +
  150.24 +from XmTestLib import *
  150.25 +rc = 0
  150.26 +
  150.27 +Net = XmNetwork()
  150.28 +
  150.29 +try:
  150.30 +    # read an IP address from the config
  150.31 +    ip     = Net.ip("dom1", "eth0")
  150.32 +    mask   = Net.mask("dom1", "eth0")
  150.33 +except NetworkError, e:
  150.34 +        FAIL(str(e))
  150.35 +
  150.36 +# Fire up a guest domain w/1 nic
  150.37 +if ENABLE_HVM_SUPPORT:
  150.38 +    brg = "xenbr0"
  150.39 +    config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
  150.40 +else:
  150.41 +    brg = None
  150.42 +    config = {"vif"  : ["ip=%s" % ip]}
  150.43 +
  150.44 +domain = XmTestDomain(extraConfig=config)
  150.45 +try:
  150.46 +    domain.start()
  150.47 +except DomainError, e:
  150.48 +    if verbose:
  150.49 +        print "Failed to create test domain because:"
  150.50 +        print e.extra
  150.51 +    FAIL(str(e))
  150.52 +
  150.53 +
  150.54 +# Attach a console
  150.55 +try:
  150.56 +    console = XmConsole(domain.getName(), historySaveCmds=True)
  150.57 +    # Activate the console
  150.58 +    console.sendInput("bhs")
  150.59 +except ConsoleError, e:
  150.60 +    FAIL(str(e))
  150.61 +
  150.62 +try:
  150.63 +    # Add a suitable dom0 IP address 
  150.64 +    dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0", bridge=brg)
  150.65 +except NetworkError, e:
  150.66 +        FAIL(str(e))
  150.67 +
  150.68 +try:
  150.69 +    console.runCmd("ifconfig eth0 inet "+ip+" netmask "+mask+" up")
  150.70 +
  150.71 +    # Ping dom0
  150.72 +    fails=""
  150.73 +    for size in trysizes:
  150.74 +        out = console.runCmd("hping2 " + dom0ip + " -E /dev/urandom -q -c 20 "
  150.75 +              + "--fast -d " + str(size))
  150.76 +        if out["return"]:
  150.77 +            fails += " " + str(size) 
  150.78 +            print out["output"]
  150.79 +except ConsoleError, e:
  150.80 +        FAIL(str(e))
  150.81 +
  150.82 +if len(fails):
  150.83 +    FAIL("TCP hping2 to dom0 failed for size" + fails + ".")
  150.84 +
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/tools/xm-test/tests/network/07_network_dom0_udp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   151.3 @@ -0,0 +1,81 @@
   151.4 +#!/usr/bin/python
   151.5 +
   151.6 +# Copyright (C) International Business Machines Corp., 2006
   151.7 +# Author:  <dykman@us.ibm.com>
   151.8 +
   151.9 +# UDP tests to dom0.
  151.10 +#  - determines dom0 network
  151.11 +#  - creates a single guest domain
  151.12 +#  - sets up a single NIC on same subnet as dom0
  151.13 +#  - conducts hping2 udp tests to the dom0 IP address
  151.14 +
  151.15 +# hping2 $dom0_IP -2 -c 1 -d $size
  151.16 +#   where $size = 1, 48, 64, 512, 1440, 1448, 1500, 1505,
  151.17 +#                 4096, 4192, 32767, 65507, 65508
  151.18 +
  151.19 +trysizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192, 
  151.20 +                32767, 65495 ]
  151.21 +
  151.22 +
  151.23 +
  151.24 +from XmTestLib import *
  151.25 +rc = 0
  151.26 +
  151.27 +Net = XmNetwork()
  151.28 +
  151.29 +try:
  151.30 +    # read an IP address from the config
  151.31 +    ip     = Net.ip("dom1", "eth0")
  151.32 +    mask   = Net.mask("dom1", "eth0")
  151.33 +except NetworkError, e:
  151.34 +        FAIL(str(e))
  151.35 +
  151.36 +# Fire up a guest domain w/1 nic
  151.37 +if ENABLE_HVM_SUPPORT:
  151.38 +    brg = "xenbr0"
  151.39 +    config = {"vif" : ['type=ioemu, bridge=%s' % brg]}
  151.40 +else:
  151.41 +    brg = None
  151.42 +    config = {"vif"  : ["ip=%s" % ip]}
  151.43 +
  151.44 +domain = XmTestDomain(extraConfig=config)
  151.45 +try:
  151.46 +    domain.start()
  151.47 +except DomainError, e:
  151.48 +    if verbose:
  151.49 +        print "Failed to create test domain because:"
  151.50 +        print e.extra
  151.51 +    FAIL(str(e))
  151.52 +
  151.53 +
  151.54 +# Attach a console
  151.55 +try:
  151.56 +    console = XmConsole(domain.getName(), historySaveCmds=True)
  151.57 +    # Activate the console
  151.58 +    console.sendInput("bhs")
  151.59 +except ConsoleError, e:
  151.60 +    FAIL(str(e))
  151.61 +
  151.62 +try:
  151.63 +    # Add a suitable dom0 IP address 
  151.64 +    dom0ip = Net.ip("dom0", "eth0", todomname=domain.getName(), toeth="eth0", bridge=brg)
  151.65 +except NetworkError, e:
  151.66 +        FAIL(str(e))
  151.67 +
  151.68 +try:
  151.69 +    console.runCmd("ifconfig eth0 inet "+ip+" netmask "+mask+" up")
  151.70 +
  151.71 +    # Ping dom0
  151.72 +    fails=""
  151.73 +    for size in trysizes:
  151.74 +        out = console.runCmd("hping2 " + dom0ip + " -E /dev/urandom -2 -q -c 20"
  151.75 +             + " --fast -d " + str(size))
  151.76 +        if out["return"]:
  151.77 +            fails += " " + str(size) 
  151.78 +            print out["output"]
  151.79 +except ConsoleError, e:
  151.80 +        FAIL(str(e))
  151.81 +
  151.82 +if len(fails):
  151.83 +    FAIL("UDP hping2 to dom0 failed for size" + fails + ".")
  151.84 +
   152.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   152.2 +++ b/tools/xm-test/tests/network/12_network_domU_tcp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   152.3 @@ -0,0 +1,82 @@
   152.4 +#!/usr/bin/python
   152.5 +
   152.6 +# Copyright (C) International Business Machines Corp., 2006
   152.7 +# Author:  <dykman@us.ibm.com>
   152.8 +
   152.9 +# TCP tests to domU interface
  152.10 +#  - creates two guest domains
  152.11 +#  - sets up a single NIC on each on same subnet 
  152.12 +#  - conducts tcp tests to the domU IP address.
  152.13 +
  152.14 +# hping2 $domU_IP -c 1 -d $size 
  152.15 +#   where $size = 1, 48, 64, 512, 1440, 1500, 1505, 
  152.16 +#                 4096, 4192, 32767, 65507, 65508
  152.17 +
  152.18 +pingsizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192, 16384, 24567, 
  152.19 +              32767, 65495 ]
  152.20 +
  152.21 +from XmTestLib import *
  152.22 +
  152.23 +def netDomain(ip):
  152.24 +    if ENABLE_HVM_SUPPORT:
  152.25 +        config = {"vif" : ['type=ioemu']}
  152.26 +    else:
  152.27 +        config = {"vif"  : ["ip=%s" % ip]}
  152.28 +
  152.29 +    dom = XmTestDomain(extraConfig=config)
  152.30 +    try:
  152.31 +        dom.start()
  152.32 +    except DomainError, e:
  152.33 +        if verbose:
  152.34 +            print "Failed to create test domain because:"
  152.35 +            print e.extra
  152.36 +        FAIL(str(e))
  152.37 +    try:
  152.38 +        # Attach a console
  152.39 +        console = XmConsole(dom.getName(), historySaveCmds=True)
  152.40 +        # Activate the console
  152.41 +        console.sendInput("bhs")
  152.42 +    except ConsoleError, e:
  152.43 +        FAIL(str(e))
  152.44 +    return console
  152.45 +    
  152.46 +rc = 0
  152.47 +
  152.48 +Net = XmNetwork()
  152.49 +
  152.50 +try:
  152.51 +    # pick an IP address 
  152.52 +    ip1   = Net.ip("dom1", "eth2")
  152.53 +    mask1 = Net.mask("dom1", "eth2")
  152.54 +except NetworkError, e:
  152.55 +    FAIL(str(e))
  152.56 +
  152.57 +try:
  152.58 +    # pick another IP address 
  152.59 +    ip2   = Net.ip("dom2", "eth2")
  152.60 +    mask2 = Net.mask("dom2", "eth2")
  152.61 +except NetworkError, e:
  152.62 +    FAIL(str(e))
  152.63 +
  152.64 +# Fire up a pair of guest domains w/1 nic each
  152.65 +src_console = netDomain(ip1)
  152.66 +dst_console = netDomain(ip2)
  152.67 +
  152.68 +try:
  152.69 +    src_console.runCmd("ifconfig eth0 inet "+ip1+" netmask "+mask1+" up")
  152.70 +    dst_console.runCmd("ifconfig eth0 inet "+ip2+" netmask "+mask2+" up")
  152.71 +
  152.72 +    # Ping the victim over eth0
  152.73 +    fails=""
  152.74 +    for size in pingsizes:
  152.75 +        out = src_console.runCmd("hping2 " + ip2 + " -E /dev/urandom -q -c 20 "
  152.76 +              + "--fast -d " + str(size))
  152.77 +        if out["return"]:
  152.78 +            fails += " " + str(size) 
  152.79 +            print out["output"]
  152.80 +except ConsoleError, e:
  152.81 +    FAIL(str(e))
  152.82 +
  152.83 +if len(fails):
  152.84 +    FAIL("TCP hping2 failed for size" + fails + ".")
  152.85 +
   153.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   153.2 +++ b/tools/xm-test/tests/network/13_network_domU_udp_pos.py	Tue Mar 14 13:50:35 2006 -0700
   153.3 @@ -0,0 +1,82 @@
   153.4 +#!/usr/bin/python
   153.5 +
   153.6 +# Copyright (C) International Business Machines Corp., 2006
   153.7 +# Author:  <dykman@us.ibm.com>
   153.8 +
   153.9 +# UDP tests to domU interface
  153.10 +#  - creates two guest domains
  153.11 +#  - sets up a single NIC on each on same subnet 
  153.12 +#  - conducts udp tests to the domU IP address.
  153.13 +
  153.14 +# hping2 $domU_IP -2 -c 1 -d $size  
  153.15 +#   where $size = 1, 48, 64, 512, 1440, 1500, 1505, 
  153.16 +#                 4096, 4192, 32767, 65507, 65508
  153.17 +
  153.18 +pingsizes = [ 1, 48, 64, 512, 1440, 1500, 1505, 4096, 4192, 
  153.19 +              32767, 65495 ]
  153.20 +
  153.21 +from XmTestLib import *
  153.22 +
  153.23 +def netDomain(ip):
  153.24 +    if ENABLE_HVM_SUPPORT:
  153.25 +        config = {"vif" : ['type=ioemu']}
  153.26 +    else:
  153.27 +        config = {"vif"  : ["ip=%s" % ip]}
  153.28 +
  153.29 +    dom = XmTestDomain(extraConfig=config)
  153.30 +    try:
  153.31 +        dom.start()
  153.32 +    except DomainError, e:
  153.33 +        if verbose:
  153.34 +            print "Failed to create test domain because:"
  153.35 +            print e.extra
  153.36 +        FAIL(str(e))
  153.37 +    try:
  153.38 +        # Attach a console
  153.39 +        console = XmConsole(dom.getName(), historySaveCmds=True)
  153.40 +        # Activate the console
  153.41 +        console.sendInput("bhs")
  153.42 +    except ConsoleError, e:
  153.43 +        FAIL(str(e))
  153.44 +    return console
  153.45 +    
  153.46 +rc = 0
  153.47 +
  153.48 +Net = XmNetwork()
  153.49 +
  153.50 +try:
  153.51 +    # pick an IP address 
  153.52 +    ip1   = Net.ip("dom1", "eth2")
  153.53 +    mask1 = Net.mask("dom1", "eth2")
  153.54 +except NetworkError, e:
  153.55 +    FAIL(str(e))
  153.56 +
  153.57 +try:
  153.58 +    # pick another IP address 
  153.59 +    ip2   = Net.ip("dom2", "eth2")
  153.60 +    mask2 = Net.mask("dom2", "eth2")
  153.61 +except NetworkError, e:
  153.62 +    FAIL(str(e))
  153.63 +
  153.64 +# Fire up a pair of guest domains w/1 nic each
  153.65 +src_console = netDomain(ip1)
  153.66 +dst_console = netDomain(ip2)
  153.67 +
  153.68 +try:
  153.69 +    src_console.runCmd("ifconfig eth0 inet "+ip1+" netmask "+mask1+" up")
  153.70 +    dst_console.runCmd("ifconfig eth0 inet "+ip2+" netmask "+mask2+" up")
  153.71 +
  153.72 +    # Ping the victim over eth0
  153.73 +    fails=""
  153.74 +    for size in pingsizes:
  153.75 +        out = src_console.runCmd("hping2 " + ip2 + " -E /dev/urandom -2 -q "
  153.76 +              + "-c 20 --fast -d " + str(size))
  153.77 +        if out["return"]:
  153.78 +            fails += " " + str(size) 
  153.79 +            print out["output"]
  153.80 +except ConsoleError, e:
  153.81 +    FAIL(str(e))
  153.82 +
  153.83 +if len(fails):
  153.84 +    FAIL("UDP hping2 failed for size" + fails + ".")
  153.85 +
   154.1 --- a/tools/xm-test/tests/network/Makefile.am	Tue Mar 14 13:10:21 2006 -0700
   154.2 +++ b/tools/xm-test/tests/network/Makefile.am	Tue Mar 14 13:50:35 2006 -0700
   154.3 @@ -1,10 +1,15 @@
   154.4  
   154.5  SUBDIRS =
   154.6 -
   154.7  TESTS = \
   154.8  	02_network_local_ping_pos.test		\
   154.9 +	03_network_local_tcp_pos.test		\
  154.10 +	04_network_local_udp_pos.test		\
  154.11  	05_network_dom0_ping_pos.test		\
  154.12 -	11_network_domU_ping_pos.test
  154.13 +	06_network_dom0_tcp_pos.test		\
  154.14 +	07_network_dom0_udp_pos.test		\
  154.15 +	11_network_domU_ping_pos.test		\
  154.16 +	12_network_domU_tcp_pos.test		\
  154.17 +	13_network_domU_udp_pos.test
  154.18  
  154.19  
  154.20  
   155.1 --- a/tools/xm-test/tests/sedf/01_sedf_multi_pos.py	Tue Mar 14 13:10:21 2006 -0700
   155.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   155.3 @@ -1,28 +0,0 @@
   155.4 -#!/usr/bin/python
   155.5 -
   155.6 -# Copyright (C) International Business Machines Corp., 2005
   155.7 -# Author: Dan Smith <danms@us.ibm.com>
   155.8 -
   155.9 -from XmTestLib import *
  155.10 -
  155.11 -sedf_opts = "20000000 5000000 0 0 0"
  155.12 -
  155.13 -domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  155.14 -
  155.15 -try:
  155.16 -    domain.start()
  155.17 -except DomainError, e:
  155.18 -    if verbose:
  155.19 -        print "Failed to create test domain because:"
  155.20 -        print e.extra
  155.21 -    FAIL(str(e))
  155.22 -
  155.23 -for i in range(5):
  155.24 -    status, output = traceCommand("xm sched-sedf %s %s" % (domain.getName(),
  155.25 -                                                           sedf_opts))
  155.26 -    if status != 0:
  155.27 -        FAIL("[%i] xm sedf returned invalid %i != 0" % (i, status))
  155.28 -
  155.29 -    
  155.30 -    
  155.31 -
   156.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   156.2 +++ b/tools/xm-test/tests/sedf/01_sedf_period_slice_pos.py	Tue Mar 14 13:50:35 2006 -0700
   156.3 @@ -0,0 +1,62 @@
   156.4 +#!/usr/bin/python
   156.5 +
   156.6 +# Copyright (C) International Business Machines Corp., 2005
   156.7 +# Author: Dan Smith <danms@us.ibm.com>
   156.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   156.9 +
  156.10 +from XmTestLib import *
  156.11 +
  156.12 +def get_sedf_params(domain):
  156.13 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  156.14 +    return (status, output.split('\n')[1].split())
  156.15 +
  156.16 +
  156.17 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  156.18 +
  156.19 +try:
  156.20 +    domain.start()
  156.21 +except DomainError, e:
  156.22 +    if verbose:
  156.23 +        print "Failed to create test domain because:"
  156.24 +        print e.extra
  156.25 +    FAIL(str(e))
  156.26 +
  156.27 +# get current param values as baseline
  156.28 +(status, params) = get_sedf_params(domain)
  156.29 +
  156.30 +# check rv
  156.31 +if status != 0:
  156.32 +    FAIL("Getting sedf parameters return non-zero rv (%d)", status)
  156.33 +
  156.34 +# parse out current params
  156.35 +(name, domid, p, s, l, e, w) = params
  156.36 +
  156.37 +# NB: setting period requires non-zero slice 
  156.38 +# scale current period in half
  156.39 +period = str(float(p) / 2)
  156.40 +slice  = str(float(p) / 4)
  156.41 +
  156.42 +opts = "%s -p %s -s %s" %(domain.getName(), period, slice)
  156.43 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  156.44 +
  156.45 +# check rv
  156.46 +if status != 0:
  156.47 +    FAIL("Setting sedf parameters return non-zero rv (%d)" % status)
  156.48 +
  156.49 +# validate 
  156.50 +(s,params) = get_sedf_params(domain)
  156.51 +
  156.52 +# check rv
  156.53 +if s != 0:
  156.54 +    FAIL("Getting sedf parameters return non-zero rv (%d)" % s)
  156.55 +
  156.56 +(name,domid,p1,s1,l1,e1,w1) = params
  156.57 +
  156.58 +if p1 != period:
  156.59 +    FAIL("Failed to change domain period from %f to %f" %(p, period))
  156.60 +
  156.61 +if s1 != slice:
  156.62 +    FAIL("Failed to change domain slice from %f to %f" %(s, slice))
  156.63 +
  156.64 +# Stop the domain (nice shutdown)
  156.65 +domain.stop()
   157.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   157.2 +++ b/tools/xm-test/tests/sedf/02_sedf_period_lower_neg.py	Tue Mar 14 13:50:35 2006 -0700
   157.3 @@ -0,0 +1,44 @@
   157.4 +#!/usr/bin/python
   157.5 +
   157.6 +# Copyright (C) International Business Machines Corp., 2005
   157.7 +# Author: Dan Smith <danms@us.ibm.com>
   157.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   157.9 +#
  157.10 +# Test if sched-sedf <dom> -p <period> handles lower bound 
  157.11 +
  157.12 +from XmTestLib import *
  157.13 +
  157.14 +def get_sedf_params(domain):
  157.15 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  157.16 +    return (status, output.split('\n')[1].split())
  157.17 +
  157.18 +
  157.19 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  157.20 +
  157.21 +try:
  157.22 +    domain.start()
  157.23 +except DomainError, e:
  157.24 +    if verbose:
  157.25 +        print "Failed to create test domain because:"
  157.26 +        print e.extra
  157.27 +    FAIL(str(e))
  157.28 +
  157.29 +# pick bogus period
  157.30 +period = "-1"
  157.31 +
  157.32 +# NB: setting period requires non-zero slice 
  157.33 +# scale current period in half
  157.34 +slice  = "5"
  157.35 +
  157.36 +opts = "%s -p %s -s %s" %(domain.getName(), period, slice)
  157.37 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  157.38 +
  157.39 +# we should see this output from xm 
  157.40 +eyecatcher = "Failed to set sedf parameters"
  157.41 +
  157.42 +# check for failure
  157.43 +if output.find(eyecatcher) >= 0:
  157.44 +    FAIL("sched-sedf let me set bogus period (%s)" %(period))
  157.45 +
  157.46 +# Stop the domain (nice shutdown)
  157.47 +domain.stop()
   158.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   158.2 +++ b/tools/xm-test/tests/sedf/03_sedf_slice_lower_neg.py	Tue Mar 14 13:50:35 2006 -0700
   158.3 @@ -0,0 +1,40 @@
   158.4 +#!/usr/bin/python
   158.5 +
   158.6 +# Copyright (C) International Business Machines Corp., 2005
   158.7 +# Author: Dan Smith <danms@us.ibm.com>
   158.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   158.9 +#
  158.10 +# Test if sched-sedf <dom> -p <period> handles lower bound 
  158.11 +
  158.12 +from XmTestLib import *
  158.13 +
  158.14 +def get_sedf_params(domain):
  158.15 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  158.16 +    return (status, output.split('\n')[1].split())
  158.17 +
  158.18 +
  158.19 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  158.20 +
  158.21 +try:
  158.22 +    domain.start()
  158.23 +except DomainError, e:
  158.24 +    if verbose:
  158.25 +        print "Failed to create test domain because:"
  158.26 +        print e.extra
  158.27 +    FAIL(str(e))
  158.28 +
  158.29 +# pick bogus slice
  158.30 +slice  = "0"
  158.31 +
  158.32 +opts = "%s -s %s" %(domain.getName(), slice)
  158.33 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  158.34 +
  158.35 +# we should see this output from xm 
  158.36 +eyecatcher = "Failed to set sedf parameters"
  158.37 +
  158.38 +# check for failure
  158.39 +if output.find(eyecatcher) >= 0:
  158.40 +    FAIL("sched-sedf let me set bogus slice (%s)" %(slice))
  158.41 +
  158.42 +# Stop the domain (nice shutdown)
  158.43 +domain.stop()
   159.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   159.2 +++ b/tools/xm-test/tests/sedf/04_sedf_slice_upper_neg.py	Tue Mar 14 13:50:35 2006 -0700
   159.3 @@ -0,0 +1,48 @@
   159.4 +#!/usr/bin/python
   159.5 +
   159.6 +# Copyright (C) International Business Machines Corp., 2005
   159.7 +# Author: Dan Smith <danms@us.ibm.com>
   159.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   159.9 +
  159.10 +from XmTestLib import *
  159.11 +
  159.12 +def get_sedf_params(domain):
  159.13 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  159.14 +    return (status, output.split('\n')[1].split())
  159.15 +
  159.16 +
  159.17 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  159.18 +
  159.19 +try:
  159.20 +    domain.start()
  159.21 +except DomainError, e:
  159.22 +    if verbose:
  159.23 +        print "Failed to create test domain because:"
  159.24 +        print e.extra
  159.25 +    FAIL(str(e))
  159.26 +
  159.27 +# get current param values as baseline
  159.28 +(status, params) = get_sedf_params(domain)
  159.29 +
  159.30 +# check rv
  159.31 +if status != 0:
  159.32 +    FAIL("Getting sedf parameters return non-zero rv (%d)", status)
  159.33 +
  159.34 +# parse out current params
  159.35 +(name, domid, p, s, l, e, w) = params
  159.36 +
  159.37 +# set slice > than current period
  159.38 +slice  = str(float(p)+1)
  159.39 +
  159.40 +opts = "%s -s %s" %(domain.getName(), slice)
  159.41 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  159.42 +
  159.43 +# we should see this output from xm 
  159.44 +eyecatcher = "Failed to set sedf parameters"
  159.45 +
  159.46 +# check for failure
  159.47 +if output.find(eyecatcher) >= 0:
  159.48 +    FAIL("sched-sedf let me set a slice bigger than my period.")
  159.49 +
  159.50 +# Stop the domain (nice shutdown)
  159.51 +domain.stop()
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/tools/xm-test/tests/sedf/05_sedf_extratime_pos.py	Tue Mar 14 13:50:35 2006 -0700
   160.3 @@ -0,0 +1,63 @@
   160.4 +#!/usr/bin/python
   160.5 +
   160.6 +# Copyright (C) International Business Machines Corp., 2005
   160.7 +# Author: Dan Smith <danms@us.ibm.com>
   160.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   160.9 +
  160.10 +from XmTestLib import *
  160.11 +
  160.12 +def get_sedf_params(domain):
  160.13 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  160.14 +    return (status, output.split('\n')[1].split())
  160.15 +
  160.16 +
  160.17 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  160.18 +
  160.19 +try:
  160.20 +    domain.start()
  160.21 +except DomainError, e:
  160.22 +    if verbose:
  160.23 +        print "Failed to create test domain because:"
  160.24 +        print e.extra
  160.25 +    FAIL(str(e))
  160.26 +
  160.27 +# get current param values as baseline
  160.28 +(status, params) = get_sedf_params(domain)
  160.29 +
  160.30 +# check rv
  160.31 +if status != 0:
  160.32 +    FAIL("Getting sedf parameters return non-zero rv (%d)", status)
  160.33 +
  160.34 +# parse out current params
  160.35 +(name, domid, p, s, l, e, w) = params
  160.36 +
  160.37 +# toggle extratime value
  160.38 +extratime = str((int(e)+1)%2)
  160.39 +
  160.40 +direction = "disable"
  160.41 +# NB: when disabling extratime(=0), must pass in a slice
  160.42 +opts = "%s -e %s" %(domain.getName(), extratime)
  160.43 +if extratime == "0":
  160.44 +    opts += " -s %s" %( str( (float(p)/2)+1 ) )
  160.45 +    direction = "enable"
  160.46 +    
  160.47 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  160.48 +
  160.49 +# check rv
  160.50 +if status != 0:
  160.51 +   FAIL("Setting sedf parameters return non-zero rv (%d)" % status)
  160.52 +
  160.53 +# validate
  160.54 +(s,params) = get_sedf_params(domain)
  160.55 +
  160.56 +# check rv
  160.57 +if s != 0:
  160.58 +    FAIL("Getting sedf parameters return non-zero rv (%d)" % s)
  160.59 +
  160.60 +(name,domid,p1,s1,l1,e1,w1) = params
  160.61 +
  160.62 +if e1 != extratime:
  160.63 +    FAIL("Failed to %s extratime" %(direction))
  160.64 +
  160.65 +# Stop the domain (nice shutdown)
  160.66 +domain.stop()
   161.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   161.2 +++ b/tools/xm-test/tests/sedf/06_sedf_extratime_disable_neg.py	Tue Mar 14 13:50:35 2006 -0700
   161.3 @@ -0,0 +1,71 @@
   161.4 +#!/usr/bin/python
   161.5 +
   161.6 +# Copyright (C) International Business Machines Corp., 2005
   161.7 +# Author: Dan Smith <danms@us.ibm.com>
   161.8 +# Author: Ryan Harper <ryanh@us.ibm.com>
   161.9 +
  161.10 +from XmTestLib import *
  161.11 +
  161.12 +def get_sedf_params(domain):
  161.13 +    status, output = traceCommand("xm sched-sedf %s" %(domain.getName()))
  161.14 +    return (status, output.split('\n')[1].split())
  161.15 +
  161.16 +
  161.17 +domain = XmTestDomain(extraConfig = {"sched":"sedf"})
  161.18 +
  161.19 +try:
  161.20 +    domain.start()
  161.21 +except DomainError, e:
  161.22 +    if verbose:
  161.23 +        print "Failed to create test domain because:"
  161.24 +        print e.extra
  161.25 +    FAIL(str(e))
  161.26 +
  161.27 +# get current param values as baseline
  161.28 +(status, params) = get_sedf_params(domain)
  161.29 +
  161.30 +# check rv
  161.31 +if status != 0:
  161.32 +    FAIL("Getting sedf parameters return non-zero rv (%d)", status)
  161.33 +
  161.34 +# parse out current params
  161.35 +(name, domid, p, s, l, e, w) = params
  161.36 +
  161.37 +# if extratime is off, turn it on and drop slice to 0
  161.38 +if str(e) == "0":
  161.39 +    extratime = 1
  161.40 +    opts = "%s -e %s" %(domain.getName(), extratime)
  161.41 +    (status, output) = traceCommand("xm sched-sedf %s" %(opts))
  161.42 +
  161.43 +    # check rv
  161.44 +    if status != 0:
  161.45 +        FAIL("Failed to force extratime on (%d)" % status)
  161.46 +
  161.47 +    # drop slice to 0 now that we are in extratime mode
  161.48 +    slice = 0
  161.49 +
  161.50 +    opts = "%s -s %s" %(domain.getName(), slice)
  161.51 +    (status, output) = traceCommand("xm sched-sedf %s" %(opts))
  161.52 +
  161.53 +    # check rv
  161.54 +    if status != 0:
  161.55 +        FAIL("Failed to force slice to 0 (%d)" % status)
  161.56 +
  161.57 +
  161.58 +# ASSERT(extratime=1, slice=0)
  161.59 +
  161.60 +# attempt to disable extratime without setting slice
  161.61 +extratime = "0"
  161.62 +
  161.63 +opts = "%s -e %s " %(domain.getName(), extratime)
  161.64 +(status, output) = traceCommand("xm sched-sedf %s" %(opts))
  161.65 +
  161.66 +# we should see this output from xm 
  161.67 +eyecatcher = "Failed to set sedf parameters"
  161.68 +
  161.69 +# check for failure
  161.70 +if output.find(eyecatcher) >= 0:
  161.71 +    FAIL("sched-sedf let me disable extratime without a non-zero slice")
  161.72 +
  161.73 +# Stop the domain (nice shutdown)
  161.74 +domain.stop()
   162.1 --- a/tools/xm-test/tests/sedf/Makefile.am	Tue Mar 14 13:10:21 2006 -0700
   162.2 +++ b/tools/xm-test/tests/sedf/Makefile.am	Tue Mar 14 13:50:35 2006 -0700
   162.3 @@ -1,7 +1,11 @@
   162.4 -
   162.5  SUBDIRS =
   162.6  
   162.7 -TESTS = 01_sedf_multi_pos.test
   162.8 +TESTS = 01_sedf_period_slice_pos.test \
   162.9 +        02_sedf_period_lower_neg.test \
  162.10 +        03_sedf_slice_lower_neg.test  \
  162.11 +        04_sedf_slice_upper_neg.test  \
  162.12 +        05_sedf_extratime_pos.test    \
  162.13 +        06_sedf_extratime_disable_neg.test
  162.14  
  162.15  XFAIL_TESTS = 
  162.16  
   163.1 --- a/xen/Makefile	Tue Mar 14 13:10:21 2006 -0700
   163.2 +++ b/xen/Makefile	Tue Mar 14 13:50:35 2006 -0700
   163.3 @@ -6,7 +6,7 @@ INSTALL_DIR		= $(INSTALL) -d -m0755
   163.4  # All other places this is stored (eg. compile.h) should be autogenerated.
   163.5  export XEN_VERSION       = 3
   163.6  export XEN_SUBVERSION    = 0
   163.7 -export XEN_EXTRAVERSION  = .0
   163.8 +export XEN_EXTRAVERSION  = -unstable
   163.9  export XEN_FULLVERSION   = $(XEN_VERSION).$(XEN_SUBVERSION)$(XEN_EXTRAVERSION)
  163.10  
  163.11  export BASEDIR          := $(CURDIR)
   164.1 --- a/xen/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
   164.2 +++ b/xen/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
   164.3 @@ -4,7 +4,6 @@
   164.4  # 'make clean' before rebuilding.
   164.5  #
   164.6  verbose     ?= n
   164.7 -debug       ?= n
   164.8  perfc       ?= n
   164.9  perfc_arrays?= n
  164.10  crash_debug ?= n
  164.11 @@ -47,12 +46,7 @@ include $(BASEDIR)/arch/$(TARGET_ARCH)/R
  164.12  
  164.13  CFLAGS += -g -D__XEN__
  164.14  
  164.15 -ifneq ($(debug),y)
  164.16 -CFLAGS += -DNDEBUG
  164.17 -ifeq ($(verbose),y)
  164.18 -CFLAGS += -DVERBOSE
  164.19 -endif
  164.20 -else
  164.21 +ifneq ($(debug)$(verbose),nn)
  164.22  CFLAGS += -DVERBOSE
  164.23  endif
  164.24  
   165.1 --- a/xen/arch/ia64/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
   165.2 +++ b/xen/arch/ia64/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
   165.3 @@ -12,7 +12,7 @@ CPPFLAGS  += -I$(BASEDIR)/include -I$(BA
   165.4  	     -I$(BASEDIR)/include/asm-ia64/linux-null 			\
   165.5               -I$(BASEDIR)/arch/ia64/linux -I$(BASEDIR)/arch/ia64/linux-xen
   165.6  
   165.7 -CFLAGS  := -nostdinc -fno-builtin -fno-common -fno-strict-aliasing
   165.8 +CFLAGS  += -nostdinc -fno-builtin -fno-common -fno-strict-aliasing
   165.9  #CFLAGS  += -O3		# -O3 over-inlines making debugging tough!
  165.10  CFLAGS  += -O2		# but no optimization causes compile errors!
  165.11  #CFLAGS  += -iwithprefix include -Wall -DMONITOR_BASE=$(MONITOR_BASE)
   166.1 --- a/xen/arch/ia64/vmx/vmx_hypercall.c	Tue Mar 14 13:10:21 2006 -0700
   166.2 +++ b/xen/arch/ia64/vmx/vmx_hypercall.c	Tue Mar 14 13:50:35 2006 -0700
   166.3 @@ -22,7 +22,7 @@
   166.4  #include <xen/config.h>
   166.5  #include <xen/errno.h>
   166.6  #include <asm/vmx_vcpu.h>
   166.7 -//#include <public/xen.h>
   166.8 +#include <xen/guest_access.h>
   166.9  #include <public/event_channel.h>
  166.10  #include <asm/vmmu.h>
  166.11  #include <asm/tlb.h>
  166.12 @@ -100,7 +100,7 @@ void hyper_dom0_op(void)
  166.13      VCPU *vcpu=current;
  166.14      u64 r32,ret;
  166.15      vcpu_get_gr_nat(vcpu,16,&r32);
  166.16 -    ret=do_dom0_op((dom0_op_t *)r32);
  166.17 +    ret=do_dom0_op(guest_handle_from_ptr(r32, dom0_op_t));
  166.18      vcpu_set_gr(vcpu, 8, ret, 0);
  166.19  
  166.20      vmx_vcpu_increment_iip(vcpu);
  166.21 @@ -111,7 +111,7 @@ void hyper_event_channel_op(void)
  166.22      VCPU *vcpu=current;
  166.23      u64 r32,ret;
  166.24      vcpu_get_gr_nat(vcpu,16,&r32);
  166.25 -    ret=do_event_channel_op((evtchn_op_t *)r32);
  166.26 +    ret=do_event_channel_op(guest_handle_from_ptr(r32, evtchn_op_t));
  166.27      vcpu_set_gr(vcpu, 8, ret, 0);
  166.28      vmx_vcpu_increment_iip(vcpu);
  166.29  }
  166.30 @@ -122,7 +122,7 @@ void hyper_xen_version(void)
  166.31      u64 r32,r33,ret;
  166.32      vcpu_get_gr_nat(vcpu,16,&r32);
  166.33      vcpu_get_gr_nat(vcpu,17,&r33);
  166.34 -    ret=do_xen_version((int )r32,(void *)r33);
  166.35 +    ret=do_xen_version((int )r32,guest_handle_from_ptr(r33, void));
  166.36      vcpu_set_gr(vcpu, 8, ret, 0);
  166.37      vmx_vcpu_increment_iip(vcpu);
  166.38  }
   167.1 --- a/xen/arch/ia64/xen/hypercall.c	Tue Mar 14 13:10:21 2006 -0700
   167.2 +++ b/xen/arch/ia64/xen/hypercall.c	Tue Mar 14 13:50:35 2006 -0700
   167.3 @@ -10,6 +10,7 @@
   167.4  #include <xen/sched.h>
   167.5  #include <xen/hypercall.h>
   167.6  #include <xen/multicall.h>
   167.7 +#include <xen/guest_access.h>
   167.8  
   167.9  #include <linux/efi.h>	/* FOR EFI_UNIMPLEMENTED */
  167.10  #include <asm/sal.h>	/* FOR struct ia64_sal_retval */
  167.11 @@ -175,7 +176,8 @@ ia64_hypercall (struct pt_regs *regs)
  167.12  			(int) vcpu_get_gr(v,33));
  167.13  		break;
  167.14  	    case __HYPERVISOR_dom0_op:
  167.15 -		regs->r8 = do_dom0_op((struct dom0_op *) regs->r14);
  167.16 +		regs->r8 = do_dom0_op(guest_handle_from_ptr(regs->r14,
  167.17 +							    dom0_op_t));
  167.18  		break;
  167.19  
  167.20  	    case __HYPERVISOR_memory_op:
  167.21 @@ -194,30 +196,30 @@ ia64_hypercall (struct pt_regs *regs)
  167.22  			    regs->r8 = reservation.nr_extents;
  167.23  			break;
  167.24  		    default:
  167.25 -			regs->r8 = do_memory_op((int) regs->r14, (void *)regs->r15);
  167.26 +			regs->r8 = do_memory_op((int) regs->r14, guest_handle_from_ptr(regs->r15, void));
  167.27  			break;
  167.28  		    }
  167.29  		}
  167.30  		break;
  167.31  
  167.32  	    case __HYPERVISOR_event_channel_op:
  167.33 -		regs->r8 = do_event_channel_op((struct evtchn_op *) regs->r14);
  167.34 +		regs->r8 = do_event_channel_op(guest_handle_from_ptr(regs->r14, evtchn_op_t));
  167.35  		break;
  167.36  
  167.37  	    case __HYPERVISOR_grant_table_op:
  167.38 -		regs->r8 = do_grant_table_op((unsigned int) regs->r14, (void *) regs->r15, (unsigned int) regs->r16);
  167.39 +		regs->r8 = do_grant_table_op((unsigned int) regs->r14, guest_handle_from_ptr(regs->r15, void), (unsigned int) regs->r16);
  167.40  		break;
  167.41  
  167.42  	    case __HYPERVISOR_console_io:
  167.43 -		regs->r8 = do_console_io((int) regs->r14, (int) regs->r15, (char *) regs->r16);
  167.44 +		regs->r8 = do_console_io((int) regs->r14, (int) regs->r15, guest_handle_from_ptr(regs->r16, char));
  167.45  		break;
  167.46  
  167.47  	    case __HYPERVISOR_xen_version:
  167.48 -		regs->r8 = do_xen_version((int) regs->r14, (void *) regs->r15);
  167.49 +		regs->r8 = do_xen_version((int) regs->r14, guest_handle_from_ptr(regs->r15, void));
  167.50  		break;
  167.51  
  167.52  	    case __HYPERVISOR_multicall:
  167.53 -		regs->r8 = do_multicall((struct multicall_entry *) regs->r14, (unsigned int) regs->r15);
  167.54 +		regs->r8 = do_multicall(guest_handle_from_ptr(regs->r14, multicall_entry_t), (unsigned int) regs->r15);
  167.55  		break;
  167.56  
  167.57  	    default:
   168.1 --- a/xen/arch/ia64/xen/process.c	Tue Mar 14 13:10:21 2006 -0700
   168.2 +++ b/xen/arch/ia64/xen/process.c	Tue Mar 14 13:50:35 2006 -0700
   168.3 @@ -810,7 +810,6 @@ unsigned long hypercall_create_continuat
   168.4              case 'l':
   168.5                  arg = (unsigned long)va_arg(args, unsigned long);
   168.6                  break;
   168.7 -            case 'p':
   168.8              case 'h':
   168.9                  arg = (unsigned long)va_arg(args, void *);
  168.10                  break;
   169.1 --- a/xen/arch/x86/Rules.mk	Tue Mar 14 13:10:21 2006 -0700
   169.2 +++ b/xen/arch/x86/Rules.mk	Tue Mar 14 13:50:35 2006 -0700
   169.3 @@ -9,15 +9,11 @@ pae ?= n
   169.4  supervisor_mode_kernel ?= n
   169.5  
   169.6  CFLAGS  += -nostdinc -fno-builtin -fno-common -fno-strict-aliasing
   169.7 -CFLAGS  += -iwithprefix include -Wall -Werror -Wno-pointer-arith -pipe
   169.8 +CFLAGS  += -iwithprefix include -Werror -Wno-pointer-arith -pipe
   169.9  CFLAGS  += -I$(BASEDIR)/include 
  169.10  CFLAGS  += -I$(BASEDIR)/include/asm-x86/mach-generic
  169.11  CFLAGS  += -I$(BASEDIR)/include/asm-x86/mach-default
  169.12  
  169.13 -ifneq ($(debug),y)
  169.14 -CFLAGS  += -O3 -fomit-frame-pointer
  169.15 -endif
  169.16 -
  169.17  # Prevent floating-point variables from creeping into Xen.
  169.18  CFLAGS  += -msoft-float
  169.19  
  169.20 @@ -26,19 +22,20 @@ CFLAGS  += $(call test-gcc-flag,$(CC),-n
  169.21  CFLAGS  += $(call test-gcc-flag,$(CC),-fno-stack-protector)
  169.22  CFLAGS  += $(call test-gcc-flag,$(CC),-fno-stack-protector-all)
  169.23  
  169.24 -ifeq ($(TARGET_SUBARCH),x86_32)
  169.25 -CFLAGS  += -m32 -march=i686
  169.26 -LDFLAGS += -m elf_i386 
  169.27 -ifeq ($(pae),y)
  169.28 +ifeq ($(TARGET_SUBARCH)$(pae),x86_32y)
  169.29  CFLAGS  += -DCONFIG_X86_PAE=1
  169.30  endif
  169.31 -endif
  169.32 +
  169.33  ifeq ($(supervisor_mode_kernel),y)
  169.34  CFLAGS  += -DCONFIG_X86_SUPERVISOR_MODE_KERNEL=1
  169.35  endif
  169.36  
  169.37 +ifeq ($(XEN_TARGET_ARCH),x86_32)
  169.38 +LDFLAGS += -m elf_i386 
  169.39 +endif
  169.40 +
  169.41  ifeq ($(TARGET_SUBARCH),x86_64)
  169.42 -CFLAGS  += -m64 -mno-red-zone -fpic -fno-reorder-blocks
  169.43 +CFLAGS  += -mno-red-zone -fpic -fno-reorder-blocks
  169.44  CFLAGS  += -fno-asynchronous-unwind-tables
  169.45  LDFLAGS += -m elf_x86_64
  169.46  endif
   170.1 --- a/xen/arch/x86/apic.c	Tue Mar 14 13:10:21 2006 -0700
   170.2 +++ b/xen/arch/x86/apic.c	Tue Mar 14 13:50:35 2006 -0700
   170.3 @@ -892,9 +892,9 @@ int __init calibrate_APIC_clock(void)
   170.4      return result;
   170.5  }
   170.6  
   170.7 -unsigned int get_apic_bus_scale(void)
   170.8 +u32 get_apic_bus_cycle(void)
   170.9  {
  170.10 -    return bus_scale;
  170.11 +    return bus_cycle;
  170.12  }
  170.13  
  170.14  static unsigned int calibration_result;
   171.1 --- a/xen/arch/x86/audit.c	Tue Mar 14 13:10:21 2006 -0700
   171.2 +++ b/xen/arch/x86/audit.c	Tue Mar 14 13:50:35 2006 -0700
   171.3 @@ -350,7 +350,7 @@ int audit_adjust_pgtables(struct domain 
   171.4          unmap_domain_page(pt);
   171.5      }
   171.6  
   171.7 -    void adjust_shadow_tables()
   171.8 +    void adjust_shadow_tables(void)
   171.9      {
  171.10          struct shadow_status *a;
  171.11          unsigned long smfn, gmfn;
  171.12 @@ -402,7 +402,7 @@ int audit_adjust_pgtables(struct domain 
  171.13          }
  171.14      }
  171.15  
  171.16 -    void adjust_oos_list()
  171.17 +    void adjust_oos_list(void)
  171.18      {
  171.19          struct out_of_sync_entry *oos;
  171.20  
  171.21 @@ -426,7 +426,7 @@ int audit_adjust_pgtables(struct domain 
  171.22          }
  171.23      }
  171.24  
  171.25 -    void adjust_for_pgtbase()
  171.26 +    void adjust_for_pgtbase(void)
  171.27      {
  171.28          struct vcpu *v;
  171.29  
  171.30 @@ -443,7 +443,7 @@ int audit_adjust_pgtables(struct domain 
  171.31          }
  171.32      }
  171.33  
  171.34 -    void adjust_guest_pages()
  171.35 +    void adjust_guest_pages(void)
  171.36      {
  171.37          struct list_head *list_ent = d->page_list.next;
  171.38          struct page_info *page;
   172.1 --- a/xen/arch/x86/dom0_ops.c	Tue Mar 14 13:10:21 2006 -0700
   172.2 +++ b/xen/arch/x86/dom0_ops.c	Tue Mar 14 13:50:35 2006 -0700
   172.3 @@ -458,7 +458,7 @@ void arch_getdomaininfo_ctxt(
   172.4  {
   172.5      memcpy(c, &v->arch.guest_context, sizeof(*c));
   172.6  
   172.7 -    if ( HVM_DOMAIN(v) )
   172.8 +    if ( hvm_guest(v) )
   172.9      {
  172.10          hvm_store_cpu_guest_regs(v, &c->user_regs);
  172.11          hvm_store_cpu_guest_ctrl_regs(v, c->ctrlreg);
  172.12 @@ -473,9 +473,9 @@ void arch_getdomaininfo_ctxt(
  172.13      c->flags = 0;
  172.14      if ( test_bit(_VCPUF_fpu_initialised, &v->vcpu_flags) )
  172.15          c->flags |= VGCF_I387_VALID;
  172.16 -    if ( KERNEL_MODE(v, &v->arch.guest_context.user_regs) )
  172.17 +    if ( guest_kernel_mode(v, &v->arch.guest_context.user_regs) )
  172.18          c->flags |= VGCF_IN_KERNEL;
  172.19 -    if ( HVM_DOMAIN(v) )
  172.20 +    if ( hvm_guest(v) )
  172.21          c->flags |= VGCF_HVM_GUEST;
  172.22  
  172.23      c->ctrlreg[3] = pagetable_get_paddr(v->arch.guest_table);
   173.1 --- a/xen/arch/x86/domain.c	Tue Mar 14 13:10:21 2006 -0700
   173.2 +++ b/xen/arch/x86/domain.c	Tue Mar 14 13:50:35 2006 -0700
   173.3 @@ -312,7 +312,8 @@ int arch_domain_create(struct domain *d)
   173.4              goto fail_nomem;
   173.5  
   173.6          memset(d->shared_info, 0, PAGE_SIZE);
   173.7 -        SHARE_PFN_WITH_DOMAIN(virt_to_page(d->shared_info), d);
   173.8 +        share_xen_page_with_guest(
   173.9 +            virt_to_page(d->shared_info), d, XENSHARE_writable);
  173.10      }
  173.11  
  173.12      return 0;
  173.13 @@ -451,6 +452,43 @@ int arch_set_info_guest(
  173.14      return 0;
  173.15  }
  173.16  
  173.17 +long
  173.18 +arch_do_vcpu_op(
  173.19 +    int cmd, struct vcpu *v, GUEST_HANDLE(void) arg)
  173.20 +{
  173.21 +    long rc = 0;
  173.22 +
  173.23 +    switch ( cmd )
  173.24 +    {
  173.25 +    case VCPUOP_register_runstate_memory_area:
  173.26 +    {
  173.27 +        struct vcpu_register_runstate_memory_area area;
  173.28 +
  173.29 +        rc = -EINVAL;
  173.30 +        if ( v != current )
  173.31 +            break;
  173.32 +
  173.33 +        rc = -EFAULT;
  173.34 +        if ( copy_from_guest(&area, arg, 1) )
  173.35 +            break;
  173.36 +
  173.37 +        if ( !access_ok(area.addr.v, sizeof(*area.addr.v)) )
  173.38 +            break;
  173.39 +
  173.40 +        rc = 0;
  173.41 +        v->runstate_guest = area.addr.v;
  173.42 +        __copy_to_user(v->runstate_guest, &v->runstate, sizeof(v->runstate));
  173.43 +
  173.44 +        break;
  173.45 +    }
  173.46 +
  173.47 +    default:
  173.48 +        rc = -ENOSYS;
  173.49 +        break;
  173.50 +    }
  173.51 +
  173.52 +    return rc;
  173.53 +}
  173.54  
  173.55  void new_thread(struct vcpu *d,
  173.56                  unsigned long start_pc,
  173.57 @@ -682,7 +720,7 @@ static void __context_switch(void)
  173.58                 stack_regs,
  173.59                 CTXT_SWITCH_STACK_BYTES);
  173.60          unlazy_fpu(p);
  173.61 -        if ( !HVM_DOMAIN(p) )
  173.62 +        if ( !hvm_guest(p) )
  173.63          {
  173.64              save_segments(p);
  173.65          }
  173.66 @@ -711,7 +749,7 @@ static void __context_switch(void)
  173.67              loaddebug(&n->arch.guest_context, 7);
  173.68          }
  173.69  
  173.70 -        if ( !HVM_DOMAIN(n) )
  173.71 +        if ( !hvm_guest(n) )
  173.72          {
  173.73              set_int80_direct_trap(n);
  173.74              switch_kernel_stack(n, cpu);
  173.75 @@ -775,7 +813,7 @@ void context_switch(struct vcpu *prev, s
  173.76          /* Re-enable interrupts before restoring state which may fault. */
  173.77          local_irq_enable();
  173.78  
  173.79 -        if ( !HVM_DOMAIN(next) )
  173.80 +        if ( !hvm_guest(next) )
  173.81          {
  173.82              load_LDT(next);
  173.83              load_segments(next);
  173.84 @@ -831,7 +869,6 @@ void sync_vcpu_execstate(struct vcpu *v)
  173.85      {                                                                       \
  173.86      case 'i': __arg = (unsigned long)va_arg(args, unsigned int);  break;    \
  173.87      case 'l': __arg = (unsigned long)va_arg(args, unsigned long); break;    \
  173.88 -    case 'p': __arg = (unsigned long)va_arg(args, void *);        break;    \
  173.89      case 'h': __arg = (unsigned long)va_arg(args, void *);        break;    \
  173.90      default:  __arg = 0; BUG();                                             \
  173.91      }                                                                       \
  173.92 @@ -994,7 +1031,7 @@ void domain_relinquish_resources(struct 
  173.93              v->arch.guest_table_user = mk_pagetable(0);
  173.94          }
  173.95  
  173.96 -        if ( HVM_DOMAIN(v) )
  173.97 +        if ( hvm_guest(v) )
  173.98              hvm_relinquish_guest_resources(v);
  173.99      }
 173.100  
   174.1 --- a/xen/arch/x86/hvm/hvm.c	Tue Mar 14 13:10:21 2006 -0700
   174.2 +++ b/xen/arch/x86/hvm/hvm.c	Tue Mar 14 13:50:35 2006 -0700
   174.3 @@ -186,7 +186,7 @@ void hvm_setup_platform(struct domain* d
   174.4  {
   174.5      struct hvm_domain *platform;
   174.6  
   174.7 -    if ( !HVM_DOMAIN(current) || (current->vcpu_id != 0) )
   174.8 +    if ( !hvm_guest(current) || (current->vcpu_id != 0) )
   174.9          return;
  174.10  
  174.11      shadow_direct_map_init(d);
  174.12 @@ -205,12 +205,10 @@ void hvm_setup_platform(struct domain* d
  174.13      }
  174.14  }
  174.15  
  174.16 -void pic_irq_request(int *interrupt_request, int level)
  174.17 +void pic_irq_request(void *data, int level)
  174.18  {
  174.19 -    if (level)
  174.20 -        *interrupt_request = 1;
  174.21 -    else
  174.22 -        *interrupt_request = 0;
  174.23 +    int *interrupt_request = data;
  174.24 +    *interrupt_request = level;
  174.25  }
  174.26  
  174.27  void hvm_pic_assist(struct vcpu *v)
  174.28 @@ -324,7 +322,7 @@ int hvm_bringup_ap(int vcpuid, int tramp
  174.29      int rc = 0;
  174.30  
  174.31      /* current must be HVM domain BSP */
  174.32 -    if ( !(HVM_DOMAIN(bsp) && bsp->vcpu_id == 0) ) {
  174.33 +    if ( !(hvm_guest(bsp) && bsp->vcpu_id == 0) ) {
  174.34          printk("Not calling hvm_bringup_ap from BSP context.\n");
  174.35          domain_crash_synchronous();
  174.36      }
   175.1 --- a/xen/arch/x86/hvm/i8259.c	Tue Mar 14 13:10:21 2006 -0700
   175.2 +++ b/xen/arch/x86/hvm/i8259.c	Tue Mar 14 13:50:35 2006 -0700
   175.3 @@ -407,7 +407,7 @@ static void pic_init1(int io_addr, int e
   175.4      pic_reset(s);
   175.5  }
   175.6  
   175.7 -void pic_init(struct hvm_virpic *s, void (*irq_request)(), 
   175.8 +void pic_init(struct hvm_virpic *s, void (*irq_request)(void *, int),
   175.9                void *irq_request_opaque)
  175.10  {
  175.11      memset(s, 0, sizeof(*s));
  175.12 @@ -422,7 +422,8 @@ void pic_init(struct hvm_virpic *s, void
  175.13      return; 
  175.14  }
  175.15  
  175.16 -void pic_set_alt_irq_func(struct hvm_virpic *s, void (*alt_irq_func)(),
  175.17 +void pic_set_alt_irq_func(struct hvm_virpic *s,
  175.18 +                          void (*alt_irq_func)(void *, int, int),
  175.19                            void *alt_irq_opaque)
  175.20  {
  175.21      s->alt_irq_func = alt_irq_func;
   176.1 --- a/xen/arch/x86/hvm/svm/intr.c	Tue Mar 14 13:10:21 2006 -0700
   176.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Tue Mar 14 13:50:35 2006 -0700
   176.3 @@ -187,7 +187,7 @@ asmlinkage void svm_intr_assist(void)
   176.4              }
   176.5              /* let's inject this interrupt */
   176.6              TRACE_3D(TRC_VMX_INT, v->domain->domain_id, intr_vector, 0);
   176.7 -            svm_inject_extint(v, intr_vector, VMX_INVALID_ERROR_CODE);
   176.8 +            svm_inject_extint(v, intr_vector, VMX_DELIVER_NO_ERROR_CODE);
   176.9              interrupt_post_injection(v, intr_vector, intr_type);
  176.10              break;
  176.11          case VLAPIC_DELIV_MODE_SMI:
   177.1 --- a/xen/arch/x86/hvm/svm/x86_64/exits.S	Tue Mar 14 13:10:21 2006 -0700
   177.2 +++ b/xen/arch/x86/hvm/svm/x86_64/exits.S	Tue Mar 14 13:50:35 2006 -0700
   177.3 @@ -157,6 +157,7 @@ svm_test_all_events:
   177.4          jnz   svm_process_softirqs
   177.5  svm_restore_all_guest:
   177.6          call svm_intr_assist
   177.7 +        call svm_asid
   177.8          call svm_load_cr2
   177.9          sti
  177.10          /*
   178.1 --- a/xen/arch/x86/hvm/vlapic.c	Tue Mar 14 13:10:21 2006 -0700
   178.2 +++ b/xen/arch/x86/hvm/vlapic.c	Tue Mar 14 13:50:35 2006 -0700
   178.3 @@ -37,7 +37,9 @@
   178.4  /* XXX remove this definition after GFW enabled */
   178.5  #define VLAPIC_NO_BIOS
   178.6  
   178.7 -extern unsigned int get_apic_bus_scale(void);
   178.8 +extern u32 get_apic_bus_cycle(void);
   178.9 +
  178.10 +#define APIC_BUS_CYCLE_NS (((s_time_t)get_apic_bus_cycle()) / 1000)
  178.11  
  178.12  static unsigned int vlapic_lvt_mask[VLAPIC_LVT_NUM] =
  178.13  {
  178.14 @@ -50,7 +52,8 @@ int vlapic_find_highest_irr(struct vlapi
  178.15  
  178.16      result = find_highest_bit((uint32_t *)&vlapic->irr[0], INTR_LEN_32);
  178.17  
  178.18 -    if (result != -1 && result < 16) {
  178.19 +    if ( result != -1 && result < 16 )
  178.20 +    {
  178.21          printk("VLAPIC: irr on reserved bits %d\n ", result);
  178.22          domain_crash_synchronous();
  178.23      }
  178.24 @@ -78,10 +81,11 @@ int vlapic_find_highest_isr(struct vlapi
  178.25  
  178.26      result = find_highest_bit((uint32_t *)&vlapic->isr[0], INTR_LEN_32);
  178.27  
  178.28 -    if (result != -1 && result < 16) {
  178.29 +    if ( result != -1 && result < 16 )
  178.30 +    {
  178.31          int i = 0;
  178.32          printk("VLAPIC: isr on reserved bits %d, isr is\n ", result);
  178.33 -        for (i = 0; i < INTR_LEN_32; i += 2)
  178.34 +        for ( i = 0; i < INTR_LEN_32; i += 2 )
  178.35              printk("%d: 0x%08x%08x\n", i, vlapic->isr[i], vlapic->isr[i+1]);
  178.36          return -1;
  178.37      }
  178.38 @@ -97,12 +101,12 @@ uint32_t vlapic_update_ppr(struct vlapic
  178.39      tpr = (vlapic->task_priority >> 4) & 0xf;      /* we want 7:4 */
  178.40  
  178.41      isr = vlapic_find_highest_isr(vlapic);
  178.42 -    if (isr != -1)
  178.43 +    if ( isr != -1 )
  178.44          isrv = (isr >> 4) & 0xf;   /* ditto */
  178.45      else
  178.46          isrv = 0;
  178.47  
  178.48 -    if (tpr >= isrv)
  178.49 +    if ( tpr >= isrv )
  178.50          ppr = vlapic->task_priority & 0xff;
  178.51      else
  178.52          ppr = isrv << 4;  /* low 4 bits of PPR have to be cleared */
  178.53 @@ -110,7 +114,7 @@ uint32_t vlapic_update_ppr(struct vlapic
  178.54      vlapic->processor_priority = ppr;
  178.55  
  178.56      HVM_DBG_LOG(DBG_LEVEL_VLAPIC_INTERRUPT,
  178.57 -                "vlapic_update_ppr: vlapic %p ppr %x isr %x isrv %x",
  178.58 +                "vlapic %p, ppr 0x%x, isr 0x%x, isrv 0x%x.",
  178.59                  vlapic, ppr, isr, isrv);
  178.60  
  178.61      return ppr;
  178.62 @@ -124,46 +128,52 @@ static int vlapic_match_dest(struct vcpu
  178.63      int result = 0;
  178.64      struct vlapic *target = VLAPIC(v);
  178.65  
  178.66 -    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_match_dest: "
  178.67 -                "target %p source %p dest %x dest_mode %x short_hand %x "
  178.68 -                "delivery_mode %x",
  178.69 +    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "target %p, source %p, dest 0x%x, "
  178.70 +                "dest_mode 0x%x, short_hand 0x%x, delivery_mode 0x%x.",
  178.71                  target, source, dest, dest_mode, short_hand, delivery_mode);
  178.72  
  178.73 -    if ( unlikely(!target) &&
  178.74 -         ( (delivery_mode != VLAPIC_DELIV_MODE_INIT) &&
  178.75 -           (delivery_mode != VLAPIC_DELIV_MODE_STARTUP) &&
  178.76 -           (delivery_mode != VLAPIC_DELIV_MODE_NMI) )) {
  178.77 -        HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_match_dest "
  178.78 -                    "uninitialized target v %p delivery_mode %x dest %x\n",
  178.79 -                    v, delivery_mode, dest); 
  178.80 -        return result; 
  178.81 +    if ( unlikely(target == NULL) &&
  178.82 +         ((delivery_mode != VLAPIC_DELIV_MODE_INIT) &&
  178.83 +          (delivery_mode != VLAPIC_DELIV_MODE_STARTUP) &&
  178.84 +          (delivery_mode != VLAPIC_DELIV_MODE_NMI)) )
  178.85 +    {
  178.86 +        HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "uninitialized target vcpu %p, "
  178.87 +                    "delivery_mode 0x%x, dest 0x%x.\n", v, delivery_mode, dest);
  178.88 +        return result;
  178.89      }
  178.90  
  178.91 -    switch (short_hand) {
  178.92 +    switch ( short_hand ) {
  178.93      case VLAPIC_NO_SHORTHAND:
  178.94 -        if (!dest_mode) {   /* Physical */
  178.95 -            result = ((target ? target->id : v->vcpu_id ) == dest);
  178.96 -        } else {            /* Logical */
  178.97 -            if (!target) 
  178.98 +        if ( !dest_mode )   /* Physical */
  178.99 +        {
 178.100 +            result = (target != NULL ? target->id : v->vcpu_id) == dest;
 178.101 +        }
 178.102 +        else                /* Logical */
 178.103 +        {
 178.104 +            if ( target == NULL )
 178.105                  break;
 178.106 -            if (((target->dest_format >> 28) & 0xf) == 0xf) {   /* Flat mode */
 178.107 +            if ( ((target->dest_format >> 28) & 0xf) == 0xf )   /* Flat mode */
 178.108 +            {
 178.109                  result = (target->logical_dest >> 24) & dest;
 178.110 -            } else {
 178.111 -                if ((delivery_mode == VLAPIC_DELIV_MODE_LPRI) &&
 178.112 -                   (dest == 0xff)) {
 178.113 +            }
 178.114 +            else
 178.115 +            {
 178.116 +                if ( (delivery_mode == VLAPIC_DELIV_MODE_LPRI) &&
 178.117 +                     (dest == 0xff) )
 178.118 +                {
 178.119                      /* What shall we do now? */
 178.120                      printk("Broadcast IPI with lowest priority "
 178.121                             "delivery mode\n");
 178.122                      domain_crash_synchronous();
 178.123                  }
 178.124                  result = (target->logical_dest == (dest & 0xf)) ?
 178.125 -                  ((target->logical_dest >> 4) & (dest >> 4)) : 0;
 178.126 +                         ((target->logical_dest >> 4) & (dest >> 4)) : 0;
 178.127              }
 178.128          }
 178.129          break;
 178.130  
 178.131      case VLAPIC_SHORTHAND_SELF:
 178.132 -        if (target == source)
 178.133 +        if ( target == source )
 178.134              result = 1;
 178.135          break;
 178.136  
 178.137 @@ -172,7 +182,7 @@ static int vlapic_match_dest(struct vcpu
 178.138          break;
 178.139  
 178.140      case VLAPIC_SHORTHAND_EXCLUDE_SELF:
 178.141 -        if (target != source)
 178.142 +        if ( target != source )
 178.143              result = 1;
 178.144          break;
 178.145  
 178.146 @@ -190,27 +200,30 @@ static int vlapic_match_dest(struct vcpu
 178.147  static int vlapic_accept_irq(struct vcpu *v, int delivery_mode,
 178.148                               int vector, int level, int trig_mode)
 178.149  {
 178.150 -    int	result = 0;
 178.151 +    int result = 0;
 178.152      struct vlapic *vlapic = VLAPIC(v);
 178.153  
 178.154 -    switch (delivery_mode) {
 178.155 +    switch ( delivery_mode ) {
 178.156      case VLAPIC_DELIV_MODE_FIXED:
 178.157      case VLAPIC_DELIV_MODE_LPRI:
 178.158          /* FIXME add logic for vcpu on reset */
 178.159 -        if (unlikely(!vlapic || !vlapic_enabled(vlapic)))
 178.160 -            return result;
 178.161 +        if ( unlikely(vlapic == NULL || !vlapic_enabled(vlapic)) )
 178.162 +            break;
 178.163  
 178.164 -        if (test_and_set_bit(vector, &vlapic->irr[0])) {
 178.165 +        if ( test_and_set_bit(vector, &vlapic->irr[0]) )
 178.166 +        {
 178.167              printk("<vlapic_accept_irq>"
 178.168 -                    "level trig mode repeatedly for vector %d\n", vector);
 178.169 -            result = 0;
 178.170 -        } else {
 178.171 -            if (level) {
 178.172 -                printk("<vlapic_accept_irq> level trig mode for vector %d\n", vector);
 178.173 -                set_bit(vector, &vlapic->tmr[0]);
 178.174 -            }
 178.175 +                   "level trig mode repeatedly for vector %d\n", vector);
 178.176 +            break;
 178.177          }
 178.178 -        evtchn_set_pending(vlapic->vcpu, iopacket_port(vlapic->vcpu));
 178.179 +
 178.180 +        if ( level )
 178.181 +        {
 178.182 +            printk("<vlapic_accept_irq> level trig mode for vector %d\n",
 178.183 +                   vector);
 178.184 +            set_bit(vector, &vlapic->tmr[0]);
 178.185 +        }
 178.186 +        evtchn_set_pending(v, iopacket_port(v));
 178.187          result = 1;
 178.188          break;
 178.189  
 178.190 @@ -225,11 +238,13 @@ static int vlapic_accept_irq(struct vcpu
 178.191          break;
 178.192  
 178.193      case VLAPIC_DELIV_MODE_INIT:
 178.194 -        if ( !level && trig_mode == 1 ) {        //Deassert
 178.195 +        if ( !level && trig_mode == 1 )     //Deassert
 178.196              printk("This hvm_vlapic is for P4, no work for De-assert init\n");
 178.197 -        } else {
 178.198 +        else
 178.199 +        {
 178.200              /* FIXME How to check the situation after vcpu reset? */
 178.201 -            if ( test_and_clear_bit(_VCPUF_initialised, &v->vcpu_flags) ) {
 178.202 +            if ( test_and_clear_bit(_VCPUF_initialised, &v->vcpu_flags) )
 178.203 +            {
 178.204                  printk("Reset hvm vcpu not supported yet\n");
 178.205                  domain_crash_synchronous();
 178.206              }
 178.207 @@ -247,7 +262,8 @@ static int vlapic_accept_irq(struct vcpu
 178.208          v->arch.hvm_vcpu.init_sipi_sipi_state =
 178.209                  HVM_VCPU_INIT_SIPI_SIPI_STATE_NORM;
 178.210  
 178.211 -        if ( test_bit(_VCPUF_initialised, &v->vcpu_flags) ) {
 178.212 +        if ( test_bit(_VCPUF_initialised, &v->vcpu_flags) )
 178.213 +        {
 178.214              printk("SIPI for initialized vcpu vcpuid %x\n", v->vcpu_id);
 178.215              domain_crash_synchronous();
 178.216          }
 178.217 @@ -257,7 +273,7 @@ static int vlapic_accept_irq(struct vcpu
 178.218          break;
 178.219  
 178.220      default:
 178.221 -        printk("TODO: not support interrup type %x\n", delivery_mode);
 178.222 +        printk("TODO: not support interrupt type %x\n", delivery_mode);
 178.223          domain_crash_synchronous();
 178.224          break;
 178.225      }
 178.226 @@ -276,13 +292,15 @@ struct vlapic* apic_round_robin(struct d
 178.227      int next, old;
 178.228      struct vlapic* target = NULL;
 178.229  
 178.230 -    if (dest_mode == 0) { //Physical mode
 178.231 -        printk("<apic_round_robin> lowest priority for physical mode\n");
 178.232 +    if ( dest_mode == 0 )   //Physical mode
 178.233 +    {
 178.234 +        printk("<apic_round_robin> lowest priority for physical mode.\n");
 178.235          return NULL;
 178.236      }
 178.237  
 178.238 -    if (!bitmap) {
 178.239 -        printk("<apic_round_robin> no bit on bitmap\n");
 178.240 +    if ( !bitmap )
 178.241 +    {
 178.242 +        printk("<apic_round_robin> no bit set in bitmap.\n");
 178.243          return NULL;
 178.244      }
 178.245  
 178.246 @@ -292,10 +310,12 @@ struct vlapic* apic_round_robin(struct d
 178.247  
 178.248      do {
 178.249          /* the vcpu array is arranged according to vcpu_id */
 178.250 -        if (test_bit(next, &bitmap)) {
 178.251 +        if ( test_bit(next, &bitmap) )
 178.252 +        {
 178.253              target = d->vcpu[next]->arch.hvm_vcpu.vlapic;
 178.254  
 178.255 -            if (!target || !vlapic_enabled(target)) {
 178.256 +            if ( target == NULL || !vlapic_enabled(target) )
 178.257 +            {
 178.258                  printk("warning: targe round robin local apic disabled\n");
 178.259                  /* XXX should we domain crash?? Or should we return NULL */
 178.260              }
 178.261 @@ -303,49 +323,48 @@ struct vlapic* apic_round_robin(struct d
 178.262          }
 178.263  
 178.264          next ++;
 178.265 -        if (!d->vcpu[next] ||
 178.266 -            !test_bit(_VCPUF_initialised, &d->vcpu[next]->vcpu_flags) ||
 178.267 -            next == MAX_VIRT_CPUS)
 178.268 +        if ( !d->vcpu[next] ||
 178.269 +             !test_bit(_VCPUF_initialised, &d->vcpu[next]->vcpu_flags) ||
 178.270 +             next == MAX_VIRT_CPUS )
 178.271              next = 0;
 178.272 -    }while(next != old);
 178.273 +    } while ( next != old );
 178.274  
 178.275      d->arch.hvm_domain.round_info[vector] = next;
 178.276      spin_unlock(&d->arch.hvm_domain.round_robin_lock);
 178.277 +
 178.278      return target;
 178.279  }
 178.280  
 178.281 -void
 178.282 -vlapic_EOI_set(struct vlapic *vlapic)
 178.283 +void vlapic_EOI_set(struct vlapic *vlapic)
 178.284  {
 178.285      int vector = vlapic_find_highest_isr(vlapic);
 178.286  
 178.287      /* Not every write EOI will has correpsoning ISR,
 178.288         one example is when Kernel check timer on setup_IO_APIC */
 178.289 -    if (vector == -1) {
 178.290 +    if ( vector == -1 )
 178.291          return ;
 178.292 -    }
 178.293  
 178.294 -    vlapic_clear_isr(vlapic, vector);
 178.295 +    clear_bit(vector, &vlapic->isr[0]);
 178.296      vlapic_update_ppr(vlapic);
 178.297  
 178.298 -    if (test_and_clear_bit(vector, &vlapic->tmr[0]))
 178.299 +    if ( test_and_clear_bit(vector, &vlapic->tmr[0]) )
 178.300          ioapic_update_EOI(vlapic->domain, vector);
 178.301  }
 178.302  
 178.303  int vlapic_check_vector(struct vlapic *vlapic,
 178.304                          unsigned char dm, int vector)
 178.305  {
 178.306 -    if ((dm == VLAPIC_DELIV_MODE_FIXED) && (vector < 16)) {
 178.307 +    if ( (dm == VLAPIC_DELIV_MODE_FIXED) && (vector < 16) )
 178.308 +    {
 178.309          vlapic->err_status |= 0x40;
 178.310          vlapic_accept_irq(vlapic->vcpu, VLAPIC_DELIV_MODE_FIXED,
 178.311 -          vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), 0, 0);
 178.312 -        printk("<vlapic_check_vector>: check fail\n");
 178.313 +                          vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), 0, 0);
 178.314 +        printk("<vlapic_check_vector>: check failed.\n");
 178.315          return 0;
 178.316      }
 178.317      return 1;
 178.318  }
 178.319  
 178.320 -
 178.321  void vlapic_ipi(struct vlapic *vlapic)
 178.322  {
 178.323      unsigned int dest = (vlapic->icr_high >> 24) & 0xff;
 178.324 @@ -360,68 +379,47 @@ void vlapic_ipi(struct vlapic *vlapic)
 178.325      struct vcpu *v = NULL;
 178.326      uint32_t lpr_map;
 178.327  
 178.328 -    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_ipi: "
 178.329 -                "icr_high %x icr_low %x "
 178.330 -                "short_hand %x dest %x trig_mode %x level %x "
 178.331 -                "dest_mode %x delivery_mode %x vector %x",
 178.332 -                vlapic->icr_high, vlapic->icr_low,
 178.333 -                short_hand, dest, trig_mode, level, dest_mode,
 178.334 -                delivery_mode, vector);
 178.335 +    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "icr_high 0x%x, icr_low 0x%x, "
 178.336 +                "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, "
 178.337 +                "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x.",
 178.338 +                vlapic->icr_high, vlapic->icr_low, short_hand, dest,
 178.339 +                trig_mode, level, dest_mode, delivery_mode, vector);
 178.340  
 178.341 -    for_each_vcpu ( vlapic->domain, v ) {
 178.342 -        if (vlapic_match_dest(v, vlapic, short_hand,
 178.343 -                              dest, dest_mode, delivery_mode)) {
 178.344 -            if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
 178.345 +    for_each_vcpu ( vlapic->domain, v )
 178.346 +    {
 178.347 +        if ( vlapic_match_dest(v, vlapic, short_hand,
 178.348 +                               dest, dest_mode, delivery_mode) )
 178.349 +        {
 178.350 +            if ( delivery_mode == VLAPIC_DELIV_MODE_LPRI )
 178.351                  set_bit(v->vcpu_id, &lpr_map);
 178.352 -            } else
 178.353 +            else
 178.354                  vlapic_accept_irq(v, delivery_mode,
 178.355                                    vector, level, trig_mode);
 178.356          }
 178.357      }
 178.358  
 178.359 -    if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
 178.360 +    if ( delivery_mode == VLAPIC_DELIV_MODE_LPRI )
 178.361 +    {
 178.362          v = vlapic->vcpu;
 178.363          target = apic_round_robin(v->domain, dest_mode, vector, lpr_map);
 178.364  
 178.365 -        if (target)
 178.366 +        if ( target )
 178.367              vlapic_accept_irq(target->vcpu, delivery_mode,
 178.368                                vector, level, trig_mode);
 178.369      }
 178.370  }
 178.371  
 178.372 -static void vlapic_begin_timer(struct vlapic *vlapic)
 178.373 -{
 178.374 -    s_time_t cur = NOW(), offset;
 178.375 -
 178.376 -    offset = vlapic->timer_current *
 178.377 -      (262144 / get_apic_bus_scale()) * vlapic->timer_divide_counter;
 178.378 -    vlapic->vlapic_timer.expires = cur + offset;
 178.379 -
 178.380 -    set_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires );
 178.381 -
 178.382 -    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_begin_timer: "
 178.383 -                "bus_scale %x now %08x%08x expire %08x%08x "
 178.384 -                "offset %08x%08x current %x",
 178.385 -                get_apic_bus_scale(), (uint32_t)(cur >> 32), (uint32_t)cur,
 178.386 -                (uint32_t)(vlapic->vlapic_timer.expires >> 32),
 178.387 -                (uint32_t) vlapic->vlapic_timer.expires,
 178.388 -                (uint32_t)(offset >> 32), (uint32_t)offset,
 178.389 -                vlapic->timer_current);
 178.390 -}
 178.391 -
 178.392 -void vlapic_read_aligned(struct vlapic *vlapic, unsigned int offset,
 178.393 +static void vlapic_read_aligned(struct vlapic *vlapic, unsigned int offset,
 178.394                           unsigned int len, unsigned int *result)
 178.395  {
 178.396 -    if (len != 4) {
 178.397 -        HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.398 -                    "local apic read with len=%d (should be 4)", len);
 178.399 -    }
 178.400 +    if ( len != 4 )
 178.401 +        printk("<vlapic_read_aligned> read with len=%d (should be 4).\n", len);
 178.402  
 178.403      *result = 0;
 178.404  
 178.405 -    switch (offset) {
 178.406 +    switch ( offset ) {
 178.407      case APIC_ID:
 178.408 -        *result = (vlapic->id) << 24;
 178.409 +        *result = vlapic->id << 24;
 178.410          break;
 178.411  
 178.412      case APIC_LVR:
 178.413 @@ -433,7 +431,7 @@ void vlapic_read_aligned(struct vlapic *
 178.414          break;
 178.415  
 178.416      case APIC_ARBPRI:
 178.417 -        printk("Access local APIC ARBPRI register which is for P6\n");
 178.418 +        printk("access local APIC ARBPRI register which is for P6\n");
 178.419          break;
 178.420  
 178.421      case APIC_PROCPRI:
 178.422 @@ -489,7 +487,7 @@ void vlapic_read_aligned(struct vlapic *
 178.423          break;
 178.424  
 178.425      case APIC_ESR:
 178.426 -        if (vlapic->err_write_count)
 178.427 +        if ( vlapic->err_write_count )
 178.428              *result = vlapic->err_status;
 178.429          break;
 178.430  
 178.431 @@ -501,51 +499,58 @@ void vlapic_read_aligned(struct vlapic *
 178.432          *result = vlapic->icr_high;
 178.433          break;
 178.434  
 178.435 -    case APIC_LVTT:     /* LVT Timer Reg */
 178.436 -    case APIC_LVTTHMR:     /* LVT Thermal Monitor */
 178.437 -    case APIC_LVTPC:     /* LVT Performance Counter */
 178.438 -    case APIC_LVT0:     /* LVT LINT0 Reg */
 178.439 -    case APIC_LVT1:     /* LVT Lint1 Reg */
 178.440 -    case APIC_LVTERR:     /* LVT Error Reg */
 178.441 +    case APIC_LVTT:         /* LVT Timer Reg */
 178.442 +    case APIC_LVTTHMR:      /* LVT Thermal Monitor */
 178.443 +    case APIC_LVTPC:        /* LVT Performance Counter */
 178.444 +    case APIC_LVT0:         /* LVT LINT0 Reg */
 178.445 +    case APIC_LVT1:         /* LVT Lint1 Reg */
 178.446 +    case APIC_LVTERR:       /* LVT Error Reg */
 178.447          *result = vlapic->lvt[(offset - APIC_LVTT) >> 4];
 178.448          break;
 178.449  
 178.450      case APIC_TMICT:
 178.451 -        *result = vlapic->timer_initial;
 178.452 +        *result = vlapic->timer_initial_count;
 178.453          break;
 178.454  
 178.455 -    case APIC_TMCCT:         //Timer CCR
 178.456 +    case APIC_TMCCT:        //Timer CCR
 178.457          {
 178.458 -            uint32_t counter;
 178.459 -            s_time_t passed, cur = NOW();
 178.460 +            uint32_t counter_passed;
 178.461 +            s_time_t passed, now = NOW();
 178.462  
 178.463 -            if (cur <= vlapic->timer_current_update) {
 178.464 -                passed = ~0x0LL - vlapic->timer_current_update + cur;
 178.465 -                HVM_DBG_LOG(DBG_LEVEL_VLAPIC,"time elapsed");
 178.466 -            }else
 178.467 -                passed = cur - vlapic->timer_current_update;
 178.468 +            if ( unlikely(now <= vlapic->timer_current_update) )
 178.469 +            {
 178.470 +                passed = ~0x0LL - vlapic->timer_current_update + now;
 178.471 +                HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "time elapsed.");
 178.472 +            }
 178.473 +            else
 178.474 +                passed = now - vlapic->timer_current_update;
 178.475  
 178.476 -            counter = (passed * get_apic_bus_scale()) / (262144* vlapic->timer_divide_counter);
 178.477 -            if (vlapic->timer_current > counter)
 178.478 -                *result = vlapic->timer_current - counter;
 178.479 -            else {
 178.480 -                if (!vlapic_lvt_timer_period(vlapic))
 178.481 -                    *result = 0;
 178.482 -                //FIXME should we add interrupt here?
 178.483 +            counter_passed = passed /
 178.484 +                             (APIC_BUS_CYCLE_NS * vlapic->timer_divide_count);
 178.485 +            vlapic->timer_current_count -= counter_passed;
 178.486 +            if ( vlapic->timer_current_count <= 0 )
 178.487 +            {
 178.488 +                if ( unlikely(!vlapic_lvt_timer_period(vlapic)) )
 178.489 +                {
 178.490 +                    vlapic->timer_current_count = 0;
 178.491 +                    // FIXME: should we add interrupt here?
 178.492 +                }
 178.493                  else
 178.494 -                    //*result = counter % vlapic->timer_initial;
 178.495 -                    *result = vlapic->timer_initial - (counter - vlapic->timer_current);
 178.496 +                {
 178.497 +                    do {
 178.498 +                        vlapic->timer_current_count += vlapic->timer_initial_count;
 178.499 +                    } while ( vlapic->timer_current_count < 0 );
 178.500 +                }
 178.501              }
 178.502 -            vlapic->timer_current = *result;
 178.503 -            vlapic->timer_current_update = NOW();
 178.504 +
 178.505 +            *result = vlapic->timer_current_count;
 178.506 +            vlapic->timer_current_update = now;
 178.507  
 178.508              HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
 178.509 -                        "initial %x timer current %x "
 178.510 -                        "update %08x%08x cur %08x%08x offset %d",
 178.511 -                        vlapic->timer_initial, vlapic->timer_current,
 178.512 -                        (uint32_t)(vlapic->timer_current_update >> 32),
 178.513 -                        (uint32_t)vlapic->timer_current_update ,
 178.514 -                        (uint32_t)(cur >> 32), (uint32_t)cur, counter);
 178.515 +                        "timer initial count 0x%x, timer current count 0x%x, "
 178.516 +                        "update 0x%016"PRIx64", now 0x%016"PRIx64", offset 0x%x.",
 178.517 +                        vlapic->timer_initial_count, vlapic->timer_current_count,
 178.518 +                        vlapic->timer_current_update, now, counter_passed);
 178.519          }
 178.520          break;
 178.521  
 178.522 @@ -554,7 +559,7 @@ void vlapic_read_aligned(struct vlapic *
 178.523          break;
 178.524  
 178.525      default:
 178.526 -        printk("Read local APIC address %x not implemented\n",offset);
 178.527 +        printk("Read local APIC address 0x%x not implemented\n", offset);
 178.528          *result = 0;
 178.529          break;
 178.530      }
 178.531 @@ -569,17 +574,16 @@ static unsigned long vlapic_read(struct 
 178.532      struct vlapic *vlapic = VLAPIC(v);
 178.533      unsigned int offset = address - vlapic->base_address;
 178.534  
 178.535 -    if ( len != 4) {
 178.536 -        /* some bugs on kernel cause read this with byte*/
 178.537 +    /* some bugs on kernel cause read this with byte*/
 178.538 +    if ( len != 4 )
 178.539          HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.540 -                    "Local APIC read with len = %lx, should be 4 instead\n",
 178.541 +                    "read with len=0x%lx, should be 4 instead.\n",
 178.542                      len);
 178.543 -    }
 178.544  
 178.545      alignment = offset & 0x3;
 178.546  
 178.547      vlapic_read_aligned(vlapic, offset & ~0x3, 4, &tmp);
 178.548 -    switch (len) {
 178.549 +    switch ( len ) {
 178.550      case 1:
 178.551          result = *((unsigned char *)&tmp + alignment);
 178.552          break;
 178.553 @@ -593,14 +597,14 @@ static unsigned long vlapic_read(struct 
 178.554          break;
 178.555  
 178.556      default:
 178.557 -        printk("Local APIC read with len = %lx, should be 4 instead\n", len);
 178.558 +        printk("Local APIC read with len=0x%lx, should be 4 instead.\n", len);
 178.559          domain_crash_synchronous();
 178.560          break;
 178.561      }
 178.562  
 178.563 -    HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.564 -                "vlapic_read offset %x with length %lx and the result is %lx",
 178.565 -                offset, len, result);
 178.566 +    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "offset 0x%x with length 0x%lx, "
 178.567 +                "and the result is 0x%lx.", offset, len, result);
 178.568 +
 178.569      return result;
 178.570  }
 178.571  
 178.572 @@ -610,40 +614,42 @@ static void vlapic_write(struct vcpu *v,
 178.573      struct vlapic *vlapic = VLAPIC(v);
 178.574      unsigned int offset = address - vlapic->base_address;
 178.575  
 178.576 -    if (offset != 0xb0)
 178.577 +    if ( offset != 0xb0 )
 178.578          HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.579 -          "vlapic_write offset %x with length %lx source %lx",
 178.580 -          offset, len, val);
 178.581 +                    "offset 0x%x with length 0x%lx, and value is 0x%lx.",
 178.582 +                    offset, len, val);
 178.583  
 178.584      /*
 178.585       * According to IA 32 Manual, all resgiters should be accessed with
 178.586       * 32 bits alignment.
 178.587       */
 178.588 -    if (len != 4) {
 178.589 +    if ( len != 4 )
 178.590 +    {
 178.591          unsigned int tmp;
 178.592          unsigned char alignment;
 178.593  
 178.594          /* Some kernel do will access with byte/word alignment*/
 178.595          printk("Notice: Local APIC write with len = %lx\n",len);
 178.596          alignment = offset & 0x3;
 178.597 -        tmp = vlapic_read(v, offset & (~0x3), 4);
 178.598 -        switch (len) {
 178.599 +        tmp = vlapic_read(v, offset & ~0x3, 4);
 178.600 +        switch ( len ) {
 178.601          case 1:
 178.602              /* XXX the saddr is a tmp variable from caller, so should be ok
 178.603 -               But we should still change the following ref to val to 
 178.604 +               But we should still change the following ref to val to
 178.605                 local variable later */
 178.606 -            val  = (tmp & ~(0xff << alignment)) |
 178.607 -                        ((val & 0xff) << alignment);
 178.608 +            val = (tmp & ~(0xff << alignment)) |
 178.609 +                  ((val & 0xff) << alignment);
 178.610              break;
 178.611  
 178.612          case 2:
 178.613 -            if (alignment != 0x0 && alignment != 0x2) {
 178.614 +            if ( alignment != 0x0 && alignment != 0x2 )
 178.615 +            {
 178.616                  printk("alignment error for vlapic with len == 2\n");
 178.617 -                    domain_crash_synchronous();
 178.618 +                domain_crash_synchronous();
 178.619              }
 178.620  
 178.621              val = (tmp & ~(0xffff << alignment)) |
 178.622 -                        ((val & 0xffff)  << alignment);
 178.623 +                  ((val & 0xffff) << alignment);
 178.624              break;
 178.625  
 178.626          case 3:
 178.627 @@ -661,7 +667,7 @@ static void vlapic_write(struct vcpu *v,
 178.628  
 178.629      offset &= 0xff0;
 178.630  
 178.631 -    switch (offset) {
 178.632 +    switch ( offset ) {
 178.633      case APIC_ID:   /* Local APIC ID */
 178.634          vlapic->id = ((val) >> 24) & VAPIC_ID_MASK;
 178.635          break;
 178.636 @@ -685,9 +691,10 @@ static void vlapic_write(struct vcpu *v,
 178.637  
 178.638      case APIC_SPIV:
 178.639          vlapic->spurious_vec = val & 0x1ff;
 178.640 -        if (!(vlapic->spurious_vec & 0x100)) {
 178.641 -            int i = 0;
 178.642 -            for (i = 0; i < VLAPIC_LVT_NUM; i++)
 178.643 +        if ( !(vlapic->spurious_vec & 0x100) )
 178.644 +        {
 178.645 +            int i;
 178.646 +            for ( i = 0; i < VLAPIC_LVT_NUM; i++ )
 178.647                  vlapic->lvt[i] |= 0x10000;
 178.648              vlapic->status |= VLAPIC_SOFTWARE_DISABLE_MASK;
 178.649          }
 178.650 @@ -697,7 +704,7 @@ static void vlapic_write(struct vcpu *v,
 178.651  
 178.652      case APIC_ESR:
 178.653          vlapic->err_write_count = !vlapic->err_write_count;
 178.654 -        if (!vlapic->err_write_count)
 178.655 +        if ( !vlapic->err_write_count )
 178.656              vlapic->err_status = 0;
 178.657          break;
 178.658  
 178.659 @@ -711,30 +718,32 @@ static void vlapic_write(struct vcpu *v,
 178.660          vlapic->icr_high = val & 0xff000000;
 178.661          break;
 178.662  
 178.663 -    case APIC_LVTT: // LVT Timer Reg
 178.664 -    case APIC_LVTTHMR: // LVT Thermal Monitor
 178.665 -    case APIC_LVTPC: // LVT Performance Counter
 178.666 -    case APIC_LVT0: // LVT LINT0 Reg
 178.667 -    case APIC_LVT1: // LVT Lint1 Reg
 178.668 -    case APIC_LVTERR: // LVT Error Reg
 178.669 +    case APIC_LVTT:         // LVT Timer Reg
 178.670 +    case APIC_LVTTHMR:      // LVT Thermal Monitor
 178.671 +    case APIC_LVTPC:        // LVT Performance Counter
 178.672 +    case APIC_LVT0:         // LVT LINT0 Reg
 178.673 +    case APIC_LVT1:         // LVT Lint1 Reg
 178.674 +    case APIC_LVTERR:       // LVT Error Reg
 178.675          {
 178.676              int vt = (offset - APIC_LVTT) >> 4;
 178.677  
 178.678              vlapic->lvt[vt] = val & vlapic_lvt_mask[vt];
 178.679 -            if (vlapic->status & VLAPIC_SOFTWARE_DISABLE_MASK)
 178.680 +            if ( vlapic->status & VLAPIC_SOFTWARE_DISABLE_MASK )
 178.681                  vlapic->lvt[vt] |= VLAPIC_LVT_BIT_MASK;
 178.682  
 178.683              /* On hardware, when write vector less than 0x20 will error */
 178.684              vlapic_check_vector(vlapic, vlapic_lvt_dm(vlapic->lvt[vt]),
 178.685 -              vlapic_lvt_vector(vlapic, vt));
 178.686 +                                vlapic_lvt_vector(vlapic, vt));
 178.687  
 178.688 -            if (!vlapic->vcpu_id && (offset == APIC_LVT0)) {
 178.689 -                if ((vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_DELIMOD)
 178.690 -                            == 0x700) {
 178.691 -                    if (!(vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_MASK)) {
 178.692 +            if ( !vlapic->vcpu_id && (offset == APIC_LVT0) )
 178.693 +            {
 178.694 +                if ( (vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_DELIMOD)
 178.695 +                      == 0x700 )
 178.696 +                {
 178.697 +                    if ( vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_MASK )
 178.698 +                        clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
 178.699 +                    else
 178.700                          set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
 178.701 -                    }else
 178.702 -                        clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
 178.703                  }
 178.704                  else
 178.705                      clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
 178.706 @@ -744,33 +753,41 @@ static void vlapic_write(struct vcpu *v,
 178.707          break;
 178.708  
 178.709      case APIC_TMICT:
 178.710 -        if (vlapic_timer_active(vlapic))
 178.711 -            stop_timer(&(vlapic->vlapic_timer));
 178.712 +        {
 178.713 +            s_time_t now = NOW(), offset;
 178.714  
 178.715 -        vlapic->timer_initial = val;
 178.716 -        vlapic->timer_current = val;
 178.717 -        vlapic->timer_current_update = NOW();
 178.718 +            if ( vlapic_timer_active(vlapic) )
 178.719 +                stop_timer(&vlapic->vlapic_timer);
 178.720 +
 178.721 +            vlapic->timer_initial_count = val;
 178.722 +            vlapic->timer_current_count = val;
 178.723 +            vlapic->timer_current_update = now;
 178.724  
 178.725 -        vlapic_begin_timer(vlapic);
 178.726 +            offset = APIC_BUS_CYCLE_NS *
 178.727 +                     vlapic->timer_divide_count *
 178.728 +                     vlapic->timer_initial_count;
 178.729 +
 178.730 +            set_timer(&vlapic->vlapic_timer, now + offset);
 178.731  
 178.732 -        HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "timer_init %x timer_current %x"
 178.733 -                    "timer_current_update %08x%08x",
 178.734 -                    vlapic->timer_initial, vlapic->timer_current,
 178.735 -                    (uint32_t)(vlapic->timer_current_update >> 32),
 178.736 -                    (uint32_t)vlapic->timer_current_update);
 178.737 +            HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.738 +                        "bus cycle is %"PRId64"ns, now 0x%016"PRIx64", "
 178.739 +                        "timer initial count 0x%x, offset 0x%016"PRIx64", "
 178.740 +                        "expire @ 0x%016"PRIx64".",
 178.741 +                        APIC_BUS_CYCLE_NS, now, vlapic->timer_initial_count,
 178.742 +                        offset, now + offset);
 178.743 +        }
 178.744          break;
 178.745  
 178.746      case APIC_TDCR:
 178.747          {
 178.748 -            //FIXME clean this code
 178.749 -            unsigned char tmp1,tmp2;
 178.750 -            tmp1 = (val & 0xf);
 178.751 -            tmp2 = ((tmp1 & 0x3 )|((tmp1 & 0x8) >>1)) + 1;
 178.752 -            vlapic->timer_divide_counter = 0x1<<tmp2;
 178.753 +            unsigned int tmp1, tmp2;
 178.754  
 178.755 -            HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
 178.756 -                        "timer divider is 0x%x",
 178.757 -                        vlapic->timer_divide_counter);
 178.758 +            tmp1 = val & 0xf;
 178.759 +            tmp2 = ((tmp1 & 0x3) | ((tmp1 & 0x8) >> 1)) + 1;
 178.760 +            vlapic->timer_divide_count = 0x1 << (tmp2 & 0x7);
 178.761 +
 178.762 +            HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER, "timer divide count is 0x%x",
 178.763 +                        vlapic->timer_divide_count);
 178.764          }
 178.765          break;
 178.766  
 178.767 @@ -784,9 +801,9 @@ static int vlapic_range(struct vcpu *v, 
 178.768  {
 178.769      struct vlapic *vlapic = VLAPIC(v);
 178.770  
 178.771 -    if (vlapic_global_enabled(vlapic) &&
 178.772 -        (addr >= vlapic->base_address) &&
 178.773 -        (addr <= (vlapic->base_address + VLOCAL_APIC_MEM_LENGTH)))
 178.774 +    if ( vlapic_global_enabled(vlapic) &&
 178.775 +         (addr >= vlapic->base_address) &&
 178.776 +         (addr <= vlapic->base_address + VLOCAL_APIC_MEM_LENGTH) )
 178.777          return 1;
 178.778  
 178.779      return 0;
 178.780 @@ -801,23 +818,21 @@ struct hvm_mmio_handler vlapic_mmio_hand
 178.781  void vlapic_msr_set(struct vlapic *vlapic, uint64_t value)
 178.782  {
 178.783      /* When apic disabled */
 178.784 -    if (!vlapic)
 178.785 +    if ( vlapic == NULL )
 178.786          return;
 178.787  
 178.788 -    if (vlapic->vcpu_id)
 178.789 +    if ( vlapic->vcpu_id )
 178.790          value &= ~MSR_IA32_APICBASE_BSP;
 178.791  
 178.792      vlapic->apic_base_msr = value;
 178.793      vlapic->base_address = vlapic_get_base_address(vlapic);
 178.794  
 178.795 -    if (!(value & 0x800))
 178.796 +    if ( !(value & 0x800) )
 178.797          set_bit(_VLAPIC_GLOB_DISABLE, &vlapic->status );
 178.798  
 178.799      HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.800 -                "apic base msr = 0x%08x%08x,\nbase address = 0x%lx",
 178.801 -                (uint32_t)(vlapic->apic_base_msr >> 32),
 178.802 -                (uint32_t)vlapic->apic_base_msr,
 178.803 -                vlapic->base_address);
 178.804 +                "apic base msr is 0x%016"PRIx64", and base address is 0x%lx.",
 178.805 +                vlapic->apic_base_msr, vlapic->base_address);
 178.806  }
 178.807  
 178.808  static inline int vlapic_get_init_id(struct vcpu *v)
 178.809 @@ -827,42 +842,51 @@ static inline int vlapic_get_init_id(str
 178.810  
 178.811  void vlapic_timer_fn(void *data)
 178.812  {
 178.813 -    struct vlapic *vlapic;
 178.814 +    struct vlapic *vlapic = data;
 178.815 +    struct vcpu *v;
 178.816 +    uint32_t timer_vector;
 178.817 +    s_time_t now;
 178.818  
 178.819 -    vlapic = data;
 178.820 -    if (!vlapic_enabled(vlapic)) return;
 178.821 -
 178.822 -    vlapic->timer_current_update = NOW();
 178.823 +    if ( unlikely(!vlapic_enabled(vlapic) ||
 178.824 +                  !vlapic_lvt_timer_enabled(vlapic)) )
 178.825 +        return;
 178.826  
 178.827 -    if (vlapic_lvt_timer_enabled(vlapic)) {
 178.828 -        if (!vlapic_irr_status(vlapic,
 178.829 -              vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER))) {
 178.830 -            test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
 178.831 -              &vlapic->irr[0]);
 178.832 -        }
 178.833 -        else
 178.834 -            vlapic->intr_pending_count[vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)]++;
 178.835 -        evtchn_set_pending(vlapic->vcpu, iopacket_port(vlapic->vcpu));
 178.836 -    }
 178.837 +    v = vlapic->vcpu;
 178.838 +    timer_vector = vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER);
 178.839 +    now = NOW();
 178.840 +
 178.841 +    vlapic->timer_current_update = now;
 178.842  
 178.843 -    vlapic->timer_current_update = NOW();
 178.844 -    if (vlapic_lvt_timer_period(vlapic)) {
 178.845 +    if ( test_and_set_bit(timer_vector, &vlapic->irr[0]) )
 178.846 +        vlapic->intr_pending_count[timer_vector]++;
 178.847 +
 178.848 +    if ( vlapic_lvt_timer_period(vlapic) )
 178.849 +    {
 178.850          s_time_t offset;
 178.851  
 178.852 -        vlapic->timer_current = vlapic->timer_initial;
 178.853 -        offset = vlapic->timer_current * (262144/get_apic_bus_scale()) * vlapic->timer_divide_counter;
 178.854 -        vlapic->vlapic_timer.expires = NOW() + offset;
 178.855 -        set_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires);
 178.856 -    }else {
 178.857 -        vlapic->timer_current = 0;
 178.858 +        vlapic->timer_current_count = vlapic->timer_initial_count;
 178.859 +
 178.860 +        offset = APIC_BUS_CYCLE_NS *
 178.861 +                 vlapic->timer_divide_count *
 178.862 +                 vlapic->timer_initial_count;
 178.863 +        set_timer(&vlapic->vlapic_timer, now + offset);
 178.864      }
 178.865 +    else
 178.866 +        vlapic->timer_current_count = 0;
 178.867 +
 178.868 +#if 0
 178.869 +    if ( test_bit(_VCPUF_running, &v->vcpu_flags) )
 178.870 +    {
 178.871 +        /* TODO: add guest time handling here */
 178.872 +    }
 178.873 +#endif
 178.874  
 178.875      HVM_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
 178.876 -      "vlapic_timer_fn: now: %08x%08x expire %08x%08x init %x current %x",
 178.877 -      (uint32_t)(NOW() >> 32),(uint32_t)NOW(),
 178.878 -      (uint32_t)(vlapic->vlapic_timer.expires >> 32),
 178.879 -      (uint32_t)vlapic->vlapic_timer.expires,
 178.880 -      vlapic->timer_initial,vlapic->timer_current);
 178.881 +                "now 0x%016"PRIx64", expire @ 0x%016"PRIx64", "
 178.882 +                "timer initial count 0x%x, timer current count 0x%x.",
 178.883 +                now, vlapic->vlapic_timer.expires,
 178.884 +                vlapic->timer_initial_count,
 178.885 +                vlapic->timer_current_count);
 178.886  }
 178.887  
 178.888  #if 0
 178.889 @@ -873,7 +897,7 @@ vlapic_check_direct_intr(struct vcpu *v,
 178.890      int type;
 178.891  
 178.892      type = __fls(vlapic->direct_intr.deliver_mode);
 178.893 -    if (type == -1)
 178.894 +    if ( type == -1 )
 178.895          return -1;
 178.896  
 178.897      *mode = type;
 178.898 @@ -881,31 +905,35 @@ vlapic_check_direct_intr(struct vcpu *v,
 178.899  }
 178.900  #endif
 178.901  
 178.902 -int
 178.903 -vlapic_accept_pic_intr(struct vcpu *v)
 178.904 +int vlapic_accept_pic_intr(struct vcpu *v)
 178.905  {
 178.906      struct vlapic *vlapic = VLAPIC(v);
 178.907  
 178.908      return vlapic ? test_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status) : 1;
 178.909  }
 178.910  
 178.911 -int cpu_get_apic_interrupt(struct vcpu* v, int *mode)
 178.912 +int cpu_get_apic_interrupt(struct vcpu *v, int *mode)
 178.913  {
 178.914      struct vlapic *vlapic = VLAPIC(v);
 178.915  
 178.916 -    if (vlapic && vlapic_enabled(vlapic)) {
 178.917 +    if ( vlapic && vlapic_enabled(vlapic) )
 178.918 +    {
 178.919          int highest_irr = vlapic_find_highest_irr(vlapic);
 178.920  
 178.921 -        if (highest_irr != -1 && highest_irr >= vlapic->processor_priority) {
 178.922 -            if (highest_irr < 0x10) {
 178.923 +        if ( highest_irr != -1 && highest_irr >= vlapic->processor_priority )
 178.924 +        {
 178.925 +            if ( highest_irr < 0x10 )
 178.926 +            {
 178.927 +                uint32_t err_vector;
 178.928 +
 178.929                  vlapic->err_status |= 0x20;
 178.930 -                /* XXX What will happen if this vector illegal stil */
 178.931 +                err_vector = vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR);
 178.932 +
 178.933                  HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
 178.934 -                  "hvm_intr_assist: illegal vector number %x err_status %x",
 178.935 -                  highest_irr,  vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR));
 178.936 +                            "Sending an illegal vector 0x%x.", highest_irr);
 178.937  
 178.938 -                set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), &vlapic->irr[0]);
 178.939 -                highest_irr = vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR);
 178.940 +                set_bit(err_vector, &vlapic->irr[0]);
 178.941 +                highest_irr = err_vector;
 178.942              }
 178.943  
 178.944              *mode = VLAPIC_DELIV_MODE_FIXED;
 178.945 @@ -915,29 +943,43 @@ int cpu_get_apic_interrupt(struct vcpu* 
 178.946      return -1;
 178.947  }
 178.948  
 178.949 -void vlapic_post_injection(struct vcpu *v, int vector, int deliver_mode) {
 178.950 -    struct vlapic  *vlapic = VLAPIC(v);
 178.951 +int cpu_has_apic_interrupt(struct vcpu* v)
 178.952 +{
 178.953 +    struct vlapic *vlapic = VLAPIC(v);
 178.954 +
 178.955 +    if (vlapic && vlapic_enabled(vlapic)) {
 178.956 +        int highest_irr = vlapic_find_highest_irr(vlapic);
 178.957  
 178.958 -    if (!vlapic)
 178.959 +        if (highest_irr != -1 && highest_irr >= vlapic->processor_priority) {
 178.960 +            return 1;
 178.961 +        }
 178.962 +    }
 178.963 +    return 0;
 178.964 +}
 178.965 + 
 178.966 +void vlapic_post_injection(struct vcpu *v, int vector, int deliver_mode)
 178.967 +{
 178.968 +    struct vlapic *vlapic = VLAPIC(v);
 178.969 +
 178.970 +    if ( unlikely(vlapic == NULL) )
 178.971          return;
 178.972  
 178.973 -    switch (deliver_mode) {
 178.974 +    switch ( deliver_mode ) {
 178.975      case VLAPIC_DELIV_MODE_FIXED:
 178.976      case VLAPIC_DELIV_MODE_LPRI:
 178.977 -        vlapic_set_isr(vlapic, vector);
 178.978 -        vlapic_clear_irr(vlapic, vector);
 178.979 +        set_bit(vector, &vlapic->isr[0]);
 178.980 +        clear_bit(vector, &vlapic->irr[0]);
 178.981          vlapic_update_ppr(vlapic);
 178.982  
 178.983 -        if (vector == vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)) {
 178.984 +        if ( vector == vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER) )
 178.985 +        {
 178.986              vlapic->intr_pending_count[vector]--;
 178.987 -            if (vlapic->intr_pending_count[vector] > 0)
 178.988 -                test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
 178.989 -                  &vlapic->irr[0]);
 178.990 +            if ( vlapic->intr_pending_count[vector] > 0 )
 178.991 +                test_and_set_bit(vector, &vlapic->irr[0]);
 178.992          }
 178.993 +        break;
 178.994  
 178.995 -        break;
 178.996 -        /*XXX deal with these later */
 178.997 -
 178.998 +    /*XXX deal with these later */
 178.999      case VLAPIC_DELIV_MODE_RESERVED:
178.1000          printk("Ignore deliver mode 3 in vlapic_post_injection\n");
178.1001          break;
178.1002 @@ -950,7 +992,7 @@ void vlapic_post_injection(struct vcpu *
178.1003          break;
178.1004  
178.1005      default:
178.1006 -        printk("<vlapic_post_injection> error deliver mode\n");
178.1007 +        printk("<vlapic_post_injection> invalid deliver mode\n");
178.1008          break;
178.1009      }
178.1010  }
178.1011 @@ -978,12 +1020,12 @@ static int vlapic_reset(struct vlapic *v
178.1012  
178.1013      vlapic->apic_base_msr = VLAPIC_BASE_MSR_INIT_VALUE;
178.1014  
178.1015 -    if (apic_id == 0)
178.1016 +    if ( apic_id == 0 )
178.1017          vlapic->apic_base_msr |= MSR_IA32_APICBASE_BSP;
178.1018  
178.1019      vlapic->base_address = vlapic_get_base_address(vlapic);
178.1020  
178.1021 -    for (i = 0; i < VLAPIC_LVT_NUM; i++)
178.1022 +    for ( i = 0; i < VLAPIC_LVT_NUM; i++ )
178.1023          vlapic->lvt[i] = VLAPIC_LVT_BIT_MASK;
178.1024  
178.1025      vlapic->dest_format = 0xffffffffU;
178.1026 @@ -1000,18 +1042,18 @@ static int vlapic_reset(struct vlapic *v
178.1027       * XXX According to mp sepcific, BIOS will enable LVT0/1,
178.1028       * remove it after BIOS enabled
178.1029       */
178.1030 -    if (!v->vcpu_id) {
178.1031 +    if ( !v->vcpu_id )
178.1032 +    {
178.1033          vlapic->lvt[VLAPIC_LVT_LINT0] = 0x700;
178.1034          vlapic->lvt[VLAPIC_LVT_LINT1] = 0x500;
178.1035          set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
178.1036      }
178.1037  #endif
178.1038  
178.1039 -    HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_reset: "
178.1040 -                "vcpu=%p id=%d vlapic_apic_base_msr=%08x%08x "
178.1041 -                "vlapic_base_address=%0lx",
178.1042 -                v, vlapic->id, (uint32_t)(vlapic->apic_base_msr >> 32),
178.1043 -                (uint32_t)vlapic->apic_base_msr, vlapic->base_address);
178.1044 +    HVM_DBG_LOG(DBG_LEVEL_VLAPIC,
178.1045 +                "vcpu=%p, id=%d, vlapic_apic_base_msr=0x%016"PRIx64", "
178.1046 +                "base_address=0x%0lx.",
178.1047 +                v, vlapic->id, vlapic->apic_base_msr, vlapic->base_address);
178.1048  
178.1049      return 1;
178.1050  }
178.1051 @@ -1025,7 +1067,8 @@ int vlapic_init(struct vcpu *v)
178.1052      HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_init %d", v->vcpu_id);
178.1053  
178.1054      vlapic = xmalloc_bytes(sizeof(struct vlapic));
178.1055 -    if (!vlapic) {
178.1056 +    if ( vlapic == NULL )
178.1057 +    {
178.1058          printk("malloc vlapic error for vcpu %x\n", v->vcpu_id);
178.1059          return -ENOMEM;
178.1060      }
   179.1 --- a/xen/arch/x86/hvm/vmx/io.c	Tue Mar 14 13:10:21 2006 -0700
   179.2 +++ b/xen/arch/x86/hvm/vmx/io.c	Tue Mar 14 13:50:35 2006 -0700
   179.3 @@ -86,28 +86,53 @@ interrupt_post_injection(struct vcpu * v
   179.4  }
   179.5  
   179.6  static inline void
   179.7 -enable_irq_window(unsigned long cpu_exec_control)
   179.8 +enable_irq_window(struct vcpu *v)
   179.9  {
  179.10 -    if (!(cpu_exec_control & CPU_BASED_VIRTUAL_INTR_PENDING)) {
  179.11 -        cpu_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
  179.12 -        __vmwrite(CPU_BASED_VM_EXEC_CONTROL, cpu_exec_control);
  179.13 +    u32  *cpu_exec_control = &v->arch.hvm_vcpu.u.vmx.exec_control;
  179.14 +    
  179.15 +    if (!(*cpu_exec_control & CPU_BASED_VIRTUAL_INTR_PENDING)) {
  179.16 +        *cpu_exec_control |= CPU_BASED_VIRTUAL_INTR_PENDING;
  179.17 +        __vmwrite(CPU_BASED_VM_EXEC_CONTROL, *cpu_exec_control);
  179.18      }
  179.19  }
  179.20  
  179.21  static inline void
  179.22 -disable_irq_window(unsigned long cpu_exec_control)
  179.23 +disable_irq_window(struct vcpu *v)
  179.24 +{
  179.25 +    u32  *cpu_exec_control = &v->arch.hvm_vcpu.u.vmx.exec_control;
  179.26 +    
  179.27 +    if ( *cpu_exec_control & CPU_BASED_VIRTUAL_INTR_PENDING ) {
  179.28 +        *cpu_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
  179.29 +        __vmwrite(CPU_BASED_VM_EXEC_CONTROL, *cpu_exec_control);
  179.30 +    }
  179.31 +}
  179.32 +
  179.33 +static inline int is_interruptibility_state(void)
  179.34  {
  179.35 -    if ( cpu_exec_control & CPU_BASED_VIRTUAL_INTR_PENDING ) {
  179.36 -        cpu_exec_control &= ~CPU_BASED_VIRTUAL_INTR_PENDING;
  179.37 -        __vmwrite(CPU_BASED_VM_EXEC_CONTROL, cpu_exec_control);
  179.38 -    }
  179.39 +    int  interruptibility;
  179.40 +    __vmread(GUEST_INTERRUPTIBILITY_INFO, &interruptibility);
  179.41 +    return interruptibility;
  179.42 +}
  179.43 +
  179.44 +/* check to see if there is pending interrupt  */
  179.45 +int cpu_has_pending_irq(struct vcpu *v)
  179.46 +{
  179.47 +    struct hvm_domain *plat = &v->domain->arch.hvm_domain;
  179.48 +
  179.49 +    /* APIC */
  179.50 +    if ( cpu_has_apic_interrupt(v) ) return 1;
  179.51 +    
  179.52 +    /* PIC */
  179.53 +    if ( !vlapic_accept_pic_intr(v) ) return 0;
  179.54 +
  179.55 +    return plat->interrupt_request;
  179.56  }
  179.57  
  179.58  asmlinkage void vmx_intr_assist(void)
  179.59  {
  179.60      int intr_type = 0;
  179.61      int highest_vector;
  179.62 -    unsigned long intr_fields, eflags, interruptibility, cpu_exec_control;
  179.63 +    unsigned long eflags;
  179.64      struct vcpu *v = current;
  179.65      struct hvm_domain *plat=&v->domain->arch.hvm_domain;
  179.66      struct hvm_virpit *vpit = &plat->vpit;
  179.67 @@ -121,42 +146,26 @@ asmlinkage void vmx_intr_assist(void)
  179.68          pic_set_irq(pic, 0, 1);
  179.69      }
  179.70  
  179.71 -    __vmread_vcpu(v, CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
  179.72 -    __vmread(VM_ENTRY_INTR_INFO_FIELD, &intr_fields);
  179.73 +    if ( !cpu_has_pending_irq(v) ) return;
  179.74  
  179.75 -    if (intr_fields & INTR_INFO_VALID_MASK) {
  179.76 -        enable_irq_window(cpu_exec_control);
  179.77 -        HVM_DBG_LOG(DBG_LEVEL_1, "vmx_intr_assist: intr_fields: %lx",
  179.78 -                    intr_fields);
  179.79 -        return;
  179.80 -    }
  179.81 -
  179.82 -    __vmread(GUEST_INTERRUPTIBILITY_INFO, &interruptibility);
  179.83 -
  179.84 -    if (interruptibility) {
  179.85 -        enable_irq_window(cpu_exec_control);
  179.86 -        HVM_DBG_LOG(DBG_LEVEL_1, "interruptibility: %lx",interruptibility);
  179.87 +    if ( is_interruptibility_state() ) {    /* pre-cleared for emulated instruction */
  179.88 +        enable_irq_window(v);
  179.89 +        HVM_DBG_LOG(DBG_LEVEL_1, "interruptibility");
  179.90          return;
  179.91      }
  179.92  
  179.93      __vmread(GUEST_RFLAGS, &eflags);
  179.94      if (irq_masked(eflags)) {
  179.95 -        enable_irq_window(cpu_exec_control);
  179.96 +        enable_irq_window(v);
  179.97          return;
  179.98      }
  179.99  
 179.100      highest_vector = cpu_get_interrupt(v, &intr_type); 
 179.101 -
 179.102 -    if (highest_vector == -1) {
 179.103 -        disable_irq_window(cpu_exec_control);
 179.104 -        return;
 179.105 -    }
 179.106 -
 179.107      switch (intr_type) {
 179.108      case VLAPIC_DELIV_MODE_EXT:
 179.109      case VLAPIC_DELIV_MODE_FIXED:
 179.110      case VLAPIC_DELIV_MODE_LPRI:
 179.111 -        vmx_inject_extint(v, highest_vector, VMX_INVALID_ERROR_CODE);
 179.112 +        vmx_inject_extint(v, highest_vector, VMX_DELIVER_NO_ERROR_CODE);
 179.113          TRACE_3D(TRC_VMX_INT, v->domain->domain_id, highest_vector, 0);
 179.114          break;
 179.115      case VLAPIC_DELIV_MODE_SMI:
   180.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Tue Mar 14 13:10:21 2006 -0700
   180.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Tue Mar 14 13:50:35 2006 -0700
   180.3 @@ -79,7 +79,7 @@ static void vmx_smp_clear_vmcs(void *inf
   180.4  {
   180.5      struct vcpu *v = (struct vcpu *)info;
   180.6  
   180.7 -    ASSERT(HVM_DOMAIN(v));
   180.8 +    ASSERT(hvm_guest(v));
   180.9  
  180.10      if (v->arch.hvm_vmx.launch_cpu == smp_processor_id())
  180.11          __vmpclear(virt_to_maddr(v->arch.hvm_vmx.vmcs));
  180.12 @@ -87,7 +87,7 @@ static void vmx_smp_clear_vmcs(void *inf
  180.13  
  180.14  void vmx_request_clear_vmcs(struct vcpu *v)
  180.15  {
  180.16 -    ASSERT(HVM_DOMAIN(v));
  180.17 +    ASSERT(hvm_guest(v));
  180.18  
  180.19      if (v->arch.hvm_vmx.launch_cpu == smp_processor_id())
  180.20          __vmpclear(virt_to_maddr(v->arch.hvm_vmx.vmcs));
  180.21 @@ -219,6 +219,7 @@ static void vmx_do_launch(struct vcpu *v
  180.22      error |= __vmwrite(CR0_READ_SHADOW, cr0);
  180.23      error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL,
  180.24                         MONITOR_CPU_BASED_EXEC_CONTROLS);
  180.25 +    v->arch.hvm_vcpu.u.vmx.exec_control = MONITOR_CPU_BASED_EXEC_CONTROLS;
  180.26  
  180.27      __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (cr4) : );
  180.28  
  180.29 @@ -362,7 +363,7 @@ static inline int construct_init_vmcs_gu
  180.30      return error;
  180.31  }
  180.32  
  180.33 -static inline int construct_vmcs_host()
  180.34 +static inline int construct_vmcs_host(void)
  180.35  {
  180.36      int error = 0;
  180.37  #ifdef __x86_64__
   181.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Tue Mar 14 13:10:21 2006 -0700
   181.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Tue Mar 14 13:50:35 2006 -0700
   181.3 @@ -223,6 +223,11 @@ static inline int long_mode_do_msr_write
   181.4  
   181.5      switch (regs->ecx){
   181.6      case MSR_EFER:
   181.7 +        /* offending reserved bit will cause #GP */
   181.8 +        if ( msr_content &
   181.9 +                ~( EFER_LME | EFER_LMA | EFER_NX | EFER_SCE ) )
  181.10 +             vmx_inject_exception(vc, TRAP_gp_fault, 0);
  181.11 +
  181.12          if ((msr_content & EFER_LME) ^
  181.13              test_bit(VMX_CPU_STATE_LME_ENABLED,
  181.14                       &vc->arch.hvm_vmx.cpu_state)){
  181.15 @@ -236,18 +241,9 @@ static inline int long_mode_do_msr_write
  181.16          if (msr_content & EFER_LME)
  181.17              set_bit(VMX_CPU_STATE_LME_ENABLED,
  181.18                      &vc->arch.hvm_vmx.cpu_state);
  181.19 -        /* No update for LME/LMA since it have no effect */
  181.20 +
  181.21          msr->msr_items[VMX_INDEX_MSR_EFER] =
  181.22              msr_content;
  181.23 -        if (msr_content & ~(EFER_LME | EFER_LMA)){
  181.24 -            msr->msr_items[VMX_INDEX_MSR_EFER] = msr_content;
  181.25 -            if (!test_bit(VMX_INDEX_MSR_EFER, &msr->flags)){
  181.26 -                rdmsrl(MSR_EFER,
  181.27 -                       host_state->msr_items[VMX_INDEX_MSR_EFER]);
  181.28 -                set_bit(VMX_INDEX_MSR_EFER, &host_state->flags);
  181.29 -                set_bit(VMX_INDEX_MSR_EFER, &msr->flags);
  181.30 -            }
  181.31 -        }
  181.32          break;
  181.33  
  181.34      case MSR_FS_BASE:
  181.35 @@ -483,12 +479,13 @@ void vmx_init_ap_context(struct vcpu_gue
  181.36  
  181.37  void do_nmi(struct cpu_user_regs *);
  181.38  
  181.39 -static int check_vmx_controls(ctrls, msr)
  181.40 +static int check_vmx_controls(u32 ctrls, u32 msr)
  181.41  {
  181.42      u32 vmx_msr_low, vmx_msr_high;
  181.43  
  181.44      rdmsr(msr, vmx_msr_low, vmx_msr_high);
  181.45 -    if (ctrls < vmx_msr_low || ctrls > vmx_msr_high) {
  181.46 +    if ( (ctrls < vmx_msr_low) || (ctrls > vmx_msr_high) )
  181.47 +    {
  181.48          printk("Insufficient VMX capability 0x%x, "
  181.49                 "msr=0x%x,low=0x%8x,high=0x%x\n",
  181.50                 ctrls, msr, vmx_msr_low, vmx_msr_high);
  181.51 @@ -599,6 +596,7 @@ static void inline __update_guest_eip(un
  181.52  
  181.53      __vmread(GUEST_RIP, &current_eip);
  181.54      __vmwrite(GUEST_RIP, current_eip + inst_len);
  181.55 +    __vmwrite(GUEST_INTERRUPTIBILITY_INFO, 0);
  181.56  }
  181.57  
  181.58  
  181.59 @@ -1919,7 +1917,7 @@ asmlinkage void vmx_vmexit_handler(struc
  181.60      /* don't bother H/W interrutps */
  181.61      if (exit_reason != EXIT_REASON_EXTERNAL_INTERRUPT &&
  181.62          exit_reason != EXIT_REASON_VMCALL &&
  181.63 -        exit_reason != EXIT_REASON_IO_INSTRUCTION)
  181.64 +        exit_reason != EXIT_REASON_IO_INSTRUCTION) 
  181.65          HVM_DBG_LOG(DBG_LEVEL_0, "exit reason = %x", exit_reason);
  181.66  
  181.67      if (exit_reason & VMX_EXIT_REASONS_FAILED_VMENTRY) {
  181.68 @@ -2029,6 +2027,7 @@ asmlinkage void vmx_vmexit_handler(struc
  181.69      case EXIT_REASON_PENDING_INTERRUPT:
  181.70          __vmwrite(CPU_BASED_VM_EXEC_CONTROL,
  181.71                    MONITOR_CPU_BASED_EXEC_CONTROLS);
  181.72 +        v->arch.hvm_vcpu.u.vmx.exec_control = MONITOR_CPU_BASED_EXEC_CONTROLS;
  181.73          break;
  181.74      case EXIT_REASON_TASK_SWITCH:
  181.75          __hvm_bug(&regs);
  181.76 @@ -2053,6 +2052,7 @@ asmlinkage void vmx_vmexit_handler(struc
  181.77          __update_guest_eip(inst_len);
  181.78          break;
  181.79      }
  181.80 +#if 0 /* keep this for debugging */
  181.81      case EXIT_REASON_VMCALL:
  181.82          __get_instruction_length(inst_len);
  181.83          __vmread(GUEST_RIP, &eip);
  181.84 @@ -2061,6 +2061,7 @@ asmlinkage void vmx_vmexit_handler(struc
  181.85          hvm_print_line(v, regs.eax); /* provides the current domain */
  181.86          __update_guest_eip(inst_len);
  181.87          break;
  181.88 +#endif
  181.89      case EXIT_REASON_CR_ACCESS:
  181.90      {
  181.91          __vmread(GUEST_RIP, &eip);
  181.92 @@ -2101,6 +2102,21 @@ asmlinkage void vmx_vmexit_handler(struc
  181.93      case EXIT_REASON_MWAIT_INSTRUCTION:
  181.94          __hvm_bug(&regs);
  181.95          break;
  181.96 +    case EXIT_REASON_VMCALL:
  181.97 +    case EXIT_REASON_VMCLEAR:
  181.98 +    case EXIT_REASON_VMLAUNCH:
  181.99 +    case EXIT_REASON_VMPTRLD:
 181.100 +    case EXIT_REASON_VMPTRST:
 181.101 +    case EXIT_REASON_VMREAD:
 181.102 +    case EXIT_REASON_VMRESUME:
 181.103 +    case EXIT_REASON_VMWRITE:
 181.104 +    case EXIT_REASON_VMOFF:
 181.105 +    case EXIT_REASON_VMON:
 181.106 +        /* Report invalid opcode exception when a VMX guest tries to execute 
 181.107 +            any of the VMX instructions */
 181.108 +        vmx_inject_exception(v, TRAP_invalid_op, VMX_DELIVER_NO_ERROR_CODE);
 181.109 +        break;
 181.110 +
 181.111      default:
 181.112          __hvm_bug(&regs);       /* should not happen */
 181.113      }
   182.1 --- a/xen/arch/x86/mm.c	Tue Mar 14 13:10:21 2006 -0700
   182.2 +++ b/xen/arch/x86/mm.c	Tue Mar 14 13:50:35 2006 -0700
   182.3 @@ -176,10 +176,9 @@ void __init init_frametable(void)
   182.4  
   182.5  void arch_init_memory(void)
   182.6  {
   182.7 -    extern void subarch_init_memory(struct domain *);
   182.8 +    extern void subarch_init_memory(void);
   182.9  
  182.10      unsigned long i, pfn, rstart_pfn, rend_pfn;
  182.11 -    struct page_info *page;
  182.12  
  182.13      memset(percpu_info, 0, sizeof(percpu_info));
  182.14  
  182.15 @@ -189,6 +188,7 @@ void arch_init_memory(void)
  182.16       * their domain field set to dom_xen.
  182.17       */
  182.18      dom_xen = alloc_domain();
  182.19 +    spin_lock_init(&dom_xen->page_alloc_lock);
  182.20      atomic_set(&dom_xen->refcnt, 1);
  182.21      dom_xen->domain_id = DOMID_XEN;
  182.22  
  182.23 @@ -198,17 +198,13 @@ void arch_init_memory(void)
  182.24       * array. Mappings occur at the priv of the caller.
  182.25       */
  182.26      dom_io = alloc_domain();
  182.27 +    spin_lock_init(&dom_io->page_alloc_lock);
  182.28      atomic_set(&dom_io->refcnt, 1);
  182.29      dom_io->domain_id = DOMID_IO;
  182.30  
  182.31      /* First 1MB of RAM is historically marked as I/O. */
  182.32      for ( i = 0; i < 0x100; i++ )
  182.33 -    {
  182.34 -        page = mfn_to_page(i);
  182.35 -        page->count_info        = PGC_allocated | 1;
  182.36 -        page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
  182.37 -        page_set_owner(page, dom_io);
  182.38 -    }
  182.39 +        share_xen_page_with_guest(mfn_to_page(i), dom_io, XENSHARE_writable);
  182.40   
  182.41      /* Any areas not specified as RAM by the e820 map are considered I/O. */
  182.42      for ( i = 0, pfn = 0; i < e820.nr_map; i++ )
  182.43 @@ -221,17 +217,47 @@ void arch_init_memory(void)
  182.44          for ( ; pfn < rstart_pfn; pfn++ )
  182.45          {
  182.46              BUG_ON(!mfn_valid(pfn));
  182.47 -            page = mfn_to_page(pfn);
  182.48 -            page->count_info        = PGC_allocated | 1;
  182.49 -            page->u.inuse.type_info = PGT_writable_page | PGT_validated | 1;
  182.50 -            page_set_owner(page, dom_io);
  182.51 +            share_xen_page_with_guest(
  182.52 +                mfn_to_page(pfn), dom_io, XENSHARE_writable);
  182.53          }
  182.54          /* Skip the RAM region. */
  182.55          pfn = rend_pfn;
  182.56      }
  182.57      BUG_ON(pfn != max_page);
  182.58  
  182.59 -    subarch_init_memory(dom_xen);
  182.60 +    subarch_init_memory();
  182.61 +}
  182.62 +
  182.63 +void share_xen_page_with_guest(
  182.64 +    struct page_info *page, struct domain *d, int readonly)
  182.65 +{
  182.66 +    if ( page_get_owner(page) == d )
  182.67 +        return;
  182.68 +
  182.69 +    set_gpfn_from_mfn(page_to_mfn(page), INVALID_M2P_ENTRY);
  182.70 +
  182.71 +    spin_lock(&d->page_alloc_lock);
  182.72 +
  182.73 +    /* The incremented type count pins as writable or read-only. */
  182.74 +    page->u.inuse.type_info  = (readonly ? PGT_none : PGT_writable_page);
  182.75 +    page->u.inuse.type_info |= PGT_validated | 1;
  182.76 +
  182.77 +    page_set_owner(page, d);
  182.78 +    wmb(); /* install valid domain ptr before updating refcnt. */
  182.79 +    ASSERT(page->count_info == 0);
  182.80 +    page->count_info |= PGC_allocated | 1;
  182.81 +
  182.82 +    if ( unlikely(d->xenheap_pages++ == 0) )
  182.83 +        get_knownalive_domain(d);
  182.84 +    list_add_tail(&page->list, &d->xenpage_list);
  182.85 +
  182.86 +    spin_unlock(&d->page_alloc_lock);
  182.87 +}
  182.88 +
  182.89 +void share_xen_page_with_privileged_guests(
  182.90 +    struct page_info *page, int readonly)
  182.91 +{
  182.92 +    share_xen_page_with_guest(page, dom_xen, readonly);
  182.93  }
  182.94  
  182.95  void write_ptbase(struct vcpu *v)
  182.96 @@ -751,9 +777,8 @@ static inline int l1_backptr(
  182.97      unsigned long *backptr, unsigned long offset_in_l2, unsigned long l2_type)
  182.98  {
  182.99      unsigned long l2_backptr = l2_type & PGT_va_mask;
 182.100 -    BUG_ON(l2_backptr == PGT_va_unknown);
 182.101 -    if ( l2_backptr == PGT_va_mutable )
 182.102 -        return 0;
 182.103 +    ASSERT(l2_backptr != PGT_va_unknown);
 182.104 +    ASSERT(l2_backptr != PGT_va_mutable);
 182.105      *backptr = 
 182.106          ((l2_backptr >> PGT_va_shift) << L3_PAGETABLE_SHIFT) | 
 182.107          (offset_in_l2 << L2_PAGETABLE_SHIFT);
 182.108 @@ -767,8 +792,8 @@ static inline int l1_backptr(
 182.109      unsigned long *backptr, unsigned long offset_in_l2, unsigned long l2_type)
 182.110  {
 182.111      unsigned long l2_backptr = l2_type & PGT_va_mask;
 182.112 -    BUG_ON(l2_backptr == PGT_va_unknown);
 182.113 -
 182.114 +    ASSERT(l2_backptr != PGT_va_unknown);
 182.115 +    ASSERT(l2_backptr != PGT_va_mutable);
 182.116      *backptr = ((l2_backptr >> PGT_va_shift) << L3_PAGETABLE_SHIFT) | 
 182.117          (offset_in_l2 << L2_PAGETABLE_SHIFT);
 182.118      return 1;
 182.119 @@ -778,8 +803,8 @@ static inline int l2_backptr(
 182.120      unsigned long *backptr, unsigned long offset_in_l3, unsigned long l3_type)
 182.121  {
 182.122      unsigned long l3_backptr = l3_type & PGT_va_mask;
 182.123 -    BUG_ON(l3_backptr == PGT_va_unknown);
 182.124 -
 182.125 +    ASSERT(l3_backptr != PGT_va_unknown);
 182.126 +    ASSERT(l3_backptr != PGT_va_mutable);
 182.127      *backptr = ((l3_backptr >> PGT_va_shift) << L4_PAGETABLE_SHIFT) | 
 182.128          (offset_in_l3 << L3_PAGETABLE_SHIFT);
 182.129      return 1;
 182.130 @@ -788,9 +813,6 @@ static inline int l2_backptr(
 182.131  static inline int l3_backptr(
 182.132      unsigned long *backptr, unsigned long offset_in_l4, unsigned long l4_type)
 182.133  {
 182.134 -    unsigned long l4_backptr = l4_type & PGT_va_mask;
 182.135 -    BUG_ON(l4_backptr == PGT_va_unknown);
 182.136 -
 182.137      *backptr = (offset_in_l4 << L4_PAGETABLE_SHIFT);
 182.138      return 1;
 182.139  }
 182.140 @@ -1412,9 +1434,8 @@ void put_page_type(struct page_info *pag
 182.141                  nx &= ~PGT_validated;
 182.142              }
 182.143          }
 182.144 -        else if ( unlikely(((nx & (PGT_pinned | PGT_count_mask)) == 
 182.145 -                            (PGT_pinned | 1)) &&
 182.146 -                           ((nx & PGT_type_mask) != PGT_writable_page)) )
 182.147 +        else if ( unlikely((nx & (PGT_pinned|PGT_type_mask|PGT_count_mask)) == 
 182.148 +                           (PGT_pinned|PGT_l1_page_table|1)) )
 182.149          {
 182.150              /* Page is now only pinned. Make the back pointer mutable again. */
 182.151              nx |= PGT_va_mutable;
 182.152 @@ -1507,14 +1528,19 @@ int get_page_type(struct page_info *page
 182.153                      nx &= ~PGT_va_mask;
 182.154                      nx |= type; /* we know the actual type is correct */
 182.155                  }
 182.156 -                else if ( ((type & PGT_va_mask) != PGT_va_mutable) &&
 182.157 -                          ((type & PGT_va_mask) != (x & PGT_va_mask)) )
 182.158 +                else
 182.159                  {
 182.160 +                    ASSERT((type & PGT_va_mask) != (x & PGT_va_mask));
 182.161 +                    ASSERT((type & PGT_va_mask) != PGT_va_mutable);
 182.162  #ifdef CONFIG_X86_PAE
 182.163                      /* We use backptr as extra typing. Cannot be unknown. */
 182.164                      if ( (type & PGT_type_mask) == PGT_l2_page_table )
 182.165                          return 0;
 182.166  #endif
 182.167 +                    /* Fixme: add code to propagate va_unknown to subtables. */
 182.168 +                    if ( ((type & PGT_type_mask) >= PGT_l2_page_table) &&
 182.169 +                         !shadow_mode_refcounts(page_get_owner(page)) )
 182.170 +                        return 0;
 182.171                      /* This table is possibly mapped at multiple locations. */
 182.172                      nx &= ~PGT_va_mask;
 182.173                      nx |= PGT_va_unknown;
 182.174 @@ -1732,14 +1758,15 @@ static inline cpumask_t vcpumask_to_pcpu
 182.175  }
 182.176  
 182.177  int do_mmuext_op(
 182.178 -    struct mmuext_op *uops,
 182.179 +    GUEST_HANDLE(mmuext_op_t) uops,
 182.180      unsigned int count,
 182.181 -    unsigned int *pdone,
 182.182 +    GUEST_HANDLE(uint) pdone,
 182.183      unsigned int foreigndom)
 182.184  {
 182.185      struct mmuext_op op;
 182.186      int rc = 0, i = 0, okay, cpu = smp_processor_id();
 182.187 -    unsigned long mfn, type, done = 0;
 182.188 +    unsigned long mfn, type;
 182.189 +    unsigned int done = 0;
 182.190      struct page_info *page;
 182.191      struct vcpu *v = current;
 182.192      struct domain *d = v->domain;
 182.193 @@ -1751,8 +1778,8 @@ int do_mmuext_op(
 182.194      if ( unlikely(count & MMU_UPDATE_PREEMPTED) )
 182.195      {
 182.196          count &= ~MMU_UPDATE_PREEMPTED;
 182.197 -        if ( unlikely(pdone != NULL) )
 182.198 -            (void)get_user(done, pdone);
 182.199 +        if ( unlikely(!guest_handle_is_null(pdone)) )
 182.200 +            (void)copy_from_guest(&done, pdone, 1);
 182.201      }
 182.202  
 182.203      if ( !set_foreigndom(cpu, foreigndom) )
 182.204 @@ -1761,7 +1788,7 @@ int do_mmuext_op(
 182.205          goto out;
 182.206      }
 182.207  
 182.208 -    if ( unlikely(!array_access_ok(uops, count, sizeof(op))) )
 182.209 +    if ( unlikely(!guest_handle_okay(uops, count)) )
 182.210      {
 182.211          rc = -EFAULT;
 182.212          goto out;
 182.213 @@ -1772,14 +1799,14 @@ int do_mmuext_op(
 182.214          if ( hypercall_preempt_check() )
 182.215          {
 182.216              rc = hypercall_create_continuation(
 182.217 -                __HYPERVISOR_mmuext_op, "pipi",
 182.218 +                __HYPERVISOR_mmuext_op, "hihi",
 182.219                  uops, (count - i) | MMU_UPDATE_PREEMPTED, pdone, foreigndom);
 182.220              break;
 182.221          }
 182.222  
 182.223 -        if ( unlikely(__copy_from_user(&op, uops, sizeof(op)) != 0) )
 182.224 +        if ( unlikely(__copy_from_guest(&op, uops, 1) != 0) )
 182.225          {
 182.226 -            MEM_LOG("Bad __copy_from_user");
 182.227 +            MEM_LOG("Bad __copy_from_guest");
 182.228              rc = -EFAULT;
 182.229              break;
 182.230          }
 182.231 @@ -1792,6 +1819,16 @@ int do_mmuext_op(
 182.232          {
 182.233          case MMUEXT_PIN_L1_TABLE:
 182.234              type = PGT_l1_page_table | PGT_va_mutable;
 182.235 +            goto pin_page;
 182.236 +
 182.237 +        case MMUEXT_PIN_L2_TABLE:
 182.238 +        case MMUEXT_PIN_L3_TABLE:
 182.239 +        case MMUEXT_PIN_L4_TABLE:
 182.240 +            /* Ignore pinning of subdirectories. */
 182.241 +            if ( (op.cmd - MMUEXT_PIN_L1_TABLE) != (CONFIG_PAGING_LEVELS - 1) )
 182.242 +                break;
 182.243 +
 182.244 +            type = PGT_root_page_table;
 182.245  
 182.246          pin_page:
 182.247              if ( shadow_mode_refcounts(FOREIGNDOM) )
 182.248 @@ -1815,20 +1852,6 @@ int do_mmuext_op(
 182.249              
 182.250              break;
 182.251  
 182.252 -#ifndef CONFIG_X86_PAE /* Unsafe on PAE because of Xen-private mappings. */
 182.253 -        case MMUEXT_PIN_L2_TABLE:
 182.254 -            type = PGT_l2_page_table | PGT_va_mutable;
 182.255 -            goto pin_page;
 182.256 -#endif
 182.257 -
 182.258 -        case MMUEXT_PIN_L3_TABLE:
 182.259 -            type = PGT_l3_page_table | PGT_va_mutable;
 182.260 -            goto pin_page;
 182.261 -
 182.262 -        case MMUEXT_PIN_L4_TABLE:
 182.263 -            type = PGT_l4_page_table | PGT_va_mutable;
 182.264 -            goto pin_page;
 182.265 -
 182.266          case MMUEXT_UNPIN_TABLE:
 182.267              if ( shadow_mode_refcounts(d) )
 182.268                  break;
 182.269 @@ -1969,24 +1992,25 @@ int do_mmuext_op(
 182.270              break;
 182.271          }
 182.272  
 182.273 -        uops++;
 182.274 +        guest_handle_add_offset(uops, 1);
 182.275      }
 182.276  
 182.277   out:
 182.278      process_deferred_ops(cpu);
 182.279  
 182.280      /* Add incremental work we have done to the @done output parameter. */
 182.281 -    if ( unlikely(pdone != NULL) )
 182.282 -        __put_user(done + i, pdone);
 182.283 +    done += i;
 182.284 +    if ( unlikely(!guest_handle_is_null(pdone)) )
 182.285 +        copy_to_guest(pdone, &done, 1);
 182.286  
 182.287      UNLOCK_BIGLOCK(d);
 182.288      return rc;
 182.289  }
 182.290  
 182.291  int do_mmu_update(
 182.292 -    struct mmu_update *ureqs,
 182.293 +    GUEST_HANDLE(mmu_update_t) ureqs,
 182.294      unsigned int count,
 182.295 -    unsigned int *pdone,
 182.296 +    GUEST_HANDLE(uint) pdone,
 182.297      unsigned int foreigndom)
 182.298  {
 182.299      struct mmu_update req;
 182.300 @@ -2010,8 +2034,8 @@ int do_mmu_update(
 182.301      if ( unlikely(count & MMU_UPDATE_PREEMPTED) )
 182.302      {
 182.303          count &= ~MMU_UPDATE_PREEMPTED;
 182.304 -        if ( unlikely(pdone != NULL) )
 182.305 -            (void)get_user(done, pdone);
 182.306 +        if ( unlikely(!guest_handle_is_null(pdone)) )
 182.307 +            (void)copy_from_guest(&done, pdone, 1);
 182.308      }
 182.309  
 182.310      domain_mmap_cache_init(&mapcache);
 182.311 @@ -2027,7 +2051,7 @@ int do_mmu_update(
 182.312      perfc_addc(num_page_updates, count);
 182.313      perfc_incr_histo(bpt_updates, count, PT_UPDATES);
 182.314  
 182.315 -    if ( unlikely(!array_access_ok(ureqs, count, sizeof(req))) )
 182.316 +    if ( unlikely(!guest_handle_okay(ureqs, count)) )
 182.317      {
 182.318          rc = -EFAULT;
 182.319          goto out;
 182.320 @@ -2038,14 +2062,14 @@ int do_mmu_update(
 182.321          if ( hypercall_preempt_check() )
 182.322          {
 182.323              rc = hypercall_create_continuation(
 182.324 -                __HYPERVISOR_mmu_update, "pipi",
 182.325 +                __HYPERVISOR_mmu_update, "hihi",
 182.326                  ureqs, (count - i) | MMU_UPDATE_PREEMPTED, pdone, foreigndom);
 182.327              break;
 182.328          }
 182.329  
 182.330 -        if ( unlikely(__copy_from_user(&req, ureqs, sizeof(req)) != 0) )
 182.331 +        if ( unlikely(__copy_from_guest(&req, ureqs, 1) != 0) )
 182.332          {
 182.333 -            MEM_LOG("Bad __copy_from_user");
 182.334 +            MEM_LOG("Bad __copy_from_guest");
 182.335              rc = -EFAULT;
 182.336              break;
 182.337          }
 182.338 @@ -2212,7 +2236,7 @@ int do_mmu_update(
 182.339              break;
 182.340          }
 182.341  
 182.342 -        ureqs++;
 182.343 +        guest_handle_add_offset(ureqs, 1);
 182.344      }
 182.345  
 182.346   out:
 182.347 @@ -2222,8 +2246,9 @@ int do_mmu_update(
 182.348      process_deferred_ops(cpu);
 182.349  
 182.350      /* Add incremental work we have done to the @done output parameter. */
 182.351 -    if ( unlikely(pdone != NULL) )
 182.352 -        __put_user(done + i, pdone);
 182.353 +    done += i;
 182.354 +    if ( unlikely(!guest_handle_is_null(pdone)) )
 182.355 +        copy_to_guest(pdone, &done, 1);
 182.356  
 182.357      if ( unlikely(shadow_mode_enabled(d)) )
 182.358          check_pagetable(v, "post-mmu"); /* debug */
 182.359 @@ -2684,7 +2709,7 @@ long set_gdt(struct vcpu *v,
 182.360  }
 182.361  
 182.362  
 182.363 -long do_set_gdt(unsigned long *frame_list, unsigned int entries)
 182.364 +long do_set_gdt(GUEST_HANDLE(ulong) frame_list, unsigned int entries)
 182.365  {
 182.366      int nr_pages = (entries + 511) / 512;
 182.367      unsigned long frames[16];
 182.368 @@ -2694,7 +2719,7 @@ long do_set_gdt(unsigned long *frame_lis
 182.369      if ( entries > FIRST_RESERVED_GDT_ENTRY )
 182.370          return -EINVAL;
 182.371      
 182.372 -    if ( copy_from_user(frames, frame_list, nr_pages * sizeof(unsigned long)) )
 182.373 +    if ( copy_from_guest((unsigned long *)frames, frame_list, nr_pages) )
 182.374          return -EFAULT;
 182.375  
 182.376      LOCK_BIGLOCK(current->domain);
 182.377 @@ -2790,52 +2815,60 @@ long do_update_descriptor(u64 pa, u64 de
 182.378  
 182.379  long arch_memory_op(int op, GUEST_HANDLE(void) arg)
 182.380  {
 182.381 -    struct xen_reserved_phys_area xrpa;
 182.382 -    unsigned long pfn;
 182.383 -    struct domain *d;
 182.384 -    unsigned int i;
 182.385 -
 182.386      switch ( op )
 182.387      {
 182.388 -    case XENMEM_reserved_phys_area:
 182.389 -        if ( copy_from_guest(&xrpa, arg, 1) )
 182.390 +    case XENMEM_add_to_physmap:
 182.391 +    {
 182.392 +        struct xen_add_to_physmap xatp;
 182.393 +        unsigned long mfn = 0, gpfn;
 182.394 +        struct domain *d;
 182.395 +
 182.396 +        if ( copy_from_guest(&xatp, arg, 1) )
 182.397              return -EFAULT;
 182.398  
 182.399 -        /* No guest has more than one reserved area. */
 182.400 -        if ( xrpa.idx != 0 )
 182.401 +        if ( (d = find_domain_by_id(xatp.domid)) == NULL )
 182.402              return -ESRCH;
 182.403  
 182.404 -        if ( (d = find_domain_by_id(xrpa.domid)) == NULL )
 182.405 -            return -ESRCH;
 182.406 -
 182.407 -        /* Only initialised translated guests have a reserved area. */
 182.408 -        if ( !shadow_mode_translate(d) || (d->max_pages == 0) )
 182.409 +        switch ( xatp.space )
 182.410 +        {
 182.411 +        case XENMAPSPACE_shared_info:
 182.412 +            if ( xatp.idx == 0 )
 182.413 +                mfn = virt_to_mfn(d->shared_info);
 182.414 +            break;
 182.415 +        case XENMAPSPACE_grant_table:
 182.416 +            if ( xatp.idx < NR_GRANT_FRAMES )
 182.417 +                mfn = virt_to_mfn(d->grant_table->shared) + xatp.idx;
 182.418 +            break;
 182.419 +        default:
 182.420 +            break;
 182.421 +        }
 182.422 +        
 182.423 +        if ( !shadow_mode_translate(d) || (mfn == 0) )
 182.424          {
 182.425              put_domain(d);
 182.426 -            return -ESRCH;
 182.427 +            return -EINVAL;
 182.428          }
 182.429  
 182.430          LOCK_BIGLOCK(d);
 182.431 -        if ( d->arch.first_reserved_pfn == 0 )
 182.432 -        {
 182.433 -            d->arch.first_reserved_pfn = pfn = d->max_pages;
 182.434 -            guest_physmap_add_page(
 182.435 -                d, pfn + 0, virt_to_maddr(d->shared_info) >> PAGE_SHIFT);
 182.436 -            for ( i = 0; i < NR_GRANT_FRAMES; i++ )
 182.437 -                guest_physmap_add_page(
 182.438 -                    d, pfn + 1 + i, gnttab_shared_mfn(d, d->grant_table, i));
 182.439 -        }
 182.440 +
 182.441 +        /* Remove previously mapped page if it was present. */
 182.442 +        if ( mfn_valid(gmfn_to_mfn(d, xatp.gpfn)) )
 182.443 +            guest_remove_page(d, xatp.gpfn);
 182.444 +
 182.445 +        /* Unmap from old location, if any. */
 182.446 +        gpfn = get_gpfn_from_mfn(mfn);
 182.447 +        if ( gpfn != INVALID_M2P_ENTRY )
 182.448 +            guest_physmap_remove_page(d, gpfn, mfn);
 182.449 +
 182.450 +        /* Map at new location. */
 182.451 +        guest_physmap_add_page(d, xatp.gpfn, mfn);
 182.452 +
 182.453          UNLOCK_BIGLOCK(d);
 182.454  
 182.455 -        xrpa.first_gpfn = d->arch.first_reserved_pfn;
 182.456 -        xrpa.nr_gpfns   = 32;
 182.457 -
 182.458          put_domain(d);
 182.459  
 182.460 -        if ( copy_to_guest(arg, &xrpa, 1) )
 182.461 -            return -EFAULT;
 182.462 -
 182.463          break;
 182.464 +    }
 182.465  
 182.466      default:
 182.467          return subarch_memory_op(op, arg);
   183.1 --- a/xen/arch/x86/physdev.c	Tue Mar 14 13:10:21 2006 -0700
   183.2 +++ b/xen/arch/x86/physdev.c	Tue Mar 14 13:50:35 2006 -0700
   183.3 @@ -6,6 +6,7 @@
   183.4  #include <xen/sched.h>
   183.5  #include <xen/irq.h>
   183.6  #include <xen/event.h>
   183.7 +#include <xen/guest_access.h>
   183.8  #include <asm/current.h>
   183.9  #include <asm/smpboot.h>
  183.10  #include <public/xen.h>
  183.11 @@ -21,13 +22,13 @@ ioapic_guest_write(
  183.12  /*
  183.13   * Demuxing hypercall.
  183.14   */
  183.15 -long do_physdev_op(struct physdev_op *uop)
  183.16 +long do_physdev_op(GUEST_HANDLE(physdev_op_t) uop)
  183.17  {
  183.18      struct physdev_op op;
  183.19      long ret;
  183.20      int  irq;
  183.21  
  183.22 -    if ( unlikely(copy_from_user(&op, uop, sizeof(op)) != 0) )
  183.23 +    if ( unlikely(copy_from_guest(&op, uop, 1) != 0) )
  183.24          return -EFAULT;
  183.25  
  183.26      switch ( op.cmd )
  183.27 @@ -101,7 +102,7 @@ long do_physdev_op(struct physdev_op *uo
  183.28          break;
  183.29      }
  183.30  
  183.31 -    if ( copy_to_user(uop, &op, sizeof(op)) )
  183.32 +    if ( copy_to_guest(uop, &op, 1) )
  183.33          ret = -EFAULT;
  183.34  
  183.35      return ret;
   184.1 --- a/xen/arch/x86/shadow.c	Tue Mar 14 13:10:21 2006 -0700
   184.2 +++ b/xen/arch/x86/shadow.c	Tue Mar 14 13:50:35 2006 -0700
   184.3 @@ -202,6 +202,16 @@ shadow_promote(struct domain *d, unsigne
   184.4   * tlbflush_timestamp holds a min & max index of valid page table entries
   184.5   * within the shadow page.
   184.6   */
   184.7 +static inline void
   184.8 +shadow_page_info_init(struct page_info *page,
   184.9 +                      unsigned long gmfn,
  184.10 +                      u32 psh_type)
  184.11 +{
  184.12 +    ASSERT( (gmfn & ~PGT_mfn_mask) == 0 );
  184.13 +    page->u.inuse.type_info = psh_type | gmfn;
  184.14 +    page->count_info = 0;
  184.15 +    page->tlbflush_timestamp = 0;
  184.16 +}
  184.17  
  184.18  static inline unsigned long
  184.19  alloc_shadow_page(struct domain *d,
  184.20 @@ -249,6 +259,11 @@ alloc_shadow_page(struct domain *d,
  184.21                  l1 = map_domain_page(page_to_mfn(page + 1));
  184.22                  memset(l1, 0, PAGE_SIZE);
  184.23                  unmap_domain_page(l1);
  184.24 +
  184.25 +                /* we'd like to initialize the second continuous page here
  184.26 +                 * and leave the first page initialization later */
  184.27 +
  184.28 +                shadow_page_info_init(page+1, gmfn, psh_type);
  184.29  #else
  184.30                  page = alloc_domheap_page(NULL);
  184.31                  if (!page)
  184.32 @@ -294,10 +309,7 @@ alloc_shadow_page(struct domain *d,
  184.33  
  184.34      smfn = page_to_mfn(page);
  184.35  
  184.36 -    ASSERT( (gmfn & ~PGT_mfn_mask) == 0 );
  184.37 -    page->u.inuse.type_info = psh_type | gmfn;
  184.38 -    page->count_info = 0;
  184.39 -    page->tlbflush_timestamp = 0;
  184.40 +    shadow_page_info_init(page, gmfn, psh_type);
  184.41  
  184.42      switch ( psh_type )
  184.43      {
  184.44 @@ -3401,7 +3413,9 @@ static inline int l2e_rw_fault(
  184.45      l1_pgentry_t sl1e;
  184.46      l1_pgentry_t old_sl1e;
  184.47      l2_pgentry_t sl2e;
  184.48 +#ifdef __x86_64__
  184.49      u64 nx = 0;
  184.50 +#endif
  184.51      int put_ref_check = 0;
  184.52      /* Check if gpfn is 2M aligned */
  184.53  
  184.54 @@ -3416,7 +3430,9 @@ static inline int l2e_rw_fault(
  184.55      l2e_remove_flags(tmp_l2e, _PAGE_PSE);
  184.56      if (l2e_get_flags(gl2e) & _PAGE_NX) {
  184.57          l2e_remove_flags(tmp_l2e, _PAGE_NX);
  184.58 -        nx = 1ULL << 63;
  184.59 +#ifdef __x86_64__
  184.60 +        nx = PGT_high_mfn_nx;
  184.61 +#endif
  184.62      }
  184.63  
  184.64  
  184.65 @@ -3424,7 +3440,11 @@ static inline int l2e_rw_fault(
  184.66      if ( !__shadow_get_l2e(v, va, &sl2e) )
  184.67          sl2e = l2e_empty();
  184.68  
  184.69 +#ifdef __x86_64__
  184.70      l1_mfn = __shadow_status(d, start_gpfn | nx, PGT_fl1_shadow);
  184.71 +#else
  184.72 +    l1_mfn = __shadow_status(d, start_gpfn, PGT_fl1_shadow);
  184.73 +#endif
  184.74  
  184.75      /* Check the corresponding l2e */
  184.76      if (l1_mfn) {
  184.77 @@ -3442,7 +3462,11 @@ static inline int l2e_rw_fault(
  184.78      } else {
  184.79          /* Allocate a new page as shadow page table if need */
  184.80          gmfn = gmfn_to_mfn(d, start_gpfn);
  184.81 +#ifdef __x86_64__
  184.82          l1_mfn = alloc_shadow_page(d, start_gpfn | nx, gmfn, PGT_fl1_shadow);
  184.83 +#else
  184.84 +        l1_mfn = alloc_shadow_page(d, start_gpfn, gmfn, PGT_fl1_shadow);
  184.85 +#endif
  184.86          if (unlikely(!l1_mfn)) {
  184.87              BUG();
  184.88          }
  184.89 @@ -3583,6 +3607,11 @@ static inline int guest_page_fault(
  184.90  
  184.91      ASSERT( d->arch.ops->guest_paging_levels >= PAGING_L3 );
  184.92  
  184.93 +#if CONFIG_PAGING_LEVELS >= 4
  184.94 +    if ( (error_code & (ERROR_I | ERROR_P)) == (ERROR_I | ERROR_P) )
  184.95 +        return 1;
  184.96 +#endif
  184.97 +
  184.98  #if CONFIG_PAGING_LEVELS == 4
  184.99      if ( d->arch.ops->guest_paging_levels == PAGING_L4 ) 
 184.100      {
   185.1 --- a/xen/arch/x86/traps.c	Tue Mar 14 13:10:21 2006 -0700
   185.2 +++ b/xen/arch/x86/traps.c	Tue Mar 14 13:50:35 2006 -0700
   185.3 @@ -132,10 +132,10 @@ static void show_guest_stack(struct cpu_
   185.4      int i;
   185.5      unsigned long *stack, addr;
   185.6  
   185.7 -    if ( HVM_DOMAIN(current) )
   185.8 +    if ( hvm_guest(current) )
   185.9          return;
  185.10  
  185.11 -    if ( VM86_MODE(regs) )
  185.12 +    if ( vm86_mode(regs) )
  185.13      {
  185.14          stack = (unsigned long *)((regs->ss << 4) + (regs->esp & 0xffff));
  185.15          printk("Guest stack trace from ss:sp = %04x:%04x (VM86)\n   ",
  185.16 @@ -254,7 +254,7 @@ void show_stack(struct cpu_user_regs *re
  185.17      unsigned long *stack = ESP_BEFORE_EXCEPTION(regs), addr;
  185.18      int i;
  185.19  
  185.20 -    if ( GUEST_MODE(regs) )
  185.21 +    if ( guest_mode(regs) )
  185.22          return show_guest_stack(regs);
  185.23  
  185.24      printk("Xen stack trace from "__OP"sp=%p:\n   ", stack);
  185.25 @@ -333,7 +333,7 @@ static inline int do_trap(int trapnr, ch
  185.26  
  185.27      DEBUGGER_trap_entry(trapnr, regs);
  185.28  
  185.29 -    if ( !GUEST_MODE(regs) )
  185.30 +    if ( !guest_mode(regs) )
  185.31          goto xen_fault;
  185.32  
  185.33      ti = &current->arch.guest_context.trap_ctxt[trapnr];
  185.34 @@ -399,7 +399,7 @@ asmlinkage int do_int3(struct cpu_user_r
  185.35  
  185.36      DEBUGGER_trap_entry(TRAP_int3, regs);
  185.37  
  185.38 -    if ( !GUEST_MODE(regs) )
  185.39 +    if ( !guest_mode(regs) )
  185.40      {
  185.41          DEBUGGER_trap_fatal(TRAP_int3, regs);
  185.42          show_registers(regs);
  185.43 @@ -431,6 +431,11 @@ void propagate_page_fault(unsigned long 
  185.44      v->arch.guest_context.ctrlreg[2] = addr;
  185.45      v->vcpu_info->arch.cr2           = addr;
  185.46  
  185.47 +    /* Re-set error_code.user flag appropriately for the guest. */
  185.48 +    error_code &= ~4;
  185.49 +    if ( !guest_kernel_mode(v, guest_cpu_user_regs()) )
  185.50 +        error_code |= 4;
  185.51 +
  185.52      ti = &v->arch.guest_context.trap_ctxt[TRAP_page_fault];
  185.53      tb->flags = TBF_EXCEPTION | TBF_EXCEPTION_ERRCODE;
  185.54      tb->error_code = error_code;
  185.55 @@ -469,7 +474,7 @@ static int handle_gdt_ldt_mapping_fault(
  185.56          if ( unlikely(ret == 0) )
  185.57          {
  185.58              /* In hypervisor mode? Leave it to the #PF handler to fix up. */
  185.59 -            if ( !GUEST_MODE(regs) )
  185.60 +            if ( !guest_mode(regs) )
  185.61                  return 0;
  185.62              /* In guest mode? Propagate #PF to guest, with adjusted %cr2. */
  185.63              propagate_page_fault(
  185.64 @@ -501,7 +506,7 @@ static int fixup_page_fault(unsigned lon
  185.65  
  185.66      if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )
  185.67      {
  185.68 -        if ( shadow_mode_external(d) && GUEST_MODE(regs) )
  185.69 +        if ( shadow_mode_external(d) && guest_mode(regs) )
  185.70              return shadow_fault(addr, regs);
  185.71          if ( (addr >= GDT_LDT_VIRT_START) && (addr < GDT_LDT_VIRT_END) )
  185.72              return handle_gdt_ldt_mapping_fault(
  185.73 @@ -523,7 +528,7 @@ static int fixup_page_fault(unsigned lon
  185.74              return EXCRET_fault_fixed;
  185.75          }
  185.76  
  185.77 -        if ( KERNEL_MODE(v, regs) &&
  185.78 +        if ( guest_kernel_mode(v, regs) &&
  185.79               /* Protection violation on write? No reserved-bit violation? */
  185.80               ((regs->error_code & 0xb) == 0x3) &&
  185.81               ptwr_do_page_fault(d, addr, regs) )
  185.82 @@ -541,7 +546,7 @@ static int fixup_page_fault(unsigned lon
  185.83   * #PF error code:
  185.84   *  Bit 0: Protection violation (=1) ; Page not present (=0)
  185.85   *  Bit 1: Write access
  185.86 - *  Bit 2: Supervisor mode
  185.87 + *  Bit 2: User mode (=1) ; Supervisor mode (=0)
  185.88   *  Bit 3: Reserved bit violation
  185.89   *  Bit 4: Instruction fetch
  185.90   */
  185.91 @@ -559,7 +564,7 @@ asmlinkage int do_page_fault(struct cpu_
  185.92      if ( unlikely((rc = fixup_page_fault(addr, regs)) != 0) )
  185.93          return rc;
  185.94  
  185.95 -    if ( unlikely(!GUEST_MODE(regs)) )
  185.96 +    if ( unlikely(!guest_mode(regs)) )
  185.97      {
  185.98          if ( likely((fixup = search_exception_table(regs->eip)) != 0) )
  185.99          {
 185.100 @@ -615,7 +620,7 @@ static inline int guest_io_okay(
 185.101  #define TOGGLE_MODE() ((void)0)
 185.102  #endif
 185.103  
 185.104 -    if ( v->arch.iopl >= (KERNEL_MODE(v, regs) ? 1 : 3) )
 185.105 +    if ( v->arch.iopl >= (guest_kernel_mode(v, regs) ? 1 : 3) )
 185.106          return 1;
 185.107  
 185.108      if ( v->arch.iobmp_limit > (port + bytes) )
 185.109 @@ -844,7 +849,7 @@ static int emulate_privileged_op(struct 
 185.110  
 185.111      case 0xfa: /* CLI */
 185.112      case 0xfb: /* STI */
 185.113 -        if ( v->arch.iopl < (KERNEL_MODE(v, regs) ? 1 : 3) )
 185.114 +        if ( v->arch.iopl < (guest_kernel_mode(v, regs) ? 1 : 3) )
 185.115              goto fail;
 185.116          /*
 185.117           * This is just too dangerous to allow, in my opinion. Consider if the
 185.118 @@ -863,7 +868,7 @@ static int emulate_privileged_op(struct 
 185.119      }
 185.120  
 185.121      /* Remaining instructions only emulated from guest kernel. */
 185.122 -    if ( !KERNEL_MODE(v, regs) )
 185.123 +    if ( !guest_kernel_mode(v, regs) )
 185.124          goto fail;
 185.125  
 185.126      /* Privileged (ring 0) instructions. */
 185.127 @@ -1065,7 +1070,7 @@ asmlinkage int do_general_protection(str
 185.128      if ( regs->error_code & 1 )
 185.129          goto hardware_gp;
 185.130  
 185.131 -    if ( !GUEST_MODE(regs) )
 185.132 +    if ( !guest_mode(regs) )
 185.133          goto gp_in_kernel;
 185.134  
 185.135      /*
 185.136 @@ -1092,7 +1097,7 @@ asmlinkage int do_general_protection(str
 185.137      {
 185.138          /* This fault must be due to <INT n> instruction. */
 185.139          ti = &current->arch.guest_context.trap_ctxt[regs->error_code>>3];
 185.140 -        if ( PERMIT_SOFTINT(TI_GET_DPL(ti), v, regs) )
 185.141 +        if ( permit_softint(TI_GET_DPL(ti), v, regs) )
 185.142          {
 185.143              tb->flags = TBF_EXCEPTION;
 185.144              regs->eip += 2;
 185.145 @@ -1300,7 +1305,7 @@ asmlinkage int do_debug(struct cpu_user_
 185.146  
 185.147      DEBUGGER_trap_entry(TRAP_debug, regs);
 185.148  
 185.149 -    if ( !GUEST_MODE(regs) )
 185.150 +    if ( !guest_mode(regs) )
 185.151      {
 185.152          /* Clear TF just for absolute sanity. */
 185.153          regs->eflags &= ~EF_TF;
 185.154 @@ -1404,14 +1409,14 @@ void __init trap_init(void)
 185.155  }
 185.156  
 185.157  
 185.158 -long do_set_trap_table(struct trap_info *traps)
 185.159 +long do_set_trap_table(GUEST_HANDLE(trap_info_t) traps)
 185.160  {
 185.161      struct trap_info cur;
 185.162      struct trap_info *dst = current->arch.guest_context.trap_ctxt;
 185.163      long rc = 0;
 185.164  
 185.165      /* If no table is presented then clear the entire virtual IDT. */
 185.166 -    if ( traps == NULL )
 185.167 +    if ( guest_handle_is_null(traps) )
 185.168      {
 185.169          memset(dst, 0, 256 * sizeof(*dst));
 185.170          init_int80_direct_trap(current);
 185.171 @@ -1423,11 +1428,11 @@ long do_set_trap_table(struct trap_info 
 185.172          if ( hypercall_preempt_check() )
 185.173          {
 185.174              rc = hypercall_create_continuation(
 185.175 -                __HYPERVISOR_set_trap_table, "p", traps);
 185.176 +                __HYPERVISOR_set_trap_table, "h", traps);
 185.177              break;
 185.178          }
 185.179  
 185.180 -        if ( copy_from_user(&cur, traps, sizeof(cur)) ) 
 185.181 +        if ( copy_from_guest(&cur, traps, 1) )
 185.182          {
 185.183              rc = -EFAULT;
 185.184              break;
 185.185 @@ -1443,7 +1448,7 @@ long do_set_trap_table(struct trap_info 
 185.186          if ( cur.vector == 0x80 )
 185.187              init_int80_direct_trap(current);
 185.188  
 185.189 -        traps++;
 185.190 +        guest_handle_add_offset(traps, 1);
 185.191      }
 185.192  
 185.193      return rc;
   186.1 --- a/xen/arch/x86/x86_32/domain_page.c	Tue Mar 14 13:10:21 2006 -0700
   186.2 +++ b/xen/arch/x86/x86_32/domain_page.c	Tue Mar 14 13:50:35 2006 -0700
   186.3 @@ -28,7 +28,7 @@ static inline struct vcpu *mapcache_curr
   186.4       * then it means we are running on the idle domain's page table and must
   186.5       * therefore use its mapcache.
   186.6       */
   186.7 -    if ( unlikely(!pagetable_get_pfn(v->arch.guest_table)) && !HVM_DOMAIN(v) )
   186.8 +    if ( unlikely(!pagetable_get_pfn(v->arch.guest_table)) && !hvm_guest(v) )
   186.9      {
  186.10          /* If we really are idling, perform lazy context switch now. */
  186.11          if ( (v = idle_vcpu[smp_processor_id()]) == current )
   187.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Mar 14 13:10:21 2006 -0700
   187.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Mar 14 13:50:35 2006 -0700
   187.3 @@ -586,6 +586,13 @@ do_arch_sched_op:
   187.4          movl %eax,UREGS_eax(%ecx)
   187.5          jmp  do_sched_op
   187.6  
   187.7 +do_arch_sched_op_new:
   187.8 +        # Ensure we return success even if we return via schedule_tail()
   187.9 +        xorl %eax,%eax
  187.10 +        GET_GUEST_REGS(%ecx)
  187.11 +        movl %eax,UREGS_eax(%ecx)
  187.12 +        jmp  do_sched_op_new
  187.13 +
  187.14  .data
  187.15  
  187.16  ENTRY(exception_table)
  187.17 @@ -640,6 +647,7 @@ ENTRY(hypercall_table)
  187.18          .long do_mmuext_op
  187.19          .long do_acm_op
  187.20          .long do_nmi_op
  187.21 +        .long do_arch_sched_op_new
  187.22          .rept NR_hypercalls-((.-hypercall_table)/4)
  187.23          .long do_ni_hypercall
  187.24          .endr
  187.25 @@ -674,6 +682,7 @@ ENTRY(hypercall_args_table)
  187.26          .byte 4 /* do_mmuext_op         */
  187.27          .byte 1 /* do_acm_op            */
  187.28          .byte 2 /* do_nmi_op            */
  187.29 +        .byte 2 /* do_arch_sched_op_new */
  187.30          .rept NR_hypercalls-(.-hypercall_args_table)
  187.31          .byte 0 /* do_ni_hypercall      */
  187.32          .endr
   188.1 --- a/xen/arch/x86/x86_32/mm.c	Tue Mar 14 13:10:21 2006 -0700
   188.2 +++ b/xen/arch/x86/x86_32/mm.c	Tue Mar 14 13:50:35 2006 -0700
   188.3 @@ -144,7 +144,7 @@ void __init zap_low_mappings(l2_pgentry_
   188.4      flush_tlb_all_pge();
   188.5  }
   188.6  
   188.7 -void subarch_init_memory(struct domain *dom_xen)
   188.8 +void subarch_init_memory(void)
   188.9  {
  188.10      unsigned long m2p_start_mfn;
  188.11      unsigned int i, j;
  188.12 @@ -175,10 +175,7 @@ void subarch_init_memory(struct domain *
  188.13          for ( j = 0; j < L2_PAGETABLE_ENTRIES; j++ )
  188.14          {
  188.15              struct page_info *page = mfn_to_page(m2p_start_mfn + j);
  188.16 -            page->count_info = PGC_allocated | 1;
  188.17 -            /* Ensure it's only mapped read-only by domains. */
  188.18 -            page->u.inuse.type_info = PGT_gdt_page | 1;
  188.19 -            page_set_owner(page, dom_xen);
  188.20 +            share_xen_page_with_privileged_guests(page, XENSHARE_readonly);
  188.21          }
  188.22      }
  188.23  
   189.1 --- a/xen/arch/x86/x86_32/seg_fixup.c	Tue Mar 14 13:10:21 2006 -0700
   189.2 +++ b/xen/arch/x86/x86_32/seg_fixup.c	Tue Mar 14 13:50:35 2006 -0700
   189.3 @@ -280,7 +280,7 @@ int gpf_emulate_4gb(struct cpu_user_regs
   189.4      int            gs_override = 0;
   189.5  
   189.6      /* WARNING: We only work for ring-3 segments. */
   189.7 -    if ( unlikely(VM86_MODE(regs)) || unlikely(!RING_3(regs)) )
   189.8 +    if ( unlikely(vm86_mode(regs)) || unlikely(!ring_3(regs)) )
   189.9      {
  189.10          DPRINTK("Taken fault at bad CS %04x\n", regs->cs);
  189.11          goto fail;
   190.1 --- a/xen/arch/x86/x86_32/traps.c	Tue Mar 14 13:10:21 2006 -0700
   190.2 +++ b/xen/arch/x86/x86_32/traps.c	Tue Mar 14 13:50:35 2006 -0700
   190.3 @@ -24,7 +24,7 @@ void show_registers(struct cpu_user_regs
   190.4      char taint_str[TAINT_STRING_MAX_LEN];
   190.5      const char *context;
   190.6  
   190.7 -    if ( HVM_DOMAIN(current) && GUEST_MODE(regs) )
   190.8 +    if ( hvm_guest(current) && guest_mode(regs) )
   190.9      {
  190.10          context = "hvm";
  190.11          hvm_store_cpu_guest_regs(current, &fault_regs);
  190.12 @@ -32,9 +32,9 @@ void show_registers(struct cpu_user_regs
  190.13      }
  190.14      else
  190.15      {
  190.16 -        context = GUEST_MODE(regs) ? "guest" : "hypervisor";
  190.17 +        context = guest_mode(regs) ? "guest" : "hypervisor";
  190.18  
  190.19 -        if ( !GUEST_MODE(regs) )
  190.20 +        if ( !guest_mode(regs) )
  190.21          {
  190.22              fault_regs.esp = (unsigned long)&regs->esp;
  190.23              fault_regs.ss = read_segment_register(ss);
  190.24 @@ -53,7 +53,7 @@ void show_registers(struct cpu_user_regs
  190.25             print_tainted(taint_str));
  190.26      printk("CPU:    %d\nEIP:    %04x:[<%08x>]",
  190.27             smp_processor_id(), fault_regs.cs, fault_regs.eip);
  190.28 -    if ( !GUEST_MODE(regs) )
  190.29 +    if ( !guest_mode(regs) )
  190.30          print_symbol(" %s", fault_regs.eip);
  190.31      printk("\nEFLAGS: %08x   CONTEXT: %s\n", fault_regs.eflags, context);
  190.32      printk("eax: %08x   ebx: %08x   ecx: %08x   edx: %08x\n",
  190.33 @@ -172,17 +172,17 @@ unsigned long do_iret(void)
  190.34      regs->esp += 4;
  190.35      regs->eflags = (eflags & ~X86_EFLAGS_IOPL) | X86_EFLAGS_IF;
  190.36  
  190.37 -    if ( VM86_MODE(regs) )
  190.38 +    if ( vm86_mode(regs) )
  190.39      {
  190.40          /* Return to VM86 mode: pop and restore ESP,SS,ES,DS,FS and GS. */
  190.41          if ( __copy_from_user(&regs->esp, (void __user *)regs->esp, 24) )
  190.42              domain_crash_synchronous();
  190.43      }
  190.44 -    else if ( unlikely(RING_0(regs)) )
  190.45 +    else if ( unlikely(ring_0(regs)) )
  190.46      {
  190.47          domain_crash_synchronous();
  190.48      }
  190.49 -    else if ( !RING_1(regs) )
  190.50 +    else if ( !ring_1(regs) )
  190.51      {
  190.52          /* Return to ring 2/3: pop and restore ESP and SS. */
  190.53          if ( __copy_from_user(&regs->esp, (void __user *)regs->esp, 8) )
   191.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Mar 14 13:10:21 2006 -0700
   191.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Mar 14 13:50:35 2006 -0700
   191.3 @@ -495,6 +495,13 @@ do_arch_sched_op:
   191.4          movq  %rax,UREGS_rax(%r10)
   191.5          jmp   do_sched_op
   191.6  
   191.7 +do_arch_sched_op_new:
   191.8 +        # Ensure we return success even if we return via schedule_tail()
   191.9 +        xorl  %eax,%eax
  191.10 +        GET_GUEST_REGS(%r10)
  191.11 +        movq  %rax,UREGS_rax(%r10)
  191.12 +        jmp   do_sched_op_new
  191.13 +
  191.14  .data
  191.15  
  191.16  ENTRY(exception_table)
  191.17 @@ -549,6 +556,7 @@ ENTRY(hypercall_table)
  191.18          .quad do_mmuext_op
  191.19          .quad do_acm_op
  191.20          .quad do_nmi_op
  191.21