ia64/xen-unstable

changeset 15587:d0477293897c

Merge with ia64 xen tree.
author kfraser@localhost.localdomain
date Thu Jul 12 09:53:58 2007 +0100 (2007-07-12)
parents f536eb8576ee a9103c71565e
children bd2f9628114e
files tools/libxc/xc_domain.c tools/libxc/xenctrl.h
line diff
     1.1 --- a/docs/xen-api/xenapi-datamodel.tex	Wed Jul 11 11:32:30 2007 -0600
     1.2 +++ b/docs/xen-api/xenapi-datamodel.tex	Thu Jul 12 09:53:58 2007 +0100
     1.3 @@ -225,6 +225,249 @@ The following enumeration types are used
     1.4  \end{longtable}
     1.5  
     1.6  \vspace{1cm}
     1.7 +\newpage
     1.8 +\section{Error Handling}
     1.9 +When a low-level transport error occurs, or a request is malformed at the HTTP
    1.10 +or XML-RPC level, the server may send an XML-RPC Fault response, or the client
    1.11 +may simulate the same.  The client must be prepared to handle these errors,
    1.12 +though they may be treated as fatal.  On the wire, these are transmitted in a
    1.13 +form similar to this:
    1.14 +
    1.15 +\begin{verbatim}
    1.16 +    <methodResponse>
    1.17 +      <fault>
    1.18 +        <value>
    1.19 +          <struct>
    1.20 +            <member>
    1.21 +                <name>faultCode</name>
    1.22 +                <value><int>-1</int></value>
    1.23 +              </member>
    1.24 +              <member>
    1.25 +                <name>faultString</name>
    1.26 +                <value><string>Malformed request</string></value>
    1.27 +            </member>
    1.28 +          </struct>
    1.29 +        </value>
    1.30 +      </fault>
    1.31 +    </methodResponse>
    1.32 +\end{verbatim}
    1.33 +
    1.34 +All other failures are reported with a more structured error response, to
    1.35 +allow better automatic response to failures, proper internationalisation of
    1.36 +any error message, and easier debugging.  On the wire, these are transmitted
    1.37 +like this:
    1.38 +
    1.39 +\begin{verbatim}
    1.40 +    <struct>
    1.41 +      <member>
    1.42 +        <name>Status</name>
    1.43 +        <value>Failure</value>
    1.44 +      </member>
    1.45 +      <member>
    1.46 +        <name>ErrorDescription</name>
    1.47 +        <value>
    1.48 +          <array>
    1.49 +            <data>
    1.50 +              <value>MAP_DUPLICATE_KEY</value>
    1.51 +              <value>Customer</value>
    1.52 +              <value>eSpeil Inc.</value>
    1.53 +              <value>eSpeil Incorporated</value>
    1.54 +            </data>
    1.55 +          </array>
    1.56 +        </value>
    1.57 +      </member>
    1.58 +    </struct>
    1.59 +\end{verbatim}
    1.60 +
    1.61 +Note that {\tt ErrorDescription} value is an array of string values. The
    1.62 +first element of the array is an error code; the remainder of the array are
    1.63 +strings representing error parameters relating to that code.  In this case,
    1.64 +the client has attempted to add the mapping {\tt Customer $\rightarrow$
    1.65 +eSpiel Incorporated} to a Map, but it already contains the mapping
    1.66 +{\tt Customer $\rightarrow$ eSpiel Inc.}, and so the request has failed.
    1.67 +
    1.68 +The reference below lists each possible error returned by each method.
    1.69 +As well as the errors explicitly listed, any method may return low-level
    1.70 +errors as described above, or any of the following generic errors:
    1.71 +
    1.72 +\begin{itemize}
    1.73 +\item HANDLE\_INVALID
    1.74 +\item INTERNAL\_ERROR
    1.75 +\item MAP\_DUPLICATE\_KEY
    1.76 +\item MESSAGE\_METHOD\_UNKNOWN
    1.77 +\item MESSAGE\_PARAMETER\_COUNT\_MISMATCH
    1.78 +\item OPERATION\_NOT\_ALLOWED
    1.79 +\item PERMISSION\_DENIED
    1.80 +\item SESSION\_INVALID
    1.81 +\end{itemize}
    1.82 +
    1.83 +Each possible error code is documented in the following section.
    1.84 +
    1.85 +\subsection{Error Codes}
    1.86 +
    1.87 +\subsubsection{HANDLE\_INVALID}
    1.88 +
    1.89 +You gave an invalid handle.  The object may have recently been deleted. 
    1.90 +The class parameter gives the type of reference given, and the handle
    1.91 +parameter echoes the bad value given.
    1.92 +
    1.93 +\vspace{0.3cm}
    1.94 +{\bf Signature:}
    1.95 +\begin{verbatim}HANDLE_INVALID(class, handle)\end{verbatim}
    1.96 +\begin{center}\rule{10em}{0.1pt}\end{center}
    1.97 +
    1.98 +\subsubsection{INTERNAL\_ERROR}
    1.99 +
   1.100 +The server failed to handle your request, due to an internal error.  The
   1.101 +given message may give details useful for debugging the problem.
   1.102 +
   1.103 +\vspace{0.3cm}
   1.104 +{\bf Signature:}
   1.105 +\begin{verbatim}INTERNAL_ERROR(message)\end{verbatim}
   1.106 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.107 +
   1.108 +\subsubsection{MAP\_DUPLICATE\_KEY}
   1.109 +
   1.110 +You tried to add a key-value pair to a map, but that key is already there. 
   1.111 +The key, current value, and the new value that you tried to set are all
   1.112 +echoed.
   1.113 +
   1.114 +\vspace{0.3cm}
   1.115 +{\bf Signature:}
   1.116 +\begin{verbatim}MAP_DUPLICATE_KEY(key, current value, new value)\end{verbatim}
   1.117 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.118 +
   1.119 +\subsubsection{MESSAGE\_METHOD\_UNKNOWN}
   1.120 +
   1.121 +You tried to call a method that does not exist.  The method name that you
   1.122 +used is echoed.
   1.123 +
   1.124 +\vspace{0.3cm}
   1.125 +{\bf Signature:}
   1.126 +\begin{verbatim}MESSAGE_METHOD_UNKNOWN(method)\end{verbatim}
   1.127 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.128 +
   1.129 +\subsubsection{MESSAGE\_PARAMETER\_COUNT\_MISMATCH}
   1.130 +
   1.131 +You tried to call a method with the incorrect number of parameters.  The
   1.132 +fully-qualified method name that you used, and the number of received and
   1.133 +expected parameters are returned.
   1.134 +
   1.135 +\vspace{0.3cm}
   1.136 +{\bf Signature:}
   1.137 +\begin{verbatim}MESSAGE_PARAMETER_COUNT_MISMATCH(method, expected, received)\end{verbatim}
   1.138 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.139 +
   1.140 +\subsubsection{NETWORK\_ALREADY\_CONNECTED}
   1.141 +
   1.142 +You tried to create a PIF, but the network you tried to attach it to is
   1.143 +already attached to some other PIF, and so the creation failed.
   1.144 +
   1.145 +\vspace{0.3cm}
   1.146 +{\bf Signature:}
   1.147 +\begin{verbatim}NETWORK_ALREADY_CONNECTED(network, connected PIF)\end{verbatim}
   1.148 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.149 +
   1.150 +\subsubsection{OPERATION\_NOT\_ALLOWED}
   1.151 +
   1.152 +You attempted an operation that was not allowed.
   1.153 +
   1.154 +\vspace{0.3cm}
   1.155 +No parameters.
   1.156 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.157 +
   1.158 +\subsubsection{PERMISSION\_DENIED}
   1.159 +
   1.160 +You do not have the required permissions to perform the operation.
   1.161 +
   1.162 +\vspace{0.3cm}
   1.163 +No parameters.
   1.164 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.165 +
   1.166 +\subsubsection{PIF\_IS\_PHYSICAL}
   1.167 +
   1.168 +You tried to destroy a PIF, but it represents an aspect of the physical
   1.169 +host configuration, and so cannot be destroyed.  The parameter echoes the
   1.170 +PIF handle you gave.
   1.171 +
   1.172 +\vspace{0.3cm}
   1.173 +{\bf Signature:}
   1.174 +\begin{verbatim}PIF_IS_PHYSICAL(PIF)\end{verbatim}
   1.175 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.176 +
   1.177 +\subsubsection{SESSION\_AUTHENTICATION\_FAILED}
   1.178 +
   1.179 +The credentials given by the user are incorrect, so access has been denied,
   1.180 +and you have not been issued a session handle.
   1.181 +
   1.182 +\vspace{0.3cm}
   1.183 +No parameters.
   1.184 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.185 +
   1.186 +\subsubsection{SESSION\_INVALID}
   1.187 +
   1.188 +You gave an invalid session handle.  It may have been invalidated by a
   1.189 +server restart, or timed out.  You should get a new session handle, using
   1.190 +one of the session.login\_ calls.  This error does not invalidate the
   1.191 +current connection.  The handle parameter echoes the bad value given.
   1.192 +
   1.193 +\vspace{0.3cm}
   1.194 +{\bf Signature:}
   1.195 +\begin{verbatim}SESSION_INVALID(handle)\end{verbatim}
   1.196 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.197 +
   1.198 +\subsubsection{SESSION\_NOT\_REGISTERED}
   1.199 +
   1.200 +This session is not registered to receive events.  You must call
   1.201 +event.register before event.next.  The session handle you are using is
   1.202 +echoed.
   1.203 +
   1.204 +\vspace{0.3cm}
   1.205 +{\bf Signature:}
   1.206 +\begin{verbatim}SESSION_NOT_REGISTERED(handle)\end{verbatim}
   1.207 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.208 +
   1.209 +\subsubsection{VALUE\_NOT\_SUPPORTED}
   1.210 +
   1.211 +You attempted to set a value that is not supported by this implementation. 
   1.212 +The fully-qualified field name and the value that you tried to set are
   1.213 +returned.  Also returned is a developer-only diagnostic reason.
   1.214 +
   1.215 +\vspace{0.3cm}
   1.216 +{\bf Signature:}
   1.217 +\begin{verbatim}VALUE_NOT_SUPPORTED(field, value, reason)\end{verbatim}
   1.218 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.219 +
   1.220 +\subsubsection{VLAN\_TAG\_INVALID}
   1.221 +
   1.222 +You tried to create a VLAN, but the tag you gave was invalid -- it mmust be
   1.223 +between 0 and 4095.  The parameter echoes the VLAN tag you gave.
   1.224 +
   1.225 +\vspace{0.3cm}
   1.226 +{\bf Signature:}
   1.227 +\begin{verbatim}VLAN_TAG_INVALID(VLAN)\end{verbatim}
   1.228 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.229 +
   1.230 +\subsubsection{VM\_BAD\_POWER\_STATE}
   1.231 +
   1.232 +You attempted an operation on a VM that was not in an appropriate power
   1.233 +state at the time; for example, you attempted to start a VM that was
   1.234 +already running.  The parameters returned are the VM's handle, and the
   1.235 +expected and actual VM state at the time of the call.
   1.236 +
   1.237 +\vspace{0.3cm}
   1.238 +{\bf Signature:}
   1.239 +\begin{verbatim}VM_BAD_POWER_STATE(vm, expected, actual)\end{verbatim}
   1.240 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.241 +
   1.242 +\subsubsection{VM\_HVM\_REQUIRED}
   1.243 +
   1.244 +HVM is required for this operation
   1.245 +
   1.246 +\vspace{0.3cm}
   1.247 +{\bf Signature:}
   1.248 +\begin{verbatim}VM_HVM_REQUIRED(vm)\end{verbatim}
   1.249 +\begin{center}\rule{10em}{0.1pt}\end{center}
   1.250  
   1.251  \newpage
   1.252  \section{Class: session}
   1.253 @@ -275,6 +518,11 @@ session ref
   1.254  
   1.255  
   1.256  ID of newly created session
   1.257 +
   1.258 +\vspace{0.3cm}
   1.259 +
   1.260 +\noindent{\bf Possible Error Codes:} {\tt SESSION\_AUTHENTICATION\_FAILED}
   1.261 +
   1.262  \vspace{0.3cm}
   1.263  \vspace{0.3cm}
   1.264  \vspace{0.3cm}
   1.265 @@ -7100,7 +7348,9 @@ value of the field
   1.266  \subsubsection{RPC name:~get\_flags}
   1.267  
   1.268  {\bf Overview:} 
   1.269 -Get the flags field of the given host\_cpu.
   1.270 +Get the flags field of the given host\_cpu.  As of this version of the
   1.271 +API, the semantics of the returned string are explicitly unspecified,
   1.272 +and may change in the future.
   1.273  
   1.274   \noindent {\bf Signature:} 
   1.275  \begin{verbatim} string get_flags (session_id s, host_cpu ref self)\end{verbatim}
   1.276 @@ -7132,7 +7382,9 @@ value of the field
   1.277  \subsubsection{RPC name:~get\_features}
   1.278  
   1.279  {\bf Overview:} 
   1.280 -Get the features field of the given host\_cpu.
   1.281 +Get the features field of the given host\_cpu. As of this version of the
   1.282 +API, the semantics of the returned string are explicitly unspecified,
   1.283 +and may change in the future.
   1.284  
   1.285   \noindent {\bf Signature:} 
   1.286  \begin{verbatim} string get_features (session_id s, host_cpu ref self)\end{verbatim}
   1.287 @@ -14192,224 +14444,3 @@ all fields from the object
   1.288  \vspace{0.3cm}
   1.289  \vspace{0.3cm}
   1.290  
   1.291 -\vspace{1cm}
   1.292 -\newpage
   1.293 -\section{Error Handling}
   1.294 -When a low-level transport error occurs, or a request is malformed at the HTTP
   1.295 -or XML-RPC level, the server may send an XML-RPC Fault response, or the client
   1.296 -may simulate the same.  The client must be prepared to handle these errors,
   1.297 -though they may be treated as fatal.  On the wire, these are transmitted in a
   1.298 -form similar to this:
   1.299 -
   1.300 -\begin{verbatim}
   1.301 -    <methodResponse>
   1.302 -      <fault>
   1.303 -        <value>
   1.304 -          <struct>
   1.305 -            <member>
   1.306 -                <name>faultCode</name>
   1.307 -                <value><int>-1</int></value>
   1.308 -              </member>
   1.309 -              <member>
   1.310 -                <name>faultString</name>
   1.311 -                <value><string>Malformed request</string></value>
   1.312 -            </member>
   1.313 -          </struct>
   1.314 -        </value>
   1.315 -      </fault>
   1.316 -    </methodResponse>
   1.317 -\end{verbatim}
   1.318 -
   1.319 -All other failures are reported with a more structured error response, to
   1.320 -allow better automatic response to failures, proper internationalisation of
   1.321 -any error message, and easier debugging.  On the wire, these are transmitted
   1.322 -like this:
   1.323 -
   1.324 -\begin{verbatim}
   1.325 -    <struct>
   1.326 -      <member>
   1.327 -        <name>Status</name>
   1.328 -        <value>Failure</value>
   1.329 -      </member>
   1.330 -      <member>
   1.331 -        <name>ErrorDescription</name>
   1.332 -        <value>
   1.333 -          <array>
   1.334 -            <data>
   1.335 -              <value>MAP_DUPLICATE_KEY</value>
   1.336 -              <value>Customer</value>
   1.337 -              <value>eSpeil Inc.</value>
   1.338 -              <value>eSpeil Incorporated</value>
   1.339 -            </data>
   1.340 -          </array>
   1.341 -        </value>
   1.342 -      </member>
   1.343 -    </struct>
   1.344 -\end{verbatim}
   1.345 -
   1.346 -Note that {\tt ErrorDescription} value is an array of string values. The
   1.347 -first element of the array is an error code; the remainder of the array are
   1.348 -strings representing error parameters relating to that code.  In this case,
   1.349 -the client has attempted to add the mapping {\tt Customer $\rightarrow$
   1.350 -eSpiel Incorporated} to a Map, but it already contains the mapping
   1.351 -{\tt Customer $\rightarrow$ eSpiel Inc.}, and so the request has failed.
   1.352 -
   1.353 -Each possible error code is documented in the following section.
   1.354 -
   1.355 -\subsection{Error Codes}
   1.356 -
   1.357 -\subsubsection{HANDLE\_INVALID}
   1.358 -
   1.359 -You gave an invalid handle.  The object may have recently been deleted. 
   1.360 -The class parameter gives the type of reference given, and the handle
   1.361 -parameter echoes the bad value given.
   1.362 -
   1.363 -\vspace{0.3cm}
   1.364 -{\bf Signature:}
   1.365 -\begin{verbatim}HANDLE_INVALID(class, handle)\end{verbatim}
   1.366 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.367 -
   1.368 -\subsubsection{INTERNAL\_ERROR}
   1.369 -
   1.370 -The server failed to handle your request, due to an internal error.  The
   1.371 -given message may give details useful for debugging the problem.
   1.372 -
   1.373 -\vspace{0.3cm}
   1.374 -{\bf Signature:}
   1.375 -\begin{verbatim}INTERNAL_ERROR(message)\end{verbatim}
   1.376 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.377 -
   1.378 -\subsubsection{MAP\_DUPLICATE\_KEY}
   1.379 -
   1.380 -You tried to add a key-value pair to a map, but that key is already there. 
   1.381 -The key, current value, and the new value that you tried to set are all
   1.382 -echoed.
   1.383 -
   1.384 -\vspace{0.3cm}
   1.385 -{\bf Signature:}
   1.386 -\begin{verbatim}MAP_DUPLICATE_KEY(key, current value, new value)\end{verbatim}
   1.387 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.388 -
   1.389 -\subsubsection{MESSAGE\_METHOD\_UNKNOWN}
   1.390 -
   1.391 -You tried to call a method that does not exist.  The method name that you
   1.392 -used is echoed.
   1.393 -
   1.394 -\vspace{0.3cm}
   1.395 -{\bf Signature:}
   1.396 -\begin{verbatim}MESSAGE_METHOD_UNKNOWN(method)\end{verbatim}
   1.397 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.398 -
   1.399 -\subsubsection{MESSAGE\_PARAMETER\_COUNT\_MISMATCH}
   1.400 -
   1.401 -You tried to call a method with the incorrect number of parameters.  The
   1.402 -fully-qualified method name that you used, and the number of received and
   1.403 -expected parameters are returned.
   1.404 -
   1.405 -\vspace{0.3cm}
   1.406 -{\bf Signature:}
   1.407 -\begin{verbatim}MESSAGE_PARAMETER_COUNT_MISMATCH(method, expected, received)\end{verbatim}
   1.408 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.409 -
   1.410 -\subsubsection{NETWORK\_ALREADY\_CONNECTED}
   1.411 -
   1.412 -You tried to create a PIF, but the network you tried to attach it to is
   1.413 -already attached to some other PIF, and so the creation failed.
   1.414 -
   1.415 -\vspace{0.3cm}
   1.416 -{\bf Signature:}
   1.417 -\begin{verbatim}NETWORK_ALREADY_CONNECTED(network, connected PIF)\end{verbatim}
   1.418 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.419 -
   1.420 -\subsubsection{OPERATION\_NOT\_ALLOWED}
   1.421 -
   1.422 -You attempted an operation that was not allowed.
   1.423 -
   1.424 -\vspace{0.3cm}
   1.425 -No parameters.
   1.426 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.427 -
   1.428 -\subsubsection{PIF\_IS\_PHYSICAL}
   1.429 -
   1.430 -You tried to destroy a PIF, but it represents an aspect of the physical
   1.431 -host configuration, and so cannot be destroyed.  The parameter echoes the
   1.432 -PIF handle you gave.
   1.433 -
   1.434 -\vspace{0.3cm}
   1.435 -{\bf Signature:}
   1.436 -\begin{verbatim}PIF_IS_PHYSICAL(PIF)\end{verbatim}
   1.437 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.438 -
   1.439 -\subsubsection{SESSION\_AUTHENTICATION\_FAILED}
   1.440 -
   1.441 -The credentials given by the user are incorrect, so access has been denied,
   1.442 -and you have not been issued a session handle.
   1.443 -
   1.444 -\vspace{0.3cm}
   1.445 -No parameters.
   1.446 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.447 -
   1.448 -\subsubsection{SESSION\_INVALID}
   1.449 -
   1.450 -You gave an invalid session handle.  It may have been invalidated by a
   1.451 -server restart, or timed out.  You should get a new session handle, using
   1.452 -one of the session.login\_ calls.  This error does not invalidate the
   1.453 -current connection.  The handle parameter echoes the bad value given.
   1.454 -
   1.455 -\vspace{0.3cm}
   1.456 -{\bf Signature:}
   1.457 -\begin{verbatim}SESSION_INVALID(handle)\end{verbatim}
   1.458 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.459 -
   1.460 -\subsubsection{SESSION\_NOT\_REGISTERED}
   1.461 -
   1.462 -This session is not registered to receive events.  You must call
   1.463 -event.register before event.next.  The session handle you are using is
   1.464 -echoed.
   1.465 -
   1.466 -\vspace{0.3cm}
   1.467 -{\bf Signature:}
   1.468 -\begin{verbatim}SESSION_NOT_REGISTERED(handle)\end{verbatim}
   1.469 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.470 -
   1.471 -\subsubsection{VALUE\_NOT\_SUPPORTED}
   1.472 -
   1.473 -You attempted to set a value that is not supported by this implementation. 
   1.474 -The fully-qualified field name and the value that you tried to set are
   1.475 -returned.  Also returned is a developer-only diagnostic reason.
   1.476 -
   1.477 -\vspace{0.3cm}
   1.478 -{\bf Signature:}
   1.479 -\begin{verbatim}VALUE_NOT_SUPPORTED(field, value, reason)\end{verbatim}
   1.480 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.481 -
   1.482 -\subsubsection{VLAN\_TAG\_INVALID}
   1.483 -
   1.484 -You tried to create a VLAN, but the tag you gave was invalid -- it mmust be
   1.485 -between 0 and 4095.  The parameter echoes the VLAN tag you gave.
   1.486 -
   1.487 -\vspace{0.3cm}
   1.488 -{\bf Signature:}
   1.489 -\begin{verbatim}VLAN_TAG_INVALID(VLAN)\end{verbatim}
   1.490 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.491 -
   1.492 -\subsubsection{VM\_BAD\_POWER\_STATE}
   1.493 -
   1.494 -You attempted an operation on a VM that was not in an appropriate power
   1.495 -state at the time; for example, you attempted to start a VM that was
   1.496 -already running.  The parameters returned are the VM's handle, and the
   1.497 -expected and actual VM state at the time of the call.
   1.498 -
   1.499 -\vspace{0.3cm}
   1.500 -{\bf Signature:}
   1.501 -\begin{verbatim}VM_BAD_POWER_STATE(vm, expected, actual)\end{verbatim}
   1.502 -\begin{center}\rule{10em}{0.1pt}\end{center}
   1.503 -
   1.504 -\subsubsection{VM\_HVM\_REQUIRED}
   1.505 -
   1.506 -HVM is required for this operation
   1.507 -
   1.508 -\vspace{0.3cm}
   1.509 -{\bf Signature:}
   1.510 -\begin{verbatim}VM_HVM_REQUIRED(vm)\end{verbatim}
   1.511 -\begin{center}\rule{10em}{0.1pt}\end{center}
     2.1 --- a/tools/firmware/hvmloader/acpi/dsdt.asl	Wed Jul 11 11:32:30 2007 -0600
     2.2 +++ b/tools/firmware/hvmloader/acpi/dsdt.asl	Thu Jul 12 09:53:58 2007 +0100
     2.3 @@ -123,11 +123,12 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
     2.4              }
     2.5  
     2.6              Name(BUFA, ResourceTemplate() {
     2.7 -                IRQ(Level, ActiveLow, Shared) { 5, 7, 10, 11 }
     2.8 +                IRQ(Level, ActiveLow, Shared) { 5, 10, 11 }
     2.9              })
    2.10  
    2.11              Name(BUFB, Buffer() {
    2.12 -                0x23, 0x00, 0x00, 0x18, 0x79, 0
    2.13 +                0x23, 0x00, 0x00, 0x18, /* IRQ descriptor */
    2.14 +                0x79, 0                 /* End tag, null checksum */
    2.15              })
    2.16  
    2.17              CreateWordField(BUFB, 0x01, IRQV)
    2.18 @@ -643,6 +644,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 2, 
    2.19                          IRQNoFlags () {4}
    2.20                      })
    2.21                  }
    2.22 +
    2.23 +                Device (LTP1)
    2.24 +                {
    2.25 +                    Name (_HID, EisaId ("PNP0400"))
    2.26 +                    Name (_UID, 0x02)
    2.27 +                    Method (_STA, 0, NotSerialized)
    2.28 +                    {
    2.29 +                        Return (0x0F)
    2.30 +                    }
    2.31 +
    2.32 +                    Name (_CRS, ResourceTemplate()
    2.33 +                    {
    2.34 +                        IO (Decode16, 0x0378, 0x0378, 0x08, 0x08)
    2.35 +                        IRQNoFlags () {7}
    2.36 +                    })
    2.37 +                } 
    2.38              }
    2.39          }
    2.40      }
     3.1 --- a/tools/firmware/hvmloader/acpi/dsdt.c	Wed Jul 11 11:32:30 2007 -0600
     3.2 +++ b/tools/firmware/hvmloader/acpi/dsdt.c	Thu Jul 12 09:53:58 2007 +0100
     3.3 @@ -1,19 +1,19 @@
     3.4  /*
     3.5   * 
     3.6   * Intel ACPI Component Architecture
     3.7 - * ASL Optimizing Compiler version 20060707 [Dec 30 2006]
     3.8 + * ASL Optimizing Compiler version 20060707 [Feb 16 2007]
     3.9   * Copyright (C) 2000 - 2006 Intel Corporation
    3.10   * Supports ACPI Specification Revision 3.0a
    3.11   * 
    3.12 - * Compilation of "dsdt.asl" - Sat May 12 16:13:55 2007
    3.13 + * Compilation of "dsdt.asl" - Wed Jul 11 13:34:30 2007
    3.14   * 
    3.15   * C source code output
    3.16   *
    3.17   */
    3.18  unsigned char AmlCode[] =
    3.19  {
    3.20 -    0x44,0x53,0x44,0x54,0x67,0x0D,0x00,0x00,  /* 00000000    "DSDTg..." */
    3.21 -    0x02,0xE0,0x58,0x65,0x6E,0x00,0x00,0x00,  /* 00000008    "..Xen..." */
    3.22 +    0x44,0x53,0x44,0x54,0x9F,0x0D,0x00,0x00,  /* 00000000    "DSDT...." */
    3.23 +    0x02,0x2E,0x58,0x65,0x6E,0x00,0x00,0x00,  /* 00000008    "..Xen..." */
    3.24      0x48,0x56,0x4D,0x00,0x00,0x00,0x00,0x00,  /* 00000010    "HVM....." */
    3.25      0x00,0x00,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
    3.26      0x07,0x07,0x06,0x20,0x08,0x50,0x4D,0x42,  /* 00000020    "... .PMB" */
    3.27 @@ -27,7 +27,7 @@ unsigned char AmlCode[] =
    3.28      0x04,0x0A,0x07,0x0A,0x07,0x00,0x00,0x08,  /* 00000060    "........" */
    3.29      0x50,0x49,0x43,0x44,0x00,0x14,0x0C,0x5F,  /* 00000068    "PICD..._" */
    3.30      0x50,0x49,0x43,0x01,0x70,0x68,0x50,0x49,  /* 00000070    "PIC.phPI" */
    3.31 -    0x43,0x44,0x10,0x4C,0xCE,0x5F,0x53,0x42,  /* 00000078    "CD.L._SB" */
    3.32 +    0x43,0x44,0x10,0x44,0xD2,0x5F,0x53,0x42,  /* 00000078    "CD.D._SB" */
    3.33      0x5F,0x5B,0x82,0x49,0x04,0x4D,0x45,0x4D,  /* 00000080    "_[.I.MEM" */
    3.34      0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000088    "0._HID.A" */
    3.35      0xD0,0x0C,0x02,0x08,0x5F,0x43,0x52,0x53,  /* 00000090    "...._CRS" */
    3.36 @@ -37,7 +37,7 @@ unsigned char AmlCode[] =
    3.37      0x00,0x00,0xFF,0xFF,0x09,0x00,0x00,0x00,  /* 000000B0    "........" */
    3.38      0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000B8    "........" */
    3.39      0x00,0x00,0x00,0x00,0x0A,0x00,0x00,0x00,  /* 000000C0    "........" */
    3.40 -    0x00,0x00,0x79,0x00,0x5B,0x82,0x49,0xC9,  /* 000000C8    "..y.[.I." */
    3.41 +    0x00,0x00,0x79,0x00,0x5B,0x82,0x41,0xCD,  /* 000000C8    "..y.[.A." */
    3.42      0x50,0x43,0x49,0x30,0x08,0x5F,0x48,0x49,  /* 000000D0    "PCI0._HI" */
    3.43      0x44,0x0C,0x41,0xD0,0x0A,0x03,0x08,0x5F,  /* 000000D8    "D.A...._" */
    3.44      0x55,0x49,0x44,0x00,0x08,0x5F,0x41,0x44,  /* 000000E0    "UID.._AD" */
    3.45 @@ -59,7 +59,7 @@ unsigned char AmlCode[] =
    3.46      0x00,0xF0,0xFF,0xFF,0xFF,0xF4,0x00,0x00,  /* 00000160    "........" */
    3.47      0x00,0x00,0x00,0x00,0x00,0x05,0x79,0x00,  /* 00000168    "......y." */
    3.48      0xA4,0x50,0x52,0x54,0x30,0x08,0x42,0x55,  /* 00000170    ".PRT0.BU" */
    3.49 -    0x46,0x41,0x11,0x09,0x0A,0x06,0x23,0xA0,  /* 00000178    "FA....#." */
    3.50 +    0x46,0x41,0x11,0x09,0x0A,0x06,0x23,0x20,  /* 00000178    "FA....# " */
    3.51      0x0C,0x18,0x79,0x00,0x08,0x42,0x55,0x46,  /* 00000180    "..y..BUF" */
    3.52      0x42,0x11,0x09,0x0A,0x06,0x23,0x00,0x00,  /* 00000188    "B....#.." */
    3.53      0x18,0x79,0x00,0x8B,0x42,0x55,0x46,0x42,  /* 00000190    ".y..BUFB" */
    3.54 @@ -348,7 +348,7 @@ unsigned char AmlCode[] =
    3.55      0x0C,0x04,0x0C,0xFF,0xFF,0x0F,0x00,0x0A,  /* 00000A68    "........" */
    3.56      0x02,0x00,0x0A,0x2F,0x12,0x0C,0x04,0x0C,  /* 00000A70    ".../...." */
    3.57      0xFF,0xFF,0x0F,0x00,0x0A,0x03,0x00,0x0A,  /* 00000A78    "........" */
    3.58 -    0x10,0x5B,0x82,0x44,0x2E,0x49,0x53,0x41,  /* 00000A80    ".[.D.ISA" */
    3.59 +    0x10,0x5B,0x82,0x4C,0x31,0x49,0x53,0x41,  /* 00000A80    ".[.L1ISA" */
    3.60      0x5F,0x08,0x5F,0x41,0x44,0x52,0x0C,0x00,  /* 00000A88    "_._ADR.." */
    3.61      0x00,0x01,0x00,0x5B,0x80,0x50,0x49,0x52,  /* 00000A90    "...[.PIR" */
    3.62      0x51,0x02,0x0A,0x60,0x0A,0x04,0x10,0x2E,  /* 00000A98    "Q..`...." */
    3.63 @@ -440,6 +440,13 @@ unsigned char AmlCode[] =
    3.64      0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000D48    "._STA..." */
    3.65      0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000D50    ".._CRS.." */
    3.66      0x0A,0x0D,0x47,0x01,0xF8,0x03,0xF8,0x03,  /* 00000D58    "..G....." */
    3.67 -    0x01,0x08,0x22,0x10,0x00,0x79,0x00,
    3.68 +    0x01,0x08,0x22,0x10,0x00,0x79,0x00,0x5B,  /* 00000D60    ".."..y.[" */
    3.69 +    0x82,0x36,0x4C,0x54,0x50,0x31,0x08,0x5F,  /* 00000D68    ".6LTP1._" */
    3.70 +    0x48,0x49,0x44,0x0C,0x41,0xD0,0x04,0x00,  /* 00000D70    "HID.A..." */
    3.71 +    0x08,0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,  /* 00000D78    "._UID..." */
    3.72 +    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000D80    "._STA..." */
    3.73 +    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x10,  /* 00000D88    ".._CRS.." */
    3.74 +    0x0A,0x0D,0x47,0x01,0x78,0x03,0x78,0x03,  /* 00000D90    "..G.x.x." */
    3.75 +    0x08,0x08,0x22,0x80,0x00,0x79,0x00,
    3.76  };
    3.77  int DsdtLen=sizeof(AmlCode);
     4.1 --- a/tools/firmware/hvmloader/config.h	Wed Jul 11 11:32:30 2007 -0600
     4.2 +++ b/tools/firmware/hvmloader/config.h	Thu Jul 12 09:53:58 2007 +0100
     4.3 @@ -9,7 +9,7 @@
     4.4  #define LAPIC_ID(vcpu_id)   ((vcpu_id) * 2)
     4.5  
     4.6  #define PCI_ISA_DEVFN       0x08    /* dev 1, fn 0 */
     4.7 -#define PCI_ISA_IRQ_MASK    0x0ca0U /* ISA IRQs 5,7,10,11 are PCI connected */
     4.8 +#define PCI_ISA_IRQ_MASK    0x0c20U /* ISA IRQs 5,10,11 are PCI connected */
     4.9  
    4.10  #define ROMBIOS_SEG            0xF000
    4.11  #define ROMBIOS_BEGIN          0x000F0000
     5.1 --- a/tools/firmware/hvmloader/hvmloader.c	Wed Jul 11 11:32:30 2007 -0600
     5.2 +++ b/tools/firmware/hvmloader/hvmloader.c	Thu Jul 12 09:53:58 2007 +0100
     5.3 @@ -180,15 +180,13 @@ static void pci_setup(void)
     5.4      unsigned int bar, pin, link, isa_irq;
     5.5  
     5.6      /* Program PCI-ISA bridge with appropriate link routes. */
     5.7 -    link = 0;
     5.8 -    for ( isa_irq = 0; isa_irq < 15; isa_irq++ )
     5.9 +    isa_irq = 0;
    5.10 +    for ( link = 0; link < 4; link++ )
    5.11      {
    5.12 -        if ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) )
    5.13 -            continue;
    5.14 +        do { isa_irq = (isa_irq + 1) & 15;
    5.15 +        } while ( !(PCI_ISA_IRQ_MASK & (1U << isa_irq)) );
    5.16          pci_writeb(PCI_ISA_DEVFN, 0x60 + link, isa_irq);
    5.17          printf("PCI-ISA link %u routed to IRQ%u\n", link, isa_irq);
    5.18 -        if ( link++ == 4 )
    5.19 -            break;
    5.20      }
    5.21  
    5.22      /* Program ELCR to match PCI-wired IRQs. */
     6.1 --- a/tools/firmware/rombios/rombios.c	Wed Jul 11 11:32:30 2007 -0600
     6.2 +++ b/tools/firmware/rombios/rombios.c	Thu Jul 12 09:53:58 2007 +0100
     6.3 @@ -9146,78 +9146,78 @@ pci_routing_table_structure:
     6.4    db 0 ;; pci bus number
     6.5    db 0x08 ;; pci device number (bit 7-3)
     6.6    db 0x61 ;; link value INTA#: pointer into PCI2ISA config space
     6.7 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
     6.8 +  dw 0x0c20 ;; IRQ bitmap INTA# 
     6.9    db 0x62 ;; link value INTB#
    6.10 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.11 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.12    db 0x63 ;; link value INTC#
    6.13 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.14 +  dw 0x0c20 ;; IRQ bitmap INTC# 
    6.15    db 0x60 ;; link value INTD#
    6.16 -  dw 0x0ca0 ;; IRQ bitmap INTD#
    6.17 +  dw 0x0c20 ;; IRQ bitmap INTD#
    6.18    db 0 ;; physical slot (0 = embedded)
    6.19    db 0 ;; reserved
    6.20    ;; second slot entry: 1st PCI slot
    6.21    db 0 ;; pci bus number
    6.22    db 0x10 ;; pci device number (bit 7-3)
    6.23    db 0x62 ;; link value INTA#
    6.24 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
    6.25 +  dw 0x0c20 ;; IRQ bitmap INTA# 
    6.26    db 0x63 ;; link value INTB#
    6.27 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.28 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.29    db 0x60 ;; link value INTC#
    6.30 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.31 +  dw 0x0c20 ;; IRQ bitmap INTC# 
    6.32    db 0x61 ;; link value INTD#
    6.33 -  dw 0x0ca0 ;; IRQ bitmap INTD#
    6.34 +  dw 0x0c20 ;; IRQ bitmap INTD#
    6.35    db 1 ;; physical slot (0 = embedded)
    6.36    db 0 ;; reserved
    6.37    ;; third slot entry: 2nd PCI slot
    6.38    db 0 ;; pci bus number
    6.39    db 0x18 ;; pci device number (bit 7-3)
    6.40    db 0x63 ;; link value INTA#
    6.41 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
    6.42 +  dw 0x0c20 ;; IRQ bitmap INTA# 
    6.43    db 0x60 ;; link value INTB#
    6.44 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.45 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.46    db 0x61 ;; link value INTC#
    6.47 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.48 +  dw 0x0c20 ;; IRQ bitmap INTC# 
    6.49    db 0x62 ;; link value INTD#
    6.50 -  dw 0x0ca0 ;; IRQ bitmap INTD#
    6.51 +  dw 0x0c20 ;; IRQ bitmap INTD#
    6.52    db 2 ;; physical slot (0 = embedded)
    6.53    db 0 ;; reserved
    6.54    ;; 4th slot entry: 3rd PCI slot
    6.55    db 0 ;; pci bus number
    6.56    db 0x20 ;; pci device number (bit 7-3)
    6.57    db 0x60 ;; link value INTA#
    6.58 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
    6.59 +  dw 0x0c20 ;; IRQ bitmap INTA# 
    6.60    db 0x61 ;; link value INTB#
    6.61 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.62 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.63    db 0x62 ;; link value INTC#
    6.64 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.65 +  dw 0x0c20 ;; IRQ bitmap INTC# 
    6.66    db 0x63 ;; link value INTD#
    6.67 -  dw 0x0ca0 ;; IRQ bitmap INTD#
    6.68 +  dw 0x0c20 ;; IRQ bitmap INTD#
    6.69    db 3 ;; physical slot (0 = embedded)
    6.70    db 0 ;; reserved
    6.71    ;; 5th slot entry: 4rd PCI slot
    6.72    db 0 ;; pci bus number
    6.73    db 0x28 ;; pci device number (bit 7-3)
    6.74    db 0x61 ;; link value INTA#
    6.75 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
    6.76 +  dw 0x0c20 ;; IRQ bitmap INTA# 
    6.77    db 0x62 ;; link value INTB#
    6.78 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.79 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.80    db 0x63 ;; link value INTC#
    6.81 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.82 +  dw 0x0c20 ;; IRQ bitmap INTC# 
    6.83    db 0x60 ;; link value INTD#
    6.84 -  dw 0x0ca0 ;; IRQ bitmap INTD#
    6.85 +  dw 0x0c20 ;; IRQ bitmap INTD#
    6.86    db 4 ;; physical slot (0 = embedded)
    6.87    db 0 ;; reserved
    6.88    ;; 6th slot entry: 5rd PCI slot
    6.89    db 0 ;; pci bus number
    6.90    db 0x30 ;; pci device number (bit 7-3)
    6.91    db 0x62 ;; link value INTA#
    6.92 -  dw 0x0ca0 ;; IRQ bitmap INTA# 
    6.93 +  dw 0x0c20 ;; IRQ bitmap INTA# 
    6.94    db 0x63 ;; link value INTB#
    6.95 -  dw 0x0ca0 ;; IRQ bitmap INTB# 
    6.96 +  dw 0x0c20 ;; IRQ bitmap INTB# 
    6.97    db 0x60 ;; link value INTC#
    6.98 -  dw 0x0ca0 ;; IRQ bitmap INTC# 
    6.99 +  dw 0x0c20 ;; IRQ bitmap INTC# 
   6.100    db 0x61 ;; link value INTD#
   6.101 -  dw 0x0ca0 ;; IRQ bitmap INTD#
   6.102 +  dw 0x0c20 ;; IRQ bitmap INTD#
   6.103    db 5 ;; physical slot (0 = embedded)
   6.104    db 0 ;; reserved
   6.105  #endif // BX_PCIBIOS
     7.1 --- a/tools/ioemu/hw/ide.c	Wed Jul 11 11:32:30 2007 -0600
     7.2 +++ b/tools/ioemu/hw/ide.c	Thu Jul 12 09:53:58 2007 +0100
     7.3 @@ -596,7 +596,8 @@ static void ide_identify(IDEState *s)
     7.4      /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
     7.5      put_le16(p + 83, (1 << 14) | (1 << 13) | (1 <<12) | (1 << 10));
     7.6      put_le16(p + 84, (1 << 14));
     7.7 -    put_le16(p + 85, (1 << 14));
     7.8 +    /* 14=nop 5=write_cache */
     7.9 +    put_le16(p + 85, (1 << 14) | (1 << 5));
    7.10      /* 13=flush_cache_ext,12=flush_cache,10=lba48 */
    7.11      put_le16(p + 86, (1 << 14) | (1 << 13) | (1 <<12) | (1 << 10));
    7.12      put_le16(p + 87, (1 << 14));
     8.1 --- a/tools/ioemu/target-i386-dm/exec-dm.c	Wed Jul 11 11:32:30 2007 -0600
     8.2 +++ b/tools/ioemu/target-i386-dm/exec-dm.c	Thu Jul 12 09:53:58 2007 +0100
     8.3 @@ -446,18 +446,16 @@ extern unsigned long logdirty_bitmap_siz
     8.4  #if defined(__x86_64__) || defined(__i386__)
     8.5  static void memcpy_words(void *dst, void *src, size_t n)
     8.6  {
     8.7 -    asm (
     8.8 +    asm volatile (
     8.9          "   movl %%edx,%%ecx \n"
    8.10  #ifdef __x86_64__
    8.11          "   shrl $3,%%ecx    \n"
    8.12 -        "   andl $7,%%edx    \n"
    8.13          "   rep  movsq       \n"
    8.14          "   test $4,%%edx    \n"
    8.15          "   jz   1f          \n"
    8.16          "   movsl            \n"
    8.17  #else /* __i386__ */
    8.18          "   shrl $2,%%ecx    \n"
    8.19 -        "   andl $3,%%edx    \n"
    8.20          "   rep  movsl       \n"
    8.21  #endif
    8.22          "1: test $2,%%edx    \n"
    8.23 @@ -467,7 +465,7 @@ static void memcpy_words(void *dst, void
    8.24          "   jz   1f          \n"
    8.25          "   movsb            \n"
    8.26          "1:                  \n"
    8.27 -        : : "S" (src), "D" (dst), "d" (n) : "ecx" );
    8.28 +        : "+S" (src), "+D" (dst) : "d" (n) : "ecx", "memory" );
    8.29  }
    8.30  #else
    8.31  static void memcpy_words(void *dst, void *src, size_t n)
     9.1 --- a/tools/ioemu/vl.c	Wed Jul 11 11:32:30 2007 -0600
     9.2 +++ b/tools/ioemu/vl.c	Thu Jul 12 09:53:58 2007 +0100
     9.3 @@ -7141,13 +7141,8 @@ int main(int argc, char **argv)
     9.4          serial_devices[i][0] = '\0';
     9.5      serial_device_index = 0;
     9.6  
     9.7 -#ifndef CONFIG_DM
     9.8      pstrcpy(parallel_devices[0], sizeof(parallel_devices[0]), "vc");
     9.9      for(i = 1; i < MAX_PARALLEL_PORTS; i++)
    9.10 -#else
    9.11 -    /* Xen steals IRQ7 for PCI. Disable LPT1 by default. */
    9.12 -    for(i = 0; i < MAX_PARALLEL_PORTS; i++)
    9.13 -#endif
    9.14          parallel_devices[i][0] = '\0';
    9.15      parallel_device_index = 0;
    9.16      
    10.1 --- a/tools/libxc/xc_domain.c	Wed Jul 11 11:32:30 2007 -0600
    10.2 +++ b/tools/libxc/xc_domain.c	Thu Jul 12 09:53:58 2007 +0100
    10.3 @@ -588,6 +588,27 @@ int xc_domain_ioport_permission(int xc_h
    10.4      return do_domctl(xc_handle, &domctl);
    10.5  }
    10.6  
    10.7 +int xc_availheap(int xc_handle,
    10.8 +                 int min_width,
    10.9 +                 int max_width,
   10.10 +                 int node,
   10.11 +                 uint64_t *bytes)
   10.12 +{
   10.13 +    DECLARE_SYSCTL;
   10.14 +    int rc;
   10.15 +
   10.16 +    sysctl.cmd = XEN_SYSCTL_availheap;
   10.17 +    sysctl.u.availheap.min_bitwidth = min_width;
   10.18 +    sysctl.u.availheap.max_bitwidth = max_width;
   10.19 +    sysctl.u.availheap.node = node;
   10.20 +
   10.21 +    rc = xc_sysctl(xc_handle, &sysctl);
   10.22 +
   10.23 +    *bytes = sysctl.u.availheap.avail_bytes;
   10.24 +
   10.25 +    return rc;
   10.26 +}
   10.27 +
   10.28  int xc_vcpu_setcontext(int xc_handle,
   10.29                         uint32_t domid,
   10.30                         uint32_t vcpu,
    11.1 --- a/tools/libxc/xenctrl.h	Wed Jul 11 11:32:30 2007 -0600
    11.2 +++ b/tools/libxc/xenctrl.h	Thu Jul 12 09:53:58 2007 +0100
    11.3 @@ -628,6 +628,20 @@ int xc_get_pfn_type_batch(int xc_handle,
    11.4  /* Get current total pages allocated to a domain. */
    11.5  long xc_get_tot_pages(int xc_handle, uint32_t domid);
    11.6  
    11.7 +/**
    11.8 + * This function retrieves the the number of bytes available
    11.9 + * in the heap in a specific range of address-widths and nodes.
   11.10 + * 
   11.11 + * @parm xc_handle a handle to an open hypervisor interface
   11.12 + * @parm domid the domain to query
   11.13 + * @parm min_width the smallest address width to query (0 if don't care)
   11.14 + * @parm max_width the largest address width to query (0 if don't care)
   11.15 + * @parm node the node to query (-1 for all)
   11.16 + * @parm *bytes caller variable to put total bytes counted
   11.17 + * @return 0 on success, <0 on failure.
   11.18 + */
   11.19 +int xc_availheap(int xc_handle, int min_width, int max_width, int node,
   11.20 +                 uint64_t *bytes);
   11.21  
   11.22  /*
   11.23   * Trace Buffer Operations
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/libxen/include/xen/api/xen_acmpolicy.h	Thu Jul 12 09:53:58 2007 +0100
    12.3 @@ -0,0 +1,117 @@
    12.4 +/*
    12.5 + * Copyright (c) 2007, IBM Corp.
    12.6 + * Copyright (c) 2007, XenSource Inc.
    12.7 + *
    12.8 + * This library is free software; you can redistribute it and/or
    12.9 + * modify it under the terms of the GNU Lesser General Public
   12.10 + * License as published by the Free Software Foundation; either
   12.11 + * version 2.1 of the License, or (at your option) any later version.
   12.12 + *
   12.13 + * This library is distributed in the hope that it will be useful,
   12.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 + * Lesser General Public License for more details.
   12.17 + *
   12.18 + * You should have received a copy of the GNU Lesser General Public
   12.19 + * License along with this library; if not, write to the Free Software
   12.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   12.21 + */
   12.22 +
   12.23 +#ifndef XEN_ACMPOLICY_H
   12.24 +#define XEN_ACMPOLICY_H
   12.25 +
   12.26 +#include "xen_common.h"
   12.27 +#include "xen_string_string_map.h"
   12.28 +#include "xen_xspolicy_decl.h"
   12.29 +#include "xen_vm_decl.h"
   12.30 +
   12.31 +/*
   12.32 + * Data structures.
   12.33 + */
   12.34 +
   12.35 +typedef struct xen_acmpolicy_record
   12.36 +{
   12.37 +    xen_xspolicy handle;
   12.38 +    char *uuid;
   12.39 +    char *repr;
   12.40 +    xs_instantiationflags flags;
   12.41 +    xs_type type;
   12.42 +} xen_acmpolicy_record;
   12.43 +
   12.44 +/**
   12.45 + * Allocate a xen_acmpolicy_record.
   12.46 + */
   12.47 +extern xen_acmpolicy_record *
   12.48 +xen_acmpolicy_record_alloc(void);
   12.49 +
   12.50 +/**
   12.51 + * Free the given xen_xspolicy_record, and all referenced values.  The
   12.52 + * given record must have been allocated by this library.
   12.53 + */
   12.54 +extern void
   12.55 +xen_acmpolicy_record_free(xen_acmpolicy_record *record);
   12.56 +
   12.57 +
   12.58 +/**
   12.59 + * Data structures for the policy's header
   12.60 + */
   12.61 +typedef struct xen_acm_header
   12.62 +{
   12.63 +    char *policyname;
   12.64 +    char *policyurl;
   12.65 +    char *date;
   12.66 +    char *reference;
   12.67 +    char *namespaceurl;
   12.68 +    char *version;
   12.69 +} xen_acm_header;
   12.70 +
   12.71 +extern xen_acm_header *
   12.72 +xen_acm_header_alloc(void);
   12.73 +
   12.74 +extern void
   12.75 +xen_acm_header_free(xen_acm_header *hdr);
   12.76 +
   12.77 +/**
   12.78 + * Get the referenced policy's record.
   12.79 + */
   12.80 +bool
   12.81 +xen_acmpolicy_get_record(xen_session *session, xen_acmpolicy_record **result,
   12.82 +                         xen_xspolicy xspolicy);
   12.83 +
   12.84 +/**
   12.85 + * Get the header of a  policy.
   12.86 + */
   12.87 +extern bool
   12.88 +xen_acmpolicy_get_header(xen_session *session, xen_acm_header **hdr,
   12.89 +                         xen_xspolicy xspolicy);
   12.90 +
   12.91 +
   12.92 +/**
   12.93 + * Get the XML representation of the policy.
   12.94 + */
   12.95 +extern bool
   12.96 +xen_acmpolicy_get_xml(xen_session *session, char **xml,
   12.97 +                      xen_xspolicy xspolicy);
   12.98 +
   12.99 +/**
  12.100 + * Get the mapping file of the policy.
  12.101 + */
  12.102 +extern bool
  12.103 +xen_acmpolicy_get_map(xen_session *session, char **map,
  12.104 +                      xen_xspolicy xspolicy);
  12.105 +
  12.106 +/**
  12.107 + * Get the binary representation (base64-encoded) of the policy.
  12.108 + */
  12.109 +extern bool
  12.110 +xen_acmpolicy_get_binary(xen_session *session, char **binary,
  12.111 +                         xen_xspolicy xspolicy);
  12.112 +
  12.113 +/**
  12.114 + * Get the UUID filed of the given policy.
  12.115 + */
  12.116 +bool
  12.117 +xen_acmpolicy_get_uuid(xen_session *session, char **result,
  12.118 +                       xen_xspolicy xspolicy);
  12.119 +
  12.120 +#endif
    13.1 --- a/tools/libxen/include/xen/api/xen_vdi.h	Wed Jul 11 11:32:30 2007 -0600
    13.2 +++ b/tools/libxen/include/xen/api/xen_vdi.h	Thu Jul 12 09:53:58 2007 +0100
    13.3 @@ -344,4 +344,17 @@ extern bool
    13.4  xen_vdi_get_all(xen_session *session, struct xen_vdi_set **result);
    13.5  
    13.6  
    13.7 +/**
    13.8 + * Set the security label of a VDI.
    13.9 + */
   13.10 +extern bool
   13.11 +xen_vdi_set_security_label(xen_session *session, int64_t *result, xen_vdi vdi,
   13.12 +                           char *label, char *oldlabel);
   13.13 +
   13.14 +/**
   13.15 + * Get the security label of a VDI.
   13.16 + */
   13.17 +extern bool
   13.18 +xen_vdi_get_security_label(xen_session *session, char **result, xen_vdi vdi);
   13.19 +
   13.20  #endif
    14.1 --- a/tools/libxen/include/xen/api/xen_vm.h	Wed Jul 11 11:32:30 2007 -0600
    14.2 +++ b/tools/libxen/include/xen/api/xen_vm.h	Thu Jul 12 09:53:58 2007 +0100
    14.3 @@ -112,6 +112,7 @@ typedef struct xen_vm_record
    14.4      bool is_control_domain;
    14.5      struct xen_vm_metrics_record_opt *metrics;
    14.6      struct xen_vm_guest_metrics_record_opt *guest_metrics;
    14.7 +    char *security_label;
    14.8  } xen_vm_record;
    14.9  
   14.10  /**
   14.11 @@ -891,4 +892,17 @@ extern bool
   14.12  xen_vm_get_all(xen_session *session, struct xen_vm_set **result);
   14.13  
   14.14  
   14.15 +/**
   14.16 + * Set the security label of a domain.
   14.17 + */
   14.18 +extern bool
   14.19 +xen_vm_set_security_label(xen_session *session, int64_t *result, xen_vm vm,
   14.20 +                          char *label, char *oldlabel);
   14.21 +
   14.22 +/**
   14.23 + * Get the security label of a domain.
   14.24 + */
   14.25 +extern bool
   14.26 +xen_vm_get_security_label(xen_session *session, char **result, xen_vm vm);
   14.27 +
   14.28  #endif
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/libxen/include/xen/api/xen_xspolicy.h	Thu Jul 12 09:53:58 2007 +0100
    15.3 @@ -0,0 +1,271 @@
    15.4 +/*
    15.5 + * Copyright (c) 2007, IBM Corp.
    15.6 + * Copyright (c) 2007, XenSource Inc.
    15.7 + *
    15.8 + * This library is free software; you can redistribute it and/or
    15.9 + * modify it under the terms of the GNU Lesser General Public
   15.10 + * License as published by the Free Software Foundation; either
   15.11 + * version 2.1 of the License, or (at your option) any later version.
   15.12 + *
   15.13 + * This library is distributed in the hope that it will be useful,
   15.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 + * Lesser General Public License for more details.
   15.17 + *
   15.18 + * You should have received a copy of the GNU Lesser General Public
   15.19 + * License along with this library; if not, write to the Free Software
   15.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   15.21 + */
   15.22 +
   15.23 +#ifndef XEN_XSPOLICY_H
   15.24 +#define XEN_XSPOLICY_H
   15.25 +
   15.26 +#include "xen_common.h"
   15.27 +#include "xen_xspolicy_decl.h"
   15.28 +#include "xen_string_string_map.h"
   15.29 +
   15.30 +
   15.31 +/*
   15.32 + * The XSPolicy and associated data structures.
   15.33 + *
   15.34 + */
   15.35 +typedef int64_t xs_type;
   15.36 +typedef int64_t xs_instantiationflags;
   15.37 +
   15.38 +enum xs_type {
   15.39 +    XS_POLICY_ACM = (1 << 0),
   15.40 +};
   15.41 +
   15.42 +enum xs_instantiationflags {
   15.43 +    XS_INST_NONE = 0,
   15.44 +    XS_INST_BOOT = (1 << 0),
   15.45 +    XS_INST_LOAD = (1 << 1),
   15.46 +};
   15.47 +
   15.48 +
   15.49 +/* Error codes returned by xend following XSPolicy operations */
   15.50 +#define XSERR_BASE                       0x1000
   15.51 +
   15.52 +#define XSERR_SUCCESS                    0
   15.53 +#define XSERR_GENERAL_FAILURE            1 + XSERR_BASE
   15.54 +#define XSERR_BAD_XML                    2 + XSERR_BASE
   15.55 +#define XSERR_XML_PROCESSING             3 + XSERR_BASE
   15.56 +#define XSERR_POLICY_INCONSISTENT        4 + XSERR_BASE
   15.57 +#define XSERR_FILE_ERROR                 5 + XSERR_BASE
   15.58 +#define XSERR_BAD_RESOURCE_FORMAT        6 + XSERR_BASE
   15.59 +#define XSERR_BAD_LABEL_FORMAT           7 + XSERR_BASE
   15.60 +#define XSERR_RESOURCE_NOT_LABELED       8 + XSERR_BASE
   15.61 +#define XSERR_RESOURCE_ALREADY_LABELED   9 + XSERR_BASE
   15.62 +#define XSERR_WRONG_POLICY_TYPE         10 + XSERR_BASE
   15.63 +#define XSERR_BOOTPOLICY_INSTALLED      11 + XSERR_BASE
   15.64 +#define XSERR_NO_DEFAULT_BOOT_TITLE     12 + XSERR_BASE
   15.65 +#define XSERR_POLICY_LOAD_FAILED        13 + XSERR_BASE
   15.66 +#define XSERR_POLICY_LOADED             14 + XSERR_BASE
   15.67 +#define XSERR_POLICY_TYPE_UNSUPPORTED   15 + XSERR_BASE
   15.68 +#define XSERR_BAD_CONFLICTSET           20 + XSERR_BASE
   15.69 +#define XSERR_RESOURCE_IN_USE           21 + XSERR_BASE
   15.70 +#define XSERR_BAD_POLICY_NAME           22 + XSERR_BASE
   15.71 +#define XSERR_RESOURCE_ACCESS           23 + XSERR_BASE
   15.72 +#define XSERR_HV_OP_FAILED              24 + XSERR_BASE
   15.73 +#define XSERR_BOOTPOLICY_INSTALL_ERROR  25 + XSERR_BASE
   15.74 +
   15.75 +
   15.76 +/**
   15.77 + * Free the given xen_xspolicy.  The given handle must have been allocated
   15.78 + * by this library.
   15.79 + */
   15.80 +extern void
   15.81 +xen_xspolicy_free(xen_xspolicy xspolicy);
   15.82 +
   15.83 +
   15.84 +typedef struct xen_xspolicy_set
   15.85 +{
   15.86 +    size_t size;
   15.87 +    xen_xspolicy *contents[];
   15.88 +} xen_xspolicy_set;
   15.89 +
   15.90 +/**
   15.91 + * Allocate a xen_xspolicy_set of the given size.
   15.92 + */
   15.93 +extern xen_xspolicy_set *
   15.94 +xen_xspolicy_set_alloc(size_t size);
   15.95 +
   15.96 +/**
   15.97 + * Free the given xen_xspolicy_set.  The given set must have been allocated
   15.98 + * by this library.
   15.99 + */
  15.100 +extern void
  15.101 +xen_xspolicy_set_free(xen_xspolicy_set *set);
  15.102 +
  15.103 +
  15.104 +typedef struct xen_xspolicy_record
  15.105 +{
  15.106 +    xen_xspolicy handle;
  15.107 +    char *uuid;
  15.108 +    char *repr;
  15.109 +    xs_instantiationflags flags;
  15.110 +    xs_type type;
  15.111 +} xen_xspolicy_record;
  15.112 +
  15.113 +/**
  15.114 + * Allocate a xen_xspolicy_record.
  15.115 + */
  15.116 +extern xen_xspolicy_record *
  15.117 +xen_xspolicy_record_alloc(void);
  15.118 +
  15.119 +/**
  15.120 + * Free the given xen_xspolicy_record, and all referenced values.  The
  15.121 + * given record must have been allocated by this library.
  15.122 + */
  15.123 +extern void
  15.124 +xen_xspolicy_record_free(xen_xspolicy_record *record);
  15.125 +
  15.126 +
  15.127 +typedef struct xen_xspolicy_record_opt
  15.128 +{
  15.129 +    bool is_record;
  15.130 +    union
  15.131 +    {
  15.132 +        xen_xspolicy handle;
  15.133 +        xen_xspolicy_record *record;
  15.134 +    } u;
  15.135 +} xen_xspolicy_record_opt;
  15.136 +
  15.137 +/**
  15.138 + * Allocate a xen_xspolicy_record_opt.
  15.139 + */
  15.140 +extern xen_xspolicy_record_opt *
  15.141 +xen_xspolicy_record_opt_alloc(void);
  15.142 +
  15.143 +/**
  15.144 + * Free the given xen_xspolicy_record_opt, and all referenced values.  The
  15.145 + * given record_opt must have been allocated by this library.
  15.146 + */
  15.147 +extern void
  15.148 +xen_xspolicy_record_opt_free(xen_xspolicy_record_opt *record_opt);
  15.149 +
  15.150 +
  15.151 +typedef struct xen_xspolicy_record_set
  15.152 +{
  15.153 +    size_t size;
  15.154 +    xen_xspolicy_record *contents[];
  15.155 +} xen_xspolicy_record_set;
  15.156 +
  15.157 +/**
  15.158 + * Allocate a xen_xspolicy_record_set of the given size.
  15.159 + */
  15.160 +extern xen_xspolicy_record_set *
  15.161 +xen_xspolicy_record_set_alloc(size_t size);
  15.162 +
  15.163 +/**
  15.164 + * Free the given xen_xspolicy_record_set, and all referenced values.  The
  15.165 + * given set must have been allocated by this library.
  15.166 + */
  15.167 +extern void
  15.168 +xen_xspolicy_record_set_free(xen_xspolicy_record_set *set);
  15.169 +
  15.170 +/**
  15.171 + * Data structures and function declarations for an XS Policy's state
  15.172 + * information.
  15.173 + */
  15.174 +typedef struct xen_xs_policystate
  15.175 +{
  15.176 +    xen_xspolicy_record_opt *xs_ref;
  15.177 +    int64_t xserr;
  15.178 +    char *repr;
  15.179 +    xs_type type;
  15.180 +    xs_instantiationflags flags;
  15.181 +    char *version;
  15.182 +    char *errors;
  15.183 +} xen_xs_policystate;
  15.184 +
  15.185 +void
  15.186 +xen_xs_policystate_free(xen_xs_policystate *state);
  15.187 +
  15.188 +
  15.189 +/**
  15.190 + * Get the referenced policy's record.
  15.191 + */
  15.192 +bool
  15.193 +xen_xspolicy_get_record(xen_session *session, xen_xspolicy_record **result,
  15.194 +                        xen_xspolicy xspolicy);
  15.195 +
  15.196 +/**
  15.197 + * Get the UUID field of the given policy.
  15.198 + */
  15.199 +bool
  15.200 +xen_xspolicy_get_uuid(xen_session *session, char **result,
  15.201 +                      xen_xspolicy xspolicy);
  15.202 +
  15.203 +/**
  15.204 + * Get a policy given it's UUID
  15.205 + */
  15.206 +bool
  15.207 +xen_xspolicy_get_by_uuid(xen_session *session, xen_xspolicy *result,
  15.208 +                         char *uuid);
  15.209 +
  15.210 +
  15.211 +/**
  15.212 + * Get the types of policies supported by the system.
  15.213 + */
  15.214 +bool
  15.215 +xen_xspolicy_get_xstype(xen_session *session, xs_type *result);
  15.216 +
  15.217 +
  15.218 +/**
  15.219 + * Get information about the currently managed policy.
  15.220 + * (The API allows only one policy to be on the system.)
  15.221 + */
  15.222 +bool
  15.223 +xen_xspolicy_get_xspolicy(xen_session *session, xen_xs_policystate **result);
  15.224 +
  15.225 +/**
  15.226 + * Activate the referenced policy by loading it into the hypervisor.
  15.227 + */
  15.228 +bool
  15.229 +xen_xspolicy_activate_xspolicy(xen_session *session, int64_t *result,
  15.230 +                               xen_xspolicy xspolicy,
  15.231 +                               xs_instantiationflags flags);
  15.232 +
  15.233 +
  15.234 +/**
  15.235 + * Set the system's policy to the given information comprising
  15.236 + * type of policy, the xml representation of the policy, some flags
  15.237 + * on whether to load the policy immediately and whether to overwrite
  15.238 + * an existing policy on the system.
  15.239 + */
  15.240 +bool
  15.241 +xen_xspolicy_set_xspolicy(xen_session *session, xen_xs_policystate **result,
  15.242 +                          xs_type type, char *repr, int64_t flags,
  15.243 +                          bool overwrite);
  15.244 +
  15.245 +
  15.246 +/**
  15.247 + * Remove any policy from having the system booted with.
  15.248 + */
  15.249 +extern bool
  15.250 +xen_xspolicy_rm_xsbootpolicy(xen_session *session);
  15.251 +
  15.252 +/**
  15.253 + * Retrieve all labeled resources.
  15.254 + */
  15.255 +extern bool
  15.256 +xen_xspolicy_get_labeled_resources(xen_session *session,
  15.257 +                                   xen_string_string_map **resources);
  15.258 +
  15.259 +/**
  15.260 + * Label a resource such as for example a hard drive partition or file
  15.261 + */
  15.262 +extern bool
  15.263 +xen_xspolicy_set_resource_label(xen_session *session,
  15.264 +                                char *resource, char *label,
  15.265 +                                char *oldlabel);
  15.266 +
  15.267 +/**
  15.268 + * Get the label of a resource.
  15.269 + */
  15.270 +extern bool
  15.271 +xen_xspolicy_get_resource_label(xen_session *session, char **label,
  15.272 +                                char *resource);
  15.273 +
  15.274 +#endif
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/libxen/include/xen/api/xen_xspolicy_decl.h	Thu Jul 12 09:53:58 2007 +0100
    16.3 @@ -0,0 +1,31 @@
    16.4 +/*
    16.5 + * Copyright (c) 2007, IBM Corp.
    16.6 + * Copyright (c) 2007, XenSource Inc.
    16.7 + *
    16.8 + * This library is free software; you can redistribute it and/or
    16.9 + * modify it under the terms of the GNU Lesser General Public
   16.10 + * License as published by the Free Software Foundation; either
   16.11 + * version 2.1 of the License, or (at your option) any later version.
   16.12 + *
   16.13 + * This library is distributed in the hope that it will be useful,
   16.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 + * Lesser General Public License for more details.
   16.17 + *
   16.18 + * You should have received a copy of the GNU Lesser General Public
   16.19 + * License along with this library; if not, write to the Free Software
   16.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   16.21 + */
   16.22 +
   16.23 +#ifndef XEN_XSPOLICY_DECL_H
   16.24 +#define XEN_XSPOLICY_DECL_H
   16.25 +
   16.26 +typedef void *xen_xspolicy;
   16.27 +
   16.28 +struct xen_xspolicy_set;
   16.29 +struct xen_xspolicy_record;
   16.30 +struct xen_xspolicy_record_set;
   16.31 +struct xen_xspolicy_record_opt;
   16.32 +struct xen_xspolicy_record_opt_set;
   16.33 +
   16.34 +#endif
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/libxen/src/xen_acmpolicy.c	Thu Jul 12 09:53:58 2007 +0100
    17.3 @@ -0,0 +1,234 @@
    17.4 +/*
    17.5 + * Copyright (c) 2007, IBM Corp.
    17.6 + * Copyright (c) 2007, XenSource Inc.
    17.7 + *
    17.8 + * This library is free software; you can redistribute it and/or
    17.9 + * modify it under the terms of the GNU Lesser General Public
   17.10 + * License as published by the Free Software Foundation; either
   17.11 + * version 2.1 of the License, or (at your option) any later version.
   17.12 + *
   17.13 + * This library is distributed in the hope that it will be useful,
   17.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   17.16 + * Lesser General Public License for more details.
   17.17 + *
   17.18 + * You should have received a copy of the GNU Lesser General Public
   17.19 + * License along with this library; if not, write to the Free Software
   17.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   17.21 + */
   17.22 +
   17.23 +
   17.24 +#include <stddef.h>
   17.25 +#include <stdlib.h>
   17.26 +
   17.27 +#include "xen_internal.h"
   17.28 +#include "xen/api/xen_common.h"
   17.29 +#include "xen/api/xen_xspolicy.h"
   17.30 +#include "xen/api/xen_acmpolicy.h"
   17.31 +
   17.32 +
   17.33 +static const struct_member xen_acmpolicy_record_struct_members[] =
   17.34 +    {
   17.35 +        { .key = "uuid",
   17.36 +          .type = &abstract_type_string,
   17.37 +          .offset = offsetof(xen_acmpolicy_record, uuid) },
   17.38 +        { .key = "flags",
   17.39 +          .type = &abstract_type_int,
   17.40 +          .offset = offsetof(xen_acmpolicy_record, flags) },
   17.41 +        { .key = "repr",
   17.42 +          .type = &abstract_type_string,
   17.43 +          .offset = offsetof(xen_acmpolicy_record, repr) },
   17.44 +        { .key = "type",
   17.45 +          .type = &abstract_type_int,
   17.46 +          .offset = offsetof(xen_acmpolicy_record, type) },
   17.47 +    };
   17.48 +
   17.49 +const abstract_type xen_acmpolicy_record_abstract_type_ =
   17.50 +    {
   17.51 +       .typename = STRUCT,
   17.52 +       .struct_size = sizeof(xen_acmpolicy_record),
   17.53 +       .member_count =
   17.54 +          sizeof(xen_acmpolicy_record_struct_members) / sizeof(struct_member),
   17.55 +       .members = xen_acmpolicy_record_struct_members
   17.56 +    };
   17.57 +
   17.58 +
   17.59 +static const struct_member xen_acm_header_struct_members[] =
   17.60 +    {
   17.61 +        { .key = "policyname",
   17.62 +          .type = &abstract_type_string,
   17.63 +          .offset = offsetof(xen_acm_header, policyname) },
   17.64 +        { .key = "policyurl",
   17.65 +          .type = &abstract_type_string,
   17.66 +          .offset = offsetof(xen_acm_header, policyurl) },
   17.67 +        { .key = "date",
   17.68 +          .type = &abstract_type_string,
   17.69 +          .offset = offsetof(xen_acm_header, date) },
   17.70 +        { .key = "reference",
   17.71 +          .type = &abstract_type_string,
   17.72 +          .offset = offsetof(xen_acm_header, reference) },
   17.73 +        { .key = "namespaceurl",
   17.74 +          .type = &abstract_type_string,
   17.75 +          .offset = offsetof(xen_acm_header, namespaceurl) },
   17.76 +        { .key = "version",
   17.77 +          .type = &abstract_type_string,
   17.78 +          .offset = offsetof(xen_acm_header, version) },
   17.79 +    };
   17.80 +
   17.81 +const abstract_type xen_acm_header_abstract_type_ =
   17.82 +    {
   17.83 +        .typename = STRUCT,
   17.84 +        .struct_size = sizeof(xen_acm_header),
   17.85 +        .member_count =
   17.86 +            sizeof(xen_acm_header_struct_members) /
   17.87 +            sizeof(struct_member),
   17.88 +        .members = xen_acm_header_struct_members,
   17.89 +    };
   17.90 +
   17.91 +void
   17.92 +xen_acm_header_free(xen_acm_header *shdr)
   17.93 +{
   17.94 +    if (shdr == NULL)
   17.95 +    {
   17.96 +        return;
   17.97 +    }
   17.98 +    free(shdr->policyname);
   17.99 +    free(shdr->policyurl);
  17.100 +    free(shdr->date);
  17.101 +    free(shdr->reference);
  17.102 +    free(shdr->namespaceurl);
  17.103 +    free(shdr->version);
  17.104 +    free(shdr);
  17.105 +}
  17.106 +
  17.107 +
  17.108 +void
  17.109 +xen_acmpolicy_record_free(xen_acmpolicy_record *record)
  17.110 +{
  17.111 +    if (record == NULL)
  17.112 +    {
  17.113 +        return;
  17.114 +    }
  17.115 +    free(record->handle);
  17.116 +    free(record->uuid);
  17.117 +    free(record->repr);
  17.118 +    free(record);
  17.119 +}
  17.120 +
  17.121 +
  17.122 +
  17.123 +bool
  17.124 +xen_acmpolicy_get_record(xen_session *session, xen_acmpolicy_record **result,
  17.125 +                         xen_xspolicy xspolicy)
  17.126 +{
  17.127 +    abstract_value param_values[] =
  17.128 +        {
  17.129 +            { .type = &abstract_type_string,
  17.130 +              .u.string_val = xspolicy }
  17.131 +        };
  17.132 +
  17.133 +    abstract_type result_type = xen_acmpolicy_record_abstract_type_;
  17.134 +
  17.135 +    *result = NULL;
  17.136 +    XEN_CALL_("ACMPolicy.get_record");
  17.137 +
  17.138 +    if (session->ok)
  17.139 +    {
  17.140 +       (*result)->handle = xen_strdup_((*result)->uuid);
  17.141 +    }
  17.142 +
  17.143 +    return session->ok;
  17.144 +}
  17.145 +
  17.146 +
  17.147 +bool
  17.148 +xen_acmpolicy_get_header(xen_session *session,
  17.149 +                         xen_acm_header **result,
  17.150 +                         xen_xspolicy xspolicy)
  17.151 +{
  17.152 +    abstract_value param_values[] =
  17.153 +        {
  17.154 +            { .type = &abstract_type_string,
  17.155 +              .u.string_val = xspolicy },
  17.156 +        };
  17.157 +
  17.158 +    abstract_type result_type = xen_acm_header_abstract_type_;
  17.159 +
  17.160 +    *result = NULL;
  17.161 +    XEN_CALL_("ACMPolicy.get_header");
  17.162 +    return session->ok;
  17.163 +}
  17.164 +
  17.165 +
  17.166 +bool
  17.167 +xen_acmpolicy_get_xml(xen_session *session,
  17.168 +                      char **result,
  17.169 +                      xen_xspolicy xspolicy)
  17.170 +{
  17.171 +    abstract_value param_values[] =
  17.172 +        {
  17.173 +            { .type = &abstract_type_string,
  17.174 +              .u.string_val = xspolicy },
  17.175 +        };
  17.176 +
  17.177 +    abstract_type result_type = abstract_type_string;
  17.178 +
  17.179 +    *result = NULL;
  17.180 +    XEN_CALL_("ACMPolicy.get_xml");
  17.181 +    return session->ok;
  17.182 +}
  17.183 +
  17.184 +
  17.185 +bool
  17.186 +xen_acmpolicy_get_map(xen_session *session,
  17.187 +                      char **result,
  17.188 +                      xen_xspolicy xspolicy)
  17.189 +{
  17.190 +    abstract_value param_values[] =
  17.191 +        {
  17.192 +            { .type = &abstract_type_string,
  17.193 +              .u.string_val = xspolicy },
  17.194 +        };
  17.195 +
  17.196 +    abstract_type result_type = abstract_type_string;
  17.197 +
  17.198 +    *result = NULL;
  17.199 +    XEN_CALL_("ACMPolicy.get_map");
  17.200 +    return session->ok;
  17.201 +}
  17.202 +
  17.203 +
  17.204 +bool
  17.205 +xen_acmpolicy_get_binary(xen_session *session, char **result,
  17.206 +                         xen_xspolicy xspolicy)
  17.207 +{
  17.208 +    abstract_value param_values[] =
  17.209 +        {
  17.210 +            { .type = &abstract_type_string,
  17.211 +              .u.string_val = xspolicy },
  17.212 +        };
  17.213 +
  17.214 +    abstract_type result_type = abstract_type_string;
  17.215 +
  17.216 +    *result = NULL;
  17.217 +    XEN_CALL_("ACMPolicy.get_binary");
  17.218 +    return session->ok;
  17.219 +}
  17.220 +
  17.221 +
  17.222 +bool
  17.223 +xen_acmpolicy_get_uuid(xen_session *session, char **result,
  17.224 +                       xen_xspolicy xspolicy)
  17.225 +{
  17.226 +    abstract_value param_values[] =
  17.227 +        {
  17.228 +            { .type = &abstract_type_string,
  17.229 +              .u.string_val = xspolicy }
  17.230 +        };
  17.231 +
  17.232 +    abstract_type result_type = abstract_type_string;
  17.233 +
  17.234 +    *result = NULL;
  17.235 +    XEN_CALL_("ACMPolicy.get_uuid");
  17.236 +    return session->ok;
  17.237 +}
    18.1 --- a/tools/libxen/src/xen_vdi.c	Wed Jul 11 11:32:30 2007 -0600
    18.2 +++ b/tools/libxen/src/xen_vdi.c	Thu Jul 12 09:53:58 2007 +0100
    18.3 @@ -534,3 +534,42 @@ xen_vdi_get_uuid(xen_session *session, c
    18.4      XEN_CALL_("VDI.get_uuid");
    18.5      return session->ok;
    18.6  }
    18.7 +
    18.8 +
    18.9 +bool
   18.10 +xen_vdi_set_security_label(xen_session *session, int64_t *result, xen_vdi vdi,
   18.11 +                           char *label, char *oldlabel)
   18.12 +{
   18.13 +    abstract_value param_values[] =
   18.14 +        {
   18.15 +            { .type = &abstract_type_string,
   18.16 +              .u.string_val = vdi },
   18.17 +            { .type = &abstract_type_string,
   18.18 +              .u.string_val = label },
   18.19 +            { .type = &abstract_type_string,
   18.20 +              .u.string_val = oldlabel },
   18.21 +        };
   18.22 +
   18.23 +    abstract_type result_type = abstract_type_int;
   18.24 +
   18.25 +    *result = 0;
   18.26 +    XEN_CALL_("VDI.set_security_label");
   18.27 +    return session->ok;
   18.28 +}
   18.29 +
   18.30 +
   18.31 +bool
   18.32 +xen_vdi_get_security_label(xen_session *session, char **result, xen_vdi vdi)
   18.33 +{
   18.34 +    abstract_value param_values[] =
   18.35 +        {
   18.36 +            { .type = &abstract_type_string,
   18.37 +              .u.string_val = vdi },
   18.38 +        };
   18.39 +
   18.40 +    abstract_type result_type = abstract_type_string;
   18.41 +
   18.42 +    *result = NULL;
   18.43 +    XEN_CALL_("VDI.get_security_label");
   18.44 +    return session->ok;
   18.45 +}
    19.1 --- a/tools/libxen/src/xen_vm.c	Wed Jul 11 11:32:30 2007 -0600
    19.2 +++ b/tools/libxen/src/xen_vm.c	Thu Jul 12 09:53:58 2007 +0100
    19.3 @@ -162,7 +162,10 @@ static const struct_member xen_vm_record
    19.4            .offset = offsetof(xen_vm_record, metrics) },
    19.5          { .key = "guest_metrics",
    19.6            .type = &abstract_type_ref,
    19.7 -          .offset = offsetof(xen_vm_record, guest_metrics) }
    19.8 +          .offset = offsetof(xen_vm_record, guest_metrics) },
    19.9 +        { .key = "security_label",
   19.10 +          .type = &abstract_type_string,
   19.11 +          .offset = offsetof(xen_vm_record, security_label) }
   19.12      };
   19.13  
   19.14  const abstract_type xen_vm_record_abstract_type_ =
   19.15 @@ -206,6 +209,7 @@ xen_vm_record_free(xen_vm_record *record
   19.16      xen_string_string_map_free(record->other_config);
   19.17      xen_vm_metrics_record_opt_free(record->metrics);
   19.18      xen_vm_guest_metrics_record_opt_free(record->guest_metrics);
   19.19 +    free(record->security_label);
   19.20      free(record);
   19.21  }
   19.22  
   19.23 @@ -1738,3 +1742,42 @@ xen_vm_get_uuid(xen_session *session, ch
   19.24      XEN_CALL_("VM.get_uuid");
   19.25      return session->ok;
   19.26  }
   19.27 +
   19.28 +
   19.29 +bool
   19.30 +xen_vm_set_security_label(xen_session *session, int64_t *result, xen_vm vm,
   19.31 +                          char *label, char *oldlabel)
   19.32 +{
   19.33 +    abstract_value param_values[] =
   19.34 +        {
   19.35 +            { .type = &abstract_type_string,
   19.36 +              .u.string_val = vm },
   19.37 +            { .type = &abstract_type_string,
   19.38 +              .u.string_val = label },
   19.39 +            { .type = &abstract_type_string,
   19.40 +              .u.string_val = oldlabel },
   19.41 +        };
   19.42 +
   19.43 +    abstract_type result_type = abstract_type_int;
   19.44 +
   19.45 +    *result = 0;
   19.46 +    XEN_CALL_("VM.set_security_label");
   19.47 +    return session->ok;
   19.48 +}
   19.49 +
   19.50 +
   19.51 +bool
   19.52 +xen_vm_get_security_label(xen_session *session, char **result, xen_vm vm)
   19.53 +{
   19.54 +    abstract_value param_values[] =
   19.55 +        {
   19.56 +            { .type = &abstract_type_string,
   19.57 +              .u.string_val = vm },
   19.58 +        };
   19.59 +
   19.60 +    abstract_type result_type = abstract_type_string;
   19.61 +
   19.62 +    *result = NULL;
   19.63 +    XEN_CALL_("VM.get_security_label");
   19.64 +    return session->ok;
   19.65 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/libxen/src/xen_xspolicy.c	Thu Jul 12 09:53:58 2007 +0100
    20.3 @@ -0,0 +1,327 @@
    20.4 +/*
    20.5 + * Copyright (c) 2007, IBM Corp.
    20.6 + * Copyright (c) 2007, XenSource Inc.
    20.7 + *
    20.8 + * This library is free software; you can redistribute it and/or
    20.9 + * modify it under the terms of the GNU Lesser General Public
   20.10 + * License as published by the Free Software Foundation; either
   20.11 + * version 2.1 of the License, or (at your option) any later version.
   20.12 + *
   20.13 + * This library is distributed in the hope that it will be useful,
   20.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 + * Lesser General Public License for more details.
   20.17 + *
   20.18 + * You should have received a copy of the GNU Lesser General Public
   20.19 + * License along with this library; if not, write to the Free Software
   20.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
   20.21 + */
   20.22 +
   20.23 +
   20.24 +#include <stddef.h>
   20.25 +#include <stdlib.h>
   20.26 +
   20.27 +#include "xen/api/xen_common.h"
   20.28 +#include "xen/api/xen_internal.h"
   20.29 +#include "xen/api/xen_xspolicy.h"
   20.30 +
   20.31 +
   20.32 +XEN_FREE(xen_xspolicy)
   20.33 +XEN_SET_ALLOC_FREE(xen_xspolicy)
   20.34 +XEN_RECORD_OPT_FREE(xen_xspolicy)
   20.35 +
   20.36 +static const struct_member xen_xspolicy_record_struct_members[] =
   20.37 +    {
   20.38 +        { .key = "uuid",
   20.39 +          .type = &abstract_type_string,
   20.40 +          .offset = offsetof(xen_xspolicy_record, uuid) },
   20.41 +        { .key = "flags",
   20.42 +          .type = &abstract_type_int,
   20.43 +          .offset = offsetof(xen_xspolicy_record, flags) },
   20.44 +        { .key = "repr",
   20.45 +          .type = &abstract_type_string,
   20.46 +          .offset = offsetof(xen_xspolicy_record, repr) },
   20.47 +        { .key = "type",
   20.48 +          .type = &abstract_type_int,
   20.49 +          .offset = offsetof(xen_xspolicy_record, type) },
   20.50 +    };
   20.51 +
   20.52 +const abstract_type xen_xspolicy_record_abstract_type_ =
   20.53 +    {
   20.54 +       .typename = STRUCT,
   20.55 +       .struct_size = sizeof(xen_xspolicy_record),
   20.56 +       .member_count =
   20.57 +           sizeof(xen_xspolicy_record_struct_members) / sizeof(struct_member),
   20.58 +       .members = xen_xspolicy_record_struct_members
   20.59 +    };
   20.60 +
   20.61 +
   20.62 +static const struct_member xen_xs_policystate_struct_members[] =
   20.63 +    {
   20.64 +        { .key = "xs_ref",
   20.65 +          .type = &abstract_type_ref,
   20.66 +          .offset = offsetof(xen_xs_policystate, xs_ref) },
   20.67 +        { .key = "xserr",
   20.68 +          .type = &abstract_type_int,
   20.69 +          .offset = offsetof(xen_xs_policystate, xserr) },
   20.70 +        { .key = "repr",
   20.71 +          .type = &abstract_type_string,
   20.72 +          .offset = offsetof(xen_xs_policystate, repr) },
   20.73 +        { .key = "type",
   20.74 +          .type = &abstract_type_int,
   20.75 +          .offset = offsetof(xen_xs_policystate, type) },
   20.76 +        { .key = "flags",
   20.77 +          .type = &abstract_type_int,
   20.78 +          .offset = offsetof(xen_xs_policystate, flags) },
   20.79 +        { .key = "version",
   20.80 +          .type = &abstract_type_string,
   20.81 +          .offset = offsetof(xen_xs_policystate, version) },
   20.82 +        { .key = "errors",
   20.83 +          .type = &abstract_type_string,
   20.84 +          .offset = offsetof(xen_xs_policystate, errors) },
   20.85 +    };
   20.86 +
   20.87 +const abstract_type xen_xs_policystate_abstract_type_ =
   20.88 +    {
   20.89 +        .typename = STRUCT,
   20.90 +        .struct_size = sizeof(xen_xs_policystate),
   20.91 +        .member_count =
   20.92 +            sizeof(xen_xs_policystate_struct_members) /
   20.93 +            sizeof(struct_member),
   20.94 +        .members = xen_xs_policystate_struct_members,
   20.95 +    };
   20.96 +
   20.97 +
   20.98 +
   20.99 +
  20.100 +void
  20.101 +xen_xs_policystate_free(xen_xs_policystate *state)
  20.102 +{
  20.103 +    if (state == NULL)
  20.104 +    {
  20.105 +        return;
  20.106 +    }
  20.107 +    xen_xspolicy_record_opt_free(state->xs_ref);
  20.108 +    free(state->repr);
  20.109 +    free(state->errors);
  20.110 +    free(state->version);
  20.111 +    free(state);
  20.112 +}
  20.113 +
  20.114 +
  20.115 +void
  20.116 +xen_xspolicy_record_free(xen_xspolicy_record *record)
  20.117 +{
  20.118 +    if (record == NULL)
  20.119 +    {
  20.120 +        return;
  20.121 +    }
  20.122 +    free(record->handle);
  20.123 +    free(record->uuid);
  20.124 +    free(record->repr);
  20.125 +    free(record);
  20.126 +}
  20.127 +
  20.128 +
  20.129 +bool
  20.130 +xen_xspolicy_get_record(xen_session *session, xen_xspolicy_record **result,
  20.131 +                        xen_xspolicy xspolicy)
  20.132 +{
  20.133 +    abstract_value param_values[] =
  20.134 +        {
  20.135 +            { .type = &abstract_type_string,
  20.136 +              .u.string_val = xspolicy }
  20.137 +        };
  20.138 +
  20.139 +    abstract_type result_type = xen_xspolicy_record_abstract_type_;
  20.140 +
  20.141 +    *result = NULL;
  20.142 +    XEN_CALL_("XSPolicy.get_record");
  20.143 +
  20.144 +    if (session->ok)
  20.145 +    {
  20.146 +       (*result)->handle = xen_strdup_((*result)->uuid);
  20.147 +    }
  20.148 +
  20.149 +    return session->ok;
  20.150 +}
  20.151 +
  20.152 +
  20.153 +bool
  20.154 +xen_xspolicy_get_uuid(xen_session *session, char **result,
  20.155 +                      xen_xspolicy xspolicy)
  20.156 +{
  20.157 +    abstract_value param_values[] =
  20.158 +        {
  20.159 +            { .type = &abstract_type_string,
  20.160 +              .u.string_val = xspolicy }
  20.161 +        };
  20.162 +
  20.163 +    abstract_type result_type = abstract_type_string;
  20.164 +
  20.165 +    *result = NULL;
  20.166 +    XEN_CALL_("XSPolicy.get_uuid");
  20.167 +    return session->ok;
  20.168 +}
  20.169 +
  20.170 +
  20.171 +bool
  20.172 +xen_xspolicy_get_by_uuid(xen_session *session, xen_xspolicy *result,
  20.173 +                         char *uuid)
  20.174 +{
  20.175 +    abstract_value param_values[] =
  20.176 +        {
  20.177 +            { .type = &abstract_type_string,
  20.178 +              .u.string_val = uuid }
  20.179 +        };
  20.180 +
  20.181 +    abstract_type result_type = abstract_type_string;
  20.182 +
  20.183 +    *result = NULL;
  20.184 +    XEN_CALL_("XSPolicy.get_by_uuid");
  20.185 +    return session->ok;
  20.186 +}
  20.187 +
  20.188 +
  20.189 +bool
  20.190 +xen_xspolicy_get_xstype(xen_session *session, xs_type *result)
  20.191 +{
  20.192 +    abstract_value param_values[] =
  20.193 +        {
  20.194 +        };
  20.195 +
  20.196 +    abstract_type result_type = abstract_type_int;
  20.197 +
  20.198 +    *result = 0;
  20.199 +    XEN_CALL_("XSPolicy.get_xstype");
  20.200 +    return session->ok;
  20.201 +}
  20.202 +
  20.203 +
  20.204 +bool
  20.205 +xen_xspolicy_set_xspolicy(xen_session *session, xen_xs_policystate **result,
  20.206 +                          xs_type type, char *repr,
  20.207 +                          xs_instantiationflags flags,
  20.208 +                          bool overwrite)
  20.209 +{
  20.210 +    abstract_value param_values[] =
  20.211 +        {
  20.212 +            { .type = &abstract_type_int,
  20.213 +              .u.int_val = type },
  20.214 +            { .type = &abstract_type_string,
  20.215 +              .u.string_val = repr },
  20.216 +            { .type = &abstract_type_int,
  20.217 +              .u.int_val = flags },
  20.218 +            { .type = &abstract_type_bool,
  20.219 +              .u.bool_val = overwrite }
  20.220 +        };
  20.221 +
  20.222 +    abstract_type result_type = xen_xs_policystate_abstract_type_;
  20.223 +
  20.224 +    *result = NULL;
  20.225 +    XEN_CALL_("XSPolicy.set_xspolicy");
  20.226 +    return session->ok;
  20.227 +}
  20.228 +
  20.229 +
  20.230 +bool
  20.231 +xen_xspolicy_get_xspolicy(xen_session *session, xen_xs_policystate **result)
  20.232 +{
  20.233 +    abstract_value param_values[] =
  20.234 +        {
  20.235 +        };
  20.236 +
  20.237 +    abstract_type result_type = xen_xs_policystate_abstract_type_;
  20.238 +
  20.239 +    *result = NULL;
  20.240 +    XEN_CALL_("XSPolicy.get_xspolicy");
  20.241 +    return session->ok;
  20.242 +}
  20.243 +
  20.244 +
  20.245 +bool
  20.246 +xen_xspolicy_get_labeled_resources(xen_session *session,
  20.247 +                                   xen_string_string_map **result)
  20.248 +{
  20.249 +    abstract_value param_values[] =
  20.250 +        {
  20.251 +        };
  20.252 +
  20.253 +    abstract_type result_type = abstract_type_string_string_map;
  20.254 +
  20.255 +    *result = NULL;
  20.256 +    XEN_CALL_("XSPolicy.get_labeled_resources");
  20.257 +    return session->ok;
  20.258 +}
  20.259 +
  20.260 +
  20.261 +bool
  20.262 +xen_xspolicy_set_resource_label(xen_session *session,
  20.263 +                                char *resource, char *label,
  20.264 +                                char *oldlabel)
  20.265 +{
  20.266 +    abstract_value param_values[] =
  20.267 +        {
  20.268 +            { .type = &abstract_type_string,
  20.269 +              .u.string_val = resource },
  20.270 +            { .type = &abstract_type_string,
  20.271 +              .u.string_val = label },
  20.272 +            { .type = &abstract_type_string,
  20.273 +              .u.string_val = oldlabel },
  20.274 +        };
  20.275 +
  20.276 +    xen_call_(session, "XSPolicy.set_resource_label", param_values, 3,
  20.277 +                       NULL, NULL);
  20.278 +    return session->ok;
  20.279 +}
  20.280 +
  20.281 +
  20.282 +bool
  20.283 +xen_xspolicy_get_resource_label(xen_session *session, char **result,
  20.284 +                                char *resource)
  20.285 +{
  20.286 +    abstract_value param_values[] =
  20.287 +        {
  20.288 +            { .type = &abstract_type_string,
  20.289 +              .u.string_val = resource },
  20.290 +        };
  20.291 +
  20.292 +    abstract_type result_type = abstract_type_string;
  20.293 +    XEN_CALL_("XSPolicy.get_resource_label");
  20.294 +    return session->ok;
  20.295 +}
  20.296 +
  20.297 +
  20.298 +bool
  20.299 +xen_xspolicy_rm_xsbootpolicy(xen_session *session)
  20.300 +{
  20.301 +    abstract_value param_values[] =
  20.302 +        {
  20.303 +        };
  20.304 +
  20.305 +    xen_call_(session, "XSPolicy.rm_xsbootpolicy", param_values, 0,
  20.306 +                       NULL, NULL);
  20.307 +    return session->ok;
  20.308 +}
  20.309 +
  20.310 +
  20.311 +bool
  20.312 +xen_xspolicy_activate_xspolicy(xen_session *session,
  20.313 +                               xs_instantiationflags *result,
  20.314 +                               xen_xspolicy xspolicy,
  20.315 +                               xs_instantiationflags flags)
  20.316 +{
  20.317 +    abstract_value param_values[] =
  20.318 +        {
  20.319 +            { .type = &abstract_type_string,
  20.320 +              .u.string_val = xspolicy },
  20.321 +            { .type = &abstract_type_int,
  20.322 +              .u.int_val = flags },
  20.323 +        };
  20.324 +
  20.325 +    abstract_type result_type = abstract_type_int;
  20.326 +
  20.327 +    *result = 0;
  20.328 +    XEN_CALL_("XSPolicy.activate_xspolicy");
  20.329 +    return session->ok;
  20.330 +}
    21.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Jul 11 11:32:30 2007 -0600
    21.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Jul 12 09:53:58 2007 +0100
    21.3 @@ -1164,6 +1164,10 @@ class XendDomain:
    21.4  
    21.5          if dominfo.getDomid() == DOM0_ID:
    21.6              raise XendError("Cannot dump core for privileged domain %s" % domid)
    21.7 +        if dominfo._stateGet() not in (DOM_STATE_PAUSED, DOM_STATE_RUNNING):
    21.8 +            raise VMBadState("Domain '%s' is not started" % domid,
    21.9 +                             POWER_STATE_NAMES[DOM_STATE_PAUSED],
   21.10 +                             POWER_STATE_NAMES[dominfo._stateGet()])
   21.11  
   21.12          try:
   21.13              log.info("Domain core dump requested for domain %s (%d) "
   21.14 @@ -1537,6 +1541,10 @@ class XendDomain:
   21.15          dominfo = self.domain_lookup_nr(domid)
   21.16          if not dominfo:
   21.17              raise XendInvalidDomain(str(domid))
   21.18 +        if dominfo._stateGet() not in (DOM_STATE_RUNNING, DOM_STATE_PAUSED):
   21.19 +            raise VMBadState("Domain '%s' is not started" % domid,
   21.20 +                             POWER_STATE_NAMES[DOM_STATE_RUNNING],
   21.21 +                             POWER_STATE_NAMES[dominfo._stateGet()])
   21.22          if trigger_name.lower() in TRIGGER_TYPE: 
   21.23              trigger = TRIGGER_TYPE[trigger_name.lower()]
   21.24          else:
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/python/xen/xm/activatepolicy.py	Thu Jul 12 09:53:58 2007 +0100
    22.3 @@ -0,0 +1,86 @@
    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) 2007 International Business Machines Corp.
   22.19 +# Author: Stefan Berger <stefanb@us.ibm.com>
   22.20 +#============================================================================
   22.21 +
   22.22 +"""Activate the managed policy of the system.
   22.23 +"""
   22.24 +
   22.25 +import sys
   22.26 +from xen.util import xsconstants
   22.27 +from xml.dom import minidom
   22.28 +from xen.xm.opts import OptionError
   22.29 +from xen.xm import getpolicy
   22.30 +from xen.xm import main as xm_main
   22.31 +from xen.xm.main import server
   22.32 +
   22.33 +def help():
   22.34 +    return """
   22.35 +    Usage: xm activatepolicy [options]
   22.36 +
   22.37 +    Activate the xend-managed policy.
   22.38 +
   22.39 +    The following options are defined:
   22.40 +      --load     Load the policy into the hypervisor.
   22.41 +      --boot     Have the system boot with the policy. Changes the default
   22.42 +                 title in grub.conf.
   22.43 +      --noboot   Remove the policy from the default entry in grub.conf.
   22.44 +    """
   22.45 +
   22.46 +def activate_policy(flags):
   22.47 +    policystate = server.xenapi.XSPolicy.get_xspolicy()
   22.48 +    xs_ref = policystate['xs_ref']
   22.49 +    if int(policystate['type']) == 0 or xs_ref == "":
   22.50 +        print "No policy is installed."
   22.51 +        return
   22.52 +    rc = int(server.xenapi.XSPolicy.activate_xspolicy(xs_ref, flags))
   22.53 +    if rc == flags:
   22.54 +        print "Successfully activated the policy."
   22.55 +    else:
   22.56 +        print "An error occurred trying to activate the policy: %s" % \
   22.57 +              xsconstants.xserr2string(rc)
   22.58 +
   22.59 +def remove_bootpolicy():
   22.60 +    server.xenapi.XSPolicy.rm_xsbootpolicy()
   22.61 +
   22.62 +def main(argv):
   22.63 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   22.64 +        raise OptionError('xm needs to be configured to use the xen-api.')
   22.65 +    flags = 0
   22.66 +    c = 1
   22.67 +
   22.68 +    while c < len(argv):
   22.69 +        if '--boot' == argv[c]:
   22.70 +            flags |= xsconstants.XS_INST_BOOT
   22.71 +        elif '--load' == argv[c]:
   22.72 +            flags |= xsconstants.XS_INST_LOAD
   22.73 +        elif '--noboot' == argv[c]:
   22.74 +            remove_bootpolicy()
   22.75 +        else:
   22.76 +            raise OptionError("Unknown command line option '%s'" % argv[c])
   22.77 +        c += 1
   22.78 +
   22.79 +    if flags != 0:
   22.80 +        activate_policy(flags)
   22.81 +
   22.82 +    getpolicy.getpolicy(False)
   22.83 +
   22.84 +if __name__ == '__main__':
   22.85 +    try:
   22.86 +        main(sys.argv)
   22.87 +    except Exception, e:
   22.88 +        sys.stderr.write('Error: %s\n' % str(e))
   22.89 +        sys.exit(-1)
    23.1 --- a/tools/python/xen/xm/addlabel.py	Wed Jul 11 11:32:30 2007 -0600
    23.2 +++ b/tools/python/xen/xm/addlabel.py	Thu Jul 12 09:53:58 2007 +0100
    23.3 @@ -25,17 +25,29 @@ import sys
    23.4  from xen.util import dictio
    23.5  from xen.util import security
    23.6  from xen.xm.opts import OptionError
    23.7 +from xen.util import xsconstants
    23.8 +from xen.xm import main as xm_main
    23.9 +from xen.xm.main import server
   23.10  
   23.11  def help():
   23.12      return """
   23.13      Format: xm addlabel <label> dom <configfile> [<policy>]
   23.14 -            xm addlabel <label> res <resource> [<policy>]
   23.15 +            xm addlabel <label> mgt <domain name> [<policy type>:<policy>]
   23.16 +            xm addlabel <label> res <resource> [[<policy type>:]<policy>]
   23.17      
   23.18      This program adds an acm_label entry into the 'configfile'
   23.19 -    for a domain or to the global resource label file for a
   23.20 -    resource. It derives the policy from the running hypervisor
   23.21 +    for a domain or allows to label a xend-managed domain.
   23.22 +    The global resource label file for is extended with labels for
   23.23 +    resources. It derives the policy from the running hypervisor
   23.24      if it is not given (optional parameter). If a label already
   23.25 -    exists for the given domain or resource, then addlabel fails."""
   23.26 +    exists for the given domain or resource, then addlabel fails.
   23.27 +
   23.28 +    For xend-managed domains, the 'mgt' parameter should be used and
   23.29 +    the 'xm' tool must have been configured to use the xen-api for
   23.30 +    communication with xen. If a policy is provided as last parameter,
   23.31 +    its type must also be given. Currently only one type of policy is
   23.32 +    supported and identified as 'ACM'. An example for a valid string
   23.33 +    is 'ACM:xm-test'. """
   23.34  
   23.35  
   23.36  def validate_config_file(configfile):
   23.37 @@ -66,32 +78,47 @@ def validate_config_file(configfile):
   23.38          return 1
   23.39  
   23.40  
   23.41 -def add_resource_label(label, resource, policyref):
   23.42 +def add_resource_label(label, resource, policyref, policy_type):
   23.43      """Adds a resource label to the global resource label file.
   23.44      """
   23.45 -    # sanity check: make sure this label can be instantiated later on
   23.46 -    ssidref = security.label2ssidref(label, policyref, 'res')
   23.47 +
   23.48 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   23.49 +
   23.50 +        # sanity check: make sure this label can be instantiated later on
   23.51 +        ssidref = security.label2ssidref(label, policyref, 'res')
   23.52 +
   23.53 +        #build canonical resource name
   23.54 +        resource = security.unify_resname(resource,mustexist=False)
   23.55  
   23.56 -    #build canonical resource name
   23.57 -    resource = security.unify_resname(resource)
   23.58 +        # see if this resource is already in the file
   23.59 +        access_control = {}
   23.60 +        fil = security.res_label_filename
   23.61 +        try:
   23.62 +            access_control = dictio.dict_read("resources", fil)
   23.63 +        except:
   23.64 +            print "Resource file not found, creating new file at:"
   23.65 +            print "%s" % (fil)
   23.66  
   23.67 -    # see if this resource is already in the file
   23.68 -    access_control = {}
   23.69 -    file = security.res_label_filename
   23.70 -    try:
   23.71 -        access_control = dictio.dict_read("resources", file)
   23.72 -    except:
   23.73 -        print "Resource file not found, creating new file at:"
   23.74 -        print "%s" % (file)
   23.75 +        if access_control.has_key(resource):
   23.76 +            security.err("This resource is already labeled.")
   23.77  
   23.78 -    if access_control.has_key(resource):
   23.79 -        security.err("This resource is already labeled.")
   23.80 -
   23.81 -    # write the data to file
   23.82 -    new_entry = { resource : tuple([policyref, label]) }
   23.83 -    access_control.update(new_entry)
   23.84 -    dictio.dict_write(access_control, "resources", file)
   23.85 -
   23.86 +        # write the data to file
   23.87 +        new_entry = { resource : tuple([policy_type, policyref, label]) }
   23.88 +        access_control.update(new_entry)
   23.89 +        dictio.dict_write(access_control, "resources", fil)
   23.90 +    else:
   23.91 +        res = [ policy_type, policyref, label ]
   23.92 +        res_xapi = security.format_resource_label(res)
   23.93 +        old = server.xenapi.XSPolicy.get_resource_label(resource)
   23.94 +        if old == "":
   23.95 +            try:
   23.96 +                server.xenapi.XSPolicy.set_resource_label(resource,
   23.97 +                                                          res_xapi,
   23.98 +                                                          "")
   23.99 +            except Exception, e:
  23.100 +                security.err("Could not label this resource: %s" % e)
  23.101 +        else:
  23.102 +            security.err("'%s' is already labeled with '%s'" % (resource,old))
  23.103  
  23.104  def add_domain_label(label, configfile, policyref):
  23.105      # sanity checks: make sure this label can be instantiated later on
  23.106 @@ -109,9 +136,35 @@ def add_domain_label(label, configfile, 
  23.107      config_fd.write(new_label)
  23.108      config_fd.close()
  23.109  
  23.110 +def add_domain_label_xapi(label, domainname, policyref, policy_type):
  23.111 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
  23.112 +        raise OptionError('Xm must be configured to use the xen-api.')
  23.113 +    uuids = server.xenapi.VM.get_by_name_label(domainname)
  23.114 +    if len(uuids) == 0:
  23.115 +        raise OptionError('A VM with that name does not exist.')
  23.116 +    if len(uuids) != 1:
  23.117 +        raise OptionError('There are multiple domains with the same name.')
  23.118 +    uuid = uuids[0]
  23.119 +    sec_lab = "%s:%s:%s" % (policy_type, policyref, label)
  23.120 +    try:
  23.121 +        old_lab = server.xenapi.VM.get_security_label(uuid)
  23.122 +        rc = server.xenapi.VM.set_security_label(uuid, sec_lab, old_lab)
  23.123 +    except:
  23.124 +        rc = -1
  23.125 +    if int(rc) < 0:
  23.126 +        raise OptionError('Could not label domain.')
  23.127 +    else:
  23.128 +        ssidref = int(rc)
  23.129 +        if ssidref != 0:
  23.130 +            print "Set the label of domain '%s' to '%s'. New ssidref = %08x" % \
  23.131 +                  (domainname,label,ssidref)
  23.132 +        else:
  23.133 +            print "Set the label of dormant domain '%s' to '%s'." % \
  23.134 +                  (domainname,label)
  23.135  
  23.136  def main(argv):
  23.137      policyref = None
  23.138 +    policy_type = ""
  23.139      if len(argv) not in (4, 5):
  23.140          raise OptionError('Needs either 2 or 3 arguments')
  23.141      
  23.142 @@ -121,6 +174,7 @@ def main(argv):
  23.143          policyref = argv[4]
  23.144      elif security.on():
  23.145          policyref = security.active_policy
  23.146 +        policy_type = xsconstants.ACM_POLICY_ID
  23.147      else:
  23.148          raise OptionError("No active policy. Must specify policy on the "
  23.149                            "command line.")
  23.150 @@ -136,11 +190,27 @@ def main(argv):
  23.151              raise OptionError('Invalid config file')
  23.152          else:
  23.153              add_domain_label(label, configfile, policyref)
  23.154 +    elif argv[2].lower() == "mgt":
  23.155 +        domain = argv[3]
  23.156 +        if policy_type == "":
  23.157 +            tmp = policyref.split(":")
  23.158 +            if len(tmp) != 2:
  23.159 +                raise OptionError("Policy name in wrong format.")
  23.160 +            policy_type, policyref = tmp
  23.161 +        add_domain_label_xapi(label, domain, policyref, policy_type)
  23.162      elif argv[2].lower() == "res":
  23.163          resource = argv[3]
  23.164 -        add_resource_label(label, resource, policyref)
  23.165 +        if policy_type == "":
  23.166 +            tmp = policyref.split(":")
  23.167 +            if len(tmp) == 1:
  23.168 +                policy_type = xsconstants.ACM_POLICY_ID
  23.169 +            elif len(tmp) == 2:
  23.170 +                policy_type, policyref = tmp
  23.171 +            else:
  23.172 +                raise OptionError("Policy name in wrong format.")
  23.173 +        add_resource_label(label, resource, policyref, policy_type)
  23.174      else:
  23.175 -        raise OptionError('Need to specify either "dom" or "res" as '
  23.176 +        raise OptionError('Need to specify either "dom", "mgt" or "res" as '
  23.177                            'object to add label to.')
  23.178              
  23.179  if __name__ == '__main__':
  23.180 @@ -149,6 +219,3 @@ if __name__ == '__main__':
  23.181      except Exception, e:
  23.182          sys.stderr.write('Error: %s\n' % str(e))
  23.183          sys.exit(-1)
  23.184 -    
  23.185 -
  23.186 -
    24.1 --- a/tools/python/xen/xm/cfgbootpolicy.py	Wed Jul 11 11:32:30 2007 -0600
    24.2 +++ b/tools/python/xen/xm/cfgbootpolicy.py	Thu Jul 12 09:53:58 2007 +0100
    24.3 @@ -31,7 +31,11 @@ from xen.util.security import policy_dir
    24.4  from xen.util.security import boot_filename, altboot_filename
    24.5  from xen.util.security import any_title_re, xen_kernel_re, any_module_re
    24.6  from xen.util.security import empty_line_re, binary_name_re, policy_name_re
    24.7 +from xen.util import xsconstants
    24.8  from xen.xm.opts import OptionError
    24.9 +from xen.xm import main as xm_main
   24.10 +from xen.xm.main import server
   24.11 +from xen.util.acmpolicy import ACMPolicy
   24.12  
   24.13  def help():
   24.14      return """
   24.15 @@ -144,6 +148,39 @@ def insert_policy(boot_file, alt_boot_fi
   24.16          pass
   24.17      return extended_titles[0]
   24.18  
   24.19 +def cfgbootpolicy_xapi(policy, user_title=None):
   24.20 +    xstype = int(server.xenapi.XSPolicy.get_xstype())
   24.21 +    if xstype & xsconstants.XS_POLICY_ACM == 0:
   24.22 +        raise OptionError("ACM policy not supported on system.")
   24.23 +    if user_title:
   24.24 +        raise OptionError("Only the default title is supported with Xen-API.")
   24.25 +
   24.26 +    policystate = server.xenapi.XSPolicy.get_xspolicy()
   24.27 +    if int(policystate['type']) == 0:
   24.28 +        print "No policy is installed."
   24.29 +        return
   24.30 +
   24.31 +    if int(policystate['type']) != xsconstants.XS_POLICY_ACM:
   24.32 +        print "Unknown policy type '%s'." % policystate['type']
   24.33 +        return
   24.34 +    else:
   24.35 +        xml = policystate['repr']
   24.36 +        xs_ref = policystate['xs_ref']
   24.37 +        if not xml:
   24.38 +            OptionError("No policy installed on system?")
   24.39 +        acmpol = ACMPolicy(xml=xml)
   24.40 +        if acmpol.get_name() != policy:
   24.41 +            OptionError("Policy installed on system '%s' does not match the "
   24.42 +                        "request policy '%s'" % (acmpol.get_name(), policy))
   24.43 +        flags = int(policystate['flags']) | xsconstants.XS_INST_BOOT
   24.44 +        rc = int(server.xenapi.XSPolicy.activate_xspolicy(xs_ref, flags))
   24.45 +        if rc == flags:
   24.46 +            print "Successfully enabled the policy for having the system" \
   24.47 +                  " booted with."
   24.48 +        else:
   24.49 +            print "An error occurred during the operation: %s" % \
   24.50 +                  xsconstants.xserr2string(rc)
   24.51 +
   24.52  
   24.53  def main(argv):
   24.54      user_kver = None
   24.55 @@ -159,24 +196,27 @@ def main(argv):
   24.56      if not policy_name_re.match(policy):
   24.57          raise OptionError("Illegal policy name: '%s'" % policy)
   24.58  
   24.59 -    policy_file = '/'.join([policy_dir_prefix] + policy.split('.'))
   24.60 -    src_binary_policy_file = policy_file + ".bin"
   24.61 -    #check if .bin exists or if policy file exists
   24.62 -    if not os.path.isfile(src_binary_policy_file):
   24.63 -        if not os.path.isfile(policy_file + "-security_policy.xml"):
   24.64 -            raise OptionError("Unknown policy '%s'" % policy)
   24.65 -        else:
   24.66 -            err_msg = "Cannot find binary file for policy '%s'." % policy
   24.67 -            err_msg += " Please use makepolicy to create binary file."
   24.68 -            raise OptionError(err_msg)
   24.69 +    if xm_main.serverType == xm_main.SERVER_XEN_API:
   24.70 +        cfgbootpolicy_xapi(policy)
   24.71 +    else:
   24.72 +        policy_file = '/'.join([policy_dir_prefix] + policy.split('.'))
   24.73 +        src_binary_policy_file = policy_file + ".bin"
   24.74 +        #check if .bin exists or if policy file exists
   24.75 +        if not os.path.isfile(src_binary_policy_file):
   24.76 +            if not os.path.isfile(policy_file + "-security_policy.xml"):
   24.77 +                raise OptionError("Unknown policy '%s'" % policy)
   24.78 +            else:
   24.79 +                err_msg = "Cannot find binary file for policy '%s'." % policy
   24.80 +                err_msg += " Please use makepolicy to create binary file."
   24.81 +                raise OptionError(err_msg)
   24.82      
   24.83 -    dst_binary_policy_file = "/boot/" + policy + ".bin"
   24.84 -    shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
   24.85 +        dst_binary_policy_file = "/boot/" + policy + ".bin"
   24.86 +        shutil.copyfile(src_binary_policy_file, dst_binary_policy_file)
   24.87      
   24.88 -    entryname = insert_policy(boot_filename, altboot_filename,
   24.89 -                              user_title, policy)
   24.90 -    print "Boot entry '%s' extended and \'%s\' copied to /boot" \
   24.91 -          % (entryname, policy + ".bin")
   24.92 +        entryname = insert_policy(boot_filename, altboot_filename,
   24.93 +                                  user_title, policy)
   24.94 +        print "Boot entry '%s' extended and \'%s\' copied to /boot" \
   24.95 +              % (entryname, policy + ".bin")
   24.96  
   24.97  if __name__ == '__main__':
   24.98      try:
    25.1 --- a/tools/python/xen/xm/create.dtd	Wed Jul 11 11:32:30 2007 -0600
    25.2 +++ b/tools/python/xen/xm/create.dtd	Thu Jul 12 09:53:58 2007 +0100
    25.3 @@ -38,6 +38,7 @@
    25.4                   memory,
    25.5                   vbd*,
    25.6                   vif*,
    25.7 +                 vtpm*,
    25.8                   console*,
    25.9                   platform*,
   25.10                   vcpu_param*,
   25.11 @@ -49,7 +50,8 @@
   25.12                   actions_after_shutdown %NORMAL_EXIT; #REQUIRED 
   25.13                   actions_after_reboot   %NORMAL_EXIT; #REQUIRED
   25.14                   actions_after_crash    %CRASH_BEHAVIOUR; #REQUIRED
   25.15 -                 PCI_bus                CDATA #REQUIRED> 
   25.16 +                 PCI_bus                CDATA #REQUIRED
   25.17 +                 security_label         CDATA #IMPLIED>
   25.18  
   25.19  <!ELEMENT memory EMPTY> 
   25.20  <!ATTLIST memory static_min      CDATA #REQUIRED
   25.21 @@ -74,6 +76,9 @@
   25.22                   qos_algorithm_type CDATA    #REQUIRED
   25.23                   network         CDATA       #IMPLIED> 
   25.24  
   25.25 +<!ELEMENT vtpm   (name*)>
   25.26 +<!ATTLIST vtpm   backend         CDATA #REQUIRED>
   25.27 +
   25.28  <!ELEMENT console (other_config*)>
   25.29  <!ATTLIST console protocol       (vt100|rfb|rdp) #REQUIRED>
   25.30  
    26.1 --- a/tools/python/xen/xm/create.py	Wed Jul 11 11:32:30 2007 -0600
    26.2 +++ b/tools/python/xen/xm/create.py	Thu Jul 12 09:53:58 2007 +0100
    26.3 @@ -643,22 +643,12 @@ def configure_security(config, vals):
    26.4                                   ['policy', policy],
    26.5                                   ['label', label] ]
    26.6  
    26.7 -        #ssidref cannot be specified together with access_control
    26.8 -        if sxp.child_value(config, 'ssidref'):
    26.9 -            err("ERROR: SSIDREF and access_control are mutually exclusive but both specified!")
   26.10 -        #else calculate ssidre from label
   26.11 +        #calculate ssidref from label
   26.12          ssidref = security.label2ssidref(label, policy, 'dom')
   26.13          if not ssidref :
   26.14              err("ERROR calculating ssidref from access_control.")
   26.15          security_label = ['security', [ config_access_control, ['ssidref' , ssidref ] ] ]
   26.16          config.append(security_label)
   26.17 -    elif num == 0:
   26.18 -        if hasattr(vals, 'ssidref'):
   26.19 -            if not security.on():
   26.20 -                err("ERROR: Security ssidref specified but no policy active.")
   26.21 -            ssidref = getattr(vals, 'ssidref')
   26.22 -            security_label = ['security', [ [ 'ssidref' , int(ssidref) ] ] ]
   26.23 -            config.append(security_label)
   26.24      elif num > 1:
   26.25          err("VM config error: Multiple access_control definitions!")
   26.26  
   26.27 @@ -1231,13 +1221,13 @@ def config_security_check(config, verbos
   26.28  
   26.29          except security.ACMError:
   26.30              print "   %s: DENIED" % (resource)
   26.31 -            (res_label, res_policy) = security.get_res_label(resource)
   26.32 +            (poltype, res_label, res_policy) = security.get_res_label(resource)
   26.33              if not res_label:
   26.34                  res_label = ""
   26.35 -            print "   --> res: %s (%s)" % (str(res_label),
   26.36 -                                           str(res_policy))
   26.37 -            print "   --> dom: %s (%s)" % (str(domain_label),
   26.38 -                                           str(domain_policy))
   26.39 +            print "   --> res: %s (%s:%s)" % (str(res_label),
   26.40 +                                           str(poltype), str(res_policy))
   26.41 +            print "   --> dom: %s (%s:%s)" % (str(domain_label),
   26.42 +                                           str(poltype), str(domain_policy))
   26.43  
   26.44              answer = 0
   26.45  
    27.1 --- a/tools/python/xen/xm/getlabel.py	Wed Jul 11 11:32:30 2007 -0600
    27.2 +++ b/tools/python/xen/xm/getlabel.py	Thu Jul 12 09:53:58 2007 +0100
    27.3 @@ -21,14 +21,19 @@
    27.4  import sys, os, re
    27.5  from xen.util import dictio
    27.6  from xen.util import security
    27.7 +from xen.util import xsconstants
    27.8  from xen.xm.opts import OptionError
    27.9 +from xen.xm import main as xm_main
   27.10 +from xen.xm.main import server
   27.11  
   27.12  def help():
   27.13      return """
   27.14      Usage: xm getlabel dom <configfile>
   27.15 +           xm getlabel mgt <domain name>
   27.16             xm getlabel res <resource>
   27.17             
   27.18 -    This program shows the label for a domain or resource."""
   27.19 +    This program shows the label for a domain, resource or virtual network
   27.20 +    interface of a Xend-managed domain."""
   27.21  
   27.22  def get_resource_label(resource):
   27.23      """Gets the resource label
   27.24 @@ -37,17 +42,24 @@ def get_resource_label(resource):
   27.25      resource = security.unify_resname(resource)
   27.26  
   27.27      # read in the resource file
   27.28 -    file = security.res_label_filename
   27.29 +    fil = security.res_label_filename
   27.30      try:
   27.31 -        access_control = dictio.dict_read("resources", file)
   27.32 +        access_control = dictio.dict_read("resources", fil)
   27.33      except:
   27.34          raise OptionError("Resource label file not found")
   27.35  
   27.36      # get the entry and print label
   27.37      if access_control.has_key(resource):
   27.38 -        policy = access_control[resource][0]
   27.39 -        label = access_control[resource][1]
   27.40 -        print "policy="+policy+",label="+label
   27.41 +        tmp = access_control[resource]
   27.42 +        if len(tmp) == 2:
   27.43 +            policy, label = tmp
   27.44 +            policytype = xsconstants.ACM_POLICY_ID
   27.45 +        elif len(tmp) == 3:
   27.46 +            policytype, policy, label = tmp
   27.47 +        else:
   27.48 +            raise security.ACMError("Resource not properly labeled. "
   27.49 +                                    "Please relabel the resource.")
   27.50 +        print policytype+":"+policy+":"+label
   27.51      else:
   27.52          raise security.ACMError("Resource not labeled")
   27.53  
   27.54 @@ -89,8 +101,19 @@ def get_domain_label(configfile):
   27.55      data = data.strip()
   27.56      data = data.lstrip("[\'")
   27.57      data = data.rstrip("\']")
   27.58 -    print data
   27.59 +    print "policytype=%s," % xsconstants.ACM_POLICY_ID + data
   27.60  
   27.61 +def get_domain_label_xapi(domainname):
   27.62 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   27.63 +        raise OptionError('xm needs to be configure to use the xen-api.')
   27.64 +    uuids = server.xenapi.VM.get_by_name_label(domainname)
   27.65 +    if len(uuids) == 0:
   27.66 +        raise OptionError('A VM with that name does not exist.')
   27.67 +    if len(uuids) != 1:
   27.68 +        raise OptionError('There are multiple domains with the same name.')
   27.69 +    uuid = uuids[0]
   27.70 +    sec_lab = server.xenapi.VM.get_security_label(uuid)
   27.71 +    print "%s" %sec_lab
   27.72  
   27.73  def main(argv):
   27.74      if len(argv) != 3:
   27.75 @@ -99,11 +122,15 @@ def main(argv):
   27.76      if argv[1].lower() == "dom":
   27.77          configfile = argv[2]
   27.78          get_domain_label(configfile)
   27.79 +    elif argv[1].lower() == "mgt":
   27.80 +        domainname = argv[2]
   27.81 +        get_domain_label_xapi(domainname)
   27.82      elif argv[1].lower() == "res":
   27.83          resource = argv[2]
   27.84          get_resource_label(resource)
   27.85      else:
   27.86 -        raise OptionError('First subcommand argument must be "dom" or "res"')
   27.87 +        raise OptionError('First subcommand argument must be "dom"'
   27.88 +                          ', "mgt" or "res"')
   27.89  
   27.90  if __name__ == '__main__':
   27.91      try:
   27.92 @@ -111,6 +138,4 @@ if __name__ == '__main__':
   27.93      except Exception, e:
   27.94          sys.stderr.write('Error: %s\n' % str(e))
   27.95          sys.exit(-1)
   27.96 -        
   27.97  
   27.98 -
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/tools/python/xen/xm/getpolicy.py	Thu Jul 12 09:53:58 2007 +0100
    28.3 @@ -0,0 +1,94 @@
    28.4 +#============================================================================
    28.5 +# This library is free software; you can redistribute it and/or
    28.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    28.7 +# License as published by the Free Software Foundation.
    28.8 +#
    28.9 +# This library is distributed in the hope that it will be useful,
   28.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   28.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   28.12 +# Lesser General Public License for more details.
   28.13 +#
   28.14 +# You should have received a copy of the GNU Lesser General Public
   28.15 +# License along with this library; if not, write to the Free Software
   28.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   28.17 +#============================================================================
   28.18 +# Copyright (C) 2007 International Business Machines Corp.
   28.19 +# Author: Stefan Berger <stefanb@us.ibm.com>
   28.20 +#============================================================================
   28.21 +
   28.22 +"""Get the managed policy of the system.
   28.23 +"""
   28.24 +
   28.25 +import sys
   28.26 +from xen.util import xsconstants
   28.27 +from xml.dom import minidom
   28.28 +from xen.xm.opts import OptionError
   28.29 +from xen.util.acmpolicy import ACMPolicy
   28.30 +from xen.xm import main as xm_main
   28.31 +from xen.xm.main import server
   28.32 +
   28.33 +def help():
   28.34 +    return """
   28.35 +    Usage: xm getpolicy [options]
   28.36 +
   28.37 +    The following options are defined
   28.38 +      --dumpxml     Display the XML of the policy
   28.39 +
   28.40 +    Get the policy managed by xend."""
   28.41 +
   28.42 +def getpolicy(dumpxml):
   28.43 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   28.44 +        raise OptionError('xm needs to be configured to use the xen-api.')
   28.45 +    types = []
   28.46 +    xstype = int(server.xenapi.XSPolicy.get_xstype())
   28.47 +    if xstype & xsconstants.XS_POLICY_ACM:
   28.48 +        types.append("ACM")
   28.49 +        xstype ^= xsconstants.XS_POLICY_ACM
   28.50 +    if xstype != 0:
   28.51 +        types.append("unsupported (%08x)" % xstype)
   28.52 +    print "Supported security subsystems   : %s \n" % ", ".join(types)
   28.53 +
   28.54 +    policystate = server.xenapi.XSPolicy.get_xspolicy()
   28.55 +    if int(policystate['type']) == 0:
   28.56 +        print "No policy is installed."
   28.57 +        return
   28.58 +    if int(policystate['type']) != xsconstants.XS_POLICY_ACM:
   28.59 +        print "Unknown policy type '%s'." % policystate['type']
   28.60 +    else:
   28.61 +        xml = policystate['repr']
   28.62 +        acmpol = None
   28.63 +        if xml:
   28.64 +            acmpol = ACMPolicy(xml=xml)
   28.65 +        print "Policy installed on the system:"
   28.66 +        if acmpol:
   28.67 +            print "Policy name           : %s" % acmpol.get_name()
   28.68 +        print "Policy type           : %s" % xsconstants.ACM_POLICY_ID
   28.69 +        print "Reference             : %s" % policystate['xs_ref']
   28.70 +        print "Version of XML policy : %s" % policystate['version']
   28.71 +        state = []
   28.72 +        flags = int(policystate['flags'])
   28.73 +        if flags & xsconstants.XS_INST_LOAD:
   28.74 +            state.append("loaded")
   28.75 +        if flags & xsconstants.XS_INST_BOOT:
   28.76 +            state.append("system booted with")
   28.77 +        print "State of the policy   : %s" % ", ".join(state)
   28.78 +        if dumpxml:
   28.79 +            xml = policystate['repr']
   28.80 +            if xml:
   28.81 +                dom = minidom.parseString(xml.encode("utf-8"))
   28.82 +                print "%s" % dom.toprettyxml(indent="   ",newl="\n")
   28.83 +
   28.84 +def main(argv):
   28.85 +    dumpxml = False
   28.86 +
   28.87 +    if '--dumpxml' in argv:
   28.88 +        dumpxml = True
   28.89 +
   28.90 +    getpolicy(dumpxml)
   28.91 +
   28.92 +if __name__ == '__main__':
   28.93 +    try:
   28.94 +        main(sys.argv)
   28.95 +    except Exception, e:
   28.96 +        sys.stderr.write('Error: %s\n' % str(e))
   28.97 +        sys.exit(-1)
    29.1 --- a/tools/python/xen/xm/labels.py	Wed Jul 11 11:32:30 2007 -0600
    29.2 +++ b/tools/python/xen/xm/labels.py	Thu Jul 12 09:53:58 2007 +0100
    29.3 @@ -24,6 +24,10 @@ import string
    29.4  from xen.util.security import ACMError, err, list_labels, active_policy
    29.5  from xen.util.security import vm_label_re, res_label_re, all_label_re
    29.6  from xen.xm.opts import OptionError
    29.7 +from xen.util.acmpolicy import ACMPolicy
    29.8 +from xen.util import xsconstants
    29.9 +from xen.xm.main import server
   29.10 +from xen.xm import main as xm_main
   29.11  
   29.12  
   29.13  def help():
   29.14 @@ -48,6 +52,12 @@ def main(argv):
   29.15          else:
   29.16              raise OptionError('Unrecognised option: %s' % arg)
   29.17  
   29.18 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   29.19 +        labels(policy, ptype)
   29.20 +    else:
   29.21 +        labels_xapi(policy, ptype)
   29.22 +
   29.23 +def labels(policy, ptype):
   29.24      if not policy:
   29.25          policy = active_policy
   29.26          if active_policy in ['NULL', 'INACTIVE', 'DEFAULT']:
   29.27 @@ -73,7 +83,30 @@ def main(argv):
   29.28      except:
   29.29          traceback.print_exc(limit = 1)
   29.30  
   29.31 +def labels_xapi(policy, ptype):
   29.32 +    policystate = server.xenapi.XSPolicy.get_xspolicy()
   29.33 +    if int(policystate['type']) == xsconstants.XS_POLICY_ACM:
   29.34 +        acmpol = ACMPolicy(xml=policystate['repr'])
   29.35 +        if policy and policy != acmpol.get_name():
   29.36 +            print "Warning: '%s' is not the currently loaded policy." % policy
   29.37 +            return labels(policy, ptype)
   29.38 +        names1 = []
   29.39 +        names2 = []
   29.40 +        if not ptype or ptype == 'dom' or ptype == 'any':
   29.41 +            names1 = acmpol.policy_get_virtualmachinelabel_names()
   29.42 +        if ptype == 'res' or ptype == 'any':
   29.43 +            names2 = acmpol.policy_get_resourcelabel_names()
   29.44 +        if len(names1) > 0:
   29.45 +            names = set(names1)
   29.46 +            names.union(names2)
   29.47 +        else:
   29.48 +            names = set(names2)
   29.49 +        for n in names:
   29.50 +            print n
   29.51 +    elif int(policystate['type']) == 0:
   29.52 +        print "No policy installed on the system."
   29.53 +    else:
   29.54 +        print "Unsupported type of policy installed on the system."
   29.55 +
   29.56  if __name__ == '__main__':
   29.57      main(sys.argv)
   29.58 -
   29.59 -
    30.1 --- a/tools/python/xen/xm/loadpolicy.py	Wed Jul 11 11:32:30 2007 -0600
    30.2 +++ b/tools/python/xen/xm/loadpolicy.py	Thu Jul 12 09:53:58 2007 +0100
    30.3 @@ -22,6 +22,11 @@ import sys
    30.4  import traceback
    30.5  from xen.util.security import ACMError, err, load_policy
    30.6  from xen.xm.opts import OptionError
    30.7 +from xen.xm import main as xm_main
    30.8 +from xen.util import xsconstants
    30.9 +from xen.xm.activatepolicy import activate_policy
   30.10 +from xen.xm.main import server
   30.11 +from xen.util.acmpolicy import ACMPolicy
   30.12  
   30.13  def help():
   30.14      return """Load the compiled binary (.bin) policy into the running
   30.15 @@ -30,8 +35,31 @@ def help():
   30.16  def main(argv):
   30.17      if len(argv) != 2:
   30.18          raise OptionError('No policy defined')
   30.19 -    
   30.20 -    load_policy(argv[1])
   30.21 +    if xm_main.serverType == xm_main.SERVER_XEN_API:
   30.22 +        policy = argv[1]
   30.23 +        print "This command is deprecated for use with Xen-API " \
   30.24 +              "configuration. Consider using\n'xm activatepolicy'."
   30.25 +        policystate = server.xenapi.XSPolicy.get_xspolicy()
   30.26 +        if int(policystate['type']) == 0:
   30.27 +            print "No policy is installed."
   30.28 +            return
   30.29 +
   30.30 +        if int(policystate['type']) != xsconstants.XS_POLICY_ACM:
   30.31 +            print "Unknown policy type '%s'." % policystate['type']
   30.32 +            return
   30.33 +        else:
   30.34 +            xml = policystate['repr']
   30.35 +            xs_ref = policystate['xs_ref']
   30.36 +            if not xml:
   30.37 +                OptionError("No policy installed on system?")
   30.38 +            acmpol = ACMPolicy(xml=xml)
   30.39 +            if acmpol.get_name() != policy:
   30.40 +                OptionError("Policy installed on system '%s' does not match"\
   30.41 +                            " the request policy '%s'" % \
   30.42 +                            (acmpol.get_name(), policy))
   30.43 +            activate_policy(xsconstants.XS_INST_LOAD)
   30.44 +    else:
   30.45 +        load_policy(argv[1])
   30.46  
   30.47  if __name__ == '__main__':
   30.48      try:
    31.1 --- a/tools/python/xen/xm/main.py	Wed Jul 11 11:32:30 2007 -0600
    31.2 +++ b/tools/python/xen/xm/main.py	Thu Jul 12 09:53:58 2007 +0100
    31.3 @@ -50,6 +50,7 @@ from xen.xend.XendConstants import *
    31.4  from xen.xm.opts import OptionError, Opts, wrap, set_true
    31.5  from xen.xm import console
    31.6  from xen.util.xmlrpcclient import ServerProxy
    31.7 +from xen.util.security import ACMError
    31.8  
    31.9  import XenAPI
   31.10  
   31.11 @@ -171,11 +172,12 @@ SUBCOMMAND_HELP = {
   31.12  
   31.13      # security
   31.14  
   31.15 -    'addlabel'      :  ('<label> {dom <ConfigFile>|res <resource>} [<policy>]',
   31.16 +    'addlabel'      :  ('<label> {dom <ConfigFile>|res <resource>|mgt <managed domain>}\n'
   31.17 +                        '                   [<policy>]',
   31.18                          'Add security label to domain.'),
   31.19 -    'rmlabel'       :  ('{dom <ConfigFile>|res <Resource>}',
   31.20 +    'rmlabel'       :  ('{dom <ConfigFile>|res <Resource>|mgt<managed domain>}',
   31.21                          'Remove a security label from domain.'),
   31.22 -    'getlabel'      :  ('{dom <ConfigFile>|res <Resource>}',
   31.23 +    'getlabel'      :  ('{dom <ConfigFile>|res <Resource>|mgt <managed domain>}',
   31.24                          'Show security label for domain or resource.'),
   31.25      'dry-run'       :  ('<ConfigFile>',
   31.26                          'Test if a domain can access its resources.'),
   31.27 @@ -186,6 +188,10 @@ SUBCOMMAND_HELP = {
   31.28      'loadpolicy'    :  ('<policy.bin>', 'Load binary policy into hypervisor.'),
   31.29      'makepolicy'    :  ('<policy>', 'Build policy and create .bin/.map '
   31.30                          'files.'),
   31.31 +    'setpolicy'     :  ('<policytype> <policyfile> [options]',
   31.32 +                        'Set the policy of the system.'),
   31.33 +    'getpolicy'     :  ('[options]', 'Get the policy of the system.'),
   31.34 +    'activatepolicy':  ('[options]', 'Activate the xend-managed policy.'),
   31.35      'labels'        :  ('[policy] [type=dom|res|any]',
   31.36                          'List <type> labels for (active) policy.'),
   31.37      'serve'         :  ('', 'Proxy Xend XMLRPC over stdio.'),
   31.38 @@ -343,6 +349,9 @@ acm_commands = [
   31.39      "loadpolicy",
   31.40      "cfgbootpolicy",
   31.41      "dumppolicy",
   31.42 +    "activatepolicy",
   31.43 +    "setpolicy",
   31.44 +    "getpolicy",
   31.45      ]
   31.46  
   31.47  all_commands = (domain_commands + host_commands + scheduler_commands +
   31.48 @@ -861,13 +870,17 @@ def parse_doms_info(info):
   31.49          'up_time'  : up_time
   31.50          }
   31.51  
   31.52 -    # We're not supporting security stuff just yet via XenAPI
   31.53 -
   31.54      if serverType != SERVER_XEN_API:
   31.55          from xen.util import security
   31.56          parsed_info['seclabel'] = security.get_security_printlabel(info)
   31.57      else:
   31.58 -        parsed_info['seclabel'] = ""
   31.59 +        label = get_info('security_label', unicode, '')
   31.60 +        tmp = label.split(":")
   31.61 +        if len(tmp) != 3:
   31.62 +            label = ""
   31.63 +        else:
   31.64 +            label = tmp[2]
   31.65 +        parsed_info['seclabel'] = label
   31.66  
   31.67      if serverType == SERVER_XEN_API:
   31.68          parsed_info['mem'] = get_info('memory_actual', int, 0) / 1024
   31.69 @@ -925,28 +938,26 @@ def xm_brief_list(doms):
   31.70          print format % d
   31.71  
   31.72  def xm_label_list(doms):
   31.73 -    print '%-32s %5s %5s %5s %5s %9s %-8s' % \
   31.74 +    print '%-32s %5s %5s %5s %10s %9s %-8s' % \
   31.75            ('Name', 'ID', 'Mem', 'VCPUs', 'State', 'Time(s)', 'Label')
   31.76      
   31.77      output = []
   31.78      format = '%(name)-32s %(domid)5s %(mem)5d %(vcpus)5d %(state)10s ' \
   31.79               '%(cpu_time)8.1f %(seclabel)9s'
   31.80  
   31.81 -    if serverType != SERVER_XEN_API:
   31.82 -        from xen.util import security
   31.83 +    from xen.util import security
   31.84          
   31.85 -        for dom in doms:
   31.86 -            d = parse_doms_info(dom)
   31.87 +    for dom in doms:
   31.88 +        d = parse_doms_info(dom)
   31.89 +        if security.active_policy not in ['INACTIVE', 'NULL', 'DEFAULT']:
   31.90 +            if not d['seclabel']:
   31.91 +                d['seclabel'] = 'ERROR'
   31.92 +        elif security.active_policy in ['DEFAULT']:
   31.93 +            d['seclabel'] = 'DEFAULT'
   31.94 +        else:
   31.95 +            d['seclabel'] = 'INACTIVE'
   31.96  
   31.97 -            if security.active_policy not in ['INACTIVE', 'NULL', 'DEFAULT']:
   31.98 -                if not d['seclabel']:
   31.99 -                    d['seclabel'] = 'ERROR'
  31.100 -            elif security.active_policy in ['DEFAULT']:
  31.101 -                d['seclabel'] = 'DEFAULT'
  31.102 -            else:
  31.103 -                d['seclabel'] = 'INACTIVE'
  31.104 -
  31.105 -            output.append((format % d, d['seclabel']))
  31.106 +        output.append((format % d, d['seclabel']))
  31.107          
  31.108      #sort by labels
  31.109      output.sort(lambda x,y: cmp( x[1].lower(), y[1].lower()))
  31.110 @@ -1989,16 +2000,24 @@ def xm_block_list(args):
  31.111                     % ni)
  31.112  
  31.113  def xm_vtpm_list(args):
  31.114 -    xenapi_unsupported()
  31.115      (use_long, params) = arg_check_for_resource_list(args, "vtpm-list")
  31.116  
  31.117      dom = params[0]
  31.118 +
  31.119 +    if serverType == SERVER_XEN_API:
  31.120 +        vtpm_refs = server.xenapi.VM.get_VTPMs(get_single_vm(dom))
  31.121 +        vtpm_properties = \
  31.122 +            map(server.xenapi.VTPM.get_runtime_properties, vtpm_refs)
  31.123 +        devs = map(lambda (handle, properties): [handle, map2sxp(properties)],
  31.124 +                   zip(range(len(vtpm_properties)), vtpm_properties))
  31.125 +    else:
  31.126 +        devs = server.xend.domain.getDeviceSxprs(dom, 'vtpm')
  31.127 +
  31.128      if use_long:
  31.129 -        devs = server.xend.domain.getDeviceSxprs(dom, 'vtpm')
  31.130          map(PrettyPrint.prettyprint, devs)
  31.131      else:
  31.132          hdr = 0
  31.133 -        for x in server.xend.domain.getDeviceSxprs(dom, 'vtpm'):
  31.134 +        for x in devs:
  31.135              if hdr == 0:
  31.136                  print 'Idx  BE handle state evt-ch ring-ref BE-path'
  31.137                  hdr = 1
  31.138 @@ -2440,6 +2459,9 @@ IMPORTED_COMMANDS = [
  31.139      'getlabel',
  31.140      'dry-run',
  31.141      'resources',
  31.142 +    'getpolicy',
  31.143 +    'setpolicy',
  31.144 +    'activatepolicy',
  31.145      ]
  31.146  
  31.147  for c in IMPORTED_COMMANDS:
  31.148 @@ -2563,6 +2585,8 @@ def _run_cmd(cmd, cmd_name, args):
  31.149          print e.usage
  31.150      except XenAPIUnsupportedException, e:
  31.151          err(str(e))
  31.152 +    except ACMError, e:
  31.153 +        err(str(e))
  31.154      except Exception, e:
  31.155          if serverType != SERVER_XEN_API:
  31.156             from xen.util import security
    32.1 --- a/tools/python/xen/xm/makepolicy.py	Wed Jul 11 11:32:30 2007 -0600
    32.2 +++ b/tools/python/xen/xm/makepolicy.py	Thu Jul 12 09:53:58 2007 +0100
    32.3 @@ -20,7 +20,10 @@
    32.4  import sys
    32.5  import traceback
    32.6  from xen.util.security import ACMError, err, make_policy
    32.7 +from xen.util import xsconstants
    32.8  from xen.xm.opts import OptionError
    32.9 +from xen.xm import main as xm_main
   32.10 +from xen.xm.setpolicy import setpolicy
   32.11  
   32.12  def usage():
   32.13      print "\nUsage: xm makepolicy <policy>\n"
   32.14 @@ -32,8 +35,13 @@ def usage():
   32.15  def main(argv):
   32.16      if len(argv) != 2:
   32.17          raise OptionError('No XML policy file specified')
   32.18 -
   32.19 -    make_policy(argv[1])
   32.20 +    if xm_main.serverType == xm_main.SERVER_XEN_API:
   32.21 +        print "This command is deprecated for use with Xen-API " \
   32.22 +              "configuration. Consider using\n'xm setpolicy'."
   32.23 +        setpolicy(xsconstants.ACM_POLICY_ID, argv[1],
   32.24 +                  xsconstants.XS_INST_LOAD, True)
   32.25 +    else:
   32.26 +        make_policy(argv[1])
   32.27  
   32.28  if __name__ == '__main__':
   32.29      try:
   32.30 @@ -41,5 +49,3 @@ if __name__ == '__main__':
   32.31      except Exception, e:
   32.32          sys.stderr.write('Error: %s\n' % str(e))
   32.33          sys.exit(-1)
   32.34 -
   32.35 -
    33.1 --- a/tools/python/xen/xm/resources.py	Wed Jul 11 11:32:30 2007 -0600
    33.2 +++ b/tools/python/xen/xm/resources.py	Thu Jul 12 09:53:58 2007 +0100
    33.3 @@ -21,7 +21,10 @@
    33.4  import sys
    33.5  from xen.util import dictio
    33.6  from xen.util import security
    33.7 +from xen.util import xsconstants
    33.8  from xen.xm.opts import OptionError
    33.9 +from xen.xm import main as xm_main
   33.10 +from xen.xm.main import server
   33.11  
   33.12  def help():
   33.13      return """
   33.14 @@ -32,20 +35,32 @@ def print_resource_data(access_control):
   33.15      """Prints out a resource dictionary to stdout
   33.16      """
   33.17      for resource in access_control:
   33.18 -        (policy, label) = access_control[resource]
   33.19 +        tmp = access_control[resource]
   33.20 +        if len(tmp) == 2:
   33.21 +            policytype = xsconstants.ACM_POLICY_ID
   33.22 +            (policy, label) = access_control[resource]
   33.23 +        elif len(tmp) == 3:
   33.24 +            policytype, policy, label = access_control[resource]
   33.25          print resource
   33.26 -        print "    policy: "+policy
   33.27 -        print "    label:  "+label
   33.28 +        print "      type: "+ policytype
   33.29 +        print "    policy: "+ policy
   33.30 +        print "    label:  "+ label
   33.31  
   33.32  def main (argv):
   33.33      if len(argv) > 1:
   33.34          raise OptionError("No arguments required")
   33.35 -    
   33.36 -    try:
   33.37 -        filename = security.res_label_filename
   33.38 -        access_control = dictio.dict_read("resources", filename)
   33.39 -    except:
   33.40 -        raise OptionError("Resource file not found")
   33.41 +
   33.42 +    if xm_main.serverType == xm_main.SERVER_XEN_API:
   33.43 +        access_control = server.xenapi.XSPolicy.get_labeled_resources()
   33.44 +        for key, value in access_control.items():
   33.45 +            access_control[key] = tuple(value.split(':'))
   33.46 +    else:
   33.47 +        try:
   33.48 +            filename = security.res_label_filename
   33.49 +            access_control = dictio.dict_read("resources", filename)
   33.50 +            print access_control
   33.51 +        except:
   33.52 +            raise OptionError("Resource file not found")
   33.53  
   33.54      print_resource_data(access_control)
   33.55  
    34.1 --- a/tools/python/xen/xm/rmlabel.py	Wed Jul 11 11:32:30 2007 -0600
    34.2 +++ b/tools/python/xen/xm/rmlabel.py	Thu Jul 12 09:53:58 2007 +0100
    34.3 @@ -22,35 +22,52 @@ import sys, os, re
    34.4  from xen.util import dictio
    34.5  from xen.util import security
    34.6  from xen.xm.opts import OptionError
    34.7 +from xen.xm import main as xm_main
    34.8 +from xen.xm.main import server
    34.9  
   34.10  def help():
   34.11      return """
   34.12      Example: xm rmlabel dom <configfile>
   34.13               xm rmlabel res <resource>
   34.14 +             xm rmlabel mgt <domain name>
   34.15  
   34.16      This program removes an acm_label entry from the 'configfile'
   34.17 -    for a domain or from the global resource label file for a
   34.18 -    resource. If the label does not exist for the given domain or
   34.19 -    resource, then rmlabel fails."""
   34.20 +    for a domain, from a Xend-managed domain, from the global resource label
   34.21 +    file for a resource or from the virtual network interface of a Xend-managed
   34.22 +    domain. If the label does not exist for the given domain or resource, then
   34.23 +    rmlabel fails."""
   34.24  
   34.25  
   34.26  def rm_resource_label(resource):
   34.27      """Removes a resource label from the global resource label file.
   34.28      """
   34.29 +    # Try Xen-API first if configured to use it
   34.30 +    if xm_main.serverType == xm_main.SERVER_XEN_API:
   34.31 +        try:
   34.32 +            oldlabel = server.xenapi.XSPolicy.get_resource_label(resource)
   34.33 +            if oldlabel != "":
   34.34 +                server.xenapi.XSPolicy.set_resource_label(resource,"",
   34.35 +                                                          oldlabel)
   34.36 +            else:
   34.37 +                raise security.ACMError("Resource not labeled")
   34.38 +        except Exception, e:
   34.39 +            print "Could not remove label from resource: %s" % e
   34.40 +        return
   34.41 +
   34.42      #build canonical resource name
   34.43      resource = security.unify_resname(resource)
   34.44  
   34.45      # read in the resource file
   34.46 -    file = security.res_label_filename
   34.47 +    fil = security.res_label_filename
   34.48      try:
   34.49 -        access_control = dictio.dict_read("resources", file)
   34.50 +        access_control = dictio.dict_read("resources", fil)
   34.51      except:
   34.52          raise security.ACMError("Resource file not found, cannot remove label!")
   34.53  
   34.54      # remove the entry and update file
   34.55      if access_control.has_key(resource):
   34.56          del access_control[resource]
   34.57 -        dictio.dict_write(access_control, "resources", file)
   34.58 +        dictio.dict_write(access_control, "resources", fil)
   34.59      else:
   34.60          raise security.ACMError("Resource not labeled")
   34.61  
   34.62 @@ -58,15 +75,15 @@ def rm_resource_label(resource):
   34.63  def rm_domain_label(configfile):
   34.64      # open the domain config file
   34.65      fd = None
   34.66 -    file = None
   34.67 +    fil = None
   34.68      if configfile[0] == '/':
   34.69 -        file = configfile
   34.70 -        fd = open(file, "rb")
   34.71 +        fil = configfile
   34.72 +        fd = open(fil, "rb")
   34.73      else:
   34.74          for prefix in [".", "/etc/xen"]:
   34.75 -            file = prefix + "/" + configfile
   34.76 -            if os.path.isfile(file):
   34.77 -                fd = open(file, "rb")
   34.78 +            fil = prefix + "/" + configfile
   34.79 +            if os.path.isfile(fil):
   34.80 +                fd = open(fil, "rb")
   34.81                  break
   34.82      if not fd:
   34.83          raise OptionError("Configuration file '%s' not found." % configfile)
   34.84 @@ -93,22 +110,40 @@ def rm_domain_label(configfile):
   34.85          raise security.ACMError('Domain not labeled')
   34.86  
   34.87      # write the data back out to the file
   34.88 -    fd = open(file, "wb")
   34.89 +    fd = open(fil, "wb")
   34.90      fd.writelines(file_contents)
   34.91      fd.close()
   34.92  
   34.93 +def rm_domain_label_xapi(domainname):
   34.94 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   34.95 +        raise OptionError('Need to be configure for using xen-api.')
   34.96 +    uuids = server.xenapi.VM.get_by_name_label(domainname)
   34.97 +    if len(uuids) == 0:
   34.98 +        raise OptionError('A VM with that name does not exist.')
   34.99 +    if len(uuids) != 1:
  34.100 +        raise OptionError('Too many domains with the same name.')
  34.101 +    uuid = uuids[0]
  34.102 +    try:
  34.103 +        old_lab = server.xenapi.VM.get_security_label(uuid)
  34.104 +        server.xenapi.VM.set_security_label(uuid, "", old_lab)
  34.105 +    except Exception, e:
  34.106 +        print('Could not remove label from domain: %s' % e)
  34.107 +
  34.108  
  34.109  def main (argv):
  34.110  
  34.111      if len(argv) != 3:
  34.112          raise OptionError('Requires 2 arguments')
  34.113      
  34.114 -    if argv[1].lower() not in ('dom', 'res'):
  34.115 +    if argv[1].lower() not in ('dom', 'mgt', 'res'):
  34.116          raise OptionError('Unrecognised type argument: %s' % argv[1])
  34.117  
  34.118      if argv[1].lower() == "dom":
  34.119          configfile = argv[2]
  34.120          rm_domain_label(configfile)
  34.121 +    elif argv[1].lower() == "mgt":
  34.122 +        domain = argv[2]
  34.123 +        rm_domain_label_xapi(domain)
  34.124      elif argv[1].lower() == "res":
  34.125          resource = argv[2]
  34.126          rm_resource_label(resource)
  34.127 @@ -119,5 +154,3 @@ if __name__ == '__main__':
  34.128      except Exception, e:
  34.129          sys.stderr.write('Error: %s\n' % str(e))
  34.130          sys.exit(-1)    
  34.131 -
  34.132 -
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/tools/python/xen/xm/setpolicy.py	Thu Jul 12 09:53:58 2007 +0100
    35.3 @@ -0,0 +1,117 @@
    35.4 +#============================================================================
    35.5 +# This library is free software; you can redistribute it and/or
    35.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    35.7 +# License as published by the Free Software Foundation.
    35.8 +#
    35.9 +# This library is distributed in the hope that it will be useful,
   35.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   35.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   35.12 +# Lesser General Public License for more details.
   35.13 +#
   35.14 +# You should have received a copy of the GNU Lesser General Public
   35.15 +# License along with this library; if not, write to the Free Software
   35.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   35.17 +#============================================================================
   35.18 +# Copyright (C) 2007 International Business Machines Corp.
   35.19 +# Author: Stefan Berger <stefanb@us.ibm.com>
   35.20 +#============================================================================
   35.21 +
   35.22 +"""Get the managed policy of the system.
   35.23 +"""
   35.24 +
   35.25 +import base64
   35.26 +import struct
   35.27 +import sys
   35.28 +import string
   35.29 +from xen.util import xsconstants
   35.30 +from xen.xm.opts import OptionError
   35.31 +from xen.util.security import policy_dir_prefix
   35.32 +from xen.xm import main as xm_main
   35.33 +from xen.xm.main import server
   35.34 +
   35.35 +def help():
   35.36 +    return """
   35.37 +    Usage: xm setpolicy <policytype> <policy> [options]
   35.38 +
   35.39 +    Set the policy managed by xend.
   35.40 +
   35.41 +    The only policytype that is currently supported is 'ACM'.
   35.42 +
   35.43 +    The following options are defined
   35.44 +      --load     Load the policy immediately
   35.45 +      --boot     Have the system load the policy during boot
   35.46 +    """
   35.47 +
   35.48 +def setpolicy(policytype, policy_name, flags, overwrite):
   35.49 +    if xm_main.serverType != xm_main.SERVER_XEN_API:
   35.50 +        raise OptionError('xm needs to be configured to use the xen-api.')
   35.51 +    if policytype != xsconstants.ACM_POLICY_ID:
   35.52 +        raise OptionError("Unsupported policytype '%s'." % policytype)
   35.53 +    else:
   35.54 +        xs_type = xsconstants.XS_POLICY_ACM
   35.55 +
   35.56 +        policy_file = policy_dir_prefix + "/" + \
   35.57 +                      string.join(string.split(policy_name, "."), "/")
   35.58 +        policy_file += "-security_policy.xml"
   35.59 +
   35.60 +        try:
   35.61 +            f = open(policy_file,"r")
   35.62 +            xml = f.read(-1)
   35.63 +            f.close()
   35.64 +        except:
   35.65 +            raise OptionError("Not a valid policy file")
   35.66 +
   35.67 +        try:
   35.68 +            policystate = server.xenapi.XSPolicy.set_xspolicy(xs_type,
   35.69 +                                                              xml,
   35.70 +                                                              flags,
   35.71 +                                                              overwrite)
   35.72 +        except Exception, e:
   35.73 +            print "An error occurred setting the policy: %s" % str(e)
   35.74 +            return
   35.75 +        xserr = int(policystate['xserr'])
   35.76 +        if xserr != 0:
   35.77 +            print "An error occurred trying to set the policy: %s" % \
   35.78 +                  xsconstants.xserr2string(abs(xserr))
   35.79 +            errors = policystate['errors']
   35.80 +            if len(errors) > 0:
   35.81 +                print "Hypervisor reported errors:"
   35.82 +                err = base64.b64decode(errors)
   35.83 +                i = 0
   35.84 +                while i + 7 < len(err):
   35.85 +                    code, data = struct.unpack("!ii", errors[i:i+8])
   35.86 +                    print "(0x%08x, 0x%08x)" % (code, data)
   35.87 +                    i += 8
   35.88 +        else:
   35.89 +            print "Successfully set the new policy."
   35.90 +
   35.91 +
   35.92 +def main(argv):
   35.93 +    if len(argv) < 3:
   35.94 +       raise OptionError("Need at least 3 arguments.")
   35.95 +
   35.96 +    if "-?" in argv:
   35.97 +        help()
   35.98 +        return
   35.99 +
  35.100 +    policytype  = argv[1]
  35.101 +    policy_name = argv[2]
  35.102 +
  35.103 +    flags = 0
  35.104 +    if '--load' in argv:
  35.105 +        flags |= xsconstants.XS_INST_LOAD
  35.106 +    if '--boot' in argv:
  35.107 +        flags |= xsconstants.XS_INST_BOOT
  35.108 +
  35.109 +    overwrite = True
  35.110 +    if '--nooverwrite' in argv:
  35.111 +        overwrite = False
  35.112 +
  35.113 +    setpolicy(policytype, policy_name, flags, overwrite)
  35.114 +
  35.115 +if __name__ == '__main__':
  35.116 +    try:
  35.117 +        main(sys.argv)
  35.118 +    except Exception, e:
  35.119 +        sys.stderr.write('Error: %s\n' % str(e))
  35.120 +        sys.exit(-1)
    36.1 --- a/tools/python/xen/xm/xenapi_create.py	Wed Jul 11 11:32:30 2007 -0600
    36.2 +++ b/tools/python/xen/xm/xenapi_create.py	Thu Jul 12 09:53:58 2007 +0100
    36.3 @@ -25,6 +25,7 @@ from xen.xend import sxp
    36.4  from xen.xend.XendAPIConstants import XEN_API_ON_NORMAL_EXIT, \
    36.5       XEN_API_ON_CRASH_BEHAVIOUR
    36.6  from xen.xm.opts import OptionError
    36.7 +from xen.util import xsconstants
    36.8  
    36.9  import sys
   36.10  import os
   36.11 @@ -308,6 +309,12 @@ class xenapi_create:
   36.12                 ""
   36.13              }
   36.14  
   36.15 +        if vm.attributes.has_key("security_label"):
   36.16 +            vm_record.update({
   36.17 +                "security_label":
   36.18 +                    vm.attributes["security_label"].value
   36.19 +                })
   36.20 +
   36.21          if len(vm.getElementsByTagName("pv")) > 0:
   36.22              vm_record.update({
   36.23                  "PV_bootloader":
   36.24 @@ -348,6 +355,12 @@ class xenapi_create:
   36.25  
   36.26              self.create_vifs(vm_ref, vifs, networks)
   36.27  
   36.28 +            # Now create vtpms
   36.29 +
   36.30 +            vtpms = vm.getElementsByTagName("vtpm")
   36.31 +
   36.32 +            self.create_vtpms(vm_ref, vtpms)
   36.33 +
   36.34              # Now create consoles
   36.35  
   36.36              consoles = vm.getElementsByTagName("console")
   36.37 @@ -441,6 +454,21 @@ class xenapi_create:
   36.38              self._network_refs = server.xenapi.network.get_all()
   36.39              return self._network_refs.pop(0)
   36.40  
   36.41 +    def create_vtpms(self, vm_ref, vtpms):
   36.42 +        if len(vtpms) > 1:
   36.43 +            vtpms = [ vtpms[0] ]
   36.44 +        log(DEBUG, "create_vtpms")
   36.45 +        return map(lambda vtpm: self.create_vtpm(vm_ref, vtpm), vtpms)
   36.46 +
   36.47 +    def create_vtpm(self, vm_ref, vtpm):
   36.48 +        vtpm_record = {
   36.49 +            "VM":
   36.50 +                vm_ref,
   36.51 +            "backend":
   36.52 +                vtpm.attributes["backend"].value
   36.53 +        }
   36.54 +        return server.xenapi.VTPM.create(vtpm_record)
   36.55 +
   36.56      def create_consoles(self, vm_ref, consoles):
   36.57          log(DEBUG, "create_consoles")
   36.58          return map(lambda console: self.create_console(vm_ref, console),
   36.59 @@ -482,6 +510,10 @@ class sxp2xml:
   36.60  
   36.61          vifs_sxp = map(lambda x: x[1], [device for device in devices
   36.62                                          if device[1][0] == "vif"])
   36.63 +
   36.64 +        vtpms_sxp = map(lambda x: x[1], [device for device in devices
   36.65 +                                         if device[1][0] == "vtpm"])
   36.66 +
   36.67          # Create XML Document
   36.68          
   36.69          impl = getDOMImplementation()
   36.70 @@ -531,6 +563,14 @@ class sxp2xml:
   36.71          vm.attributes["vcpus_at_startup"] \
   36.72              = str(get_child_by_name(config, "vcpus", 1))
   36.73  
   36.74 +        sec_data = get_child_by_name(config, "security")
   36.75 +        if sec_data:
   36.76 +            try :
   36.77 +                vm.attributes['security_label'] = \
   36.78 +                      "%s:%s:%s" % (xsconstants.ACM_POLICY_ID, sec_data[0][1][1],sec_data[0][2][1])
   36.79 +            except Exception, e:
   36.80 +                raise "Invalid security data format: %s" % str(sec_data)
   36.81 +
   36.82          # Make the name tag
   36.83  
   36.84          vm.appendChild(self.make_name_tag(
   36.85 @@ -601,6 +641,12 @@ class sxp2xml:
   36.86  
   36.87          map(vm.appendChild, vifs)
   36.88  
   36.89 +        # And now the vTPMs
   36.90 +
   36.91 +        vtpms = map(lambda vtpm: self.extract_vtpm(vtpm, document), vtpms_sxp)
   36.92 +
   36.93 +        map(vm.appendChild, vtpms)
   36.94 +
   36.95          # Last but not least the consoles...
   36.96  
   36.97          consoles = self.extract_consoles(image, document)
   36.98 @@ -708,6 +754,15 @@ class sxp2xml:
   36.99          
  36.100          return vif
  36.101  
  36.102 +    def extract_vtpm(self, vtpm_sxp, document):
  36.103 +
  36.104 +        vtpm = document.createElement("vtpm")
  36.105 +
  36.106 +        vtpm.attributes["backend"] \
  36.107 +             = get_child_by_name(vtpm_sxp, "backend", "0")
  36.108 +
  36.109 +        return vtpm
  36.110 +
  36.111      _eths = -1
  36.112  
  36.113      def mk_other_config(self, key, value, document):
    37.1 --- a/tools/vtpm_manager/util/hashtable_itr.c	Wed Jul 11 11:32:30 2007 -0600
    37.2 +++ b/tools/vtpm_manager/util/hashtable_itr.c	Thu Jul 12 09:53:58 2007 +0100
    37.3 @@ -225,7 +225,7 @@ hashtable_iterator_search(struct hashtab
    37.4      
    37.5  egress:
    37.6  #ifdef HASHTABLE_THREADED
    37.7 -    pthread_mutex_lock(&h->mutex);
    37.8 +    pthread_mutex_unlock(&h->mutex);
    37.9  #endif 
   37.10      return ret;
   37.11  }
    38.1 --- a/tools/xenstore/xsls.c	Wed Jul 11 11:32:30 2007 -0600
    38.2 +++ b/tools/xenstore/xsls.c	Thu Jul 12 09:53:58 2007 +0100
    38.3 @@ -8,6 +8,7 @@
    38.4  #include <sys/ioctl.h>
    38.5  #include <termios.h>
    38.6  
    38.7 +#define STRING_MAX PATH_MAX
    38.8  static int max_width = 80;
    38.9  static int desired_width = 60;
   38.10  
   38.11 @@ -19,7 +20,8 @@ static int desired_width = 60;
   38.12  void print_dir(struct xs_handle *h, char *path, int cur_depth, int show_perms)
   38.13  {
   38.14      char **e;
   38.15 -    char newpath[512], *val;
   38.16 +    char newpath[STRING_MAX], *val;
   38.17 +    int newpath_len;
   38.18      int i;
   38.19      unsigned int num, len;
   38.20  
   38.21 @@ -33,13 +35,26 @@ void print_dir(struct xs_handle *h, char
   38.22          unsigned int nperms;
   38.23          int linewid;
   38.24  
   38.25 -        for (linewid=0; linewid<cur_depth; linewid++) putchar(' ');
   38.26 +        /* Print indent and path basename */
   38.27 +        for (linewid=0; linewid<cur_depth; linewid++) {
   38.28 +            putchar(' ');
   38.29 +        }
   38.30          linewid += printf("%.*s",
   38.31                            (int) (max_width - TAG_LEN - linewid), e[i]);
   38.32 -        sprintf(newpath, "%s%s%s", path, 
   38.33 +
   38.34 +        /* Compose fullpath and fetch value */
   38.35 +        newpath_len = snprintf(newpath, sizeof(newpath), "%s%s%s", path, 
   38.36                  path[strlen(path)-1] == '/' ? "" : "/", 
   38.37                  e[i]);
   38.38 -        val = xs_read(h, XBT_NULL, newpath, &len);
   38.39 +        if ( newpath_len < sizeof(newpath) ) {
   38.40 +            val = xs_read(h, XBT_NULL, newpath, &len);
   38.41 +        }
   38.42 +        else {
   38.43 +            /* Path was truncated and thus invalid */
   38.44 +            val = NULL;
   38.45 +        }
   38.46 +
   38.47 +        /* Print value */
   38.48          if (val == NULL) {
   38.49              printf(":\n");
   38.50          }
   38.51 @@ -88,7 +103,7 @@ void print_dir(struct xs_handle *h, char
   38.52  
   38.53  void usage(int argc, char *argv[])
   38.54  {
   38.55 -    fprintf(stderr, "Usage: %s [-p] [path]\n", argv[0]);
   38.56 +    fprintf(stderr, "Usage: %s [-w] [-p] [path]\n", argv[0]);
   38.57  }
   38.58  
   38.59  int main(int argc, char *argv[])
   38.60 @@ -104,11 +119,14 @@ int main(int argc, char *argv[])
   38.61      if (!ret)
   38.62          max_width = ws.ws_col - PAD;
   38.63  
   38.64 -    while (0 < (c = getopt(argc, argv, "ps"))) {
   38.65 +    while (0 < (c = getopt(argc, argv, "psw"))) {
   38.66          switch (c) {
   38.67 +        case 'w':
   38.68 +            max_width= STRING_MAX - PAD;
   38.69 +            desired_width = 0;
   38.70 +            break;
   38.71          case 'p':
   38.72              show_perm = 1;
   38.73 -            max_width -= 16;
   38.74              break;
   38.75          case 's':
   38.76              socket = 1;
   38.77 @@ -121,6 +139,11 @@ int main(int argc, char *argv[])
   38.78          }
   38.79      }
   38.80  
   38.81 +    /* Adjust the width here to avoid argument order dependency */
   38.82 +    if ( show_perm ) {
   38.83 +        max_width -= 16;
   38.84 +    }
   38.85 +
   38.86      xsh = socket ? xs_daemon_open() : xs_domain_open();
   38.87      if (xsh == NULL)
   38.88          err(1, socket ? "xs_daemon_open" : "xs_domain_open");
    39.1 --- a/xen/arch/ia64/linux-xen/perfmon.c	Wed Jul 11 11:32:30 2007 -0600
    39.2 +++ b/xen/arch/ia64/linux-xen/perfmon.c	Thu Jul 12 09:53:58 2007 +0100
    39.3 @@ -7729,7 +7729,7 @@ do_perfmon_op(unsigned long cmd,
    39.4  {
    39.5  	unsigned long error = 0;
    39.6  
    39.7 -	if (!NONPRIV_OP(cmd) && current->domain != xenoprof_primary_profiler) {
    39.8 +	if (!NONPRIV_OP(cmd) && current->domain->domain_id !=0) {
    39.9  		gdprintk(XENLOG_INFO, "xen perfmon: "
   39.10  			 "dom %d denied privileged operation %ld\n",
   39.11  			 current->domain->domain_id, cmd);
    40.1 --- a/xen/arch/ia64/xen/oprofile/perfmon.c	Wed Jul 11 11:32:30 2007 -0600
    40.2 +++ b/xen/arch/ia64/xen/oprofile/perfmon.c	Thu Jul 12 09:53:58 2007 +0100
    40.3 @@ -119,19 +119,10 @@ void xenoprof_perfmon_exit(void)
    40.4  ///////////////////////////////////////////////////////////////////////////
    40.5  // glue methods for xenoprof and perfmon.
    40.6  int
    40.7 -xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type)
    40.8 +xenoprof_arch_init(int *num_events, char *cpu_type)
    40.9  {
   40.10      *num_events = 0;
   40.11      strlcpy(cpu_type, get_cpu_type(), XENOPROF_CPU_TYPE_SIZE);
   40.12 -
   40.13 -    *is_primary = 0;
   40.14 -    if (xenoprof_primary_profiler == NULL) {
   40.15 -        /* For now, only dom0 can be the primary profiler */
   40.16 -        if (current->domain->domain_id == 0) {
   40.17 -            *is_primary = 1;
   40.18 -        }
   40.19 -    } else if (xenoprof_primary_profiler == current->domain)
   40.20 -        *is_primary = 1;
   40.21      return 0;
   40.22  }
   40.23  
    41.1 --- a/xen/arch/x86/acpi/Makefile	Wed Jul 11 11:32:30 2007 -0600
    41.2 +++ b/xen/arch/x86/acpi/Makefile	Thu Jul 12 09:53:58 2007 +0100
    41.3 @@ -1,1 +1,2 @@
    41.4  obj-y += boot.o
    41.5 +obj-y += power.o suspend.o wakeup_prot.o
    42.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.2 +++ b/xen/arch/x86/acpi/power.c	Thu Jul 12 09:53:58 2007 +0100
    42.3 @@ -0,0 +1,273 @@
    42.4 +/* drivers/acpi/sleep/power.c - PM core functionality for Xen
    42.5 + *
    42.6 + * Copyrights from Linux side:
    42.7 + * Copyright (c) 2000-2003 Patrick Mochel
    42.8 + * Copyright (C) 2001-2003 Pavel Machek <pavel@suse.cz>
    42.9 + * Copyright (c) 2003 Open Source Development Lab
   42.10 + * Copyright (c) 2004 David Shaohua Li <shaohua.li@intel.com>
   42.11 + * Copyright (c) 2005 Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>
   42.12 + *
   42.13 + * Slimmed with Xen specific support.
   42.14 + */
   42.15 +
   42.16 +#include <xen/config.h>
   42.17 +#include <asm/io.h>
   42.18 +#include <asm/acpi.h>
   42.19 +#include <xen/acpi.h>
   42.20 +#include <xen/errno.h>
   42.21 +#include <xen/iocap.h>
   42.22 +#include <xen/sched.h>
   42.23 +#include <asm/acpi.h>
   42.24 +#include <asm/irq.h>
   42.25 +#include <asm/init.h>
   42.26 +#include <xen/spinlock.h>
   42.27 +#include <xen/sched.h>
   42.28 +#include <xen/domain.h>
   42.29 +#include <xen/console.h>
   42.30 +#include <public/platform.h>
   42.31 +
   42.32 +#define pmprintk(_l, _f, _a...) printk(_l "<PM>" _f, ## _a )
   42.33 +
   42.34 +u8 sleep_states[ACPI_S_STATE_COUNT];
   42.35 +DEFINE_SPINLOCK(pm_lock);
   42.36 +
   42.37 +struct acpi_sleep_info {
   42.38 +    uint16_t pm1a_cnt;
   42.39 +    uint16_t pm1b_cnt;
   42.40 +    uint16_t pm1a_evt;
   42.41 +    uint16_t pm1b_evt;
   42.42 +    uint16_t pm1a_cnt_val;
   42.43 +    uint16_t pm1b_cnt_val;
   42.44 +    uint32_t sleep_state;
   42.45 +} acpi_sinfo;
   42.46 +
   42.47 +extern void do_suspend_lowlevel(void);
   42.48 +
   42.49 +static char *acpi_states[ACPI_S_STATE_COUNT] =
   42.50 +{
   42.51 +    [ACPI_STATE_S1] = "standby",
   42.52 +    [ACPI_STATE_S3] = "mem",
   42.53 +    [ACPI_STATE_S4] = "disk",
   42.54 +};
   42.55 +
   42.56 +unsigned long acpi_video_flags;
   42.57 +unsigned long saved_videomode;
   42.58 +
   42.59 +/* XXX: Add suspend failure recover later */
   42.60 +static int device_power_down(void)
   42.61 +{
   42.62 +    console_suspend();
   42.63 +
   42.64 +    time_suspend();
   42.65 +
   42.66 +    i8259A_suspend();
   42.67 +    
   42.68 +    ioapic_suspend();
   42.69 +    
   42.70 +    lapic_suspend();
   42.71 +
   42.72 +    return 0;
   42.73 +}
   42.74 +
   42.75 +static void device_power_up(void)
   42.76 +{
   42.77 +    lapic_resume();
   42.78 +    
   42.79 +    ioapic_resume();
   42.80 +
   42.81 +    i8259A_resume();
   42.82 +    
   42.83 +    time_resume();
   42.84 +
   42.85 +    console_resume();
   42.86 +}
   42.87 +
   42.88 +static void freeze_domains(void)
   42.89 +{
   42.90 +    struct domain *d;
   42.91 +
   42.92 +    for_each_domain(d)
   42.93 +        if (d->domain_id != 0)
   42.94 +            domain_pause(d);
   42.95 +}
   42.96 +
   42.97 +static void thaw_domains(void)
   42.98 +{
   42.99 +    struct domain *d;
  42.100 +
  42.101 +    for_each_domain(d)
  42.102 +        if (d->domain_id != 0)
  42.103 +            domain_unpause(d);
  42.104 +}
  42.105 +
  42.106 +/* Main interface to do xen specific suspend/resume */
  42.107 +int enter_state(u32 state)
  42.108 +{
  42.109 +    unsigned long flags;
  42.110 +    int error;
  42.111 +
  42.112 +    if (state <= ACPI_STATE_S0 || state > ACPI_S_STATES_MAX)
  42.113 +        return -EINVAL;
  42.114 +
  42.115 +    /* Sync lazy state on ths cpu */
  42.116 +    __sync_lazy_execstate();
  42.117 +    pmprintk(XENLOG_INFO, "Flush lazy state\n");
  42.118 +
  42.119 +    if (!spin_trylock(&pm_lock))
  42.120 +        return -EBUSY;
  42.121 +    
  42.122 +    freeze_domains();
  42.123 +
  42.124 +    hvm_suspend_cpu();
  42.125 +
  42.126 +    pmprintk(XENLOG_INFO, "PM: Preparing system for %s sleep\n",
  42.127 +        acpi_states[state]);
  42.128 +
  42.129 +    local_irq_save(flags);
  42.130 +
  42.131 +    if ((error = device_power_down()))
  42.132 +    {
  42.133 +        printk(XENLOG_ERR "Some devices failed to power down\n");
  42.134 +        goto Done;
  42.135 +    }
  42.136 +
  42.137 +    ACPI_FLUSH_CPU_CACHE();
  42.138 +
  42.139 +    switch (state)
  42.140 +    {
  42.141 +        case ACPI_STATE_S3:
  42.142 +            do_suspend_lowlevel();
  42.143 +            break;
  42.144 +        default:
  42.145 +            error = -EINVAL;
  42.146 +            break;
  42.147 +    }
  42.148 +
  42.149 +    pmprintk(XENLOG_INFO, "Back to C!\n");
  42.150 +
  42.151 +    device_power_up();
  42.152 +
  42.153 +    pmprintk(XENLOG_INFO, "PM: Finishing wakeup.\n");
  42.154 +
  42.155 + Done:
  42.156 +    local_irq_restore(flags);
  42.157 +
  42.158 +    hvm_resume_cpu();
  42.159 +
  42.160 +    thaw_domains();
  42.161 +    spin_unlock(&pm_lock);
  42.162 +    return error;
  42.163 +}
  42.164 +
  42.165 +/*
  42.166 + * Xen just requires address of pm1x_cnt, and ACPI interpreter
  42.167 + * is still kept in dom0. Address of xen wakeup stub will be
  42.168 + * returned, and then dom0 writes that address to FACS.
  42.169 + */
  42.170 +int set_acpi_sleep_info(struct xenpf_set_acpi_sleep *info)
  42.171 +{
  42.172 +    if (acpi_sinfo.pm1a_cnt)
  42.173 +        pmprintk(XENLOG_WARNING, "Multiple setting on acpi sleep info\n");
  42.174 +
  42.175 +    acpi_sinfo.pm1a_cnt = info->pm1a_cnt_port;
  42.176 +    acpi_sinfo.pm1b_cnt = info->pm1b_cnt_port;
  42.177 +    acpi_sinfo.pm1a_evt = info->pm1a_evt_port;
  42.178 +    acpi_sinfo.pm1b_evt = info->pm1b_evt_port;
  42.179 +    info->xen_waking_vec = (uint64_t)bootsym_phys(wakeup_start);
  42.180 +
  42.181 +    pmprintk(XENLOG_INFO, "pm1a[%x],pm1b[%x],pm1a_e[%x],pm1b_e[%x]"
  42.182 +                       "wake[%"PRIx64"]",
  42.183 +                       acpi_sinfo.pm1a_cnt, acpi_sinfo.pm1b_cnt,
  42.184 +                       acpi_sinfo.pm1a_evt, acpi_sinfo.pm1b_evt,
  42.185 +                       info->xen_waking_vec);
  42.186 +    return 0;
  42.187 +}
  42.188 +
  42.189 +/*
  42.190 + * Dom0 issues this hypercall in place of writing pm1a_cnt. Xen then
  42.191 + * takes over the control and put the system into sleep state really.
  42.192 + * Also video flags and mode are passed here, in case user may use
  42.193 + * "acpi_sleep=***" for video resume.
  42.194 + *
  42.195 + * Guest may issue a two-phases write to PM1x_CNT, to work
  42.196 + * around poorly implemented hardware. It's better to keep
  42.197 + * this logic here. Two writes can be differentiated by 
  42.198 + * enable bit setting.
  42.199 + */
  42.200 +int acpi_enter_sleep(struct xenpf_enter_acpi_sleep *sleep)
  42.201 +{
  42.202 +    if (!IS_PRIV(current->domain) || !acpi_sinfo.pm1a_cnt)
  42.203 +        return -EPERM;
  42.204 +
  42.205 +    /* Sanity check */
  42.206 +    if (acpi_sinfo.pm1b_cnt_val &&
  42.207 +        ((sleep->pm1a_cnt_val ^ sleep->pm1b_cnt_val) &
  42.208 +        ACPI_BITMASK_SLEEP_ENABLE))
  42.209 +    {
  42.210 +        pmprintk(XENLOG_ERR, "Mismatched pm1a/pm1b setting\n");
  42.211 +        return -EINVAL;
  42.212 +    }
  42.213 +
  42.214 +    /* Write #1 */
  42.215 +    if (!(sleep->pm1a_cnt_val & ACPI_BITMASK_SLEEP_ENABLE))
  42.216 +    {
  42.217 +        outw((u16)sleep->pm1a_cnt_val, acpi_sinfo.pm1a_cnt);
  42.218 +        if (acpi_sinfo.pm1b_cnt)
  42.219 +            outw((u16)sleep->pm1b_cnt_val, acpi_sinfo.pm1b_cnt);
  42.220 +        return 0;
  42.221 +    }
  42.222 +
  42.223 +    /* Write #2 */
  42.224 +    acpi_sinfo.pm1a_cnt_val = sleep->pm1a_cnt_val;
  42.225 +    acpi_sinfo.pm1b_cnt_val = sleep->pm1b_cnt_val;
  42.226 +    acpi_sinfo.sleep_state = sleep->sleep_state;
  42.227 +    acpi_video_flags = sleep->video_flags;
  42.228 +    saved_videomode = sleep->video_mode;
  42.229 +
  42.230 +    return enter_state(acpi_sinfo.sleep_state);
  42.231 +}
  42.232 +
  42.233 +static int acpi_get_wake_status(void)
  42.234 +{
  42.235 +    uint16_t val;
  42.236 +
  42.237 +    /* Wake status is the 15th bit of PM1 status register. (ACPI spec 3.0) */
  42.238 +    val = inw(acpi_sinfo.pm1a_evt) | inw(acpi_sinfo.pm1b_evt);
  42.239 +    val &= ACPI_BITMASK_WAKE_STATUS;
  42.240 +    val >>= ACPI_BITPOSITION_WAKE_STATUS;
  42.241 +    return val;
  42.242 +}
  42.243 +
  42.244 +/* System is really put into sleep state by this stub */
  42.245 +acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
  42.246 +{
  42.247 +    ACPI_FLUSH_CPU_CACHE();
  42.248 +
  42.249 +    outw((u16)acpi_sinfo.pm1a_cnt_val, acpi_sinfo.pm1a_cnt);
  42.250 +    if (acpi_sinfo.pm1b_cnt)
  42.251 +        outw((u16)acpi_sinfo.pm1b_cnt_val, acpi_sinfo.pm1b_cnt);
  42.252 +    
  42.253 +    /* Wait until we enter sleep state, and spin until we wake */
  42.254 +    while (!acpi_get_wake_status());
  42.255 +    return_ACPI_STATUS(AE_OK);
  42.256 +}
  42.257 +
  42.258 +static int __init acpi_sleep_init(void)
  42.259 +{
  42.260 +    int i = 0; 
  42.261 +
  42.262 +    pmprintk(XENLOG_INFO, "ACPI (supports");
  42.263 +    for (i = 0; i < ACPI_S_STATE_COUNT; i++)
  42.264 +    {
  42.265 +        if (i == ACPI_STATE_S3)
  42.266 +        {
  42.267 +            sleep_states[i] = 1;
  42.268 +            printk(" S%d", i);
  42.269 +        }
  42.270 +        else
  42.271 +            sleep_states[i] = 0;
  42.272 +    }
  42.273 +    printk(")\n");
  42.274 +    return 0;
  42.275 +}
  42.276 +__initcall(acpi_sleep_init);
    43.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.2 +++ b/xen/arch/x86/acpi/suspend.c	Thu Jul 12 09:53:58 2007 +0100
    43.3 @@ -0,0 +1,85 @@
    43.4 +/*
    43.5 + * Suspend support specific for i386.
    43.6 + *
    43.7 + * Distribute under GPLv2
    43.8 + *
    43.9 + * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
   43.10 + * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
   43.11 + */
   43.12 +#include <xen/config.h>
   43.13 +#include <xen/acpi.h>
   43.14 +#include <xen/smp.h>
   43.15 +#include <asm/processor.h>
   43.16 +#include <asm/msr.h>
   43.17 +#include <asm/flushtlb.h>
   43.18 +#include <asm/hvm/hvm.h>
   43.19 +#include <asm/hvm/support.h>
   43.20 +#include <asm/i387.h>
   43.21 +
   43.22 +/* Following context save/restore happens on the real context
   43.23 + * of current vcpu, with a lazy state sync forced earlier. 
   43.24 + */
   43.25 +#if defined(CONFIG_X86_64)
   43.26 +unsigned long saved_lstar, saved_cstar;
   43.27 +#endif
   43.28 +void save_rest_processor_state(void)
   43.29 +{
   43.30 +    /*
   43.31 +     * Net effect of unlazy_fpu is to set cr0.ts and thus there's no
   43.32 +     * need to restore fpu after resume.
   43.33 +     */
   43.34 +    if (!is_idle_vcpu(current))
   43.35 +        unlazy_fpu(current);
   43.36 +
   43.37 +#if defined(CONFIG_X86_64)
   43.38 +    rdmsrl(MSR_CSTAR, saved_cstar);
   43.39 +    rdmsrl(MSR_LSTAR, saved_lstar);
   43.40 +#endif
   43.41 +
   43.42 +    bootsym(video_flags) = acpi_video_flags;
   43.43 +    bootsym(video_mode) = saved_videomode;
   43.44 +}
   43.45 +
   43.46 +#define loaddebug(_v,_reg) \
   43.47 +    __asm__ __volatile__ ("mov %0,%%db" #_reg : : "r" ((_v)->debugreg[_reg]))
   43.48 +
   43.49 +void restore_rest_processor_state(void)
   43.50 +{
   43.51 +    int cpu = smp_processor_id();
   43.52 +    struct tss_struct *t = &init_tss[cpu];
   43.53 +    struct vcpu *v = current;
   43.54 +
   43.55 +    /* Really scared by suffixed comment from Linux, and keep it for safe */
   43.56 +    set_tss_desc(cpu, t);    /* This just modifies memory; should not be necessary. But... This is necessary, because 386 hardware has concept of busy TSS or some similar stupidity. */
   43.57 +
   43.58 +    load_TR(cpu);
   43.59 +
   43.60 +#if defined(CONFIG_X86_64)
   43.61 +    /* Recover syscall MSRs */
   43.62 +    wrmsrl(MSR_LSTAR, saved_lstar);
   43.63 +    wrmsrl(MSR_CSTAR, saved_cstar);
   43.64 +    wrmsr(MSR_STAR, 0, (FLAT_RING3_CS32<<16) | __HYPERVISOR_CS);
   43.65 +    wrmsr(MSR_SYSCALL_MASK, EF_VM|EF_RF|EF_NT|EF_DF|EF_IE|EF_TF, 0U);    
   43.66 +#else /* !defined(CONFIG_X86_64) */
   43.67 +    if (supervisor_mode_kernel && cpu_has_sep)
   43.68 +        wrmsr(MSR_IA32_SYSENTER_ESP, &t->esp1, 0);
   43.69 +#endif
   43.70 +
   43.71 +    /* Maybe load the debug registers. */
   43.72 +    if ( !is_idle_vcpu(v) && unlikely(v->arch.guest_context.debugreg[7]) )
   43.73 +    {
   43.74 +        loaddebug(&v->arch.guest_context, 0);
   43.75 +        loaddebug(&v->arch.guest_context, 1);
   43.76 +        loaddebug(&v->arch.guest_context, 2);
   43.77 +        loaddebug(&v->arch.guest_context, 3);
   43.78 +        /* no 4 and 5 */
   43.79 +        loaddebug(&v->arch.guest_context, 6);
   43.80 +        loaddebug(&v->arch.guest_context, 7);
   43.81 +    }
   43.82 +
   43.83 +    /* Do we start fpu really? Just set cr0.ts to monitor it */
   43.84 +    stts();
   43.85 +
   43.86 +    mtrr_ap_init();
   43.87 +    mcheck_init(&boot_cpu_data);
   43.88 +}
    44.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    44.2 +++ b/xen/arch/x86/acpi/wakeup_prot.S	Thu Jul 12 09:53:58 2007 +0100
    44.3 @@ -0,0 +1,267 @@
    44.4 +        .text
    44.5 +
    44.6 +#include <xen/config.h>
    44.7 +#include <xen/multiboot.h>
    44.8 +#include <public/xen.h>
    44.9 +#include <asm/asm_defns.h>
   44.10 +#include <asm/desc.h>
   44.11 +#include <asm/page.h>
   44.12 +#include <asm/msr.h>
   44.13 +
   44.14 +#if defined(__x86_64__)
   44.15 +
   44.16 +        .code64
   44.17 +
   44.18 +#define GREG(x)         %r##x
   44.19 +#define SAVED_GREG(x)   saved_r##x(%rip)
   44.20 +#define DECLARE_GREG(x) saved_r##x:     .quad   0
   44.21 +#define SAVE_GREG(x)    movq GREG(x), SAVED_GREG(x)
   44.22 +#define LOAD_GREG(x)    movq SAVED_GREG(x), GREG(x)
   44.23 +
   44.24 +#define REF(x)          x(%rip)
   44.25 +
   44.26 +#define RDMSR(ind, m)                   \
   44.27 +        xorq    %rdx, %rdx;             \
   44.28 +        mov     $ind, %ecx;             \
   44.29 +        rdmsr;                          \
   44.30 +        shlq    $0x20, %rdx;              \
   44.31 +        orq     %rax, %rdx;             \
   44.32 +        movq    %rdx, m(%rip);
   44.33 +
   44.34 +#define WRMSR(ind, m)                   \
   44.35 +        mov     $ind, %ecx;             \
   44.36 +        movq    m(%rip), %rdx;          \
   44.37 +        mov     %edx, %eax;             \
   44.38 +        shrq    $0x20, %rdx;              \
   44.39 +        wrmsr;
   44.40 +
   44.41 +#else /* !defined(__x86_64__) */
   44.42 +
   44.43 +        .code32
   44.44 +
   44.45 +#define GREG(x)         %e##x
   44.46 +#define SAVED_GREG(x)   saved_e##x
   44.47 +#define DECLARE_GREG(x) saved_e##x:     .long   0
   44.48 +#define SAVE_GREG(x)    movl GREG(x), SAVED_GREG(x)
   44.49 +#define LOAD_GREG(x)    movl SAVED_GREG(x), GREG(x)
   44.50 +
   44.51 +#define REF(x)          x
   44.52 +
   44.53 +#endif
   44.54 +
   44.55 +ENTRY(do_suspend_lowlevel)
   44.56 +
   44.57 +        SAVE_GREG(sp)
   44.58 +        SAVE_GREG(ax)
   44.59 +        SAVE_GREG(bx)
   44.60 +        SAVE_GREG(cx)
   44.61 +        SAVE_GREG(dx)
   44.62 +        SAVE_GREG(bp)
   44.63 +        SAVE_GREG(si)
   44.64 +        SAVE_GREG(di)
   44.65 +
   44.66 +#if defined(__x86_64__)
   44.67 +
   44.68 +        SAVE_GREG(8)     # save r8...r15
   44.69 +        SAVE_GREG(9)
   44.70 +        SAVE_GREG(10)
   44.71 +        SAVE_GREG(11)
   44.72 +        SAVE_GREG(12)
   44.73 +        SAVE_GREG(13)
   44.74 +        SAVE_GREG(14)
   44.75 +        SAVE_GREG(15)
   44.76 +        pushfq;
   44.77 +        popq    SAVED_GREG(flags)
   44.78 +
   44.79 +        mov     %cr8, GREG(ax)
   44.80 +        mov     GREG(ax), REF(saved_cr8)
   44.81 +
   44.82 +        RDMSR(MSR_FS_BASE, saved_fs_base)
   44.83 +        RDMSR(MSR_GS_BASE, saved_gs_base)
   44.84 +        RDMSR(MSR_SHADOW_GS_BASE, saved_kernel_gs_base)
   44.85 +
   44.86 +#else /* !defined(__x86_64__) */
   44.87 +
   44.88 +        pushfl;
   44.89 +        popl    SAVED_GREG(flags)
   44.90 +
   44.91 +#endif
   44.92 +
   44.93 +        mov     %ds, REF(saved_ds)
   44.94 +        mov     %es, REF(saved_es)
   44.95 +        mov     %fs, REF(saved_fs)
   44.96 +        mov     %gs, REF(saved_gs)
   44.97 +        mov     %ss, REF(saved_ss)
   44.98 +
   44.99 +        sgdt    REF(saved_gdt)
  44.100 +        sidt    REF(saved_idt)
  44.101 +        sldt    REF(saved_ldt)
  44.102 +
  44.103 +        mov     %cr0, GREG(ax)
  44.104 +        mov     GREG(ax), REF(saved_cr0)
  44.105 +
  44.106 +        mov     %cr3, GREG(ax)
  44.107 +        mov     GREG(ax), REF(saved_cr3)
  44.108 +
  44.109 +        call    save_rest_processor_state
  44.110 +
  44.111 +#if defined(__x86_64__)
  44.112 +
  44.113 +        mov     $3, %rdi
  44.114 +        xor     %eax, %eax
  44.115 +
  44.116 +#else /* !defined(__x86_64__) */
  44.117 +
  44.118 +        push    $3
  44.119 +
  44.120 +#endif
  44.121 +
  44.122 +        /* enter sleep state physically */
  44.123 +        call    acpi_enter_sleep_state
  44.124 +        jmp     __ret_point
  44.125 +
  44.126 +        .align  16
  44.127 +        .globl  __ret_point
  44.128 +__ret_point:
  44.129 +
  44.130 +        /* mmu_cr4_features contains latest cr4 setting */
  44.131 +        mov     REF(mmu_cr4_features), GREG(ax)
  44.132 +        mov     GREG(ax), %cr4
  44.133 +
  44.134 +        mov     REF(saved_cr3), GREG(ax)
  44.135 +        mov     GREG(ax), %cr3
  44.136 +
  44.137 +        mov     REF(saved_cr0), GREG(ax)
  44.138 +        mov     GREG(ax), %cr0
  44.139 +
  44.140 +        lgdt    REF(saved_gdt)
  44.141 +        lidt    REF(saved_idt)
  44.142 +        lldt    REF(saved_ldt)
  44.143 +
  44.144 +        mov     REF(saved_ss), %ss
  44.145 +        LOAD_GREG(sp)
  44.146 +
  44.147 +#if defined(__x86_64__)
  44.148 +
  44.149 +        mov     REF(saved_cr8), %rax
  44.150 +        mov     %rax, %cr8
  44.151 +
  44.152 +        pushq   SAVED_GREG(flags)
  44.153 +        popfq
  44.154 +
  44.155 +        /* Idle vcpu doesn't need segment selectors reload, since
  44.156 +         * those may contain stale value from other domains and 
  44.157 +         * reload may result page fault due to no matched gdt entry
  44.158 +         */
  44.159 +        mov     $(STACK_SIZE - 8), %rax
  44.160 +        or      %rsp, %rax
  44.161 +        and     $~7, %rax
  44.162 +        mov     (%rax), %rax
  44.163 +        mov     0x10(%rax), %rax
  44.164 +        cmpw    $0x7fff, (%rax)
  44.165 +        je      1f
  44.166 +
  44.167 +        /* These selectors are from guest, and thus need reload */
  44.168 +        mov     REF(saved_ds), %ds
  44.169 +        mov     REF(saved_es), %es
  44.170 +        mov     REF(saved_fs), %fs
  44.171 +
  44.172 +        /* gs load is special */
  44.173 +        mov     REF(saved_gs), %rsi
  44.174 +        mov     $3, %rdi        # SEGBASE_GS_USER_SEL
  44.175 +        call    do_set_segment_base
  44.176 +
  44.177 +1:
  44.178 +        # MSR restore
  44.179 +        WRMSR(MSR_FS_BASE, saved_fs_base)
  44.180 +        WRMSR(MSR_GS_BASE, saved_gs_base)
  44.181 +        WRMSR(MSR_SHADOW_GS_BASE, saved_kernel_gs_base)
  44.182 +
  44.183 +#else /* !defined(__x86_64__) */
  44.184 +
  44.185 +        pushl   SAVED_GREG(flags)
  44.186 +        popfl
  44.187 +
  44.188 +        /* No reload to fs/gs, which is saved in bottom stack already */
  44.189 +        mov     REF(saved_ds), %ds
  44.190 +        mov     REF(saved_es), %es
  44.191 +
  44.192 +#endif
  44.193 +
  44.194 +        call restore_rest_processor_state
  44.195 +
  44.196 +        LOAD_GREG(bp)
  44.197 +        LOAD_GREG(ax)
  44.198 +        LOAD_GREG(bx)
  44.199 +        LOAD_GREG(cx)
  44.200 +        LOAD_GREG(dx)
  44.201 +        LOAD_GREG(si)
  44.202 +        LOAD_GREG(di)
  44.203 +#if defined(__x86_64__)
  44.204 +        LOAD_GREG(8)     # save r8...r15
  44.205 +        LOAD_GREG(9)
  44.206 +        LOAD_GREG(10)
  44.207 +        LOAD_GREG(11)
  44.208 +        LOAD_GREG(12)
  44.209 +        LOAD_GREG(13)
  44.210 +        LOAD_GREG(14)
  44.211 +        LOAD_GREG(15)
  44.212 +#endif
  44.213 +        ret 
  44.214 +
  44.215 +.data
  44.216 +        .align 16
  44.217 +saved_ds:        .word   0
  44.218 +saved_es:        .word   0
  44.219 +saved_ss:        .word   0
  44.220 +saved_gs:        .word   0
  44.221 +saved_fs:        .word   0
  44.222 +
  44.223 +        .align 4
  44.224 +        .globl   saved_magic
  44.225 +saved_magic:     .long   0x9abcdef0
  44.226 +
  44.227 +        .align 8
  44.228 +DECLARE_GREG(sp)
  44.229 +DECLARE_GREG(bp)
  44.230 +DECLARE_GREG(ax)
  44.231 +DECLARE_GREG(bx)
  44.232 +DECLARE_GREG(cx)
  44.233 +DECLARE_GREG(dx)
  44.234 +DECLARE_GREG(si)
  44.235 +DECLARE_GREG(di)
  44.236 +DECLARE_GREG(flags)
  44.237 +
  44.238 +#if defined(__x86_64__)
  44.239 +
  44.240 +DECLARE_GREG(8)
  44.241 +DECLARE_GREG(9)
  44.242 +DECLARE_GREG(10)
  44.243 +DECLARE_GREG(11)
  44.244 +DECLARE_GREG(12)
  44.245 +DECLARE_GREG(13)
  44.246 +DECLARE_GREG(14)
  44.247 +DECLARE_GREG(15)
  44.248 +
  44.249 +saved_gdt:      .quad   0,0
  44.250 +saved_idt:      .quad   0,0
  44.251 +saved_ldt:      .quad   0,0
  44.252 +
  44.253 +saved_cr0:      .quad   0
  44.254 +saved_cr3:      .quad   0
  44.255 +saved_cr8:      .quad   0
  44.256 +
  44.257 +saved_gs_base:  .quad   0
  44.258 +saved_fs_base:  .quad   0
  44.259 +saved_kernel_gs_base:   .quad   0
  44.260 +
  44.261 +#else /* !defined(__x86_64__) */
  44.262 +
  44.263 +saved_gdt:      .long   0,0
  44.264 +saved_idt:      .long   0,0
  44.265 +saved_ldt:      .long   0
  44.266 +
  44.267 +saved_cr0:      .long   0
  44.268 +saved_cr3:      .long   0
  44.269 +
  44.270 +#endif 
    45.1 --- a/xen/arch/x86/apic.c	Wed Jul 11 11:32:30 2007 -0600
    45.2 +++ b/xen/arch/x86/apic.c	Thu Jul 12 09:53:58 2007 +0100
    45.3 @@ -957,7 +957,7 @@ void __setup_APIC_LVTT(unsigned int cloc
    45.4      apic_write_around(APIC_TMICT, clocks/APIC_DIVISOR);
    45.5  }
    45.6  
    45.7 -static void __init setup_APIC_timer(unsigned int clocks)
    45.8 +static void __devinit setup_APIC_timer(unsigned int clocks)
    45.9  {
   45.10      unsigned long flags;
   45.11      local_irq_save(flags);
    46.1 --- a/xen/arch/x86/boot/Makefile	Wed Jul 11 11:32:30 2007 -0600
    46.2 +++ b/xen/arch/x86/boot/Makefile	Thu Jul 12 09:53:58 2007 +0100
    46.3 @@ -1,3 +1,4 @@
    46.4  obj-y += head.o
    46.5  
    46.6 -head.o: head.S $(TARGET_SUBARCH).S trampoline.S mem.S video.S cmdline.S edd.S
    46.7 +head.o: head.S $(TARGET_SUBARCH).S trampoline.S mem.S video.S \
    46.8 +	cmdline.S edd.S wakeup.S
    47.1 --- a/xen/arch/x86/boot/head.S	Wed Jul 11 11:32:30 2007 -0600
    47.2 +++ b/xen/arch/x86/boot/head.S	Thu Jul 12 09:53:58 2007 +0100
    47.3 @@ -175,9 +175,11 @@ 1:      stosl   /* low mappings cover up
    47.4  
    47.5  #include "cmdline.S"
    47.6  
    47.7 +        .align 16
    47.8          .globl trampoline_start, trampoline_end
    47.9  trampoline_start:
   47.10  #include "trampoline.S"
   47.11 +#include "wakeup.S"
   47.12  trampoline_end:
   47.13  
   47.14          .text
    48.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    48.2 +++ b/xen/arch/x86/boot/wakeup.S	Thu Jul 12 09:53:58 2007 +0100
    48.3 @@ -0,0 +1,212 @@
    48.4 +        .code16
    48.5 +
    48.6 +#undef wakesym
    48.7 +/* Used in real mode, to cal offset in current segment */
    48.8 +#define wakesym(sym) (sym - wakeup_start)
    48.9 +
   48.10 +ENTRY(wakeup_start)
   48.11 +        wakeup_code_start = .
   48.12 +
   48.13 +        cli
   48.14 +        cld
   48.15 +
   48.16 +        # setup data segment
   48.17 +        movw    %cs, %ax
   48.18 +        movw    %ax, %ds
   48.19 +        movw    %ax, %ss        # A stack required for BIOS call
   48.20 +        movw    $wakesym(wakeup_stack), %sp
   48.21 +
   48.22 +        pushl   $0              # Kill dangerous flag early
   48.23 +        popfl
   48.24 +
   48.25 +        # check magic number
   48.26 +        movl    wakesym(real_magic), %eax
   48.27 +        cmpl    $0x12345678, %eax
   48.28 +        jne     bogus_real_magic
   48.29 +
   48.30 +        # for acpi_sleep=s3_bios
   48.31 +        testl   $1, wakesym(video_flags)
   48.32 +        jz      1f
   48.33 +        lcall   $0xc000, $3
   48.34 +        movw    %cs, %ax        # In case messed by BIOS
   48.35 +        movw    %ax, %ds
   48.36 +        movw    %ax, %ss        # Need this? How to ret if clobbered?
   48.37 +
   48.38 +1:      # for acpi_sleep=s3_mode
   48.39 +        testl   $2, wakesym(video_flags)
   48.40 +        jz      1f
   48.41 +        movl    wakesym(video_mode), %eax
   48.42 +        call    mode_setw
   48.43 +
   48.44 +1:      # Show some progress if VGA is resumed
   48.45 +        movw    $0xb800, %ax
   48.46 +        movw    %ax, %fs
   48.47 +        movw    $0x0e00 + 'L', %fs:(0x10)
   48.48 +
   48.49 +        # boot trampoline is under 1M, and shift its start into
   48.50 +        # %fs to reference symbols in that area
   48.51 +        movl    $BOOT_TRAMPOLINE, %eax
   48.52 +        shrl    $4, %eax
   48.53 +        movl    %eax, %fs
   48.54 +        lidt    %fs:bootsym(idt_48)
   48.55 +        lgdt    %fs:bootsym(gdt_48)
   48.56 +
   48.57 +        movw    $1, %ax
   48.58 +        lmsw    %ax             # Turn on CR0.PE 
   48.59 +        jmp     1f
   48.60 +1:      ljmpl   $BOOT_CS32, $bootsym_phys(wakeup_32)
   48.61 +
   48.62 +/* This code uses an extended set of video mode numbers. These include:
   48.63 + * Aliases for standard modes
   48.64 + *      NORMAL_VGA (-1)
   48.65 + *      EXTENDED_VGA (-2)
   48.66 + *      ASK_VGA (-3)
   48.67 + * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
   48.68 + * of compatibility when extending the table. These are between 0x00 and 0xff.
   48.69 + */
   48.70 +#define VIDEO_FIRST_MENU 0x0000
   48.71 +
   48.72 +/* Standard BIOS video modes (BIOS number + 0x0100) */
   48.73 +#define VIDEO_FIRST_BIOS 0x0100
   48.74 +
   48.75 +/* VESA BIOS video modes (VESA number + 0x0200) */
   48.76 +#define VIDEO_FIRST_VESA 0x0200
   48.77 +
   48.78 +/* Video7 special modes (BIOS number + 0x0900) */
   48.79 +#define VIDEO_FIRST_V7 0x0900
   48.80 +
   48.81 +# Setting of user mode (AX=mode ID) => CF=success
   48.82 +mode_setw:
   48.83 +        movw    %ax, %bx
   48.84 +        cmpb    $VIDEO_FIRST_VESA>>8, %ah
   48.85 +        jnc     check_vesaw
   48.86 +        decb    %ah
   48.87 +
   48.88 +setbadw: clc
   48.89 +        ret
   48.90 +
   48.91 +check_vesaw:
   48.92 +        subb    $VIDEO_FIRST_VESA>>8, %bh
   48.93 +        orw     $0x4000, %bx                    # Use linear frame buffer
   48.94 +        movw    $0x4f02, %ax                    # VESA BIOS mode set call
   48.95 +        int     $0x10
   48.96 +        cmpw    $0x004f, %ax                    # AL=4f if implemented
   48.97 +        jnz     _setbadw                        # AH=0 if OK
   48.98 +
   48.99 +        stc
  48.100 +        ret
  48.101 +
  48.102 +_setbadw: jmp    setbadw
  48.103 +
  48.104 +bogus_real_magic:
  48.105 +        movw    $0x0e00 + 'B', %fs:(0x12)
  48.106 +        jmp     bogus_real_magic
  48.107 +
  48.108 +        .align 4
  48.109 +real_magic:     .long 0x12345678
  48.110 +         .globl video_mode, video_flags
  48.111 +video_mode:     .long 0
  48.112 +video_flags:    .long 0
  48.113 +
  48.114 +        .code32
  48.115 +
  48.116 +        # Now in protect mode, with paging disabled
  48.117 +        # Add offset for any reference to xen specific symbols
  48.118 +
  48.119 +wakeup_32:
  48.120 +        mov     $BOOT_DS, %eax
  48.121 +        mov     %eax, %ds
  48.122 +        mov     %eax, %ss
  48.123 +        mov     $bootsym_phys(wakeup_stack), %esp
  48.124 +
  48.125 +        # check saved magic again
  48.126 +        mov     $sym_phys(saved_magic), %eax
  48.127 +        add     bootsym_phys(trampoline_xen_phys_start), %eax
  48.128 +        mov     (%eax), %eax
  48.129 +        cmp     $0x9abcdef0, %eax
  48.130 +        jne     bogus_saved_magic
  48.131 +        
  48.132 +        /* fpu init? */
  48.133 +
  48.134 +        /* Initialise CR4. */
  48.135 +#if CONFIG_PAGING_LEVELS == 2
  48.136 +        mov     $X86_CR4_PSE, %ecx
  48.137 +#else
  48.138 +        mov     $X86_CR4_PAE, %ecx
  48.139 +#endif
  48.140 +        mov     %ecx, %cr4
  48.141 +
  48.142 +        /* Load pagetable base register */
  48.143 +        mov     $sym_phys(idle_pg_table),%eax
  48.144 +        add     bootsym_phys(trampoline_xen_phys_start),%eax
  48.145 +        mov     %eax,%cr3
  48.146 +
  48.147 +        /* Will cpuid feature change after resume? */
  48.148 +#if CONFIG_PAGING_LEVELS != 2
  48.149 +        /* Set up EFER (Extended Feature Enable Register). */
  48.150 +        mov     bootsym_phys(cpuid_ext_features),%edi
  48.151 +        test    $0x20100800,%edi /* SYSCALL/SYSRET, No Execute, Long Mode? */
  48.152 +        jz      .Lskip_eferw
  48.153 +        movl    $MSR_EFER,%ecx
  48.154 +        rdmsr
  48.155 +#if CONFIG_PAGING_LEVELS == 4
  48.156 +        btsl    $_EFER_LME,%eax /* Long Mode      */
  48.157 +        btsl    $_EFER_SCE,%eax /* SYSCALL/SYSRET */
  48.158 +#endif
  48.159 +        btl     $20,%edi        /* No Execute?    */
  48.160 +        jnc     1f
  48.161 +        btsl    $_EFER_NX,%eax  /* No Execute     */
  48.162 +1:      wrmsr
  48.163 +.Lskip_eferw:
  48.164 +#endif
  48.165 +
  48.166 +        wbinvd
  48.167 +
  48.168 +        mov     $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */
  48.169 +        mov     %eax,%cr0
  48.170 +        jmp     1f
  48.171 +1:
  48.172 +
  48.173 +#if defined(__x86_64__)
  48.174 +
  48.175 +        /* Now in compatibility mode. Long-jump to 64-bit mode */
  48.176 +        ljmp    $BOOT_CS64, $bootsym_phys(wakeup_64)
  48.177 +
  48.178 +        .code64
  48.179 +        .align  8
  48.180 +        .word   0,0,0
  48.181 +lgdt_descr:
  48.182 +        .word   LAST_RESERVED_GDT_BYTE
  48.183 +        .quad   gdt_table - FIRST_RESERVED_GDT_BYTE
  48.184 +        
  48.185 +wakeup_64:
  48.186 +        lgdt    lgdt_descr(%rip)
  48.187 +        mov     $(__HYPERVISOR_DS64), %eax
  48.188 +        mov     %eax, %ds
  48.189 +
  48.190 +        # long jump to return point, with cs reload
  48.191 +        rex64 ljmp    *ret_point(%rip)
  48.192 +
  48.193 +        .align 8
  48.194 +ret_point:
  48.195 +        .quad   __ret_point
  48.196 +        .word   __HYPERVISOR_CS64
  48.197 +
  48.198 +#else /* !defined(__x86_64__) */
  48.199 +        lgdt    gdt_descr
  48.200 +        mov     $(__HYPERVISOR_DS), %eax
  48.201 +        mov     %eax, %ds
  48.202 +
  48.203 +        ljmp    $(__HYPERVISOR_CS), $__ret_point
  48.204 +#endif
  48.205 +
  48.206 +bogus_saved_magic:
  48.207 +        movw    $0x0e00 + 'S', 0xb8014
  48.208 +        jmp     bogus_saved_magic
  48.209 +
  48.210 +        .align  16
  48.211 +wakeup_stack_begin:     # Stack grows down
  48.212 +
  48.213 +        .fill   PAGE_SIZE,1,0
  48.214 +wakeup_stack:           # Just below end of first page in this section
  48.215 +ENTRY(wakeup_end)
    49.1 --- a/xen/arch/x86/cpu/common.c	Wed Jul 11 11:32:30 2007 -0600
    49.2 +++ b/xen/arch/x86/cpu/common.c	Thu Jul 12 09:53:58 2007 +0100
    49.3 @@ -594,3 +594,11 @@ void __devinit cpu_init(void)
    49.4  	/* Install correct page table. */
    49.5  	write_ptbase(current);
    49.6  }
    49.7 +
    49.8 +#ifdef CONFIG_HOTPLUG_CPU
    49.9 +void __cpuinit cpu_uninit(void)
   49.10 +{
   49.11 +	int cpu = raw_smp_processor_id();
   49.12 +	cpu_clear(cpu, cpu_initialized);
   49.13 +}
   49.14 +#endif
    50.1 --- a/xen/arch/x86/dmi_scan.c	Wed Jul 11 11:32:30 2007 -0600
    50.2 +++ b/xen/arch/x86/dmi_scan.c	Thu Jul 12 09:53:58 2007 +0100
    50.3 @@ -184,7 +184,6 @@ static __init int broken_toshiba_keyboar
    50.4  static __init int reset_videomode_after_s3(struct dmi_blacklist *d)
    50.5  {
    50.6  	/* See acpi_wakeup.S */
    50.7 -	extern long acpi_video_flags;
    50.8  	acpi_video_flags |= 2;
    50.9  	return 0;
   50.10  }
    51.1 --- a/xen/arch/x86/domain.c	Wed Jul 11 11:32:30 2007 -0600
    51.2 +++ b/xen/arch/x86/domain.c	Thu Jul 12 09:53:58 2007 +0100
    51.3 @@ -76,10 +76,37 @@ static void default_idle(void)
    51.4          local_irq_enable();
    51.5  }
    51.6  
    51.7 +#ifdef CONFIG_HOTPLUG_CPU
    51.8 +#include <asm/nmi.h>
    51.9 +/* We don't actually take CPU down, just spin without interrupts. */
   51.10 +static inline void play_dead(void)
   51.11 +{
   51.12 +    __cpu_disable();
   51.13 +    /* This must be done before dead CPU ack */
   51.14 +    cpu_exit_clear();
   51.15 +    wbinvd();
   51.16 +    mb();
   51.17 +    /* Ack it */
   51.18 +    __get_cpu_var(cpu_state) = CPU_DEAD;
   51.19 +
   51.20 +    /* With physical CPU hotplug, we should halt the cpu. */
   51.21 +    local_irq_disable();
   51.22 +    for ( ; ; )
   51.23 +        halt();
   51.24 +}
   51.25 +#else
   51.26 +static inline void play_dead(void)
   51.27 +{
   51.28 +    BUG();
   51.29 +}
   51.30 +#endif /* CONFIG_HOTPLUG_CPU */
   51.31 +
   51.32  void idle_loop(void)
   51.33  {
   51.34      for ( ; ; )
   51.35      {
   51.36 +        if (cpu_is_offline(smp_processor_id()))
   51.37 +            play_dead();
   51.38          page_scrub_schedule_work();
   51.39          default_idle();
   51.40          do_softirq();
    52.1 --- a/xen/arch/x86/e820.c	Wed Jul 11 11:32:30 2007 -0600
    52.2 +++ b/xen/arch/x86/e820.c	Thu Jul 12 09:53:58 2007 +0100
    52.3 @@ -310,23 +310,22 @@ static unsigned long __init find_max_pfn
    52.4      return max_pfn;
    52.5  }
    52.6  
    52.7 -#ifdef __i386__
    52.8 -static void __init clip_4gb(void)
    52.9 +static void __init clip_to_limit(uint64_t limit, char *warnmsg)
   52.10  {
   52.11 -    unsigned long long limit = (1ULL << 30) * MACHPHYS_MBYTES;
   52.12      int i;
   52.13 +    char _warnmsg[160];
   52.14  
   52.15 -    /* 32-bit systems restricted to a 4GB physical memory map,
   52.16 -     * with PAE to 16 GB (with current memory layout) */
   52.17      for ( i = 0; i < e820.nr_map; i++ )
   52.18      {
   52.19          if ( (e820.map[i].addr + e820.map[i].size) <= limit )
   52.20              continue;
   52.21 -        printk("WARNING: Only the first %d GB of the physical memory map "
   52.22 -               "can be accessed\n"
   52.23 -               "         by Xen in 32-bit mode. "
   52.24 -               "Truncating the memory map...\n",
   52.25 -	       MACHPHYS_MBYTES);
   52.26 +        if ( warnmsg )
   52.27 +        {
   52.28 +            snprintf(_warnmsg, sizeof(_warnmsg), warnmsg, (int)(limit>>30));
   52.29 +            printk("WARNING: %s\n", _warnmsg);
   52.30 +        }
   52.31 +        printk("Truncating memory map to %lukB\n",
   52.32 +               (unsigned long)(limit >> 10));
   52.33          if ( e820.map[i].addr >= limit )
   52.34          {
   52.35              e820.nr_map = i;
   52.36 @@ -338,34 +337,6 @@ static void __init clip_4gb(void)
   52.37          }            
   52.38      }
   52.39  }
   52.40 -#else
   52.41 -#define clip_4gb() ((void)0)
   52.42 -#endif
   52.43 -
   52.44 -static void __init clip_mem(void)
   52.45 -{
   52.46 -    int i;
   52.47 -
   52.48 -    if ( !opt_mem )
   52.49 -        return;
   52.50 -
   52.51 -    for ( i = 0; i < e820.nr_map; i++ )
   52.52 -    {
   52.53 -        if ( (e820.map[i].addr + e820.map[i].size) <= opt_mem )
   52.54 -            continue;
   52.55 -        printk("Truncating memory map to %lukB\n",
   52.56 -               (unsigned long)(opt_mem >> 10));
   52.57 -        if ( e820.map[i].addr >= opt_mem )
   52.58 -        {
   52.59 -            e820.nr_map = i;
   52.60 -        }
   52.61 -        else
   52.62 -        {
   52.63 -            e820.map[i].size = opt_mem - e820.map[i].addr;
   52.64 -            e820.nr_map = i + 1;          
   52.65 -        }
   52.66 -    }
   52.67 -}
   52.68  
   52.69  static void __init machine_specific_memory_setup(
   52.70      struct e820entry *raw, int *raw_nr)
   52.71 @@ -374,8 +345,22 @@ static void __init machine_specific_memo
   52.72      sanitize_e820_map(raw, &nr);
   52.73      *raw_nr = nr;
   52.74      (void)copy_e820_map(raw, nr);
   52.75 -    clip_4gb();
   52.76 -    clip_mem();
   52.77 +
   52.78 +    if ( opt_mem )
   52.79 +        clip_to_limit(opt_mem, NULL);
   52.80 +
   52.81 +#ifdef __i386__
   52.82 +    clip_to_limit((1ULL << 30) * MACHPHYS_MBYTES,
   52.83 +                  "Only the first %u GB of the physical memory map "
   52.84 +                  "can be accessed by Xen in 32-bit mode.");
   52.85 +#endif
   52.86 +
   52.87 +#ifdef __x86_64__
   52.88 +    clip_to_limit((uint64_t)(MACH2PHYS_COMPAT_VIRT_END -
   52.89 +                             __HYPERVISOR_COMPAT_VIRT_START) << 10,
   52.90 +                  "Only the first %u GB of the physical memory map "
   52.91 +                  "can be accessed by 32-on-64 guests.");
   52.92 +#endif
   52.93  }
   52.94  
   52.95  unsigned long __init init_e820(
    53.1 --- a/xen/arch/x86/hvm/hvm.c	Wed Jul 11 11:32:30 2007 -0600
    53.2 +++ b/xen/arch/x86/hvm/hvm.c	Thu Jul 12 09:53:58 2007 +0100
    53.3 @@ -78,8 +78,7 @@ void hvm_enable(struct hvm_function_tabl
    53.4  
    53.5  void hvm_disable(void)
    53.6  {
    53.7 -    if ( hvm_enabled )
    53.8 -        hvm_funcs.disable();
    53.9 +    hvm_suspend_cpu();
   53.10  }
   53.11  
   53.12  void hvm_stts(struct vcpu *v)
    54.1 --- a/xen/arch/x86/hvm/svm/svm.c	Wed Jul 11 11:32:30 2007 -0600
    54.2 +++ b/xen/arch/x86/hvm/svm/svm.c	Thu Jul 12 09:53:58 2007 +0100
    54.3 @@ -94,9 +94,8 @@ static void svm_inject_exception(struct 
    54.4      vmcb->eventinj = event;
    54.5  }
    54.6  
    54.7 -static void stop_svm(void)
    54.8 +static void svm_suspend_cpu(void)
    54.9  {
   54.10 -    /* We turn off the EFER_SVME bit. */
   54.11      write_efer(read_efer() & ~EFER_SVME);
   54.12  }
   54.13  
   54.14 @@ -974,7 +973,7 @@ static int svm_event_injection_faulted(s
   54.15  
   54.16  static struct hvm_function_table svm_function_table = {
   54.17      .name                 = "SVM",
   54.18 -    .disable              = stop_svm,
   54.19 +    .suspend_cpu          = svm_suspend_cpu,
   54.20      .domain_initialise    = svm_domain_initialise,
   54.21      .domain_destroy       = svm_domain_destroy,
   54.22      .vcpu_initialise      = svm_vcpu_initialise,
    55.1 --- a/xen/arch/x86/hvm/vlapic.c	Wed Jul 11 11:32:30 2007 -0600
    55.2 +++ b/xen/arch/x86/hvm/vlapic.c	Thu Jul 12 09:53:58 2007 +0100
    55.3 @@ -915,10 +915,17 @@ HVM_REGISTER_SAVE_RESTORE(LAPIC_REGS, la
    55.4  int vlapic_init(struct vcpu *v)
    55.5  {
    55.6      struct vlapic *vlapic = vcpu_vlapic(v);
    55.7 +    unsigned int memflags = 0;
    55.8  
    55.9      HVM_DBG_LOG(DBG_LEVEL_VLAPIC, "%d", v->vcpu_id);
   55.10  
   55.11 -    vlapic->regs_page = alloc_domheap_page(NULL);
   55.12 +#ifdef __i386__
   55.13 +    /* 32-bit VMX may be limited to 32-bit physical addresses. */
   55.14 +    if ( boot_cpu_data.x86_vendor == X86_VENDOR_INTEL )
   55.15 +        memflags = MEMF_bits(32);
   55.16 +#endif
   55.17 +
   55.18 +    vlapic->regs_page = alloc_domheap_pages(NULL, 0, memflags);
   55.19      if ( vlapic->regs_page == NULL )
   55.20      {
   55.21          dprintk(XENLOG_ERR, "alloc vlapic regs error: %d/%d\n",
    56.1 --- a/xen/arch/x86/hvm/vmx/vmcs.c	Wed Jul 11 11:32:30 2007 -0600
    56.2 +++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Jul 12 09:53:58 2007 +0100
    56.3 @@ -45,7 +45,9 @@ u32 vmx_vmexit_control __read_mostly;
    56.4  u32 vmx_vmentry_control __read_mostly;
    56.5  bool_t cpu_has_vmx_ins_outs_instr_info __read_mostly;
    56.6  
    56.7 +static DEFINE_PER_CPU(struct vmcs_struct *, host_vmcs);
    56.8  static DEFINE_PER_CPU(struct vmcs_struct *, current_vmcs);
    56.9 +static DEFINE_PER_CPU(struct list_head, active_vmcs_list);
   56.10  
   56.11  static u32 vmcs_revision_id __read_mostly;
   56.12  
   56.13 @@ -151,6 +153,14 @@ void vmx_init_vmcs_config(void)
   56.14  
   56.15      /* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
   56.16      BUG_ON((vmx_msr_high & 0x1fff) > PAGE_SIZE);
   56.17 +
   56.18 +#ifdef __x86_64__
   56.19 +    /* IA-32 SDM Vol 3B: 64-bit CPUs always have VMX_BASIC_MSR[48]==0. */
   56.20 +    BUG_ON(vmx_msr_high & (1u<<16));
   56.21 +#endif
   56.22 +
   56.23 +    /* Require Write-Back (WB) memory type for VMCS accesses. */
   56.24 +    BUG_ON(((vmx_msr_high >> 18) & 15) != 6);
   56.25  }
   56.26  
   56.27  static struct vmcs_struct *vmx_alloc_vmcs(void)
   56.28 @@ -177,34 +187,81 @@ static void vmx_free_vmcs(struct vmcs_st
   56.29  static void __vmx_clear_vmcs(void *info)
   56.30  {
   56.31      struct vcpu *v = info;
   56.32 +    struct arch_vmx_struct *arch_vmx = &v->arch.hvm_vmx;
   56.33  
   56.34 -    __vmpclear(virt_to_maddr(v->arch.hvm_vmx.vmcs));
   56.35 +    /* Otherwise we can nest (vmx_suspend_cpu() vs. vmx_clear_vmcs()). */
   56.36 +    ASSERT(!local_irq_is_enabled());
   56.37 +
   56.38 +    if ( arch_vmx->active_cpu == smp_processor_id() )
   56.39 +    {
   56.40 +        __vmpclear(virt_to_maddr(arch_vmx->vmcs));
   56.41  
   56.42 -    v->arch.hvm_vmx.active_cpu = -1;
   56.43 -    v->arch.hvm_vmx.launched   = 0;
   56.44 +        arch_vmx->active_cpu = -1;
   56.45 +        arch_vmx->launched   = 0;
   56.46  
   56.47 -    if ( v->arch.hvm_vmx.vmcs == this_cpu(current_vmcs) )
   56.48 -        this_cpu(current_vmcs) = NULL;
   56.49 +        list_del(&arch_vmx->active_list);
   56.50 +
   56.51 +        if ( arch_vmx->vmcs == this_cpu(current_vmcs) )
   56.52 +            this_cpu(current_vmcs) = NULL;
   56.53 +    }
   56.54  }
   56.55  
   56.56  static void vmx_clear_vmcs(struct vcpu *v)
   56.57  {
   56.58      int cpu = v->arch.hvm_vmx.active_cpu;
   56.59  
   56.60 -    if ( cpu == -1 )
   56.61 -        return;
   56.62 -
   56.63 -    if ( cpu == smp_processor_id() )
   56.64 -        return __vmx_clear_vmcs(v);
   56.65 -
   56.66 -    on_selected_cpus(cpumask_of_cpu(cpu), __vmx_clear_vmcs, v, 1, 1);
   56.67 +    if ( cpu != -1 )
   56.68 +        on_selected_cpus(cpumask_of_cpu(cpu), __vmx_clear_vmcs, v, 1, 1);
   56.69  }
   56.70  
   56.71  static void vmx_load_vmcs(struct vcpu *v)
   56.72  {
   56.73 +    unsigned long flags;
   56.74 +
   56.75 +    local_irq_save(flags);
   56.76 +
   56.77 +    if ( v->arch.hvm_vmx.active_cpu == -1 )
   56.78 +    {
   56.79 +        list_add(&v->arch.hvm_vmx.active_list, &this_cpu(active_vmcs_list));
   56.80 +        v->arch.hvm_vmx.active_cpu = smp_processor_id();
   56.81 +    }
   56.82 +
   56.83 +    ASSERT(v->arch.hvm_vmx.active_cpu == smp_processor_id());
   56.84 +
   56.85      __vmptrld(virt_to_maddr(v->arch.hvm_vmx.vmcs));
   56.86 -    v->arch.hvm_vmx.active_cpu = smp_processor_id();
   56.87      this_cpu(current_vmcs) = v->arch.hvm_vmx.vmcs;
   56.88 +
   56.89 +    local_irq_restore(flags);
   56.90 +}
   56.91 +
   56.92 +void vmx_suspend_cpu(void)
   56.93 +{
   56.94 +    struct list_head *active_vmcs_list = &this_cpu(active_vmcs_list);
   56.95 +    unsigned long flags;
   56.96 +
   56.97 +    local_irq_save(flags);
   56.98 +
   56.99 +    while ( !list_empty(active_vmcs_list) )
  56.100 +        __vmx_clear_vmcs(list_entry(active_vmcs_list->next,
  56.101 +                                    struct vcpu, arch.hvm_vmx.active_list));
  56.102 +
  56.103 +    if ( read_cr4() & X86_CR4_VMXE )
  56.104 +    {
  56.105 +        __vmxoff();
  56.106 +        clear_in_cr4(X86_CR4_VMXE);
  56.107 +    }
  56.108 +
  56.109 +    local_irq_restore(flags);
  56.110 +}
  56.111 +
  56.112 +void vmx_resume_cpu(void)
  56.113 +{
  56.114 +    if ( !read_cr4() & X86_CR4_VMXE )
  56.115 +    {
  56.116 +        set_in_cr4(X86_CR4_VMXE);
  56.117 +        if ( __vmxon(virt_to_maddr(this_cpu(host_vmcs))) )
  56.118 +            BUG();
  56.119 +    }
  56.120  }
  56.121  
  56.122  void vmx_vmcs_enter(struct vcpu *v)
  56.123 @@ -239,63 +296,40 @@ void vmx_vmcs_exit(struct vcpu *v)
  56.124  
  56.125  struct vmcs_struct *vmx_alloc_host_vmcs(void)
  56.126  {
  56.127 -    return vmx_alloc_vmcs();
  56.128 +    ASSERT(this_cpu(host_vmcs) == NULL);
  56.129 +    this_cpu(host_vmcs) = vmx_alloc_vmcs();
  56.130 +    INIT_LIST_HEAD(&this_cpu(active_vmcs_list));
  56.131 +    return this_cpu(host_vmcs);
  56.132  }
  56.133  
  56.134  void vmx_free_host_vmcs(struct vmcs_struct *vmcs)
  56.135  {
  56.136 +    ASSERT(vmcs == this_cpu(host_vmcs));
  56.137      vmx_free_vmcs(vmcs);
  56.138 +    this_cpu(host_vmcs) = NULL;
  56.139  }
  56.140  
  56.141 -#define GUEST_SEGMENT_LIMIT     0xffffffff
  56.142 -
  56.143 -struct host_execution_env {
  56.144 -    /* selectors */
  56.145 -    unsigned short ldtr_selector;
  56.146 -    unsigned short tr_selector;
  56.147 -    unsigned short ds_selector;
  56.148 -    unsigned short cs_selector;
  56.149 -    /* limits */
  56.150 -    unsigned short gdtr_limit;
  56.151 -    unsigned short ldtr_limit;
  56.152 -    unsigned short idtr_limit;
  56.153 -    unsigned short tr_limit;
  56.154 -    /* base */
  56.155 -    unsigned long gdtr_base;
  56.156 -    unsigned long ldtr_base;
  56.157 -    unsigned long idtr_base;
  56.158 -    unsigned long tr_base;
  56.159 -    unsigned long ds_base;
  56.160 -    unsigned long cs_base;
  56.161 -#ifdef __x86_64__
  56.162 -    unsigned long fs_base;
  56.163 -    unsigned long gs_base;
  56.164 -#endif
  56.165 +struct xgt_desc {
  56.166 +    unsigned short size;
  56.167 +    unsigned long address __attribute__((packed));
  56.168  };
  56.169  
  56.170  static void vmx_set_host_env(struct vcpu *v)
  56.171  {
  56.172      unsigned int tr, cpu;
  56.173 -    struct host_execution_env host_env;
  56.174 -    struct Xgt_desc_struct desc;
  56.175 +    struct xgt_desc desc;
  56.176  
  56.177      cpu = smp_processor_id();
  56.178 -    __asm__ __volatile__ ("sidt  (%0) \n" :: "a"(&desc) : "memory");
  56.179 -    host_env.idtr_limit = desc.size;
  56.180 -    host_env.idtr_base = desc.address;
  56.181 -    __vmwrite(HOST_IDTR_BASE, host_env.idtr_base);
  56.182 +
  56.183 +    __asm__ __volatile__ ( "sidt (%0) \n" : : "a" (&desc) : "memory" );
  56.184 +    __vmwrite(HOST_IDTR_BASE, desc.address);
  56.185  
  56.186 -    __asm__ __volatile__ ("sgdt  (%0) \n" :: "a"(&desc) : "memory");
  56.187 -    host_env.gdtr_limit = desc.size;
  56.188 -    host_env.gdtr_base = desc.address;
  56.189 -    __vmwrite(HOST_GDTR_BASE, host_env.gdtr_base);
  56.190 +    __asm__ __volatile__ ( "sgdt (%0) \n" : : "a" (&desc) : "memory" );
  56.191 +    __vmwrite(HOST_GDTR_BASE, desc.address);
  56.192  
  56.193 -    __asm__ __volatile__ ("str  (%0) \n" :: "a"(&tr) : "memory");
  56.194 -    host_env.tr_selector = tr;
  56.195 -    host_env.tr_limit = sizeof(struct tss_struct);
  56.196 -    host_env.tr_base = (unsigned long) &init_tss[cpu];
  56.197 -    __vmwrite(HOST_TR_SELECTOR, host_env.tr_selector);
  56.198 -    __vmwrite(HOST_TR_BASE, host_env.tr_base);
  56.199 +    __asm__ __volatile__ ( "str (%0) \n" : : "a" (&tr) : "memory" );
  56.200 +    __vmwrite(HOST_TR_SELECTOR, tr);
  56.201 +    __vmwrite(HOST_TR_BASE, (unsigned long)&init_tss[cpu]);
  56.202  
  56.203      /*
  56.204       * Skip end of cpu_user_regs when entering the hypervisor because the
  56.205 @@ -306,6 +340,8 @@ static void vmx_set_host_env(struct vcpu
  56.206                (unsigned long)&get_cpu_info()->guest_cpu_user_regs.error_code);
  56.207  }
  56.208  
  56.209 +#define GUEST_SEGMENT_LIMIT     0xffffffff
  56.210 +
  56.211  static void construct_vmcs(struct vcpu *v)
  56.212  {
  56.213      unsigned long cr0, cr4;
  56.214 @@ -448,11 +484,8 @@ static void construct_vmcs(struct vcpu *
  56.215  
  56.216      if ( cpu_has_vmx_tpr_shadow )
  56.217      {
  56.218 -        paddr_t virt_page_ma = page_to_maddr(vcpu_vlapic(v)->regs_page);
  56.219 -        __vmwrite(VIRTUAL_APIC_PAGE_ADDR, virt_page_ma);
  56.220 -#if defined (CONFIG_X86_PAE)
  56.221 -        __vmwrite(VIRTUAL_APIC_PAGE_ADDR_HIGH, virt_page_ma >> 32);
  56.222 -#endif
  56.223 +        __vmwrite(VIRTUAL_APIC_PAGE_ADDR,
  56.224 +                  page_to_maddr(vcpu_vlapic(v)->regs_page));
  56.225          __vmwrite(TPR_THRESHOLD, 0);
  56.226      }
  56.227  
  56.228 @@ -472,12 +505,17 @@ static void construct_vmcs(struct vcpu *
  56.229  
  56.230  int vmx_create_vmcs(struct vcpu *v)
  56.231  {
  56.232 -    if ( v->arch.hvm_vmx.vmcs == NULL )
  56.233 +    struct arch_vmx_struct *arch_vmx = &v->arch.hvm_vmx;
  56.234 +
  56.235 +    if ( arch_vmx->vmcs == NULL )
  56.236      {
  56.237 -        if ( (v->arch.hvm_vmx.vmcs = vmx_alloc_vmcs()) == NULL )
  56.238 +        if ( (arch_vmx->vmcs = vmx_alloc_vmcs()) == NULL )
  56.239              return -ENOMEM;
  56.240  
  56.241 -        __vmx_clear_vmcs(v);
  56.242 +        INIT_LIST_HEAD(&arch_vmx->active_list);
  56.243 +        __vmpclear(virt_to_maddr(arch_vmx->vmcs));
  56.244 +        arch_vmx->active_cpu = -1;
  56.245 +        arch_vmx->launched   = 0;
  56.246      }
  56.247  
  56.248      construct_vmcs(v);
    57.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Wed Jul 11 11:32:30 2007 -0600
    57.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Jul 12 09:53:58 2007 +0100
    57.3 @@ -907,15 +907,6 @@ static void vmx_ctxt_switch_to(struct vc
    57.4      vmx_restore_dr(v);
    57.5  }
    57.6  
    57.7 -static void stop_vmx(void)
    57.8 -{
    57.9 -    if ( !(read_cr4() & X86_CR4_VMXE) )
   57.10 -        return;
   57.11 -
   57.12 -    __vmxoff();
   57.13 -    clear_in_cr4(X86_CR4_VMXE);
   57.14 -}
   57.15 -
   57.16  static void vmx_store_cpu_guest_regs(
   57.17      struct vcpu *v, struct cpu_user_regs *regs, unsigned long *crs)
   57.18  {
   57.19 @@ -1244,7 +1235,6 @@ static void disable_intercept_for_msr(u3
   57.20  
   57.21  static struct hvm_function_table vmx_function_table = {
   57.22      .name                 = "VMX",
   57.23 -    .disable              = stop_vmx,
   57.24      .domain_initialise    = vmx_domain_initialise,
   57.25      .domain_destroy       = vmx_domain_destroy,
   57.26      .vcpu_initialise      = vmx_vcpu_initialise,
   57.27 @@ -1271,7 +1261,9 @@ static struct hvm_function_table vmx_fun
   57.28      .inject_exception     = vmx_inject_exception,
   57.29      .init_ap_context      = vmx_init_ap_context,
   57.30      .init_hypercall_page  = vmx_init_hypercall_page,
   57.31 -    .event_injection_faulted = vmx_event_injection_faulted
   57.32 +    .event_injection_faulted = vmx_event_injection_faulted,
   57.33 +    .suspend_cpu          = vmx_suspend_cpu,
   57.34 +    .resume_cpu           = vmx_resume_cpu,
   57.35  };
   57.36  
   57.37  int start_vmx(void)
   57.38 @@ -2718,7 +2710,7 @@ static void vmx_free_vlapic_mapping(stru
   57.39  
   57.40  static void vmx_install_vlapic_mapping(struct vcpu *v)
   57.41  {
   57.42 -    paddr_t virt_page_ma, apic_page_ma;
   57.43 +    unsigned long virt_page_ma, apic_page_ma;
   57.44  
   57.45      if ( !cpu_has_vmx_virtualize_apic_accesses )
   57.46          return;
   57.47 @@ -2730,10 +2722,6 @@ static void vmx_install_vlapic_mapping(s
   57.48      vmx_vmcs_enter(v);
   57.49      __vmwrite(VIRTUAL_APIC_PAGE_ADDR, virt_page_ma);
   57.50      __vmwrite(APIC_ACCESS_ADDR, apic_page_ma);
   57.51 -#if defined (CONFIG_X86_PAE)
   57.52 -    __vmwrite(VIRTUAL_APIC_PAGE_ADDR_HIGH, virt_page_ma >> 32);
   57.53 -    __vmwrite(APIC_ACCESS_ADDR_HIGH, apic_page_ma >> 32);
   57.54 -#endif
   57.55      vmx_vmcs_exit(v);
   57.56  }
   57.57  
    58.1 --- a/xen/arch/x86/i8259.c	Wed Jul 11 11:32:30 2007 -0600
    58.2 +++ b/xen/arch/x86/i8259.c	Thu Jul 12 09:53:58 2007 +0100
    58.3 @@ -336,7 +336,7 @@ int i8259A_suspend(void)
    58.4      return 0;
    58.5  }
    58.6  
    58.7 -void __init init_8259A(int auto_eoi)
    58.8 +void __devinit init_8259A(int auto_eoi)
    58.9  {
   58.10      unsigned long flags;
   58.11  
   58.12 @@ -396,6 +396,7 @@ void __init init_IRQ(void)
   58.13          irq_desc[i].action  = NULL;
   58.14          irq_desc[i].depth   = 1;
   58.15          spin_lock_init(&irq_desc[i].lock);
   58.16 +        cpus_setall(irq_desc[i].affinity);
   58.17          set_intr_gate(i, interrupt[i]);
   58.18      }
   58.19  
    59.1 --- a/xen/arch/x86/io_apic.c	Wed Jul 11 11:32:30 2007 -0600
    59.2 +++ b/xen/arch/x86/io_apic.c	Thu Jul 12 09:53:58 2007 +0100
    59.3 @@ -35,9 +35,6 @@
    59.4  #include <mach_apic.h>
    59.5  #include <io_ports.h>
    59.6  
    59.7 -#define set_irq_info(irq, mask) ((void)0)
    59.8 -#define set_native_irq_info(irq, mask) ((void)0)
    59.9 -
   59.10  /* Different to Linux: our implementation can be simpler. */
   59.11  #define make_8259A_irq(irq) (io_apic_irqs &= ~(1<<(irq)))
   59.12  
    60.1 --- a/xen/arch/x86/irq.c	Wed Jul 11 11:32:30 2007 -0600
    60.2 +++ b/xen/arch/x86/irq.c	Thu Jul 12 09:53:58 2007 +0100
    60.3 @@ -654,3 +654,36 @@ static int __init setup_dump_irqs(void)
    60.4      return 0;
    60.5  }
    60.6  __initcall(setup_dump_irqs);
    60.7 +
    60.8 +#ifdef CONFIG_HOTPLUG_CPU
    60.9 +#include <asm/mach-generic/mach_apic.h>
   60.10 +#include <xen/delay.h>
   60.11 +
   60.12 +void fixup_irqs(cpumask_t map)
   60.13 +{
   60.14 +    unsigned int irq;
   60.15 +    static int warned;
   60.16 +
   60.17 +    for ( irq = 0; irq < NR_IRQS; irq++ )
   60.18 +    {
   60.19 +        cpumask_t mask;
   60.20 +        if ( irq == 2 )
   60.21 +            continue;
   60.22 +
   60.23 +        cpus_and(mask, irq_desc[irq].affinity, map);
   60.24 +        if ( any_online_cpu(mask) == NR_CPUS )
   60.25 +        {
   60.26 +            printk("Breaking affinity for irq %i\n", irq);
   60.27 +            mask = map;
   60.28 +        }
   60.29 +        if ( irq_desc[irq].handler->set_affinity )
   60.30 +            irq_desc[irq].handler->set_affinity(irq, mask);
   60.31 +        else if ( irq_desc[irq].action && !(warned++) )
   60.32 +            printk("Cannot set affinity for irq %i\n", irq);
   60.33 +    }
   60.34 +
   60.35 +    local_irq_enable();
   60.36 +    mdelay(1);
   60.37 +    local_irq_disable();
   60.38 +}
   60.39 +#endif
    61.1 --- a/xen/arch/x86/nmi.c	Wed Jul 11 11:32:30 2007 -0600
    61.2 +++ b/xen/arch/x86/nmi.c	Thu Jul 12 09:53:58 2007 +0100
    61.3 @@ -202,7 +202,7 @@ void release_lapic_nmi(void)
    61.4          enable_lapic_nmi_watchdog();
    61.5  }
    61.6  
    61.7 -#define __pminit __init
    61.8 +#define __pminit __devinit
    61.9  
   61.10  /*
   61.11   * Activate the NMI watchdog via the local APIC.
    62.1 --- a/xen/arch/x86/oprofile/nmi_int.c	Wed Jul 11 11:32:30 2007 -0600
    62.2 +++ b/xen/arch/x86/oprofile/nmi_int.c	Thu Jul 12 09:53:58 2007 +0100
    62.3 @@ -27,20 +27,15 @@
    62.4  #include "op_counter.h"
    62.5  #include "op_x86_model.h"
    62.6   
    62.7 +struct op_counter_config counter_config[OP_MAX_COUNTER];
    62.8 +
    62.9  static struct op_x86_model_spec const * model;
   62.10  static struct op_msrs cpu_msrs[NR_CPUS];
   62.11  static unsigned long saved_lvtpc[NR_CPUS];
   62.12  
   62.13 -#define VIRQ_BITMASK_SIZE (MAX_OPROF_DOMAINS/32 + 1)
   62.14 -extern int active_domains[MAX_OPROF_DOMAINS];
   62.15 -extern unsigned int adomains;
   62.16 -extern struct domain *adomain_ptrs[MAX_OPROF_DOMAINS];
   62.17 -extern unsigned long virq_ovf_pending[VIRQ_BITMASK_SIZE];
   62.18 +static char *cpu_type;
   62.19 +
   62.20  extern int is_active(struct domain *d);
   62.21 -extern int active_id(struct domain *d);
   62.22 -extern int is_profiled(struct domain *d);
   62.23 -
   62.24 -
   62.25  
   62.26  static int nmi_callback(struct cpu_user_regs *regs, int cpu)
   62.27  {
   62.28 @@ -262,9 +257,7 @@ void nmi_stop(void)
   62.29  }
   62.30  
   62.31  
   62.32 -struct op_counter_config counter_config[OP_MAX_COUNTER];
   62.33 -
   62.34 -static int __init p4_init(char * cpu_type)
   62.35 +static int __init p4_init(char ** cpu_type)
   62.36  { 
   62.37  	__u8 cpu_model = current_cpu_data.x86_model;
   62.38  
   62.39 @@ -276,20 +269,18 @@ static int __init p4_init(char * cpu_typ
   62.40  	}
   62.41  
   62.42  #ifndef CONFIG_SMP
   62.43 -	strlcpy (cpu_type, "i386/p4", XENOPROF_CPU_TYPE_SIZE);
   62.44 +	*cpu_type = "i386/p4", XENOPROF_CPU_TYPE_SIZE);
   62.45  	model = &op_p4_spec;
   62.46  	return 1;
   62.47  #else
   62.48  	switch (smp_num_siblings) {
   62.49  		case 1:
   62.50 -			strlcpy (cpu_type, "i386/p4", 
   62.51 -				 XENOPROF_CPU_TYPE_SIZE);
   62.52 +			*cpu_type = "i386/p4";
   62.53  			model = &op_p4_spec;
   62.54  			return 1;
   62.55  
   62.56  		case 2:
   62.57 -			strlcpy (cpu_type, "i386/p4-ht", 
   62.58 -				 XENOPROF_CPU_TYPE_SIZE);
   62.59 +			*cpu_type = "i386/p4-ht";
   62.60  			model = &op_p4_ht2_spec;
   62.61  			return 1;
   62.62  	}
   62.63 @@ -300,7 +291,7 @@ static int __init p4_init(char * cpu_typ
   62.64  }
   62.65  
   62.66  
   62.67 -static int __init ppro_init(char *cpu_type)
   62.68 +static int __init ppro_init(char ** cpu_type)
   62.69  {
   62.70  	__u8 cpu_model = current_cpu_data.x86_model;
   62.71  
   62.72 @@ -311,41 +302,32 @@ static int __init ppro_init(char *cpu_ty
   62.73  		return 0;
   62.74  	}
   62.75  	else if (cpu_model == 15)
   62.76 -		strlcpy (cpu_type, "i386/core_2", XENOPROF_CPU_TYPE_SIZE);
   62.77 +		*cpu_type = "i386/core_2";
   62.78  	else if (cpu_model == 14)
   62.79 -		strlcpy (cpu_type, "i386/core", XENOPROF_CPU_TYPE_SIZE);
   62.80 +		*cpu_type = "i386/core";
   62.81  	else if (cpu_model == 9)
   62.82 -		strlcpy (cpu_type, "i386/p6_mobile", XENOPROF_CPU_TYPE_SIZE);
   62.83 +		*cpu_type = "i386/p6_mobile";
   62.84  	else if (cpu_model > 5)
   62.85 -		strlcpy (cpu_type, "i386/piii", XENOPROF_CPU_TYPE_SIZE);
   62.86 +		*cpu_type = "i386/piii";
   62.87  	else if (cpu_model > 2)
   62.88 -		strlcpy (cpu_type, "i386/pii", XENOPROF_CPU_TYPE_SIZE);
   62.89 +		*cpu_type = "i386/pii";
   62.90  	else
   62.91 -		strlcpy (cpu_type, "i386/ppro", XENOPROF_CPU_TYPE_SIZE);
   62.92 +		*cpu_type = "i386/ppro";
   62.93  
   62.94  	model = &op_ppro_spec;
   62.95  	return 1;
   62.96  }
   62.97  
   62.98 -int nmi_init(int *num_events, int *is_primary, char *cpu_type)
   62.99 +static int __init nmi_init(void)
  62.100  {
  62.101  	__u8 vendor = current_cpu_data.x86_vendor;
  62.102  	__u8 family = current_cpu_data.x86;
  62.103 -	int prim = 0;
  62.104   
  62.105  	if (!cpu_has_apic) {
  62.106 -		printk("xenoprof: Initialization failed. No apic.\n");
  62.107 +		printk("xenoprof: Initialization failed. No APIC\n");
  62.108  		return -ENODEV;
  62.109  	}
  62.110  
  62.111 -	if (xenoprof_primary_profiler == NULL) {
  62.112 -		/* For now, only dom0 can be the primary profiler */
  62.113 -		if (current->domain->domain_id == 0) {
  62.114 -			xenoprof_primary_profiler = current->domain;
  62.115 -			prim = 1;
  62.116 -		}
  62.117 -	}
  62.118 - 
  62.119  	switch (vendor) {
  62.120  		case X86_VENDOR_AMD:
  62.121  			/* Needs to be at least an Athlon (or hammer in 32bit mode) */
  62.122 @@ -358,15 +340,13 @@ int nmi_init(int *num_events, int *is_pr
  62.123  				return -ENODEV;
  62.124  			case 6:
  62.125  				model = &op_athlon_spec;
  62.126 -				strlcpy (cpu_type, "i386/athlon", 
  62.127 -					 XENOPROF_CPU_TYPE_SIZE);
  62.128 +				cpu_type = "i386/athlon";
  62.129  				break;
  62.130  			case 0xf:
  62.131  				model = &op_athlon_spec;
  62.132 -				/* Actually it could be i386/hammer too, but give
  62.133 -				   user space an consistent name. */
  62.134 -				strlcpy (cpu_type, "x86-64/hammer", 
  62.135 -					 XENOPROF_CPU_TYPE_SIZE);
  62.136 +				/* Actually it could be i386/hammer too, but
  62.137 +				   give user space an consistent name. */
  62.138 +				cpu_type = "x86-64/hammer";
  62.139  				break;
  62.140  			}
  62.141  			break;
  62.142 @@ -375,13 +355,13 @@ int nmi_init(int *num_events, int *is_pr
  62.143  			switch (family) {
  62.144  				/* Pentium IV */
  62.145  				case 0xf:
  62.146 -					if (!p4_init(cpu_type))
  62.147 +					if (!p4_init(&cpu_type))
  62.148  						return -ENODEV;
  62.149  					break;
  62.150  
  62.151  				/* A P6-class processor */
  62.152  				case 6:
  62.153 -					if (!ppro_init(cpu_type))
  62.154 +					if (!ppro_init(&cpu_type))
  62.155  						return -ENODEV;
  62.156  					break;
  62.157  
  62.158 @@ -400,9 +380,16 @@ int nmi_init(int *num_events, int *is_pr
  62.159  			return -ENODEV;
  62.160  	}
  62.161  
  62.162 -	*num_events = model->num_counters;
  62.163 -	*is_primary = prim;
  62.164 -
  62.165  	return 0;
  62.166  }
  62.167  
  62.168 +__initcall(nmi_init);
  62.169 +
  62.170 +int xenoprof_arch_init(int *num_events, char *_cpu_type)
  62.171 +{
  62.172 +	if (cpu_type == NULL)
  62.173 +		return -ENODEV;
  62.174 +	*num_events = model->num_counters;
  62.175 +	strlcpy(_cpu_type, cpu_type, XENOPROF_CPU_TYPE_SIZE);
  62.176 +	return 0;
  62.177 +}
    63.1 --- a/xen/arch/x86/platform_hypercall.c	Wed Jul 11 11:32:30 2007 -0600
    63.2 +++ b/xen/arch/x86/platform_hypercall.c	Thu Jul 12 09:53:58 2007 +0100
    63.3 @@ -18,6 +18,7 @@
    63.4  #include <xen/console.h>
    63.5  #include <xen/iocap.h>
    63.6  #include <xen/guest_access.h>
    63.7 +#include <xen/acpi.h>
    63.8  #include <asm/current.h>
    63.9  #include <public/platform.h>
   63.10  #include <asm/edd.h>
   63.11 @@ -247,6 +248,22 @@ ret_t do_platform_op(XEN_GUEST_HANDLE(xe
   63.12          }
   63.13          break;
   63.14  
   63.15 +#if 0
   63.16 +    case XENPF_set_acpi_sleep:
   63.17 +    {
   63.18 +        ret = set_acpi_sleep_info(&op->u.set_acpi_sleep);
   63.19 +        if (!ret && copy_to_guest(u_xenpf_op, op, 1))
   63.20 +            ret = -EFAULT;
   63.21 +    }
   63.22 +    break;
   63.23 +
   63.24 +    case XENPF_enter_acpi_sleep:
   63.25 +    {
   63.26 +        ret = acpi_enter_sleep(&op->u.enter_acpi_sleep);
   63.27 +    }
   63.28 +    break;
   63.29 +#endif
   63.30 +
   63.31      default:
   63.32          ret = -ENOSYS;
   63.33          break;
    64.1 --- a/xen/arch/x86/smpboot.c	Wed Jul 11 11:32:30 2007 -0600
    64.2 +++ b/xen/arch/x86/smpboot.c	Thu Jul 12 09:53:58 2007 +0100
    64.3 @@ -110,6 +110,11 @@ u8 x86_cpu_to_apicid[NR_CPUS] __read_mos
    64.4  EXPORT_SYMBOL(x86_cpu_to_apicid);
    64.5  
    64.6  static void map_cpu_to_logical_apicid(void);
    64.7 +/* State of each CPU. */
    64.8 +DEFINE_PER_CPU(int, cpu_state) = { 0 };
    64.9 +
   64.10 +static void *stack_base[NR_CPUS] __cacheline_aligned;
   64.11 +spinlock_t cpu_add_remove_lock;
   64.12  
   64.13  /*
   64.14   * The bootstrap kernel entry code has set these up. Save them for
   64.15 @@ -396,9 +401,11 @@ void __devinit smp_callin(void)
   64.16  	/*
   64.17  	 *      Synchronize the TSC with the BP
   64.18  	 */
   64.19 -	if (cpu_has_tsc && cpu_khz && !tsc_sync_disabled)
   64.20 +	if (cpu_has_tsc && cpu_khz && !tsc_sync_disabled) {
   64.21  		synchronize_tsc_ap();
   64.22 -	calibrate_tsc_ap();
   64.23 +		/* No sync for same reason as above */
   64.24 +		calibrate_tsc_ap();
   64.25 +	}
   64.26  }
   64.27  
   64.28  static int cpucount, booting_cpu;
   64.29 @@ -464,8 +471,12 @@ static void construct_percpu_idt(unsigne
   64.30  {
   64.31  	unsigned char idt_load[10];
   64.32  
   64.33 -	idt_tables[cpu] = xmalloc_array(idt_entry_t, IDT_ENTRIES);
   64.34 -	memcpy(idt_tables[cpu], idt_table, IDT_ENTRIES*sizeof(idt_entry_t));
   64.35 +	/* If IDT table exists since last hotplug, reuse it */
   64.36 +	if (!idt_tables[cpu]) {
   64.37 +		idt_tables[cpu] = xmalloc_array(idt_entry_t, IDT_ENTRIES);
   64.38 +		memcpy(idt_tables[cpu], idt_table,
   64.39 +				IDT_ENTRIES*sizeof(idt_entry_t));
   64.40 +	}
   64.41  
   64.42  	*(unsigned short *)(&idt_load[0]) = (IDT_ENTRIES*sizeof(idt_entry_t))-1;
   64.43  	*(unsigned long  *)(&idt_load[2]) = (unsigned long)idt_tables[cpu];
   64.44 @@ -488,7 +499,7 @@ void __devinit start_secondary(void *unu
   64.45  
   64.46  	set_processor_id(cpu);
   64.47  	set_current(idle_vcpu[cpu]);
   64.48 -        this_cpu(curr_vcpu) = idle_vcpu[cpu];
   64.49 +	this_cpu(curr_vcpu) = idle_vcpu[cpu];
   64.50  
   64.51  	percpu_traps_init();
   64.52  
   64.53 @@ -516,24 +527,14 @@ void __devinit start_secondary(void *unu
   64.54  	set_cpu_sibling_map(raw_smp_processor_id());
   64.55  	wmb();
   64.56  
   64.57 -	/*
   64.58 -	 * We need to hold call_lock, so there is no inconsistency
   64.59 -	 * between the time smp_call_function() determines number of
   64.60 -	 * IPI receipients, and the time when the determination is made
   64.61 -	 * for which cpus receive the IPI. Holding this
   64.62 -	 * lock helps us to not include this cpu in a currently in progress
   64.63 -	 * smp_call_function().
   64.64 -	 */
   64.65 -	/*lock_ipi_call_lock();*/
   64.66  	cpu_set(smp_processor_id(), cpu_online_map);
   64.67 -	/*unlock_ipi_call_lock();*/
   64.68 -	/*per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;*/
   64.69 +	per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
   64.70 +
   64.71 +	init_percpu_time();
   64.72  
   64.73  	/* We can take interrupts now: we're officially "up". */
   64.74  	local_irq_enable();
   64.75  
   64.76 -        init_percpu_time();
   64.77 -
   64.78  	wmb();
   64.79  	startup_cpu_idle_loop();
   64.80  }
   64.81 @@ -794,6 +795,22 @@ static inline int alloc_cpu_id(void)
   64.82  	return cpu;
   64.83  }
   64.84  
   64.85 +static struct vcpu *prepare_idle_vcpu(unsigned int cpu)
   64.86 +{
   64.87 +	if (idle_vcpu[cpu])
   64.88 +		return idle_vcpu[cpu];
   64.89 +
   64.90 +	return alloc_idle_vcpu(cpu);
   64.91 +}
   64.92 +
   64.93 +static void *prepare_idle_stack(unsigned int cpu)
   64.94 +{
   64.95 +	if (!stack_base[cpu])
   64.96 +		stack_base[cpu] = alloc_xenheap_pages(STACK_ORDER);
   64.97 +
   64.98 +	return stack_base[cpu];
   64.99 +}
  64.100 +
  64.101  static int __devinit do_boot_cpu(int apicid, int cpu)
  64.102  /*
  64.103   * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
  64.104 @@ -811,7 +828,7 @@ static int __devinit do_boot_cpu(int api
  64.105  
  64.106  	booting_cpu = cpu;
  64.107  
  64.108 -	v = alloc_idle_vcpu(cpu);
  64.109 +	v = prepare_idle_vcpu(cpu);
  64.110  	BUG_ON(v == NULL);
  64.111  
  64.112  	/* start_eip had better be page-aligned! */
  64.113 @@ -820,7 +837,7 @@ static int __devinit do_boot_cpu(int api
  64.114  	/* So we see what's up   */
  64.115  	printk("Booting processor %d/%d eip %lx\n", cpu, apicid, start_eip);
  64.116  
  64.117 -	stack_start.esp = alloc_xenheap_pages(STACK_ORDER);
  64.118 +	stack_start.esp = prepare_idle_stack(cpu);
  64.119  
  64.120  	/* Debug build: detect stack overflow by setting up a guard page. */
  64.121  	memguard_guard_stack(stack_start.esp);
  64.122 @@ -897,6 +914,51 @@ static int __devinit do_boot_cpu(int api
  64.123  	return boot_error;
  64.124  }
  64.125  
  64.126 +#ifdef CONFIG_HOTPLUG_CPU
  64.127 +static void idle_task_exit(void)
  64.128 +{
  64.129 +	/* Give up lazy state borrowed by this idle vcpu */
  64.130 +	__sync_lazy_execstate();
  64.131 +}
  64.132 +
  64.133 +void cpu_exit_clear(void)
  64.134 +{
  64.135 +	int cpu = raw_smp_processor_id();
  64.136 +
  64.137 +	idle_task_exit();
  64.138 +
  64.139 +	cpucount --;
  64.140 +	cpu_uninit();
  64.141 +
  64.142 +	cpu_clear(cpu, cpu_callout_map);
  64.143 +	cpu_clear(cpu, cpu_callin_map);
  64.144 +
  64.145 +	cpu_clear(cpu, smp_commenced_mask);
  64.146 +	unmap_cpu_to_logical_apicid(cpu);
  64.147 +}
  64.148 +
  64.149 +static int __cpuinit __smp_prepare_cpu(int cpu)
  64.150 +{
  64.151 +	int	apicid, ret;
  64.152 +
  64.153 +	apicid = x86_cpu_to_apicid[cpu];
  64.154 +	if (apicid == BAD_APICID) {
  64.155 +		ret = -ENODEV;
  64.156 +		goto exit;
  64.157 +	}
  64.158 +
  64.159 +	tsc_sync_disabled = 1;
  64.160 +
  64.161 +	do_boot_cpu(apicid, cpu);
  64.162 +
  64.163 +	tsc_sync_disabled = 0;
  64.164 +
  64.165 +	ret = 0;
  64.166 +exit:
  64.167 +	return ret;
  64.168 +}
  64.169 +#endif
  64.170 +
  64.171  /*
  64.172   * Cycle through the processors sending APIC IPIs to boot each.
  64.173   */
  64.174 @@ -924,6 +986,8 @@ static void __init smp_boot_cpus(unsigne
  64.175  	boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
  64.176  	x86_cpu_to_apicid[0] = boot_cpu_physical_apicid;
  64.177  
  64.178 +	stack_base[0] = stack_start.esp;
  64.179 +
  64.180  	/*current_thread_info()->cpu = 0;*/
  64.181  	/*smp_tune_scheduling();*/
  64.182  
  64.183 @@ -1094,11 +1158,238 @@ void __devinit smp_prepare_boot_cpu(void
  64.184  	cpu_set(smp_processor_id(), cpu_callout_map);
  64.185  	cpu_set(smp_processor_id(), cpu_present_map);
  64.186  	cpu_set(smp_processor_id(), cpu_possible_map);
  64.187 -	/*per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;*/
  64.188 +	per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
  64.189 +	spin_lock_init(&cpu_add_remove_lock);
  64.190 +}
  64.191 +
  64.192 +#ifdef CONFIG_HOTPLUG_CPU
  64.193 +static void
  64.194 +remove_siblinginfo(int cpu)
  64.195 +{
  64.196 +	int sibling;
  64.197 +	struct cpuinfo_x86 *c = cpu_data;
  64.198 +
  64.199 +	for_each_cpu_mask(sibling, cpu_core_map[cpu]) {
  64.200 +		cpu_clear(cpu, cpu_core_map[sibling]);
  64.201 +		/*
  64.202 +		 * last thread sibling in this cpu core going down
  64.203 +		 */
  64.204 +		if (cpus_weight(cpu_sibling_map[cpu]) == 1)
  64.205 +			c[sibling].booted_cores--;
  64.206 +	}
  64.207 +			
  64.208 +	for_each_cpu_mask(sibling, cpu_sibling_map[cpu])
  64.209 +		cpu_clear(cpu, cpu_sibling_map[sibling]);
  64.210 +	cpus_clear(cpu_sibling_map[cpu]);
  64.211 +	cpus_clear(cpu_core_map[cpu]);
  64.212 +	phys_proc_id[cpu] = BAD_APICID;
  64.213 +	cpu_core_id[cpu] = BAD_APICID;
  64.214 +	cpu_clear(cpu, cpu_sibling_setup_map);
  64.215 +}
  64.216 +
  64.217 +extern void fixup_irqs(cpumask_t map);
  64.218 +int __cpu_disable(void)
  64.219 +{
  64.220 +	cpumask_t map = cpu_online_map;
  64.221 +	int cpu = smp_processor_id();
  64.222 +
  64.223 +	/*
  64.224 +	 * Perhaps use cpufreq to drop frequency, but that could go
  64.225 +	 * into generic code.
  64.226 + 	 *
  64.227 +	 * We won't take down the boot processor on i386 due to some
  64.228 +	 * interrupts only being able to be serviced by the BSP.
  64.229 +	 * Especially so if we're not using an IOAPIC	-zwane
  64.230 +	 */
  64.231 +	if (cpu == 0)
  64.232 +		return -EBUSY;
  64.233 +
  64.234 +	local_irq_disable();
  64.235 +	clear_local_APIC();
  64.236 +	/* Allow any queued timer interrupts to get serviced */
  64.237 +	local_irq_enable();
  64.238 +	mdelay(1);
  64.239 +	local_irq_disable();
  64.240 +
  64.241 +	time_suspend();
  64.242 +
  64.243 +	remove_siblinginfo(cpu);
  64.244 +
  64.245 +	cpu_clear(cpu, map);
  64.246 +	fixup_irqs(map);
  64.247 +	/* It's now safe to remove this processor from the online map */
  64.248 +	cpu_clear(cpu, cpu_online_map);
  64.249 +	return 0;
  64.250 +}
  64.251 +
  64.252 +void __cpu_die(unsigned int cpu)
  64.253 +{
  64.254 +	/* We don't do anything here: idle task is faking death itself. */
  64.255 +	unsigned int i;
  64.256 +
  64.257 +	for (i = 0; i < 10; i++) {
  64.258 +		/* They ack this in play_dead by setting CPU_DEAD */
  64.259 +		if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
  64.260 +			printk ("CPU %d is now offline\n", cpu);
  64.261 +			return;
  64.262 +		}
  64.263 +		mdelay(100);
  64.264 +		mb();
  64.265 +		process_pending_timers();
  64.266 +	}
  64.267 + 	printk(KERN_ERR "CPU %u didn't die...\n", cpu);
  64.268  }
  64.269  
  64.270 +/* 
  64.271 + * XXX: One important thing missed here is to migrate vcpus
  64.272 + * from dead cpu to other online ones and then put whole
  64.273 + * system into a stop state. It assures a safe environment
  64.274 + * for a cpu hotplug/remove at normal running state.
  64.275 + *
  64.276 + * However for xen PM case, at this point:
  64.277 + * 	-> All other domains should be notified with PM event,
  64.278 + *	   and then in following states:
  64.279 + *		* Suspend state, or
  64.280 + *		* Paused state, which is a force step to all
  64.281 + *		  domains if they do nothing to suspend
  64.282 + *	-> All vcpus of dom0 (except vcpu0) have already beem
  64.283 + *	   hot removed
  64.284 + * with the net effect that all other cpus only have idle vcpu
  64.285 + * running. In this special case, we can avoid vcpu migration
  64.286 + * then and system can be considered in a stop state.
  64.287 + *
  64.288 + * So current cpu hotplug is a special version for PM specific
  64.289 + * usage, and need more effort later for full cpu hotplug.
  64.290 + * (ktian1)
  64.291 + */
  64.292 +int cpu_down(unsigned int cpu)
  64.293 +{
  64.294 +	int err = 0;
  64.295 +	cpumask_t mask;
  64.296 +
  64.297 +	spin_lock(&cpu_add_remove_lock);
  64.298 +	if (num_online_cpus() == 1) {
  64.299 +		err = -EBUSY;
  64.300 +		goto out;
  64.301 +	}
  64.302 +
  64.303 +	if (!cpu_online(cpu)) {
  64.304 +		err = -EINVAL;
  64.305 +		goto out;
  64.306 +	}
  64.307 +
  64.308 +	printk("Prepare to bring CPU%d down...\n", cpu);
  64.309 +	/* Send notification to remote idle vcpu */
  64.310 +	cpus_clear(mask);
  64.311 +	cpu_set(cpu, mask);
  64.312 +	per_cpu(cpu_state, cpu) = CPU_DYING;
  64.313 +	smp_send_event_check_mask(mask);
  64.314 +
  64.315 +	__cpu_die(cpu);
  64.316 +
  64.317 +	if (cpu_online(cpu)) {
  64.318 +		printk("Bad state (DEAD, but in online map) on CPU%d\n", cpu);
  64.319 +		err = -EBUSY;
  64.320 +	}
  64.321 +out:
  64.322 +	spin_unlock(&cpu_add_remove_lock);
  64.323 +	return err;
  64.324 +}
  64.325 +
  64.326 +int cpu_up(unsigned int cpu)
  64.327 +{
  64.328 +	int err = 0;
  64.329 +
  64.330 +	spin_lock(&cpu_add_remove_lock);
  64.331 +	if (cpu_online(cpu)) {
  64.332 +		printk("Bring up a online cpu. Bogus!\n");
  64.333 +		err = -EBUSY;
  64.334 +		goto out;
  64.335 +	}
  64.336 +
  64.337 +	err = __cpu_up(cpu);
  64.338 +	if (err < 0)
  64.339 +		goto out;
  64.340 +
  64.341 +out:
  64.342 +	spin_unlock(&cpu_add_remove_lock);
  64.343 +	return err;
  64.344 +}
  64.345 +
  64.346 +/* From kernel/power/main.c */
  64.347 +/* This is protected by pm_sem semaphore */
  64.348 +static cpumask_t frozen_cpus;
  64.349 +
  64.350 +void disable_nonboot_cpus(void)
  64.351 +{
  64.352 +	int cpu, error;
  64.353 +
  64.354 +	error = 0;
  64.355 +	cpus_clear(frozen_cpus);
  64.356 +	printk("Freezing cpus ...\n");
  64.357 +	for_each_online_cpu(cpu) {
  64.358 +		if (cpu == 0)
  64.359 +			continue;
  64.360 +		error = cpu_down(cpu);
  64.361 +		if (!error) {
  64.362 +			cpu_set(cpu, frozen_cpus);
  64.363 +			printk("CPU%d is down\n", cpu);
  64.364 +			continue;
  64.365 +		}
  64.366 +		printk("Error taking cpu %d down: %d\n", cpu, error);
  64.367 +	}
  64.368 +	BUG_ON(raw_smp_processor_id() != 0);
  64.369 +	if (error)
  64.370 +		panic("cpus not sleeping");
  64.371 +}
  64.372 +
  64.373 +void enable_nonboot_cpus(void)
  64.374 +{
  64.375 +	int cpu, error;
  64.376 +
  64.377 +	printk("Thawing cpus ...\n");
  64.378 +	for_each_cpu_mask(cpu, frozen_cpus) {
  64.379 +		error = cpu_up(cpu);
  64.380 +		if (!error) {
  64.381 +			printk("CPU%d is up\n", cpu);
  64.382 +			continue;
  64.383 +		}
  64.384 +		printk("Error taking cpu %d up: %d\n", cpu, error);
  64.385 +		panic("Not enough cpus");
  64.386 +	}
  64.387 +	cpus_clear(frozen_cpus);
  64.388 +}
  64.389 +#else /* ... !CONFIG_HOTPLUG_CPU */
  64.390 +int __cpu_disable(void)
  64.391 +{
  64.392 +	return -ENOSYS;
  64.393 +}
  64.394 +
  64.395 +void __cpu_die(unsigned int cpu)
  64.396 +{
  64.397 +	/* We said "no" in __cpu_disable */
  64.398 +	BUG();
  64.399 +}
  64.400 +#endif /* CONFIG_HOTPLUG_CPU */
  64.401 +
  64.402  int __devinit __cpu_up(unsigned int cpu)
  64.403  {
  64.404 +#ifdef CONFIG_HOTPLUG_CPU
  64.405 +	int ret=0;
  64.406 +
  64.407 +	/*
  64.408 +	 * We do warm boot only on cpus that had booted earlier
  64.409 +	 * Otherwise cold boot is all handled from smp_boot_cpus().
  64.410 +	 * cpu_callin_map is set during AP kickstart process. Its reset
  64.411 +	 * when a cpu is taken offline from cpu_exit_clear().
  64.412 +	 */
  64.413 +	if (!cpu_isset(cpu, cpu_callin_map))
  64.414 +		ret = __smp_prepare_cpu(cpu);
  64.415 +
  64.416 +	if (ret)
  64.417 +		return -EIO;
  64.418 +#endif
  64.419 +
  64.420  	/* In case one didn't come up */
  64.421  	if (!cpu_isset(cpu, cpu_callin_map)) {
  64.422  		printk(KERN_DEBUG "skipping cpu%d, didn't come online\n", cpu);
  64.423 @@ -1117,6 +1408,7 @@ int __devinit __cpu_up(unsigned int cpu)
  64.424  	return 0;
  64.425  }
  64.426  
  64.427 +
  64.428  void __init smp_cpus_done(unsigned int max_cpus)
  64.429  {
  64.430  #ifdef CONFIG_X86_IO_APIC
    65.1 --- a/xen/arch/x86/x86_32/traps.c	Wed Jul 11 11:32:30 2007 -0600
    65.2 +++ b/xen/arch/x86/x86_32/traps.c	Thu Jul 12 09:53:58 2007 +0100
    65.3 @@ -232,7 +232,7 @@ unsigned long do_iret(void)
    65.4      return 0;
    65.5  }
    65.6  
    65.7 -void __init percpu_traps_init(void)
    65.8 +void __devinit percpu_traps_init(void)
    65.9  {
   65.10      struct tss_struct *tss = &doublefault_tss;
   65.11      asmlinkage int hypercall(void);
    66.1 --- a/xen/arch/x86/x86_64/traps.c	Wed Jul 11 11:32:30 2007 -0600
    66.2 +++ b/xen/arch/x86/x86_64/traps.c	Thu Jul 12 09:53:58 2007 +0100
    66.3 @@ -285,7 +285,7 @@ static int write_stack_trampoline(
    66.4      return 34;
    66.5  }
    66.6  
    66.7 -void __init percpu_traps_init(void)
    66.8 +void __devinit percpu_traps_init(void)
    66.9  {
   66.10      char *stack_bottom, *stack;
   66.11      int   cpu = smp_processor_id();
    67.1 --- a/xen/common/page_alloc.c	Wed Jul 11 11:32:30 2007 -0600
    67.2 +++ b/xen/common/page_alloc.c	Thu Jul 12 09:53:58 2007 +0100
    67.3 @@ -936,6 +936,21 @@ void free_domheap_pages(struct page_info
    67.4          put_domain(d);
    67.5  }
    67.6  
    67.7 +unsigned long avail_domheap_pages_region(
    67.8 +    unsigned int node, unsigned int min_width, unsigned int max_width)
    67.9 +{
   67.10 +    int zone_lo, zone_hi;
   67.11 +
   67.12 +    zone_lo = min_width ? (min_width - (PAGE_SHIFT + 1)) : (MEMZONE_XEN + 1);
   67.13 +    zone_lo = max_t(int, MEMZONE_XEN + 1, zone_lo);
   67.14 +    zone_lo = min_t(int, NR_ZONES - 1, zone_lo);
   67.15 +
   67.16 +    zone_hi = max_width ? (max_width - (PAGE_SHIFT + 1)) : (NR_ZONES - 1);
   67.17 +    zone_hi = max_t(int, MEMZONE_XEN + 1, zone_hi);
   67.18 +    zone_hi = min_t(int, NR_ZONES - 1, zone_hi);
   67.19 +
   67.20 +    return avail_heap_pages(zone_lo, zone_hi, node);
   67.21 +}
   67.22  
   67.23  unsigned long avail_domheap_pages(void)
   67.24  {
   67.25 @@ -957,11 +972,6 @@ unsigned long avail_domheap_pages(void)
   67.26      return avail_nrm + avail_dma;
   67.27  }
   67.28  
   67.29 -unsigned long avail_nodeheap_pages(int node)
   67.30 -{
   67.31 -    return avail_heap_pages(0, NR_ZONES - 1, node);
   67.32 -}
   67.33 -
   67.34  static void pagealloc_keyhandler(unsigned char key)
   67.35  {
   67.36      unsigned int zone = MEMZONE_XEN;
    68.1 --- a/xen/common/sysctl.c	Wed Jul 11 11:32:30 2007 -0600
    68.2 +++ b/xen/common/sysctl.c	Thu Jul 12 09:53:58 2007 +0100
    68.3 @@ -21,6 +21,8 @@
    68.4  #include <xen/keyhandler.h>
    68.5  #include <asm/current.h>
    68.6  #include <public/sysctl.h>
    68.7 +#include <asm/numa.h>
    68.8 +#include <xen/nodemask.h>
    68.9  
   68.10  extern long arch_do_sysctl(
   68.11      struct xen_sysctl *op, XEN_GUEST_HANDLE(xen_sysctl_t) u_sysctl);
   68.12 @@ -169,6 +171,18 @@ long do_sysctl(XEN_GUEST_HANDLE(xen_sysc
   68.13      }
   68.14      break;
   68.15  
   68.16 +    case XEN_SYSCTL_availheap:
   68.17 +    { 
   68.18 +        op->u.availheap.avail_bytes = avail_domheap_pages_region(
   68.19 +            op->u.availheap.node,
   68.20 +            op->u.availheap.min_bitwidth,
   68.21 +            op->u.availheap.max_bitwidth);
   68.22 +        op->u.availheap.avail_bytes <<= PAGE_SHIFT;
   68.23 +
   68.24 +        ret = copy_to_guest(u_sysctl, op, 1) ? -EFAULT : 0;
   68.25 +    }
   68.26 +    break;
   68.27 +
   68.28      default:
   68.29          ret = arch_do_sysctl(op, u_sysctl);
   68.30          break;
    69.1 --- a/xen/common/xenoprof.c	Wed Jul 11 11:32:30 2007 -0600
    69.2 +++ b/xen/common/xenoprof.c	Thu Jul 12 09:53:58 2007 +0100
    69.3 @@ -21,26 +21,26 @@
    69.4  /* Lock protecting the following global state */
    69.5  static DEFINE_SPINLOCK(xenoprof_lock);
    69.6  
    69.7 -struct domain *active_domains[MAX_OPROF_DOMAINS];
    69.8 -int active_ready[MAX_OPROF_DOMAINS];
    69.9 -unsigned int adomains;
   69.10 +static struct domain *active_domains[MAX_OPROF_DOMAINS];
   69.11 +static int active_ready[MAX_OPROF_DOMAINS];
   69.12 +static unsigned int adomains;
   69.13  
   69.14 -struct domain *passive_domains[MAX_OPROF_DOMAINS];
   69.15 -unsigned int pdomains;
   69.16 +static struct domain *passive_domains[MAX_OPROF_DOMAINS];
   69.17 +static unsigned int pdomains;
   69.18  
   69.19 -unsigned int activated;
   69.20 -struct domain *xenoprof_primary_profiler;
   69.21 -int xenoprof_state = XENOPROF_IDLE;
   69.22 +static unsigned int activated;
   69.23 +static struct domain *xenoprof_primary_profiler;
   69.24 +static int xenoprof_state = XENOPROF_IDLE;
   69.25  static unsigned long backtrace_depth;
   69.26  
   69.27 -u64 total_samples;
   69.28 -u64 invalid_buffer_samples;
   69.29 -u64 corrupted_buffer_samples;
   69.30 -u64 lost_samples;
   69.31 -u64 active_samples;
   69.32 -u64 passive_samples;
   69.33 -u64 idle_samples;
   69.34 -u64 others_samples;
   69.35 +static u64 total_samples;
   69.36 +static u64 invalid_buffer_samples;
   69.37 +static u64 corrupted_buffer_samples;
   69.38 +static u64 lost_samples;
   69.39 +static u64 active_samples;
   69.40 +static u64 passive_samples;
   69.41 +static u64 idle_samples;
   69.42 +static u64 others_samples;
   69.43  
   69.44  int is_active(struct domain *d)
   69.45  {
   69.46 @@ -48,13 +48,13 @@ int is_active(struct domain *d)
   69.47      return ((x != NULL) && (x->domain_type == XENOPROF_DOMAIN_ACTIVE));
   69.48  }
   69.49  
   69.50 -int is_passive(struct domain *d)
   69.51 +static int is_passive(struct domain *d)
   69.52  {
   69.53      struct xenoprof *x = d->xenoprof;
   69.54      return ((x != NULL) && (x->domain_type == XENOPROF_DOMAIN_PASSIVE));
   69.55  }
   69.56  
   69.57 -int is_profiled(struct domain *d)
   69.58 +static int is_profiled(struct domain *d)
   69.59  {
   69.60      return (is_active(d) || is_passive(d));
   69.61  }
   69.62 @@ -543,24 +543,24 @@ void xenoprof_log_event(struct vcpu *vcp
   69.63  
   69.64  static int xenoprof_op_init(XEN_GUEST_HANDLE(void) arg)
   69.65  {
   69.66 +    struct domain *d = current->domain;
   69.67      struct xenoprof_init xenoprof_init;
   69.68      int ret;
   69.69  
   69.70      if ( copy_from_guest(&xenoprof_init, arg, 1) )
   69.71          return -EFAULT;
   69.72  
   69.73 -    if ( (ret = xenoprof_arch_init(&xenoprof_init.num_events, 
   69.74 -                                   &xenoprof_init.is_primary, 
   69.75 +    if ( (ret = xenoprof_arch_init(&xenoprof_init.num_events,
   69.76                                     xenoprof_init.cpu_type)) )
   69.77          return ret;
   69.78  
   69.79 -    if ( copy_to_guest(arg, &xenoprof_init, 1) )
   69.80 -        return -EFAULT;
   69.81 -
   69.82 +    xenoprof_init.is_primary = 
   69.83 +        ((xenoprof_primary_profiler == d) ||
   69.84 +         ((xenoprof_primary_profiler == NULL) && (d->domain_id == 0)));
   69.85      if ( xenoprof_init.is_primary )
   69.86          xenoprof_primary_profiler = current->domain;
   69.87  
   69.88 -    return 0;
   69.89 +    return (copy_to_guest(arg, &xenoprof_init, 1) ? -EFAULT : 0);
   69.90  }
   69.91  
   69.92  #endif /* !COMPAT */
    70.1 --- a/xen/drivers/char/ns16550.c	Wed Jul 11 11:32:30 2007 -0600
    70.2 +++ b/xen/drivers/char/ns16550.c	Thu Jul 12 09:53:58 2007 +0100
    70.3 @@ -170,7 +170,7 @@ static int ns16550_getc(struct serial_po
    70.4      return 1;
    70.5  }
    70.6  
    70.7 -static void __init ns16550_init_preirq(struct serial_port *port)
    70.8 +static void __devinit ns16550_init_preirq(struct serial_port *port)
    70.9  {
   70.10      struct ns16550 *uart = port->uart;
   70.11      unsigned char lcr;
   70.12 @@ -214,7 +214,7 @@ static void __init ns16550_init_preirq(s
   70.13          port->tx_fifo_size = 16;
   70.14  }
   70.15  
   70.16 -static void __init ns16550_init_postirq(struct serial_port *port)
   70.17 +static void __devinit ns16550_init_postirq(struct serial_port *port)
   70.18  {
   70.19      struct ns16550 *uart = port->uart;
   70.20      int rc, bits;
    71.1 --- a/xen/drivers/char/serial.c	Wed Jul 11 11:32:30 2007 -0600
    71.2 +++ b/xen/drivers/char/serial.c	Thu Jul 12 09:53:58 2007 +0100
    71.3 @@ -348,7 +348,7 @@ int serial_tx_space(int handle)
    71.4      return SERIAL_TXBUFSZ - (port->txbufp - port->txbufc);
    71.5  }
    71.6  
    71.7 -void __init serial_init_preirq(void)
    71.8 +void __devinit serial_init_preirq(void)
    71.9  {
   71.10      int i;
   71.11      for ( i = 0; i < ARRAY_SIZE(com); i++ )
   71.12 @@ -356,7 +356,7 @@ void __init serial_init_preirq(void)
   71.13              com[i].driver->init_preirq(&com[i]);
   71.14  }
   71.15  
   71.16 -void __init serial_init_postirq(void)
   71.17 +void __devinit serial_init_postirq(void)
   71.18  {
   71.19      int i;
   71.20      for ( i = 0; i < ARRAY_SIZE(com); i++ )
    72.1 --- a/xen/include/asm-ia64/xenoprof.h	Wed Jul 11 11:32:30 2007 -0600
    72.2 +++ b/xen/include/asm-ia64/xenoprof.h	Thu Jul 12 09:53:58 2007 +0100
    72.3 @@ -24,7 +24,7 @@
    72.4  #ifndef __ASM_XENOPROF_H__
    72.5  #define __ASM_XENOPROF_H__
    72.6  
    72.7 -int xenoprof_arch_init(int *num_events, int *is_primary, char *cpu_type);
    72.8 +int xenoprof_arch_init(int *num_events, char *cpu_type);
    72.9  int xenoprof_arch_reserve_counters(void);
   72.10  int xenoprof_arch_counter(XEN_GUEST_HANDLE(void) arg);
   72.11  int xenoprof_arch_setup_events(void);
    73.1 --- a/xen/include/asm-x86/acpi.h	Wed Jul 11 11:32:30 2007 -0600
    73.2 +++ b/xen/include/asm-x86/acpi.h	Thu Jul 12 09:53:58 2007 +0100
    73.3 @@ -173,6 +173,14 @@ extern unsigned long acpi_wakeup_address
    73.4  /* early initialization routine */
    73.5  extern void acpi_reserve_bootmem(void);
    73.6  
    73.7 +extern unsigned long acpi_video_flags;
    73.8 +extern unsigned long saved_videomode;
    73.9 +struct xenpf_set_acpi_sleep;
   73.10 +struct xenpf_enter_acpi_sleep;
   73.11 +extern int set_acpi_sleep_info(struct xenpf_set_acpi_sleep *info);
   73.12 +extern int acpi_enter_sleep(struct xenpf_enter_acpi_sleep *sleep);
   73.13 +extern int acpi_enter_state(u32 state);
   73.14 +
   73.15  #endif /*CONFIG_ACPI_SLEEP*/
   73.16  
   73.17  extern u8 x86_acpiid_to_apicid[];
    74.1 --- a/xen/include/asm-x86/config.h	Wed Jul 11 11:32:30 2007 -0600
    74.2 +++ b/xen/include/asm-x86/config.h	Thu Jul 12 09:53:58 2007 +0100
    74.3 @@ -25,9 +25,7 @@
    74.4  #define CONFIG_X86_PM_TIMER 1
    74.5  #define CONFIG_HPET_TIMER 1
    74.6  #define CONFIG_X86_MCE_P4THERMAL 1
    74.7 -#define CONFIG_ACPI_NUMA 1
    74.8  #define CONFIG_NUMA 1
    74.9 -#define CONFIG_ACPI_SRAT 1
   74.10  #define CONFIG_DISCONTIGMEM 1
   74.11  #define CONFIG_NUMA_EMU 1
   74.12  
   74.13 @@ -36,9 +34,15 @@
   74.14  
   74.15  #define CONFIG_ACPI 1
   74.16  #define CONFIG_ACPI_BOOT 1
   74.17 +#define CONFIG_ACPI_SLEEP 1
   74.18 +#define CONFIG_ACPI_NUMA 1
   74.19 +#define CONFIG_ACPI_SRAT 1
   74.20  
   74.21  #define CONFIG_VGA 1
   74.22  
   74.23 +#define CONFIG_HOTPLUG 1
   74.24 +#define CONFIG_HOTPLUG_CPU 1
   74.25 +
   74.26  #define HZ 100
   74.27  
   74.28  #define OPT_CONSOLE_STR "com1,vga"
   74.29 @@ -100,6 +104,8 @@ extern char trampoline_start[], trampoli
   74.30  extern char trampoline_realmode_entry[];
   74.31  extern unsigned int trampoline_xen_phys_start;
   74.32  extern unsigned char trampoline_cpu_started;
   74.33 +extern char wakeup_start[];
   74.34 +extern unsigned int video_mode, video_flags;
   74.35  #endif
   74.36  
   74.37  #if defined(__x86_64__)
    75.1 --- a/xen/include/asm-x86/desc.h	Wed Jul 11 11:32:30 2007 -0600
    75.2 +++ b/xen/include/asm-x86/desc.h	Thu Jul 12 09:53:58 2007 +0100
    75.3 @@ -203,11 +203,6 @@ extern struct desc_struct compat_gdt_tab
    75.4  # define compat_gdt_table gdt_table
    75.5  #endif
    75.6  
    75.7 -struct Xgt_desc_struct {
    75.8 -    unsigned short size;
    75.9 -    unsigned long address __attribute__((packed));
   75.10 -};
   75.11 -
   75.12  extern void set_intr_gate(unsigned int irq, void * addr);
   75.13  extern void set_system_gate(unsigned int n, void *addr);
   75.14  extern void set_task_gate(unsigned int n, unsigned int sel);
    76.1 --- a/xen/include/asm-x86/hvm/hvm.h	Wed Jul 11 11:32:30 2007 -0600
    76.2 +++ b/xen/include/asm-x86/hvm/hvm.h	Thu Jul 12 09:53:58 2007 +0100
    76.3 @@ -72,11 +72,6 @@ struct hvm_function_table {
    76.4      char *name;
    76.5  
    76.6      /*
    76.7 -     *  Disable HVM functionality
    76.8 -     */
    76.9 -    void (*disable)(void);
   76.10 -
   76.11 -    /*
   76.12       * Initialise/destroy HVM domain/vcpu resources
   76.13       */
   76.14      int  (*domain_initialise)(struct domain *d);
   76.15 @@ -160,6 +155,9 @@ struct hvm_function_table {
   76.16      void (*init_hypercall_page)(struct domain *d, void *hypercall_page);
   76.17  
   76.18      int  (*event_injection_faulted)(struct vcpu *v);
   76.19 +
   76.20 +    void (*suspend_cpu)(void);
   76.21 +    void (*resume_cpu)(void);
   76.22  };
   76.23  
   76.24  extern struct hvm_function_table hvm_funcs;
   76.25 @@ -316,4 +314,16 @@ static inline int hvm_event_injection_fa
   76.26  /* These exceptions must always be intercepted. */
   76.27  #define HVM_TRAP_MASK (1U << TRAP_machine_check)
   76.28  
   76.29 +static inline void hvm_suspend_cpu(void)
   76.30 +{
   76.31 +    if ( hvm_funcs.suspend_cpu )
   76.32 +        hvm_funcs.suspend_cpu();
   76.33 +}
   76.34 +
   76.35 +static inline void hvm_resume_cpu(void)
   76.36 +{
   76.37 +    if ( hvm_funcs.resume_cpu )
   76.38 +        hvm_funcs.resume_cpu();
   76.39 +}
   76.40 +
   76.41  #endif /* __ASM_X86_HVM_HVM_H__ */
    77.1 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Wed Jul 11 11:32:30 2007 -0600
    77.2 +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Jul 12 09:53:58 2007 +0100
    77.3 @@ -28,6 +28,8 @@ extern int start_vmx(void);
    77.4  extern void vmcs_dump_vcpu(void);
    77.5  extern void vmx_init_vmcs_config(void);
    77.6  extern void setup_vmcs_dump(void);
    77.7 +extern void vmx_suspend_cpu(void);
    77.8 +extern void vmx_resume_cpu(void);
    77.9  
   77.10  struct vmcs_struct {
   77.11      u32 vmcs_revision_id;
   77.12 @@ -59,6 +61,7 @@ struct arch_vmx_struct {
   77.13       *  - Activated on a CPU by VMPTRLD. Deactivated by VMCLEAR.
   77.14       *  - Launched on active CPU by VMLAUNCH when current VMCS.
   77.15       */
   77.16 +    struct list_head     active_list;
   77.17      int                  active_cpu;
   77.18      int                  launched;
   77.19  
    78.1 --- a/xen/include/asm-x86/smp.h	Wed Jul 11 11:32:30 2007 -0600
    78.2 +++ b/xen/include/asm-x86/smp.h	Thu Jul 12 09:53:58 2007 +0100
    78.3 @@ -50,9 +50,22 @@ extern u8 x86_cpu_to_apicid[];
    78.4  
    78.5  #define cpu_physical_id(cpu)	x86_cpu_to_apicid[cpu]
    78.6  
    78.7 +/* State of each CPU. */
    78.8 +#define CPU_ONLINE	0x0002	/* CPU is up */
    78.9 +#define CPU_DYING	0x0003	/* CPU is requested to die */
   78.10 +#define CPU_DEAD	0x0004	/* CPU is dead */
   78.11 +DECLARE_PER_CPU(int, cpu_state);
   78.12 +
   78.13  #ifdef CONFIG_HOTPLUG_CPU
   78.14 +#define cpu_is_offline(cpu) unlikely(per_cpu(cpu_state,cpu) == CPU_DYING)
   78.15 +extern int cpu_down(unsigned int cpu);
   78.16 +extern int cpu_up(unsigned int cpu);
   78.17  extern void cpu_exit_clear(void);
   78.18  extern void cpu_uninit(void);
   78.19 +extern void disable_nonboot_cpus(void);
   78.20 +extern void enable_nonboot_cpus(void);
   78.21 +#else
   78.22 +static inline int cpu_is_offline(int cpu) {return 0;}
   78.23  #endif
   78.24  
   78.25  /*
    79.1 --- a/xen/include/asm-x86/system.h	Wed Jul 11 11:32:30 2007 -0600
    79.2 +++ b/xen/include/asm-x86/system.h	Thu Jul 12 09:53:58 2007 +0100
    79.3 @@ -313,6 +313,8 @@ static always_inline unsigned long long 
    79.4  #define __sti()			__asm__ __volatile__("sti": : :"memory")
    79.5  /* used in the idle loop; sti takes one instruction cycle to complete */
    79.6  #define safe_halt()		__asm__ __volatile__("sti; hlt": : :"memory")
    79.7 +/* used when interrupts are already enabled or to shutdown the processor */
    79.8 +#define halt()			__asm__ __volatile__("hlt": : :"memory")
    79.9  
   79.10  /* For spinlocks etc */
   79.11  #if defined(__i386__)
    80.1 --- a/xen/include/asm-x86/xenoprof.h	Wed Jul 11 11:32:30 2007 -0600
    80.2 +++ b/xen/include/asm-x86/xenoprof.h	Thu Jul 12 09:53:58 2007 +0100
    80.3 @@ -23,7 +23,6 @@
    80.4  #ifndef __ASM_X86_XENOPROF_H__
    80.5  #define __ASM_X86_XENOPROF_H__
    80.6  
    80.7 -int nmi_init(int *num_events, int *is_primary, char *cpu_type);
    80.8  int nmi_reserve_counters(void);
    80.9  int nmi_setup_events(void);
   80.10  int nmi_enable_virq(void);
   80.11 @@ -32,8 +31,7 @@ void nmi_stop(void);
   80.12  void nmi_disable_virq(void);
   80.13  void nmi_release_counters(void);
   80.14  
   80.15 -#define xenoprof_arch_init(num_events, is_primary, cpu_type)    \
   80.16 -    nmi_init(num_events, is_primary, cpu_type)
   80.17 +int xenoprof_arch_init(int *num_events, char *cpu_type);
   80.18  #define xenoprof_arch_reserve_counters()        nmi_reserve_counters()
   80.19  #define xenoprof_arch_setup_events()            nmi_setup_events()
   80.20  #define xenoprof_arch_enable_virq()             nmi_enable_virq()
    81.1 --- a/xen/include/public/platform.h	Wed Jul 11 11:32:30 2007 -0600
    81.2 +++ b/xen/include/public/platform.h	Thu Jul 12 09:53:58 2007 +0100
    81.3 @@ -153,6 +153,31 @@ struct xenpf_firmware_info {
    81.4  typedef struct xenpf_firmware_info xenpf_firmware_info_t;
    81.5  DEFINE_XEN_GUEST_HANDLE(xenpf_firmware_info_t);
    81.6  
    81.7 +#define XENPF_set_acpi_sleep      51
    81.8 +struct xenpf_set_acpi_sleep {
    81.9 +    /* IN variables. */
   81.10 +    uint16_t pm1a_cnt_port;
   81.11 +    uint16_t pm1b_cnt_port;
   81.12 +    uint16_t pm1a_evt_port;
   81.13 +    uint16_t pm1b_evt_port;
   81.14 +    /* OUT variables */
   81.15 +    uint64_t xen_waking_vec;   /* Tell dom0 to set FACS waking vector */
   81.16 +};
   81.17 +typedef struct xenpf_set_acpi_sleep xenpf_set_acpi_sleep_t;
   81.18 +DEFINE_XEN_GUEST_HANDLE(xenpf_set_acpi_sleep_t);
   81.19 +
   81.20 +#define XENPF_enter_acpi_sleep    52
   81.21 +struct xenpf_enter_acpi_sleep {
   81.22 +    /* IN variables */
   81.23 +    uint16_t pm1a_cnt_val;
   81.24 +    uint16_t pm1b_cnt_val;
   81.25 +    uint32_t sleep_state;       /* Which state to enter */
   81.26 +    uint32_t video_flags;       /* S3_bios or s3_mode */
   81.27 +    uint32_t video_mode;        /* Mode setting for s3_mode */
   81.28 +};
   81.29 +typedef struct xenpf_enter_acpi_sleep xenpf_enter_acpi_sleep_t;
   81.30 +DEFINE_XEN_GUEST_HANDLE(xenpf_enter_acpi_sleep_t);
   81.31 +
   81.32  struct xen_platform_op {
   81.33      uint32_t cmd;
   81.34      uint32_t interface_version; /* XENPF_INTERFACE_VERSION */
   81.35 @@ -164,6 +189,8 @@ struct xen_platform_op {
   81.36          struct xenpf_microcode_update  microcode;
   81.37          struct xenpf_platform_quirk    platform_quirk;
   81.38          struct xenpf_firmware_info     firmware_info;
   81.39 +        struct xenpf_set_acpi_sleep    set_acpi_sleep;
   81.40 +        struct xenpf_enter_acpi_sleep  enter_acpi_sleep;
   81.41          uint8_t                        pad[128];
   81.42      } u;
   81.43  };
    82.1 --- a/xen/include/public/sysctl.h	Wed Jul 11 11:32:30 2007 -0600
    82.2 +++ b/xen/include/public/sysctl.h	Thu Jul 12 09:53:58 2007 +0100
    82.3 @@ -185,6 +185,18 @@ struct xen_sysctl_getcpuinfo {
    82.4  typedef struct xen_sysctl_getcpuinfo xen_sysctl_getcpuinfo_t;
    82.5  DEFINE_XEN_GUEST_HANDLE(xen_sysctl_getcpuinfo_t); 
    82.6  
    82.7 +#define XEN_SYSCTL_availheap         9
    82.8 +struct xen_sysctl_availheap {
    82.9 +    /* IN variables. */
   82.10 +    uint32_t min_bitwidth;  /* Smallest address width (zero if don't care). */
   82.11 +    uint32_t max_bitwidth;  /* Largest address width (zero if don't care). */
   82.12 +    int32_t  node;          /* NUMA node of interest (-1 for all nodes). */
   82.13 +    /* OUT variables. */
   82.14 +    uint64_t avail_bytes;   /* Bytes available in the specified region. */
   82.15 +};
   82.16 +typedef struct xen_sysctl_availheap xen_sysctl_availheap_t;
   82.17 +DEFINE_XEN_GUEST_HANDLE(xen_sysctl_availheap_t);
   82.18 + 
   82.19  struct xen_sysctl {
   82.20      uint32_t cmd;
   82.21      uint32_t interface_version; /* XEN_SYSCTL_INTERFACE_VERSION */
   82.22 @@ -197,6 +209,7 @@ struct xen_sysctl {
   82.23          struct xen_sysctl_getdomaininfolist getdomaininfolist;
   82.24          struct xen_sysctl_debug_keys        debug_keys;
   82.25          struct xen_sysctl_getcpuinfo        getcpuinfo;
   82.26 +        struct xen_sysctl_availheap         availheap;
   82.27          uint8_t                             pad[128];
   82.28      } u;
   82.29  };
    83.1 --- a/xen/include/xen/irq.h	Wed Jul 11 11:32:30 2007 -0600
    83.2 +++ b/xen/include/xen/irq.h	Thu Jul 12 09:53:58 2007 +0100
    83.3 @@ -57,6 +57,7 @@ typedef struct {
    83.4      struct irqaction *action;	/* IRQ action list */
    83.5      unsigned int depth;		/* nested irq disables */
    83.6      spinlock_t lock;
    83.7 +    cpumask_t affinity;
    83.8  } __cacheline_aligned irq_desc_t;
    83.9  
   83.10  extern irq_desc_t irq_desc[NR_IRQS];
   83.11 @@ -74,4 +75,13 @@ extern int pirq_guest_unmask(struct doma
   83.12  extern int pirq_guest_bind(struct vcpu *v, int irq, int will_share);
   83.13  extern int pirq_guest_unbind(struct domain *d, int irq);
   83.14  
   83.15 +static inline void set_native_irq_info(int irq, cpumask_t mask)
   83.16 +{
   83.17 +	irq_desc[irq].affinity = mask;
   83.18 +}
   83.19 +
   83.20 +static inline void set_irq_info(int irq, cpumask_t mask)
   83.21 +{
   83.22 +	set_native_irq_info(irq, mask);
   83.23 +}
   83.24  #endif /* __XEN_IRQ_H__ */
    84.1 --- a/xen/include/xen/mm.h	Wed Jul 11 11:32:30 2007 -0600
    84.2 +++ b/xen/include/xen/mm.h	Thu Jul 12 09:53:58 2007 +0100
    84.3 @@ -61,6 +61,8 @@ struct page_info *__alloc_domheap_pages(
    84.4      struct domain *d, unsigned int cpu, unsigned int order, 
    84.5      unsigned int memflags);
    84.6  void free_domheap_pages(struct page_info *pg, unsigned int order);
    84.7 +unsigned long avail_domheap_pages_region(
    84.8 +    unsigned int node, unsigned int min_width, unsigned int max_width);
    84.9  unsigned long avail_domheap_pages(void);
   84.10  #define alloc_domheap_page(d) (alloc_domheap_pages(d,0,0))
   84.11  #define free_domheap_page(p)  (free_domheap_pages(p,0))
    85.1 --- a/xen/include/xen/xenoprof.h	Wed Jul 11 11:32:30 2007 -0600
    85.2 +++ b/xen/include/xen/xenoprof.h	Thu Jul 12 09:53:58 2007 +0100
    85.3 @@ -69,6 +69,4 @@ int do_xenoprof_op(int op, XEN_GUEST_HAN
    85.4  int xenoprof_add_trace(struct domain *d, struct vcpu *v, 
    85.5                         unsigned long eip, int mode);
    85.6  
    85.7 -extern struct domain *xenoprof_primary_profiler;
    85.8 -
    85.9  #endif  /* __XEN__XENOPROF_H__ */