ia64/xen-unstable

changeset 19245:6227bf629626

merge with xen-unstable.hg
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Mar 02 18:26:56 2009 +0900 (2009-03-02)
parents c4c4ba857d8b e5c696aaf2a6
children 2a4eaa76d974
files xen/include/asm-ia64/hvm/iommu.h
line diff
     1.1 --- a/buildconfigs/enable-xen-config	Mon Mar 02 16:52:22 2009 +0900
     1.2 +++ b/buildconfigs/enable-xen-config	Mon Mar 02 18:26:56 2009 +0900
     1.3 @@ -19,29 +19,70 @@ setopt()
     1.4  
     1.5  	# Then append the new value
     1.6  	case ${VALUE} in
     1.7 -	    y|m) echo "${OPTION}=${VALUE}" >> "${CONFIG}" ;;
     1.8 -	    n)   echo "# ${OPTION} is not set" >> "${CONFIG}" ;;
     1.9 -	    *)   echo "Invalid value ${VALUE} for ${OPTION}" 1>&2 ; exit 1 ;;
    1.10 +	    n)     echo "# ${OPTION} is not set" >> "${CONFIG}" ;;
    1.11 +	    y|m|*) echo "${OPTION}=${VALUE}" >> "${CONFIG}" ;;
    1.12  	esac
    1.13  }
    1.14  
    1.15  setopt CONFIG_PARAVIRT y
    1.16 +setopt CONFIG_PARAVIRT_DEBUG y
    1.17  setopt CONFIG_PARAVIRT_GUEST y
    1.18 +
    1.19  setopt CONFIG_XEN y
    1.20 +setopt CONFIG_XEN_BLKDEV_FRONTEND y
    1.21 +setopt CONFIG_XEN_NETDEV_FRONTEND y
    1.22 +setopt CONFIG_XEN_KBDDEV_FRONTEND y
    1.23 +setopt CONFIG_XEN_FBDEV_FRONTEND y
    1.24 +setopt CONFIG_XEN_BALLOON y
    1.25 +setopt CONFIG_XEN_SCRUB_PAGES y
    1.26 +setopt CONFIG_XEN_DEV_EVTCHN y
    1.27 +setopt CONFIG_XEN_BACKEND y
    1.28 +setopt CONFIG_XEN_BLKDEV_BACKEND y
    1.29 +setopt CONFIG_XEN_NETDEV_BACKEND y
    1.30 +setopt CONFIG_XENFS y
    1.31 +setopt CONFIG_XEN_COMPAT_XENFS y
    1.32 +setopt CONFIG_HVC_XEN y
    1.33 +setopt CONFIG_XEN_MAX_DOMAIN_MEMORY 32
    1.34 +setopt CONFIG_XEN_DEBUG_FS y
    1.35 +setopt CONFIG_XEN_DOM0 y
    1.36 +
    1.37  setopt CONFIG_VMI y
    1.38 +
    1.39  setopt CONFIG_KVM y
    1.40  setopt CONFIG_KVM_INTEL y
    1.41  setopt CONFIG_KVM_AMD y
    1.42 +setopt CONFIG_KVM_CLOCK y
    1.43 +setopt CONFIG_KVM_GUEST n
    1.44 +setopt CONFIG_KVM_TRACE n
    1.45 +
    1.46  setopt CONFIG_LGUEST n
    1.47 -setopt CONFIG_XEN_BLKDEV_FRONTEND y
    1.48 -setopt CONFIG_XEN_NETDEV_FRONTEND y
    1.49 -setopt CONFIG_HVC_XEN y
    1.50 +
    1.51 +setopt CONFIG_LOCALVERSION_AUTO n
    1.52 +
    1.53 +# Should all be set one way or another in defconfig but aren't
    1.54  setopt CONFIG_NUMA n
    1.55 -setopt CONFIG_LOCALVERSION_AUTO n
    1.56 +setopt CONFIG_X86_VSMP n
    1.57 +setopt CONFIG_X86_UV n
    1.58 +setopt CONFIG_CALGARY_IOMMU n
    1.59 +setopt CONFIG_AMD_IOMMU n
    1.60 +setopt CONFIG_MAXSMP n
    1.61 +setopt CONFIG_SPARSEMEM_VMEMMAP n
    1.62 +setopt CONFIG_I7300_IDLE n
    1.63 +setopt CONFIG_DMAR n
    1.64 +setopt CONFIG_INTR_REMAP n
    1.65 +setopt CONFIG_GFS2_FS n
    1.66 +setopt CONFIG_IOMMU_DEBUG n
    1.67  
    1.68  case ${XEN_TARGET_ARCH} in
    1.69      x86_32) setopt CONFIG_64BIT n ;;
    1.70 -    x86_64) setopt CONFIG_64BIT y ;;
    1.71 +    x86_64)
    1.72 +	setopt CONFIG_64BIT y
    1.73 +	setopt CONFIG_IA32_EMULATION y
    1.74 +	setopt CONFIG_IA32_AOUT n
    1.75 +	setopt CONFIG_CRYPTO_AES_X86_64 n
    1.76 +	setopt CONFIG_CRYPTO_SALSA20_X86_64 n
    1.77 +	setopt CONFIG_CRYPTO_TWOFISH_X86_64 n
    1.78 +	;;
    1.79      *) ;;
    1.80  esac
    1.81  
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/buildconfigs/mk.linux-2.6-pvops	Mon Mar 02 18:26:56 2009 +0900
     2.3 @@ -0,0 +1,14 @@
     2.4 +XEN_LINUX_SOURCE ?= git-clone
     2.5 +LINUX_VER ?= 2.6-pvops
     2.6 +
     2.7 +IMAGE_TARGET ?= bzImage
     2.8 +
     2.9 +XEN_LINUX_CONFIG_UPDATE := buildconfigs/enable-xen-config
    2.10 +
    2.11 +XEN_LINUX_GIT_URL ?= git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git
    2.12 +XEN_LINUX_GIT_REMOTENAME ?= xen
    2.13 +XEN_LINUX_GIT_REMOTEBRANCH ?= xen/dom0/hackery
    2.14 +
    2.15 +EXTRAVERSION ?=
    2.16 +
    2.17 +include buildconfigs/mk.linux-2.6-common
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/docs/misc/xsm-flask.txt	Mon Mar 02 18:26:56 2009 +0900
     3.3 @@ -0,0 +1,148 @@
     3.4 +These notes are compiled from xen-devel questions and postings that have occured
     3.5 +since the inclusion of XSM.  These notes are not intended to be definitive
     3.6 +documentation but should address many common problems that arrise when
     3.7 +experimenting with XSM:FLASK.
     3.8 +
     3.9 +Xen XSM:FLASK configuration
    3.10 +---------------------------
    3.11 +
    3.12 +1) cd xen-unstable.hg
    3.13 +2) edit Config.mk in the toplevel xen directory as follows:
    3.14 +
    3.15 +	XSM_ENABLE ?= y
    3.16 +	FLASK_ENABLE ?= y
    3.17 +	ACM_SECURITY ?= n
    3.18 +	
    3.19 +NB: Only one security module can be selected at a time.  If no module is
    3.20 +selected, then the default DUMMY module will be enforced.  The DUMMY module
    3.21 +only exercises the security framework and does not enforce any security
    3.22 +policies.  Changing the security module selection will require recompiling xen.
    3.23 +These settings will also configure the corresponding toolchain support.  
    3.24 +
    3.25 +3) make xen
    3.26 +4) make tools
    3.27 +
    3.28 +
    3.29 +Xen XSM:FLASK policy
    3.30 +--------------------
    3.31 +
    3.32 +These instructions will enable the configuration and build of the sample policy.
    3.33 +The sample policy provides the MINIMUM policy necessary to boot a
    3.34 +paravirtualized dom0 and create a paravirtualized domU.  Many of the 
    3.35 +default capabilities and usages supported by dom0/domU are disallowed by the
    3.36 +sample policy.  Further, the policy is comprised of a limited number of types and 
    3.37 +must be adjusted to meet the specific security goals of the installation. 
    3.38 +Modification of the policy is straightforward and is covered in a later section.
    3.39 +
    3.40 +NB: The policy is not automatically built as part of the tool support because 
    3.41 +of an external dependancy on the checkpolicy compiler.  The FLASK policy uses 
    3.42 +the same syntax and structure as SELinux and compiling the policy relies on 
    3.43 +the SELinux policy toolchain.  This toolchain is available under many 
    3.44 +distributions as well as the following URL,
    3.45 +
    3.46 +	http://userspace.selinuxproject.org/releases/20080909/stable/checkpolicy-1.34.7.tar.gz
    3.47 +
    3.48 +1) cd xen-unstable.hg/tools/flask/policy
    3.49 +2) make policy
    3.50 +3) cp policy.20 /boot/xenpolicy.20
    3.51 +4) edit /etc/grub.conf, add a module line to the xen entry,
    3.52 +
    3.53 +	module /xenpolicy.20
    3.54 +
    3.55 +5) reboot, and select the updated xen entry
    3.56 +
    3.57 +NB: The module entry can be inserted on any line after the xen kernel line.  Typical
    3.58 +configurations use the last module entry or the module entry that immediately 
    3.59 +follows the xen kernel entry.
    3.60 +
    3.61 +Xen configuration of xend
    3.62 +-------------------------
    3.63 +
    3.64 +1) cd /etc/xen
    3.65 +2) edit xend-config.sxp
    3.66 +3) uncomment the line containing the key:value pair entry, 
    3.67 +
    3.68 +	#(xsm_module_name dummy)
    3.69 +
    3.70 +4) change the value entry to 'flask'
    3.71 +
    3.72 +	(xsm_module_name flask)
    3.73 +
    3.74 +5) restart xend
    3.75 +
    3.76 +Creating policy controlled domains
    3.77 +----------------------------------
    3.78 +
    3.79 +2) Edit the domain config file and add the following entry,
    3.80 +
    3.81 +	access_control = ["policy=,label=system_u:object_r:domU_t"]
    3.82 +
    3.83 +NB: The 'policy' field is not used by XSM:FLASK.  The 'label' must exist in the 
    3.84 +loaded policy. 'system_u:object_r:domU_t' is one of the existing labels from 
    3.85 +the sample policy and shown for example purposes.
    3.86 +
    3.87 +2) Create the domain using the 'xm create' command.
    3.88 +3) Use the 'xm list -l' command to list the running domains and their labels.
    3.89 +
    3.90 +Updating the XSM:FLASK policy
    3.91 +-----------------------------
    3.92 +
    3.93 +It is recommended that the XSM:FLASK policy be tailored to meet the specific
    3.94 +security goals of the platform.  The policy is tailored by editing the xen.te 
    3.95 +file in the 'policy' subdirectory.
    3.96 +
    3.97 +1) cd xen-unstable.hg/tools/flask/policy
    3.98 +2) edit policy/modules/xen/xen.te - make changes to support platform security goals.
    3.99 +3) make policy
   3.100 +4) cp policy.20 /boot/xenpolicy.20
   3.101 +5) reboot
   3.102 +
   3.103 +Alternatively, one may reload the policy using the 'flask_loadpolicy' tool
   3.104 +installed by the xen tools.
   3.105 +
   3.106 +1) flask_loadpolicy policy.20
   3.107 +
   3.108 +NB: The sample policy permits policy reloads as well as general manipulation of
   3.109 +the Flask security server only from dom0.  The policy can be tailored further to
   3.110 +restrict policy reloads and other manipulations to boot-time only, by removing 
   3.111 +the corresponding statements from the policy.
   3.112 +
   3.113 +Enforcing the XSM:FLASK policy
   3.114 +------------------------------
   3.115 +
   3.116 +By default, XSM:FLASK is compiled and installed in permissive mode.  This
   3.117 +configuration will allow an XSM:FLASK system to start in enforcing mode.
   3.118 +
   3.119 +1) edit /etc/grub.conf
   3.120 +2) append the parameter 'flask_enforcing=1' to the xen kernel line.
   3.121 +3) reboot, and select the updated xen entry
   3.122 +
   3.123 +
   3.124 +Additional notes on XSM:FLASK
   3.125 +-----------------------------
   3.126 +
   3.127 +1) xen command line parameters
   3.128 +
   3.129 +	a) flask_enforcing
   3.130 +	
   3.131 +	The default value for flask_enforcing is '0'.  This parameter causes the 
   3.132 +	platform to boot in permissive mode which means that the policy is loaded 
   3.133 +	but not enforced.  This mode is often helpful for developing new systems 
   3.134 +	and policies as the policy violations are reported on the xen console and 
   3.135 +	may be viewed in dom0 through 'xm dmesg'.
   3.136 +	
   3.137 +	To boot the platform into enforcing mode, which means that the policy is
   3.138 +	loaded and enforced, append 'flask_enforcing=1' on the grub line.
   3.139 +	
   3.140 +	This parameter may also be changed through the flask hyercall.
   3.141 +	
   3.142 +	b) flask_enabled
   3.143 +	
   3.144 +	The default value for flask_enabled is '1'.  This parameter causes the
   3.145 +	platform to enable the FLASK security module under the XSM framework.
   3.146 +	The parameter may be enabled/disabled only once per boot.  If the parameter
   3.147 +	is set to '0', only a reboot can re-enable flask.  When flask_enabled is '0'
   3.148 +	the DUMMY module is enforced.
   3.149 +
   3.150 +	This parameter may also be changed through the flask hypercall.  But may
   3.151 +	only be performed once per boot.
     4.1 --- a/tools/console/daemon/io.c	Mon Mar 02 16:52:22 2009 +0900
     4.2 +++ b/tools/console/daemon/io.c	Mon Mar 02 18:26:56 2009 +0900
     4.3 @@ -402,9 +402,7 @@ static int domain_create_tty(struct doma
     4.4  	assert(dom->slave_fd == -1);
     4.5  	assert(dom->master_fd == -1);
     4.6  
     4.7 -	cfmakeraw(&term);
     4.8 -
     4.9 -	if (openpty(&dom->master_fd, &dom->slave_fd, NULL, &term, NULL) < 0) {
    4.10 +	if (openpty(&dom->master_fd, &dom->slave_fd, NULL, NULL, NULL) < 0) {
    4.11  		err = errno;
    4.12  		dolog(LOG_ERR, "Failed to create tty for domain-%d "
    4.13  		      "(errno = %i, %s)",
    4.14 @@ -412,6 +410,22 @@ static int domain_create_tty(struct doma
    4.15  		return 0;
    4.16  	}
    4.17  
    4.18 +	if (tcgetattr(dom->slave_fd, &term) < 0) {
    4.19 +		err = errno;
    4.20 +		dolog(LOG_ERR, "Failed to get tty attributes for domain-%d "
    4.21 +			"(errno = %i, %s)",
    4.22 +			dom->domid, err, strerror(err));
    4.23 +		goto out;
    4.24 +	}
    4.25 +	cfmakeraw(&term);
    4.26 +	if (tcsetattr(dom->slave_fd, TCSANOW, &term) < 0) {
    4.27 +		err = errno;
    4.28 +		dolog(LOG_ERR, "Failed to set tty attributes for domain-%d "
    4.29 +			"(errno = %i, %s)",
    4.30 +			dom->domid, err, strerror(err));
    4.31 +		goto out;
    4.32 +	}
    4.33 +
    4.34  	if ((slave = ptsname(dom->master_fd)) == NULL) {
    4.35  		err = errno;
    4.36  		dolog(LOG_ERR, "Failed to get slave name for domain-%d "
     5.1 --- a/tools/hotplug/Linux/init.d/xendomains	Mon Mar 02 16:52:22 2009 +0900
     5.2 +++ b/tools/hotplug/Linux/init.d/xendomains	Mon Mar 02 18:26:56 2009 +0900
     5.3 @@ -213,7 +213,7 @@ is_running()
     5.4  start() 
     5.5  {
     5.6      if [ -f $LOCKFILE ]; then 
     5.7 -	echo -n "xendomains already running (lockfile exists)"
     5.8 +	echo -e "xendomains already running (lockfile exists)"
     5.9  	return; 
    5.10      fi
    5.11  
    5.12 @@ -230,10 +230,12 @@ start()
    5.13                  HEADER=`head -c 16 $dom | head -n 1 2> /dev/null`
    5.14                  if [ $HEADER = "LinuxGuestRecord" ]; then
    5.15                      echo -n " ${dom##*/}"
    5.16 -                    xm restore $dom
    5.17 +                    XMR=`xm restore $dom 2>&1 1>/dev/null`
    5.18 +                    #xm restore $dom
    5.19                      if [ $? -ne 0 ]; then
    5.20 +                        echo -e "\nAn error occurred while restoring domain ${dom##*/}:\n$XMR"
    5.21                          rc_failed $?
    5.22 -                        echo -n '!'
    5.23 +                        echo -e '!'
    5.24                      else
    5.25                          # mv $dom ${dom%/*}/.${dom##*/}
    5.26                          rm $dom
    5.27 @@ -241,7 +243,7 @@ start()
    5.28                  fi
    5.29              fi
    5.30          done
    5.31 -	echo .
    5.32 +	echo -e
    5.33      fi
    5.34  
    5.35      if contains_something "$XENDOMAINS_AUTO"
    5.36 @@ -264,16 +266,17 @@ start()
    5.37  	    if [ $? -eq 0 ] || is_running $dom; then
    5.38  		echo -n "(skip)"
    5.39  	    else
    5.40 -		xm create --quiet --defconfig $dom
    5.41 +		XMC=`xm create --quiet --defconfig $dom`
    5.42  		if [ $? -ne 0 ]; then
    5.43 +		    echo -e "\nAn error occurred while creating domain ${dom##*/}: $XMC\n"
    5.44  		    rc_failed $?
    5.45 -		    echo -n '!'
    5.46 +		    echo -e '!'
    5.47  		else
    5.48  		    usleep $XENDOMAINS_CREATE_USLEEP
    5.49  		fi
    5.50  	    fi
    5.51  	done
    5.52 -    fi	
    5.53 +    fi
    5.54  }
    5.55  
    5.56  all_zombies()
    5.57 @@ -293,18 +296,21 @@ all_zombies()
    5.58  # if it has not exited by that time kill it, so the init script will
    5.59  # succeed within a finite amount of time; if $2 is nonnull, it will
    5.60  # kill the command as well as soon as no domain (except for zombies)
    5.61 -# are left (used for shutdown --all).
    5.62 +# are left (used for shutdown --all). Third parameter, if any, suppresses
    5.63 +# output of dots per working state (formatting issues)
    5.64  watchdog_xm()
    5.65  {
    5.66      if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
    5.67  	exit
    5.68      fi
    5.69 +
    5.70      usleep 20000
    5.71      for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
    5.72  	# exit if xm save/migrate/shutdown is finished
    5.73  	PSAX=`ps axlw | grep "xm $1" | grep -v grep`
    5.74  	if test -z "$PSAX"; then exit; fi
    5.75 -	echo -n "."; sleep 1
    5.76 +	if ! test -n "$3"; then echo -n '.'; fi
    5.77 +	sleep 1
    5.78  	# go to kill immediately if there's only zombies left
    5.79  	if all_zombies && test -n "$2"; then break; fi
    5.80      done
    5.81 @@ -312,10 +318,14 @@ watchdog_xm()
    5.82      read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
    5.83      # kill xm $1
    5.84      kill $PSPID >/dev/null 2>&1
    5.85 +    
    5.86 +    echo -e .
    5.87  }
    5.88  
    5.89  stop()
    5.90  {
    5.91 +    exec 3>&2 2> /dev/null
    5.92 +    
    5.93      # Collect list of domains to shut down
    5.94      if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
    5.95  	rdnames
    5.96 @@ -333,7 +343,7 @@ stop()
    5.97  		    # nothing
    5.98  		    ;;
    5.99  		(*)
   5.100 -		    echo -n '(skip)'
   5.101 +		    echo -e '(skip)'
   5.102  		    continue
   5.103  		    ;;
   5.104  	    esac
   5.105 @@ -345,8 +355,9 @@ stop()
   5.106  	if test -n "$XENDOMAINS_SYSRQ"; then
   5.107  	    for sysrq in $XENDOMAINS_SYSRQ; do
   5.108  		echo -n "(SR-$sysrq)"
   5.109 -		xm sysrq $id $sysrq
   5.110 +		XMR=`xm sysrq $id $sysrq 2>&1 1>/dev/null`
   5.111  		if test $? -ne 0; then
   5.112 +		    echo -e "\nAn error occurred while doing sysrq on domain:\n$XMR\n"
   5.113  		    rc_failed $?
   5.114  		    echo -n '!'
   5.115  		fi
   5.116 @@ -362,13 +373,18 @@ stop()
   5.117  	    echo -n "(migr)"
   5.118  	    watchdog_xm migrate &
   5.119  	    WDOG_PID=$!
   5.120 -	    xm migrate $id $XENDOMAINS_MIGRATE
   5.121 +	    XMR=`xm migrate $id $XENDOMAINS_MIGRATE 2>&1 1>/dev/null`
   5.122  	    if test $? -ne 0; then
   5.123 +		echo -e "\nAn error occurred while migrating domain:\n$XMR\n"
   5.124  		rc_failed $?
   5.125 -		echo -n '!'
   5.126 +		echo -e '!'
   5.127 +
   5.128  		kill $WDOG_PID >/dev/null 2>&1
   5.129  	    else
   5.130  		kill $WDOG_PID >/dev/null 2>&1
   5.131 +		
   5.132 +		echo -e .
   5.133 +		usleep 1000
   5.134  		continue
   5.135  	    fi
   5.136  	fi
   5.137 @@ -377,13 +393,16 @@ stop()
   5.138  	    watchdog_xm save &
   5.139  	    WDOG_PID=$!
   5.140  	    mkdir -p "$XENDOMAINS_SAVE"
   5.141 -	    xm save $id $XENDOMAINS_SAVE/$name
   5.142 +	    XMR=`xm save $id $XENDOMAINS_SAVE/$name 2>&1 1>/dev/null`
   5.143  	    if test $? -ne 0; then
   5.144 +		echo -e "\nAn error occurred while saving domain:\n$XMR\n"
   5.145  		rc_failed $?
   5.146 -		echo -n '!'
   5.147 +		echo -e '!'
   5.148  		kill $WDOG_PID >/dev/null 2>&1
   5.149  	    else
   5.150  		kill $WDOG_PID >/dev/null 2>&1
   5.151 +		echo -e .
   5.152 +		usleep 1000
   5.153  		continue
   5.154  	    fi
   5.155  	fi
   5.156 @@ -392,10 +411,11 @@ stop()
   5.157  	    echo -n "(shut)"
   5.158  	    watchdog_xm shutdown &
   5.159  	    WDOG_PID=$!
   5.160 -	    xm shutdown $id $XENDOMAINS_SHUTDOWN
   5.161 +	    XMR=`xm shutdown $id $XENDOMAINS_SHUTDOWN 2>&1 1>/dev/null`
   5.162  	    if test $? -ne 0; then
   5.163 +		echo -e "\nAn error occurred while shutting down domain:\n$XMR\n"
   5.164  		rc_failed $?
   5.165 -		echo -n '!'
   5.166 +		echo -e '!'
   5.167  	    fi
   5.168  	    kill $WDOG_PID >/dev/null 2>&1
   5.169  	fi
   5.170 @@ -408,18 +428,21 @@ stop()
   5.171      if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
   5.172  	# XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait"
   5.173  	echo -n " SHUTDOWN_ALL "
   5.174 -	watchdog_xm shutdown 1 &
   5.175 +	watchdog_xm shutdown 1 false &
   5.176  	WDOG_PID=$!
   5.177 -	xm shutdown $XENDOMAINS_SHUTDOWN_ALL
   5.178 +	XMR=`xm shutdown $XENDOMAINS_SHUTDOWN_ALL 2>&1 1>/dev/null`
   5.179  	if test $? -ne 0; then
   5.180 +	    echo -e "\nAn error occurred while shutting down all domains: $XMR\n"
   5.181  	    rc_failed $?
   5.182 -	    echo -n '!'
   5.183 +	    echo -e '!'
   5.184  	fi
   5.185  	kill $WDOG_PID >/dev/null 2>&1
   5.186      fi
   5.187  
   5.188      # Unconditionally delete lock file
   5.189      rm -f $LOCKFILE
   5.190 +    
   5.191 +    exec 2>&3
   5.192  }
   5.193  
   5.194  check_domain_up()
     6.1 --- a/tools/libxc/xc_ptrace.c	Mon Mar 02 16:52:22 2009 +0900
     6.2 +++ b/tools/libxc/xc_ptrace.c	Mon Mar 02 18:26:56 2009 +0900
     6.3 @@ -149,173 +149,6 @@ online_vcpus_changed(uint64_t cpumap)
     6.4  
     6.5  }
     6.6  
     6.7 -/* --------------------- */
     6.8 -/* XXX application state */
     6.9 -static long      nr_pages = 0;
    6.10 -static uint64_t *page_array = NULL;
    6.11 -
    6.12 -static uint64_t to_ma(int cpu, uint64_t maddr)
    6.13 -{
    6.14 -    return maddr;
    6.15 -}
    6.16 -
    6.17 -static void *
    6.18 -map_domain_va_32(
    6.19 -    int xc_handle,
    6.20 -    int cpu,
    6.21 -    void *guest_va,
    6.22 -    int perm)
    6.23 -{
    6.24 -    unsigned long l2e, l1e, l1p, p, va = (unsigned long)guest_va;
    6.25 -    uint32_t *l2, *l1;
    6.26 -    static void *v[MAX_VIRT_CPUS];
    6.27 -
    6.28 -    l2 = xc_map_foreign_range(
    6.29 -         xc_handle, current_domid, PAGE_SIZE, PROT_READ,
    6.30 -         xen_cr3_to_pfn(ctxt[cpu].c.ctrlreg[3]));
    6.31 -    if ( l2 == NULL )
    6.32 -        return NULL;
    6.33 -
    6.34 -    l2e = l2[l2_table_offset_i386(va)];
    6.35 -    munmap(l2, PAGE_SIZE);
    6.36 -    if ( !(l2e & _PAGE_PRESENT) )
    6.37 -        return NULL;
    6.38 -    l1p = to_ma(cpu, l2e);
    6.39 -    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
    6.40 -    if ( l1 == NULL )
    6.41 -        return NULL;
    6.42 -
    6.43 -    l1e = l1[l1_table_offset_i386(va)];
    6.44 -    munmap(l1, PAGE_SIZE);
    6.45 -    if ( !(l1e & _PAGE_PRESENT) )
    6.46 -        return NULL;
    6.47 -    p = to_ma(cpu, l1e);
    6.48 -    if ( v[cpu] != NULL )
    6.49 -        munmap(v[cpu], PAGE_SIZE);
    6.50 -    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
    6.51 -    if ( v[cpu] == NULL )
    6.52 -        return NULL;
    6.53 -
    6.54 -    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
    6.55 -}
    6.56 -
    6.57 -
    6.58 -static void *
    6.59 -map_domain_va_pae(
    6.60 -    int xc_handle,
    6.61 -    int cpu,
    6.62 -    void *guest_va,
    6.63 -    int perm)
    6.64 -{
    6.65 -    uint64_t l3e, l2e, l1e, l2p, l1p, p;
    6.66 -    unsigned long va = (unsigned long)guest_va;
    6.67 -    uint64_t *l3, *l2, *l1;
    6.68 -    static void *v[MAX_VIRT_CPUS];
    6.69 -
    6.70 -    l3 = xc_map_foreign_range(
    6.71 -        xc_handle, current_domid, PAGE_SIZE, PROT_READ,
    6.72 -        xen_cr3_to_pfn(ctxt[cpu].c.ctrlreg[3]));
    6.73 -    if ( l3 == NULL )
    6.74 -        return NULL;
    6.75 -
    6.76 -    l3e = l3[l3_table_offset_pae(va)];
    6.77 -    munmap(l3, PAGE_SIZE);
    6.78 -    if ( !(l3e & _PAGE_PRESENT) )
    6.79 -        return NULL;
    6.80 -    l2p = to_ma(cpu, l3e);
    6.81 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
    6.82 -    if ( l2 == NULL )
    6.83 -        return NULL;
    6.84 -
    6.85 -    l2e = l2[l2_table_offset_pae(va)];
    6.86 -    munmap(l2, PAGE_SIZE);
    6.87 -    if ( !(l2e & _PAGE_PRESENT) )
    6.88 -        return NULL;
    6.89 -    l1p = to_ma(cpu, l2e);
    6.90 -    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
    6.91 -    if ( l1 == NULL )
    6.92 -        return NULL;
    6.93 -
    6.94 -    l1e = l1[l1_table_offset_pae(va)];
    6.95 -    munmap(l1, PAGE_SIZE);
    6.96 -    if ( !(l1e & _PAGE_PRESENT) )
    6.97 -        return NULL;
    6.98 -    p = to_ma(cpu, l1e);
    6.99 -    if ( v[cpu] != NULL )
   6.100 -        munmap(v[cpu], PAGE_SIZE);
   6.101 -    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
   6.102 -    if ( v[cpu] == NULL )
   6.103 -        return NULL;
   6.104 -
   6.105 -    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
   6.106 -}
   6.107 -
   6.108 -#ifdef __x86_64__
   6.109 -static void *
   6.110 -map_domain_va_64(
   6.111 -    int xc_handle,
   6.112 -    int cpu,
   6.113 -    void *guest_va,
   6.114 -    int perm)
   6.115 -{
   6.116 -    unsigned long l4e, l3e, l2e, l1e, l3p, l2p, l1p, p, va = (unsigned long)guest_va;
   6.117 -    uint64_t *l4, *l3, *l2, *l1;
   6.118 -    static void *v[MAX_VIRT_CPUS];
   6.119 -
   6.120 -    if ((ctxt[cpu].c.ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
   6.121 -        return map_domain_va_32(xc_handle, cpu, guest_va, perm);
   6.122 -
   6.123 -    l4 = xc_map_foreign_range(
   6.124 -        xc_handle, current_domid, PAGE_SIZE, PROT_READ,
   6.125 -        xen_cr3_to_pfn(ctxt[cpu].c.ctrlreg[3]));
   6.126 -    if ( l4 == NULL )
   6.127 -        return NULL;
   6.128 -
   6.129 -    l4e = l4[l4_table_offset(va)];
   6.130 -    munmap(l4, PAGE_SIZE);
   6.131 -    if ( !(l4e & _PAGE_PRESENT) )
   6.132 -        return NULL;
   6.133 -    l3p = to_ma(cpu, l4e);
   6.134 -    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p >> PAGE_SHIFT);
   6.135 -    if ( l3 == NULL )
   6.136 -        return NULL;
   6.137 -
   6.138 -    l3e = l3[l3_table_offset(va)];
   6.139 -    munmap(l3, PAGE_SIZE);
   6.140 -    if ( !(l3e & _PAGE_PRESENT) )
   6.141 -        return NULL;
   6.142 -    l2p = to_ma(cpu, l3e);
   6.143 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
   6.144 -    if ( l2 == NULL )
   6.145 -        return NULL;
   6.146 -
   6.147 -    l2e = l2[l2_table_offset(va)];
   6.148 -    munmap(l2, PAGE_SIZE);
   6.149 -    if ( !(l2e & _PAGE_PRESENT) )
   6.150 -        return NULL;
   6.151 -    l1p = to_ma(cpu, l2e);
   6.152 -    if (l2e & 0x80)  { /* 2M pages */
   6.153 -        p = to_ma(cpu, l1p + (l1_table_offset(va) << PAGE_SHIFT));
   6.154 -    } else { /* 4K pages */
   6.155 -        l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
   6.156 -        if ( l1 == NULL )
   6.157 -            return NULL;
   6.158 -
   6.159 -        l1e = l1[l1_table_offset(va)];
   6.160 -        munmap(l1, PAGE_SIZE);
   6.161 -        if ( !(l1e & _PAGE_PRESENT) )
   6.162 -            return NULL;
   6.163 -        p = to_ma(cpu, l1e);
   6.164 -    }
   6.165 -    if ( v[cpu] != NULL )
   6.166 -        munmap(v[cpu], PAGE_SIZE);
   6.167 -    v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
   6.168 -    if ( v[cpu] == NULL )
   6.169 -        return NULL;
   6.170 -
   6.171 -    return (void *)((unsigned long)v[cpu] | (va & (PAGE_SIZE - 1)));
   6.172 -}
   6.173 -#endif
   6.174  
   6.175  static void *
   6.176  map_domain_va(
   6.177 @@ -324,68 +157,30 @@ map_domain_va(
   6.178      void *guest_va,
   6.179      int perm)
   6.180  {
   6.181 -    unsigned long va = (unsigned long) guest_va;
   6.182 -    long npgs = xc_get_tot_pages(xc_handle, current_domid);
   6.183 -    static enum { MODE_UNKNOWN, MODE_64, MODE_32, MODE_PAE } mode;
   6.184 -
   6.185 -    if ( mode == MODE_UNKNOWN )
   6.186 -    {
   6.187 -        xen_capabilities_info_t caps;
   6.188 -        (void)xc_version(xc_handle, XENVER_capabilities, caps);
   6.189 -        if ( strstr(caps, "-x86_64") )
   6.190 -            mode = MODE_64;
   6.191 -        else if ( strstr(caps, "-x86_32p") )
   6.192 -            mode = MODE_PAE;
   6.193 -        else if ( strstr(caps, "-x86_32") )
   6.194 -            mode = MODE_32;
   6.195 -    }
   6.196 +    unsigned long va = (unsigned long)guest_va;
   6.197 +    unsigned long mfn;
   6.198 +    void *map;
   6.199  
   6.200 -    if ( nr_pages != npgs )
   6.201 -    {
   6.202 -        if ( nr_pages > 0 )
   6.203 -            free(page_array);
   6.204 -        nr_pages = npgs;
   6.205 -        if ( (page_array = malloc(nr_pages * sizeof(*page_array))) == NULL )
   6.206 -        {
   6.207 -            IPRINTF("Could not allocate memory\n");
   6.208 -            return NULL;
   6.209 -        }
   6.210 -        if ( xc_get_pfn_list(xc_handle, current_domid,
   6.211 -                             page_array, nr_pages) != nr_pages )
   6.212 -        {
   6.213 -            IPRINTF("Could not get the page frame list\n");
   6.214 -            return NULL;
   6.215 -        }
   6.216 -    }
   6.217 +    /* cross page boundary */
   6.218 +    if ( (va & ~PAGE_MASK) + sizeof(long) > PAGE_SIZE )
   6.219 +        return NULL;
   6.220  
   6.221 -    if (fetch_regs(xc_handle, cpu, NULL))
   6.222 +    mfn = xc_translate_foreign_address(xc_handle, current_domid, cpu, va);
   6.223 +    if ( mfn == 0 )
   6.224          return NULL;
   6.225  
   6.226 -    if (!paging_enabled(&ctxt[cpu])) {
   6.227 -        static void * v;
   6.228 -        uint64_t page;
   6.229 -
   6.230 -        if ( v != NULL )
   6.231 -            munmap(v, PAGE_SIZE);
   6.232 -
   6.233 -        page = to_ma(cpu, va);
   6.234 -
   6.235 -        v = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE,
   6.236 -                perm, page >> PAGE_SHIFT);
   6.237 +    map = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, 
   6.238 +                               perm, mfn);
   6.239 +    if (map == NULL)
   6.240 +        return NULL;
   6.241  
   6.242 -        if ( v == NULL )
   6.243 -            return NULL;
   6.244 +    return map + (va & ~PAGE_MASK);
   6.245 +}
   6.246  
   6.247 -        return (void *)(((unsigned long)v) | (va & BSD_PAGE_MASK));
   6.248 -    }
   6.249 -#ifdef __x86_64__
   6.250 -    if ( mode == MODE_64 )
   6.251 -        return map_domain_va_64(xc_handle, cpu, guest_va, perm);
   6.252 -#endif
   6.253 -    if ( mode == MODE_PAE )
   6.254 -        return map_domain_va_pae(xc_handle, cpu, guest_va, perm);
   6.255 -    /* else ( mode == MODE_32 ) */
   6.256 -    return map_domain_va_32(xc_handle, cpu, guest_va, perm);
   6.257 +static void
   6.258 +unmap_domain_va(void *guest_va)
   6.259 +{
   6.260 +    munmap((void *)((unsigned long)guest_va & PAGE_MASK), PAGE_SIZE);
   6.261  }
   6.262  
   6.263  int control_c_pressed_flag = 0;
   6.264 @@ -473,6 +268,8 @@ xc_ptrace(
   6.265          if ( guest_va == NULL )
   6.266              goto out_error;
   6.267          retval = *guest_va;
   6.268 +        if (!current_isfile)
   6.269 +            unmap_domain_va(guest_va);
   6.270          break;
   6.271  
   6.272      case PTRACE_POKETEXT:
   6.273 @@ -486,7 +283,9 @@ xc_ptrace(
   6.274                  xc_handle, cpu, addr, PROT_READ|PROT_WRITE);
   6.275          if ( guest_va == NULL )
   6.276              goto out_error;
   6.277 -        *guest_va = (unsigned long)data;
   6.278 +        *guest_va = edata;
   6.279 +        if (!current_isfile)
   6.280 +            unmap_domain_va(guest_va);
   6.281          break;
   6.282  
   6.283      case PTRACE_GETREGS:
     7.1 --- a/tools/misc/xenpm.c	Mon Mar 02 16:52:22 2009 +0900
     7.2 +++ b/tools/misc/xenpm.c	Mon Mar 02 18:26:56 2009 +0900
     7.3 @@ -303,35 +303,34 @@ static void signal_int_handler(int signo
     7.4      printf("Elapsed time (ms): %"PRIu64"\n", (usec_end - usec_start) / 1000UL);
     7.5      for ( i = 0; i < max_cpu_nr; i++ )
     7.6      {
     7.7 -        uint64_t temp;
     7.8 -        printf("CPU%d:\n\tresidency\tpercentage\n", i);
     7.9 -        if ( cx_cap )
    7.10 +        uint64_t res, triggers;
    7.11 +        double avg_res;
    7.12 +
    7.13 +        printf("\nCPU%d:\tResidency(ms)\t\tAvg Res(ms)\n",i);
    7.14 +        if ( cx_cap && sum_cx[i] > 0 )
    7.15          {
    7.16              for ( j = 0; j < cxstat_end[i].nr; j++ )
    7.17              {
    7.18 -                if ( sum_cx[i] > 0 )
    7.19 -                {
    7.20 -                    temp = cxstat_end[i].residencies[j] -
    7.21 -                           cxstat_start[i].residencies[j];
    7.22 -                    printf("  C%d\t%"PRIu64" ms\t%.2f%%\n", j,
    7.23 -                           temp / 1000000UL, 100UL * temp / (double)sum_cx[i]);
    7.24 -                }
    7.25 +                res = cxstat_end[i].residencies[j] -
    7.26 +                    cxstat_start[i].residencies[j];
    7.27 +                triggers = cxstat_end[i].triggers[j] -
    7.28 +                    cxstat_start[i].triggers[j];
    7.29 +                avg_res = (triggers==0) ? 0: (double)res/triggers/1000000.0;
    7.30 +                printf("  C%d\t%"PRIu64"\t(%5.2f%%)\t%.2f\n", j, res/1000000UL,
    7.31 +                        100 * res / (double)sum_cx[i], avg_res );
    7.32              }
    7.33 +            printf("\n");
    7.34          }
    7.35 -        if ( px_cap )
    7.36 +        if ( px_cap && sum_px[i]>0 )
    7.37          {
    7.38              for ( j = 0; j < pxstat_end[i].total; j++ )
    7.39              {
    7.40 -                if ( sum_px[i] > 0 )
    7.41 -                {
    7.42 -                    temp = pxstat_end[i].pt[j].residency -
    7.43 -                           pxstat_start[i].pt[j].residency;
    7.44 -                    printf("  P%d\t%"PRIu64" ms\t%.2f%%\n", j,
    7.45 -                           temp / 1000000UL, 100UL * temp / (double)sum_px[i]);
    7.46 -                }
    7.47 +                res = pxstat_end[i].pt[j].residency -
    7.48 +                    pxstat_start[i].pt[j].residency;
    7.49 +                printf("  P%d\t%"PRIu64"\t(%5.2f%%)\n", j,
    7.50 +                        res / 1000000UL, 100UL * res / (double)sum_px[i]);
    7.51              }
    7.52          }
    7.53 -        printf("\n");
    7.54      }
    7.55  
    7.56      /* some clean up and then exits */
    7.57 @@ -408,6 +407,7 @@ void start_gather_func(int argc, char *a
    7.58          free(cxstat);
    7.59          return ;
    7.60      }
    7.61 +    printf("Start sampling, waiting for CTRL-C or SIGINT signal ...\n");
    7.62  
    7.63      pause();
    7.64  }
     8.1 --- a/tools/pygrub/src/pygrub	Mon Mar 02 16:52:22 2009 +0900
     8.2 +++ b/tools/pygrub/src/pygrub	Mon Mar 02 18:26:56 2009 +0900
     8.3 @@ -501,7 +501,7 @@ def get_entry_idx(cf, entry):
     8.4  
     8.5      return None
     8.6  
     8.7 -def run_grub(file, entry, fs):
     8.8 +def run_grub(file, entry, fs, arg):
     8.9      global g
    8.10      global sel
    8.11  
    8.12 @@ -534,7 +534,7 @@ def run_grub(file, entry, fs):
    8.13      if img.initrd:
    8.14          grubcfg["ramdisk"] = img.initrd[1]
    8.15      if img.args:
    8.16 -        grubcfg["args"] = img.args
    8.17 +        grubcfg["args"] = img.args + " " + arg
    8.18  
    8.19      return grubcfg
    8.20  
    8.21 @@ -659,7 +659,7 @@ if __name__ == "__main__":
    8.22      chosencfg = sniff_solaris(fs, incfg)
    8.23  
    8.24      if not chosencfg["kernel"]:
    8.25 -        chosencfg = run_grub(file, entry, fs)
    8.26 +        chosencfg = run_grub(file, entry, fs, incfg["args"])
    8.27  
    8.28      data = fs.open_file(chosencfg["kernel"]).read()
    8.29      (tfd, bootcfg["kernel"]) = tempfile.mkstemp(prefix="boot_kernel.",
     9.1 --- a/tools/python/xen/util/vscsi_util.py	Mon Mar 02 16:52:22 2009 +0900
     9.2 +++ b/tools/python/xen/util/vscsi_util.py	Mon Mar 02 18:26:56 2009 +0900
     9.3 @@ -78,8 +78,38 @@ def _vscsi_get_hctl_by(phyname, scsi_dev
     9.4      return (None, None)
     9.5  
     9.6  
     9.7 -def vscsi_get_scsidevices():
     9.8 -    """ get all scsi devices"""
     9.9 +def _vscsi_get_scsiid(sg):
    9.10 +    scsi_id = os.popen('/sbin/scsi_id -gu -s /class/scsi_generic/' + sg).read().split()
    9.11 +    if len(scsi_id):
    9.12 +        return scsi_id[0]
    9.13 +    return None
    9.14 +
    9.15 +
    9.16 +def _vscsi_get_scsidevices_by_lsscsi(option = ""):
    9.17 +    """ get all scsi devices information by lsscsi """
    9.18 +
    9.19 +    devices = []
    9.20 +
    9.21 +    for scsiinfo in os.popen('lsscsi -g %s' % option).readlines():
    9.22 +        s = scsiinfo.split()
    9.23 +        hctl = s[0][1:-1]
    9.24 +        try:
    9.25 +            devname = s[-2].split('/dev/')[1]
    9.26 +        except IndexError:
    9.27 +            devname = None
    9.28 +        try:
    9.29 +            sg = s[-1].split('/dev/')[1]
    9.30 +            scsi_id = _vscsi_get_scsiid(sg)
    9.31 +        except IndexError:
    9.32 +            sg = None
    9.33 +            scsi_id = None
    9.34 +        devices.append([hctl, devname, sg, scsi_id])
    9.35 +
    9.36 +    return devices
    9.37 +
    9.38 +
    9.39 +def _vscsi_get_scsidevices_by_sysfs():
    9.40 +    """ get all scsi devices information by sysfs """
    9.41  
    9.42      devices = []
    9.43      sysfs_mnt = utils.find_sysfs_mount() 
    9.44 @@ -100,18 +130,29 @@ def vscsi_get_scsidevices():
    9.45  
    9.46                  if re.match('^scsi_generic', f):
    9.47                      sg = os.path.basename(realpath)
    9.48 -                    lines = os.popen('/sbin/scsi_id -gu -s /class/scsi_generic/' + sg).read().split()
    9.49 -                    if len(lines):
    9.50 -                        scsi_id = lines[0]
    9.51 -
    9.52 +                    scsi_id = _vscsi_get_scsiid(sg)
    9.53              devices.append([hctl, devname, sg, scsi_id])
    9.54  
    9.55      return devices
    9.56  
    9.57  
    9.58 +def vscsi_get_scsidevices():
    9.59 +    """ get all scsi devices information """
    9.60 +
    9.61 +    devices = _vscsi_get_scsidevices_by_lsscsi("")
    9.62 +    if devices:
    9.63 +        return devices
    9.64 +    return _vscsi_get_scsidevices_by_sysfs()
    9.65 +
    9.66 +
    9.67  def vscsi_get_hctl_and_devname_by(target, scsi_devices = None):
    9.68      if scsi_devices is None:
    9.69 -        scsi_devices = vscsi_get_scsidevices()
    9.70 +        if len(target.split(':')) == 4:
    9.71 +            scsi_devices = _vscsi_get_scsidevices_by_lsscsi(target)
    9.72 +        elif target.startswith('/dev/'): 
    9.73 +            scsi_devices = _vscsi_get_scsidevices_by_lsscsi("| grep %s" % target)
    9.74 +        else:
    9.75 +            scsi_devices = vscsi_get_scsidevices()
    9.76  
    9.77      if len(target.split(':')) == 4:
    9.78          return _vscsi_get_devname_by(target, scsi_devices)
    10.1 --- a/tools/python/xen/xend/XendAPI.py	Mon Mar 02 16:52:22 2009 +0900
    10.2 +++ b/tools/python/xen/xend/XendAPI.py	Mon Mar 02 18:26:56 2009 +0900
    10.3 @@ -29,6 +29,7 @@ import xmlrpclib
    10.4  import XendDomain, XendDomainInfo, XendNode, XendDmesg
    10.5  import XendLogging, XendTaskManager, XendAPIStore
    10.6  
    10.7 +from xen.xend import uuid as genuuid
    10.8  from XendAPIVersion import *
    10.9  from XendAuthSessions import instance as auth_manager
   10.10  from XendError import *
   10.11 @@ -1867,7 +1868,7 @@ class XendAPI(object):
   10.12          dom = xendom.get_vm_by_uuid(vbd_struct['VM'])
   10.13          vdi = xennode.get_vdi_by_uuid(vbd_struct['VDI'])
   10.14          if not vdi:
   10.15 -            return xen_api_error(['HANDLE_INVALID', 'VDI', vdi_ref])
   10.16 +            return xen_api_error(['HANDLE_INVALID', 'VDI', vbd_struct['VDI']])
   10.17  
   10.18          # new VBD via VDI/SR
   10.19          vdi_image = vdi.get_location()
   10.20 @@ -2392,7 +2393,7 @@ class XendAPI(object):
   10.21              tpmif.destroy_vtpmstate(dom.getName())
   10.22              return xen_api_success_void()
   10.23          else:
   10.24 -            return xen_api_error(['HANDLE_INVALID', 'VM', vtpm_struct['VM']])
   10.25 +            return xen_api_error(['HANDLE_INVALID', 'VTPM', vtpm_ref])
   10.26  
   10.27      # class methods
   10.28      def VTPM_create(self, session, vtpm_struct):
   10.29 @@ -2614,7 +2615,7 @@ class XendAPI(object):
   10.30          return xen_api_success_void()
   10.31  
   10.32      def event_unregister(self, session, unreg_classes):
   10.33 -        event_unregister(session, reg_classes)
   10.34 +        event_unregister(session, unreg_classes)
   10.35          return xen_api_success_void()
   10.36  
   10.37      def event_next(self, session):
   10.38 @@ -2641,7 +2642,7 @@ class XendAPI(object):
   10.39          return xen_api_error(['DEBUG_FAIL', session])
   10.40  
   10.41      def debug_create(self, session):
   10.42 -        debug_uuid = uuid.createString()
   10.43 +        debug_uuid = genuuid.createString()
   10.44          self._debug[debug_uuid] = None
   10.45          return xen_api_success(debug_uuid)
   10.46  
    11.1 --- a/tools/python/xen/xend/XendBootloader.py	Mon Mar 02 16:52:22 2009 +0900
    11.2 +++ b/tools/python/xen/xend/XendBootloader.py	Mon Mar 02 18:26:56 2009 +0900
    11.3 @@ -67,9 +67,23 @@ def bootloader(blexec, disk, dom, quiet 
    11.4      # listening on the bootloader's fifo for the results.
    11.5  
    11.6      (m1, s1) = pty.openpty()
    11.7 -    tty.setraw(m1);
    11.8 -    fcntl.fcntl(m1, fcntl.F_SETFL, os.O_NDELAY);
    11.9 -    os.close(s1)
   11.10 +
   11.11 +    # On Solaris, the pty master side will get cranky if we try
   11.12 +    # to write to it while there is no slave. To work around this,
   11.13 +    # keep the slave descriptor open until we're done. Set it
   11.14 +    # to raw terminal parameters, otherwise it will echo back
   11.15 +    # characters, which will confuse the I/O loop below.
   11.16 +    # Furthermore, a raw master pty device has no terminal
   11.17 +    # semantics on Solaris, so don't try to set any attributes
   11.18 +    # for it.
   11.19 +    if os.uname()[0] != 'SunOS' and os.uname()[0] != 'NetBSD':
   11.20 +        tty.setraw(m1)
   11.21 +        os.close(s1)
   11.22 +    else:
   11.23 +        tty.setraw(s1)
   11.24 +
   11.25 +    fcntl.fcntl(m1, fcntl.F_SETFL, os.O_NDELAY)
   11.26 +
   11.27      slavename = ptsname.ptsname(m1)
   11.28      dom.storeDom("console/tty", slavename)
   11.29  
   11.30 @@ -108,7 +122,11 @@ def bootloader(blexec, disk, dom, quiet 
   11.31      # record that this domain is bootloading
   11.32      dom.bootloader_pid = child
   11.33  
   11.34 -    tty.setraw(m2);
   11.35 +    # On Solaris, the master pty side does not have terminal semantics,
   11.36 +    # so don't try to set any attributes, as it will fail.
   11.37 +    if os.uname()[0] != 'SunOS':
   11.38 +        tty.setraw(m2);
   11.39 +
   11.40      fcntl.fcntl(m2, fcntl.F_SETFL, os.O_NDELAY);
   11.41      while True:
   11.42          try:
   11.43 @@ -117,32 +135,55 @@ def bootloader(blexec, disk, dom, quiet 
   11.44              if e.errno == errno.EINTR:
   11.45                  continue
   11.46          break
   11.47 +
   11.48 +    fcntl.fcntl(r, fcntl.F_SETFL, os.O_NDELAY);
   11.49 +
   11.50      ret = ""
   11.51      inbuf=""; outbuf="";
   11.52 +    # filedescriptors:
   11.53 +    #   r - input from the bootloader (bootstring output)
   11.54 +    #   m1 - input/output from/to xenconsole
   11.55 +    #   m2 - input/output from/to pty that controls the bootloader
   11.56 +    # The filedescriptors are NDELAY, so it's ok to try to read
   11.57 +    # bigger chunks than may be available, to keep e.g. curses
   11.58 +    # screen redraws in the bootloader efficient. m1 is the side that
   11.59 +    # gets xenconsole input, which will be keystrokes, so a small number
   11.60 +    # is sufficient. m2 is pygrub output, which will be curses screen
   11.61 +    # updates, so a larger number (1024) is appropriate there.
   11.62 +    #
   11.63 +    # For writeable descriptors, only include them in the set for select
   11.64 +    # if there is actual data to write, otherwise this would loop too fast,
   11.65 +    # eating up CPU time.
   11.66 +
   11.67      while True:
   11.68 -        sel = select.select([r, m1, m2], [m1, m2], [])
   11.69 +        wsel = []
   11.70 +        if len(outbuf) != 0:
   11.71 +            wsel = wsel + [m1]
   11.72 +        if len(inbuf) != 0:
   11.73 +            wsel = wsel + [m2]
   11.74 +        sel = select.select([r, m1, m2], wsel, [])
   11.75          try: 
   11.76              if m1 in sel[0]:
   11.77 -                s = os.read(m1, 1)
   11.78 +                s = os.read(m1, 16)
   11.79                  inbuf += s
   11.80 -            if m2 in sel[1] and len(inbuf) != 0:
   11.81 -                os.write(m2, inbuf[0])
   11.82 -                inbuf = inbuf[1:]
   11.83 +            if m2 in sel[1]:
   11.84 +                n = os.write(m2, inbuf)
   11.85 +                inbuf = inbuf[n:]
   11.86          except OSError, e:
   11.87              if e.errno == errno.EIO:
   11.88                  pass
   11.89          try:
   11.90              if m2 in sel[0]:
   11.91 -                s = os.read(m2, 1)
   11.92 +                s = os.read(m2, 1024)
   11.93                  outbuf += s
   11.94 -            if m1 in sel[1] and len(outbuf) != 0:
   11.95 -                os.write(m1, outbuf[0])
   11.96 -                outbuf = outbuf[1:]
   11.97 +            if m1 in sel[1]:
   11.98 +                n = os.write(m1, outbuf)
   11.99 +                outbuf = outbuf[n:]
  11.100          except OSError, e:
  11.101              if e.errno == errno.EIO:
  11.102                  pass
  11.103          if r in sel[0]:
  11.104 -            s = os.read(r, 1)
  11.105 +            s = os.read(r, 128)
  11.106              ret = ret + s
  11.107              if len(s) == 0:
  11.108                  break
  11.109 @@ -152,6 +193,8 @@ def bootloader(blexec, disk, dom, quiet 
  11.110      os.close(r)
  11.111      os.close(m2)
  11.112      os.close(m1)
  11.113 +    if os.uname()[0] == 'SunOS' or os.uname()[0] == 'NetBSD':
  11.114 +        os.close(s1)
  11.115      os.unlink(fifo)
  11.116  
  11.117      # Re-acquire the lock to cover the changes we're about to make
    12.1 --- a/tools/python/xen/xend/XendConfig.py	Mon Mar 02 16:52:22 2009 +0900
    12.2 +++ b/tools/python/xen/xend/XendConfig.py	Mon Mar 02 18:26:56 2009 +0900
    12.3 @@ -158,6 +158,7 @@ XENAPI_PLATFORM_CFG_TYPES = {
    12.4      'vncdisplay': int,
    12.5      'vnclisten': str,
    12.6      'timer_mode': int,
    12.7 +    'vpt_align': int,
    12.8      'viridian': int,
    12.9      'vncpasswd': str,
   12.10      'vncunused': int,
   12.11 @@ -430,6 +431,8 @@ class XendConfig(dict):
   12.12      def _vcpus_sanity_check(self):
   12.13          if 'VCPUs_max' in self and 'vcpu_avail' not in self:
   12.14              self['vcpu_avail'] = (1 << self['VCPUs_max']) - 1
   12.15 +        if 'online_vcpus' in self:
   12.16 +            self['VCPUs_live'] = self['online_vcpus']
   12.17  
   12.18      def _uuid_sanity_check(self):
   12.19          """Make sure UUID is in proper string format with hyphens."""
   12.20 @@ -459,6 +462,8 @@ class XendConfig(dict):
   12.21                  self['platform']['rtc_timeoffset'] = 0
   12.22              if 'hpet' not in self['platform']:
   12.23                  self['platform']['hpet'] = 0
   12.24 +            if 'vpt_align' not in self['platform']:
   12.25 +                self['platform']['vpt_align'] = 1
   12.26              if 'loader' not in self['platform']:
   12.27                  # Old configs may have hvmloader set as PV_kernel param
   12.28                  if self.has_key('PV_kernel') and self['PV_kernel'] != '':
   12.29 @@ -1269,6 +1274,7 @@ class XendConfig(dict):
   12.30                                                    uuid.createString())
   12.31                  vscsi_dict = self.vscsi_convert_sxp_to_dict(config)
   12.32                  vscsi_devs = vscsi_dict['devs']
   12.33 +                vscsi_mode = vscsi_dict['feature-host']
   12.34  
   12.35                  # create XenAPI DSCSI objects.
   12.36                  for vscsi_dev in vscsi_devs:
   12.37 @@ -1283,9 +1289,14 @@ class XendConfig(dict):
   12.38                      }
   12.39                      XendDSCSI(dscsi_uuid, dscsi_record)
   12.40  
   12.41 -                target['devices'][vscsi_devs_uuid] = \
   12.42 -                    (dev_type, {'devs': vscsi_devs, 'uuid': vscsi_devs_uuid} )
   12.43 -                log.debug("XendConfig: reading device: %s" % vscsi_devs)
   12.44 +                vscsi_info = {
   12.45 +                    'devs': vscsi_devs,
   12.46 +                    'feature-host': vscsi_mode,
   12.47 +                    'uuid': vscsi_devs_uuid
   12.48 +                }
   12.49 +                target['devices'][vscsi_devs_uuid] = (dev_type, vscsi_info)
   12.50 +                log.debug("XendConfig: reading device: %s,%s" % \
   12.51 +                          (vscsi_devs, vscsi_mode))
   12.52                  return vscsi_devs_uuid
   12.53  
   12.54              for opt_val in config[1:]:
   12.55 @@ -1575,7 +1586,7 @@ class XendConfig(dict):
   12.56                  try:
   12.57                      opt, val = opt_val
   12.58                      pci_dev_info[opt] = val
   12.59 -                except TypeError:
   12.60 +                except (TypeError, ValueError):
   12.61                      pass
   12.62              # append uuid for each pci device.
   12.63              dpci_uuid = pci_dev_info.get('uuid', uuid.createString())
   12.64 @@ -1609,6 +1620,7 @@ class XendConfig(dict):
   12.65          #
   12.66          # [device,
   12.67          #   [vscsi,
   12.68 +        #     [feature-host, 0],
   12.69          #     [dev,
   12.70          #       [devid, 0], [p-devname, sdb], [p-dev, 1:0:0:1],
   12.71          #       [v-dev, 0:0:0:0], [state, 1]
   12.72 @@ -1619,6 +1631,7 @@ class XendConfig(dict):
   12.73          #     ]
   12.74          #   ],
   12.75          #   [vscsi,
   12.76 +        #     [feature-host, 1],
   12.77          #     [dev,
   12.78          #       [devid, 1], [p-devname, sdg], [p-dev, 2:0:0:0],
   12.79          #       [v-dev, 1:0:0:0], [state, 1]
   12.80 @@ -1639,6 +1652,7 @@ class XendConfig(dict):
   12.81          #
   12.82          # [device,
   12.83          #   [vscsi,
   12.84 +        #     [feature-host, 0],
   12.85          #     [dev,
   12.86          #       [devid, 0], [p-devname, sdd], [p-dev, 1:0:0:3],
   12.87          #       [v-dev, 0:0:0:2], [state, 1]
   12.88 @@ -1653,7 +1667,8 @@ class XendConfig(dict):
   12.89          # The Dict looks like this:
   12.90          #
   12.91          # { devs: [ {devid: 0, p-devname: sdd, p-dev: 1:0:0:3,
   12.92 -        #            v-dev: 0:0:0:2, state: 1} ] }
   12.93 +        #            v-dev: 0:0:0:2, state: 1} ],
   12.94 +        #   feature-host: 1 }
   12.95  
   12.96          dev_config = {}
   12.97  
   12.98 @@ -1672,6 +1687,9 @@ class XendConfig(dict):
   12.99              vscsi_devs.append(vscsi_dev_info)
  12.100          dev_config['devs'] = vscsi_devs 
  12.101  
  12.102 +        vscsi_mode = sxp.children(dev_sxp, 'feature-host')[0]
  12.103 +        dev_config['feature-host'] = vscsi_mode[1]
  12.104 +
  12.105          return dev_config
  12.106  
  12.107      def console_add(self, protocol, location, other_config = {}):
  12.108 @@ -1784,6 +1802,7 @@ class XendConfig(dict):
  12.109              if dev_type == 'vscsi': # Special case for vscsi
  12.110                  vscsi_dict = self.vscsi_convert_sxp_to_dict(config)
  12.111                  vscsi_devs = vscsi_dict['devs']
  12.112 +                vscsi_mode = vscsi_dict['feature-host']
  12.113  
  12.114                  # destroy existing XenAPI DSCSI objects
  12.115                  for dscsi_uuid in XendDSCSI.get_by_VM(self['uuid']):
  12.116 @@ -1802,8 +1821,12 @@ class XendConfig(dict):
  12.117                      }
  12.118                      XendDSCSI(dscsi_uuid, dscsi_record)
  12.119  
  12.120 -                self['devices'][dev_uuid] = \
  12.121 -                    (dev_type, {'devs': vscsi_devs, 'uuid': dev_uuid} )
  12.122 +                vscsi_info = { 
  12.123 +                    'devs': vscsi_devs,
  12.124 +                    'feature-host': vscsi_mode,
  12.125 +                    'uuid': dev_uuid
  12.126 +                }
  12.127 +                self['devices'][dev_uuid] = (dev_type, vscsi_info)
  12.128                  return True
  12.129                  
  12.130              for opt_val in config[1:]:
  12.131 @@ -1880,7 +1903,6 @@ class XendConfig(dict):
  12.132      def all_devices_sxpr(self, target = None):
  12.133          """Returns the SXPR for all devices in the current configuration."""
  12.134          sxprs = []
  12.135 -        pci_devs = []
  12.136  
  12.137          if target == None:
  12.138              target = self
  12.139 @@ -1895,7 +1917,8 @@ class XendConfig(dict):
  12.140                  if dev_type == 'pci':
  12.141                      sxpr = ['pci', ['uuid', dev_info['uuid']]]
  12.142                  elif dev_type == 'vscsi':
  12.143 -                    sxpr = ['vscsi', ['uuid', dev_info['uuid']]]
  12.144 +                    sxpr = ['vscsi', ['uuid', dev_info['uuid']],
  12.145 +                                     ['feature-host', dev_info['feature-host']]]
  12.146                  for pci_dev_info in dev_info['devs']:
  12.147                      pci_dev_sxpr = ['dev']
  12.148                      for opt, val in pci_dev_info.items():
    13.1 --- a/tools/python/xen/xend/XendConstants.py	Mon Mar 02 16:52:22 2009 +0900
    13.2 +++ b/tools/python/xen/xend/XendConstants.py	Mon Mar 02 18:26:56 2009 +0900
    13.3 @@ -50,6 +50,7 @@ HVM_PARAM_VIRIDIAN     = 9 # x86
    13.4  HVM_PARAM_TIMER_MODE   = 10
    13.5  HVM_PARAM_HPET_ENABLED = 11
    13.6  HVM_PARAM_ACPI_S_STATE = 14
    13.7 +HVM_PARAM_VPT_ALIGN    = 16
    13.8  
    13.9  restart_modes = [
   13.10      "restart",
    14.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Mar 02 16:52:22 2009 +0900
    14.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Mon Mar 02 18:26:56 2009 +0900
    14.3 @@ -898,15 +898,21 @@ class XendDomainInfo:
    14.4          else:
    14.5              cur_dev_sxp = self._getDeviceInfo_vscsi(req_devid, None)
    14.6              new_dev_sxp = ['vscsi']
    14.7 +            cur_mode = sxp.children(cur_dev_sxp, 'feature-host')[0]
    14.8 +            new_dev_sxp.append(cur_mode)
    14.9 +
   14.10              for cur_dev in sxp.children(cur_dev_sxp, 'dev'):
   14.11                  if state == xenbusState['Closing']:
   14.12 +                    if int(cur_mode[1]) == 1:
   14.13 +                        continue
   14.14                      cur_dev_vdev = sxp.child_value(cur_dev, 'v-dev')
   14.15                      if cur_dev_vdev == dev['v-dev']:
   14.16                          continue
   14.17                  new_dev_sxp.append(cur_dev)
   14.18  
   14.19              if state == xenbusState['Initialising']:
   14.20 -                new_dev_sxp.append(sxp.child0(dev_sxp, 'dev'))
   14.21 +                for new_dev in sxp.children(dev_sxp, 'dev'):
   14.22 +                    new_dev_sxp.append(new_dev)
   14.23  
   14.24              dev_uuid = sxp.child_value(cur_dev_sxp, 'uuid')
   14.25              self.info.device_update(dev_uuid, new_dev_sxp)
   14.26 @@ -1112,7 +1118,8 @@ class XendDomainInfo:
   14.27                          vscsi_dev.append(['frontstate', None])
   14.28                          vscsi_devs[1].append(vscsi_dev)
   14.29                          dev_num = int(sxp.child_value(vscsi_dev, 'devid'))
   14.30 -                    sxprs.append([dev_num, [vscsi_devs]])
   14.31 +                    vscsi_mode = sxp.children(dev_info, 'feature-host')[0]
   14.32 +                    sxprs.append([dev_num, [vscsi_devs, vscsi_mode]])
   14.33                  elif deviceClass == 'vbd':
   14.34                      dev = sxp.child_value(dev_info, 'dev')
   14.35                      if 'ioemu:' in dev:
   14.36 @@ -2237,6 +2244,12 @@ class XendDomainInfo:
   14.37              xc.hvm_set_param(self.domid, HVM_PARAM_HPET_ENABLED,
   14.38                               long(hpet))
   14.39  
   14.40 +        # Optionally enable periodic vpt aligning
   14.41 +        vpt_align = self.info["platform"].get("vpt_align")
   14.42 +        if hvm and vpt_align is not None:
   14.43 +            xc.hvm_set_param(self.domid, HVM_PARAM_VPT_ALIGN,
   14.44 +                             long(vpt_align))
   14.45 +
   14.46          # Set maximum number of vcpus in domain
   14.47          xc.domain_max_vcpus(self.domid, int(self.info['VCPUs_max']))
   14.48  
    15.1 --- a/tools/python/xen/xend/server/vscsiif.py	Mon Mar 02 16:52:22 2009 +0900
    15.2 +++ b/tools/python/xen/xend/server/vscsiif.py	Mon Mar 02 18:26:56 2009 +0900
    15.3 @@ -68,6 +68,8 @@ class VSCSIController(DevController):
    15.4              vscsi_config.append(['devs', devs])
    15.5              state = self.readFrontend(devid, 'state')
    15.6              vscsi_config.append(['state', state])
    15.7 +            hostmode = self.readBackend(devid, 'feature-host')
    15.8 +            vscsi_config.append(['feature-host', hostmode])
    15.9              backid = self.readFrontend(devid, 'backend-id')
   15.10              vscsi_config.append(['backend-id', backid])
   15.11              backpath = self.readFrontend(devid, 'backend')
   15.12 @@ -98,6 +100,8 @@ class VSCSIController(DevController):
   15.13              devid = vscsi_config.get('devid', '')
   15.14              back[devpath + '/devid'] = str(devid)
   15.15  
   15.16 +        host_mode = config.get('feature-host','')
   15.17 +        back['feature-host'] = str(host_mode)
   15.18          back['uuid'] = config.get('uuid','')
   15.19          devid = int(devid)
   15.20          return (devid, back, {})
   15.21 @@ -133,6 +137,7 @@ class VSCSIController(DevController):
   15.22              vscsi_devs.append(dev_dict)
   15.23  
   15.24          config['devs'] = vscsi_devs
   15.25 +        config['feature-host'] = self.readBackend(devid, 'feature-host')
   15.26          config['uuid'] = self.readBackend(devid, 'uuid')
   15.27          return config
   15.28  
   15.29 @@ -171,6 +176,7 @@ class VSCSIController(DevController):
   15.30          vscsi_config = config['devs'][0]
   15.31          state = vscsi_config.get('state', xenbusState['Unknown'])
   15.32          driver_state = self.readBackend(devid, 'state')
   15.33 +
   15.34          if str(xenbusState['Connected']) != driver_state:
   15.35              raise VmError("Driver status is not connected")
   15.36  
   15.37 @@ -182,13 +188,20 @@ class VSCSIController(DevController):
   15.38          elif state == xenbusState['Closing']:
   15.39              found = False
   15.40              devs = self.readBackendList(devid, "vscsi-devs")
   15.41 +            hostmode = int(self.readBackend(devid, 'feature-host'))
   15.42              vscsipath = "vscsi-devs/"
   15.43              vdev = vscsi_config.get('v-dev', '')
   15.44  
   15.45              for dev in devs:
   15.46                  devpath = vscsipath + dev
   15.47                  old_vdev = self.readBackend(devid, devpath + '/v-dev')
   15.48 -                if vdev == old_vdev:
   15.49 +
   15.50 +                if hostmode == 1:
   15.51 +                    #At hostmode, all v-dev that belongs to devid is deleted.
   15.52 +                    found = True
   15.53 +                    self.writeBackend(devid, devpath + '/state', \
   15.54 +                                    str(xenbusState['Closing']))
   15.55 +                elif vdev == old_vdev:
   15.56                      found = True
   15.57                      self.writeBackend(devid, devpath + '/state', \
   15.58                                      str(xenbusState['Closing']))
    16.1 --- a/tools/python/xen/xm/create.py	Mon Mar 02 16:52:22 2009 +0900
    16.2 +++ b/tools/python/xen/xm/create.py	Mon Mar 02 18:26:56 2009 +0900
    16.3 @@ -219,6 +219,10 @@ gopts.var('timer_mode', val='TIMER_MODE'
    16.4            use="""Timer mode (0=delay virtual time when ticks are missed;
    16.5            1=virtual time is always wallclock time.""")
    16.6  
    16.7 +gopts.var('vpt_align', val='VPT_ALIGN',
    16.8 +          fn=set_int, default=1,
    16.9 +          use="Enable aligning all periodic vpt to reduce timer interrupts.")
   16.10 +
   16.11  gopts.var('viridian', val='VIRIDIAN',
   16.12            fn=set_int, default=0,
   16.13            use="""Expose Viridian interface to x86 HVM guest?
   16.14 @@ -699,33 +703,20 @@ def configure_pci(config_devs, vals):
   16.15          config_pci.insert(0, 'pci')
   16.16          config_devs.append(['device', config_pci])
   16.17  
   16.18 -def vscsi_convert_sxp_to_dict(dev_sxp):
   16.19 -    dev_dict = {}
   16.20 -    for opt_val in dev_sxp[1:]:
   16.21 -        try:
   16.22 -            opt, val = opt_val
   16.23 -            dev_dict[opt] = val
   16.24 -        except TypeError:
   16.25 -            pass
   16.26 -    return dev_dict
   16.27 -
   16.28 -def vscsi_lookup_devid(devlist, req_devid):
   16.29 -    if len(devlist) == 0:
   16.30 -        return 0
   16.31 -    else:
   16.32 -        for devid, backend in devlist:
   16.33 -            if devid == req_devid:
   16.34 -                return 1
   16.35 -        return 0
   16.36 -
   16.37  def configure_vscsis(config_devs, vals):
   16.38      """Create the config for vscsis (virtual scsi devices).
   16.39      """
   16.40 -    devidlist = []
   16.41 -    config_scsi = []
   16.42 +
   16.43 +    def get_devid(hctl):
   16.44 +        return int(hctl.split(':')[0])
   16.45 +
   16.46      if len(vals.vscsi) == 0:
   16.47          return 0
   16.48  
   16.49 +    config_scsi = {}
   16.50 +    pHCTL_list = []
   16.51 +    vHCTL_list = []
   16.52 +
   16.53      scsi_devices = vscsi_util.vscsi_get_scsidevices()
   16.54      for (p_dev, v_dev, backend) in vals.vscsi:
   16.55          (p_hctl, devname) = \
   16.56 @@ -734,34 +725,55 @@ def configure_vscsis(config_devs, vals):
   16.57          if p_hctl == None:
   16.58              raise ValueError('Cannot find device "%s"' % p_dev)
   16.59  
   16.60 -        for config in config_scsi:
   16.61 -            dev = vscsi_convert_sxp_to_dict(config)
   16.62 -            if dev['v-dev'] == v_dev:
   16.63 -                raise ValueError('The virtual device "%s" is already defined' % v_dev)
   16.64 +        feature_host = 0
   16.65 +        if v_dev == 'host':
   16.66 +            feature_host = 1
   16.67 +            scsi_info = []
   16.68 +            devid = get_devid(p_hctl)
   16.69 +            for (pHCTL, devname, _, _) in scsi_devices:
   16.70 +                if get_devid(pHCTL) == devid:
   16.71 +                    scsi_info.append([devid, pHCTL, devname, pHCTL])
   16.72 +        else:
   16.73 +            scsi_info = [[get_devid(v_dev), p_hctl, devname, v_dev]]
   16.74  
   16.75 -        v_hctl = v_dev.split(':')
   16.76 -        devid = int(v_hctl[0])
   16.77 -        config_scsi.append(['dev', \
   16.78 -                        ['state', xenbusState['Initialising']], \
   16.79 -                        ['devid', devid], \
   16.80 -                        ['p-dev', p_hctl], \
   16.81 -                        ['p-devname', devname], \
   16.82 -                        ['v-dev', v_dev] ])
   16.83 +        devid_key = scsi_info[0][0]
   16.84 +        try:
   16.85 +            config = config_scsi[devid_key]
   16.86 +        except KeyError:
   16.87 +            config = {'feature-host': feature_host, 'backend': backend, 'devs': []}
   16.88  
   16.89 -        if vscsi_lookup_devid(devidlist, devid) == 0:
   16.90 -            devidlist.append([devid, backend])
   16.91 +        devs = config['devs']
   16.92 +        for (devid, pHCTL, devname, vHCTL) in scsi_info:
   16.93 +            if pHCTL in pHCTL_list:
   16.94 +                raise ValueError('The physical device "%s" is already defined' % pHCTL)
   16.95 +            if vHCTL in vHCTL_list:
   16.96 +                raise ValueError('The virtual device "%s" is already defined' % vHCTL)
   16.97 +            pHCTL_list.append(pHCTL)
   16.98 +            vHCTL_list.append(vHCTL)
   16.99 +            devs.append(['dev', \
  16.100 +                         ['state', xenbusState['Initialising']], \
  16.101 +                         ['devid', devid], \
  16.102 +                         ['p-dev', pHCTL], \
  16.103 +                         ['p-devname', devname], \
  16.104 +                         ['v-dev', vHCTL] ])
  16.105  
  16.106 -    for devid, backend in devidlist:
  16.107 -        tmp = []
  16.108 -        for config in config_scsi:
  16.109 -            dev = vscsi_convert_sxp_to_dict(config)
  16.110 -            if dev['devid'] == devid:
  16.111 -                tmp.append(config)
  16.112 +        if config['feature-host'] != feature_host:
  16.113 +            raise ValueError('The physical device "%s" cannot define '
  16.114 +                             'because mode is different' % scsi_info[0][1])
  16.115 +        if config['backend'] != backend:
  16.116 +            raise ValueError('The physical device "%s" cannot define '
  16.117 +                             'because backend is different' % scsi_info[0][1])
  16.118  
  16.119 -        tmp.insert(0, 'vscsi')
  16.120 -        if backend:
  16.121 -            tmp.append(['backend', backend])
  16.122 -        config_devs.append(['device', tmp])
  16.123 +        config['devs'] = devs
  16.124 +        config_scsi[devid_key] = config
  16.125 +
  16.126 +    for config in config_scsi.values():
  16.127 +        device = ['vscsi', ['feature-host', config['feature-host']]]
  16.128 +        for dev in config['devs']:
  16.129 +            device.append(dev)
  16.130 +        if config['backend']:
  16.131 +            device.append(['backend', config['backend']])
  16.132 +        config_devs.append(['device', device])
  16.133  
  16.134  def configure_ioports(config_devs, vals):
  16.135      """Create the config for legacy i/o ranges.
  16.136 @@ -891,7 +903,8 @@ def configure_hvm(config_image, vals):
  16.137               'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
  16.138               'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
  16.139               'guest_os_type', 'hap', 'opengl', 'cpuid', 'cpuid_check',
  16.140 -             'viridian', 'xen_extended_power_mgmt', 'pci_msitranslate' ]
  16.141 +             'viridian', 'xen_extended_power_mgmt', 'pci_msitranslate',
  16.142 +             'vpt_align' ]
  16.143  
  16.144      for a in args:
  16.145          if a in vals.__dict__ and vals.__dict__[a] is not None:
  16.146 @@ -1039,7 +1052,7 @@ def preprocess_vscsi(vals):
  16.147          n = len(d)
  16.148          if n == 2:
  16.149              tmp = d[1].split(':')
  16.150 -            if len(tmp) != 4:
  16.151 +            if d[1] != 'host' and len(tmp) != 4:
  16.152                  err('vscsi syntax error "%s"' % d[1])
  16.153              else:
  16.154                  d.append(None)
    17.1 --- a/tools/python/xen/xm/main.py	Mon Mar 02 16:52:22 2009 +0900
    17.2 +++ b/tools/python/xen/xm/main.py	Mon Mar 02 18:26:56 2009 +0900
    17.3 @@ -2032,6 +2032,8 @@ def parse_dev_info(info):
    17.4          'mac'        : get_info('mac',          str,   '??'),
    17.5          #block-device specific
    17.6          'ring-ref'   : get_info('ring-ref',     int,   -1),
    17.7 +        #vscsi specific
    17.8 +        'feature-host'   : get_info('feature-host',     int,   -1),
    17.9          }
   17.10  
   17.11  def arg_check_for_resource_list(args, name):
   17.12 @@ -2275,14 +2277,14 @@ def xm_scsi_list(args):
   17.13          hdr = 0
   17.14          for x in devs:
   17.15              if hdr == 0:
   17.16 -                print "%-3s %-3s %-5s  %-10s %-5s %-10s %-4s" \
   17.17 -                        % ('Idx', 'BE', 'state', 'phy-hctl', 'phy', 'vir-hctl', 'devstate')
   17.18 +                print "%-3s %-3s %-5s %-4s  %-10s %-5s %-10s %-4s" \
   17.19 +                        % ('Idx', 'BE', 'state', 'host', 'phy-hctl', 'phy', 'vir-hctl', 'devstate')
   17.20                  hdr = 1
   17.21              ni = parse_dev_info(x[1])
   17.22              ni['idx'] = int(x[0])
   17.23              for dev in x[1][0][1]:
   17.24                  mi = vscsi_convert_sxp_to_dict(dev)
   17.25 -                print "%(idx)-3d %(backend-id)-3d %(state)-5d " % ni,
   17.26 +                print "%(idx)-3d %(backend-id)-3d %(state)-5d %(feature-host)-4d " % ni,
   17.27                  print "%(p-dev)-10s %(p-devname)-5s %(v-dev)-10s %(frontstate)-4s" % mi
   17.28  
   17.29  def parse_block_configuration(args):
   17.30 @@ -2512,27 +2514,46 @@ def xm_pci_attach(args):
   17.31          server.xend.domain.device_configure(dom, pci)
   17.32  
   17.33  def parse_scsi_configuration(p_scsi, v_hctl, state):
   17.34 -    v = v_hctl.split(':')
   17.35 -    if len(v) != 4:
   17.36 -        raise OptionError("Invalid argument: %s" % v_hctl)
   17.37 -
   17.38 -    p_hctl = None
   17.39 -    devname = None
   17.40 +    def get_devid(hctl):
   17.41 +        return int(hctl.split(':')[0])
   17.42 +
   17.43 +    host_mode = 0
   17.44 +    scsi_devices = None
   17.45 +
   17.46      if p_scsi is not None:
   17.47 +        # xm scsi-attach
   17.48 +        if v_hctl == "host":
   17.49 +            host_mode = 1
   17.50 +            scsi_devices = vscsi_util.vscsi_get_scsidevices()
   17.51 +        elif len(v_hctl.split(':')) != 4:
   17.52 +            raise OptionError("Invalid argument: %s" % v_hctl)
   17.53          (p_hctl, devname) = \
   17.54 -            vscsi_util.vscsi_get_hctl_and_devname_by(p_scsi)
   17.55 +            vscsi_util.vscsi_get_hctl_and_devname_by(p_scsi, scsi_devices)
   17.56          if p_hctl is None:
   17.57              raise OptionError("Cannot find device '%s'" % p_scsi)
   17.58 -
   17.59 -    scsi = ['vscsi']
   17.60 -    scsi.append(['dev', \
   17.61 -                 ['state', state], \
   17.62 -                 ['devid', int(v[0])], \
   17.63 -                 ['p-dev', p_hctl], \
   17.64 -                 ['p-devname', devname], \
   17.65 -                 ['v-dev', v_hctl] \
   17.66 -               ])
   17.67 -
   17.68 +        if host_mode:
   17.69 +            scsi_info = []
   17.70 +            devid = get_devid(p_hctl)
   17.71 +            for pHCTL, devname, _, _ in scsi_devices:
   17.72 +                if get_devid(pHCTL) == devid:
   17.73 +                    scsi_info.append([devid, pHCTL, devname, pHCTL])
   17.74 +        else:
   17.75 +            scsi_info = [[get_devid(v_hctl), p_hctl, devname, v_hctl]] 
   17.76 +    else:
   17.77 +        # xm scsi-detach
   17.78 +        if len(v_hctl.split(':')) != 4:
   17.79 +            raise OptionError("Invalid argument: %s" % v_hctl)
   17.80 +        scsi_info = [[get_devid(v_hctl), None, None, v_hctl]]
   17.81 +
   17.82 +    scsi = ['vscsi', ['feature-host', host_mode]]
   17.83 +    for devid, pHCTL, devname, vHCTL in scsi_info:
   17.84 +        scsi.append(['dev', \
   17.85 +                     ['state', state], \
   17.86 +                     ['devid', devid], \
   17.87 +                     ['p-dev', pHCTL], \
   17.88 +                     ['p-devname', devname], \
   17.89 +                     ['v-dev', vHCTL] \
   17.90 +                   ])
   17.91      return scsi
   17.92  
   17.93  def xm_scsi_attach(args):
    18.1 --- a/tools/python/xen/xm/xenapi_create.py	Mon Mar 02 16:52:22 2009 +0900
    18.2 +++ b/tools/python/xen/xm/xenapi_create.py	Mon Mar 02 18:26:56 2009 +0900
    18.3 @@ -1037,6 +1037,7 @@ class sxp2xml:
    18.4              'usbdevice',
    18.5              'hpet',
    18.6              'timer_mode',
    18.7 +            'vpt_align',
    18.8              'viridian',
    18.9              'vhpt',
   18.10              'guest_os_type',
    19.1 --- a/tools/xenstore/xenstored_core.c	Mon Mar 02 16:52:22 2009 +0900
    19.2 +++ b/tools/xenstore/xenstored_core.c	Mon Mar 02 18:26:56 2009 +0900
    19.3 @@ -1937,14 +1937,17 @@ int main(int argc, char *argv[])
    19.4  			handle_event();
    19.5  
    19.6  		next = list_entry(connections.next, typeof(*conn), list);
    19.7 +		if (&next->list != &connections)
    19.8 +			talloc_increase_ref_count(next);
    19.9  		while (&next->list != &connections) {
   19.10  			conn = next;
   19.11  
   19.12  			next = list_entry(conn->list.next,
   19.13  					  typeof(*conn), list);
   19.14 +			if (&next->list != &connections)
   19.15 +				talloc_increase_ref_count(next);
   19.16  
   19.17  			if (conn->domain) {
   19.18 -				talloc_increase_ref_count(conn);
   19.19  				if (domain_can_read(conn))
   19.20  					handle_input(conn);
   19.21  				if (talloc_free(conn) == 0)
   19.22 @@ -1957,7 +1960,6 @@ int main(int argc, char *argv[])
   19.23  				if (talloc_free(conn) == 0)
   19.24  					continue;
   19.25  			} else {
   19.26 -				talloc_increase_ref_count(conn);
   19.27  				if (FD_ISSET(conn->fd, &inset))
   19.28  					handle_input(conn);
   19.29  				if (talloc_free(conn) == 0)
    20.1 --- a/xen/arch/ia64/xen/domain.c	Mon Mar 02 16:52:22 2009 +0900
    20.2 +++ b/xen/arch/ia64/xen/domain.c	Mon Mar 02 18:26:56 2009 +0900
    20.3 @@ -2023,6 +2023,7 @@ static void __init calc_dom0_size(void)
    20.4  	unsigned long p2m_pages;
    20.5  	unsigned long spare_hv_pages;
    20.6  	unsigned long max_dom0_size;
    20.7 +	unsigned long iommu_pg_table_pages = 0;
    20.8  
    20.9  	/* Estimate maximum memory we can safely allocate for dom0
   20.10  	 * by subtracting the p2m table allocation and a chunk of memory
   20.11 @@ -2033,8 +2034,13 @@ static void __init calc_dom0_size(void)
   20.12  	domheap_pages = avail_domheap_pages();
   20.13  	p2m_pages = domheap_pages / PTRS_PER_PTE;
   20.14  	spare_hv_pages = 8192 + (domheap_pages / 4096);
   20.15 -	max_dom0_size = (domheap_pages - (p2m_pages + spare_hv_pages))
   20.16 -			 * PAGE_SIZE;
   20.17 +
   20.18 +	if (iommu_enabled)
   20.19 +		iommu_pg_table_pages = domheap_pages * 4 / 512;
   20.20 +		/* There are 512 ptes in one 4K vtd page. */
   20.21 +
   20.22 +	max_dom0_size = (domheap_pages - (p2m_pages + spare_hv_pages) -
   20.23 +			iommu_pg_table_pages) * PAGE_SIZE;
   20.24  	printk("Maximum permitted dom0 size: %luMB\n",
   20.25  	       max_dom0_size / (1024*1024));
   20.26  
    21.1 --- a/xen/arch/x86/acpi/power.c	Mon Mar 02 16:52:22 2009 +0900
    21.2 +++ b/xen/arch/x86/acpi/power.c	Mon Mar 02 18:26:56 2009 +0900
    21.3 @@ -175,6 +175,7 @@ static int enter_state(u32 state)
    21.4      printk("Entering ACPI S%d state.\n", state);
    21.5  
    21.6      local_irq_save(flags);
    21.7 +    spin_debug_disable();
    21.8  
    21.9      if ( (error = device_power_down()) )
   21.10      {
   21.11 @@ -208,6 +209,7 @@ static int enter_state(u32 state)
   21.12      printk(XENLOG_INFO "Finishing wakeup from ACPI S%d state.", state);
   21.13  
   21.14   done:
   21.15 +    spin_debug_enable();
   21.16      local_irq_restore(flags);
   21.17      console_end_sync();
   21.18      acpi_sleep_post(state);
    22.1 --- a/xen/arch/x86/hvm/hvm.c	Mon Mar 02 16:52:22 2009 +0900
    22.2 +++ b/xen/arch/x86/hvm/hvm.c	Mon Mar 02 18:26:56 2009 +0900
    22.3 @@ -542,6 +542,22 @@ static int hvm_load_cpu_ctxt(struct doma
    22.4          return -EINVAL;
    22.5      }
    22.6  
    22.7 +    /* Older Xen versions used to save the segment arbytes directly 
    22.8 +     * from the VMCS on Intel hosts.  Detect this and rearrange them
    22.9 +     * into the struct segment_register format. */
   22.10 +#define UNFOLD_ARBYTES(_r)                          \
   22.11 +    if ( (_r & 0xf000) && !(_r & 0x0f00) )          \
   22.12 +        _r = ((_r & 0xff) | ((_r >> 4) & 0xf00))
   22.13 +    UNFOLD_ARBYTES(ctxt.cs_arbytes);
   22.14 +    UNFOLD_ARBYTES(ctxt.ds_arbytes);
   22.15 +    UNFOLD_ARBYTES(ctxt.es_arbytes);
   22.16 +    UNFOLD_ARBYTES(ctxt.fs_arbytes);
   22.17 +    UNFOLD_ARBYTES(ctxt.gs_arbytes);
   22.18 +    UNFOLD_ARBYTES(ctxt.ss_arbytes);
   22.19 +    UNFOLD_ARBYTES(ctxt.tr_arbytes);
   22.20 +    UNFOLD_ARBYTES(ctxt.ldtr_arbytes);
   22.21 +#undef UNFOLD_ARBYTES
   22.22 +
   22.23      /* Architecture-specific vmcs/vmcb bits */
   22.24      if ( hvm_funcs.load_cpu_ctxt(v, &ctxt) < 0 )
   22.25          return -EINVAL;
    23.1 --- a/xen/arch/x86/hvm/mtrr.c	Mon Mar 02 16:52:22 2009 +0900
    23.2 +++ b/xen/arch/x86/hvm/mtrr.c	Mon Mar 02 18:26:56 2009 +0900
    23.3 @@ -351,11 +351,18 @@ static uint8_t page_pat_type(uint64_t pa
    23.4  static uint8_t effective_mm_type(struct mtrr_state *m,
    23.5                                   uint64_t pat,
    23.6                                   paddr_t gpa,
    23.7 -                                 uint32_t pte_flags)
    23.8 +                                 uint32_t pte_flags,
    23.9 +                                 uint8_t gmtrr_mtype)
   23.10  {
   23.11      uint8_t mtrr_mtype, pat_value, effective;
   23.12 -
   23.13 -    mtrr_mtype = get_mtrr_type(m, gpa);
   23.14 +   
   23.15 +    /* if get_pat_flags() gives a dedicated MTRR type,
   23.16 +     * just use it
   23.17 +     */ 
   23.18 +    if ( gmtrr_mtype == NO_HARDCODE_MEM_TYPE )
   23.19 +        mtrr_mtype = get_mtrr_type(m, gpa);
   23.20 +    else
   23.21 +        mtrr_mtype = gmtrr_mtype;
   23.22  
   23.23      pat_value = page_pat_type(pat, pte_flags);
   23.24  
   23.25 @@ -367,7 +374,8 @@ static uint8_t effective_mm_type(struct 
   23.26  uint32_t get_pat_flags(struct vcpu *v,
   23.27                         uint32_t gl1e_flags,
   23.28                         paddr_t gpaddr,
   23.29 -                       paddr_t spaddr)
   23.30 +                       paddr_t spaddr,
   23.31 +                       uint8_t gmtrr_mtype)
   23.32  {
   23.33      uint8_t guest_eff_mm_type;
   23.34      uint8_t shadow_mtrr_type;
   23.35 @@ -378,7 +386,8 @@ uint32_t get_pat_flags(struct vcpu *v,
   23.36      /* 1. Get the effective memory type of guest physical address,
   23.37       * with the pair of guest MTRR and PAT
   23.38       */
   23.39 -    guest_eff_mm_type = effective_mm_type(g, pat, gpaddr, gl1e_flags);
   23.40 +    guest_eff_mm_type = effective_mm_type(g, pat, gpaddr, 
   23.41 +                                          gl1e_flags, gmtrr_mtype);
   23.42      /* 2. Get the memory type of host physical address, with MTRR */
   23.43      shadow_mtrr_type = get_mtrr_type(&mtrr_state, spaddr);
   23.44  
    24.1 --- a/xen/arch/x86/hvm/vpic.c	Mon Mar 02 16:52:22 2009 +0900
    24.2 +++ b/xen/arch/x86/hvm/vpic.c	Mon Mar 02 18:26:56 2009 +0900
    24.3 @@ -56,7 +56,7 @@ static int vpic_get_priority(struct hvm_
    24.4  
    24.5      /* prio = ffs(mask ROR vpic->priority_add); */
    24.6      asm ( "ror %%cl,%b1 ; bsf %1,%0"
    24.7 -          : "=r" (prio) : "r" ((uint32_t)mask), "c" (vpic->priority_add) );
    24.8 +          : "=r" (prio) : "q" ((uint32_t)mask), "c" (vpic->priority_add) );
    24.9      return prio;
   24.10  }
   24.11  
    25.1 --- a/xen/arch/x86/hvm/vpt.c	Mon Mar 02 16:52:22 2009 +0900
    25.2 +++ b/xen/arch/x86/hvm/vpt.c	Mon Mar 02 18:26:56 2009 +0900
    25.3 @@ -384,13 +384,25 @@ void create_periodic_time(
    25.4      pt->period_cycles = (u64)period;
    25.5      pt->one_shot = !period;
    25.6      pt->scheduled = NOW() + delta;
    25.7 -    /*
    25.8 -     * Offset LAPIC ticks from other timer ticks. Otherwise guests which use
    25.9 -     * LAPIC ticks for process accounting can see long sequences of process
   25.10 -     * ticks incorrectly accounted to interrupt processing.
   25.11 -     */
   25.12 -    if ( !pt->one_shot && (pt->source == PTSRC_lapic) )
   25.13 -        pt->scheduled += delta >> 1;
   25.14 +
   25.15 +    if ( !pt->one_shot )
   25.16 +    {
   25.17 +        if ( v->domain->arch.hvm_domain.params[HVM_PARAM_VPT_ALIGN] )
   25.18 +        {
   25.19 +            pt->scheduled = align_timer(pt->scheduled, pt->period);
   25.20 +        }
   25.21 +        else if ( pt->source == PTSRC_lapic )
   25.22 +        {
   25.23 +            /*
   25.24 +             * Offset LAPIC ticks from other timer ticks. Otherwise guests
   25.25 +             * which use LAPIC ticks for process accounting can see long
   25.26 +             * sequences of process ticks incorrectly accounted to interrupt
   25.27 +             * processing (seen with RHEL3 guest).
   25.28 +             */
   25.29 +            pt->scheduled += delta >> 1;
   25.30 +        }
   25.31 +    }
   25.32 +
   25.33      pt->cb = cb;
   25.34      pt->priv = data;
   25.35  
    26.1 --- a/xen/arch/x86/io_apic.c	Mon Mar 02 16:52:22 2009 +0900
    26.2 +++ b/xen/arch/x86/io_apic.c	Mon Mar 02 18:26:56 2009 +0900
    26.3 @@ -1779,6 +1779,20 @@ static inline void check_timer(void)
    26.4   */
    26.5  #define PIC_IRQS	(1 << PIC_CASCADE_IR)
    26.6  
    26.7 +static struct IO_APIC_route_entry *ioapic_pm_state;
    26.8 +
    26.9 +void ioapic_pm_state_alloc(void)
   26.10 +{
   26.11 +    int i, nr_entry = 0;
   26.12 +
   26.13 +    for (i = 0; i < nr_ioapics; i++)
   26.14 +        nr_entry += nr_ioapic_registers[i];
   26.15 +
   26.16 +    ioapic_pm_state = _xmalloc(sizeof(struct IO_APIC_route_entry)*nr_entry,
   26.17 +                               sizeof(struct IO_APIC_route_entry));
   26.18 +    BUG_ON(ioapic_pm_state == NULL);
   26.19 +}
   26.20 +
   26.21  void __init setup_IO_APIC(void)
   26.22  {
   26.23      enable_IO_APIC();
   26.24 @@ -1801,40 +1815,16 @@ void __init setup_IO_APIC(void)
   26.25      init_IO_APIC_traps();
   26.26      check_timer();
   26.27      print_IO_APIC();
   26.28 +    ioapic_pm_state_alloc();
   26.29  
   26.30      register_keyhandler('z', print_IO_APIC_keyhandler, "print ioapic info");
   26.31  }
   26.32  
   26.33 -struct IO_APIC_route_entry *ioapic_pm_state=NULL;
   26.34 -
   26.35 -void ioapic_pm_state_alloc(void)
   26.36 +void ioapic_suspend(void)
   26.37  {
   26.38 -    int i, nr_entry = 0;
   26.39 -
   26.40 -    if (ioapic_pm_state != NULL)
   26.41 -        return;
   26.42 -
   26.43 -    for (i = 0; i < nr_ioapics; i++)
   26.44 -        nr_entry += nr_ioapic_registers[i];
   26.45 -
   26.46 -    ioapic_pm_state = _xmalloc(sizeof(struct IO_APIC_route_entry)*nr_entry,
   26.47 -                               sizeof(struct IO_APIC_route_entry));
   26.48 -}
   26.49 -
   26.50 -int ioapic_suspend(void)
   26.51 -{
   26.52 -    struct IO_APIC_route_entry *entry;
   26.53 +    struct IO_APIC_route_entry *entry = ioapic_pm_state;
   26.54      unsigned long flags;
   26.55 -    int apic,i;
   26.56 -
   26.57 -    ioapic_pm_state_alloc();
   26.58 -
   26.59 -    if (ioapic_pm_state == NULL) {
   26.60 -        printk("Cannot suspend ioapic due to lack of memory\n");
   26.61 -        return 1;
   26.62 -    }
   26.63 -
   26.64 -    entry = ioapic_pm_state;
   26.65 +    int apic, i;
   26.66  
   26.67      spin_lock_irqsave(&ioapic_lock, flags);
   26.68      for (apic = 0; apic < nr_ioapics; apic++) {
   26.69 @@ -1844,23 +1834,14 @@ int ioapic_suspend(void)
   26.70          }
   26.71      }
   26.72      spin_unlock_irqrestore(&ioapic_lock, flags);
   26.73 -
   26.74 -    return 0;
   26.75  }
   26.76  
   26.77 -int ioapic_resume(void)
   26.78 +void ioapic_resume(void)
   26.79  {
   26.80 -    struct IO_APIC_route_entry *entry;
   26.81 +    struct IO_APIC_route_entry *entry = ioapic_pm_state;
   26.82      unsigned long flags;
   26.83      union IO_APIC_reg_00 reg_00;
   26.84 -    int i,apic;
   26.85 -    
   26.86 -    if (ioapic_pm_state == NULL){
   26.87 -        printk("Cannot resume ioapic due to lack of memory\n");
   26.88 -        return 1;
   26.89 -    }
   26.90 -    
   26.91 -    entry = ioapic_pm_state;
   26.92 +    int i, apic;
   26.93  
   26.94      spin_lock_irqsave(&ioapic_lock, flags);
   26.95      for (apic = 0; apic < nr_ioapics; apic++){
   26.96 @@ -1875,8 +1856,6 @@ int ioapic_resume(void)
   26.97          }
   26.98      }
   26.99      spin_unlock_irqrestore(&ioapic_lock, flags);
  26.100 -
  26.101 -    return 0;
  26.102  }
  26.103  
  26.104  /* --------------------------------------------------------------------------
    27.1 --- a/xen/arch/x86/irq.c	Mon Mar 02 16:52:22 2009 +0900
    27.2 +++ b/xen/arch/x86/irq.c	Mon Mar 02 18:26:56 2009 +0900
    27.3 @@ -1142,6 +1142,8 @@ void fixup_irqs(cpumask_t map)
    27.4      static int warned;
    27.5      irq_guest_action_t *action;
    27.6      struct pending_eoi *peoi;
    27.7 +    irq_desc_t         *desc;
    27.8 +    unsigned long       flags;
    27.9  
   27.10      /* Direct all future interrupts away from this CPU. */
   27.11      for ( vector = 0; vector < NR_VECTORS; vector++ )
   27.12 @@ -1150,18 +1152,24 @@ void fixup_irqs(cpumask_t map)
   27.13          if ( vector_to_irq(vector) == 2 )
   27.14              continue;
   27.15  
   27.16 -        cpus_and(mask, irq_desc[vector].affinity, map);
   27.17 +        desc = &irq_desc[vector];
   27.18 +
   27.19 +        spin_lock_irqsave(&desc->lock, flags);
   27.20 +
   27.21 +        cpus_and(mask, desc->affinity, map);
   27.22          if ( any_online_cpu(mask) == NR_CPUS )
   27.23          {
   27.24              printk("Breaking affinity for vector %u (irq %i)\n",
   27.25                     vector, vector_to_irq(vector));
   27.26              mask = map;
   27.27          }
   27.28 -        if ( irq_desc[vector].handler->set_affinity )
   27.29 -            irq_desc[vector].handler->set_affinity(vector, mask);
   27.30 -        else if ( irq_desc[vector].action && !(warned++) )
   27.31 -            printk("Cannot set affinity for irq %u (irq %i)\n",
   27.32 +        if ( desc->handler->set_affinity )
   27.33 +            desc->handler->set_affinity(vector, mask);
   27.34 +        else if ( desc->action && !(warned++) )
   27.35 +            printk("Cannot set affinity for vector %u (irq %i)\n",
   27.36                     vector, vector_to_irq(vector));
   27.37 +
   27.38 +        spin_unlock_irqrestore(&desc->lock, flags);
   27.39      }
   27.40  
   27.41      /* Service any interrupts that beat us in the re-direction race. */
    28.1 --- a/xen/arch/x86/mm/shadow/multi.c	Mon Mar 02 16:52:22 2009 +0900
    28.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Mon Mar 02 18:26:56 2009 +0900
    28.3 @@ -546,15 +546,32 @@ static always_inline void
    28.4           !is_xen_heap_mfn(mfn_x(target_mfn)) )
    28.5      {
    28.6          unsigned int type;
    28.7 +
    28.8 +        /* compute the PAT index for shadow page entry when VT-d is enabled
    28.9 +         * and device assigned. 
   28.10 +         * 1) direct MMIO: compute the PAT index with gMTRR=UC and gPAT.
   28.11 +         * 2) if enables snoop control, compute the PAT index as WB.
   28.12 +         * 3) if disables snoop control, compute the PAT index with
   28.13 +         *    gMTRR and gPAT.
   28.14 +         */
   28.15          if ( hvm_get_mem_pinned_cacheattr(d, gfn_x(target_gfn), &type) )
   28.16              sflags |= pat_type_2_pte_flags(type);
   28.17          else if ( d->arch.hvm_domain.is_in_uc_mode )
   28.18              sflags |= pat_type_2_pte_flags(PAT_TYPE_UNCACHABLE);
   28.19 +        else if ( p2mt == p2m_mmio_direct )
   28.20 +            sflags |= get_pat_flags(v,
   28.21 +                                    gflags,
   28.22 +                                    gfn_to_paddr(target_gfn),
   28.23 +                                    ((paddr_t)mfn_x(target_mfn)) << PAGE_SHIFT,
   28.24 +                                    MTRR_TYPE_UNCACHABLE); 
   28.25 +        else if ( iommu_snoop )
   28.26 +            sflags |= pat_type_2_pte_flags(PAT_TYPE_WRBACK);
   28.27          else
   28.28              sflags |= get_pat_flags(v,
   28.29                                      gflags,
   28.30                                      gfn_to_paddr(target_gfn),
   28.31 -                                    ((paddr_t)mfn_x(target_mfn)) << PAGE_SHIFT);
   28.32 +                                    ((paddr_t)mfn_x(target_mfn)) << PAGE_SHIFT,
   28.33 +                                    NO_HARDCODE_MEM_TYPE);
   28.34      }
   28.35  
   28.36      // Set the A&D bits for higher level shadows.
    29.1 --- a/xen/arch/x86/msi.c	Mon Mar 02 16:52:22 2009 +0900
    29.2 +++ b/xen/arch/x86/msi.c	Mon Mar 02 18:26:56 2009 +0900
    29.3 @@ -29,17 +29,17 @@
    29.4  
    29.5  /* bitmap indicate which fixed map is free */
    29.6  DEFINE_SPINLOCK(msix_fixmap_lock);
    29.7 -DECLARE_BITMAP(msix_fixmap_pages, MAX_MSIX_PAGES);
    29.8 +DECLARE_BITMAP(msix_fixmap_pages, FIX_MSIX_MAX_PAGES);
    29.9  
   29.10  static int msix_fixmap_alloc(void)
   29.11  {
   29.12 -    int i, rc = -1;
   29.13 +    int i, rc = -ENOMEM;
   29.14  
   29.15      spin_lock(&msix_fixmap_lock);
   29.16 -    for ( i = 0; i < MAX_MSIX_PAGES; i++ )
   29.17 +    for ( i = 0; i < FIX_MSIX_MAX_PAGES; i++ )
   29.18          if ( !test_bit(i, &msix_fixmap_pages) )
   29.19              break;
   29.20 -    if ( i == MAX_MSIX_PAGES )
   29.21 +    if ( i == FIX_MSIX_MAX_PAGES )
   29.22          goto out;
   29.23      rc = FIX_MSIX_IO_RESERV_BASE + i;
   29.24      set_bit(i, &msix_fixmap_pages);
   29.25 @@ -51,8 +51,66 @@ static int msix_fixmap_alloc(void)
   29.26  
   29.27  static void msix_fixmap_free(int idx)
   29.28  {
   29.29 +    spin_lock(&msix_fixmap_lock);
   29.30      if ( idx >= FIX_MSIX_IO_RESERV_BASE )
   29.31          clear_bit(idx - FIX_MSIX_IO_RESERV_BASE, &msix_fixmap_pages);
   29.32 +    spin_unlock(&msix_fixmap_lock);
   29.33 +}
   29.34 +
   29.35 +static int msix_get_fixmap(struct pci_dev *dev, unsigned long table_paddr,
   29.36 +                           unsigned long entry_paddr)
   29.37 +{
   29.38 +    int nr_page, idx;
   29.39 +
   29.40 +    nr_page = (entry_paddr >> PAGE_SHIFT) - (table_paddr >> PAGE_SHIFT);
   29.41 +
   29.42 +    if ( nr_page < 0 || nr_page >= MAX_MSIX_TABLE_PAGES )
   29.43 +        return -EINVAL;
   29.44 +
   29.45 +    spin_lock(&dev->msix_table_lock);
   29.46 +    if ( dev->msix_table_refcnt[nr_page]++ == 0 )
   29.47 +    {
   29.48 +        idx = msix_fixmap_alloc();
   29.49 +        if ( idx < 0 )
   29.50 +        {
   29.51 +            dev->msix_table_refcnt[nr_page]--;
   29.52 +            goto out;
   29.53 +        }
   29.54 +        set_fixmap_nocache(idx, entry_paddr);
   29.55 +        dev->msix_table_idx[nr_page] = idx;
   29.56 +    }
   29.57 +    else
   29.58 +        idx = dev->msix_table_idx[nr_page];
   29.59 +
   29.60 + out:
   29.61 +    spin_unlock(&dev->msix_table_lock);
   29.62 +    return idx;
   29.63 +}
   29.64 +
   29.65 +static void msix_put_fixmap(struct pci_dev *dev, int idx)
   29.66 +{
   29.67 +    int i;
   29.68 +    unsigned long start;
   29.69 +
   29.70 +    spin_lock(&dev->msix_table_lock);
   29.71 +    for ( i = 0; i < MAX_MSIX_TABLE_PAGES; i++ )
   29.72 +    {
   29.73 +        if ( dev->msix_table_idx[i] == idx )
   29.74 +            break;
   29.75 +    }
   29.76 +    if ( i == MAX_MSIX_TABLE_PAGES )
   29.77 +        goto out;
   29.78 +
   29.79 +    if ( --dev->msix_table_refcnt[i] == 0 )
   29.80 +    {
   29.81 +        start = fix_to_virt(idx);
   29.82 +        destroy_xen_mappings(start, start + PAGE_SIZE);
   29.83 +        msix_fixmap_free(idx);
   29.84 +        dev->msix_table_idx[i] = 0;
   29.85 +    }
   29.86 +
   29.87 + out:
   29.88 +    spin_unlock(&dev->msix_table_lock);
   29.89  }
   29.90  
   29.91  /*
   29.92 @@ -122,8 +180,7 @@ static void read_msi_msg(struct msi_desc
   29.93      case PCI_CAP_ID_MSIX:
   29.94      {
   29.95          void __iomem *base;
   29.96 -        base = entry->mask_base +
   29.97 -            entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
   29.98 +        base = entry->mask_base;
   29.99  
  29.100          msg->address_lo = readl(base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
  29.101          msg->address_hi = readl(base + PCI_MSIX_ENTRY_UPPER_ADDR_OFFSET);
  29.102 @@ -199,8 +256,7 @@ static void write_msi_msg(struct msi_des
  29.103      case PCI_CAP_ID_MSIX:
  29.104      {
  29.105          void __iomem *base;
  29.106 -        base = entry->mask_base +
  29.107 -            entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE;
  29.108 +        base = entry->mask_base;
  29.109  
  29.110          writel(msg->address_lo,
  29.111                 base + PCI_MSIX_ENTRY_LOWER_ADDR_OFFSET);
  29.112 @@ -288,8 +344,7 @@ static void msix_flush_writes(unsigned i
  29.113          break;
  29.114      case PCI_CAP_ID_MSIX:
  29.115      {
  29.116 -        int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
  29.117 -            PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
  29.118 +        int offset = PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
  29.119          readl(entry->mask_base + offset);
  29.120          break;
  29.121      }
  29.122 @@ -330,8 +385,7 @@ static void msi_set_mask_bit(unsigned in
  29.123          break;
  29.124      case PCI_CAP_ID_MSIX:
  29.125      {
  29.126 -        int offset = entry->msi_attrib.entry_nr * PCI_MSIX_ENTRY_SIZE +
  29.127 -            PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
  29.128 +        int offset = PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET;
  29.129          writel(flag, entry->mask_base + offset);
  29.130          readl(entry->mask_base + offset);
  29.131          break;
  29.132 @@ -392,13 +446,10 @@ int msi_free_vector(struct msi_desc *ent
  29.133      {
  29.134          unsigned long start;
  29.135  
  29.136 -        writel(1, entry->mask_base + entry->msi_attrib.entry_nr
  29.137 -               * PCI_MSIX_ENTRY_SIZE
  29.138 -               + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.139 +        writel(1, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.140  
  29.141          start = (unsigned long)entry->mask_base & ~(PAGE_SIZE - 1);
  29.142 -        msix_fixmap_free(virt_to_fix(start));
  29.143 -        destroy_xen_mappings(start, start + PAGE_SIZE);
  29.144 +        msix_put_fixmap(entry->dev, virt_to_fix(start));
  29.145      }
  29.146      list_del(&entry->list);
  29.147      xfree(entry);
  29.148 @@ -500,8 +551,8 @@ static int msix_capability_init(struct p
  29.149      struct msi_desc *entry;
  29.150      int pos;
  29.151      u16 control;
  29.152 -    unsigned long phys_addr;
  29.153 -    u32 table_offset;
  29.154 +    unsigned long table_paddr, entry_paddr;
  29.155 +    u32 table_offset, entry_offset;
  29.156      u8 bir;
  29.157      void __iomem *base;
  29.158      int idx;
  29.159 @@ -525,15 +576,17 @@ static int msix_capability_init(struct p
  29.160      table_offset = pci_conf_read32(bus, slot, func, msix_table_offset_reg(pos));
  29.161      bir = (u8)(table_offset & PCI_MSIX_FLAGS_BIRMASK);
  29.162      table_offset &= ~PCI_MSIX_FLAGS_BIRMASK;
  29.163 -    phys_addr = msi->table_base + table_offset;
  29.164 -    idx = msix_fixmap_alloc();
  29.165 +    entry_offset = msi->entry_nr * PCI_MSIX_ENTRY_SIZE;
  29.166 +
  29.167 +    table_paddr = msi->table_base + table_offset;
  29.168 +    entry_paddr = table_paddr + entry_offset;
  29.169 +    idx = msix_get_fixmap(dev, table_paddr, entry_paddr);
  29.170      if ( idx < 0 )
  29.171      {
  29.172          xfree(entry);
  29.173 -        return -ENOMEM;
  29.174 +        return idx;
  29.175      }
  29.176 -    set_fixmap_nocache(idx, phys_addr);
  29.177 -    base = (void *)(fix_to_virt(idx) + (phys_addr & ((1UL << PAGE_SHIFT) - 1)));
  29.178 +    base = (void *)(fix_to_virt(idx) + (entry_paddr & ((1UL << PAGE_SHIFT) - 1)));
  29.179  
  29.180      entry->msi_attrib.type = PCI_CAP_ID_MSIX;
  29.181      entry->msi_attrib.is_64 = 1;
  29.182 @@ -548,9 +601,7 @@ static int msix_capability_init(struct p
  29.183      list_add_tail(&entry->list, &dev->msi_list);
  29.184  
  29.185      /* Mask interrupt here */
  29.186 -    writel(1, entry->mask_base + entry->msi_attrib.entry_nr
  29.187 -                * PCI_MSIX_ENTRY_SIZE
  29.188 -                + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.189 +    writel(1, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.190  
  29.191      *desc = entry;
  29.192      /* Restore MSI-X enabled bits */
  29.193 @@ -675,9 +726,7 @@ static void __pci_disable_msix(struct ms
  29.194  
  29.195      BUG_ON(list_empty(&dev->msi_list));
  29.196  
  29.197 -    writel(1, entry->mask_base + entry->msi_attrib.entry_nr
  29.198 -      * PCI_MSIX_ENTRY_SIZE
  29.199 -      + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.200 +    writel(1, entry->mask_base + PCI_MSIX_ENTRY_VECTOR_CTRL_OFFSET);
  29.201  
  29.202      pci_conf_write16(bus, slot, func, msix_control_reg(pos), control);
  29.203  }
    30.1 --- a/xen/arch/x86/shutdown.c	Mon Mar 02 16:52:22 2009 +0900
    30.2 +++ b/xen/arch/x86/shutdown.c	Mon Mar 02 18:26:56 2009 +0900
    30.3 @@ -302,6 +302,7 @@ void machine_restart(unsigned int delay_
    30.4  
    30.5      watchdog_disable();
    30.6      console_start_sync();
    30.7 +    spin_debug_disable();
    30.8  
    30.9      local_irq_enable();
   30.10  
    31.1 --- a/xen/arch/x86/time.c	Mon Mar 02 16:52:22 2009 +0900
    31.2 +++ b/xen/arch/x86/time.c	Mon Mar 02 18:26:56 2009 +0900
    31.3 @@ -607,13 +607,14 @@ static void platform_time_calibration(vo
    31.4  {
    31.5      u64 count;
    31.6      s_time_t stamp;
    31.7 +    unsigned long flags;
    31.8  
    31.9 -    spin_lock_irq(&platform_timer_lock);
   31.10 +    spin_lock_irqsave(&platform_timer_lock, flags);
   31.11      count = plt_stamp64 + ((plt_src.read_counter() - plt_stamp) & plt_mask);
   31.12      stamp = __read_platform_stime(count);
   31.13      stime_platform_stamp = stamp;
   31.14      platform_timer_stamp = count;
   31.15 -    spin_unlock_irq(&platform_timer_lock);
   31.16 +    spin_unlock_irqrestore(&platform_timer_lock, flags);
   31.17  }
   31.18  
   31.19  static void resume_platform_timer(void)
    32.1 --- a/xen/common/timer.c	Mon Mar 02 16:52:22 2009 +0900
    32.2 +++ b/xen/common/timer.c	Mon Mar 02 18:26:56 2009 +0900
    32.3 @@ -473,6 +473,13 @@ void process_pending_timers(void)
    32.4          timer_softirq_action();
    32.5  }
    32.6  
    32.7 +s_time_t align_timer(s_time_t firsttick, uint64_t period)
    32.8 +{
    32.9 +    if ( !period )
   32.10 +        return firsttick;
   32.11 +
   32.12 +    return firsttick + (period - 1) - ((firsttick - 1) % period);
   32.13 +}
   32.14  
   32.15  static void dump_timerq(unsigned char key)
   32.16  {
    33.1 --- a/xen/drivers/passthrough/amd/iommu_init.c	Mon Mar 02 16:52:22 2009 +0900
    33.2 +++ b/xen/drivers/passthrough/amd/iommu_init.c	Mon Mar 02 18:26:56 2009 +0900
    33.3 @@ -37,9 +37,6 @@ struct ivrs_mappings *ivrs_mappings;
    33.4  struct list_head amd_iommu_head;
    33.5  struct table_struct device_table;
    33.6  
    33.7 -extern void *int_remap_table;
    33.8 -extern spinlock_t int_remap_table_lock;
    33.9 -
   33.10  static int __init map_iommu_mmio_region(struct amd_iommu *iommu)
   33.11  {
   33.12      unsigned long mfn;
   33.13 @@ -487,11 +484,13 @@ static int set_iommu_interrupt_handler(s
   33.14      }
   33.15  
   33.16      irq_desc[vector].handler = &iommu_msi_type;
   33.17 +    vector_to_iommu[vector] = iommu;
   33.18      ret = request_irq_vector(vector, amd_iommu_page_fault, 0,
   33.19                               "amd_iommu", iommu);
   33.20      if ( ret )
   33.21      {
   33.22          irq_desc[vector].handler = &no_irq_type;
   33.23 +        vector_to_iommu[vector] = NULL;
   33.24          free_irq_vector(vector);
   33.25          amd_iov_error("can't request irq\n");
   33.26          return 0;
   33.27 @@ -499,7 +498,6 @@ static int set_iommu_interrupt_handler(s
   33.28  
   33.29      /* Make sure that vector is never re-used. */
   33.30      vector_irq[vector] = NEVER_ASSIGN_IRQ;
   33.31 -    vector_to_iommu[vector] = iommu;
   33.32      iommu->vector = vector;
   33.33      return vector;
   33.34  }
    34.1 --- a/xen/drivers/passthrough/amd/iommu_intr.c	Mon Mar 02 16:52:22 2009 +0900
    34.2 +++ b/xen/drivers/passthrough/amd/iommu_intr.c	Mon Mar 02 18:26:56 2009 +0900
    34.3 @@ -23,7 +23,7 @@
    34.4  #include <asm/hvm/svm/amd-iommu-proto.h>
    34.5  
    34.6  #define INTREMAP_TABLE_ORDER    1
    34.7 -DEFINE_SPINLOCK(int_remap_table_lock);
    34.8 +static DEFINE_SPINLOCK(int_remap_table_lock);
    34.9  void *int_remap_table = NULL;
   34.10  
   34.11  static u8 *get_intremap_entry(u8 vector, u8 dm)
   34.12 @@ -110,21 +110,13 @@ static void update_intremap_entry_from_i
   34.13  
   34.14  int __init amd_iommu_setup_intremap_table(void)
   34.15  {
   34.16 -    unsigned long flags;
   34.17 -
   34.18 -    spin_lock_irqsave(&int_remap_table_lock, flags);
   34.19 -
   34.20      if ( int_remap_table == NULL )
   34.21      {
   34.22          int_remap_table = __alloc_amd_iommu_tables(INTREMAP_TABLE_ORDER);
   34.23          if ( int_remap_table == NULL )
   34.24 -        {
   34.25 -            spin_unlock_irqrestore(&int_remap_table_lock, flags);
   34.26              return -ENOMEM;
   34.27 -        }
   34.28          memset(int_remap_table, 0, PAGE_SIZE * (1UL << INTREMAP_TABLE_ORDER));
   34.29      }
   34.30 -    spin_unlock_irqrestore(&int_remap_table_lock, flags);
   34.31  
   34.32      return 0;
   34.33  }
   34.34 @@ -210,15 +202,11 @@ void amd_iommu_msi_msg_update_ire(
   34.35  
   34.36  int __init deallocate_intremap_table(void)
   34.37  {
   34.38 -    unsigned long flags;
   34.39 -
   34.40 -    spin_lock_irqsave(&int_remap_table_lock, flags);
   34.41      if ( int_remap_table )
   34.42      {
   34.43          __free_amd_iommu_tables(int_remap_table, INTREMAP_TABLE_ORDER);
   34.44          int_remap_table = NULL;
   34.45      }
   34.46 -    spin_unlock_irqrestore(&int_remap_table_lock, flags);
   34.47  
   34.48      return 0;
   34.49  }
    35.1 --- a/xen/drivers/passthrough/amd/iommu_map.c	Mon Mar 02 16:52:22 2009 +0900
    35.2 +++ b/xen/drivers/passthrough/amd/iommu_map.c	Mon Mar 02 18:26:56 2009 +0900
    35.3 @@ -446,14 +446,13 @@ static u64 iommu_l2e_from_pfn(struct pag
    35.4  int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn)
    35.5  {
    35.6      u64 iommu_l2e;
    35.7 -    unsigned long flags;
    35.8      struct hvm_iommu *hd = domain_hvm_iommu(d);
    35.9      int iw = IOMMU_IO_WRITE_ENABLED;
   35.10      int ir = IOMMU_IO_READ_ENABLED;
   35.11  
   35.12      BUG_ON( !hd->root_table );
   35.13  
   35.14 -    spin_lock_irqsave(&hd->mapping_lock, flags);
   35.15 +    spin_lock(&hd->mapping_lock);
   35.16  
   35.17      if ( is_hvm_domain(d) && !hd->p2m_synchronized )
   35.18          goto out;
   35.19 @@ -461,14 +460,14 @@ int amd_iommu_map_page(struct domain *d,
   35.20      iommu_l2e = iommu_l2e_from_pfn(hd->root_table, hd->paging_mode, gfn);
   35.21      if ( iommu_l2e == 0 )
   35.22      {
   35.23 -        spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.24 +        spin_unlock(&hd->mapping_lock);
   35.25          amd_iov_error("Invalid IO pagetable entry gfn = %lx\n", gfn);
   35.26          return -EFAULT;
   35.27      }
   35.28      set_iommu_l1e_present(iommu_l2e, gfn, (u64)mfn << PAGE_SHIFT, iw, ir);
   35.29  
   35.30  out:
   35.31 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.32 +    spin_unlock(&hd->mapping_lock);
   35.33      return 0;
   35.34  }
   35.35  
   35.36 @@ -481,11 +480,11 @@ int amd_iommu_unmap_page(struct domain *
   35.37  
   35.38      BUG_ON( !hd->root_table );
   35.39  
   35.40 -    spin_lock_irqsave(&hd->mapping_lock, flags);
   35.41 +    spin_lock(&hd->mapping_lock);
   35.42  
   35.43      if ( is_hvm_domain(d) && !hd->p2m_synchronized )
   35.44      {
   35.45 -        spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.46 +        spin_unlock(&hd->mapping_lock);
   35.47          return 0;
   35.48      }
   35.49  
   35.50 @@ -493,14 +492,14 @@ int amd_iommu_unmap_page(struct domain *
   35.51  
   35.52      if ( iommu_l2e == 0 )
   35.53      {
   35.54 -        spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.55 +        spin_unlock(&hd->mapping_lock);
   35.56          amd_iov_error("Invalid IO pagetable entry gfn = %lx\n", gfn);
   35.57          return -EFAULT;
   35.58      }
   35.59  
   35.60      /* mark PTE as 'page not present' */
   35.61      clear_iommu_l1e_present(iommu_l2e, gfn);
   35.62 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.63 +    spin_unlock(&hd->mapping_lock);
   35.64  
   35.65      /* send INVALIDATE_IOMMU_PAGES command */
   35.66      for_each_amd_iommu ( iommu )
   35.67 @@ -520,12 +519,12 @@ int amd_iommu_reserve_domain_unity_map(
   35.68      unsigned long size, int iw, int ir)
   35.69  {
   35.70      u64 iommu_l2e;
   35.71 -    unsigned long flags, npages, i;
   35.72 +    unsigned long npages, i;
   35.73      struct hvm_iommu *hd = domain_hvm_iommu(domain);
   35.74  
   35.75      npages = region_to_pages(phys_addr, size);
   35.76  
   35.77 -    spin_lock_irqsave(&hd->mapping_lock, flags);
   35.78 +    spin_lock(&hd->mapping_lock);
   35.79      for ( i = 0; i < npages; ++i )
   35.80      {
   35.81          iommu_l2e = iommu_l2e_from_pfn(
   35.82 @@ -533,7 +532,7 @@ int amd_iommu_reserve_domain_unity_map(
   35.83  
   35.84          if ( iommu_l2e == 0 )
   35.85          {
   35.86 -            spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.87 +            spin_unlock(&hd->mapping_lock);
   35.88              amd_iov_error("Invalid IO pagetable entry phys_addr = %lx\n",
   35.89                            phys_addr);
   35.90              return -EFAULT;
   35.91 @@ -544,13 +543,13 @@ int amd_iommu_reserve_domain_unity_map(
   35.92  
   35.93          phys_addr += PAGE_SIZE;
   35.94      }
   35.95 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
   35.96 +    spin_unlock(&hd->mapping_lock);
   35.97      return 0;
   35.98  }
   35.99  
  35.100  int amd_iommu_sync_p2m(struct domain *d)
  35.101  {
  35.102 -    unsigned long mfn, gfn, flags;
  35.103 +    unsigned long mfn, gfn;
  35.104      u64 iommu_l2e;
  35.105      struct page_info *page;
  35.106      struct hvm_iommu *hd;
  35.107 @@ -562,7 +561,7 @@ int amd_iommu_sync_p2m(struct domain *d)
  35.108  
  35.109      hd = domain_hvm_iommu(d);
  35.110  
  35.111 -    spin_lock_irqsave(&hd->mapping_lock, flags);
  35.112 +    spin_lock(&hd->mapping_lock);
  35.113  
  35.114      if ( hd->p2m_synchronized )
  35.115          goto out;
  35.116 @@ -582,7 +581,7 @@ int amd_iommu_sync_p2m(struct domain *d)
  35.117          if ( iommu_l2e == 0 )
  35.118          {
  35.119              spin_unlock(&d->page_alloc_lock);
  35.120 -            spin_unlock_irqrestore(&hd->mapping_lock, flags);
  35.121 +            spin_unlock(&hd->mapping_lock);
  35.122              amd_iov_error("Invalid IO pagetable entry gfn = %lx\n", gfn);
  35.123              return -EFAULT;
  35.124          }
  35.125 @@ -595,7 +594,7 @@ int amd_iommu_sync_p2m(struct domain *d)
  35.126      hd->p2m_synchronized = 1;
  35.127  
  35.128  out:
  35.129 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
  35.130 +    spin_unlock(&hd->mapping_lock);
  35.131      return 0;
  35.132  }
  35.133  
    36.1 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c	Mon Mar 02 16:52:22 2009 +0900
    36.2 +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c	Mon Mar 02 18:26:56 2009 +0900
    36.3 @@ -172,22 +172,18 @@ int amd_iov_detect(void)
    36.4  static int allocate_domain_resources(struct hvm_iommu *hd)
    36.5  {
    36.6      /* allocate root table */
    36.7 -    unsigned long flags;
    36.8 -
    36.9 -    spin_lock_irqsave(&hd->mapping_lock, flags);
   36.10 +    spin_lock(&hd->mapping_lock);
   36.11      if ( !hd->root_table )
   36.12      {
   36.13          hd->root_table = alloc_amd_iommu_pgtable();
   36.14          if ( !hd->root_table )
   36.15 -            goto error_out;
   36.16 +        {
   36.17 +            spin_unlock(&hd->mapping_lock);
   36.18 +            return -ENOMEM;
   36.19 +        }
   36.20      }
   36.21 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
   36.22 -
   36.23 +    spin_unlock(&hd->mapping_lock);
   36.24      return 0;
   36.25 -
   36.26 - error_out:
   36.27 -    spin_unlock_irqrestore(&hd->mapping_lock, flags);
   36.28 -    return -ENOMEM;
   36.29  }
   36.30  
   36.31  static int get_paging_mode(unsigned long entries)
   36.32 @@ -298,7 +294,6 @@ static int reassign_device( struct domai
   36.33                   bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
   36.34                   source->domain_id, target->domain_id);
   36.35  
   36.36 -    spin_unlock(&pcidevs_lock);
   36.37      return 0;
   36.38  }
   36.39  
   36.40 @@ -352,11 +347,13 @@ static void deallocate_iommu_page_tables
   36.41  {
   36.42      struct hvm_iommu *hd  = domain_hvm_iommu(d);
   36.43  
   36.44 +    spin_lock(&hd->mapping_lock);
   36.45      if ( hd->root_table )
   36.46      {
   36.47          deallocate_next_page_table(hd->root_table, hd->paging_mode);
   36.48          hd->root_table = NULL;
   36.49      }
   36.50 +    spin_unlock(&hd->mapping_lock);
   36.51  }
   36.52  
   36.53  
    37.1 --- a/xen/drivers/passthrough/pci.c	Mon Mar 02 16:52:22 2009 +0900
    37.2 +++ b/xen/drivers/passthrough/pci.c	Mon Mar 02 18:26:56 2009 +0900
    37.3 @@ -48,6 +48,7 @@ struct pci_dev *alloc_pdev(u8 bus, u8 de
    37.4      pdev->domain = NULL;
    37.5      INIT_LIST_HEAD(&pdev->msi_list);
    37.6      list_add(&pdev->alldevs_list, &alldevs_list);
    37.7 +    spin_lock_init(&pdev->msix_table_lock);
    37.8  
    37.9      return pdev;
   37.10  }
    38.1 --- a/xen/drivers/passthrough/vtd/ia64/vtd.c	Mon Mar 02 16:52:22 2009 +0900
    38.2 +++ b/xen/drivers/passthrough/vtd/ia64/vtd.c	Mon Mar 02 18:26:56 2009 +0900
    38.3 @@ -114,3 +114,34 @@ void hvm_dpci_isairq_eoi(struct domain *
    38.4  {
    38.5      /* dummy */
    38.6  }
    38.7 +
    38.8 +static int do_dom0_iommu_mapping(unsigned long start, unsigned long end,
    38.9 +				void *arg)
   38.10 +{
   38.11 +    unsigned long tmp, pfn, j, page_addr = start;
   38.12 +    struct domain *d = (struct domain *)arg;
   38.13 +
   38.14 +    extern int xen_in_range(paddr_t start, paddr_t end);
   38.15 +    /* Set up 1:1 page table for dom0 for all Ram except Xen bits.*/
   38.16 +
   38.17 +    while (page_addr < end)
   38.18 +    {
   38.19 +	if (xen_in_range(page_addr, page_addr + PAGE_SIZE))
   38.20 +            continue;
   38.21 +
   38.22 +        pfn = page_addr >> PAGE_SHIFT;
   38.23 +        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
   38.24 +        for ( j = 0; j < tmp; j++ )
   38.25 +            iommu_map_page(d, (pfn*tmp+j), (pfn*tmp+j));
   38.26 +
   38.27 +	page_addr += PAGE_SIZE;
   38.28 +    }
   38.29 +    return 0;
   38.30 +}
   38.31 +
   38.32 +void iommu_set_dom0_mapping(struct domain *d)
   38.33 +{
   38.34 +	if (dom0)
   38.35 +	    BUG_ON(d != dom0);
   38.36 +	efi_memmap_walk(do_dom0_iommu_mapping, d);
   38.37 +}
    39.1 --- a/xen/drivers/passthrough/vtd/iommu.c	Mon Mar 02 16:52:22 2009 +0900
    39.2 +++ b/xen/drivers/passthrough/vtd/iommu.c	Mon Mar 02 18:26:56 2009 +0900
    39.3 @@ -30,6 +30,7 @@
    39.4  #include <xen/pci.h>
    39.5  #include <xen/pci_regs.h>
    39.6  #include <xen/keyhandler.h>
    39.7 +#include <asm/msi.h>
    39.8  #include "iommu.h"
    39.9  #include "dmar.h"
   39.10  #include "extern.h"
   39.11 @@ -40,6 +41,7 @@
   39.12  static spinlock_t domid_bitmap_lock;    /* protect domain id bitmap */
   39.13  static int domid_bitmap_size;           /* domain id bitmap size in bits */
   39.14  static unsigned long *domid_bitmap;     /* iommu domain id bitmap */
   39.15 +static bool_t rwbf_quirk;
   39.16  
   39.17  static void setup_dom0_devices(struct domain *d);
   39.18  static void setup_dom0_rmrr(struct domain *d);
   39.19 @@ -230,7 +232,7 @@ static void iommu_flush_write_buffer(str
   39.20      unsigned long flag;
   39.21      s_time_t start_time;
   39.22  
   39.23 -    if ( !cap_rwbf(iommu->cap) )
   39.24 +    if ( !rwbf_quirk && !cap_rwbf(iommu->cap) )
   39.25          return;
   39.26      val = iommu->gcmd | DMA_GCMD_WBF;
   39.27  
   39.28 @@ -829,7 +831,6 @@ static void dma_msi_data_init(struct iom
   39.29      spin_unlock_irqrestore(&iommu->register_lock, flags);
   39.30  }
   39.31  
   39.32 -#ifdef SUPPORT_MSI_REMAPPING
   39.33  static void dma_msi_addr_init(struct iommu *iommu, int phy_cpu)
   39.34  {
   39.35      u64 msi_address;
   39.36 @@ -846,12 +847,6 @@ static void dma_msi_addr_init(struct iom
   39.37      dmar_writel(iommu->reg, DMAR_FEUADDR_REG, (u32)(msi_address >> 32));
   39.38      spin_unlock_irqrestore(&iommu->register_lock, flags);
   39.39  }
   39.40 -#else
   39.41 -static void dma_msi_addr_init(struct iommu *iommu, int phy_cpu)
   39.42 -{
   39.43 -    /* ia64: TODO */
   39.44 -}
   39.45 -#endif
   39.46  
   39.47  static void dma_msi_set_affinity(unsigned int vector, cpumask_t dest)
   39.48  {
   39.49 @@ -870,7 +865,7 @@ static struct hw_interrupt_type dma_msi_
   39.50      .set_affinity = dma_msi_set_affinity,
   39.51  };
   39.52  
   39.53 -int iommu_set_interrupt(struct iommu *iommu)
   39.54 +static int iommu_set_interrupt(struct iommu *iommu)
   39.55  {
   39.56      int vector, ret;
   39.57  
   39.58 @@ -882,10 +877,12 @@ int iommu_set_interrupt(struct iommu *io
   39.59      }
   39.60  
   39.61      irq_desc[vector].handler = &dma_msi_type;
   39.62 +    vector_to_iommu[vector] = iommu;
   39.63      ret = request_irq_vector(vector, iommu_page_fault, 0, "dmar", iommu);
   39.64      if ( ret )
   39.65      {
   39.66          irq_desc[vector].handler = &no_irq_type;
   39.67 +        vector_to_iommu[vector] = NULL;
   39.68          free_irq_vector(vector);
   39.69          gdprintk(XENLOG_ERR VTDPREFIX, "IOMMU: can't request irq\n");
   39.70          return ret;
   39.71 @@ -893,7 +890,6 @@ int iommu_set_interrupt(struct iommu *io
   39.72  
   39.73      /* Make sure that vector is never re-used. */
   39.74      vector_irq[vector] = NEVER_ASSIGN_IRQ;
   39.75 -    vector_to_iommu[vector] = iommu;
   39.76  
   39.77      return vector;
   39.78  }
   39.79 @@ -987,7 +983,6 @@ static int intel_iommu_domain_init(struc
   39.80  {
   39.81      struct hvm_iommu *hd = domain_hvm_iommu(d);
   39.82      struct iommu *iommu = NULL;
   39.83 -    u64 i, j, tmp;
   39.84      struct acpi_drhd_unit *drhd;
   39.85  
   39.86      drhd = list_entry(acpi_drhd_units.next, typeof(*drhd), list);
   39.87 @@ -999,17 +994,8 @@ static int intel_iommu_domain_init(struc
   39.88      {
   39.89          extern int xen_in_range(paddr_t start, paddr_t end);
   39.90  
   39.91 -        /* Set up 1:1 page table for dom0 for all RAM except Xen bits. */
   39.92 -        for ( i = 0; i < max_page; i++ )
   39.93 -        {
   39.94 -            if ( !page_is_conventional_ram(i) ||
   39.95 -                 xen_in_range(i << PAGE_SHIFT, (i + 1) << PAGE_SHIFT) )
   39.96 -                continue;
   39.97 -
   39.98 -            tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
   39.99 -            for ( j = 0; j < tmp; j++ )
  39.100 -                iommu_map_page(d, (i*tmp+j), (i*tmp+j));
  39.101 -        }
  39.102 +        /* Set up 1:1 page table for dom0 */
  39.103 +        iommu_set_dom0_mapping(d);
  39.104  
  39.105          setup_dom0_devices(d);
  39.106          setup_dom0_rmrr(d);
  39.107 @@ -1734,6 +1720,19 @@ static void setup_dom0_rmrr(struct domai
  39.108      spin_unlock(&pcidevs_lock);
  39.109  }
  39.110  
  39.111 +static void platform_quirks(void)
  39.112 +{
  39.113 +    u32 id;
  39.114 +
  39.115 +    /* Mobile 4 Series Chipset neglects to set RWBF capability. */
  39.116 +    id = pci_conf_read32(0, 0, 0, 0);
  39.117 +    if ( id == 0x2a408086 )
  39.118 +    {
  39.119 +        dprintk(XENLOG_INFO VTDPREFIX, "DMAR: Forcing write-buffer flush\n");
  39.120 +        rwbf_quirk = 1;
  39.121 +    }
  39.122 +}
  39.123 +
  39.124  int intel_vtd_setup(void)
  39.125  {
  39.126      struct acpi_drhd_unit *drhd;
  39.127 @@ -1742,6 +1741,8 @@ int intel_vtd_setup(void)
  39.128      if ( !vtd_enabled )
  39.129          return -ENODEV;
  39.130  
  39.131 +    platform_quirks();
  39.132 +
  39.133      spin_lock_init(&domid_bitmap_lock);
  39.134      clflush_size = get_cache_line_size();
  39.135  
    40.1 --- a/xen/drivers/passthrough/vtd/iommu.h	Mon Mar 02 16:52:22 2009 +0900
    40.2 +++ b/xen/drivers/passthrough/vtd/iommu.h	Mon Mar 02 18:26:56 2009 +0900
    40.3 @@ -397,8 +397,8 @@ struct poll_info {
    40.4      u32 udata;
    40.5  };
    40.6  
    40.7 -#define MAX_QINVAL_PAGES 8
    40.8  #define NUM_QINVAL_PAGES 1
    40.9 +#define IQA_REG_QS       0    // derived from NUM_QINVAL_PAGES per VT-d spec.
   40.10  #define QINVAL_ENTRY_NR (PAGE_SIZE_4K*NUM_QINVAL_PAGES/sizeof(struct qinval_entry))
   40.11  #define qinval_present(v) ((v).lo & 1)
   40.12  #define qinval_fault_disable(v) (((v).lo >> 1) & 1)
    41.1 --- a/xen/drivers/passthrough/vtd/qinval.c	Mon Mar 02 16:52:22 2009 +0900
    41.2 +++ b/xen/drivers/passthrough/vtd/qinval.c	Mon Mar 02 18:26:56 2009 +0900
    41.3 @@ -317,9 +317,9 @@ int queue_invalidate_iec(struct iommu *i
    41.4      return ret;
    41.5  }
    41.6  
    41.7 -u64 iec_cap;
    41.8  int __iommu_flush_iec(struct iommu *iommu, u8 granu, u8 im, u16 iidx)
    41.9  {
   41.10 +    u64 iec_cap;
   41.11      int ret;
   41.12      ret = queue_invalidate_iec(iommu, granu, im, iidx);
   41.13      ret |= invalidate_sync(iommu);
   41.14 @@ -445,8 +445,7 @@ int qinval_setup(struct iommu *iommu)
   41.15       * registers are automatically reset to 0 with write
   41.16       * to IQA register.
   41.17       */
   41.18 -    if ( NUM_QINVAL_PAGES <= MAX_QINVAL_PAGES )
   41.19 -        qi_ctrl->qinval_maddr |= NUM_QINVAL_PAGES - 1;
   41.20 +    qi_ctrl->qinval_maddr |= IQA_REG_QS;
   41.21      dmar_writeq(iommu->reg, DMAR_IQA_REG, qi_ctrl->qinval_maddr);
   41.22  
   41.23      /* enable queued invalidation hardware */
    42.1 --- a/xen/drivers/passthrough/vtd/x86/vtd.c	Mon Mar 02 16:52:22 2009 +0900
    42.2 +++ b/xen/drivers/passthrough/vtd/x86/vtd.c	Mon Mar 02 18:26:56 2009 +0900
    42.3 @@ -143,3 +143,23 @@ void hvm_dpci_isairq_eoi(struct domain *
    42.4      }
    42.5      spin_unlock(&d->event_lock);
    42.6  }
    42.7 +
    42.8 +void iommu_set_dom0_mapping(struct domain *d)
    42.9 +{
   42.10 +    u64 i, j, tmp;
   42.11 +    extern int xen_in_range(paddr_t start, paddr_t end);
   42.12 +
   42.13 +    BUG_ON(d->domain_id != 0);
   42.14 +
   42.15 +    for ( i = 0; i < max_page; i++ )
   42.16 +    {
   42.17 +        /* Set up 1:1 mapping for dom0 for all RAM except Xen bits. */
   42.18 +        if ( !page_is_conventional_ram(i) ||
   42.19 +             xen_in_range(i << PAGE_SHIFT, (i + 1) << PAGE_SHIFT) )
   42.20 +            continue;
   42.21 +
   42.22 +        tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);
   42.23 +        for ( j = 0; j < tmp; j++ )
   42.24 +            iommu_map_page(d, (i*tmp+j), (i*tmp+j));
   42.25 +    }
   42.26 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/xen/include/asm-ia64/msi.h	Mon Mar 02 18:26:56 2009 +0900
    44.3 @@ -0,0 +1,20 @@
    44.4 +#ifndef __ASM_MSI_H
    44.5 +#define __ASM_MSI_H
    44.6 +
    44.7 +/*
    44.8 + * MSI Defined Data Structures
    44.9 + */
   44.10 +#define MSI_ADDRESS_HEADER		0xfee
   44.11 +#define MSI_ADDRESS_HEADER_SHIFT	12
   44.12 +#define MSI_ADDRESS_HEADER_MASK		0xfff000
   44.13 +#define MSI_ADDRESS_DEST_ID_MASK	0xfff0000f
   44.14 +#define MSI_TARGET_CPU_MASK		0xff
   44.15 +#define MSI_TARGET_CPU_SHIFT		4
   44.16 +#define MSI_DELIVERY_MODE		0
   44.17 +#define MSI_LEVEL_MODE			1	/* Edge always assert */
   44.18 +#define MSI_TRIGGER_MODE		0	/* MSI is edge sensitive */
   44.19 +#define MSI_PHYSICAL_MODE		0
   44.20 +#define MSI_LOGICAL_MODE		1
   44.21 +#define MSI_REDIRECTION_HINT_MODE	0
   44.22 +
   44.23 +#endif /* __ASM_MSI_H */
    45.1 --- a/xen/include/asm-x86/fixmap.h	Mon Mar 02 16:52:22 2009 +0900
    45.2 +++ b/xen/include/asm-x86/fixmap.h	Mon Mar 02 18:26:56 2009 +0900
    45.3 @@ -50,7 +50,7 @@ enum fixed_addresses {
    45.4      FIX_IOMMU_MMIO_END = FIX_IOMMU_MMIO_BASE_0 + IOMMU_PAGES -1,
    45.5      FIX_TBOOT_SHARED_BASE,
    45.6      FIX_MSIX_IO_RESERV_BASE,
    45.7 -    FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + MAX_MSIX_PAGES -1,
    45.8 +    FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGES -1,
    45.9      __end_of_fixed_addresses
   45.10  };
   45.11  
    46.1 --- a/xen/include/asm-x86/io_apic.h	Mon Mar 02 16:52:22 2009 +0900
    46.2 +++ b/xen/include/asm-x86/io_apic.h	Mon Mar 02 18:26:56 2009 +0900
    46.3 @@ -182,13 +182,13 @@ extern int timer_uses_ioapic_pin_0;
    46.4  #endif /*CONFIG_ACPI_BOOT*/
    46.5  
    46.6  extern int (*ioapic_renumber_irq)(int ioapic, int irq);
    46.7 -extern int ioapic_suspend(void);
    46.8 -extern int ioapic_resume(void);
    46.9 +extern void ioapic_suspend(void);
   46.10 +extern void ioapic_resume(void);
   46.11  
   46.12  #else  /* !CONFIG_X86_IO_APIC */
   46.13  #define io_apic_assign_pci_irqs 0
   46.14 -static inline int ioapic_suspend(void) {return 0};
   46.15 -static inline int ioapic_resume(void) {return 0};
   46.16 +static inline void ioapic_suspend(void) {}
   46.17 +static inline void ioapic_resume(void) {}
   46.18  #endif
   46.19  
   46.20  extern int assign_irq_vector(int irq);
    47.1 --- a/xen/include/asm-x86/msi.h	Mon Mar 02 16:52:22 2009 +0900
    47.2 +++ b/xen/include/asm-x86/msi.h	Mon Mar 02 18:26:56 2009 +0900
    47.3 @@ -49,9 +49,9 @@
    47.4  
    47.5  /* MAX fixed pages reserved for mapping MSIX tables. */
    47.6  #if defined(__x86_64__)
    47.7 -#define MAX_MSIX_PAGES              512
    47.8 +#define FIX_MSIX_MAX_PAGES              512
    47.9  #else
   47.10 -#define MAX_MSIX_PAGES              32
   47.11 +#define FIX_MSIX_MAX_PAGES              32
   47.12  #endif
   47.13  
   47.14  struct msi_info {
   47.15 @@ -93,7 +93,7 @@ struct msi_desc {
   47.16  
   47.17  	struct list_head list;
   47.18  
   47.19 -	void __iomem *mask_base;
   47.20 +	void __iomem *mask_base;        /* va for the entry in mask table */
   47.21  	struct pci_dev *dev;
   47.22  	int vector;
   47.23  
    48.1 --- a/xen/include/asm-x86/mtrr.h	Mon Mar 02 16:52:22 2009 +0900
    48.2 +++ b/xen/include/asm-x86/mtrr.h	Mon Mar 02 18:26:56 2009 +0900
    48.3 @@ -11,6 +11,7 @@
    48.4  #define MTRR_TYPE_WRBACK     6
    48.5  #define MTRR_NUM_TYPES       7
    48.6  #define MEMORY_NUM_TYPES     MTRR_NUM_TYPES
    48.7 +#define NO_HARDCODE_MEM_TYPE    MTRR_NUM_TYPES
    48.8  
    48.9  #define NORMAL_CACHE_MODE          0
   48.10  #define NO_FILL_CACHE_MODE         2
   48.11 @@ -63,7 +64,7 @@ extern int mtrr_del(int reg, unsigned lo
   48.12  extern int mtrr_del_page(int reg, unsigned long base, unsigned long size);
   48.13  extern void mtrr_centaur_report_mcr(int mcr, u32 lo, u32 hi);
   48.14  extern u32 get_pat_flags(struct vcpu *v, u32 gl1e_flags, paddr_t gpaddr,
   48.15 -                  paddr_t spaddr);
   48.16 +                  paddr_t spaddr, uint8_t gmtrr_mtype);
   48.17  extern uint8_t epte_get_entry_emt(
   48.18      struct domain *d, unsigned long gfn, unsigned long mfn,
   48.19      uint8_t *igmt, int direct_mmio);
    49.1 --- a/xen/include/public/hvm/params.h	Mon Mar 02 16:52:22 2009 +0900
    49.2 +++ b/xen/include/public/hvm/params.h	Mon Mar 02 18:26:56 2009 +0900
    49.3 @@ -103,6 +103,9 @@
    49.4  /* TSS used on Intel when CR0.PE=0. */
    49.5  #define HVM_PARAM_VM86_TSS     15
    49.6  
    49.7 -#define HVM_NR_PARAMS          16
    49.8 +/* Boolean: Enable aligning all periodic vpts to reduce interrupts */
    49.9 +#define HVM_PARAM_VPT_ALIGN    16
   49.10 +
   49.11 +#define HVM_NR_PARAMS          17
   49.12  
   49.13  #endif /* __XEN_PUBLIC_HVM_PARAMS_H__ */
    50.1 --- a/xen/include/xen/iommu.h	Mon Mar 02 16:52:22 2009 +0900
    50.2 +++ b/xen/include/xen/iommu.h	Mon Mar 02 18:26:56 2009 +0900
    50.3 @@ -114,4 +114,6 @@ void iommu_update_ire_from_msi(struct ms
    50.4  void iommu_suspend(void);
    50.5  void iommu_resume(void);
    50.6  
    50.7 +void iommu_set_dom0_mapping(struct domain *d);
    50.8 +
    50.9  #endif /* _IOMMU_H_ */
    51.1 --- a/xen/include/xen/pci.h	Mon Mar 02 16:52:22 2009 +0900
    51.2 +++ b/xen/include/xen/pci.h	Mon Mar 02 18:26:56 2009 +0900
    51.3 @@ -29,10 +29,16 @@
    51.4  #define PCI_BDF(b,d,f)  ((((b) & 0xff) << 8) | PCI_DEVFN(d,f))
    51.5  #define PCI_BDF2(b,df)  ((((b) & 0xff) << 8) | ((df) & 0xff))
    51.6  
    51.7 +#define MAX_MSIX_TABLE_PAGES    8    /* 2048 entries */
    51.8  struct pci_dev {
    51.9      struct list_head alldevs_list;
   51.10      struct list_head domain_list;
   51.11 +
   51.12      struct list_head msi_list;
   51.13 +    int msix_table_refcnt[MAX_MSIX_TABLE_PAGES];
   51.14 +    int msix_table_idx[MAX_MSIX_TABLE_PAGES];
   51.15 +    spinlock_t msix_table_lock;
   51.16 +
   51.17      struct domain *domain;
   51.18      const u8 bus;
   51.19      const u8 devfn;
    52.1 --- a/xen/include/xen/timer.h	Mon Mar 02 16:52:22 2009 +0900
    52.2 +++ b/xen/include/xen/timer.h	Mon Mar 02 18:26:56 2009 +0900
    52.3 @@ -122,6 +122,9 @@ DECLARE_PER_CPU(s_time_t, timer_deadline
    52.4  /* Arch-defined function to reprogram timer hardware for new deadline. */
    52.5  extern int reprogram_timer(s_time_t timeout);
    52.6  
    52.7 +/* calculate the aligned first tick time for a given periodic timer */ 
    52.8 +extern s_time_t align_timer(s_time_t firsttick, uint64_t period);
    52.9 +
   52.10  #endif /* _TIMER_H_ */
   52.11  
   52.12  /*
    53.1 --- a/xen/xsm/flask/ss/policydb.c	Mon Mar 02 16:52:22 2009 +0900
    53.2 +++ b/xen/xsm/flask/ss/policydb.c	Mon Mar 02 18:26:56 2009 +0900
    53.3 @@ -1515,8 +1515,8 @@ int policydb_read(struct policydb *p, vo
    53.4      if ( len != strlen(POLICYDB_STRING) )
    53.5      {
    53.6          printk(KERN_ERR "security:  policydb string length %d does not "
    53.7 -               "match expected length %Zu\n",
    53.8 -               len, (u32) strlen(POLICYDB_STRING));
    53.9 +               "match expected length %lu\n",
   53.10 +               len, strlen(POLICYDB_STRING));
   53.11          goto bad;
   53.12      }
   53.13      policydb_str = xmalloc_array(char, len + 1);