ia64/xen-unstable

changeset 16604:d90dbf72049c

merge with xen-unstable.hg (staging)
author Alex Williamson <alex.williamson@hp.com>
date Wed Dec 12 10:50:03 2007 -0700 (2007-12-12)
parents be02461e9810 4553bc1087d9
children 8f0cbfc478d6
files tools/python/xen/xend/server/usbif.py
line diff
     1.1 --- a/docs/misc/crashdb.txt	Wed Dec 12 10:47:54 2007 -0700
     1.2 +++ b/docs/misc/crashdb.txt	Wed Dec 12 10:50:03 2007 -0700
     1.3 @@ -5,31 +5,46 @@ Xen has a simple gdb stub for doing post
     1.4  you've crashed it, you get to poke around and find out why.  There's
     1.5  also a special key handler for making it crash, which is handy.
     1.6  
     1.7 -You need to have crash_debug=y set when compiling to enable the crash
     1.8 -debugger (so go ``export crash_debug=y; make'', or ``crash_debug=y
     1.9 -make'' or ``make crash_debug=y''), and you also need to enable it on
    1.10 -the Xen command line, by going e.g. cdb=com1.  If you need to have a
    1.11 -serial port shared between cdb and the console, try cdb=com1H.  CDB
    1.12 -will then set the high bit on every byte it sends, and only respond to
    1.13 -bytes with the high bit set.  Similarly for com2.
    1.14 -
    1.15 -The next step depends on your individual setup.  This is how to do
    1.16 -it for a normal test box in the SRG:
    1.17 +You need to have crash_debug=y set when compiling , and you also need
    1.18 +to enable it on the Xen command line, eg by gdb=com1.
    1.19  
    1.20 --- Make your test machine crash.  Either a normal panic or hitting
    1.21 -   'C-A C-A C-A %' on the serial console will do.
    1.22 --- Start gdb as ``gdb ./xen-syms''
    1.23 --- Go ``target remote serial.srg:12331'', where 12331 is the second port
    1.24 -   reported for that machine by xenuse. (In this case, the machine is
    1.25 -   bombjack)
    1.26 --- Go ``add-symbol-file vmlinux''
    1.27 --- Debug as if you had a core file
    1.28 --- When you're finished, go and reboot your test box.  Hitting 'R' on the
    1.29 -   serial console won't work.
    1.30 +If you need to have a serial port shared between gdb and the console,
    1.31 +you can use gdb=com1H.  CDB will then set the high bit on every byte
    1.32 +it sends, and only respond to bytes with the high bit set.  Similarly
    1.33 +for com2.  If you do this you will need a demultiplexing program on
    1.34 +the debugging workstation, such as perhaps tools/misc/nsplitd.
    1.35  
    1.36 -At one stage, it was sometimes possible to resume after entering the
    1.37 -debugger from the serial console.  This seems to have rotted, however,
    1.38 -and I'm not terribly interested in putting it back.
    1.39 +The next step depends on your individual setup.  This is how to do it
    1.40 +if you have a simple null modem connection between the test box and
    1.41 +the workstation, and aren't using a H/L split console:
    1.42 +
    1.43 +  * Set debug=y in Config.mk
    1.44 +  * Set crash_debug=y in xen/Rules.mk
    1.45 +  * Make the changes in the attached patch, and build.
    1.46 +  * Arrange to pass gdb=com1 as a hypervisor command line argument
    1.47 +    (I already have com1=38400,8n1 console=com1,vga sync_console)
    1.48 +    
    1.49 +  * Boot the system with minicom (or your favourite terminal program)
    1.50 +    connected from your workstation via a null modem cable in the
    1.51 +    usual way.
    1.52 +  * In minicom, give the escape character (^A by default) three times
    1.53 +    to talk to Xen (Xen prints `(XEN) *** Serial input -> Xen...').
    1.54 +  * Press % and observe the messages
    1.55 +     (XEN) '%' pressed -> trapping into debugger
    1.56 +     (XEN) GDB connection activated.
    1.57 +     (XEN) Waiting for GDB to attach...
    1.58 +  * Disconnect from minicom without allowing minicom to send any
    1.59 +    modem control sequences.
    1.60 +  * Start gdb with   gdb /path/to/build/tree/xen/xen-syms  and then
    1.61 +      (gdb) set remotebaud 38400
    1.62 +      Remote debugging using /dev/ttyS0
    1.63 +      0xff124d61 in idle_loop () at domain.c:78
    1.64 +      78              safe_halt();
    1.65 +      (gdb)
    1.66 +
    1.67 +There is code which was once intended to make it possible to resume
    1.68 +after entering the debugger.  However this does not presently work; it
    1.69 +has been nonfunctional for quite some time.
    1.70  
    1.71  As soon as you reach the debugger, we disable interrupts, the
    1.72  watchdog, and every other CPU, so the state of the world shouldn't
    1.73 @@ -44,7 +59,5 @@ Reasons why we might fail to reach the d
    1.74     you're screwed.
    1.75  -- If the page tables are wrong, you're screwed
    1.76  -- If the serial port setup is wrong, badness happens
    1.77 --- We acquire the console lock at one stage XXX this is unnecessary and
    1.78 -   stupid
    1.79  -- Obviously, the low level processor state can be screwed in any
    1.80     number of wonderful ways
     2.1 --- a/docs/misc/vtd.txt	Wed Dec 12 10:47:54 2007 -0700
     2.2 +++ b/docs/misc/vtd.txt	Wed Dec 12 10:50:03 2007 -0700
     2.3 @@ -2,7 +2,7 @@ Title   : How to do PCI Passthrough with
     2.4  Authors : Allen Kay    <allen.m.kay@intel.com>
     2.5            Weidong Han  <weidong.han@intel.com>
     2.6  Created : October-24-2007
     2.7 -Updated : October-24-2007
     2.8 +Updated : December-11-2007
     2.9  
    2.10  How to turn on VT-d in Xen
    2.11  --------------------------
    2.12 @@ -22,7 +22,7 @@ 11) "hide" pci device from dom0 as follo
    2.13  title Xen-Fedora Core (2.6.18-xen)
    2.14          root (hd0,0)
    2.15          kernel /boot/xen.gz com1=115200,8n1 console=com1 vtd=1
    2.16 -        module /boot/vmlinuz-2.6.18.8-xen root=LABEL=/ ro console=tty0 console=ttyS0,115200,8n1 pciback.hide=(01:00.0)(03:00.0) pciback.verbose_request=1 apic=debug maxcpus=1
    2.17 +        module /boot/vmlinuz-2.6.18.8-xen root=LABEL=/ ro console=tty0 console=ttyS0,115200,8n1 pciback.hide=(01:00.0)(03:00.0) pciback.verbose_request=1 apic=debug
    2.18          module /boot/initrd-2.6.18-xen.img
    2.19  
    2.20  12) reboot system
    2.21 @@ -32,6 +32,15 @@ 15) start hvm guest and use "lspci" to s
    2.22      "ifconfig" to see if IP address has been assigned to NIC devices.
    2.23  
    2.24  
    2.25 +Caveat on Conventional PCI Device Passthrough
    2.26 +---------------------------------------------
    2.27 +
    2.28 +VT-d spec specifies that all conventional PCI devices behind a
    2.29 +PCIe-to-PCI bridge have to be assigned to the same domain.
    2.30 +
    2.31 +PCIe devices do not have this restriction.
    2.32 +
    2.33 +
    2.34  VT-d Enabled Systems
    2.35  --------------------
    2.36  
    2.37 @@ -48,3 +57,4 @@ http://www.dell.com/content/products/cat
    2.38  
    2.39  - HP Compaq:  DC7800
    2.40  http://h10010.www1.hp.com/wwpc/us/en/en/WF04a/12454-12454-64287-321860-3328898.html
    2.41 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/docs/xen-api/revision-history.tex	Wed Dec 12 10:50:03 2007 -0700
     3.3 @@ -0,0 +1,20 @@
     3.4 +{ \bf Revision History}
     3.5 +
     3.6 +\begin{center}
     3.7 + \begin{tabular}{|l|l|l|l|}
     3.8 +  \hline
     3.9 +  1.0.0 & 27th April 07 & Xensource et al. &
    3.10 +   \begin{minipage}[t][.7cm]{7cm}
    3.11 +     Initial Revision
    3.12 +   \end{minipage}\\
    3.13 +  \hline
    3.14 +  1.0.1 & 10th Dec. 07 & S. Berger &
    3.15 +   \begin{minipage}[t]{7cm}
    3.16 +    \begin{flushleft}
    3.17 +     Added XSPolicy.reset\_xspolicy, VTPM.get\_other\_config,
    3.18 +     VTPM.set\_otherconfig. ACMPolicy.get\_enforced\_binary methods.
    3.19 +    \end{flushleft}
    3.20 +   \end{minipage}\\
    3.21 +  \hline
    3.22 + \end{tabular}
    3.23 +\end{center}
    3.24 \ No newline at end of file
     4.1 --- a/docs/xen-api/xenapi-coversheet.tex	Wed Dec 12 10:47:54 2007 -0700
     4.2 +++ b/docs/xen-api/xenapi-coversheet.tex	Wed Dec 12 10:50:03 2007 -0700
     4.3 @@ -17,12 +17,12 @@
     4.4  \newcommand{\coversheetlogo}{xen.eps}
     4.5  
     4.6  %% Document date
     4.7 -\newcommand{\datestring}{27th April 2007}
     4.8 +\newcommand{\datestring}{10th December 2007}
     4.9  
    4.10  \newcommand{\releasestatement}{Stable Release}
    4.11  
    4.12  %% Document revision
    4.13 -\newcommand{\revstring}{API Revision 1.0.0}
    4.14 +\newcommand{\revstring}{API Revision 1.0.1}
    4.15  
    4.16  %% Document authors
    4.17  \newcommand{\docauthors}{
     5.1 --- a/docs/xen-api/xenapi-datamodel.tex	Wed Dec 12 10:47:54 2007 -0700
     5.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Wed Dec 12 10:50:03 2007 -0700
     5.3 @@ -14735,6 +14735,45 @@ xs\_policystate
     5.4  State information about the policy. In case an error occurred, the 'xs\_err'
     5.5  field contains the error code. The 'errors' may contain further information
     5.6  about the error.
     5.7 + \vspace{0.3cm}
     5.8 +\vspace{0.3cm}
     5.9 +\vspace{0.3cm}
    5.10 +\subsubsection{RPC name:~reset\_xspolicy}
    5.11 +
    5.12 +{\bf Overview:}
    5.13 +Attempt to reset the system's policy by installing the default policy.
    5.14 +Since this function is implemented as an update to the current policy, it
    5.15 +underlies the same restrictions. This function may fail if for example
    5.16 +other domains than Domain-0 are running and use a different label than
    5.17 +Domain-0
    5.18 +
    5.19 +\noindent {\bf Signature:}
    5.20 +\begin{verbatim} xs_policystate reset_xspolicy (session_id s, xs_type type)
    5.21 +\end{verbatim}
    5.22 +
    5.23 +\noindent{\bf Arguments:}
    5.24 +
    5.25 +\vspace{0.3cm}
    5.26 +
    5.27 +\begin{tabular}{|c|c|p{7cm}|}
    5.28 + \hline
    5.29 +{\bf type} & {\bf name} & {\bf description} \\ \hline
    5.30 +{\tt xs\_type } & type & the type of policy \\ \hline
    5.31 +
    5.32 +\end{tabular}
    5.33 +
    5.34 +\vspace{0.3cm}
    5.35 +
    5.36 +
    5.37 + \noindent {\bf Return Type:}
    5.38 +{\tt
    5.39 +xs\_policystate
    5.40 +}
    5.41 +
    5.42 +
    5.43 +State information about the policy. In case an error occurred, the 'xs\_err'
    5.44 +field contains the error code. The 'errors' may contain further information
    5.45 +about the error.
    5.46  \vspace{0.3cm}
    5.47  \vspace{0.3cm}
    5.48  \vspace{0.3cm}
     6.1 --- a/docs/xen-api/xenapi.tex	Wed Dec 12 10:47:54 2007 -0700
     6.2 +++ b/docs/xen-api/xenapi.tex	Wed Dec 12 10:50:03 2007 -0700
     6.3 @@ -32,6 +32,9 @@
     6.4  % The coversheet itself
     6.5  \include{coversheet}
     6.6  
     6.7 +% The revision history
     6.8 +\include{revision-history}
     6.9 +
    6.10  % ... and off we go!
    6.11  
    6.12  \chapter{Introduction}
     7.1 --- a/tools/ioemu/hw/pass-through.c	Wed Dec 12 10:47:54 2007 -0700
     7.2 +++ b/tools/ioemu/hw/pass-through.c	Wed Dec 12 10:50:03 2007 -0700
     7.3 @@ -327,6 +327,7 @@ struct pt_dev * register_real_device(PCI
     7.4      struct pt_dev *assigned_device = NULL;
     7.5      struct pci_dev *pci_dev;
     7.6      uint8_t e_device, e_intx;
     7.7 +    struct pci_config_cf8 machine_bdf;
     7.8  
     7.9      PT_LOG("Assigning real physical device %02x:%02x.%x ...\n",
    7.10          r_bus, r_dev, r_func);
    7.11 @@ -360,13 +361,22 @@ struct pt_dev * register_real_device(PCI
    7.12      /* Issue PCIe FLR */
    7.13      pdev_flr(pci_dev);
    7.14  
    7.15 +    /* Assign device */
    7.16 +    machine_bdf.reg = 0;
    7.17 +    machine_bdf.bus = r_bus;
    7.18 +    machine_bdf.dev = r_dev;
    7.19 +    machine_bdf.func = r_func;
    7.20 +    rc = xc_assign_device(xc_handle, domid, machine_bdf.value);
    7.21 +    if ( rc < 0 )
    7.22 +        PT_LOG("Error: xc_assign_device error %d\n", rc);
    7.23 +
    7.24      /* Initialize virtualized PCI configuration (Extended 256 Bytes) */
    7.25      for ( i = 0; i < PCI_CONFIG_SIZE; i++ )
    7.26          assigned_device->dev.config[i] = pci_read_byte(pci_dev, i);
    7.27  
    7.28      /* Handle real device's MMIO/PIO BARs */
    7.29      pt_register_regions(assigned_device);
    7.30 -    
    7.31 +
    7.32      /* Bind interrupt */
    7.33      e_device = (assigned_device->dev.devfn >> 3) & 0x1f;
    7.34      e_intx = assigned_device->dev.config[0x3d]-1;
     8.1 --- a/tools/ioemu/hw/vga.c	Wed Dec 12 10:47:54 2007 -0700
     8.2 +++ b/tools/ioemu/hw/vga.c	Wed Dec 12 10:50:03 2007 -0700
     8.3 @@ -1742,6 +1742,7 @@ static CPUWriteMemoryFunc *vga_mem_write
     8.4  static void vga_save(QEMUFile *f, void *opaque)
     8.5  {
     8.6      VGAState *s = opaque;
     8.7 +    uint32_t vram_size;
     8.8  #ifdef CONFIG_BOCHS_VBE
     8.9      int i;
    8.10  #endif
    8.11 @@ -1783,17 +1784,21 @@ static void vga_save(QEMUFile *f, void *
    8.12  #else
    8.13      qemu_put_byte(f, 0);
    8.14  #endif
    8.15 +    vram_size = s->vram_size;
    8.16 +    qemu_put_be32s(f, &vram_size); 
    8.17 +    qemu_put_buffer(f, s->vram_ptr, s->vram_size); 
    8.18  }
    8.19  
    8.20  static int vga_load(QEMUFile *f, void *opaque, int version_id)
    8.21  {
    8.22      VGAState *s = opaque;
    8.23      int is_vbe, ret;
    8.24 +    uint32_t vram_size;
    8.25  #ifdef CONFIG_BOCHS_VBE
    8.26      int i;
    8.27  #endif
    8.28  
    8.29 -    if (version_id > 2)
    8.30 +    if (version_id > 3)
    8.31          return -EINVAL;
    8.32  
    8.33      if (s->pci_dev && version_id >= 2) {
    8.34 @@ -1839,6 +1844,13 @@ static int vga_load(QEMUFile *f, void *o
    8.35      if (is_vbe)
    8.36          return -EINVAL;
    8.37  #endif
    8.38 +    if (version_id >= 3) {
    8.39 +	/* people who restore old images may be lucky ... */
    8.40 +	qemu_get_be32s(f, &vram_size);
    8.41 +	if (vram_size != s->vram_size)
    8.42 +	    return -EINVAL;
    8.43 +	qemu_get_buffer(f, s->vram_ptr, s->vram_size); 
    8.44 +    }
    8.45  
    8.46      /* force refresh */
    8.47      s->graphic_mode = -1;
    8.48 @@ -2052,7 +2064,7 @@ static void vga_init(VGAState *s)
    8.49  {
    8.50      int vga_io_memory;
    8.51  
    8.52 -    register_savevm("vga", 0, 2, vga_save, vga_load, s);
    8.53 +    register_savevm("vga", 0, 3, vga_save, vga_load, s);
    8.54  
    8.55      register_ioport_write(0x3c0, 16, 1, vga_ioport_write, s);
    8.56  
     9.1 --- a/tools/libxc/xc_domain.c	Wed Dec 12 10:47:54 2007 -0700
     9.2 +++ b/tools/libxc/xc_domain.c	Wed Dec 12 10:50:03 2007 -0700
     9.3 @@ -759,7 +759,21 @@ int xc_assign_device(
     9.4      domctl.cmd = XEN_DOMCTL_assign_device;
     9.5      domctl.domain = domid;
     9.6      domctl.u.assign_device.machine_bdf = machine_bdf;
     9.7 - 
     9.8 +
     9.9 +    return do_domctl(xc_handle, &domctl);
    9.10 +}
    9.11 +
    9.12 +int xc_test_assign_device(
    9.13 +    int xc_handle,
    9.14 +    uint32_t domid,
    9.15 +    uint32_t machine_bdf)
    9.16 +{
    9.17 +    DECLARE_DOMCTL;
    9.18 +
    9.19 +    domctl.cmd = XEN_DOMCTL_test_assign_device;
    9.20 +    domctl.domain = domid;
    9.21 +    domctl.u.assign_device.machine_bdf = machine_bdf;
    9.22 +
    9.23      return do_domctl(xc_handle, &domctl);
    9.24  }
    9.25  
    10.1 --- a/tools/libxc/xenctrl.h	Wed Dec 12 10:47:54 2007 -0700
    10.2 +++ b/tools/libxc/xenctrl.h	Wed Dec 12 10:50:03 2007 -0700
    10.3 @@ -914,6 +914,10 @@ int xc_assign_device(int xc_handle,
    10.4                       uint32_t domid,
    10.5                       uint32_t machine_bdf);
    10.6  
    10.7 +int xc_test_assign_device(int xc_handle,
    10.8 +                          uint32_t domid,
    10.9 +                          uint32_t machine_bdf);
   10.10 +
   10.11  int xc_domain_memory_mapping(int xc_handle,
   10.12                               uint32_t domid,
   10.13                               unsigned long first_gfn,
    11.1 --- a/tools/libxen/include/xen/api/xen_xspolicy.h	Wed Dec 12 10:47:54 2007 -0700
    11.2 +++ b/tools/libxen/include/xen/api/xen_xspolicy.h	Wed Dec 12 10:50:03 2007 -0700
    11.3 @@ -240,6 +240,19 @@ xen_xspolicy_set_xspolicy(xen_session *s
    11.4                            bool overwrite);
    11.5  
    11.6  
    11.7 +
    11.8 +/**
    11.9 + * Attempt to reset the system's policy to the DEFAULT policy for the
   11.10 + * respective policy type. This is done by updating the system and therefore
   11.11 + * underlies the same restrictions of a policy update. This operation may
   11.12 + * for example fail if other domains than Domain-0 are running and have
   11.13 + * different labels than Domain-0.
   11.14 + */
   11.15 +bool
   11.16 +xen_xspolicy_reset_xspolicy(xen_session *session, xen_xs_policystate **result,
   11.17 +                            xs_type type);
   11.18 +
   11.19 +
   11.20  /**
   11.21   * Remove any policy from having the system booted with.
   11.22   */
    12.1 --- a/tools/libxen/src/xen_xspolicy.c	Wed Dec 12 10:47:54 2007 -0700
    12.2 +++ b/tools/libxen/src/xen_xspolicy.c	Wed Dec 12 10:50:03 2007 -0700
    12.3 @@ -225,6 +225,24 @@ xen_xspolicy_set_xspolicy(xen_session *s
    12.4  
    12.5  
    12.6  bool
    12.7 +xen_xspolicy_reset_xspolicy(xen_session *session, xen_xs_policystate **result,
    12.8 +                            xs_type type)
    12.9 +{
   12.10 +    abstract_value param_values[] =
   12.11 +        {
   12.12 +            { .type = &abstract_type_int,
   12.13 +              .u.int_val = type },
   12.14 +        };
   12.15 +
   12.16 +    abstract_type result_type = xen_xs_policystate_abstract_type_;
   12.17 +
   12.18 +    *result = NULL;
   12.19 +    XEN_CALL_("XSPolicy.reset_xspolicy");
   12.20 +    return session->ok;
   12.21 +}
   12.22 +
   12.23 +
   12.24 +bool
   12.25  xen_xspolicy_get_xspolicy(xen_session *session, xen_xs_policystate **result)
   12.26  {
   12.27      abstract_value param_values[] =
    13.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Wed Dec 12 10:47:54 2007 -0700
    13.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed Dec 12 10:50:03 2007 -0700
    13.3 @@ -560,9 +560,9 @@ static int next_bdf(char **str, int *seg
    13.4      return 1;
    13.5  }
    13.6  
    13.7 -static PyObject *pyxc_assign_device(XcObject *self,
    13.8 -                                    PyObject *args,
    13.9 -                                    PyObject *kwds)
   13.10 +static PyObject *pyxc_test_assign_device(XcObject *self,
   13.11 +                                         PyObject *args,
   13.12 +                                         PyObject *kwds)
   13.13  {
   13.14      uint32_t dom;
   13.15      char *pci_str;
   13.16 @@ -580,7 +580,7 @@ static PyObject *pyxc_assign_device(XcOb
   13.17          bdf |= (dev & 0x1f) << 11;
   13.18          bdf |= (func & 0x7) << 8;
   13.19  
   13.20 -        if ( xc_assign_device(self->xc_handle, dom, bdf) != 0 )
   13.21 +        if ( xc_test_assign_device(self->xc_handle, dom, bdf) != 0 )
   13.22              break;
   13.23  
   13.24          bdf = 0;
   13.25 @@ -1426,10 +1426,10 @@ static PyMethodDef pyxc_methods[] = {
   13.26        " value   [long]:     Value of param.\n"
   13.27        "Returns: [int] 0 on success.\n" },
   13.28  
   13.29 -     { "assign_device",
   13.30 -       (PyCFunction)pyxc_assign_device,
   13.31 +     { "test_assign_device",
   13.32 +       (PyCFunction)pyxc_test_assign_device,
   13.33         METH_VARARGS | METH_KEYWORDS, "\n"
   13.34 -       "assign device with VT-d.\n"
   13.35 +       "test device assignment with VT-d.\n"
   13.36         " dom     [int]:      Identifier of domain to build into.\n"
   13.37         " pci_str [str]:      PCI devices.\n"
   13.38         "Returns: [int] 0 on success, or device bdf that can't be assigned.\n" },
    14.1 --- a/tools/python/xen/util/acmpolicy.py	Wed Dec 12 10:47:54 2007 -0700
    14.2 +++ b/tools/python/xen/util/acmpolicy.py	Wed Dec 12 10:50:03 2007 -0700
    14.3 @@ -86,7 +86,7 @@ DEFAULT_policy = \
    14.4  "  <SecurityLabelTemplate>\n" +\
    14.5  "    <SubjectLabels bootstrap=\"SystemManagement\">\n" +\
    14.6  "      <VirtualMachineLabel>\n" +\
    14.7 -"        <Name>SystemManagement</Name>\n" +\
    14.8 +"        <Name%s>SystemManagement</Name>\n" +\
    14.9  "        <SimpleTypeEnforcementTypes>\n" +\
   14.10  "          <Type>SystemManagement</Type>\n" +\
   14.11  "        </SimpleTypeEnforcementTypes>\n" +\
   14.12 @@ -99,8 +99,11 @@ DEFAULT_policy = \
   14.13  "</SecurityPolicyDefinition>\n"
   14.14  
   14.15  
   14.16 -def get_DEFAULT_policy():
   14.17 -    return DEFAULT_policy
   14.18 +def get_DEFAULT_policy(dom0label=""):
   14.19 +    fromnode = ""
   14.20 +    if dom0label != "":
   14.21 +        fromnode = " from=\"%s\"" % dom0label
   14.22 +    return DEFAULT_policy % fromnode
   14.23  
   14.24  def initialize():
   14.25      xoptions = XendOptions.instance()
   14.26 @@ -375,6 +378,12 @@ class ACMPolicy(XSPolicy):
   14.27  
   14.28      force_default_policy = classmethod(force_default_policy)
   14.29  
   14.30 +    def get_reset_policy_xml(klass):
   14.31 +        dom0_label = security.get_ssid(0)[1]
   14.32 +        return get_DEFAULT_policy(dom0_label)
   14.33 +
   14.34 +    get_reset_policy_xml = classmethod(get_reset_policy_xml)
   14.35 +
   14.36      def __do_update_version_check(self, acmpol_new):
   14.37          acmpol_old = self
   14.38  
    15.1 --- a/tools/python/xen/util/xsm/acm/acm.py	Wed Dec 12 10:47:54 2007 -0700
    15.2 +++ b/tools/python/xen/util/xsm/acm/acm.py	Wed Dec 12 10:50:03 2007 -0700
    15.3 @@ -86,6 +86,7 @@ xmlrpc_exports = [
    15.4    'list_labels',
    15.5    'get_labeled_resources',
    15.6    'set_policy',
    15.7 +  'reset_policy',
    15.8    'get_policy',
    15.9    'activate_policy',
   15.10    'rm_bootpolicy',
   15.11 @@ -567,6 +568,20 @@ def set_policy(xs_type, xml, flags, over
   15.12          err(str(e))
   15.13  
   15.14  
   15.15 +def reset_policy():
   15.16 +    """
   15.17 +       Xend exports this function via XML-RPC
   15.18 +    """
   15.19 +    from xen.xend import XendXSPolicyAdmin
   15.20 +    xspoladmin = XendXSPolicyAdmin.XSPolicyAdminInstance()
   15.21 +    try:
   15.22 +        acmpol, rc, errors = \
   15.23 +             xspoladmin.reset_acmpolicy()
   15.24 +        return rc, base64.b64encode(errors)
   15.25 +    except Exception, e:
   15.26 +        err(str(e))
   15.27 +
   15.28 +
   15.29  def get_policy():
   15.30      """
   15.31          Xend exports this function via XML-RPC
    16.1 --- a/tools/python/xen/util/xsm/dummy/dummy.py	Wed Dec 12 10:47:54 2007 -0700
    16.2 +++ b/tools/python/xen/util/xsm/dummy/dummy.py	Wed Dec 12 10:50:03 2007 -0700
    16.3 @@ -21,6 +21,7 @@ xmlrpc_exports = [
    16.4    'list_labels',
    16.5    'get_labeled_resources',
    16.6    'set_policy',
    16.7 +  'reset_policy',
    16.8    'get_policy',
    16.9    'activate_policy',
   16.10    'rm_bootpolicy',
   16.11 @@ -102,6 +103,9 @@ def get_labeled_resources():
   16.12  def set_policy(xs_type, xml, flags, overwrite):
   16.13      err("Command not supported under xsm 'dummy' module.")
   16.14  
   16.15 +def reset_policy():
   16.16 +    err("Command not supported under xsm 'dummy' module.")
   16.17 +
   16.18  def get_policy():
   16.19      return "", 0
   16.20  
    17.1 --- a/tools/python/xen/xend/XendDevices.py	Wed Dec 12 10:47:54 2007 -0700
    17.2 +++ b/tools/python/xen/xend/XendDevices.py	Wed Dec 12 10:50:03 2007 -0700
    17.3 @@ -19,7 +19,7 @@
    17.4  # A collection of DevControllers 
    17.5  #
    17.6  
    17.7 -from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, usbif, vfbif
    17.8 +from xen.xend.server import blkif, netif, tpmif, pciif, iopif, irqif, vfbif
    17.9  from xen.xend.server.BlktapController import BlktapController
   17.10  from xen.xend.server.ConsoleController import ConsoleController
   17.11  
   17.12 @@ -41,7 +41,6 @@ class XendDevices:
   17.13          'pci': pciif.PciController,
   17.14          'ioports': iopif.IOPortsController,
   17.15          'irq': irqif.IRQController,
   17.16 -        'usb': usbif.UsbifController,
   17.17          'tap': BlktapController,
   17.18          'vfb': vfbif.VfbifController,
   17.19          'vkbd': vfbif.VkbdifController,
    18.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Dec 12 10:47:54 2007 -0700
    18.2 +++ b/tools/python/xen/xend/XendDomain.py	Wed Dec 12 10:50:03 2007 -0700
    18.3 @@ -613,13 +613,19 @@ class XendDomain:
    18.4                  if dom.getName() == DOM0_NAME:
    18.5                      continue
    18.6                  
    18.7 -                if dom._stateGet() == DOM_STATE_RUNNING:
    18.8 -                    shutdownAction = dom.info.get('on_xend_stop', 'ignore')
    18.9 -                    if shutdownAction == 'shutdown':
   18.10 -                        log.debug('Shutting down domain: %s' % dom.getName())
   18.11 -                        dom.shutdown("poweroff")
   18.12 -                    elif shutdownAction == 'suspend':
   18.13 -                        self.domain_suspend(dom.getName())
   18.14 +                try:
   18.15 +                    if dom._stateGet() == DOM_STATE_RUNNING:
   18.16 +                        shutdownAction = dom.info.get('on_xend_stop', 'ignore')
   18.17 +                        if shutdownAction == 'shutdown':
   18.18 +                            log.debug('Shutting down domain: %s' % dom.getName())
   18.19 +                            dom.shutdown("poweroff")
   18.20 +                        elif shutdownAction == 'suspend':
   18.21 +                            self.domain_suspend(dom.getName())
   18.22 +                        else:
   18.23 +                            log.debug('Domain %s continues to run.' % dom.getName())
   18.24 +                except:
   18.25 +                    log.exception('Domain %s failed to %s.' % \
   18.26 +                                  (dom.getName(), shutdownAction))
   18.27          finally:
   18.28              self.domains_lock.release()
   18.29  
    19.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Dec 12 10:47:54 2007 -0700
    19.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Wed Dec 12 10:50:03 2007 -0700
    19.3 @@ -1653,10 +1653,10 @@ class XendDomainInfo:
    19.4          # Set maximum number of vcpus in domain
    19.5          xc.domain_max_vcpus(self.domid, int(self.info['VCPUs_max']))
    19.6  
    19.7 -        # Assign devices with VT-d
    19.8 +        # Test whether the devices can be assigned with VT-d
    19.9          pci_str = str(self.info["platform"].get("pci"))
   19.10          if hvm and pci_str:
   19.11 -            bdf = xc.assign_device(self.domid, pci_str)
   19.12 +            bdf = xc.test_assign_device(self.domid, pci_str)
   19.13              if bdf != 0:
   19.14                  bus = (bdf >> 16) & 0xff
   19.15                  devfn = (bdf >> 8) & 0xff
   19.16 @@ -1880,8 +1880,6 @@ class XendDomainInfo:
   19.17  
   19.18          self._cleanupVm()
   19.19          if self.dompath is not None:
   19.20 -            if self.domid is not None:
   19.21 -                xc.domain_destroy_hook(self.domid)
   19.22              self.destroyDomain()
   19.23  
   19.24          self._cleanup_phantom_devs(paths)
   19.25 @@ -1899,6 +1897,7 @@ class XendDomainInfo:
   19.26  
   19.27          try:
   19.28              if self.domid is not None:
   19.29 +                xc.domain_destroy_hook(self.domid)
   19.30                  xc.domain_destroy(self.domid)
   19.31                  for state in DOM_STATES_OLD:
   19.32                      self.info[state] = 0
    20.1 --- a/tools/python/xen/xend/XendXSPolicy.py	Wed Dec 12 10:47:54 2007 -0700
    20.2 +++ b/tools/python/xen/xend/XendXSPolicy.py	Wed Dec 12 10:50:03 2007 -0700
    20.3 @@ -43,6 +43,7 @@ class XendXSPolicy(XendBase):
    20.4      def getFuncs(self):
    20.5          funcs = [ 'get_xstype',
    20.6                    'set_xspolicy',
    20.7 +                  'reset_xspolicy',
    20.8                    'get_xspolicy',
    20.9                    'rm_xsbootpolicy',
   20.10                    'get_resource_label',
   20.11 @@ -104,6 +105,36 @@ class XendXSPolicy(XendBase):
   20.12              raise SecurityError(-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED)
   20.13          return polstate
   20.14  
   20.15 +
   20.16 +    def reset_xspolicy(self, xstype):
   20.17 +        xstype = int(xstype)
   20.18 +        polstate = { 'xs_ref': "", 'repr'   : "", 'type'   : 0,
   20.19 +                     'flags' : 0 , 'version': 0 , 'errors' : "", 'xserr' : 0 }
   20.20 +        if xstype == xsconstants.XS_POLICY_ACM:
   20.21 +            poladmin = XSPolicyAdminInstance()
   20.22 +            try:
   20.23 +                (xspol, rc, errors) = poladmin.reset_acmpolicy()
   20.24 +                if rc != 0:
   20.25 +                    polstate.update( { 'xserr' : rc,
   20.26 +                                       'errors': base64.b64encode(errors) } )
   20.27 +                else:
   20.28 +                    ref = xspol.get_ref()
   20.29 +                    polstate = {
   20.30 +                      'xs_ref' : ref,
   20.31 +                      'flags'  : poladmin.get_policy_flags(xspol),
   20.32 +                      'type'   : xstype,
   20.33 +                      'repr'   : "",
   20.34 +                      'version': xspol.get_version(),
   20.35 +                      'errors' : base64.b64encode(errors),
   20.36 +                      'xserr'  : rc,
   20.37 +                    }
   20.38 +            except Exception, e:
   20.39 +                raise
   20.40 +        else:
   20.41 +            raise SecurityError(-xsconstants.XSERR_POLICY_TYPE_UNSUPPORTED)
   20.42 +        return polstate
   20.43 +
   20.44 +
   20.45      def activate_xspolicy(self, flags):
   20.46          flags = int(flags)
   20.47          rc = -xsconstants.XSERR_GENERAL_FAILURE
   20.48 @@ -162,6 +193,7 @@ class XendXSPolicy(XendBase):
   20.49      get_xstype      = classmethod(get_xstype)
   20.50      get_xspolicy    = classmethod(get_xspolicy)
   20.51      set_xspolicy    = classmethod(set_xspolicy)
   20.52 +    reset_xspolicy  = classmethod(reset_xspolicy)
   20.53      rm_xsbootpolicy = classmethod(rm_xsbootpolicy)
   20.54      set_resource_label = classmethod(set_resource_label)
   20.55      get_resource_label = classmethod(get_resource_label)
    21.1 --- a/tools/python/xen/xend/XendXSPolicyAdmin.py	Wed Dec 12 10:47:54 2007 -0700
    21.2 +++ b/tools/python/xen/xend/XendXSPolicyAdmin.py	Wed Dec 12 10:50:03 2007 -0700
    21.3 @@ -179,6 +179,23 @@ class XSPolicyAdmin:
    21.4              self.xsobjs[ref]  = acmpol
    21.5          return (acmpol, xsconstants.XSERR_SUCCESS, errors)
    21.6  
    21.7 +
    21.8 +    def reset_acmpolicy(self):
    21.9 +        """
   21.10 +           Attempt to reset the system's policy by udating it with
   21.11 +           the DEFAULT policy.
   21.12 +        """
   21.13 +        from xen.xend import XendDomain
   21.14 +        domains = XendDomain.instance()
   21.15 +        try:
   21.16 +            domains.domains_lock.acquire()
   21.17 +            xml = ACMPolicy.get_reset_policy_xml()
   21.18 +            flags = xsconstants.XS_INST_BOOT | xsconstants.XS_INST_LOAD
   21.19 +            return self.__add_acmpolicy_to_system(xml, flags, True)
   21.20 +        finally:
   21.21 +            domains.domains_lock.release()
   21.22 +
   21.23 +
   21.24      def make_boot_policy(self, acmpol):
   21.25          if acmpol.is_default_policy():
   21.26              return xsconstants.XSERR_SUCCESS
    22.1 --- a/tools/python/xen/xend/server/usbif.py	Wed Dec 12 10:47:54 2007 -0700
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,42 +0,0 @@
    22.4 -#============================================================================
    22.5 -# This library is free software; you can redistribute it and/or
    22.6 -# modify it under the terms of version 2.1 of the GNU Lesser General Public
    22.7 -# License as published by the Free Software Foundation.
    22.8 -#
    22.9 -# This library is distributed in the hope that it will be useful,
   22.10 -# but WITHOUT ANY WARRANTY; without even the implied warranty of
   22.11 -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   22.12 -# Lesser General Public License for more details.
   22.13 -#
   22.14 -# You should have received a copy of the GNU Lesser General Public
   22.15 -# License along with this library; if not, write to the Free Software
   22.16 -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22.17 -#============================================================================
   22.18 -# Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
   22.19 -# Copyright (C) 2004 Intel Research Cambridge
   22.20 -# Copyright (C) 2004 Mark Williamson <mark.williamson@cl.cam.ac.uk>
   22.21 -# Copyright (C) 2005 XenSource Ltd
   22.22 -#============================================================================
   22.23 -
   22.24 -
   22.25 -"""Support for virtual USB hubs.
   22.26 -"""
   22.27 -
   22.28 -from xen.xend.server.DevController import DevController
   22.29 -
   22.30 -
   22.31 -class UsbifController(DevController):
   22.32 -    """USB device interface controller. Handles all USB devices
   22.33 -    for a domain.
   22.34 -    """
   22.35 -    
   22.36 -    def __init__(self, vm):
   22.37 -        """Create a USB device controller.
   22.38 -        """
   22.39 -        DevController.__init__(self, vm)
   22.40 -
   22.41 -
   22.42 -    def getDeviceDetails(self, _):
   22.43 -        """@see DevController.getDeviceDetails"""
   22.44 -
   22.45 -        return (self.allocateDeviceID(), {}, {})
    23.1 --- a/tools/python/xen/xm/create.py	Wed Dec 12 10:47:54 2007 -0700
    23.2 +++ b/tools/python/xen/xm/create.py	Wed Dec 12 10:50:03 2007 -0700
    23.3 @@ -309,11 +309,6 @@ gopts.var('irq', val='IRQ',
    23.4           For example 'irq=7'.
    23.5           This option may be repeated to add more than one IRQ.""")
    23.6  
    23.7 -gopts.var('usbport', val='PATH',
    23.8 -          fn=append_value, default=[],
    23.9 -          use="""Add a physical USB port to a domain, as specified by the path
   23.10 -          to that port.  This option may be repeated to add more than one port.""")
   23.11 -
   23.12  gopts.var('vfb', val="type={vnc,sdl},vncunused=1,vncdisplay=N,vnclisten=ADDR,display=DISPLAY,xauthority=XAUTHORITY,vncpasswd=PASSWORD",
   23.13            fn=append_value, default=[],
   23.14            use="""Make the domain a framebuffer backend.
   23.15 @@ -617,11 +612,6 @@ def configure_irq(config_devs, vals):
   23.16          config_irq = ['irq', ['irq', irq]]
   23.17          config_devs.append(['device', config_irq])
   23.18  
   23.19 -def configure_usb(config_devs, vals):
   23.20 -    for path in vals.usbport:
   23.21 -        config_usb = ['usbport', ['path', path]]
   23.22 -        config_devs.append(['device', config_usb])
   23.23 -
   23.24  def configure_vfbs(config_devs, vals):
   23.25      for f in vals.vfb:
   23.26          d = comma_sep_kv_to_dict(f)
   23.27 @@ -800,7 +790,6 @@ def make_config(vals):
   23.28      configure_ioports(config_devs, vals)
   23.29      configure_irq(config_devs, vals)
   23.30      configure_vifs(config_devs, vals)
   23.31 -    configure_usb(config_devs, vals)
   23.32      configure_vtpm(config_devs, vals)
   23.33      configure_vfbs(config_devs, vals)
   23.34      configure_security(config, vals)
    24.1 --- a/tools/python/xen/xm/main.py	Wed Dec 12 10:47:54 2007 -0700
    24.2 +++ b/tools/python/xen/xm/main.py	Wed Dec 12 10:50:03 2007 -0700
    24.3 @@ -1833,7 +1833,7 @@ def xm_debug_keys(args):
    24.4  def xm_top(args):
    24.5      arg_check(args, "top", 0)
    24.6  
    24.7 -    os.execvp('xentop', ['xentop'])
    24.8 +    os.system('xentop')
    24.9  
   24.10  def xm_dmesg(args):
   24.11      arg_check(args, "dmesg", 0, 1)
    25.1 --- a/tools/python/xen/xm/resetpolicy.py	Wed Dec 12 10:47:54 2007 -0700
    25.2 +++ b/tools/python/xen/xm/resetpolicy.py	Wed Dec 12 10:50:03 2007 -0700
    25.3 @@ -26,40 +26,6 @@ from xen.xm.main import server
    25.4  from xen.util import xsconstants
    25.5  from xen.util.acmpolicy import ACMPolicy
    25.6  
    25.7 -DOM0_UUID = "00000000-0000-0000-0000-000000000000"
    25.8 -
    25.9 -DEFAULT_policy_template = \
   25.10 -"<?xml version=\"1.0\" ?>" +\
   25.11 -"<SecurityPolicyDefinition xmlns=\"http://www.ibm.com\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.ibm.com ../../security_policy.xsd\">" +\
   25.12 -"  <PolicyHeader>" +\
   25.13 -"    <PolicyName>DEFAULT</PolicyName>" +\
   25.14 -"    <Version>1.0</Version>" +\
   25.15 -"  </PolicyHeader>" +\
   25.16 -"  <SimpleTypeEnforcement>" +\
   25.17 -"    <SimpleTypeEnforcementTypes>" +\
   25.18 -"      <Type>SystemManagement</Type>" +\
   25.19 -"    </SimpleTypeEnforcementTypes>" +\
   25.20 -"  </SimpleTypeEnforcement>" +\
   25.21 -"  <ChineseWall>" +\
   25.22 -"    <ChineseWallTypes>" +\
   25.23 -"      <Type>SystemManagement</Type>" +\
   25.24 -"    </ChineseWallTypes>" +\
   25.25 -"  </ChineseWall>" +\
   25.26 -"  <SecurityLabelTemplate>" +\
   25.27 -"    <SubjectLabels bootstrap=\"SystemManagement\">" +\
   25.28 -"      <VirtualMachineLabel>" +\
   25.29 -"        <Name%s>SystemManagement</Name>" +\
   25.30 -"        <SimpleTypeEnforcementTypes>" +\
   25.31 -"          <Type>SystemManagement</Type>" +\
   25.32 -"        </SimpleTypeEnforcementTypes>" +\
   25.33 -"        <ChineseWallTypes>" +\
   25.34 -"          <Type/>" +\
   25.35 -"        </ChineseWallTypes>" +\
   25.36 -"      </VirtualMachineLabel>" +\
   25.37 -"    </SubjectLabels>" +\
   25.38 -"  </SecurityLabelTemplate>" +\
   25.39 -"</SecurityPolicyDefinition>"
   25.40 -
   25.41  
   25.42  def help():
   25.43      return """
   25.44 @@ -69,16 +35,6 @@ def help():
   25.45      since otherwise this operation will fail.
   25.46      """
   25.47  
   25.48 -def get_reset_policy_xml(dom0_seclab):
   25.49 -    if dom0_seclab == "":
   25.50 -        return DEFAULT_policy_template % ""
   25.51 -    else:
   25.52 -        poltyp, policy, label = dom0_seclab.split(":")
   25.53 -        if label != "SystemManagement":
   25.54 -            return DEFAULT_policy_template % \
   25.55 -                   (" from=\"%s\"" % label)
   25.56 -        else:
   25.57 -            return DEFAULT_policy_template % ""
   25.58  
   25.59  def resetpolicy():
   25.60      msg = None
   25.61 @@ -99,13 +55,8 @@ def resetpolicy():
   25.62             not acmpol.is_default_policy():
   25.63              msg = "Old policy not found in bootloader file."
   25.64  
   25.65 -        seclab = server.xenapi.VM.get_security_label(DOM0_UUID)
   25.66 -        xml = get_reset_policy_xml(seclab)
   25.67          try:
   25.68 -            policystate = server.xenapi.XSPolicy.set_xspolicy(xs_type,
   25.69 -                                                              xml,
   25.70 -                                                              flags,
   25.71 -                                                              True)
   25.72 +            policystate = server.xenapi.XSPolicy.reset_xspolicy(xs_type)
   25.73          except Exception, e:
   25.74              raise security.XSMError("An error occurred resetting the "
   25.75                                      "policy: %s" % str(e))
   25.76 @@ -130,14 +81,7 @@ def resetpolicy():
   25.77             not acmpol.is_default_policy():
   25.78              msg = "Old policy not found in bootloader file."
   25.79  
   25.80 -        seclab = server.xend.security.get_domain_label(0)
   25.81 -        if seclab[0] == '\'':
   25.82 -            seclab =  seclab[1:]
   25.83 -        xml = get_reset_policy_xml(seclab)
   25.84 -        rc, errors = server.xend.security.set_policy(xs_type,
   25.85 -                                                     xml,
   25.86 -                                                     flags,
   25.87 -                                                     True)
   25.88 +        rc, errors = server.xend.security.reset_policy()
   25.89          if rc != xsconstants.XSERR_SUCCESS:
   25.90              raise security.XSMError("Could not reset the system's policy. "
   25.91                                      "Try to halt all guests.")
    26.1 --- a/xen/arch/x86/domctl.c	Wed Dec 12 10:47:54 2007 -0700
    26.2 +++ b/xen/arch/x86/domctl.c	Wed Dec 12 10:50:03 2007 -0700
    26.3 @@ -525,10 +525,31 @@ long arch_do_domctl(
    26.4      }
    26.5      break;
    26.6  
    26.7 +    case XEN_DOMCTL_test_assign_device:
    26.8 +    {
    26.9 +        u8 bus, devfn;
   26.10 +
   26.11 +        ret = -EINVAL;
   26.12 +        if ( !vtd_enabled )
   26.13 +            break;
   26.14 +
   26.15 +        bus = (domctl->u.assign_device.machine_bdf >> 16) & 0xff;
   26.16 +        devfn = (domctl->u.assign_device.machine_bdf >> 8) & 0xff;
   26.17 +
   26.18 +        if ( device_assigned(bus, devfn) )
   26.19 +        {
   26.20 +            gdprintk(XENLOG_ERR, "XEN_DOMCTL_test_assign_device: "
   26.21 +                     "%x:%x:%x already assigned\n",
   26.22 +                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
   26.23 +            break;
   26.24 +        }
   26.25 +        ret = 0;
   26.26 +    }
   26.27 +    break;
   26.28 +
   26.29      case XEN_DOMCTL_assign_device:
   26.30      {
   26.31          struct domain *d;
   26.32 -        struct hvm_iommu *hd;
   26.33          u8 bus, devfn;
   26.34  
   26.35          ret = -EINVAL;
   26.36 @@ -541,7 +562,6 @@ long arch_do_domctl(
   26.37                  "XEN_DOMCTL_assign_device: get_domain_by_id() failed\n");
   26.38              break;
   26.39          }
   26.40 -        hd = domain_hvm_iommu(d);
   26.41          bus = (domctl->u.assign_device.machine_bdf >> 16) & 0xff;
   26.42          devfn = (domctl->u.assign_device.machine_bdf >> 8) & 0xff;
   26.43  
   26.44 @@ -549,7 +569,7 @@ long arch_do_domctl(
   26.45          {
   26.46              gdprintk(XENLOG_ERR, "XEN_DOMCTL_assign_device: "
   26.47                       "%x:%x:%x already assigned\n",
   26.48 -                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); 
   26.49 +                     bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
   26.50              break;
   26.51          }
   26.52  
    27.1 --- a/xen/arch/x86/gdbstub.c	Wed Dec 12 10:47:54 2007 -0700
    27.2 +++ b/xen/arch/x86/gdbstub.c	Wed Dec 12 10:50:03 2007 -0700
    27.3 @@ -71,18 +71,20 @@ gdb_arch_read_reg(unsigned long regnum, 
    27.4      gdb_send_reply("", ctx);
    27.5  }
    27.6  
    27.7 -/* Like copy_from_user, but safe to call with interrupts disabled.
    27.8 -   Trust me, and don't look behind the curtain. */
    27.9 +/*
   27.10 + * Use __copy_*_user to make us page-fault safe, but not otherwise restrict
   27.11 + * our access to the full virtual address space.
   27.12 + */
   27.13  unsigned int
   27.14  gdb_arch_copy_from_user(void *dest, const void *src, unsigned len)
   27.15  {
   27.16 -    return copy_from_user(dest, src, len);
   27.17 +    return __copy_from_user(dest, src, len);
   27.18  }
   27.19  
   27.20  unsigned int 
   27.21  gdb_arch_copy_to_user(void *dest, const void *src, unsigned len)
   27.22  {
   27.23 -    return copy_to_user(dest, src, len);
   27.24 +    return __copy_to_user(dest, src, len);
   27.25  }
   27.26  
   27.27  void 
    28.1 --- a/xen/arch/x86/hvm/i8254.c	Wed Dec 12 10:47:54 2007 -0700
    28.2 +++ b/xen/arch/x86/hvm/i8254.c	Wed Dec 12 10:50:03 2007 -0700
    28.3 @@ -501,6 +501,8 @@ void pit_init(struct vcpu *v, unsigned l
    28.4      /* Some sub-functions assert that they are called with the lock held. */
    28.5      spin_lock(&pit->lock);
    28.6  
    28.7 +    pit->pt0.source = PTSRC_isa;
    28.8 +
    28.9      register_portio_handler(v->domain, PIT_BASE, 4, handle_pit_io);
   28.10      register_portio_handler(v->domain, 0x61, 1, handle_speaker_io);
   28.11      ticks_per_sec(v) = cpu_khz * (int64_t)1000;
    29.1 --- a/xen/arch/x86/hvm/irq.c	Wed Dec 12 10:47:54 2007 -0700
    29.2 +++ b/xen/arch/x86/hvm/irq.c	Wed Dec 12 10:50:03 2007 -0700
    29.3 @@ -347,30 +347,6 @@ struct hvm_intack hvm_vcpu_ack_pending_i
    29.4      return intack;
    29.5  }
    29.6  
    29.7 -int get_isa_irq_vector(struct vcpu *v, int isa_irq, enum hvm_intsrc src)
    29.8 -{
    29.9 -    unsigned int gsi = hvm_isa_irq_to_gsi(isa_irq);
   29.10 -
   29.11 -    if ( src == hvm_intsrc_pic )
   29.12 -        return (v->domain->arch.hvm_domain.vpic[isa_irq >> 3].irq_base
   29.13 -                + (isa_irq & 7));
   29.14 -
   29.15 -    ASSERT(src == hvm_intsrc_lapic);
   29.16 -    return domain_vioapic(v->domain)->redirtbl[gsi].fields.vector;
   29.17 -}
   29.18 -
   29.19 -int is_isa_irq_masked(struct vcpu *v, int isa_irq)
   29.20 -{
   29.21 -    unsigned int gsi = hvm_isa_irq_to_gsi(isa_irq);
   29.22 -
   29.23 -    if ( is_lvtt(v, isa_irq) )
   29.24 -        return !is_lvtt_enabled(v);
   29.25 -
   29.26 -    return ((v->domain->arch.hvm_domain.vpic[isa_irq >> 3].imr &
   29.27 -             (1 << (isa_irq & 7))) &&
   29.28 -            domain_vioapic(v->domain)->redirtbl[gsi].fields.mask);
   29.29 -}
   29.30 -
   29.31  int hvm_local_events_need_delivery(struct vcpu *v)
   29.32  {
   29.33      struct hvm_intack intack;
    30.1 --- a/xen/arch/x86/hvm/mtrr.c	Wed Dec 12 10:47:54 2007 -0700
    30.2 +++ b/xen/arch/x86/hvm/mtrr.c	Wed Dec 12 10:50:03 2007 -0700
    30.3 @@ -769,3 +769,83 @@ int32_t hvm_set_mem_pinned_cacheattr(
    30.4  
    30.5      return 0;
    30.6  }
    30.7 +
    30.8 +static int hvm_save_mtrr_msr(struct domain *d, hvm_domain_context_t *h)
    30.9 +{
   30.10 +    int i;
   30.11 +    struct vcpu *v;
   30.12 +    struct hvm_hw_mtrr hw_mtrr;
   30.13 +    struct mtrr_state *mtrr_state;
   30.14 +    /* save mtrr&pat */
   30.15 +    for_each_vcpu(d, v)
   30.16 +    {
   30.17 +        mtrr_state = &v->arch.hvm_vcpu.mtrr;
   30.18 +
   30.19 +        hw_mtrr.msr_pat_cr = v->arch.hvm_vcpu.pat_cr;
   30.20 +
   30.21 +        hw_mtrr.msr_mtrr_def_type = mtrr_state->def_type
   30.22 +                                | (mtrr_state->enabled << 10);
   30.23 +        hw_mtrr.msr_mtrr_cap = mtrr_state->mtrr_cap;
   30.24 +
   30.25 +        for ( i = 0; i < MTRR_VCNT; i++ )
   30.26 +        {
   30.27 +            /* save physbase */
   30.28 +            hw_mtrr.msr_mtrr_var[i*2] =
   30.29 +                ((uint64_t*)mtrr_state->var_ranges)[i*2];
   30.30 +            /* save physmask */
   30.31 +            hw_mtrr.msr_mtrr_var[i*2+1] =
   30.32 +                ((uint64_t*)mtrr_state->var_ranges)[i*2+1];
   30.33 +        }
   30.34 +
   30.35 +        for ( i = 0; i < NUM_FIXED_MSR; i++ )
   30.36 +            hw_mtrr.msr_mtrr_fixed[i] =
   30.37 +                ((uint64_t*)mtrr_state->fixed_ranges)[i];
   30.38 +
   30.39 +        if ( hvm_save_entry(MTRR, v->vcpu_id, h, &hw_mtrr) != 0 )
   30.40 +            return 1;
   30.41 +    }
   30.42 +    return 0;
   30.43 +}
   30.44 +
   30.45 +static int hvm_load_mtrr_msr(struct domain *d, hvm_domain_context_t *h)
   30.46 +{
   30.47 +    int vcpuid, i;
   30.48 +    struct vcpu *v;
   30.49 +    struct mtrr_state *mtrr_state;
   30.50 +    struct hvm_hw_mtrr hw_mtrr;
   30.51 +
   30.52 +    vcpuid = hvm_load_instance(h);
   30.53 +    if ( vcpuid > MAX_VIRT_CPUS || (v = d->vcpu[vcpuid]) == NULL )
   30.54 +    {
   30.55 +        gdprintk(XENLOG_ERR, "HVM restore: domain has no vcpu %u\n", vcpuid);
   30.56 +        return -EINVAL;
   30.57 +    }
   30.58 +
   30.59 +    if ( hvm_load_entry(MTRR, h, &hw_mtrr) != 0 )
   30.60 +        return -EINVAL;
   30.61 +
   30.62 +    mtrr_state = &v->arch.hvm_vcpu.mtrr;
   30.63 +
   30.64 +    pat_msr_set(&v->arch.hvm_vcpu.pat_cr, hw_mtrr.msr_pat_cr);
   30.65 +
   30.66 +    mtrr_state->mtrr_cap = hw_mtrr.msr_mtrr_cap;
   30.67 +
   30.68 +    for ( i = 0; i < NUM_FIXED_MSR; i++ )
   30.69 +        mtrr_fix_range_msr_set(mtrr_state, i, hw_mtrr.msr_mtrr_fixed[i]);
   30.70 +
   30.71 +    for ( i = 0; i < MTRR_VCNT; i++ )
   30.72 +    {
   30.73 +        mtrr_var_range_msr_set(mtrr_state,
   30.74 +                MTRRphysBase_MSR(i), hw_mtrr.msr_mtrr_var[i*2]);
   30.75 +        mtrr_var_range_msr_set(mtrr_state,
   30.76 +                MTRRphysMask_MSR(i), hw_mtrr.msr_mtrr_var[i*2+1]);
   30.77 +    }
   30.78 +
   30.79 +    mtrr_def_type_msr_set(mtrr_state, hw_mtrr.msr_mtrr_def_type);
   30.80 +
   30.81 +    v->arch.hvm_vcpu.mtrr.is_initialized = 1;
   30.82 +    return 0;
   30.83 +}
   30.84 +
   30.85 +HVM_REGISTER_SAVE_RESTORE(MTRR, hvm_save_mtrr_msr, hvm_load_mtrr_msr,
   30.86 +                          1, HVMSR_PER_VCPU);
    31.1 --- a/xen/arch/x86/hvm/rtc.c	Wed Dec 12 10:47:54 2007 -0700
    31.2 +++ b/xen/arch/x86/hvm/rtc.c	Wed Dec 12 10:50:03 2007 -0700
    31.3 @@ -42,14 +42,6 @@ static void rtc_periodic_cb(struct vcpu 
    31.4      spin_unlock(&s->lock);
    31.5  }
    31.6  
    31.7 -int is_rtc_periodic_irq(void *opaque)
    31.8 -{
    31.9 -    RTCState *s = opaque;
   31.10 -
   31.11 -    return !(s->hw.cmos_data[RTC_REG_C] & RTC_AF || 
   31.12 -             s->hw.cmos_data[RTC_REG_C] & RTC_UF);
   31.13 -}
   31.14 -
   31.15  /* Enable/configure/disable the periodic timer based on the RTC_PIE and
   31.16   * RTC_RATE_SELECT settings */
   31.17  static void rtc_timer_update(RTCState *s)
   31.18 @@ -488,6 +480,8 @@ void rtc_init(struct vcpu *v, int base)
   31.19  
   31.20      spin_lock_init(&s->lock);
   31.21  
   31.22 +    s->pt.source = PTSRC_isa;
   31.23 +
   31.24      s->hw.cmos_data[RTC_REG_A] = RTC_REF_CLCK_32KHZ | 6; /* ~1kHz */
   31.25      s->hw.cmos_data[RTC_REG_B] = RTC_24H;
   31.26      s->hw.cmos_data[RTC_REG_C] = 0;
    32.1 --- a/xen/arch/x86/hvm/vioapic.c	Wed Dec 12 10:47:54 2007 -0700
    32.2 +++ b/xen/arch/x86/hvm/vioapic.c	Wed Dec 12 10:50:03 2007 -0700
    32.3 @@ -300,7 +300,7 @@ static uint32_t ioapic_get_delivery_bitm
    32.4  static inline int pit_channel0_enabled(void)
    32.5  {
    32.6      PITState *pit = &current->domain->arch.hvm_domain.pl_time.vpit;
    32.7 -    return pit->pt0.enabled;
    32.8 +    return pt_active(&pit->pt0);
    32.9  }
   32.10  
   32.11  static void vioapic_deliver(struct hvm_hw_vioapic *vioapic, int irq)
    33.1 --- a/xen/arch/x86/hvm/vlapic.c	Wed Dec 12 10:47:54 2007 -0700
    33.2 +++ b/xen/arch/x86/hvm/vlapic.c	Wed Dec 12 10:50:03 2007 -0700
    33.3 @@ -68,9 +68,6 @@ static unsigned int vlapic_lvt_mask[VLAP
    33.4  #define APIC_DEST_NOSHORT                0x0
    33.5  #define APIC_DEST_MASK                   0x800
    33.6  
    33.7 -#define vlapic_lvt_enabled(vlapic, lvt_type)                    \
    33.8 -    (!(vlapic_get_reg(vlapic, lvt_type) & APIC_LVT_MASKED))
    33.9 -
   33.10  #define vlapic_lvt_vector(vlapic, lvt_type)                     \
   33.11      (vlapic_get_reg(vlapic, lvt_type) & APIC_VECTOR_MASK)
   33.12  
   33.13 @@ -932,6 +929,8 @@ int vlapic_init(struct vcpu *v)
   33.14  
   33.15      HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "%d", v->vcpu_id);
   33.16  
   33.17 +    vlapic->pt.source = PTSRC_lapic;
   33.18 +
   33.19  #ifdef __i386__
   33.20      /* 32-bit VMX may be limited to 32-bit physical addresses. */
   33.21      if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
   33.22 @@ -974,18 +973,3 @@ void vlapic_destroy(struct vcpu *v)
   33.23      unmap_domain_page_global(vlapic->regs);
   33.24      free_domheap_page(vlapic->regs_page);
   33.25  }
   33.26 -
   33.27 -int is_lvtt(struct vcpu *v, int vector)
   33.28 -{
   33.29 -    return vcpu_vlapic(v)->pt.enabled &&
   33.30 -           vector == vlapic_lvt_vector(vcpu_vlapic(v), APIC_LVTT);
   33.31 -}
   33.32 -
   33.33 -int is_lvtt_enabled(struct vcpu *v)
   33.34 -{
   33.35 -    if ( unlikely(!vlapic_enabled(vcpu_vlapic(v))) ||
   33.36 -            !vlapic_lvt_enabled(vcpu_vlapic(v), APIC_LVTT)) 
   33.37 -        return 0;
   33.38 -
   33.39 -    return 1;
   33.40 -}
    34.1 --- a/xen/arch/x86/hvm/vmx/vtd/dmar.c	Wed Dec 12 10:47:54 2007 -0700
    34.2 +++ b/xen/arch/x86/hvm/vmx/vtd/dmar.c	Wed Dec 12 10:50:03 2007 -0700
    34.3 @@ -30,7 +30,6 @@
    34.4  #include "pci-direct.h"
    34.5  #include "pci_regs.h"
    34.6  
    34.7 -#define VTDPREFIX
    34.8  int vtd_enabled;
    34.9  boolean_param("vtd", vtd_enabled);
   34.10  
    35.1 --- a/xen/arch/x86/hvm/vmx/vtd/intel-iommu.c	Wed Dec 12 10:47:54 2007 -0700
    35.2 +++ b/xen/arch/x86/hvm/vmx/vtd/intel-iommu.c	Wed Dec 12 10:50:03 2007 -0700
    35.3 @@ -37,7 +37,6 @@
    35.4  
    35.5  #define domain_iommu_domid(d) ((d)->arch.hvm_domain.hvm_iommu.iommu_domid)
    35.6  
    35.7 -#define VTDPREFIX
    35.8  extern void print_iommu_regs(struct acpi_drhd_unit *drhd);
    35.9  extern void print_vtd_entries(struct domain *d, int bus, int devfn,
   35.10                                unsigned long gmfn);
   35.11 @@ -954,7 +953,7 @@ struct iommu *iommu_alloc(void *hw_data)
   35.12  
   35.13      set_fixmap_nocache(FIX_IOMMU_REGS_BASE_0 + nr_iommus, drhd->address);
   35.14      iommu->reg = (void *) fix_to_virt(FIX_IOMMU_REGS_BASE_0 + nr_iommus);
   35.15 -    dprintk(XENLOG_ERR VTDPREFIX,
   35.16 +    dprintk(XENLOG_INFO VTDPREFIX,
   35.17              "iommu_alloc: iommu->reg = %p drhd->address = %lx\n",
   35.18              iommu->reg, drhd->address);
   35.19      nr_iommus++;
   35.20 @@ -1058,7 +1057,7 @@ static int domain_context_mapping_one(
   35.21  
   35.22      if ( context_present(*context) )
   35.23      {
   35.24 -        gdprintk(XENLOG_INFO VTDPREFIX,
   35.25 +        gdprintk(XENLOG_WARNING VTDPREFIX,
   35.26                   "domain_context_mapping_one:context present:bdf=%x:%x:%x\n",
   35.27                   bus, PCI_SLOT(devfn), PCI_FUNC(devfn));
   35.28          return 0;
   35.29 @@ -1097,7 +1096,7 @@ static int domain_context_mapping_one(
   35.30      iommu_flush_cache_entry(iommu, context);
   35.31  
   35.32      gdprintk(XENLOG_INFO VTDPREFIX,
   35.33 -             "context_mapping_one-%x:%x:%x-*context=%"PRIx64":%"PRIx64
   35.34 +             "domain_context_mapping_one-%x:%x:%x-*context=%"PRIx64":%"PRIx64
   35.35               " hd->pgd=%p\n",
   35.36               bus, PCI_SLOT(devfn), PCI_FUNC(devfn),
   35.37               context->hi, context->lo, hd->pgd);
   35.38 @@ -1198,14 +1197,11 @@ static int domain_context_mapping(
   35.39              PCI_FUNC(pdev->devfn), PCI_SUBORDINATE_BUS);
   35.40  
   35.41          if ( sec_bus != sub_bus )
   35.42 -        {
   35.43 -            dprintk(XENLOG_INFO VTDPREFIX,
   35.44 -                    "context_mapping: nested PCI bridge not supported\n");
   35.45 -            dprintk(XENLOG_INFO VTDPREFIX,
   35.46 -                    "    bdf = %x:%x:%x sec_bus = %x sub_bus = %x\n",
   35.47 -                    pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
   35.48 -                    sec_bus, sub_bus);
   35.49 -        }
   35.50 +            gdprintk(XENLOG_WARNING VTDPREFIX,
   35.51 +                     "context_context_mapping: nested PCI bridge not "
   35.52 +                     "supported: bdf = %x:%x:%x sec_bus = %x sub_bus = %x\n",
   35.53 +                     pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
   35.54 +                     sec_bus, sub_bus);
   35.55          break;
   35.56      case DEV_TYPE_PCIe_ENDPOINT:
   35.57          gdprintk(XENLOG_INFO VTDPREFIX,
   35.58 @@ -1227,7 +1223,7 @@ static int domain_context_mapping(
   35.59              if ( bus2bridge[pdev->bus].bus != 0 )
   35.60                  gdprintk(XENLOG_WARNING VTDPREFIX,
   35.61                           "domain_context_mapping:bus2bridge"
   35.62 -                         "[pdev->bus].bus != 0\n");
   35.63 +                         "[%d].bus != 0\n", pdev->bus);
   35.64  
   35.65              ret = domain_context_mapping_one(
   35.66                  domain, iommu,
   35.67 @@ -1345,8 +1341,8 @@ static int domain_context_unmap(
   35.68          {
   35.69              if ( bus2bridge[pdev->bus].bus != 0 )
   35.70                  gdprintk(XENLOG_WARNING VTDPREFIX,
   35.71 -                         "domain_context_mapping:"
   35.72 -                         "bus2bridge[pdev->bus].bus != 0\n");
   35.73 +                         "domain_context_unmap:"
   35.74 +                         "bus2bridge[%d].bus != 0\n", pdev->bus);
   35.75  
   35.76              ret = domain_context_unmap_one(domain, iommu,
   35.77                                             (u8)(bus2bridge[pdev->bus].bus),
    36.1 --- a/xen/arch/x86/hvm/vmx/vtd/io.c	Wed Dec 12 10:47:54 2007 -0700
    36.2 +++ b/xen/arch/x86/hvm/vmx/vtd/io.c	Wed Dec 12 10:50:03 2007 -0700
    36.3 @@ -131,7 +131,7 @@ int pt_irq_create_bind_vtd(
    36.4          pirq_guest_bind(d->vcpu[0], machine_gsi, BIND_PIRQ__WILL_SHARE);
    36.5      }
    36.6  
    36.7 -    gdprintk(XENLOG_INFO,
    36.8 +    gdprintk(XENLOG_INFO VTDPREFIX,
    36.9               "VT-d irq bind: m_irq = %x device = %x intx = %x\n",
   36.10               machine_gsi, device, intx);
   36.11      return 0;
   36.12 @@ -187,7 +187,7 @@ static void hvm_dpci_isairq_eoi(struct d
   36.13                  if ( --dpci->mirq[i].pending == 0 )
   36.14                  {
   36.15                      spin_unlock(&dpci->dirq_lock);
   36.16 -                    gdprintk(XENLOG_INFO,
   36.17 +                    gdprintk(XENLOG_INFO VTDPREFIX,
   36.18                               "hvm_dpci_isairq_eoi:: mirq = %x\n", i);
   36.19                      stop_timer(&dpci->hvm_timer[irq_to_vector(i)]);
   36.20                      pirq_guest_eoi(d, i);
   36.21 @@ -226,7 +226,8 @@ void hvm_dpci_eoi(struct domain *d, unsi
   36.22      {
   36.23          spin_unlock(&hvm_irq_dpci->dirq_lock);
   36.24  
   36.25 -        gdprintk(XENLOG_INFO, "hvm_dpci_eoi:: mirq = %x\n", machine_gsi);
   36.26 +        gdprintk(XENLOG_INFO VTDPREFIX,
   36.27 +                 "hvm_dpci_eoi:: mirq = %x\n", machine_gsi);
   36.28          stop_timer(&hvm_irq_dpci->hvm_timer[irq_to_vector(machine_gsi)]);
   36.29          if ( (ent == NULL) || !ent->fields.mask )
   36.30              pirq_guest_eoi(d, machine_gsi);
    37.1 --- a/xen/arch/x86/hvm/vmx/vtd/utils.c	Wed Dec 12 10:47:54 2007 -0700
    37.2 +++ b/xen/arch/x86/hvm/vmx/vtd/utils.c	Wed Dec 12 10:50:03 2007 -0700
    37.3 @@ -34,7 +34,6 @@
    37.4  #include <xen/xmalloc.h>
    37.5  #include <xen/inttypes.h>
    37.6  
    37.7 -#define VTDPREFIX "[VT-D]"
    37.8  #define INTEL   0x8086
    37.9  #define SEABURG 0x4000
   37.10  #define C_STEP  2
    38.1 --- a/xen/arch/x86/hvm/vpt.c	Wed Dec 12 10:47:54 2007 -0700
    38.2 +++ b/xen/arch/x86/hvm/vpt.c	Wed Dec 12 10:50:03 2007 -0700
    38.3 @@ -15,7 +15,6 @@
    38.4   * You should have received a copy of the GNU General Public License along with
    38.5   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    38.6   * Place - Suite 330, Boston, MA 02111-1307 USA.
    38.7 - *
    38.8   */
    38.9  
   38.10  #include <xen/time.h>
   38.11 @@ -26,6 +25,46 @@
   38.12  #define mode_is(d, name) \
   38.13      ((d)->arch.hvm_domain.params[HVM_PARAM_TIMER_MODE] == HVMPTM_##name)
   38.14  
   38.15 +static int pt_irq_vector(struct periodic_time *pt, enum hvm_intsrc src)
   38.16 +{
   38.17 +    struct vcpu *v = pt->vcpu;
   38.18 +    unsigned int gsi, isa_irq;
   38.19 +
   38.20 +    if ( pt->source == PTSRC_lapic )
   38.21 +        return pt->irq;
   38.22 +
   38.23 +    isa_irq = pt->irq;
   38.24 +    gsi = hvm_isa_irq_to_gsi(isa_irq);
   38.25 +
   38.26 +    if ( src == hvm_intsrc_pic )
   38.27 +        return (v->domain->arch.hvm_domain.vpic[isa_irq >> 3].irq_base
   38.28 +                + (isa_irq & 7));
   38.29 +
   38.30 +    ASSERT(src == hvm_intsrc_lapic);
   38.31 +    return domain_vioapic(v->domain)->redirtbl[gsi].fields.vector;
   38.32 +}
   38.33 +
   38.34 +static int pt_irq_masked(struct periodic_time *pt)
   38.35 +{
   38.36 +    struct vcpu *v = pt->vcpu;
   38.37 +    unsigned int gsi, isa_irq;
   38.38 +    uint8_t pic_imr;
   38.39 +
   38.40 +    if ( pt->source == PTSRC_lapic )
   38.41 +    {
   38.42 +        struct vlapic *vlapic = vcpu_vlapic(v);
   38.43 +        return (vlapic_enabled(vlapic) &&
   38.44 +                !(vlapic_get_reg(vlapic, APIC_LVTT) & APIC_LVT_MASKED));
   38.45 +    }
   38.46 +
   38.47 +    isa_irq = pt->irq;
   38.48 +    gsi = hvm_isa_irq_to_gsi(isa_irq);
   38.49 +    pic_imr = v->domain->arch.hvm_domain.vpic[isa_irq >> 3].imr;
   38.50 +
   38.51 +    return (((pic_imr & (1 << (isa_irq & 7))) || !vlapic_accept_pic_intr(v)) &&
   38.52 +            domain_vioapic(v->domain)->redirtbl[gsi].fields.mask);
   38.53 +}
   38.54 +
   38.55  static void pt_lock(struct periodic_time *pt)
   38.56  {
   38.57      struct vcpu *v;
   38.58 @@ -144,29 +183,39 @@ static void pt_timer_fn(void *data)
   38.59  void pt_update_irq(struct vcpu *v)
   38.60  {
   38.61      struct list_head *head = &v->arch.hvm_vcpu.tm_list;
   38.62 -    struct periodic_time *pt;
   38.63 +    struct periodic_time *pt, *earliest_pt = NULL;
   38.64      uint64_t max_lag = -1ULL;
   38.65 -    int irq = -1;
   38.66 +    int irq, is_lapic;
   38.67  
   38.68      spin_lock(&v->arch.hvm_vcpu.tm_lock);
   38.69  
   38.70      list_for_each_entry ( pt, head, list )
   38.71      {
   38.72 -        if ( !is_isa_irq_masked(v, pt->irq) && pt->pending_intr_nr &&
   38.73 +        if ( !pt_irq_masked(pt) && pt->pending_intr_nr &&
   38.74               ((pt->last_plt_gtime + pt->period_cycles) < max_lag) )
   38.75          {
   38.76              max_lag = pt->last_plt_gtime + pt->period_cycles;
   38.77 -            irq = pt->irq;
   38.78 +            earliest_pt = pt;
   38.79          }
   38.80      }
   38.81  
   38.82 +    if ( earliest_pt == NULL )
   38.83 +    {
   38.84 +        spin_unlock(&v->arch.hvm_vcpu.tm_lock);
   38.85 +        return;
   38.86 +    }
   38.87 +
   38.88 +    earliest_pt->irq_issued = 1;
   38.89 +    irq = earliest_pt->irq;
   38.90 +    is_lapic = (earliest_pt->source == PTSRC_lapic);
   38.91 +
   38.92      spin_unlock(&v->arch.hvm_vcpu.tm_lock);
   38.93  
   38.94 -    if ( is_lvtt(v, irq) )
   38.95 +    if ( is_lapic )
   38.96      {
   38.97          vlapic_set_irq(vcpu_vlapic(v), irq, 0);
   38.98      }
   38.99 -    else if ( irq >= 0 )
  38.100 +    else
  38.101      {
  38.102          hvm_isa_irq_deassert(v->domain, irq);
  38.103          hvm_isa_irq_assert(v->domain, irq);
  38.104 @@ -178,29 +227,12 @@ static struct periodic_time *is_pt_irq(
  38.105  {
  38.106      struct list_head *head = &v->arch.hvm_vcpu.tm_list;
  38.107      struct periodic_time *pt;
  38.108 -    struct RTCState *rtc = &v->domain->arch.hvm_domain.pl_time.vrtc;
  38.109 -    int vector;
  38.110  
  38.111      list_for_each_entry ( pt, head, list )
  38.112      {
  38.113 -        if ( !pt->pending_intr_nr )
  38.114 -            continue;
  38.115 -
  38.116 -        if ( is_lvtt(v, pt->irq) )
  38.117 -        {
  38.118 -            if ( pt->irq != intack.vector )
  38.119 -                continue;
  38.120 +        if ( pt->pending_intr_nr && pt->irq_issued &&
  38.121 +             (intack.vector == pt_irq_vector(pt, intack.source)) )
  38.122              return pt;
  38.123 -        }
  38.124 -
  38.125 -        vector = get_isa_irq_vector(v, pt->irq, intack.source);
  38.126 -
  38.127 -        /* RTC irq need special care */
  38.128 -        if ( (intack.vector != vector) ||
  38.129 -             ((pt->irq == 8) && !is_rtc_periodic_irq(rtc)) )
  38.130 -            continue;
  38.131 -
  38.132 -        return pt;
  38.133      }
  38.134  
  38.135      return NULL;
  38.136 @@ -222,11 +254,13 @@ void pt_intr_post(struct vcpu *v, struct
  38.137      }
  38.138  
  38.139      pt->do_not_freeze = 0;
  38.140 +    pt->irq_issued = 0;
  38.141  
  38.142      if ( pt->one_shot )
  38.143      {
  38.144 -        pt->enabled = 0;
  38.145 -        list_del(&pt->list);
  38.146 +        if ( pt->on_list )
  38.147 +            list_del(&pt->list);
  38.148 +        pt->on_list = 0;
  38.149      }
  38.150      else
  38.151      {
  38.152 @@ -290,13 +324,15 @@ void create_periodic_time(
  38.153      struct vcpu *v, struct periodic_time *pt, uint64_t period,
  38.154      uint8_t irq, char one_shot, time_cb *cb, void *data)
  38.155  {
  38.156 +    ASSERT(pt->source != 0);
  38.157 +
  38.158      destroy_periodic_time(pt);
  38.159  
  38.160      spin_lock(&v->arch.hvm_vcpu.tm_lock);
  38.161  
  38.162 -    pt->enabled = 1;
  38.163      pt->pending_intr_nr = 0;
  38.164      pt->do_not_freeze = 0;
  38.165 +    pt->irq_issued = 0;
  38.166  
  38.167      /* Periodic timer must be at least 0.9ms. */
  38.168      if ( (period < 900000) && !one_shot )
  38.169 @@ -319,11 +355,12 @@ void create_periodic_time(
  38.170       * LAPIC ticks for process accounting can see long sequences of process
  38.171       * ticks incorrectly accounted to interrupt processing.
  38.172       */
  38.173 -    if ( is_lvtt(v, irq) )
  38.174 +    if ( pt->source == PTSRC_lapic )
  38.175          pt->scheduled += period >> 1;
  38.176      pt->cb = cb;
  38.177      pt->priv = data;
  38.178  
  38.179 +    pt->on_list = 1;
  38.180      list_add(&pt->list, &v->arch.hvm_vcpu.tm_list);
  38.181  
  38.182      init_timer(&pt->timer, pt_timer_fn, pt, v->processor);
  38.183 @@ -334,12 +371,14 @@ void create_periodic_time(
  38.184  
  38.185  void destroy_periodic_time(struct periodic_time *pt)
  38.186  {
  38.187 -    if ( !pt->enabled )
  38.188 +    /* Was this structure previously initialised by create_periodic_time()? */
  38.189 +    if ( pt->vcpu == NULL )
  38.190          return;
  38.191  
  38.192      pt_lock(pt);
  38.193 -    pt->enabled = 0;
  38.194 -    list_del(&pt->list);
  38.195 +    if ( pt->on_list )
  38.196 +        list_del(&pt->list);
  38.197 +    pt->on_list = 0;
  38.198      pt_unlock(pt);
  38.199  
  38.200      /*
    39.1 --- a/xen/arch/x86/traps.c	Wed Dec 12 10:47:54 2007 -0700
    39.2 +++ b/xen/arch/x86/traps.c	Wed Dec 12 10:50:03 2007 -0700
    39.3 @@ -912,6 +912,14 @@ static int __spurious_page_fault(
    39.4      l1_pgentry_t l1e, *l1t;
    39.5      unsigned int required_flags, disallowed_flags;
    39.6  
    39.7 +    /*
    39.8 +     * We do not take spurious page faults in IRQ handlers as we do not
    39.9 +     * modify page tables in IRQ context. We therefore bail here because
   39.10 +     * map_domain_page() is not IRQ-safe.
   39.11 +     */
   39.12 +    if ( in_irq() )
   39.13 +        return 0;
   39.14 +
   39.15      /* Reserved bit violations are never spurious faults. */
   39.16      if ( regs->error_code & PFEC_reserved_bit )
   39.17          return 0;
    40.1 --- a/xen/common/gdbstub.c	Wed Dec 12 10:47:54 2007 -0700
    40.2 +++ b/xen/common/gdbstub.c	Wed Dec 12 10:50:03 2007 -0700
    40.3 @@ -43,6 +43,7 @@
    40.4  #include <xen/smp.h>
    40.5  #include <xen/console.h>
    40.6  #include <xen/errno.h>
    40.7 +#include <asm/byteorder.h>
    40.8  
    40.9  /* Printk isn't particularly safe just after we've trapped to the
   40.10     debugger. so avoid it. */
   40.11 @@ -215,8 +216,7 @@ void
   40.12  gdb_write_to_packet_hex(unsigned long x, int int_size, struct gdb_context *ctx)
   40.13  {
   40.14      char buf[sizeof(unsigned long) * 2 + 1];
   40.15 -    int i = sizeof(unsigned long) * 2;
   40.16 -    int width = int_size * 2;
   40.17 +    int i, width = int_size * 2;
   40.18  
   40.19      buf[sizeof(unsigned long) * 2] = 0;
   40.20  
   40.21 @@ -233,6 +233,8 @@ gdb_write_to_packet_hex(unsigned long x,
   40.22          break;
   40.23      }
   40.24  
   40.25 +#ifdef __BIG_ENDIAN
   40.26 +	i = sizeof(unsigned long) * 2
   40.27      do {
   40.28          buf[--i] = hex2char(x & 15);
   40.29          x >>= 4;
   40.30 @@ -242,6 +244,17 @@ gdb_write_to_packet_hex(unsigned long x,
   40.31          buf[--i] = '0';
   40.32  
   40.33      gdb_write_to_packet(&buf[i], width, ctx);
   40.34 +#elif defined(__LITTLE_ENDIAN)
   40.35 +	i = 0;
   40.36 +	while (i < width) {
   40.37 +		buf[i++] = hex2char(x>>4);
   40.38 +		buf[i++] = hex2char(x);
   40.39 +		x >>= 8;
   40.40 +	}
   40.41 +	gdb_write_to_packet(buf, width, ctx);
   40.42 +#else
   40.43 +# error unknown endian
   40.44 +#endif
   40.45  }
   40.46  
   40.47  static int
   40.48 @@ -512,7 +525,7 @@ int
   40.49  
   40.50      if ( gdb_ctx->serhnd < 0 )
   40.51      {
   40.52 -        dbg_printk("Debugger not ready yet.\n");
   40.53 +        printk("Debugging connection not set up.\n");
   40.54          return -EBUSY;
   40.55      }
   40.56  
    41.1 --- a/xen/common/keyhandler.c	Wed Dec 12 10:47:54 2007 -0700
    41.2 +++ b/xen/common/keyhandler.c	Wed Dec 12 10:50:03 2007 -0700
    41.3 @@ -275,6 +275,7 @@ extern void perfc_reset(unsigned char ke
    41.4  
    41.5  static void do_debug_key(unsigned char key, struct cpu_user_regs *regs)
    41.6  {
    41.7 +    printk("'%c' pressed -> trapping into debugger\n", key);
    41.8      (void)debugger_trap_fatal(0xf001, regs);
    41.9      nop(); /* Prevent the compiler doing tail call
   41.10                               optimisation, as that confuses xendbg a
    42.1 --- a/xen/include/asm-x86/hvm/irq.h	Wed Dec 12 10:47:54 2007 -0700
    42.2 +++ b/xen/include/asm-x86/hvm/irq.h	Wed Dec 12 10:50:03 2007 -0700
    42.3 @@ -160,7 +160,4 @@ struct hvm_intack hvm_vcpu_has_pending_i
    42.4  struct hvm_intack hvm_vcpu_ack_pending_irq(struct vcpu *v,
    42.5                                             struct hvm_intack intack);
    42.6  
    42.7 -int get_isa_irq_vector(struct vcpu *vcpu, int irq, enum hvm_intsrc src);
    42.8 -int is_isa_irq_masked(struct vcpu *v, int isa_irq);
    42.9 -
   42.10  #endif /* __ASM_X86_HVM_IRQ_H__ */
    43.1 --- a/xen/include/asm-x86/hvm/vlapic.h	Wed Dec 12 10:47:54 2007 -0700
    43.2 +++ b/xen/include/asm-x86/hvm/vlapic.h	Wed Dec 12 10:50:03 2007 -0700
    43.3 @@ -92,7 +92,4 @@ struct vlapic *apic_round_robin(
    43.4  
    43.5  int vlapic_match_logical_addr(struct vlapic *vlapic, uint8_t mda);
    43.6  
    43.7 -int is_lvtt(struct vcpu *v, int vector);
    43.8 -int is_lvtt_enabled(struct vcpu *v);
    43.9 -
   43.10  #endif /* __ASM_X86_HVM_VLAPIC_H__ */
    44.1 --- a/xen/include/asm-x86/hvm/vpt.h	Wed Dec 12 10:47:54 2007 -0700
    44.2 +++ b/xen/include/asm-x86/hvm/vpt.h	Wed Dec 12 10:50:03 2007 -0700
    44.3 @@ -72,12 +72,16 @@ typedef void time_cb(struct vcpu *v, voi
    44.4  
    44.5  struct periodic_time {
    44.6      struct list_head list;
    44.7 -    char enabled;
    44.8 -    char one_shot;              /* one shot time */
    44.9 -    char do_not_freeze;
   44.10 +    bool_t on_list;
   44.11 +    bool_t one_shot;
   44.12 +    bool_t do_not_freeze;
   44.13 +    bool_t irq_issued;
   44.14 +#define PTSRC_isa    1 /* ISA time source */
   44.15 +#define PTSRC_lapic  2 /* LAPIC time source */
   44.16 +    u8 source;                  /* PTSRC_ */
   44.17      u8 irq;
   44.18      struct vcpu *vcpu;          /* vcpu timer interrupt delivers to */
   44.19 -    u32 pending_intr_nr;        /* the couner for pending timer interrupts */
   44.20 +    u32 pending_intr_nr;        /* pending timer interrupts */
   44.21      u64 period;                 /* frequency in ns */
   44.22      u64 period_cycles;          /* frequency in cpu cycles */
   44.23      s_time_t scheduled;         /* scheduled timer interrupt */
   44.24 @@ -140,6 +144,19 @@ void pt_update_irq(struct vcpu *v);
   44.25  void pt_intr_post(struct vcpu *v, struct hvm_intack intack);
   44.26  void pt_reset(struct vcpu *v);
   44.27  void pt_migrate(struct vcpu *v);
   44.28 +
   44.29 +/* Is given periodic timer active? */
   44.30 +#define pt_active(pt) ((pt)->on_list)
   44.31 +
   44.32 +/*
   44.33 + * Create/destroy a periodic (or one-shot!) timer.
   44.34 + * The given periodic timer structure must be initialised with zero bytes,
   44.35 + * except for the 'source' field which must be initialised with the
   44.36 + * correct PTSRC_ value. The initialised timer structure can then be passed
   44.37 + * to {create,destroy}_periodic_time() and number of times and in any order.
   44.38 + * Note that, for a given periodic timer, invocations of these functions MUST
   44.39 + * be serialised.
   44.40 + */
   44.41  void create_periodic_time(
   44.42      struct vcpu *v, struct periodic_time *pt, uint64_t period,
   44.43      uint8_t irq, char one_shot, time_cb *cb, void *data);
   44.44 @@ -152,7 +169,6 @@ void pit_deinit(struct domain *d);
   44.45  void rtc_init(struct vcpu *v, int base);
   44.46  void rtc_migrate_timers(struct vcpu *v);
   44.47  void rtc_deinit(struct domain *d);
   44.48 -int is_rtc_periodic_irq(void *opaque);
   44.49  void pmtimer_init(struct vcpu *v);
   44.50  void pmtimer_deinit(struct domain *d);
   44.51  
    45.1 --- a/xen/include/asm-x86/iommu.h	Wed Dec 12 10:47:54 2007 -0700
    45.2 +++ b/xen/include/asm-x86/iommu.h	Wed Dec 12 10:50:03 2007 -0700
    45.3 @@ -79,5 +79,6 @@ int pt_irq_create_bind_vtd(struct domain
    45.4                             xen_domctl_bind_pt_irq_t *pt_irq_bind);
    45.5  
    45.6  #define PT_IRQ_TIME_OUT MILLISECS(8)
    45.7 +#define VTDPREFIX "[VT-D]"
    45.8  
    45.9  #endif /* _IOMMU_H_ */
    46.1 --- a/xen/include/asm-x86/mtrr.h	Wed Dec 12 10:47:54 2007 -0700
    46.2 +++ b/xen/include/asm-x86/mtrr.h	Wed Dec 12 10:50:03 2007 -0700
    46.3 @@ -47,6 +47,7 @@ struct mtrr_var_range {
    46.4  };
    46.5  
    46.6  #define NUM_FIXED_RANGES 88
    46.7 +#define NUM_FIXED_MSR 11
    46.8  struct mtrr_state {
    46.9  	struct mtrr_var_range *var_ranges;
   46.10  	mtrr_type fixed_ranges[NUM_FIXED_RANGES];
    47.1 --- a/xen/include/public/arch-x86/hvm/save.h	Wed Dec 12 10:47:54 2007 -0700
    47.2 +++ b/xen/include/public/arch-x86/hvm/save.h	Wed Dec 12 10:50:03 2007 -0700
    47.3 @@ -405,9 +405,26 @@ struct hvm_hw_pmtimer {
    47.4  
    47.5  DECLARE_HVM_SAVE_TYPE(PMTIMER, 13, struct hvm_hw_pmtimer);
    47.6  
    47.7 +/*
    47.8 + * MTRR MSRs
    47.9 + */
   47.10 +
   47.11 +struct hvm_hw_mtrr {
   47.12 +#define MTRR_VCNT 8
   47.13 +#define NUM_FIXED_MSR 11
   47.14 +    uint64_t msr_pat_cr;
   47.15 +    /* mtrr physbase & physmask msr pair*/
   47.16 +    uint64_t msr_mtrr_var[MTRR_VCNT*2];
   47.17 +    uint64_t msr_mtrr_fixed[NUM_FIXED_MSR];
   47.18 +    uint64_t msr_mtrr_cap;
   47.19 +    uint64_t msr_mtrr_def_type;
   47.20 +};
   47.21 +
   47.22 +DECLARE_HVM_SAVE_TYPE(MTRR, 14, struct hvm_hw_mtrr);
   47.23 +
   47.24  /* 
   47.25   * Largest type-code in use
   47.26   */
   47.27 -#define HVM_SAVE_CODE_MAX 13
   47.28 +#define HVM_SAVE_CODE_MAX 14
   47.29  
   47.30  #endif /* __XEN_PUBLIC_HVM_SAVE_X86_H__ */
    48.1 --- a/xen/include/public/domctl.h	Wed Dec 12 10:47:54 2007 -0700
    48.2 +++ b/xen/include/public/domctl.h	Wed Dec 12 10:50:03 2007 -0700
    48.3 @@ -435,9 +435,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_sendt
    48.4  
    48.5  
    48.6  /* Assign PCI device to HVM guest. Sets up IOMMU structures. */
    48.7 -#define XEN_DOMCTL_assign_device     37
    48.8 -#define DPCI_ADD_MAPPING         1
    48.9 -#define DPCI_REMOVE_MAPPING      0 
   48.10 +#define XEN_DOMCTL_assign_device      37
   48.11 +#define XEN_DOMCTL_test_assign_device 45
   48.12  struct xen_domctl_assign_device {
   48.13      uint32_t  machine_bdf;   /* machine PCI ID of assigned device */
   48.14  };
   48.15 @@ -473,6 +472,8 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_bind_
   48.16  
   48.17  /* Bind machine I/O address range -> HVM address range. */
   48.18  #define XEN_DOMCTL_memory_mapping    39
   48.19 +#define DPCI_ADD_MAPPING         1
   48.20 +#define DPCI_REMOVE_MAPPING      0
   48.21  struct xen_domctl_memory_mapping {
   48.22      uint64_aligned_t first_gfn; /* first page (hvm guest phys page) in range */
   48.23      uint64_aligned_t first_mfn; /* first page (machine page) in range */
   48.24 @@ -544,8 +545,11 @@ DEFINE_XEN_GUEST_HANDLE(xen_domctl_ext_v
   48.25   */
   48.26  #define XEN_DOMCTL_set_opt_feature    44
   48.27  struct xen_domctl_set_opt_feature {
   48.28 -#ifdef __ia64__
   48.29 +#if defined(__ia64__)
   48.30      struct xen_ia64_opt_feature optf;
   48.31 +#else
   48.32 +    /* Make struct non-empty: do not depend on this field name! */
   48.33 +    uint64_t dummy;
   48.34  #endif
   48.35  };
   48.36  typedef struct xen_domctl_set_opt_feature xen_domctl_set_opt_feature_t;
    49.1 --- a/xen/include/xen/gdbstub.h	Wed Dec 12 10:47:54 2007 -0700
    49.2 +++ b/xen/include/xen/gdbstub.h	Wed Dec 12 10:50:03 2007 -0700
    49.3 @@ -53,6 +53,7 @@ void gdb_write_to_packet(
    49.4      const char *buf, int count, struct gdb_context *ctx);
    49.5  void gdb_write_to_packet_hex(
    49.6      unsigned long x, int int_size, struct gdb_context *ctx);
    49.7 +    /* ... writes in target native byte order as required by gdb spec. */
    49.8  void gdb_send_packet(struct gdb_context *ctx);
    49.9  void gdb_send_reply(const char *buf, struct gdb_context *ctx);
   49.10