ia64/xen-unstable

changeset 9739:41823e46d6ac

merge with xen-unstable.hg
author awilliam@xenbuild.aw
date Tue Apr 18 09:35:40 2006 -0600 (2006-04-18)
parents 4ed269e73e95 c4eead8a925b
children a1add4e39878
files tools/ioemu/vl.c tools/libxc/xc_ia64_stubs.c xen/include/asm-x86/mach-default/irq_vectors_limits.h
line diff
     1.1 --- a/.hgignore	Mon Apr 17 08:47:36 2006 -0600
     1.2 +++ b/.hgignore	Tue Apr 18 09:35:40 2006 -0600
     1.3 @@ -184,6 +184,7 @@
     1.4  ^tools/xm-test/ramdisk/buildroot
     1.5  ^xen/BLOG$
     1.6  ^xen/TAGS$
     1.7 +^xen/cscope\.*$
     1.8  ^xen/arch/x86/asm-offsets\.s$
     1.9  ^xen/arch/x86/boot/mkelf32$
    1.10  ^xen/arch/x86/xen\.lds$
     2.1 --- a/buildconfigs/Rules.mk	Mon Apr 17 08:47:36 2006 -0600
     2.2 +++ b/buildconfigs/Rules.mk	Tue Apr 18 09:35:40 2006 -0600
     2.3 @@ -99,14 +99,14 @@ endif
     2.4  linux-2.6-xen.patch: ref-linux-$(LINUX_VER)/.valid-ref
     2.5  	rm -rf tmp-$@
     2.6  	cp -al $(<D) tmp-$@
     2.7 -	( cd linux-2.6-xen-sparse && ./mkbuildtree ../tmp-$@ )	
     2.8 +	( cd linux-2.6-xen-sparse && bash ./mkbuildtree ../tmp-$@ )	
     2.9  	diff -Nurp $(patsubst ref%,pristine%,$(<D)) tmp-$@ > $@ || true
    2.10  	rm -rf tmp-$@
    2.11  
    2.12  %-xen.patch: ref-%/.valid-ref
    2.13  	rm -rf tmp-$@
    2.14  	cp -al $(<D) tmp-$@
    2.15 -	( cd $*-xen-sparse && ./mkbuildtree ../tmp-$@ )	
    2.16 +	( cd $*-xen-sparse && bash ./mkbuildtree ../tmp-$@ )	
    2.17  	diff -Nurp $(patsubst ref%,pristine%,$(<D)) tmp-$@ > $@ || true
    2.18  	rm -rf tmp-$@
    2.19  
     3.1 --- a/buildconfigs/linux-defconfig_xen0_x86_64	Mon Apr 17 08:47:36 2006 -0600
     3.2 +++ b/buildconfigs/linux-defconfig_xen0_x86_64	Tue Apr 18 09:35:40 2006 -0600
     3.3 @@ -1,7 +1,7 @@
     3.4  #
     3.5  # Automatically generated make config: don't edit
     3.6 -# Linux kernel version: 2.6.16-rc3-xen0
     3.7 -# Mon Feb 20 11:37:43 2006
     3.8 +# Linux kernel version: 2.6.16-xen0
     3.9 +# Thu Apr 13 14:58:29 2006
    3.10  #
    3.11  CONFIG_X86_64=y
    3.12  CONFIG_64BIT=y
    3.13 @@ -99,6 +99,8 @@ CONFIG_X86_PC=y
    3.14  # CONFIG_MPSC is not set
    3.15  CONFIG_GENERIC_CPU=y
    3.16  CONFIG_X86_64_XEN=y
    3.17 +CONFIG_X86_NO_TSS=y
    3.18 +CONFIG_X86_NO_IDT=y
    3.19  CONFIG_X86_L1_CACHE_BYTES=128
    3.20  CONFIG_X86_L1_CACHE_SHIFT=7
    3.21  CONFIG_X86_GOOD_APIC=y
    3.22 @@ -176,6 +178,19 @@ CONFIG_PCI_DIRECT=y
    3.23  CONFIG_XEN_PCIDEV_FRONTEND=y
    3.24  # CONFIG_XEN_PCIDEV_FE_DEBUG is not set
    3.25  # CONFIG_UNORDERED_IO is not set
    3.26 +# CONFIG_PCIEPORTBUS is not set
    3.27 +CONFIG_PCI_LEGACY_PROC=y
    3.28 +# CONFIG_PCI_DEBUG is not set
    3.29 +
    3.30 +#
    3.31 +# PCCARD (PCMCIA/CardBus) support
    3.32 +#
    3.33 +# CONFIG_PCCARD is not set
    3.34 +
    3.35 +#
    3.36 +# PCI Hotplug Support
    3.37 +#
    3.38 +# CONFIG_HOTPLUG_PCI is not set
    3.39  
    3.40  #
    3.41  # Executable file formats / Emulations
    3.42 @@ -1001,11 +1016,7 @@ CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=y
    3.43  CONFIG_INFINIBAND_SRP=y
    3.44  
    3.45  #
    3.46 -# SN Devices
    3.47 -#
    3.48 -
    3.49 -#
    3.50 -# EDAC - error detection and reporting (RAS)
    3.51 +# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
    3.52  #
    3.53  # CONFIG_EDAC is not set
    3.54  
    3.55 @@ -1239,7 +1250,7 @@ CONFIG_CRYPTO_CRC32C=m
    3.56  # Hardware crypto devices
    3.57  #
    3.58  CONFIG_XEN=y
    3.59 -CONFIG_NO_IDLE_HZ=y
    3.60 +CONFIG_XEN_INTERFACE_VERSION=0x00030101
    3.61  
    3.62  #
    3.63  # XEN
    3.64 @@ -1266,6 +1277,7 @@ CONFIG_XEN_DISABLE_SERIAL=y
    3.65  CONFIG_XEN_SYSFS=y
    3.66  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    3.67  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    3.68 +CONFIG_NO_IDLE_HZ=y
    3.69  
    3.70  #
    3.71  # Library routines
     4.1 --- a/buildconfigs/linux-defconfig_xenU_x86_64	Mon Apr 17 08:47:36 2006 -0600
     4.2 +++ b/buildconfigs/linux-defconfig_xenU_x86_64	Tue Apr 18 09:35:40 2006 -0600
     4.3 @@ -1,7 +1,7 @@
     4.4  #
     4.5  # Automatically generated make config: don't edit
     4.6 -# Linux kernel version: 2.6.16-rc3-xen0
     4.7 -# Thu Feb 16 22:56:02 2006
     4.8 +# Linux kernel version: 2.6.16-xenU
     4.9 +# Thu Apr 13 14:59:16 2006
    4.10  #
    4.11  CONFIG_X86_64=y
    4.12  CONFIG_64BIT=y
    4.13 @@ -103,6 +103,8 @@ CONFIG_X86_PC=y
    4.14  CONFIG_MPSC=y
    4.15  # CONFIG_GENERIC_CPU is not set
    4.16  CONFIG_X86_64_XEN=y
    4.17 +CONFIG_X86_NO_TSS=y
    4.18 +CONFIG_X86_NO_IDT=y
    4.19  CONFIG_X86_L1_CACHE_BYTES=128
    4.20  CONFIG_X86_L1_CACHE_SHIFT=7
    4.21  CONFIG_X86_GOOD_APIC=y
    4.22 @@ -147,6 +149,15 @@ CONFIG_GENERIC_PENDING_IRQ=y
    4.23  # CONFIG_UNORDERED_IO is not set
    4.24  
    4.25  #
    4.26 +# PCCARD (PCMCIA/CardBus) support
    4.27 +#
    4.28 +# CONFIG_PCCARD is not set
    4.29 +
    4.30 +#
    4.31 +# PCI Hotplug Support
    4.32 +#
    4.33 +
    4.34 +#
    4.35  # Executable file formats / Emulations
    4.36  #
    4.37  CONFIG_BINFMT_ELF=y
    4.38 @@ -844,11 +855,7 @@ CONFIG_DUMMY_CONSOLE=y
    4.39  #
    4.40  
    4.41  #
    4.42 -# SN Devices
    4.43 -#
    4.44 -
    4.45 -#
    4.46 -# EDAC - error detection and reporting (RAS)
    4.47 +# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
    4.48  #
    4.49  # CONFIG_EDAC is not set
    4.50  
    4.51 @@ -1128,7 +1135,7 @@ CONFIG_CRYPTO_CRC32C=m
    4.52  # Hardware crypto devices
    4.53  #
    4.54  CONFIG_XEN=y
    4.55 -CONFIG_NO_IDLE_HZ=y
    4.56 +CONFIG_XEN_INTERFACE_VERSION=0x00030101
    4.57  
    4.58  #
    4.59  # XEN
    4.60 @@ -1144,6 +1151,7 @@ CONFIG_XEN_DISABLE_SERIAL=y
    4.61  CONFIG_XEN_SYSFS=y
    4.62  CONFIG_HAVE_ARCH_ALLOC_SKB=y
    4.63  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
    4.64 +CONFIG_NO_IDLE_HZ=y
    4.65  
    4.66  #
    4.67  # Library routines
     5.1 --- a/buildconfigs/linux-defconfig_xen_x86_64	Mon Apr 17 08:47:36 2006 -0600
     5.2 +++ b/buildconfigs/linux-defconfig_xen_x86_64	Tue Apr 18 09:35:40 2006 -0600
     5.3 @@ -1,7 +1,7 @@
     5.4  #
     5.5  # Automatically generated make config: don't edit
     5.6  # Linux kernel version: 2.6.16-xen
     5.7 -# Mon Mar 27 09:43:44 2006
     5.8 +# Thu Apr 13 15:01:04 2006
     5.9  #
    5.10  CONFIG_X86_64=y
    5.11  CONFIG_64BIT=y
    5.12 @@ -186,6 +186,41 @@ CONFIG_PCI_DIRECT=y
    5.13  CONFIG_XEN_PCIDEV_FRONTEND=y
    5.14  # CONFIG_XEN_PCIDEV_FE_DEBUG is not set
    5.15  # CONFIG_UNORDERED_IO is not set
    5.16 +# CONFIG_PCIEPORTBUS is not set
    5.17 +# CONFIG_PCI_LEGACY_PROC is not set
    5.18 +# CONFIG_PCI_DEBUG is not set
    5.19 +
    5.20 +#
    5.21 +# PCCARD (PCMCIA/CardBus) support
    5.22 +#
    5.23 +CONFIG_PCCARD=m
    5.24 +# CONFIG_PCMCIA_DEBUG is not set
    5.25 +CONFIG_PCMCIA=m
    5.26 +CONFIG_PCMCIA_LOAD_CIS=y
    5.27 +CONFIG_PCMCIA_IOCTL=y
    5.28 +CONFIG_CARDBUS=y
    5.29 +
    5.30 +#
    5.31 +# PC-card bridges
    5.32 +#
    5.33 +CONFIG_YENTA=m
    5.34 +CONFIG_YENTA_O2=y
    5.35 +CONFIG_YENTA_RICOH=y
    5.36 +CONFIG_YENTA_TI=y
    5.37 +CONFIG_YENTA_ENE_TUNE=y
    5.38 +CONFIG_YENTA_TOSHIBA=y
    5.39 +CONFIG_PD6729=m
    5.40 +CONFIG_I82092=m
    5.41 +CONFIG_PCCARD_NONSTATIC=m
    5.42 +
    5.43 +#
    5.44 +# PCI Hotplug Support
    5.45 +#
    5.46 +CONFIG_HOTPLUG_PCI=m
    5.47 +# CONFIG_HOTPLUG_PCI_FAKE is not set
    5.48 +# CONFIG_HOTPLUG_PCI_ACPI is not set
    5.49 +# CONFIG_HOTPLUG_PCI_CPCI is not set
    5.50 +# CONFIG_HOTPLUG_PCI_SHPC is not set
    5.51  
    5.52  #
    5.53  # Executable file formats / Emulations
    5.54 @@ -625,6 +660,10 @@ CONFIG_BT_HCIUART_BCSP=y
    5.55  CONFIG_BT_HCIBCM203X=m
    5.56  CONFIG_BT_HCIBPA10X=m
    5.57  CONFIG_BT_HCIBFUSB=m
    5.58 +# CONFIG_BT_HCIDTL1 is not set
    5.59 +# CONFIG_BT_HCIBT3C is not set
    5.60 +# CONFIG_BT_HCIBLUECARD is not set
    5.61 +# CONFIG_BT_HCIBTUART is not set
    5.62  CONFIG_BT_HCIVHCI=m
    5.63  CONFIG_IEEE80211=m
    5.64  # CONFIG_IEEE80211_DEBUG is not set
    5.65 @@ -769,6 +808,7 @@ CONFIG_PARPORT=m
    5.66  CONFIG_PARPORT_PC=m
    5.67  # CONFIG_PARPORT_PC_FIFO is not set
    5.68  # CONFIG_PARPORT_PC_SUPERIO is not set
    5.69 +# CONFIG_PARPORT_PC_PCMCIA is not set
    5.70  CONFIG_PARPORT_NOT_PC=y
    5.71  # CONFIG_PARPORT_GSC is not set
    5.72  CONFIG_PARPORT_1284=y
    5.73 @@ -851,6 +891,7 @@ CONFIG_BLK_DEV_IDE=y
    5.74  # CONFIG_BLK_DEV_HD_IDE is not set
    5.75  CONFIG_BLK_DEV_IDEDISK=y
    5.76  CONFIG_IDEDISK_MULTI_MODE=y
    5.77 +# CONFIG_BLK_DEV_IDECS is not set
    5.78  CONFIG_BLK_DEV_IDECD=y
    5.79  # CONFIG_BLK_DEV_IDETAPE is not set
    5.80  CONFIG_BLK_DEV_IDEFLOPPY=y
    5.81 @@ -1012,6 +1053,13 @@ CONFIG_SCSI_DC390T=m
    5.82  # CONFIG_SCSI_DEBUG is not set
    5.83  
    5.84  #
    5.85 +# PCMCIA SCSI adapter support
    5.86 +#
    5.87 +# CONFIG_PCMCIA_FDOMAIN is not set
    5.88 +# CONFIG_PCMCIA_QLOGIC is not set
    5.89 +# CONFIG_PCMCIA_SYM53C500 is not set
    5.90 +
    5.91 +#
    5.92  # Multi-device support (RAID and LVM)
    5.93  #
    5.94  CONFIG_MD=y
    5.95 @@ -1141,6 +1189,7 @@ CONFIG_DE4X5=m
    5.96  CONFIG_WINBOND_840=m
    5.97  CONFIG_DM9102=m
    5.98  CONFIG_ULI526X=m
    5.99 +# CONFIG_PCMCIA_XIRCOM is not set
   5.100  # CONFIG_HP100 is not set
   5.101  CONFIG_NET_PCI=y
   5.102  CONFIG_PCNET32=m
   5.103 @@ -1224,6 +1273,13 @@ CONFIG_NET_RADIO=y
   5.104  # Obsolete Wireless cards support (pre-802.11)
   5.105  #
   5.106  # CONFIG_STRIP is not set
   5.107 +# CONFIG_PCMCIA_WAVELAN is not set
   5.108 +# CONFIG_PCMCIA_NETWAVE is not set
   5.109 +
   5.110 +#
   5.111 +# Wireless 802.11 Frequency Hopping cards support
   5.112 +#
   5.113 +# CONFIG_PCMCIA_RAYCS is not set
   5.114  
   5.115  #
   5.116  # Wireless 802.11b ISA/PCI cards support
   5.117 @@ -1243,6 +1299,15 @@ CONFIG_ATMEL=m
   5.118  CONFIG_PCI_ATMEL=m
   5.119  
   5.120  #
   5.121 +# Wireless 802.11b Pcmcia/Cardbus cards support
   5.122 +#
   5.123 +# CONFIG_PCMCIA_HERMES is not set
   5.124 +# CONFIG_PCMCIA_SPECTRUM is not set
   5.125 +# CONFIG_AIRO_CS is not set
   5.126 +# CONFIG_PCMCIA_ATMEL is not set
   5.127 +# CONFIG_PCMCIA_WL3501 is not set
   5.128 +
   5.129 +#
   5.130  # Prism GT/Duette 802.11(a/b/g) PCI/Cardbus support
   5.131  #
   5.132  CONFIG_PRISM54=m
   5.133 @@ -1250,9 +1315,15 @@ CONFIG_HOSTAP=m
   5.134  # CONFIG_HOSTAP_FIRMWARE is not set
   5.135  CONFIG_HOSTAP_PLX=m
   5.136  CONFIG_HOSTAP_PCI=m
   5.137 +# CONFIG_HOSTAP_CS is not set
   5.138  CONFIG_NET_WIRELESS=y
   5.139  
   5.140  #
   5.141 +# PCMCIA network device support
   5.142 +#
   5.143 +# CONFIG_NET_PCMCIA is not set
   5.144 +
   5.145 +#
   5.146  # Wan interfaces
   5.147  #
   5.148  # CONFIG_WAN is not set
   5.149 @@ -1376,6 +1447,10 @@ CONFIG_HISAX_ENTERNOW_PCI=y
   5.150  #
   5.151  # HiSax PCMCIA card service modules
   5.152  #
   5.153 +# CONFIG_HISAX_SEDLBAUER_CS is not set
   5.154 +# CONFIG_HISAX_ELSA_CS is not set
   5.155 +# CONFIG_HISAX_AVM_A1_CS is not set
   5.156 +# CONFIG_HISAX_TELES_CS is not set
   5.157  
   5.158  #
   5.159  # HiSax sub driver modules
   5.160 @@ -1412,6 +1487,7 @@ CONFIG_CAPI_AVM=y
   5.161  CONFIG_ISDN_DRV_AVMB1_B1PCI=m
   5.162  CONFIG_ISDN_DRV_AVMB1_B1PCIV4=y
   5.163  CONFIG_ISDN_DRV_AVMB1_B1PCMCIA=m
   5.164 +# CONFIG_ISDN_DRV_AVMB1_AVM_CS is not set
   5.165  CONFIG_ISDN_DRV_AVMB1_T1PCI=m
   5.166  CONFIG_ISDN_DRV_AVMB1_C4=m
   5.167  
   5.168 @@ -1600,6 +1676,13 @@ CONFIG_DRM_RADEON=m
   5.169  CONFIG_DRM_MGA=m
   5.170  CONFIG_DRM_VIA=m
   5.171  CONFIG_DRM_SAVAGE=m
   5.172 +
   5.173 +#
   5.174 +# PCMCIA character devices
   5.175 +#
   5.176 +# CONFIG_SYNCLINK_CS is not set
   5.177 +# CONFIG_CARDMAN_4000 is not set
   5.178 +# CONFIG_CARDMAN_4040 is not set
   5.179  # CONFIG_MWAVE is not set
   5.180  # CONFIG_RAW_DRIVER is not set
   5.181  # CONFIG_HPET is not set
   5.182 @@ -2101,6 +2184,10 @@ CONFIG_SND_USB_AUDIO=m
   5.183  CONFIG_SND_USB_USX2Y=m
   5.184  
   5.185  #
   5.186 +# PCMCIA devices
   5.187 +#
   5.188 +
   5.189 +#
   5.190  # Open Sound System
   5.191  #
   5.192  # CONFIG_SOUND_PRIME is not set
   5.193 @@ -2134,6 +2221,7 @@ CONFIG_USB_OHCI_HCD=m
   5.194  CONFIG_USB_OHCI_LITTLE_ENDIAN=y
   5.195  CONFIG_USB_UHCI_HCD=m
   5.196  CONFIG_USB_SL811_HCD=m
   5.197 +# CONFIG_USB_SL811_CS is not set
   5.198  
   5.199  #
   5.200  # USB Device Class drivers
   5.201 @@ -2284,6 +2372,7 @@ CONFIG_USB_SERIAL_SAFE_PADDED=y
   5.202  CONFIG_USB_SERIAL_TI=m
   5.203  CONFIG_USB_SERIAL_CYBERJACK=m
   5.204  CONFIG_USB_SERIAL_XIRCOM=m
   5.205 +# CONFIG_USB_SERIAL_OPTION is not set
   5.206  CONFIG_USB_SERIAL_OMNINET=m
   5.207  CONFIG_USB_EZUSB=y
   5.208  
   5.209 @@ -2649,7 +2738,7 @@ CONFIG_CRYPTO_CRC32C=m
   5.210  # Hardware crypto devices
   5.211  #
   5.212  CONFIG_XEN=y
   5.213 -CONFIG_NO_IDLE_HZ=y
   5.214 +CONFIG_XEN_INTERFACE_VERSION=0x00030101
   5.215  
   5.216  #
   5.217  # XEN
   5.218 @@ -2676,6 +2765,7 @@ CONFIG_XEN_DISABLE_SERIAL=y
   5.219  CONFIG_XEN_SYSFS=m
   5.220  CONFIG_HAVE_ARCH_ALLOC_SKB=y
   5.221  CONFIG_HAVE_ARCH_DEV_ALLOC_SKB=y
   5.222 +CONFIG_NO_IDLE_HZ=y
   5.223  
   5.224  #
   5.225  # Library routines
     6.1 --- a/buildconfigs/mk.linux-2.6-xen	Mon Apr 17 08:47:36 2006 -0600
     6.2 +++ b/buildconfigs/mk.linux-2.6-xen	Tue Apr 18 09:35:40 2006 -0600
     6.3 @@ -22,8 +22,8 @@ build: $(LINUX_DIR)/include/linux/autoco
     6.4  	rm -rf $(LINUX_DIR)
     6.5  	cp -al $(<D) $(LINUX_DIR)
     6.6  	# Apply arch-xen patches
     6.7 -	( cd linux-$(LINUX_SERIES)-xen-sparse ; \
     6.8 -          LINUX_ARCH=$(LINUX_ARCH) ./mkbuildtree ../$(LINUX_DIR) )
     6.9 +	( cd linux-$(LINUX_SERIES)-xen-sparse && \
    6.10 +          LINUX_ARCH=$(LINUX_ARCH) bash ./mkbuildtree ../$(LINUX_DIR) )
    6.11  	# Re-use config from install dir if one exits else use default config
    6.12  	CONFIG_VERSION=$$(sed -ne 's/^EXTRAVERSION = //p' $(LINUX_DIR)/Makefile); \
    6.13  	[ -r $(DESTDIR)/boot/config-$(LINUX_VER)$$CONFIG_VERSION-$(EXTRAVERSION) ] && \
     7.1 --- a/docs/src/user.tex	Mon Apr 17 08:47:36 2006 -0600
     7.2 +++ b/docs/src/user.tex	Tue Apr 18 09:35:40 2006 -0600
     7.3 @@ -1232,8 +1232,15 @@ customized variants for your site's pref
     7.4  \subsection{PCI}
     7.5  \label{ss:pcidd}
     7.6  
     7.7 -Individual PCI devices can be assigned to a given domain to allow that
     7.8 -domain direct access to the PCI hardware. To use this functionality, ensure
     7.9 +Individual PCI devices can be assigned to a given domain (a PCI driver domain)
    7.10 +to allow that domain direct access to the PCI hardware.
    7.11 +
    7.12 +While PCI Driver Domains can increase the stability and security of a system
    7.13 +by addressing a number of security concerns, there are some security issues
    7.14 +that remain that you can read about in Section~\ref{s:ddsecurity}.
    7.15 +
    7.16 +\subsubsection{Compile-Time Setup}
    7.17 +To use this functionality, ensure
    7.18  that the PCI Backend is compiled in to a privileged domain (e.g. domain 0)
    7.19  and that the domains which will be assigned PCI devices have the PCI Frontend
    7.20  compiled in. In XenLinux, the PCI Backend is available under the Xen
    7.21 @@ -1241,21 +1248,73 @@ configuration section while the PCI Fron
    7.22  architecture-specific "Bus Options" section. You may compile both the backend
    7.23  and the frontend into the same kernel; they will not affect each other.
    7.24  
    7.25 +\subsubsection{PCI Backend Configuration - Binding at Boot}
    7.26  The PCI devices you wish to assign to unprivileged domains must be "hidden"
    7.27  from your backend domain (usually domain 0) so that it does not load a driver
    7.28  for them. Use the \path{pciback.hide} kernel parameter which is specified on
    7.29  the kernel command-line and is configurable through GRUB (see
    7.30  Section~\ref{s:configure}). Note that devices are not really hidden from the
    7.31 -backend domain. The PCI Backend ensures that no other device driver loads
    7.32 -for those devices. PCI devices are identified by hexadecimal
    7.33 -slot/funciton numbers (on Linux, use \path{lspci} to determine slot/funciton
    7.34 -numbers of your devices) and can be specified with or without the PCI domain: \\
    7.35 +backend domain. The PCI Backend appears to the Linux kernel as a regular PCI
    7.36 +device driver. The PCI Backend ensures that no other device driver loads
    7.37 +for the devices by binding itself as the device driver for those devices.
    7.38 +PCI devices are identified by hexadecimal slot/funciton numbers (on Linux,
    7.39 +use \path{lspci} to determine slot/funciton numbers of your devices) and
    7.40 +can be specified with or without the PCI domain: \\
    7.41  \centerline{  {\tt ({\em bus}:{\em slot}.{\em func})} example {\tt (02:1d.3)}} \\
    7.42  \centerline{  {\tt ({\em domain}:{\em bus}:{\em slot}.{\em func})} example {\tt (0000:02:1d.3)}} \\
    7.43  
    7.44  An example kernel command-line which hides two PCI devices might be: \\
    7.45  \centerline{ {\tt root=/dev/sda4 ro console=tty0 pciback.hide=(02:01.f)(0000:04:1d.0) } } \\
    7.46  
    7.47 +\subsubsection{PCI Backend Configuration - Late Binding}
    7.48 +PCI devices can also be bound to the PCI Backend after boot through the manual
    7.49 +binding/unbinding facilities provided by the Linux kernel in sysfs (allowing
    7.50 +for a Xen user to give PCI devices to driver domains that were not specified
    7.51 +on the kernel command-line). There are several attributes with the PCI
    7.52 +Backend's sysfs directory (\path{/sys/bus/pci/drivers/pciback}) that can be
    7.53 +used to bind/unbind devices:
    7.54 +
    7.55 +\begin{description}
    7.56 +\item[slots] lists all of the PCI slots that the PCI Backend will try to seize
    7.57 +  (or "hide" from Domain 0). A PCI slot must appear in this list before it can
    7.58 +  be bound to the PCI Backend through the \path{bind} attribute.
    7.59 +\item[new\_slot] write the name of a slot here (in 0000:00:00.0 format) to
    7.60 +  have the PCI Backend seize the device in this slot.
    7.61 +\item[remove\_slot] write the name of a slot here (same format as
    7.62 +  \path{new\_slot}) to have the PCI Backend no longer try to seize devices in
    7.63 +  this slot. Note that this does not unbind the driver from a device it has
    7.64 +  already seized.
    7.65 +\item[bind] write the name of a slot here (in 0000:00:00.0 format) to have
    7.66 +  the Linux kernel attempt to bind the device in that slot to the PCI Backend
    7.67 +  driver.
    7.68 +\item[unbind] write the name of a skit here (same format as \path{bind}) to have
    7.69 +  the Linux kernel unbind the device from the PCI Backend. DO NOT unbind a
    7.70 +  device while it is currently given to a PCI driver domain!
    7.71 +\end{description}
    7.72 +
    7.73 +Some examples:
    7.74 +
    7.75 +Bind a device to the PCI Backend which is not bound to any other driver.
    7.76 +\begin{verbatim}
    7.77 +# # Add a new slot to the PCI Backend's list
    7.78 +# echo -n 0000:01:04.d > /sys/bus/pci/drivers/pciback/new_slot
    7.79 +# # Now that the backend is watching for the slot, bind to it
    7.80 +# echo -n 0000:01:04.d > /sys/bus/pci/drivers/pciback/bind
    7.81 +\end{verbatim}
    7.82 +
    7.83 +Unbind a device from its driver and bind to the PCI Backend.
    7.84 +\begin{verbatim}
    7.85 +# # Unbind a PCI network card from its network driver
    7.86 +# echo -n 0000:05:02.0 > /sys/bus/pci/drivers/3c905/unbind
    7.87 +# # And now bind it to the PCI Backend
    7.88 +# echo -n 0000:05:02.0 > /sys/bus/pci/drivers/pciback/new_slot
    7.89 +# echo -n 0000:05:02.0 > /sys/bus/pci/drivers/pciback/bind
    7.90 +\end{verbatim}
    7.91 +
    7.92 +Note that the "-n" option in the example is important as it causes echo to not
    7.93 +output a new-line.
    7.94 +
    7.95 +\subsubsection{PCI Frontend Configuration}
    7.96  To configure a domU to receive a PCI device:
    7.97  
    7.98  \begin{description}
    7.99 @@ -1282,9 +1341,6 @@ To configure a domU to receive a PCI dev
   7.100  }
   7.101  \end{description}
   7.102  
   7.103 -There are a number of security concerns associated with PCI Driver Domains
   7.104 -that you can read about in Section~\ref{s:ddsecurity}.
   7.105 -
   7.106  %% There are two possible types of privileges: IO privileges and
   7.107  %% administration privileges.
   7.108  
     8.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/fixup.c	Mon Apr 17 08:47:36 2006 -0600
     8.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/fixup.c	Tue Apr 18 09:35:40 2006 -0600
     8.3 @@ -68,6 +68,7 @@ fastcall void do_fixup_4gb_segment(struc
     8.4  	DP("");
     8.5  
     8.6  	for (i = 5; i > 0; i--) {
     8.7 +		touch_softlockup_watchdog();
     8.8  		printk("Pausing... %d", i);
     8.9  		mdelay(1000);
    8.10  		printk("\b\b\b\b\b\b\b\b\b\b\b\b");
     9.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Mon Apr 17 08:47:36 2006 -0600
     9.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c	Tue Apr 18 09:35:40 2006 -0600
     9.3 @@ -206,8 +206,8 @@ swiotlb_init(void)
     9.4  }
     9.5  
     9.6  /*
     9.7 - * We use __copy_to_user to transfer to the host buffer because the buffer
     9.8 - * may be mapped read-only (e.g, in blkback driver) but lower-level
     9.9 + * We use __copy_to_user_inatomic to transfer to the host buffer because the
    9.10 + * buffer may be mapped read-only (e.g, in blkback driver) but lower-level
    9.11   * drivers map the buffer for DMA_BIDIRECTIONAL access. This causes an
    9.12   * unnecessary copy from the aperture to the host buffer, and a page fault.
    9.13   */
    9.14 @@ -225,7 +225,7 @@ static void
    9.15  			dev  = dma_addr + size - len;
    9.16  			host = kmp + buffer.offset;
    9.17  			if (dir == DMA_FROM_DEVICE) {
    9.18 -				if (__copy_to_user(host, dev, bytes))
    9.19 +				if (__copy_to_user_inatomic(host, dev, bytes))
    9.20  					/* inaccessible */;
    9.21  			} else
    9.22  				memcpy(dev, host, bytes);
    9.23 @@ -238,7 +238,7 @@ static void
    9.24  		char *host = (char *)phys_to_virt(
    9.25  			page_to_pseudophys(buffer.page)) + buffer.offset;
    9.26  		if (dir == DMA_FROM_DEVICE) {
    9.27 -			if (__copy_to_user(host, dma_addr, size))
    9.28 +			if (__copy_to_user_inatomic(host, dma_addr, size))
    9.29  				/* inaccessible */;
    9.30  		} else if (dir == DMA_TO_DEVICE)
    9.31  			memcpy(dma_addr, host, size);
    10.1 --- a/linux-2.6-xen-sparse/arch/x86_64/Kconfig	Mon Apr 17 08:47:36 2006 -0600
    10.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/Kconfig	Tue Apr 18 09:35:40 2006 -0600
    10.3 @@ -568,7 +568,6 @@ config UNORDERED_IO
    10.4  	 from i386. Requires that the driver writer used memory barriers
    10.5  	 properly.
    10.6  
    10.7 -if !X86_64_XEN
    10.8  source "drivers/pci/pcie/Kconfig"
    10.9  
   10.10  source "drivers/pci/Kconfig"
   10.11 @@ -576,7 +575,6 @@ source "drivers/pci/Kconfig"
   10.12  source "drivers/pcmcia/Kconfig"
   10.13  
   10.14  source "drivers/pci/hotplug/Kconfig"
   10.15 -endif
   10.16  
   10.17  endmenu
   10.18  
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Mon Apr 17 08:47:36 2006 -0600
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Tue Apr 18 09:35:40 2006 -0600
    11.3 @@ -186,9 +186,8 @@ static void fast_flush_area(pending_req_
    11.4  		handle = pending_handle(req, i);
    11.5  		if (handle == BLKBACK_INVALID_HANDLE)
    11.6  			continue;
    11.7 -		unmap[invcount].host_addr    = vaddr(req, i);
    11.8 -		unmap[invcount].dev_bus_addr = 0;
    11.9 -		unmap[invcount].handle       = handle;
   11.10 +		gnttab_set_unmap_op(&unmap[i], vaddr(req, i), GNTMAP_host_map,
   11.11 +				    handle);
   11.12  		pending_handle(req, i) = BLKBACK_INVALID_HANDLE;
   11.13  		invcount++;
   11.14  	}
   11.15 @@ -384,6 +383,8 @@ static void dispatch_rw_block_io(blkif_t
   11.16  	pending_req->nr_pages  = nseg;
   11.17  
   11.18  	for (i = 0; i < nseg; i++) {
   11.19 +		uint32_t flags;
   11.20 +
   11.21  		seg[i].nsec = req->seg[i].last_sect -
   11.22  			req->seg[i].first_sect + 1;
   11.23  
   11.24 @@ -392,12 +393,11 @@ static void dispatch_rw_block_io(blkif_t
   11.25  			goto fail_response;
   11.26  		preq.nr_sects += seg[i].nsec;
   11.27  
   11.28 -		map[i].host_addr = vaddr(pending_req, i);
   11.29 -		map[i].dom = blkif->domid;
   11.30 -		map[i].ref = req->seg[i].gref;
   11.31 -		map[i].flags = GNTMAP_host_map;
   11.32 +		flags = GNTMAP_host_map;
   11.33  		if ( operation == WRITE )
   11.34 -			map[i].flags |= GNTMAP_readonly;
   11.35 +			flags |= GNTMAP_readonly;
   11.36 +		gnttab_set_map_op(&map[i], vaddr(pending_req, i), flags,
   11.37 +				  req->seg[i].gref, blkif->domid);
   11.38  	}
   11.39  
   11.40  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg);
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Mon Apr 17 08:47:36 2006 -0600
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Tue Apr 18 09:35:40 2006 -0600
    12.3 @@ -58,10 +58,8 @@ static int map_frontend_page(blkif_t *bl
    12.4  	struct gnttab_map_grant_ref op;
    12.5  	int ret;
    12.6  
    12.7 -	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
    12.8 -	op.flags     = GNTMAP_host_map;
    12.9 -	op.ref       = shared_page;
   12.10 -	op.dom       = blkif->domid;
   12.11 +	gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
   12.12 +			  GNTMAP_host_map, shared_page, blkif->domid);
   12.13  
   12.14  	lock_vm_area(blkif->blk_ring_area);
   12.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   12.16 @@ -90,9 +88,8 @@ static void unmap_frontend_page(blkif_t 
   12.17  	struct gnttab_unmap_grant_ref op;
   12.18  	int ret;
   12.19  
   12.20 -	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   12.21 -	op.handle       = blkif->shmem_handle;
   12.22 -	op.dev_bus_addr = 0;
   12.23 +	gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
   12.24 +			    GNTMAP_host_map, blkif->shmem_handle);
   12.25  
   12.26  	lock_vm_area(blkif->blk_ring_area);
   12.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Mon Apr 17 08:47:36 2006 -0600
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Tue Apr 18 09:35:40 2006 -0600
    13.3 @@ -418,9 +418,9 @@ static void fast_flush_area(int idx, int
    13.4  		if (BLKTAP_INVALID_HANDLE(handle))
    13.5  			continue;
    13.6  
    13.7 -		unmap[op].host_addr = MMAP_VADDR(mmap_vstart, idx, i);
    13.8 -		unmap[op].dev_bus_addr = 0;
    13.9 -		unmap[op].handle = handle->kernel;
   13.10 +		gnttab_set_unmap_op(&unmap[op],
   13.11 +				    MMAP_VADDR(mmap_vstart, idx, i),
   13.12 +				    GNTMAP_host_map, handle->kernel);
   13.13  		op++;
   13.14  
   13.15  		if (create_lookup_pte_addr(
   13.16 @@ -430,9 +430,10 @@ static void fast_flush_area(int idx, int
   13.17  			DPRINTK("Couldn't get a pte addr!\n");
   13.18  			return;
   13.19  		}
   13.20 -		unmap[op].host_addr    = ptep;
   13.21 -		unmap[op].dev_bus_addr = 0;
   13.22 -		unmap[op].handle       = handle->user;
   13.23 +		gnttab_set_unmap_grnat_ref(&unmap[op], ptep,
   13.24 +					   GNTMAP_host_map |
   13.25 +					   GNTMAP_application_map |
   13.26 +					   GNTMAP_contains_pte, handle->user);
   13.27  		op++;
   13.28              
   13.29  		BLKTAP_INVALIDATE_HANDLE(handle);
   13.30 @@ -703,21 +704,21 @@ static void dispatch_rw_block_io(blkif_t
   13.31  		unsigned long uvaddr;
   13.32  		unsigned long kvaddr;
   13.33  		uint64_t ptep;
   13.34 +		uint32_t flags;
   13.35  
   13.36  		uvaddr = MMAP_VADDR(user_vstart, pending_idx, i);
   13.37  		kvaddr = MMAP_VADDR(mmap_vstart, pending_idx, i);
   13.38  
   13.39 -		/* Map the remote page to kernel. */
   13.40 -		map[op].host_addr = kvaddr;
   13.41 -		map[op].dom   = blkif->domid;
   13.42 -		map[op].ref   = req->seg[i].gref;
   13.43 -		map[op].flags = GNTMAP_host_map;
   13.44 +		flags = GNTMAP_host_map;
   13.45  		/* This needs a bit more thought in terms of interposition: 
   13.46  		 * If we want to be able to modify pages during write using 
   13.47  		 * grant table mappings, the guest will either need to allow 
   13.48  		 * it, or we'll need to incur a copy. Bit of an fbufs moment. ;) */
   13.49  		if (req->operation == BLKIF_OP_WRITE)
   13.50 -			map[op].flags |= GNTMAP_readonly;
   13.51 +			flags |= GNTMAP_readonly;
   13.52 +		/* Map the remote page to kernel. */
   13.53 +		gnttab_set_map_op(&map[op], kvaddr, flags, req->seg[i].gref,
   13.54 +				  blkif->domid);
   13.55  		op++;
   13.56  
   13.57  		/* Now map it to user. */
   13.58 @@ -728,14 +729,13 @@ static void dispatch_rw_block_io(blkif_t
   13.59  			goto bad_descriptor;
   13.60  		}
   13.61  
   13.62 -		map[op].host_addr = ptep;
   13.63 -		map[op].dom       = blkif->domid;
   13.64 -		map[op].ref       = req->seg[i].gref;
   13.65 -		map[op].flags     = GNTMAP_host_map | GNTMAP_application_map
   13.66 +		flags = GNTMAP_host_map | GNTMAP_application_map
   13.67  			| GNTMAP_contains_pte;
   13.68  		/* Above interposition comment applies here as well. */
   13.69  		if (req->operation == BLKIF_OP_WRITE)
   13.70 -			map[op].flags |= GNTMAP_readonly;
   13.71 +			flags |= GNTMAP_readonly;
   13.72 +		gnttab_set_map_op(&map[op], ptep, flags, req->seg[i].gref,
   13.73 +				  blkif->domid);
   13.74  		op++;
   13.75  	}
   13.76  
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon Apr 17 08:47:36 2006 -0600
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Tue Apr 18 09:35:40 2006 -0600
    14.3 @@ -33,10 +33,8 @@ static int map_frontend_page(blkif_t *bl
    14.4  	struct gnttab_map_grant_ref op;
    14.5  	int ret;
    14.6  
    14.7 -	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
    14.8 -	op.flags     = GNTMAP_host_map;
    14.9 -	op.ref       = shared_page;
   14.10 -	op.dom       = blkif->domid;
   14.11 +	gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
   14.12 +			  GNTMAP_host_map, shared_page, blkif->domid);
   14.13  
   14.14  	lock_vm_area(blkif->blk_ring_area);
   14.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   14.16 @@ -59,9 +57,8 @@ static void unmap_frontend_page(blkif_t 
   14.17  	struct gnttab_unmap_grant_ref op;
   14.18  	int ret;
   14.19  
   14.20 -	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   14.21 -	op.handle       = blkif->shmem_handle;
   14.22 -	op.dev_bus_addr = 0;
   14.23 +	gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
   14.24 +			    GNTMAP_host_map, blkif->shmem_handle);
   14.25  
   14.26  	lock_vm_area(blkif->blk_ring_area);
   14.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Mon Apr 17 08:47:36 2006 -0600
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/evtchn.c	Tue Apr 18 09:35:40 2006 -0600
    15.3 @@ -513,6 +513,8 @@ static void ack_dynirq(unsigned int irq)
    15.4  {
    15.5  	int evtchn = evtchn_from_irq(irq);
    15.6  
    15.7 +	move_native_irq(irq);
    15.8 +
    15.9  	if (VALID_EVTCHN(evtchn)) {
   15.10  		mask_evtchn(evtchn);
   15.11  		clear_evtchn(evtchn);
   15.12 @@ -636,6 +638,8 @@ static void ack_pirq(unsigned int irq)
   15.13  {
   15.14  	int evtchn = evtchn_from_irq(irq);
   15.15  
   15.16 +	move_native_irq(irq);
   15.17 +
   15.18  	if (VALID_EVTCHN(evtchn)) {
   15.19  		mask_evtchn(evtchn);
   15.20  		clear_evtchn(evtchn);
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Mon Apr 17 08:47:36 2006 -0600
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/core/gnttab.c	Tue Apr 18 09:35:40 2006 -0600
    16.3 @@ -65,6 +65,7 @@ EXPORT_SYMBOL_GPL(gnttab_end_foreign_tra
    16.4  EXPORT_SYMBOL_GPL(gnttab_alloc_grant_references);
    16.5  EXPORT_SYMBOL_GPL(gnttab_free_grant_references);
    16.6  EXPORT_SYMBOL_GPL(gnttab_free_grant_reference);
    16.7 +EXPORT_SYMBOL_GPL(gnttab_empty_grant_references);
    16.8  EXPORT_SYMBOL_GPL(gnttab_claim_grant_reference);
    16.9  EXPORT_SYMBOL_GPL(gnttab_release_grant_reference);
   16.10  EXPORT_SYMBOL_GPL(gnttab_request_free_callback);
   16.11 @@ -325,6 +326,12 @@ gnttab_alloc_grant_references(u16 count,
   16.12  }
   16.13  
   16.14  int
   16.15 +gnttab_empty_grant_references(const grant_ref_t *private_head)
   16.16 +{
   16.17 +	return (*private_head == GNTTAB_LIST_END);
   16.18 +}
   16.19 +
   16.20 +int
   16.21  gnttab_claim_grant_reference(grant_ref_t *private_head)
   16.22  {
   16.23  	grant_ref_t g = *private_head;
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Mon Apr 17 08:47:36 2006 -0600
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Tue Apr 18 09:35:40 2006 -0600
    17.3 @@ -150,10 +150,8 @@ static int map_frontend_pages(
    17.4  	struct gnttab_map_grant_ref op;
    17.5  	int ret;
    17.6  
    17.7 -	op.host_addr = (unsigned long)netif->tx_comms_area->addr;
    17.8 -	op.flags     = GNTMAP_host_map;
    17.9 -	op.ref       = tx_ring_ref;
   17.10 -	op.dom       = netif->domid;
   17.11 +	gnttab_set_map_op(&op, (unsigned long)netif->tx_comms_area->addr,
   17.12 +			  GNTMAP_host_map, tx_ring_ref, netif->domid);
   17.13      
   17.14  	lock_vm_area(netif->tx_comms_area);
   17.15  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   17.16 @@ -168,10 +166,8 @@ static int map_frontend_pages(
   17.17  	netif->tx_shmem_ref    = tx_ring_ref;
   17.18  	netif->tx_shmem_handle = op.handle;
   17.19  
   17.20 -	op.host_addr = (unsigned long)netif->rx_comms_area->addr;
   17.21 -	op.flags     = GNTMAP_host_map;
   17.22 -	op.ref       = rx_ring_ref;
   17.23 -	op.dom       = netif->domid;
   17.24 +	gnttab_set_map_op(&op, (unsigned long)netif->rx_comms_area->addr,
   17.25 +			  GNTMAP_host_map, rx_ring_ref, netif->domid);
   17.26  
   17.27  	lock_vm_area(netif->rx_comms_area);
   17.28  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   17.29 @@ -194,18 +190,16 @@ static void unmap_frontend_pages(netif_t
   17.30  	struct gnttab_unmap_grant_ref op;
   17.31  	int ret;
   17.32  
   17.33 -	op.host_addr    = (unsigned long)netif->tx_comms_area->addr;
   17.34 -	op.handle       = netif->tx_shmem_handle;
   17.35 -	op.dev_bus_addr = 0;
   17.36 +	gnttab_set_unmap_op(&op, (unsigned long)netif->tx_comms_area->addr,
   17.37 +			    GNTMAP_host_map, netif->tx_shmem_handle);
   17.38  
   17.39  	lock_vm_area(netif->tx_comms_area);
   17.40  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   17.41  	unlock_vm_area(netif->tx_comms_area);
   17.42  	BUG_ON(ret);
   17.43  
   17.44 -	op.host_addr    = (unsigned long)netif->rx_comms_area->addr;
   17.45 -	op.handle       = netif->rx_shmem_handle;
   17.46 -	op.dev_bus_addr = 0;
   17.47 +	gnttab_set_unmap_op(&op, (unsigned long)netif->rx_comms_area->addr,
   17.48 +			    GNTMAP_host_map, netif->rx_shmem_handle);
   17.49  
   17.50  	lock_vm_area(netif->rx_comms_area);
   17.51  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Mon Apr 17 08:47:36 2006 -0600
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Tue Apr 18 09:35:40 2006 -0600
    18.3 @@ -453,9 +453,9 @@ inline static void net_tx_action_dealloc
    18.4  	gop = tx_unmap_ops;
    18.5  	while (dc != dp) {
    18.6  		pending_idx = dealloc_ring[MASK_PEND_IDX(dc++)];
    18.7 -		gop->host_addr    = MMAP_VADDR(pending_idx);
    18.8 -		gop->dev_bus_addr = 0;
    18.9 -		gop->handle       = grant_tx_handle[pending_idx];
   18.10 +		gnttab_set_unmap_op(gop, MMAP_VADDR(pending_idx),
   18.11 +				    GNTMAP_host_map,
   18.12 +				    grant_tx_handle[pending_idx]);
   18.13  		gop++;
   18.14  	}
   18.15  	ret = HYPERVISOR_grant_table_op(
   18.16 @@ -579,10 +579,9 @@ static void net_tx_action(unsigned long 
   18.17  		/* Packets passed to netif_rx() must have some headroom. */
   18.18  		skb_reserve(skb, 16);
   18.19  
   18.20 -		mop->host_addr = MMAP_VADDR(pending_idx);
   18.21 -		mop->dom       = netif->domid;
   18.22 -		mop->ref       = txreq.gref;
   18.23 -		mop->flags     = GNTMAP_host_map | GNTMAP_readonly;
   18.24 +		gnttab_set_map_op(mop, MMAP_VADDR(pending_idx),
   18.25 +				  GNTMAP_host_map | GNTMAP_readonly,
   18.26 +				  txreq.gref, netif->domid);
   18.27  		mop++;
   18.28  
   18.29  		memcpy(&pending_tx_info[pending_idx].req,
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Mon Apr 17 08:47:36 2006 -0600
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Apr 18 09:35:40 2006 -0600
    19.3 @@ -106,7 +106,7 @@ struct netfront_info
    19.4  	/* Receive-ring batched refills. */
    19.5  #define RX_MIN_TARGET 8
    19.6  #define RX_DFL_MIN_TARGET 64
    19.7 -#define RX_MAX_TARGET NET_RX_RING_SIZE
    19.8 +#define RX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
    19.9  	int rx_min_target, rx_max_target, rx_target;
   19.10  	struct sk_buff_head rx_batch;
   19.11  
   19.12 @@ -119,6 +119,7 @@ struct netfront_info
   19.13  	struct sk_buff *tx_skbs[NET_TX_RING_SIZE+1];
   19.14  	struct sk_buff *rx_skbs[NET_RX_RING_SIZE+1];
   19.15  
   19.16 +#define TX_MAX_TARGET min_t(int, NET_RX_RING_SIZE, 256)
   19.17  	grant_ref_t gref_tx_head;
   19.18  	grant_ref_t grant_tx_ref[NET_TX_RING_SIZE + 1];
   19.19  	grant_ref_t gref_rx_head;
   19.20 @@ -505,8 +506,9 @@ static void network_tx_buf_gc(struct net
   19.21  	} while (prod != np->tx.sring->rsp_prod);
   19.22  
   19.23   out:
   19.24 -	if (np->tx_full &&
   19.25 -	    ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE)) {
   19.26 +	if ((np->tx_full) &&
   19.27 +	    ((np->tx.sring->req_prod - prod) < NET_TX_RING_SIZE) &&
   19.28 +	    !gnttab_empty_grant_references(&np->gref_tx_head)) {
   19.29  		np->tx_full = 0;
   19.30  		if (np->user_state == UST_OPEN)
   19.31  			netif_wake_queue(dev);
   19.32 @@ -705,7 +707,8 @@ static int network_start_xmit(struct sk_
   19.33  
   19.34  	network_tx_buf_gc(dev);
   19.35  
   19.36 -	if (RING_FULL(&np->tx)) {
   19.37 +	if (RING_FULL(&np->tx) ||
   19.38 +	    gnttab_empty_grant_references(&np->gref_tx_head)) {
   19.39  		np->tx_full = 1;
   19.40  		netif_stop_queue(dev);
   19.41  	}
   19.42 @@ -1140,14 +1143,14 @@ static int create_netdev(int handle, str
   19.43  	}
   19.44  
   19.45  	/* A grant for every tx ring slot */
   19.46 -	if (gnttab_alloc_grant_references(NET_TX_RING_SIZE,
   19.47 +	if (gnttab_alloc_grant_references(TX_MAX_TARGET,
   19.48  					  &np->gref_tx_head) < 0) {
   19.49  		printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
   19.50  		err = -ENOMEM;
   19.51  		goto exit;
   19.52  	}
   19.53  	/* A grant for every rx ring slot */
   19.54 -	if (gnttab_alloc_grant_references(NET_RX_RING_SIZE,
   19.55 +	if (gnttab_alloc_grant_references(RX_MAX_TARGET,
   19.56  					  &np->gref_rx_head) < 0) {
   19.57  		printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
   19.58  		gnttab_free_grant_references(np->gref_tx_head);
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Mon Apr 17 08:47:36 2006 -0600
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Tue Apr 18 09:35:40 2006 -0600
    20.3 @@ -13,6 +13,7 @@
    20.4  
    20.5  #include "common.h"
    20.6  #include <xen/balloon.h>
    20.7 +#include <xen/gnttab.h>
    20.8  
    20.9  static kmem_cache_t *tpmif_cachep;
   20.10  int num_frontends = 0;
   20.11 @@ -72,12 +73,10 @@ tpmif_t *tpmif_find(domid_t domid, long 
   20.12  static int map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
   20.13  {
   20.14  	int ret;
   20.15 -	struct gnttab_map_grant_ref op = {
   20.16 -		.host_addr = (unsigned long)tpmif->tx_area->addr,
   20.17 -		.flags = GNTMAP_host_map,
   20.18 -		.ref = shared_page,
   20.19 -		.dom = tpmif->domid,
   20.20 -	};
   20.21 +	struct gnttab_map_grant_ref op;
   20.22 +
   20.23 +	gnttab_set_map_op(&op, (unsigned long)tpmif->tx_area->addr,
   20.24 +			  GNTMAP_host_map, shared_page, tpmif->domid);
   20.25  
   20.26  	lock_vm_area(tpmif->tx_area);
   20.27  	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   20.28 @@ -100,9 +99,8 @@ static void unmap_frontend_page(tpmif_t 
   20.29  	struct gnttab_unmap_grant_ref op;
   20.30  	int ret;
   20.31  
   20.32 -	op.host_addr    = (unsigned long)tpmif->tx_area->addr;
   20.33 -	op.handle       = tpmif->shmem_handle;
   20.34 -	op.dev_bus_addr = 0;
   20.35 +	gnttab_set_unmap_op(&op, (unsigned long)tpmif->tx_area->addr,
   20.36 +			    GNTMAP_host_map, tpmif->shmem_handle);
   20.37  
   20.38  	lock_vm_area(tpmif->tx_area);
   20.39  	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Mon Apr 17 08:47:36 2006 -0600
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Tue Apr 18 09:35:40 2006 -0600
    21.3 @@ -21,6 +21,7 @@
    21.4  #include <asm/uaccess.h>
    21.5  #include <xen/xenbus.h>
    21.6  #include <xen/interface/grant_table.h>
    21.7 +#include <xen/gnttab.h>
    21.8  
    21.9  /* local data structures */
   21.10  struct data_exchange {
   21.11 @@ -278,10 +279,8 @@ int _packet_write(struct packet *pak,
   21.12  			return 0;
   21.13  		}
   21.14  
   21.15 -		map_op.host_addr = MMAP_VADDR(tpmif, i);
   21.16 -		map_op.flags = GNTMAP_host_map;
   21.17 -		map_op.ref = tx->ref;
   21.18 -		map_op.dom = tpmif->domid;
   21.19 +		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
   21.20 +				  GNTMAP_host_map, tx->ref, tpmif->domid);
   21.21  
   21.22  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
   21.23  						       &map_op, 1))) {
   21.24 @@ -308,9 +307,8 @@ int _packet_write(struct packet *pak,
   21.25  		}
   21.26  		tx->size = tocopy;
   21.27  
   21.28 -		unmap_op.host_addr = MMAP_VADDR(tpmif, i);
   21.29 -		unmap_op.handle = handle;
   21.30 -		unmap_op.dev_bus_addr = 0;
   21.31 +		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
   21.32 +				    GNTMAP_host_map, handle);
   21.33  
   21.34  		if (unlikely
   21.35  		    (HYPERVISOR_grant_table_op
   21.36 @@ -422,10 +420,8 @@ static int packet_read_shmem(struct pack
   21.37  
   21.38  		tx = &tpmif->tx->ring[i].req;
   21.39  
   21.40 -		map_op.host_addr = MMAP_VADDR(tpmif, i);
   21.41 -		map_op.flags = GNTMAP_host_map;
   21.42 -		map_op.ref = tx->ref;
   21.43 -		map_op.dom = tpmif->domid;
   21.44 +		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
   21.45 +				  GNTMAP_host_map, tx->ref, tpmif->domid);
   21.46  
   21.47  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
   21.48  						       &map_op, 1))) {
   21.49 @@ -461,9 +457,8 @@ static int packet_read_shmem(struct pack
   21.50  			tpmif->domid, buffer[offset], buffer[offset + 1],
   21.51  			buffer[offset + 2], buffer[offset + 3]);
   21.52  
   21.53 -		unmap_op.host_addr = MMAP_VADDR(tpmif, i);
   21.54 -		unmap_op.handle = handle;
   21.55 -		unmap_op.dev_bus_addr = 0;
   21.56 +		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
   21.57 +				    GNTMAP_host_map, handle);
   21.58  
   21.59  		if (unlikely
   21.60  		    (HYPERVISOR_grant_table_op
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Mon Apr 17 08:47:36 2006 -0600
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Tue Apr 18 09:35:40 2006 -0600
    22.3 @@ -164,10 +164,10 @@ static void frontend_changed(struct xenb
    22.4  
    22.5  	switch (frontend_state) {
    22.6  	case XenbusStateInitialising:
    22.7 -	case XenbusStateConnected:
    22.8 +	case XenbusStateInitialised:
    22.9  		break;
   22.10  
   22.11 -	case XenbusStateInitialised:
   22.12 +	case XenbusStateConnected:
   22.13  		err = connect_ring(be);
   22.14  		if (err) {
   22.15  			return;
    23.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Mon Apr 17 08:47:36 2006 -0600
    23.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Tue Apr 18 09:35:40 2006 -0600
    23.3 @@ -334,12 +334,6 @@ again:
    23.4  		goto abort_transaction;
    23.5  	}
    23.6  
    23.7 -	err = xenbus_printf(xbt, dev->nodename,
    23.8 -	                    "state", "%d", XenbusStateInitialised);
    23.9 -	if (err) {
   23.10 -		goto abort_transaction;
   23.11 -	}
   23.12 -
   23.13  	err = xenbus_transaction_end(xbt, 0);
   23.14  	if (err == -EAGAIN)
   23.15  		goto again;
   23.16 @@ -347,6 +341,9 @@ again:
   23.17  		xenbus_dev_fatal(dev, err, "completing transaction");
   23.18  		goto destroy_tpmring;
   23.19  	}
   23.20 +
   23.21 +	xenbus_switch_state(dev, XenbusStateConnected);
   23.22 +
   23.23  	return 0;
   23.24  
   23.25  abort_transaction:
   23.26 @@ -387,6 +384,7 @@ static void backend_changed(struct xenbu
   23.27  		if (tp->is_suspended == 0) {
   23.28  			device_unregister(&dev->dev);
   23.29  		}
   23.30 +		xenbus_switch_state(dev, XenbusStateClosed);
   23.31  		break;
   23.32  	}
   23.33  }
   23.34 @@ -439,6 +437,7 @@ static int tpmfront_suspend(struct xenbu
   23.35  
   23.36  	/* lock, so no app can send */
   23.37  	mutex_lock(&suspend_lock);
   23.38 +	xenbus_switch_state(dev, XenbusStateClosed);
   23.39  	tp->is_suspended = 1;
   23.40  
   23.41  	for (ctr = 0; atomic_read(&tp->tx_busy) && ctr <= 25; ctr++) {
    24.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Mon Apr 17 08:47:36 2006 -0600
    24.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_backend_client.c	Tue Apr 18 09:35:40 2006 -0600
    24.3 @@ -37,11 +37,7 @@
    24.4  /* Based on Rusty Russell's skeleton driver's map_page */
    24.5  int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
    24.6  {
    24.7 -	struct gnttab_map_grant_ref op = {
    24.8 -		.flags = GNTMAP_host_map,
    24.9 -		.ref   = gnt_ref,
   24.10 -		.dom   = dev->otherend_id,
   24.11 -	};
   24.12 +	struct gnttab_map_grant_ref op;
   24.13  	struct vm_struct *area;
   24.14  
   24.15  	*vaddr = NULL;
   24.16 @@ -50,8 +46,9 @@ int xenbus_map_ring_valloc(struct xenbus
   24.17  	if (!area)
   24.18  		return -ENOMEM;
   24.19  
   24.20 -	op.host_addr = (unsigned long)area->addr;
   24.21 -
   24.22 +	gnttab_set_map_op(&op, (unsigned long)area->addr, GNTMAP_host_map,
   24.23 +			  gnt_ref, dev->otherend_id);
   24.24 +	
   24.25  	lock_vm_area(area);
   24.26  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   24.27  	unlock_vm_area(area);
   24.28 @@ -76,13 +73,10 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring_valloc
   24.29  int xenbus_map_ring(struct xenbus_device *dev, int gnt_ref,
   24.30  		   grant_handle_t *handle, void *vaddr)
   24.31  {
   24.32 -	struct gnttab_map_grant_ref op = {
   24.33 -		.host_addr = (unsigned long)vaddr,
   24.34 -		.flags     = GNTMAP_host_map,
   24.35 -		.ref       = gnt_ref,
   24.36 -		.dom       = dev->otherend_id,
   24.37 -	};
   24.38 -
   24.39 +	struct gnttab_map_grant_ref op;
   24.40 +	
   24.41 +	gnttab_set_map_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
   24.42 +			  gnt_ref, dev->otherend_id);
   24.43  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   24.44  
   24.45  	if (op.status != GNTST_okay) {
   24.46 @@ -101,9 +95,7 @@ EXPORT_SYMBOL_GPL(xenbus_map_ring);
   24.47  int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
   24.48  {
   24.49  	struct vm_struct *area;
   24.50 -	struct gnttab_unmap_grant_ref op = {
   24.51 -		.host_addr = (unsigned long)vaddr,
   24.52 -	};
   24.53 +	struct gnttab_unmap_grant_ref op;
   24.54  
   24.55  	/* It'd be nice if linux/vmalloc.h provided a find_vm_area(void *addr)
   24.56  	 * method so that we don't have to muck with vmalloc internals here.
   24.57 @@ -124,7 +116,8 @@ int xenbus_unmap_ring_vfree(struct xenbu
   24.58  		return GNTST_bad_virt_addr;
   24.59  	}
   24.60  
   24.61 -	op.handle = (grant_handle_t)area->phys_addr;
   24.62 +	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
   24.63 +			    (grant_handle_t)area->phys_addr);
   24.64  
   24.65  	lock_vm_area(area);
   24.66  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   24.67 @@ -145,11 +138,10 @@ EXPORT_SYMBOL_GPL(xenbus_unmap_ring_vfre
   24.68  int xenbus_unmap_ring(struct xenbus_device *dev,
   24.69  		     grant_handle_t handle, void *vaddr)
   24.70  {
   24.71 -	struct gnttab_unmap_grant_ref op = {
   24.72 -		.host_addr = (unsigned long)vaddr,
   24.73 -		.handle    = handle,
   24.74 -	};
   24.75 +	struct gnttab_unmap_grant_ref op;
   24.76  
   24.77 +	gnttab_set_unmap_op(&op, (unsigned long)vaddr, GNTMAP_host_map,
   24.78 +			    handle);
   24.79  	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   24.80  
   24.81  	if (op.status != GNTST_okay)
    25.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Mon Apr 17 08:47:36 2006 -0600
    25.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_dev.c	Tue Apr 18 09:35:40 2006 -0600
    25.3 @@ -114,6 +114,7 @@ static ssize_t xenbus_dev_write(struct f
    25.4  {
    25.5  	struct xenbus_dev_data *u = filp->private_data;
    25.6  	struct xenbus_dev_transaction *trans = NULL;
    25.7 +	uint32_t msg_type;
    25.8  	void *reply;
    25.9  
   25.10  	if ((len + u->len) > sizeof(u->u.buffer))
   25.11 @@ -126,7 +127,9 @@ static ssize_t xenbus_dev_write(struct f
   25.12  	if (u->len < (sizeof(u->u.msg) + u->u.msg.len))
   25.13  		return len;
   25.14  
   25.15 -	switch (u->u.msg.type) {
   25.16 +	msg_type = u->u.msg.type;
   25.17 +
   25.18 +	switch (msg_type) {
   25.19  	case XS_TRANSACTION_START:
   25.20  	case XS_TRANSACTION_END:
   25.21  	case XS_DIRECTORY:
   25.22 @@ -138,7 +141,7 @@ static ssize_t xenbus_dev_write(struct f
   25.23  	case XS_MKDIR:
   25.24  	case XS_RM:
   25.25  	case XS_SET_PERMS:
   25.26 -		if (u->u.msg.type == XS_TRANSACTION_START) {
   25.27 +		if (msg_type == XS_TRANSACTION_START) {
   25.28  			trans = kmalloc(sizeof(*trans), GFP_KERNEL);
   25.29  			if (!trans)
   25.30  				return -ENOMEM;
   25.31 @@ -150,10 +153,10 @@ static ssize_t xenbus_dev_write(struct f
   25.32  			return PTR_ERR(reply);
   25.33  		}
   25.34  
   25.35 -		if (u->u.msg.type == XS_TRANSACTION_START) {
   25.36 +		if (msg_type == XS_TRANSACTION_START) {
   25.37  			trans->handle = simple_strtoul(reply, NULL, 0);
   25.38  			list_add(&trans->list, &u->transactions);
   25.39 -		} else if (u->u.msg.type == XS_TRANSACTION_END) {
   25.40 +		} else if (msg_type == XS_TRANSACTION_END) {
   25.41  			list_for_each_entry(trans, &u->transactions, list)
   25.42  				if (trans->handle == u->u.msg.tx_id)
   25.43  					break;
    26.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon Apr 17 08:47:36 2006 -0600
    26.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Tue Apr 18 09:35:40 2006 -0600
    26.3 @@ -825,6 +825,8 @@ static int resume_dev(struct device *dev
    26.4  		return err;
    26.5  	}
    26.6  
    26.7 +	xdev->state = XenbusStateInitialising;
    26.8 +
    26.9  	if (drv->resume)
   26.10  		err = drv->resume(xdev);
   26.11  	if (err)
    27.1 --- a/linux-2.6-xen-sparse/include/xen/gnttab.h	Mon Apr 17 08:47:36 2006 -0600
    27.2 +++ b/linux-2.6-xen-sparse/include/xen/gnttab.h	Tue Apr 18 09:35:40 2006 -0600
    27.3 @@ -40,6 +40,7 @@
    27.4  #include <linux/config.h>
    27.5  #include <asm/hypervisor.h>
    27.6  #include <xen/interface/grant_table.h>
    27.7 +#include <xen/features.h>
    27.8  
    27.9  /* NR_GRANT_FRAMES must be less than or equal to that configured in Xen */
   27.10  #ifdef __ia64__
   27.11 @@ -90,6 +91,8 @@ void gnttab_free_grant_reference(grant_r
   27.12  
   27.13  void gnttab_free_grant_references(grant_ref_t head);
   27.14  
   27.15 +int gnttab_empty_grant_references(const grant_ref_t *pprivate_head);
   27.16 +
   27.17  int gnttab_claim_grant_reference(grant_ref_t *pprivate_head);
   27.18  
   27.19  void gnttab_release_grant_reference(grant_ref_t *private_head,
   27.20 @@ -113,6 +116,37 @@ void gnttab_grant_foreign_transfer_ref(g
   27.21  int gnttab_suspend(void);
   27.22  int gnttab_resume(void);
   27.23  
   27.24 +static inline void
   27.25 +gnttab_set_map_op(struct gnttab_map_grant_ref *map, unsigned long addr,
   27.26 +		  uint32_t flags, grant_ref_t ref, domid_t domid)
   27.27 +{
   27.28 +	if (flags & GNTMAP_contains_pte)
   27.29 +		map->host_addr = addr;
   27.30 +	else if (xen_feature(XENFEAT_auto_translated_physmap))
   27.31 +		map->host_addr = __pa(addr);
   27.32 +	else
   27.33 +		map->host_addr = addr;
   27.34 +
   27.35 +	map->flags = flags;
   27.36 +	map->ref = ref;
   27.37 +	map->dom = domid;
   27.38 +}
   27.39 +
   27.40 +static inline void
   27.41 +gnttab_set_unmap_op(struct gnttab_unmap_grant_ref *unmap, unsigned long addr,
   27.42 +		    uint32_t flags, grant_handle_t handle)
   27.43 +{
   27.44 +	if (flags & GNTMAP_contains_pte)
   27.45 +		unmap->host_addr = addr;
   27.46 +	else if (xen_feature(XENFEAT_auto_translated_physmap))
   27.47 +		unmap->host_addr = __pa(addr);
   27.48 +	else
   27.49 +		unmap->host_addr = addr;
   27.50 +
   27.51 +	unmap->handle = handle;
   27.52 +	unmap->dev_bus_addr = 0;
   27.53 +}
   27.54 +
   27.55  #endif /* __ASM_GNTTAB_H__ */
   27.56  
   27.57  /*
    28.1 --- a/linux-2.6-xen-sparse/mkbuildtree	Mon Apr 17 08:47:36 2006 -0600
    28.2 +++ b/linux-2.6-xen-sparse/mkbuildtree	Tue Apr 18 09:35:40 2006 -0600
    28.3 @@ -90,8 +90,8 @@ abs_to_rel ${AD} ${AS}
    28.4  RS=$DESTPATH
    28.5  
    28.6  # Arch-specific pre-processing
    28.7 -if [ -x arch/${LINUX_ARCH}/xen-mkbuildtree-pre ]; then
    28.8 -	arch/${LINUX_ARCH}/xen-mkbuildtree-pre
    28.9 +if [ -e arch/${LINUX_ARCH}/xen-mkbuildtree-pre ]; then
   28.10 +	bash arch/${LINUX_ARCH}/xen-mkbuildtree-pre
   28.11  fi
   28.12  
   28.13  # Remove old copies of files and directories at the destination
   28.14 @@ -115,6 +115,6 @@ relative_lndir ../../../${RS}/../xen/inc
   28.15  
   28.16  # Arch-specific post-processing
   28.17  cd ${AD}
   28.18 -if [ -x arch/${LINUX_ARCH}/xen-mkbuildtree-post ]; then
   28.19 -	arch/${LINUX_ARCH}/xen-mkbuildtree-post
   28.20 +if [ -e arch/${LINUX_ARCH}/xen-mkbuildtree-post ]; then
   28.21 +	bash arch/${LINUX_ARCH}/xen-mkbuildtree-post
   28.22  fi
    29.1 --- a/linux-2.6-xen-sparse/net/core/dev.c	Mon Apr 17 08:47:36 2006 -0600
    29.2 +++ b/linux-2.6-xen-sparse/net/core/dev.c	Tue Apr 18 09:35:40 2006 -0600
    29.3 @@ -1294,6 +1294,7 @@ int dev_queue_xmit(struct sk_buff *skb)
    29.4  		if ((skb->h.raw + skb->csum + 2) > skb->tail)
    29.5  			goto out_kfree_skb;
    29.6  		skb->ip_summed = CHECKSUM_HW;
    29.7 +		skb->proto_csum_blank = 0;
    29.8  	}
    29.9  #endif
   29.10  
    30.1 --- a/tools/debugger/gdb/gdbbuild	Mon Apr 17 08:47:36 2006 -0600
    30.2 +++ b/tools/debugger/gdb/gdbbuild	Tue Apr 18 09:35:40 2006 -0600
    30.3 @@ -7,7 +7,7 @@ rm -rf gdb-6.2.1 gdb-6.2.1-linux-i386-xe
    30.4  tar xjf gdb-6.2.1.tar.bz2
    30.5  
    30.6  cd gdb-6.2.1-xen-sparse
    30.7 -./mkbuildtree ../gdb-6.2.1
    30.8 +bash ./mkbuildtree ../gdb-6.2.1
    30.9  
   30.10  cd ..
   30.11  mkdir gdb-6.2.1-linux-i386-xen
    31.1 --- a/tools/examples/xend-config.sxp	Mon Apr 17 08:47:36 2006 -0600
    31.2 +++ b/tools/examples/xend-config.sxp	Tue Apr 18 09:35:40 2006 -0600
    31.3 @@ -127,3 +127,6 @@
    31.4  
    31.5  # Whether to enable core-dumps when domains crash.
    31.6  #(enable-dump no)
    31.7 +
    31.8 +# The tool used for initiating virtual TPM migration
    31.9 +#(external-migration-tool '')
    32.1 --- a/tools/firmware/hvmloader/Makefile	Mon Apr 17 08:47:36 2006 -0600
    32.2 +++ b/tools/firmware/hvmloader/Makefile	Tue Apr 18 09:35:40 2006 -0600
    32.3 @@ -21,7 +21,7 @@
    32.4  # External CFLAGS can do more harm than good.
    32.5  CFLAGS :=
    32.6  
    32.7 -XEN_TARGET_ARCH = x86_32
    32.8 +override XEN_TARGET_ARCH = x86_32
    32.9  XEN_ROOT = ../../..
   32.10  include $(XEN_ROOT)/Config.mk
   32.11  
    33.1 --- a/tools/firmware/vmxassist/Makefile	Mon Apr 17 08:47:36 2006 -0600
    33.2 +++ b/tools/firmware/vmxassist/Makefile	Tue Apr 18 09:35:40 2006 -0600
    33.3 @@ -21,7 +21,7 @@
    33.4  # External CFLAGS can do more harm than good.
    33.5  CFLAGS :=
    33.6  
    33.7 -XEN_TARGET_ARCH = x86_32
    33.8 +override XEN_TARGET_ARCH = x86_32
    33.9  XEN_ROOT = ../../..
   33.10  include $(XEN_ROOT)/Config.mk
   33.11  
    34.1 --- a/tools/ioemu/vl.c	Mon Apr 17 08:47:36 2006 -0600
    34.2 +++ b/tools/ioemu/vl.c	Tue Apr 18 09:35:40 2006 -0600
    34.3 @@ -138,7 +138,7 @@ int adlib_enabled = 1;
    34.4  int gus_enabled = 1;
    34.5  int pci_enabled = 1;
    34.6  int prep_enabled = 0;
    34.7 -int rtc_utc = 0;
    34.8 +int rtc_utc = 1;
    34.9  int cirrus_vga_enabled = 1;
   34.10  int vga_accelerate = 1;
   34.11  int graphic_width = 800;
    35.1 --- a/tools/libxc/xc_bvtsched.c	Mon Apr 17 08:47:36 2006 -0600
    35.2 +++ b/tools/libxc/xc_bvtsched.c	Tue Apr 18 09:35:40 2006 -0600
    35.3 @@ -1,8 +1,8 @@
    35.4  /******************************************************************************
    35.5   * xc_bvtsched.c
    35.6 - * 
    35.7 + *
    35.8   * API for manipulating parameters of the Borrowed Virtual Time scheduler.
    35.9 - * 
   35.10 + *
   35.11   * Copyright (c) 2003, K A Fraser.
   35.12   */
   35.13  
   35.14 @@ -26,7 +26,7 @@ int xc_bvtsched_global_get(int xc_handle
   35.15  {
   35.16      DECLARE_DOM0_OP;
   35.17      int ret;
   35.18 -    
   35.19 +
   35.20      op.cmd = DOM0_SCHEDCTL;
   35.21      op.u.schedctl.sched_id = SCHED_BVT;
   35.22      op.u.schedctl.direction = SCHED_INFO_GET;
   35.23 @@ -71,7 +71,7 @@ int xc_bvtsched_domain_get(int xc_handle
   35.24                             long long *warpl,
   35.25                             long long *warpu)
   35.26  {
   35.27 -    
   35.28 +
   35.29      DECLARE_DOM0_OP;
   35.30      int ret;
   35.31      struct bvt_adjdom *adjptr = &op.u.adjustdom.u.bvt;
    36.1 --- a/tools/libxc/xc_core.c	Mon Apr 17 08:47:36 2006 -0600
    36.2 +++ b/tools/libxc/xc_core.c	Tue Apr 18 09:35:40 2006 -0600
    36.3 @@ -23,7 +23,7 @@ copy_from_domain_page(int xc_handle,
    36.4      return 0;
    36.5  }
    36.6  
    36.7 -int 
    36.8 +int
    36.9  xc_domain_dumpcore_via_callback(int xc_handle,
   36.10                                  uint32_t domid,
   36.11                                  void *args,
   36.12 @@ -45,13 +45,13 @@ xc_domain_dumpcore_via_callback(int xc_h
   36.13          PERROR("Could not allocate dump_mem");
   36.14          goto error_out;
   36.15      }
   36.16 - 
   36.17 +
   36.18      if ( xc_domain_getinfo(xc_handle, domid, 1, &info) != 1 )
   36.19      {
   36.20          PERROR("Could not get info for domain");
   36.21          goto error_out;
   36.22      }
   36.23 - 
   36.24 +
   36.25      if ( domid != info.domid )
   36.26      {
   36.27          PERROR("Domain %d does not exist", domid);
   36.28 @@ -61,10 +61,10 @@ xc_domain_dumpcore_via_callback(int xc_h
   36.29      for ( i = 0; i <= info.max_vcpu_id; i++ )
   36.30          if ( xc_vcpu_getcontext(xc_handle, domid, i, &ctxt[nr_vcpus]) == 0)
   36.31              nr_vcpus++;
   36.32 - 
   36.33 +
   36.34      nr_pages = info.nr_pages;
   36.35  
   36.36 -    header.xch_magic = XC_CORE_MAGIC; 
   36.37 +    header.xch_magic = XC_CORE_MAGIC;
   36.38      header.xch_nr_vcpus = nr_vcpus;
   36.39      header.xch_nr_pages = nr_pages;
   36.40      header.xch_ctxt_offset = sizeof(struct xc_core_header);
   36.41 @@ -74,7 +74,7 @@ xc_domain_dumpcore_via_callback(int xc_h
   36.42                   (sizeof(vcpu_guest_context_t) * nr_vcpus) +
   36.43                   (nr_pages * sizeof(unsigned long)));
   36.44      header.xch_pages_offset = round_pgup(dummy_len);
   36.45 -    
   36.46 +
   36.47      sts = dump_rtn(args, (char *)&header, sizeof(struct xc_core_header));
   36.48      if ( sts != 0 )
   36.49          goto error_out;
   36.50 @@ -150,7 +150,7 @@ static int local_file_dump(void *args, c
   36.51      return 0;
   36.52  }
   36.53  
   36.54 -int 
   36.55 +int
   36.56  xc_domain_dumpcore(int xc_handle,
   36.57                     uint32_t domid,
   36.58                     const char *corename)
   36.59 @@ -163,7 +163,7 @@ xc_domain_dumpcore(int xc_handle,
   36.60          PERROR("Could not open corefile %s: %s", corename, strerror(errno));
   36.61          return -errno;
   36.62      }
   36.63 - 
   36.64 +
   36.65      sts = xc_domain_dumpcore_via_callback(
   36.66          xc_handle, domid, &da, &local_file_dump);
   36.67  
    37.1 --- a/tools/libxc/xc_domain.c	Mon Apr 17 08:47:36 2006 -0600
    37.2 +++ b/tools/libxc/xc_domain.c	Tue Apr 18 09:35:40 2006 -0600
    37.3 @@ -1,8 +1,8 @@
    37.4  /******************************************************************************
    37.5   * xc_domain.c
    37.6 - * 
    37.7 + *
    37.8   * API for manipulating and obtaining information on domains.
    37.9 - * 
   37.10 + *
   37.11   * Copyright (c) 2003, K A Fraser.
   37.12   */
   37.13  
   37.14 @@ -26,17 +26,17 @@ int xc_domain_create(int xc_handle,
   37.15  
   37.16      *pdomid = (uint16_t)op.u.createdomain.domain;
   37.17      return 0;
   37.18 -}    
   37.19 +}
   37.20  
   37.21  
   37.22 -int xc_domain_pause(int xc_handle, 
   37.23 +int xc_domain_pause(int xc_handle,
   37.24                      uint32_t domid)
   37.25  {
   37.26      DECLARE_DOM0_OP;
   37.27      op.cmd = DOM0_PAUSEDOMAIN;
   37.28      op.u.pausedomain.domain = (domid_t)domid;
   37.29      return do_dom0_op(xc_handle, &op);
   37.30 -}    
   37.31 +}
   37.32  
   37.33  
   37.34  int xc_domain_unpause(int xc_handle,
   37.35 @@ -46,7 +46,7 @@ int xc_domain_unpause(int xc_handle,
   37.36      op.cmd = DOM0_UNPAUSEDOMAIN;
   37.37      op.u.unpausedomain.domain = (domid_t)domid;
   37.38      return do_dom0_op(xc_handle, &op);
   37.39 -}    
   37.40 +}
   37.41  
   37.42  
   37.43  int xc_domain_destroy(int xc_handle,
   37.44 @@ -88,7 +88,7 @@ int xc_domain_shutdown(int xc_handle,
   37.45  
   37.46  
   37.47  int xc_vcpu_setaffinity(int xc_handle,
   37.48 -                        uint32_t domid, 
   37.49 +                        uint32_t domid,
   37.50                          int vcpu,
   37.51                          cpumap_t cpumap)
   37.52  {
   37.53 @@ -109,7 +109,7 @@ int xc_domain_getinfo(int xc_handle,
   37.54      unsigned int nr_doms;
   37.55      uint32_t next_domid = first_domid;
   37.56      DECLARE_DOM0_OP;
   37.57 -    int rc = 0; 
   37.58 +    int rc = 0;
   37.59  
   37.60      memset(info, 0, max_doms*sizeof(xc_dominfo_t));
   37.61  
   37.62 @@ -127,8 +127,8 @@ int xc_domain_getinfo(int xc_handle,
   37.63          info->blocked  = !!(op.u.getdomaininfo.flags & DOMFLAGS_BLOCKED);
   37.64          info->running  = !!(op.u.getdomaininfo.flags & DOMFLAGS_RUNNING);
   37.65  
   37.66 -        info->shutdown_reason = 
   37.67 -            (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) & 
   37.68 +        info->shutdown_reason =
   37.69 +            (op.u.getdomaininfo.flags>>DOMFLAGS_SHUTDOWNSHIFT) &
   37.70              DOMFLAGS_SHUTDOWNMASK;
   37.71  
   37.72          if ( info->shutdown && (info->shutdown_reason == SHUTDOWN_crash) )
   37.73 @@ -152,7 +152,7 @@ int xc_domain_getinfo(int xc_handle,
   37.74          info++;
   37.75      }
   37.76  
   37.77 -    if( !nr_doms ) return rc; 
   37.78 +    if( !nr_doms ) return rc;
   37.79  
   37.80      return nr_doms;
   37.81  }
   37.82 @@ -167,7 +167,7 @@ int xc_domain_getinfolist(int xc_handle,
   37.83  
   37.84      if ( mlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
   37.85          return -1;
   37.86 -    
   37.87 +
   37.88      op.cmd = DOM0_GETDOMAININFOLIST;
   37.89      op.u.getdomaininfolist.first_domain = first_domain;
   37.90      op.u.getdomaininfolist.max_domains  = max_domains;
   37.91 @@ -177,10 +177,10 @@ int xc_domain_getinfolist(int xc_handle,
   37.92          ret = -1;
   37.93      else
   37.94          ret = op.u.getdomaininfolist.num_domains;
   37.95 -    
   37.96 +
   37.97      if ( munlock(info, max_domains*sizeof(xc_domaininfo_t)) != 0 )
   37.98          ret = -1;
   37.99 -    
  37.100 +
  37.101      return ret;
  37.102  }
  37.103  
  37.104 @@ -209,7 +209,7 @@ int xc_vcpu_getcontext(int xc_handle,
  37.105  
  37.106  
  37.107  int xc_shadow_control(int xc_handle,
  37.108 -                      uint32_t domid, 
  37.109 +                      uint32_t domid,
  37.110                        unsigned int sop,
  37.111                        unsigned long *dirty_bitmap,
  37.112                        unsigned long pages,
  37.113 @@ -238,11 +238,11 @@ int xc_domain_setcpuweight(int xc_handle
  37.114  {
  37.115      int sched_id;
  37.116      int ret;
  37.117 -    
  37.118 +
  37.119      /* Figure out which scheduler is currently used: */
  37.120      if ( (ret = xc_sched_id(xc_handle, &sched_id)) != 0 )
  37.121          return ret;
  37.122 -    
  37.123 +
  37.124      switch ( sched_id )
  37.125      {
  37.126          case SCHED_BVT:
  37.127 @@ -253,20 +253,20 @@ int xc_domain_setcpuweight(int xc_handle
  37.128              long long warpl;
  37.129              long long warpu;
  37.130  
  37.131 -            /* Preserve all the scheduling parameters apart 
  37.132 +            /* Preserve all the scheduling parameters apart
  37.133                 of MCU advance. */
  37.134              if ( (ret = xc_bvtsched_domain_get(
  37.135 -                xc_handle, domid, &mcuadv, 
  37.136 +                xc_handle, domid, &mcuadv,
  37.137                  &warpback, &warpvalue, &warpl, &warpu)) != 0 )
  37.138                  return ret;
  37.139 -            
  37.140 +
  37.141              /* The MCU advance is inverse of the weight.
  37.142                 Default value of the weight is 1, default mcuadv 10.
  37.143                 The scaling factor is therefore 10. */
  37.144              if ( weight > 0 )
  37.145                  mcuadv = 10 / weight;
  37.146 -            
  37.147 -            ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv, 
  37.148 +
  37.149 +            ret = xc_bvtsched_domain_set(xc_handle, domid, mcuadv,
  37.150                                           warpback, warpvalue, warpl, warpu);
  37.151              break;
  37.152          }
  37.153 @@ -276,7 +276,7 @@ int xc_domain_setcpuweight(int xc_handle
  37.154  }
  37.155  
  37.156  int xc_domain_setmaxmem(int xc_handle,
  37.157 -                        uint32_t domid, 
  37.158 +                        uint32_t domid,
  37.159                          unsigned int max_memkb)
  37.160  {
  37.161      DECLARE_DOM0_OP;
  37.162 @@ -287,7 +287,7 @@ int xc_domain_setmaxmem(int xc_handle,
  37.163  }
  37.164  
  37.165  int xc_domain_memory_increase_reservation(int xc_handle,
  37.166 -                                          uint32_t domid, 
  37.167 +                                          uint32_t domid,
  37.168                                            unsigned long nr_extents,
  37.169                                            unsigned int extent_order,
  37.170                                            unsigned int address_bits,
  37.171 @@ -297,7 +297,7 @@ int xc_domain_memory_increase_reservatio
  37.172      struct xen_memory_reservation reservation = {
  37.173          .extent_start = extent_start, /* may be NULL */
  37.174          .nr_extents   = nr_extents,
  37.175 -        .extent_order = extent_order,  
  37.176 +        .extent_order = extent_order,
  37.177          .address_bits = address_bits,
  37.178          .domid        = domid
  37.179      };
  37.180 @@ -319,16 +319,16 @@ int xc_domain_memory_increase_reservatio
  37.181  }
  37.182  
  37.183  int xc_domain_memory_decrease_reservation(int xc_handle,
  37.184 -                                          uint32_t domid, 
  37.185 +                                          uint32_t domid,
  37.186                                            unsigned long nr_extents,
  37.187                                            unsigned int extent_order,
  37.188                                            unsigned long *extent_start)
  37.189  {
  37.190      int err;
  37.191      struct xen_memory_reservation reservation = {
  37.192 -        .extent_start = extent_start, 
  37.193 +        .extent_start = extent_start,
  37.194          .nr_extents   = nr_extents,
  37.195 -        .extent_order = extent_order,  
  37.196 +        .extent_order = extent_order,
  37.197          .address_bits = 0,
  37.198          .domid        = domid
  37.199      };
  37.200 @@ -411,7 +411,7 @@ int xc_domain_max_vcpus(int xc_handle, u
  37.201      return do_dom0_op(xc_handle, &op);
  37.202  }
  37.203  
  37.204 -int xc_domain_sethandle(int xc_handle, uint32_t domid, 
  37.205 +int xc_domain_sethandle(int xc_handle, uint32_t domid,
  37.206                          xen_domain_handle_t handle)
  37.207  {
  37.208      DECLARE_DOM0_OP;
  37.209 @@ -506,7 +506,7 @@ int xc_domain_iomem_permission(int xc_ha
  37.210      op.cmd = DOM0_IOMEM_PERMISSION;
  37.211      op.u.iomem_permission.domain = domid;
  37.212      op.u.iomem_permission.first_mfn = first_mfn;
  37.213 -	op.u.iomem_permission.nr_mfns = nr_mfns;
  37.214 +    op.u.iomem_permission.nr_mfns = nr_mfns;
  37.215      op.u.iomem_permission.allow_access = allow_access;
  37.216  
  37.217      return do_dom0_op(xc_handle, &op);
    38.1 --- a/tools/libxc/xc_elf.h	Mon Apr 17 08:47:36 2006 -0600
    38.2 +++ b/tools/libxc/xc_elf.h	Tue Apr 18 09:35:40 2006 -0600
    38.3 @@ -46,7 +46,7 @@ typedef uint32_t	Elf64_Half;
    38.4  typedef uint16_t	Elf64_Quarter;
    38.5  
    38.6  /*
    38.7 - * e_ident[] identification indexes 
    38.8 + * e_ident[] identification indexes
    38.9   * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html
   38.10   */
   38.11  #define EI_MAG0		0		/* file ID */
   38.12 @@ -57,7 +57,7 @@ typedef uint16_t	Elf64_Quarter;
   38.13  #define EI_DATA		5		/* data encoding */
   38.14  #define EI_VERSION	6		/* ELF header version */
   38.15  #define EI_OSABI	7		/* OS/ABI ID */
   38.16 -#define EI_ABIVERSION	8		/* ABI version */ 
   38.17 +#define EI_ABIVERSION	8		/* ABI version */
   38.18  #define EI_PAD		9		/* start of pad bytes */
   38.19  #define EI_NIDENT	16		/* Size of e_ident[] */
   38.20  
   38.21 @@ -119,7 +119,7 @@ typedef struct elfhdr {
   38.22  	Elf32_Half	e_phnum;	/* number of program header entries */
   38.23  	Elf32_Half	e_shentsize;	/* section header entry size */
   38.24  	Elf32_Half	e_shnum;	/* number of section header entries */
   38.25 -	Elf32_Half	e_shstrndx;	/* section header table's "section 
   38.26 +	Elf32_Half	e_shstrndx;	/* section header table's "section
   38.27  					   header string table" entry offset */
   38.28  } Elf32_Ehdr;
   38.29  
   38.30 @@ -160,7 +160,7 @@ typedef struct {
   38.31  #define EM_486		6		/* Intel 80486 - unused? */
   38.32  #define EM_860		7		/* Intel 80860 */
   38.33  #define EM_MIPS		8		/* MIPS R3000 Big-Endian only */
   38.34 -/* 
   38.35 +/*
   38.36   * Don't know if EM_MIPS_RS4_BE,
   38.37   * EM_SPARC64, EM_PARISC,
   38.38   * or EM_PPC are ABI compliant
   38.39 @@ -441,7 +441,7 @@ typedef struct {
   38.40  #define DT_NUM		25		/* Number used. */
   38.41  #define DT_LOPROC	0x70000000	/* reserved range for processor */
   38.42  #define DT_HIPROC	0x7fffffff	/*  specific dynamic array tags */
   38.43 -	
   38.44 +
   38.45  /* Standard ELF hashing function */
   38.46  unsigned int elf_hash(const unsigned char *name);
   38.47  
    39.1 --- a/tools/libxc/xc_evtchn.c	Mon Apr 17 08:47:36 2006 -0600
    39.2 +++ b/tools/libxc/xc_evtchn.c	Tue Apr 18 09:35:40 2006 -0600
    39.3 @@ -1,8 +1,8 @@
    39.4  /******************************************************************************
    39.5   * xc_evtchn.c
    39.6 - * 
    39.7 + *
    39.8   * API for manipulating and accessing inter-domain event channels.
    39.9 - * 
   39.10 + *
   39.11   * Copyright (c) 2004, K A Fraser.
   39.12   */
   39.13  
   39.14 @@ -44,7 +44,7 @@ int xc_evtchn_alloc_unbound(int xc_handl
   39.15  
   39.16      if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
   39.17          rc = op.u.alloc_unbound.port;
   39.18 -    
   39.19 +
   39.20      return rc;
   39.21  }
   39.22  
   39.23 @@ -62,6 +62,6 @@ int xc_evtchn_status(int xc_handle,
   39.24  
   39.25      if ( (rc = do_evtchn_op(xc_handle, &op)) == 0 )
   39.26          memcpy(status, &op.u.status, sizeof(*status));
   39.27 -    
   39.28 +
   39.29      return rc;
   39.30  }
    40.1 --- a/tools/libxc/xc_ia64_stubs.c	Mon Apr 17 08:47:36 2006 -0600
    40.2 +++ b/tools/libxc/xc_ia64_stubs.c	Tue Apr 18 09:35:40 2006 -0600
    40.3 @@ -22,7 +22,7 @@ unsigned long xc_ia64_fpsr_default(void)
    40.4          return FPSR_DEFAULT;
    40.5  }
    40.6  
    40.7 -int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
    40.8 +int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
    40.9                    uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
   40.10                    int (*suspend)(int domid))
   40.11  {
   40.12 @@ -53,11 +53,11 @@ xc_plan9_build(int xc_handle,
   40.13      VMM don't handle this now.
   40.14      This method will touch guest buffer to make sure the buffer's mapping
   40.15      is tracked by VMM,
   40.16 -  */
   40.17 + */
   40.18  
   40.19  int xc_ia64_get_pfn_list(int xc_handle,
   40.20 -                         uint32_t domid, 
   40.21 -                         unsigned long *pfn_buf, 
   40.22 +                         uint32_t domid,
   40.23 +                         unsigned long *pfn_buf,
   40.24                           unsigned int start_page,
   40.25                           unsigned int nr_pages)
   40.26  {
   40.27 @@ -78,16 +78,16 @@ int xc_ia64_get_pfn_list(int xc_handle,
   40.28          op.u.getmemlist.buffer   = __pfn_buf;
   40.29  
   40.30          if ( (max_pfns != -1UL)
   40.31 -		    && mlock(__pfn_buf, __nr_pages * sizeof(unsigned long)) != 0 )
   40.32 +            && mlock(__pfn_buf, __nr_pages * sizeof(unsigned long)) != 0 )
   40.33          {
   40.34              PERROR("Could not lock pfn list buffer");
   40.35              return -1;
   40.36 -        }    
   40.37 +        }
   40.38  
   40.39          ret = do_dom0_op(xc_handle, &op);
   40.40  
   40.41          if (max_pfns != -1UL)
   40.42 -        	(void)munlock(__pfn_buf, __nr_pages * sizeof(unsigned long));
   40.43 +            (void)munlock(__pfn_buf, __nr_pages * sizeof(unsigned long));
   40.44  
   40.45          if (max_pfns == -1UL)
   40.46              return 0;
   40.47 @@ -97,12 +97,12 @@ int xc_ia64_get_pfn_list(int xc_handle,
   40.48          __nr_pages -= num_pfns;
   40.49          __pfn_buf += num_pfns;
   40.50  
   40.51 -        if (ret < 0) 
   40.52 -            // dummy write to make sure this tlb mapping is tracked by VMM 
   40.53 +        if (ret < 0)
   40.54 +            // dummy write to make sure this tlb mapping is tracked by VMM
   40.55              *__pfn_buf = 0;
   40.56 -        else 
   40.57 -            return nr_pages;    
   40.58 -    }    
   40.59 +        else
   40.60 +            return nr_pages;
   40.61 +    }
   40.62      return nr_pages;
   40.63  }
   40.64  
   40.65 @@ -111,7 +111,7 @@ long xc_get_max_pages(int xc_handle, uin
   40.66      dom0_op_t op;
   40.67      op.cmd = DOM0_GETDOMAININFO;
   40.68      op.u.getdomaininfo.domain = (domid_t)domid;
   40.69 -    return (do_dom0_op(xc_handle, &op) < 0) ? 
   40.70 +    return (do_dom0_op(xc_handle, &op) < 0) ?
   40.71          -1 : op.u.getdomaininfo.max_pages;
   40.72  }
   40.73  
   40.74 @@ -119,7 +119,7 @@ int xc_ia64_copy_to_domain_pages(int xc_
   40.75          void* src_page, unsigned long dst_pfn, int nr_pages)
   40.76  {
   40.77      // N.B. gva should be page aligned
   40.78 -    
   40.79 +
   40.80      unsigned long *page_array = NULL;
   40.81      int i;
   40.82  
   40.83 @@ -134,22 +134,22 @@ int xc_ia64_copy_to_domain_pages(int xc_
   40.84      }
   40.85  
   40.86      for ( i=0; i< nr_pages; i++ ){
   40.87 -	if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
   40.88 -			src_page + (i << PAGE_SHIFT)))
   40.89 -	    goto error_out;
   40.90 +        if (xc_copy_to_domain_page(xc_handle, domid, page_array[i],
   40.91 +                    src_page + (i << PAGE_SHIFT)))
   40.92 +            goto error_out;
   40.93      }
   40.94      free(page_array);
   40.95      return 0;
   40.96 -    
   40.97 +
   40.98  error_out:
   40.99      free(page_array);
  40.100      return -1;
  40.101  }
  40.102  
  40.103  
  40.104 -#define HOB_SIGNATURE 0x3436474953424f48 // "HOBSIG64"
  40.105 -#define GFW_HOB_START         ((4UL<<30)-(14UL<<20))    //4G -14M
  40.106 -#define GFW_HOB_SIZE          (1UL<<20)              //1M
  40.107 +#define HOB_SIGNATURE         0x3436474953424f48        // "HOBSIG64"
  40.108 +#define GFW_HOB_START         ((4UL<<30)-(14UL<<20))    // 4G - 14M
  40.109 +#define GFW_HOB_SIZE          (1UL<<20)                 // 1M
  40.110  #define RAW_GFW_START_NR(s)   ((s) >> PAGE_SHIFT)
  40.111  #define RAW_GFW_HOB_START_NR(s)                \
  40.112          (RAW_GFW_START_NR(s) + ((GFW_HOB_START - GFW_START) >> PAGE_SHIFT))
  40.113 @@ -170,7 +170,7 @@ typedef struct {
  40.114   * INFO HOB is the first data data in one HOB list
  40.115   * it contains the control information of the HOB list
  40.116   */
  40.117 -typedef struct { 
  40.118 +typedef struct {
  40.119      HOB_GENERIC_HEADER  header;
  40.120      unsigned long       length;    // current length of hob
  40.121      unsigned long       cur_pos;   // current poisiton of hob
  40.122 @@ -251,7 +251,7 @@ hob_init( void  *buffer ,unsigned long b
  40.123          // buffer too small
  40.124          return -1;
  40.125      }
  40.126 -    
  40.127 +
  40.128      phit = (HOB_INFO*)buffer;
  40.129      phit->header.signature = HOB_SIGNATURE;
  40.130      phit->header.type = HOB_TYPE_INFO;
  40.131 @@ -259,7 +259,7 @@ hob_init( void  *buffer ,unsigned long b
  40.132      phit->length = sizeof(HOB_INFO) + sizeof(HOB_GENERIC_HEADER);
  40.133      phit->cur_pos = 0;
  40.134      phit->buf_size = buf_size;
  40.135 -    
  40.136 +
  40.137      terminal = (HOB_GENERIC_HEADER*) (buffer + sizeof(HOB_INFO));
  40.138      terminal->signature= HOB_SIGNATURE;
  40.139      terminal->type = HOB_TYPE_TERMINAL;
  40.140 @@ -270,7 +270,7 @@ hob_init( void  *buffer ,unsigned long b
  40.141  
  40.142  /*
  40.143   *  Add a new HOB to the HOB List.
  40.144 - *       
  40.145 + *
  40.146   *  hob_start  -  start address of hob buffer
  40.147   *  type       -  type of the hob to be added
  40.148   *  data       -  data of the hob to be added
  40.149 @@ -285,8 +285,8 @@ hob_add(
  40.150  )
  40.151  {
  40.152      HOB_INFO *phit;
  40.153 -    HOB_GENERIC_HEADER     *newhob,*tail;   
  40.154 -    
  40.155 +    HOB_GENERIC_HEADER     *newhob,*tail;
  40.156 +
  40.157      phit = (HOB_INFO*)hob_start;
  40.158  
  40.159      if (phit->length + data_size > phit->buf_size){
  40.160 @@ -294,7 +294,7 @@ hob_add(
  40.161          return -1;
  40.162      }
  40.163  
  40.164 -    //append new HOB 
  40.165 +    //append new HOB
  40.166      newhob = (HOB_GENERIC_HEADER*)
  40.167          (hob_start + phit->length - sizeof(HOB_GENERIC_HEADER));
  40.168      newhob->signature = HOB_SIGNATURE;
  40.169 @@ -302,7 +302,7 @@ hob_add(
  40.170      newhob->length = data_size + sizeof(HOB_GENERIC_HEADER);
  40.171      memcpy((void*)newhob + sizeof(HOB_GENERIC_HEADER), data, data_size);
  40.172  
  40.173 -    // append terminal HOB  
  40.174 +    // append terminal HOB
  40.175      tail = (HOB_GENERIC_HEADER*) ( hob_start + phit->length + data_size);
  40.176      tail->signature = HOB_SIGNATURE;
  40.177      tail->type = HOB_TYPE_TERMINAL;
  40.178 @@ -316,9 +316,9 @@ hob_add(
  40.179  }
  40.180  
  40.181  int get_hob_size(void* hob_buf){
  40.182 -    
  40.183 +
  40.184      HOB_INFO *phit = (HOB_INFO*)hob_buf;
  40.185 -    
  40.186 +
  40.187      if (phit->header.signature != HOB_SIGNATURE){
  40.188          PERROR("xc_get_hob_size:Incorrect signature");
  40.189          return -1;
  40.190 @@ -328,32 +328,32 @@ int get_hob_size(void* hob_buf){
  40.191  
  40.192  int build_hob (void* hob_buf, unsigned long hob_buf_size,
  40.193                    unsigned long dom_mem_size)
  40.194 -{   
  40.195 -    //Init HOB List 
  40.196 +{
  40.197 +    //Init HOB List
  40.198      if (hob_init (hob_buf, hob_buf_size)<0){
  40.199          PERROR("buffer too small");
  40.200          goto err_out;
  40.201      }
  40.202 -    
  40.203 +
  40.204      if ( add_mem_hob( hob_buf,dom_mem_size) < 0){
  40.205          PERROR("Add memory hob failed, buffer too small");
  40.206          goto err_out;
  40.207      }
  40.208 -    
  40.209 +
  40.210      if ( add_pal_hob( hob_buf ) < 0 ){
  40.211          PERROR("Add PAL hob failed, buffer too small");
  40.212          goto err_out;
  40.213      }
  40.214 -    
  40.215 +
  40.216      return 0;
  40.217  
  40.218  err_out:
  40.219 -    return -1;  
  40.220 +    return -1;
  40.221  }
  40.222  
  40.223 -static int 
  40.224 +static int
  40.225  load_hob(int xc_handle, uint32_t dom, void *hob_buf,
  40.226 -	 unsigned long dom_mem_size)
  40.227 +         unsigned long dom_mem_size)
  40.228  {
  40.229      // hob_buf should be page aligned
  40.230      int hob_size;
  40.231 @@ -370,22 +370,22 @@ load_hob(int xc_handle, uint32_t dom, vo
  40.232      }
  40.233  
  40.234      nr_pages = (hob_size + PAGE_SIZE -1) >> PAGE_SHIFT;
  40.235 -    
  40.236 +
  40.237      return xc_ia64_copy_to_domain_pages(xc_handle, dom,
  40.238              hob_buf, RAW_GFW_HOB_START_NR(dom_mem_size), nr_pages );
  40.239  }
  40.240  
  40.241  #define MIN(x, y) ((x) < (y)) ? (x) : (y)
  40.242 -static int 
  40.243 +static int
  40.244  add_mem_hob(void* hob_buf, unsigned long dom_mem_size){
  40.245      hob_mem_t memhob;
  40.246  
  40.247      // less than 3G
  40.248      memhob.start = 0;
  40.249      memhob.size = MIN(dom_mem_size, 0xC0000000);
  40.250 -    
  40.251 +
  40.252      if (hob_add(hob_buf, HOB_TYPE_MEM, &memhob, sizeof(memhob)) < 0){
  40.253 -	return -1;
  40.254 +        return -1;
  40.255      }
  40.256  
  40.257      if (dom_mem_size > 0xC0000000) {
  40.258 @@ -409,29 +409,29 @@ unsigned char config_pal_mem_attrib[8] =
  40.259  };
  40.260  unsigned char config_pal_cache_info[152] = {
  40.261      3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.262 -    6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12, 
  40.263 +    6, 4, 6, 7, 255, 1, 0, 1, 0, 64, 0, 0, 12, 12,
  40.264      49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 7, 0, 1,
  40.265 -    0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0, 
  40.266 -    0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0, 
  40.267 -    12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7, 
  40.268 +    0, 1, 0, 64, 0, 0, 12, 12, 49, 0, 0, 0, 0, 0, 0,
  40.269 +    0, 0, 0, 6, 8, 7, 7, 255, 7, 0, 11, 0, 0, 16, 0,
  40.270 +    12, 17, 49, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 8, 7,
  40.271      7, 7, 5, 9, 11, 0, 0, 4, 0, 12, 15, 49, 0, 254, 255,
  40.272 -    255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9, 
  40.273 -    11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.274 +    255, 255, 255, 255, 255, 255, 2, 8, 7, 7, 7, 5, 9,
  40.275 +    11, 0, 0, 4, 0, 12, 15, 49, 0, 0, 0, 0, 0, 0, 0, 0,
  40.276      0, 3, 12, 7, 7, 7, 14, 1, 3, 0, 0, 192, 0, 12, 20, 49, 0
  40.277  };
  40.278  unsigned char config_pal_cache_prot_info[200] = {
  40.279 -    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.280 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.281      45, 0, 16, 8, 0, 76, 12, 64, 0, 0, 0, 0, 0, 0, 0,
  40.282 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.283 -    8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.284 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 
  40.285 -    0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.286 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.287 +    8, 0, 16, 4, 0, 76, 44, 68, 0, 0, 0, 0, 0, 0, 0, 0,
  40.288 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32,
  40.289 +    0, 16, 8, 0, 81, 44, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.290      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0,
  40.291 -    112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.292 -    0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255, 
  40.293 +    112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.294 +    0, 0, 0, 0, 0, 0, 254, 255, 255, 255, 255, 255, 255, 255,
  40.295      32, 0, 112, 12, 0, 79, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.296 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160, 
  40.297 -    12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.298 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 160,
  40.299 +    12, 0, 84, 124, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.300      0, 0, 0
  40.301  };
  40.302  unsigned char config_pal_debug_info[16] = {
  40.303 @@ -444,37 +444,37 @@ unsigned char config_pal_freq_base[8] = 
  40.304      109, 219, 182, 13, 0, 0, 0, 0
  40.305  };
  40.306  unsigned char config_pal_freq_ratios[24] = {
  40.307 -    11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4, 
  40.308 +    11, 1, 0, 0, 77, 7, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 4,
  40.309      0, 0, 0, 7, 0, 0, 0
  40.310  };
  40.311  unsigned char config_pal_halt_info[64] = {
  40.312 -    0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.313 +    0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0, 0, 0, 0, 0, 0,
  40.314      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.315 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.316 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.317      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  40.318  };
  40.319  unsigned char config_pal_perf_mon_info[136] = {
  40.320 -    12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0, 
  40.321 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.322 -    0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255, 
  40.323 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.324 -    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
  40.325 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.326 -    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0, 
  40.327 -    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.328 +    12, 47, 18, 8, 0, 0, 0, 0, 241, 255, 0, 0, 255, 7, 0, 0,
  40.329 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.330 +    0, 0, 0, 0, 0, 0, 0, 0, 241, 255, 0, 0, 223, 0, 255, 255,
  40.331 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.332 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0,
  40.333 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.334 +    0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 0, 0, 0, 0, 0, 0,
  40.335 +    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.336      0, 0, 0, 0, 0, 0, 0, 0
  40.337  };
  40.338  unsigned char config_pal_proc_get_features[104] = {
  40.339 -    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  40.340 -    0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0, 
  40.341 -    0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 
  40.342 -    231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0, 
  40.343 -    0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0, 
  40.344 +    3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  40.345 +    0, 0, 0, 0, 64, 6, 64, 49, 0, 0, 0, 0, 64, 6, 0, 0,
  40.346 +    0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0,
  40.347 +    231, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, 0, 0, 0, 0,
  40.348 +    0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 0, 0, 0, 0, 0,
  40.349      63, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0,
  40.350      0, 0, 0, 0, 0, 0, 0, 0
  40.351  };
  40.352  unsigned char config_pal_ptce_info[24] = {
  40.353 -    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 
  40.354 +    0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0,
  40.355      0, 0, 0, 0, 0, 0, 0, 0
  40.356  };
  40.357  unsigned char config_pal_register_info[64] = {
  40.358 @@ -509,7 +509,7 @@ unsigned char config_pal_vm_page_size[16
  40.359  typedef struct{
  40.360      hob_type_t type;
  40.361      void* data;
  40.362 -    unsigned long size;     
  40.363 +    unsigned long size;
  40.364  }hob_batch_t;
  40.365  
  40.366  hob_batch_t hob_batch[]={
  40.367 @@ -588,13 +588,13 @@ hob_batch_t hob_batch[]={
  40.368      {  HOB_TYPE_PAL_VM_PAGE_SIZE,
  40.369          &config_pal_vm_page_size,
  40.370          sizeof(config_pal_vm_page_size)
  40.371 -    },      
  40.372 +    },
  40.373  };
  40.374  
  40.375  static int add_pal_hob(void* hob_buf){
  40.376      int i;
  40.377      for (i=0; i<sizeof(hob_batch)/sizeof(hob_batch_t); i++){
  40.378 -        if (hob_add(hob_buf, hob_batch[i].type, 
  40.379 +        if (hob_add(hob_buf, hob_batch[i].type,
  40.380                      hob_batch[i].data,
  40.381                      hob_batch[i].size)<0)
  40.382              return -1;
  40.383 @@ -620,7 +620,7 @@ static int setup_guest(  int xc_handle,
  40.384      }
  40.385  
  40.386      /* Load guest firmware */
  40.387 -    if( xc_ia64_copy_to_domain_pages( xc_handle, dom, 
  40.388 +    if( xc_ia64_copy_to_domain_pages( xc_handle, dom,
  40.389              image, RAW_GFW_IMAGE_START_NR(dom_memsize, image_size),
  40.390              image_size>>PAGE_SHIFT)) {
  40.391          PERROR("Could not load guest firmware into domain");
  40.392 @@ -635,7 +635,7 @@ static int setup_guest(  int xc_handle,
  40.393  
  40.394      /* Retrieve special pages like io, xenstore, etc. */
  40.395      if ( xc_ia64_get_pfn_list(xc_handle, dom, page_array,
  40.396 -				RAW_IO_PAGE_START_NR(dom_memsize), 2) != 2 )
  40.397 +                              RAW_IO_PAGE_START_NR(dom_memsize), 2) != 2 )
  40.398      {
  40.399          PERROR("Could not get the page frame list");
  40.400          goto error_out;
  40.401 @@ -643,9 +643,9 @@ static int setup_guest(  int xc_handle,
  40.402  
  40.403      *store_mfn = page_array[1];
  40.404      if ((sp = (shared_iopage_t *) xc_map_foreign_range(
  40.405 -		xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  40.406 -		page_array[0])) == 0)
  40.407 -	goto error_out;
  40.408 +                    xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
  40.409 +                    page_array[0])) == 0)
  40.410 +        goto error_out;
  40.411      memset(sp, 0, PAGE_SIZE);
  40.412  
  40.413      for (i = 0; i < vcpus; i++) {
  40.414 @@ -698,14 +698,14 @@ int xc_hvm_build(int xc_handle,
  40.415  
  40.416      image_size = (image_size + PAGE_SIZE - 1) & PAGE_MASK;
  40.417  
  40.418 -    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){   
  40.419 +    if ( mlock(&st_ctxt, sizeof(st_ctxt) ) ){
  40.420          PERROR("Unable to mlock ctxt");
  40.421          return 1;
  40.422      }
  40.423  
  40.424      op.cmd = DOM0_GETDOMAININFO;
  40.425      op.u.getdomaininfo.domain = (domid_t)domid;
  40.426 -    if ( (do_dom0_op(xc_handle, &op) < 0) || 
  40.427 +    if ( (do_dom0_op(xc_handle, &op) < 0) ||
  40.428           ((uint16_t)op.u.getdomaininfo.domain != domid) ) {
  40.429          PERROR("Could not get info on domain");
  40.430          goto error_out;
    41.1 --- a/tools/libxc/xc_linux_build.c	Mon Apr 17 08:47:36 2006 -0600
    41.2 +++ b/tools/libxc/xc_linux_build.c	Tue Apr 18 09:35:40 2006 -0600
    41.3 @@ -237,7 +237,7 @@ static int setup_pg_tables(int xc_handle
    41.4          else
    41.5          {
    41.6              *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
    41.7 -            if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) && 
    41.8 +            if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
    41.9                   (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
   41.10                  *vl1e &= ~_PAGE_RW;
   41.11          }
   41.12 @@ -314,7 +314,7 @@ static int setup_pg_tables_pae(int xc_ha
   41.13              else
   41.14                  *vl2e++ = l1tab | L2_PROT;
   41.15          }
   41.16 -        
   41.17 +
   41.18          if ( shadow_mode_enabled )
   41.19          {
   41.20              *vl1e = (count << PAGE_SHIFT) | L1_PROT;
   41.21 @@ -323,12 +323,12 @@ static int setup_pg_tables_pae(int xc_ha
   41.22          {
   41.23              *vl1e = ((uint64_t)page_array[count] << PAGE_SHIFT) | L1_PROT;
   41.24              if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   41.25 -                 (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   41.26 +                 (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
   41.27                  *vl1e &= ~_PAGE_RW;
   41.28          }
   41.29          vl1e++;
   41.30      }
   41.31 -     
   41.32 +
   41.33      munmap(vl1tab, PAGE_SIZE);
   41.34      munmap(vl2tab, PAGE_SIZE);
   41.35      munmap(vl3tab, PAGE_SIZE);
   41.36 @@ -376,13 +376,13 @@ static int setup_pg_tables_64(int xc_han
   41.37          ctxt->ctrlreg[3] = pl4tab;
   41.38      else
   41.39          ctxt->ctrlreg[3] = l4tab;
   41.40 -    
   41.41 +
   41.42      for ( count = 0; count < ((v_end-dsi_v_start)>>PAGE_SHIFT); count++)
   41.43      {
   41.44          if ( !((unsigned long)vl1e & (PAGE_SIZE-1)) )
   41.45          {
   41.46              alloc_pt(l1tab, vl1tab, pl1tab);
   41.47 -            
   41.48 +
   41.49              if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
   41.50              {
   41.51                  alloc_pt(l2tab, vl2tab, pl2tab);
   41.52 @@ -410,7 +410,7 @@ static int setup_pg_tables_64(int xc_han
   41.53                  *vl2e = l1tab | L2_PROT;
   41.54              vl2e++;
   41.55          }
   41.56 -        
   41.57 +
   41.58          if ( shadow_mode_enabled )
   41.59          {
   41.60              *vl1e = (count << PAGE_SHIFT) | L1_PROT;
   41.61 @@ -419,14 +419,14 @@ static int setup_pg_tables_64(int xc_han
   41.62          {
   41.63              *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
   41.64              if ( (count >= ((vpt_start-dsi_v_start)>>PAGE_SHIFT)) &&
   41.65 -                 (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) ) 
   41.66 +                 (count <  ((vpt_end  -dsi_v_start)>>PAGE_SHIFT)) )
   41.67                  {
   41.68                      *vl1e &= ~_PAGE_RW;
   41.69                  }
   41.70          }
   41.71          vl1e++;
   41.72      }
   41.73 -     
   41.74 +
   41.75      munmap(vl1tab, PAGE_SIZE);
   41.76      munmap(vl2tab, PAGE_SIZE);
   41.77      munmap(vl3tab, PAGE_SIZE);
   41.78 @@ -509,7 +509,7 @@ static int setup_guest(int xc_handle,
   41.79             " Loaded kernel: %p->%p\n"
   41.80             " Init. ramdisk: %p->%p\n"
   41.81             " TOTAL:         %p->%p\n",
   41.82 -           _p(dsi.v_kernstart), _p(dsi.v_kernend), 
   41.83 +           _p(dsi.v_kernstart), _p(dsi.v_kernend),
   41.84             _p(vinitrd_start),   _p(vinitrd_end),
   41.85             _p(dsi.v_start),     _p(v_end));
   41.86      printf(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry));
   41.87 @@ -696,10 +696,10 @@ static int setup_guest(int xc_handle,
   41.88                                             required_features);
   41.89  
   41.90      /*
   41.91 -     * Why do we need this? The number of page-table frames depends on the 
   41.92 -     * size of the bootstrap address space. But the size of the address space 
   41.93 -     * depends on the number of page-table frames (since each one is mapped 
   41.94 -     * read-only). We have a pair of simultaneous equations in two unknowns, 
   41.95 +     * Why do we need this? The number of page-table frames depends on the
   41.96 +     * size of the bootstrap address space. But the size of the address space
   41.97 +     * depends on the number of page-table frames (since each one is mapped
   41.98 +     * read-only). We have a pair of simultaneous equations in two unknowns,
   41.99       * which we solve by exhaustive search.
  41.100       */
  41.101      v_end = round_pgup(dsi.v_end);
  41.102 @@ -731,13 +731,13 @@ static int setup_guest(int xc_handle,
  41.103          if ( dsi.pae_kernel )
  41.104          {
  41.105              /* FIXME: assumes one L2 pgtable @ 0xc0000000 */
  41.106 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >> 
  41.107 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT_PAE)-1)) >>
  41.108                     L2_PAGETABLE_SHIFT_PAE) + 2) <= nr_pt_pages )
  41.109                  break;
  41.110          }
  41.111          else
  41.112          {
  41.113 -            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
  41.114 +            if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >>
  41.115                     L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
  41.116                  break;
  41.117          }
  41.118 @@ -873,7 +873,7 @@ static int setup_guest(int xc_handle,
  41.119              count) )
  41.120          {
  41.121              fprintf(stderr,"m2p update failure p=%lx m=%lx\n",
  41.122 -                    count, page_array[count]); 
  41.123 +                    count, page_array[count]);
  41.124              munmap(physmap, PAGE_SIZE);
  41.125              goto error_out;
  41.126          }
  41.127 @@ -982,7 +982,7 @@ static int setup_guest(int xc_handle,
  41.128          start_info->mod_len      = initrd->len;
  41.129      }
  41.130      if ( cmdline != NULL )
  41.131 -    { 
  41.132 +    {
  41.133          strncpy((char *)start_info->cmd_line, cmdline, MAX_GUEST_CMDLINE);
  41.134          start_info->cmd_line[MAX_GUEST_CMDLINE-1] = '\0';
  41.135      }
  41.136 @@ -1073,14 +1073,14 @@ static int xc_linux_build_internal(int x
  41.137  #endif
  41.138  
  41.139      if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
  41.140 -    {   
  41.141 +    {
  41.142          PERROR("%s: ctxt mlock failed", __func__);
  41.143          return 1;
  41.144      }
  41.145  
  41.146      op.cmd = DOM0_GETDOMAININFO;
  41.147      op.u.getdomaininfo.domain = (domid_t)domid;
  41.148 -    if ( (xc_dom0_op(xc_handle, &op) < 0) || 
  41.149 +    if ( (xc_dom0_op(xc_handle, &op) < 0) ||
  41.150           ((uint16_t)op.u.getdomaininfo.domain != domid) )
  41.151      {
  41.152          PERROR("Could not get info on domain");
  41.153 @@ -1089,9 +1089,9 @@ static int xc_linux_build_internal(int x
  41.154  
  41.155      memset(ctxt, 0, sizeof(*ctxt));
  41.156  
  41.157 -    if ( setup_guest(xc_handle, domid, image, image_size, 
  41.158 +    if ( setup_guest(xc_handle, domid, image, image_size,
  41.159                       initrd,
  41.160 -                     nr_pages, 
  41.161 +                     nr_pages,
  41.162                       &vstartinfo_start, &vkern_entry,
  41.163                       &vstack_start, ctxt, cmdline,
  41.164                       op.u.getdomaininfo.shared_info_frame,
  41.165 @@ -1152,7 +1152,7 @@ static int xc_linux_build_internal(int x
  41.166  
  41.167      /* No LDT. */
  41.168      ctxt->ldt_ents = 0;
  41.169 -    
  41.170 +
  41.171      /* Use the default Xen-provided GDT. */
  41.172      ctxt->gdt_ents = 0;
  41.173  
  41.174 @@ -1184,7 +1184,7 @@ static int xc_linux_build_internal(int x
  41.175  
  41.176      launch_op.cmd = DOM0_SETVCPUCONTEXT;
  41.177      rc = xc_dom0_op(xc_handle, &launch_op);
  41.178 -    
  41.179 +
  41.180      return rc;
  41.181  
  41.182   error_out:
    42.1 --- a/tools/libxc/xc_linux_restore.c	Mon Apr 17 08:47:36 2006 -0600
    42.2 +++ b/tools/libxc/xc_linux_restore.c	Tue Apr 18 09:35:40 2006 -0600
    42.3 @@ -1,8 +1,8 @@
    42.4  /******************************************************************************
    42.5   * xc_linux_restore.c
    42.6 - * 
    42.7 + *
    42.8   * Restore the state of a Linux session.
    42.9 - * 
   42.10 + *
   42.11   * Copyright (c) 2003, K A Fraser.
   42.12   */
   42.13  
   42.14 @@ -13,13 +13,13 @@
   42.15  #include "xg_save_restore.h"
   42.16  
   42.17  /* max mfn of the whole machine */
   42.18 -static unsigned long max_mfn; 
   42.19 +static unsigned long max_mfn;
   42.20  
   42.21  /* virtual starting address of the hypervisor */
   42.22 -static unsigned long hvirt_start; 
   42.23 +static unsigned long hvirt_start;
   42.24  
   42.25  /* #levels of page tables used by the currrent guest */
   42.26 -static unsigned int pt_levels; 
   42.27 +static unsigned int pt_levels;
   42.28  
   42.29  /* total number of pages used by the current guest */
   42.30  static unsigned long max_pfn;
   42.31 @@ -41,84 +41,84 @@ read_exact(int fd, void *buf, size_t cou
   42.32          s = read(fd, &b[r], count - r);
   42.33          if ((s == -1) && (errno == EINTR))
   42.34              continue;
   42.35 -        if (s <= 0) { 
   42.36 +        if (s <= 0) {
   42.37              break;
   42.38 -        } 
   42.39 +        }
   42.40          r += s;
   42.41      }
   42.42  
   42.43 -    return (r == count) ? 1 : 0; 
   42.44 +    return (r == count) ? 1 : 0;
   42.45  }
   42.46  
   42.47  /*
   42.48 -** In the state file (or during transfer), all page-table pages are 
   42.49 -** converted into a 'canonical' form where references to actual mfns 
   42.50 -** are replaced with references to the corresponding pfns. 
   42.51 -** This function inverts that operation, replacing the pfn values with 
   42.52 -** the (now known) appropriate mfn values. 
   42.53 +** In the state file (or during transfer), all page-table pages are
   42.54 +** converted into a 'canonical' form where references to actual mfns
   42.55 +** are replaced with references to the corresponding pfns.
   42.56 +** This function inverts that operation, replacing the pfn values with
   42.57 +** the (now known) appropriate mfn values.
   42.58  */
   42.59 -int uncanonicalize_pagetable(unsigned long type, void *page) 
   42.60 -{ 
   42.61 -    int i, pte_last; 
   42.62 -    unsigned long pfn; 
   42.63 -    uint64_t pte; 
   42.64 +int uncanonicalize_pagetable(unsigned long type, void *page)
   42.65 +{
   42.66 +    int i, pte_last;
   42.67 +    unsigned long pfn;
   42.68 +    uint64_t pte;
   42.69  
   42.70 -    pte_last = PAGE_SIZE / ((pt_levels == 2)? 4 : 8); 
   42.71 +    pte_last = PAGE_SIZE / ((pt_levels == 2)? 4 : 8);
   42.72  
   42.73      /* Now iterate through the page table, uncanonicalizing each PTE */
   42.74 -    for(i = 0; i < pte_last; i++) { 
   42.75 -        
   42.76 -        if(pt_levels == 2) 
   42.77 -            pte = ((uint32_t *)page)[i]; 
   42.78 -        else 
   42.79 -            pte = ((uint64_t *)page)[i]; 
   42.80 +    for(i = 0; i < pte_last; i++) {
   42.81  
   42.82 -        if(pte & _PAGE_PRESENT) { 
   42.83 +        if(pt_levels == 2)
   42.84 +            pte = ((uint32_t *)page)[i];
   42.85 +        else
   42.86 +            pte = ((uint64_t *)page)[i];
   42.87 +
   42.88 +        if(pte & _PAGE_PRESENT) {
   42.89  
   42.90              pfn = (pte >> PAGE_SHIFT) & 0xffffffff;
   42.91 -            
   42.92 -            if(pfn >= max_pfn) { 
   42.93 +
   42.94 +            if(pfn >= max_pfn) {
   42.95                  /* This "page table page" is probably not one; bail. */
   42.96                  ERR("Frame number in type %lu page table is out of range: "
   42.97 -                    "i=%d pfn=0x%lx max_pfn=%lu", 
   42.98 +                    "i=%d pfn=0x%lx max_pfn=%lu",
   42.99                      type >> 28, i, pfn, max_pfn);
  42.100 -                return 0; 
  42.101 -            } 
  42.102 -            
  42.103 -            
  42.104 +                return 0;
  42.105 +            }
  42.106 +
  42.107 +
  42.108              pte &= 0xffffff0000000fffULL;
  42.109              pte |= (uint64_t)p2m[pfn] << PAGE_SHIFT;
  42.110  
  42.111 -            if(pt_levels == 2) 
  42.112 -                ((uint32_t *)page)[i] = (uint32_t)pte; 
  42.113 -            else 
  42.114 -                ((uint64_t *)page)[i] = (uint64_t)pte; 
  42.115 +            if(pt_levels == 2)
  42.116 +                ((uint32_t *)page)[i] = (uint32_t)pte;
  42.117 +            else
  42.118 +                ((uint64_t *)page)[i] = (uint64_t)pte;
  42.119  
  42.120 -        
  42.121 +
  42.122  
  42.123          }
  42.124      }
  42.125 -    
  42.126 -    return 1; 
  42.127 +
  42.128 +    return 1;
  42.129  }
  42.130  
  42.131 -int xc_linux_restore(int xc_handle, int io_fd, 
  42.132 -                     uint32_t dom, unsigned long nr_pfns, 
  42.133 +int xc_linux_restore(int xc_handle, int io_fd,
  42.134 +                     uint32_t dom, unsigned long nr_pfns,
  42.135                       unsigned int store_evtchn, unsigned long *store_mfn,
  42.136                       unsigned int console_evtchn, unsigned long *console_mfn)
  42.137  {
  42.138      DECLARE_DOM0_OP;
  42.139      int rc = 1, i, n;
  42.140 -    unsigned long mfn, pfn; 
  42.141 +    unsigned long mfn, pfn;
  42.142      unsigned int prev_pc, this_pc;
  42.143      int verify = 0;
  42.144 -    int nraces = 0; 
  42.145 +    int nraces = 0;
  42.146  
  42.147      /* The new domain's shared-info frame number. */
  42.148      unsigned long shared_info_frame;
  42.149      unsigned char shared_info_page[PAGE_SIZE]; /* saved contents from file */
  42.150      shared_info_t *shared_info = (shared_info_t *)shared_info_page;
  42.151 -    
  42.152 +
  42.153      /* A copy of the CPU context of the guest. */
  42.154      vcpu_guest_context_t ctxt;
  42.155  
  42.156 @@ -135,7 +135,7 @@ int xc_linux_restore(int xc_handle, int 
  42.157      unsigned long *page = NULL;
  42.158  
  42.159      /* A copy of the pfn-to-mfn table frame list. */
  42.160 -    unsigned long *p2m_frame_list = NULL; 
  42.161 +    unsigned long *p2m_frame_list = NULL;
  42.162  
  42.163      /* A temporary mapping of the guest's start_info page. */
  42.164      start_info_t *start_info;
  42.165 @@ -148,17 +148,17 @@ int xc_linux_restore(int xc_handle, int 
  42.166      unsigned long buf[PAGE_SIZE/sizeof(unsigned long)];
  42.167  
  42.168      struct mmuext_op pin[MAX_PIN_BATCH];
  42.169 -    unsigned int nr_pins; 
  42.170 +    unsigned int nr_pins;
  42.171  
  42.172  
  42.173 -    max_pfn = nr_pfns; 
  42.174 +    max_pfn = nr_pfns;
  42.175  
  42.176      DPRINTF("xc_linux_restore start: max_pfn = %lx\n", max_pfn);
  42.177  
  42.178  
  42.179 -    if(!get_platform_info(xc_handle, dom, 
  42.180 +    if(!get_platform_info(xc_handle, dom,
  42.181                            &max_mfn, &hvirt_start, &pt_levels)) {
  42.182 -        ERR("Unable to get platform info."); 
  42.183 +        ERR("Unable to get platform info.");
  42.184          return 1;
  42.185      }
  42.186  
  42.187 @@ -171,20 +171,20 @@ int xc_linux_restore(int xc_handle, int 
  42.188  
  42.189  
  42.190      /* Read the saved P2M frame list */
  42.191 -    if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) { 
  42.192 +    if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
  42.193          ERR("Couldn't allocate p2m_frame_list array");
  42.194          goto out;
  42.195      }
  42.196 -    
  42.197 -    if (!read_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) { 
  42.198 +
  42.199 +    if (!read_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) {
  42.200          ERR("read p2m_frame_list failed");
  42.201          goto out;
  42.202      }
  42.203  
  42.204 -    
  42.205 +
  42.206      /* We want zeroed memory so use calloc rather than malloc. */
  42.207 -    p2m        = calloc(sizeof(unsigned long), max_pfn); 
  42.208 -    pfn_type   = calloc(sizeof(unsigned long), max_pfn);    
  42.209 +    p2m        = calloc(sizeof(unsigned long), max_pfn);
  42.210 +    pfn_type   = calloc(sizeof(unsigned long), max_pfn);
  42.211      region_mfn = calloc(sizeof(unsigned long), MAX_BATCH_SIZE);
  42.212  
  42.213      if ((p2m == NULL) || (pfn_type == NULL) || (region_mfn == NULL)) {
  42.214 @@ -192,7 +192,7 @@ int xc_linux_restore(int xc_handle, int 
  42.215          errno = ENOMEM;
  42.216          goto out;
  42.217      }
  42.218 -    
  42.219 +
  42.220      if (mlock(region_mfn, sizeof(unsigned long) * MAX_BATCH_SIZE)) {
  42.221          ERR("Could not mlock region_mfn");
  42.222          goto out;
  42.223 @@ -207,27 +207,27 @@ int xc_linux_restore(int xc_handle, int 
  42.224      }
  42.225      shared_info_frame = op.u.getdomaininfo.shared_info_frame;
  42.226  
  42.227 -    if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) { 
  42.228 +    if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
  42.229          errno = ENOMEM;
  42.230          goto out;
  42.231      }
  42.232 -    
  42.233 +
  42.234      if(xc_domain_memory_increase_reservation(
  42.235 -           xc_handle, dom, max_pfn, 0, 0, NULL) != 0) { 
  42.236 +           xc_handle, dom, max_pfn, 0, 0, NULL) != 0) {
  42.237          ERR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
  42.238          errno = ENOMEM;
  42.239          goto out;
  42.240      }
  42.241  
  42.242 -    DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn)); 
  42.243 +    DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn));
  42.244  
  42.245      /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
  42.246      if (xc_get_pfn_list(xc_handle, dom, p2m, max_pfn) != max_pfn) {
  42.247          ERR("Did not read correct number of frame numbers for new dom");
  42.248          goto out;
  42.249      }
  42.250 -    
  42.251 -    if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) { 
  42.252 +
  42.253 +    if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) {
  42.254          ERR("Could not initialise for MMU updates");
  42.255          goto out;
  42.256      }
  42.257 @@ -242,7 +242,7 @@ int xc_linux_restore(int xc_handle, int 
  42.258      prev_pc = 0;
  42.259  
  42.260      n = 0;
  42.261 -    while (1) { 
  42.262 +    while (1) {
  42.263  
  42.264          int j;
  42.265  
  42.266 @@ -253,13 +253,13 @@ int xc_linux_restore(int xc_handle, int 
  42.267              prev_pc = this_pc;
  42.268          }
  42.269  
  42.270 -        if (!read_exact(io_fd, &j, sizeof(int))) { 
  42.271 +        if (!read_exact(io_fd, &j, sizeof(int))) {
  42.272              ERR("Error when reading batch size");
  42.273              goto out;
  42.274          }
  42.275  
  42.276          PPRINTF("batch %d\n",j);
  42.277 - 
  42.278 +
  42.279          if (j == -1) {
  42.280              verify = 1;
  42.281              fprintf(stderr, "Entering page verify mode\n");
  42.282 @@ -269,27 +269,27 @@ int xc_linux_restore(int xc_handle, int 
  42.283          if (j == 0)
  42.284              break;  /* our work here is done */
  42.285  
  42.286 -        if (j > MAX_BATCH_SIZE) { 
  42.287 +        if (j > MAX_BATCH_SIZE) {
  42.288              ERR("Max batch size exceeded. Giving up.");
  42.289              goto out;
  42.290          }
  42.291 - 
  42.292 -        if (!read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long))) { 
  42.293 +
  42.294 +        if (!read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long))) {
  42.295              ERR("Error when reading region pfn types");
  42.296              goto out;
  42.297          }
  42.298  
  42.299 -        for (i = 0; i < j; i++) { 
  42.300 +        for (i = 0; i < j; i++) {
  42.301  
  42.302              if ((region_pfn_type[i] & LTAB_MASK) == XTAB)
  42.303                  region_mfn[i] = 0; /* we know map will fail, but don't care */
  42.304 -            else 
  42.305 -                region_mfn[i] = p2m[region_pfn_type[i] & ~LTAB_MASK]; 
  42.306 +            else
  42.307 +                region_mfn[i] = p2m[region_pfn_type[i] & ~LTAB_MASK];
  42.308  
  42.309          }
  42.310 - 
  42.311 +
  42.312          if (!(region_base = xc_map_foreign_batch(
  42.313 -                  xc_handle, dom, PROT_WRITE, region_mfn, j))) {  
  42.314 +                  xc_handle, dom, PROT_WRITE, region_mfn, j))) {
  42.315              ERR("map batch failed");
  42.316              goto out;
  42.317          }
  42.318 @@ -297,12 +297,12 @@ int xc_linux_restore(int xc_handle, int 
  42.319          for ( i = 0; i < j; i++ )
  42.320          {
  42.321              void *page;
  42.322 -            unsigned long pagetype; 
  42.323 +            unsigned long pagetype;
  42.324  
  42.325              pfn      = region_pfn_type[i] & ~LTAB_MASK;
  42.326 -            pagetype = region_pfn_type[i] & LTAB_MASK; 
  42.327 +            pagetype = region_pfn_type[i] & LTAB_MASK;
  42.328  
  42.329 -            if (pagetype == XTAB) 
  42.330 +            if (pagetype == XTAB)
  42.331                  /* a bogus/unmapped page: skip it */
  42.332                  continue;
  42.333  
  42.334 @@ -311,72 +311,72 @@ int xc_linux_restore(int xc_handle, int 
  42.335                  goto out;
  42.336              }
  42.337  
  42.338 -            pfn_type[pfn] = pagetype; 
  42.339 +            pfn_type[pfn] = pagetype;
  42.340  
  42.341              mfn = p2m[pfn];
  42.342  
  42.343              /* In verify mode, we use a copy; otherwise we work in place */
  42.344 -            page = verify ? (void *)buf : (region_base + i*PAGE_SIZE); 
  42.345 +            page = verify ? (void *)buf : (region_base + i*PAGE_SIZE);
  42.346  
  42.347 -            if (!read_exact(io_fd, page, PAGE_SIZE)) { 
  42.348 +            if (!read_exact(io_fd, page, PAGE_SIZE)) {
  42.349                  ERR("Error when reading page (type was %lx)", pagetype);
  42.350                  goto out;
  42.351              }
  42.352  
  42.353 -            pagetype &= LTABTYPE_MASK; 
  42.354 +            pagetype &= LTABTYPE_MASK;
  42.355  
  42.356 -            if(pagetype >= L1TAB && pagetype <= L4TAB) { 
  42.357 -                
  42.358 -                /* 
  42.359 -                ** A page table page - need to 'uncanonicalize' it, i.e. 
  42.360 -                ** replace all the references to pfns with the corresponding 
  42.361 -                ** mfns for the new domain. 
  42.362 -                ** 
  42.363 -                ** On PAE we need to ensure that PGDs are in MFNs < 4G, and 
  42.364 -                ** so we may need to update the p2m after the main loop. 
  42.365 -                ** Hence we defer canonicalization of L1s until then. 
  42.366 +            if(pagetype >= L1TAB && pagetype <= L4TAB) {
  42.367 +
  42.368 +                /*
  42.369 +                ** A page table page - need to 'uncanonicalize' it, i.e.
  42.370 +                ** replace all the references to pfns with the corresponding
  42.371 +                ** mfns for the new domain.
  42.372 +                **
  42.373 +                ** On PAE we need to ensure that PGDs are in MFNs < 4G, and
  42.374 +                ** so we may need to update the p2m after the main loop.
  42.375 +                ** Hence we defer canonicalization of L1s until then.
  42.376                  */
  42.377 -                if(pt_levels != 3 || pagetype != L1TAB) { 
  42.378 +                if(pt_levels != 3 || pagetype != L1TAB) {
  42.379  
  42.380                      if(!uncanonicalize_pagetable(pagetype, page)) {
  42.381 -                        /* 
  42.382 +                        /*
  42.383                          ** Failing to uncanonicalize a page table can be ok
  42.384                          ** under live migration since the pages type may have
  42.385 -                        ** changed by now (and we'll get an update later). 
  42.386 +                        ** changed by now (and we'll get an update later).
  42.387                          */
  42.388 -                        DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n", 
  42.389 -                                pagetype >> 28, pfn, mfn); 
  42.390 -                        nraces++; 
  42.391 -                        continue; 
  42.392 +                        DPRINTF("PT L%ld race on pfn=%08lx mfn=%08lx\n",
  42.393 +                                pagetype >> 28, pfn, mfn);
  42.394 +                        nraces++;
  42.395 +                        continue;
  42.396                      }
  42.397  
  42.398 -                } 
  42.399 -                    
  42.400 -            } else if(pagetype != NOTAB) { 
  42.401 +                }
  42.402 +
  42.403 +            } else if(pagetype != NOTAB) {
  42.404  
  42.405                  ERR("Bogus page type %lx page table is out of range: "
  42.406                      "i=%d max_pfn=%lu", pagetype, i, max_pfn);
  42.407                  goto out;
  42.408  
  42.409 -            } 
  42.410 +            }
  42.411  
  42.412  
  42.413              if (verify) {
  42.414  
  42.415                  int res = memcmp(buf, (region_base + i*PAGE_SIZE), PAGE_SIZE);
  42.416  
  42.417 -                if (res) { 
  42.418 +                if (res) {
  42.419  
  42.420                      int v;
  42.421  
  42.422                      DPRINTF("************** pfn=%lx type=%lx gotcs=%08lx "
  42.423 -                            "actualcs=%08lx\n", pfn, pfn_type[pfn], 
  42.424 -                            csum_page(region_base + i*PAGE_SIZE), 
  42.425 +                            "actualcs=%08lx\n", pfn, pfn_type[pfn],
  42.426 +                            csum_page(region_base + i*PAGE_SIZE),
  42.427                              csum_page(buf));
  42.428  
  42.429                      for (v = 0; v < 4; v++) {
  42.430 -                        
  42.431 -                        unsigned long *p = (unsigned long *) 
  42.432 +
  42.433 +                        unsigned long *p = (unsigned long *)
  42.434                              (region_base + i*PAGE_SIZE);
  42.435                          if (buf[v] != p[v])
  42.436                              DPRINTF("    %d: %08lx %08lx\n", v, buf[v], p[v]);
  42.437 @@ -384,8 +384,8 @@ int xc_linux_restore(int xc_handle, int 
  42.438                  }
  42.439              }
  42.440  
  42.441 -            if (xc_add_mmu_update(xc_handle, mmu, 
  42.442 -                                  (((unsigned long long)mfn) << PAGE_SHIFT) 
  42.443 +            if (xc_add_mmu_update(xc_handle, mmu,
  42.444 +                                  (((unsigned long long)mfn) << PAGE_SHIFT)
  42.445                                    | MMU_MACHPHYS_UPDATE, pfn)) {
  42.446                  ERR("failed machpys update mfn=%lx pfn=%lx", mfn, pfn);
  42.447                  goto out;
  42.448 @@ -398,149 +398,149 @@ int xc_linux_restore(int xc_handle, int 
  42.449  
  42.450      DPRINTF("Received all pages (%d races)\n", nraces);
  42.451  
  42.452 -    if(pt_levels == 3) { 
  42.453 +    if(pt_levels == 3) {
  42.454  
  42.455 -        /* 
  42.456 -        ** XXX SMH on PAE we need to ensure PGDs are in MFNs < 4G. This 
  42.457 +        /*
  42.458 +        ** XXX SMH on PAE we need to ensure PGDs are in MFNs < 4G. This
  42.459          ** is a little awkward and involves (a) finding all such PGDs and
  42.460 -        ** replacing them with 'lowmem' versions; (b) upating the p2m[] 
  42.461 +        ** replacing them with 'lowmem' versions; (b) upating the p2m[]
  42.462          ** with the new info; and (c) canonicalizing all the L1s using the
  42.463 -        ** (potentially updated) p2m[]. 
  42.464 -        ** 
  42.465 +        ** (potentially updated) p2m[].
  42.466 +        **
  42.467          ** This is relatively slow (and currently involves two passes through
  42.468          ** the pfn_type[] array), but at least seems to be correct. May wish
  42.469 -        ** to consider more complex approaches to optimize this later. 
  42.470 +        ** to consider more complex approaches to optimize this later.
  42.471          */
  42.472  
  42.473 -        int j, k; 
  42.474 +        int j, k;
  42.475  
  42.476          /* First pass: find all L3TABs current in > 4G mfns and get new mfns */
  42.477          for (i = 0; i < max_pfn; i++) {
  42.478 -            
  42.479 +
  42.480              if (((pfn_type[i] & LTABTYPE_MASK)==L3TAB) && (p2m[i]>0xfffffUL)) {
  42.481  
  42.482 -                unsigned long new_mfn; 
  42.483 -                uint64_t l3ptes[4]; 
  42.484 -                uint64_t *l3tab; 
  42.485 +                unsigned long new_mfn;
  42.486 +                uint64_t l3ptes[4];
  42.487 +                uint64_t *l3tab;
  42.488  
  42.489                  l3tab = (uint64_t *)
  42.490 -                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
  42.491 -                                         PROT_READ, p2m[i]); 
  42.492 +                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  42.493 +                                         PROT_READ, p2m[i]);
  42.494  
  42.495 -                for(j = 0; j < 4; j++) 
  42.496 -                    l3ptes[j] = l3tab[j]; 
  42.497 -                
  42.498 -                munmap(l3tab, PAGE_SIZE); 
  42.499 +                for(j = 0; j < 4; j++)
  42.500 +                    l3ptes[j] = l3tab[j];
  42.501 +
  42.502 +                munmap(l3tab, PAGE_SIZE);
  42.503  
  42.504                  if (!(new_mfn=xc_make_page_below_4G(xc_handle, dom, p2m[i]))) {
  42.505                      ERR("Couldn't get a page below 4GB :-(");
  42.506                      goto out;
  42.507                  }
  42.508 -                
  42.509 +
  42.510                  p2m[i] = new_mfn;
  42.511 -                if (xc_add_mmu_update(xc_handle, mmu, 
  42.512 -                                      (((unsigned long long)new_mfn) 
  42.513 -                                       << PAGE_SHIFT) | 
  42.514 +                if (xc_add_mmu_update(xc_handle, mmu,
  42.515 +                                      (((unsigned long long)new_mfn)
  42.516 +                                       << PAGE_SHIFT) |
  42.517                                        MMU_MACHPHYS_UPDATE, i)) {
  42.518                      ERR("Couldn't m2p on PAE root pgdir");
  42.519                      goto out;
  42.520                  }
  42.521 -                
  42.522 +
  42.523                  l3tab = (uint64_t *)
  42.524 -                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
  42.525 -                                         PROT_READ | PROT_WRITE, p2m[i]); 
  42.526 -                
  42.527 -                for(j = 0; j < 4; j++) 
  42.528 -                    l3tab[j] = l3ptes[j]; 
  42.529 -                
  42.530 -                munmap(l3tab, PAGE_SIZE); 
  42.531 -                
  42.532 +                    xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  42.533 +                                         PROT_READ | PROT_WRITE, p2m[i]);
  42.534 +
  42.535 +                for(j = 0; j < 4; j++)
  42.536 +                    l3tab[j] = l3ptes[j];
  42.537 +
  42.538 +                munmap(l3tab, PAGE_SIZE);
  42.539 +
  42.540              }
  42.541          }
  42.542  
  42.543          /* Second pass: find all L1TABs and uncanonicalize them */
  42.544 -        j = 0; 
  42.545 +        j = 0;
  42.546  
  42.547 -        for(i = 0; i < max_pfn; i++) { 
  42.548 -            
  42.549 -            if (((pfn_type[i] & LTABTYPE_MASK)==L1TAB)) { 
  42.550 -                region_mfn[j] = p2m[i]; 
  42.551 -                j++; 
  42.552 +        for(i = 0; i < max_pfn; i++) {
  42.553 +
  42.554 +            if (((pfn_type[i] & LTABTYPE_MASK)==L1TAB)) {
  42.555 +                region_mfn[j] = p2m[i];
  42.556 +                j++;
  42.557              }
  42.558  
  42.559 -            if(i == (max_pfn-1) || j == MAX_BATCH_SIZE) { 
  42.560 +            if(i == (max_pfn-1) || j == MAX_BATCH_SIZE) {
  42.561  
  42.562                  if (!(region_base = xc_map_foreign_batch(
  42.563 -                          xc_handle, dom, PROT_READ | PROT_WRITE, 
  42.564 -                          region_mfn, j))) {  
  42.565 +                          xc_handle, dom, PROT_READ | PROT_WRITE,
  42.566 +                          region_mfn, j))) {
  42.567                      ERR("map batch failed");
  42.568                      goto out;
  42.569                  }
  42.570  
  42.571                  for(k = 0; k < j; k++) {
  42.572 -                    if(!uncanonicalize_pagetable(L1TAB, 
  42.573 +                    if(!uncanonicalize_pagetable(L1TAB,
  42.574                                                   region_base + k*PAGE_SIZE)) {
  42.575 -                        ERR("failed uncanonicalize pt!"); 
  42.576 -                        goto out; 
  42.577 -                    } 
  42.578 +                        ERR("failed uncanonicalize pt!");
  42.579 +                        goto out;
  42.580 +                    }
  42.581                  }
  42.582 -                
  42.583 -                munmap(region_base, j*PAGE_SIZE); 
  42.584 -                j = 0; 
  42.585 +
  42.586 +                munmap(region_base, j*PAGE_SIZE);
  42.587 +                j = 0;
  42.588              }
  42.589          }
  42.590  
  42.591      }
  42.592  
  42.593  
  42.594 -    if (xc_finish_mmu_updates(xc_handle, mmu)) { 
  42.595 -        ERR("Error doing finish_mmu_updates()"); 
  42.596 +    if (xc_finish_mmu_updates(xc_handle, mmu)) {
  42.597 +        ERR("Error doing finish_mmu_updates()");
  42.598          goto out;
  42.599 -    } 
  42.600 +    }
  42.601  
  42.602  
  42.603      /*
  42.604       * Pin page tables. Do this after writing to them as otherwise Xen
  42.605       * will barf when doing the type-checking.
  42.606       */
  42.607 -    nr_pins = 0; 
  42.608 +    nr_pins = 0;
  42.609      for (i = 0; i < max_pfn; i++) {
  42.610  
  42.611          if (i == (max_pfn-1) || nr_pins == MAX_PIN_BATCH) {
  42.612 -            if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) { 
  42.613 -                ERR("Failed to pin batch of %d page tables", nr_pins); 
  42.614 +            if (xc_mmuext_op(xc_handle, pin, nr_pins, dom) < 0) {
  42.615 +                ERR("Failed to pin batch of %d page tables", nr_pins);
  42.616                  goto out;
  42.617 -            } 
  42.618 +            }
  42.619              nr_pins = 0;
  42.620          }
  42.621  
  42.622          if ( (pfn_type[i] & LPINTAB) == 0 )
  42.623              continue;
  42.624  
  42.625 -        switch(pfn_type[i]) { 
  42.626 +        switch(pfn_type[i]) {
  42.627  
  42.628 -        case (L1TAB|LPINTAB): 
  42.629 +        case (L1TAB|LPINTAB):
  42.630              pin[nr_pins].cmd = MMUEXT_PIN_L1_TABLE;
  42.631 -            break; 
  42.632 -            
  42.633 -        case (L2TAB|LPINTAB): 
  42.634 +            break;
  42.635 +
  42.636 +        case (L2TAB|LPINTAB):
  42.637              pin[nr_pins].cmd = MMUEXT_PIN_L2_TABLE;
  42.638 -            break; 
  42.639 -            
  42.640 -        case (L3TAB|LPINTAB): 
  42.641 +            break;
  42.642 +
  42.643 +        case (L3TAB|LPINTAB):
  42.644              pin[nr_pins].cmd = MMUEXT_PIN_L3_TABLE;
  42.645 -            break; 
  42.646 +            break;
  42.647  
  42.648          case (L4TAB|LPINTAB):
  42.649              pin[nr_pins].cmd = MMUEXT_PIN_L4_TABLE;
  42.650 -            break; 
  42.651 -            
  42.652 -        default: 
  42.653 -            continue; 
  42.654 +            break;
  42.655 +
  42.656 +        default:
  42.657 +            continue;
  42.658          }
  42.659  
  42.660          pin[nr_pins].arg1.mfn = p2m[i];
  42.661 -        nr_pins++; 
  42.662 +        nr_pins++;
  42.663  
  42.664      }
  42.665  
  42.666 @@ -553,17 +553,17 @@ int xc_linux_restore(int xc_handle, int 
  42.667          unsigned long *pfntab;
  42.668          int rc;
  42.669  
  42.670 -        if (!read_exact(io_fd, &count, sizeof(count))) { 
  42.671 +        if (!read_exact(io_fd, &count, sizeof(count))) {
  42.672              ERR("Error when reading pfn count");
  42.673              goto out;
  42.674          }
  42.675  
  42.676 -        if(!(pfntab = malloc(sizeof(unsigned long) * count))) { 
  42.677 +        if(!(pfntab = malloc(sizeof(unsigned long) * count))) {
  42.678              ERR("Out of memory");
  42.679              goto out;
  42.680          }
  42.681 -        
  42.682 -        if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) { 
  42.683 +
  42.684 +        if (!read_exact(io_fd, pfntab, sizeof(unsigned long)*count)) {
  42.685              ERR("Error when reading pfntab");
  42.686              goto out;
  42.687          }
  42.688 @@ -572,14 +572,14 @@ int xc_linux_restore(int xc_handle, int 
  42.689  
  42.690              unsigned long pfn = pfntab[i];
  42.691  
  42.692 -            if(pfn > max_pfn) 
  42.693 +            if(pfn > max_pfn)
  42.694                  /* shouldn't happen - continue optimistically */
  42.695 -                continue; 
  42.696 +                continue;
  42.697  
  42.698 -            pfntab[i] = p2m[pfn];   
  42.699 -            p2m[pfn]  = INVALID_P2M_ENTRY; // not in pseudo-physical map 
  42.700 +            pfntab[i] = p2m[pfn];
  42.701 +            p2m[pfn]  = INVALID_P2M_ENTRY; // not in pseudo-physical map
  42.702          }
  42.703 -        
  42.704 +
  42.705          if (count > 0) {
  42.706  
  42.707              struct xen_memory_reservation reservation = {
  42.708 @@ -590,16 +590,16 @@ int xc_linux_restore(int xc_handle, int 
  42.709              };
  42.710  
  42.711              if ((rc = xc_memory_op(xc_handle, XENMEM_decrease_reservation,
  42.712 -                                   &reservation)) != count) { 
  42.713 +                                   &reservation)) != count) {
  42.714                  ERR("Could not decrease reservation : %d", rc);
  42.715                  goto out;
  42.716              } else
  42.717                  DPRINTF("Decreased reservation by %d pages\n", count);
  42.718 -        } 
  42.719 +        }
  42.720      }
  42.721  
  42.722 -    if (!read_exact(io_fd, &ctxt, sizeof(ctxt)) || 
  42.723 -        !read_exact(io_fd, shared_info_page, PAGE_SIZE)) { 
  42.724 +    if (!read_exact(io_fd, &ctxt, sizeof(ctxt)) ||
  42.725 +        !read_exact(io_fd, shared_info_page, PAGE_SIZE)) {
  42.726          ERR("Error when reading ctxt or shared info page");
  42.727          goto out;
  42.728      }
  42.729 @@ -642,15 +642,15 @@ int xc_linux_restore(int xc_handle, int 
  42.730  
  42.731      if (pfn >= max_pfn) {
  42.732          ERR("PT base is bad: pfn=%lu max_pfn=%lu type=%08lx",
  42.733 -            pfn, max_pfn, pfn_type[pfn]); 
  42.734 +            pfn, max_pfn, pfn_type[pfn]);
  42.735          goto out;
  42.736      }
  42.737  
  42.738 -    if ( (pfn_type[pfn] & LTABTYPE_MASK) != 
  42.739 +    if ( (pfn_type[pfn] & LTABTYPE_MASK) !=
  42.740           ((unsigned long)pt_levels<<LTAB_SHIFT) ) {
  42.741          ERR("PT base is bad. pfn=%lu nr=%lu type=%08lx %08lx",
  42.742 -            pfn, max_pfn, pfn_type[pfn], 
  42.743 -            (unsigned long)pt_levels<<LTAB_SHIFT); 
  42.744 +            pfn, max_pfn, pfn_type[pfn],
  42.745 +            (unsigned long)pt_levels<<LTAB_SHIFT);
  42.746          goto out;
  42.747      }
  42.748  
  42.749 @@ -667,7 +667,7 @@ int xc_linux_restore(int xc_handle, int 
  42.750          xc_handle, dom, PAGE_SIZE, PROT_WRITE, shared_info_frame);
  42.751      memcpy(page, shared_info, sizeof(shared_info_t));
  42.752      munmap(page, PAGE_SIZE);
  42.753 -    
  42.754 +
  42.755      /* Uncanonicalise the pfn-to-mfn table frame-number list. */
  42.756      for (i = 0; i < P2M_FL_ENTRIES; i++) {
  42.757          pfn = p2m_frame_list[i];
  42.758 @@ -678,16 +678,16 @@ int xc_linux_restore(int xc_handle, int 
  42.759  
  42.760          p2m_frame_list[i] = p2m[pfn];
  42.761      }
  42.762 -    
  42.763 +
  42.764      /* Copy the P2M we've constructed to the 'live' P2M */
  42.765 -    if (!(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE, 
  42.766 +    if (!(live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_WRITE,
  42.767                                            p2m_frame_list, P2M_FL_ENTRIES))) {
  42.768          ERR("Couldn't map p2m table");
  42.769          goto out;
  42.770      }
  42.771  
  42.772 -    memcpy(live_p2m, p2m, P2M_SIZE); 
  42.773 -    munmap(live_p2m, P2M_SIZE); 
  42.774 +    memcpy(live_p2m, p2m, P2M_SIZE);
  42.775 +    munmap(live_p2m, P2M_SIZE);
  42.776  
  42.777      /*
  42.778       * Safety checking of saved context:
    43.1 --- a/tools/libxc/xc_linux_save.c	Mon Apr 17 08:47:36 2006 -0600
    43.2 +++ b/tools/libxc/xc_linux_save.c	Tue Apr 18 09:35:40 2006 -0600
    43.3 @@ -1,8 +1,8 @@
    43.4  /******************************************************************************
    43.5   * xc_linux_save.c
    43.6 - * 
    43.7 + *
    43.8   * Save the state of a running Linux session.
    43.9 - * 
   43.10 + *
   43.11   * Copyright (c) 2003, K A Fraser.
   43.12   */
   43.13  
   43.14 @@ -17,23 +17,23 @@
   43.15  
   43.16  /*
   43.17  ** Default values for important tuning parameters. Can override by passing
   43.18 -** non-zero replacement values to xc_linux_save().  
   43.19 +** non-zero replacement values to xc_linux_save().
   43.20  **
   43.21 -** XXX SMH: should consider if want to be able to override MAX_MBIT_RATE too. 
   43.22 -** 
   43.23 +** XXX SMH: should consider if want to be able to override MAX_MBIT_RATE too.
   43.24 +**
   43.25  */
   43.26 -#define DEF_MAX_ITERS   29   /* limit us to 30 times round loop   */ 
   43.27 +#define DEF_MAX_ITERS   29   /* limit us to 30 times round loop   */
   43.28  #define DEF_MAX_FACTOR   3   /* never send more than 3x nr_pfns   */
   43.29  
   43.30  
   43.31  /* max mfn of the whole machine */
   43.32 -static unsigned long max_mfn; 
   43.33 +static unsigned long max_mfn;
   43.34  
   43.35  /* virtual starting address of the hypervisor */
   43.36 -static unsigned long hvirt_start; 
   43.37 +static unsigned long hvirt_start;
   43.38  
   43.39  /* #levels of page tables used by the currrent guest */
   43.40 -static unsigned int pt_levels; 
   43.41 +static unsigned int pt_levels;
   43.42  
   43.43  /* total number of pages used by the current guest */
   43.44  static unsigned long max_pfn;
   43.45 @@ -56,8 +56,8 @@ static unsigned long *live_m2p = NULL;
   43.46  (((_mfn) < (max_mfn)) &&                        \
   43.47   ((mfn_to_pfn(_mfn) < (max_pfn)) &&               \
   43.48    (live_p2m[mfn_to_pfn(_mfn)] == (_mfn))))
   43.49 -    
   43.50 - 
   43.51 +
   43.52 +
   43.53  /* Returns TRUE if MFN is successfully converted to a PFN. */
   43.54  #define translate_mfn_to_pfn(_pmfn)                             \
   43.55  ({                                                              \
   43.56 @@ -70,12 +70,12 @@ static unsigned long *live_m2p = NULL;
   43.57      _res;                                                       \
   43.58  })
   43.59  
   43.60 -/* 
   43.61 -** During (live) save/migrate, we maintain a number of bitmaps to track 
   43.62 -** which pages we have to send, to fixup, and to skip. 
   43.63 +/*
   43.64 +** During (live) save/migrate, we maintain a number of bitmaps to track
   43.65 +** which pages we have to send, to fixup, and to skip.
   43.66  */
   43.67  
   43.68 -#define BITS_PER_LONG (sizeof(unsigned long) * 8) 
   43.69 +#define BITS_PER_LONG (sizeof(unsigned long) * 8)
   43.70  #define BITMAP_SIZE   ((max_pfn + BITS_PER_LONG - 1) / 8)
   43.71  
   43.72  #define BITMAP_ENTRY(_nr,_bmap) \
   43.73 @@ -85,17 +85,17 @@ static unsigned long *live_m2p = NULL;
   43.74  
   43.75  static inline int test_bit (int nr, volatile void * addr)
   43.76  {
   43.77 -    return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1; 
   43.78 +    return (BITMAP_ENTRY(nr, addr) >> BITMAP_SHIFT(nr)) & 1;
   43.79  }
   43.80  
   43.81  static inline void clear_bit (int nr, volatile void * addr)
   43.82  {
   43.83 -    BITMAP_ENTRY(nr, addr) &= ~(1 << BITMAP_SHIFT(nr)); 
   43.84 +    BITMAP_ENTRY(nr, addr) &= ~(1 << BITMAP_SHIFT(nr));
   43.85  }
   43.86  
   43.87  static inline void set_bit ( int nr, volatile void * addr)
   43.88  {
   43.89 -    BITMAP_ENTRY(nr, addr) |= (1 << BITMAP_SHIFT(nr)); 
   43.90 +    BITMAP_ENTRY(nr, addr) |= (1 << BITMAP_SHIFT(nr));
   43.91  }
   43.92  
   43.93  /* Returns the hamming weight (i.e. the number of bits set) in a N-bit word */
   43.94 @@ -122,7 +122,7 @@ static inline int permute( int i, int nr
   43.95  {
   43.96      /* Need a simple permutation function so that we scan pages in a
   43.97         pseudo random order, enabling us to get a better estimate of
   43.98 -       the domain's page dirtying rate as we go (there are often 
   43.99 +       the domain's page dirtying rate as we go (there are often
  43.100         contiguous ranges of pfns that have similar behaviour, and we
  43.101         want to mix them up. */
  43.102  
  43.103 @@ -130,21 +130,21 @@ static inline int permute( int i, int nr
  43.104      /* 512MB domain, 128k pages, order 17 */
  43.105  
  43.106      /*
  43.107 -      QPONMLKJIHGFEDCBA  
  43.108 -             QPONMLKJIH  
  43.109 -      GFEDCBA  
  43.110 +      QPONMLKJIHGFEDCBA
  43.111 +             QPONMLKJIH
  43.112 +      GFEDCBA
  43.113       */
  43.114 -    
  43.115 +
  43.116      /*
  43.117 -      QPONMLKJIHGFEDCBA  
  43.118 -                  EDCBA  
  43.119 +      QPONMLKJIHGFEDCBA
  43.120 +                  EDCBA
  43.121               QPONM
  43.122        LKJIHGF
  43.123        */
  43.124  
  43.125      do { i = ((i>>(order_nr-10)) | ( i<<10 ) ) & ((1<<order_nr)-1); }
  43.126      while ( i >= nr ); /* this won't ever loop if nr is a power of 2 */
  43.127 -    
  43.128 +
  43.129      return i;
  43.130  }
  43.131  
  43.132 @@ -165,7 +165,7 @@ static uint64_t llgettimeofday(void)
  43.133  
  43.134  static uint64_t tv_delta(struct timeval *new, struct timeval *old)
  43.135  {
  43.136 -    return ((new->tv_sec - old->tv_sec)*1000000 ) + 
  43.137 +    return ((new->tv_sec - old->tv_sec)*1000000 ) +
  43.138          (new->tv_usec - old->tv_usec);
  43.139  }
  43.140  
  43.141 @@ -175,7 +175,7 @@ static uint64_t tv_delta(struct timeval 
  43.142  
  43.143  /*
  43.144  ** We control the rate at which we transmit (or save) to minimize impact
  43.145 -** on running domains (including the target if we're doing live migrate). 
  43.146 +** on running domains (including the target if we're doing live migrate).
  43.147  */
  43.148  
  43.149  #define MAX_MBIT_RATE    500      /* maximum transmit rate for migrate */
  43.150 @@ -193,10 +193,10 @@ static uint64_t tv_delta(struct timeval 
  43.151  static int mbit_rate, ombit_rate = 0;
  43.152  
  43.153  /* Have we reached the maximum transmission rate? */
  43.154 -#define RATE_IS_MAX() (mbit_rate == MAX_MBIT_RATE) 
  43.155 +#define RATE_IS_MAX() (mbit_rate == MAX_MBIT_RATE)
  43.156  
  43.157  
  43.158 -static inline void initialize_mbit_rate() 
  43.159 +static inline void initialize_mbit_rate()
  43.160  {
  43.161      mbit_rate = START_MBIT_RATE;
  43.162  }
  43.163 @@ -213,7 +213,7 @@ static int ratewrite(int io_fd, void *bu
  43.164  
  43.165      if (START_MBIT_RATE == 0)
  43.166          return write(io_fd, buf, n);
  43.167 -    
  43.168 +
  43.169      budget -= n;
  43.170      if (budget < 0) {
  43.171          if (mbit_rate != ombit_rate) {
  43.172 @@ -253,46 +253,46 @@ static int ratewrite(int io_fd, void *bu
  43.173  
  43.174  #else /* ! ADAPTIVE SAVE */
  43.175  
  43.176 -#define RATE_IS_MAX() (0) 
  43.177 -#define ratewrite(_io_fd, _buf, _n) write((_io_fd), (_buf), (_n)) 
  43.178 -#define initialize_mbit_rate() 
  43.179 +#define RATE_IS_MAX() (0)
  43.180 +#define ratewrite(_io_fd, _buf, _n) write((_io_fd), (_buf), (_n))
  43.181 +#define initialize_mbit_rate()
  43.182  
  43.183  #endif
  43.184  
  43.185  
  43.186  static inline ssize_t write_exact(int fd, void *buf, size_t count)
  43.187  {
  43.188 -    if(write(fd, buf, count) != count) 
  43.189 -        return 0; 
  43.190 -    return 1; 
  43.191 -} 
  43.192 +    if(write(fd, buf, count) != count)
  43.193 +        return 0;
  43.194 +    return 1;
  43.195 +}
  43.196  
  43.197  
  43.198  
  43.199 -static int print_stats(int xc_handle, uint32_t domid, int pages_sent, 
  43.200 +static int print_stats(int xc_handle, uint32_t domid, int pages_sent,
  43.201                         xc_shadow_control_stats_t *stats, int print)
  43.202  {
  43.203      static struct timeval wall_last;
  43.204      static long long      d0_cpu_last;
  43.205      static long long      d1_cpu_last;
  43.206 -    
  43.207 +
  43.208      struct timeval        wall_now;
  43.209      long long             wall_delta;
  43.210      long long             d0_cpu_now, d0_cpu_delta;
  43.211      long long             d1_cpu_now, d1_cpu_delta;
  43.212 -    
  43.213 +
  43.214      gettimeofday(&wall_now, NULL);
  43.215 -    
  43.216 +
  43.217      d0_cpu_now = xc_domain_get_cpu_usage(xc_handle, 0, /* FIXME */ 0)/1000;
  43.218      d1_cpu_now = xc_domain_get_cpu_usage(xc_handle, domid, /* FIXME */ 0)/1000;
  43.219  
  43.220 -    if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) ) 
  43.221 +    if ( (d0_cpu_now == -1) || (d1_cpu_now == -1) )
  43.222          fprintf(stderr, "ARRHHH!!\n");
  43.223 -    
  43.224 +
  43.225      wall_delta = tv_delta(&wall_now,&wall_last)/1000;
  43.226 -    
  43.227 +
  43.228      if (wall_delta == 0) wall_delta = 1;
  43.229 -    
  43.230 +
  43.231      d0_cpu_delta = (d0_cpu_now - d0_cpu_last)/1000;
  43.232      d1_cpu_delta = (d1_cpu_now - d1_cpu_last)/1000;
  43.233  
  43.234 @@ -300,14 +300,14 @@ static int print_stats(int xc_handle, ui
  43.235          fprintf(stderr,
  43.236                  "delta %lldms, dom0 %d%%, target %d%%, sent %dMb/s, "
  43.237                  "dirtied %dMb/s %" PRId32 " pages\n",
  43.238 -                wall_delta, 
  43.239 +                wall_delta,
  43.240                  (int)((d0_cpu_delta*100)/wall_delta),
  43.241                  (int)((d1_cpu_delta*100)/wall_delta),
  43.242                  (int)((pages_sent*PAGE_SIZE)/(wall_delta*(1000/8))),
  43.243                  (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))),
  43.244                  stats->dirty_count);
  43.245  
  43.246 -#ifdef ADAPTIVE_SAVE    
  43.247 +#ifdef ADAPTIVE_SAVE
  43.248      if (((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8))) > mbit_rate) {
  43.249          mbit_rate = (int)((stats->dirty_count*PAGE_SIZE)/(wall_delta*(1000/8)))
  43.250              + 50;
  43.251 @@ -315,16 +315,16 @@ static int print_stats(int xc_handle, ui
  43.252              mbit_rate = MAX_MBIT_RATE;
  43.253      }
  43.254  #endif
  43.255 -    
  43.256 +
  43.257      d0_cpu_last = d0_cpu_now;
  43.258      d1_cpu_last = d1_cpu_now;
  43.259 -    wall_last   = wall_now; 
  43.260 +    wall_last   = wall_now;
  43.261  
  43.262      return 0;
  43.263  }
  43.264  
  43.265  
  43.266 -static int analysis_phase(int xc_handle, uint32_t domid, int max_pfn, 
  43.267 +static int analysis_phase(int xc_handle, uint32_t domid, int max_pfn,
  43.268                            unsigned long *arr, int runs)
  43.269  {
  43.270      long long start, now;
  43.271 @@ -335,24 +335,24 @@ static int analysis_phase(int xc_handle,
  43.272  
  43.273      for (j = 0; j < runs; j++) {
  43.274          int i;
  43.275 -        
  43.276 +
  43.277          xc_shadow_control(xc_handle, domid, DOM0_SHADOW_CONTROL_OP_CLEAN,
  43.278                            arr, max_pfn, NULL);
  43.279          fprintf(stderr, "#Flush\n");
  43.280 -        for ( i = 0; i < 40; i++ ) {     
  43.281 -            usleep(50000);     
  43.282 +        for ( i = 0; i < 40; i++ ) {
  43.283 +            usleep(50000);
  43.284              now = llgettimeofday();
  43.285              xc_shadow_control(xc_handle, domid, DOM0_SHADOW_CONTROL_OP_PEEK,
  43.286                                NULL, 0, &stats);
  43.287 -            
  43.288 +
  43.289              fprintf(stderr, "now= %lld faults= %" PRId32 " dirty= %" PRId32
  43.290 -                    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n", 
  43.291 -                    ((now-start)+500)/1000, 
  43.292 +                    " dirty_net= %" PRId32 " dirty_block= %" PRId32"\n",
  43.293 +                    ((now-start)+500)/1000,
  43.294                      stats.fault_count, stats.dirty_count,
  43.295                      stats.dirty_net_count, stats.dirty_block_count);
  43.296          }
  43.297      }
  43.298 -    
  43.299 +
  43.300      return -1;
  43.301  }
  43.302  
  43.303 @@ -375,7 +375,7 @@ static int suspend_and_state(int (*suspe
  43.304          return -1;
  43.305      }
  43.306  
  43.307 -    if ( xc_vcpu_getcontext(xc_handle, dom, 0 /* XXX */, ctxt)) 
  43.308 +    if ( xc_vcpu_getcontext(xc_handle, dom, 0 /* XXX */, ctxt))
  43.309          ERR("Could not get vcpu context");
  43.310  
  43.311  
  43.312 @@ -383,22 +383,22 @@ static int suspend_and_state(int (*suspe
  43.313          return 0; // success
  43.314  
  43.315      if (info->paused) {
  43.316 -        // try unpausing domain, wait, and retest 
  43.317 +        // try unpausing domain, wait, and retest
  43.318          xc_domain_unpause( xc_handle, dom );
  43.319 -        
  43.320 +
  43.321          ERR("Domain was paused. Wait and re-test.");
  43.322          usleep(10000);  // 10ms
  43.323 -        
  43.324 +
  43.325          goto retry;
  43.326      }
  43.327  
  43.328  
  43.329      if( ++i < 100 ) {
  43.330          ERR("Retry suspend domain.");
  43.331 -        usleep(10000);  // 10ms 
  43.332 +        usleep(10000);  // 10ms
  43.333          goto retry;
  43.334      }
  43.335 -    
  43.336 +
  43.337      ERR("Unable to suspend domain.");
  43.338  
  43.339      return -1;
  43.340 @@ -406,173 +406,173 @@ static int suspend_and_state(int (*suspe
  43.341  
  43.342  
  43.343  /*
  43.344 -** During transfer (or in the state file), all page-table pages must be  
  43.345 -** converted into a 'canonical' form where references to actual mfns 
  43.346 -** are replaced with references to the corresponding pfns. 
  43.347 +** During transfer (or in the state file), all page-table pages must be
  43.348 +** converted into a 'canonical' form where references to actual mfns
  43.349 +** are replaced with references to the corresponding pfns.
  43.350  **
  43.351 -** This function performs the appropriate conversion, taking into account 
  43.352 -** which entries do not require canonicalization (in particular, those 
  43.353 -** entries which map the virtual address reserved for the hypervisor). 
  43.354 +** This function performs the appropriate conversion, taking into account
  43.355 +** which entries do not require canonicalization (in particular, those
  43.356 +** entries which map the virtual address reserved for the hypervisor).
  43.357  */
  43.358 -void canonicalize_pagetable(unsigned long type, unsigned long pfn, 
  43.359 -                             const void *spage, void *dpage) 
  43.360 -{ 
  43.361 -    
  43.362 +void canonicalize_pagetable(unsigned long type, unsigned long pfn,
  43.363 +                             const void *spage, void *dpage)
  43.364 +{
  43.365 +
  43.366      int i, pte_last, xen_start, xen_end;
  43.367      uint64_t pte;
  43.368  
  43.369 -    /* 
  43.370 +    /*
  43.371      ** We need to determine which entries in this page table hold
  43.372      ** reserved hypervisor mappings. This depends on the current
  43.373 -    ** page table type as well as the number of paging levels. 
  43.374 +    ** page table type as well as the number of paging levels.
  43.375      */
  43.376 -    xen_start = xen_end = pte_last = PAGE_SIZE / ((pt_levels == 2)? 4 : 8); 
  43.377 -    
  43.378 -    if (pt_levels == 2 && type == L2TAB)
  43.379 -        xen_start = (hvirt_start >> L2_PAGETABLE_SHIFT); 
  43.380 +    xen_start = xen_end = pte_last = PAGE_SIZE / ((pt_levels == 2)? 4 : 8);
  43.381  
  43.382 -    if (pt_levels == 3 && type == L3TAB) 
  43.383 -        xen_start = L3_PAGETABLE_ENTRIES_PAE; 
  43.384 -        
  43.385 -    /* 
  43.386 -    ** in PAE only the L2 mapping the top 1GB contains Xen mappings. 
  43.387 +    if (pt_levels == 2 && type == L2TAB)
  43.388 +        xen_start = (hvirt_start >> L2_PAGETABLE_SHIFT);
  43.389 +
  43.390 +    if (pt_levels == 3 && type == L3TAB)
  43.391 +        xen_start = L3_PAGETABLE_ENTRIES_PAE;
  43.392 +
  43.393 +    /*
  43.394 +    ** in PAE only the L2 mapping the top 1GB contains Xen mappings.
  43.395      ** We can spot this by looking for the guest linear mapping which
  43.396 -    ** Xen always ensures is present in that L2. Guests must ensure 
  43.397 -    ** that this check will fail for other L2s. 
  43.398 +    ** Xen always ensures is present in that L2. Guests must ensure
  43.399 +    ** that this check will fail for other L2s.
  43.400      */
  43.401      if (pt_levels == 3 && type == L2TAB) {
  43.402  
  43.403  /* XXX index of the L2 entry in PAE mode which holds the guest LPT */
  43.404 -#define PAE_GLPT_L2ENTRY (495) 
  43.405 -        pte = ((uint64_t*)spage)[PAE_GLPT_L2ENTRY]; 
  43.406 +#define PAE_GLPT_L2ENTRY (495)
  43.407 +        pte = ((uint64_t*)spage)[PAE_GLPT_L2ENTRY];
  43.408  
  43.409          if(((pte >> PAGE_SHIFT) & 0x0fffffff) == live_p2m[pfn])
  43.410 -            xen_start = (hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff; 
  43.411 +            xen_start = (hvirt_start >> L2_PAGETABLE_SHIFT_PAE) & 0x1ff;
  43.412      }
  43.413  
  43.414 -    if (pt_levels == 4 && type == L4TAB) { 
  43.415 +    if (pt_levels == 4 && type == L4TAB) {
  43.416          /*
  43.417 -        ** XXX SMH: should compute these from hvirt_start (which we have) 
  43.418 -        ** and hvirt_end (which we don't) 
  43.419 +        ** XXX SMH: should compute these from hvirt_start (which we have)
  43.420 +        ** and hvirt_end (which we don't)
  43.421          */
  43.422 -        xen_start = 256; 
  43.423 -        xen_end   = 272; 
  43.424 +        xen_start = 256;
  43.425 +        xen_end   = 272;
  43.426      }
  43.427  
  43.428      /* Now iterate through the page table, canonicalizing each PTE */
  43.429      for (i = 0; i < pte_last; i++ ) {
  43.430  
  43.431 -        unsigned long pfn, mfn; 
  43.432 -        
  43.433 +        unsigned long pfn, mfn;
  43.434 +
  43.435          if (pt_levels == 2)
  43.436              pte = ((uint32_t*)spage)[i];
  43.437          else
  43.438              pte = ((uint64_t*)spage)[i];
  43.439 -        
  43.440 +
  43.441          if (i >= xen_start && i < xen_end)
  43.442              pte = 0;
  43.443 -        
  43.444 +
  43.445          if (pte & _PAGE_PRESENT) {
  43.446 -            
  43.447 -            mfn = (pte >> PAGE_SHIFT) & 0xfffffff;      
  43.448 +
  43.449 +            mfn = (pte >> PAGE_SHIFT) & 0xfffffff;
  43.450              if (!MFN_IS_IN_PSEUDOPHYS_MAP(mfn)) {
  43.451 -                /* This will happen if the type info is stale which 
  43.452 +                /* This will happen if the type info is stale which
  43.453                     is quite feasible under live migration */
  43.454                  DPRINTF("PT Race: [%08lx,%d] pte=%llx, mfn=%08lx\n",
  43.455 -                        type, i, (unsigned long long)pte, mfn); 
  43.456 +                        type, i, (unsigned long long)pte, mfn);
  43.457                  pfn = 0; /* zap it - we'll retransmit this page later */
  43.458 -            } else 
  43.459 +            } else
  43.460                  pfn = mfn_to_pfn(mfn);
  43.461 -            
  43.462 +
  43.463              pte &= 0xffffff0000000fffULL;
  43.464              pte |= (uint64_t)pfn << PAGE_SHIFT;
  43.465          }
  43.466 -        
  43.467 +
  43.468          if (pt_levels == 2)
  43.469              ((uint32_t*)dpage)[i] = pte;
  43.470          else
  43.471 -            ((uint64_t*)dpage)[i] = pte;		       
  43.472 -        
  43.473 -    } 
  43.474 -    
  43.475 -    return; 
  43.476 +            ((uint64_t*)dpage)[i] = pte;
  43.477 +
  43.478 +    }
  43.479 +
  43.480 +    return;
  43.481  }
  43.482  
  43.483  
  43.484  
  43.485 -static unsigned long *xc_map_m2p(int xc_handle, 
  43.486 -                                 unsigned long max_mfn, 
  43.487 -                                 int prot) 
  43.488 -{ 
  43.489 +static unsigned long *xc_map_m2p(int xc_handle,
  43.490 +                                 unsigned long max_mfn,
  43.491 +                                 int prot)
  43.492 +{
  43.493      struct xen_machphys_mfn_list xmml;
  43.494 -    privcmd_mmap_t ioctlx; 
  43.495 -    privcmd_mmap_entry_t *entries; 
  43.496 -    unsigned long m2p_chunks, m2p_size; 
  43.497 -    unsigned long *m2p; 
  43.498 -    int i, rc; 
  43.499 +    privcmd_mmap_t ioctlx;
  43.500 +    privcmd_mmap_entry_t *entries;
  43.501 +    unsigned long m2p_chunks, m2p_size;
  43.502 +    unsigned long *m2p;
  43.503 +    int i, rc;
  43.504  
  43.505 -    m2p_size   = M2P_SIZE(max_mfn); 
  43.506 -    m2p_chunks = M2P_CHUNKS(max_mfn); 
  43.507 +    m2p_size   = M2P_SIZE(max_mfn);
  43.508 +    m2p_chunks = M2P_CHUNKS(max_mfn);
  43.509  
  43.510      xmml.max_extents = m2p_chunks;
  43.511 -    if (!(xmml.extent_start = malloc(m2p_chunks * sizeof(unsigned long)))) { 
  43.512 -        ERR("failed to allocate space for m2p mfns"); 
  43.513 -        return NULL; 
  43.514 -    } 
  43.515 +    if (!(xmml.extent_start = malloc(m2p_chunks * sizeof(unsigned long)))) {
  43.516 +        ERR("failed to allocate space for m2p mfns");
  43.517 +        return NULL;
  43.518 +    }
  43.519  
  43.520      if (xc_memory_op(xc_handle, XENMEM_machphys_mfn_list, &xmml) ||
  43.521          (xmml.nr_extents != m2p_chunks)) {
  43.522 -        ERR("xc_get_m2p_mfns"); 
  43.523 +        ERR("xc_get_m2p_mfns");
  43.524          return NULL;
  43.525      }
  43.526  
  43.527 -    if ((m2p = mmap(NULL, m2p_size, prot, 
  43.528 +    if ((m2p = mmap(NULL, m2p_size, prot,
  43.529                      MAP_SHARED, xc_handle, 0)) == MAP_FAILED) {
  43.530 -        ERR("failed to mmap m2p"); 
  43.531 -        return NULL; 
  43.532 -    } 
  43.533 +        ERR("failed to mmap m2p");
  43.534 +        return NULL;
  43.535 +    }
  43.536  
  43.537 -    if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) { 
  43.538 -        ERR("failed to allocate space for mmap entries"); 
  43.539 -        return NULL; 
  43.540 -    } 
  43.541 +    if (!(entries = malloc(m2p_chunks * sizeof(privcmd_mmap_entry_t)))) {
  43.542 +        ERR("failed to allocate space for mmap entries");
  43.543 +        return NULL;
  43.544 +    }
  43.545  
  43.546      ioctlx.num   = m2p_chunks;
  43.547 -    ioctlx.dom   = DOMID_XEN; 
  43.548 -    ioctlx.entry = entries; 
  43.549 -    
  43.550 -    for (i=0; i < m2p_chunks; i++) { 
  43.551 -        entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE)); 
  43.552 +    ioctlx.dom   = DOMID_XEN;
  43.553 +    ioctlx.entry = entries;
  43.554 +
  43.555 +    for (i=0; i < m2p_chunks; i++) {
  43.556 +        entries[i].va = (unsigned long)(((void *)m2p) + (i * M2P_CHUNK_SIZE));
  43.557          entries[i].mfn = xmml.extent_start[i];
  43.558          entries[i].npages = M2P_CHUNK_SIZE >> PAGE_SHIFT;
  43.559      }
  43.560  
  43.561      if ((rc = ioctl(xc_handle, IOCTL_PRIVCMD_MMAP, &ioctlx)) < 0) {
  43.562 -        ERR("ioctl_mmap failed (rc = %d)", rc); 
  43.563 -        return NULL; 
  43.564 +        ERR("ioctl_mmap failed (rc = %d)", rc);
  43.565 +        return NULL;
  43.566      }
  43.567  
  43.568      free(xmml.extent_start);
  43.569 -    free(entries); 
  43.570 +    free(entries);
  43.571  
  43.572 -    return m2p; 
  43.573 +    return m2p;
  43.574  }
  43.575  
  43.576  
  43.577  
  43.578 -int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
  43.579 +int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
  43.580                    uint32_t max_factor, uint32_t flags, int (*suspend)(int))
  43.581  {
  43.582      xc_dominfo_t info;
  43.583  
  43.584      int rc = 1, i, j, last_iter, iter = 0;
  43.585 -    int live  = (flags & XCFLAGS_LIVE); 
  43.586 -    int debug = (flags & XCFLAGS_DEBUG); 
  43.587 +    int live  = (flags & XCFLAGS_LIVE);
  43.588 +    int debug = (flags & XCFLAGS_DEBUG);
  43.589      int sent_last_iter, skip_this_iter;
  43.590  
  43.591      /* The new domain's shared-info frame number. */
  43.592      unsigned long shared_info_frame;
  43.593 -    
  43.594 +
  43.595      /* A copy of the CPU context of the guest. */
  43.596      vcpu_guest_context_t ctxt;
  43.597  
  43.598 @@ -581,7 +581,7 @@ int xc_linux_save(int xc_handle, int io_
  43.599      unsigned long *pfn_batch = NULL;
  43.600  
  43.601      /* A temporary mapping, and a copy, of one frame of guest memory. */
  43.602 -    char page[PAGE_SIZE]; 
  43.603 +    char page[PAGE_SIZE];
  43.604  
  43.605      /* Double and single indirect references to the live P2M table */
  43.606      unsigned long *live_p2m_frame_list_list = NULL;
  43.607 @@ -597,14 +597,14 @@ int xc_linux_save(int xc_handle, int io_
  43.608      unsigned char *region_base = NULL;
  43.609  
  43.610      /* power of 2 order of max_pfn */
  43.611 -    int order_nr; 
  43.612 +    int order_nr;
  43.613  
  43.614      /* bitmap of pages:
  43.615 -       - that should be sent this iteration (unless later marked as skip); 
  43.616 +       - that should be sent this iteration (unless later marked as skip);
  43.617         - to skip this iteration because already dirty;
  43.618         - to fixup by sending at the end if not already resent; */
  43.619      unsigned long *to_send = NULL, *to_skip = NULL, *to_fix = NULL;
  43.620 -    
  43.621 +
  43.622      xc_shadow_control_stats_t stats;
  43.623  
  43.624      unsigned long needed_to_fix = 0;
  43.625 @@ -612,29 +612,29 @@ int xc_linux_save(int xc_handle, int io_
  43.626  
  43.627  
  43.628      /* If no explicit control parameters given, use defaults */
  43.629 -    if(!max_iters) 
  43.630 -        max_iters = DEF_MAX_ITERS; 
  43.631 -    if(!max_factor) 
  43.632 -        max_factor = DEF_MAX_FACTOR; 
  43.633 -    
  43.634 -    initialize_mbit_rate(); 
  43.635 +    if(!max_iters)
  43.636 +        max_iters = DEF_MAX_ITERS;
  43.637 +    if(!max_factor)
  43.638 +        max_factor = DEF_MAX_FACTOR;
  43.639  
  43.640 -    if(!get_platform_info(xc_handle, dom, 
  43.641 +    initialize_mbit_rate();
  43.642 +
  43.643 +    if(!get_platform_info(xc_handle, dom,
  43.644                            &max_mfn, &hvirt_start, &pt_levels)) {
  43.645 -        ERR("Unable to get platform info."); 
  43.646 +        ERR("Unable to get platform info.");
  43.647          return 1;
  43.648      }
  43.649  
  43.650      if (xc_domain_getinfo(xc_handle, dom, 1, &info) != 1) {
  43.651          ERR("Could not get domain info");
  43.652 -        return 1; 
  43.653 +        return 1;
  43.654      }
  43.655  
  43.656      if (mlock(&ctxt, sizeof(ctxt))) {
  43.657          ERR("Unable to mlock ctxt");
  43.658          return 1;
  43.659      }
  43.660 -    
  43.661 +
  43.662      /* Only have to worry about vcpu 0 even for SMP */
  43.663      if (xc_vcpu_getcontext(xc_handle, dom, 0, &ctxt)) {
  43.664          ERR("Could not get vcpu context");
  43.665 @@ -648,16 +648,16 @@ int xc_linux_save(int xc_handle, int io_
  43.666          ERR("Domain is not in a valid Linux guest OS state");
  43.667          goto out;
  43.668      }
  43.669 -  
  43.670 +
  43.671     /* cheesy sanity check */
  43.672      if ((info.max_memkb >> (PAGE_SHIFT - 10)) > max_mfn) {
  43.673 -        ERR("Invalid state record -- pfn count out of range: %lu", 
  43.674 -            (info.max_memkb >> (PAGE_SHIFT - 10))); 
  43.675 +        ERR("Invalid state record -- pfn count out of range: %lu",
  43.676 +            (info.max_memkb >> (PAGE_SHIFT - 10)));
  43.677          goto out;
  43.678       }
  43.679 - 
  43.680 +
  43.681      /* Map the shared info frame */
  43.682 -    if(!(live_shinfo = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, 
  43.683 +    if(!(live_shinfo = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
  43.684                                              PROT_READ, shared_info_frame))) {
  43.685          ERR("Couldn't map live_shinfo");
  43.686          goto out;
  43.687 @@ -665,8 +665,8 @@ int xc_linux_save(int xc_handle, int io_
  43.688  
  43.689      max_pfn = live_shinfo->arch.max_pfn;
  43.690  
  43.691 -    live_p2m_frame_list_list = 
  43.692 -        xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ, 
  43.693 +    live_p2m_frame_list_list =
  43.694 +        xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, PROT_READ,
  43.695                               live_shinfo->arch.pfn_to_mfn_frame_list_list);
  43.696  
  43.697      if (!live_p2m_frame_list_list) {
  43.698 @@ -674,24 +674,24 @@ int xc_linux_save(int xc_handle, int io_
  43.699          goto out;
  43.700      }
  43.701  
  43.702 -    live_p2m_frame_list = 
  43.703 +    live_p2m_frame_list =
  43.704          xc_map_foreign_batch(xc_handle, dom, PROT_READ,
  43.705                               live_p2m_frame_list_list,
  43.706 -                             P2M_FLL_ENTRIES); 
  43.707 -    
  43.708 +                             P2M_FLL_ENTRIES);
  43.709 +
  43.710      if (!live_p2m_frame_list) {
  43.711          ERR("Couldn't map p2m_frame_list");
  43.712          goto out;
  43.713      }
  43.714  
  43.715 -    /* Map all the frames of the pfn->mfn table. For migrate to succeed, 
  43.716 -       the guest must not change which frames are used for this purpose. 
  43.717 +    /* Map all the frames of the pfn->mfn table. For migrate to succeed,
  43.718 +       the guest must not change which frames are used for this purpose.
  43.719         (its not clear why it would want to change them, and we'll be OK
  43.720         from a safety POV anyhow. */
  43.721  
  43.722      live_p2m = xc_map_foreign_batch(xc_handle, dom, PROT_READ,
  43.723                                      live_p2m_frame_list,
  43.724 -                                    P2M_FL_ENTRIES); 
  43.725 +                                    P2M_FL_ENTRIES);
  43.726  
  43.727      if (!live_p2m) {
  43.728          ERR("Couldn't map p2m table");
  43.729 @@ -699,25 +699,25 @@ int xc_linux_save(int xc_handle, int io_
  43.730      }
  43.731  
  43.732      /* Setup the mfn_to_pfn table mapping */
  43.733 -    if(!(live_m2p = xc_map_m2p(xc_handle, max_mfn, PROT_READ))) { 
  43.734 -        ERR("Failed to map live M2P table"); 
  43.735 -        goto out; 
  43.736 -    } 
  43.737 +    if(!(live_m2p = xc_map_m2p(xc_handle, max_mfn, PROT_READ))) {
  43.738 +        ERR("Failed to map live M2P table");
  43.739 +        goto out;
  43.740 +    }
  43.741  
  43.742 -    
  43.743 +
  43.744      /* Get a local copy of the live_P2M_frame_list */
  43.745 -    if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) { 
  43.746 +    if(!(p2m_frame_list = malloc(P2M_FL_SIZE))) {
  43.747          ERR("Couldn't allocate p2m_frame_list array");
  43.748          goto out;
  43.749      }
  43.750 -    memcpy(p2m_frame_list, live_p2m_frame_list, P2M_FL_SIZE); 
  43.751 +    memcpy(p2m_frame_list, live_p2m_frame_list, P2M_FL_SIZE);
  43.752  
  43.753      /* Canonicalise the pfn-to-mfn table frame-number list. */
  43.754      for (i = 0; i < max_pfn; i += ulpp) {
  43.755 -        if (!translate_mfn_to_pfn(&p2m_frame_list[i/ulpp])) { 
  43.756 +        if (!translate_mfn_to_pfn(&p2m_frame_list[i/ulpp])) {
  43.757              ERR("Frame# in pfn-to-mfn frame list is not in pseudophys");
  43.758 -            ERR("entry %d: p2m_frame_list[%ld] is 0x%lx", i, i/ulpp, 
  43.759 -                p2m_frame_list[i/ulpp]); 
  43.760 +            ERR("entry %d: p2m_frame_list[%ld] is 0x%lx", i, i/ulpp,
  43.761 +                p2m_frame_list[i/ulpp]);
  43.762              goto out;
  43.763          }
  43.764      }
  43.765 @@ -725,31 +725,31 @@ int xc_linux_save(int xc_handle, int io_
  43.766      /* Domain is still running at this point */
  43.767      if (live) {
  43.768  
  43.769 -        if (xc_shadow_control(xc_handle, dom, 
  43.770 +        if (xc_shadow_control(xc_handle, dom,
  43.771                                DOM0_SHADOW_CONTROL_OP_ENABLE_LOGDIRTY,
  43.772 -                              NULL, 0, NULL ) < 0) { 
  43.773 +                              NULL, 0, NULL ) < 0) {
  43.774              ERR("Couldn't enable shadow mode");
  43.775              goto out;
  43.776          }
  43.777 -        
  43.778 +
  43.779          last_iter = 0;
  43.780 -        
  43.781 +
  43.782      } else {
  43.783 -        
  43.784 +
  43.785          /* This is a non-live suspend. Issue the call back to get the
  43.786             domain suspended */
  43.787 -        
  43.788 +
  43.789          last_iter = 1;
  43.790 -        
  43.791 +
  43.792          if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
  43.793              ERR("Domain appears not to have suspended");
  43.794              goto out;
  43.795          }
  43.796 -        
  43.797 +
  43.798      }
  43.799  
  43.800      /* pretend we sent all the pages last iteration */
  43.801 -    sent_last_iter = max_pfn; 
  43.802 +    sent_last_iter = max_pfn;
  43.803  
  43.804  
  43.805      /* calculate the power of 2 order of max_pfn, e.g.
  43.806 @@ -758,15 +758,15 @@ int xc_linux_save(int xc_handle, int io_
  43.807          continue;
  43.808  
  43.809      /* Setup to_send / to_fix and to_skip bitmaps */
  43.810 -    to_send = malloc(BITMAP_SIZE); 
  43.811 -    to_fix  = calloc(1, BITMAP_SIZE); 
  43.812 -    to_skip = malloc(BITMAP_SIZE); 
  43.813 -    
  43.814 +    to_send = malloc(BITMAP_SIZE);
  43.815 +    to_fix  = calloc(1, BITMAP_SIZE);
  43.816 +    to_skip = malloc(BITMAP_SIZE);
  43.817 +
  43.818      if (!to_send || !to_fix || !to_skip) {
  43.819          ERR("Couldn't allocate to_send array");
  43.820          goto out;
  43.821      }
  43.822 -    
  43.823 +
  43.824      memset(to_send, 0xff, BITMAP_SIZE);
  43.825  
  43.826      if (mlock(to_send, BITMAP_SIZE)) {
  43.827 @@ -779,7 +779,7 @@ int xc_linux_save(int xc_handle, int io_
  43.828          ERR("Unable to mlock to_skip");
  43.829          return 1;
  43.830      }
  43.831 -        
  43.832 +
  43.833      analysis_phase(xc_handle, dom, max_pfn, to_skip, 0);
  43.834  
  43.835      /* We want zeroed memory so use calloc rather than malloc. */
  43.836 @@ -787,7 +787,7 @@ int xc_linux_save(int xc_handle, int io_
  43.837      pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(unsigned long));
  43.838  
  43.839      if ((pfn_type == NULL) || (pfn_batch == NULL)) {
  43.840 -        ERR("failed to alloc memory for pfn_type and/or pfn_batch arrays"); 
  43.841 +        ERR("failed to alloc memory for pfn_type and/or pfn_batch arrays");
  43.842          errno = ENOMEM;
  43.843          goto out;
  43.844      }
  43.845 @@ -803,12 +803,12 @@ int xc_linux_save(int xc_handle, int io_
  43.846       */
  43.847      {
  43.848          int err=0;
  43.849 -        unsigned long mfn; 
  43.850 +        unsigned long mfn;
  43.851          for (i = 0; i < max_pfn; i++) {
  43.852  
  43.853              mfn = live_p2m[i];
  43.854 -            if((mfn != INVALID_P2M_ENTRY) && (mfn_to_pfn(mfn) != i)) { 
  43.855 -                DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i, 
  43.856 +            if((mfn != INVALID_P2M_ENTRY) && (mfn_to_pfn(mfn) != i)) {
  43.857 +                DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i,
  43.858                          mfn, mfn_to_pfn(mfn));
  43.859                  err++;
  43.860              }
  43.861 @@ -819,16 +819,16 @@ int xc_linux_save(int xc_handle, int io_
  43.862  
  43.863      /* Start writing out the saved-domain record. */
  43.864  
  43.865 -    if(!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) { 
  43.866 +    if(!write_exact(io_fd, &max_pfn, sizeof(unsigned long))) {
  43.867          ERR("write: max_pfn");
  43.868          goto out;
  43.869      }
  43.870  
  43.871 -    if(!write_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) { 
  43.872 +    if(!write_exact(io_fd, p2m_frame_list, P2M_FL_SIZE)) {
  43.873          ERR("write: p2m_frame_list");
  43.874          goto out;
  43.875      }
  43.876 -    
  43.877 +
  43.878      print_stats(xc_handle, dom, 0, &stats, 0);
  43.879  
  43.880      /* Now write out each data page, canonicalising page tables as we go... */
  43.881 @@ -853,8 +853,8 @@ int xc_linux_save(int xc_handle, int io_
  43.882                  DPRINTF("\b\b\b\b%3d%%", this_pc);
  43.883                  prev_pc = this_pc;
  43.884              }
  43.885 -            
  43.886 -            /* slightly wasteful to peek the whole array evey time, 
  43.887 +
  43.888 +            /* slightly wasteful to peek the whole array evey time,
  43.889                 but this is fast enough for the moment. */
  43.890              if (!last_iter && xc_shadow_control(
  43.891                      xc_handle, dom, DOM0_SHADOW_CONTROL_OP_PEEK,
  43.892 @@ -862,7 +862,7 @@ int xc_linux_save(int xc_handle, int io_
  43.893                  ERR("Error peeking shadow bitmap");
  43.894                  goto out;
  43.895              }
  43.896 -     
  43.897 +
  43.898  
  43.899              /* load pfn_type[] with the mfn of all the pages we're doing in
  43.900                 this batch. */
  43.901 @@ -873,11 +873,11 @@ int xc_linux_save(int xc_handle, int io_
  43.902                  if (debug) {
  43.903                      DPRINTF("%d pfn= %08lx mfn= %08lx %d  [mfn]= %08lx\n",
  43.904                              iter, (unsigned long)n, live_p2m[n],
  43.905 -                            test_bit(n, to_send), 
  43.906 +                            test_bit(n, to_send),
  43.907                              mfn_to_pfn(live_p2m[n]&0xFFFFF));
  43.908                  }
  43.909 -                
  43.910 -                if (!last_iter && test_bit(n, to_send)&& test_bit(n, to_skip)) 
  43.911 +
  43.912 +                if (!last_iter && test_bit(n, to_send)&& test_bit(n, to_skip))
  43.913                      skip_this_iter++; /* stats keeping */
  43.914  
  43.915                  if (!((test_bit(n, to_send) && !test_bit(n, to_skip)) ||
  43.916 @@ -885,13 +885,13 @@ int xc_linux_save(int xc_handle, int io_
  43.917                        (test_bit(n, to_fix)  && last_iter)))
  43.918                      continue;
  43.919  
  43.920 -                /* 
  43.921 +                /*
  43.922                  ** we get here if:
  43.923                  **  1. page is marked to_send & hasn't already been re-dirtied
  43.924                  **  2. (ignore to_skip in last iteration)
  43.925                  **  3. add in pages that still need fixup (net bufs)
  43.926                  */
  43.927 -  
  43.928 +
  43.929                  pfn_batch[batch] = n;
  43.930                  pfn_type[batch]  = live_p2m[n];
  43.931  
  43.932 @@ -914,80 +914,80 @@ int xc_linux_save(int xc_handle, int io_
  43.933                              iter,n,pfn_type[batch]);
  43.934                  }
  43.935  
  43.936 -                clear_bit(n, to_fix); 
  43.937 -                
  43.938 +                clear_bit(n, to_fix);
  43.939 +
  43.940                  batch++;
  43.941              }
  43.942 -     
  43.943 +
  43.944              if (batch == 0)
  43.945                  goto skip; /* vanishingly unlikely... */
  43.946 -      
  43.947 +
  43.948              if ((region_base = xc_map_foreign_batch(
  43.949 -                     xc_handle, dom, PROT_READ, pfn_type, batch)) == 0) { 
  43.950 +                     xc_handle, dom, PROT_READ, pfn_type, batch)) == 0) {
  43.951                  ERR("map batch failed");
  43.952                  goto out;
  43.953              }
  43.954 -     
  43.955 +
  43.956              if (xc_get_pfn_type_batch(xc_handle, dom, batch, pfn_type)) {
  43.957                  ERR("get_pfn_type_batch failed");
  43.958                  goto out;
  43.959              }
  43.960 -     
  43.961 +
  43.962              for (j = 0; j < batch; j++) {
  43.963  
  43.964                  if ((pfn_type[j] & LTAB_MASK) == XTAB) {
  43.965                      DPRINTF("type fail: page %i mfn %08lx\n", j, pfn_type[j]);
  43.966                      continue;
  43.967                  }
  43.968 -  
  43.969 -                if (debug) 
  43.970 +
  43.971 +                if (debug)
  43.972                      fprintf(stderr, "%d pfn= %08lx mfn= %08lx [mfn]= %08lx"
  43.973                              " sum= %08lx\n",
  43.974 -                            iter, 
  43.975 +                            iter,
  43.976                              (pfn_type[j] & LTAB_MASK) | pfn_batch[j],
  43.977                              pfn_type[j],
  43.978                              mfn_to_pfn(pfn_type[j]&(~LTAB_MASK)),
  43.979                              csum_page(region_base + (PAGE_SIZE*j)));
  43.980 -                
  43.981 +
  43.982                  /* canonicalise mfn->pfn */
  43.983                  pfn_type[j] = (pfn_type[j] & LTAB_MASK) | pfn_batch[j];
  43.984              }
  43.985  
  43.986 -            if(!write_exact(io_fd, &batch, sizeof(unsigned int))) { 
  43.987 +            if(!write_exact(io_fd, &batch, sizeof(unsigned int))) {
  43.988                  ERR("Error when writing to state file (2)");
  43.989                  goto out;
  43.990              }
  43.991  
  43.992 -            if(!write_exact(io_fd, pfn_type, sizeof(unsigned long)*j)) { 
  43.993 +            if(!write_exact(io_fd, pfn_type, sizeof(unsigned long)*j)) {
  43.994                  ERR("Error when writing to state file (3)");
  43.995                  goto out;
  43.996              }
  43.997 -            
  43.998 +
  43.999              /* entering this loop, pfn_type is now in pfns (Not mfns) */
 43.1000              for (j = 0; j < batch; j++) {
 43.1001 -                
 43.1002 -                unsigned long pfn      = pfn_type[j] & ~LTAB_MASK; 
 43.1003 -                unsigned long pagetype = pfn_type[j] & LTAB_MASK; 
 43.1004 -                void *spage            = (void *) region_base + (PAGE_SIZE*j); 
 43.1005 +
 43.1006 +                unsigned long pfn      = pfn_type[j] & ~LTAB_MASK;
 43.1007 +                unsigned long pagetype = pfn_type[j] & LTAB_MASK;
 43.1008 +                void *spage            = (void *) region_base + (PAGE_SIZE*j);
 43.1009  
 43.1010  
 43.1011                  /* write out pages in batch */
 43.1012                  if (pagetype == XTAB)
 43.1013                      continue;
 43.1014  
 43.1015 -                pagetype &= LTABTYPE_MASK; 
 43.1016 -                
 43.1017 +                pagetype &= LTABTYPE_MASK;
 43.1018 +
 43.1019                  if (pagetype >= L1TAB && pagetype <= L4TAB) {
 43.1020 -                    
 43.1021 +
 43.1022                      /* We have a pagetable page: need to rewrite it. */
 43.1023 -                    canonicalize_pagetable(pagetype, pfn, spage, page); 
 43.1024 -                    
 43.1025 +                    canonicalize_pagetable(pagetype, pfn, spage, page);
 43.1026 +
 43.1027                      if (ratewrite(io_fd, page, PAGE_SIZE) != PAGE_SIZE) {
 43.1028                          ERR("Error when writing to state file (4)");
 43.1029                          goto out;
 43.1030                      }
 43.1031 -                    
 43.1032 -                }  else {  
 43.1033 +
 43.1034 +                }  else {
 43.1035  
 43.1036                      /* We have a normal page: just write it directly. */
 43.1037                      if (ratewrite(io_fd, spage, PAGE_SIZE) != PAGE_SIZE) {
 43.1038 @@ -996,36 +996,36 @@ int xc_linux_save(int xc_handle, int io_
 43.1039                      }
 43.1040                  }
 43.1041              } /* end of the write out for this batch */
 43.1042 -            
 43.1043 +
 43.1044              sent_this_iter += batch;
 43.1045  
 43.1046              munmap(region_base, batch*PAGE_SIZE);
 43.1047 -        
 43.1048 +
 43.1049          } /* end of this while loop for this iteration */
 43.1050 -        
 43.1051 -      skip: 
 43.1052 -        
 43.1053 +
 43.1054 +      skip:
 43.1055 +
 43.1056          total_sent += sent_this_iter;
 43.1057  
 43.1058 -        DPRINTF("\r %d: sent %d, skipped %d, ", 
 43.1059 +        DPRINTF("\r %d: sent %d, skipped %d, ",
 43.1060                  iter, sent_this_iter, skip_this_iter );
 43.1061  
 43.1062          if (last_iter) {
 43.1063              print_stats( xc_handle, dom, sent_this_iter, &stats, 1);
 43.1064  
 43.1065 -            DPRINTF("Total pages sent= %ld (%.2fx)\n", 
 43.1066 +            DPRINTF("Total pages sent= %ld (%.2fx)\n",
 43.1067                      total_sent, ((float)total_sent)/max_pfn );
 43.1068              DPRINTF("(of which %ld were fixups)\n", needed_to_fix  );
 43.1069 -        }       
 43.1070 +        }
 43.1071  
 43.1072          if (last_iter && debug){
 43.1073              int minusone = -1;
 43.1074 -            memset(to_send, 0xff, BITMAP_SIZE); 
 43.1075 +            memset(to_send, 0xff, BITMAP_SIZE);
 43.1076              debug = 0;
 43.1077              fprintf(stderr, "Entering debug resend-all mode\n");
 43.1078 -    
 43.1079 +
 43.1080              /* send "-1" to put receiver into debug mode */
 43.1081 -            if(!write_exact(io_fd, &minusone, sizeof(int))) { 
 43.1082 +            if(!write_exact(io_fd, &minusone, sizeof(int))) {
 43.1083                  ERR("Error when writing to state file (6)");
 43.1084                  goto out;
 43.1085              }
 43.1086 @@ -1033,34 +1033,34 @@ int xc_linux_save(int xc_handle, int io_
 43.1087              continue;
 43.1088          }
 43.1089  
 43.1090 -        if (last_iter) break; 
 43.1091 +        if (last_iter) break;
 43.1092  
 43.1093          if (live) {
 43.1094  
 43.1095  
 43.1096 -            if( 
 43.1097 +            if(
 43.1098                  ((sent_this_iter > sent_last_iter) && RATE_IS_MAX()) ||
 43.1099                  (iter >= max_iters) ||
 43.1100                  (sent_this_iter+skip_this_iter < 50) ||
 43.1101 -                (total_sent > max_pfn*max_factor) ) { 
 43.1102 +                (total_sent > max_pfn*max_factor) ) {
 43.1103  
 43.1104                  DPRINTF("Start last iteration\n");
 43.1105                  last_iter = 1;
 43.1106 -                
 43.1107 +
 43.1108                  if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
 43.1109                                        &ctxt)) {
 43.1110                      ERR("Domain appears not to have suspended");
 43.1111                      goto out;
 43.1112                  }
 43.1113 -                
 43.1114 -                DPRINTF("SUSPEND shinfo %08lx eip %08lx edx %08lx\n", 
 43.1115 -                        info.shared_info_frame, 
 43.1116 -                        (unsigned long)ctxt.user_regs.eip, 
 43.1117 +
 43.1118 +                DPRINTF("SUSPEND shinfo %08lx eip %08lx edx %08lx\n",
 43.1119 +                        info.shared_info_frame,
 43.1120 +                        (unsigned long)ctxt.user_regs.eip,
 43.1121                          (unsigned long)ctxt.user_regs.edx);
 43.1122 -            } 
 43.1123 -            
 43.1124 +            }
 43.1125 +
 43.1126              if (xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_CLEAN,
 43.1127 -                                  to_send, max_pfn, &stats ) != max_pfn) {  
 43.1128 +                                  to_send, max_pfn, &stats ) != max_pfn) {
 43.1129                  ERR("Error flushing shadow PT");
 43.1130                  goto out;
 43.1131              }
 43.1132 @@ -1068,7 +1068,7 @@ int xc_linux_save(int xc_handle, int io_
 43.1133              sent_last_iter = sent_this_iter;
 43.1134  
 43.1135              print_stats(xc_handle, dom, sent_this_iter, &stats, 1);
 43.1136 -     
 43.1137 +
 43.1138          }
 43.1139  
 43.1140  
 43.1141 @@ -1077,8 +1077,8 @@ int xc_linux_save(int xc_handle, int io_
 43.1142      DPRINTF("All memory is saved\n");
 43.1143  
 43.1144      /* Zero terminate */
 43.1145 -    i = 0; 
 43.1146 -    if (!write_exact(io_fd, &i, sizeof(int))) { 
 43.1147 +    i = 0;
 43.1148 +    if (!write_exact(io_fd, &i, sizeof(int))) {
 43.1149          ERR("Error when writing to state file (6)");
 43.1150          goto out;
 43.1151      }
 43.1152 @@ -1086,18 +1086,18 @@ int xc_linux_save(int xc_handle, int io_
 43.1153      /* Send through a list of all the PFNs that were not in map at the close */
 43.1154      {
 43.1155          unsigned int i,j;
 43.1156 -        unsigned long pfntab[1024]; 
 43.1157 +        unsigned long pfntab[1024];
 43.1158  
 43.1159          for (i = 0, j = 0; i < max_pfn; i++) {
 43.1160              if (!is_mapped(live_p2m[i]))
 43.1161                  j++;
 43.1162          }
 43.1163 -        
 43.1164 -        if(!write_exact(io_fd, &j, sizeof(unsigned int))) { 
 43.1165 +
 43.1166 +        if(!write_exact(io_fd, &j, sizeof(unsigned int))) {
 43.1167              ERR("Error when writing to state file (6a)");
 43.1168              goto out;
 43.1169 -        }	
 43.1170 -        
 43.1171 +        }
 43.1172 +
 43.1173          for (i = 0, j = 0; i < max_pfn; ) {
 43.1174  
 43.1175              if (!is_mapped(live_p2m[i]))
 43.1176 @@ -1105,16 +1105,16 @@ int xc_linux_save(int xc_handle, int io_
 43.1177  
 43.1178              i++;
 43.1179              if (j == 1024 || i == max_pfn) {
 43.1180 -                if(!write_exact(io_fd, &pfntab, sizeof(unsigned long)*j)) { 
 43.1181 +                if(!write_exact(io_fd, &pfntab, sizeof(unsigned long)*j)) {
 43.1182                      ERR("Error when writing to state file (6b)");
 43.1183                      goto out;
 43.1184 -                } 
 43.1185 +                }
 43.1186                  j = 0;
 43.1187              }
 43.1188          }
 43.1189  
 43.1190      }
 43.1191 -    
 43.1192 +
 43.1193      /* Canonicalise the suspend-record frame number. */
 43.1194      if ( !translate_mfn_to_pfn(&ctxt.user_regs.edx) ){
 43.1195          ERR("Suspend record is not in range of pseudophys map");
 43.1196 @@ -1138,7 +1138,7 @@ int xc_linux_save(int xc_handle, int io_
 43.1197          PAGE_SHIFT;
 43.1198  
 43.1199      if (!write_exact(io_fd, &ctxt, sizeof(ctxt)) ||
 43.1200 -        !write_exact(io_fd, live_shinfo, PAGE_SIZE)) { 
 43.1201 +        !write_exact(io_fd, live_shinfo, PAGE_SIZE)) {
 43.1202          ERR("Error when writing to state file (1)");
 43.1203          goto out;
 43.1204      }
 43.1205 @@ -1149,26 +1149,26 @@ int xc_linux_save(int xc_handle, int io_
 43.1206   out:
 43.1207  
 43.1208      if (live) {
 43.1209 -        if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF, 
 43.1210 -                             NULL, 0, NULL ) < 0) { 
 43.1211 +        if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF,
 43.1212 +                             NULL, 0, NULL ) < 0) {
 43.1213              DPRINTF("Warning - couldn't disable shadow mode");
 43.1214          }
 43.1215      }
 43.1216 -    
 43.1217 +
 43.1218      if (live_shinfo)
 43.1219          munmap(live_shinfo, PAGE_SIZE);
 43.1220 -    
 43.1221 -    if (live_p2m_frame_list_list) 
 43.1222 -        munmap(live_p2m_frame_list_list, PAGE_SIZE); 
 43.1223  
 43.1224 -    if (live_p2m_frame_list) 
 43.1225 -        munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE); 
 43.1226 +    if (live_p2m_frame_list_list)
 43.1227 +        munmap(live_p2m_frame_list_list, PAGE_SIZE);
 43.1228  
 43.1229 -    if(live_p2m) 
 43.1230 -        munmap(live_p2m, P2M_SIZE); 
 43.1231 +    if (live_p2m_frame_list)
 43.1232 +        munmap(live_p2m_frame_list, P2M_FLL_ENTRIES * PAGE_SIZE);
 43.1233  
 43.1234 -    if(live_m2p) 
 43.1235 -        munmap(live_m2p, M2P_SIZE(max_mfn)); 
 43.1236 +    if(live_p2m)
 43.1237 +        munmap(live_p2m, P2M_SIZE);
 43.1238 +
 43.1239 +    if(live_m2p)
 43.1240 +        munmap(live_m2p, M2P_SIZE(max_mfn));
 43.1241  
 43.1242      free(pfn_type);
 43.1243      free(pfn_batch);
    44.1 --- a/tools/libxc/xc_load_aout9.c	Mon Apr 17 08:47:36 2006 -0600
    44.2 +++ b/tools/libxc/xc_load_aout9.c	Tue Apr 18 09:35:40 2006 -0600
    44.3 @@ -22,7 +22,7 @@ static void copyout(int, uint32_t, unsig
    44.4  struct Exec *get_header(const char *, unsigned long, struct Exec *);
    44.5  
    44.6  
    44.7 -int 
    44.8 +int
    44.9  probe_aout9(
   44.10      const char *image,
   44.11      unsigned long image_size,
   44.12 @@ -40,7 +40,7 @@ probe_aout9(
   44.13      return 0;
   44.14  }
   44.15  
   44.16 -static int 
   44.17 +static int
   44.18  parseaout9image(
   44.19      const char *image,
   44.20      unsigned long image_size,
   44.21 @@ -74,7 +74,7 @@ parseaout9image(
   44.22      return 0;
   44.23  }
   44.24  
   44.25 -static int 
   44.26 +static int
   44.27  loadaout9image(
   44.28      const char *image,
   44.29      unsigned long image_size,
   44.30 @@ -123,7 +123,7 @@ copyout(
   44.31          if(chunksz > PAGE_SIZE - pgoff)
   44.32              chunksz = PAGE_SIZE - pgoff;
   44.33  
   44.34 -        pg = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_WRITE, 
   44.35 +        pg = xc_map_foreign_range(xch, dom, PAGE_SIZE, PROT_WRITE,
   44.36                                    parray[off>>PAGE_SHIFT]);
   44.37          memcpy(pg + pgoff, buf, chunksz);
   44.38          munmap(pg, PAGE_SIZE);
    45.1 --- a/tools/libxc/xc_load_bin.c	Mon Apr 17 08:47:36 2006 -0600
    45.2 +++ b/tools/libxc/xc_load_bin.c	Tue Apr 18 09:35:40 2006 -0600
    45.3 @@ -161,7 +161,7 @@ findtable(const char *image, unsigned lo
    45.4      return NULL;
    45.5  }
    45.6  
    45.7 -static int parsebinimage(const char *image, 
    45.8 +static int parsebinimage(const char *image,
    45.9                           unsigned long image_size,
   45.10                           struct domain_setup_info *dsi)
   45.11  {
    46.1 --- a/tools/libxc/xc_load_elf.c	Mon Apr 17 08:47:36 2006 -0600
    46.2 +++ b/tools/libxc/xc_load_elf.c	Tue Apr 18 09:35:40 2006 -0600
    46.3 @@ -51,7 +51,7 @@ static inline int is_loadable_phdr(Elf_P
    46.4              ((phdr->p_flags & (PF_W|PF_X)) != 0));
    46.5  }
    46.6  
    46.7 -static int parseelfimage(const char *image, 
    46.8 +static int parseelfimage(const char *image,
    46.9                           unsigned long elfsize,
   46.10                           struct domain_setup_info *dsi)
   46.11  {
   46.12 @@ -102,10 +102,10 @@ static int parseelfimage(const char *ima
   46.13          ERROR("ELF image has no section-header strings table (shstrtab).");
   46.14          return -EINVAL;
   46.15      }
   46.16 -    shdr = (Elf_Shdr *)(image + ehdr->e_shoff + 
   46.17 +    shdr = (Elf_Shdr *)(image + ehdr->e_shoff +
   46.18                          (ehdr->e_shstrndx*ehdr->e_shentsize));
   46.19      shstrtab = image + shdr->sh_offset;
   46.20 -    
   46.21 +
   46.22      /* Find the special '__xen_guest' section and check its contents. */
   46.23      for ( h = 0; h < ehdr->e_shnum; h++ )
   46.24      {
   46.25 @@ -148,7 +148,7 @@ static int parseelfimage(const char *ima
   46.26  
   46.27      dsi->xen_guest_string = guestinfo;
   46.28  
   46.29 -    for ( h = 0; h < ehdr->e_phnum; h++ ) 
   46.30 +    for ( h = 0; h < ehdr->e_phnum; h++ )
   46.31      {
   46.32          phdr = (Elf_Phdr *)(image + ehdr->e_phoff + (h*ehdr->e_phentsize));
   46.33          if ( !is_loadable_phdr(phdr) )
   46.34 @@ -159,8 +159,8 @@ static int parseelfimage(const char *ima
   46.35              kernend = phdr->p_paddr + phdr->p_memsz;
   46.36      }
   46.37  
   46.38 -    if ( (kernstart > kernend) || 
   46.39 -         (ehdr->e_entry < kernstart) || 
   46.40 +    if ( (kernstart > kernend) ||
   46.41 +         (ehdr->e_entry < kernstart) ||
   46.42           (ehdr->e_entry > kernend) )
   46.43      {
   46.44          ERROR("Malformed ELF image.");
   46.45 @@ -196,12 +196,12 @@ loadelfimage(
   46.46      char         *va;
   46.47      unsigned long pa, done, chunksz;
   46.48  
   46.49 -    for ( h = 0; h < ehdr->e_phnum; h++ ) 
   46.50 +    for ( h = 0; h < ehdr->e_phnum; h++ )
   46.51      {
   46.52          phdr = (Elf_Phdr *)(image + ehdr->e_phoff + (h*ehdr->e_phentsize));
   46.53          if ( !is_loadable_phdr(phdr) )
   46.54              continue;
   46.55 -        
   46.56 +
   46.57          for ( done = 0; done < phdr->p_filesz; done += chunksz )
   46.58          {
   46.59              pa = (phdr->p_paddr + done) - dsi->v_start;
   46.60 @@ -265,7 +265,7 @@ loadelfsymtab(
   46.61      shdr = (Elf_Shdr *)(p + sizeof(int) + sizeof(Elf_Ehdr));
   46.62      memcpy(shdr, image + ehdr->e_shoff, ehdr->e_shnum * sizeof(Elf_Shdr));
   46.63  
   46.64 -    for ( h = 0; h < ehdr->e_shnum; h++ ) 
   46.65 +    for ( h = 0; h < ehdr->e_shnum; h++ )
   46.66      {
   46.67          if ( shdr[h].sh_type == SHT_STRTAB )
   46.68          {
    47.1 --- a/tools/libxc/xc_misc.c	Mon Apr 17 08:47:36 2006 -0600
    47.2 +++ b/tools/libxc/xc_misc.c	Tue Apr 18 09:35:40 2006 -0600
    47.3 @@ -1,6 +1,6 @@
    47.4  /******************************************************************************
    47.5   * xc_misc.c
    47.6 - * 
    47.7 + *
    47.8   * Miscellaneous control interface functions.
    47.9   */
   47.10  
   47.11 @@ -21,7 +21,7 @@ int xc_interface_close(int xc_handle)
   47.12  
   47.13  int xc_readconsolering(int xc_handle,
   47.14                         char **pbuffer,
   47.15 -                       unsigned int *pnr_chars, 
   47.16 +                       unsigned int *pnr_chars,
   47.17                         int clear)
   47.18  {
   47.19      int ret;
   47.20 @@ -46,14 +46,14 @@ int xc_readconsolering(int xc_handle,
   47.21      safe_munlock(buffer, nr_chars);
   47.22  
   47.23      return ret;
   47.24 -}    
   47.25 +}
   47.26  
   47.27  int xc_physinfo(int xc_handle,
   47.28                  xc_physinfo_t *put_info)
   47.29  {
   47.30      int ret;
   47.31      DECLARE_DOM0_OP;
   47.32 -    
   47.33 +
   47.34      op.cmd = DOM0_PHYSINFO;
   47.35      op.interface_version = DOM0_INTERFACE_VERSION;
   47.36  
   47.37 @@ -70,15 +70,15 @@ int xc_sched_id(int xc_handle,
   47.38  {
   47.39      int ret;
   47.40      DECLARE_DOM0_OP;
   47.41 -    
   47.42 +
   47.43      op.cmd = DOM0_SCHED_ID;
   47.44      op.interface_version = DOM0_INTERFACE_VERSION;
   47.45 -    
   47.46 +
   47.47      if ( (ret = do_dom0_op(xc_handle, &op)) != 0 )
   47.48          return ret;
   47.49 -    
   47.50 +
   47.51      *sched_id = op.u.sched_id.sched_id;
   47.52 -    
   47.53 +
   47.54      return 0;
   47.55  }
   47.56  
   47.57 @@ -100,9 +100,9 @@ int xc_perfc_control(int xc_handle,
   47.58  
   47.59  long long xc_msr_read(int xc_handle, int cpu_mask, int msr)
   47.60  {
   47.61 -    int rc;    
   47.62 +    int rc;
   47.63      DECLARE_DOM0_OP;
   47.64 -    
   47.65 +
   47.66      op.cmd = DOM0_MSR;
   47.67      op.u.msr.write = 0;
   47.68      op.u.msr.msr = msr;
   47.69 @@ -116,9 +116,9 @@ long long xc_msr_read(int xc_handle, int
   47.70  int xc_msr_write(int xc_handle, int cpu_mask, int msr, unsigned int low,
   47.71                    unsigned int high)
   47.72  {
   47.73 -    int rc;    
   47.74 +    int rc;
   47.75      DECLARE_DOM0_OP;
   47.76 -    
   47.77 +
   47.78      op.cmd = DOM0_MSR;
   47.79      op.u.msr.write = 1;
   47.80      op.u.msr.msr = msr;
   47.81 @@ -127,7 +127,7 @@ int xc_msr_write(int xc_handle, int cpu_
   47.82      op.u.msr.in2 = high;
   47.83  
   47.84      rc = do_dom0_op(xc_handle, &op);
   47.85 -    
   47.86 +
   47.87      return rc;
   47.88  }
   47.89  
    48.1 --- a/tools/libxc/xc_physdev.c	Mon Apr 17 08:47:36 2006 -0600
    48.2 +++ b/tools/libxc/xc_physdev.c	Tue Apr 18 09:35:40 2006 -0600
    48.3 @@ -1,8 +1,8 @@
    48.4  /******************************************************************************
    48.5   * xc_physdev.c
    48.6 - * 
    48.7 + *
    48.8   * API for manipulating physical-device access permissions.
    48.9 - * 
   48.10 + *
   48.11   * Copyright (c) 2004, Rolf Neugebauer (Intel Research Cambridge)
   48.12   * Copyright (c) 2004, K A Fraser (University of Cambridge)
   48.13   */
    49.1 --- a/tools/libxc/xc_private.c	Mon Apr 17 08:47:36 2006 -0600
    49.2 +++ b/tools/libxc/xc_private.c	Tue Apr 18 09:35:40 2006 -0600
    49.3 @@ -1,6 +1,6 @@
    49.4  /******************************************************************************
    49.5   * xc_private.c
    49.6 - * 
    49.7 + *
    49.8   * Helper functions for the rest of the library.
    49.9   */
   49.10  
   49.11 @@ -10,7 +10,7 @@
   49.12  void *xc_map_foreign_batch(int xc_handle, uint32_t dom, int prot,
   49.13                             unsigned long *arr, int num )
   49.14  {
   49.15 -    privcmd_mmapbatch_t ioctlx; 
   49.16 +    privcmd_mmapbatch_t ioctlx;
   49.17      void *addr;
   49.18      addr = mmap(NULL, num*PAGE_SIZE, prot, MAP_SHARED, xc_handle, 0);
   49.19      if ( addr == MAP_FAILED )
   49.20 @@ -38,8 +38,8 @@ void *xc_map_foreign_range(int xc_handle
   49.21                             int size, int prot,
   49.22                             unsigned long mfn )
   49.23  {
   49.24 -    privcmd_mmap_t ioctlx; 
   49.25 -    privcmd_mmap_entry_t entry; 
   49.26 +    privcmd_mmap_t ioctlx;
   49.27 +    privcmd_mmap_entry_t entry;
   49.28      void *addr;
   49.29      addr = mmap(NULL, size, prot, MAP_SHARED, xc_handle, 0);
   49.30      if ( addr == MAP_FAILED )
   49.31 @@ -64,7 +64,7 @@ void *xc_map_foreign_range(int xc_handle
   49.32  /*******************/
   49.33  
   49.34  /* NB: arr must be mlock'ed */
   49.35 -int xc_get_pfn_type_batch(int xc_handle, 
   49.36 +int xc_get_pfn_type_batch(int xc_handle,
   49.37                            uint32_t dom, int num, unsigned long *arr)
   49.38  {
   49.39      DECLARE_DOM0_OP;
   49.40 @@ -76,8 +76,8 @@ int xc_get_pfn_type_batch(int xc_handle,
   49.41  }
   49.42  
   49.43  #define GETPFN_ERR (~0U)
   49.44 -unsigned int get_pfn_type(int xc_handle, 
   49.45 -                          unsigned long mfn, 
   49.46 +unsigned int get_pfn_type(int xc_handle,
   49.47 +                          unsigned long mfn,
   49.48                            uint32_t dom)
   49.49  {
   49.50      DECLARE_DOM0_OP;
   49.51 @@ -119,7 +119,7 @@ int xc_mmuext_op(
   49.52  
   49.53   out1:
   49.54      return ret;
   49.55 -}    
   49.56 +}
   49.57  
   49.58  static int flush_mmu_updates(int xc_handle, xc_mmu_t *mmu)
   49.59  {
   49.60 @@ -166,7 +166,7 @@ xc_mmu_t *xc_init_mmu_updates(int xc_han
   49.61      return mmu;
   49.62  }
   49.63  
   49.64 -int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
   49.65 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
   49.66                        unsigned long long ptr, unsigned long long val)
   49.67  {
   49.68      mmu->updates[mmu->idx].ptr = ptr;
   49.69 @@ -288,7 +288,7 @@ int xc_memory_op(int xc_handle,
   49.70  
   49.71   out1:
   49.72      return ret;
   49.73 -}    
   49.74 +}
   49.75  
   49.76  
   49.77  long long xc_domain_get_cpu_usage( int xc_handle, domid_t domid, int vcpu )
   49.78 @@ -308,8 +308,8 @@ long long xc_domain_get_cpu_usage( int x
   49.79  
   49.80  
   49.81  int xc_get_pfn_list(int xc_handle,
   49.82 -                    uint32_t domid, 
   49.83 -                    unsigned long *pfn_buf, 
   49.84 +                    uint32_t domid,
   49.85 +                    unsigned long *pfn_buf,
   49.86                      unsigned long max_pfns)
   49.87  {
   49.88      DECLARE_DOM0_OP;
   49.89 @@ -327,7 +327,7 @@ int xc_get_pfn_list(int xc_handle,
   49.90      {
   49.91          PERROR("xc_get_pfn_list: pfn_buf mlock failed");
   49.92          return -1;
   49.93 -    }    
   49.94 +    }
   49.95  
   49.96      ret = do_dom0_op(xc_handle, &op);
   49.97  
   49.98 @@ -356,13 +356,13 @@ long xc_get_tot_pages(int xc_handle, uin
   49.99      DECLARE_DOM0_OP;
  49.100      op.cmd = DOM0_GETDOMAININFO;
  49.101      op.u.getdomaininfo.domain = (domid_t)domid;
  49.102 -    return (do_dom0_op(xc_handle, &op) < 0) ? 
  49.103 +    return (do_dom0_op(xc_handle, &op) < 0) ?
  49.104          -1 : op.u.getdomaininfo.tot_pages;
  49.105  }
  49.106  
  49.107  int xc_copy_to_domain_page(int xc_handle,
  49.108                             uint32_t domid,
  49.109 -                           unsigned long dst_pfn, 
  49.110 +                           unsigned long dst_pfn,
  49.111                             const char *src_page)
  49.112  {
  49.113      void *vaddr = xc_map_foreign_range(
  49.114 @@ -481,7 +481,7 @@ unsigned long xc_make_page_below_4G(
  49.115  {
  49.116      unsigned long new_mfn;
  49.117  
  49.118 -    if ( xc_domain_memory_decrease_reservation( 
  49.119 +    if ( xc_domain_memory_decrease_reservation(
  49.120          xc_handle, domid, 1, 0, &mfn) != 0 )
  49.121      {
  49.122          fprintf(stderr,"xc_make_page_below_4G decrease failed. mfn=%lx\n",mfn);
    50.1 --- a/tools/libxc/xc_private.h	Mon Apr 17 08:47:36 2006 -0600
    50.2 +++ b/tools/libxc/xc_private.h	Tue Apr 18 09:35:40 2006 -0600
    50.3 @@ -57,7 +57,7 @@ static inline void safe_munlock(const vo
    50.4  }
    50.5  
    50.6  static inline int do_privcmd(int xc_handle,
    50.7 -                             unsigned int cmd, 
    50.8 +                             unsigned int cmd,
    50.9                               unsigned long data)
   50.10  {
   50.11      return ioctl(xc_handle, cmd, data);
   50.12 @@ -67,7 +67,7 @@ static inline int do_xen_hypercall(int x
   50.13                                     privcmd_hypercall_t *hypercall)
   50.14  {
   50.15      return do_privcmd(xc_handle,
   50.16 -                      IOCTL_PRIVCMD_HYPERCALL, 
   50.17 +                      IOCTL_PRIVCMD_HYPERCALL,
   50.18                        (unsigned long)hypercall);
   50.19  }
   50.20  
   50.21 @@ -78,7 +78,7 @@ static inline int do_xen_version(int xc_
   50.22      hypercall.op     = __HYPERVISOR_xen_version;
   50.23      hypercall.arg[0] = (unsigned long) cmd;
   50.24      hypercall.arg[1] = (unsigned long) dest;
   50.25 -    
   50.26 +
   50.27      return do_xen_hypercall(xc_handle, &hypercall);
   50.28  }
   50.29  
   50.30 @@ -121,13 +121,13 @@ typedef struct privcmd_mmap_entry {
   50.31      unsigned long va;
   50.32      unsigned long mfn;
   50.33      unsigned long npages;
   50.34 -} privcmd_mmap_entry_t; 
   50.35 +} privcmd_mmap_entry_t;
   50.36  
   50.37  typedef struct privcmd_mmap {
   50.38      int num;
   50.39      domid_t dom;
   50.40      privcmd_mmap_entry_t *entry;
   50.41 -} privcmd_mmap_t; 
   50.42 +} privcmd_mmap_t;
   50.43  */
   50.44  
   50.45  #endif /* __XC_PRIVATE_H__ */
    51.1 --- a/tools/libxc/xc_ptrace.c	Mon Apr 17 08:47:36 2006 -0600
    51.2 +++ b/tools/libxc/xc_ptrace.c	Tue Apr 18 09:35:40 2006 -0600
    51.3 @@ -46,7 +46,7 @@ static cpumap_t                 regs_val
    51.4  static vcpu_guest_context_t     ctxt[MAX_VIRT_CPUS];
    51.5  
    51.6  extern int ffsll(long long int);
    51.7 -#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) ) 
    51.8 +#define FOREACH_CPU(cpumap, i)  for ( cpumap = online_cpumap; (i = ffsll(cpumap)); cpumap &= ~(1 << (index - 1)) )
    51.9  
   51.10  
   51.11  static int
   51.12 @@ -58,22 +58,22 @@ fetch_regs(int xc_handle, int cpu, int *
   51.13      if (online)
   51.14          *online = 0;
   51.15      if ( !(regs_valid & (1 << cpu)) )
   51.16 -    { 
   51.17 -        retval = xc_vcpu_getcontext(xc_handle, current_domid, 
   51.18 -						cpu, &ctxt[cpu]);
   51.19 -        if ( retval ) 
   51.20 +    {
   51.21 +        retval = xc_vcpu_getcontext(xc_handle, current_domid,
   51.22 +                cpu, &ctxt[cpu]);
   51.23 +        if ( retval )
   51.24              goto done;
   51.25 -	regs_valid |= (1 << cpu);
   51.26 +        regs_valid |= (1 << cpu);
   51.27  
   51.28      }
   51.29 -	if ( online == NULL )
   51.30 -	    goto done;
   51.31 +    if ( online == NULL )
   51.32 +        goto done;
   51.33  
   51.34 -	retval = xc_vcpu_getinfo(xc_handle, current_domid, cpu, &info);
   51.35 -	*online = info.online;
   51.36 -    
   51.37 +    retval = xc_vcpu_getinfo(xc_handle, current_domid, cpu, &info);
   51.38 +    *online = info.online;
   51.39 +
   51.40   done:
   51.41 -    return retval;    
   51.42 +    return retval;
   51.43  }
   51.44  
   51.45  static struct thr_ev_handlers {
   51.46 @@ -81,8 +81,8 @@ static struct thr_ev_handlers {
   51.47      thr_ev_handler_t td_death;
   51.48  } handlers;
   51.49  
   51.50 -void 
   51.51 -xc_register_event_handler(thr_ev_handler_t h, 
   51.52 +void
   51.53 +xc_register_event_handler(thr_ev_handler_t h,
   51.54                            td_event_e e)
   51.55  {
   51.56      switch (e) {
   51.57 @@ -97,7 +97,7 @@ xc_register_event_handler(thr_ev_handler
   51.58      }
   51.59  }
   51.60  
   51.61 -static inline int 
   51.62 +static inline int
   51.63  paging_enabled(vcpu_guest_context_t *v)
   51.64  {
   51.65      unsigned long cr0 = v->ctrlreg[0];
   51.66 @@ -114,19 +114,19 @@ static int
   51.67  get_online_cpumap(int xc_handle, dom0_getdomaininfo_t *d, cpumap_t *cpumap)
   51.68  {
   51.69      int i, online, retval;
   51.70 -    
   51.71 +
   51.72      *cpumap = 0;
   51.73      for (i = 0; i <= d->max_vcpu_id; i++) {
   51.74          if ((retval = fetch_regs(xc_handle, i, &online)))
   51.75              return retval;
   51.76          if (online)
   51.77 -            *cpumap |= (1 << i);            
   51.78 +            *cpumap |= (1 << i);
   51.79      }
   51.80 -    
   51.81 +
   51.82      return 0;
   51.83  }
   51.84  
   51.85 -/* 
   51.86 +/*
   51.87   * Notify GDB of any vcpus that have come online or gone offline
   51.88   * update online_cpumap
   51.89   *
   51.90 @@ -137,7 +137,7 @@ online_vcpus_changed(cpumap_t cpumap)
   51.91  {
   51.92      cpumap_t changed_cpumap = cpumap ^ online_cpumap;
   51.93      int index;
   51.94 -    
   51.95 +
   51.96      while ( (index = ffsll(changed_cpumap)) ) {
   51.97          if ( cpumap & (1 << (index - 1)) )
   51.98          {
   51.99 @@ -149,7 +149,7 @@ online_vcpus_changed(cpumap_t cpumap)
  51.100          changed_cpumap &= ~(1 << (index - 1));
  51.101      }
  51.102      online_cpumap = cpumap;
  51.103 -    
  51.104 +
  51.105  }
  51.106  
  51.107  /* --------------------- */
  51.108 @@ -172,7 +172,7 @@ map_domain_va_32(
  51.109      static unsigned long  pde_phys[MAX_VIRT_CPUS];
  51.110      static uint32_t *pde_virt[MAX_VIRT_CPUS];
  51.111      static unsigned long  page_phys[MAX_VIRT_CPUS];
  51.112 -    static uint32_t *page_virt[MAX_VIRT_CPUS];    
  51.113 +    static uint32_t *page_virt[MAX_VIRT_CPUS];
  51.114      static int            prev_perm[MAX_VIRT_CPUS];
  51.115  
  51.116     if (ctxt[cpu].ctrlreg[3] == 0)
  51.117 @@ -221,7 +221,7 @@ map_domain_va_32(
  51.118              return NULL;
  51.119          }
  51.120          prev_perm[cpu] = perm;
  51.121 -    } 
  51.122 +    }
  51.123  
  51.124      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
  51.125  }
  51.126 @@ -284,7 +284,7 @@ map_domain_va_64(
  51.127      if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
  51.128          return map_domain_va_32(xc_handle, cpu, guest_va, perm);
  51.129  
  51.130 -    l4 = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE, 
  51.131 +    l4 = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE,
  51.132              PROT_READ, ctxt[cpu].ctrlreg[3] >> PAGE_SHIFT);
  51.133      if ( l4 == NULL )
  51.134          return NULL;
  51.135 @@ -349,7 +349,7 @@ map_domain_va(
  51.136              mode = MODE_64;
  51.137          else if ( strstr(caps, "-x86_32p") )
  51.138              mode = MODE_PAE;
  51.139 -        else if ( strstr(caps, "-x86_32") ) 
  51.140 +        else if ( strstr(caps, "-x86_32") )
  51.141              mode = MODE_32;
  51.142      }
  51.143  
  51.144 @@ -374,7 +374,7 @@ map_domain_va(
  51.145      if (fetch_regs(xc_handle, cpu, NULL))
  51.146          return NULL;
  51.147  
  51.148 -    if (!paging_enabled(&ctxt[cpu])) { 
  51.149 +    if (!paging_enabled(&ctxt[cpu])) {
  51.150          static void * v;
  51.151          unsigned long page;
  51.152  
  51.153 @@ -383,9 +383,9 @@ map_domain_va(
  51.154  
  51.155          page = page_array[va >> PAGE_SHIFT] << PAGE_SHIFT;
  51.156  
  51.157 -        v = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE, 
  51.158 +        v = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE,
  51.159                  perm, page >> PAGE_SHIFT);
  51.160 -    
  51.161 +
  51.162          if ( v == NULL )
  51.163              return NULL;
  51.164  
  51.165 @@ -403,7 +403,7 @@ map_domain_va(
  51.166  
  51.167  int control_c_pressed_flag = 0;
  51.168  
  51.169 -static int 
  51.170 +static int
  51.171  __xc_waitdomain(
  51.172      int xc_handle,
  51.173      int domain,
  51.174 @@ -420,7 +420,7 @@ static int
  51.175  
  51.176      op.cmd = DOM0_GETDOMAININFO;
  51.177      op.u.getdomaininfo.domain = domain;
  51.178 -    
  51.179 +
  51.180   retry:
  51.181      retval = do_dom0_op(xc_handle, &op);
  51.182      if ( retval || (op.u.getdomaininfo.domain != domain) )
  51.183 @@ -429,7 +429,7 @@ static int
  51.184          goto done;
  51.185      }
  51.186      *status = op.u.getdomaininfo.flags;
  51.187 -    
  51.188 +
  51.189      if ( options & WNOHANG )
  51.190          goto done;
  51.191  
  51.192 @@ -472,16 +472,16 @@ xc_ptrace(
  51.193      void           *data = (char *)edata;
  51.194  
  51.195      cpu = (request != PTRACE_ATTACH) ? domid_tid : 0;
  51.196 -    
  51.197 +
  51.198      switch ( request )
  51.199 -    { 
  51.200 +    {
  51.201      case PTRACE_PEEKTEXT:
  51.202      case PTRACE_PEEKDATA:
  51.203          if (current_isfile)
  51.204 -            guest_va = (unsigned long *)map_domain_va_core(current_domid, 
  51.205 +            guest_va = (unsigned long *)map_domain_va_core(current_domid,
  51.206                                  cpu, addr, ctxt);
  51.207          else
  51.208 -            guest_va = (unsigned long *)map_domain_va(xc_handle, 
  51.209 +            guest_va = (unsigned long *)map_domain_va(xc_handle,
  51.210                                  cpu, addr, PROT_READ);
  51.211          if ( guest_va == NULL )
  51.212              goto out_error;
  51.213 @@ -492,26 +492,26 @@ xc_ptrace(
  51.214      case PTRACE_POKEDATA:
  51.215          /* XXX assume that all CPUs have the same address space */
  51.216          if (current_isfile)
  51.217 -            guest_va = (unsigned long *)map_domain_va_core(current_domid, 
  51.218 +            guest_va = (unsigned long *)map_domain_va_core(current_domid,
  51.219                                  cpu, addr, ctxt);
  51.220          else
  51.221 -            guest_va = (unsigned long *)map_domain_va(xc_handle, 
  51.222 +            guest_va = (unsigned long *)map_domain_va(xc_handle,
  51.223                                  cpu, addr, PROT_READ|PROT_WRITE);
  51.224 -        if ( guest_va == NULL ) 
  51.225 +        if ( guest_va == NULL )
  51.226              goto out_error;
  51.227          *guest_va = (unsigned long)data;
  51.228          break;
  51.229  
  51.230      case PTRACE_GETREGS:
  51.231 -        if (!current_isfile && fetch_regs(xc_handle, cpu, NULL)) 
  51.232 +        if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
  51.233              goto out_error;
  51.234 -        SET_PT_REGS(pt, ctxt[cpu].user_regs); 
  51.235 +        SET_PT_REGS(pt, ctxt[cpu].user_regs);
  51.236          memcpy(data, &pt, sizeof(struct gdb_regs));
  51.237          break;
  51.238  
  51.239      case PTRACE_GETFPREGS:
  51.240      case PTRACE_GETFPXREGS:
  51.241 -        if (!current_isfile && fetch_regs(xc_handle, cpu, NULL)) 
  51.242 +        if (!current_isfile && fetch_regs(xc_handle, cpu, NULL))
  51.243                  goto out_error;
  51.244          memcpy(data, &ctxt[cpu].fpu_ctxt, sizeof(ctxt[cpu].fpu_ctxt));
  51.245          break;
  51.246 @@ -520,7 +520,7 @@ xc_ptrace(
  51.247          if (current_isfile)
  51.248                  goto out_unspported; /* XXX not yet supported */
  51.249          SET_XC_REGS(((struct gdb_regs *)data), ctxt[cpu].user_regs);
  51.250 -        if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, 
  51.251 +        if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu,
  51.252                                  &ctxt[cpu])))
  51.253              goto out_error_dom0;
  51.254          break;
  51.255 @@ -531,8 +531,8 @@ xc_ptrace(
  51.256          /*  XXX we can still have problems if the user switches threads
  51.257           *  during single-stepping - but that just seems retarded
  51.258           */
  51.259 -        ctxt[cpu].user_regs.eflags |= PSL_T; 
  51.260 -        if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu, 
  51.261 +        ctxt[cpu].user_regs.eflags |= PSL_T;
  51.262 +        if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, cpu,
  51.263                                  &ctxt[cpu])))
  51.264              goto out_error_dom0;
  51.265          /* FALLTHROUGH */
  51.266 @@ -545,13 +545,13 @@ xc_ptrace(
  51.267          {
  51.268              FOREACH_CPU(cpumap, index) {
  51.269                  cpu = index - 1;
  51.270 -                if (fetch_regs(xc_handle, cpu, NULL)) 
  51.271 +                if (fetch_regs(xc_handle, cpu, NULL))
  51.272                      goto out_error;
  51.273                  /* Clear trace flag */
  51.274 -                if ( ctxt[cpu].user_regs.eflags & PSL_T ) 
  51.275 +                if ( ctxt[cpu].user_regs.eflags & PSL_T )
  51.276                  {
  51.277                      ctxt[cpu].user_regs.eflags &= ~PSL_T;
  51.278 -                    if ((retval = xc_vcpu_setcontext(xc_handle, current_domid, 
  51.279 +                    if ((retval = xc_vcpu_setcontext(xc_handle, current_domid,
  51.280                                                  cpu, &ctxt[cpu])))
  51.281                          goto out_error_dom0;
  51.282                  }
  51.283 @@ -566,7 +566,7 @@ xc_ptrace(
  51.284                  goto out_error_dom0;
  51.285          }
  51.286          regs_valid = 0;
  51.287 -        if ((retval = xc_domain_unpause(xc_handle, current_domid > 0 ? 
  51.288 +        if ((retval = xc_domain_unpause(xc_handle, current_domid > 0 ?
  51.289                                  current_domid : -current_domid)))
  51.290              goto out_error_dom0;
  51.291          break;
  51.292 @@ -627,7 +627,7 @@ xc_ptrace(
  51.293  
  51.294  }
  51.295  
  51.296 -int 
  51.297 +int
  51.298  xc_waitdomain(
  51.299      int xc_handle,
  51.300      int domain,
    52.1 --- a/tools/libxc/xc_ptrace.h	Mon Apr 17 08:47:36 2006 -0600
    52.2 +++ b/tools/libxc/xc_ptrace.h	Tue Apr 18 09:35:40 2006 -0600
    52.3 @@ -107,7 +107,7 @@ struct gdb_regs {
    52.4      long esi; /* 12 */
    52.5      long edi; /* 16 */
    52.6      long ebp; /* 20 */
    52.7 -    long eax; /* 24 */ 
    52.8 +    long eax; /* 24 */
    52.9      int  xds; /* 28 */
   52.10      int  xes; /* 32 */
   52.11      int  xfs; /* 36 */
   52.12 @@ -116,7 +116,7 @@ struct gdb_regs {
   52.13      long eip;    /* 48 */
   52.14      int  xcs;    /* 52 */
   52.15      long eflags; /* 56 */
   52.16 -    long esp;    /* 60 */     
   52.17 +    long esp;    /* 60 */
   52.18      int  xss;    /* 64 */
   52.19  };
   52.20  
   52.21 @@ -169,20 +169,20 @@ struct gdb_regs {
   52.22  typedef void (*thr_ev_handler_t)(long);
   52.23  
   52.24  void xc_register_event_handler(
   52.25 -    thr_ev_handler_t h, 
   52.26 +    thr_ev_handler_t h,
   52.27      td_event_e e);
   52.28  
   52.29  long xc_ptrace(
   52.30      int xc_handle,
   52.31 -    enum __ptrace_request request, 
   52.32 +    enum __ptrace_request request,
   52.33      uint32_t  domid,
   52.34 -    long addr, 
   52.35 +    long addr,
   52.36      long data);
   52.37  
   52.38  int xc_waitdomain(
   52.39      int xc_handle,
   52.40 -    int domain, 
   52.41 -    int *status, 
   52.42 +    int domain,
   52.43 +    int *status,
   52.44      int options);
   52.45  
   52.46  #endif /* XC_PTRACE */
    53.1 --- a/tools/libxc/xc_ptrace_core.c	Mon Apr 17 08:47:36 2006 -0600
    53.2 +++ b/tools/libxc/xc_ptrace_core.c	Tue Apr 18 09:35:40 2006 -0600
    53.3 @@ -39,7 +39,7 @@ map_domain_va_core(unsigned long domfd, 
    53.4      static unsigned long  page_phys[MAX_VIRT_CPUS];
    53.5      static unsigned long *page_virt[MAX_VIRT_CPUS];
    53.6  
    53.7 -    if (cr3[cpu] != cr3_phys[cpu]) 
    53.8 +    if (cr3[cpu] != cr3_phys[cpu])
    53.9      {
   53.10          cr3_phys[cpu] = cr3[cpu];
   53.11          if (cr3_virt[cpu])
   53.12 @@ -53,12 +53,12 @@ map_domain_va_core(unsigned long domfd, 
   53.13              return NULL;
   53.14          }
   53.15          cr3_virt[cpu] = v;
   53.16 -    } 
   53.17 +    }
   53.18      if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
   53.19          return NULL;
   53.20      if (ctxt[cpu].flags & VGCF_HVM_GUEST)
   53.21          pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
   53.22 -    if (pde != pde_phys[cpu]) 
   53.23 +    if (pde != pde_phys[cpu])
   53.24      {
   53.25          pde_phys[cpu] = pde;
   53.26          if (pde_virt[cpu])
   53.27 @@ -74,7 +74,7 @@ map_domain_va_core(unsigned long domfd, 
   53.28          return NULL;
   53.29      if (ctxt[cpu].flags & VGCF_HVM_GUEST)
   53.30          page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
   53.31 -    if (page != page_phys[cpu]) 
   53.32 +    if (page != page_phys[cpu])
   53.33      {
   53.34          page_phys[cpu] = page;
   53.35          if (page_virt[cpu])
   53.36 @@ -89,11 +89,11 @@ map_domain_va_core(unsigned long domfd, 
   53.37              return NULL;
   53.38          }
   53.39          page_virt[cpu] = v;
   53.40 -    } 
   53.41 +    }
   53.42      return (void *)(((unsigned long)page_virt[cpu]) | (va & BSD_PAGE_MASK));
   53.43  }
   53.44  
   53.45 -int 
   53.46 +int
   53.47  xc_waitdomain_core(
   53.48      int xc_handle,
   53.49      int domfd,
   53.50 @@ -122,7 +122,7 @@ xc_waitdomain_core(
   53.51          nr_vcpus = header.xch_nr_vcpus;
   53.52          pages_offset = header.xch_pages_offset;
   53.53  
   53.54 -        if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) != 
   53.55 +        if (read(domfd, ctxt, sizeof(vcpu_guest_context_t)*nr_vcpus) !=
   53.56              sizeof(vcpu_guest_context_t)*nr_vcpus)
   53.57              return -1;
   53.58  
   53.59 @@ -134,7 +134,7 @@ xc_waitdomain_core(
   53.60              printf("Could not allocate p2m_array\n");
   53.61              return -1;
   53.62          }
   53.63 -        if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) != 
   53.64 +        if (read(domfd, p2m_array, sizeof(unsigned long)*nr_pages) !=
   53.65              sizeof(unsigned long)*nr_pages)
   53.66              return -1;
   53.67  
    54.1 --- a/tools/libxc/xc_sedf.c	Mon Apr 17 08:47:36 2006 -0600
    54.2 +++ b/tools/libxc/xc_sedf.c	Tue Apr 18 09:35:40 2006 -0600
    54.3 @@ -1,8 +1,8 @@
    54.4  /******************************************************************************
    54.5   * xc_sedf.c
    54.6 - * 
    54.7 + *
    54.8   * API for manipulating parameters of the Simple EDF scheduler.
    54.9 - * 
   54.10 + *
   54.11   * changes by Stephan Diestelhorst
   54.12   * based on code
   54.13   * by Mark Williamson, Copyright (c) 2004 Intel Research Cambridge.
   54.14 @@ -35,7 +35,7 @@ int xc_sedf_domain_get(int xc_handle, ui
   54.15      int ret;
   54.16      struct sedf_adjdom *p = &op.u.adjustdom.u.sedf;
   54.17  
   54.18 -    op.cmd = DOM0_ADJUSTDOM;    
   54.19 +    op.cmd = DOM0_ADJUSTDOM;
   54.20      op.u.adjustdom.domain = (domid_t)domid;
   54.21      op.u.adjustdom.sched_id = SCHED_SEDF;
   54.22      op.u.adjustdom.direction = SCHED_INFO_GET;
    55.1 --- a/tools/libxc/xc_tbuf.c	Mon Apr 17 08:47:36 2006 -0600
    55.2 +++ b/tools/libxc/xc_tbuf.c	Tue Apr 18 09:35:40 2006 -0600
    55.3 @@ -1,8 +1,8 @@
    55.4  /******************************************************************************
    55.5   * xc_tbuf.c
    55.6 - * 
    55.7 + *
    55.8   * API for manipulating and accessing trace buffer parameters
    55.9 - * 
   55.10 + *
   55.11   * Copyright (c) 2005, Rob Gardner
   55.12   */
   55.13  
   55.14 @@ -18,7 +18,7 @@ int xc_tbuf_enable(int xc_handle, int en
   55.15      op.u.tbufcontrol.op  = DOM0_TBUF_ENABLE;
   55.16    else
   55.17      op.u.tbufcontrol.op  = DOM0_TBUF_DISABLE;
   55.18 -  
   55.19 +
   55.20    return xc_dom0_op(xc_handle, &op);
   55.21  }
   55.22  
   55.23 @@ -30,10 +30,10 @@ int xc_tbuf_set_size(int xc_handle, uint
   55.24    op.interface_version = DOM0_INTERFACE_VERSION;
   55.25    op.u.tbufcontrol.op  = DOM0_TBUF_SET_SIZE;
   55.26    op.u.tbufcontrol.size = size;
   55.27 -  
   55.28 +
   55.29    return xc_dom0_op(xc_handle, &op);
   55.30  }
   55.31 -  
   55.32 +
   55.33  int xc_tbuf_get_size(int xc_handle, uint32_t *size)
   55.34  {
   55.35    int rc;
    56.1 --- a/tools/libxc/xenctrl.h	Mon Apr 17 08:47:36 2006 -0600
    56.2 +++ b/tools/libxc/xenctrl.h	Tue Apr 18 09:35:40 2006 -0600
    56.3 @@ -1,8 +1,8 @@
    56.4  /******************************************************************************
    56.5   * xenctrl.h
    56.6 - * 
    56.7 + *
    56.8   * A library for low-level access to the Xen control interfaces.
    56.9 - * 
   56.10 + *
   56.11   * Copyright (c) 2003-2004, K A Fraser.
   56.12   */
   56.13  
   56.14 @@ -30,7 +30,7 @@
   56.15  
   56.16  /*
   56.17   *  DEFINITIONS FOR CPU BARRIERS
   56.18 - */ 
   56.19 + */
   56.20  
   56.21  #if defined(__i386__)
   56.22  #define mb()  __asm__ __volatile__ ( "lock; addl $0,0(%%esp)" : : : "memory" )
   56.23 @@ -51,7 +51,7 @@
   56.24  
   56.25  /*
   56.26   *  INITIALIZATION FUNCTIONS
   56.27 - */ 
   56.28 + */
   56.29  
   56.30  /**
   56.31   * This function opens a handle to the hypervisor interface.  This function can
   56.32 @@ -96,20 +96,20 @@ typedef struct xc_core_header {
   56.33  
   56.34  long xc_ptrace_core(
   56.35      int xc_handle,
   56.36 -    enum __ptrace_request request, 
   56.37 -    uint32_t domid, 
   56.38 -    long addr, 
   56.39 +    enum __ptrace_request request,
   56.40 +    uint32_t domid,
   56.41 +    long addr,
   56.42      long data,
   56.43      vcpu_guest_context_t *ctxt);
   56.44  void * map_domain_va_core(
   56.45 -    unsigned long domfd, 
   56.46 -    int cpu, 
   56.47 +    unsigned long domfd,
   56.48 +    int cpu,
   56.49      void *guest_va,
   56.50      vcpu_guest_context_t *ctxt);
   56.51  int xc_waitdomain_core(
   56.52      int xc_handle,
   56.53 -    int domain, 
   56.54 -    int *status, 
   56.55 +    int domain,
   56.56 +    int *status,
   56.57      int options,
   56.58      vcpu_guest_context_t *ctxt);
   56.59  
   56.60 @@ -120,7 +120,7 @@ int xc_waitdomain_core(
   56.61  typedef struct {
   56.62      uint32_t      domid;
   56.63      uint32_t      ssidref;
   56.64 -    unsigned int  dying:1, crashed:1, shutdown:1, 
   56.65 +    unsigned int  dying:1, crashed:1, shutdown:1,
   56.66                    paused:1, blocked:1, running:1;
   56.67      unsigned int  shutdown_reason; /* only meaningful if shutdown==1 */
   56.68      unsigned long nr_pages;
   56.69 @@ -133,7 +133,7 @@ typedef struct {
   56.70  } xc_dominfo_t;
   56.71  
   56.72  typedef dom0_getdomaininfo_t xc_domaininfo_t;
   56.73 -int xc_domain_create(int xc_handle, 
   56.74 +int xc_domain_create(int xc_handle,
   56.75                       uint32_t ssidref,
   56.76                       xen_domain_handle_t handle,
   56.77                       uint32_t *pdomid);
   56.78 @@ -144,7 +144,7 @@ int xc_domain_create(int xc_handle,
   56.79   *  xc_domain_dumpcore_via_callback - produces a dump, using a specified
   56.80   *                                    callback function
   56.81   */
   56.82 -int xc_domain_dumpcore(int xc_handle, 
   56.83 +int xc_domain_dumpcore(int xc_handle,
   56.84                         uint32_t domid,
   56.85                         const char *corename);
   56.86  
   56.87 @@ -156,7 +156,7 @@ int xc_domain_dumpcore(int xc_handle,
   56.88   */
   56.89  typedef int (dumpcore_rtn_t)(void *arg, char *buffer, unsigned int length);
   56.90  
   56.91 -int xc_domain_dumpcore_via_callback(int xc_handle, 
   56.92 +int xc_domain_dumpcore_via_callback(int xc_handle,
   56.93                                      uint32_t domid,
   56.94                                      void *arg,
   56.95                                      dumpcore_rtn_t dump_rtn);
   56.96 @@ -170,7 +170,7 @@ int xc_domain_dumpcore_via_callback(int 
   56.97   * @return 0 on success, -1 on failure.
   56.98   */
   56.99  int xc_domain_max_vcpus(int xc_handle,
  56.100 -                        uint32_t domid, 
  56.101 +                        uint32_t domid,
  56.102                          unsigned int max);
  56.103  
  56.104  /**
  56.105 @@ -181,7 +181,7 @@ int xc_domain_max_vcpus(int xc_handle,
  56.106   * @parm domid the domain id to pause
  56.107   * @return 0 on success, -1 on failure.
  56.108   */
  56.109 -int xc_domain_pause(int xc_handle, 
  56.110 +int xc_domain_pause(int xc_handle,
  56.111                      uint32_t domid);
  56.112  /**
  56.113   * This function unpauses a domain.  The domain should have been previously
  56.114 @@ -191,7 +191,7 @@ int xc_domain_pause(int xc_handle,
  56.115   * @parm domid the domain id to unpause
  56.116   * return 0 on success, -1 on failure
  56.117   */
  56.118 -int xc_domain_unpause(int xc_handle, 
  56.119 +int xc_domain_unpause(int xc_handle,
  56.120                        uint32_t domid);
  56.121  
  56.122  /**
  56.123 @@ -203,7 +203,7 @@ int xc_domain_unpause(int xc_handle,
  56.124   * @parm domid the domain id to destroy
  56.125   * @return 0 on success, -1 on failure
  56.126   */
  56.127 -int xc_domain_destroy(int xc_handle, 
  56.128 +int xc_domain_destroy(int xc_handle,
  56.129                        uint32_t domid);
  56.130  
  56.131  /**
  56.132 @@ -217,7 +217,7 @@ int xc_domain_destroy(int xc_handle,
  56.133   * @parm reason is the reason (SHUTDOWN_xxx) for the shutdown
  56.134   * @return 0 on success, -1 on failure
  56.135   */
  56.136 -int xc_domain_shutdown(int xc_handle, 
  56.137 +int xc_domain_shutdown(int xc_handle,
  56.138                         uint32_t domid,
  56.139                         int reason);
  56.140  
  56.141 @@ -242,7 +242,7 @@ int xc_vcpu_setaffinity(int xc_handle,
  56.142   * @return the number of domains enumerated or -1 on error
  56.143   */
  56.144  int xc_domain_getinfo(int xc_handle,
  56.145 -                      uint32_t first_domid, 
  56.146 +                      uint32_t first_domid,
  56.147                        unsigned int max_doms,
  56.148                        xc_dominfo_t *info);
  56.149  
  56.150 @@ -307,12 +307,12 @@ long long xc_domain_get_cpu_usage(int xc
  56.151                                    domid_t domid,
  56.152                                    int vcpu);
  56.153  
  56.154 -int xc_domain_sethandle(int xc_handle, uint32_t domid, 
  56.155 +int xc_domain_sethandle(int xc_handle, uint32_t domid,
  56.156                          xen_domain_handle_t handle);
  56.157  
  56.158  typedef dom0_shadow_control_stats_t xc_shadow_control_stats_t;
  56.159  int xc_shadow_control(int xc_handle,
  56.160 -                      uint32_t domid, 
  56.161 +                      uint32_t domid,
  56.162                        unsigned int sop,
  56.163                        unsigned long *dirty_bitmap,
  56.164                        unsigned long pages,
  56.165 @@ -386,7 +386,7 @@ int xc_physdev_pci_access_modify(int xc_
  56.166  
  56.167  int xc_readconsolering(int xc_handle,
  56.168                         char **pbuffer,
  56.169 -                       unsigned int *pnr_chars, 
  56.170 +                       unsigned int *pnr_chars,
  56.171                         int clear);
  56.172  
  56.173  typedef dom0_physinfo_t xc_physinfo_t;
  56.174 @@ -397,18 +397,18 @@ int xc_sched_id(int xc_handle,
  56.175                  int *sched_id);
  56.176  
  56.177  int xc_domain_setmaxmem(int xc_handle,
  56.178 -                        uint32_t domid, 
  56.179 +                        uint32_t domid,
  56.180                          unsigned int max_memkb);
  56.181  
  56.182  int xc_domain_memory_increase_reservation(int xc_handle,
  56.183 -                                          uint32_t domid, 
  56.184 +                                          uint32_t domid,
  56.185                                            unsigned long nr_extents,
  56.186                                            unsigned int extent_order,
  56.187                                            unsigned int address_bits,
  56.188                                            unsigned long *extent_start);
  56.189  
  56.190  int xc_domain_memory_decrease_reservation(int xc_handle,
  56.191 -                                          uint32_t domid, 
  56.192 +                                          uint32_t domid,
  56.193                                            unsigned long nr_extents,
  56.194                                            unsigned int extent_order,
  56.195                                            unsigned long *extent_start);
  56.196 @@ -443,7 +443,7 @@ int xc_domain_iomem_permission(int xc_ha
  56.197                                 unsigned long nr_mfns,
  56.198                                 uint8_t allow_access);
  56.199  
  56.200 -unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid, 
  56.201 +unsigned long xc_make_page_below_4G(int xc_handle, uint32_t domid,
  56.202                                      unsigned long mfn);
  56.203  
  56.204  typedef dom0_perfc_desc_t xc_perfc_desc_t;
  56.205 @@ -492,11 +492,11 @@ void *xc_map_foreign_batch(int xc_handle
  56.206  unsigned long xc_translate_foreign_address(int xc_handle, uint32_t dom,
  56.207                                             int vcpu, unsigned long long virt);
  56.208  
  56.209 -int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf, 
  56.210 +int xc_get_pfn_list(int xc_handle, uint32_t domid, unsigned long *pfn_buf,
  56.211                      unsigned long max_pfns);
  56.212  
  56.213  int xc_ia64_get_pfn_list(int xc_handle, uint32_t domid,
  56.214 -                         unsigned long *pfn_buf, 
  56.215 +                         unsigned long *pfn_buf,
  56.216                           unsigned int start_page, unsigned int nr_pages);
  56.217  
  56.218  int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
  56.219 @@ -551,7 +551,7 @@ int xc_tbuf_enable(int xc_handle, int en
  56.220  int xc_tbuf_set_size(int xc_handle, uint32_t size);
  56.221  
  56.222  /**
  56.223 - * This function retrieves the current size of the trace buffers. 
  56.224 + * This function retrieves the current size of the trace buffers.
  56.225   * Note that the size returned is in terms of bytes, not pages.
  56.226  
  56.227   * @parm xc_handle a handle to an open hypervisor interface
  56.228 @@ -577,7 +577,7 @@ struct xc_mmu {
  56.229  };
  56.230  typedef struct xc_mmu xc_mmu_t;
  56.231  xc_mmu_t *xc_init_mmu_updates(int xc_handle, domid_t dom);
  56.232 -int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu, 
  56.233 +int xc_add_mmu_update(int xc_handle, xc_mmu_t *mmu,
  56.234                     unsigned long long ptr, unsigned long long val);
  56.235  int xc_finish_mmu_updates(int xc_handle, xc_mmu_t *mmu);
  56.236  
    57.1 --- a/tools/libxc/xenguest.h	Mon Apr 17 08:47:36 2006 -0600
    57.2 +++ b/tools/libxc/xenguest.h	Tue Apr 18 09:35:40 2006 -0600
    57.3 @@ -1,8 +1,8 @@
    57.4  /******************************************************************************
    57.5   * xenguest.h
    57.6 - * 
    57.7 + *
    57.8   * A library for guest domain management in Xen.
    57.9 - * 
   57.10 + *
   57.11   * Copyright (c) 2003-2004, K A Fraser.
   57.12   */
   57.13  
   57.14 @@ -21,7 +21,7 @@
   57.15   * @parm dom the id of the domain
   57.16   * @return 0 on success, -1 on failure
   57.17   */
   57.18 -int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
   57.19 +int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
   57.20                    uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
   57.21                    int (*suspend)(int domid));
   57.22  
   57.23 @@ -37,8 +37,8 @@ int xc_linux_save(int xc_handle, int io_
   57.24   * @parm store_mfn returned with the mfn of the store page
   57.25   * @return 0 on success, -1 on failure
   57.26   */
   57.27 -int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom, 
   57.28 -                     unsigned long nr_pfns, unsigned int store_evtchn, 
   57.29 +int xc_linux_restore(int xc_handle, int io_fd, uint32_t dom,
   57.30 +                     unsigned long nr_pfns, unsigned int store_evtchn,
   57.31                       unsigned long *store_mfn, unsigned int console_evtchn,
   57.32                       unsigned long *console_mfn);
   57.33  
    58.1 --- a/tools/libxc/xg_private.c	Mon Apr 17 08:47:36 2006 -0600
    58.2 +++ b/tools/libxc/xg_private.c	Tue Apr 18 09:35:40 2006 -0600
    58.3 @@ -1,6 +1,6 @@
    58.4  /******************************************************************************
    58.5   * xg_private.c
    58.6 - * 
    58.7 + *
    58.8   * Helper functions for the rest of the library.
    58.9   */
   58.10  
    59.1 --- a/tools/libxc/xg_private.h	Mon Apr 17 08:47:36 2006 -0600
    59.2 +++ b/tools/libxc/xg_private.h	Tue Apr 18 09:35:40 2006 -0600
    59.3 @@ -11,7 +11,7 @@
    59.4  #include <sys/stat.h>
    59.5  
    59.6  #include "xenctrl.h"
    59.7 -#include "xenguest.h" 
    59.8 +#include "xenguest.h"
    59.9  
   59.10  #include <xen/linux/privcmd.h>
   59.11  #include <xen/memory.h>
   59.12 @@ -62,7 +62,7 @@ unsigned long csum_page (void * page);
   59.13  #define L2_PAGETABLE_ENTRIES_PAE  512
   59.14  #define L3_PAGETABLE_ENTRIES_PAE    4
   59.15  
   59.16 -#if defined(__i386__) 
   59.17 +#if defined(__i386__)
   59.18  #define L1_PAGETABLE_ENTRIES   1024
   59.19  #define L2_PAGETABLE_ENTRIES   1024
   59.20  #elif defined(__x86_64__)
   59.21 @@ -71,7 +71,7 @@ unsigned long csum_page (void * page);
   59.22  #define L3_PAGETABLE_ENTRIES    512
   59.23  #define L4_PAGETABLE_ENTRIES    512
   59.24  #endif
   59.25 - 
   59.26 +
   59.27  #define PAGE_SHIFT              XC_PAGE_SHIFT
   59.28  #define PAGE_SIZE               (1UL << PAGE_SHIFT)
   59.29  #define PAGE_MASK               (~(PAGE_SIZE-1))
   59.30 @@ -167,8 +167,8 @@ typedef struct mfn_mapper {
   59.31      int error;
   59.32      int max_queue_size;
   59.33      void * addr;
   59.34 -    privcmd_mmap_t ioctl; 
   59.35 -    
   59.36 +    privcmd_mmap_t ioctl;
   59.37 +
   59.38  } mfn_mapper_t;
   59.39  
   59.40  int xc_copy_to_domain_page(int xc_handle, uint32_t domid,
    60.1 --- a/tools/libxc/xg_save_restore.h	Mon Apr 17 08:47:36 2006 -0600
    60.2 +++ b/tools/libxc/xg_save_restore.h	Tue Apr 18 09:35:40 2006 -0600
    60.3 @@ -1,7 +1,7 @@
    60.4  /*
    60.5  ** xg_save_restore.h
    60.6 -** 
    60.7 -** Defintions and utilities for save / restore. 
    60.8 +**
    60.9 +** Defintions and utilities for save / restore.
   60.10  */
   60.11  
   60.12  #include "xc_private.h"
   60.13 @@ -29,8 +29,8 @@ while (0)
   60.14  
   60.15  
   60.16  /*
   60.17 -** We process save/restore/migrate in batches of pages; the below 
   60.18 -** determines how many pages we (at maximum) deal with in each batch. 
   60.19 +** We process save/restore/migrate in batches of pages; the below
   60.20 +** determines how many pages we (at maximum) deal with in each batch.
   60.21  */
   60.22  #define MAX_BATCH_SIZE 1024   /* up to 1024 pages (4MB) at a time */
   60.23  
   60.24 @@ -40,56 +40,56 @@ while (0)
   60.25  
   60.26  
   60.27  /*
   60.28 -** Determine various platform information required for save/restore, in 
   60.29 -** particular: 
   60.30 +** Determine various platform information required for save/restore, in
   60.31 +** particular:
   60.32  **
   60.33 -**    - the maximum MFN on this machine, used to compute the size of 
   60.34 -**      the M2P table; 
   60.35 -** 
   60.36 -**    - the starting virtual address of the the hypervisor; we use this 
   60.37 -**      to determine which parts of guest address space(s) do and don't 
   60.38 -**      require canonicalization during save/restore; and 
   60.39 -** 
   60.40 -**    - the number of page-table levels for save/ restore. This should 
   60.41 -**      be a property of the domain, but for the moment we just read it 
   60.42 +**    - the maximum MFN on this machine, used to compute the size of
   60.43 +**      the M2P table;
   60.44 +**
   60.45 +**    - the starting virtual address of the the hypervisor; we use this
   60.46 +**      to determine which parts of guest address space(s) do and don't
   60.47 +**      require canonicalization during save/restore; and
   60.48 +**
   60.49 +**    - the number of page-table levels for save/ restore. This should
   60.50 +**      be a property of the domain, but for the moment we just read it
   60.51  **      from the hypervisor.
   60.52  **
   60.53 -** Returns 1 on success, 0 on failure. 
   60.54 +** Returns 1 on success, 0 on failure.
   60.55  */
   60.56 -static int get_platform_info(int xc_handle, uint32_t dom, 
   60.57 -                             /* OUT */ unsigned long *max_mfn,  
   60.58 -                             /* OUT */ unsigned long *hvirt_start, 
   60.59 +static int get_platform_info(int xc_handle, uint32_t dom,
   60.60 +                             /* OUT */ unsigned long *max_mfn,
   60.61 +                             /* OUT */ unsigned long *hvirt_start,
   60.62                               /* OUT */ unsigned int *pt_levels)
   60.63 -    
   60.64 -{ 
   60.65 +
   60.66 +{
   60.67      xen_capabilities_info_t xen_caps = "";
   60.68      xen_platform_parameters_t xen_params;
   60.69  
   60.70      if (xc_version(xc_handle, XENVER_platform_parameters, &xen_params) != 0)
   60.71          return 0;
   60.72 -    
   60.73 +
   60.74      if (xc_version(xc_handle, XENVER_capabilities, &xen_caps) != 0)
   60.75          return 0;
   60.76  
   60.77      *max_mfn = xc_memory_op(xc_handle, XENMEM_maximum_ram_page, NULL);
   60.78 -    
   60.79 +
   60.80      *hvirt_start = xen_params.virt_start;
   60.81  
   60.82      if (strstr(xen_caps, "xen-3.0-x86_64"))
   60.83          *pt_levels = 4;
   60.84      else if (strstr(xen_caps, "xen-3.0-x86_32p"))
   60.85 -        *pt_levels = 3; 
   60.86 +        *pt_levels = 3;
   60.87      else if (strstr(xen_caps, "xen-3.0-x86_32"))
   60.88 -        *pt_levels = 2; 
   60.89 -    else 
   60.90 -        return 0; 
   60.91 -    
   60.92 +        *pt_levels = 2;
   60.93 +    else
   60.94 +        return 0;
   60.95 +
   60.96      return 1;
   60.97 -} 
   60.98 +}
   60.99  
  60.100  
  60.101 -/* 
  60.102 -** Save/restore deal with the mfn_to_pfn (M2P) and pfn_to_mfn (P2M) tables. 
  60.103 +/*
  60.104 +** Save/restore deal with the mfn_to_pfn (M2P) and pfn_to_mfn (P2M) tables.
  60.105  ** The M2P simply holds the corresponding PFN, while the top bit of a P2M
  60.106  ** entry tell us whether or not the the PFN is currently mapped.
  60.107  */
  60.108 @@ -98,18 +98,18 @@ static int get_platform_info(int xc_hand
  60.109  #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
  60.110  
  60.111  
  60.112 -/* 
  60.113 -** The M2P is made up of some number of 'chunks' of at least 2MB in size. 
  60.114 -** The below definitions and utility function(s) deal with mapping the M2P 
  60.115 -** regarldess of the underlying machine memory size or architecture. 
  60.116 +/*
  60.117 +** The M2P is made up of some number of 'chunks' of at least 2MB in size.
  60.118 +** The below definitions and utility function(s) deal with mapping the M2P
  60.119 +** regarldess of the underlying machine memory size or architecture.
  60.120  */
  60.121 -#define M2P_SHIFT       L2_PAGETABLE_SHIFT_PAE 
  60.122 -#define M2P_CHUNK_SIZE  (1 << M2P_SHIFT) 
  60.123 -#define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(unsigned long)), M2P_SHIFT) 
  60.124 +#define M2P_SHIFT       L2_PAGETABLE_SHIFT_PAE
  60.125 +#define M2P_CHUNK_SIZE  (1 << M2P_SHIFT)
  60.126 +#define M2P_SIZE(_m)    ROUNDUP(((_m) * sizeof(unsigned long)), M2P_SHIFT)
  60.127  #define M2P_CHUNKS(_m)  (M2P_SIZE((_m)) >> M2P_SHIFT)
  60.128  
  60.129  /* Size in bytes of the P2M (rounded up to the nearest PAGE_SIZE bytes) */
  60.130 -#define P2M_SIZE        ROUNDUP((max_pfn * sizeof(unsigned long)), PAGE_SHIFT) 
  60.131 +#define P2M_SIZE        ROUNDUP((max_pfn * sizeof(unsigned long)), PAGE_SHIFT)
  60.132  
  60.133  /* Number of unsigned longs in a page */
  60.134  #define ulpp            (PAGE_SIZE/sizeof(unsigned long))
  60.135 @@ -127,12 +127,12 @@ static int get_platform_info(int xc_hand
  60.136  #define NR_SLACK_ENTRIES   ((8 * 1024 * 1024) / PAGE_SIZE)
  60.137  
  60.138  /* Is the given PFN within the 'slack' region at the top of the P2M? */
  60.139 -#define IS_REAL_PFN(_pfn)  ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES) 
  60.140 +#define IS_REAL_PFN(_pfn)  ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES)
  60.141  
  60.142  /* Returns TRUE if the PFN is currently mapped */
  60.143  #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
  60.144  
  60.145 -#define INVALID_P2M_ENTRY   (~0UL) 
  60.146 +#define INVALID_P2M_ENTRY   (~0UL)
  60.147  
  60.148  
  60.149  
    61.1 --- a/tools/misc/xen-clone	Mon Apr 17 08:47:36 2006 -0600
    61.2 +++ b/tools/misc/xen-clone	Tue Apr 18 09:35:40 2006 -0600
    61.3 @@ -113,7 +113,7 @@ else
    61.4  
    61.5   # Turn linux into xenolinux then build it
    61.6   cd xenolinux-${LINUX_VER}-sparse
    61.7 - ./mkbuildtree ../../linux-${LINUX_VER}
    61.8 + bash ./mkbuildtree ../../linux-${LINUX_VER}
    61.9   cd ../..
   61.10   mv linux-${LINUX_VER} xenolinux-${LINUX_VER}
   61.11   cd xenolinux-${LINUX_VER}
    62.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Mon Apr 17 08:47:36 2006 -0600
    62.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Tue Apr 18 09:35:40 2006 -0600
    62.3 @@ -589,7 +589,7 @@ static PyObject *xspy_transaction_end(Xs
    62.4  
    62.5  static PyObject *xspy_introduce_domain(XsHandle *self, PyObject *args)
    62.6  {
    62.7 -    domid_t dom;
    62.8 +    uint32_t dom;
    62.9      unsigned long page;
   62.10      unsigned int port;
   62.11  
   62.12 @@ -620,7 +620,7 @@ static PyObject *xspy_introduce_domain(X
   62.13  
   62.14  static PyObject *xspy_release_domain(XsHandle *self, PyObject *args)
   62.15  {
   62.16 -    domid_t dom;
   62.17 +    uint32_t dom;
   62.18  
   62.19      struct xs_handle *xh = xshandle(self);
   62.20      bool result = 0;
   62.21 @@ -677,7 +677,7 @@ static PyObject *xspy_close(XsHandle *se
   62.22  static PyObject *xspy_get_domain_path(XsHandle *self, PyObject *args)
   62.23  {
   62.24      struct xs_handle *xh = xshandle(self);
   62.25 -    int domid;
   62.26 +    uint32_t domid;
   62.27      char *xsval;
   62.28  
   62.29      if (!xh)
    63.1 --- a/tools/python/xen/xend/XendCheckpoint.py	Mon Apr 17 08:47:36 2006 -0600
    63.2 +++ b/tools/python/xen/xend/XendCheckpoint.py	Tue Apr 18 09:35:40 2006 -0600
    63.3 @@ -53,7 +53,7 @@ def read_exact(fd, size, errmsg):
    63.4  
    63.5  
    63.6  
    63.7 -def save(fd, dominfo, live):
    63.8 +def save(fd, dominfo, live, dst):
    63.9      write_exact(fd, SIGNATURE, "could not write guest state file: signature")
   63.10  
   63.11      config = sxp.to_string(dominfo.sxpr())
   63.12 @@ -65,6 +65,8 @@ def save(fd, dominfo, live):
   63.13      dominfo.setName('migrating-' + domain_name)
   63.14  
   63.15      try:
   63.16 +        dominfo.migrateDevices(live, dst, 1, domain_name)
   63.17 +
   63.18          write_exact(fd, pack("!i", len(config)),
   63.19                      "could not write guest state file: config len")
   63.20          write_exact(fd, config, "could not write guest state file: config")
   63.21 @@ -85,7 +87,9 @@ def save(fd, dominfo, live):
   63.22                  log.debug("Suspending %d ...", dominfo.getDomid())
   63.23                  dominfo.shutdown('suspend')
   63.24                  dominfo.waitForShutdown()
   63.25 +                dominfo.migrateDevices(live, dst, 2, domain_name)
   63.26                  log.info("Domain %d suspended.", dominfo.getDomid())
   63.27 +                dominfo.migrateDevices(live, dst, 3, domain_name)
   63.28                  tochild.write("done\n")
   63.29                  tochild.flush()
   63.30                  log.debug('Written done')
    64.1 --- a/tools/python/xen/xend/XendDomain.py	Mon Apr 17 08:47:36 2006 -0600
    64.2 +++ b/tools/python/xen/xend/XendDomain.py	Tue Apr 18 09:35:40 2006 -0600
    64.3 @@ -405,6 +405,9 @@ class XendDomain:
    64.4          if dominfo.getDomid() == PRIV_DOMAIN:
    64.5              raise XendError("Cannot migrate privileged domain %i" % domid)
    64.6  
    64.7 +        """ The following call may raise a XendError exception """
    64.8 +        dominfo.testMigrateDevices(live, dst)
    64.9 +
   64.10          if port == 0:
   64.11              port = xroot.get_xend_relocation_port()
   64.12          try:
   64.13 @@ -414,8 +417,8 @@ class XendDomain:
   64.14              raise XendError("can't connect: %s" % err[1])
   64.15  
   64.16          sock.send("receive\n")
   64.17 -        sock.recv(80) 
   64.18 -        XendCheckpoint.save(sock.fileno(), dominfo, live)
   64.19 +        sock.recv(80)
   64.20 +        XendCheckpoint.save(sock.fileno(), dominfo, live, dst)
   64.21  
   64.22  
   64.23      def domain_save(self, domid, dst):
   64.24 @@ -435,7 +438,7 @@ class XendDomain:
   64.25              fd = os.open(dst, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
   64.26              try:
   64.27                  # For now we don't support 'live checkpoint' 
   64.28 -                return XendCheckpoint.save(fd, dominfo, False)
   64.29 +                return XendCheckpoint.save(fd, dominfo, False, dst)
   64.30              finally:
   64.31                  os.close(fd)
   64.32          except OSError, ex:
    65.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Apr 17 08:47:36 2006 -0600
    65.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Tue Apr 18 09:35:40 2006 -0600
    65.3 @@ -1395,6 +1395,38 @@ class XendDomainInfo:
    65.4          if self.image:
    65.5              self.image.createDeviceModel()
    65.6  
    65.7 +    ## public:
    65.8 +
    65.9 +    def testMigrateDevices(self, live, dst):
   65.10 +        """ Notify all device about intention of migration
   65.11 +        @raise: XendError for a device that cannot be migrated
   65.12 +        """
   65.13 +        for (n, c) in self.info['device']:
   65.14 +            rc = self.migrateDevice(n, c, live, dst, 0)
   65.15 +            if rc != 0:
   65.16 +                raise XendError("Device of type '%s' refuses migration." % n)
   65.17 +
   65.18 +    def migrateDevices(self, live, dst, step, domName=''):
   65.19 +        """Notify the devices about migration
   65.20 +        """
   65.21 +        ctr = 0
   65.22 +        try:
   65.23 +            for (n, c) in self.info['device']:
   65.24 +                self.migrateDevice(n, c, live, dst, step, domName)
   65.25 +                ctr = ctr + 1
   65.26 +        except:
   65.27 +            for (n, c) in self.info['device']:
   65.28 +                if ctr == 0:
   65.29 +                    step = step - 1
   65.30 +                ctr = ctr - 1
   65.31 +                self.recoverMigrateDevice(n, c, live, dst, step, domName)
   65.32 +            raise
   65.33 +
   65.34 +    def migrateDevice(self, deviceClass, deviceConfig, live, dst, step, domName=''):
   65.35 +        return self.getDeviceController(deviceClass).migrate(deviceConfig, live, dst, step, domName)
   65.36 +
   65.37 +    def recoverMigrateDevice(self, deviceClass, deviceConfig, live, dst, step, domName=''):
   65.38 +        return self.getDeviceController(deviceClass).recover_migrate(deviceConfig, live, dst, step, domName)
   65.39  
   65.40      def waitForDevices(self):
   65.41          """Wait for this domain's configured devices to connect.
    66.1 --- a/tools/python/xen/xend/XendRoot.py	Mon Apr 17 08:47:36 2006 -0600
    66.2 +++ b/tools/python/xen/xend/XendRoot.py	Tue Apr 18 09:35:40 2006 -0600
    66.3 @@ -86,6 +86,9 @@ class XendRoot:
    66.4      server (deprecated)."""
    66.5      xend_unix_server_default = 'no'
    66.6  
    66.7 +    """Default external migration tool """
    66.8 +    external_migration_tool_default = ''
    66.9 +
   66.10      """Default path the unix-domain server listens at."""
   66.11      xend_unix_path_default = '/var/lib/xend/xend-socket'
   66.12  
   66.13 @@ -250,6 +253,9 @@ class XendRoot:
   66.14          else:
   66.15              return None
   66.16  
   66.17 +    def get_external_migration_tool(self):
   66.18 +        """@return the name of the tool to handle virtual TPM migration."""
   66.19 +        return self.get_config_value('external-migration-tool', self.external_migration_tool_default)
   66.20  
   66.21      def get_enable_dump(self):
   66.22          return self.get_config_bool('enable-dump', 'no')
    67.1 --- a/tools/python/xen/xend/server/DevController.py	Mon Apr 17 08:47:36 2006 -0600
    67.2 +++ b/tools/python/xen/xend/server/DevController.py	Tue Apr 18 09:35:40 2006 -0600
    67.3 @@ -267,6 +267,41 @@ class DevController:
    67.4  
    67.5          raise NotImplementedError()
    67.6  
    67.7 +    def migrate(self, deviceConfig, live, dst, step, domName):
    67.8 +        """ Migration of a device. The 'live' parameter indicates
    67.9 +            whether the device is live-migrated (live=1). 'dst' then gives
   67.10 +            the hostname of the machine to migrate to.
   67.11 +        This function is called for 4 steps:
   67.12 +        If step == 0: Check whether the device is ready to be migrated
   67.13 +                      or can at all be migrated; return a '-1' if
   67.14 +                      the device is NOT ready, a '0' otherwise. If it is
   67.15 +                      not ready ( = not possible to migrate this device),
   67.16 +                      migration will not take place.
   67.17 +           step == 1: Called immediately after step 0; migration
   67.18 +                      of the kernel has started;
   67.19 +           step == 2: Called after the suspend has been issued
   67.20 +                      to the domain and the domain is not scheduled anymore.
   67.21 +                      Synchronize with what was started in step 1, if necessary.
   67.22 +                      Now the device should initiate its transfer to the
   67.23 +                      given target. Since there might be more than just
   67.24 +                      one device initiating a migration, this step should
   67.25 +                      put the process performing the transfer into the
   67.26 +                      background and return immediately to achieve as much
   67.27 +                      concurrency as possible.
   67.28 +           step == 3: Synchronize with the migration of the device that
   67.29 +                      was initiated in step 2.
   67.30 +                      Make sure that the migration has finished and only
   67.31 +                      then return from the call.
   67.32 +        """
   67.33 +        return 0
   67.34 +
   67.35 +
   67.36 +    def recover_migrate(self, deviceConfig, list, dst, step, domName):
   67.37 +        """ Recover from device migration. The given step was the
   67.38 +            last one that was successfully executed.
   67.39 +        """
   67.40 +        return 0
   67.41 +
   67.42  
   67.43      def getDomid(self):
   67.44          """Stub to {@link XendDomainInfo.getDomid}, for use by our
    68.1 --- a/tools/python/xen/xend/server/tpmif.py	Mon Apr 17 08:47:36 2006 -0600
    68.2 +++ b/tools/python/xen/xend/server/tpmif.py	Tue Apr 18 09:35:40 2006 -0600
    68.3 @@ -23,9 +23,17 @@
    68.4  
    68.5  from xen.xend import sxp
    68.6  from xen.xend.XendLogging import log
    68.7 +from xen.xend.XendError import XendError
    68.8 +from xen.xend import XendRoot
    68.9  
   68.10  from xen.xend.server.DevController import DevController
   68.11  
   68.12 +import os
   68.13 +import re
   68.14 +
   68.15 +
   68.16 +xroot = XendRoot.instance()
   68.17 +
   68.18  
   68.19  class TPMifController(DevController):
   68.20      """TPM interface controller. Handles all TPM devices for a domain.
   68.21 @@ -61,3 +69,43 @@ class TPMifController(DevController):
   68.22              result.append(['instance', instance])
   68.23  
   68.24          return result
   68.25 +
   68.26 +    def migrate(self, deviceConfig, live, dst, step, domName):
   68.27 +        """@see DevContoller.migrate"""
   68.28 +        if live:
   68.29 +            tool = xroot.get_external_migration_tool()
   68.30 +            if tool != '':
   68.31 +                log.info("Request to live-migrate device to %s. step=%d.",
   68.32 +                         dst, step)
   68.33 +
   68.34 +                if step == 0:
   68.35 +                    """Assuming for now that everything is ok and migration
   68.36 +                       with the given tool can proceed.
   68.37 +                    """
   68.38 +                    return 0
   68.39 +                else:
   68.40 +                    fd = os.popen("%s -type vtpm -step %d -host %s -domname %s" %
   68.41 +                                  (tool, step, dst, domName),
   68.42 +                                  'r')
   68.43 +                    for line in fd.readlines():
   68.44 +                        mo = re.search('Error', line)
   68.45 +                        if mo:
   68.46 +                            raise XendError("vtpm: Fatal error in migration step %d." %
   68.47 +                                            step)
   68.48 +                    return 0
   68.49 +            else:
   68.50 +                log.debug("External migration tool not in configuration.")
   68.51 +                return -1
   68.52 +        return 0
   68.53 +
   68.54 +    def recover_migrate(self, deviceConfig, live, dst, step, domName):
   68.55 +        """@see DevContoller.recover_migrate"""
   68.56 +        if live:
   68.57 +            tool = xroot.get_external_migration_tool()
   68.58 +            if tool != '':
   68.59 +                log.info("Request to recover live-migrated device. last good step=%d.",
   68.60 +                         step)
   68.61 +                fd = os.popen("%s -type vtpm -step %d -host %s -domname %s -recover" %
   68.62 +                              (tool, step, dst, domName),
   68.63 +                              'r')
   68.64 +        return 0
    69.1 --- a/tools/python/xen/xm/create.py	Mon Apr 17 08:47:36 2006 -0600
    69.2 +++ b/tools/python/xen/xm/create.py	Tue Apr 18 09:35:40 2006 -0600
    69.3 @@ -158,7 +158,7 @@ gopts.var('cpu', val='CPU',
    69.4            use="CPU to run the VCPU0 on.")
    69.5  
    69.6  gopts.var('cpus', val='CPUS',
    69.7 -          fn=set_int, default=None,
    69.8 +          fn=set_value, default=None,
    69.9            use="CPUS to run the domain on.")
   69.10  
   69.11  gopts.var('pae', val='PAE',
    70.1 --- a/tools/xenmon/README	Mon Apr 17 08:47:36 2006 -0600
    70.2 +++ b/tools/xenmon/README	Tue Apr 18 09:35:40 2006 -0600
    70.3 @@ -84,6 +84,16 @@ Usage Notes and issues
    70.4     events cause a trace record to be emitted.
    70.5   - To exit xenmon, type 'q'
    70.6   - To cycle the display to other physical cpu's, type 'c'
    70.7 + - The first time xenmon is run, it attempts to allocate xen trace buffers
    70.8 +   using a default size. If you wish to use a non-default value for the
    70.9 +   trace buffer size, run the 'setsize' program (located in tools/xentrace)
   70.10 +   and specify the number of memory pages as a parameter. The default is 20.
   70.11 + - Not well tested with domains using more than 1 virtual cpu
   70.12 + - If you create a lot of domains, or repeatedly kill a domain and restart it,
   70.13 +   and the domain id's get to be bigger than NDOMAINS, then xenmon behaves badly.
   70.14 +   This is a bug that is due to xenbaked's treatment of domain id's vs. domain
   70.15 +   indices in a data array. Will be fixed in a future release; Workaround:
   70.16 +   Increase NDOMAINS in xenbaked and rebuild.
   70.17  
   70.18  Future Work
   70.19  -----------
    71.1 --- a/tools/xenmon/xenbaked.c	Mon Apr 17 08:47:36 2006 -0600
    71.2 +++ b/tools/xenmon/xenbaked.c	Tue Apr 18 09:35:40 2006 -0600
    71.3 @@ -7,6 +7,7 @@
    71.4   *
    71.5   * Copyright (C) 2004 by Intel Research Cambridge
    71.6   * Copyright (C) 2005 by Hewlett Packard, Palo Alto and Fort Collins
    71.7 + * Copyright (C) 2006 by Hewlett Packard Fort Collins
    71.8   *
    71.9   * Authors: Diwaker Gupta, diwaker.gupta@hp.com
   71.10   *          Rob Gardner, rob.gardner@hp.com
   71.11 @@ -42,6 +43,8 @@
   71.12  #include <xenctrl.h>
   71.13  #include <xen/xen.h>
   71.14  #include <string.h>
   71.15 +#include <sys/select.h>
   71.16 +#include <xen/linux/evtchn.h>
   71.17  
   71.18  #include "xc_private.h"
   71.19  typedef struct { int counter; } atomic_t;
   71.20 @@ -81,6 +84,7 @@ settings_t opts;
   71.21  
   71.22  int interrupted = 0; /* gets set if we get a SIGHUP */
   71.23  int rec_count = 0;
   71.24 +int wakeups = 0;
   71.25  time_t start_time;
   71.26  int dom0_flips = 0;
   71.27  
   71.28 @@ -88,8 +92,6 @@ int dom0_flips = 0;
   71.29  _new_qos_data **cpu_qos_data;
   71.30  
   71.31  
   71.32 -#define ID(X) ((X>NDOMAINS-1)?(NDOMAINS-1):X)
   71.33 -
   71.34  // array of currently running domains, indexed by cpu
   71.35  int *running = NULL;
   71.36  
   71.37 @@ -223,6 +225,9 @@ void dump_stats(void)
   71.38      printf("processed %d total records in %d seconds (%ld per second)\n",
   71.39              rec_count, (int)run_time, rec_count/run_time);
   71.40  
   71.41 +    printf("woke up %d times in %d seconds (%ld per second)\n", wakeups,
   71.42 +	   (int) run_time, wakeups/run_time);
   71.43 +
   71.44      check_gotten_sum();
   71.45  }
   71.46  
   71.47 @@ -243,6 +248,112 @@ void log_event(int event_id)
   71.48          stat_map[0].event_count++;	// other
   71.49  }
   71.50  
   71.51 +#define EVTCHN_DEV_NAME  "/dev/xen/evtchn"
   71.52 +#define EVTCHN_DEV_MAJOR 10
   71.53 +#define EVTCHN_DEV_MINOR 201
   71.54 +
   71.55 +int virq_port;
   71.56 +int eventchn_fd = -1;
   71.57 +
   71.58 +/* Returns the event channel handle. */
   71.59 +/* Stolen from xenstore code */
   71.60 +int eventchn_init(void)
   71.61 +{
   71.62 +  struct stat st;
   71.63 +  struct ioctl_evtchn_bind_virq bind;
   71.64 +  int rc;
   71.65 +  
   71.66 +  // to revert to old way:
   71.67 +  if (0)
   71.68 +    return -1;
   71.69 +  
   71.70 +  /* Make sure any existing device file links to correct device. */
   71.71 +  if ((lstat(EVTCHN_DEV_NAME, &st) != 0) || !S_ISCHR(st.st_mode) ||
   71.72 +      (st.st_rdev != makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)))
   71.73 +    (void)unlink(EVTCHN_DEV_NAME);
   71.74 +  
   71.75 + reopen:
   71.76 +  eventchn_fd = open(EVTCHN_DEV_NAME, O_NONBLOCK|O_RDWR);
   71.77 +  if (eventchn_fd == -1) {
   71.78 +    if ((errno == ENOENT) &&
   71.79 +	((mkdir("/dev/xen", 0755) == 0) || (errno == EEXIST)) &&
   71.80 +	(mknod(EVTCHN_DEV_NAME, S_IFCHR|0600,
   71.81 +	       makedev(EVTCHN_DEV_MAJOR, EVTCHN_DEV_MINOR)) == 0))
   71.82 +      goto reopen;
   71.83 +    return -errno;
   71.84 +  }
   71.85 +  
   71.86 +  if (eventchn_fd < 0)
   71.87 +    perror("Failed to open evtchn device");
   71.88 +  
   71.89 +  bind.virq = VIRQ_TBUF;
   71.90 +  rc = ioctl(eventchn_fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
   71.91 +  if (rc == -1)
   71.92 +    perror("Failed to bind to domain exception virq port");
   71.93 +  virq_port = rc;
   71.94 +  
   71.95 +  return eventchn_fd;
   71.96 +}
   71.97 +
   71.98 +void wait_for_event(void)
   71.99 +{
  71.100 +  int ret;
  71.101 +  fd_set inset;
  71.102 +  evtchn_port_t port;
  71.103 +  struct timeval tv;
  71.104 +  
  71.105 +  if (eventchn_fd < 0) {
  71.106 +    nanosleep(&opts.poll_sleep, NULL);
  71.107 +    return;
  71.108 +  }
  71.109 +
  71.110 +  FD_ZERO(&inset);
  71.111 +  FD_SET(eventchn_fd, &inset);
  71.112 +  tv.tv_sec = 1;
  71.113 +  tv.tv_usec = 0;
  71.114 +  // tv = millis_to_timespec(&opts.poll_sleep);
  71.115 +  ret = select(eventchn_fd+1, &inset, NULL, NULL, &tv);
  71.116 +  
  71.117 +  if ( (ret == 1) && FD_ISSET(eventchn_fd, &inset)) {
  71.118 +    if (read(eventchn_fd, &port, sizeof(port)) != sizeof(port))
  71.119 +      perror("Failed to read from event fd");
  71.120 +    
  71.121 +    //    if (port == virq_port)
  71.122 +    //      printf("got the event I was looking for\r\n");
  71.123 +    
  71.124 +    if (write(eventchn_fd, &port, sizeof(port)) != sizeof(port))
  71.125 +      perror("Failed to write to event fd");
  71.126 +  }
  71.127 +}
  71.128 +
  71.129 +void enable_tracing_or_die(int xc_handle) 
  71.130 +{
  71.131 +  int enable = 1;
  71.132 +  int tbsize = DEFAULT_TBUF_SIZE;
  71.133 +  
  71.134 +  if (xc_tbuf_enable(xc_handle, enable) != 0) {
  71.135 +    if (xc_tbuf_set_size(xc_handle, tbsize) != 0) {
  71.136 +      perror("set_size Hypercall failure");
  71.137 +      exit(1);
  71.138 +    }
  71.139 +    printf("Set default trace buffer allocation (%d pages)\n", tbsize);
  71.140 +    if (xc_tbuf_enable(xc_handle, enable) != 0) {
  71.141 +      perror("Could not enable trace buffers\n");
  71.142 +      exit(1);
  71.143 +    }
  71.144 +  }
  71.145 +  else
  71.146 +    printf("Tracing enabled\n");
  71.147 +}
  71.148 +
  71.149 +void disable_tracing(void)
  71.150 +{
  71.151 +  int enable = 0;
  71.152 +  int xc_handle = xc_interface_open();
  71.153 +    
  71.154 +  xc_tbuf_enable(xc_handle, enable);
  71.155 +  xc_interface_close(xc_handle);
  71.156 +}
  71.157  
  71.158  
  71.159  /**
  71.160 @@ -258,6 +369,17 @@ void get_tbufs(unsigned long *mfn, unsig
  71.161      int ret;
  71.162      dom0_op_t op;                        /* dom0 op we'll build             */
  71.163      int xc_handle = xc_interface_open(); /* for accessing control interface */
  71.164 +    unsigned int tbsize;
  71.165 +
  71.166 +    enable_tracing_or_die(xc_handle);
  71.167 +
  71.168 +    if (xc_tbuf_get_size(xc_handle, &tbsize) != 0) {
  71.169 +      perror("Failure to get tbuf info from Xen. Guess size is 0?");
  71.170 +      exit(1);
  71.171 +    }
  71.172 +    else
  71.173 +      printf("Current tbuf size: 0x%x\n", tbsize);
  71.174 +    
  71.175  
  71.176      op.cmd = DOM0_TBUFCONTROL;
  71.177      op.interface_version = DOM0_INTERFACE_VERSION;
  71.178 @@ -448,6 +570,11 @@ int monitor_tbufs(void)
  71.179      meta  = init_bufs_ptrs (tbufs_mapped, num, size);
  71.180      data  = init_rec_ptrs(meta, num);
  71.181  
  71.182 +    // Set up event channel for select()
  71.183 +    if (eventchn_init() < 0) {
  71.184 +      fprintf(stderr, "Failed to initialize event channel; Using POLL method\r\n");
  71.185 +    }
  71.186 +
  71.187      /* now, scan buffers for events */
  71.188      while ( !interrupted )
  71.189      {
  71.190 @@ -460,7 +587,8 @@ int monitor_tbufs(void)
  71.191                  meta[i]->cons++;
  71.192              }
  71.193  
  71.194 -        nanosleep(&opts.poll_sleep, NULL);
  71.195 +	wait_for_event();
  71.196 +	wakeups++;
  71.197      }
  71.198  
  71.199      /* cleanup */
  71.200 @@ -640,6 +768,7 @@ int main(int argc, char **argv)
  71.201  
  71.202      dump_stats();
  71.203      msync(new_qos, sizeof(_new_qos_data), MS_SYNC);
  71.204 +    disable_tracing();
  71.205  
  71.206      return ret;
  71.207  }
  71.208 @@ -737,7 +866,9 @@ void qos_update_thread(int cpu, int domi
  71.209          start = new_qos->domain_info[id].start_time;
  71.210          if (start > now) {		// wrapped around
  71.211              run_time = now + (~0ULL - start);
  71.212 -	    printf("warning: start > now\n");
  71.213 +	    // this could happen if there is nothing going on within a cpu;
  71.214 +	    // in this case the idle domain would run forever
  71.215 +	    //        printf("warning: start > now\n");
  71.216          }
  71.217          else
  71.218              run_time = now - start;
  71.219 @@ -746,11 +877,11 @@ void qos_update_thread(int cpu, int domi
  71.220          new_qos->domain_info[id].ns_oncpu_since_boot += run_time;
  71.221          new_qos->domain_info[id].start_time = now;
  71.222          new_qos->domain_info[id].ns_since_boot += time_since_update;
  71.223 -#if 1
  71.224 +
  71.225  	new_qos->qdata[n].ns_gotten[id] += run_time;
  71.226 -	if (domid == 0 && cpu == 1)
  71.227 -	  printf("adding run time for dom0 on cpu1\r\n");
  71.228 -#endif
  71.229 +	//	if (domid == 0 && cpu == 1)
  71.230 +	//	  printf("adding run time for dom0 on cpu1\r\n");
  71.231 +
  71.232      }
  71.233  
  71.234      new_qos->domain_info[id].runnable_at_last_update = domain_runnable(domid);
  71.235 @@ -916,13 +1047,13 @@ void qos_state_runnable(int cpu, int dom
  71.236  {
  71.237      int id = ID(domid);
  71.238  
  71.239 +    qos_update_thread_stats(cpu, domid, now);
  71.240 +
  71.241      if (domain_runnable(id))	// double call?
  71.242          return;
  71.243      new_qos->domain_info[id].runnable = 1;
  71.244      update_blocked_time(domid, now);
  71.245  
  71.246 -    qos_update_thread_stats(cpu, domid, now);
  71.247 -
  71.248      new_qos->domain_info[id].blocked_start_time = 0; /* invalidate */
  71.249      new_qos->domain_info[id].runnable_start_time = now;
  71.250      //  runnable_start_time[id] = now;
  71.251 @@ -951,7 +1082,7 @@ int domain_ok(int cpu, int domid, uint64
  71.252      if (domid == IDLE_DOMAIN_ID)
  71.253          domid = NDOMAINS-1;
  71.254      if (domid < 0 || domid >= NDOMAINS) {
  71.255 -        printf("bad domain id: %d\n", domid);
  71.256 +        printf("bad domain id: %d\r\n", domid);
  71.257          return 0;
  71.258      }
  71.259      if (new_qos->domain_info[domid].in_use == 0)
    72.1 --- a/tools/xenmon/xenbaked.h	Mon Apr 17 08:47:36 2006 -0600
    72.2 +++ b/tools/xenmon/xenbaked.h	Tue Apr 18 09:35:40 2006 -0600
    72.3 @@ -1,5 +1,5 @@
    72.4  /******************************************************************************
    72.5 - * tools/xenbaked.h
    72.6 + * TOOLS/xenbaked.h
    72.7   *
    72.8   * Header file for xenbaked
    72.9   *
   72.10 @@ -30,6 +30,7 @@
   72.11  #define million 1000000LL
   72.12  #define billion 1000000000LL
   72.13  
   72.14 +// caution: don't use QOS_ADD with negative numbers!
   72.15  #define QOS_ADD(N,A) ((N+A)<(NSAMPLES-1) ? (N+A) : A)
   72.16  #define QOS_INCR(N) ((N<(NSAMPLES-2)) ? (N+1) : 0)
   72.17  #define QOS_DECR(N) ((N==0) ? (NSAMPLES-1) : (N-1))
   72.18 @@ -43,6 +44,8 @@
   72.19  /* Number of data points to keep */
   72.20  #define NSAMPLES 100
   72.21  
   72.22 +#define ID(X) ((X>NDOMAINS-1)?(NDOMAINS-1):X)
   72.23 +#define DEFAULT_TBUF_SIZE 20
   72.24  
   72.25  // per domain stuff
   72.26  typedef struct 
    73.1 --- a/tools/xenmon/xenmon.py	Mon Apr 17 08:47:36 2006 -0600
    73.2 +++ b/tools/xenmon/xenmon.py	Tue Apr 18 09:35:40 2006 -0600
    73.3 @@ -5,7 +5,7 @@
    73.4  # There is a curses interface for live monitoring. XenMon also allows
    73.5  # logging to a file. For options, run python xenmon.py -h
    73.6  #
    73.7 -# Copyright (C) 2005 by Hewlett Packard, Palo Alto and Fort Collins
    73.8 +# Copyright (C) 2005,2006 by Hewlett Packard, Palo Alto and Fort Collins
    73.9  # Authors: Lucy Cherkasova, lucy.cherkasova@hp.com
   73.10  #          Rob Gardner, rob.gardner@hp.com
   73.11  #          Diwaker Gupta, diwaker.gupta@hp.com
   73.12 @@ -85,6 +85,33 @@ def setup_cmdline_parser():
   73.13      parser.add_option("--ms_per_sample", dest="mspersample",
   73.14              action="store", type="int", default=100,
   73.15              help = "determines how many ms worth of data goes in a sample")
   73.16 +    parser.add_option("--cpu", dest="cpu", action="store", type="int", default=0,
   73.17 +            help = "specifies which cpu to display data for")
   73.18 +
   73.19 +    parser.add_option("--allocated", dest="allocated", action="store_true",
   73.20 +                      default=False, help="Display allocated time for each domain")
   73.21 +    parser.add_option("--noallocated", dest="allocated", action="store_false",
   73.22 +                      default=False, help="Don't display allocated time for each domain")
   73.23 +
   73.24 +    parser.add_option("--blocked", dest="blocked", action="store_true",
   73.25 +                      default=True, help="Display blocked time for each domain")
   73.26 +    parser.add_option("--noblocked", dest="blocked", action="store_false",
   73.27 +                      default=True, help="Don't display blocked time for each domain")
   73.28 +
   73.29 +    parser.add_option("--waited", dest="waited", action="store_true",
   73.30 +                      default=True, help="Display waiting time for each domain")
   73.31 +    parser.add_option("--nowaited", dest="waited", action="store_false",
   73.32 +                      default=True, help="Don't display waiting time for each domain")
   73.33 +
   73.34 +    parser.add_option("--excount", dest="excount", action="store_true",
   73.35 +                      default=False, help="Display execution count for each domain")
   73.36 +    parser.add_option("--noexcount", dest="excount", action="store_false",
   73.37 +                      default=False, help="Don't display execution count for each domain")
   73.38 +    parser.add_option("--iocount", dest="iocount", action="store_true",
   73.39 +                      default=False, help="Display I/O count for each domain")
   73.40 +    parser.add_option("--noiocount", dest="iocount", action="store_false",
   73.41 +                      default=False, help="Don't display I/O count for each domain")
   73.42 +
   73.43      return parser
   73.44  
   73.45  # encapsulate information about a domain
   73.46 @@ -227,20 +254,18 @@ def display(scr, row, col, str, attr=0):
   73.47  
   73.48  
   73.49  # the live monitoring code
   73.50 -def show_livestats():
   73.51 -    cpu = 0          # cpu of interest to display data for
   73.52 +def show_livestats(cpu):
   73.53      ncpu = 1         # number of cpu's on this platform
   73.54      slen = 0         # size of shared data structure, incuding padding
   73.55 -    global dom_in_use
   73.56 +    cpu_1sec_usage = 0.0
   73.57 +    cpu_10sec_usage = 0.0
   73.58 +    heartbeat = 1
   73.59 +    global dom_in_use, options
   73.60      
   73.61      # mmap the (the first chunk of the) file
   73.62      shmf = open(SHM_FILE, "r+")
   73.63      shm = mmap.mmap(shmf.fileno(), QOS_DATA_SIZE)
   73.64  
   73.65 -    samples = []
   73.66 -    doms = []
   73.67 -    dom_in_use = []
   73.68 -
   73.69      # initialize curses
   73.70      stdscr = _c.initscr()
   73.71      _c.noecho()
   73.72 @@ -253,7 +278,8 @@ def show_livestats():
   73.73      # display in a loop
   73.74      while True:
   73.75  
   73.76 -        for cpuidx in range(0, ncpu):
   73.77 +        cpuidx = 0
   73.78 +        while cpuidx < ncpu:
   73.79  
   73.80              # calculate offset in mmap file to start from
   73.81              idx = cpuidx * slen
   73.82 @@ -261,6 +287,7 @@ def show_livestats():
   73.83  
   73.84              samples = []
   73.85              doms = []
   73.86 +            dom_in_use = []
   73.87  
   73.88              # read in data
   73.89              for i in range(0, NSAMPLES):
   73.90 @@ -279,6 +306,8 @@ def show_livestats():
   73.91  #		dom_in_use.append(in_use)
   73.92                  dom_in_use.append(dom[8])
   73.93                  idx += len
   73.94 +#            print "dom_in_use(cpu=%d): " % cpuidx, dom_in_use
   73.95 +
   73.96  
   73.97              len = struct.calcsize("4i")
   73.98              oldncpu = ncpu
   73.99 @@ -295,6 +324,8 @@ def show_livestats():
  73.100              if cpuidx == cpu:
  73.101                  break
  73.102  
  73.103 +            cpuidx = cpuidx + 1
  73.104 +
  73.105          # calculate starting and ending datapoints; never look at "next" since
  73.106          # it represents live data that may be in transition. 
  73.107          startat = next - 1
  73.108 @@ -312,13 +343,16 @@ def show_livestats():
  73.109          row = 0
  73.110          display(stdscr, row, 1, "CPU = %d" % cpu, _c.A_STANDOUT)
  73.111  
  73.112 -        display(stdscr, row, 10, "%sLast 10 seconds%sLast 1 second" % (6*' ', 30*' '), _c.A_BOLD)
  73.113 +        display(stdscr, row, 10, "%sLast 10 seconds (%3.2f%%)%sLast 1 second (%3.2f%%)" % (6*' ', cpu_10sec_usage, 30*' ', cpu_1sec_usage), _c.A_BOLD)
  73.114          row +=1
  73.115          display(stdscr, row, 1, "%s" % ((maxx-2)*'='))
  73.116  
  73.117          total_h1_cpu = 0
  73.118          total_h2_cpu = 0
  73.119  
  73.120 +        cpu_1sec_usage = 0.0
  73.121 +        cpu_10sec_usage = 0.0
  73.122 +
  73.123          for dom in range(0, NDOMAINS):
  73.124              if not dom_in_use[dom]:
  73.125                  continue
  73.126 @@ -332,92 +366,102 @@ def show_livestats():
  73.127                  display(stdscr, row, col, "%s" % time_scale(h2[dom][0][0]))
  73.128                  col += 12
  73.129                  display(stdscr, row, col, "%3.2f%%" % h2[dom][0][1])
  73.130 +                if dom != NDOMAINS - 1:
  73.131 +                    cpu_10sec_usage += h2[dom][0][1]
  73.132                  col += 12
  73.133                  display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][0][2]))
  73.134                  col += 18
  73.135                  display(stdscr, row, col, "%s" % time_scale(h1[dom][0][0]))
  73.136                  col += 12
  73.137 -                display(stdscr, row, col, "%3.2f%%" % h1[dom][0][1])
  73.138 +                display(stdscr, row, col, "%3.2f%%" % h1[dom][0][1], _c.A_STANDOUT)
  73.139                  col += 12
  73.140                  display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][0][2]))
  73.141                  col += 18
  73.142                  display(stdscr, row, col, "Gotten")
  73.143 +
  73.144 +                if dom != NDOMAINS - 1:
  73.145 +                    cpu_1sec_usage = cpu_1sec_usage + h1[dom][0][1]
  73.146      
  73.147                  # display allocated
  73.148 -                row += 1
  73.149 -                col = 2
  73.150 -                display(stdscr, row, col, "%d" % dom)
  73.151 -                col += 28
  73.152 -                display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][1]))
  73.153 -                col += 42
  73.154 -                display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][1]))
  73.155 -                col += 18
  73.156 -                display(stdscr, row, col, "Allocated")
  73.157 +                if options.allocated:
  73.158 +                    row += 1
  73.159 +                    col = 2
  73.160 +                    display(stdscr, row, col, "%d" % dom)
  73.161 +                    col += 28
  73.162 +                    display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][1]))
  73.163 +                    col += 42
  73.164 +                    display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][1]))
  73.165 +                    col += 18
  73.166 +                    display(stdscr, row, col, "Allocated")
  73.167  
  73.168                  # display blocked
  73.169 -                row += 1
  73.170 -                col = 2
  73.171 -                display(stdscr, row, col, "%d" % dom)
  73.172 -                col += 4
  73.173 -                display(stdscr, row, col, "%s" % time_scale(h2[dom][2][0]))
  73.174 -                col += 12
  73.175 -                display(stdscr, row, col, "%3.2f%%" % h2[dom][2][1])
  73.176 -                col += 12
  73.177 -                display(stdscr, row, col, "%s/io" % time_scale(h2[dom][2][2]))
  73.178 -                col += 18
  73.179 -                display(stdscr, row, col, "%s" % time_scale(h1[dom][2][0]))
  73.180 -                col += 12
  73.181 -                display(stdscr, row, col, "%3.2f%%" % h1[dom][2][1])
  73.182 -                col += 12
  73.183 -                display(stdscr, row, col, "%s/io" % time_scale(h1[dom][2][2]))
  73.184 -                col += 18
  73.185 -                display(stdscr, row, col, "Blocked")
  73.186 +                if options.blocked:
  73.187 +                    row += 1
  73.188 +                    col = 2
  73.189 +                    display(stdscr, row, col, "%d" % dom)
  73.190 +                    col += 4
  73.191 +                    display(stdscr, row, col, "%s" % time_scale(h2[dom][2][0]))
  73.192 +                    col += 12
  73.193 +                    display(stdscr, row, col, "%3.2f%%" % h2[dom][2][1])
  73.194 +                    col += 12
  73.195 +                    display(stdscr, row, col, "%s/io" % time_scale(h2[dom][2][2]))
  73.196 +                    col += 18
  73.197 +                    display(stdscr, row, col, "%s" % time_scale(h1[dom][2][0]))
  73.198 +                    col += 12
  73.199 +                    display(stdscr, row, col, "%3.2f%%" % h1[dom][2][1])
  73.200 +                    col += 12
  73.201 +                    display(stdscr, row, col, "%s/io" % time_scale(h1[dom][2][2]))
  73.202 +                    col += 18
  73.203 +                    display(stdscr, row, col, "Blocked")
  73.204  
  73.205                  # display waited
  73.206 -                row += 1
  73.207 -                col = 2
  73.208 -                display(stdscr, row, col, "%d" % dom)
  73.209 -                col += 4
  73.210 -                display(stdscr, row, col, "%s" % time_scale(h2[dom][3][0]))
  73.211 -                col += 12
  73.212 -                display(stdscr, row, col, "%3.2f%%" % h2[dom][3][1])
  73.213 -                col += 12
  73.214 -                display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][3][2]))
  73.215 -                col += 18
  73.216 -                display(stdscr, row, col, "%s" % time_scale(h1[dom][3][0]))
  73.217 -                col += 12
  73.218 -                display(stdscr, row, col, "%3.2f%%" % h1[dom][3][1])
  73.219 -                col += 12
  73.220 -                display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][3][2]))
  73.221 -                col += 18
  73.222 -                display(stdscr, row, col, "Waited")
  73.223 +                if options.waited:
  73.224 +                    row += 1
  73.225 +                    col = 2
  73.226 +                    display(stdscr, row, col, "%d" % dom)
  73.227 +                    col += 4
  73.228 +                    display(stdscr, row, col, "%s" % time_scale(h2[dom][3][0]))
  73.229 +                    col += 12
  73.230 +                    display(stdscr, row, col, "%3.2f%%" % h2[dom][3][1])
  73.231 +                    col += 12
  73.232 +                    display(stdscr, row, col, "%s/ex" % time_scale(h2[dom][3][2]))
  73.233 +                    col += 18
  73.234 +                    display(stdscr, row, col, "%s" % time_scale(h1[dom][3][0]))
  73.235 +                    col += 12
  73.236 +                    display(stdscr, row, col, "%3.2f%%" % h1[dom][3][1])
  73.237 +                    col += 12
  73.238 +                    display(stdscr, row, col, "%s/ex" % time_scale(h1[dom][3][2]))
  73.239 +                    col += 18
  73.240 +                    display(stdscr, row, col, "Waited")
  73.241  
  73.242                  # display ex count
  73.243 -                row += 1
  73.244 -                col = 2
  73.245 -                display(stdscr, row, col, "%d" % dom)
  73.246 -
  73.247 -                col += 28
  73.248 -                display(stdscr, row, col, "%d/s" % h2[dom][4])
  73.249 -                col += 42
  73.250 -                display(stdscr, row, col, "%d" % h1[dom][4])
  73.251 -                col += 18
  73.252 -                display(stdscr, row, col, "Execution count")
  73.253 +                if options.excount:
  73.254 +                    row += 1
  73.255 +                    col = 2
  73.256 +                    display(stdscr, row, col, "%d" % dom)
  73.257 +                    
  73.258 +                    col += 28
  73.259 +                    display(stdscr, row, col, "%d/s" % h2[dom][4])
  73.260 +                    col += 42
  73.261 +                    display(stdscr, row, col, "%d" % h1[dom][4])
  73.262 +                    col += 18
  73.263 +                    display(stdscr, row, col, "Execution count")
  73.264  
  73.265                  # display io count
  73.266 -                row += 1
  73.267 -                col = 2
  73.268 -                display(stdscr, row, col, "%d" % dom)
  73.269 -                col += 4
  73.270 -                display(stdscr, row, col, "%d/s" % h2[dom][5][0])
  73.271 -                col += 24
  73.272 -                display(stdscr, row, col, "%d/ex" % h2[dom][5][1])
  73.273 -                col += 18
  73.274 -                display(stdscr, row, col, "%d" % h1[dom][5][0])
  73.275 -                col += 24
  73.276 -                display(stdscr, row, col, "%3.2f/ex" % h1[dom][5][1])
  73.277 -                col += 18
  73.278 -                display(stdscr, row, col, "I/O Count")
  73.279 +                if options.iocount:
  73.280 +                    row += 1
  73.281 +                    col = 2
  73.282 +                    display(stdscr, row, col, "%d" % dom)
  73.283 +                    col += 4
  73.284 +                    display(stdscr, row, col, "%d/s" % h2[dom][5][0])
  73.285 +                    col += 24
  73.286 +                    display(stdscr, row, col, "%d/ex" % h2[dom][5][1])
  73.287 +                    col += 18
  73.288 +                    display(stdscr, row, col, "%d" % h1[dom][5][0])
  73.289 +                    col += 24
  73.290 +                    display(stdscr, row, col, "%3.2f/ex" % h1[dom][5][1])
  73.291 +                    col += 18
  73.292 +                    display(stdscr, row, col, "I/O Count")
  73.293  
  73.294              #row += 1
  73.295              #stdscr.hline(row, 1, '-', maxx - 2)
  73.296 @@ -426,6 +470,9 @@ def show_livestats():
  73.297  
  73.298  
  73.299          row += 1
  73.300 +        star = heartbeat * '*'
  73.301 +        heartbeat = 1 - heartbeat
  73.302 +        display(stdscr, row, 1, star)
  73.303          display(stdscr, row, 2, TOTALS % (total_h2_cpu, total_h1_cpu))
  73.304          row += 1
  73.305  #        display(stdscr, row, 2, 
  73.306 @@ -515,11 +562,11 @@ def writelog():
  73.307          outfiles[dom].delayed_write("# passed cpu dom cpu(tot) cpu(%) cpu/ex allocated/ex blocked(tot) blocked(%) blocked/io waited(tot) waited(%) waited/ex ex/s io(tot) io/ex\n")
  73.308  
  73.309      while options.duration == 0 or interval < (options.duration * 1000):
  73.310 -        for cpuidx in range(0, ncpu):
  73.311 +        cpuidx = 0
  73.312 +        while cpuidx < ncpu:
  73.313  
  73.314              idx = cpuidx * slen      # offset needed in mmap file
  73.315  
  73.316 -
  73.317              samples = []
  73.318              doms = []
  73.319              dom_in_use = []
  73.320 @@ -571,6 +618,7 @@ def writelog():
  73.321              curr = time.time()
  73.322              interval += (curr - last) * 1000
  73.323              last = curr
  73.324 +            cpuidx = cpuidx + 1
  73.325          time.sleep(options.interval / 1000.0)
  73.326  
  73.327      for dom in range(0, NDOMAINS):
  73.328 @@ -601,7 +649,7 @@ def main():
  73.329      
  73.330      start_xenbaked()
  73.331      if options.live:
  73.332 -        show_livestats()
  73.333 +        show_livestats(options.cpu)
  73.334      else:
  73.335          try:
  73.336              writelog()
    74.1 --- a/tools/xenstore/xenstored_core.c	Mon Apr 17 08:47:36 2006 -0600
    74.2 +++ b/tools/xenstore/xenstored_core.c	Tue Apr 18 09:35:40 2006 -0600
    74.3 @@ -77,6 +77,10 @@ static void check_store(void);
    74.4  	} while (0)
    74.5  
    74.6  
    74.7 +int quota_nb_entry_per_domain = 1000;
    74.8 +int quota_nb_watch_per_domain = 128;
    74.9 +int quota_max_entry_size = 2048; /* 2K */
   74.10 +
   74.11  #ifdef TESTING
   74.12  static bool failtest = false;
   74.13  
   74.14 @@ -455,6 +459,10 @@ static bool write_node(struct connection
   74.15  	data.dsize = 3*sizeof(uint32_t)
   74.16  		+ node->num_perms*sizeof(node->perms[0])
   74.17  		+ node->datalen + node->childlen;
   74.18 +
   74.19 +	if (data.dsize >= quota_max_entry_size)
   74.20 +		goto error;
   74.21 +
   74.22  	data.dptr = talloc_size(node, data.dsize);
   74.23  	((uint32_t *)data.dptr)[0] = node->num_perms;
   74.24  	((uint32_t *)data.dptr)[1] = node->datalen;
   74.25 @@ -470,10 +478,12 @@ static bool write_node(struct connection
   74.26  	/* TDB should set errno, but doesn't even set ecode AFAICT. */
   74.27  	if (tdb_store(tdb_context(conn), key, data, TDB_REPLACE) != 0) {
   74.28  		corrupt(conn, "Write of %s = %s failed", key, data);
   74.29 -		errno = ENOSPC;
   74.30 -		return false;
   74.31 +		goto error;
   74.32  	}
   74.33  	return true;
   74.34 + error:
   74.35 +	errno = ENOSPC;
   74.36 +	return false;
   74.37  }
   74.38  
   74.39  static enum xs_perm_type perm_for_conn(struct connection *conn,
   74.40 @@ -765,8 +775,11 @@ static void delete_node_single(struct co
   74.41  	key.dptr = (void *)node->name;
   74.42  	key.dsize = strlen(node->name);
   74.43  
   74.44 -	if (tdb_delete(tdb_context(conn), key) != 0)
   74.45 +	if (tdb_delete(tdb_context(conn), key) != 0) {
   74.46  		corrupt(conn, "Could not delete '%s'", node->name);
   74.47 +		return;
   74.48 +	}
   74.49 +	domain_entry_dec(conn);
   74.50  }
   74.51  
   74.52  /* Must not be / */
   74.53 @@ -788,7 +801,10 @@ static struct node *construct_node(struc
   74.54  		parent = construct_node(conn, parentname);
   74.55  	if (!parent)
   74.56  		return NULL;
   74.57 -	
   74.58 +
   74.59 +	if (domain_entry(conn) >= quota_nb_entry_per_domain)
   74.60 +		return NULL;
   74.61 +
   74.62  	/* Add child to parent. */
   74.63  	base = basename(name);
   74.64  	baselen = strlen(base) + 1;
   74.65 @@ -814,6 +830,7 @@ static struct node *construct_node(struc
   74.66  	node->children = node->data = NULL;
   74.67  	node->childlen = node->datalen = 0;
   74.68  	node->parent = parent;
   74.69 +	domain_entry_inc(conn);
   74.70  	return node;
   74.71  }
   74.72  
   74.73 @@ -848,8 +865,10 @@ static struct node *create_node(struct c
   74.74  	/* We write out the nodes down, setting destructor in case
   74.75  	 * something goes wrong. */
   74.76  	for (i = node; i; i = i->parent) {
   74.77 -		if (!write_node(conn, i))
   74.78 +		if (!write_node(conn, i)) {
   74.79 +			domain_entry_dec(conn);
   74.80  			return NULL;
   74.81 +		}
   74.82  		talloc_set_destructor(i, destroy_node);
   74.83  	}
   74.84  
   74.85 @@ -1706,6 +1725,9 @@ static void usage(void)
   74.86  "  --no-fork           to request that the daemon does not fork,\n"
   74.87  "  --output-pid        to request that the pid of the daemon is output,\n"
   74.88  "  --trace-file <file> giving the file for logging, and\n"
   74.89 +"  --entry-nb <nb>     limit the number of entries per domain,\n"
   74.90 +"  --entry-size <size> limit the size of entry per domain, and\n"
   74.91 +"  --entry-watch <nb>  limit the number of watches per domain,\n"
   74.92  "  --no-recovery       to request that no recovery should be attempted when\n"
   74.93  "                      the store is corrupted (debug only),\n"
   74.94  "  --preserve-local    to request that /local is preserved on start-up,\n"
   74.95 @@ -1715,14 +1737,17 @@ static void usage(void)
   74.96  
   74.97  static struct option options[] = {
   74.98  	{ "no-domain-init", 0, NULL, 'D' },
   74.99 +	{ "entry-nb", 1, NULL, 'E' },
  74.100  	{ "pid-file", 1, NULL, 'F' },
  74.101  	{ "help", 0, NULL, 'H' },
  74.102  	{ "no-fork", 0, NULL, 'N' },
  74.103  	{ "output-pid", 0, NULL, 'P' },
  74.104 +	{ "entry-size", 1, NULL, 'S' },
  74.105  	{ "trace-file", 1, NULL, 'T' },
  74.106  	{ "no-recovery", 0, NULL, 'R' },
  74.107  	{ "preserve-local", 0, NULL, 'L' },
  74.108  	{ "verbose", 0, NULL, 'V' },
  74.109 +	{ "watch-nb", 1, NULL, 'W' },
  74.110  	{ NULL, 0, NULL, 0 } };
  74.111  
  74.112  extern void dump_conn(struct connection *conn); 
  74.113 @@ -1737,12 +1762,15 @@ int main(int argc, char *argv[])
  74.114  	bool no_domain_init = false;
  74.115  	const char *pidfile = NULL;
  74.116  
  74.117 -	while ((opt = getopt_long(argc, argv, "DF:HNPT:RLV", options,
  74.118 +	while ((opt = getopt_long(argc, argv, "DE:F:HNPS:T:RLVW:", options,
  74.119  				  NULL)) != -1) {
  74.120  		switch (opt) {
  74.121  		case 'D':
  74.122  			no_domain_init = true;
  74.123  			break;
  74.124 +		case 'E':
  74.125 +			quota_nb_entry_per_domain = strtol(optarg, NULL, 10);
  74.126 +			break;
  74.127  		case 'F':
  74.128  			pidfile = optarg;
  74.129  			break;
  74.130 @@ -1761,12 +1789,18 @@ int main(int argc, char *argv[])
  74.131  		case 'L':
  74.132  			remove_local = false;
  74.133  			break;
  74.134 +		case 'S':
  74.135 +			quota_max_entry_size = strtol(optarg, NULL, 10);
  74.136 +			break;
  74.137  		case 'T':
  74.138  			tracefile = optarg;
  74.139  			break;
  74.140  		case 'V':
  74.141  			verbose = true;
  74.142  			break;
  74.143 +		case 'W':
  74.144 +			quota_nb_watch_per_domain = strtol(optarg, NULL, 10);
  74.145 +			break;
  74.146  		}
  74.147  	}
  74.148  	if (optind != argc)
    75.1 --- a/tools/xenstore/xenstored_domain.c	Mon Apr 17 08:47:36 2006 -0600
    75.2 +++ b/tools/xenstore/xenstored_domain.c	Tue Apr 18 09:35:40 2006 -0600
    75.3 @@ -74,6 +74,12 @@ struct domain
    75.4  
    75.5  	/* Have we noticed that this domain is shutdown? */
    75.6  	int shutdown;
    75.7 +
    75.8 +	/* number of entry from this domain in the store */
    75.9 +	int nbentry;
   75.10 +
   75.11 +	/* number of watch for this domain */
   75.12 +	int nbwatch;
   75.13  };
   75.14  
   75.15  static LIST_HEAD(domains);
   75.16 @@ -285,6 +291,8 @@ static struct domain *new_domain(void *c
   75.17  	domain->conn->id = domid;
   75.18  
   75.19  	domain->remote_port = port;
   75.20 +	domain->nbentry = 0;
   75.21 +	domain->nbwatch = 0;
   75.22  
   75.23  	return domain;
   75.24  }
   75.25 @@ -562,6 +570,50 @@ int domain_init(void)
   75.26  	return eventchn_fd;
   75.27  }
   75.28  
   75.29 +void domain_entry_inc(struct connection *conn)
   75.30 +{
   75.31 +	if (!conn || !conn->domain)
   75.32 +		return;
   75.33 +	conn->domain->nbentry++;
   75.34 +}
   75.35 +
   75.36 +void domain_entry_dec(struct connection *conn)
   75.37 +{
   75.38 +	if (!conn || !conn->domain)
   75.39 +		return;
   75.40 +	if (conn->domain->nbentry)
   75.41 +		conn->domain->nbentry--;
   75.42 +}
   75.43 +
   75.44 +int domain_entry(struct connection *conn)
   75.45 +{
   75.46 +	return (conn && conn->domain && conn->domain->domid)
   75.47 +		? conn->domain->nbentry
   75.48 +		: 0;
   75.49 +}
   75.50 +
   75.51 +void domain_watch_inc(struct connection *conn)
   75.52 +{
   75.53 +	if (!conn || !conn->domain)
   75.54 +		return;
   75.55 +	conn->domain->nbwatch++;
   75.56 +}
   75.57 +
   75.58 +void domain_watch_dec(struct connection *conn)
   75.59 +{
   75.60 +	if (!conn || !conn->domain)
   75.61 +		return;
   75.62 +	if (conn->domain->nbwatch)
   75.63 +		conn->domain->nbwatch--;
   75.64 +}
   75.65 +
   75.66 +int domain_watch(struct connection *conn)
   75.67 +{
   75.68 +	return (conn && conn->domain && conn->domain->domid)
   75.69 +		? conn->domain->nbwatch
   75.70 +		: 0;
   75.71 +}
   75.72 +
   75.73  /*
   75.74   * Local variables:
   75.75   *  c-file-style: "linux"
    76.1 --- a/tools/xenstore/xenstored_domain.h	Mon Apr 17 08:47:36 2006 -0600
    76.2 +++ b/tools/xenstore/xenstored_domain.h	Tue Apr 18 09:35:40 2006 -0600
    76.3 @@ -47,4 +47,12 @@ void restore_existing_connections(void);
    76.4  bool domain_can_read(struct connection *conn);
    76.5  bool domain_can_write(struct connection *conn);
    76.6  
    76.7 +/* Quota manipulation */
    76.8 +void domain_entry_inc(struct connection *conn);
    76.9 +void domain_entry_dec(struct connection *conn);
   76.10 +int domain_entry(struct connection *conn);
   76.11 +void domain_watch_inc(struct connection *conn);
   76.12 +void domain_watch_dec(struct connection *conn);
   76.13 +int domain_watch(struct connection *conn);
   76.14 +
   76.15  #endif /* _XENSTORED_DOMAIN_H */
    77.1 --- a/tools/xenstore/xenstored_watch.c	Mon Apr 17 08:47:36 2006 -0600
    77.2 +++ b/tools/xenstore/xenstored_watch.c	Tue Apr 18 09:35:40 2006 -0600
    77.3 @@ -32,6 +32,8 @@
    77.4  #include "xenstored_test.h"
    77.5  #include "xenstored_domain.h"
    77.6  
    77.7 +extern int quota_nb_watch_per_domain;
    77.8 +
    77.9  struct watch
   77.10  {
   77.11  	/* Watches on this connection */
   77.12 @@ -135,6 +137,11 @@ void do_watch(struct connection *conn, s
   77.13  		}
   77.14  	}
   77.15  
   77.16 +	if (domain_watch(conn) > quota_nb_watch_per_domain) {
   77.17 +		send_error(conn, E2BIG);
   77.18 +		return;
   77.19 +	}
   77.20 +
   77.21  	watch = talloc(conn, struct watch);
   77.22  	watch->node = talloc_strdup(watch, vec[0]);
   77.23  	watch->token = talloc_strdup(watch, vec[1]);
   77.24 @@ -145,6 +152,7 @@ void do_watch(struct connection *conn, s
   77.25  
   77.26  	INIT_LIST_HEAD(&watch->events);
   77.27  
   77.28 +	domain_watch_inc(conn);
   77.29  	list_add_tail(&watch->list, &conn->watches);
   77.30  	trace_create(watch, "watch");
   77.31  	talloc_set_destructor(watch, destroy_watch);
   77.32 @@ -169,6 +177,7 @@ void do_unwatch(struct connection *conn,
   77.33  		if (streq(watch->node, node) && streq(watch->token, vec[1])) {
   77.34  			list_del(&watch->list);
   77.35  			talloc_free(watch);
   77.36 +			domain_watch_dec(conn);
   77.37  			send_ack(conn, XS_UNWATCH);
   77.38  			return;
   77.39  		}
    78.1 --- a/xen/Makefile	Mon Apr 17 08:47:36 2006 -0600
    78.2 +++ b/xen/Makefile	Tue Apr 18 09:35:40 2006 -0600
    78.3 @@ -10,19 +10,22 @@ export BASEDIR := $(CURDIR)
    78.4  .PHONY: default
    78.5  default: build
    78.6  
    78.7 -ifeq ($(XEN_ROOT),)
    78.8 -
    78.9 -.PHONY: build install clean
   78.10 -build install clean:
   78.11 -	make -f Rules.mk $@
   78.12 +.PHONY: dist
   78.13 +dist: install
   78.14  
   78.15 -else
   78.16 +.PHONY: debug
   78.17 +debug:
   78.18 +	objdump -D -S $(TARGET)-syms > $(TARGET).s
   78.19  
   78.20 -.PHONY: build
   78.21 -build: $(TARGET).gz
   78.22 +.PHONY: build install clean cscope TAGS tags
   78.23 +build install clean cscope TAGS tags::
   78.24 +	make -f Rules.mk _$@
   78.25  
   78.26 -.PHONY: install
   78.27 -install: $(TARGET).gz
   78.28 +.PHONY: _build
   78.29 +_build: $(TARGET).gz
   78.30 +
   78.31 +.PHONY: _install
   78.32 +_install: $(TARGET).gz
   78.33  	[ -d $(DESTDIR)/boot ] || $(INSTALL_DIR) $(DESTDIR)/boot
   78.34  	$(INSTALL_DATA) $(TARGET).gz $(DESTDIR)/boot/$(notdir $(TARGET))-$(XEN_FULLVERSION).gz
   78.35  	ln -f -s $(notdir $(TARGET))-$(XEN_FULLVERSION).gz $(DESTDIR)/boot/$(notdir $(TARGET))-$(XEN_VERSION).$(XEN_SUBVERSION).gz
   78.36 @@ -35,8 +38,8 @@ install: $(TARGET).gz
   78.37  	$(INSTALL_DATA) include/public/io/*.h $(DESTDIR)/usr/include/xen/io
   78.38  	$(INSTALL_DATA) include/public/COPYING $(DESTDIR)/usr/include/xen
   78.39  
   78.40 -.PHONY: clean
   78.41 -clean:: delete-unfresh-files
   78.42 +.PHONY: _clean
   78.43 +_clean: delete-unfresh-files
   78.44  	$(MAKE) -C tools clean
   78.45  	$(MAKE) -f $(BASEDIR)/Rules.mk -C common clean
   78.46  	$(MAKE) -f $(BASEDIR)/Rules.mk -C drivers clean
   78.47 @@ -46,15 +49,6 @@ clean:: delete-unfresh-files
   78.48  	rm -f include/asm-*/asm-offsets.h
   78.49  	rm -f include/xen/acm_policy.h
   78.50  
   78.51 -endif
   78.52 -
   78.53 -.PHONY: dist
   78.54 -dist: install
   78.55 -
   78.56 -.PHONY: debug
   78.57 -debug:
   78.58 -	objdump -D -S $(TARGET)-syms > $(TARGET).s
   78.59 -
   78.60  $(TARGET).gz: $(TARGET)
   78.61  	gzip -f -9 < $< > $@.new
   78.62  	mv $@.new $@
   78.63 @@ -135,16 +129,16 @@ define all_sources
   78.64        find $(SUBDIRS) -name SCCS -prune -o -name '*.[chS]' -print )
   78.65  endef
   78.66  
   78.67 -.PHONY: TAGS
   78.68 -TAGS: 
   78.69 +.PHONY: _TAGS
   78.70 +_TAGS: 
   78.71  	$(all_sources) | etags -
   78.72  
   78.73 -.PHONY: tags
   78.74 -tags: 
   78.75 +.PHONY: _tags
   78.76 +_tags: 
   78.77  	$(all_sources) | xargs ctags
   78.78  
   78.79 -.PHONY: cscope
   78.80 -cscope: 
   78.81 +.PHONY: _cscope
   78.82 +_cscope:
   78.83  	$(all_sources) > cscope.files
   78.84  	cscope -k -b -q
   78.85  
    79.1 --- a/xen/arch/x86/Makefile	Mon Apr 17 08:47:36 2006 -0600
    79.2 +++ b/xen/arch/x86/Makefile	Tue Apr 18 09:35:40 2006 -0600
    79.3 @@ -76,6 +76,7 @@ boot/mkelf32: boot/mkelf32.c
    79.4  	$(HOSTCC) $(HOSTCFLAGS) -o $@ $<
    79.5  
    79.6  shadow_guest32.o: shadow.c
    79.7 +shadow_guest32pae.o: shadow.c
    79.8  
    79.9  .PHONY: clean
   79.10  clean::
    80.1 --- a/xen/arch/x86/audit.c	Mon Apr 17 08:47:36 2006 -0600
    80.2 +++ b/xen/arch/x86/audit.c	Tue Apr 18 09:35:40 2006 -0600
    80.3 @@ -639,7 +639,7 @@ void _audit_domain(struct domain *d, int
    80.4      void scan_for_pfn_in_grant_table(struct domain *d, unsigned xmfn)
    80.5      {
    80.6          int i;
    80.7 -        active_grant_entry_t *act = d->grant_table->active;
    80.8 +        struct active_grant_entry *act = d->grant_table->active;
    80.9  
   80.10          spin_lock(&d->grant_table->lock);
   80.11  
    81.1 --- a/xen/arch/x86/hvm/intercept.c	Mon Apr 17 08:47:36 2006 -0600
    81.2 +++ b/xen/arch/x86/hvm/intercept.c	Tue Apr 18 09:35:40 2006 -0600
    81.3 @@ -208,8 +208,9 @@ int register_io_handler(unsigned long ad
    81.4  
    81.5  static void pit_cal_count(struct hvm_virpit *vpit)
    81.6  {
    81.7 -    u64 nsec_delta = (unsigned int)((NOW() - vpit->inject_point));
    81.8 +    u64 nsec_delta = (unsigned int)((NOW() - vpit->count_point));
    81.9  
   81.10 +    nsec_delta += vpit->count_advance;
   81.11      if (nsec_delta > vpit->period)
   81.12          HVM_DBG_LOG(DBG_LEVEL_1,
   81.13  	            "HVM_PIT: long time has passed from last injection!");
    82.1 --- a/xen/arch/x86/hvm/svm/intr.c	Mon Apr 17 08:47:36 2006 -0600
    82.2 +++ b/xen/arch/x86/hvm/svm/intr.c	Tue Apr 18 09:35:40 2006 -0600
    82.3 @@ -79,7 +79,8 @@ interrupt_post_injection(struct vcpu * v
    82.4          } else {
    82.5              vpit->pending_intr_nr--;
    82.6          }
    82.7 -        vpit->inject_point = NOW();
    82.8 +        vpit->count_advance = 0;
    82.9 +        vpit->count_point = NOW();
   82.10  
   82.11          vpit->last_pit_gtime += vpit->period_cycles;
   82.12          svm_set_guest_time(v, vpit->last_pit_gtime);
    83.1 --- a/xen/arch/x86/hvm/svm/svm.c	Mon Apr 17 08:47:36 2006 -0600
    83.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Tue Apr 18 09:35:40 2006 -0600
    83.3 @@ -315,20 +315,30 @@ static inline int long_mode_do_msr_write
    83.4      {
    83.5      case MSR_EFER:
    83.6  #ifdef __x86_64__
    83.7 -        if ((msr_content & EFER_LME) ^ test_bit(SVM_CPU_STATE_LME_ENABLED,
    83.8 -                                                &vc->arch.hvm_svm.cpu_state))
    83.9 +        /* offending reserved bit will cause #GP */
   83.10 +        if ( msr_content & ~(EFER_LME | EFER_LMA | EFER_NX | EFER_SCE) )
   83.11          {
   83.12 -            if (test_bit(SVM_CPU_STATE_PG_ENABLED, &vc->arch.hvm_svm.cpu_state)
   83.13 -                    || !test_bit(SVM_CPU_STATE_PAE_ENABLED,
   83.14 -                                 &vc->arch.hvm_svm.cpu_state))
   83.15 +            printk("trying to set reserved bit in EFER\n");
   83.16 +            svm_inject_exception(vmcb, TRAP_gp_fault, 1, 0);
   83.17 +            return 0;
   83.18 +        }
   83.19 +
   83.20 +        /* LME: 0 -> 1 */
   83.21 +        if ( msr_content & EFER_LME &&
   83.22 +             !test_bit(SVM_CPU_STATE_LME_ENABLED, &vc->arch.hvm_svm.cpu_state) )
   83.23 +        {
   83.24 +            if ( svm_paging_enabled(vc) ||
   83.25 +                 !test_bit(SVM_CPU_STATE_PAE_ENABLED,
   83.26 +                           &vc->arch.hvm_svm.cpu_state) )
   83.27              {
   83.28 +                printk("trying to set LME bit when "
   83.29 +                       "in paging mode or PAE bit is not set\n");
   83.30                  svm_inject_exception(vmcb, TRAP_gp_fault, 1, 0);
   83.31 +                return 0;
   83.32              }
   83.33 +            set_bit(SVM_CPU_STATE_LME_ENABLED, &vc->arch.hvm_svm.cpu_state);
   83.34          }
   83.35  
   83.36 -        if (msr_content & EFER_LME)
   83.37 -            set_bit(SVM_CPU_STATE_LME_ENABLED, &vc->arch.hvm_svm.cpu_state);
   83.38 -
   83.39          /* We have already recorded that we want LME, so it will be set 
   83.40           * next time CR0 gets updated. So we clear that bit and continue.
   83.41           */
   83.42 @@ -669,6 +679,7 @@ static void svm_freeze_time(struct vcpu 
   83.43      
   83.44      if ( vpit->first_injected && !v->domain->arch.hvm_domain.guest_time ) {
   83.45          v->domain->arch.hvm_domain.guest_time = svm_get_guest_time(v);
   83.46 +        vpit->count_advance += (NOW() - vpit->count_point);
   83.47          stop_timer(&(vpit->pit_timer));
   83.48      }
   83.49  }
   83.50 @@ -757,7 +768,8 @@ void arch_svm_do_resume(struct vcpu *v)
   83.51          reset_stack_and_jump( svm_asm_do_resume );
   83.52      }
   83.53      else {
   83.54 -        printk("VCPU core pinned: %d to %d\n", v->arch.hvm_svm.launch_core, smp_processor_id() );
   83.55 +        printk("VCPU core pinned: %d to %d\n", 
   83.56 +                v->arch.hvm_svm.launch_core, smp_processor_id() );
   83.57          v->arch.hvm_svm.launch_core = smp_processor_id();
   83.58          svm_migrate_timers( v );
   83.59          svm_do_resume( v );
   83.60 @@ -922,6 +934,7 @@ static void svm_vmexit_do_cpuid(struct v
   83.61              clear_bit(X86_FEATURE_APIC, &edx);
   83.62  	    
   83.63  #if CONFIG_PAGING_LEVELS < 3
   83.64 +        clear_bit(X86_FEATURE_NX, &edx);
   83.65          clear_bit(X86_FEATURE_PAE, &edx);
   83.66          clear_bit(X86_FEATURE_PSE, &edx);
   83.67          clear_bit(X86_FEATURE_PSE36, &edx);
   83.68 @@ -929,12 +942,14 @@ static void svm_vmexit_do_cpuid(struct v
   83.69          if ( v->domain->arch.ops->guest_paging_levels == PAGING_L2 )
   83.70          {
   83.71              if ( !v->domain->arch.hvm_domain.pae_enabled )
   83.72 -                clear_bit(X86_FEATURE_PAE, &edx);
   83.73 +            {
   83.74 +               clear_bit(X86_FEATURE_PAE, &edx);
   83.75 +               clear_bit(X86_FEATURE_NX, &edx);
   83.76 +            }
   83.77              clear_bit(X86_FEATURE_PSE, &edx);
   83.78              clear_bit(X86_FEATURE_PSE36, &edx);
   83.79          }
   83.80 -#endif
   83.81 -	
   83.82 +#endif	
   83.83          /* Clear out reserved bits. */
   83.84          ecx &= ~SVM_VCPU_CPUID_L1_RESERVED; /* mask off reserved bits */
   83.85          clear_bit(X86_FEATURE_MWAIT & 31, &ecx);
   83.86 @@ -1312,8 +1327,7 @@ static int svm_set_cr0(unsigned long val
   83.87      unsigned long mfn;
   83.88      int paging_enabled;
   83.89      struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
   83.90 -    unsigned long crn;
   83.91 -
   83.92 +  
   83.93      ASSERT(vmcb);
   83.94  
   83.95      /* We don't want to lose PG.  ET is reserved and should be always be 1*/
   83.96 @@ -1358,37 +1372,39 @@ static int svm_set_cr0(unsigned long val
   83.97              set_bit(SVM_CPU_STATE_LMA_ENABLED,
   83.98                      &v->arch.hvm_svm.cpu_state);
   83.99              vmcb->efer |= (EFER_LMA | EFER_LME);
  83.100 -
  83.101 -#if CONFIG_PAGING_LEVELS >= 4 
  83.102 -            if (!shadow_set_guest_paging_levels(v->domain, 4)) 
  83.103 +            if (!shadow_set_guest_paging_levels(v->domain, PAGING_L4) )
  83.104              {
  83.105                  printk("Unsupported guest paging levels\n");
  83.106                  domain_crash_synchronous(); /* need to take a clean path */
  83.107              }
  83.108 -#endif
  83.109          }
  83.110          else
  83.111  #endif  /* __x86_64__ */
  83.112          {
  83.113  #if CONFIG_PAGING_LEVELS >= 3
  83.114 -            if (!shadow_set_guest_paging_levels(v->domain, 2))
  83.115 +            /* seems it's a 32-bit or 32-bit PAE guest */
  83.116 +            if ( test_bit(SVM_CPU_STATE_PAE_ENABLED,
  83.117 +                        &v->arch.hvm_svm.cpu_state) )
  83.118              {
  83.119 -                printk("Unsupported guest paging levels\n");
  83.120 -                domain_crash_synchronous(); /* need to take a clean path */
  83.121 +                /* The guest enables PAE first and then it enables PG, it is
  83.122 +                 * really a PAE guest */
  83.123 +                if ( !shadow_set_guest_paging_levels(v->domain, PAGING_L3) )
  83.124 +                {
  83.125 +                    printk("Unsupported guest paging levels\n");
  83.126 +                    domain_crash_synchronous();
  83.127 +                }
  83.128 +            }
  83.129 +            else
  83.130 +            {
  83.131 +                if ( !shadow_set_guest_paging_levels(v->domain, PAGING_L2) )
  83.132 +                {
  83.133 +                    printk("Unsupported guest paging levels\n");
  83.134 +                    domain_crash_synchronous(); /* need to take a clean path */
  83.135 +                }
  83.136              }
  83.137  #endif
  83.138          }
  83.139  
  83.140 -        /* update CR4's PAE if needed */
  83.141 -        crn = vmcb->cr4;
  83.142 -        if ((!(crn & X86_CR4_PAE)) 
  83.143 -                && test_bit(SVM_CPU_STATE_PAE_ENABLED, 
  83.144 -                    &v->arch.hvm_svm.cpu_state))
  83.145 -        {
  83.146 -            HVM_DBG_LOG(DBG_LEVEL_1, "enable PAE on cr4\n");
  83.147 -            vmcb->cr4 |= X86_CR4_PAE;
  83.148 -        }
  83.149 -
  83.150          /* Now arch.guest_table points to machine physical. */
  83.151          v->arch.guest_table = mk_pagetable((u64)mfn << PAGE_SHIFT);
  83.152          update_pagetables(v);
  83.153 @@ -1402,8 +1418,17 @@ static int svm_set_cr0(unsigned long val
  83.154          /* arch->shadow_table should hold the next CR3 for shadow */
  83.155          HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR3 value = %lx, mfn = %lx\n", 
  83.156                      v->arch.hvm_svm.cpu_cr3, mfn);
  83.157 +
  83.158 +        return 1;
  83.159      }
  83.160  
  83.161 +    if ( !((value & X86_CR0_PE) && (value & X86_CR0_PG)) && paging_enabled )
  83.162 +        if ( v->arch.hvm_svm.cpu_cr3 ) {
  83.163 +            put_page(mfn_to_page(get_mfn_from_gpfn(
  83.164 +                      v->arch.hvm_svm.cpu_cr3 >> PAGE_SHIFT)));
  83.165 +            v->arch.guest_table = mk_pagetable(0);
  83.166 +        }
  83.167 +
  83.168      /*
  83.169       * SVM implements paged real-mode and when we return to real-mode
  83.170       * we revert back to the physical mappings that the domain builder
  83.171 @@ -1415,6 +1440,14 @@ static int svm_set_cr0(unsigned long val
  83.172              return 0;
  83.173          }
  83.174  
  83.175 +        clear_all_shadow_status( v->domain );
  83.176 +        set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
  83.177 +        vmcb->cr3 = pagetable_get_paddr(v->domain->arch.phys_table);
  83.178 +    }
  83.179 +    else if ( (value & (X86_CR0_PE | X86_CR0_PG)) == X86_CR0_PE )
  83.180 +    {
  83.181 +        /* we should take care of this kind of situation */
  83.182 +        clear_all_shadow_status(v->domain);
  83.183          set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
  83.184          vmcb->cr3 = pagetable_get_paddr(v->domain->arch.phys_table);
  83.185      }
  83.186 @@ -1438,15 +1471,21 @@ static void mov_from_cr(int cr, int gp, 
  83.187      {
  83.188      case 0:
  83.189          value = v->arch.hvm_svm.cpu_shadow_cr0;
  83.190 -        break;
  83.191 +        if (svm_dbg_on)
  83.192 +            printk("CR0 read =%lx \n", value );
  83.193 +          break;
  83.194      case 2:
  83.195          value = vmcb->cr2;
  83.196          break;
  83.197      case 3:
  83.198          value = (unsigned long) v->arch.hvm_svm.cpu_cr3;
  83.199 -        break;
  83.200 +        if (svm_dbg_on)
  83.201 +            printk("CR3 read =%lx \n", value );
  83.202 +          break;
  83.203      case 4:
  83.204          value = (unsigned long) v->arch.hvm_svm.cpu_shadow_cr4;
  83.205 +        if (svm_dbg_on)
  83.206 +           printk( "CR4 read=%lx\n", value );
  83.207          break;
  83.208      case 8:
  83.209  #if 0
  83.210 @@ -1466,6 +1505,12 @@ static void mov_from_cr(int cr, int gp, 
  83.211  }
  83.212  
  83.213  
  83.214 +static inline int svm_pgbit_test(struct vcpu *v)
  83.215 +{
  83.216 +   return v->arch.hvm_svm.cpu_shadow_cr0 & X86_CR0_PG;
  83.217 +}
  83.218 +
  83.219 +
  83.220  /*
  83.221   * Write to control registers
  83.222   */
  83.223 @@ -1486,12 +1531,15 @@ static int mov_to_cr(int gpreg, int cr, 
  83.224      switch (cr) 
  83.225      {
  83.226      case 0: 
  83.227 +        if (svm_dbg_on)
  83.228 +            printk("CR0 write =%lx \n", value );
  83.229          return svm_set_cr0(value);
  83.230  
  83.231      case 3: 
  83.232      {
  83.233          unsigned long old_base_mfn, mfn;
  83.234 -
  83.235 +        if (svm_dbg_on)
  83.236 +            printk("CR3 write =%lx \n", value );
  83.237          /* If paging is not enabled yet, simply copy the value to CR3. */
  83.238          if (!svm_paging_enabled(v)) {
  83.239              v->arch.hvm_svm.cpu_cr3 = value;
  83.240 @@ -1533,19 +1581,104 @@ static int mov_to_cr(int gpreg, int cr, 
  83.241              if (old_base_mfn)
  83.242                  put_page(mfn_to_page(old_base_mfn));
  83.243  
  83.244 +            /*
  83.245 +             * arch.shadow_table should now hold the next CR3 for shadow
  83.246 +             */
  83.247 +#if CONFIG_PAGING_LEVELS >= 3
  83.248 +            if ( v->domain->arch.ops->guest_paging_levels == PAGING_L3 )
  83.249 +                shadow_sync_all(v->domain);
  83.250 +#endif
  83.251 +            v->arch.hvm_svm.cpu_cr3 = value;
  83.252              update_pagetables(v);
  83.253 -            
  83.254 -            /* arch.shadow_table should now hold the next CR3 for shadow*/
  83.255 -            v->arch.hvm_svm.cpu_cr3 = value;
  83.256              HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR3 value = %lx", value);
  83.257              vmcb->cr3 = pagetable_get_paddr(v->arch.shadow_table);
  83.258          }
  83.259          break;
  83.260      }
  83.261  
  83.262 -    case 4:         
  83.263 -        /* CR4 */
  83.264 -        if (value & X86_CR4_PAE) {
  83.265 +    case 4: /* CR4 */
  83.266 +    {
  83.267 +        if (svm_dbg_on)
  83.268 +            printk( "write cr4=%lx, cr0=%lx\n", 
  83.269 +                     value,  v->arch.hvm_svm.cpu_shadow_cr0 );
  83.270 +        old_cr = v->arch.hvm_svm.cpu_shadow_cr4;
  83.271 +        if ( value & X86_CR4_PAE && !(old_cr & X86_CR4_PAE) )
  83.272 +        {
  83.273 +            set_bit(SVM_CPU_STATE_PAE_ENABLED, &v->arch.hvm_svm.cpu_state);
  83.274 +            if ( svm_pgbit_test(v) )
  83.275 +            {
  83.276 +                /* The guest is a 32-bit PAE guest. */
  83.277 +#if CONFIG_PAGING_LEVELS >= 4
  83.278 +                unsigned long mfn, old_base_mfn;
  83.279 +
  83.280 +                if( !shadow_set_guest_paging_levels(v->domain, PAGING_L3) )
  83.281 +                {
  83.282 +                    printk("Unsupported guest paging levels\n");
  83.283 +                    domain_crash_synchronous(); /* need to take a clean path */
  83.284 +                }
  83.285 +
  83.286 +                if ( !VALID_MFN(mfn = get_mfn_from_gpfn(
  83.287 +                                    v->arch.hvm_svm.cpu_cr3 >> PAGE_SHIFT)) ||
  83.288 +                     !get_page(mfn_to_page(mfn), v->domain) )
  83.289 +                {
  83.290 +                    printk("Invalid CR3 value = %lx", v->arch.hvm_svm.cpu_cr3);
  83.291 +                    domain_crash_synchronous(); /* need to take a clean path */
  83.292 +                }
  83.293 +
  83.294 +                old_base_mfn = pagetable_get_pfn(v->arch.guest_table);
  83.295 +                if ( old_base_mfn )
  83.296 +                    put_page(mfn_to_page(old_base_mfn));
  83.297 +
  83.298 +                /*
  83.299 +                 * Now arch.guest_table points to machine physical.
  83.300 +                 */
  83.301 +
  83.302 +                v->arch.guest_table = mk_pagetable((u64)mfn << PAGE_SHIFT);
  83.303 +                update_pagetables(v);
  83.304 +
  83.305 +                HVM_DBG_LOG(DBG_LEVEL_VMMU, "New arch.guest_table = %lx",
  83.306 +                            (unsigned long) (mfn << PAGE_SHIFT));
  83.307 +
  83.308 +                vmcb->cr3 = pagetable_get_paddr(v->arch.shadow_table);
  83.309 +
  83.310 +                /*
  83.311 +                 * arch->shadow_table should hold the next CR3 for shadow
  83.312 +                 */
  83.313 +
  83.314 +                HVM_DBG_LOG(DBG_LEVEL_VMMU, "Update CR3 value = %lx, mfn = %lx",
  83.315 +                            v->arch.hvm_svm.cpu_cr3, mfn);
  83.316 +#endif
  83.317 +            }
  83.318 +            else
  83.319 +            {
  83.320 +                /*  The guest is a 64 bit or 32-bit PAE guest. */
  83.321 +#if CONFIG_PAGING_LEVELS >= 4
  83.322 +                if ( (v->domain->arch.ops != NULL) &&
  83.323 +                        v->domain->arch.ops->guest_paging_levels == PAGING_L2)
  83.324 +                {
  83.325 +                    /* Seems the guest first enables PAE without enabling PG,
  83.326 +                     * it must enable PG after that, and it is a 32-bit PAE
  83.327 +                     * guest */
  83.328 +
  83.329 +                    if ( !shadow_set_guest_paging_levels(v->domain, PAGING_L3) )
  83.330 +                    {
  83.331 +                        printk("Unsupported guest paging levels\n");
  83.332 +                        domain_crash_synchronous();
  83.333 +                    }                   
  83.334 +                }
  83.335 +                else
  83.336 +                {
  83.337 +                    if ( !shadow_set_guest_paging_levels(v->domain,
  83.338 +                                                            PAGING_L4) )
  83.339 +                    {
  83.340 +                        printk("Unsupported guest paging levels\n");
  83.341 +                        domain_crash_synchronous();
  83.342 +                    }
  83.343 +                }
  83.344 +#endif
  83.345 +            }
  83.346 +        }
  83.347 +        else if (value & X86_CR4_PAE) {
  83.348              set_bit(SVM_CPU_STATE_PAE_ENABLED, &v->arch.hvm_svm.cpu_state);
  83.349          } else {
  83.350              if (test_bit(SVM_CPU_STATE_LMA_ENABLED,
  83.351 @@ -1555,7 +1688,6 @@ static int mov_to_cr(int gpreg, int cr, 
  83.352              clear_bit(SVM_CPU_STATE_PAE_ENABLED, &v->arch.hvm_svm.cpu_state);
  83.353          }
  83.354  
  83.355 -        old_cr = v->arch.hvm_svm.cpu_shadow_cr4;
  83.356          v->arch.hvm_svm.cpu_shadow_cr4 = value;
  83.357          vmcb->cr4 = value | SVM_CR4_HOST_MASK;
  83.358    
  83.359 @@ -1569,6 +1701,7 @@ static int mov_to_cr(int gpreg, int cr, 
  83.360              shadow_sync_all(v->domain);
  83.361          }
  83.362          break;
  83.363 +    }
  83.364  
  83.365      default:
  83.366          printk("invalid cr: %d\n", cr);
  83.367 @@ -1933,6 +2066,7 @@ static int svm_do_vmmcall_reset_to_realm
  83.368  
  83.369      vmcb->cr4 = SVM_CR4_HOST_MASK;
  83.370      v->arch.hvm_svm.cpu_shadow_cr4 = 0;
  83.371 +    clear_bit(SVM_CPU_STATE_PAE_ENABLED, &v->arch.hvm_svm.cpu_state);
  83.372  
  83.373      /* This will jump to ROMBIOS */
  83.374      vmcb->rip = 0xFFF0;
  83.375 @@ -1989,6 +2123,7 @@ static int svm_do_vmmcall_reset_to_realm
  83.376      vmcb->idtr.base = 0x00;
  83.377  
  83.378      vmcb->rax = 0;
  83.379 +    vmcb->rsp = 0;
  83.380  
  83.381      return 0;
  83.382  }
  83.383 @@ -2280,7 +2415,8 @@ void walk_shadow_and_guest_pt(unsigned l
  83.384      gpte.l1 = 0;
  83.385      __copy_from_user(&gpte, &linear_pg_table[ l1_linear_offset(gva) ], sizeof(gpte) );
  83.386      printk( "G-PTE = %x, flags=%x\n", gpte.l1, l1e_get_flags(gpte) );
  83.387 -    __copy_from_user( &spte, &phys_to_machine_mapping[ l1e_get_pfn( gpte ) ], sizeof(spte) );
  83.388 +    __copy_from_user( &spte, &phys_to_machine_mapping[ l1e_get_pfn( gpte ) ], 
  83.389 +                      sizeof(spte) );
  83.390      printk( "S-PTE = %x, flags=%x\n", spte.l1, l1e_get_flags(spte));
  83.391  }
  83.392  #endif /* SVM_WALK_GUEST_PAGES */
  83.393 @@ -2314,18 +2450,29 @@ asmlinkage void svm_vmexit_handler(struc
  83.394      {
  83.395          if (svm_paging_enabled(v) && !mmio_space(gva_to_gpa(vmcb->exitinfo2)))
  83.396          {
  83.397 +            printk("I%08ld,ExC=%s(%d),IP=%x:%llx,I1=%llx,I2=%llx,INT=%llx, gpa=%llx\n", 
  83.398 +                    intercepts_counter,
  83.399 +                    exit_reasons[exit_reason], exit_reason, regs.cs,
  83.400 +		    (unsigned long long) regs.rip,
  83.401 +		    (unsigned long long) vmcb->exitinfo1,
  83.402 +		    (unsigned long long) vmcb->exitinfo2,
  83.403 +		    (unsigned long long) vmcb->exitintinfo.bytes,
  83.404 +            (unsigned long long) gva_to_gpa( vmcb->exitinfo2 ) );
  83.405 +        }
  83.406 +        else 
  83.407 +        {
  83.408              printk("I%08ld,ExC=%s(%d),IP=%x:%llx,I1=%llx,I2=%llx,INT=%llx\n", 
  83.409                      intercepts_counter,
  83.410                      exit_reasons[exit_reason], exit_reason, regs.cs,
  83.411  		    (unsigned long long) regs.rip,
  83.412  		    (unsigned long long) vmcb->exitinfo1,
  83.413  		    (unsigned long long) vmcb->exitinfo2,
  83.414 -		    (unsigned long long) vmcb->exitintinfo.bytes);
  83.415 +		    (unsigned long long) vmcb->exitintinfo.bytes );
  83.416          }
  83.417      } 
  83.418 -    else if (svm_dbg_on 
  83.419 -            && exit_reason != VMEXIT_IOIO 
  83.420 -            && exit_reason != VMEXIT_INTR) 
  83.421 +    else if ( svm_dbg_on 
  83.422 +              && exit_reason != VMEXIT_IOIO 
  83.423 +              && exit_reason != VMEXIT_INTR) 
  83.424      {
  83.425  
  83.426          if (exit_reasons[exit_reason])
  83.427 @@ -2350,7 +2497,9 @@ asmlinkage void svm_vmexit_handler(struc
  83.428      }
  83.429  
  83.430  #ifdef SVM_WALK_GUEST_PAGES
  83.431 -    if( exit_reason == VMEXIT_EXCEPTION_PF && ( ( vmcb->exitinfo2 == vmcb->rip )|| vmcb->exitintinfo.bytes) )
  83.432 +    if( exit_reason == VMEXIT_EXCEPTION_PF 
  83.433 +        && ( ( vmcb->exitinfo2 == vmcb->rip )
  83.434 +        || vmcb->exitintinfo.bytes) )
  83.435      {
  83.436         if (svm_paging_enabled(v) && !mmio_space(gva_to_gpa(vmcb->exitinfo2)))     
  83.437             walk_shadow_and_guest_pt( vmcb->exitinfo2 );
  83.438 @@ -2434,13 +2583,24 @@ asmlinkage void svm_vmexit_handler(struc
  83.439           */
  83.440          break;
  83.441  
  83.442 +    case VMEXIT_INIT:
  83.443 +        /*
  83.444 +         * Nothing to do, in fact we should never get to this point. 
  83.445 +         */
  83.446 +        break;
  83.447 +
  83.448 +    case VMEXIT_EXCEPTION_BP:
  83.449  #ifdef XEN_DEBUGGER
  83.450 -    case VMEXIT_EXCEPTION_BP:
  83.451          svm_debug_save_cpu_user_regs(&regs);
  83.452          pdb_handle_exception(3, &regs, 1);
  83.453          svm_debug_restore_cpu_user_regs(&regs);
  83.454 +#else
  83.455 +        if ( test_bit(_DOMF_debugging, &v->domain->domain_flags) )
  83.456 +            domain_pause_for_debugger();
  83.457 +        else 
  83.458 +            svm_inject_exception(vmcb, TRAP_int3, 0, 0);
  83.459 +#endif
  83.460          break;
  83.461 -#endif
  83.462  
  83.463      case VMEXIT_EXCEPTION_NM:
  83.464          svm_do_no_device_fault(vmcb);
    84.1 --- a/xen/arch/x86/hvm/svm/vmcb.c	Mon Apr 17 08:47:36 2006 -0600
    84.2 +++ b/xen/arch/x86/hvm/svm/vmcb.c	Tue Apr 18 09:35:40 2006 -0600
    84.3 @@ -257,7 +257,8 @@ static int construct_init_vmcb_guest(str
    84.4      /* CR3 is set in svm_final_setup_guest */
    84.5  
    84.6      __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (crn) :); 
    84.7 -    arch_svm->cpu_shadow_cr4 = crn & ~(X86_CR4_PGE | X86_CR4_PSE);
    84.8 +    crn &= ~(X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE);
    84.9 +    arch_svm->cpu_shadow_cr4 = crn;
   84.10      vmcb->cr4 = crn | SVM_CR4_HOST_MASK;
   84.11  
   84.12      vmcb->rsp = 0;
   84.13 @@ -484,6 +485,7 @@ void svm_do_resume(struct vcpu *v)
   84.14      if ( vpit->first_injected ) {
   84.15          if ( v->domain->arch.hvm_domain.guest_time ) {
   84.16              svm_set_guest_time(v, v->domain->arch.hvm_domain.guest_time);
   84.17 +            vpit->count_point = NOW();
   84.18              v->domain->arch.hvm_domain.guest_time = 0;
   84.19          }
   84.20          pickup_deactive_ticks(vpit);
    85.1 --- a/xen/arch/x86/hvm/vmx/io.c	Mon Apr 17 08:47:36 2006 -0600
    85.2 +++ b/xen/arch/x86/hvm/vmx/io.c	Tue Apr 18 09:35:40 2006 -0600
    85.3 @@ -84,7 +84,8 @@ interrupt_post_injection(struct vcpu * v
    85.4          } else {
    85.5              vpit->pending_intr_nr--;
    85.6          }
    85.7 -        vpit->inject_point = NOW();
    85.8 +        vpit->count_advance = 0;
    85.9 +        vpit->count_point = NOW();
   85.10  
   85.11          vpit->last_pit_gtime += vpit->period_cycles;
   85.12          set_guest_time(v, vpit->last_pit_gtime);
   85.13 @@ -208,6 +209,7 @@ void vmx_do_resume(struct vcpu *v)
   85.14      /* pick up the elapsed PIT ticks and re-enable pit_timer */
   85.15      if ( vpit->first_injected ) {
   85.16          if ( v->domain->arch.hvm_domain.guest_time ) {
   85.17 +            vpit->count_point = NOW();
   85.18              set_guest_time(v, v->domain->arch.hvm_domain.guest_time);
   85.19              v->domain->arch.hvm_domain.guest_time = 0;
   85.20          }
    86.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Mon Apr 17 08:47:36 2006 -0600
    86.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Tue Apr 18 09:35:40 2006 -0600
    86.3 @@ -362,6 +362,7 @@ static void vmx_freeze_time(struct vcpu 
    86.4      
    86.5      if ( vpit->first_injected && !v->domain->arch.hvm_domain.guest_time ) {
    86.6          v->domain->arch.hvm_domain.guest_time = get_guest_time(v);
    86.7 +        vpit->count_advance += (NOW() - vpit->count_point);
    86.8          stop_timer(&(vpit->pit_timer));
    86.9      }
   86.10  }
    87.1 --- a/xen/arch/x86/hvm/vmx/x86_64/exits.S	Mon Apr 17 08:47:36 2006 -0600
    87.2 +++ b/xen/arch/x86/hvm/vmx/x86_64/exits.S	Tue Apr 18 09:35:40 2006 -0600
    87.3 @@ -94,6 +94,7 @@
    87.4  ENTRY(vmx_asm_vmexit_handler)
    87.5          /* selectors are restored/saved by VMX */
    87.6          HVM_SAVE_ALL_NOSEGREGS
    87.7 +        call vmx_trace_vmexit
    87.8          call vmx_vmexit_handler
    87.9          jmp vmx_asm_do_resume
   87.10  
   87.11 @@ -114,6 +115,7 @@ 1:
   87.12  /* vmx_restore_all_guest */
   87.13          call vmx_intr_assist
   87.14          call vmx_load_cr2
   87.15 +        call vmx_trace_vmentry
   87.16          .endif
   87.17          /* 
   87.18           * Check if we are going back to VMX-based VM
    88.1 --- a/xen/arch/x86/i8259.c	Mon Apr 17 08:47:36 2006 -0600
    88.2 +++ b/xen/arch/x86/i8259.c	Tue Apr 18 09:35:40 2006 -0600
    88.3 @@ -318,7 +318,7 @@ void __init init_8259A(int auto_eoi)
    88.4       * outb_p - this has to work on a wide range of PC hardware.
    88.5       */
    88.6      outb_p(0x11, 0x20);     /* ICW1: select 8259A-1 init */
    88.7 -    outb_p(0x20 + 0, 0x21); /* ICW2: 8259A-1 IR0-7 mapped to 0x20-0x27 */
    88.8 +    outb_p(FIRST_LEGACY_VECTOR + 0, 0x21); /* ICW2: 8259A-1 IR0-7 */
    88.9      outb_p(0x04, 0x21);     /* 8259A-1 (the master) has a slave on IR2 */
   88.10      if (auto_eoi)
   88.11          outb_p(0x03, 0x21); /* master does Auto EOI */
   88.12 @@ -326,7 +326,7 @@ void __init init_8259A(int auto_eoi)
   88.13          outb_p(0x01, 0x21); /* master expects normal EOI */
   88.14  
   88.15      outb_p(0x11, 0xA0);     /* ICW1: select 8259A-2 init */
   88.16 -    outb_p(0x20 + 8, 0xA1); /* ICW2: 8259A-2 IR0-7 mapped to 0x28-0x2f */
   88.17 +    outb_p(FIRST_LEGACY_VECTOR + 8, 0xA1); /* ICW2: 8259A-2 IR0-7 */
   88.18      outb_p(0x02, 0xA1);     /* 8259A-2 is a slave on master's IR2 */
   88.19      outb_p(0x01, 0xA1);     /* (slave's support for AEOI in flat mode
   88.20                                 is to be investigated) */
    89.1 --- a/xen/arch/x86/io_apic.c	Mon Apr 17 08:47:36 2006 -0600
    89.2 +++ b/xen/arch/x86/io_apic.c	Tue Apr 18 09:35:40 2006 -0600
    89.3 @@ -657,11 +657,11 @@ static inline int IO_APIC_irq_trigger(in
    89.4  }
    89.5  
    89.6  /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
    89.7 -u8 irq_vector[NR_IRQ_VECTORS] __read_mostly = { FIRST_DEVICE_VECTOR , 0 };
    89.8 +u8 irq_vector[NR_IRQ_VECTORS] __read_mostly;
    89.9  
   89.10  int assign_irq_vector(int irq)
   89.11  {
   89.12 -    static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
   89.13 +    static int current_vector = FIRST_DYNAMIC_VECTOR, offset = 0;
   89.14  
   89.15      BUG_ON(irq >= NR_IRQ_VECTORS);
   89.16      if (irq != AUTO_ASSIGN && IO_APIC_VECTOR(irq) > 0)
   89.17 @@ -677,11 +677,11 @@ next:
   89.18      if (current_vector == 0x80)
   89.19          goto next;
   89.20  
   89.21 -    if (current_vector >= FIRST_SYSTEM_VECTOR) {
   89.22 +    if (current_vector > LAST_DYNAMIC_VECTOR) {
   89.23          offset++;
   89.24          if (!(offset%8))
   89.25              return -ENOSPC;
   89.26 -        current_vector = FIRST_DEVICE_VECTOR + offset;
   89.27 +        current_vector = FIRST_DYNAMIC_VECTOR + offset;
   89.28      }
   89.29  
   89.30      vector_irq[current_vector] = irq;
   89.31 @@ -1321,11 +1321,26 @@ static unsigned int startup_level_ioapic
   89.32      return 0; /* don't check for pending */
   89.33  }
   89.34  
   89.35 +int ioapic_ack_new = 1;
   89.36 +static void setup_ioapic_ack(char *s)
   89.37 +{
   89.38 +    if ( !strcmp(s, "old") )
   89.39 +        ioapic_ack_new = 0;
   89.40 +    else if ( !strcmp(s, "new") )
   89.41 +        ioapic_ack_new = 1;
   89.42 +    else
   89.43 +        printk("Unknown ioapic_ack value specified: '%s'\n", s);
   89.44 +}
   89.45 +custom_param("ioapic_ack", setup_ioapic_ack);
   89.46 +
   89.47  static void mask_and_ack_level_ioapic_irq (unsigned int irq)
   89.48  {
   89.49      unsigned long v;
   89.50      int i;
   89.51  
   89.52 +    if ( ioapic_ack_new )
   89.53 +        return;
   89.54 +
   89.55      mask_IO_APIC_irq(irq);
   89.56  /*
   89.57   * It appears there is an erratum which affects at least version 0x11
   89.58 @@ -1363,7 +1378,51 @@ static void mask_and_ack_level_ioapic_ir
   89.59  
   89.60  static void end_level_ioapic_irq (unsigned int irq)
   89.61  {
   89.62 -    unmask_IO_APIC_irq(irq);
   89.63 +    unsigned long v;
   89.64 +    int i;
   89.65 +
   89.66 +    if ( !ioapic_ack_new )
   89.67 +    {
   89.68 +        if ( !(irq_desc[IO_APIC_VECTOR(irq)].status & IRQ_DISABLED) )
   89.69 +            unmask_IO_APIC_irq(irq);
   89.70 +        return;
   89.71 +    }
   89.72 +
   89.73 +/*
   89.74 + * It appears there is an erratum which affects at least version 0x11
   89.75 + * of I/O APIC (that's the 82093AA and cores integrated into various
   89.76 + * chipsets).  Under certain conditions a level-triggered interrupt is
   89.77 + * erroneously delivered as edge-triggered one but the respective IRR
   89.78 + * bit gets set nevertheless.  As a result the I/O unit expects an EOI
   89.79 + * message but it will never arrive and further interrupts are blocked
   89.80 + * from the source.  The exact reason is so far unknown, but the
   89.81 + * phenomenon was observed when two consecutive interrupt requests
   89.82 + * from a given source get delivered to the same CPU and the source is
   89.83 + * temporarily disabled in between.
   89.84 + *
   89.85 + * A workaround is to simulate an EOI message manually.  We achieve it
   89.86 + * by setting the trigger mode to edge and then to level when the edge
   89.87 + * trigger mode gets detected in the TMR of a local APIC for a
   89.88 + * level-triggered interrupt.  We mask the source for the time of the
   89.89 + * operation to prevent an edge-triggered interrupt escaping meanwhile.
   89.90 + * The idea is from Manfred Spraul.  --macro
   89.91 + */
   89.92 +    i = IO_APIC_VECTOR(irq);
   89.93 +
   89.94 +    v = apic_read(APIC_TMR + ((i & ~0x1f) >> 1));
   89.95 +
   89.96 +    ack_APIC_irq();
   89.97 +
   89.98 +    if (!(v & (1 << (i & 0x1f)))) {
   89.99 +        atomic_inc(&irq_mis_count);
  89.100 +        spin_lock(&ioapic_lock);
  89.101 +        __mask_IO_APIC_irq(irq);
  89.102 +        __edge_IO_APIC_irq(irq);
  89.103 +        __level_IO_APIC_irq(irq);
  89.104 +        if ( !(irq_desc[IO_APIC_VECTOR(irq)].status & IRQ_DISABLED) )
  89.105 +            __unmask_IO_APIC_irq(irq);
  89.106 +        spin_unlock(&ioapic_lock);
  89.107 +    }
  89.108  }
  89.109  
  89.110  static unsigned int startup_edge_ioapic_vector(unsigned int vector)
  89.111 @@ -1695,6 +1754,7 @@ void __init setup_IO_APIC(void)
  89.112          io_apic_irqs = ~PIC_IRQS;
  89.113  
  89.114      printk("ENABLING IO-APIC IRQs\n");
  89.115 +    printk(" -> Using %s ACK method\n", ioapic_ack_new ? "new" : "old");
  89.116  
  89.117      /*
  89.118       * Set up IO-APIC IRQ routing.
  89.119 @@ -1956,9 +2016,9 @@ int ioapic_guest_write(unsigned long phy
  89.120          return 0;
  89.121      }
  89.122  
  89.123 -    if ( old_rte.vector >= FIRST_DEVICE_VECTOR )
  89.124 +    if ( old_rte.vector >= FIRST_DYNAMIC_VECTOR )
  89.125          old_irq = vector_irq[old_rte.vector];
  89.126 -    if ( new_rte.vector >= FIRST_DEVICE_VECTOR )
  89.127 +    if ( new_rte.vector >= FIRST_DYNAMIC_VECTOR )
  89.128          new_irq = vector_irq[new_rte.vector];
  89.129  
  89.130      if ( (old_irq != new_irq) && (old_irq != -1) && IO_APIC_IRQ(old_irq) )
    90.1 --- a/xen/arch/x86/irq.c	Mon Apr 17 08:47:36 2006 -0600
    90.2 +++ b/xen/arch/x86/irq.c	Tue Apr 18 09:35:40 2006 -0600
    90.3 @@ -148,48 +148,236 @@ typedef struct {
    90.4      u8 nr_guests;
    90.5      u8 in_flight;
    90.6      u8 shareable;
    90.7 +    u8 ack_type;
    90.8 +#define ACKTYPE_NONE   0     /* No final acknowledgement is required */
    90.9 +#define ACKTYPE_UNMASK 1     /* Unmask PIC hardware (from any CPU)   */
   90.10 +#define ACKTYPE_EOI    2     /* EOI on the CPU that was interrupted  */
   90.11 +    cpumask_t cpu_eoi_map;   /* CPUs that need to EOI this interrupt */
   90.12      struct domain *guest[IRQ_MAX_GUESTS];
   90.13  } irq_guest_action_t;
   90.14  
   90.15 +/*
   90.16 + * Stack of interrupts awaiting EOI on each CPU. These must be popped in
   90.17 + * order, as only the current highest-priority pending irq can be EOIed.
   90.18 + */
   90.19 +static struct {
   90.20 +    u8 vector; /* Vector awaiting EOI */
   90.21 +    u8 ready;  /* Ready for EOI now?  */
   90.22 +} pending_eoi[NR_CPUS][NR_VECTORS] __cacheline_aligned;
   90.23 +#define pending_eoi_sp(cpu) (pending_eoi[cpu][NR_VECTORS-1].vector)
   90.24 +
   90.25  static void __do_IRQ_guest(int vector)
   90.26  {
   90.27      unsigned int        irq = vector_to_irq(vector);
   90.28      irq_desc_t         *desc = &irq_desc[vector];
   90.29      irq_guest_action_t *action = (irq_guest_action_t *)desc->action;
   90.30      struct domain      *d;
   90.31 -    int                 i;
   90.32 +    int                 i, sp, cpu = smp_processor_id();
   90.33 +
   90.34 +    if ( unlikely(action->nr_guests == 0) )
   90.35 +    {
   90.36 +        /* An interrupt may slip through while freeing an ACKTYPE_EOI irq. */
   90.37 +        ASSERT(action->ack_type == ACKTYPE_EOI);
   90.38 +        ASSERT(desc->status & IRQ_DISABLED);
   90.39 +        desc->handler->end(vector);
   90.40 +        return;
   90.41 +    }
   90.42 +
   90.43 +    if ( action->ack_type == ACKTYPE_EOI )
   90.44 +    {
   90.45 +        sp = pending_eoi_sp(cpu);
   90.46 +        ASSERT((sp == 0) || (pending_eoi[cpu][sp-1].vector < vector));
   90.47 +        ASSERT(sp < (NR_VECTORS-1));
   90.48 +        pending_eoi[cpu][sp].vector = vector;
   90.49 +        pending_eoi[cpu][sp].ready = 0;
   90.50 +        pending_eoi_sp(cpu) = sp+1;
   90.51 +        cpu_set(cpu, action->cpu_eoi_map);
   90.52 +    }
   90.53  
   90.54      for ( i = 0; i < action->nr_guests; i++ )
   90.55      {
   90.56          d = action->guest[i];
   90.57 -        if ( !test_and_set_bit(irq, &d->pirq_mask) )
   90.58 +        if ( (action->ack_type != ACKTYPE_NONE) &&
   90.59 +             !test_and_set_bit(irq, &d->pirq_mask) )
   90.60              action->in_flight++;
   90.61          send_guest_pirq(d, irq);
   90.62      }
   90.63  }
   90.64  
   90.65 +/* Flush all ready EOIs from the top of this CPU's pending-EOI stack. */
   90.66 +static void flush_ready_eoi(void *unused)
   90.67 +{
   90.68 +    irq_desc_t *desc;
   90.69 +    int         vector, sp, cpu = smp_processor_id();
   90.70 +
   90.71 +    ASSERT(!local_irq_is_enabled());
   90.72 +
   90.73 +    sp = pending_eoi_sp(cpu);
   90.74 +
   90.75 +    while ( (--sp >= 0) && pending_eoi[cpu][sp].ready )
   90.76 +    {
   90.77 +        vector = pending_eoi[cpu][sp].vector;
   90.78 +        desc = &irq_desc[vector];
   90.79 +        spin_lock(&desc->lock);
   90.80 +        desc->handler->end(vector);
   90.81 +        spin_unlock(&desc->lock);
   90.82 +    }
   90.83 +
   90.84 +    pending_eoi_sp(cpu) = sp+1;
   90.85 +}
   90.86 +
   90.87 +static void __set_eoi_ready(irq_desc_t *desc)
   90.88 +{
   90.89 +    irq_guest_action_t *action = (irq_guest_action_t *)desc->action;
   90.90 +    int                 vector, sp, cpu = smp_processor_id();
   90.91 +
   90.92 +    vector = desc - irq_desc;
   90.93 +
   90.94 +    if ( !(desc->status & IRQ_GUEST) ||
   90.95 +         (action->in_flight != 0) ||
   90.96 +         !test_and_clear_bit(cpu, &action->cpu_eoi_map) )
   90.97 +        return;
   90.98 +
   90.99 +    sp = pending_eoi_sp(cpu);
  90.100 +    do {
  90.101 +        ASSERT(sp > 0);
  90.102 +    } while ( pending_eoi[cpu][--sp].vector != vector );
  90.103 +    ASSERT(!pending_eoi[cpu][sp].ready);
  90.104 +    pending_eoi[cpu][sp].ready = 1;
  90.105 +}
  90.106 +
  90.107 +/* Mark specified IRQ as ready-for-EOI (if it really is) and attempt to EOI. */
  90.108 +static void set_eoi_ready(void *data)
  90.109 +{
  90.110 +    irq_desc_t *desc = data;
  90.111 +
  90.112 +    ASSERT(!local_irq_is_enabled());
  90.113 +
  90.114 +    spin_lock(&desc->lock);
  90.115 +    __set_eoi_ready(desc);
  90.116 +    spin_unlock(&desc->lock);
  90.117 +
  90.118 +    flush_ready_eoi(NULL);
  90.119 +}
  90.120 +
  90.121 +/*
  90.122 + * Forcibly flush all pending EOIs on this CPU by emulating end-of-ISR
  90.123 + * notifications from guests. The caller of this function must ensure that
  90.124 + * all CPUs execute flush_ready_eoi().
  90.125 + */
  90.126 +static void flush_all_pending_eoi(void *unused)
  90.127 +{
  90.128 +    irq_desc_t         *desc;
  90.129 +    irq_guest_action_t *action;
  90.130 +    int                 i, vector, sp, cpu = smp_processor_id();
  90.131 +
  90.132 +    ASSERT(!local_irq_is_enabled());
  90.133 +
  90.134 +    sp = pending_eoi_sp(cpu);
  90.135 +    while ( --sp >= 0 )
  90.136 +    {
  90.137 +        if ( pending_eoi[cpu][sp].ready )
  90.138 +            continue;
  90.139 +        vector = pending_eoi[cpu][sp].vector;
  90.140 +        desc = &irq_desc[vector];
  90.141 +        spin_lock(&desc->lock);
  90.142 +        action = (irq_guest_action_t *)desc->action;
  90.143 +        ASSERT(action->ack_type == ACKTYPE_EOI);
  90.144 +        ASSERT(desc->status & IRQ_GUEST);
  90.145 +        for ( i = 0; i < action->nr_guests; i++ )
  90.146 +            clear_bit(vector_to_irq(vector), &action->guest[i]->pirq_mask);
  90.147 +        action->in_flight = 0;
  90.148 +        spin_unlock(&desc->lock);
  90.149 +    }
  90.150 +
  90.151 +    flush_ready_eoi(NULL);
  90.152 +}
  90.153 +
  90.154  int pirq_guest_unmask(struct domain *d)
  90.155  {
  90.156 -    irq_desc_t    *desc;
  90.157 -    unsigned int   pirq;
  90.158 -    shared_info_t *s = d->shared_info;
  90.159 +    irq_desc_t         *desc;
  90.160 +    irq_guest_action_t *action;
  90.161 +    cpumask_t           cpu_eoi_map = CPU_MASK_NONE;
  90.162 +    unsigned int        pirq, cpu = smp_processor_id();
  90.163 +    shared_info_t      *s = d->shared_info;
  90.164  
  90.165      for ( pirq = find_first_bit(d->pirq_mask, NR_PIRQS);
  90.166            pirq < NR_PIRQS;
  90.167            pirq = find_next_bit(d->pirq_mask, NR_PIRQS, pirq+1) )
  90.168      {
  90.169 -        desc = &irq_desc[irq_to_vector(pirq)];
  90.170 +        desc   = &irq_desc[irq_to_vector(pirq)];
  90.171 +        action = (irq_guest_action_t *)desc->action;
  90.172 +
  90.173          spin_lock_irq(&desc->lock);
  90.174 +
  90.175          if ( !test_bit(d->pirq_to_evtchn[pirq], &s->evtchn_mask[0]) &&
  90.176 -             test_and_clear_bit(pirq, &d->pirq_mask) &&
  90.177 -             (--((irq_guest_action_t *)desc->action)->in_flight == 0) )
  90.178 -            desc->handler->end(irq_to_vector(pirq));
  90.179 -        spin_unlock_irq(&desc->lock);
  90.180 +             test_and_clear_bit(pirq, &d->pirq_mask) )
  90.181 +        {
  90.182 +            ASSERT(action->ack_type != ACKTYPE_NONE);
  90.183 +            if ( --action->in_flight == 0 )
  90.184 +            {
  90.185 +                if ( action->ack_type == ACKTYPE_UNMASK )
  90.186 +                    desc->handler->end(irq_to_vector(pirq));
  90.187 +                cpu_eoi_map = action->cpu_eoi_map;
  90.188 +            }
  90.189 +        }
  90.190 +
  90.191 +        if ( __test_and_clear_bit(cpu, &cpu_eoi_map) )
  90.192 +        {
  90.193 +            __set_eoi_ready(desc);
  90.194 +            spin_unlock(&desc->lock);
  90.195 +            flush_ready_eoi(NULL);
  90.196 +            local_irq_enable();
  90.197 +        }
  90.198 +        else
  90.199 +        {
  90.200 +            spin_unlock_irq(&desc->lock);
  90.201 +        }
  90.202 +
  90.203 +        if ( !cpus_empty(cpu_eoi_map) )
  90.204 +        {
  90.205 +            on_selected_cpus(cpu_eoi_map, set_eoi_ready, desc, 1, 0);
  90.206 +            cpu_eoi_map = CPU_MASK_NONE;
  90.207 +        }
  90.208      }
  90.209  
  90.210      return 0;
  90.211  }
  90.212  
  90.213 +extern int ioapic_ack_new;
  90.214 +int pirq_acktype(int irq)
  90.215 +{
  90.216 +    irq_desc_t  *desc;
  90.217 +    unsigned int vector;
  90.218 +
  90.219 +    vector = irq_to_vector(irq);
  90.220 +    if ( vector == 0 )
  90.221 +        return ACKTYPE_NONE;
  90.222 +
  90.223 +    desc = &irq_desc[vector];
  90.224 +
  90.225 +    /*
  90.226 +     * Edge-triggered IO-APIC interrupts need no final acknowledgement:
  90.227 +     * we ACK early during interrupt processing.
  90.228 +     */
  90.229 +    if ( !strcmp(desc->handler->typename, "IO-APIC-edge") )
  90.230 +        return ACKTYPE_NONE;
  90.231 +
  90.232 +    /* Legacy PIC interrupts can be acknowledged from any CPU. */
  90.233 +    if ( !strcmp(desc->handler->typename, "XT-PIC") )
  90.234 +        return ACKTYPE_UNMASK;
  90.235 +
  90.236 +    /*
  90.237 +     * Level-triggered IO-APIC interrupts need to be acknowledged on the CPU
  90.238 +     * on which they were received. This is because we tickle the LAPIC to EOI.
  90.239 +     */
  90.240 +    if ( !strcmp(desc->handler->typename, "IO-APIC-level") )
  90.241 +        return ioapic_ack_new ? ACKTYPE_EOI : ACKTYPE_UNMASK;
  90.242 +
  90.243 +    BUG();
  90.244 +    return 0;
  90.245 +}
  90.246 +
  90.247  int pirq_guest_bind(struct vcpu *v, int irq, int will_share)
  90.248  {
  90.249      unsigned int        vector;
  90.250 @@ -202,6 +390,7 @@ int pirq_guest_bind(struct vcpu *v, int 
  90.251      if ( (irq < 0) || (irq >= NR_IRQS) )
  90.252          return -EINVAL;
  90.253  
  90.254 + retry:
  90.255      vector = irq_to_vector(irq);
  90.256      if ( vector == 0 )
  90.257          return -EINVAL;
  90.258 @@ -230,10 +419,12 @@ int pirq_guest_bind(struct vcpu *v, int 
  90.259              goto out;
  90.260          }
  90.261  
  90.262 -        action->nr_guests = 0;
  90.263 -        action->in_flight = 0;
  90.264 -        action->shareable = will_share;
  90.265 -        
  90.266 +        action->nr_guests   = 0;
  90.267 +        action->in_flight   = 0;
  90.268 +        action->shareable   = will_share;
  90.269 +        action->ack_type    = pirq_acktype(irq);
  90.270 +        action->cpu_eoi_map = CPU_MASK_NONE;
  90.271 +
  90.272          desc->depth = 0;
  90.273          desc->status |= IRQ_GUEST;
  90.274          desc->status &= ~IRQ_DISABLED;
  90.275 @@ -251,6 +442,18 @@ int pirq_guest_bind(struct vcpu *v, int 
  90.276          rc = -EBUSY;
  90.277          goto out;
  90.278      }
  90.279 +    else if ( action->nr_guests == 0 )
  90.280 +    {
  90.281 +        /*
  90.282 +         * Indicates that an ACKTYPE_EOI interrupt is being released.
  90.283 +         * Wait for that to happen before continuing.
  90.284 +         */
  90.285 +        ASSERT(action->ack_type == ACKTYPE_EOI);
  90.286 +        ASSERT(desc->status & IRQ_DISABLED);
  90.287 +        spin_unlock_irqrestore(&desc->lock, flags);
  90.288 +        cpu_relax();
  90.289 +        goto retry;
  90.290 +    }
  90.291  
  90.292      if ( action->nr_guests == IRQ_MAX_GUESTS )
  90.293      {
  90.294 @@ -271,6 +474,7 @@ int pirq_guest_unbind(struct domain *d, 
  90.295      unsigned int        vector = irq_to_vector(irq);
  90.296      irq_desc_t         *desc = &irq_desc[vector];
  90.297      irq_guest_action_t *action;
  90.298 +    cpumask_t           cpu_eoi_map;
  90.299      unsigned long       flags;
  90.300      int                 i;
  90.301  
  90.302 @@ -280,28 +484,68 @@ int pirq_guest_unbind(struct domain *d, 
  90.303  
  90.304      action = (irq_guest_action_t *)desc->action;
  90.305  
  90.306 -    if ( test_and_clear_bit(irq, &d->pirq_mask) &&
  90.307 -         (--action->in_flight == 0) )
  90.308 -        desc->handler->end(vector);
  90.309 +    i = 0;
  90.310 +    while ( action->guest[i] && (action->guest[i] != d) )
  90.311 +        i++;
  90.312 +    memmove(&action->guest[i], &action->guest[i+1], IRQ_MAX_GUESTS-i-1);
  90.313 +    action->nr_guests--;
  90.314  
  90.315 -    if ( action->nr_guests == 1 )
  90.316 +    switch ( action->ack_type )
  90.317      {
  90.318 -        desc->action = NULL;
  90.319 -        xfree(action);
  90.320 -        desc->depth   = 1;
  90.321 -        desc->status |= IRQ_DISABLED;
  90.322 -        desc->status &= ~IRQ_GUEST;
  90.323 -        desc->handler->shutdown(vector);
  90.324 -    }
  90.325 -    else
  90.326 -    {
  90.327 -        i = 0;
  90.328 -        while ( action->guest[i] && (action->guest[i] != d) )
  90.329 -            i++;
  90.330 -        memmove(&action->guest[i], &action->guest[i+1], IRQ_MAX_GUESTS-i-1);
  90.331 -        action->nr_guests--;
  90.332 +    case ACKTYPE_UNMASK:
  90.333 +        if ( test_and_clear_bit(irq, &d->pirq_mask) &&
  90.334 +             (--action->in_flight == 0) )
  90.335 +            desc->handler->end(vector);
  90.336 +        break;
  90.337 +    case ACKTYPE_EOI:
  90.338 +        /* NB. If #guests == 0 then we clear the eoi_map later on. */
  90.339 +        if ( test_and_clear_bit(irq, &d->pirq_mask) &&
  90.340 +             (--action->in_flight == 0) &&
  90.341 +             (action->nr_guests != 0) )
  90.342 +        {
  90.343 +            cpu_eoi_map = action->cpu_eoi_map;
  90.344 +            spin_unlock_irqrestore(&desc->lock, flags);    
  90.345 +            on_selected_cpus(cpu_eoi_map, set_eoi_ready, desc, 1, 0);
  90.346 +            spin_lock_irqsave(&desc->lock, flags);
  90.347 +        }
  90.348 +        break;
  90.349      }
  90.350  
  90.351 +    BUG_ON(test_bit(irq, &d->pirq_mask));
  90.352 +
  90.353 +    if ( action->nr_guests != 0 )
  90.354 +        goto out;
  90.355 +
  90.356 +    BUG_ON(action->in_flight != 0);
  90.357 +
  90.358 +    /* Disabling IRQ before releasing the desc_lock avoids an IRQ storm. */
  90.359 +    desc->depth   = 1;
  90.360 +    desc->status |= IRQ_DISABLED;
  90.361 +    desc->handler->disable(vector);
  90.362 +
  90.363 +    /*
  90.364 +     * We may have a EOI languishing anywhere in one of the per-CPU
  90.365 +     * EOI stacks. Forcibly flush the stack on every CPU where this might
  90.366 +     * be the case.
  90.367 +     */
  90.368 +    cpu_eoi_map = action->cpu_eoi_map;
  90.369 +    if ( !cpus_empty(cpu_eoi_map) )
  90.370 +    {
  90.371 +        BUG_ON(action->ack_type != ACKTYPE_EOI);
  90.372 +        spin_unlock_irqrestore(&desc->lock, flags);
  90.373 +        on_selected_cpus(cpu_eoi_map, flush_all_pending_eoi, NULL, 1, 1);
  90.374 +        on_selected_cpus(cpu_online_map, flush_ready_eoi, NULL, 1, 1);
  90.375 +        spin_lock_irqsave(&desc->lock, flags);
  90.376 +    }
  90.377 +
  90.378 +    BUG_ON(!cpus_empty(action->cpu_eoi_map));
  90.379 +
  90.380 +    desc->action = NULL;
  90.381 +    xfree(action);
  90.382 +    desc->status &= ~IRQ_GUEST;
  90.383 +    desc->handler->shutdown(vector);
  90.384 +
  90.385 + out:
  90.386      spin_unlock_irqrestore(&desc->lock, flags);    
  90.387      return 0;
  90.388  }
  90.389 @@ -373,3 +617,41 @@ static int __init setup_dump_irqs(void)
  90.390      return 0;
  90.391  }
  90.392  __initcall(setup_dump_irqs);
  90.393 +
  90.394 +static struct timer end_irq_timer[NR_CPUS];
  90.395 +
  90.396 +/*
  90.397 + * force_intack: Forcibly emit all pending EOIs on each CPU every second.
  90.398 + * Mainly useful for debugging or poking lazy guests ISRs.
  90.399 + */
  90.400 +
  90.401 +static void end_irq_timeout(void *unused)
  90.402 +{
  90.403 +    int cpu = smp_processor_id();
  90.404 +
  90.405 +    local_irq_disable();
  90.406 +    flush_all_pending_eoi(NULL);
  90.407 +    local_irq_enable();
  90.408 +
  90.409 +    on_selected_cpus(cpu_online_map, flush_ready_eoi, NULL, 1, 0);
  90.410 +
  90.411 +    set_timer(&end_irq_timer[cpu], NOW() + MILLISECS(1000));
  90.412 +}
  90.413 +
  90.414 +static void __init __setup_irq_timeout(void *unused)
  90.415 +{
  90.416 +    int cpu = smp_processor_id();
  90.417 +    init_timer(&end_irq_timer[cpu], end_irq_timeout, NULL, cpu);
  90.418 +    set_timer(&end_irq_timer[cpu], NOW() + MILLISECS(1000));
  90.419 +}
  90.420 +
  90.421 +static int force_intack;
  90.422 +boolean_param("force_intack", force_intack);
  90.423 +
  90.424 +static int __init setup_irq_timeout(void)
  90.425 +{
  90.426 +    if ( force_intack )
  90.427 +        on_each_cpu(__setup_irq_timeout, NULL, 1, 1);
  90.428 +    return 0;
  90.429 +}
  90.430 +__initcall(setup_irq_timeout);
    91.1 --- a/xen/arch/x86/physdev.c	Mon Apr 17 08:47:36 2006 -0600
    91.2 +++ b/xen/arch/x86/physdev.c	Tue Apr 18 09:35:40 2006 -0600
    91.3 @@ -18,6 +18,9 @@ ioapic_guest_read(
    91.4  extern int
    91.5  ioapic_guest_write(
    91.6      unsigned long physbase, unsigned int reg, u32 pval);
    91.7 +extern int
    91.8 +pirq_acktype(
    91.9 +    int irq);
   91.10  
   91.11  /*
   91.12   * Demuxing hypercall.
   91.13 @@ -43,8 +46,7 @@ long do_physdev_op(GUEST_HANDLE(physdev_
   91.14          if ( (irq < 0) || (irq >= NR_IRQS) )
   91.15              break;
   91.16          op.u.irq_status_query.flags = 0;
   91.17 -        /* Edge-triggered interrupts don't need an explicit unmask downcall. */
   91.18 -        if ( !strstr(irq_desc[irq_to_vector(irq)].handler->typename, "edge") )
   91.19 +        if ( pirq_acktype(irq) != 0 )
   91.20              op.u.irq_status_query.flags |= PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY;
   91.21          ret = 0;
   91.22          break;
    92.1 --- a/xen/arch/x86/shadow.c	Mon Apr 17 08:47:36 2006 -0600
    92.2 +++ b/xen/arch/x86/shadow.c	Tue Apr 18 09:35:40 2006 -0600
    92.3 @@ -1531,14 +1531,10 @@ static void resync_pae_guest_l3(struct d
    92.4  
    92.5          idx = get_cr3_idxval(v);
    92.6          smfn = __shadow_status(
    92.7 -            d, ((unsigned long)(idx << PGT_score_shift) | entry->gpfn), PGT_l4_shadow);
    92.8 -
    92.9 -#ifndef NDEBUG
   92.10 +            d, ((unsigned long)(idx << PGT_pae_idx_shift) | entry->gpfn), PGT_l4_shadow);
   92.11 +
   92.12          if ( !smfn ) 
   92.13 -        {
   92.14 -            BUG();
   92.15 -        }
   92.16 -#endif
   92.17 +            continue;
   92.18  
   92.19          guest    = (pgentry_64_t *)map_domain_page(entry->gmfn);
   92.20          snapshot = (pgentry_64_t *)map_domain_page(entry->snapshot_mfn);
   92.21 @@ -1550,9 +1546,35 @@ static void resync_pae_guest_l3(struct d
   92.22              if ( entry_has_changed(
   92.23                      guest[index], snapshot[index], PAGE_FLAG_MASK) ) 
   92.24              {
   92.25 +                unsigned long gpfn;
   92.26 +
   92.27 +                /*
   92.28 +                 * Looks like it's no longer a page table. 
   92.29 +                 */
   92.30 +                if ( unlikely(entry_get_value(guest[index]) & PAE_PDPT_RESERVED) )
   92.31 +                {
   92.32 +                    if ( entry_get_flags(shadow_l3[i]) & _PAGE_PRESENT )
   92.33 +                        put_shadow_ref(entry_get_pfn(shadow_l3[i]));
   92.34 +
   92.35 +                    shadow_l3[i] = entry_empty();
   92.36 +                    continue;
   92.37 +                }
   92.38 +
   92.39 +                gpfn = entry_get_pfn(guest[index]);
   92.40 +
   92.41 +                if ( unlikely(gpfn != (gpfn & PGT_mfn_mask)) )
   92.42 +                {
   92.43 +                    if ( entry_get_flags(shadow_l3[i]) & _PAGE_PRESENT )
   92.44 +                        put_shadow_ref(entry_get_pfn(shadow_l3[i]));
   92.45 +
   92.46 +                    shadow_l3[i] = entry_empty();
   92.47 +                    continue;
   92.48 +                }
   92.49 +
   92.50                  validate_entry_change(d, &guest[index],
   92.51                                        &shadow_l3[i], PAGING_L3);
   92.52              }
   92.53 +
   92.54              if ( entry_get_value(guest[index]) != 0 )
   92.55                  max = i;
   92.56  
   92.57 @@ -1676,6 +1698,19 @@ static int resync_all(struct domain *d, 
   92.58                  {
   92.59                      int error;
   92.60  
   92.61 +#if CONFIG_PAGING_LEVELS == 4
   92.62 +                    unsigned long gpfn;
   92.63 +
   92.64 +                    gpfn = guest_l1e_get_paddr(guest1[i]) >> PAGE_SHIFT;
   92.65 +
   92.66 +                    if ( unlikely(gpfn != (gpfn & PGT_mfn_mask)) )
   92.67 +                    {
   92.68 +                        guest_l1_pgentry_t tmp_gl1e = guest_l1e_empty();
   92.69 +                        validate_pte_change(d, tmp_gl1e, sl1e_p);
   92.70 +                        continue;
   92.71 +                    }
   92.72 +#endif
   92.73 +
   92.74                      error = validate_pte_change(d, guest1[i], sl1e_p);
   92.75                      if ( error ==  -1 )
   92.76                          unshadow_l1 = 1;
   92.77 @@ -1698,6 +1733,7 @@ static int resync_all(struct domain *d, 
   92.78              perfc_incrc(resync_l1);
   92.79              perfc_incr_histo(wpt_updates, changed, PT_UPDATES);
   92.80              perfc_incr_histo(l1_entries_checked, max_shadow - min_shadow + 1, PT_UPDATES);
   92.81 +
   92.82              if ( d->arch.ops->guest_paging_levels >= PAGING_L3 &&
   92.83                   unshadow_l1 ) {
   92.84                  pgentry_64_t l2e = { 0 };
   92.85 @@ -1804,18 +1840,22 @@ static int resync_all(struct domain *d, 
   92.86              for ( i = min_shadow; i <= max_shadow; i++ )
   92.87              {
   92.88                  if ( (i < min_snapshot) || (i > max_snapshot) ||
   92.89 -                  entry_has_changed(
   92.90 -                      guest_pt[i], snapshot_pt[i], PAGE_FLAG_MASK) )
   92.91 +                    entry_has_changed(
   92.92 +                        guest_pt[i], snapshot_pt[i], PAGE_FLAG_MASK) )
   92.93                  {
   92.94 -
   92.95                      unsigned long gpfn;
   92.96  
   92.97                      gpfn = entry_get_pfn(guest_pt[i]);
   92.98                      /*
   92.99 -                     * Looks like it's longer a page table.
  92.100 +                     * Looks like it's no longer a page table.
  92.101                       */
  92.102                      if ( unlikely(gpfn != (gpfn & PGT_mfn_mask)) )
  92.103 +                    {
  92.104 +                        if ( entry_get_flags(shadow_pt[i]) & _PAGE_PRESENT )
  92.105 +                            put_shadow_ref(entry_get_pfn(shadow_pt[i]));
  92.106 +                         shadow_pt[i] = entry_empty(); 
  92.107                          continue;
  92.108 +                    }
  92.109  
  92.110                      need_flush |= validate_entry_change(
  92.111                          d, &guest_pt[i], &shadow_pt[i],
  92.112 @@ -1864,11 +1904,17 @@ static int resync_all(struct domain *d, 
  92.113                      unsigned long gpfn;
  92.114  
  92.115                      gpfn = l4e_get_pfn(new_root_e);
  92.116 +
  92.117                      /*
  92.118 -                     * Looks like it's longer a page table.
  92.119 +                     * Looks like it's no longer a page table.
  92.120                       */
  92.121                      if ( unlikely(gpfn != (gpfn & PGT_mfn_mask)) )
  92.122 +                    {
  92.123 +                        if ( l4e_get_flags(shadow4[i]) & _PAGE_PRESENT )
  92.124 +                            put_shadow_ref(l4e_get_pfn(shadow4[i]));
  92.125 +                        shadow4[i] = l4e_empty(); 
  92.126                          continue;
  92.127 +                    }
  92.128  
  92.129                      if ( d->arch.ops->guest_paging_levels == PAGING_L4 ) 
  92.130                      {
  92.131 @@ -2372,7 +2418,7 @@ static void shadow_update_pagetables(str
  92.132      if ( SH_GUEST_32PAE && d->arch.ops->guest_paging_levels == PAGING_L3 ) 
  92.133      {
  92.134          u32 index = get_cr3_idxval(v);
  92.135 -        gpfn = (index << PGT_score_shift) | gpfn;
  92.136 +        gpfn = ((unsigned long)index << PGT_pae_idx_shift) | gpfn;
  92.137      }
  92.138  #endif
  92.139  
  92.140 @@ -3233,8 +3279,35 @@ update_top_level_shadow(struct vcpu *v, 
  92.141      int i;
  92.142  
  92.143      for ( i = 0; i < PAE_L3_PAGETABLE_ENTRIES; i++ )
  92.144 +    {
  92.145 +        unsigned long gpfn;
  92.146 +
  92.147 +        /*
  92.148 +         * Looks like it's no longer a page table. 
  92.149 +         */
  92.150 +        if ( unlikely(entry_get_value(gple[index*4+i]) & PAE_PDPT_RESERVED) )
  92.151 +        {
  92.152 +            if ( entry_get_flags(sple[i]) & _PAGE_PRESENT )
  92.153 +                put_shadow_ref(entry_get_pfn(sple[i]));
  92.154 +
  92.155 +            sple[i] = entry_empty();
  92.156 +            continue;
  92.157 +        }
  92.158 +
  92.159 +        gpfn = entry_get_pfn(gple[index*4+i]);
  92.160 +
  92.161 +        if ( unlikely(gpfn != (gpfn & PGT_mfn_mask)) )
  92.162 +        {
  92.163 +            if ( entry_get_flags(sple[i]) & _PAGE_PRESENT )
  92.164 +                put_shadow_ref(entry_get_pfn(sple[i]));
  92.165 +
  92.166 +            sple[i] = entry_empty();
  92.167 +            continue;
  92.168 +        }
  92.169 +
  92.170          validate_entry_change(
  92.171              v->domain, &gple[index*4+i], &sple[i], PAGING_L3);
  92.172 +    }
  92.173  
  92.174      unmap_domain_page(sple);
  92.175  }
    93.1 --- a/xen/arch/x86/shadow32.c	Mon Apr 17 08:47:36 2006 -0600
    93.2 +++ b/xen/arch/x86/shadow32.c	Tue Apr 18 09:35:40 2006 -0600
    93.3 @@ -583,6 +583,13 @@ static void free_shadow_pages(struct dom
    93.4          {
    93.5              put_shadow_ref(pagetable_get_pfn(v->arch.shadow_table));
    93.6              v->arch.shadow_table = mk_pagetable(0);
    93.7 +
    93.8 +            if ( shadow_mode_external(d) )
    93.9 +            {
   93.10 +                if ( v->arch.shadow_vtable )
   93.11 +                    unmap_domain_page_global(v->arch.shadow_vtable);
   93.12 +                v->arch.shadow_vtable = NULL;
   93.13 +            }
   93.14          }
   93.15  
   93.16          if ( v->arch.monitor_shadow_ref )
   93.17 @@ -2886,7 +2893,7 @@ int shadow_fault(unsigned long va, struc
   93.18      SH_VVLOG("shadow_fault( va=%lx, code=%lu )",
   93.19               va, (unsigned long)regs->error_code);
   93.20      perfc_incrc(shadow_fault_calls);
   93.21 -    
   93.22 +
   93.23      check_pagetable(v, "pre-sf");
   93.24  
   93.25      /*
   93.26 @@ -2917,7 +2924,16 @@ int shadow_fault(unsigned long va, struc
   93.27      // the mapping is in-sync, so the check of the PDE's present bit, above,
   93.28      // covers this access.
   93.29      //
   93.30 -    orig_gpte = gpte = linear_pg_table[l1_linear_offset(va)];
   93.31 +    if ( __copy_from_user(&gpte,
   93.32 +                          &linear_pg_table[l1_linear_offset(va)],
   93.33 +                          sizeof(gpte)) ) {
   93.34 +        printk("%s() failed, crashing domain %d "
   93.35 +               "due to a unaccessible linear page table (gpde=%" PRIpte "), va=%lx\n",
   93.36 +               __func__, d->domain_id, l2e_get_intpte(gpde), va);
   93.37 +        domain_crash_synchronous();
   93.38 +    }
   93.39 +    orig_gpte = gpte;
   93.40 +
   93.41      if ( unlikely(!(l1e_get_flags(gpte) & _PAGE_PRESENT)) )
   93.42      {
   93.43          SH_VVLOG("shadow_fault - EXIT: gpte not present (%" PRIpte ") (gpde %" PRIpte ")",
   93.44 @@ -2928,7 +2944,7 @@ int shadow_fault(unsigned long va, struc
   93.45      }
   93.46  
   93.47      /* Write fault? */
   93.48 -    if ( regs->error_code & 2 )  
   93.49 +    if ( regs->error_code & 2 )
   93.50      {
   93.51          int allow_writes = 0;
   93.52  
   93.53 @@ -2942,7 +2958,7 @@ int shadow_fault(unsigned long va, struc
   93.54              else
   93.55              {
   93.56                  /* Write fault on a read-only mapping. */
   93.57 -                SH_VVLOG("shadow_fault - EXIT: wr fault on RO page (%" PRIpte ")", 
   93.58 +                SH_VVLOG("shadow_fault - EXIT: wr fault on RO page (%" PRIpte ")",
   93.59                           l1e_get_intpte(gpte));
   93.60                  perfc_incrc(shadow_fault_bail_ro_mapping);
   93.61                  goto fail;
   93.62 @@ -2955,10 +2971,10 @@ int shadow_fault(unsigned long va, struc
   93.63          }
   93.64  
   93.65          /* User access violation in guest? */
   93.66 -        if ( unlikely((regs->error_code & 4) && 
   93.67 +        if ( unlikely((regs->error_code & 4) &&
   93.68                        !(l1e_get_flags(gpte) & _PAGE_USER)))
   93.69          {
   93.70 -            SH_VVLOG("shadow_fault - EXIT: wr fault on super page (%" PRIpte ")", 
   93.71 +            SH_VVLOG("shadow_fault - EXIT: wr fault on super page (%" PRIpte ")",
   93.72                      l1e_get_intpte(gpte));
   93.73              goto fail;
   93.74  
   93.75 @@ -2980,7 +2996,7 @@ int shadow_fault(unsigned long va, struc
   93.76          /* Read-protection violation in guest? */
   93.77          if ( unlikely((regs->error_code & 1) ))
   93.78          {
   93.79 -            SH_VVLOG("shadow_fault - EXIT: read fault on super page (%" PRIpte ")", 
   93.80 +            SH_VVLOG("shadow_fault - EXIT: read fault on super page (%" PRIpte ")",
   93.81                      l1e_get_intpte(gpte));
   93.82              goto fail;
   93.83  
   93.84 @@ -3275,19 +3291,29 @@ void __update_pagetables(struct vcpu *v)
   93.85  
   93.86  void clear_all_shadow_status(struct domain *d)
   93.87  {
   93.88 +    struct vcpu *v = current;
   93.89 +
   93.90 +    /*
   93.91 +     * Don't clean up while other vcpus are working.
   93.92 +     */
   93.93 +    if ( v->vcpu_id )
   93.94 +        return;
   93.95 +
   93.96      shadow_lock(d);
   93.97 +
   93.98      free_shadow_pages(d);
   93.99      free_shadow_ht_entries(d);
  93.100 -    d->arch.shadow_ht = 
  93.101 +    d->arch.shadow_ht =
  93.102          xmalloc_array(struct shadow_status, shadow_ht_buckets);
  93.103      if ( d->arch.shadow_ht == NULL ) {
  93.104 -        printk("clear all shadow status:xmalloc fail\n");
  93.105 +        printk("clear all shadow status: xmalloc failed\n");
  93.106          domain_crash_synchronous();
  93.107      }
  93.108      memset(d->arch.shadow_ht, 0,
  93.109             shadow_ht_buckets * sizeof(struct shadow_status));
  93.110  
  93.111      free_out_of_sync_entries(d);
  93.112 +
  93.113      shadow_unlock(d);
  93.114  }
  93.115  
    94.1 --- a/xen/arch/x86/shadow_public.c	Mon Apr 17 08:47:36 2006 -0600
    94.2 +++ b/xen/arch/x86/shadow_public.c	Tue Apr 18 09:35:40 2006 -0600
    94.3 @@ -102,6 +102,15 @@ void free_shadow_pages(struct domain *d)
    94.4  
    94.5  int shadow_set_guest_paging_levels(struct domain *d, int levels)
    94.6  {
    94.7 +    struct vcpu *v = current;
    94.8 +
    94.9 +    /*
   94.10 +     * Need to wait for VCPU0 to complete the on-going shadow ops.
   94.11 +     */
   94.12 +
   94.13 +    if ( v->vcpu_id )
   94.14 +        return 1;
   94.15 +
   94.16      shadow_lock(d);
   94.17  
   94.18      switch(levels) {
   94.19 @@ -692,7 +701,6 @@ void free_fake_shadow_l2(struct domain *
   94.20  void free_shadow_page(unsigned long smfn)
   94.21  {
   94.22      struct page_info *page = mfn_to_page(smfn);
   94.23 -
   94.24      unsigned long gmfn = page->u.inuse.type_info & PGT_mfn_mask;
   94.25      struct domain *d = page_get_owner(mfn_to_page(gmfn));
   94.26      unsigned long gpfn = mfn_to_gmfn(d, gmfn);
   94.27 @@ -709,10 +717,9 @@ void free_shadow_page(unsigned long smfn
   94.28          if ( !mfn )
   94.29              gpfn |= (1UL << 63);
   94.30      }
   94.31 -    if (d->arch.ops->guest_paging_levels == PAGING_L3)
   94.32 -        if (type == PGT_l4_shadow ) {
   94.33 -            gpfn = ((unsigned long)page->tlbflush_timestamp << PGT_score_shift) | gpfn;
   94.34 -        }
   94.35 +    if ( d->arch.ops->guest_paging_levels == PAGING_L3 )
   94.36 +        if ( type == PGT_l4_shadow ) 
   94.37 +            gpfn = ((unsigned long)page->tlbflush_timestamp << PGT_pae_idx_shift) | gpfn;
   94.38  #endif
   94.39  
   94.40      delete_shadow_status(d, gpfn, gmfn, type);
   94.41 @@ -743,9 +750,24 @@ void free_shadow_page(unsigned long smfn
   94.42  #if CONFIG_PAGING_LEVELS >= 3
   94.43      case PGT_l2_shadow:
   94.44      case PGT_l3_shadow:
   94.45 +        shadow_demote(d, gpfn, gmfn);
   94.46 +        free_shadow_tables(d, smfn, shadow_type_to_level(type));
   94.47 +        d->arch.shadow_page_count--;
   94.48 +        break;
   94.49 +
   94.50      case PGT_l4_shadow:
   94.51          gpfn = gpfn & PGT_mfn_mask;
   94.52 -        shadow_demote(d, gpfn, gmfn);
   94.53 +        if ( d->arch.ops->guest_paging_levels == PAGING_L3 )
   94.54 +        {
   94.55 +            /*
   94.56 +             * Since a single PDPT page can have multiple PDPs, it's possible
   94.57 +             * that shadow_demote() has been already called for gmfn.
   94.58 +             */
   94.59 +            if ( mfn_is_page_table(gmfn) )
   94.60 +                shadow_demote(d, gpfn, gmfn);
   94.61 +        } else
   94.62 +            shadow_demote(d, gpfn, gmfn);
   94.63 +
   94.64          free_shadow_tables(d, smfn, shadow_type_to_level(type));
   94.65          d->arch.shadow_page_count--;
   94.66          break;
   94.67 @@ -898,6 +920,13 @@ void free_shadow_pages(struct domain *d)
   94.68          {
   94.69              put_shadow_ref(pagetable_get_pfn(v->arch.shadow_table));
   94.70              v->arch.shadow_table = mk_pagetable(0);
   94.71 +
   94.72 +            if ( shadow_mode_external(d) )
   94.73 +            {
   94.74 +                if ( v->arch.shadow_vtable )
   94.75 +                    unmap_domain_page_global(v->arch.shadow_vtable);
   94.76 +                v->arch.shadow_vtable = NULL;
   94.77 +            }
   94.78          }
   94.79  
   94.80          if ( v->arch.monitor_shadow_ref )
   94.81 @@ -2034,7 +2063,16 @@ void shadow_sync_and_drop_references(
   94.82  
   94.83  void clear_all_shadow_status(struct domain *d)
   94.84  {
   94.85 +    struct vcpu *v = current;
   94.86 +
   94.87 +    /*
   94.88 +     * Don't clean up while other vcpus are working.
   94.89 +     */
   94.90 +    if ( v->vcpu_id )
   94.91 +        return;
   94.92 +
   94.93      shadow_lock(d);
   94.94 +
   94.95      free_shadow_pages(d);
   94.96      free_shadow_ht_entries(d);
   94.97      d->arch.shadow_ht = 
   94.98 @@ -2047,6 +2085,7 @@ void clear_all_shadow_status(struct doma
   94.99             shadow_ht_buckets * sizeof(struct shadow_status));
  94.100  
  94.101      free_out_of_sync_entries(d);
  94.102 +
  94.103      shadow_unlock(d);
  94.104  }
  94.105  
    95.1 --- a/xen/arch/x86/smp.c	Mon Apr 17 08:47:36 2006 -0600
    95.2 +++ b/xen/arch/x86/smp.c	Tue Apr 18 09:35:40 2006 -0600
    95.3 @@ -261,7 +261,7 @@ int smp_call_function(
    95.4      return on_selected_cpus(allbutself, func, info, retry, wait);
    95.5  }
    95.6  
    95.7 -extern int on_selected_cpus(
    95.8 +int on_selected_cpus(
    95.9      cpumask_t selected,
   95.10      void (*func) (void *info),
   95.11      void *info,
    96.1 --- a/xen/arch/x86/smpboot.c	Mon Apr 17 08:47:36 2006 -0600
    96.2 +++ b/xen/arch/x86/smpboot.c	Tue Apr 18 09:35:40 2006 -0600
    96.3 @@ -41,6 +41,7 @@
    96.4  #include <xen/irq.h>
    96.5  #include <xen/delay.h>
    96.6  #include <xen/softirq.h>
    96.7 +#include <xen/serial.h>
    96.8  #include <asm/current.h>
    96.9  #include <asm/mc146818rtc.h>
   96.10  #include <asm/desc.h>
   96.11 @@ -1231,12 +1232,25 @@ void __init smp_cpus_done(unsigned int m
   96.12  
   96.13  void __init smp_intr_init(void)
   96.14  {
   96.15 +	int irq, seridx;
   96.16 +
   96.17  	/*
   96.18  	 * IRQ0 must be given a fixed assignment and initialized,
   96.19  	 * because it's used before the IO-APIC is set up.
   96.20  	 */
   96.21 -	irq_vector[0] = FIRST_DEVICE_VECTOR;
   96.22 -	vector_irq[FIRST_DEVICE_VECTOR] = 0;
   96.23 +	irq_vector[0] = FIRST_HIPRIORITY_VECTOR;
   96.24 +	vector_irq[FIRST_HIPRIORITY_VECTOR] = 0;
   96.25 +
   96.26 +	/*
   96.27 +	 * Also ensure serial interrupts are high priority. We do not
   96.28 +	 * want them to be blocked by unacknowledged guest-bound interrupts.
   96.29 +	 */
   96.30 +	for (seridx = 0; seridx < 2; seridx++) {
   96.31 +		if ((irq = serial_irq(seridx)) < 0)
   96.32 +			continue;
   96.33 +		irq_vector[irq] = FIRST_HIPRIORITY_VECTOR + seridx + 1;
   96.34 +		vector_irq[FIRST_HIPRIORITY_VECTOR + seridx + 1] = irq;
   96.35 +	}
   96.36  
   96.37  	/* IPI for event checking. */
   96.38  	set_intr_gate(EVENT_CHECK_VECTOR, event_check_interrupt);
    97.1 --- a/xen/common/dom0_ops.c	Mon Apr 17 08:47:36 2006 -0600
    97.2 +++ b/xen/common/dom0_ops.c	Tue Apr 18 09:35:40 2006 -0600
    97.3 @@ -581,20 +581,31 @@ long do_dom0_op(GUEST_HANDLE(dom0_op_t) 
    97.4      case DOM0_SETDOMAINMAXMEM:
    97.5      {
    97.6          struct domain *d; 
    97.7 +        unsigned long new_max;
    97.8 +
    97.9          ret = -ESRCH;
   97.10          d = find_domain_by_id(op->u.setdomainmaxmem.domain);
   97.11 -        if ( d != NULL )
   97.12 +        if ( d == NULL )
   97.13 +            break;
   97.14 +
   97.15 +        ret = -EINVAL;
   97.16 +        new_max = op->u.setdomainmaxmem.max_memkb >> (PAGE_SHIFT-10);
   97.17 +
   97.18 +        spin_lock(&d->page_alloc_lock);
   97.19 +        if ( new_max >= d->tot_pages )
   97.20          {
   97.21 -            d->max_pages = op->u.setdomainmaxmem.max_memkb >> (PAGE_SHIFT-10);
   97.22 -            put_domain(d);
   97.23 +            d->max_pages = new_max;
   97.24              ret = 0;
   97.25          }
   97.26 +        spin_unlock(&d->page_alloc_lock);
   97.27 +
   97.28 +        put_domain(d);
   97.29      }
   97.30      break;
   97.31  
   97.32      case DOM0_SETDOMAINHANDLE:
   97.33      {
   97.34 -        struct domain *d; 
   97.35 +        struct domain *d;
   97.36          ret = -ESRCH;
   97.37          d = find_domain_by_id(op->u.setdomainhandle.domain);
   97.38          if ( d != NULL )
    98.1 --- a/xen/common/grant_table.c	Mon Apr 17 08:47:36 2006 -0600
    98.2 +++ b/xen/common/grant_table.c	Tue Apr 18 09:35:40 2006 -0600
    98.3 @@ -41,21 +41,21 @@
    98.4  
    98.5  static inline int
    98.6  get_maptrack_handle(
    98.7 -    grant_table_t *t)
    98.8 +    struct grant_table *t)
    98.9  {
   98.10      unsigned int h;
   98.11      if ( unlikely((h = t->maptrack_head) == (t->maptrack_limit - 1)) )
   98.12          return -1;
   98.13 -    t->maptrack_head = t->maptrack[h].ref_and_flags >> MAPTRACK_REF_SHIFT;
   98.14 +    t->maptrack_head = t->maptrack[h].ref;
   98.15      t->map_count++;
   98.16      return h;
   98.17  }
   98.18  
   98.19  static inline void
   98.20  put_maptrack_handle(
   98.21 -    grant_table_t *t, int handle)
   98.22 +    struct grant_table *t, int handle)
   98.23  {
   98.24 -    t->maptrack[handle].ref_and_flags = t->maptrack_head << MAPTRACK_REF_SHIFT;
   98.25 +    t->maptrack[handle].ref = t->maptrack_head;
   98.26      t->maptrack_head = handle;
   98.27      t->map_count--;
   98.28  }
   98.29 @@ -76,7 +76,7 @@ static void
   98.30      int            handle;
   98.31      unsigned long  frame = 0;
   98.32      int            rc = GNTST_okay;
   98.33 -    active_grant_entry_t *act;
   98.34 +    struct active_grant_entry *act;
   98.35  
   98.36      /* Entry details from @rd's shared grant table. */
   98.37      grant_entry_t *sha;
   98.38 @@ -123,9 +123,9 @@ static void
   98.39      /* Get a maptrack handle. */
   98.40      if ( unlikely((handle = get_maptrack_handle(ld->grant_table)) == -1) )
   98.41      {
   98.42 -        int              i;
   98.43 -        grant_mapping_t *new_mt;
   98.44 -        grant_table_t   *lgt = ld->grant_table;
   98.45 +        int                   i;
   98.46 +        struct grant_mapping *new_mt;
   98.47 +        struct grant_table   *lgt = ld->grant_table;
   98.48  
   98.49          if ( (lgt->maptrack_limit << 1) > MAPTRACK_MAX_ENTRIES )
   98.50          {
   98.51 @@ -147,7 +147,7 @@ static void
   98.52  
   98.53          memcpy(new_mt, lgt->maptrack, PAGE_SIZE << lgt->maptrack_order);
   98.54          for ( i = lgt->maptrack_limit; i < (lgt->maptrack_limit << 1); i++ )
   98.55 -            new_mt[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
   98.56 +            new_mt[i].ref = i+1;
   98.57  
   98.58          free_xenheap_pages(lgt->maptrack, lgt->maptrack_order);
   98.59          lgt->maptrack          = new_mt;
   98.60 @@ -264,10 +264,9 @@ static void
   98.61  
   98.62      TRACE_1D(TRC_MEM_PAGE_GRANT_MAP, op->dom);
   98.63  
   98.64 -    ld->grant_table->maptrack[handle].domid         = op->dom;
   98.65 -    ld->grant_table->maptrack[handle].ref_and_flags =
   98.66 -        (op->ref << MAPTRACK_REF_SHIFT) |
   98.67 -        (op->flags & MAPTRACK_GNTMAP_MASK);
   98.68 +    ld->grant_table->maptrack[handle].domid = op->dom;
   98.69 +    ld->grant_table->maptrack[handle].ref   = op->ref;
   98.70 +    ld->grant_table->maptrack[handle].flags = op->flags;
   98.71  
   98.72      op->dev_bus_addr = (u64)frame << PAGE_SHIFT;
   98.73      op->handle       = handle;
   98.74 @@ -326,9 +325,9 @@ static void
   98.75      domid_t          dom;
   98.76      grant_ref_t      ref;
   98.77      struct domain   *ld, *rd;
   98.78 -    active_grant_entry_t *act;
   98.79 +    struct active_grant_entry *act;
   98.80      grant_entry_t   *sha;
   98.81 -    grant_mapping_t *map;
   98.82 +    struct grant_mapping *map;
   98.83      u16              flags;
   98.84      s16              rc = 0;
   98.85      unsigned long    frame;
   98.86 @@ -340,7 +339,7 @@ static void
   98.87      map = &ld->grant_table->maptrack[op->handle];
   98.88  
   98.89      if ( unlikely(op->handle >= ld->grant_table->maptrack_limit) ||
   98.90 -         unlikely(!(map->ref_and_flags & MAPTRACK_GNTMAP_MASK)) )
   98.91 +         unlikely(!map->flags) )
   98.92      {
   98.93          DPRINTK("Bad handle (%d).\n", op->handle);
   98.94          op->status = GNTST_bad_handle;
   98.95 @@ -348,8 +347,8 @@ static void
   98.96      }
   98.97  
   98.98      dom   = map->domid;
   98.99 -    ref   = map->ref_and_flags >> MAPTRACK_REF_SHIFT;
  98.100 -    flags = map->ref_and_flags & MAPTRACK_GNTMAP_MASK;
  98.101 +    ref   = map->ref;
  98.102 +    flags = map->flags;
  98.103  
  98.104      if ( unlikely((rd = find_domain_by_id(dom)) == NULL) ||
  98.105           unlikely(ld == rd) )
  98.106 @@ -380,7 +379,7 @@ static void
  98.107          if ( flags & GNTMAP_device_map )
  98.108          {
  98.109              ASSERT(act->pin & (GNTPIN_devw_mask | GNTPIN_devr_mask));
  98.110 -            map->ref_and_flags &= ~GNTMAP_device_map;
  98.111 +            map->flags &= ~GNTMAP_device_map;
  98.112              if ( flags & GNTMAP_readonly )
  98.113              {
  98.114                  act->pin -= GNTPIN_devr_inc;
  98.115 @@ -401,7 +400,7 @@ static void
  98.116              goto unmap_out;
  98.117  
  98.118          ASSERT(act->pin & (GNTPIN_hstw_mask | GNTPIN_hstr_mask));
  98.119 -        map->ref_and_flags &= ~GNTMAP_host_map;
  98.120 +        map->flags &= ~GNTMAP_host_map;
  98.121          if ( flags & GNTMAP_readonly )
  98.122          {
  98.123              act->pin -= GNTPIN_hstr_inc;
  98.124 @@ -414,9 +413,9 @@ static void
  98.125          }
  98.126      }
  98.127  
  98.128 -    if ( (map->ref_and_flags & (GNTMAP_device_map|GNTMAP_host_map)) == 0 )
  98.129 +    if ( (map->flags & (GNTMAP_device_map|GNTMAP_host_map)) == 0 )
  98.130      {
  98.131 -        map->ref_and_flags = 0;
  98.132 +        map->flags = 0;
  98.133          put_maptrack_handle(ld->grant_table, op->handle);
  98.134      }
  98.135  
  98.136 @@ -534,12 +533,12 @@ static int
  98.137  gnttab_prepare_for_transfer(
  98.138      struct domain *rd, struct domain *ld, grant_ref_t ref)
  98.139  {
  98.140 -    grant_table_t *rgt;
  98.141 -    grant_entry_t *sha;
  98.142 -    domid_t        sdom;
  98.143 -    u16            sflags;
  98.144 -    u32            scombo, prev_scombo;
  98.145 -    int            retries = 0;
  98.146 +    struct grant_table *rgt;
  98.147 +    struct grant_entry *sha;
  98.148 +    domid_t             sdom;
  98.149 +    u16                 sflags;
  98.150 +    u32                 scombo, prev_scombo;
  98.151 +    int                 retries = 0;
  98.152  
  98.153      if ( unlikely((rgt = rd->grant_table) == NULL) ||
  98.154           unlikely(ref >= NR_GRANT_ENTRIES) )
  98.155 @@ -775,10 +774,11 @@ int
  98.156  grant_table_create(
  98.157      struct domain *d)
  98.158  {
  98.159 -    grant_table_t *t;
  98.160 -    int            i;
  98.161 +    struct grant_table *t;
  98.162 +    int                 i;
  98.163  
  98.164 -    if ( (t = xmalloc(grant_table_t)) == NULL )
  98.165 +    BUG_ON(MAPTRACK_MAX_ENTRIES < NR_GRANT_ENTRIES);
  98.166 +    if ( (t = xmalloc(struct grant_table)) == NULL )
  98.167          goto no_mem;
  98.168  
  98.169      /* Simple stuff. */
  98.170 @@ -786,19 +786,19 @@ grant_table_create(
  98.171      spin_lock_init(&t->lock);
  98.172  
  98.173      /* Active grant table. */
  98.174 -    if ( (t->active = xmalloc_array(active_grant_entry_t, NR_GRANT_ENTRIES))
  98.175 -         == NULL )
  98.176 +    t->active = xmalloc_array(struct active_grant_entry, NR_GRANT_ENTRIES);
  98.177 +    if ( t->active == NULL )
  98.178          goto no_mem;
  98.179 -    memset(t->active, 0, sizeof(active_grant_entry_t) * NR_GRANT_ENTRIES);
  98.180 +    memset(t->active, 0, sizeof(struct active_grant_entry) * NR_GRANT_ENTRIES);
  98.181  
  98.182      /* Tracking of mapped foreign frames table */
  98.183      if ( (t->maptrack = alloc_xenheap_page()) == NULL )
  98.184          goto no_mem;
  98.185      t->maptrack_order = 0;
  98.186 -    t->maptrack_limit = PAGE_SIZE / sizeof(grant_mapping_t);
  98.187 +    t->maptrack_limit = PAGE_SIZE / sizeof(struct grant_mapping);
  98.188      memset(t->maptrack, 0, PAGE_SIZE);
  98.189      for ( i = 0; i < t->maptrack_limit; i++ )
  98.190 -        t->maptrack[i].ref_and_flags = (i+1) << MAPTRACK_REF_SHIFT;
  98.191 +        t->maptrack[i].ref = i+1;
  98.192  
  98.193      /* Shared grant table. */
  98.194      t->shared = alloc_xenheap_pages(ORDER_GRANT_FRAMES);
  98.195 @@ -828,27 +828,26 @@ void
  98.196  gnttab_release_mappings(
  98.197      struct domain *d)
  98.198  {
  98.199 -    grant_table_t        *gt = d->grant_table;
  98.200 -    grant_mapping_t      *map;
  98.201 +    struct grant_table   *gt = d->grant_table;
  98.202 +    struct grant_mapping *map;
  98.203      grant_ref_t           ref;
  98.204      grant_handle_t        handle;
  98.205      struct domain        *rd;
  98.206 -    active_grant_entry_t *act;
  98.207 -    grant_entry_t        *sha;
  98.208 +    struct active_grant_entry *act;
  98.209 +    struct grant_entry   *sha;
  98.210  
  98.211      BUG_ON(!test_bit(_DOMF_dying, &d->domain_flags));
  98.212  
  98.213      for ( handle = 0; handle < gt->maptrack_limit; handle++ )
  98.214      {
  98.215          map = &gt->maptrack[handle];
  98.216 -        if ( !(map->ref_and_flags & (GNTMAP_device_map|GNTMAP_host_map)) )
  98.217 +        if ( !(map->flags & (GNTMAP_device_map|GNTMAP_host_map)) )
  98.218              continue;
  98.219  
  98.220 -        ref = map->ref_and_flags >> MAPTRACK_REF_SHIFT;
  98.221 +        ref = map->ref;
  98.222  
  98.223          DPRINTK("Grant release (%hu) ref:(%hu) flags:(%x) dom:(%hu)\n",
  98.224 -                handle, ref, map->ref_and_flags & MAPTRACK_GNTMAP_MASK,
  98.225 -                map->domid);
  98.226 +                handle, ref, map->flags, map->domid);
  98.227  
  98.228          rd = find_domain_by_id(map->domid);
  98.229          BUG_ON(rd == NULL);
  98.230 @@ -858,16 +857,16 @@ gnttab_release_mappings(
  98.231          act = &rd->grant_table->active[ref];
  98.232          sha = &rd->grant_table->shared[ref];
  98.233  
  98.234 -        if ( map->ref_and_flags & GNTMAP_readonly )
  98.235 +        if ( map->flags & GNTMAP_readonly )
  98.236          {
  98.237 -            if ( map->ref_and_flags & GNTMAP_device_map )
  98.238 +            if ( map->flags & GNTMAP_device_map )
  98.239              {
  98.240                  BUG_ON(!(act->pin & GNTPIN_devr_mask));
  98.241                  act->pin -= GNTPIN_devr_inc;
  98.242                  put_page(mfn_to_page(act->frame));
  98.243              }
  98.244  
  98.245 -            if ( map->ref_and_flags & GNTMAP_host_map )
  98.246 +            if ( map->flags & GNTMAP_host_map )
  98.247              {
  98.248                  BUG_ON(!(act->pin & GNTPIN_hstr_mask));
  98.249                  act->pin -= GNTPIN_hstr_inc;
  98.250 @@ -877,14 +876,14 @@ gnttab_release_mappings(
  98.251          }
  98.252          else
  98.253          {
  98.254 -            if ( map->ref_and_flags & GNTMAP_device_map )
  98.255 +            if ( map->flags & GNTMAP_device_map )
  98.256              {
  98.257                  BUG_ON(!(act->pin & GNTPIN_devw_mask));
  98.258                  act->pin -= GNTPIN_devw_inc;
  98.259                  put_page_and_type(mfn_to_page(act->frame));
  98.260              }
  98.261  
  98.262 -            if ( map->ref_and_flags & GNTMAP_host_map )
  98.263 +            if ( map->flags & GNTMAP_host_map )
  98.264              {
  98.265                  BUG_ON(!(act->pin & GNTPIN_hstw_mask));
  98.266                  act->pin -= GNTPIN_hstw_inc;
  98.267 @@ -903,7 +902,7 @@ gnttab_release_mappings(
  98.268  
  98.269          put_domain(rd);
  98.270  
  98.271 -        map->ref_and_flags = 0;
  98.272 +        map->flags = 0;
  98.273      }
  98.274  }
  98.275  
  98.276 @@ -912,7 +911,7 @@ void
  98.277  grant_table_destroy(
  98.278      struct domain *d)
  98.279  {
  98.280 -    grant_table_t *t = d->grant_table;
  98.281 +    struct grant_table *t = d->grant_table;
  98.282  
  98.283      if ( t == NULL )
  98.284          return;
    99.1 --- a/xen/drivers/char/console.c	Mon Apr 17 08:47:36 2006 -0600
    99.2 +++ b/xen/drivers/char/console.c	Tue Apr 18 09:35:40 2006 -0600
    99.3 @@ -65,11 +65,12 @@ spinlock_t console_lock = SPIN_LOCK_UNLO
    99.4  #define COLUMNS     80
    99.5  #define LINES       25
    99.6  #define ATTRIBUTE    7
    99.7 +#define VIDEO_SIZE  (COLUMNS * LINES * 2)
    99.8  
    99.9  /* Clear the screen and initialize VIDEO, XPOS and YPOS.  */
   99.10  static void cls(void)
   99.11  {
   99.12 -    memset(video, 0, COLUMNS * LINES * 2);
   99.13 +    memset(video, 0, VIDEO_SIZE);
   99.14      xpos = ypos = 0;
   99.15      outw(10+(1<<(5+8)), 0x3d4); /* cursor off */
   99.16  }
   99.17 @@ -107,9 +108,9 @@ static int detect_vga(void)
   99.18       * 
   99.19       * These checks are basically to detect headless server boxes.
   99.20       */
   99.21 -    return (detect_video(__va(0xA0000)) || 
   99.22 -            detect_video(__va(0xB0000)) || 
   99.23 -            detect_video(__va(0xB8000)));
   99.24 +    return (detect_video(ioremap(0xA0000, VIDEO_SIZE)) || 
   99.25 +            detect_video(ioremap(0xB0000, VIDEO_SIZE)) || 
   99.26 +            detect_video(ioremap(0xB8000, VIDEO_SIZE)));
   99.27  }
   99.28  
   99.29  /* This is actually code from vgaHWRestore in an old version of XFree86 :-) */
   99.30 @@ -143,7 +144,7 @@ static void init_vga(void)
   99.31          return;
   99.32      }
   99.33  
   99.34 -    video = __va(0xB8000);
   99.35 +    video = ioremap(0xB8000, VIDEO_SIZE);
   99.36  
   99.37      tmp = inb(0x3da);
   99.38      outb(0x00, 0x3c0);
   99.39 @@ -180,12 +181,10 @@ static void put_newline(void)
   99.40  
   99.41      if (ypos >= LINES)
   99.42      {
   99.43 -        static char zeroarr[2*COLUMNS] = { 0 };
   99.44          ypos = LINES-1;
   99.45 -        memcpy((char*)video, 
   99.46 -               (char*)video + 2*COLUMNS, (LINES-1)*2*COLUMNS);
   99.47 -        memcpy((char*)video + (LINES-1)*2*COLUMNS, 
   99.48 -               zeroarr, 2*COLUMNS);
   99.49 +        memmove((char*)video, 
   99.50 +                (char*)video + 2*COLUMNS, (LINES-1)*2*COLUMNS);
   99.51 +        memset((char*)video + (LINES-1)*2*COLUMNS, 0, 2*COLUMNS);
   99.52      }
   99.53  }
   99.54  
   100.1 --- a/xen/drivers/char/ns16550.c	Mon Apr 17 08:47:36 2006 -0600
   100.2 +++ b/xen/drivers/char/ns16550.c	Tue Apr 18 09:35:40 2006 -0600
   100.3 @@ -260,13 +260,20 @@ static void ns16550_endboot(struct seria
   100.4  #define ns16550_endboot NULL
   100.5  #endif
   100.6  
   100.7 +static int ns16550_irq(struct serial_port *port)
   100.8 +{
   100.9 +    struct ns16550 *uart = port->uart;
  100.10 +    return ((uart->irq > 0) ? uart->irq : -1);
  100.11 +}
  100.12 +
  100.13  static struct uart_driver ns16550_driver = {
  100.14      .init_preirq  = ns16550_init_preirq,
  100.15      .init_postirq = ns16550_init_postirq,
  100.16      .endboot      = ns16550_endboot,
  100.17      .tx_empty     = ns16550_tx_empty,
  100.18      .putc         = ns16550_putc,
  100.19 -    .getc         = ns16550_getc
  100.20 +    .getc         = ns16550_getc,
  100.21 +    .irq          = ns16550_irq
  100.22  };
  100.23  
  100.24  static int parse_parity_char(int c)
   101.1 --- a/xen/drivers/char/serial.c	Mon Apr 17 08:47:36 2006 -0600
   101.2 +++ b/xen/drivers/char/serial.c	Tue Apr 18 09:35:40 2006 -0600
   101.3 @@ -372,6 +372,15 @@ void serial_endboot(void)
   101.4              com[i].driver->endboot(&com[i]);
   101.5  }
   101.6  
   101.7 +int serial_irq(int idx)
   101.8 +{
   101.9 +    if ( (idx >= 0) && (idx < ARRAY_SIZE(com)) &&
  101.10 +         com[idx].driver && com[idx].driver->irq )
  101.11 +        return com[idx].driver->irq(&com[idx]);
  101.12 +
  101.13 +    return -1;
  101.14 +}
  101.15 +
  101.16  void serial_register_uart(int idx, struct uart_driver *driver, void *uart)
  101.17  {
  101.18      /* Store UART-specific info. */
   102.1 --- a/xen/include/asm-x86/hvm/vmx/vmx.h	Mon Apr 17 08:47:36 2006 -0600
   102.2 +++ b/xen/include/asm-x86/hvm/vmx/vmx.h	Tue Apr 18 09:35:40 2006 -0600
   102.3 @@ -61,8 +61,7 @@ extern unsigned int cpu_rev;
   102.4      CPU_BASED_MWAIT_EXITING | \
   102.5      CPU_BASED_MOV_DR_EXITING | \
   102.6      CPU_BASED_ACTIVATE_IO_BITMAP | \
   102.7 -    CPU_BASED_USE_TSC_OFFSETING  | \
   102.8 -    CPU_BASED_UNCOND_IO_EXITING \
   102.9 +    CPU_BASED_USE_TSC_OFFSETING  \
  102.10      )
  102.11  
  102.12  #define MONITOR_CPU_BASED_EXEC_CONTROLS_IA32E_MODE \
   103.1 --- a/xen/include/asm-x86/hvm/vpit.h	Mon Apr 17 08:47:36 2006 -0600
   103.2 +++ b/xen/include/asm-x86/hvm/vpit.h	Tue Apr 18 09:35:40 2006 -0600
   103.3 @@ -38,7 +38,8 @@
   103.4  struct hvm_virpit {
   103.5      /* for simulation of counter 0 in mode 2 */
   103.6      u64 period_cycles;          /* pit frequency in cpu cycles */
   103.7 -    s_time_t inject_point;      /* the time inject virt intr */
   103.8 +    s_time_t count_advance;     /* accumulated count advance since last fire */
   103.9 +    s_time_t count_point;        /* last point accumulating count advance */
  103.10      s_time_t scheduled;         /* scheduled timer interrupt */
  103.11      struct timer pit_timer;     /* periodic timer for mode 2*/
  103.12      unsigned int channel;       /* the pit channel, counter 0~2 */
   104.1 --- a/xen/include/asm-x86/irq.h	Mon Apr 17 08:47:36 2006 -0600
   104.2 +++ b/xen/include/asm-x86/irq.h	Tue Apr 18 09:35:40 2006 -0600
   104.3 @@ -11,8 +11,8 @@
   104.4  #define IO_APIC_IRQ(irq)    (((irq) >= 16) || ((1<<(irq)) & io_apic_irqs))
   104.5  #define IO_APIC_VECTOR(irq) (irq_vector[irq])
   104.6  
   104.7 -#define LEGACY_VECTOR(irq)          ((irq) + FIRST_EXTERNAL_VECTOR)
   104.8 -#define LEGACY_IRQ_FROM_VECTOR(vec) ((vec) - FIRST_EXTERNAL_VECTOR)
   104.9 +#define LEGACY_VECTOR(irq)          ((irq) + FIRST_LEGACY_VECTOR)
  104.10 +#define LEGACY_IRQ_FROM_VECTOR(vec) ((vec) - FIRST_LEGACY_VECTOR)
  104.11  
  104.12  #define irq_to_vector(irq)  \
  104.13      (IO_APIC_IRQ(irq) ? IO_APIC_VECTOR(irq) : LEGACY_VECTOR(irq))
   105.1 --- a/xen/include/asm-x86/mach-default/irq_vectors.h	Mon Apr 17 08:47:36 2006 -0600
   105.2 +++ b/xen/include/asm-x86/mach-default/irq_vectors.h	Tue Apr 18 09:35:40 2006 -0600
   105.3 @@ -1,96 +1,36 @@
   105.4 -/*
   105.5 - * This file should contain #defines for all of the interrupt vector
   105.6 - * numbers used by this architecture.
   105.7 - *
   105.8 - * In addition, there are some standard defines:
   105.9 - *
  105.10 - *	FIRST_EXTERNAL_VECTOR:
  105.11 - *		The first free place for external interrupts
  105.12 - *
  105.13 - *	SYSCALL_VECTOR:
  105.14 - *		The IRQ vector a syscall makes the user to kernel transition
  105.15 - *		under.
  105.16 - *
  105.17 - *	TIMER_IRQ:
  105.18 - *		The IRQ number the timer interrupt comes in at.
  105.19 - *
  105.20 - *	NR_IRQS:
  105.21 - *		The total number of interrupt vectors (including all the
  105.22 - *		architecture specific interrupts) needed.
  105.23 - *
  105.24 - */			
  105.25  #ifndef _ASM_IRQ_VECTORS_H
  105.26  #define _ASM_IRQ_VECTORS_H
  105.27  
  105.28 -/*
  105.29 - * IDT vectors usable for external interrupt sources start
  105.30 - * at 0x20:
  105.31 - */
  105.32 -#define FIRST_EXTERNAL_VECTOR	0x20
  105.33 -
  105.34 -#define HYPERCALL_VECTOR	0x82
  105.35 -
  105.36 -/*
  105.37 - * Vectors 0x20-0x2f are used for ISA interrupts.
  105.38 - */
  105.39 -
  105.40 -/*
  105.41 - * Special IRQ vectors used by the SMP architecture, 0xf0-0xff
  105.42 - *
  105.43 - *  some of the following vectors are 'rare', they are merged
  105.44 - *  into a single vector (CALL_FUNCTION_VECTOR) to save vector space.
  105.45 - *  TLB, reschedule and local APIC vectors are performance-critical.
  105.46 - *
  105.47 - *  Vectors 0xf0-0xfa are free (reserved for future Linux use).
  105.48 - */
  105.49 +/* Processor-initiated interrupts are all high priority. */
  105.50  #define SPURIOUS_APIC_VECTOR	0xff
  105.51  #define ERROR_APIC_VECTOR	0xfe
  105.52  #define INVALIDATE_TLB_VECTOR	0xfd
  105.53  #define EVENT_CHECK_VECTOR	0xfc
  105.54  #define CALL_FUNCTION_VECTOR	0xfb
  105.55 -
  105.56 -#define THERMAL_APIC_VECTOR	0xf0
  105.57 -/*
  105.58 - * Local APIC timer IRQ vector is on a different priority level,
  105.59 - * to work around the 'lost local interrupt if more than 2 IRQ
  105.60 - * sources per level' errata.
  105.61 - */
  105.62 -#define LOCAL_TIMER_VECTOR	0xef
  105.63 -
  105.64 -/*
  105.65 - * First APIC vector available to drivers: (vectors 0x30-0xee)
  105.66 - * we start at 0x31 to spread out vectors evenly between priority
  105.67 - * levels. (0x80 is the syscall vector)
  105.68 - */
  105.69 -#define FIRST_DEVICE_VECTOR	0x31
  105.70 -#define FIRST_SYSTEM_VECTOR	0xef
  105.71 -
  105.72 -#define TIMER_IRQ 0
  105.73 +#define THERMAL_APIC_VECTOR	0xfa
  105.74 +#define LOCAL_TIMER_VECTOR	0xf9
  105.75  
  105.76  /*
  105.77 - * 16 8259A IRQ's, 208 potential APIC interrupt sources.
  105.78 - * Right now the APIC is mostly only used for SMP.
  105.79 - * 256 vectors is an architectural limit. (we can have
  105.80 - * more than 256 devices theoretically, but they will
  105.81 - * have to use shared interrupts)
  105.82 - * Since vectors 0x00-0x1f are used/reserved for the CPU,
  105.83 - * the usable vector space is 0x20-0xff (224 vectors)
  105.84 + * High-priority dynamically-allocated vectors. For interrupts that
  105.85 + * must be higher priority than any guest-bound interrupt.
  105.86   */
  105.87 +#define FIRST_HIPRIORITY_VECTOR	0xf0
  105.88 +#define LAST_HIPRIORITY_VECTOR  0xf8
  105.89  
  105.90 -/*
  105.91 - * The maximum number of vectors supported by i386 processors
  105.92 - * is limited to 256. For processors other than i386, NR_VECTORS
  105.93 - * should be changed accordingly.
  105.94 - */
  105.95 +/* Legacy PIC uses vectors 0xe0-0xef. */
  105.96 +#define FIRST_LEGACY_VECTOR	0xe0
  105.97 +#define LAST_LEGACY_VECTOR      0xef
  105.98 +
  105.99 +#define HYPERCALL_VECTOR	0x82
 105.100 +
 105.101 +/* Dynamically-allocated vectors available to any driver. */
 105.102 +#define FIRST_DYNAMIC_VECTOR	0x20
 105.103 +#define LAST_DYNAMIC_VECTOR	0xdf
 105.104 +
 105.105  #define NR_VECTORS 256
 105.106  
 105.107 -#include "irq_vectors_limits.h"
 105.108 -
 105.109 -#define FPU_IRQ			13
 105.110 -
 105.111 -#define	FIRST_VM86_IRQ		3
 105.112 -#define LAST_VM86_IRQ		15
 105.113 -#define invalid_vm86_irq(irq)	((irq) < 3 || (irq) > 15)
 105.114 -
 105.115 +/* Limited by number of trap vectors. */
 105.116 +#define NR_IRQS        NR_VECTORS
 105.117 +#define NR_IRQ_VECTORS NR_IRQS
 105.118  
 105.119  #endif /* _ASM_IRQ_VECTORS_H */
   106.1 --- a/xen/include/asm-x86/mach-default/irq_vectors_limits.h	Mon Apr 17 08:47:36 2006 -0600
   106.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   106.3 @@ -1,8 +0,0 @@
   106.4 -#ifndef _ASM_IRQ_VECTORS_LIMITS_H
   106.5 -#define _ASM_IRQ_VECTORS_LIMITS_H
   106.6 -
   106.7 -/* Limited by number of trap vectors. */
   106.8 -#define NR_IRQS        FIRST_SYSTEM_VECTOR
   106.9 -#define NR_IRQ_VECTORS NR_IRQS
  106.10 -
  106.11 -#endif /* _ASM_IRQ_VECTORS_LIMITS_H */
   107.1 --- a/xen/include/asm-x86/mm.h	Mon Apr 17 08:47:36 2006 -0600
   107.2 +++ b/xen/include/asm-x86/mm.h	Tue Apr 18 09:35:40 2006 -0600
   107.3 @@ -103,11 +103,13 @@ struct page_info
   107.4  #define PGT_high_mfn_mask   (0xfffUL << PGT_high_mfn_shift)
   107.5  #define PGT_mfn_mask        (((1U<<23)-1) | PGT_high_mfn_mask)
   107.6  #define PGT_high_mfn_nx     (0x800UL << PGT_high_mfn_shift)
   107.7 +#define PGT_pae_idx_shift   PGT_high_mfn_shift
   107.8  #else
   107.9   /* 23-bit mfn mask for shadow types: good for up to 32GB RAM. */
  107.10  #define PGT_mfn_mask        ((1U<<23)-1)
  107.11   /* NX for PAE xen is not supported yet */
  107.12  #define PGT_high_mfn_nx     (1ULL << 63)
  107.13 +#define PGT_pae_idx_shift   23
  107.14  #endif
  107.15  
  107.16  #define PGT_score_shift     23
   108.1 --- a/xen/include/asm-x86/shadow_64.h	Mon Apr 17 08:47:36 2006 -0600
   108.2 +++ b/xen/include/asm-x86/shadow_64.h	Tue Apr 18 09:35:40 2006 -0600
   108.3 @@ -119,6 +119,8 @@ typedef struct { intpte_t lo; } pgentry_
   108.4  #define PAE_CR3_IDX_MASK    0x7f
   108.5  #define PAE_CR3_IDX_NO      128
   108.6  
   108.7 +#define PAE_PDPT_RESERVED   0x1e6 /* [8:5], [2,1] */
   108.8 +
   108.9  /******************************************************************************/
  108.10  static inline int  table_offset_64(unsigned long va, int level)
  108.11  {
   109.1 --- a/xen/include/public/xen.h	Mon Apr 17 08:47:36 2006 -0600
   109.2 +++ b/xen/include/public/xen.h	Tue Apr 18 09:35:40 2006 -0600
   109.3 @@ -286,7 +286,8 @@ typedef struct vcpu_time_info {
   109.4      uint64_t system_time;     /* Time, in nanosecs, since boot.    */
   109.5      /*
   109.6       * Current system time:
   109.7 -     *   system_time + ((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul
   109.8 +     *   system_time +
   109.9 +     *   ((((tsc - tsc_timestamp) << tsc_shift) * tsc_to_system_mul) >> 32)
  109.10       * CPU frequency (Hz):
  109.11       *   ((10^9 << 32) / tsc_to_system_mul) >> tsc_shift
  109.12       */
   110.1 --- a/xen/include/xen/grant_table.h	Mon Apr 17 08:47:36 2006 -0600
   110.2 +++ b/xen/include/xen/grant_table.h	Tue Apr 18 09:35:40 2006 -0600
   110.3 @@ -29,11 +29,11 @@
   110.4  #include <asm/grant_table.h>
   110.5  
   110.6  /* Active grant entry - used for shadowing GTF_permit_access grants. */
   110.7 -typedef struct {
   110.8 +struct active_grant_entry {
   110.9      u32           pin;    /* Reference count information.  */
  110.10      domid_t       domid;  /* Domain being granted access.  */
  110.11      unsigned long frame;  /* Frame being granted.          */
  110.12 -} active_grant_entry_t;
  110.13 +};
  110.14  
  110.15   /* Count of writable host-CPU mappings. */
  110.16  #define GNTPIN_hstw_shift    (0)
  110.17 @@ -60,29 +60,30 @@ typedef struct {
  110.18   * Tracks a mapping of another domain's grant reference. Each domain has a
  110.19   * table of these, indexes into which are returned as a 'mapping handle'.
  110.20   */
  110.21 -typedef struct {
  110.22 -    u16      ref_and_flags; /* 0-4: GNTMAP_* ; 5-15: grant ref */
  110.23 +struct grant_mapping {
  110.24 +    u32      ref;           /* grant ref */
  110.25 +    u16      flags;         /* 0-4: GNTMAP_* ; 5-15: unused */
  110.26      domid_t  domid;         /* granting domain */
  110.27 -} grant_mapping_t;
  110.28 -#define MAPTRACK_GNTMAP_MASK  0x1f
  110.29 -#define MAPTRACK_REF_SHIFT    5
  110.30 -#define MAPTRACK_MAX_ENTRIES  (1 << (16 - MAPTRACK_REF_SHIFT))
  110.31 +};
  110.32 +
  110.33 +/* Fairly arbitrary. [POLICY] */
  110.34 +#define MAPTRACK_MAX_ENTRIES 16384
  110.35  
  110.36  /* Per-domain grant information. */
  110.37 -typedef struct {
  110.38 +struct grant_table {
  110.39      /* Shared grant table (see include/public/grant_table.h). */
  110.40 -    grant_entry_t        *shared;
  110.41 +    struct grant_entry   *shared;
  110.42      /* Active grant table. */
  110.43 -    active_grant_entry_t *active;
  110.44 +    struct active_grant_entry *active;
  110.45      /* Mapping tracking table. */
  110.46 -    grant_mapping_t      *maptrack;
  110.47 +    struct grant_mapping *maptrack;
  110.48      unsigned int          maptrack_head;
  110.49      unsigned int          maptrack_order;
  110.50      unsigned int          maptrack_limit;
  110.51      unsigned int          map_count;
  110.52      /* Lock protecting updates to active and shared grant tables. */
  110.53      spinlock_t            lock;
  110.54 -} grant_table_t;
  110.55 +};
  110.56  
  110.57  /* Create/destroy per-domain grant table context. */
  110.58  int grant_table_create(
   111.1 --- a/xen/include/xen/sched.h	Mon Apr 17 08:47:36 2006 -0600
   111.2 +++ b/xen/include/xen/sched.h	Tue Apr 18 09:35:40 2006 -0600
   111.3 @@ -125,7 +125,7 @@ struct domain
   111.4      struct evtchn   *evtchn[NR_EVTCHN_BUCKETS];
   111.5      spinlock_t       evtchn_lock;
   111.6  
   111.7 -    grant_table_t   *grant_table;
   111.8 +    struct grant_table *grant_table;
   111.9  
  111.10      /*
  111.11       * Interrupt to event-channel mappings. Updates should be protected by the 
   112.1 --- a/xen/include/xen/serial.h	Mon Apr 17 08:47:36 2006 -0600
   112.2 +++ b/xen/include/xen/serial.h	Tue Apr 18 09:35:40 2006 -0600
   112.3 @@ -57,6 +57,8 @@ struct uart_driver {
   112.4      void (*putc)(struct serial_port *, char);
   112.5      /* Get a character from the serial line: returns 0 if none available. */
   112.6      int  (*getc)(struct serial_port *, char *);
   112.7 +    /* Get IRQ number for this port's serial line: returns -1 if none. */
   112.8 +    int  (*irq)(struct serial_port *);
   112.9  };
  112.10  
  112.11  /* 'Serial handles' are composed from the following fields. */
  112.12 @@ -99,6 +101,9 @@ void serial_end_sync(int handle);
  112.13  /* Return number of bytes headroom in transmit buffer. */
  112.14  int serial_tx_space(int handle);
  112.15  
  112.16 +/* Return irq number for specified serial port (identified by index). */
  112.17 +int serial_irq(int idx);
  112.18 +
  112.19  /*
  112.20   * Initialisation and helper functions for uart drivers.
  112.21   */