Xen 
 
Home About Xen.org Xen Xen Summit Wiki Mailing List Bug Tracker Xen Downloads
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] merge with xen-unstable.hg
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 30 Aug 2006 22:11:03 +0000
Delivery-date: Wed, 30 Aug 2006 15:17:16 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User awilliam@xxxxxxxxxxx
# Node ID 684fdcfb251a443fa885c142b427d253ec033212
# Parent  896fcdd49c7ff59f7d28b6402fd4453e60c38232
# Parent  f790546ecfda03193a4b8983f7bb6b0f65924603
merge with xen-unstable.hg
---
 xen/arch/x86/shadow2-common.c                      | 3407 ---------------
 xen/arch/x86/shadow2.c                             | 4492 ---------------------
 xen/include/asm-x86/page-guest32.h                 |  105 
 xen/include/asm-x86/shadow2-multi.h                |  116 
 xen/include/asm-x86/shadow2-private.h              |  593 --
 xen/include/asm-x86/shadow2-types.h                |  692 ---
 xen/include/asm-x86/shadow2.h                      |  626 --
 docs/man/xend-config.sxp.pod.5                     |    2 
 docs/misc/xend.tex                                 |    4 
 docs/src/user.tex                                  |    4 
 tools/Makefile                                     |    1 
 tools/console/daemon/io.c                          |   18 
 tools/examples/vif-route                           |    6 
 tools/examples/xen-hotplug-common.sh               |    2 
 tools/examples/xen-network-common.sh               |   40 
 tools/examples/xend-config.sxp                     |    2 
 tools/firmware/hvmloader/smbios.c                  |   12 
 tools/firmware/hvmloader/util.c                    |   54 
 tools/firmware/hvmloader/util.h                    |   10 
 tools/ioemu/Makefile                               |    2 
 tools/ioemu/patches/qemu-logging                   |    1 
 tools/ioemu/patches/xen-build                      |   14 
 tools/ioemu/vl.c                                   |    2 
 tools/libxc/xc_hvm_build.c                         |    2 
 tools/misc/xend                                    |    2 
 tools/python/xen/util/bugtool.py                   |    4 
 tools/python/xen/xend/XendRoot.py                  |    2 
 tools/python/xen/xend/server/params.py             |    4 
 tools/security/python/xensec_gen/main.py           |    2 
 unmodified_drivers/linux-2.6/platform-pci/evtchn.c |    2 
 xen/arch/x86/Makefile                              |   21 
 xen/arch/x86/domain.c                              |   46 
 xen/arch/x86/domain_build.c                        |    8 
 xen/arch/x86/domctl.c                              |    2 
 xen/arch/x86/hvm/hvm.c                             |    6 
 xen/arch/x86/hvm/platform.c                        |    4 
 xen/arch/x86/hvm/svm/svm.c                         |  183 
 xen/arch/x86/hvm/svm/vmcb.c                        |    2 
 xen/arch/x86/hvm/vmx/vmcs.c                        |    4 
 xen/arch/x86/hvm/vmx/vmx.c                         |   20 
 xen/arch/x86/mm.c                                  |  142 
 xen/arch/x86/mm/Makefile                           |    1 
 xen/arch/x86/mm/shadow/Makefile                    |   15 
 xen/arch/x86/mm/shadow/common.c                    | 3407 +++++++++++++++
 xen/arch/x86/mm/shadow/multi.c                     | 4492 +++++++++++++++++++++
 xen/arch/x86/mm/shadow/multi.h                     |  116 
 xen/arch/x86/mm/shadow/page-guest32.h              |  105 
 xen/arch/x86/mm/shadow/private.h                   |  593 ++
 xen/arch/x86/mm/shadow/types.h                     |  692 +++
 xen/arch/x86/traps.c                               |    8 
 xen/include/asm-x86/domain.h                       |   18 
 xen/include/asm-x86/hvm/svm/vmcb.h                 |   45 
 xen/include/asm-x86/mm.h                           |   82 
 xen/include/asm-x86/perfc_defn.h                   |  102 
 xen/include/asm-x86/shadow.h                       |  614 ++
 55 files changed, 10488 insertions(+), 10463 deletions(-)

diff -r 896fcdd49c7f -r 684fdcfb251a docs/man/xend-config.sxp.pod.5
--- a/docs/man/xend-config.sxp.pod.5    Mon Aug 28 16:16:07 2006 -0600
+++ b/docs/man/xend-config.sxp.pod.5    Mon Aug 28 16:26:37 2006 -0600
@@ -23,7 +23,7 @@ The following lists the daemon configura
 =item I<logfile>
 
 The location of the file to record runtime log messages.  Defaults to
-I</var/log/xend.log>.
+I</var/log/xen/xend.log>.
 
 =item I<loglevel>
 
diff -r 896fcdd49c7f -r 684fdcfb251a docs/misc/xend.tex
--- a/docs/misc/xend.tex        Mon Aug 28 16:16:07 2006 -0600
+++ b/docs/misc/xend.tex        Mon Aug 28 16:26:37 2006 -0600
@@ -214,7 +214,7 @@ Configuration scripts ({\it e.g.} for ne
 Configuration scripts ({\it e.g.} for network-script) are looked for in {\tt 
/etc/xen}
 unless their name begins with '/'.
 
-Xend sends its log output to {\tt /var/log/xend.log}. This is a rotating 
logfile,
+Xend sends its log output to {\tt /var/log/xen/xend.log}. This is a rotating 
logfile,
 and logs are moved onto {\tt xend.log.1} {\it etc.} as they get large. Old 
logs may
 be deleted.
 
@@ -411,7 +411,7 @@ allows access to some debugging function
 \end{itemize}
 
 When tracing is on xend logs all functions calls and exceptions to
-{\tt /var/log/xend.trace}.
+{\tt /var/log/xen/xend.trace}.
 
 \begin{thebibliography}{99}
 
diff -r 896fcdd49c7f -r 684fdcfb251a docs/src/user.tex
--- a/docs/src/user.tex Mon Aug 28 16:16:07 2006 -0600
+++ b/docs/src/user.tex Mon Aug 28 16:26:37 2006 -0600
@@ -973,8 +973,8 @@ using the \texttt{xm} tool.
 
 \subsection{Logging}
 
-As \xend\ runs, events will be logged to \path{/var/log/xend.log} and
-(less frequently) to \path{/var/log/xend-debug.log}. These, along with
+As \xend\ runs, events will be logged to \path{/var/log/xen/xend.log} and
+(less frequently) to \path{/var/log/xen/xend-debug.log}. These, along with
 the standard syslog files, are useful when troubleshooting problems.
 
 \subsection{Configuring \Xend\ }
diff -r 896fcdd49c7f -r 684fdcfb251a tools/Makefile
--- a/tools/Makefile    Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/Makefile    Mon Aug 28 16:26:37 2006 -0600
@@ -39,6 +39,7 @@ install: check
        done
        $(MAKE) ioemuinstall
        $(INSTALL_DIR) -p $(DESTDIR)/var/xen/dump
+       $(INSTALL_DIR) -p $(DESTDIR)/var/log/xen
 
 .PHONY: clean
 clean: check_clean
diff -r 896fcdd49c7f -r 684fdcfb251a tools/console/daemon/io.c
--- a/tools/console/daemon/io.c Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/console/daemon/io.c Mon Aug 28 16:26:37 2006 -0600
@@ -584,16 +584,14 @@ void handle_io(void)
                            FD_ISSET(xc_evtchn_fd(d->xce_handle), &readfds))
                                handle_ring_read(d);
 
-                       if (d->tty_fd != -1) {
-                               if (FD_ISSET(d->tty_fd, &readfds))
-                                       handle_tty_read(d);
-
-                               if (FD_ISSET(d->tty_fd, &writefds))
-                                       handle_tty_write(d);
-
-                               if (d->is_dead)
-                                       cleanup_domain(d);
-                       }
+                       if (d->tty_fd != -1 && FD_ISSET(d->tty_fd, &readfds))
+                               handle_tty_read(d);
+
+                       if (d->tty_fd != -1 && FD_ISSET(d->tty_fd, &writefds))
+                               handle_tty_write(d);
+
+                       if (d->is_dead)
+                               cleanup_domain(d);
                }
        } while (ret > -1);
 }
diff -r 896fcdd49c7f -r 684fdcfb251a tools/examples/vif-route
--- a/tools/examples/vif-route  Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/examples/vif-route  Mon Aug 28 16:26:37 2006 -0600
@@ -30,10 +30,12 @@ case "$command" in
         ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up
         echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
         ipcmd='add'
+        cmdprefix=''
         ;;
     offline)
-        ifdown ${vif}
+        do_without_error ifdown ${vif}
         ipcmd='del'
+        cmdprefix='do_without_error'
         ;;
 esac
 
@@ -41,7 +43,7 @@ if [ "${ip}" ] ; then
     # If we've been given a list of IP addresses, then add routes from dom0 to
     # the guest using those addresses.
     for addr in ${ip} ; do
-      ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
+      ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
     done 
 fi
 
diff -r 896fcdd49c7f -r 684fdcfb251a tools/examples/xen-hotplug-common.sh
--- a/tools/examples/xen-hotplug-common.sh      Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/examples/xen-hotplug-common.sh      Mon Aug 28 16:26:37 2006 -0600
@@ -21,7 +21,7 @@ dir=$(dirname "$0")
 . "$dir/xen-script-common.sh"
 . "$dir/locking.sh"
 
-exec 2>>/var/log/xen-hotplug.log
+exec 2>>/var/log/xen/xen-hotplug.log
 
 export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
 export LANG="POSIX"
diff -r 896fcdd49c7f -r 684fdcfb251a tools/examples/xen-network-common.sh
--- a/tools/examples/xen-network-common.sh      Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/examples/xen-network-common.sh      Mon Aug 28 16:26:37 2006 -0600
@@ -44,34 +44,18 @@ then
   }
 elif ! which ifup >/dev/null 2>/dev/null
 then
-  if [ -e /etc/conf.d/net ]
-  then
-    preiftransfer()
-    {
-      true
-    }
-    ifup()
-    {
-      /etc/init.d/net.$1 start
-    }
-    ifdown()
-    {
-      /etc/init.d/net.$1 stop
-    }
-  else
-    preiftransfer()
-    {
-      true
-    }
-    ifup()
-    {
-      false
-    }
-    ifdown()
-    {
-      false
-    }
-  fi
+  preiftransfer()
+  {
+    true
+  }
+  ifup()
+  {
+    false
+  }
+  ifdown()
+  {
+    false
+  }
 else
   preiftransfer()
   {
diff -r 896fcdd49c7f -r 684fdcfb251a tools/examples/xend-config.sxp
--- a/tools/examples/xend-config.sxp    Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/examples/xend-config.sxp    Mon Aug 28 16:26:37 2006 -0600
@@ -11,7 +11,7 @@
 # Commented out entries show the default for that entry, unless otherwise
 # specified.
 
-#(logfile /var/log/xend.log)
+#(logfile /var/log/xen/xend.log)
 #(loglevel DEBUG)
 
 #(xend-http-server no)
diff -r 896fcdd49c7f -r 684fdcfb251a tools/firmware/hvmloader/smbios.c
--- a/tools/firmware/hvmloader/smbios.c Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/firmware/hvmloader/smbios.c Mon Aug 28 16:26:37 2006 -0600
@@ -116,8 +116,10 @@ smbios_table_size(uint32_t vcpus, const 
 
        /* type 0: "Xen", xen_version, and release_date */
        size += strlen("Xen") + strlen(xen_version) + 2;
-       /* type 1: "Xen", xen_version, "HVM domU" */
-       size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) + 3;
+       /* type 1: "Xen", xen_version, "HVM domU", UUID as string for 
+                   serial number */
+       size += strlen("Xen") + strlen("HVM domU") + strlen(xen_version) +
+                       36 + 4;
        /* type 3: "Xen" */
        size += strlen("Xen") + 1;
        /* type 4: socket designation ("CPU n"), processor_manufacturer */
@@ -371,6 +373,7 @@ smbios_type_1_init(void *start, const ch
 smbios_type_1_init(void *start, const char *xen_version, 
                   uint8_t uuid[16])
 {
+       char uuid_str[37];
        struct smbios_type_1 *p = (struct smbios_type_1 *)start;
        p->header.type = 1;
        p->header.length = sizeof(struct smbios_type_1);
@@ -379,7 +382,7 @@ smbios_type_1_init(void *start, const ch
        p->manufacturer_str = 1;
        p->product_name_str = 2;
        p->version_str = 3;
-       p->serial_number_str = 0;
+       p->serial_number_str = 4;
     
        memcpy(p->uuid, uuid, 16);
 
@@ -395,6 +398,9 @@ smbios_type_1_init(void *start, const ch
        start += strlen("HVM domU") + 1;
        strcpy((char *)start, xen_version);
        start += strlen(xen_version) + 1;
+       uuid_to_string(uuid_str, uuid); 
+       strcpy((char *)start, uuid_str);
+       start += strlen(uuid_str) + 1;
        *((uint8_t *)start) = 0;
     
        return start+1; 
diff -r 896fcdd49c7f -r 684fdcfb251a tools/firmware/hvmloader/util.c
--- a/tools/firmware/hvmloader/util.c   Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/firmware/hvmloader/util.c   Mon Aug 28 16:26:37 2006 -0600
@@ -174,3 +174,57 @@ cpuid(uint32_t idx, uint32_t *eax, uint3
                : "0" (idx) );
 }
 
+/* Write a two-character hex representation of 'byte' to digits[].
+   Pre-condition: sizeof(digits) >= 2 */
+void
+byte_to_hex(char *digits, uint8_t byte)
+{
+       uint8_t nybbel = byte >> 4;
+
+       if (nybbel > 9)
+               digits[0] = 'a' + nybbel-10;
+       else
+               digits[0] = '0' + nybbel;
+
+       nybbel = byte & 0x0f;
+       if (nybbel > 9)
+               digits[1] = 'a' + nybbel-10;
+       else
+               digits[1] = '0' + nybbel;
+}
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+   string.
+
+   Pre-condition: sizeof(dest) >= 37 */
+void
+uuid_to_string(char *dest, uint8_t *uuid)
+{
+       int i = 0;
+       char *p = dest;
+
+       for (i = 0; i < 4; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 4; i < 6; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 6; i < 8; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 8; i < 10; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+       *p++ = '-';
+       for (i = 10; i < 16; ++i) {
+               byte_to_hex(p, uuid[i]);
+               p += 2;
+       }
+}
diff -r 896fcdd49c7f -r 684fdcfb251a tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h   Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/firmware/hvmloader/util.h   Mon Aug 28 16:26:37 2006 -0600
@@ -25,6 +25,16 @@ void *memset(void *s, int c, unsigned n)
 void *memset(void *s, int c, unsigned n);
 char *itoa(char *a, unsigned int i);
 
+/* convert a byte to two lowercase hex digits, with no terminating NUL 
+   character.  digits[] must have at least two elements. */
+void byte_to_hex(char *digits, uint8_t byte);
+
+/* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
+   string.
+
+   Pre-condition: sizeof(dest) >= 37 */
+void uuid_to_string(char *dest, uint8_t *uuid);
+
 /* Debug output */
 void puts(const char *s);
 
diff -r 896fcdd49c7f -r 684fdcfb251a tools/ioemu/Makefile
--- a/tools/ioemu/Makefile      Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/ioemu/Makefile      Mon Aug 28 16:26:37 2006 -0600
@@ -94,7 +94,7 @@ test speed test2: all
        $(MAKE) -C tests $@
 
 TAGS: 
-       etags *.[ch] tests/*.[ch]
+       etags *.[ch] target-i386-dm/*.[ch] hw/*.[ch]
 
 cscope:
        rm -f ./cscope.*
diff -r 896fcdd49c7f -r 684fdcfb251a tools/ioemu/patches/qemu-logging
--- a/tools/ioemu/patches/qemu-logging  Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/ioemu/patches/qemu-logging  Mon Aug 28 16:26:37 2006 -0600
@@ -43,7 +43,7 @@ Index: ioemu/vl.c
      /* default mac address of the first network interface */
      
 +    /* init debug */
-+    sprintf(qemu_dm_logfilename, "/var/log/qemu-dm.%d.log", getpid());
++    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
 +    cpu_set_log_filename(qemu_dm_logfilename);
 +    cpu_set_log(0);
 +    
diff -r 896fcdd49c7f -r 684fdcfb251a tools/ioemu/patches/xen-build
--- a/tools/ioemu/patches/xen-build     Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/ioemu/patches/xen-build     Mon Aug 28 16:26:37 2006 -0600
@@ -1,7 +1,7 @@ Index: ioemu/Makefile
 Index: ioemu/Makefile
 ===================================================================
---- ioemu.orig/Makefile        2006-08-06 02:03:44.915543858 +0100
-+++ ioemu/Makefile     2006-08-06 02:11:33.461331417 +0100
+--- ioemu.orig/Makefile        2006-08-28 20:19:23.000000000 +0100
++++ ioemu/Makefile     2006-08-28 20:20:08.000000000 +0100
 @@ -1,11 +1,14 @@
  # Makefile for QEMU.
  
@@ -60,6 +60,15 @@ Index: ioemu/Makefile
  ifndef CONFIG_WIN32
        mkdir -p "$(DESTDIR)$(datadir)/keymaps"
        for x in $(KEYMAPS); do \
+@@ -89,7 +94,7 @@
+       $(MAKE) -C tests $@
+ 
+ TAGS: 
+-      etags *.[ch] tests/*.[ch]
++      etags *.[ch] target-i386-dm/*.[ch] hw/*.[ch]
+ 
+ cscope:
+       rm -f ./cscope.*
 @@ -107,11 +112,11 @@
        texi2dvi $<
  
@@ -76,8 +85,8 @@ Index: ioemu/Makefile
  info: qemu-doc.info qemu-tech.info
 Index: ioemu/Makefile.target
 ===================================================================
---- ioemu.orig/Makefile.target 2006-08-06 02:03:44.922543079 +0100
-+++ ioemu/Makefile.target      2006-08-06 02:09:22.320951557 +0100
+--- ioemu.orig/Makefile.target 2006-08-28 20:19:23.000000000 +0100
++++ ioemu/Makefile.target      2006-08-28 20:19:47.000000000 +0100
 @@ -1,5 +1,8 @@
  include config.mak
  
@@ -149,8 +158,8 @@ Index: ioemu/Makefile.target
  include .depend
 Index: ioemu/configure
 ===================================================================
---- ioemu.orig/configure       2006-08-06 02:03:45.783447220 +0100
-+++ ioemu/configure    2006-08-06 02:09:41.076860544 +0100
+--- ioemu.orig/configure       2006-08-28 20:19:23.000000000 +0100
++++ ioemu/configure    2006-08-28 20:19:47.000000000 +0100
 @@ -18,8 +18,8 @@
  
  # default parameters
diff -r 896fcdd49c7f -r 684fdcfb251a tools/ioemu/vl.c
--- a/tools/ioemu/vl.c  Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/ioemu/vl.c  Mon Aug 28 16:26:37 2006 -0600
@@ -5924,7 +5924,7 @@ int main(int argc, char **argv)
     /* default mac address of the first network interface */
     
     /* init debug */
-    sprintf(qemu_dm_logfilename, "/var/log/qemu-dm.%d.log", getpid());
+    sprintf(qemu_dm_logfilename, "/var/log/xen/qemu-dm.%d.log", getpid());
     cpu_set_log_filename(qemu_dm_logfilename);
     cpu_set_log(0);
     
diff -r 896fcdd49c7f -r 684fdcfb251a tools/libxc/xc_hvm_build.c
--- a/tools/libxc/xc_hvm_build.c        Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/libxc/xc_hvm_build.c        Mon Aug 28 16:26:37 2006 -0600
@@ -441,7 +441,7 @@ static int xc_hvm_build_internal(int xc_
         goto error_out;
     }
 
-    /* HVM domains must be put into shadow2 mode at the start of day */
+    /* HVM domains must be put into shadow mode at the start of day */
     if ( xc_shadow_control(xc_handle, domid, XEN_DOMCTL_SHADOW_OP_ENABLE,
                            NULL, 0, NULL, 
                            XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT  |
diff -r 896fcdd49c7f -r 684fdcfb251a tools/misc/xend
--- a/tools/misc/xend   Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/misc/xend   Mon Aug 28 16:26:37 2006 -0600
@@ -86,7 +86,7 @@ def start_xenstored():
     XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
     cmd = "xenstored --pid-file /var/run/xenstore.pid"
     if XENSTORED_TRACE:
-        cmd += " -T /var/log/xenstored-trace.log"
+        cmd += " -T /var/log/xen/xenstored-trace.log"
     s,o = commands.getstatusoutput(cmd)
 
 def start_consoled():
diff -r 896fcdd49c7f -r 684fdcfb251a tools/python/xen/util/bugtool.py
--- a/tools/python/xen/util/bugtool.py  Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/python/xen/util/bugtool.py  Mon Aug 28 16:26:37 2006 -0600
@@ -43,8 +43,8 @@ TITLE_RE = re.compile(r'<title>(.*)</tit
 
 FILES_TO_SEND = [ '/var/log/' + x for x in 
                   [ 'syslog', 'messages', 'debug',
-                    'xend.log', 'xend-debug.log', 'xenstored-trace.log',
-                    'xen-hotplug.log' ] ]
+                    'xen/xend.log', 'xen/xend-debug.log', 
'xen/xenstored-trace.log',
+                    'xen/xen-hotplug.log' ] ]
 #FILES_TO_SEND = [  ]
 
 
diff -r 896fcdd49c7f -r 684fdcfb251a tools/python/xen/xend/XendRoot.py
--- a/tools/python/xen/xend/XendRoot.py Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/python/xen/xend/XendRoot.py Mon Aug 28 16:26:37 2006 -0600
@@ -52,7 +52,7 @@ class XendRoot:
     block_script_dir = "/etc/xen/scripts"
 
     """Default path to the log file. """
-    logfile_default = "/var/log/xend.log"
+    logfile_default = "/var/log/xen/xend.log"
 
     """Default level of information to be logged."""
     loglevel_default = 'DEBUG'
diff -r 896fcdd49c7f -r 684fdcfb251a tools/python/xen/xend/server/params.py
--- a/tools/python/xen/xend/server/params.py    Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/python/xen/xend/server/params.py    Mon Aug 28 16:26:37 2006 -0600
@@ -39,8 +39,8 @@ def getenv(var, val, conv=None):
 
 # The following parameters could be placed in a configuration file.
 XEND_PID_FILE      = '/var/run/xend.pid'
-XEND_TRACE_FILE    = '/var/log/xend.trace'
-XEND_DEBUG_LOG     = '/var/log/xend-debug.log'
+XEND_TRACE_FILE    = '/var/log/xen/xend.trace'
+XEND_DEBUG_LOG     = '/var/log/xen/xend-debug.log'
 XEND_USER          = 'root'
 XEND_DEBUG         = getenv("XEND_DEBUG",     0, conv=int)
 XEND_DAEMONIZE     = getenv("XEND_DAEMONIZE", not XEND_DEBUG, conv=int)
diff -r 896fcdd49c7f -r 684fdcfb251a tools/security/python/xensec_gen/main.py
--- a/tools/security/python/xensec_gen/main.py  Mon Aug 28 16:16:07 2006 -0600
+++ b/tools/security/python/xensec_gen/main.py  Mon Aug 28 16:26:37 2006 -0600
@@ -34,7 +34,7 @@ import CGIHTTPServer
 
 gHttpPort = 7777
 gHttpDir  = '/var/lib/xensec_gen'
-gLogFile  = '/var/log/xensec_gen.log'
+gLogFile  = '/var/log/xen/xensec_gen.log'
 gUser     = 'nobody'
 gGroup    = 'nobody'
 
diff -r 896fcdd49c7f -r 684fdcfb251a 
unmodified_drivers/linux-2.6/platform-pci/evtchn.c
--- a/unmodified_drivers/linux-2.6/platform-pci/evtchn.c        Mon Aug 28 
16:16:07 2006 -0600
+++ b/unmodified_drivers/linux-2.6/platform-pci/evtchn.c        Mon Aug 28 
16:26:37 2006 -0600
@@ -4,7 +4,7 @@
  * A simplified event channel for para-drivers in unmodified linux
  *
  * Copyright (c) 2002-2005, K A Fraser
- * Copyright (c) 2005, <xiaofeng.ling@xxxxxxxxx>
+ * Copyright (c) 2005, Intel Corporation <xiaofeng.ling@xxxxxxxxx>
  *
  * This file may be distributed separately from the Linux kernel, or
  * incorporated into other software packages, subject to the following license:
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/Makefile
--- a/xen/arch/x86/Makefile     Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/Makefile     Mon Aug 28 16:26:37 2006 -0600
@@ -2,6 +2,7 @@ subdir-y += cpu
 subdir-y += cpu
 subdir-y += genapic
 subdir-y += hvm
+subdir-y += mm
 subdir-y += oprofile
 
 subdir-$(x86_32) += x86_32
@@ -41,23 +42,6 @@ obj-y += usercopy.o
 obj-y += usercopy.o
 obj-y += x86_emulate.o
 
-ifneq ($(pae),n)
-obj-$(x86_32) += shadow2-common.o shadow2_g2_on_s3.o shadow2_g3_on_s3.o
-else
-obj-$(x86_32) += shadow2-common.o shadow2_g2_on_s2.o
-endif
-
-obj-$(x86_64) += shadow2-common.o shadow2_g4_on_s4.o shadow2_g3_on_s3.o \
-                 shadow2_g2_on_s3.o
-
-guest_levels  = $(subst g,,$(filter g%,$(subst ., ,$(subst _, ,$(subst 
shadow2_,,$(1))))))
-shadow_levels = $(subst s,,$(filter s%,$(subst ., ,$(subst _, ,$(subst 
shadow2_,,$(1))))))
-shadow2_defns = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1)) \
-                -DSHADOW_PAGING_LEVELS=$(call shadow_levels,$(1))
-
-shadow2_%.o: shadow2.c $(HDRS) Makefile
-       $(CC) $(CFLAGS) $(call shadow2_defns,$(@F)) -c $< -o $@
-
 obj-$(crash_debug) += gdbstub.o
 
 $(TARGET): $(TARGET)-syms boot/mkelf32
@@ -86,9 +70,6 @@ boot/mkelf32: boot/mkelf32.c
 boot/mkelf32: boot/mkelf32.c
        $(HOSTCC) $(HOSTCFLAGS) -o $@ $<
 
-shadow_guest32.o: shadow.c
-shadow_guest32pae.o: shadow.c
-
 .PHONY: clean
 clean::
        rm -f asm-offsets.s xen.lds boot/*.o boot/*~ boot/core boot/mkelf32
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/domain.c
--- a/xen/arch/x86/domain.c     Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/domain.c     Mon Aug 28 16:26:37 2006 -0600
@@ -200,12 +200,12 @@ int arch_domain_create(struct domain *d)
 
 #endif /* __x86_64__ */
 
-    shadow2_lock_init(d);
-    for ( i = 0; i <= SHADOW2_MAX_ORDER; i++ )
-        INIT_LIST_HEAD(&d->arch.shadow2.freelists[i]);
-    INIT_LIST_HEAD(&d->arch.shadow2.p2m_freelist);
-    INIT_LIST_HEAD(&d->arch.shadow2.p2m_inuse);
-    INIT_LIST_HEAD(&d->arch.shadow2.toplevel_shadows);
+    shadow_lock_init(d);
+    for ( i = 0; i <= SHADOW_MAX_ORDER; i++ )
+        INIT_LIST_HEAD(&d->arch.shadow.freelists[i]);
+    INIT_LIST_HEAD(&d->arch.shadow.p2m_freelist);
+    INIT_LIST_HEAD(&d->arch.shadow.p2m_inuse);
+    INIT_LIST_HEAD(&d->arch.shadow.toplevel_shadows);
 
     if ( !is_idle_domain(d) )
     {
@@ -236,7 +236,7 @@ int arch_domain_create(struct domain *d)
 
 void arch_domain_destroy(struct domain *d)
 {
-    shadow2_final_teardown(d);
+    shadow_final_teardown(d);
 
     free_xenheap_pages(
         d->arch.mm_perdomain_pt,
@@ -342,10 +342,10 @@ int arch_set_info_guest(
         }
     }    
 
-    /* Shadow2: make sure the domain has enough shadow memory to
+    /* Shadow: make sure the domain has enough shadow memory to
      * boot another vcpu */
-    if ( shadow2_mode_enabled(d) 
-         && d->arch.shadow2.total_pages < shadow2_min_acceptable_pages(d) )
+    if ( shadow_mode_enabled(d) 
+         && d->arch.shadow.total_pages < shadow_min_acceptable_pages(d) )
     {
         destroy_gdt(v);
         return -ENOMEM;
@@ -357,8 +357,8 @@ int arch_set_info_guest(
     /* Don't redo final setup */
     set_bit(_VCPUF_initialised, &v->vcpu_flags);
 
-    if ( shadow2_mode_enabled(d) )
-        shadow2_update_paging_modes(v);
+    if ( shadow_mode_enabled(d) )
+        shadow_update_paging_modes(v);
 
     update_cr3(v);
 
@@ -936,11 +936,11 @@ void domain_relinquish_resources(struct 
     for_each_vcpu ( d, v )
     {
         /* Drop ref to guest_table (from new_guest_cr3(), svm/vmx cr3 handling,
-         * or sh2_update_paging_modes()) */
+         * or sh_update_paging_modes()) */
         pfn = pagetable_get_pfn(v->arch.guest_table);
         if ( pfn != 0 )
         {
-            if ( shadow2_mode_refcounts(d) )
+            if ( shadow_mode_refcounts(d) )
                 put_page(mfn_to_page(pfn));
             else
                 put_page_and_type(mfn_to_page(pfn));
@@ -962,7 +962,7 @@ void domain_relinquish_resources(struct 
         hvm_relinquish_guest_resources(d);
 
     /* Tear down shadow mode stuff. */
-    shadow2_teardown(d);
+    shadow_teardown(d);
 
     /*
      * Relinquish GDT mappings. No need for explicit unmapping of the LDT as
@@ -981,18 +981,18 @@ void domain_relinquish_resources(struct 
 
 void arch_dump_domain_info(struct domain *d)
 {
-    if ( shadow2_mode_enabled(d) )
-    {
-        printk("    shadow2 mode: ");
-        if ( d->arch.shadow2.mode & SHM2_enable )
+    if ( shadow_mode_enabled(d) )
+    {
+        printk("    shadow mode: ");
+        if ( d->arch.shadow.mode & SHM2_enable )
             printk("enabled ");
-        if ( shadow2_mode_refcounts(d) )
+        if ( shadow_mode_refcounts(d) )
             printk("refcounts ");
-        if ( shadow2_mode_log_dirty(d) )
+        if ( shadow_mode_log_dirty(d) )
             printk("log_dirty ");
-        if ( shadow2_mode_translate(d) )
+        if ( shadow_mode_translate(d) )
             printk("translate ");
-        if ( shadow2_mode_external(d) )
+        if ( shadow_mode_external(d) )
             printk("external ");
         printk("\n");
     }
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/domain_build.c
--- a/xen/arch/x86/domain_build.c       Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/domain_build.c       Mon Aug 28 16:26:37 2006 -0600
@@ -679,8 +679,8 @@ int construct_dom0(struct domain *d,
         (void)alloc_vcpu(d, i, i);
 
     /* Set up CR3 value for write_ptbase */
-    if ( shadow2_mode_enabled(v->domain) )
-        shadow2_update_paging_modes(v);
+    if ( shadow_mode_enabled(v->domain) )
+        shadow_update_paging_modes(v);
     else
         update_cr3(v);
 
@@ -791,8 +791,8 @@ int construct_dom0(struct domain *d,
     new_thread(v, dsi.v_kernentry, vstack_end, vstartinfo_start);
 
     if ( opt_dom0_shadow )
-        if ( shadow2_test_enable(d) == 0 ) 
-            shadow2_update_paging_modes(v);
+        if ( shadow_test_enable(d) == 0 ) 
+            shadow_update_paging_modes(v);
 
     if ( supervisor_mode_kernel )
     {
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/domctl.c
--- a/xen/arch/x86/domctl.c     Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/domctl.c     Mon Aug 28 16:26:37 2006 -0600
@@ -39,7 +39,7 @@ long arch_do_domctl(
         d = find_domain_by_id(domctl->domain);
         if ( d != NULL )
         {
-            ret = shadow2_domctl(d, &domctl->u.shadow_op, u_domctl);
+            ret = shadow_domctl(d, &domctl->u.shadow_op, u_domctl);
             put_domain(d);
             copy_to_guest(u_domctl, domctl, 1);
         } 
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/hvm.c
--- a/xen/arch/x86/hvm/hvm.c    Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/hvm.c    Mon Aug 28 16:26:37 2006 -0600
@@ -384,8 +384,8 @@ int hvm_copy(void *buf, unsigned long va
         if (count > size)
             count = size;
 
-        gfn = shadow2_gva_to_gfn(v, vaddr);
-        mfn = mfn_x(sh2_vcpu_gfn_to_mfn(v, gfn));
+        gfn = shadow_gva_to_gfn(v, vaddr);
+        mfn = mfn_x(sh_vcpu_gfn_to_mfn(v, gfn));
 
         if (mfn == INVALID_MFN)
             return 0;
@@ -539,7 +539,7 @@ void hvm_do_hypercall(struct cpu_user_re
         return;
     }
 
-    if ( current->arch.shadow2.mode->guest_levels == 4 )
+    if ( current->arch.shadow.mode->guest_levels == 4 )
     {
         pregs->rax = hvm_hypercall64_table[pregs->rax](pregs->rdi,
                                                        pregs->rsi,
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/platform.c
--- a/xen/arch/x86/hvm/platform.c       Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/platform.c       Mon Aug 28 16:26:37 2006 -0600
@@ -721,7 +721,7 @@ void send_pio_req(struct cpu_user_regs *
 
     if (pvalid) {
         if (hvm_paging_enabled(current))
-            p->u.data = shadow2_gva_to_gpa(current, value);
+            p->u.data = shadow_gva_to_gpa(current, value);
         else
             p->u.pdata = (void *) value; /* guest VA == guest PA */
     } else
@@ -771,7 +771,7 @@ void send_mmio_req(
 
     if (pvalid) {
         if (hvm_paging_enabled(v))
-            p->u.data = shadow2_gva_to_gpa(v, value);
+            p->u.data = shadow_gva_to_gpa(v, value);
         else
             p->u.pdata = (void *) value; /* guest VA == guest PA */
     } else
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/svm/svm.c
--- a/xen/arch/x86/hvm/svm/svm.c        Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/svm/svm.c        Mon Aug 28 16:26:37 2006 -0600
@@ -29,7 +29,7 @@
 #include <xen/domain_page.h>
 #include <asm/current.h>
 #include <asm/io.h>
-#include <asm/shadow2.h>
+#include <asm/shadow.h>
 #include <asm/regs.h>
 #include <asm/cpufeature.h>
 #include <asm/processor.h>
@@ -402,6 +402,50 @@ static inline int long_mode_do_msr_write
     }
     return 1;
 }
+
+
+#define loaddebug(_v,_reg) \
+    __asm__ __volatile__ ("mov %0,%%db" #_reg : : "r" ((_v)->debugreg[_reg]))
+#define savedebug(_v,_reg) \
+    __asm__ __volatile__ ("mov %%db" #_reg ",%0" : : "r" 
((_v)->debugreg[_reg]))
+
+
+static inline void svm_save_dr(struct vcpu *v)
+{
+    if (v->arch.hvm_vcpu.flag_dr_dirty)
+    {
+        /* clear the DR dirty flag and re-enable intercepts for DR accesses */ 
+        v->arch.hvm_vcpu.flag_dr_dirty = 0;
+        v->arch.hvm_svm.vmcb->dr_intercepts = DR_INTERCEPT_ALL_WRITES;
+
+        savedebug(&v->arch.guest_context, 0);    
+        savedebug(&v->arch.guest_context, 1);    
+        savedebug(&v->arch.guest_context, 2);    
+        savedebug(&v->arch.guest_context, 3);    
+    }
+}
+
+
+static inline void __restore_debug_registers(struct vcpu *v)
+{
+    loaddebug(&v->arch.guest_context, 0);
+    loaddebug(&v->arch.guest_context, 1);
+    loaddebug(&v->arch.guest_context, 2);
+    loaddebug(&v->arch.guest_context, 3);
+}
+
+
+static inline void svm_restore_dr(struct vcpu *v)
+{
+    struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
+
+    if (!vmcb)
+        return;
+
+    if (unlikely(vmcb->dr7 & 0xFF))
+        __restore_debug_registers(v);
+}
+
 
 static int svm_realmode(struct vcpu *v)
 {
@@ -717,6 +761,7 @@ static void svm_ctxt_switch_from(struct 
 static void svm_ctxt_switch_from(struct vcpu *v)
 {
     svm_freeze_time(v);
+    svm_save_dr(v);
 }
 
 static void svm_ctxt_switch_to(struct vcpu *v)
@@ -732,6 +777,7 @@ static void svm_ctxt_switch_to(struct vc
     set_segment_register(es, 0);
     set_segment_register(ss, 0);
 #endif
+    svm_restore_dr(v);
 }
 
 
@@ -746,10 +792,10 @@ static void svm_final_setup_guest(struct
     if ( v != d->vcpu[0] )
         return;
 
-    if ( !shadow2_mode_external(d) )
+    if ( !shadow_mode_external(d) )
     {
         DPRINTK("Can't init HVM for dom %u vcpu %u: "
-                "not in shadow2 external mode\n", d->domain_id, v->vcpu_id);
+                "not in shadow external mode\n", d->domain_id, v->vcpu_id);
         domain_crash(d);
     }
 
@@ -914,7 +960,7 @@ static int svm_do_page_fault(unsigned lo
                 va, eip, (unsigned long)regs->error_code);
 //#endif
 
-    result = shadow2_fault(va, regs); 
+    result = shadow_fault(va, regs); 
 
     if( result ) {
         /* Let's make sure that the Guest TLB is flushed */
@@ -1183,55 +1229,16 @@ static inline void set_reg(unsigned int 
 }
                            
 
-static void svm_dr_access (struct vcpu *v, unsigned int reg, unsigned int type,
-                           struct cpu_user_regs *regs)
-{
-    unsigned long *reg_p = 0;
-    unsigned int gpreg = 0;
-    unsigned long eip;
-    int inst_len;
-    int index;
-    struct vmcb_struct *vmcb;
-    u8 buffer[MAX_INST_LEN];
-    u8 prefix = 0;
-
-    vmcb = v->arch.hvm_svm.vmcb;
-    
-    ASSERT(vmcb);
-
-    eip = vmcb->rip;
-    inst_copy_from_guest(buffer, svm_rip2pointer(vmcb), sizeof(buffer));
-    index = skip_prefix_bytes(buffer, sizeof(buffer));
-    
-    ASSERT(buffer[index+0] == 0x0f && (buffer[index+1] & 0xFD) == 0x21);
-
-    if (index > 0 && (buffer[index-1] & 0xF0) == 0x40)
-        prefix = buffer[index-1];
-
-    gpreg = decode_src_reg(prefix, buffer[index + 2]);
-    ASSERT(reg == decode_dest_reg(prefix, buffer[index + 2]));
-
-    HVM_DBG_LOG(DBG_LEVEL_1, "svm_dr_access : eip=%lx, reg=%d, gpreg = %x",
-                eip, reg, gpreg);
-
-    reg_p = get_reg_p(gpreg, regs, vmcb);
-        
-    switch (type) 
-    {
-    case TYPE_MOV_TO_DR: 
-        inst_len = __get_instruction_length(vmcb, INSTR_MOV2DR, buffer);
-        v->arch.guest_context.debugreg[reg] = *reg_p;
-        break;
-    case TYPE_MOV_FROM_DR:
-        inst_len = __get_instruction_length(vmcb, INSTR_MOVDR2, buffer);
-        *reg_p = v->arch.guest_context.debugreg[reg];
-        break;
-    default:
-        __hvm_bug(regs);
-        break;
-    }
-    ASSERT(inst_len > 0);
-    __update_guest_eip(vmcb, inst_len);
+static void svm_dr_access(struct vcpu *v, struct cpu_user_regs *regs)
+{
+    struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
+
+    v->arch.hvm_vcpu.flag_dr_dirty = 1;
+
+    __restore_debug_registers(v);
+
+    /* allow the guest full access to the debug registers */
+    vmcb->dr_intercepts = 0;
 }
 
 
@@ -1562,7 +1569,7 @@ static int svm_set_cr0(unsigned long val
         v->arch.guest_table = pagetable_from_pfn(mfn);
         if ( old_base_mfn )
             put_page(mfn_to_page(old_base_mfn));
-        shadow2_update_paging_modes(v);
+        shadow_update_paging_modes(v);
 
         HVM_DBG_LOG(DBG_LEVEL_VMMU, "New arch.guest_table = %lx", 
                     (unsigned long) (mfn << PAGE_SHIFT));
@@ -1588,14 +1595,14 @@ static int svm_set_cr0(unsigned long val
             svm_inject_exception(v, TRAP_gp_fault, 1, 0);
             return 0;
         }
-        shadow2_update_paging_modes(v);
+        shadow_update_paging_modes(v);
         vmcb->cr3 = v->arch.hvm_vcpu.hw_cr3;
         set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
     }
     else if ( (value & (X86_CR0_PE | X86_CR0_PG)) == X86_CR0_PE )
     {
         /* we should take care of this kind of situation */
-        shadow2_update_paging_modes(v);
+        shadow_update_paging_modes(v);
         vmcb->cr3 = v->arch.hvm_vcpu.hw_cr3;
         set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
     }
@@ -1706,7 +1713,7 @@ static int mov_to_cr(int gpreg, int cr, 
             mfn = get_mfn_from_gpfn(value >> PAGE_SHIFT);
             if (mfn != pagetable_get_pfn(v->arch.guest_table))
                 __hvm_bug(regs);
-            shadow2_update_cr3(v);
+            shadow_update_cr3(v);
         }
         else 
         {
@@ -1771,7 +1778,7 @@ static int mov_to_cr(int gpreg, int cr, 
                 v->arch.guest_table = pagetable_from_pfn(mfn);
                 if ( old_base_mfn )
                     put_page(mfn_to_page(old_base_mfn));
-                shadow2_update_paging_modes(v);
+                shadow_update_paging_modes(v);
 
                 HVM_DBG_LOG(DBG_LEVEL_VMMU, "New arch.guest_table = %lx",
                             (unsigned long) (mfn << PAGE_SHIFT));
@@ -1808,7 +1815,7 @@ static int mov_to_cr(int gpreg, int cr, 
         if ((old_cr ^ value) & (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE))
         {
             set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
-            shadow2_update_paging_modes(v);
+            shadow_update_paging_modes(v);
         }
         break;
     }
@@ -2149,7 +2156,7 @@ void svm_handle_invlpg(const short invlp
 
     /* Overkill, we may not this */
     set_bit(ARCH_SVM_VMCB_ASSIGN_ASID, &v->arch.hvm_svm.flags);
-    shadow2_invlpg(v, g_vaddr);
+    shadow_invlpg(v, g_vaddr);
 }
 
 
@@ -2520,7 +2527,7 @@ void walk_shadow_and_guest_pt(unsigned l
     struct vmcb_struct *vmcb = v->arch.hvm_svm.vmcb;
     unsigned long gpa;
 
-    gpa = shadow2_gva_to_gpa(current, gva);
+    gpa = shadow_gva_to_gpa(current, gva);
     printk( "gva = %lx, gpa=%lx, gCR3=%x\n", gva, gpa, (u32)vmcb->cr3 );
     if( !svm_paging_enabled(v) || mmio_space(gpa) )
         return;
@@ -2591,7 +2598,7 @@ asmlinkage void svm_vmexit_handler(struc
         if (svm_dbg_on && exit_reason == VMEXIT_EXCEPTION_PF) 
         {
             if (svm_paging_enabled(v) && 
-                !mmio_space(shadow2_gva_to_gpa(current, vmcb->exitinfo2)))
+                !mmio_space(shadow_gva_to_gpa(current, vmcb->exitinfo2)))
             {
                 printk("I%08ld,ExC=%s(%d),IP=%x:%llx,"
                        "I1=%llx,I2=%llx,INT=%llx, "
@@ -2601,7 +2608,7 @@ asmlinkage void svm_vmexit_handler(struc
                        (unsigned long long) vmcb->exitinfo1,
                        (unsigned long long) vmcb->exitinfo2,
                        (unsigned long long) vmcb->exitintinfo.bytes,
-                       (unsigned long long) shadow2_gva_to_gpa(current, 
vmcb->exitinfo2));
+                       (unsigned long long) shadow_gva_to_gpa(current, 
vmcb->exitinfo2));
             }
             else 
             {
@@ -2862,53 +2869,9 @@ asmlinkage void svm_vmexit_handler(struc
     case VMEXIT_CR8_WRITE:
         svm_cr_access(v, 8, TYPE_MOV_TO_CR, &regs);
         break;
-
-    case VMEXIT_DR0_READ:
-        svm_dr_access(v, 0, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR1_READ:
-        svm_dr_access(v, 1, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR2_READ:
-        svm_dr_access(v, 2, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR3_READ:
-        svm_dr_access(v, 3, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR6_READ:
-        svm_dr_access(v, 6, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR7_READ:
-        svm_dr_access(v, 7, TYPE_MOV_FROM_DR, &regs);
-        break;
-
-    case VMEXIT_DR0_WRITE:
-        svm_dr_access(v, 0, TYPE_MOV_TO_DR, &regs);
-        break;
-
-    case VMEXIT_DR1_WRITE:
-        svm_dr_access(v, 1, TYPE_MOV_TO_DR, &regs);
-        break;
-
-    case VMEXIT_DR2_WRITE:
-        svm_dr_access(v, 2, TYPE_MOV_TO_DR, &regs);
-        break;
-
-    case VMEXIT_DR3_WRITE:
-        svm_dr_access(v, 3, TYPE_MOV_TO_DR, &regs);
-        break;
-
-    case VMEXIT_DR6_WRITE:
-        svm_dr_access(v, 6, TYPE_MOV_TO_DR, &regs);
-        break;
-
-    case VMEXIT_DR7_WRITE:
-        svm_dr_access(v, 7, TYPE_MOV_TO_DR, &regs);
+       
+    case VMEXIT_DR0_WRITE ... VMEXIT_DR7_WRITE:
+        svm_dr_access(v, &regs);
         break;
 
     case VMEXIT_IOIO:
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/svm/vmcb.c
--- a/xen/arch/x86/hvm/svm/vmcb.c       Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/svm/vmcb.c       Mon Aug 28 16:26:37 2006 -0600
@@ -121,7 +121,7 @@ static int construct_vmcb_controls(struc
         GENERAL2_INTERCEPT_SKINIT | GENERAL2_INTERCEPT_RDTSCP;
 
     /* read or write all debug registers 0 - 15 */
-    vmcb->dr_intercepts = 0;
+    vmcb->dr_intercepts = DR_INTERCEPT_ALL_WRITES;
 
     /* RD/WR all control registers 0 - 15, but not read CR2 */
     vmcb->cr_intercepts = ~(CR_INTERCEPT_CR2_READ | CR_INTERCEPT_CR2_WRITE);
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c       Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/vmx/vmcs.c       Mon Aug 28 16:26:37 2006 -0600
@@ -35,7 +35,7 @@
 #include <xen/event.h>
 #include <xen/kernel.h>
 #include <xen/keyhandler.h>
-#include <asm/shadow2.h>
+#include <asm/shadow.h>
 
 static int vmcs_size;
 static int vmcs_order;
@@ -272,7 +272,7 @@ static void vmx_do_launch(struct vcpu *v
     error |= __vmwrite(GUEST_TR_BASE, 0);
     error |= __vmwrite(GUEST_TR_LIMIT, 0xff);
 
-    shadow2_update_paging_modes(v);
+    shadow_update_paging_modes(v);
     printk("%s(): GUEST_CR3<=%08lx, HOST_CR3<=%08lx\n",
            __func__, v->arch.hvm_vcpu.hw_cr3, v->arch.cr3);
     __vmwrite(GUEST_CR3, v->arch.hvm_vcpu.hw_cr3);
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c        Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/hvm/vmx/vmx.c        Mon Aug 28 16:26:37 2006 -0600
@@ -40,7 +40,7 @@
 #include <asm/hvm/vmx/vmx.h>
 #include <asm/hvm/vmx/vmcs.h>
 #include <asm/hvm/vmx/cpu.h>
-#include <asm/shadow2.h>
+#include <asm/shadow.h>
 #include <public/sched.h>
 #include <public/hvm/ioreq.h>
 #include <asm/hvm/vpic.h>
@@ -66,10 +66,10 @@ static int vmx_initialize_guest_resource
     if ( v->vcpu_id != 0 )
         return 1;
 
-    if ( !shadow2_mode_external(d) )
+    if ( !shadow_mode_external(d) )
     {
         DPRINTK("Can't init HVM for dom %u vcpu %u: "
-                "not in shadow2 external mode\n", 
+                "not in shadow external mode\n", 
                 d->domain_id, v->vcpu_id);
         domain_crash(d);
     }
@@ -865,7 +865,7 @@ static int vmx_do_page_fault(unsigned lo
     }
 #endif
 
-    result = shadow2_fault(va, regs);
+    result = shadow_fault(va, regs);
 
     TRACE_VMEXIT (2,result);
 #if 0
@@ -1039,7 +1039,7 @@ static void vmx_vmexit_do_invlpg(unsigne
      * We do the safest things first, then try to update the shadow
      * copying from guest
      */
-    shadow2_invlpg(v, va);
+    shadow_invlpg(v, va);
 }
 
 
@@ -1301,7 +1301,7 @@ vmx_world_restore(struct vcpu *v, struct
 
  skip_cr3:
 
-    shadow2_update_paging_modes(v);
+    shadow_update_paging_modes(v);
     if (!vmx_paging_enabled(v))
         HVM_DBG_LOG(DBG_LEVEL_VMMU, "switching to vmxassist. use phys table");
     else
@@ -1504,7 +1504,7 @@ static int vmx_set_cr0(unsigned long val
         v->arch.guest_table = pagetable_from_pfn(mfn);
         if (old_base_mfn)
             put_page(mfn_to_page(old_base_mfn));
-        shadow2_update_paging_modes(v);
+        shadow_update_paging_modes(v);
 
         HVM_DBG_LOG(DBG_LEVEL_VMMU, "New arch.guest_table = %lx",
                     (unsigned long) (mfn << PAGE_SHIFT));
@@ -1577,7 +1577,7 @@ static int vmx_set_cr0(unsigned long val
     else if ( (value & (X86_CR0_PE | X86_CR0_PG)) == X86_CR0_PE )
     {
         __vmwrite(GUEST_CR3, v->arch.hvm_vcpu.hw_cr3);
-        shadow2_update_paging_modes(v);
+        shadow_update_paging_modes(v);
     }
 
     return 1;
@@ -1662,7 +1662,7 @@ static int mov_to_cr(int gp, int cr, str
             mfn = get_mfn_from_gpfn(value >> PAGE_SHIFT);
             if (mfn != pagetable_get_pfn(v->arch.guest_table))
                 __hvm_bug(regs);
-            shadow2_update_cr3(v);
+            shadow_update_cr3(v);
         } else {
             /*
              * If different, make a shadow. Check if the PDBR is valid
@@ -1755,7 +1755,7 @@ static int mov_to_cr(int gp, int cr, str
          * all TLB entries except global entries.
          */
         if ( (old_cr ^ value) & (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE) )
-            shadow2_update_paging_modes(v);
+            shadow_update_paging_modes(v);
         break;
     }
     default:
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/mm.c
--- a/xen/arch/x86/mm.c Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/mm.c Mon Aug 28 16:26:37 2006 -0600
@@ -454,12 +454,12 @@ int map_ldt_shadow_page(unsigned int off
 
     res = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
 
-    if ( !res && unlikely(shadow2_mode_refcounts(d)) )
-    {
-        shadow2_lock(d);
-        shadow2_remove_write_access(d->vcpu[0], _mfn(mfn), 0, 0);
+    if ( !res && unlikely(shadow_mode_refcounts(d)) )
+    {
+        shadow_lock(d);
+        shadow_remove_write_access(d->vcpu[0], _mfn(mfn), 0, 0);
         res = get_page_and_type(mfn_to_page(mfn), d, PGT_ldt_page);
-        shadow2_unlock(d);
+        shadow_unlock(d);
     }
 
     if ( unlikely(!res) )
@@ -527,7 +527,7 @@ get_linear_pagetable(
     struct page_info *page;
     unsigned long pfn;
 
-    ASSERT( !shadow2_mode_refcounts(d) );
+    ASSERT( !shadow_mode_refcounts(d) );
 
     if ( (root_get_flags(re) & _PAGE_RW) )
     {
@@ -602,12 +602,12 @@ get_page_from_l1e(
         d = dom_io;
     }
 
-    /* Foreign mappings into guests in shadow2 external mode don't
+    /* Foreign mappings into guests in shadow external mode don't
      * contribute to writeable mapping refcounts.  (This allows the
      * qemu-dm helper process in dom0 to map the domain's memory without
      * messing up the count of "real" writable mappings.) */
     okay = (((l1e_get_flags(l1e) & _PAGE_RW) && 
-             !(unlikely(shadow2_mode_external(d) && (d != current->domain))))
+             !(unlikely(shadow_mode_external(d) && (d != current->domain))))
             ? get_page_and_type(page, d, PGT_writable_page)
             : get_page(page, d));
     if ( !okay )
@@ -771,9 +771,9 @@ void put_page_from_l1e(l1_pgentry_t l1e,
     }
 
     /* Remember we didn't take a type-count of foreign writable mappings
-     * to shadow2 external domains */
+     * to shadow external domains */
     if ( (l1e_get_flags(l1e) & _PAGE_RW) && 
-         !(unlikely((e != d) && shadow2_mode_external(e))) )
+         !(unlikely((e != d) && shadow_mode_external(e))) )
     {
         put_page_and_type(page);
     }
@@ -830,7 +830,7 @@ static int alloc_l1_table(struct page_in
     l1_pgentry_t  *pl1e;
     int            i;
 
-    ASSERT(!shadow2_mode_refcounts(d));
+    ASSERT(!shadow_mode_refcounts(d));
 
     pl1e = map_domain_page(pfn);
 
@@ -883,7 +883,7 @@ static int create_pae_xen_mappings(l3_pg
      *     a. alloc_l3_table() calls this function and this check will fail
      *     b. mod_l3_entry() disallows updates to slot 3 in an existing table
      *
-     * XXX -- this needs revisiting for shadow2_mode_refcount()==true...
+     * XXX -- this needs revisiting for shadow_mode_refcount()==true...
      */
     page = l3e_get_page(l3e3);
     BUG_ON(page->u.inuse.type_info & PGT_pinned);
@@ -1007,7 +1007,7 @@ static int alloc_l2_table(struct page_in
     l2_pgentry_t  *pl2e;
     int            i;
 
-    ASSERT(!shadow2_mode_refcounts(d));
+    ASSERT(!shadow_mode_refcounts(d));
     
     pl2e = map_domain_page(pfn);
 
@@ -1059,7 +1059,7 @@ static int alloc_l3_table(struct page_in
     l3_pgentry_t  *pl3e;
     int            i;
 
-    ASSERT(!shadow2_mode_refcounts(d));
+    ASSERT(!shadow_mode_refcounts(d));
 
 #ifdef CONFIG_X86_PAE
     /*
@@ -1120,7 +1120,7 @@ static int alloc_l4_table(struct page_in
     unsigned long vaddr;
     int            i;
 
-    ASSERT(!shadow2_mode_refcounts(d));
+    ASSERT(!shadow_mode_refcounts(d));
 
     for ( i = 0; i < L4_PAGETABLE_ENTRIES; i++ )
     {
@@ -1234,8 +1234,8 @@ static inline int update_l1e(l1_pgentry_
                              struct vcpu *v)
 {
     int rv = 1;
-    if ( unlikely(shadow2_mode_enabled(v->domain)) )
-        shadow2_lock(v->domain);
+    if ( unlikely(shadow_mode_enabled(v->domain)) )
+        shadow_lock(v->domain);
 #ifndef PTE_UPDATE_WITH_CMPXCHG
     rv = (!__copy_to_user(pl1e, &nl1e, sizeof(nl1e)));
 #else
@@ -1266,10 +1266,10 @@ static inline int update_l1e(l1_pgentry_
         }
     }
 #endif
-    if ( unlikely(shadow2_mode_enabled(v->domain)) )
-    {
-        shadow2_validate_guest_entry(v, _mfn(gl1mfn), pl1e);
-        shadow2_unlock(v->domain);    
+    if ( unlikely(shadow_mode_enabled(v->domain)) )
+    {
+        shadow_validate_guest_entry(v, _mfn(gl1mfn), pl1e);
+        shadow_unlock(v->domain);    
     }
     return rv;
 }
@@ -1339,13 +1339,13 @@ static int mod_l1_entry(l1_pgentry_t *pl
 #endif
 #define UPDATE_ENTRY(_t,_p,_o,_n,_m)  ({                            \
     int rv;                                                         \
-    if ( unlikely(shadow2_mode_enabled(current->domain)) )          \
-        shadow2_lock(current->domain);                              \
+    if ( unlikely(shadow_mode_enabled(current->domain)) )          \
+        shadow_lock(current->domain);                              \
     rv = _UPDATE_ENTRY(_t, _p, _o, _n);                             \
-    if ( unlikely(shadow2_mode_enabled(current->domain)) )          \
+    if ( unlikely(shadow_mode_enabled(current->domain)) )          \
     {                                                               \
-        shadow2_validate_guest_entry(current, _mfn(_m), (_p));      \
-        shadow2_unlock(current->domain);                            \
+        shadow_validate_guest_entry(current, _mfn(_m), (_p));      \
+        shadow_unlock(current->domain);                            \
     }                                                               \
     rv;                                                             \
 })
@@ -1581,21 +1581,21 @@ void free_page_type(struct page_info *pa
          */
         this_cpu(percpu_mm_info).deferred_ops |= DOP_FLUSH_ALL_TLBS;
 
-        if ( unlikely(shadow2_mode_enabled(owner)
-                 && !shadow2_lock_is_acquired(owner)) )
+        if ( unlikely(shadow_mode_enabled(owner)
+                 && !shadow_lock_is_acquired(owner)) )
         {
             /* Raw page tables are rewritten during save/restore. */
-            if ( !shadow2_mode_translate(owner) )
+            if ( !shadow_mode_translate(owner) )
                 mark_dirty(owner, page_to_mfn(page));
 
-            if ( shadow2_mode_refcounts(owner) )
+            if ( shadow_mode_refcounts(owner) )
                 return;
 
             gmfn = mfn_to_gmfn(owner, page_to_mfn(page));
             ASSERT(VALID_M2P(gmfn));
-            shadow2_lock(owner);
-            shadow2_remove_all_shadows(owner->vcpu[0], _mfn(gmfn));
-            shadow2_unlock(owner);
+            shadow_lock(owner);
+            shadow_remove_all_shadows(owner->vcpu[0], _mfn(gmfn));
+            shadow_unlock(owner);
         }
     }
 
@@ -1760,7 +1760,7 @@ int get_page_type(struct page_info *page
 #endif
                     /* Fixme: add code to propagate va_unknown to subtables. */
                     if ( ((type & PGT_type_mask) >= PGT_l2_page_table) &&
-                         !shadow2_mode_refcounts(page_get_owner(page)) )
+                         !shadow_mode_refcounts(page_get_owner(page)) )
                         return 0;
                     /* This table is possibly mapped at multiple locations. */
                     nx &= ~PGT_va_mask;
@@ -1810,7 +1810,7 @@ int new_guest_cr3(unsigned long mfn)
     if ( hvm_guest(v) && !hvm_paging_enabled(v) )
         domain_crash_synchronous();
 
-    if ( shadow2_mode_refcounts(d) )
+    if ( shadow_mode_refcounts(d) )
     {
         okay = get_page_from_pagenr(mfn, d);
         if ( unlikely(!okay) )
@@ -1858,7 +1858,7 @@ int new_guest_cr3(unsigned long mfn)
 
     if ( likely(old_base_mfn != 0) )
     {
-        if ( shadow2_mode_refcounts(d) )
+        if ( shadow_mode_refcounts(d) )
             put_page(mfn_to_page(old_base_mfn));
         else
             put_page_and_type(mfn_to_page(old_base_mfn));
@@ -2043,7 +2043,7 @@ int do_mmuext_op(
             type = PGT_root_page_table;
 
         pin_page:
-            if ( shadow2_mode_refcounts(FOREIGNDOM) )
+            if ( shadow_mode_refcounts(FOREIGNDOM) )
                 break;
 
             okay = get_page_and_type_from_pagenr(mfn, type, FOREIGNDOM);
@@ -2065,7 +2065,7 @@ int do_mmuext_op(
             break;
 
         case MMUEXT_UNPIN_TABLE:
-            if ( shadow2_mode_refcounts(d) )
+            if ( shadow_mode_refcounts(d) )
                 break;
 
             if ( unlikely(!(okay = get_page_from_pagenr(mfn, d))) )
@@ -2078,11 +2078,11 @@ int do_mmuext_op(
             {
                 put_page_and_type(page);
                 put_page(page);
-                if ( shadow2_mode_enabled(d) )
+                if ( shadow_mode_enabled(d) )
                 {
-                    shadow2_lock(d);
-                    shadow2_remove_all_shadows(v, _mfn(mfn));
-                    shadow2_unlock(d);
+                    shadow_lock(d);
+                    shadow_remove_all_shadows(v, _mfn(mfn));
+                    shadow_unlock(d);
                 }
             }
             else
@@ -2125,8 +2125,8 @@ int do_mmuext_op(
             break;
     
         case MMUEXT_INVLPG_LOCAL:
-            if ( !shadow2_mode_enabled(d) 
-                 || shadow2_invlpg(v, op.arg1.linear_addr) != 0 )
+            if ( !shadow_mode_enabled(d) 
+                 || shadow_invlpg(v, op.arg1.linear_addr) != 0 )
                 local_flush_tlb_one(op.arg1.linear_addr);
             break;
 
@@ -2173,7 +2173,7 @@ int do_mmuext_op(
             unsigned long ptr  = op.arg1.linear_addr;
             unsigned long ents = op.arg2.nr_ents;
 
-            if ( shadow2_mode_external(d) )
+            if ( shadow_mode_external(d) )
             {
                 MEM_LOG("ignoring SET_LDT hypercall from external "
                         "domain %u", d->domain_id);
@@ -2319,7 +2319,7 @@ int do_mmu_update(
             case PGT_l3_page_table:
             case PGT_l4_page_table:
             {
-                if ( shadow2_mode_refcounts(d) )
+                if ( shadow_mode_refcounts(d) )
                 {
                     DPRINTK("mmu update on shadow-refcounted domain!");
                     break;
@@ -2372,16 +2372,16 @@ int do_mmu_update(
                 if ( unlikely(!get_page_type(page, PGT_writable_page)) )
                     break;
 
-                if ( unlikely(shadow2_mode_enabled(d)) )
-                    shadow2_lock(d);
+                if ( unlikely(shadow_mode_enabled(d)) )
+                    shadow_lock(d);
 
                 *(intpte_t *)va = req.val;
                 okay = 1;
 
-                if ( unlikely(shadow2_mode_enabled(d)) )
+                if ( unlikely(shadow_mode_enabled(d)) )
                 {
-                    shadow2_validate_guest_entry(v, _mfn(mfn), va);
-                    shadow2_unlock(d);
+                    shadow_validate_guest_entry(v, _mfn(mfn), va);
+                    shadow_unlock(d);
                 }
 
                 put_page_type(page);
@@ -2405,8 +2405,8 @@ int do_mmu_update(
                 break;
             }
 
-            if ( shadow2_mode_translate(FOREIGNDOM) )
-                shadow2_guest_physmap_add_page(FOREIGNDOM, gpfn, mfn);
+            if ( shadow_mode_translate(FOREIGNDOM) )
+                shadow_guest_physmap_add_page(FOREIGNDOM, gpfn, mfn);
             else 
                 set_gpfn_from_mfn(mfn, gpfn);
             okay = 1;
@@ -2492,7 +2492,7 @@ static int create_grant_pte_mapping(
         goto failed;
     } 
 
-    if ( !shadow2_mode_refcounts(d) )
+    if ( !shadow_mode_refcounts(d) )
         put_page_from_l1e(ol1e, d);
 
     put_page_type(page);
@@ -2590,7 +2590,7 @@ static int create_grant_va_mapping(
                     l2e_get_pfn(__linear_l2_table[l2_linear_offset(va)]), v) )
         return GNTST_general_error;
 
-    if ( !shadow2_mode_refcounts(d) )
+    if ( !shadow_mode_refcounts(d) )
         put_page_from_l1e(ol1e, d);
 
     return GNTST_okay;
@@ -2714,10 +2714,10 @@ int do_update_va_mapping(unsigned long v
 
     perfc_incrc(calls_to_update_va);
 
-    if ( unlikely(!__addr_ok(va) && !shadow2_mode_external(d)) )
+    if ( unlikely(!__addr_ok(va) && !shadow_mode_external(d)) )
         return -EINVAL;
 
-    if ( unlikely(shadow2_mode_refcounts(d)) )
+    if ( unlikely(shadow_mode_refcounts(d)) )
     {
         DPRINTK("Grant op on a shadow-refcounted domain\n");
         return -EINVAL; 
@@ -2725,11 +2725,11 @@ int do_update_va_mapping(unsigned long v
 
     LOCK_BIGLOCK(d);
 
-    if ( likely(rc == 0) && unlikely(shadow2_mode_enabled(d)) )
+    if ( likely(rc == 0) && unlikely(shadow_mode_enabled(d)) )
     {
         if ( unlikely(this_cpu(percpu_mm_info).foreign &&
-                      (shadow2_mode_translate(d) ||
-                       shadow2_mode_translate(
+                      (shadow_mode_translate(d) ||
+                       shadow_mode_translate(
                            this_cpu(percpu_mm_info).foreign))) )
         {
             /*
@@ -2770,8 +2770,8 @@ int do_update_va_mapping(unsigned long v
         switch ( (bmap_ptr = flags & ~UVMF_FLUSHTYPE_MASK) )
         {
         case UVMF_LOCAL:
-            if ( !shadow2_mode_enabled(d) 
-                 || (shadow2_invlpg(current, va) != 0) ) 
+            if ( !shadow_mode_enabled(d) 
+                 || (shadow_invlpg(current, va) != 0) ) 
                 local_flush_tlb_one(va);
             break;
         case UVMF_ALL:
@@ -3006,7 +3006,7 @@ long arch_memory_op(int op, XEN_GUEST_HA
             break;
         }
 
-        if ( !shadow2_mode_translate(d) || (mfn == 0) )
+        if ( !shadow_mode_translate(d) || (mfn == 0) )
         {
             put_domain(d);
             return -EINVAL;
@@ -3196,21 +3196,21 @@ static int ptwr_emulated_update(
     pl1e = (l1_pgentry_t *)((unsigned long)pl1e + (addr & ~PAGE_MASK));
     if ( do_cmpxchg )
     {
-        if ( shadow2_mode_enabled(d) )
-            shadow2_lock(d);
+        if ( shadow_mode_enabled(d) )
+            shadow_lock(d);
         ol1e = l1e_from_intpte(old);
         if ( cmpxchg((intpte_t *)pl1e, old, val) != old )
         {
-            if ( shadow2_mode_enabled(d) )
-                shadow2_unlock(d);
+            if ( shadow_mode_enabled(d) )
+                shadow_unlock(d);
             unmap_domain_page(pl1e);
             put_page_from_l1e(nl1e, d);
             return X86EMUL_CMPXCHG_FAILED;
         }
-        if ( unlikely(shadow2_mode_enabled(v->domain)) )
-        {
-            shadow2_validate_guest_entry(v, _mfn(page_to_mfn(page)), pl1e);
-            shadow2_unlock(v->domain);    
+        if ( unlikely(shadow_mode_enabled(v->domain)) )
+        {
+            shadow_validate_guest_entry(v, _mfn(page_to_mfn(page)), pl1e);
+            shadow_unlock(v->domain);    
         }
     }
     else
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/traps.c
--- a/xen/arch/x86/traps.c      Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/arch/x86/traps.c      Mon Aug 28 16:26:37 2006 -0600
@@ -870,8 +870,8 @@ static int fixup_page_fault(unsigned lon
 
     if ( unlikely(IN_HYPERVISOR_RANGE(addr)) )
     {
-        if ( shadow2_mode_external(d) && guest_mode(regs) )
-            return shadow2_fault(addr, regs);
+        if ( shadow_mode_external(d) && guest_mode(regs) )
+            return shadow_fault(addr, regs);
         if ( (addr >= GDT_LDT_VIRT_START) && (addr < GDT_LDT_VIRT_END) )
             return handle_gdt_ldt_mapping_fault(
                 addr - GDT_LDT_VIRT_START, regs);
@@ -890,8 +890,8 @@ static int fixup_page_fault(unsigned lon
          ptwr_do_page_fault(d, addr, regs) )
         return EXCRET_fault_fixed;
 
-    if ( shadow2_mode_enabled(d) )
-        return shadow2_fault(addr, regs);
+    if ( shadow_mode_enabled(d) )
+        return shadow_fault(addr, regs);
 
     return 0;
 }
diff -r 896fcdd49c7f -r 684fdcfb251a xen/include/asm-x86/domain.h
--- a/xen/include/asm-x86/domain.h      Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/include/asm-x86/domain.h      Mon Aug 28 16:26:37 2006 -0600
@@ -59,10 +59,10 @@ extern void hypercall_page_initialise(st
 
 struct shadow_domain {
     u32               mode;  /* flags to control shadow operation */
-    spinlock_t        lock;  /* shadow2 domain lock */
+    spinlock_t        lock;  /* shadow domain lock */
     int               locker; /* processor which holds the lock */
     const char       *locker_function; /* Func that took it */
-    struct list_head  freelists[SHADOW2_MAX_ORDER + 1]; 
+    struct list_head  freelists[SHADOW_MAX_ORDER + 1]; 
     struct list_head  p2m_freelist;
     struct list_head  p2m_inuse;
     struct list_head  toplevel_shadows;
@@ -70,10 +70,10 @@ struct shadow_domain {
     unsigned int      free_pages;   /* number of pages on freelists */
     unsigned int      p2m_pages;    /* number of pages in p2m map */
 
-    /* Shadow2 hashtable */
-    struct shadow2_hash_entry *hash_table;
-    struct shadow2_hash_entry *hash_freelist;
-    struct shadow2_hash_entry *hash_allocations;
+    /* Shadow hashtable */
+    struct shadow_hash_entry *hash_table;
+    struct shadow_hash_entry *hash_freelist;
+    struct shadow_hash_entry *hash_allocations;
     int hash_walking;  /* Some function is walking the hash table */
 
     /* Shadow log-dirty bitmap */
@@ -107,7 +107,7 @@ struct arch_domain
     /* Shadow-translated guest: Pseudophys base address of reserved area. */
     unsigned long first_reserved_pfn;
 
-    struct shadow_domain shadow2;
+    struct shadow_domain shadow;
 
     /* Shadow translated domain: P2M mapping */
     pagetable_t phys_table;
@@ -135,7 +135,7 @@ struct pae_l3_cache { };
 
 struct shadow_vcpu {
     /* Pointers to mode-specific entry points. */
-    struct shadow2_paging_mode *mode;
+    struct shadow_paging_mode *mode;
     /* Last MFN that we emulated a write to. */
     unsigned long last_emulated_mfn;
     /* HVM guest: paging enabled (CR0.PG)?  */
@@ -201,7 +201,7 @@ struct arch_vcpu
     /* Current LDT details. */
     unsigned long shadow_ldt_mapcnt;
 
-    struct shadow_vcpu shadow2;
+    struct shadow_vcpu shadow;
 } __cacheline_aligned;
 
 /* shorthands to improve code legibility */
diff -r 896fcdd49c7f -r 684fdcfb251a xen/include/asm-x86/hvm/svm/vmcb.h
--- a/xen/include/asm-x86/hvm/svm/vmcb.h        Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/include/asm-x86/hvm/svm/vmcb.h        Mon Aug 28 16:26:37 2006 -0600
@@ -113,6 +113,51 @@ enum CRInterceptBits
     CR_INTERCEPT_CR14_WRITE = 1 << 30,
     CR_INTERCEPT_CR15_WRITE = 1 << 31,
 };
+
+
+/* debug register intercepts */
+enum DRInterceptBits
+{
+    DR_INTERCEPT_DR0_READ   = 1 << 0,
+    DR_INTERCEPT_DR1_READ   = 1 << 1,
+    DR_INTERCEPT_DR2_READ   = 1 << 2,
+    DR_INTERCEPT_DR3_READ   = 1 << 3,
+    DR_INTERCEPT_DR4_READ   = 1 << 4,
+    DR_INTERCEPT_DR5_READ   = 1 << 5,
+    DR_INTERCEPT_DR6_READ   = 1 << 6,
+    DR_INTERCEPT_DR7_READ   = 1 << 7,
+    DR_INTERCEPT_DR8_READ   = 1 << 8,
+    DR_INTERCEPT_DR9_READ   = 1 << 9,
+    DR_INTERCEPT_DR10_READ  = 1 << 10,
+    DR_INTERCEPT_DR11_READ  = 1 << 11,
+    DR_INTERCEPT_DR12_READ  = 1 << 12,
+    DR_INTERCEPT_DR13_READ  = 1 << 13,
+    DR_INTERCEPT_DR14_READ  = 1 << 14,
+    DR_INTERCEPT_DR15_READ  = 1 << 15,
+    DR_INTERCEPT_DR0_WRITE  = 1 << 16,
+    DR_INTERCEPT_DR1_WRITE  = 1 << 17,
+    DR_INTERCEPT_DR2_WRITE  = 1 << 18,
+    DR_INTERCEPT_DR3_WRITE  = 1 << 19,
+    DR_INTERCEPT_DR4_WRITE  = 1 << 20,
+    DR_INTERCEPT_DR5_WRITE  = 1 << 21,
+    DR_INTERCEPT_DR6_WRITE  = 1 << 22,
+    DR_INTERCEPT_DR7_WRITE  = 1 << 23,
+    DR_INTERCEPT_DR8_WRITE  = 1 << 24,
+    DR_INTERCEPT_DR9_WRITE  = 1 << 25,
+    DR_INTERCEPT_DR10_WRITE = 1 << 26,
+    DR_INTERCEPT_DR11_WRITE = 1 << 27,
+    DR_INTERCEPT_DR12_WRITE = 1 << 28,
+    DR_INTERCEPT_DR13_WRITE = 1 << 29,
+    DR_INTERCEPT_DR14_WRITE = 1 << 30,
+    DR_INTERCEPT_DR15_WRITE = 1 << 31,
+};
+
+/* for lazy save/restore we'd like to intercept all DR writes */
+#define DR_INTERCEPT_ALL_WRITES \
+    (DR_INTERCEPT_DR0_WRITE|DR_INTERCEPT_DR1_WRITE|DR_INTERCEPT_DR2_WRITE \
+    |DR_INTERCEPT_DR3_WRITE|DR_INTERCEPT_DR4_WRITE|DR_INTERCEPT_DR5_WRITE \
+    |DR_INTERCEPT_DR6_WRITE|DR_INTERCEPT_DR7_WRITE) 
+
 
 enum VMEXIT_EXITCODE
 {
diff -r 896fcdd49c7f -r 684fdcfb251a xen/include/asm-x86/mm.h
--- a/xen/include/asm-x86/mm.h  Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/include/asm-x86/mm.h  Mon Aug 28 16:26:37 2006 -0600
@@ -22,7 +22,7 @@ struct page_info
     /* Each frame can be threaded onto a doubly-linked list. */
     union {
         struct list_head list;
-        /* Shadow2 uses this field as an up-pointer in lower-level shadows */
+        /* Shadow uses this field as an up-pointer in lower-level shadows */
         paddr_t up;
     };
 
@@ -59,7 +59,7 @@ struct page_info
         /* Only used on guest pages with a shadow.
          * Guest pages with a shadow must have a non-zero type count, so this
          * does not conflict with the tlbflush timestamp. */
-        u32 shadow2_flags;
+        u32 shadow_flags;
 
         // XXX -- we expect to add another field here, to be used for min/max
         // purposes, which is only used for shadow pages.
@@ -76,7 +76,7 @@ struct page_info
 #define PGT_ldt_page        (6U<<29) /* using this page in an LDT? */
 #define PGT_writable_page   (7U<<29) /* has writable mappings of this page? */
 
-#ifndef SHADOW2
+#ifndef SHADOW
 #define PGT_l1_shadow       PGT_l1_page_table
 #define PGT_l2_shadow       PGT_l2_page_table
 #define PGT_l3_shadow       PGT_l3_page_table
@@ -117,7 +117,7 @@ struct page_info
  /* 16-bit count of uses of this frame as its current type. */
 #define PGT_count_mask      ((1U<<16)-1)
 
-#ifndef SHADOW2
+#ifndef SHADOW
 #ifdef __x86_64__
 #define PGT_high_mfn_shift  52
 #define PGT_high_mfn_mask   (0xfffUL << PGT_high_mfn_shift)
@@ -132,7 +132,7 @@ struct page_info
 #define PGT_score_shift     23
 #define PGT_score_mask      (((1U<<4)-1)<<PGT_score_shift)
 #endif
-#endif /* SHADOW2 */
+#endif /* SHADOW */
 
  /* Cleared when the owning guest 'frees' this page. */
 #define _PGC_allocated      31
@@ -146,38 +146,38 @@ struct page_info
  /* 29-bit count of references to this frame. */
 #define PGC_count_mask      ((1U<<29)-1)
 
-/* shadow2 uses the count_info on shadow pages somewhat differently */
-/* NB: please coordinate any changes here with the SH2F's in shadow2.h */
-#define PGC_SH2_none           (0U<<28) /* on the shadow2 free list */
-#define PGC_SH2_min_shadow     (1U<<28)
-#define PGC_SH2_l1_32_shadow   (1U<<28) /* shadowing a 32-bit L1 guest page */
-#define PGC_SH2_fl1_32_shadow  (2U<<28) /* L1 shadow for a 32b 4M superpage */
-#define PGC_SH2_l2_32_shadow   (3U<<28) /* shadowing a 32-bit L2 guest page */
-#define PGC_SH2_l1_pae_shadow  (4U<<28) /* shadowing a pae L1 page */
-#define PGC_SH2_fl1_pae_shadow (5U<<28) /* L1 shadow for pae 2M superpg */
-#define PGC_SH2_l2_pae_shadow  (6U<<28) /* shadowing a pae L2-low page */
-#define PGC_SH2_l2h_pae_shadow (7U<<28) /* shadowing a pae L2-high page */
-#define PGC_SH2_l3_pae_shadow  (8U<<28) /* shadowing a pae L3 page */
-#define PGC_SH2_l1_64_shadow   (9U<<28) /* shadowing a 64-bit L1 page */
-#define PGC_SH2_fl1_64_shadow (10U<<28) /* L1 shadow for 64-bit 2M superpg */
-#define PGC_SH2_l2_64_shadow  (11U<<28) /* shadowing a 64-bit L2 page */
-#define PGC_SH2_l3_64_shadow  (12U<<28) /* shadowing a 64-bit L3 page */
-#define PGC_SH2_l4_64_shadow  (13U<<28) /* shadowing a 64-bit L4 page */
-#define PGC_SH2_max_shadow    (13U<<28)
-#define PGC_SH2_p2m_table     (14U<<28) /* in use as the p2m table */
-#define PGC_SH2_monitor_table (15U<<28) /* in use as a monitor table */
-#define PGC_SH2_unused        (15U<<28)
-
-#define PGC_SH2_type_mask     (15U<<28)
-#define PGC_SH2_type_shift          28
-
-#define PGC_SH2_pinned         (1U<<27)
-
-#define _PGC_SH2_log_dirty          26
-#define PGC_SH2_log_dirty      (1U<<26)
+/* shadow uses the count_info on shadow pages somewhat differently */
+/* NB: please coordinate any changes here with the SHF's in shadow.h */
+#define PGC_SH_none           (0U<<28) /* on the shadow free list */
+#define PGC_SH_min_shadow     (1U<<28)
+#define PGC_SH_l1_32_shadow   (1U<<28) /* shadowing a 32-bit L1 guest page */
+#define PGC_SH_fl1_32_shadow  (2U<<28) /* L1 shadow for a 32b 4M superpage */
+#define PGC_SH_l2_32_shadow   (3U<<28) /* shadowing a 32-bit L2 guest page */
+#define PGC_SH_l1_pae_shadow  (4U<<28) /* shadowing a pae L1 page */
+#define PGC_SH_fl1_pae_shadow (5U<<28) /* L1 shadow for pae 2M superpg */
+#define PGC_SH_l2_pae_shadow  (6U<<28) /* shadowing a pae L2-low page */
+#define PGC_SH_l2h_pae_shadow (7U<<28) /* shadowing a pae L2-high page */
+#define PGC_SH_l3_pae_shadow  (8U<<28) /* shadowing a pae L3 page */
+#define PGC_SH_l1_64_shadow   (9U<<28) /* shadowing a 64-bit L1 page */
+#define PGC_SH_fl1_64_shadow (10U<<28) /* L1 shadow for 64-bit 2M superpg */
+#define PGC_SH_l2_64_shadow  (11U<<28) /* shadowing a 64-bit L2 page */
+#define PGC_SH_l3_64_shadow  (12U<<28) /* shadowing a 64-bit L3 page */
+#define PGC_SH_l4_64_shadow  (13U<<28) /* shadowing a 64-bit L4 page */
+#define PGC_SH_max_shadow    (13U<<28)
+#define PGC_SH_p2m_table     (14U<<28) /* in use as the p2m table */
+#define PGC_SH_monitor_table (15U<<28) /* in use as a monitor table */
+#define PGC_SH_unused        (15U<<28)
+
+#define PGC_SH_type_mask     (15U<<28)
+#define PGC_SH_type_shift          28
+
+#define PGC_SH_pinned         (1U<<27)
+
+#define _PGC_SH_log_dirty          26
+#define PGC_SH_log_dirty      (1U<<26)
 
 /* 26 bit ref count for shadow pages */
-#define PGC_SH2_count_mask    ((1U<<26) - 1)
+#define PGC_SH_count_mask    ((1U<<26) - 1)
 
 /* We trust the slab allocator in slab.c, and our use of it. */
 #define PageSlab(page)     (1)
@@ -201,9 +201,9 @@ static inline u32 pickle_domptr(struct d
 
 /* The order of the largest allocation unit we use for shadow pages */
 #if CONFIG_PAGING_LEVELS == 2
-#define SHADOW2_MAX_ORDER 0 /* Only ever need 4k allocations */
+#define SHADOW_MAX_ORDER 0 /* Only ever need 4k allocations */
 #else  
-#define SHADOW2_MAX_ORDER 2 /* Need up to 16k allocs for 32-bit on PAE/64 */
+#define SHADOW_MAX_ORDER 2 /* Need up to 16k allocs for 32-bit on PAE/64 */
 #endif
 
 #define page_get_owner(_p)    (unpickle_domptr((_p)->u.inuse._domain))
@@ -227,7 +227,7 @@ extern int shadow_remove_all_write_acces
 extern int shadow_remove_all_write_access(
     struct domain *d, unsigned long gmfn, unsigned long mfn);
 extern u32 shadow_remove_all_access( struct domain *d, unsigned long gmfn);
-extern int _shadow2_mode_refcounts(struct domain *d);
+extern int _shadow_mode_refcounts(struct domain *d);
 
 static inline void put_page(struct page_info *page)
 {
@@ -259,7 +259,7 @@ static inline int get_page(struct page_i
              unlikely((nx & PGC_count_mask) == 0) || /* Count overflow? */
              unlikely(d != _domain) )                /* Wrong owner? */
         {
-            if ( !_shadow2_mode_refcounts(domain) )
+            if ( !_shadow_mode_refcounts(domain) )
                 DPRINTK("Error pfn %lx: rd=%p, od=%p, caf=%08x, taf=%" 
                         PRtype_info "\n",
                         page_to_mfn(page), domain, unpickle_domptr(d),
@@ -345,11 +345,11 @@ int check_descriptor(struct desc_struct 
 
 
 #define mfn_to_gmfn(_d, mfn)                            \
-    ( (shadow2_mode_translate(_d))                      \
+    ( (shadow_mode_translate(_d))                      \
       ? get_gpfn_from_mfn(mfn)                          \
       : (mfn) )
 
-#define gmfn_to_mfn(_d, gpfn)  mfn_x(sh2_gfn_to_mfn(_d, gpfn))
+#define gmfn_to_mfn(_d, gpfn)  mfn_x(sh_gfn_to_mfn(_d, gpfn))
 
 
 /*
diff -r 896fcdd49c7f -r 684fdcfb251a xen/include/asm-x86/perfc_defn.h
--- a/xen/include/asm-x86/perfc_defn.h  Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/include/asm-x86/perfc_defn.h  Mon Aug 28 16:26:37 2006 -0600
@@ -30,59 +30,59 @@ PERFCOUNTER_CPU(exception_fixed,        
 PERFCOUNTER_CPU(exception_fixed,        "pre-exception fixed")
 
 
-/* Shadow2 counters */
-PERFCOUNTER_CPU(shadow2_alloc,          "calls to shadow2_alloc")
-PERFCOUNTER_CPU(shadow2_alloc_tlbflush, "shadow2_alloc flushed TLBs")
+/* Shadow counters */
+PERFCOUNTER_CPU(shadow_alloc,          "calls to shadow_alloc")
+PERFCOUNTER_CPU(shadow_alloc_tlbflush, "shadow_alloc flushed TLBs")
 
 /* STATUS counters do not reset when 'P' is hit */
-PERFSTATUS(shadow2_alloc_count,         "number of shadow pages in use")
-PERFCOUNTER_CPU(shadow2_free,           "calls to shadow2_free")
-PERFCOUNTER_CPU(shadow2_prealloc_1,     "shadow2 recycles old shadows")
-PERFCOUNTER_CPU(shadow2_prealloc_2,     "shadow2 recycles in-use shadows")
-PERFCOUNTER_CPU(shadow2_linear_map_failed, "shadow2 hit read-only linear map")
-PERFCOUNTER_CPU(shadow2_a_update,       "shadow2 A bit update")
-PERFCOUNTER_CPU(shadow2_ad_update,      "shadow2 A&D bit update")
-PERFCOUNTER_CPU(shadow2_fault,          "calls to shadow2_fault")
-PERFCOUNTER_CPU(shadow2_fault_bail_bad_gfn, "shadow2_fault guest bad gfn")
-PERFCOUNTER_CPU(shadow2_fault_bail_not_present, 
-                                        "shadow2_fault guest not-present")
-PERFCOUNTER_CPU(shadow2_fault_bail_nx,  "shadow2_fault guest NX fault")
-PERFCOUNTER_CPU(shadow2_fault_bail_ro_mapping, "shadow2_fault guest R/W fault")
-PERFCOUNTER_CPU(shadow2_fault_bail_user_supervisor, 
-                                        "shadow2_fault guest U/S fault")
-PERFCOUNTER_CPU(shadow2_fault_emulate_read, "shadow2_fault emulates a read")
-PERFCOUNTER_CPU(shadow2_fault_emulate_write, "shadow2_fault emulates a write")
-PERFCOUNTER_CPU(shadow2_fault_emulate_failed, "shadow2_fault emulator fails")
-PERFCOUNTER_CPU(shadow2_fault_mmio,     "shadow2_fault handled as mmio")
-PERFCOUNTER_CPU(shadow2_fault_fixed,    "shadow2_fault fixed fault")
-PERFCOUNTER_CPU(shadow2_ptwr_emulate,   "shadow2 causes ptwr to emulate")
-PERFCOUNTER_CPU(shadow2_validate_gl1e_calls, "calls to shadow2_validate_gl1e")
-PERFCOUNTER_CPU(shadow2_validate_gl2e_calls, "calls to shadow2_validate_gl2e")
-PERFCOUNTER_CPU(shadow2_validate_gl3e_calls, "calls to shadow2_validate_gl3e")
-PERFCOUNTER_CPU(shadow2_validate_gl4e_calls, "calls to shadow2_validate_gl4e")
-PERFCOUNTER_CPU(shadow2_hash_lookups,   "calls to shadow2_hash_lookup")
-PERFCOUNTER_CPU(shadow2_hash_lookup_head, "shadow2 hash hit in bucket head")
-PERFCOUNTER_CPU(shadow2_hash_lookup_miss, "shadow2 hash misses")
-PERFCOUNTER_CPU(shadow2_get_shadow_status, "calls to get_shadow_status")
-PERFCOUNTER_CPU(shadow2_hash_inserts,   "calls to shadow2_hash_insert")
-PERFCOUNTER_CPU(shadow2_hash_deletes,   "calls to shadow2_hash_delete")
-PERFCOUNTER_CPU(shadow2_writeable,      "shadow2 removes write access")
-PERFCOUNTER_CPU(shadow2_writeable_h_1,  "shadow2 writeable: 32b w2k3")
-PERFCOUNTER_CPU(shadow2_writeable_h_2,  "shadow2 writeable: 32pae w2k3")
-PERFCOUNTER_CPU(shadow2_writeable_h_3,  "shadow2 writeable: 64b w2k3")
-PERFCOUNTER_CPU(shadow2_writeable_h_4,  "shadow2 writeable: 32b linux low")
-PERFCOUNTER_CPU(shadow2_writeable_bf,   "shadow2 writeable brute-force")
-PERFCOUNTER_CPU(shadow2_mappings,       "shadow2 removes all mappings")
-PERFCOUNTER_CPU(shadow2_mappings_bf,    "shadow2 rm-mappings brute-force")
-PERFCOUNTER_CPU(shadow2_early_unshadow, "shadow2 unshadows for fork/exit")
-PERFCOUNTER_CPU(shadow2_early_unshadow_top, "shadow2 unhooks for fork/exit")
-PERFCOUNTER_CPU(shadow2_unshadow,       "shadow2 unshadows a page")
-PERFCOUNTER_CPU(shadow2_up_pointer,     "shadow2 unshadow by up-pointer")
-PERFCOUNTER_CPU(shadow2_unshadow_bf,    "shadow2 unshadow brute-force")
-PERFCOUNTER_CPU(shadow2_get_page_fail,  "shadow2_get_page_from_l1e failed")
-PERFCOUNTER_CPU(shadow2_guest_walk,     "shadow2 walks guest tables")
-PERFCOUNTER_CPU(shadow2_walk_cache_hit, "shadow2 walk-cache hits")
-PERFCOUNTER_CPU(shadow2_walk_cache_miss, "shadow2 walk-cache misses")
+PERFSTATUS(shadow_alloc_count,         "number of shadow pages in use")
+PERFCOUNTER_CPU(shadow_free,           "calls to shadow_free")
+PERFCOUNTER_CPU(shadow_prealloc_1,     "shadow recycles old shadows")
+PERFCOUNTER_CPU(shadow_prealloc_2,     "shadow recycles in-use shadows")
+PERFCOUNTER_CPU(shadow_linear_map_failed, "shadow hit read-only linear map")
+PERFCOUNTER_CPU(shadow_a_update,       "shadow A bit update")
+PERFCOUNTER_CPU(shadow_ad_update,      "shadow A&D bit update")
+PERFCOUNTER_CPU(shadow_fault,          "calls to shadow_fault")
+PERFCOUNTER_CPU(shadow_fault_bail_bad_gfn, "shadow_fault guest bad gfn")
+PERFCOUNTER_CPU(shadow_fault_bail_not_present, 
+                                        "shadow_fault guest not-present")
+PERFCOUNTER_CPU(shadow_fault_bail_nx,  "shadow_fault guest NX fault")
+PERFCOUNTER_CPU(shadow_fault_bail_ro_mapping, "shadow_fault guest R/W fault")
+PERFCOUNTER_CPU(shadow_fault_bail_user_supervisor, 
+                                        "shadow_fault guest U/S fault")
+PERFCOUNTER_CPU(shadow_fault_emulate_read, "shadow_fault emulates a read")
+PERFCOUNTER_CPU(shadow_fault_emulate_write, "shadow_fault emulates a write")
+PERFCOUNTER_CPU(shadow_fault_emulate_failed, "shadow_fault emulator fails")
+PERFCOUNTER_CPU(shadow_fault_mmio,     "shadow_fault handled as mmio")
+PERFCOUNTER_CPU(shadow_fault_fixed,    "shadow_fault fixed fault")
+PERFCOUNTER_CPU(shadow_ptwr_emulate,   "shadow causes ptwr to emulate")
+PERFCOUNTER_CPU(shadow_validate_gl1e_calls, "calls to shadow_validate_gl1e")
+PERFCOUNTER_CPU(shadow_validate_gl2e_calls, "calls to shadow_validate_gl2e")
+PERFCOUNTER_CPU(shadow_validate_gl3e_calls, "calls to shadow_validate_gl3e")
+PERFCOUNTER_CPU(shadow_validate_gl4e_calls, "calls to shadow_validate_gl4e")
+PERFCOUNTER_CPU(shadow_hash_lookups,   "calls to shadow_hash_lookup")
+PERFCOUNTER_CPU(shadow_hash_lookup_head, "shadow hash hit in bucket head")
+PERFCOUNTER_CPU(shadow_hash_lookup_miss, "shadow hash misses")
+PERFCOUNTER_CPU(shadow_get_shadow_status, "calls to get_shadow_status")
+PERFCOUNTER_CPU(shadow_hash_inserts,   "calls to shadow_hash_insert")
+PERFCOUNTER_CPU(shadow_hash_deletes,   "calls to shadow_hash_delete")
+PERFCOUNTER_CPU(shadow_writeable,      "shadow removes write access")
+PERFCOUNTER_CPU(shadow_writeable_h_1,  "shadow writeable: 32b w2k3")
+PERFCOUNTER_CPU(shadow_writeable_h_2,  "shadow writeable: 32pae w2k3")
+PERFCOUNTER_CPU(shadow_writeable_h_3,  "shadow writeable: 64b w2k3")
+PERFCOUNTER_CPU(shadow_writeable_h_4,  "shadow writeable: 32b linux low")
+PERFCOUNTER_CPU(shadow_writeable_bf,   "shadow writeable brute-force")
+PERFCOUNTER_CPU(shadow_mappings,       "shadow removes all mappings")
+PERFCOUNTER_CPU(shadow_mappings_bf,    "shadow rm-mappings brute-force")
+PERFCOUNTER_CPU(shadow_early_unshadow, "shadow unshadows for fork/exit")
+PERFCOUNTER_CPU(shadow_early_unshadow_top, "shadow unhooks for fork/exit")
+PERFCOUNTER_CPU(shadow_unshadow,       "shadow unshadows a page")
+PERFCOUNTER_CPU(shadow_up_pointer,     "shadow unshadow by up-pointer")
+PERFCOUNTER_CPU(shadow_unshadow_bf,    "shadow unshadow brute-force")
+PERFCOUNTER_CPU(shadow_get_page_fail,  "shadow_get_page_from_l1e failed")
+PERFCOUNTER_CPU(shadow_guest_walk,     "shadow walks guest tables")
+PERFCOUNTER_CPU(shadow_walk_cache_hit, "shadow walk-cache hits")
+PERFCOUNTER_CPU(shadow_walk_cache_miss, "shadow walk-cache misses")
 
 
 /*#endif*/ /* __XEN_PERFC_DEFN_H__ */
diff -r 896fcdd49c7f -r 684fdcfb251a xen/include/asm-x86/shadow.h
--- a/xen/include/asm-x86/shadow.h      Mon Aug 28 16:16:07 2006 -0600
+++ b/xen/include/asm-x86/shadow.h      Mon Aug 28 16:26:37 2006 -0600
@@ -1,7 +1,9 @@
 /******************************************************************************
  * include/asm-x86/shadow.h
  * 
- * Copyright (c) 2006 by XenSource Inc.
+ * Parts of this code are Copyright (c) 2006 by XenSource Inc.
+ * Parts of this code are Copyright (c) 2006 by Michael A Fetterman
+ * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
  * 
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,26 +23,608 @@
 #ifndef _XEN_SHADOW_H
 #define _XEN_SHADOW_H
 
-/* This file is just a wrapper around the new Shadow2 header,
- * providing names that must be defined in any shadow implementation. */
-
-#include <asm/shadow2.h>
+#include <public/domctl.h> 
+#include <xen/sched.h>
+#include <xen/perfc.h>
+#include <asm/flushtlb.h>
 
 /* How to make sure a page is not referred to in a shadow PT */
 /* This will need to be a for_each_vcpu if we go to per-vcpu shadows */ 
 #define shadow_drop_references(_d, _p)                      \
-    shadow2_remove_all_mappings((_d)->vcpu[0], _mfn(page_to_mfn(_p)))
+    shadow_remove_all_mappings((_d)->vcpu[0], _mfn(page_to_mfn(_p)))
 #define shadow_sync_and_drop_references(_d, _p)             \
-    shadow2_remove_all_mappings((_d)->vcpu[0], _mfn(page_to_mfn(_p)))
-
-/* Whether we are translating the domain's frame numbers for it */
-#define shadow_mode_translate(d)  shadow2_mode_translate(d)
-
-/* ...and  if so, how to add and remove entries in the mapping */
+    shadow_remove_all_mappings((_d)->vcpu[0], _mfn(page_to_mfn(_p)))
+
+/* How to add and remove entries in the p2m mapping. */
 #define guest_physmap_add_page(_d, _p, _m)                  \
-    shadow2_guest_physmap_add_page((_d), (_p), (_m))
+    shadow_guest_physmap_add_page((_d), (_p), (_m))
 #define guest_physmap_remove_page(_d, _p, _m   )            \
-    shadow2_guest_physmap_remove_page((_d), (_p), (_m))
+    shadow_guest_physmap_remove_page((_d), (_p), (_m))
+
+/* Shadow PT operation mode : shadow-mode variable in arch_domain. */
+
+#define SHM2_shift 10
+/* We're in one of the shadow modes */
+#define SHM2_enable    (1U << SHM2_shift)
+/* Refcounts based on shadow tables instead of guest tables */
+#define SHM2_refcounts (XEN_DOMCTL_SHADOW_ENABLE_REFCOUNT << SHM2_shift)
+/* Enable log dirty mode */
+#define SHM2_log_dirty (XEN_DOMCTL_SHADOW_ENABLE_LOG_DIRTY << SHM2_shift)
+/* Xen does p2m translation, not guest */
+#define SHM2_translate (XEN_DOMCTL_SHADOW_ENABLE_TRANSLATE << SHM2_shift)
+/* Xen does not steal address space from the domain for its own booking;
+ * requires VT or similar mechanisms */
+#define SHM2_external  (XEN_DOMCTL_SHADOW_ENABLE_EXTERNAL << SHM2_shift)
+
+#define shadow_mode_enabled(_d)   ((_d)->arch.shadow.mode)
+#define shadow_mode_refcounts(_d) ((_d)->arch.shadow.mode & SHM2_refcounts)
+#define shadow_mode_log_dirty(_d) ((_d)->arch.shadow.mode & SHM2_log_dirty)
+#define shadow_mode_translate(_d) ((_d)->arch.shadow.mode & SHM2_translate)
+#define shadow_mode_external(_d)  ((_d)->arch.shadow.mode & SHM2_external)
+
+/* Xen traps & emulates all reads of all page table pages:
+ *not yet supported
+ */
+#define shadow_mode_trap_reads(_d) ({ (void)(_d); 0; })
+
+// flags used in the return value of the shadow_set_lXe() functions...
+#define SHADOW_SET_CHANGED            0x1
+#define SHADOW_SET_FLUSH              0x2
+#define SHADOW_SET_ERROR              0x4
+#define SHADOW_SET_L3PAE_RECOPY       0x8
+
+// How do we tell that we have a 32-bit PV guest in a 64-bit Xen?
+#ifdef __x86_64__
+#define pv_32bit_guest(_v) 0 // not yet supported
+#else
+#define pv_32bit_guest(_v) !hvm_guest(v)
+#endif
+
+/* The shadow lock.
+ *
+ * This lock is per-domain.  It is intended to allow us to make atomic
+ * updates to the software TLB that the shadow tables provide.
+ * 
+ * Specifically, it protects:
+ *   - all changes to shadow page table pages
+ *   - the shadow hash table
+ *   - the shadow page allocator 
+ *   - all changes to guest page table pages; if/when the notion of
+ *     out-of-sync pages is added to this code, then the shadow lock is
+ *     protecting all guest page table pages which are not listed as
+ *     currently as both guest-writable and out-of-sync...
+ *     XXX -- need to think about this relative to writable page tables.
+ *   - all changes to the page_info->tlbflush_timestamp
+ *   - the page_info->count fields on shadow pages
+ *   - the shadow dirty bit array and count
+ *   - XXX
+ */
+#ifndef CONFIG_SMP
+#error shadow.h currently requires CONFIG_SMP
+#endif
+
+#define shadow_lock_init(_d)                                   \
+    do {                                                        \
+        spin_lock_init(&(_d)->arch.shadow.lock);               \
+        (_d)->arch.shadow.locker = -1;                         \
+        (_d)->arch.shadow.locker_function = "nobody";          \
+    } while (0)
+
+#define shadow_lock_is_acquired(_d)                            \
+    (current->processor == (_d)->arch.shadow.locker)
+
+#define shadow_lock(_d)                                                 \
+    do {                                                                 \
+        if ( unlikely((_d)->arch.shadow.locker == current->processor) ) \
+        {                                                                \
+            printk("Error: shadow lock held by %s\n",                   \
+                   (_d)->arch.shadow.locker_function);                  \
+            BUG();                                                       \
+        }                                                                \
+        spin_lock(&(_d)->arch.shadow.lock);                             \
+        ASSERT((_d)->arch.shadow.locker == -1);                         \
+        (_d)->arch.shadow.locker = current->processor;                  \
+        (_d)->arch.shadow.locker_function = __func__;                   \
+    } while (0)
+
+#define shadow_unlock(_d)                                              \
+    do {                                                                \
+        ASSERT((_d)->arch.shadow.locker == current->processor);        \
+        (_d)->arch.shadow.locker = -1;                                 \
+        (_d)->arch.shadow.locker_function = "nobody";                  \
+        spin_unlock(&(_d)->arch.shadow.lock);                          \
+    } while (0)
+
+/* 
+ * Levels of self-test and paranoia
+ * XXX should go in config files somewhere?  
+ */
+#define SHADOW_AUDIT_HASH           0x01  /* Check current hash bucket */
+#define SHADOW_AUDIT_HASH_FULL      0x02  /* Check every hash bucket */
+#define SHADOW_AUDIT_ENTRIES        0x04  /* Check this walk's shadows */
+#define SHADOW_AUDIT_ENTRIES_FULL   0x08  /* Check every shadow */
+#define SHADOW_AUDIT_ENTRIES_MFNS   0x10  /* Check gfn-mfn map in shadows */
+#define SHADOW_AUDIT_P2M            0x20  /* Check the p2m table */
+
+#ifdef NDEBUG
+#define SHADOW_AUDIT                   0
+#define SHADOW_AUDIT_ENABLE            0
+#else
+#define SHADOW_AUDIT                0x15  /* Basic audit of all except p2m. */
+#define SHADOW_AUDIT_ENABLE         shadow_audit_enable
+extern int shadow_audit_enable;
+#endif
+
+/* 
+ * Levels of optimization
+ * XXX should go in config files somewhere?  
+ */
+#define SHOPT_WRITABLE_HEURISTIC  0x01  /* Guess at RW PTEs via linear maps */
+#define SHOPT_EARLY_UNSHADOW      0x02  /* Unshadow l1s on fork or exit */
+
+#define SHADOW_OPTIMIZATIONS      0x03
+
+
+/* With shadow pagetables, the different kinds of address start 
+ * to get get confusing.
+ * 
+ * Virtual addresses are what they usually are: the addresses that are used 
+ * to accessing memory while the guest is running.  The MMU translates from 
+ * virtual addresses to machine addresses. 
+ * 
+ * (Pseudo-)physical addresses are the abstraction of physical memory the
+ * guest uses for allocation and so forth.  For the purposes of this code, 
+ * we can largely ignore them.
+ *
+ * Guest frame numbers (gfns) are the entries that the guest puts in its
+ * pagetables.  For normal paravirtual guests, they are actual frame numbers,
+ * with the translation done by the guest.  
+ * 
+ * Machine frame numbers (mfns) are the entries that the hypervisor puts
+ * in the shadow page tables.
+ *
+ * Elsewhere in the xen code base, the name "gmfn" is generally used to refer
+ * to a "machine frame number, from the guest's perspective", or in other
+ * words, pseudo-physical frame numbers.  However, in the shadow code, the
+ * term "gmfn" means "the mfn of a guest page"; this combines naturally with
+ * other terms such as "smfn" (the mfn of a shadow page), gl2mfn (the mfn of a
+ * guest L2 page), etc...
+ */
+
+/* With this defined, we do some ugly things to force the compiler to
+ * give us type safety between mfns and gfns and other integers.
+ * TYPE_SAFE(int foo) defines a foo_t, and _foo() and foo_x() functions 
+ * that translate beween int and foo_t.
+ * 
+ * It does have some performance cost because the types now have 
+ * a different storage attribute, so may not want it on all the time. */
+#ifndef NDEBUG
+#define TYPE_SAFETY 1
+#endif
+
+#ifdef TYPE_SAFETY
+#define TYPE_SAFE(_type,_name)                                  \
+typedef struct { _type _name; } _name##_t;                      \
+static inline _name##_t _##_name(_type n) { return (_name##_t) { n }; } \
+static inline _type _name##_x(_name##_t n) { return n._name; }
+#else
+#define TYPE_SAFE(_type,_name)                                          \
+typedef _type _name##_t;                                                \
+static inline _name##_t _##_name(_type n) { return n; }                 \
+static inline _type _name##_x(_name##_t n) { return n; }
+#endif
+
+TYPE_SAFE(unsigned long,mfn)
+#define SH_PRI_mfn "05lx"
+
+static inline int
+valid_mfn(mfn_t m)
+{
+    return VALID_MFN(mfn_x(m));
+}
+
+static inline mfn_t
+pagetable_get_mfn(pagetable_t pt)
+{
+    return _mfn(pagetable_get_pfn(pt));
+}
+
+static inline pagetable_t
+pagetable_from_mfn(mfn_t mfn)
+{
+    return pagetable_from_pfn(mfn_x(mfn));
+}
+
+static inline int
+shadow_vcpu_mode_translate(struct vcpu *v)
+{
+    // Returns true if this VCPU needs to be using the P2M table to translate
+    // between GFNs and MFNs.
+    //
+    // This is true of translated HVM domains on a vcpu which has paging
+    // enabled.  (HVM vcpu's with paging disabled are using the p2m table as
+    // its paging table, so no translation occurs in this case.)
+    //
+    return v->arch.shadow.hvm_paging_enabled;
+}
+
+
+/**************************************************************************/
+/* Mode-specific entry points into the shadow code */
+
+struct x86_emulate_ctxt;
+struct shadow_paging_mode {
+    int           (*page_fault            )(struct vcpu *v, unsigned long va,
+                                            struct cpu_user_regs *regs);
+    int           (*invlpg                )(struct vcpu *v, unsigned long va);
+    unsigned long (*gva_to_gpa            )(struct vcpu *v, unsigned long va);
+    unsigned long (*gva_to_gfn            )(struct vcpu *v, unsigned long va);
+    void          (*update_cr3            )(struct vcpu *v);
+    int           (*map_and_validate_gl1e )(struct vcpu *v, mfn_t gmfn,
+                                            void *new_guest_entry, u32 size);
+    int           (*map_and_validate_gl2e )(struct vcpu *v, mfn_t gmfn,
+                                            void *new_guest_entry, u32 size);
+    int           (*map_and_validate_gl2he)(struct vcpu *v, mfn_t gmfn,
+                                            void *new_guest_entry, u32 size);
+    int           (*map_and_validate_gl3e )(struct vcpu *v, mfn_t gmfn,
+                                            void *new_guest_entry, u32 size);
+    int           (*map_and_validate_gl4e )(struct vcpu *v, mfn_t gmfn,
+                                            void *new_guest_entry, u32 size);
+    void          (*detach_old_tables     )(struct vcpu *v);
+    int           (*x86_emulate_write     )(struct vcpu *v, unsigned long va,
+                                            void *src, u32 bytes,
+                                            struct x86_emulate_ctxt *ctxt);
+    int           (*x86_emulate_cmpxchg   )(struct vcpu *v, unsigned long va,
+                                            unsigned long old, 
+                                            unsigned long new,
+                                            unsigned int bytes,
+                                            struct x86_emulate_ctxt *ctxt);
+    int           (*x86_emulate_cmpxchg8b )(struct vcpu *v, unsigned long va,
+                                            unsigned long old_lo, 
+                                            unsigned long old_hi, 
+                                            unsigned long new_lo,
+                                            unsigned long new_hi,
+                                            struct x86_emulate_ctxt *ctxt);
+    mfn_t         (*make_monitor_table    )(struct vcpu *v);
+    void          (*destroy_monitor_table )(struct vcpu *v, mfn_t mmfn);
+#if SHADOW_OPTIMIZATIONS & SHOPT_WRITABLE_HEURISTIC
+    int           (*guess_wrmap           )(struct vcpu *v, 
+                                            unsigned long vaddr, mfn_t gmfn);
+#endif
+    /* For outsiders to tell what mode we're in */
+    unsigned int shadow_levels;
+    unsigned int guest_levels;
+};
+
+static inline int shadow_guest_paging_levels(struct vcpu *v)
+{
+    ASSERT(v->arch.shadow.mode != NULL);
+    return v->arch.shadow.mode->guest_levels;
+}
+
+/**************************************************************************/
+/* Entry points into the shadow code */
+
+/* Turning on shadow test mode */
+int shadow_test_enable(struct domain *d);
+
+/* Handler for shadow control ops: enabling and disabling shadow modes, 
+ * and log-dirty bitmap ops all happen through here. */
+int shadow_domctl(struct domain *d, 
+                   xen_domctl_shadow_op_t *sc,
+                   XEN_GUEST_HANDLE(xen_domctl_t) u_domctl);
+
+/* Call when destroying a domain */
+void shadow_teardown(struct domain *d);
+
+/* Call once all of the references to the domain have gone away */
+void shadow_final_teardown(struct domain *d);
+
+
+/* Mark a page as dirty in the bitmap */
+void sh_do_mark_dirty(struct domain *d, mfn_t gmfn);
+static inline void mark_dirty(struct domain *d, unsigned long gmfn)
+{
+    if ( shadow_mode_log_dirty(d) )
+    {
+        shadow_lock(d);
+        sh_do_mark_dirty(d, _mfn(gmfn));
+        shadow_unlock(d);
+    }
+}
+
+/* Internal version, for when the shadow lock is already held */
+static inline void sh_mark_dirty(struct domain *d, mfn_t gmfn)
+{
+    ASSERT(shadow_lock_is_acquired(d));
+    if ( shadow_mode_log_dirty(d) )
+        sh_do_mark_dirty(d, gmfn);
+}
+
+static inline int
+shadow_fault(unsigned long va, struct cpu_user_regs *regs)
+/* Called from pagefault handler in Xen, and from the HVM trap handlers
+ * for pagefaults.  Returns 1 if this fault was an artefact of the
+ * shadow code (and the guest should retry) or 0 if it is not (and the
+ * fault should be handled elsewhere or passed to the guest). */
+{
+    struct vcpu *v = current;
+    perfc_incrc(shadow_fault);
+    return v->arch.shadow.mode->page_fault(v, va, regs);
+}
+
+static inline int
+shadow_invlpg(struct vcpu *v, unsigned long va)
+/* Called when the guest requests an invlpg.  Returns 1 if the invlpg
+ * instruction should be issued on the hardware, or 0 if it's safe not
+ * to do so. */
+{
+    return v->arch.shadow.mode->invlpg(v, va);
+}
+
+static inline unsigned long
+shadow_gva_to_gpa(struct vcpu *v, unsigned long va)
+/* Called to translate a guest virtual address to what the *guest*
+ * pagetables would map it to. */
+{
+    return v->arch.shadow.mode->gva_to_gpa(v, va);
+}
+
+static inline unsigned long
+shadow_gva_to_gfn(struct vcpu *v, unsigned long va)
+/* Called to translate a guest virtual address to what the *guest*
+ * pagetables would map it to. */
+{
+    return v->arch.shadow.mode->gva_to_gfn(v, va);
+}
+
+static inline void
+shadow_update_cr3(struct vcpu *v)
+/* Updates all the things that are derived from the guest's CR3. 
+ * Called when the guest changes CR3. */
+{
+    shadow_lock(v->domain);
+    v->arch.shadow.mode->update_cr3(v);
+    shadow_unlock(v->domain);
+}
+
+
+/* Should be called after CR3 is updated.
+ * Updates vcpu->arch.cr3 and, for HVM guests, vcpu->arch.hvm_vcpu.cpu_cr3.
+ * 
+ * Also updates other state derived from CR3 (vcpu->arch.guest_vtable,
+ * shadow_vtable, etc).
+ *
+ * Uses values found in vcpu->arch.(guest_table and guest_table_user), and
+ * for HVM guests, arch.monitor_table and hvm's guest CR3.
+ *
+ * Update ref counts to shadow tables appropriately.
+ * For PAE, relocate L3 entries, if necessary, into low memory.
+ */
+static inline void update_cr3(struct vcpu *v)
+{
+    unsigned long cr3_mfn=0;
+
+    if ( shadow_mode_enabled(v->domain) )
+    {
+        shadow_update_cr3(v);
+        return;
+    }
+
+#if CONFIG_PAGING_LEVELS == 4
+    if ( !(v->arch.flags & TF_kernel_mode) )
+        cr3_mfn = pagetable_get_pfn(v->arch.guest_table_user);
+    else
+#endif
+        cr3_mfn = pagetable_get_pfn(v->arch.guest_table);
+
+    make_cr3(v, cr3_mfn);
+}
+
+extern void sh_update_paging_modes(struct vcpu *v);
+
+/* Should be called to initialise paging structures if the paging mode
+ * has changed, and when bringing up a VCPU for the first time. */
+static inline void shadow_update_paging_modes(struct vcpu *v)
+{
+    ASSERT(shadow_mode_enabled(v->domain));
+    shadow_lock(v->domain);
+    sh_update_paging_modes(v);
+    shadow_unlock(v->domain);
+}
+
+static inline void
+shadow_detach_old_tables(struct vcpu *v)
+{
+    if ( v->arch.shadow.mode )
+        v->arch.shadow.mode->detach_old_tables(v);
+}
+
+static inline mfn_t
+shadow_make_monitor_table(struct vcpu *v)
+{
+    return v->arch.shadow.mode->make_monitor_table(v);
+}
+
+static inline void
+shadow_destroy_monitor_table(struct vcpu *v, mfn_t mmfn)
+{
+    v->arch.shadow.mode->destroy_monitor_table(v, mmfn);
+}
+
+/* Validate a pagetable change from the guest and update the shadows. */
+extern int shadow_validate_guest_entry(struct vcpu *v, mfn_t gmfn,
+                                        void *new_guest_entry);
+
+/* Update the shadows in response to a pagetable write from a HVM guest */
+extern void shadow_validate_guest_pt_write(struct vcpu *v, mfn_t gmfn, 
+                                            void *entry, u32 size);
+
+/* Remove all writeable mappings of a guest frame from the shadows.
+ * Returns non-zero if we need to flush TLBs. 
+ * level and fault_addr desribe how we found this to be a pagetable;
+ * level==0 means we have some other reason for revoking write access. */
+extern int shadow_remove_write_access(struct vcpu *v, mfn_t readonly_mfn,
+                                       unsigned int level,
+                                       unsigned long fault_addr);
+
+/* Remove all mappings of the guest mfn from the shadows. 
+ * Returns non-zero if we need to flush TLBs. */
+extern int shadow_remove_all_mappings(struct vcpu *v, mfn_t target_mfn);
+
+void
+shadow_remove_all_shadows_and_parents(struct vcpu *v, mfn_t gmfn);
+/* This is a HVM page that we thing is no longer a pagetable.
+ * Unshadow it, and recursively unshadow pages that reference it. */
+
+/* Remove all shadows of the guest mfn. */
+extern void sh_remove_shadows(struct vcpu *v, mfn_t gmfn, int all);
+static inline void shadow_remove_all_shadows(struct vcpu *v, mfn_t gmfn)
+{
+    sh_remove_shadows(v, gmfn, 1);
+}
+
+/* Add a page to a domain */
+void
+shadow_guest_physmap_add_page(struct domain *d, unsigned long gfn,
+                               unsigned long mfn);
+
+/* Remove a page from a domain */
+void
+shadow_guest_physmap_remove_page(struct domain *d, unsigned long gfn,
+                                  unsigned long mfn);
+
+/*
+ * Definitions for the shadow_flags field in page_info.
+ * These flags are stored on *guest* pages...
+ * Bits 1-13 are encodings for the shadow types.
+ */
+#define PGC_SH_type_to_index(_type) ((_type) >> PGC_SH_type_shift)
+#define SHF_page_type_mask \
+    (((1u << (PGC_SH_type_to_index(PGC_SH_max_shadow) + 1u)) - 1u) - \
+     ((1u << PGC_SH_type_to_index(PGC_SH_min_shadow)) - 1u))
+
+#define SHF_L1_32   (1u << PGC_SH_type_to_index(PGC_SH_l1_32_shadow))
+#define SHF_FL1_32  (1u << PGC_SH_type_to_index(PGC_SH_fl1_32_shadow))
+#define SHF_L2_32   (1u << PGC_SH_type_to_index(PGC_SH_l2_32_shadow))
+#define SHF_L1_PAE  (1u << PGC_SH_type_to_index(PGC_SH_l1_pae_shadow))
+#define SHF_FL1_PAE (1u << PGC_SH_type_to_index(PGC_SH_fl1_pae_shadow))
+#define SHF_L2_PAE  (1u << PGC_SH_type_to_index(PGC_SH_l2_pae_shadow))
+#define SHF_L2H_PAE (1u << PGC_SH_type_to_index(PGC_SH_l2h_pae_shadow))
+#define SHF_L3_PAE  (1u << PGC_SH_type_to_index(PGC_SH_l3_pae_shadow))
+#define SHF_L1_64   (1u << PGC_SH_type_to_index(PGC_SH_l1_64_shadow))
+#define SHF_FL1_64  (1u << PGC_SH_type_to_index(PGC_SH_fl1_64_shadow))
+#define SHF_L2_64   (1u << PGC_SH_type_to_index(PGC_SH_l2_64_shadow))
+#define SHF_L3_64   (1u << PGC_SH_type_to_index(PGC_SH_l3_64_shadow))
+#define SHF_L4_64   (1u << PGC_SH_type_to_index(PGC_SH_l4_64_shadow))
+
+/* Used for hysteresis when automatically unhooking mappings on fork/exit */
+#define SHF_unhooked_mappings (1u<<31)
+
+/* 
+ * Allocation of shadow pages 
+ */
+
+/* Return the minumum acceptable number of shadow pages a domain needs */
+unsigned int shadow_min_acceptable_pages(struct domain *d);
+
+/* Set the pool of shadow pages to the required number of MB.
+ * Input will be rounded up to at least min_acceptable_shadow_pages().
+ * Returns 0 for success, 1 for failure. */
+unsigned int shadow_set_allocation(struct domain *d, 
+                                    unsigned int megabytes,
+                                    int *preempted);
+
+/* Return the size of the shadow pool, rounded up to the nearest MB */
+static inline unsigned int shadow_get_allocation(struct domain *d)
+{
+    unsigned int pg = d->arch.shadow.total_pages;
+    return ((pg >> (20 - PAGE_SHIFT))
+            + ((pg & ((1 << (20 - PAGE_SHIFT)) - 1)) ? 1 : 0));
+}
+
+/*
+ * Linked list for chaining entries in the shadow hash table. 
+ */
+struct shadow_hash_entry {
+    struct shadow_hash_entry *next;
+    mfn_t smfn;                 /* MFN of the shadow */
+#ifdef _x86_64_ /* Shorten 'n' so we don't waste a whole word on storing 't' */
+    unsigned long n:56;         /* MFN of guest PT or GFN of guest superpage */
+#else
+    unsigned long n;            /* MFN of guest PT or GFN of guest superpage */
+#endif
+    unsigned char t;            /* shadow type bits, or 0 for empty */
+};
+
+#define SHADOW_HASH_BUCKETS 251
+/* Other possibly useful primes are 509, 1021, 2039, 4093, 8191, 16381 */
+
+
+#if SHADOW_OPTIMIZATIONS & SHOPT_CACHE_WALKS
+/* Optimization: cache the results of guest walks.  This helps with MMIO
+ * and emulated writes, which tend to issue very similar walk requests
+ * repeatedly.  We keep the results of the last few walks, and blow
+ * away the cache on guest cr3 write, mode change, or page fault. */
+
+#define SH_WALK_CACHE_ENTRIES 4
+
+/* Rather than cache a guest walk, which would include mapped pointers 
+ * to pages, we cache what a TLB would remember about the walk: the 
+ * permissions and the l1 gfn */
+struct shadow_walk_cache {
+    unsigned long va;           /* The virtual address (or 0 == unused) */
+    unsigned long gfn;          /* The gfn from the effective l1e   */
+    u32 permissions;            /* The aggregated permission bits   */
+};
+#endif
+
+
+/**************************************************************************/
+/* Guest physmap (p2m) support */
+
+/* Walk another domain's P2M table, mapping pages as we go */
+extern mfn_t
+sh_gfn_to_mfn_foreign(struct domain *d, unsigned long gpfn);
+
+
+/* General conversion function from gfn to mfn */
+static inline mfn_t
+sh_gfn_to_mfn(struct domain *d, unsigned long gfn)
+{
+    if ( !shadow_mode_translate(d) )
+        return _mfn(gfn);
+    else if ( likely(current->domain == d) )
+        return _mfn(get_mfn_from_gpfn(gfn));
+    else
+        return sh_gfn_to_mfn_foreign(d, gfn);
+}
+
+// vcpu-specific version of gfn_to_mfn().  This is where we hide the dirty
+// little secret that, for hvm guests with paging disabled, nearly all of the
+// shadow code actually think that the guest is running on *untranslated* page
+// tables (which is actually domain->phys_table).
+//
+static inline mfn_t
+sh_vcpu_gfn_to_mfn(struct vcpu *v, unsigned long gfn)
+{ 
+    if ( !shadow_vcpu_mode_translate(v) )
+        return _mfn(gfn);
+    if ( likely(current->domain == v->domain) )
+        return _mfn(get_mfn_from_gpfn(gfn));
+    return sh_gfn_to_mfn_foreign(v->domain, gfn);
+}
+
+static inline unsigned long
+sh_mfn_to_gfn(struct domain *d, mfn_t mfn)
+{
+    if ( shadow_mode_translate(d) )
+        return get_gpfn_from_mfn(mfn_x(mfn));
+    else
+        return mfn_x(mfn);
+}
+
+
 
 #endif /* _XEN_SHADOW_H */
 
@@ -49,7 +633,7 @@
  * mode: C
  * c-set-style: "BSD"
  * c-basic-offset: 4
- * tab-width: 4
  * indent-tabs-mode: nil
  * End:
  */
+      
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/mm/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xen/arch/x86/mm/Makefile  Mon Aug 28 16:26:37 2006 -0600
@@ -0,0 +1,1 @@
+subdir-y += shadow
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/mm/shadow/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xen/arch/x86/mm/shadow/Makefile   Mon Aug 28 16:26:37 2006 -0600
@@ -0,0 +1,15 @@
+ifneq ($(pae),n)
+obj-$(x86_32) += common.o g2_on_s3.o g3_on_s3.o
+else
+obj-$(x86_32) += common.o g2_on_s2.o
+endif
+
+obj-$(x86_64) += common.o g4_on_s4.o g3_on_s3.o g2_on_s3.o
+
+guest_levels  = $(subst g,,$(filter g%,$(subst ., ,$(subst _, ,$(1)))))
+shadow_levels = $(subst s,,$(filter s%,$(subst ., ,$(subst _, ,$(1)))))
+shadow_defns  = -DGUEST_PAGING_LEVELS=$(call guest_levels,$(1)) \
+                -DSHADOW_PAGING_LEVELS=$(call shadow_levels,$(1))
+
+g%.o: multi.c $(HDRS) Makefile
+       $(CC) $(CFLAGS) $(call shadow_defns,$(@F)) -c $< -o $@
diff -r 896fcdd49c7f -r 684fdcfb251a xen/arch/x86/mm/shadow/common.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/xen/arch/x86/mm/shadow/common.c   Mon Aug 28 16:26:37 2006 -0600
@@ -0,0 +1,3407 @@
+/******************************************************************************
+ * arch/x86/mm/shadow/common.c
+ *
+ * Shadow code that does not need to be multiply compiled.
+ * Parts of this code are Copyright (c) 2006 by XenSource Inc.
+ * Parts of this code are Copyright (c) 2006 by Michael A Fetterman
+ * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al.
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#define SHADOW 1
+
+#include <xen/config.h>
+#include <xen/types.h>
+#include <xen/mm.h>
+#include <xen/trace.h>
+#include <xen/sched.h>
+#include <xen/perfc.h>
+#include <xen/irq.h>
+#include <xen/domain_page.h>
+#include <xen/guest_access.h>
+#include <xen/keyhandler.h>
+#include <asm/event.h>
+#include <asm/page.h>
+#include <asm/current.h>
+#include <asm/flushtlb.h>
+#include <asm/shadow.h>
+#include "private.h"
+
+#if SHADOW_AUDIT
+int shadow_audit_enable = 0;
+
+static void shadow_audit_key(unsigned char key)
+{
+    shadow_audit_enable = !shadow_audit_enable;
+    printk("%s shadow_audit_enable=%d\n",
+           __func__, shadow_audit_enable);
+}
+
+static int __init shadow_audit_key_init(void)
+{
+    register_keyhandler(
+        'O', shadow_audit_key,  "toggle shadow audits");
+    return 0;
+}
+__initcall(shadow_audit_key_init);
+#endif /* SHADOW_AUDIT */
+
+static void sh_free_log_dirty_bitmap(struct domain *d);
+
+int _shadow_mode_refcounts(struct domain *d)
+{
+    return shadow_mode_refcounts(d);
+}
+
+
+/**************************************************************************/
+/* x86 emulator support for the shadow code
+ */
+
+static int
+sh_x86_emulate_read_std(unsigned long addr,
+                         unsigned long *val,
+                         unsigned int bytes,
+                         struct x86_emulate_ctxt *ctxt)
+{
+    struct vcpu *v = current;
+    if ( hvm_guest(v) )
+    {
+        *val = 0;
+        // XXX -- this is WRONG.
+        //        It entirely ignores the permissions in the page tables.
+        //        In this case, that is only a user vs supervisor access check.
+        //
+        if ( hvm_copy(val, addr, bytes, HVM_COPY_IN) )
+        {
+#if 0
+            SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
+                           v->domain->domain_id, v->vcpu_id, 
+                           addr, *val, bytes);
+#endif
+            return X86EMUL_CONTINUE;
+        }
+
+        /* If we got here, there was nothing mapped here, or a bad GFN 
+         * was mapped here.  This should never happen: we're here because
+         * of a write fault at the end of the instruction we're emulating. */ 
+        SHADOW_PRINTK("read failed to va %#lx\n", addr);
+        return X86EMUL_PROPAGATE_FAULT;
+    }
+    else 
+    {
+        SHADOW_PRINTK("this operation is not emulated yet\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+}
+
+static int
+sh_x86_emulate_write_std(unsigned long addr,
+                          unsigned long val,
+                          unsigned int bytes,
+                          struct x86_emulate_ctxt *ctxt)
+{
+    struct vcpu *v = current;
+#if 0
+    SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
+                  v->domain->domain_id, v->vcpu_id, addr, val, bytes);
+#endif
+    if ( hvm_guest(v) )
+    {
+        // XXX -- this is WRONG.
+        //        It entirely ignores the permissions in the page tables.
+        //        In this case, that includes user vs supervisor, and
+        //        write access.
+        //
+        if ( hvm_copy(&val, addr, bytes, HVM_COPY_OUT) )
+            return X86EMUL_CONTINUE;
+
+        /* If we got here, there was nothing mapped here, or a bad GFN 
+         * was mapped here.  This should never happen: we're here because
+         * of a write fault at the end of the instruction we're emulating,
+         * which should be handled by sh_x86_emulate_write_emulated. */ 
+        SHADOW_PRINTK("write failed to va %#lx\n", addr);
+        return X86EMUL_PROPAGATE_FAULT;
+    }
+    else 
+    {
+        SHADOW_PRINTK("this operation is not emulated yet\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+}
+
+static int
+sh_x86_emulate_write_emulated(unsigned long addr,
+                               unsigned long val,
+                               unsigned int bytes,
+                               struct x86_emulate_ctxt *ctxt)
+{
+    struct vcpu *v = current;
+#if 0
+    SHADOW_PRINTK("d=%u v=%u a=%#lx v=%#lx bytes=%u\n",
+                  v->domain->domain_id, v->vcpu_id, addr, val, bytes);
+#endif
+    if ( hvm_guest(v) )
+    {
+        return v->arch.shadow.mode->x86_emulate_write(v, addr, &val, bytes, 
ctxt);
+    }
+    else 
+    {
+        SHADOW_PRINTK("this operation is not emulated yet\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+}
+
+static int 
+sh_x86_emulate_cmpxchg_emulated(unsigned long addr,
+                                 unsigned long old,
+                                 unsigned long new,
+                                 unsigned int bytes,
+                                 struct x86_emulate_ctxt *ctxt)
+{
+    struct vcpu *v = current;
+#if 0
+    SHADOW_PRINTK("d=%u v=%u a=%#lx o?=%#lx n:=%#lx bytes=%u\n",
+                   v->domain->domain_id, v->vcpu_id, addr, old, new, bytes);
+#endif
+    if ( hvm_guest(v) )
+    {
+        return v->arch.shadow.mode->x86_emulate_cmpxchg(v, addr, old, new, 
+                                                    bytes, ctxt);
+    }
+    else 
+    {
+        SHADOW_PRINTK("this operation is not emulated yet\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+}
+
+static int 
+sh_x86_emulate_cmpxchg8b_emulated(unsigned long addr,
+                                   unsigned long old_lo,
+                                   unsigned long old_hi,
+                                   unsigned long new_lo,
+                                   unsigned long new_hi,
+                                   struct x86_emulate_ctxt *ctxt)
+{
+    struct vcpu *v = current;
+#if 0
+    SHADOW_PRINTK("d=%u v=%u a=%#lx o?=%#lx:%lx n:=%#lx:%lx\n",
+                   v->domain->domain_id, v->vcpu_id, addr, old_hi, old_lo,
+                   new_hi, new_lo, ctxt);
+#endif
+    if ( hvm_guest(v) )
+    {
+        return v->arch.shadow.mode->x86_emulate_cmpxchg8b(v, addr, old_lo, 
old_hi,
+                                                      new_lo, new_hi, ctxt);
+    }
+    else 
+    {
+        SHADOW_PRINTK("this operation is not emulated yet\n");
+        return X86EMUL_UNHANDLEABLE;
+    }
+}
+
+
+struct x86_emulate_ops shadow_emulator_ops = {
+    .read_std           = sh_x86_emulate_read_std,
+    .write_std          = sh_x86_emulate_write_std,
+    .read_emulated      = sh_x86_emulate_read_std,
+    .write_emulated     = sh_x86_emulate_write_emulated,
+    .cmpxchg_emulated   = sh_x86_emulate_cmpxchg_emulated,
+    .cmpxchg8b_emulated = sh_x86_emulate_cmpxchg8b_emulated,
+};
+
+
+/**************************************************************************/
+/* Code for "promoting" a guest page to the point where the shadow code is
+ * willing to let it be treated as a guest page table.  This generally
+ * involves making sure there are no writable mappings available to the guest
+ * for this page.
+ */
+void shadow_promote(struct vcpu *v, mfn_t gmfn, u32 type)
+{
+    struct page_info *page = mfn_to_page(gmfn);
+    unsigned long type_info;
+
+    ASSERT(valid_mfn(gmfn));
+
+    /* We should never try to promote a gmfn that has writeable mappings */
+    ASSERT(shadow_remove_write_access(v, gmfn, 0, 0) == 0);
+
+    // Is the page already shadowed?
+    if ( !test_and_set_bit(_PGC_page_table, &page->count_info) )
+    {
+        // No prior shadow exists...
+
+        // Grab a type-ref.  We don't really care if we are racing with another
+        // vcpu or not, or even what kind of type we get; we just want the type
+        // count to be > 0.
+        //
+        do {
+            type_info =
+                page->u.inuse.type_info & (PGT_type_mask | PGT_va_mask);
+        } while ( !get_page_type(page, type_info) );
+
+        // Now that the type ref is non-zero, we can safely use the
+        // shadow_flags.
+        //
+        page->shadow_flags = 0;
+    }
+
+    ASSERT(!test_bit(type >> PGC_SH_type_shift, &page->shadow_flags));
+    set_bit(type >> PGC_SH_type_shift, &page->shadow_flags);
+}
+
+void shadow_demote(struct vcpu *v, mfn_t gmfn, u32 type)
+{
+    struct page_info *page = mfn_to_page(gmfn);
+
+    ASSERT(test_bit(_PGC_page_table, &page->count_info));
+    ASSERT(test_bit(type >> PGC_SH_type_shift, &page->shadow_flags));
+
+    clear_bit(type >> PGC_SH_type_shift, &page->shadow_flags);
+
+    if ( (page->shadow_flags & SHF_page_type_mask) == 0 )
+    {
+        // release the extra type ref
+        put_page_type(page);
+
+        // clear the is-a-page-table bit.
+        clear_bit(_PGC_page_table, &page->count_info);
+    }
+}
+
+/**************************************************************************/
+/* Validate a pagetable change from the guest and update the shadows.
+ * Returns a bitmask of SHADOW_SET_* flags. */
+
+static int
+__shadow_validate_guest_entry(struct vcpu *v, mfn_t gmfn, 
+                               void *entry, u32 size)
+{
+    int result = 0;
+    struct page