ia64/xen-unstable

changeset 7551:eee0489b3a17

merge
author kaf24@firebug.cl.cam.ac.uk
date Sat Oct 29 09:51:35 2005 +0100 (2005-10-29)
parents 7eac3edd0589 8cf7d1d715f4
children 07aa5213d811
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c tools/examples/Makefile tools/python/xen/xend/image.py xen/arch/ia64/xen/domain.c xen/include/public/io/ioreq.h
line diff
     1.1 --- a/extras/mini-os/include/events.h	Mon Oct 24 21:00:35 2005 -0600
     1.2 +++ b/extras/mini-os/include/events.h	Sat Oct 29 09:51:35 2005 +0100
     1.3 @@ -47,7 +47,7 @@ static inline int notify_via_evtchn(int 
     1.4  {
     1.5      evtchn_op_t op;
     1.6      op.cmd = EVTCHNOP_send;
     1.7 -    op.u.send.local_port = port;
     1.8 +    op.u.send.port = port;
     1.9      return HYPERVISOR_event_channel_op(&op);
    1.10  }
    1.11  
     2.1 --- a/extras/mini-os/include/hypervisor.h	Mon Oct 24 21:00:35 2005 -0600
     2.2 +++ b/extras/mini-os/include/hypervisor.h	Sat Oct 29 09:51:35 2005 +0100
     2.3 @@ -14,6 +14,7 @@
     2.4  
     2.5  #include <types.h>
     2.6  #include <xen/xen.h>
     2.7 +#include <xen/dom0_ops.h>
     2.8  
     2.9  /*
    2.10   * a placeholder for the start of day information passed up from the hypervisor
    2.11 @@ -37,548 +38,281 @@ void clear_evtchn(u32 port);
    2.12   * Assembler stubs for hyper-calls.
    2.13   */
    2.14  #if defined(__i386__)
    2.15 +/* Taken from Linux */
    2.16 +
    2.17 +#ifndef __HYPERCALL_H__
    2.18 +#define __HYPERCALL_H__
    2.19 +
    2.20 +#include <xen/sched.h>
    2.21 +
    2.22 +#define _hypercall0(type, name)			\
    2.23 +({						\
    2.24 +	long __res;				\
    2.25 +	asm volatile (				\
    2.26 +		TRAP_INSTR			\
    2.27 +		: "=a" (__res)			\
    2.28 +		: "0" (__HYPERVISOR_##name)	\
    2.29 +		: "memory" );			\
    2.30 +	(type)__res;				\
    2.31 +})
    2.32 +
    2.33 +#define _hypercall1(type, name, a1)				\
    2.34 +({								\
    2.35 +	long __res, __ign1;					\
    2.36 +	asm volatile (						\
    2.37 +		TRAP_INSTR					\
    2.38 +		: "=a" (__res), "=b" (__ign1)			\
    2.39 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1))	\
    2.40 +		: "memory" );					\
    2.41 +	(type)__res;						\
    2.42 +})
    2.43 +
    2.44 +#define _hypercall2(type, name, a1, a2)				\
    2.45 +({								\
    2.46 +	long __res, __ign1, __ign2;				\
    2.47 +	asm volatile (						\
    2.48 +		TRAP_INSTR					\
    2.49 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2)	\
    2.50 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.51 +		"2" ((long)(a2))				\
    2.52 +		: "memory" );					\
    2.53 +	(type)__res;						\
    2.54 +})
    2.55 +
    2.56 +#define _hypercall3(type, name, a1, a2, a3)			\
    2.57 +({								\
    2.58 +	long __res, __ign1, __ign2, __ign3;			\
    2.59 +	asm volatile (						\
    2.60 +		TRAP_INSTR					\
    2.61 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    2.62 +		"=d" (__ign3)					\
    2.63 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.64 +		"2" ((long)(a2)), "3" ((long)(a3))		\
    2.65 +		: "memory" );					\
    2.66 +	(type)__res;						\
    2.67 +})
    2.68 +
    2.69 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
    2.70 +({								\
    2.71 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
    2.72 +	asm volatile (						\
    2.73 +		TRAP_INSTR					\
    2.74 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    2.75 +		"=d" (__ign3), "=S" (__ign4)			\
    2.76 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.77 +		"2" ((long)(a2)), "3" ((long)(a3)),		\
    2.78 +		"4" ((long)(a4))				\
    2.79 +		: "memory" );					\
    2.80 +	(type)__res;						\
    2.81 +})
    2.82 +
    2.83 +#define _hypercall5(type, name, a1, a2, a3, a4, a5)		\
    2.84 +({								\
    2.85 +	long __res, __ign1, __ign2, __ign3, __ign4, __ign5;	\
    2.86 +	asm volatile (						\
    2.87 +		TRAP_INSTR					\
    2.88 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    2.89 +		"=d" (__ign3), "=S" (__ign4), "=D" (__ign5)	\
    2.90 +		: "0" (__HYPERVISOR_##name), "1" ((long)(a1)),	\
    2.91 +		"2" ((long)(a2)), "3" ((long)(a3)),		\
    2.92 +		"4" ((long)(a4)), "5" ((long)(a5))		\
    2.93 +		: "memory" );					\
    2.94 +	(type)__res;						\
    2.95 +})
    2.96 +
    2.97  static inline int
    2.98  HYPERVISOR_set_trap_table(
    2.99 -    trap_info_t *table)
   2.100 +	trap_info_t *table)
   2.101  {
   2.102 -    int ret;
   2.103 -    unsigned long ignore;
   2.104 -
   2.105 -    __asm__ __volatile__ (
   2.106 -        TRAP_INSTR
   2.107 -        : "=a" (ret), "=b" (ignore)
   2.108 -	: "0" (__HYPERVISOR_set_trap_table), "1" (table)
   2.109 -	: "memory" );
   2.110 -
   2.111 -    return ret;
   2.112 +	return _hypercall1(int, set_trap_table, table);
   2.113  }
   2.114  
   2.115  static inline int
   2.116  HYPERVISOR_mmu_update(
   2.117 -    mmu_update_t *req, int count, int *success_count, domid_t domid)
   2.118 +	mmu_update_t *req, int count, int *success_count, domid_t domid)
   2.119  {
   2.120 -    int ret;
   2.121 -    unsigned long ign1, ign2, ign3, ign4;
   2.122 -
   2.123 -    __asm__ __volatile__ (
   2.124 -        TRAP_INSTR
   2.125 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.126 -	: "0" (__HYPERVISOR_mmu_update), "1" (req), "2" (count),
   2.127 -        "3" (success_count), "4" (domid)
   2.128 -	: "memory" );
   2.129 -
   2.130 -    return ret;
   2.131 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   2.132  }
   2.133  
   2.134  static inline int
   2.135  HYPERVISOR_mmuext_op(
   2.136 -    struct mmuext_op *op, int count, int *success_count, domid_t domid)
   2.137 +	struct mmuext_op *op, int count, int *success_count, domid_t domid)
   2.138  {
   2.139 -    int ret;
   2.140 -    unsigned long ign1, ign2, ign3, ign4;
   2.141 -
   2.142 -    __asm__ __volatile__ (
   2.143 -        TRAP_INSTR
   2.144 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.145 -	: "0" (__HYPERVISOR_mmuext_op), "1" (op), "2" (count),
   2.146 -        "3" (success_count), "4" (domid)
   2.147 -	: "memory" );
   2.148 -
   2.149 -    return ret;
   2.150 +	return _hypercall4(int, mmuext_op, op, count, success_count, domid);
   2.151  }
   2.152  
   2.153  static inline int
   2.154  HYPERVISOR_set_gdt(
   2.155 -    unsigned long *frame_list, int entries)
   2.156 +	unsigned long *frame_list, int entries)
   2.157  {
   2.158 -    int ret;
   2.159 -    unsigned long ign1, ign2;
   2.160 -
   2.161 -    __asm__ __volatile__ (
   2.162 -        TRAP_INSTR
   2.163 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.164 -	: "0" (__HYPERVISOR_set_gdt), "1" (frame_list), "2" (entries)
   2.165 -	: "memory" );
   2.166 -
   2.167 -
   2.168 -    return ret;
   2.169 +	return _hypercall2(int, set_gdt, frame_list, entries);
   2.170  }
   2.171  
   2.172  static inline int
   2.173  HYPERVISOR_stack_switch(
   2.174 -    unsigned long ss, unsigned long esp)
   2.175 +	unsigned long ss, unsigned long esp)
   2.176  {
   2.177 -    int ret;
   2.178 -    unsigned long ign1, ign2;
   2.179 -
   2.180 -    __asm__ __volatile__ (
   2.181 -        TRAP_INSTR
   2.182 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.183 -	: "0" (__HYPERVISOR_stack_switch), "1" (ss), "2" (esp)
   2.184 -	: "memory" );
   2.185 -
   2.186 -    return ret;
   2.187 +	return _hypercall2(int, stack_switch, ss, esp);
   2.188  }
   2.189  
   2.190  static inline int
   2.191  HYPERVISOR_set_callbacks(
   2.192 -    unsigned long event_selector, unsigned long event_address,
   2.193 -    unsigned long failsafe_selector, unsigned long failsafe_address)
   2.194 +	unsigned long event_selector, unsigned long event_address,
   2.195 +	unsigned long failsafe_selector, unsigned long failsafe_address)
   2.196  {
   2.197 -    int ret;
   2.198 -    unsigned long ign1, ign2, ign3, ign4;
   2.199 -
   2.200 -    __asm__ __volatile__ (
   2.201 -        TRAP_INSTR
   2.202 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.203 -	: "0" (__HYPERVISOR_set_callbacks), "1" (event_selector),
   2.204 -	  "2" (event_address), "3" (failsafe_selector), "4" (failsafe_address)
   2.205 -	: "memory" );
   2.206 -
   2.207 -    return ret;
   2.208 +	return _hypercall4(int, set_callbacks,
   2.209 +			   event_selector, event_address,
   2.210 +			   failsafe_selector, failsafe_address);
   2.211  }
   2.212  
   2.213  static inline int
   2.214  HYPERVISOR_fpu_taskswitch(
   2.215 -    int set)
   2.216 -{
   2.217 -    int ret;
   2.218 -    unsigned long ign;
   2.219 -
   2.220 -    __asm__ __volatile__ (
   2.221 -        TRAP_INSTR
   2.222 -        : "=a" (ret), "=b" (ign)
   2.223 -        : "0" (__HYPERVISOR_fpu_taskswitch), "1" (set)
   2.224 -        : "memory" );
   2.225 -
   2.226 -    return ret;
   2.227 -}
   2.228 -
   2.229 -static inline int
   2.230 -HYPERVISOR_yield(
   2.231 -    void)
   2.232 +	int set)
   2.233  {
   2.234 -    int ret;
   2.235 -    unsigned long ign;
   2.236 -
   2.237 -    __asm__ __volatile__ (
   2.238 -        TRAP_INSTR
   2.239 -        : "=a" (ret), "=b" (ign)
   2.240 -	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield)
   2.241 -	: "memory", "ecx" );
   2.242 -
   2.243 -    return ret;
   2.244 -}
   2.245 -
   2.246 -static inline int
   2.247 -HYPERVISOR_block(
   2.248 -    void)
   2.249 -{
   2.250 -    int ret;
   2.251 -    unsigned long ign1;
   2.252 -    __asm__ __volatile__ (
   2.253 -        TRAP_INSTR
   2.254 -        : "=a" (ret), "=b" (ign1)
   2.255 -	: "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block)
   2.256 -	: "memory", "ecx" );
   2.257 -
   2.258 -    return ret;
   2.259 +	return _hypercall1(int, fpu_taskswitch, set);
   2.260  }
   2.261  
   2.262  static inline int
   2.263 -HYPERVISOR_shutdown(
   2.264 -    void)
   2.265 -{
   2.266 -    int ret;
   2.267 -    unsigned long ign1;
   2.268 -    __asm__ __volatile__ (
   2.269 -        TRAP_INSTR
   2.270 -        : "=a" (ret), "=b" (ign1)
   2.271 -	: "0" (__HYPERVISOR_sched_op),
   2.272 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift))
   2.273 -        : "memory", "ecx" );
   2.274 -
   2.275 -    return ret;
   2.276 -}
   2.277 -
   2.278 -static inline int
   2.279 -HYPERVISOR_reboot(
   2.280 -    void)
   2.281 +HYPERVISOR_sched_op(
   2.282 +	int cmd, unsigned long arg)
   2.283  {
   2.284 -    int ret;
   2.285 -    unsigned long ign1;
   2.286 -    __asm__ __volatile__ (
   2.287 -        TRAP_INSTR
   2.288 -        : "=a" (ret), "=b" (ign1)
   2.289 -	: "0" (__HYPERVISOR_sched_op),
   2.290 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift))
   2.291 -        : "memory", "ecx" );
   2.292 -
   2.293 -    return ret;
   2.294 -}
   2.295 -
   2.296 -static inline int
   2.297 -HYPERVISOR_suspend(
   2.298 -    unsigned long srec)
   2.299 -{
   2.300 -    int ret;
   2.301 -    unsigned long ign1, ign2;
   2.302 -
   2.303 -    /* NB. On suspend, control software expects a suspend record in %esi. */
   2.304 -    __asm__ __volatile__ (
   2.305 -        TRAP_INSTR
   2.306 -        : "=a" (ret), "=b" (ign1), "=S" (ign2)
   2.307 -	: "0" (__HYPERVISOR_sched_op),
   2.308 -        "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 
   2.309 -        "S" (srec) : "memory", "ecx");
   2.310 -
   2.311 -    return ret;
   2.312 -}
   2.313 -
   2.314 -static inline int
   2.315 -HYPERVISOR_crash(
   2.316 -    void)
   2.317 -{
   2.318 -    int ret;
   2.319 -    unsigned long ign1;
   2.320 -    __asm__ __volatile__ (
   2.321 -        TRAP_INSTR
   2.322 -        : "=a" (ret), "=b" (ign1)
   2.323 -	: "0" (__HYPERVISOR_sched_op),
   2.324 -	  "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift))
   2.325 -        : "memory", "ecx" );
   2.326 -
   2.327 -    return ret;
   2.328 +	return _hypercall2(int, sched_op, cmd, arg);
   2.329  }
   2.330  
   2.331  static inline long
   2.332  HYPERVISOR_set_timer_op(
   2.333 -    u64 timeout)
   2.334 +	u64 timeout)
   2.335  {
   2.336 -    int ret;
   2.337 -    unsigned long timeout_hi = (unsigned long)(timeout>>32);
   2.338 -    unsigned long timeout_lo = (unsigned long)timeout;
   2.339 -    unsigned long ign1, ign2;
   2.340 -
   2.341 -    __asm__ __volatile__ (
   2.342 -        TRAP_INSTR
   2.343 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.344 -	: "0" (__HYPERVISOR_set_timer_op), "b" (timeout_lo), "c" (timeout_hi)
   2.345 -	: "memory");
   2.346 -
   2.347 -    return ret;
   2.348 +	unsigned long timeout_hi = (unsigned long)(timeout>>32);
   2.349 +	unsigned long timeout_lo = (unsigned long)timeout;
   2.350 +	return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
   2.351  }
   2.352  
   2.353 -#if 0
   2.354  static inline int
   2.355  HYPERVISOR_dom0_op(
   2.356 -    dom0_op_t *dom0_op)
   2.357 +	dom0_op_t *dom0_op)
   2.358  {
   2.359 -    int ret;
   2.360 -    unsigned long ign1;
   2.361 -
   2.362 -    dom0_op->interface_version = DOM0_INTERFACE_VERSION;
   2.363 -    __asm__ __volatile__ (
   2.364 -        TRAP_INSTR
   2.365 -        : "=a" (ret), "=b" (ign1)
   2.366 -	: "0" (__HYPERVISOR_dom0_op), "1" (dom0_op)
   2.367 -	: "memory");
   2.368 -
   2.369 -    return ret;
   2.370 +	dom0_op->interface_version = DOM0_INTERFACE_VERSION;
   2.371 +	return _hypercall1(int, dom0_op, dom0_op);
   2.372  }
   2.373 -#endif
   2.374  
   2.375  static inline int
   2.376  HYPERVISOR_set_debugreg(
   2.377 -    int reg, unsigned long value)
   2.378 +	int reg, unsigned long value)
   2.379  {
   2.380 -    int ret;
   2.381 -    unsigned long ign1, ign2;
   2.382 -    __asm__ __volatile__ (
   2.383 -        TRAP_INSTR
   2.384 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.385 -	: "0" (__HYPERVISOR_set_debugreg), "1" (reg), "2" (value)
   2.386 -	: "memory" );
   2.387 -
   2.388 -    return ret;
   2.389 +	return _hypercall2(int, set_debugreg, reg, value);
   2.390  }
   2.391  
   2.392  static inline unsigned long
   2.393  HYPERVISOR_get_debugreg(
   2.394 -    int reg)
   2.395 +	int reg)
   2.396  {
   2.397 -    unsigned long ret;
   2.398 -    unsigned long ign;
   2.399 -    __asm__ __volatile__ (
   2.400 -        TRAP_INSTR
   2.401 -        : "=a" (ret), "=b" (ign)
   2.402 -	: "0" (__HYPERVISOR_get_debugreg), "1" (reg)
   2.403 -	: "memory" );
   2.404 -
   2.405 -    return ret;
   2.406 +	return _hypercall1(unsigned long, get_debugreg, reg);
   2.407  }
   2.408  
   2.409  static inline int
   2.410  HYPERVISOR_update_descriptor(
   2.411 -    u64 ma, u64 desc)
   2.412 +	u64 ma, u64 desc)
   2.413  {
   2.414 -    int ret;
   2.415 -    unsigned long ign1, ign2, ign3, ign4;
   2.416 -
   2.417 -    __asm__ __volatile__ (
   2.418 -        TRAP_INSTR
   2.419 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.420 -	: "0" (__HYPERVISOR_update_descriptor),
   2.421 -	  "1" ((unsigned long)ma), "2" ((unsigned long)(ma>>32)),
   2.422 -	  "3" ((unsigned long)desc), "4" ((unsigned long)(desc>>32))
   2.423 -	: "memory" );
   2.424 -
   2.425 -    return ret;
   2.426 +	return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
   2.427  }
   2.428  
   2.429  static inline int
   2.430 -HYPERVISOR_dom_mem_op(
   2.431 -    unsigned int op, unsigned long *extent_list,
   2.432 -    unsigned long nr_extents, unsigned int extent_order)
   2.433 +HYPERVISOR_memory_op(
   2.434 +	unsigned int cmd, void *arg)
   2.435  {
   2.436 -    int ret;
   2.437 -    unsigned long ign1, ign2, ign3, ign4, ign5;
   2.438 -
   2.439 -    __asm__ __volatile__ (
   2.440 -        TRAP_INSTR
   2.441 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4),
   2.442 -	  "=D" (ign5)
   2.443 -	: "0" (__HYPERVISOR_dom_mem_op), "1" (op), "2" (extent_list),
   2.444 -	  "3" (nr_extents), "4" (extent_order), "5" (DOMID_SELF)
   2.445 -        : "memory" );
   2.446 -
   2.447 -    return ret;
   2.448 +	return _hypercall2(int, memory_op, cmd, arg);
   2.449  }
   2.450  
   2.451  static inline int
   2.452  HYPERVISOR_multicall(
   2.453 -    void *call_list, int nr_calls)
   2.454 +	void *call_list, int nr_calls)
   2.455  {
   2.456 -    int ret;
   2.457 -    unsigned long ign1, ign2;
   2.458 -
   2.459 -    __asm__ __volatile__ (
   2.460 -        TRAP_INSTR
   2.461 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.462 -	: "0" (__HYPERVISOR_multicall), "1" (call_list), "2" (nr_calls)
   2.463 -	: "memory" );
   2.464 -
   2.465 -    return ret;
   2.466 +	return _hypercall2(int, multicall, call_list, nr_calls);
   2.467  }
   2.468  
   2.469  static inline int
   2.470  HYPERVISOR_update_va_mapping(
   2.471 -    unsigned long va, pte_t new_val, unsigned long flags)
   2.472 +	unsigned long va, pte_t new_val, unsigned long flags)
   2.473  {
   2.474 -    int ret;
   2.475 -    unsigned long ign1, ign2, ign3, ign4;
   2.476 -
   2.477 -    __asm__ __volatile__ (
   2.478 -        TRAP_INSTR
   2.479 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4)
   2.480 -	: "0" (__HYPERVISOR_update_va_mapping), 
   2.481 -          "1" (va), "2" ((new_val).pte_low),
   2.482 +	unsigned long pte_hi = 0;
   2.483  #ifdef CONFIG_X86_PAE
   2.484 -	  "3" ((new_val).pte_high),
   2.485 -#else
   2.486 -	  "3" (0),
   2.487 +	pte_hi = new_val.pte_high;
   2.488  #endif
   2.489 -	  "4" (flags)
   2.490 -	: "memory" );
   2.491 -
   2.492 -    return ret;
   2.493 +	return _hypercall4(int, update_va_mapping, va,
   2.494 +			   new_val.pte_low, pte_hi, flags);
   2.495  }
   2.496  
   2.497  static inline int
   2.498  HYPERVISOR_event_channel_op(
   2.499 -    void *op)
   2.500 +	void *op)
   2.501  {
   2.502 -    int ret;
   2.503 -    unsigned long ignore;
   2.504 -    __asm__ __volatile__ (
   2.505 -        TRAP_INSTR
   2.506 -        : "=a" (ret), "=b" (ignore)
   2.507 -	: "0" (__HYPERVISOR_event_channel_op), "1" (op)
   2.508 -	: "memory" );
   2.509 -
   2.510 -    return ret;
   2.511 +	return _hypercall1(int, event_channel_op, op);
   2.512  }
   2.513  
   2.514  static inline int
   2.515  HYPERVISOR_xen_version(
   2.516 -    int cmd, void *arg)
   2.517 +	int cmd, void *arg)
   2.518  {
   2.519 -    int ret;
   2.520 -    unsigned long ignore, ign2;
   2.521 -
   2.522 -    __asm__ __volatile__ (
   2.523 -        TRAP_INSTR
   2.524 -        : "=a" (ret), "=b" (ignore), "=c" (ign2)
   2.525 -	: "0" (__HYPERVISOR_xen_version), "1" (cmd), "2" (arg)
   2.526 -	: "memory" );
   2.527 -
   2.528 -    return ret;
   2.529 +	return _hypercall2(int, xen_version, cmd, arg);
   2.530  }
   2.531  
   2.532  static inline int
   2.533  HYPERVISOR_console_io(
   2.534 -    int cmd, int count, char *str)
   2.535 +	int cmd, int count, char *str)
   2.536  {
   2.537 -    int ret;
   2.538 -    unsigned long ign1, ign2, ign3;
   2.539 -    __asm__ __volatile__ (
   2.540 -        TRAP_INSTR
   2.541 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
   2.542 -	: "0" (__HYPERVISOR_console_io), "1" (cmd), "2" (count), "3" (str)
   2.543 -	: "memory" );
   2.544 -
   2.545 -    return ret;
   2.546 +	return _hypercall3(int, console_io, cmd, count, str);
   2.547  }
   2.548  
   2.549  static inline int
   2.550  HYPERVISOR_physdev_op(
   2.551 -    void *physdev_op)
   2.552 +	void *physdev_op)
   2.553  {
   2.554 -    int ret;
   2.555 -    unsigned long ign;
   2.556 -
   2.557 -    __asm__ __volatile__ (
   2.558 -        TRAP_INSTR
   2.559 -        : "=a" (ret), "=b" (ign)
   2.560 -	: "0" (__HYPERVISOR_physdev_op), "1" (physdev_op)
   2.561 -	: "memory" );
   2.562 -
   2.563 -    return ret;
   2.564 +	return _hypercall1(int, physdev_op, physdev_op);
   2.565  }
   2.566  
   2.567  static inline int
   2.568  HYPERVISOR_grant_table_op(
   2.569 -    unsigned int cmd, void *uop, unsigned int count)
   2.570 +	unsigned int cmd, void *uop, unsigned int count)
   2.571  {
   2.572 -    int ret;
   2.573 -    unsigned long ign1, ign2, ign3;
   2.574 -
   2.575 -    __asm__ __volatile__ (
   2.576 -        TRAP_INSTR
   2.577 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3)
   2.578 -	: "0" (__HYPERVISOR_grant_table_op), "1" (cmd), "2" (uop), "3" (count)
   2.579 -	: "memory" );
   2.580 -
   2.581 -    return ret;
   2.582 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   2.583  }
   2.584  
   2.585  static inline int
   2.586  HYPERVISOR_update_va_mapping_otherdomain(
   2.587 -    unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
   2.588 +	unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
   2.589  {
   2.590 -    int ret;
   2.591 -    unsigned long ign1, ign2, ign3, ign4, ign5;
   2.592 -
   2.593 -    __asm__ __volatile__ (
   2.594 -        TRAP_INSTR
   2.595 -        : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3),
   2.596 -	  "=S" (ign4), "=D" (ign5)
   2.597 -	: "0" (__HYPERVISOR_update_va_mapping_otherdomain),
   2.598 -          "1" (va), "2" ((new_val).pte_low),
   2.599 +	unsigned long pte_hi = 0;
   2.600  #ifdef CONFIG_X86_PAE
   2.601 -	  "3" ((new_val).pte_high),
   2.602 -#else
   2.603 -	  "3" (0),
   2.604 +	pte_hi = new_val.pte_high;
   2.605  #endif
   2.606 -	  "4" (flags), "5" (domid) :
   2.607 -        "memory" );
   2.608 -    
   2.609 -    return ret;
   2.610 +	return _hypercall5(int, update_va_mapping_otherdomain, va,
   2.611 +			   new_val.pte_low, pte_hi, flags, domid);
   2.612  }
   2.613  
   2.614  static inline int
   2.615  HYPERVISOR_vm_assist(
   2.616 -    unsigned int cmd, unsigned int type)
   2.617 +	unsigned int cmd, unsigned int type)
   2.618  {
   2.619 -    int ret;
   2.620 -    unsigned long ign1, ign2;
   2.621 -
   2.622 -    __asm__ __volatile__ (
   2.623 -        TRAP_INSTR
   2.624 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.625 -	: "0" (__HYPERVISOR_vm_assist), "1" (cmd), "2" (type)
   2.626 -	: "memory" );
   2.627 -
   2.628 -    return ret;
   2.629 -}
   2.630 -
   2.631 -static inline int
   2.632 -HYPERVISOR_boot_vcpu(
   2.633 -    unsigned long vcpu, vcpu_guest_context_t *ctxt)
   2.634 -{
   2.635 -    int ret;
   2.636 -    unsigned long ign1, ign2;
   2.637 -
   2.638 -    __asm__ __volatile__ (
   2.639 -        TRAP_INSTR
   2.640 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.641 -	: "0" (__HYPERVISOR_boot_vcpu), "1" (vcpu), "2" (ctxt)
   2.642 -	: "memory");
   2.643 -
   2.644 -    return ret;
   2.645 +	return _hypercall2(int, vm_assist, cmd, type);
   2.646  }
   2.647  
   2.648  static inline int
   2.649 -HYPERVISOR_vcpu_down(
   2.650 -    int vcpu)
   2.651 +HYPERVISOR_vcpu_op(
   2.652 +	int cmd, int vcpuid, void *extra_args)
   2.653  {
   2.654 -    int ret;
   2.655 -    unsigned long ign1;
   2.656 -    /* Yes, I really do want to clobber edx here: when we resume a
   2.657 -       vcpu after unpickling a multi-processor domain, it returns
   2.658 -       here, but clobbers all of the call clobbered registers. */
   2.659 -    __asm__ __volatile__ (
   2.660 -        TRAP_INSTR
   2.661 -        : "=a" (ret), "=b" (ign1)
   2.662 -	: "0" (__HYPERVISOR_sched_op),
   2.663 -	  "1" (SCHEDOP_vcpu_down | (vcpu << SCHEDOP_vcpushift))
   2.664 -        : "memory", "ecx", "edx" );
   2.665 -
   2.666 -    return ret;
   2.667 +	return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
   2.668  }
   2.669  
   2.670  static inline int
   2.671 -HYPERVISOR_vcpu_up(
   2.672 -    int vcpu)
   2.673 +HYPERVISOR_suspend(
   2.674 +	unsigned long srec)
   2.675  {
   2.676 -    int ret;
   2.677 -    unsigned long ign1;
   2.678 -    __asm__ __volatile__ (
   2.679 -        TRAP_INSTR
   2.680 -        : "=a" (ret), "=b" (ign1)
   2.681 -	: "0" (__HYPERVISOR_sched_op),
   2.682 -	  "1" (SCHEDOP_vcpu_up | (vcpu << SCHEDOP_vcpushift))
   2.683 -        : "memory", "ecx" );
   2.684 -
   2.685 -    return ret;
   2.686 +	return _hypercall3(int, sched_op, SCHEDOP_shutdown,
   2.687 +			   SHUTDOWN_suspend, srec);
   2.688  }
   2.689  
   2.690 -static inline int
   2.691 -HYPERVISOR_vcpu_pickle(
   2.692 -    int vcpu, vcpu_guest_context_t *ctxt)
   2.693 -{
   2.694 -    int ret;
   2.695 -    unsigned long ign1, ign2;
   2.696 -    __asm__ __volatile__ (
   2.697 -        TRAP_INSTR
   2.698 -        : "=a" (ret), "=b" (ign1), "=c" (ign2)
   2.699 -	: "0" (__HYPERVISOR_sched_op),
   2.700 -	  "1" (SCHEDOP_vcpu_pickle | (vcpu << SCHEDOP_vcpushift)),
   2.701 -	  "2" (ctxt)
   2.702 -        : "memory" );
   2.703 -
   2.704 -    return ret;
   2.705 -}
   2.706 +#endif /* __HYPERCALL_H__ */
   2.707  #elif defined(__x86_64__)
   2.708  
   2.709  #define __syscall_clobber "r11","rcx","memory"
   2.710 @@ -792,106 +526,4 @@ HYPERVISOR_set_timer_op(
   2.711  }
   2.712  #endif
   2.713  
   2.714 -
   2.715 -static __inline__ int HYPERVISOR_dom0_op(void *dom0_op)
   2.716 -{
   2.717 -    int ret;
   2.718 -    __asm__ __volatile__ (
   2.719 -        TRAP_INSTR
   2.720 -        : "=a" (ret) : "0" (__HYPERVISOR_dom0_op),
   2.721 -        _a1 (dom0_op) : "memory" );
   2.722 -
   2.723 -    return ret;
   2.724 -}
   2.725 -
   2.726 -static __inline__ int HYPERVISOR_set_debugreg(int reg, unsigned long value)
   2.727 -{
   2.728 -    int ret;
   2.729 -    __asm__ __volatile__ (
   2.730 -        TRAP_INSTR
   2.731 -        : "=a" (ret) : "0" (__HYPERVISOR_set_debugreg),
   2.732 -        _a1 (reg), _a2 (value) : "memory" );
   2.733 -
   2.734 -    return ret;
   2.735 -}
   2.736 -
   2.737 -static __inline__ unsigned long HYPERVISOR_get_debugreg(int reg)
   2.738 -{
   2.739 -    unsigned long ret;
   2.740 -    __asm__ __volatile__ (
   2.741 -        TRAP_INSTR
   2.742 -        : "=a" (ret) : "0" (__HYPERVISOR_get_debugreg),
   2.743 -        _a1 (reg) : "memory" );
   2.744 -
   2.745 -    return ret;
   2.746 -}
   2.747 -
   2.748 -static __inline__ int HYPERVISOR_update_descriptor(
   2.749 -    unsigned long pa, unsigned long word1, unsigned long word2)
   2.750 -{
   2.751 -    int ret;
   2.752 -    __asm__ __volatile__ (
   2.753 -        TRAP_INSTR
   2.754 -        : "=a" (ret) : "0" (__HYPERVISOR_update_descriptor), 
   2.755 -        _a1 (pa), _a2 (word1), _a3 (word2) : "memory" );
   2.756 -
   2.757 -    return ret;
   2.758 -}
   2.759 -
   2.760 -static __inline__ int HYPERVISOR_dom_mem_op(void *dom_mem_op)
   2.761 -{
   2.762 -    int ret;
   2.763 -    __asm__ __volatile__ (
   2.764 -        TRAP_INSTR
   2.765 -        : "=a" (ret) : "0" (__HYPERVISOR_memory_op),
   2.766 -        _a1 (dom_mem_op) : "memory" );
   2.767 -
   2.768 -    return ret;
   2.769 -}
   2.770 -
   2.771 -static __inline__ int HYPERVISOR_multicall(void *call_list, int nr_calls)
   2.772 -{
   2.773 -    int ret;
   2.774 -    __asm__ __volatile__ (
   2.775 -        TRAP_INSTR
   2.776 -        : "=a" (ret) : "0" (__HYPERVISOR_multicall),
   2.777 -        _a1 (call_list), _a2 (nr_calls) : "memory" );
   2.778 -
   2.779 -    return ret;
   2.780 -}
   2.781 -
   2.782 -static __inline__ int HYPERVISOR_update_va_mapping(
   2.783 -    unsigned long page_nr, unsigned long new_val, unsigned long flags)
   2.784 -{
   2.785 -    int ret;
   2.786 -    __asm__ __volatile__ (
   2.787 -        TRAP_INSTR
   2.788 -        : "=a" (ret) : "0" (__HYPERVISOR_update_va_mapping), 
   2.789 -        _a1 (page_nr), _a2 (new_val), _a3 (flags) : "memory" );
   2.790 -
   2.791 -    return ret;
   2.792 -}
   2.793 -
   2.794 -static __inline__ int HYPERVISOR_xen_version(int cmd)
   2.795 -{
   2.796 -    int ret;
   2.797 -    __asm__ __volatile__ (
   2.798 -        TRAP_INSTR
   2.799 -        : "=a" (ret) : "0" (__HYPERVISOR_xen_version), 
   2.800 -        _a1 (cmd) : "memory" );
   2.801 -
   2.802 -    return ret;
   2.803 -}
   2.804 -
   2.805 -static __inline__ int HYPERVISOR_console_io(int cmd, int count, char *str)
   2.806 -{
   2.807 -    int ret;
   2.808 -    __asm__ __volatile__ (
   2.809 -        TRAP_INSTR
   2.810 -        : "=a" (ret) : "0" (__HYPERVISOR_console_io),
   2.811 -        _a1 (cmd), _a2 (count), _a3 (str) : "memory" );
   2.812 -
   2.813 -    return ret;
   2.814 -}
   2.815 -
   2.816  #endif /* __HYPERVISOR_H__ */
     3.1 --- a/extras/mini-os/include/os.h	Mon Oct 24 21:00:35 2005 -0600
     3.2 +++ b/extras/mini-os/include/os.h	Sat Oct 29 09:51:35 2005 +0100
     3.3 @@ -24,7 +24,7 @@
     3.4  #include <xen/xen.h>
     3.5  
     3.6  
     3.7 -#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0))
     3.8 +#define force_evtchn_callback() ((void)HYPERVISOR_xen_version(0, 0))
     3.9  
    3.10  #define __KERNEL_CS  FLAT_KERNEL_CS
    3.11  #define __KERNEL_DS  FLAT_KERNEL_DS
    3.12 @@ -55,6 +55,8 @@
    3.13  /* Everything below this point is not included by assembler (.S) files. */
    3.14  #ifndef __ASSEMBLY__
    3.15  
    3.16 +extern shared_info_t *HYPERVISOR_shared_info;
    3.17 +
    3.18  void trap_init(void);
    3.19  
    3.20  /* 
     4.1 --- a/extras/mini-os/include/types.h	Mon Oct 24 21:00:35 2005 -0600
     4.2 +++ b/extras/mini-os/include/types.h	Sat Oct 29 09:51:35 2005 +0100
     4.3 @@ -54,7 +54,14 @@ typedef unsigned long       uintptr_t;
     4.4  typedef struct { unsigned long pte; } pte_t;
     4.5  #endif
     4.6  
     4.7 -
     4.8 +typedef  u8 uint8_t;
     4.9 +typedef  s8 int8_t;
    4.10 +typedef u16 uint16_t;
    4.11 +typedef s16 int16_t;
    4.12 +typedef u32 uint32_t;
    4.13 +typedef s32 int32_t;
    4.14 +typedef u64 uint64_t;
    4.15 +typedef s64 int64_t;
    4.16  
    4.17  
    4.18  #define INT_MAX         ((int)(~0U>>1))
     5.1 --- a/extras/mini-os/kernel.c	Mon Oct 24 21:00:35 2005 -0600
     5.2 +++ b/extras/mini-os/kernel.c	Sat Oct 29 09:51:35 2005 +0100
     5.3 @@ -61,7 +61,7 @@ void failsafe_callback(void);
     5.4  
     5.5  extern char shared_info[PAGE_SIZE];
     5.6  
     5.7 -#define __pte(x) ((pte_t) { (0) } )
     5.8 +#define __pte(x) ((pte_t) { (x) } )
     5.9  
    5.10  static shared_info_t *map_shared_info(unsigned long pa)
    5.11  {
    5.12 @@ -150,5 +150,5 @@ void start_kernel(start_info_t *si)
    5.13  void do_exit(void)
    5.14  {
    5.15      printk("do_exit called!\n");
    5.16 -    for ( ;; ) HYPERVISOR_shutdown();
    5.17 +    for ( ;; ) HYPERVISOR_sched_op(SCHEDOP_shutdown, SHUTDOWN_crash);
    5.18  }
     6.1 --- a/extras/mini-os/time.c	Mon Oct 24 21:00:35 2005 -0600
     6.2 +++ b/extras/mini-os/time.c	Sat Oct 29 09:51:35 2005 +0100
     6.3 @@ -208,7 +208,7 @@ void block_domain(u32 millisecs)
     6.4      struct timeval tv;
     6.5      gettimeofday(&tv);
     6.6      HYPERVISOR_set_timer_op(monotonic_clock() + 1000000LL * (s64) millisecs);
     6.7 -    HYPERVISOR_block();
     6.8 +    HYPERVISOR_sched_op(SCHEDOP_block, 0);
     6.9  }
    6.10  
    6.11  
     7.1 --- a/extras/mini-os/xenbus/xenbus_xs.c	Mon Oct 24 21:00:35 2005 -0600
     7.2 +++ b/extras/mini-os/xenbus/xenbus_xs.c	Sat Oct 29 09:51:35 2005 +0100
     7.3 @@ -39,7 +39,7 @@
     7.4  #include <wait.h>
     7.5  #include <sched.h>
     7.6  #include <semaphore.h>
     7.7 -#include "xenstored.h"
     7.8 +#include <xen/io/xs_wire.h>
     7.9  #include "xenbus_comms.h"
    7.10  
    7.11  #define streq(a, b) (strcmp((a), (b)) == 0)
    7.12 @@ -408,7 +408,12 @@ static char *xs_read_watch(char **token)
    7.13  
    7.14  static int xs_acknowledge_watch(const char *token)
    7.15  {
    7.16 +#if 0
    7.17  	return xs_error(xs_single(XS_WATCH_ACK, token, NULL));
    7.18 +#else
    7.19 +	/* XS_WATCH_ACK is no longer available */
    7.20 +	return 0;
    7.21 +#endif
    7.22  }
    7.23  
    7.24  static int xs_unwatch(const char *path, const char *token)
     8.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Mon Oct 24 21:00:35 2005 -0600
     8.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Sat Oct 29 09:51:35 2005 +0100
     8.3 @@ -733,6 +733,7 @@ void __init setup_arch(char **cmdline_p)
     8.4  #ifdef CONFIG_XEN
     8.5  	{
     8.6  		int i, j, k, fpp;
     8.7 +		unsigned long va;
     8.8  
     8.9  		/* Make sure we have a large enough P->M table. */
    8.10  		phys_to_machine_mapping = alloc_bootmem(
    8.11 @@ -746,9 +747,21 @@ void __init setup_arch(char **cmdline_p)
    8.12  			__pa(xen_start_info->mfn_list), 
    8.13  			PFN_PHYS(PFN_UP(xen_start_info->nr_pages *
    8.14  					sizeof(unsigned long))));
    8.15 -		make_pages_readonly((void *)xen_start_info->mfn_list,
    8.16 -				    PFN_UP(xen_start_info->nr_pages *
    8.17 -					   sizeof(unsigned long)));
    8.18 +
    8.19 +		/* 'Initial mapping' of old p2m table must be destroyed. */
    8.20 +		for (va = xen_start_info->mfn_list;
    8.21 +		     va < (xen_start_info->mfn_list +
    8.22 +			   (xen_start_info->nr_pages*sizeof(unsigned long)));
    8.23 +		     va += PAGE_SIZE) {
    8.24 +			HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
    8.25 +		}
    8.26 +
    8.27 +		/* 'Initial mapping' of initrd must be destroyed. */
    8.28 +		for (va = xen_start_info->mod_start;
    8.29 +		     va < (xen_start_info->mod_start+xen_start_info->mod_len);
    8.30 +		     va += PAGE_SIZE) {
    8.31 +			HYPERVISOR_update_va_mapping(va, __pte_ma(0), 0);
    8.32 +		}
    8.33  
    8.34  		/* 
    8.35  		 * Initialise the list of the frames that specify the list of 
     9.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Mon Oct 24 21:00:35 2005 -0600
     9.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Sat Oct 29 09:51:35 2005 +0100
     9.3 @@ -5,7 +5,7 @@
     9.4  #define evtchn_upcall_pending		0
     9.5  #define evtchn_upcall_mask		1
     9.6  
     9.7 -#define sizeof_vcpu_shift		3
     9.8 +#define sizeof_vcpu_shift		4
     9.9  
    9.10  #ifdef CONFIG_SMP
    9.11  //#define preempt_disable(reg)	incl threadinfo_preempt_count(reg)
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Mon Oct 24 21:00:35 2005 -0600
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Sat Oct 29 09:51:35 2005 +0100
    10.3 @@ -70,6 +70,9 @@ spinlock_t balloon_lock = SPIN_LOCK_UNLO
    10.4  static unsigned long current_pages;
    10.5  static unsigned long target_pages;
    10.6  
    10.7 +/* VM /proc information for memory */
    10.8 +extern unsigned long totalram_pages;
    10.9 +
   10.10  /* We may hit the hard limit in Xen. If we do then we remember it. */
   10.11  static unsigned long hard_limit;
   10.12  
   10.13 @@ -188,12 +191,13 @@ static int increase_reservation(unsigned
   10.14  	rc = HYPERVISOR_memory_op(
   10.15  		XENMEM_increase_reservation, &reservation);
   10.16  	if (rc < nr_pages) {
   10.17 +		int ret;
   10.18  		/* We hit the Xen hard limit: reprobe. */
   10.19  		reservation.extent_start = mfn_list;
   10.20  		reservation.nr_extents   = rc;
   10.21 -		BUG_ON(HYPERVISOR_memory_op(
   10.22 -			XENMEM_decrease_reservation,
   10.23 -			&reservation) != rc);
   10.24 +		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   10.25 +				&reservation);
   10.26 +		BUG_ON(ret != rc);
   10.27  		hard_limit = current_pages + rc - driver_pages;
   10.28  		goto out;
   10.29  	}
   10.30 @@ -210,11 +214,14 @@ static int increase_reservation(unsigned
   10.31  		xen_machphys_update(mfn_list[i], pfn);
   10.32              
   10.33  		/* Link back into the page tables if not highmem. */
   10.34 -		if (pfn < max_low_pfn)
   10.35 -			BUG_ON(HYPERVISOR_update_va_mapping(
   10.36 +		if (pfn < max_low_pfn) {
   10.37 +			int ret;
   10.38 +			ret = HYPERVISOR_update_va_mapping(
   10.39  				(unsigned long)__va(pfn << PAGE_SHIFT),
   10.40  				pfn_pte_ma(mfn_list[i], PAGE_KERNEL),
   10.41 -				0));
   10.42 +				0);
   10.43 +			BUG_ON(ret);
   10.44 +		}
   10.45  
   10.46  		/* Relinquish the page back to the allocator. */
   10.47  		ClearPageReserved(page);
   10.48 @@ -223,6 +230,7 @@ static int increase_reservation(unsigned
   10.49  	}
   10.50  
   10.51  	current_pages += nr_pages;
   10.52 +	totalram_pages = current_pages;
   10.53  
   10.54   out:
   10.55  	balloon_unlock(flags);
   10.56 @@ -238,6 +246,7 @@ static int decrease_reservation(unsigned
   10.57  	struct page   *page;
   10.58  	void          *v;
   10.59  	int            need_sleep = 0;
   10.60 +	int ret;
   10.61  	struct xen_memory_reservation reservation = {
   10.62  		.address_bits = 0,
   10.63  		.extent_order = 0,
   10.64 @@ -264,8 +273,9 @@ static int decrease_reservation(unsigned
   10.65  		if (!PageHighMem(page)) {
   10.66  			v = phys_to_virt(pfn << PAGE_SHIFT);
   10.67  			scrub_pages(v, 1);
   10.68 -			BUG_ON(HYPERVISOR_update_va_mapping(
   10.69 -				(unsigned long)v, __pte_ma(0), 0));
   10.70 +			ret = HYPERVISOR_update_va_mapping(
   10.71 +				(unsigned long)v, __pte_ma(0), 0);
   10.72 +			BUG_ON(ret);
   10.73  		}
   10.74  #ifdef CONFIG_XEN_SCRUB_PAGES
   10.75  		else {
   10.76 @@ -291,10 +301,11 @@ static int decrease_reservation(unsigned
   10.77  
   10.78  	reservation.extent_start = mfn_list;
   10.79  	reservation.nr_extents   = nr_pages;
   10.80 -	BUG_ON(HYPERVISOR_memory_op(
   10.81 -		XENMEM_decrease_reservation, &reservation) != nr_pages);
   10.82 +	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   10.83 +	BUG_ON(ret != nr_pages);
   10.84  
   10.85  	current_pages -= nr_pages;
   10.86 +	totalram_pages = current_pages;
   10.87  
   10.88  	balloon_unlock(flags);
   10.89  
   10.90 @@ -496,6 +507,7 @@ static int dealloc_pte_fn(
   10.91  	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
   10.92  {
   10.93  	unsigned long mfn = pte_mfn(*pte);
   10.94 +	int ret;
   10.95  	struct xen_memory_reservation reservation = {
   10.96  		.extent_start = &mfn,
   10.97  		.nr_extents   = 1,
   10.98 @@ -505,8 +517,8 @@ static int dealloc_pte_fn(
   10.99  	set_pte_at(&init_mm, addr, pte, __pte_ma(0));
  10.100  	phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] =
  10.101  		INVALID_P2M_ENTRY;
  10.102 -	BUG_ON(HYPERVISOR_memory_op(
  10.103 -		XENMEM_decrease_reservation, &reservation) != 1);
  10.104 +	ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
  10.105 +	BUG_ON(ret != 1);
  10.106  	return 0;
  10.107  }
  10.108  
  10.109 @@ -514,6 +526,7 @@ struct page *balloon_alloc_empty_page_ra
  10.110  {
  10.111  	unsigned long vstart, flags;
  10.112  	unsigned int  order = get_order(nr_pages * PAGE_SIZE);
  10.113 +	int ret;
  10.114  
  10.115  	vstart = __get_free_pages(GFP_KERNEL, order);
  10.116  	if (vstart == 0)
  10.117 @@ -522,8 +535,9 @@ struct page *balloon_alloc_empty_page_ra
  10.118  	scrub_pages(vstart, 1 << order);
  10.119  
  10.120  	balloon_lock(flags);
  10.121 -	BUG_ON(generic_page_range(
  10.122 -		&init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL));
  10.123 +	ret = generic_page_range(
  10.124 +		&init_mm, vstart, PAGE_SIZE << order, dealloc_pte_fn, NULL);
  10.125 +	BUG_ON(ret);
  10.126  	current_pages -= 1UL << order;
  10.127  	balloon_unlock(flags);
  10.128  
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Mon Oct 24 21:00:35 2005 -0600
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c	Sat Oct 29 09:51:35 2005 +0100
    11.3 @@ -108,6 +108,7 @@ static void fast_flush_area(int idx, int
    11.4  	struct gnttab_unmap_grant_ref unmap[BLKIF_MAX_SEGMENTS_PER_REQUEST];
    11.5  	unsigned int i, invcount = 0;
    11.6  	u16 handle;
    11.7 +	int ret;
    11.8  
    11.9  	for (i = 0; i < nr_pages; i++) {
   11.10  		handle = pending_handle(idx, i);
   11.11 @@ -120,8 +121,9 @@ static void fast_flush_area(int idx, int
   11.12  		invcount++;
   11.13  	}
   11.14  
   11.15 -	BUG_ON(HYPERVISOR_grant_table_op(
   11.16 -		GNTTABOP_unmap_grant_ref, unmap, invcount));
   11.17 +	ret = HYPERVISOR_grant_table_op(
   11.18 +		GNTTABOP_unmap_grant_ref, unmap, invcount);
   11.19 +	BUG_ON(ret);
   11.20  }
   11.21  
   11.22  
   11.23 @@ -338,6 +340,7 @@ static void dispatch_rw_block_io(blkif_t
   11.24  	struct bio *bio = NULL, *biolist[BLKIF_MAX_SEGMENTS_PER_REQUEST];
   11.25  	int nbio = 0;
   11.26  	request_queue_t *q;
   11.27 +	int ret;
   11.28  
   11.29  	/* Check that number of segments is sane. */
   11.30  	nseg = req->nr_segments;
   11.31 @@ -367,8 +370,8 @@ static void dispatch_rw_block_io(blkif_t
   11.32  			map[i].flags |= GNTMAP_readonly;
   11.33  	}
   11.34  
   11.35 -	BUG_ON(HYPERVISOR_grant_table_op(
   11.36 -		GNTTABOP_map_grant_ref, map, nseg));
   11.37 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, nseg);
   11.38 +	BUG_ON(ret);
   11.39  
   11.40  	for (i = 0; i < nseg; i++) {
   11.41  		if (unlikely(map[i].handle < 0)) {
   11.42 @@ -493,6 +496,7 @@ static int __init blkif_init(void)
   11.43  {
   11.44  	int i;
   11.45  	struct page *page;
   11.46 +	int ret;
   11.47  
   11.48  	blkif_interface_init();
   11.49  
   11.50 @@ -509,7 +513,8 @@ static int __init blkif_init(void)
   11.51  	spin_lock_init(&blkio_schedule_list_lock);
   11.52  	INIT_LIST_HEAD(&blkio_schedule_list);
   11.53  
   11.54 -	BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
   11.55 +	ret = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
   11.56 +	BUG_ON(ret < 0);
   11.57  
   11.58  	blkif_xenbus_init();
   11.59  
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Mon Oct 24 21:00:35 2005 -0600
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Sat Oct 29 09:51:35 2005 +0100
    12.3 @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid)
    12.4  static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    12.5  {
    12.6  	struct gnttab_map_grant_ref op;
    12.7 +	int ret;
    12.8  
    12.9  	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
   12.10  	op.flags     = GNTMAP_host_map;
   12.11 @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *bl
   12.12  	op.dom       = blkif->domid;
   12.13  
   12.14  	lock_vm_area(blkif->blk_ring_area);
   12.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   12.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   12.17  	unlock_vm_area(blkif->blk_ring_area);
   12.18 +	BUG_ON(ret);
   12.19  
   12.20  	if (op.handle < 0) {
   12.21  		DPRINTK(" Grant table operation failure !\n");
   12.22 @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *bl
   12.23  static void unmap_frontend_page(blkif_t *blkif)
   12.24  {
   12.25  	struct gnttab_unmap_grant_ref op;
   12.26 +	int ret;
   12.27  
   12.28  	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   12.29  	op.handle       = blkif->shmem_handle;
   12.30  	op.dev_bus_addr = 0;
   12.31  
   12.32  	lock_vm_area(blkif->blk_ring_area);
   12.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   12.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   12.35  	unlock_vm_area(blkif->blk_ring_area);
   12.36 +	BUG_ON(ret);
   12.37  }
   12.38  
   12.39  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Mon Oct 24 21:00:35 2005 -0600
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c	Sat Oct 29 09:51:35 2005 +0100
    13.3 @@ -305,6 +305,7 @@ static irqreturn_t blkif_int(int irq, vo
    13.4  
    13.5  	for (i = info->ring.rsp_cons; i != rp; i++) {
    13.6  		unsigned long id;
    13.7 +		int ret;
    13.8  
    13.9  		bret = RING_GET_RESPONSE(&info->ring, i);
   13.10  		id   = bret->id;
   13.11 @@ -321,9 +322,10 @@ static irqreturn_t blkif_int(int irq, vo
   13.12  				DPRINTK("Bad return from blkdev data "
   13.13  					"request: %x\n", bret->status);
   13.14  
   13.15 -			BUG_ON(end_that_request_first(
   13.16 +			ret = end_that_request_first(
   13.17  				req, (bret->status == BLKIF_RSP_OKAY),
   13.18 -				req->hard_nr_sectors));
   13.19 +				req->hard_nr_sectors);
   13.20 +			BUG_ON(ret);
   13.21  			end_that_request_last(req);
   13.22  			break;
   13.23  		default:
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Mon Oct 24 21:00:35 2005 -0600
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c	Sat Oct 29 09:51:35 2005 +0100
    14.3 @@ -413,6 +413,7 @@ static void fast_flush_area(int idx, int
    14.4  	unsigned int i, op = 0;
    14.5  	struct grant_handle_pair *handle;
    14.6  	unsigned long ptep;
    14.7 +	int ret;
    14.8  
    14.9  	for ( i = 0; i < nr_pages; i++)
   14.10  	{
   14.11 @@ -440,8 +441,8 @@ static void fast_flush_area(int idx, int
   14.12  		BLKTAP_INVALIDATE_HANDLE(handle);
   14.13  	}
   14.14  
   14.15 -	BUG_ON(HYPERVISOR_grant_table_op(
   14.16 -		GNTTABOP_unmap_grant_ref, unmap, op));
   14.17 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, unmap, op);
   14.18 +	BUG_ON(ret);
   14.19  
   14.20  	if (blktap_vma != NULL)
   14.21  		zap_page_range(blktap_vma, 
   14.22 @@ -673,6 +674,7 @@ static void dispatch_rw_block_io(blkif_t
   14.23  	struct gnttab_map_grant_ref map[BLKIF_MAX_SEGMENTS_PER_REQUEST*2];
   14.24  	int op, ret;
   14.25  	unsigned int nseg;
   14.26 +	int retval;
   14.27  
   14.28  	/* Check that number of segments is sane. */
   14.29  	nseg = req->nr_segments;
   14.30 @@ -740,8 +742,8 @@ static void dispatch_rw_block_io(blkif_t
   14.31  		op++;
   14.32  	}
   14.33  
   14.34 -	BUG_ON(HYPERVISOR_grant_table_op(
   14.35 -		GNTTABOP_map_grant_ref, map, op));
   14.36 +	retval = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, map, op);
   14.37 +	BUG_ON(retval);
   14.38  
   14.39  	op = 0;
   14.40  	for (i = 0; i < (req->nr_segments*2); i += 2) {
   14.41 @@ -877,7 +879,8 @@ static int __init blkif_init(void)
   14.42  	spin_lock_init(&blkio_schedule_list_lock);
   14.43  	INIT_LIST_HEAD(&blkio_schedule_list);
   14.44  
   14.45 -	BUG_ON(kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES) < 0);
   14.46 +	i = kernel_thread(blkio_schedule, 0, CLONE_FS | CLONE_FILES);
   14.47 +	BUG_ON(i<0);
   14.48  
   14.49  	blkif_xenbus_init();
   14.50  
    15.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Mon Oct 24 21:00:35 2005 -0600
    15.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Sat Oct 29 09:51:35 2005 +0100
    15.3 @@ -31,6 +31,7 @@ blkif_t *alloc_blkif(domid_t domid)
    15.4  static int map_frontend_page(blkif_t *blkif, unsigned long shared_page)
    15.5  {
    15.6  	struct gnttab_map_grant_ref op;
    15.7 +	int ret;
    15.8  
    15.9  	op.host_addr = (unsigned long)blkif->blk_ring_area->addr;
   15.10  	op.flags     = GNTMAP_host_map;
   15.11 @@ -38,8 +39,9 @@ static int map_frontend_page(blkif_t *bl
   15.12  	op.dom       = blkif->domid;
   15.13  
   15.14  	lock_vm_area(blkif->blk_ring_area);
   15.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   15.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   15.17  	unlock_vm_area(blkif->blk_ring_area);
   15.18 +	BUG_ON(ret);
   15.19  
   15.20  	if (op.handle < 0) {
   15.21  		DPRINTK(" Grant table operation failure !\n");
   15.22 @@ -55,14 +57,16 @@ static int map_frontend_page(blkif_t *bl
   15.23  static void unmap_frontend_page(blkif_t *blkif)
   15.24  {
   15.25  	struct gnttab_unmap_grant_ref op;
   15.26 +	int ret;
   15.27  
   15.28  	op.host_addr    = (unsigned long)blkif->blk_ring_area->addr;
   15.29  	op.handle       = blkif->shmem_handle;
   15.30  	op.dev_bus_addr = 0;
   15.31  
   15.32  	lock_vm_area(blkif->blk_ring_area);
   15.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   15.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   15.35  	unlock_vm_area(blkif->blk_ring_area);
   15.36 +	BUG_ON(ret);
   15.37  }
   15.38  
   15.39  int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn)
    16.1 --- a/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Mon Oct 24 21:00:35 2005 -0600
    16.2 +++ b/linux-2.6-xen-sparse/drivers/xen/evtchn/evtchn.c	Sat Oct 29 09:51:35 2005 +0100
    16.3 @@ -282,6 +282,7 @@ static int evtchn_ioctl(struct inode *in
    16.4  
    16.5  	case IOCTL_EVTCHN_UNBIND: {
    16.6  		struct ioctl_evtchn_unbind unbind;
    16.7 +		int ret;
    16.8  
    16.9  		rc = -EFAULT;
   16.10  		if (copy_from_user(&unbind, (void *)arg, sizeof(unbind)))
   16.11 @@ -306,7 +307,8 @@ static int evtchn_ioctl(struct inode *in
   16.12  
   16.13  		op.cmd = EVTCHNOP_close;
   16.14  		op.u.close.port = unbind.port;
   16.15 -		BUG_ON(HYPERVISOR_event_channel_op(&op));
   16.16 +		ret = HYPERVISOR_event_channel_op(&op);
   16.17 +		BUG_ON(ret);
   16.18  
   16.19  		rc = 0;
   16.20  		break;
   16.21 @@ -399,6 +401,7 @@ static int evtchn_release(struct inode *
   16.22  
   16.23  	for (i = 0; i < NR_EVENT_CHANNELS; i++)
   16.24  	{
   16.25 +		int ret;
   16.26  		if (port_user[i] != u)
   16.27  			continue;
   16.28  
   16.29 @@ -407,7 +410,8 @@ static int evtchn_release(struct inode *
   16.30  
   16.31  		op.cmd = EVTCHNOP_close;
   16.32  		op.u.close.port = i;
   16.33 -		BUG_ON(HYPERVISOR_event_channel_op(&op));
   16.34 +		ret = HYPERVISOR_event_channel_op(&op);
   16.35 +		BUG_ON(ret);
   16.36  	}
   16.37  
   16.38  	spin_unlock_irq(&port_user_lock);
    17.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Mon Oct 24 21:00:35 2005 -0600
    17.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Sat Oct 29 09:51:35 2005 +0100
    17.3 @@ -115,6 +115,7 @@ static int map_frontend_pages(
    17.4  	netif_t *netif, grant_ref_t tx_ring_ref, grant_ref_t rx_ring_ref)
    17.5  {
    17.6  	struct gnttab_map_grant_ref op;
    17.7 +	int ret;
    17.8  
    17.9  	op.host_addr = (unsigned long)netif->comms_area->addr;
   17.10  	op.flags     = GNTMAP_host_map;
   17.11 @@ -122,8 +123,9 @@ static int map_frontend_pages(
   17.12  	op.dom       = netif->domid;
   17.13      
   17.14  	lock_vm_area(netif->comms_area);
   17.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   17.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   17.17  	unlock_vm_area(netif->comms_area);
   17.18 +	BUG_ON(ret);
   17.19  
   17.20  	if (op.handle < 0) { 
   17.21  		DPRINTK(" Gnttab failure mapping tx_ring_ref!\n");
   17.22 @@ -139,8 +141,9 @@ static int map_frontend_pages(
   17.23  	op.dom       = netif->domid;
   17.24  
   17.25  	lock_vm_area(netif->comms_area);
   17.26 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   17.27 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   17.28  	unlock_vm_area(netif->comms_area);
   17.29 +	BUG_ON(ret);
   17.30  
   17.31  	if (op.handle < 0) { 
   17.32  		DPRINTK(" Gnttab failure mapping rx_ring_ref!\n");
   17.33 @@ -156,22 +159,25 @@ static int map_frontend_pages(
   17.34  static void unmap_frontend_pages(netif_t *netif)
   17.35  {
   17.36  	struct gnttab_unmap_grant_ref op;
   17.37 +	int ret;
   17.38  
   17.39  	op.host_addr    = (unsigned long)netif->comms_area->addr;
   17.40  	op.handle       = netif->tx_shmem_handle;
   17.41  	op.dev_bus_addr = 0;
   17.42  
   17.43  	lock_vm_area(netif->comms_area);
   17.44 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   17.45 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   17.46  	unlock_vm_area(netif->comms_area);
   17.47 +	BUG_ON(ret);
   17.48  
   17.49  	op.host_addr    = (unsigned long)netif->comms_area->addr + PAGE_SIZE;
   17.50  	op.handle       = netif->rx_shmem_handle;
   17.51  	op.dev_bus_addr = 0;
   17.52  
   17.53  	lock_vm_area(netif->comms_area);
   17.54 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   17.55 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   17.56  	unlock_vm_area(netif->comms_area);
   17.57 +	BUG_ON(ret);
   17.58  }
   17.59  
   17.60  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
    18.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Mon Oct 24 21:00:35 2005 -0600
    18.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Sat Oct 29 09:51:35 2005 +0100
    18.3 @@ -112,9 +112,12 @@ static void free_mfn(unsigned long mfn)
    18.4  	spin_lock_irqsave(&mfn_lock, flags);
    18.5  	if ( alloc_index != MAX_MFN_ALLOC )
    18.6  		mfn_list[alloc_index++] = mfn;
    18.7 -	else
    18.8 -		BUG_ON(HYPERVISOR_memory_op(XENMEM_decrease_reservation,
    18.9 -					    &reservation) != 1);
   18.10 +	else {
   18.11 +		int ret;
   18.12 +		ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
   18.13 +					    &reservation);
   18.14 +		BUG_ON(ret != 1);
   18.15 +	}
   18.16  	spin_unlock_irqrestore(&mfn_lock, flags);
   18.17  }
   18.18  #endif
   18.19 @@ -159,13 +162,15 @@ int netif_be_start_xmit(struct sk_buff *
   18.20  	 */
   18.21  	if (skb_shared(skb) || skb_cloned(skb) || !is_xen_skb(skb)) {
   18.22  		int hlen = skb->data - skb->head;
   18.23 +		int ret;
   18.24  		struct sk_buff *nskb = dev_alloc_skb(hlen + skb->len);
   18.25  		if ( unlikely(nskb == NULL) )
   18.26  			goto drop;
   18.27  		skb_reserve(nskb, hlen);
   18.28  		__skb_put(nskb, skb->len);
   18.29 -		BUG_ON(skb_copy_bits(skb, -hlen, nskb->data - hlen,
   18.30 -				     skb->len + hlen));
   18.31 +		ret = skb_copy_bits(skb, -hlen, nskb->data - hlen,
   18.32 +				     skb->len + hlen);
   18.33 +		BUG_ON(ret);
   18.34  		nskb->dev = skb->dev;
   18.35  		nskb->proto_csum_valid = skb->proto_csum_valid;
   18.36  		dev_kfree_skb(skb);
   18.37 @@ -218,6 +223,7 @@ static void net_rx_action(unsigned long 
   18.38  	struct sk_buff *skb;
   18.39  	u16 notify_list[NETIF_RX_RING_SIZE];
   18.40  	int notify_nr = 0;
   18.41 +	int ret;
   18.42  
   18.43  	skb_queue_head_init(&rxq);
   18.44  
   18.45 @@ -279,7 +285,8 @@ static void net_rx_action(unsigned long 
   18.46  	mcl++;
   18.47  
   18.48  	mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
   18.49 -	BUG_ON(HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl) != 0);
   18.50 +	ret = HYPERVISOR_multicall(rx_mcl, mcl - rx_mcl);
   18.51 +	BUG_ON(ret != 0);
   18.52  
   18.53  	mcl = rx_mcl;
   18.54  	if( HYPERVISOR_grant_table_op(GNTTABOP_transfer, grant_rx_op, 
   18.55 @@ -421,6 +428,7 @@ inline static void net_tx_action_dealloc
   18.56  	u16 pending_idx;
   18.57  	PEND_RING_IDX dc, dp;
   18.58  	netif_t *netif;
   18.59 +	int ret;
   18.60  
   18.61  	dc = dealloc_cons;
   18.62  	dp = dealloc_prod;
   18.63 @@ -436,8 +444,9 @@ inline static void net_tx_action_dealloc
   18.64  		gop->handle       = grant_tx_ref[pending_idx];
   18.65  		gop++;
   18.66  	}
   18.67 -	BUG_ON(HYPERVISOR_grant_table_op(
   18.68 -		GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops));
   18.69 +	ret = HYPERVISOR_grant_table_op(
   18.70 +		GNTTABOP_unmap_grant_ref, tx_unmap_ops, gop - tx_unmap_ops);
   18.71 +	BUG_ON(ret);
   18.72  
   18.73  	while (dealloc_cons != dp) {
   18.74  		pending_idx = dealloc_ring[MASK_PEND_IDX(dealloc_cons++)];
   18.75 @@ -477,6 +486,7 @@ static void net_tx_action(unsigned long 
   18.76  	NETIF_RING_IDX i;
   18.77  	gnttab_map_grant_ref_t *mop;
   18.78  	unsigned int data_len;
   18.79 +	int ret;
   18.80  
   18.81  	if (dealloc_cons != dealloc_prod)
   18.82  		net_tx_action_dealloc();
   18.83 @@ -599,8 +609,9 @@ static void net_tx_action(unsigned long 
   18.84  	if (mop == tx_map_ops)
   18.85  		return;
   18.86  
   18.87 -	BUG_ON(HYPERVISOR_grant_table_op(
   18.88 -		GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops));
   18.89 +	ret = HYPERVISOR_grant_table_op(
   18.90 +		GNTTABOP_map_grant_ref, tx_map_ops, mop - tx_map_ops);
   18.91 +	BUG_ON(ret);
   18.92  
   18.93  	mop = tx_map_ops;
   18.94  	while ((skb = __skb_dequeue(&tx_queue)) != NULL) {
    19.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Mon Oct 24 21:00:35 2005 -0600
    19.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Sat Oct 29 09:51:35 2005 +0100
    19.3 @@ -78,6 +78,7 @@ tpmif_find(domid_t domid, long int insta
    19.4  static int
    19.5  map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
    19.6  {
    19.7 +	int ret;
    19.8  	struct gnttab_map_grant_ref op = {
    19.9  		.host_addr = (unsigned long)tpmif->tx_area->addr,
   19.10  		.flags = GNTMAP_host_map,
   19.11 @@ -86,8 +87,9 @@ map_frontend_page(tpmif_t *tpmif, unsign
   19.12  	};
   19.13  
   19.14  	lock_vm_area(tpmif->tx_area);
   19.15 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   19.16 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1);
   19.17  	unlock_vm_area(tpmif->tx_area);
   19.18 +	BUG_ON(ret);
   19.19  
   19.20  	if (op.handle < 0) {
   19.21  		DPRINTK(" Grant table operation failure !\n");
   19.22 @@ -104,14 +106,16 @@ static void
   19.23  unmap_frontend_page(tpmif_t *tpmif)
   19.24  {
   19.25  	struct gnttab_unmap_grant_ref op;
   19.26 +	int ret;
   19.27  
   19.28  	op.host_addr    = (unsigned long)tpmif->tx_area->addr;
   19.29  	op.handle       = tpmif->shmem_handle;
   19.30  	op.dev_bus_addr = 0;
   19.31  
   19.32  	lock_vm_area(tpmif->tx_area);
   19.33 -	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   19.34 +	ret = HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1);
   19.35  	unlock_vm_area(tpmif->tx_area);
   19.36 +	BUG_ON(ret);
   19.37  }
   19.38  
   19.39  int
    20.1 --- a/linux-2.6-xen-sparse/drivers/xen/util.c	Mon Oct 24 21:00:35 2005 -0600
    20.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Sat Oct 29 09:51:35 2005 +0100
    20.3 @@ -34,7 +34,9 @@ struct vm_struct *alloc_vm_area(unsigned
    20.4  
    20.5  void free_vm_area(struct vm_struct *area)
    20.6  {
    20.7 -	BUG_ON(remove_vm_area(area->addr) != area);
    20.8 +	struct vm_struct *ret;
    20.9 +	ret = remove_vm_area(area->addr);
   20.10 +	BUG_ON(ret != area);
   20.11  	kfree(area);
   20.12  }
   20.13  
    21.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Mon Oct 24 21:00:35 2005 -0600
    21.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Sat Oct 29 09:51:35 2005 +0100
    21.3 @@ -738,6 +738,7 @@ static int __init xenbus_probe_init(void
    21.4  
    21.5  		unsigned long page;
    21.6  		evtchn_op_t op = { 0 };
    21.7 +		int ret;
    21.8  
    21.9  
   21.10  		/* Allocate page. */
   21.11 @@ -758,7 +759,8 @@ static int __init xenbus_probe_init(void
   21.12  		op.u.alloc_unbound.dom        = DOMID_SELF;
   21.13  		op.u.alloc_unbound.remote_dom = 0; 
   21.14  
   21.15 -		BUG_ON(HYPERVISOR_event_channel_op(&op)); 
   21.16 +		ret = HYPERVISOR_event_channel_op(&op);
   21.17 +		BUG_ON(ret); 
   21.18  		xen_start_info->store_evtchn = op.u.alloc_unbound.port;
   21.19  
   21.20  		/* And finally publish the above info in /proc/xen */
    22.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Mon Oct 24 21:00:35 2005 -0600
    22.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Sat Oct 29 09:51:35 2005 +0100
    22.3 @@ -82,7 +82,7 @@ static struct xs_handle xs_state;
    22.4  static LIST_HEAD(watches);
    22.5  static DEFINE_SPINLOCK(watches_lock);
    22.6  
    22.7 -/* List of pending watch calbback events, and a lock to protect it. */
    22.8 +/* List of pending watch callback events, and a lock to protect it. */
    22.9  static LIST_HEAD(watch_events);
   22.10  static DEFINE_SPINLOCK(watch_events_lock);
   22.11  
   22.12 @@ -544,11 +544,8 @@ void xenbus_dev_error(struct xenbus_devi
   22.13  	char *printf_buffer = NULL, *path_buffer = NULL;
   22.14  
   22.15  	printf_buffer = kmalloc(PRINTF_BUFFER_SIZE, GFP_KERNEL);
   22.16 -	if (printf_buffer == NULL) {
   22.17 -		printk("xenbus: failed to write error node for %s (%d): %d\n",
   22.18 -		       dev->nodename, err, errno);
   22.19 +	if (printf_buffer == NULL)
   22.20  		goto fail;
   22.21 -	}
   22.22  
   22.23  	len = sprintf(printf_buffer, "%i ", -err);
   22.24  	va_start(ap, fmt);
   22.25 @@ -561,8 +558,8 @@ void xenbus_dev_error(struct xenbus_devi
   22.26  	path_buffer = error_path(dev);
   22.27  
   22.28  	if (path_buffer == NULL) {
   22.29 -		printk("xenbus: failed to write error node for %s (%s): %d\n",
   22.30 -		       dev->nodename, printf_buffer, errno);
   22.31 +		printk("xenbus: failed to write error node for %s (%s)\n",
   22.32 +		       dev->nodename, printf_buffer);
   22.33  		goto fail;
   22.34  	}
   22.35  
   22.36 @@ -587,8 +584,8 @@ void xenbus_dev_ok(struct xenbus_device 
   22.37  		char *path_buffer = error_path(dev);
   22.38  
   22.39  		if (path_buffer == NULL) {
   22.40 -			printk("xenbus: failed to clear error node for %s: "
   22.41 -			       "%d\n", dev->nodename, errno);
   22.42 +			printk("xenbus: failed to clear error node for %s\n",
   22.43 +			       dev->nodename);
   22.44  			return;
   22.45  		}
   22.46  
    23.1 --- a/tools/Makefile	Mon Oct 24 21:00:35 2005 -0600
    23.2 +++ b/tools/Makefile	Sat Oct 29 09:51:35 2005 +0100
    23.3 @@ -16,9 +16,6 @@ SUBDIRS += vtpm_manager
    23.4  SUBDIRS += vtpm
    23.5  endif
    23.6  SUBDIRS += xenstat
    23.7 -
    23.8 -.PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean
    23.9 -
   23.10  # These don't cross-compile
   23.11  ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
   23.12  SUBDIRS += python
    24.1 --- a/tools/console/daemon/io.c	Mon Oct 24 21:00:35 2005 -0600
    24.2 +++ b/tools/console/daemon/io.c	Sat Oct 29 09:51:35 2005 +0100
    24.3 @@ -512,7 +512,9 @@ static void handle_xs(int fd)
    24.4  		enum_domains();
    24.5  	else if (sscanf(vec[XS_WATCH_TOKEN], "dom%u", &domid) == 1) {
    24.6  		dom = lookup_domain(domid);
    24.7 -		if (dom->is_dead == false)
    24.8 +		/* We may get watches firing for domains that have recently
    24.9 +		   been removed, so dom may be NULL here. */
   24.10 +		if (dom && dom->is_dead == false)
   24.11  			domain_create_ring(dom);
   24.12  	}
   24.13  
    25.1 --- a/tools/examples/Makefile	Mon Oct 24 21:00:35 2005 -0600
    25.2 +++ b/tools/examples/Makefile	Sat Oct 29 09:51:35 2005 +0100
    25.3 @@ -9,6 +9,7 @@ INSTALL_DATA	= $(INSTALL) -m0644
    25.4  # Init scripts.
    25.5  XEND_INITD = init.d/xend
    25.6  XENDOMAINS_INITD = init.d/xendomains
    25.7 +XENDOMAINS_SYSCONFIG = init.d/sysconfig.xendomains
    25.8  
    25.9  # Xen configuration dir and configs to go there.
   25.10  XEN_CONFIG_DIR = /etc/xen
   25.11 @@ -24,8 +25,9 @@ XEN_SCRIPTS = network-bridge vif-bridge
   25.12  XEN_SCRIPTS += network-route vif-route
   25.13  XEN_SCRIPTS += network-nat vif-nat
   25.14  XEN_SCRIPTS += block
   25.15 -XEN_SCRIPTS += block-enbd
   25.16 +XEN_SCRIPTS += block-enbd block-nbd
   25.17  XEN_SCRIPTS += xen-hotplug-common.sh xen-network-common.sh vif-common.sh
   25.18 +XEN_SCRIPTS += block-common.sh
   25.19  
   25.20  XEN_HOTPLUG_DIR = /etc/hotplug
   25.21  XEN_HOTPLUG_SCRIPTS = xen-backend.agent
   25.22 @@ -52,8 +54,10 @@ install: all install-initd install-confi
   25.23  
   25.24  install-initd:
   25.25  	[ -d $(DESTDIR)/etc/init.d ] || $(INSTALL_DIR) $(DESTDIR)/etc/init.d
   25.26 +	[ -d $(DESTDIR)/etc/sysconfig ] || $(INSTALL_DIR) $(DESTDIR)/etc/sysconfig
   25.27  	$(INSTALL_PROG) $(XEND_INITD) $(DESTDIR)/etc/init.d
   25.28  	$(INSTALL_PROG) $(XENDOMAINS_INITD) $(DESTDIR)/etc/init.d
   25.29 +	$(INSTALL_PROG) $(XENDOMAINS_SYSCONFIG) $(DESTDIR)/etc/sysconfig/xendomains
   25.30  
   25.31  install-configs: $(XEN_CONFIGS)
   25.32  	[ -d $(DESTDIR)$(XEN_CONFIG_DIR) ] || \
    26.1 --- a/tools/examples/block	Mon Oct 24 21:00:35 2005 -0600
    26.2 +++ b/tools/examples/block	Sat Oct 29 09:51:35 2005 +0100
    26.3 @@ -1,7 +1,7 @@
    26.4  #!/bin/sh
    26.5  
    26.6  dir=$(dirname "$0")
    26.7 -. "$dir/xen-hotplug-common.sh"
    26.8 +. "$dir/block-common.sh"
    26.9  
   26.10  expand_dev() {
   26.11    local dev
   26.12 @@ -16,21 +16,9 @@ expand_dev() {
   26.13    echo -n $dev
   26.14  }
   26.15  
   26.16 -write_dev() {
   26.17 -  local major
   26.18 -  local minor
   26.19 -  local pdev
   26.20 -	
   26.21 -  major=$(stat -L -c %t "$1")
   26.22 -  minor=$(stat -L -c %T "$1")
   26.23 -  pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
   26.24 -  xenstore_write "$XENBUS_PATH"/physical-device $pdev \
   26.25 -      "$XENBUS_PATH"/node $1
   26.26 -}
   26.27 -
   26.28  t=$(xenstore_read "$XENBUS_PATH"/type || true)
   26.29  
   26.30 -case $1 in 
   26.31 +case "$command" in 
   26.32    bind)
   26.33      p=$(xenstore_read "$XENBUS_PATH"/params)
   26.34      case $t in 
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/tools/examples/block-common.sh	Sat Oct 29 09:51:35 2005 +0100
    27.3 @@ -0,0 +1,51 @@
    27.4 +#
    27.5 +# Copyright (c) 2005 XenSource Ltd.
    27.6 +#
    27.7 +# This library is free software; you can redistribute it and/or
    27.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    27.9 +# License as published by the Free Software Foundation.
   27.10 +#
   27.11 +# This library is distributed in the hope that it will be useful,
   27.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   27.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27.14 +# Lesser General Public License for more details.
   27.15 +#
   27.16 +# You should have received a copy of the GNU Lesser General Public
   27.17 +# License along with this library; if not, write to the Free Software
   27.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   27.19 +#
   27.20 +
   27.21 +
   27.22 +dir=$(dirname "$0")
   27.23 +. "$dir/xen-hotplug-common.sh"
   27.24 +
   27.25 +command="$1"
   27.26 +
   27.27 +if [ "$command" != "bind" ] && [ "$command" != "unbind" ]
   27.28 +then
   27.29 +  log err "Invalid command: $command"
   27.30 +  exit 1
   27.31 +fi
   27.32 +
   27.33 +
   27.34 +XENBUS_PATH="${XENBUS_PATH:?}"
   27.35 +
   27.36 +
   27.37 +##
   27.38 +# Write physical-device = 0xMMmm and node = device to the store, where MM
   27.39 +# and mm are the major and minor numbers of device.
   27.40 +#
   27.41 +# @param device The device from which major and minor numbers are read, which
   27.42 +#               will be written into the store.
   27.43 +#
   27.44 +write_dev() {
   27.45 +  local major
   27.46 +  local minor
   27.47 +  local pdev
   27.48 +	
   27.49 +  major=$(stat -L -c %t "$1")
   27.50 +  minor=$(stat -L -c %T "$1")
   27.51 +  pdev=$(printf "0x%02x%02x" "0x$major" "0x$minor")
   27.52 +  xenstore_write "$XENBUS_PATH"/physical-device "$pdev" \
   27.53 +                 "$XENBUS_PATH"/node "$1"
   27.54 +}
    28.1 --- a/tools/examples/block-enbd	Mon Oct 24 21:00:35 2005 -0600
    28.2 +++ b/tools/examples/block-enbd	Sat Oct 29 09:51:35 2005 +0100
    28.3 @@ -2,25 +2,19 @@
    28.4  
    28.5  # Usage: block-enbd [bind server ctl_port |unbind node]
    28.6  #
    28.7 -# The file argument to the bind command is the file we are to bind to a
    28.8 -# loop device.
    28.9 -#
   28.10  # The node argument to unbind is the name of the device node we are to
   28.11  # unbind.
   28.12  #
   28.13  # This assumes you're running a correctly configured server at the other end!
   28.14  
   28.15 -set -e
   28.16 +dir=$(dirname "$0")
   28.17 +. "$dir/block-common.sh"
   28.18  
   28.19 -case $1 in
   28.20 +case "$command" in
   28.21    bind)
   28.22      for dev in /dev/nd*; do
   28.23        if nbd-client $2:$3 $dev; then
   28.24 -        major=$(stat -L -c %t "$dev")
   28.25 -        minor=$(stat -L -c %T "$dev")
   28.26 -        pdev=$(printf "0x%02x%02x" 0x$major 0x$minor)
   28.27 -        xenstore-write "$XENBUS_PATH"/physical-device $pdev \
   28.28 -          "$XENBUS_PATH"/node $dev
   28.29 +        write_dev $dev
   28.30          exit 0
   28.31        fi
   28.32      done
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/tools/examples/block-nbd	Sat Oct 29 09:51:35 2005 +0100
    29.3 @@ -0,0 +1,27 @@
    29.4 +#!/bin/sh
    29.5 +
    29.6 +# Usage: block-nbd [bind server ctl_port |unbind node]
    29.7 +#
    29.8 +# The node argument to unbind is the name of the device node we are to
    29.9 +# unbind.
   29.10 +#
   29.11 +# This assumes you're running a correctly configured server at the other end!
   29.12 +
   29.13 +dir=$(dirname "$0")
   29.14 +. "$dir/block-common.sh"
   29.15 +
   29.16 +case "$command" in
   29.17 +  bind)
   29.18 +    for dev in /dev/nbd*; do
   29.19 +      if nbd-client $2 $3 $dev; then
   29.20 +        write_dev $dev
   29.21 +        exit 0
   29.22 +      fi
   29.23 +    done
   29.24 +    exit 1
   29.25 +    ;;
   29.26 +  unbind)
   29.27 +    nbd-client -d $2
   29.28 +    exit 0
   29.29 +    ;;
   29.30 +esac
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/tools/examples/init.d/sysconfig.xendomains	Sat Oct 29 09:51:35 2005 +0100
    30.3 @@ -0,0 +1,126 @@
    30.4 +## Path: System/xen
    30.5 +## Description: xen domain start/stop on boot
    30.6 +## Type: string
    30.7 +## Default: 
    30.8 +#
    30.9 +# The xendomains script can send SysRq requests to domains on shutdown.
   30.10 +# If you don't want to MIGRATE, SAVE, or SHUTDOWN, this may be a possibility
   30.11 +# to do a quick and dirty shutdown ("s e i u o") or at least sync the disks
   30.12 +# of the domains ("s").
   30.13 +#
   30.14 +XENDOMAINS_SYSRQ=""
   30.15 +
   30.16 +## Type: integer 
   30.17 +## Default: 100000
   30.18 +#
   30.19 +# If XENDOMAINS_SYSRQ is set, this variable determines how long to wait
   30.20 +# (in microseconds) after each SysRq, so the domain has a chance to react.
   30.21 +# If you want to a quick'n'dirty shutdown via SysRq, you may want to set
   30.22 +# it to a relatively high value (1200000).
   30.23 +#
   30.24 +XENDOMAINS_USLEEP=100000
   30.25 +
   30.26 +## Type: string
   30.27 +## Default: ""
   30.28 +#
   30.29 +# Set this to a non-empty string if you want to migrate virtual machines
   30.30 +# on shutdown. The string will be passed to the xm migrate DOMID command
   30.31 +# as is: It should contain the target IP address of the physical machine
   30.32 +# to migrate to and optionally parameters like --live. Leave empty if
   30.33 +# you don't want to try virtual machine relocation on shutdown.
   30.34 +# If migration succeeds, neither SAVE nor SHUTDOWN will be executed for
   30.35 +# that domain.
   30.36 +#
   30.37 +XENDOMAINS_MIGRATE=""
   30.38 +
   30.39 +## Type: string
   30.40 +## Default: /var/lib/xen/save
   30.41 +#
   30.42 +# Directory to save running domains to when the system (dom0) is
   30.43 +# shut down. Will also be used to restore domains from if # XENDOMAINS_RESTORE
   30.44 +# is set (see below). Leave empty to disable domain saving on shutdown 
   30.45 +# (e.g. because you rather shut domains down).
   30.46 +# If domain saving does succeed, SHUTDOWN will not be executed.
   30.47 +#
   30.48 +XENDOMAINS_SAVE=/var/lib/xen/save
   30.49 +
   30.50 +## Type: string
   30.51 +## Default: "--halt --wait"
   30.52 +#
   30.53 +# If neither MIGRATE nor SAVE were enabled or if they failed, you can
   30.54 +# try to shut down a domain by sending it a shutdown request. To do this,
   30.55 +# set this to "--halt --wait". Omit the "--wait" flag to avoid waiting
   30.56 +# for the domain to be really down. Leave empty to skip domain shutdown.
   30.57 +#
   30.58 +XENDOMAINS_SHUTDOWN="--halt --wait"
   30.59 +
   30.60 +## Type: string
   30.61 +## Default: "--all --halt --wait"
   30.62 +#
   30.63 +# After we have gone over all virtual machines (resp. all automatically
   30.64 +# started ones, see XENDOMAINS_AUTO_ONLY below) in a loop and sent SysRq,
   30.65 +# migrated, saved and/or shutdown according to the settings above, we
   30.66 +# might want to shutdown the virtual machines that are still running
   30.67 +# for some reason or another. To do this, set this variable to
   30.68 +# "--all --halt --wait", it will be passed to xm shutdown.
   30.69 +# Leave it empty not to do anything special here.
   30.70 +# (Note: This will hit all virtual machines, even if XENDOMAINS_AUTO_ONLY
   30.71 +# is set.)
   30.72 +# 
   30.73 +XENDOMAINS_SHUTDOWN_ALL="--all --halt --wait"
   30.74 +
   30.75 +## Type: boolean
   30.76 +## Default: true
   30.77 +#
   30.78 +# This variable determines whether saved domains from XENDOMAINS_SAVE
   30.79 +# will be restored on system startup. 
   30.80 +#
   30.81 +XENDOMAINS_RESTORE=true
   30.82 +
   30.83 +## Type: string
   30.84 +## Default: /etc/xen/auto
   30.85 +#
   30.86 +# This variable sets the directory where domains configurations
   30.87 +# are stored that should be started on system startup automatically.
   30.88 +# Leave empty if you don't want to start domains automatically
   30.89 +# (or just don't place any xen domain config files in that dir).
   30.90 +# Note that the script tries to be clever if both RESTORE and AUTO are 
   30.91 +# set: It will first restore saved domains and then only start domains
   30.92 +# in AUTO which are not running yet. 
   30.93 +# Note that the name matching is somewhat fuzzy.
   30.94 +#
   30.95 +XENDOMAINS_AUTO=/etc/xen/auto
   30.96 +
   30.97 +## Type: boolean
   30.98 +## Default: false
   30.99 +# 
  30.100 +# If this variable is set to "true", only the domains started via config 
  30.101 +# files in XENDOMAINS_AUTO will be treated according to XENDOMAINS_SYSRQ,
  30.102 +# XENDOMAINS_MIGRATE, XENDOMAINS_SAVE, XENDMAINS_SHUTDOWN; otherwise
  30.103 +# all running domains will be. 
  30.104 +# Note that the name matching is somewhat fuzzy.
  30.105 +# 
  30.106 +XENDOMAINS_AUTO_ONLY=false
  30.107 +
  30.108 +## Type: integer
  30.109 +## Default: 300
  30.110 +#
  30.111 +# On xendomains stop, a number of xm commands (xm migrate, save, shutdown,
  30.112 +# shutdown --all) may be executed. In the worst case, these commands may
  30.113 +# stall forever, which will prevent a successful shutdown of the machine.
  30.114 +# If this variable is non-zero, the script will set up a watchdog timer
  30.115 +# for every of these xm commands and time it out after the number of seconds
  30.116 +# specified by this variable.
  30.117 +# Note that SHUTDOWN_ALL will not be called if no virtual machines or only
  30.118 +# zombies are still running, so you don't need to enable this timeout just
  30.119 +# for the zombie case.
  30.120 +# The setting should be large enough to make sure that migrate/save/shutdown
  30.121 +# can succeed. If you do live migrations, keep in mind that live migration
  30.122 +# of a 1GB machine over Gigabit ethernet may actually take something like
  30.123 +# 100s (assuming that live migration uses 10% of the network # bandwidth).
  30.124 +# Depending on the virtual machine, a shutdown may also require a significant
  30.125 +# amount of time. So better setup this variable to a huge number and hope the
  30.126 +# watchdog never fires.
  30.127 +#
  30.128 +XENDOMAINS_STOP_MAXWAIT=300
  30.129 +
    31.1 --- a/tools/examples/init.d/xendomains	Mon Oct 24 21:00:35 2005 -0600
    31.2 +++ b/tools/examples/init.d/xendomains	Sat Oct 29 09:51:35 2005 +0100
    31.3 @@ -1,4 +1,4 @@
    31.4 -#!/bin/sh
    31.5 +#!/bin/bash
    31.6  #
    31.7  # /etc/init.d/xendomains
    31.8  # Start / stop domains automatically when domain 0 boots / shuts down.
    31.9 @@ -22,101 +22,418 @@
   31.10  # Should-Stop:
   31.11  # Default-Start:     3 4 5
   31.12  # Default-Stop:      0 1 2 6
   31.13 +# Default-Enabled:   yes
   31.14  # Short-Description: Start/stop secondary xen domains
   31.15  # Description:       Start / stop domains automatically when domain 0 
   31.16  #                    boots / shuts down.
   31.17  ### END INIT INFO
   31.18  
   31.19 +# Correct exit code would probably be 5, but it's enough 
   31.20 +# if xend complains if we're not running as privileged domain
   31.21  if ! [ -e /proc/xen/privcmd ]; then
   31.22  	exit 0
   31.23  fi
   31.24  
   31.25 -RETVAL=0
   31.26 +LOCKFILE=/var/lock/subsys/xendomains
   31.27 +XENDOM_CONFIG=/etc/sysconfig/xendomains
   31.28  
   31.29 -INITD=/etc/init.d
   31.30 +test -r $XENDOM_CONFIG || { echo "$XENDOM_CONFIG not existing";
   31.31 +	if [ "$1" = "stop" ]; then exit 0;
   31.32 +	else exit 6; fi; }
   31.33  
   31.34 -AUTODIR=/etc/xen/auto
   31.35 -LOCKFILE=/var/lock/subsys/xendomains
   31.36 +. $XENDOM_CONFIG
   31.37  
   31.38 -if [ -e /lib/lsb ]; then
   31.39 -    # assume an LSB-compliant distro (Debian with LSB package,
   31.40 -    # recent-enough SuSE, others...)
   31.41 -
   31.42 -    . /lib/lsb/init-functions # source LSB standard functions
   31.43 -
   31.44 -    on_fn_exit()
   31.45 +# Use the SUSE rc_ init script functions;
   31.46 +# emulate them on LSB, RH and other systems
   31.47 +if test -e /etc/rc.status; then
   31.48 +    # SUSE rc script library
   31.49 +    . /etc/rc.status
   31.50 +else    
   31.51 +    _cmd=$1
   31.52 +    declare -a _SMSG
   31.53 +    if test "${_cmd}" = "status"; then
   31.54 +	_SMSG=(running dead dead unused unknown)
   31.55 +	_RC_UNUSED=3
   31.56 +    else
   31.57 +	_SMSG=(done failed failed missed failed skipped unused failed failed)
   31.58 +	_RC_UNUSED=6
   31.59 +    fi
   31.60 +    if test -e /lib/lsb/init-functions; then
   31.61 +	# LSB    
   31.62 +    	. /lib/lsb/init-functions
   31.63 +	echo_rc()
   31.64 +	{
   31.65 +	    if test ${_RC_RV} = 0; then
   31.66 +		log_success_msg "  [${_SMSG[${_RC_RV}]}] "
   31.67 +	    else
   31.68 +		log_failure_msg "  [${_SMSG[${_RC_RV}]}] "
   31.69 +	    fi
   31.70 +	}
   31.71 +    elif test -e /etc/init.d/functions; then
   31.72 +	# REDHAT
   31.73 +	. /etc/init.d/functions
   31.74 +	echo_rc()
   31.75 +	{
   31.76 +	    #echo -n "  [${_SMSG[${_RC_RV}]}] "
   31.77 +	    if test ${_RC_RV} = 0; then
   31.78 +		success "  [${_SMSG[${_RC_RV}]}] "
   31.79 +	    else
   31.80 +		failure "  [${_SMSG[${_RC_RV}]}] "
   31.81 +	    fi
   31.82 +	}
   31.83 +    else    
   31.84 +	# emulate it
   31.85 +	echo_rc()
   31.86 +	{
   31.87 +	    echo "  [${_SMSG[${_RC_RV}]}] "
   31.88 +	}
   31.89 +    fi
   31.90 +    rc_reset() { _RC_RV=0; }
   31.91 +    rc_failed()
   31.92      {
   31.93 -	if [ $RETVAL -eq 0 ]; then
   31.94 -	    log_success_msg
   31.95 -	else
   31.96 -	    log_failure_msg
   31.97 -	fi
   31.98 +	if test -z "$1"; then 
   31.99 +	    _RC_RV=1;
  31.100 +	elif test "$1" != "0"; then 
  31.101 +	    _RC_RV=$1; 
  31.102 +    	fi
  31.103 +	return ${_RC_RV}
  31.104      }
  31.105 -elif [ -r $INITD/functions ]; then
  31.106 -    # assume a Redhat-like distro
  31.107 -    . $INITD/functions # source Redhat functions
  31.108 -
  31.109 -    on_fn_exit()
  31.110 +    rc_check()
  31.111 +    {
  31.112 +	return rc_failed $?
  31.113 +    }	
  31.114 +    rc_status()
  31.115      {
  31.116 -	if [ $RETVAL -eq 0 ]; then
  31.117 -	    success
  31.118 -	else
  31.119 -	    failure
  31.120 -	fi
  31.121 -	
  31.122 -	echo
  31.123 +	rc_failed $?
  31.124 +	if test "$1" = "-r"; then _RC_RV=0; shift; fi
  31.125 +	if test "$1" = "-s"; then rc_failed 5; echo_rc; rc_failed 3; shift; fi
  31.126 +	if test "$1" = "-u"; then rc_failed ${_RC_UNUSED}; echo_rc; rc_failed 3; shift; fi
  31.127 +	if test "$1" = "-v"; then echo_rc; shift; fi
  31.128 +	if test "$1" = "-r"; then _RC_RV=0; shift; fi
  31.129 +	return ${_RC_RV}
  31.130      }
  31.131 -else
  31.132 -    # none of the above
  31.133 -    LOCKFILE=/var/lock/xendomains
  31.134 -
  31.135 -    on_fn_exit()
  31.136 +    rc_exit() { exit ${_RC_RV}; }
  31.137 +    rc_active() 
  31.138      {
  31.139 -	echo
  31.140 +	if test -z "$RUNLEVEL"; then read RUNLEVEL REST < <(/sbin/runlevel); fi
  31.141 +	if test -e /etc/init.d/S[0-9][0-9]${1}; then return 0; fi
  31.142 +	return 1
  31.143      }
  31.144  fi
  31.145  
  31.146 +if ! which usleep >&/dev/null
  31.147 +then
  31.148 +  usleep()
  31.149 +  {
  31.150 +    if [ -n "$1" ]
  31.151 +    then
  31.152 +      sleep $(( $1 / 1000 ))
  31.153 +    fi
  31.154 +  }
  31.155 +fi
  31.156  
  31.157 +# Reset status of this service
  31.158 +rc_reset
  31.159  
  31.160 -start() {
  31.161 -    if [ -f $LOCKFILE ]; then return; fi
  31.162 +##
  31.163 +# Returns 0 (success) if the given parameter names a directory, and that
  31.164 +# directory is not empty.
  31.165 +#
  31.166 +contains_something()
  31.167 +{
  31.168 +  if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ]
  31.169 +  then
  31.170 +    return 0
  31.171 +  else
  31.172 +    return 1
  31.173 +  fi
  31.174 +}
  31.175  
  31.176 -    echo -n $"Starting auto Xen domains:"
  31.177 +# read name from xen config file
  31.178 +rdname()
  31.179 +{
  31.180 +    NM=`grep '^name *=' $1 | sed -e 's/^name *= *"\([^"]*\)".*$/\1/' -e 's/%[id]/[0-9]*/g'`
  31.181 +}
  31.182  
  31.183 -    # We expect config scripts for auto starting domains to be in
  31.184 -    # AUTODIR - they could just be symlinks to files elsewhere
  31.185 -    if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
  31.186 +rdnames()
  31.187 +{
  31.188 +    NAMES=
  31.189 +    if ! contains_something "$XENDOMAINS_AUTO"
  31.190 +    then 
  31.191 +	return
  31.192 +    fi
  31.193 +    for dom in $XENDOMAINS_AUTO/*; do
  31.194 +	rdname $dom
  31.195 +	if test -z $NAMES; then 
  31.196 +	    NAMES=$NM; 
  31.197 +	else
  31.198 +	    NAMES="$NAMES|$NM"
  31.199 +	fi
  31.200 +    done
  31.201 +}
  31.202 +
  31.203 +parseln()
  31.204 +{
  31.205 +    name=`echo "$1" | cut -c0-17`
  31.206 +    name=${name%% *}
  31.207 +    rest=`echo "$1" | cut -c18- `
  31.208 +    read id mem cpu vcpu state tm < <(echo "$rest")
  31.209 +}
  31.210 +
  31.211 +is_running()
  31.212 +{
  31.213 +    rdname $1
  31.214 +    RC=1
  31.215 +    while read LN; do
  31.216 +	parseln "$LN"
  31.217 +	if test $id = 0; then continue; fi
  31.218 +	case $name in 
  31.219 +	    ($NM)
  31.220 +		RC=0
  31.221 +		;;
  31.222 +	esac
  31.223 +    done < <(xm list | grep -v '^Name')
  31.224 +    return $RC
  31.225 +}
  31.226 +
  31.227 +start() 
  31.228 +{
  31.229 +    if [ -f $LOCKFILE ]; then 
  31.230 +	echo -n "xendomains already running (lockfile exists)"
  31.231 +	return; 
  31.232 +    fi
  31.233 +
  31.234 +    if [ "$XENDOMAINS_RESTORE" = "true" ] &&
  31.235 +       contains_something "$XENDOMAINS_SAVE"
  31.236 +    then
  31.237 +        mkdir -p $(dirname "$LOCKFILE")
  31.238  	touch $LOCKFILE
  31.239 -	
  31.240 -       # Create all domains with config files in AUTODIR.
  31.241 -	for dom in  $AUTODIR/*; do
  31.242 -	    xm create --quiet --defconfig $dom
  31.243 +	echo -n "Restoring Xen domains:"
  31.244 +	for dom in $XENDOMAINS_SAVE/*; do
  31.245 +	    echo -n " ${dom##*/}"
  31.246 +	    xm restore $dom
  31.247  	    if [ $? -ne 0 ]; then
  31.248 -		RETVAL=$?
  31.249 +		rc_failed $?
  31.250 +		echo -n '!'
  31.251 +	    else
  31.252 +		# mv $dom ${dom%/*}/.${dom##*/}
  31.253 +		rm $dom
  31.254  	    fi
  31.255  	done
  31.256 -
  31.257      fi
  31.258  
  31.259 -    on_fn_exit
  31.260 +    if contains_something "$XENDOMAINS_AUTO"
  31.261 +    then
  31.262 +	touch $LOCKFILE
  31.263 +	echo -n "Starting auto Xen domains:"
  31.264 +	# We expect config scripts for auto starting domains to be in
  31.265 +	# XENDOMAINS_AUTO - they could just be symlinks to files elsewhere
  31.266 +
  31.267 +	# Create all domains with config files in XENDOMAINS_AUTO.
  31.268 +	# TODO: We should record which domain name belongs 
  31.269 +	# so we have the option to selectively shut down / migrate later
  31.270 +	for dom in $XENDOMAINS_AUTO/*; do
  31.271 +	    echo -n " ${dom##*/}"
  31.272 +	    if is_running $dom; then
  31.273 +		echo -n "(skip)"
  31.274 +	    else
  31.275 +		xm create --quiet --defconfig $dom
  31.276 +		if [ $? -ne 0 ]; then
  31.277 +		    rc_failed $?
  31.278 +		    echo -n '!'
  31.279 +		fi
  31.280 +	    fi
  31.281 +	done
  31.282 +    fi	
  31.283 +}
  31.284 +
  31.285 +all_zombies()
  31.286 +{
  31.287 +    while read LN; do
  31.288 +	parseln "$LN"
  31.289 +	if test $id = 0; then continue; fi
  31.290 +	if test "$state" != "-b---d" -a "$state" != "-----d"; then
  31.291 +	    return 1;
  31.292 +	fi
  31.293 +    done < <(xm list | grep -v '^Name')
  31.294 +    return 0
  31.295 +}
  31.296 +
  31.297 +# Wait for max $XENDOMAINS_STOP_MAXWAIT for xm $1 to finish;
  31.298 +# if it has not exited by that time kill it, so the init script will
  31.299 +# succeed within a finite amount of time; if $2 is nonnull, it will
  31.300 +# kill the command as well as soon as no domain (except for zombies)
  31.301 +# are left (used for shutdown --all).
  31.302 +watchdog_xm()
  31.303 +{
  31.304 +    if test -z "$XENDOMAINS_STOP_MAXWAIT" -o "$XENDOMAINS_STOP_MAXWAIT" = "0"; then
  31.305 +	exit
  31.306 +    fi
  31.307 +    usleep 20000
  31.308 +    for no in `seq 0 $XENDOMAINS_STOP_MAXWAIT`; do
  31.309 +	# exit if xm save/migrate/shutdown is finished
  31.310 +	PSAX=`ps axlw | grep "xm $1" | grep -v grep`
  31.311 +	if test -z "$PSAX"; then exit; fi
  31.312 +	echo -n "."; sleep 1
  31.313 +	# go to kill immediately if there's only zombies left
  31.314 +	if all_zombies && test -n "$2"; then break; fi
  31.315 +    done
  31.316 +    sleep 1
  31.317 +    read PSF PSUID PSPID PSPPID < <(echo "$PSAX")
  31.318 +    # kill xm $1
  31.319 +    kill $PSPID >/dev/null 2>&1
  31.320  }
  31.321  
  31.322  stop()
  31.323  {
  31.324 +    # Collect list of domains to shut down
  31.325 +    if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
  31.326 +	rdnames
  31.327 +    fi
  31.328 +    echo -n "Shutting down Xen domains:"
  31.329 +    while read LN; do
  31.330 +	parseln "$LN"
  31.331 +	if test $id = 0; then continue; fi
  31.332 +	echo -n " $name"
  31.333 +	if test "$XENDOMAINS_AUTO_ONLY" = "true"; then
  31.334 +	    case $name in
  31.335 +		($NAMES)
  31.336 +		    # nothing
  31.337 +		    ;;
  31.338 +		(*)
  31.339 +		    echo -n "(skip)"
  31.340 +		    continue
  31.341 +		    ;;
  31.342 +	    esac
  31.343 +	fi
  31.344 +	# XENDOMAINS_SYSRQ chould be something like just "s" 
  31.345 +	# or "s e i u" or even "s e s i u o"
  31.346 +	# for the latter, you should set XENDOMAINS_USLEEP to 1200000 or so
  31.347 +	if test -n "$XENDOMAINS_SYSRQ"; then
  31.348 +	    for sysrq in $XENDOMAINS_SYSRQ; do
  31.349 +		echo -n "(SR-$sysrq)"
  31.350 +		xm sysrq $id $sysrq
  31.351 +		if test $? -ne 0; then
  31.352 +		    rc_failed $?
  31.353 +		    echo -n '!'
  31.354 +		fi
  31.355 +		# usleep just ignores empty arg
  31.356 +		usleep $XENDOMAINS_USLEEP
  31.357 +	    done
  31.358 +	fi
  31.359 +	if test "$state" = "-b---d" -o "$state" = "-----d"; then
  31.360 +	    echo -n "(zomb)"
  31.361 +	    continue
  31.362 +	fi
  31.363 +	if test -n "$XENDOMAINS_MIGRATE"; then
  31.364 +	    echo -n "(migr)"
  31.365 +	    watchdog_xm migrate &
  31.366 +	    WDOG_PID=$!
  31.367 +	    xm migrate $id $XENDOMAINS_MIGRATE
  31.368 +	    if test $? -ne 0; then
  31.369 +		rc_failed $?
  31.370 +		echo -n '!'
  31.371 +		kill $WDOG_PID >/dev/null 2>&1
  31.372 +	    else
  31.373 +		kill $WDOG_PID >/dev/null 2>&1
  31.374 +		continue
  31.375 +	    fi
  31.376 +	fi
  31.377 +	if test -n "$XENDOMAINS_SAVE"; then
  31.378 +	    echo -n "(save)"
  31.379 +	    watchdog_xm save &
  31.380 +	    WDOG_PID=$!
  31.381 +	    xm save $id $XENDOMAINS_SAVE/$name
  31.382 +	    if test $? -ne 0; then
  31.383 +		rc_failed $?
  31.384 +		echo -n '!'
  31.385 +		kill $WDOG_PIG >/dev/null 2>&1
  31.386 +	    else
  31.387 +		kill $WDOG_PIG >/dev/null 2>&1
  31.388 +		continue
  31.389 +	    fi
  31.390 +	fi
  31.391 +	if test -n "$XENDOMAINS_SHUTDOWN"; then
  31.392 +	    # XENDOMAINS_SHUTDOWN should be "--halt --wait"
  31.393 +	    echo -n "(shut)"
  31.394 +	    watchdog_xm shutdown &
  31.395 +	    WDOG_PID=$!
  31.396 +	    xm shutdown $id $XENDOMAINS_SHUTDOWN
  31.397 +	    if test $? -ne 0; then
  31.398 +		rc_failed $?
  31.399 +		echo -n '!'
  31.400 +	    fi
  31.401 +	    kill $WDOG_PIG >/dev/null 2>&1
  31.402 +	fi
  31.403 +    done < <(xm list | grep -v '^Name')
  31.404 +
  31.405      # NB. this shuts down ALL Xen domains (politely), not just the ones in
  31.406      # AUTODIR/*
  31.407      # This is because it's easier to do ;-) but arguably if this script is run
  31.408      # on system shutdown then it's also the right thing to do.
  31.409 -    
  31.410 -    echo -n $"Shutting down all Xen domains:"
  31.411 +    if ! all_zombies && test -n "$XENDOMAINS_SHUTDOWN_ALL"; then
  31.412 +	# XENDOMAINS_SHUTDOWN_ALL should be "--all --halt --wait"
  31.413 +	echo -n " SHUTDOWN_ALL "
  31.414 +	watchdog_xm shutdown 1 &
  31.415 +	WDOG_PID=$!
  31.416 +	xm shutdown $XENDOMAINS_SHUTDOWN_ALL
  31.417 +	if test $? -ne 0; then
  31.418 +	    rc_failed $?
  31.419 +	    echo -n '!'
  31.420 +	fi
  31.421 +	kill $WDOG_PID >/dev/null 2>&1
  31.422 +    fi
  31.423  
  31.424 -    xm shutdown --all --wait --halt
  31.425 +    # Unconditionally delete lock file
  31.426 +    rm -f $LOCKFILE
  31.427 +}
  31.428 +
  31.429 +check_domain_up()
  31.430 +{
  31.431 +    while read LN; do
  31.432 +	parseln "$LN"
  31.433 +	if test $id = 0; then continue; fi
  31.434 +	case $name in 
  31.435 +	    ($1)
  31.436 +		return 0
  31.437 +		;;
  31.438 +	esac
  31.439 +    done < <(xm list | grep -v "^Name")
  31.440 +    return 1
  31.441 +}
  31.442  
  31.443 -    RETVAL=$?
  31.444 +check_all_auto_domains_up()
  31.445 +{
  31.446 +    if ! contains_something "$XENDOMAINS_AUTO"
  31.447 +    then
  31.448 +      return 0
  31.449 +    fi
  31.450 +    missing=
  31.451 +    for nm in $XENDOMAINS_AUTO/*; do
  31.452 +	rdname $nm
  31.453 +	found=0
  31.454 +	if check_domain_up "$NM"; then 
  31.455 +	    echo -n " $name"
  31.456 +	else 
  31.457 +	    missing="$missing $NM"
  31.458 +	fi
  31.459 +    done
  31.460 +    if test -n "$missing"; then
  31.461 +	echo -n " MISS AUTO:$missing"
  31.462 +	return 1
  31.463 +    fi
  31.464 +    return 0
  31.465 +}
  31.466  
  31.467 -    [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
  31.468 -
  31.469 -    on_fn_exit
  31.470 +check_all_saved_domains_up()
  31.471 +{
  31.472 +    if ! contains_something "$XENDOMAINS_SAVE" 
  31.473 +    then
  31.474 +      return 0
  31.475 +    fi
  31.476 +    missing=`/bin/ls $XENDOMAINS_SAVE`
  31.477 +    echo -n " MISS SAVED: " $missing
  31.478 +    return 1
  31.479  }
  31.480  
  31.481  # This does NOT necessarily restart all running domains: instead it
  31.482 @@ -124,47 +441,56 @@ stop()
  31.483  # AUTODIR.  If other domains have been started manually then they will
  31.484  # not get restarted.
  31.485  # Commented out to avoid confusion!
  31.486 -#
  31.487 -#restart()
  31.488 -#{
  31.489 -#    stop
  31.490 -#    start
  31.491 -#}
  31.492  
  31.493 -# same as restart for now - commented out to avoid confusion
  31.494 -#reload()
  31.495 -#{
  31.496 -#    restart
  31.497 -#}
  31.498 +restart()
  31.499 +{
  31.500 +    stop
  31.501 +    start
  31.502 +}
  31.503 +
  31.504 +reload()
  31.505 +{
  31.506 +    restart
  31.507 +}
  31.508  
  31.509  
  31.510  case "$1" in
  31.511      start)
  31.512  	start
  31.513 +	rc_status
  31.514 +	if test -f $LOCKFILE; then rc_status -v; fi
  31.515  	;;
  31.516  
  31.517      stop)
  31.518  	stop
  31.519 +	rc_status -v
  31.520 +	;;
  31.521 +
  31.522 +    restart)
  31.523 +	restart
  31.524 +	;;
  31.525 +    reload)
  31.526 +	reload
  31.527  	;;
  31.528  
  31.529 -# The following are commented out to disable them by default to avoid confusion
  31.530 -# - see the notes above
  31.531 -#
  31.532 -#    restart)
  31.533 -#	restart
  31.534 -#	;;
  31.535 -#
  31.536 -#    reload)
  31.537 -#	reload
  31.538 -#	;;
  31.539 -
  31.540      status)
  31.541 -	xm list
  31.542 +	echo -n "Checking for xendomains:" 
  31.543 +	if test ! -f $LOCKFILE; then 
  31.544 +	    rc_failed 3
  31.545 +	else
  31.546 +	    check_all_auto_domains_up
  31.547 +	    rc_status
  31.548 +	    check_all_saved_domains_up
  31.549 +	    rc_status
  31.550 +	fi
  31.551 +	rc_status -v
  31.552  	;;
  31.553  
  31.554      *)
  31.555 -	echo $"Usage: $0 {start|stop|status}"
  31.556 +	echo "Usage: $0 {start|stop|restart|reload|status}"
  31.557 +	rc_failed 3
  31.558 +	rc_status -v
  31.559  	;;
  31.560  esac
  31.561  
  31.562 -exit $RETVAL
  31.563 +rc_exit
    32.1 --- a/tools/examples/network-bridge	Mon Oct 24 21:00:35 2005 -0600
    32.2 +++ b/tools/examples/network-bridge	Sat Oct 29 09:51:35 2005 +0100
    32.3 @@ -208,7 +208,7 @@ op_start () {
    32.4  
    32.5      if ip link show ${vdev} 2>/dev/null >/dev/null; then
    32.6  	mac=`ip link show ${netdev} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
    32.7 -	eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- ${netdev}`
    32.8 +	preiftransfer ${netdev}
    32.9  	transfer_addrs ${netdev} ${vdev}
   32.10  	if ! ifdown ${netdev}; then
   32.11  	    # if ifup didn't work, see if we have an ip= on cmd line
   32.12 @@ -231,7 +231,7 @@ op_start () {
   32.13  	ip link set ${bridge} up
   32.14  	ip link set ${vif0} up
   32.15  	ip link set ${pdev} up 
   32.16 -	if ! ifup ${HWD_CONFIG_0} ${netdev} ; then
   32.17 +	if ! ifup ${netdev} ; then
   32.18  	    if [ ${kip} ] ; then
   32.19  		# use the addresses we grocked from /proc/cmdline
   32.20  		if [ -z "${kmask}" ]; then 
    33.1 --- a/tools/examples/xen-hotplug-common.sh	Mon Oct 24 21:00:35 2005 -0600
    33.2 +++ b/tools/examples/xen-hotplug-common.sh	Sat Oct 29 09:51:35 2005 +0100
    33.3 @@ -1,3 +1,21 @@
    33.4 +#
    33.5 +# Copyright (c) 2005 XenSource Ltd.
    33.6 +#
    33.7 +# This library is free software; you can redistribute it and/or
    33.8 +# modify it under the terms of version 2.1 of the GNU Lesser General Public
    33.9 +# License as published by the Free Software Foundation.
   33.10 +#
   33.11 +# This library is distributed in the hope that it will be useful,
   33.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   33.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   33.14 +# Lesser General Public License for more details.
   33.15 +#
   33.16 +# You should have received a copy of the GNU Lesser General Public
   33.17 +# License along with this library; if not, write to the Free Software
   33.18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   33.19 +#
   33.20 +
   33.21 +
   33.22  set -e
   33.23  
   33.24  export PATH="/sbin:/bin:/usr/bin:/usr/sbin:$PATH"
    34.1 --- a/tools/examples/xen-network-common.sh	Mon Oct 24 21:00:35 2005 -0600
    34.2 +++ b/tools/examples/xen-network-common.sh	Sat Oct 29 09:51:35 2005 +0100
    34.3 @@ -16,11 +16,40 @@
    34.4  #
    34.5  
    34.6  
    34.7 -# Gentoo doesn't have ifup/ifdown: define appropriate alternatives
    34.8 -if ! which ifup >&/dev/null
    34.9 +# On SuSE it is necessary to run a command before transfering addresses and
   34.10 +# routes from the physical interface to the virtual.  This command creates a
   34.11 +# variable $HWD_CONFIG_0 that specifies the appropriate configuration for
   34.12 +# ifup.
   34.13 +
   34.14 +# Gentoo doesn't have ifup/ifdown, so we define appropriate alternatives.
   34.15 +
   34.16 +# Other platforms just use ifup / ifdown directly.
   34.17 +
   34.18 +##
   34.19 +# preiftransfer
   34.20 +#
   34.21 +# @param $1 The current name for the physical device, which is also the name
   34.22 +#           that the virtual device will take once the physical device has
   34.23 +#           been renamed.
   34.24 +
   34.25 +if [ -e /etc/SuSE-release ]
   34.26 +then
   34.27 +  preiftransfer()
   34.28 +  {
   34.29 +    eval `/sbin/getcfg -d /etc/sysconfig/network/ -f ifcfg- -- $1`
   34.30 +  }
   34.31 +  ifup()
   34.32 +  {
   34.33 +    /sbin/ifup ${HWD_CONFIG_0} $1
   34.34 +  }
   34.35 +elif ! which ifup >&/dev/null
   34.36  then
   34.37    if [ -e /etc/conf.d/net ]
   34.38    then
   34.39 +    preiftransfer()
   34.40 +    {
   34.41 +      true
   34.42 +    }
   34.43      ifup()
   34.44      {
   34.45        /etc/init.d/net.$1 start
   34.46 @@ -34,4 +63,9 @@ then
   34.47        "You don't have ifup and don't seem to be running Gentoo either!"
   34.48      exit 1
   34.49    fi
   34.50 +else
   34.51 +  preiftransfer()
   34.52 +  {
   34.53 +    true
   34.54 +  }
   34.55  fi
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/tools/examples/xmexample.nbd	Sat Oct 29 09:51:35 2005 +0100
    35.3 @@ -0,0 +1,23 @@
    35.4 +#  -*- mode: python; -*-
    35.5 +#
    35.6 +# xm create configuration example.
    35.7 +#
    35.8 +# This configuration is appropriate for using Network Block Device (NBD)
    35.9 +# filesystems.
   35.10 +#
   35.11 +# Each of these parameters will need changing to match your setup.
   35.12 +# 
   35.13 +
   35.14 +kernel = "/boot/vmlinuz-2.6.13-15b-xen"
   35.15 +ramdisk = "/boot/initrd-2.6.13-15b-xen"
   35.16 +memory = 128
   35.17 +name = "nbd4"
   35.18 +nics=1
   35.19 +# Please change MAC
   35.20 +vif = [ 'mac=aa:cc:10:10:00:a0, bridge=xenbr0' ]
   35.21 +# Please change PORT
   35.22 +disk = [ 'nbd:134.100.233.115 20004,hda1,w' ]
   35.23 +dhcp = "dhcp"
   35.24 +hostname= "nbd4" 
   35.25 +root = "/dev/hda1 ro"
   35.26 +extra = "3"
    36.1 --- a/tools/ioemu/hw/ide.c	Mon Oct 24 21:00:35 2005 -0600
    36.2 +++ b/tools/ioemu/hw/ide.c	Sat Oct 29 09:51:35 2005 +0100
    36.3 @@ -22,6 +22,7 @@
    36.4   * THE SOFTWARE.
    36.5   */
    36.6  #include "vl.h"
    36.7 +#include <pthread.h>
    36.8  
    36.9  /* debug IDE devices */
   36.10  //#define DEBUG_IDE
   36.11 @@ -360,6 +361,48 @@ typedef struct PCIIDEState {
   36.12      BMDMAState bmdma[2];
   36.13  } PCIIDEState;
   36.14  
   36.15 +#define DMA_MULTI_THREAD
   36.16 +
   36.17 +#ifdef DMA_MULTI_THREAD
   36.18 +
   36.19 +static int file_pipes[2];
   36.20 +
   36.21 +static void ide_dma_loop(BMDMAState *bm);
   36.22 +static void dma_thread_loop(BMDMAState *bm);
   36.23 +
   36.24 +static void *dma_thread_func(void* opaque)
   36.25 +{
   36.26 +    BMDMAState* req;
   36.27 +
   36.28 +    while (read(file_pipes[0], &req, sizeof(req))) {
   36.29 +        dma_thread_loop(req);
   36.30 +    }
   36.31 +
   36.32 +    return NULL;
   36.33 +}
   36.34 +
   36.35 +static void dma_create_thread()
   36.36 +{
   36.37 +    pthread_t tid;
   36.38 +    int rt;
   36.39 +
   36.40 +    if (pipe(file_pipes) != 0){
   36.41 +        fprintf(stderr, "create pipe failed\n");
   36.42 +        exit(1);
   36.43 +    }
   36.44 +
   36.45 +    if ( (rt = pthread_create(&tid, NULL, dma_thread_func, NULL)) ) {
   36.46 +        fprintf(stderr, "Oops, dma thread creation failed, errno=%d\n", rt);
   36.47 +        exit(1);
   36.48 +    }
   36.49 +
   36.50 +    if ( (rt = pthread_detach(tid)) ) {
   36.51 +        fprintf(stderr, "Oops, dma thread detachment failed, errno=%d\n", rt);
   36.52 +        exit(1);
   36.53 +    }
   36.54 +}
   36.55 +#endif //DMA_MULTI_THREAD
   36.56 +
   36.57  static void ide_dma_start(IDEState *s, IDEDMAFunc *dma_cb);
   36.58  
   36.59  static void padstr(char *str, const char *src, int len)
   36.60 @@ -1978,8 +2021,16 @@ static void ide_map(PCIDevice *pci_dev, 
   36.61  
   36.62  /* XXX: full callback usage to prepare non blocking I/Os support -
   36.63     error handling */
   36.64 +#ifdef DMA_MULTI_THREAD
   36.65  static void ide_dma_loop(BMDMAState *bm)
   36.66  {
   36.67 +    write(file_pipes[1], &bm, sizeof(bm));
   36.68 +}
   36.69 +static void dma_thread_loop(BMDMAState *bm)
   36.70 +#else 
   36.71 +static void ide_dma_loop(BMDMAState *bm)
   36.72 +#endif //DMA_MULTI_THREAD
   36.73 +{
   36.74      struct {
   36.75          uint32_t addr;
   36.76          uint32_t size;
   36.77 @@ -2166,6 +2217,9 @@ void pci_ide_init(PCIBus *bus, BlockDriv
   36.78          d->ide_if[i].pci_dev = (PCIDevice *)d;
   36.79      ide_init2(&d->ide_if[0], 16, hd_table[0], hd_table[1]);
   36.80      ide_init2(&d->ide_if[2], 16, hd_table[2], hd_table[3]);
   36.81 +#ifdef DMA_MULTI_THREAD    
   36.82 +    dma_create_thread();
   36.83 +#endif //DMA_MULTI_THREAD    
   36.84  }
   36.85  
   36.86  /* hd_table must contain 4 block drivers */
   36.87 @@ -2196,6 +2250,9 @@ void pci_piix3_ide_init(PCIBus *bus, Blo
   36.88      ide_init2(&d->ide_if[2], 15, hd_table[2], hd_table[3]);
   36.89      ide_init_ioport(&d->ide_if[0], 0x1f0, 0x3f6);
   36.90      ide_init_ioport(&d->ide_if[2], 0x170, 0x376);
   36.91 +#ifdef DMA_MULTI_THREAD    
   36.92 +    dma_create_thread();
   36.93 +#endif //DMA_MULTI_THREAD    
   36.94  }
   36.95  
   36.96  /***********************************************************/
    37.1 --- a/tools/libxc/xc_elf.h	Mon Oct 24 21:00:35 2005 -0600
    37.2 +++ b/tools/libxc/xc_elf.h	Sat Oct 29 09:51:35 2005 +0100
    37.3 @@ -24,26 +24,26 @@
    37.4   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    37.5   */
    37.6  
    37.7 -typedef u_int8_t	Elf_Byte;
    37.8 +typedef uint8_t		Elf_Byte;
    37.9  
   37.10 -typedef u_int32_t	Elf32_Addr;	/* Unsigned program address */
   37.11 -typedef u_int32_t	Elf32_Off;	/* Unsigned file offset */
   37.12 +typedef uint32_t	Elf32_Addr;	/* Unsigned program address */
   37.13 +typedef uint32_t	Elf32_Off;	/* Unsigned file offset */
   37.14  typedef int32_t		Elf32_Sword;	/* Signed large integer */
   37.15 -typedef u_int32_t	Elf32_Word;	/* Unsigned large integer */
   37.16 -typedef u_int16_t	Elf32_Half;	/* Unsigned medium integer */
   37.17 +typedef uint32_t	Elf32_Word;	/* Unsigned large integer */
   37.18 +typedef uint16_t	Elf32_Half;	/* Unsigned medium integer */
   37.19  
   37.20 -typedef u_int64_t	Elf64_Addr;
   37.21 -typedef u_int64_t	Elf64_Off;
   37.22 +typedef uint64_t	Elf64_Addr;
   37.23 +typedef uint64_t	Elf64_Off;
   37.24  typedef int32_t		Elf64_Shalf;
   37.25  
   37.26  typedef int32_t		Elf64_Sword;
   37.27 -typedef u_int32_t	Elf64_Word;
   37.28 +typedef uint32_t	Elf64_Word;
   37.29  
   37.30  typedef int64_t		Elf64_Sxword;
   37.31 -typedef u_int64_t	Elf64_Xword;
   37.32 +typedef uint64_t	Elf64_Xword;
   37.33  
   37.34 -typedef u_int32_t	Elf64_Half;
   37.35 -typedef u_int16_t	Elf64_Quarter;
   37.36 +typedef uint32_t	Elf64_Half;
   37.37 +typedef uint16_t	Elf64_Quarter;
   37.38  
   37.39  /*
   37.40   * e_ident[] identification indexes 
    38.1 --- a/tools/libxc/xc_linux_build.c	Mon Oct 24 21:00:35 2005 -0600
    38.2 +++ b/tools/libxc/xc_linux_build.c	Sat Oct 29 09:51:35 2005 +0100
    38.3 @@ -350,6 +350,8 @@ static int setup_guest(int xc_handle,
    38.4      start_info = xc_map_foreign_range(
    38.5          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE, page_array[0]);
    38.6      memset(start_info, 0, sizeof(*start_info));
    38.7 +    rc = xc_version(xc_handle, XENVER_version, NULL);
    38.8 +    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
    38.9      start_info->flags        = flags;
   38.10      start_info->store_mfn    = nr_pages - 2;
   38.11      start_info->store_evtchn = store_evtchn;
   38.12 @@ -624,6 +626,8 @@ static int setup_guest(int xc_handle,
   38.13          xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
   38.14          page_array[(vstartinfo_start-dsi.v_start)>>PAGE_SHIFT]);
   38.15      memset(start_info, 0, sizeof(*start_info));
   38.16 +    rc = xc_version(xc_handle, XENVER_version, NULL);
   38.17 +    sprintf(start_info->magic, "Xen-%i.%i", rc >> 16, rc & (0xFFFF));
   38.18      start_info->nr_pages     = nr_pages;
   38.19      start_info->shared_info  = shared_info_frame << PAGE_SHIFT;
   38.20      start_info->flags        = flags;
    39.1 --- a/tools/libxc/xc_vmx_build.c	Mon Oct 24 21:00:35 2005 -0600
    39.2 +++ b/tools/libxc/xc_vmx_build.c	Sat Oct 29 09:51:35 2005 +0100
    39.3 @@ -279,6 +279,7 @@ static int setup_guest(int xc_handle,
    39.4                         vcpu_guest_context_t *ctxt,
    39.5                         unsigned long shared_info_frame,
    39.6                         unsigned int control_evtchn,
    39.7 +                       unsigned int lapic,
    39.8                         unsigned int vcpus,
    39.9                         unsigned int store_evtchn,
   39.10                         unsigned long *store_mfn)
   39.11 @@ -554,7 +555,7 @@ static int setup_guest(int xc_handle,
   39.12      ctxt->user_regs.eax = 0;
   39.13      ctxt->user_regs.esp = 0;
   39.14      ctxt->user_regs.ebx = 0; /* startup_32 expects this to be 0 to signal boot cpu */
   39.15 -    ctxt->user_regs.ecx = 0;
   39.16 +    ctxt->user_regs.ecx = lapic;
   39.17      ctxt->user_regs.esi = 0;
   39.18      ctxt->user_regs.edi = 0;
   39.19      ctxt->user_regs.ebp = 0;
   39.20 @@ -597,6 +598,7 @@ int xc_vmx_build(int xc_handle,
   39.21                   int memsize,
   39.22                   const char *image_name,
   39.23                   unsigned int control_evtchn,
   39.24 +                 unsigned int lapic,
   39.25                   unsigned int vcpus,
   39.26                   unsigned int store_evtchn,
   39.27                   unsigned long *store_mfn)
   39.28 @@ -651,9 +653,9 @@ int xc_vmx_build(int xc_handle,
   39.29          goto error_out;
   39.30      }
   39.31  
   39.32 -    if ( setup_guest(xc_handle, domid, memsize, image, image_size,
   39.33 -                     nr_pages, ctxt, op.u.getdomaininfo.shared_info_frame,
   39.34 -                     control_evtchn, vcpus, store_evtchn, store_mfn) < 0)
   39.35 +    if ( setup_guest(xc_handle, domid, memsize, image, image_size, nr_pages,
   39.36 +                     ctxt, op.u.getdomaininfo.shared_info_frame, control_evtchn,
   39.37 +                     lapic, vcpus, store_evtchn, store_mfn) < 0)
   39.38      {
   39.39          ERROR("Error constructing guest OS");
   39.40          goto error_out;
    40.1 --- a/tools/libxc/xenguest.h	Mon Oct 24 21:00:35 2005 -0600
    40.2 +++ b/tools/libxc/xenguest.h	Sat Oct 29 09:51:35 2005 +0100
    40.3 @@ -56,6 +56,7 @@ int xc_vmx_build(int xc_handle,
    40.4                   int memsize,
    40.5                   const char *image_name,
    40.6                   unsigned int control_evtchn,
    40.7 +                 unsigned int lapic,
    40.8                   unsigned int vcpus,
    40.9                   unsigned int store_evtchn,
   40.10                   unsigned long *store_mfn);
    41.1 --- a/tools/misc/cpuperf/cpuperf.c	Mon Oct 24 21:00:35 2005 -0600
    41.2 +++ b/tools/misc/cpuperf/cpuperf.c	Sat Oct 29 09:51:35 2005 +0100
    41.3 @@ -16,7 +16,6 @@
    41.4  
    41.5  #include <sys/types.h>
    41.6  #include <sched.h>
    41.7 -#include <error.h>
    41.8  #include <stdio.h>
    41.9  #include <unistd.h>
   41.10  #include <stdlib.h>
    42.1 --- a/tools/misc/miniterm/miniterm.c	Mon Oct 24 21:00:35 2005 -0600
    42.2 +++ b/tools/misc/miniterm/miniterm.c	Sat Oct 29 09:51:35 2005 +0100
    42.3 @@ -29,7 +29,7 @@
    42.4  #include <stdlib.h>
    42.5  #include <unistd.h>
    42.6  #include <fcntl.h>
    42.7 -#include <sys/signal.h>
    42.8 +#include <signal.h>
    42.9  #include <sys/types.h>
   42.10  #include <sys/wait.h>
   42.11  
    43.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Mon Oct 24 21:00:35 2005 -0600
    43.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Sat Oct 29 09:51:35 2005 +0100
    43.3 @@ -438,19 +438,20 @@ static PyObject *pyxc_vmx_build(PyObject
    43.4      char *image;
    43.5      int control_evtchn, store_evtchn;
    43.6      int vcpus = 1;
    43.7 +    int lapic = 0;
    43.8      int memsize;
    43.9      unsigned long store_mfn = 0;
   43.10  
   43.11      static char *kwd_list[] = { "dom", "control_evtchn", "store_evtchn",
   43.12 -                                "memsize", "image", "vcpus", NULL };
   43.13 +                                "memsize", "image", "lapic", "vcpus", NULL };
   43.14  
   43.15 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisi", kwd_list,
   43.16 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iiiisii", kwd_list,
   43.17                                        &dom, &control_evtchn, &store_evtchn,
   43.18 -                                      &memsize, &image, &vcpus) )
   43.19 +                                      &memsize, &image, &lapic, &vcpus) )
   43.20          return NULL;
   43.21  
   43.22      if ( xc_vmx_build(xc->xc_handle, dom, memsize, image, control_evtchn,
   43.23 -                      vcpus, store_evtchn, &store_mfn) != 0 )
   43.24 +                      lapic, vcpus, store_evtchn, &store_mfn) != 0 )
   43.25          return PyErr_SetFromErrno(xc_error);
   43.26  
   43.27      return Py_BuildValue("{s:i}", "store_mfn", store_mfn);
    44.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Mon Oct 24 21:00:35 2005 -0600
    44.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Sat Oct 29 09:51:35 2005 +0100
    44.3 @@ -695,7 +695,7 @@ static PyObject *xspy_introduce_domain(P
    44.4                                         PyObject *kwds)
    44.5  {
    44.6      static char *kwd_spec[] = { "dom", "page", "port", NULL };
    44.7 -    static char *arg_spec = "iii";
    44.8 +    static char *arg_spec = "ili";
    44.9      domid_t dom = 0;
   44.10      unsigned long page = 0;
   44.11      unsigned int port = 0;
    45.1 --- a/tools/python/xen/web/tcp.py	Mon Oct 24 21:00:35 2005 -0600
    45.2 +++ b/tools/python/xen/web/tcp.py	Sat Oct 29 09:51:35 2005 +0100
    45.3 @@ -99,7 +99,7 @@ def listenTCP(port, factory, interface='
    45.4      return l
    45.5  
    45.6  def SetCloExec(SocketListener):
    45.7 -    SocketListener.SetCloExec()
    45.8 +    SocketListener.setCloExec()
    45.9  
   45.10  def connectTCP(host, port, factory, timeout=None, bindAddress=None):
   45.11      c = TCPConnector(host, port, factory, timeout=timeout, bindAddress=bindAddress)
    46.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Mon Oct 24 21:00:35 2005 -0600
    46.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Sat Oct 29 09:51:35 2005 +0100
    46.3 @@ -595,6 +595,7 @@ class XendDomainInfo:
    46.4          to_store = {
    46.5              'domid':              str(self.domid),
    46.6              'vm':                 self.vmpath,
    46.7 +            'name':               self.info['name'],
    46.8              'console/limit':      str(xroot.get_console_limit() * 1024),
    46.9              'memory/target':      str(self.info['memory_KiB'])
   46.10              }
    47.1 --- a/tools/python/xen/xend/image.py	Mon Oct 24 21:00:35 2005 -0600
    47.2 +++ b/tools/python/xen/xend/image.py	Sat Oct 29 09:51:35 2005 +0100
    47.3 @@ -203,6 +203,10 @@ class VmxImageHandler(ImageHandler):
    47.4  
    47.5          self.dmargs += self.configVNC(imageConfig)
    47.6  
    47.7 +        self.lapic = 0
    47.8 +        lapic = sxp.child_value(imageConfig, 'lapic')
    47.9 +        if not lapic is None:
   47.10 +            self.lapic = int(lapic)
   47.11  
   47.12      def buildDomain(self):
   47.13          # Create an event channel
   47.14 @@ -217,6 +221,7 @@ class VmxImageHandler(ImageHandler):
   47.15          log.debug("control_evtchn = %d", self.device_channel)
   47.16          log.debug("store_evtchn   = %d", store_evtchn)
   47.17          log.debug("memsize        = %d", self.vm.getMemoryTarget() / 1024)
   47.18 +        log.debug("lapic          = %d", self.lapic)
   47.19          log.debug("vcpus          = %d", self.vm.getVCpuCount())
   47.20  
   47.21          return xc.vmx_build(dom            = self.vm.getDomid(),
   47.22 @@ -224,6 +229,7 @@ class VmxImageHandler(ImageHandler):
   47.23                              control_evtchn = self.device_channel,
   47.24                              store_evtchn   = store_evtchn,
   47.25                              memsize        = self.vm.getMemoryTarget() / 1024,
   47.26 +                            lapic          = self.lapic,
   47.27                              vcpus          = self.vm.getVCpuCount())
   47.28  
   47.29  
    48.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Mon Oct 24 21:00:35 2005 -0600
    48.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Sat Oct 29 09:51:35 2005 +0100
    48.3 @@ -262,10 +262,7 @@ class Daemon:
    48.4              return 1
    48.5  
    48.6      def stop(self):
    48.7 -        result = self.cleanup_xend(True)
    48.8 -        from xen.xend import Vifctl
    48.9 -        Vifctl.network("stop")
   48.10 -        return result
   48.11 +        return self.cleanup_xend(True)
   48.12  
   48.13      def run(self, status):
   48.14          try:
    49.1 --- a/tools/python/xen/xend/server/SrvDomainDir.py	Mon Oct 24 21:00:35 2005 -0600
    49.2 +++ b/tools/python/xen/xend/server/SrvDomainDir.py	Sat Oct 29 09:51:35 2005 +0100
    49.3 @@ -25,7 +25,6 @@ from xen.xend import XendDomain
    49.4  from xen.xend.XendDomainInfo import XendDomainInfo
    49.5  from xen.xend.Args import FormFn
    49.6  from xen.xend.XendError import XendError
    49.7 -from xen.xend.XendLogging import log
    49.8  
    49.9  from xen.web.SrvDir import SrvDir
   49.10  from SrvDomain import SrvDomain
   49.11 @@ -52,7 +51,7 @@ class SrvDomainDir(SrvDir):
   49.12          else:
   49.13              return self.domain(x)
   49.14  
   49.15 -    def op_create(self, op, req):
   49.16 +    def op_create(self, _, req):
   49.17          """Create a domain.
   49.18          Expects the domain config in request parameter 'config' in SXP format.
   49.19          """
   49.20 @@ -66,12 +65,12 @@ class SrvDomainDir(SrvDir):
   49.21              pin.input_eof()
   49.22              config = pin.get_val()
   49.23              ok = 1
   49.24 +        except sxp.ParseError, ex:
   49.25 +            errmsg = 'Invalid configuration ' + str(ex)
   49.26          except Exception, ex:
   49.27              print 'op_create> Exception in config', ex
   49.28              traceback.print_exc()
   49.29              errmsg = 'Configuration error ' + str(ex)
   49.30 -        except sxp.ParseError, ex:
   49.31 -            errmsg = 'Invalid configuration ' + str(ex)
   49.32          if not ok:
   49.33              raise XendError(errmsg)
   49.34          try:
   49.35 @@ -108,7 +107,7 @@ class SrvDomainDir(SrvDir):
   49.36          """
   49.37          return req.threadRequest(self.do_restore, op, req)
   49.38  
   49.39 -    def do_restore(self, op, req):
   49.40 +    def do_restore(self, _, req):
   49.41          fn = FormFn(self.xd.domain_restore,
   49.42                      [['file', 'str']])
   49.43          dominfo = fn(req.args)
    50.1 --- a/tools/python/xen/xend/server/event.py	Mon Oct 24 21:00:35 2005 -0600
    50.2 +++ b/tools/python/xen/xend/server/event.py	Sat Oct 29 09:51:35 2005 +0100
    50.3 @@ -192,4 +192,5 @@ def listenEvent(daemon):
    50.4      if xroot.get_xend_http_server():
    50.5          port = xroot.get_xend_event_port()
    50.6          interface = xroot.get_xend_address()
    50.7 -        tcp.listenTCP(port, factory, interface=interface)
    50.8 +        l = tcp.listenTCP(port, factory, interface=interface)
    50.9 +        l.setCloExec()
    51.1 --- a/tools/python/xen/xend/xenstore/xstransact.py	Mon Oct 24 21:00:35 2005 -0600
    51.2 +++ b/tools/python/xen/xend/xenstore/xstransact.py	Sat Oct 29 09:51:35 2005 +0100
    51.3 @@ -5,9 +5,6 @@
    51.4  # Public License.  See the file "COPYING" in the main directory of
    51.5  # this archive for more details.
    51.6  
    51.7 -import errno
    51.8 -import threading
    51.9 -from xen.lowlevel import xs
   51.10  from xen.xend.xenstore.xsutil import xshandle
   51.11  
   51.12  
    52.1 --- a/tools/python/xen/xm/create.py	Mon Oct 24 21:00:35 2005 -0600
    52.2 +++ b/tools/python/xen/xm/create.py	Sat Oct 29 09:51:35 2005 +0100
    52.3 @@ -158,6 +158,10 @@ gopts.var('cpu', val='CPU',
    52.4            fn=set_int, default=None,
    52.5            use="CPU to run the domain on.")
    52.6  
    52.7 +gopts.var('lapic', val='LAPIC',
    52.8 +          fn=set_int, default=0,
    52.9 +          use="Disable or enable local APIC of VMX domain.")
   52.10 +
   52.11  gopts.var('vcpus', val='VCPUS',
   52.12            fn=set_int, default=1,
   52.13            use="# of Virtual CPUS in domain.")
   52.14 @@ -316,10 +320,6 @@ gopts.var('nfs_root', val="PATH",
   52.15            fn=set_value, default=None,
   52.16            use="Set the path of the root NFS directory.")
   52.17  
   52.18 -gopts.var('memmap', val='FILE',
   52.19 -          fn=set_value, default='',
   52.20 -          use="Path to memap SXP file.")
   52.21 -
   52.22  gopts.var('device_model', val='FILE',
   52.23            fn=set_value, default='',
   52.24            use="Path to device model program.")
   52.25 @@ -542,9 +542,9 @@ def configure_vfr(opts, config, vals):
   52.26  def configure_vmx(opts, config_image, vals):
   52.27      """Create the config for VMX devices.
   52.28      """
   52.29 -    args = [ 'memmap', 'device_model', 'vcpus', 'cdrom',
   52.30 -             'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', 
   52.31 -             'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display', 'ne2000']
   52.32 +    args = [ 'device_model', 'vcpus', 'cdrom', 'boot', 'fda', 'fdb',
   52.33 +             'localtime', 'serial', 'macaddr', 'stdvga', 'isa', 'nographic',
   52.34 +             'vnc', 'vncviewer', 'sdl', 'display', 'ne2000', 'lapic']
   52.35      for a in args:
   52.36          if (vals.__dict__[a]):
   52.37              config_image.append([a, vals.__dict__[a]])
    53.1 --- a/tools/python/xen/xm/main.py	Mon Oct 24 21:00:35 2005 -0600
    53.2 +++ b/tools/python/xen/xm/main.py	Sat Oct 29 09:51:35 2005 +0100
    53.3 @@ -61,6 +61,8 @@ xm common subcommands:
    53.4      top                     monitor system and domains in real-time
    53.5      unpause <DomId>         unpause a paused domain
    53.6  
    53.7 +<DomName> can be substituted for <DomId> in xm subcommands.
    53.8 +
    53.9  For a complete list of subcommands run 'xm help --long'
   53.10  For more help on xm see the xm(1) man page
   53.11  For more help on xm create, see the xmdomain.cfg(5) man page"""
   53.12 @@ -119,6 +121,8 @@ xm full list of subcommands:
   53.13      vnet-create <config>       create a vnet from a config file
   53.14      vnet-delete <vnetid>       delete a vnet
   53.15  
   53.16 +<DomName> can be substituted for <DomId> in xm subcommands.
   53.17 +
   53.18  For a short list of subcommands run 'xm help'
   53.19  For more help on xm see the xm(1) man page
   53.20  For more help on xm create, see the xmdomain.cfg(5) man page"""
    54.1 --- a/tools/security/getlabel.sh	Mon Oct 24 21:00:35 2005 -0600
    54.2 +++ b/tools/security/getlabel.sh	Sat Oct 29 09:51:35 2005 +0100
    54.3 @@ -36,18 +36,21 @@ source labelfuncs.sh
    54.4  
    54.5  usage ()
    54.6  {
    54.7 -	echo "Usage: $0 -sid <ssidref> [<policy name>] or"
    54.8 -	echo "       $0 -dom <domid>   [<policy name>]  "
    54.9 -	echo ""
   54.10 -	echo "policy name : the name of the policy, i.e. 'chwall'"
   54.11 -	echo "              If the policy name is omitted, the grub.conf"
   54.12 -	echo "              entry of the running system is tried to be read"
   54.13 -	echo "              and the policy name determined from there."
   54.14 -	echo "ssidref     : an ssidref in hex or decimal format, i.e., '0x00010002'"
   54.15 -	echo "              or '65538'"
   54.16 -	echo "domid       : id of the domain, i.e., '1'; Use numbers from the 2nd"
   54.17 -	echo "              column shown when invoking 'xm list'"
   54.18 -	echo ""
   54.19 +echo "Use this tool to display the label of a domain or the label that is
   54.20 +corresponding to an ssidref given the name of the running policy.
   54.21 +
   54.22 +Usage: $0 -sid <ssidref> [<policy name>] or
   54.23 +       $0 -dom <domid>   [<policy name>]
   54.24 +
   54.25 +policy name : the name of the policy, i.e. 'chwall'
   54.26 +              If the policy name is omitted, the grub.conf
   54.27 +              entry of the running system is tried to be read
   54.28 +              and the policy name determined from there.
   54.29 +ssidref     : an ssidref in hex or decimal format, i.e., '0x00010002'
   54.30 +              or '65538'
   54.31 +domid       : id of the domain, i.e., '1'; Use numbers from the 2nd
   54.32 +              column shown when invoking 'xm list'
   54.33 +"
   54.34  }
   54.35  
   54.36  
    55.1 --- a/tools/security/setlabel.sh	Mon Oct 24 21:00:35 2005 -0600
    55.2 +++ b/tools/security/setlabel.sh	Sat Oct 29 09:51:35 2005 +0100
    55.3 @@ -39,21 +39,27 @@ source labelfuncs.sh
    55.4  
    55.5  usage ()
    55.6  {
    55.7 -	echo "Usage: $0 [Option] <vmfile> <label> [<policy name>]"
    55.8 -	echo "    or $0 -l [<policy name>]"
    55.9 -	echo ""
   55.10 -	echo "Valid options are:"
   55.11 -	echo "-r          : to relabel a file without being prompted"
   55.12 -	echo ""
   55.13 -	echo "vmfile      : XEN vm configuration file"
   55.14 -	echo "label       : the label to map to an ssidref"
   55.15 -	echo "policy name : the name of the policy, i.e. 'chwall'"
   55.16 -	echo "              If the policy name is omitted, it is attempted"
   55.17 -	echo "              to find the current policy's name in grub.conf."
   55.18 -	echo ""
   55.19 -	echo "-l [<policy name>] is used to show valid labels in the map file of"
   55.20 -	echo "                   the given or current policy."
   55.21 -	echo ""
   55.22 +echo "Use this tool to put the ssidref corresponding to a label of a policy into
   55.23 +the VM configuration file, or use it to display all labels of a policy.
   55.24 +
   55.25 +Usage: $0 [Option] <vmfile> <label> [<policy name>]
   55.26 +    or $0 -l [<policy name>]
   55.27 +
   55.28 +Valid options are:
   55.29 +-r          : to relabel a file without being prompted
   55.30 +
   55.31 +vmfile      : XEN vm configuration file; give complete path
   55.32 +label       : the label to map to an ssidref
   55.33 +policy name : the name of the policy, i.e. 'chwall'
   55.34 +              If the policy name is omitted, it is attempted
   55.35 +              to find the current policy's name in grub.conf.
   55.36 +
   55.37 +-l [<policy name>] is used to show valid labels in the map file of
   55.38 +                   the given or current policy. If the policy name
   55.39 +                   is omitted, it will be tried to determine the
   55.40 +                   current policy from grub.conf (/boot/grub/grub.conf)
   55.41 +
   55.42 +"
   55.43  }
   55.44  
   55.45  
   55.46 @@ -83,7 +89,7 @@ if [ "$mode" == "show" ]; then
   55.47  			exit -1;
   55.48  		fi
   55.49  	else
   55.50 -		policy=$3;
   55.51 +		policy=$1;
   55.52  	fi
   55.53  
   55.54  
   55.55 @@ -92,7 +98,7 @@ if [ "$mode" == "show" ]; then
   55.56  	if [ "$res" != "0" ]; then
   55.57  		showLabels $mapfile
   55.58  	else
   55.59 -		echo "Could not find map file for policy '$1'."
   55.60 +		echo "Could not find map file for policy '$policy'."
   55.61  	fi
   55.62  elif [ "$mode" == "usage" ]; then
   55.63  	usage
    56.1 --- a/tools/security/updategrub.sh	Mon Oct 24 21:00:35 2005 -0600
    56.2 +++ b/tools/security/updategrub.sh	Sat Oct 29 09:51:35 2005 +0100
    56.3 @@ -26,11 +26,16 @@ fi
    56.4  # Show usage of this program
    56.5  usage ()
    56.6  {
    56.7 -	echo "Usage: $0 <policy name> <root of xen repository>"
    56.8 -	echo ""
    56.9 -	echo "<policy name>             : The name of the policy, i.e. xen_null"
   56.10 -	echo "<root of xen repository>  : The root of the XEN repositrory."
   56.11 -	echo ""
   56.12 +echo "Use this tool to add the binary policy to the Xen grub entry and
   56.13 +have Xen automatically enforce the policy when starting.
   56.14 +
   56.15 +Usage: $0 <policy name> <root of xen repository>
   56.16 +
   56.17 +<policy name>             : The name of the policy, i.e. xen_null
   56.18 +<root of xen repository>  : The root of the XEN repository. Give
   56.19 +                            complete path.
   56.20 +
   56.21 +"
   56.22  }
   56.23  
   56.24  # This function sets the global variable 'linux'
   56.25 @@ -43,11 +48,24 @@ getLinuxVersion ()
   56.26  	for f in $path/linux-*-xen0 ; do
   56.27  		versionfile=$f/include/linux/version.h
   56.28  		if [ -r $versionfile ]; then
   56.29 -			lnx=`cat $versionfile | \
   56.30 -			     grep UTS_RELEASE | \
   56.31 -			     awk '{             \
   56.32 -			       len=length($3);  \
   56.33 -			       print substr($3,2,len-2) }'`
   56.34 +			lnx=`cat $versionfile |                \
   56.35 +			     grep UTS_RELEASE |                \
   56.36 +			     awk '{                            \
   56.37 +			       len=length($3);                 \
   56.38 +			       version=substr($3,2,len-2);     \
   56.39 +			       split(version,numbers,".");     \
   56.40 +			       if (numbers[4]=="") {           \
   56.41 +			         printf("%s.%s.%s",            \
   56.42 +			                 numbers[1],           \
   56.43 +			                 numbers[2],           \
   56.44 +			                 numbers[3]);          \
   56.45 +			       } else {                        \
   56.46 +			         printf("%s.%s.%s[.0-9]*-xen0",\
   56.47 +			                numbers[1],            \
   56.48 +			                numbers[2],            \
   56.49 +			                numbers[3]);           \
   56.50 +			       }                               \
   56.51 +			     }'`
   56.52  		fi
   56.53  		if [ "$lnx" != "" ]; then
   56.54  			linux="[./0-9a-zA-z]*$lnx"
   56.55 @@ -143,10 +161,19 @@ updateGrub ()
   56.56  		echo "Could not create temporary file! Aborting."
   56.57  		exit -1
   56.58  	fi
   56.59 -	mv -f $tmpfile $grubconf
   56.60 +	diff $tmpfile $grubconf > /dev/null
   56.61 +	RES=$?
   56.62 +	if [ "$RES" == "0" ]; then
   56.63 +		echo "No changes were made to $grubconf."
   56.64 +	else
   56.65 +		echo "Successfully updated $grubconf."
   56.66 +		mv -f $tmpfile $grubconf
   56.67 +	fi
   56.68  }
   56.69  
   56.70  if [ "$1" == "" -o "$2" == "" ]; then
   56.71 +	echo "Error: Not enough command line parameters."
   56.72 +	echo ""
   56.73  	usage
   56.74  	exit -1
   56.75  fi
    57.1 --- a/tools/xenstat/libxenstat/Makefile	Mon Oct 24 21:00:35 2005 -0600
    57.2 +++ b/tools/xenstat/libxenstat/Makefile	Sat Oct 29 09:51:35 2005 +0100
    57.3 @@ -38,13 +38,13 @@ SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.
    57.4  
    57.5  WARN_FLAGS=-Wall -Werror
    57.6  
    57.7 -CFLAGS+=-Isrc -I$(XEN_LIBXC)
    57.8 +CFLAGS+=-Isrc -I$(XEN_LIBXC) -I$(XEN_XENSTORE)
    57.9  LDFLAGS+=-Lsrc
   57.10  
   57.11  all: $(LIB)
   57.12  
   57.13  $(LIB): $(OBJECTS)
   57.14 -	$(AR) rc $@ $^
   57.15 +	$(AR) rc $@ $^ $(XEN_XENSTORE)/libxenstore.so
   57.16  	$(RANLIB) $@
   57.17  
   57.18  $(SHLIB): $(OBJECTS)
    58.1 --- a/tools/xenstat/libxenstat/src/xenstat.c	Mon Oct 24 21:00:35 2005 -0600
    58.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Sat Oct 29 09:51:35 2005 +0100
    58.3 @@ -21,6 +21,7 @@
    58.4  #include <string.h>
    58.5  #include <unistd.h>
    58.6  #include <xen-interface.h>
    58.7 +#include <xs.h>
    58.8  #include "xenstat.h"
    58.9  
   58.10  /*
   58.11 @@ -31,6 +32,7 @@
   58.12  
   58.13  struct xenstat_handle {
   58.14  	xi_handle *xihandle;
   58.15 +	struct xs_handle *xshandle; /* xenstore handle */
   58.16  	int page_size;
   58.17  	FILE *procnetdev;
   58.18  	char xen_version[VERSION_SIZE]; /* xen version running on this node */
   58.19 @@ -49,6 +51,7 @@ struct xenstat_node {
   58.20  
   58.21  struct xenstat_domain {
   58.22  	unsigned int id;
   58.23 +	char *name;
   58.24  	unsigned int state;
   58.25  	unsigned long long cpu_ns;
   58.26  	unsigned int num_vcpus;		/* No. vcpus configured for domain */
   58.27 @@ -110,6 +113,7 @@ static void xenstat_free_xen_version(xen
   58.28  static void xenstat_uninit_vcpus(xenstat_handle * handle);
   58.29  static void xenstat_uninit_networks(xenstat_handle * handle);
   58.30  static void xenstat_uninit_xen_version(xenstat_handle * handle);
   58.31 +static char *xenstat_get_domain_name(xenstat_handle * handle, unsigned int domain_id);
   58.32  
   58.33  static xenstat_collector collectors[] = {
   58.34  	{ XENSTAT_VCPU, xenstat_collect_vcpus,
   58.35 @@ -153,6 +157,13 @@ xenstat_handle *xenstat_init()
   58.36  		return NULL;
   58.37  	}
   58.38  
   58.39 +	handle->xshandle = xs_daemon_open_readonly(); /* open handle to xenstore*/
   58.40 +	if (handle->xshandle == NULL) {
   58.41 +		perror("unable to open xenstore\n");
   58.42 +		free(handle);
   58.43 +		return NULL;
   58.44 +	}
   58.45 +
   58.46  	return handle;
   58.47  }
   58.48  
   58.49 @@ -163,6 +174,7 @@ void xenstat_uninit(xenstat_handle * han
   58.50  		for (i = 0; i < NUM_COLLECTORS; i++)
   58.51  			collectors[i].uninit(handle);
   58.52  		xi_uninit(handle->xihandle);
   58.53 +		xs_daemon_close(handle->xshandle);
   58.54  		free(handle);
   58.55  	}
   58.56  }
   58.57 @@ -228,6 +240,7 @@ xenstat_node *xenstat_get_node(xenstat_h
   58.58  		for (i = 0; i < new_domains; i++) {
   58.59  			/* Fill in domain using domaininfo[i] */
   58.60  			domain->id = domaininfo[i].domain;
   58.61 +			domain->name = xenstat_get_domain_name(handle, domaininfo[i].domain);
   58.62  			domain->state = domaininfo[i].flags;
   58.63  			domain->cpu_ns = domaininfo[i].cpu_time;
   58.64  			domain->num_vcpus = (domaininfo[i].max_vcpu_id+1);
   58.65 @@ -339,6 +352,12 @@ unsigned xenstat_domain_id(xenstat_domai
   58.66  	return domain->id;
   58.67  }
   58.68  
   58.69 +/* Get the domain name for the domain */
   58.70 +char *xenstat_domain_name(xenstat_domain * domain)
   58.71 +{
   58.72 +	return domain->name;
   58.73 +}
   58.74 +
   58.75  /* Get information about how much CPU time has been used */
   58.76  unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
   58.77  {
   58.78 @@ -675,3 +694,25 @@ static void xenstat_free_xen_version(xen
   58.79  static void xenstat_uninit_xen_version(xenstat_handle * handle)
   58.80  {
   58.81  }
   58.82 +
   58.83 +static char *xenstat_get_domain_name(xenstat_handle *handle, unsigned int domain_id)
   58.84 +{
   58.85 +	char path[80];
   58.86 +	char *name;
   58.87 +	unsigned int *len;
   58.88 +	struct xs_transaction_handle *xstranshandle;
   58.89 +
   58.90 +	snprintf(path, sizeof(path),"/local/domain/%i/name", domain_id);
   58.91 +	
   58.92 +	xstranshandle = xs_transaction_start(handle->xshandle);
   58.93 +	if (xstranshandle == NULL) {
   58.94 +		perror("Unable to get transcation handle from xenstore\n");
   58.95 +		exit(1); /* Change this */
   58.96 +	}
   58.97 +
   58.98 +	name = (char *) xs_read(handle->xshandle, xstranshandle, path, len);
   58.99 +	
  58.100 +	xs_transaction_end(handle->xshandle, xstranshandle, false);
  58.101 +
  58.102 +	return name;
  58.103 +}	
    59.1 --- a/tools/xenstat/libxenstat/src/xenstat.h	Mon Oct 24 21:00:35 2005 -0600
    59.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h	Sat Oct 29 09:51:35 2005 +0100
    59.3 @@ -80,6 +80,9 @@ unsigned long long xenstat_node_cpu_hz(x
    59.4  /* Get the domain ID for this domain */
    59.5  unsigned xenstat_domain_id(xenstat_domain * domain);
    59.6  
    59.7 +/* Set the domain name for the domain */
    59.8 +char *xenstat_domain_name(xenstat_domain * domain);
    59.9 +
   59.10  /* Get information about how much CPU time has been used */
   59.11  unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain);
   59.12  
    60.1 --- a/tools/xenstat/xentop/xentop.c	Mon Oct 24 21:00:35 2005 -0600
    60.2 +++ b/tools/xenstat/xentop/xentop.c	Sat Oct 29 09:51:35 2005 +0100
    60.3 @@ -67,8 +67,6 @@ static int compare_domains(xenstat_domai
    60.4  static unsigned long long tot_net_bytes( xenstat_domain *, int);
    60.5  
    60.6  /* Field functions */
    60.7 -static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2);
    60.8 -static void print_domid(xenstat_domain *domain);
    60.9  static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2);
   60.10  static void print_state(xenstat_domain *domain);
   60.11  static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2);
   60.12 @@ -91,6 +89,8 @@ static int compare_net_rx(xenstat_domain
   60.13  static void print_net_rx(xenstat_domain *domain);
   60.14  static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2);
   60.15  static void print_ssid(xenstat_domain *domain);
   60.16 +static int compare_name(xenstat_domain *domain1, xenstat_domain *domain2);
   60.17 +static void print_name(xenstat_domain *domain);
   60.18  
   60.19  /* Section printing functions */
   60.20  static void do_summary(void);
   60.21 @@ -104,6 +104,7 @@ static void top(void);
   60.22  /* Field types */
   60.23  typedef enum field_id {
   60.24  	FIELD_DOMID,
   60.25 +	FIELD_NAME,
   60.26  	FIELD_STATE,
   60.27  	FIELD_CPU,
   60.28  	FIELD_CPU_PCT,
   60.29 @@ -127,7 +128,7 @@ typedef struct field {
   60.30  } field;
   60.31  
   60.32  field fields[] = {
   60.33 -	{ FIELD_DOMID,   "DOMID",      5, compare_domid,   print_domid   },
   60.34 +	{ FIELD_NAME,    "NAME",      10, compare_name,    print_name    },
   60.35  	{ FIELD_STATE,   "STATE",      6, compare_state,   print_state   },
   60.36  	{ FIELD_CPU,     "CPU(sec)",  10, compare_cpu,     print_cpu     },
   60.37  	{ FIELD_CPU_PCT, "CPU(%)",     6, compare_cpu_pct, print_cpu_pct },
   60.38 @@ -344,16 +345,16 @@ static int compare_domains(xenstat_domai
   60.39  
   60.40  /* Field functions */
   60.41  
   60.42 -/* Compares domain ids of two domains, returning -1,0,1 for <,=,> */
   60.43 -int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2)
   60.44 +/* Compare domain names, returning -1,0,1 for <,=,> */
   60.45 +int compare_name(xenstat_domain *domain1, xenstat_domain *domain2)
   60.46  {
   60.47 -	return compare(xenstat_domain_id(domain1), xenstat_domain_id(domain2));
   60.48 +	return strcasecmp(xenstat_domain_name(domain1), xenstat_domain_name(domain2));
   60.49  }
   60.50  
   60.51 -/* Prints domain identification number */
   60.52 -void print_domid(xenstat_domain *domain)
   60.53 +/* Prints domain name */
   60.54 +void print_name(xenstat_domain *domain)
   60.55  {
   60.56 -	print("%5u", xenstat_domain_id(domain));
   60.57 +	print("%10s", xenstat_domain_name(domain));
   60.58  }
   60.59  
   60.60  struct {
    61.1 --- a/tools/xenstore/Makefile	Mon Oct 24 21:00:35 2005 -0600
    61.2 +++ b/tools/xenstore/Makefile	Sat Oct 29 09:51:35 2005 +0100
    61.3 @@ -77,7 +77,7 @@ libxenstore.so: xs.opic xs_lib.opic
    61.4  clean: testsuite-clean
    61.5  	rm -f *.o *.opic *.so
    61.6  	rm -f xenstored xs_random xs_stress xs_crashme
    61.7 -	rm -f xs_test xenstored_test
    61.8 +	rm -f xs_test xenstored_test xs_tdb_dump
    61.9  	$(RM) $(PROG_DEP)
   61.10  
   61.11  print-dir:
    62.1 --- a/tools/xenstore/xenstored_core.c	Mon Oct 24 21:00:35 2005 -0600
    62.2 +++ b/tools/xenstore/xenstored_core.c	Sat Oct 29 09:51:35 2005 +0100
    62.3 @@ -188,7 +188,7 @@ static void trace_io(const struct connec
    62.4  	tm = localtime(&now);
    62.5  
    62.6  	write(tracefd, prefix, strlen(prefix));
    62.7 -	sprintf(string, " %p %0d:%0d:%0d ", conn, tm->tm_hour, tm->tm_min,
    62.8 +	sprintf(string, " %p %02d:%02d:%02d ", conn, tm->tm_hour, tm->tm_min,
    62.9  		tm->tm_sec);
   62.10  	write(tracefd, string, strlen(string));
   62.11  	write(tracefd, sockmsg_string(data->hdr.msg.type),
    63.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c	Mon Oct 24 21:00:35 2005 -0600
    63.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c	Sat Oct 29 09:51:35 2005 +0100
    63.3 @@ -392,8 +392,11 @@ check_cache(struct domain *dom, domid_t 
    63.4      int i;
    63.5  
    63.6      printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom);
    63.7 +
    63.8 +    if (dom->ssid == NULL)
    63.9 +        return 0;
   63.10      ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   63.11 -                         (struct acm_ssid_domain *)(dom)->ssid);
   63.12 +                         (struct acm_ssid_domain *)(dom->ssid));
   63.13  
   63.14      for(i=0; i< ACM_TE_CACHE_SIZE; i++) {
   63.15          if ((ste_ssid->ste_cache[i].valid == VALID) &&
   63.16 @@ -412,6 +415,8 @@ cache_result(struct domain *subj, struct
   63.17      struct ste_ssid *ste_ssid;
   63.18      int i;
   63.19      printkd("caching from doms: %x --> %x.\n", subj->domain_id, obj->domain_id);
   63.20 +    if (subj->ssid == NULL)
   63.21 +        return;
   63.22      ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   63.23                           (struct acm_ssid_domain *)(subj)->ssid);
   63.24      for(i=0; i< ACM_TE_CACHE_SIZE; i++)
   63.25 @@ -431,26 +436,34 @@ clean_id_from_cache(domid_t id)
   63.26      struct ste_ssid *ste_ssid;
   63.27      int i;
   63.28      struct domain **pd;
   63.29 +    struct acm_ssid_domain *ssid;
   63.30  
   63.31      printkd("deleting cache for dom %x.\n", id);
   63.32 -
   63.33      read_lock(&domlist_lock); /* look through caches of all domains */
   63.34      pd = &domain_list;
   63.35      for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
   63.36 -        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   63.37 -                             (struct acm_ssid_domain *)(*pd)->ssid);
   63.38 +        ssid = (struct acm_ssid_domain *)((*pd)->ssid);
   63.39 +
   63.40 +        if (ssid == NULL)
   63.41 +            continue; /* hanging domain structure, no ssid any more ... */
   63.42 +        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssid);
   63.43 +        if (!ste_ssid) {
   63.44 +            printk("%s: deleting ID from cache ERROR (no ste_ssid)!\n",
   63.45 +                   __func__);
   63.46 +            goto out;
   63.47 +        }
   63.48          for (i=0; i<ACM_TE_CACHE_SIZE; i++)
   63.49              if ((ste_ssid->ste_cache[i].valid == VALID) &&
   63.50 -                (ste_ssid->ste_cache[i].id = id))
   63.51 +                (ste_ssid->ste_cache[i].id == id))
   63.52                  ste_ssid->ste_cache[i].valid = FREE;
   63.53      }
   63.54 + out:
   63.55      read_unlock(&domlist_lock);
   63.56  }
   63.57  
   63.58  /***************************
   63.59   * Authorization functions
   63.60   **************************/
   63.61 -
   63.62  static int 
   63.63  ste_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
   63.64  {      
   63.65 @@ -484,44 +497,13 @@ ste_post_domain_destroy(void *subject_ss
   63.66  
   63.67  /* -------- EVENTCHANNEL OPERATIONS -----------*/
   63.68  static int
   63.69 -ste_pre_eventchannel_unbound(domid_t id) {
   63.70 -    struct domain *subj, *obj;
   63.71 -    int ret;
   63.72 -    traceprintk("%s: dom%x-->dom%x.\n", 
   63.73 -                __func__, current->domain->domain_id, id);
   63.74 -
   63.75 -    if (check_cache(current->domain, id)) {
   63.76 -        atomic_inc(&ste_bin_pol.ec_cachehit_count);
   63.77 -        return ACM_ACCESS_PERMITTED;
   63.78 -    }
   63.79 -    atomic_inc(&ste_bin_pol.ec_eval_count);
   63.80 -    subj = current->domain;
   63.81 -    obj = find_domain_by_id(id);
   63.82 -
   63.83 -    if (share_common_type(subj, obj)) {
   63.84 -        cache_result(subj, obj);
   63.85 -        ret = ACM_ACCESS_PERMITTED;
   63.86 -    } else {
   63.87 -        atomic_inc(&ste_bin_pol.ec_denied_count); 
   63.88 -        ret = ACM_ACCESS_DENIED; 
   63.89 -    }
   63.90 -    if (obj != NULL)
   63.91 -        put_domain(obj);
   63.92 -    return ret;
   63.93 -}
   63.94 -
   63.95 -static int
   63.96 -ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
   63.97 -{
   63.98 +ste_pre_eventchannel_unbound(domid_t id1, domid_t id2) {
   63.99      struct domain *subj, *obj;
  63.100      int ret;
  63.101      traceprintk("%s: dom%x-->dom%x.\n", __func__,
  63.102                  (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
  63.103                  (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
  63.104  
  63.105 -    /* following is a bit longer but ensures that we
  63.106 -     * "put" only domains that we where "find"-ing 
  63.107 -     */
  63.108      if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
  63.109      if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
  63.110  
  63.111 @@ -531,7 +513,7 @@ ste_pre_eventchannel_interdomain(domid_t
  63.112          ret = ACM_ACCESS_DENIED;
  63.113          goto out;
  63.114      }
  63.115 -    /* cache check late, but evtchn is not on performance critical path */
  63.116 +    /* cache check late */
  63.117      if (check_cache(subj, obj->domain_id)) {
  63.118          atomic_inc(&ste_bin_pol.ec_cachehit_count);
  63.119          ret = ACM_ACCESS_PERMITTED;
  63.120 @@ -546,7 +528,7 @@ ste_pre_eventchannel_interdomain(domid_t
  63.121          atomic_inc(&ste_bin_pol.ec_denied_count); 
  63.122          ret = ACM_ACCESS_DENIED; 
  63.123      }
  63.124 - out:
  63.125 +  out:
  63.126      if (obj != NULL)
  63.127          put_domain(obj);
  63.128      if (subj != NULL)
  63.129 @@ -554,6 +536,50 @@ ste_pre_eventchannel_interdomain(domid_t
  63.130      return ret;
  63.131  }
  63.132  
  63.133 +static int
  63.134 +ste_pre_eventchannel_interdomain(domid_t id)
  63.135 +{
  63.136 +    struct domain *subj=NULL, *obj=NULL;
  63.137 +    int ret;
  63.138 +
  63.139 +    traceprintk("%s: dom%x-->dom%x.\n", __func__,
  63.140 +                current->domain->domain_id,
  63.141 +                (id == DOMID_SELF) ? current->domain->domain_id : id);
  63.142 +
  63.143 +    /* following is a bit longer but ensures that we
  63.144 +     * "put" only domains that we where "find"-ing 
  63.145 +     */
  63.146 +    if (id == DOMID_SELF) id = current->domain->domain_id;
  63.147 +
  63.148 +    subj = current->domain;
  63.149 +    obj  = find_domain_by_id(id);
  63.150 +    if (obj == NULL) {
  63.151 +        ret = ACM_ACCESS_DENIED;
  63.152 +        goto out;
  63.153 +    }
  63.154 +
  63.155 +    /* cache check late, but evtchn is not on performance critical path */
  63.156 +    if (check_cache(subj, obj->domain_id)) {
  63.157 +        atomic_inc(&ste_bin_pol.ec_cachehit_count);
  63.158 +        ret = ACM_ACCESS_PERMITTED;
  63.159 +        goto out;
  63.160 +    }
  63.161 +
  63.162 +    atomic_inc(&ste_bin_pol.ec_eval_count);
  63.163 +
  63.164 +    if (share_common_type(subj, obj)) {
  63.165 +        cache_result(subj, obj);
  63.166 +        ret = ACM_ACCESS_PERMITTED;
  63.167 +    } else {
  63.168 +        atomic_inc(&ste_bin_pol.ec_denied_count); 
  63.169 +        ret = ACM_ACCESS_DENIED; 
  63.170 +    }
  63.171 + out:
  63.172 +    if (obj != NULL)
  63.173 +        put_domain(obj);
  63.174 +    return ret;
  63.175 +}
  63.176 +
  63.177  /* -------- SHARED MEMORY OPERATIONS -----------*/
  63.178  
  63.179  static int
    64.1 --- a/xen/arch/ia64/xen/domain.c	Mon Oct 24 21:00:35 2005 -0600
    64.2 +++ b/xen/arch/ia64/xen/domain.c	Sat Oct 29 09:51:35 2005 +0100
    64.3 @@ -29,6 +29,7 @@
    64.4  #include <xen/event.h>
    64.5  //#include <xen/shadow.h>
    64.6  #include <xen/console.h>
    64.7 +#include <xen/compile.h>
    64.8  
    64.9  #include <xen/elf.h>
   64.10  //#include <asm/page.h>
   64.11 @@ -948,6 +949,7 @@ int construct_dom0(struct domain *d,
   64.12  	si = (start_info_t *)alloc_xenheap_page();
   64.13  	memset(si, 0, PAGE_SIZE);
   64.14  	d->shared_info->arch.start_info_pfn = __pa(si) >> PAGE_SHIFT;
   64.15 +	sprintf(si->magic, "Xen-%i.%i", XEN_VERSION, XEN_SUBVERSION);
   64.16  
   64.17  #if 0
   64.18  	si->nr_pages     = d->tot_pages;
    65.1 --- a/xen/arch/x86/apic.c	Mon Oct 24 21:00:35 2005 -0600
    65.2 +++ b/xen/arch/x86/apic.c	Sat Oct 29 09:51:35 2005 +0100
    65.3 @@ -815,6 +815,10 @@ int __init calibrate_APIC_clock(void)
    65.4      return result;
    65.5  }
    65.6  
    65.7 +unsigned int get_apic_bus_scale(void)
    65.8 +{
    65.9 +    return bus_scale;
   65.10 +}
   65.11  
   65.12  static unsigned int calibration_result;
   65.13  
    66.1 --- a/xen/arch/x86/dm/i8259.c	Mon Oct 24 21:00:35 2005 -0600
    66.2 +++ b/xen/arch/x86/dm/i8259.c	Sat Oct 29 09:51:35 2005 +0100
    66.3 @@ -32,8 +32,8 @@
    66.4  #include <public/io/ioreq.h>
    66.5  #include <asm/vmx.h>
    66.6  #include <public/io/vmx_vpic.h>
    66.7 -#include <public/io/vmx_vlapic.h>
    66.8  #include <asm/current.h>
    66.9 +#include <asm/vmx_vlapic.h>
   66.10  
   66.11  /* set irq level. If an edge is detected, then the IRR is set to 1 */
   66.12  static inline void pic_set_irq1(PicState *s, int irq, int level)
   66.13 @@ -135,7 +135,6 @@ void do_pic_irqs (struct vmx_virpic *s, 
   66.14  {
   66.15      s->pics[1].irr |= (uint8_t)(irqs >> 8);
   66.16      s->pics[0].irr |= (uint8_t) irqs;
   66.17 -    /* TODO for alt_irq_func */
   66.18      pic_update_irq(s);
   66.19  }
   66.20  
   66.21 @@ -505,14 +504,22 @@ int cpu_get_pic_interrupt(struct vcpu *v
   66.22  {
   66.23      int intno;
   66.24      struct vmx_virpic *s = &v->domain->arch.vmx_platform.vmx_pic;
   66.25 -    
   66.26 +    struct vmx_platform *plat = &v->domain->arch.vmx_platform;
   66.27 +
   66.28 +    if ( !vlapic_accept_pic_intr(v) )
   66.29 +        return -1;
   66.30 +
   66.31 +    if ( !plat->interrupt_request )
   66.32 +        return -1;
   66.33 +
   66.34      /* read the irq from the PIC */
   66.35      intno = pic_read_irq(s);
   66.36      *type = VLAPIC_DELIV_MODE_EXT;
   66.37 +    plat->interrupt_request = 0;
   66.38      return intno;
   66.39  }
   66.40  
   66.41 -int is_pit_irq(struct vcpu *v, int irq)
   66.42 +int is_pit_irq(struct vcpu *v, int irq, int type)
   66.43  {
   66.44      int  pit_vec = v->domain->arch.vmx_platform.vmx_pic.pics[0].irq_base;
   66.45  
    67.1 --- a/xen/arch/x86/domain_build.c	Mon Oct 24 21:00:35 2005 -0600
    67.2 +++ b/xen/arch/x86/domain_build.c	Sat Oct 29 09:51:35 2005 +0100
    67.3 @@ -15,6 +15,7 @@
    67.4  #include <xen/elf.h>
    67.5  #include <xen/kernel.h>
    67.6  #include <xen/domain.h>
    67.7 +#include <xen/compile.h>
    67.8  #include <asm/regs.h>
    67.9  #include <asm/system.h>
   67.10  #include <asm/io.h>
   67.11 @@ -582,26 +583,23 @@ int construct_dom0(struct domain *d,
   67.12              _initrd_start, (_initrd_start+initrd_len+PAGE_SIZE-1) & PAGE_MASK);
   67.13      }
   67.14  
   67.15 -    d->next_io_page = max_page;
   67.16 -
   67.17      /* Set up start info area. */
   67.18      si = (start_info_t *)vstartinfo_start;
   67.19      memset(si, 0, PAGE_SIZE);
   67.20      si->nr_pages = nr_pages;
   67.21  
   67.22 +    si->shared_info = virt_to_phys(d->shared_info);
   67.23      if ( opt_dom0_translate )
   67.24      {
   67.25 -        si->shared_info  = d->next_io_page << PAGE_SHIFT;
   67.26 -        set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, d->next_io_page);
   67.27 -        d->next_io_page++;
   67.28 +        si->shared_info  = max_page << PAGE_SHIFT;
   67.29 +        set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, max_page);
   67.30      }
   67.31 -    else
   67.32 -        si->shared_info  = virt_to_phys(d->shared_info);
   67.33  
   67.34      si->flags        = SIF_PRIVILEGED | SIF_INITDOMAIN;
   67.35      si->pt_base      = vpt_start;
   67.36      si->nr_pt_frames = nr_pt_pages;
   67.37      si->mfn_list     = vphysmap_start;
   67.38 +    sprintf(si->magic, "Xen-%i.%i", XEN_VERSION, XEN_SUBVERSION);
   67.39  
   67.40      /* Write the phys->machine and machine->phys table entries. */
   67.41      for ( pfn = 0; pfn < d->tot_pages; pfn++ )
    68.1 --- a/xen/arch/x86/mm.c	Mon Oct 24 21:00:35 2005 -0600
    68.2 +++ b/xen/arch/x86/mm.c	Sat Oct 29 09:51:35 2005 +0100
    68.3 @@ -1164,6 +1164,7 @@ static int mod_l3_entry(l3_pgentry_t *pl
    68.4  {
    68.5      l3_pgentry_t ol3e;
    68.6      unsigned long vaddr;
    68.7 +    int okay;
    68.8  
    68.9      if ( unlikely(!is_guest_l3_slot(pgentry_ptr_to_slot(pl3e))) )
   68.10      {
   68.11 @@ -1218,7 +1219,9 @@ static int mod_l3_entry(l3_pgentry_t *pl
   68.12          return 0;
   68.13      }
   68.14  
   68.15 -    BUG_ON(!create_pae_xen_mappings(pl3e));
   68.16 +    okay = create_pae_xen_mappings(pl3e);
   68.17 +    BUG_ON(!okay);
   68.18 +
   68.19      put_page_from_l3e(ol3e, pfn);
   68.20      return 1;
   68.21  }
    69.1 --- a/xen/arch/x86/time.c	Mon Oct 24 21:00:35 2005 -0600
    69.2 +++ b/xen/arch/x86/time.c	Sat Oct 29 09:51:35 2005 +0100
    69.3 @@ -323,7 +323,7 @@ static u64 read_pit_count(void)
    69.4      return pit_counter64 + (u16)(pit_stamp - pit_read_counter());
    69.5  }
    69.6  
    69.7 -static int init_pit(void)
    69.8 +static void init_pit(void)
    69.9  {
   69.10      read_platform_count = read_pit_count;
   69.11  
   69.12 @@ -333,8 +333,6 @@ static int init_pit(void)
   69.13  
   69.14      printk("Platform timer is %s PIT\n", freq_string(CLOCK_TICK_RATE));
   69.15      using_pit = 1;
   69.16 -
   69.17 -    return 1;
   69.18  }
   69.19  
   69.20  /************************************************************
   69.21 @@ -563,7 +561,7 @@ static void platform_time_calibration(vo
   69.22  static void init_platform_timer(void)
   69.23  {
   69.24      if ( !init_cyclone() && !init_hpet() )
   69.25 -        BUG_ON(!init_pit());
   69.26 +        init_pit();
   69.27  }
   69.28  
   69.29  
    70.1 --- a/xen/arch/x86/vmx.c	Mon Oct 24 21:00:35 2005 -0600
    70.2 +++ b/xen/arch/x86/vmx.c	Sat Oct 29 09:51:35 2005 +0100
    70.3 @@ -65,6 +65,11 @@ void vmx_final_setup_guest(struct vcpu *
    70.4  
    70.5      if ( v == v->domain->vcpu[0] )
    70.6      {
    70.7 +        v->domain->arch.vmx_platform.lapic_enable =
    70.8 +            v->arch.guest_context.user_regs.ecx;
    70.9 +        v->arch.guest_context.user_regs.ecx = 0;
   70.10 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "lapic enable is %d.\n",
   70.11 +                    v->domain->arch.vmx_platform.lapic_enable);
   70.12          /*
   70.13           * Required to do this once per domain
   70.14           * XXX todo: add a seperate function to do these.
   70.15 @@ -96,6 +101,10 @@ void vmx_relinquish_resources(struct vcp
   70.16      destroy_vmcs(&v->arch.arch_vmx);
   70.17      free_monitor_pagetable(v);
   70.18      rem_ac_timer(&v->domain->arch.vmx_platform.vmx_pit.pit_timer);
   70.19 +    if ( vmx_apic_support(v->domain) ) {
   70.20 +        rem_ac_timer( &(VLAPIC(v)->vlapic_timer) );
   70.21 +        xfree( VLAPIC(v) );
   70.22 +    }
   70.23  }
   70.24  
   70.25  #ifdef __x86_64__
   70.26 @@ -442,7 +451,9 @@ static int vmx_do_page_fault(unsigned lo
   70.27  
   70.28      /* Use 1:1 page table to identify MMIO address space */
   70.29      if ( mmio_space(gpa) ){
   70.30 -        if (gpa >= 0xFEE00000) { /* workaround for local APIC */
   70.31 +        struct vcpu *v = current;
   70.32 +        /* No support for APIC */
   70.33 +        if (!vmx_apic_support(v->domain) && gpa >= 0xFEC00000) { 
   70.34              u32 inst_len;
   70.35              __vmread(VM_EXIT_INSTRUCTION_LEN, &(inst_len));
   70.36              __update_guest_eip(inst_len);
   70.37 @@ -487,6 +498,7 @@ static void vmx_vmexit_do_cpuid(unsigned
   70.38  {
   70.39      unsigned int eax, ebx, ecx, edx;
   70.40      unsigned long eip;
   70.41 +    struct vcpu *v = current;
   70.42  
   70.43      __vmread(GUEST_RIP, &eip);
   70.44  
   70.45 @@ -500,6 +512,9 @@ static void vmx_vmexit_do_cpuid(unsigned
   70.46      cpuid(input, &eax, &ebx, &ecx, &edx);
   70.47  
   70.48      if (input == 1) {
   70.49 +        if ( vmx_apic_support(v->domain) &&
   70.50 +                !vlapic_global_enabled((VLAPIC(v))) )
   70.51 +            clear_bit(X86_FEATURE_APIC, &edx);
   70.52  #ifdef __i386__
   70.53          clear_bit(X86_FEATURE_PSE, &edx);
   70.54          clear_bit(X86_FEATURE_PAE, &edx);
   70.55 @@ -1441,6 +1456,7 @@ static int vmx_cr_access(unsigned long e
   70.56  static inline void vmx_do_msr_read(struct cpu_user_regs *regs)
   70.57  {
   70.58      u64 msr_content = 0;
   70.59 +    struct vcpu *v = current;
   70.60  
   70.61      VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_read: ecx=%lx, eax=%lx, edx=%lx",
   70.62                  (unsigned long)regs->ecx, (unsigned long)regs->eax,
   70.63 @@ -1455,6 +1471,9 @@ static inline void vmx_do_msr_read(struc
   70.64      case MSR_IA32_SYSENTER_EIP:
   70.65          __vmread(GUEST_SYSENTER_EIP, &msr_content);
   70.66          break;
   70.67 +    case MSR_IA32_APICBASE:
   70.68 +        msr_content = VLAPIC(v) ? VLAPIC(v)->apic_base_msr : 0;
   70.69 +        break;
   70.70      default:
   70.71          if(long_mode_do_msr_read(regs))
   70.72              return;
   70.73 @@ -1474,6 +1493,7 @@ static inline void vmx_do_msr_read(struc
   70.74  static inline void vmx_do_msr_write(struct cpu_user_regs *regs)
   70.75  {
   70.76      u64 msr_content;
   70.77 +    struct vcpu *v = current;
   70.78  
   70.79      VMX_DBG_LOG(DBG_LEVEL_1, "vmx_do_msr_write: ecx=%lx, eax=%lx, edx=%lx",
   70.80                  (unsigned long)regs->ecx, (unsigned long)regs->eax,
   70.81 @@ -1491,6 +1511,9 @@ static inline void vmx_do_msr_write(stru
   70.82      case MSR_IA32_SYSENTER_EIP:
   70.83          __vmwrite(GUEST_SYSENTER_EIP, msr_content);
   70.84          break;
   70.85 +    case MSR_IA32_APICBASE:
   70.86 +        vlapic_msr_set(VLAPIC(v), msr_content);
   70.87 +        break;
   70.88      default:
   70.89          long_mode_do_msr_write(regs);
   70.90          break;
    71.1 --- a/xen/arch/x86/vmx_intercept.c	Mon Oct 24 21:00:35 2005 -0600
    71.2 +++ b/xen/arch/x86/vmx_intercept.c	Sat Oct 29 09:51:35 2005 +0100
    71.3 @@ -23,6 +23,7 @@
    71.4  #include <asm/vmx_platform.h>
    71.5  #include <asm/vmx_virpit.h>
    71.6  #include <asm/vmx_intercept.h>
    71.7 +#include <asm/vmx_vlapic.h>
    71.8  #include <public/io/ioreq.h>
    71.9  #include <xen/lib.h>
   71.10  #include <xen/sched.h>
   71.11 @@ -32,6 +33,123 @@
   71.12  
   71.13  #ifdef CONFIG_VMX
   71.14  
   71.15 +struct vmx_mmio_handler vmx_mmio_handers[VMX_MMIO_HANDLER_NR] =
   71.16 +{
   71.17 +    {
   71.18 +        .check_handler = vlapic_range,
   71.19 +        .read_handler  = vlapic_read,
   71.20 +        .write_handler = vlapic_write
   71.21 +    }
   71.22 +};
   71.23 +
   71.24 +static inline void vmx_mmio_access(struct vcpu *v,
   71.25 +                                   ioreq_t *p,
   71.26 +                                   vmx_mmio_read_t read_handler,
   71.27 +                                   vmx_mmio_write_t write_handler)
   71.28 +{
   71.29 +    ioreq_t *req;
   71.30 +    vcpu_iodata_t *vio = get_vio(v->domain, v->vcpu_id);
   71.31 +    unsigned int tmp1, tmp2;
   71.32 +    unsigned long data;
   71.33 +
   71.34 +    if (vio == NULL) {
   71.35 +        printk("vlapic_access: bad shared page\n");
   71.36 +        domain_crash_synchronous();
   71.37 +    }
   71.38 +
   71.39 +    req = &vio->vp_ioreq;
   71.40 +
   71.41 +    switch (req->type) {
   71.42 +    case IOREQ_TYPE_COPY:
   71.43 +    {
   71.44 +        int sign = (req->df) ? -1 : 1, i;
   71.45 +
   71.46 +        if (!req->pdata_valid) {
   71.47 +            if (req->dir == IOREQ_READ){
   71.48 +                req->u.data = read_handler(v, req->addr, req->size);
   71.49 +            } else {                 /* req->dir != IOREQ_READ */
   71.50 +                write_handler(v, req->addr, req->size, req->u.data);
   71.51 +            }
   71.52 +        } else {                     /* !req->pdata_valid */
   71.53 +            if (req->dir == IOREQ_READ) {
   71.54 +                for (i = 0; i < req->count; i++) {
   71.55 +                    data = read_handler(v,
   71.56 +                      req->addr + (sign * i * req->size),
   71.57 +                      req->size);
   71.58 +                    vmx_copy(&data,
   71.59 +                      (unsigned long)p->u.pdata + (sign * i * req->size),
   71.60 +                      p->size,
   71.61 +                      VMX_COPY_OUT);
   71.62 +                }
   71.63 +            } else {                  /* !req->dir == IOREQ_READ */
   71.64 +                for (i = 0; i < req->count; i++) {
   71.65 +                    vmx_copy(&data,
   71.66 +                      (unsigned long)p->u.pdata + (sign * i * req->size),
   71.67 +                      p->size,
   71.68 +                      VMX_COPY_IN);
   71.69 +                    write_handler(v,
   71.70 +                      req->addr + (sign * i * req->size),
   71.71 +                      req->size, data);
   71.72 +                }
   71.73 +            }
   71.74 +        }
   71.75 +        break;
   71.76 +    }
   71.77 +
   71.78 +    case IOREQ_TYPE_AND:
   71.79 +        tmp1 = read_handler(v, req->addr, req->size);
   71.80 +        if (req->dir == IOREQ_WRITE) {
   71.81 +            tmp2 = tmp1 & (unsigned long) req->u.data;
   71.82 +            write_handler(v, req->addr, req->size, tmp2);
   71.83 +        }
   71.84 +        req->u.data = tmp1;
   71.85 +        break;
   71.86 +
   71.87 +    case IOREQ_TYPE_OR:
   71.88 +        tmp1 = read_handler(v, req->addr, req->size);
   71.89 +        if (req->dir == IOREQ_WRITE) {
   71.90 +            tmp2 = tmp1 | (unsigned long) req->u.data;
   71.91 +            write_handler(v, req->addr, req->size, tmp2);
   71.92 +        }
   71.93 +        req->u.data = tmp1;
   71.94 +        break;
   71.95 +
   71.96 +    case IOREQ_TYPE_XOR:
   71.97 +        tmp1 = read_handler(v, req->addr, req->size);
   71.98 +        if (req->dir == IOREQ_WRITE) {
   71.99 +            tmp2 = tmp1 ^ (unsigned long) req->u.data;
  71.100 +            write_handler(v, req->addr, req->size, tmp2);
  71.101 +        }
  71.102 +        req->u.data = tmp1;
  71.103 +        break;
  71.104 +
  71.105 +    default:
  71.106 +        printk("error ioreq type for local APIC %x\n", req->type);
  71.107 +        domain_crash_synchronous();
  71.108 +        break;
  71.109 +    }
  71.110 +}
  71.111 +
  71.112 +int vmx_mmio_intercept(ioreq_t *p)
  71.113 +{
  71.114 +    struct vcpu *v = current;
  71.115 +    int i;
  71.116 +    struct vmx_mmio_handler *handler = vmx_mmio_handers;
  71.117 +
  71.118 +    /* XXX currently only APIC use intercept */
  71.119 +    if ( !vmx_apic_support(v->domain) )
  71.120 +        return 0;
  71.121 +
  71.122 +    for ( i = 0; i < VMX_MMIO_HANDLER_NR; i++ ) {
  71.123 +        if ( handler[i].check_handler(v, p->addr) ) {
  71.124 +            vmx_mmio_access(v, p,
  71.125 +              handler[i].read_handler, handler[i].write_handler);
  71.126 +            return 1;
  71.127 +        }
  71.128 +    }
  71.129 +    return 0;
  71.130 +}
  71.131 +
  71.132  /*
  71.133   * Check if the request is handled inside xen
  71.134   * return value: 0 --not handled; 1 --handled
    72.1 --- a/xen/arch/x86/vmx_io.c	Mon Oct 24 21:00:35 2005 -0600
    72.2 +++ b/xen/arch/x86/vmx_io.c	Sat Oct 29 09:51:35 2005 +0100
    72.3 @@ -36,9 +36,9 @@
    72.4  #include <asm/apic.h>
    72.5  #include <asm/shadow.h>
    72.6  
    72.7 +#include <asm/vmx_vlapic.h>
    72.8  #include <public/io/ioreq.h>
    72.9  #include <public/io/vmx_vpic.h>
   72.10 -#include <public/io/vmx_vlapic.h>
   72.11  
   72.12  #ifdef CONFIG_VMX
   72.13  #if defined (__i386__)
   72.14 @@ -732,48 +732,6 @@ void vmx_wait_io()
   72.15      } while(1);
   72.16  }
   72.17  
   72.18 -#if defined(__i386__) || defined(__x86_64__)
   72.19 -static inline int __fls(u32 word)
   72.20 -{
   72.21 -    int bit;
   72.22 -
   72.23 -    __asm__("bsrl %1,%0"
   72.24 -            :"=r" (bit)
   72.25 -            :"rm" (word));
   72.26 -    return word ? bit : -1;
   72.27 -}
   72.28 -#else
   72.29 -#define __fls(x)  generic_fls(x)
   72.30 -static __inline__ int generic_fls(u32 x)
   72.31 -{
   72.32 -    int r = 31;
   72.33 -
   72.34 -    if (!x)
   72.35 -        return -1;
   72.36 -    if (!(x & 0xffff0000u)) {
   72.37 -        x <<= 16;
   72.38 -        r -= 16;
   72.39 -    }
   72.40 -    if (!(x & 0xff000000u)) {
   72.41 -        x <<= 8;
   72.42 -        r -= 8;
   72.43 -    }
   72.44 -    if (!(x & 0xf0000000u)) {
   72.45 -        x <<= 4;
   72.46 -        r -= 4;
   72.47 -    }
   72.48 -    if (!(x & 0xc0000000u)) {
   72.49 -        x <<= 2;
   72.50 -        r -= 2;
   72.51 -    }
   72.52 -    if (!(x & 0x80000000u)) {
   72.53 -        x <<= 1;
   72.54 -        r -= 1;
   72.55 -    }
   72.56 -    return r;
   72.57 -}
   72.58 -#endif
   72.59 -
   72.60  /* Simple minded Local APIC priority implementation. Fix later */
   72.61  static __inline__ int find_highest_irq(u32 *pintr)
   72.62  {
   72.63 @@ -801,31 +759,31 @@ interrupt_post_injection(struct vcpu * v
   72.64      struct vmx_virpit *vpit = &(v->domain->arch.vmx_platform.vmx_pit);
   72.65      u64    drift;
   72.66  
   72.67 +    if ( is_pit_irq(v, vector, type) ) {
   72.68 +        if ( !vpit->first_injected ) {
   72.69 +            vpit->first_injected = 1;
   72.70 +            vpit->pending_intr_nr = 0;
   72.71 +        } else {
   72.72 +            vpit->pending_intr_nr--;
   72.73 +        }
   72.74 +        vpit->inject_point = NOW();
   72.75 +        drift = vpit->period_cycles * vpit->pending_intr_nr;
   72.76 +        drift = v->arch.arch_vmx.tsc_offset - drift;
   72.77 +        __vmwrite(TSC_OFFSET, drift);
   72.78 +
   72.79 +#if defined (__i386__)
   72.80 +        __vmwrite(TSC_OFFSET_HIGH, (drift >> 32));
   72.81 +#endif
   72.82 +
   72.83 +    }
   72.84 +
   72.85      switch(type)
   72.86      {
   72.87      case VLAPIC_DELIV_MODE_EXT:
   72.88 -        if ( is_pit_irq(v, vector) ) {
   72.89 -            if ( !vpit->first_injected ) {
   72.90 -                vpit->first_injected = 1;
   72.91 -                vpit->pending_intr_nr = 0;
   72.92 -            }
   72.93 -            else {
   72.94 -                vpit->pending_intr_nr--;
   72.95 -            }
   72.96 -            vpit->inject_point = NOW();
   72.97 -            drift = vpit->period_cycles * vpit->pending_intr_nr;
   72.98 -            drift = v->arch.arch_vmx.tsc_offset - drift;
   72.99 -            __vmwrite(TSC_OFFSET, drift);
  72.100 -
  72.101 -#if defined (__i386__)
  72.102 -            __vmwrite(TSC_OFFSET_HIGH, (drift >> 32));
  72.103 -#endif
  72.104 - 
  72.105 -        }
  72.106          break;
  72.107  
  72.108      default:
  72.109 -        printk("Not support interrupt type\n");
  72.110 +        vlapic_post_injection(v, vector, type);
  72.111          break;
  72.112      }
  72.113  }
  72.114 @@ -885,6 +843,24 @@ void vmx_pic_assist(struct vcpu *v)
  72.115  
  72.116  }
  72.117  
  72.118 +int cpu_get_interrupt(struct vcpu *v, int *type)
  72.119 +{
  72.120 +    int intno;
  72.121 +    struct vmx_virpic *s = &v->domain->arch.vmx_platform.vmx_pic;
  72.122 +
  72.123 +    if ( (intno = cpu_get_apic_interrupt(v, type)) != -1 ) {
  72.124 +        /* set irq request if a PIC irq is still pending */
  72.125 +        /* XXX: improve that */
  72.126 +        pic_update_irq(s);
  72.127 +        return intno;
  72.128 +    }
  72.129 +    /* read the irq from the PIC */
  72.130 +    if ( (intno = cpu_get_pic_interrupt(v, type)) != -1 )
  72.131 +        return intno;
  72.132 +
  72.133 +    return -1;
  72.134 +}
  72.135 +
  72.136  asmlinkage void vmx_intr_assist(void)
  72.137  {
  72.138      int intr_type = 0;
  72.139 @@ -902,11 +878,6 @@ asmlinkage void vmx_intr_assist(void)
  72.140          pic_set_irq(pic, 0, 1);
  72.141      }
  72.142  
  72.143 -    if ( !plat->interrupt_request ) {
  72.144 -        disable_irq_window(cpu_exec_control);
  72.145 -        return;
  72.146 -    }
  72.147 -
  72.148      __vmread(VM_ENTRY_INTR_INFO_FIELD, &intr_fields);
  72.149  
  72.150      if (intr_fields & INTR_INFO_VALID_MASK) {
  72.151 @@ -928,16 +899,21 @@ asmlinkage void vmx_intr_assist(void)
  72.152          enable_irq_window(cpu_exec_control);
  72.153          return;
  72.154      }
  72.155 -    plat->interrupt_request = 0;
  72.156 -    highest_vector = cpu_get_pic_interrupt(v, &intr_type); 
  72.157 +
  72.158 +    highest_vector = cpu_get_interrupt(v, &intr_type); 
  72.159 +
  72.160 +    if (highest_vector == -1) {
  72.161 +        disable_irq_window(cpu_exec_control);
  72.162 +        return;
  72.163 +    }
  72.164  
  72.165      switch (intr_type) {
  72.166      case VLAPIC_DELIV_MODE_EXT:
  72.167 +    case VLAPIC_DELIV_MODE_FIXED:
  72.168 +    case VLAPIC_DELIV_MODE_LPRI:
  72.169          vmx_inject_extint(v, highest_vector, VMX_INVALID_ERROR_CODE);
  72.170          TRACE_3D(TRC_VMX_INT, v->domain->domain_id, highest_vector, 0);
  72.171          break;
  72.172 -    case VLAPIC_DELIV_MODE_FIXED:
  72.173 -    case VLAPIC_DELIV_MODE_LPRI:
  72.174      case VLAPIC_DELIV_MODE_SMI:
  72.175      case VLAPIC_DELIV_MODE_NMI:
  72.176      case VLAPIC_DELIV_MODE_INIT:
    73.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    73.2 +++ b/xen/arch/x86/vmx_vlapic.c	Sat Oct 29 09:51:35 2005 +0100
    73.3 @@ -0,0 +1,997 @@
    73.4 +/*
    73.5 + * vmx_vlapic.c: virtualize LAPIC for VMX vcpus.
    73.6 + * Copyright (c) 2004, Intel Corporation.
    73.7 + *
    73.8 + * This program is free software; you can redistribute it and/or modify it
    73.9 + * under the terms and conditions of the GNU General Public License,
   73.10 + * version 2, as published by the Free Software Foundation.
   73.11 + *
   73.12 + * This program is distributed in the hope it will be useful, but WITHOUT
   73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   73.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   73.15 + * more details.
   73.16 + *
   73.17 + * You should have received a copy of the GNU General Public License along with
   73.18 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   73.19 + * Place - Suite 330, Boston, MA 02111-1307 USA.
   73.20 + *
   73.21 + */
   73.22 +
   73.23 +#include <xen/config.h>
   73.24 +#include <xen/types.h>
   73.25 +#include <xen/mm.h>
   73.26 +#include <xen/xmalloc.h>
   73.27 +#include <asm/shadow.h>
   73.28 +#include <asm/page.h>
   73.29 +#include <xen/event.h>
   73.30 +#include <xen/trace.h>
   73.31 +#include <asm/vmx.h>
   73.32 +#include <asm/vmx_platform.h>
   73.33 +#include <asm/vmx_vlapic.h>
   73.34 +
   73.35 +#include <xen/lib.h>
   73.36 +#include <xen/sched.h>
   73.37 +#include <asm/current.h>
   73.38 +#include <public/io/ioreq.h>
   73.39 +
   73.40 +#ifdef CONFIG_VMX
   73.41 +
   73.42 +/* XXX remove this definition after GFW enabled */
   73.43 +#define VLAPIC_NO_BIOS
   73.44 +
   73.45 +extern unsigned int get_apic_bus_scale(void);
   73.46 +
   73.47 +static unsigned int vlapic_lvt_mask[VLAPIC_LVT_NUM] =
   73.48 +{
   73.49 +    0x310ff, 0x117ff, 0x117ff, 0x1f7ff, 0x1f7ff, 0x117ff
   73.50 +};
   73.51 +
   73.52 +int vlapic_find_highest_irr(struct vlapic *vlapic)
   73.53 +{
   73.54 +    int result;
   73.55 +
   73.56 +    result = find_highest_bit((uint32_t *)&vlapic->irr[0], INTR_LEN_32);
   73.57 +
   73.58 +    if (result != -1 && result < 16) {
   73.59 +        printk("VLAPIC: irr on reserved bits %d\n ", result);
   73.60 +        domain_crash_synchronous();
   73.61 +    }
   73.62 +
   73.63 +    return result;
   73.64 +}
   73.65 +
   73.66 +inline int vmx_apic_support(struct domain *d)
   73.67 +{
   73.68 +    return d->arch.vmx_platform.lapic_enable;
   73.69 +}
   73.70 +
   73.71 +int vlapic_find_highest_isr(struct vlapic *vlapic)
   73.72 +{
   73.73 +    int result;
   73.74 +
   73.75 +    result = find_highest_bit((uint32_t *)&vlapic->isr[0], INTR_LEN_32);
   73.76 +
   73.77 +    if (result != -1 && result < 16) {
   73.78 +        int i = 0;
   73.79 +        printk("VLAPIC: isr on reserved bits %d, isr is\n ", result);
   73.80 +        for (i = 0; i < INTR_LEN_32; i += 2)
   73.81 +            printk("%d: 0x%08x%08x\n", i, vlapic->isr[i], vlapic->isr[i+1]);
   73.82 +        return -1;
   73.83 +    }
   73.84 +
   73.85 +    return result;
   73.86 +}
   73.87 +
   73.88 +uint32_t vlapic_update_ppr(struct vlapic *vlapic)
   73.89 +{
   73.90 +    uint32_t tpr, isrv, ppr;
   73.91 +    int isr;
   73.92 +
   73.93 +    tpr = (vlapic->task_priority >> 4) & 0xf;      /* we want 7:4 */
   73.94 +
   73.95 +    isr = vlapic_find_highest_isr(vlapic);
   73.96 +    if (isr != -1)
   73.97 +        isrv = (isr >> 4) & 0xf;   /* ditto */
   73.98 +    else
   73.99 +        isrv = 0;
  73.100 +
  73.101 +    if (tpr >= isrv)
  73.102 +        ppr = vlapic->task_priority & 0xff;
  73.103 +    else
  73.104 +        ppr = isrv << 4;  /* low 4 bits of PPR have to be cleared */
  73.105 +
  73.106 +    vlapic->processor_priority = ppr;
  73.107 +
  73.108 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC_INTERRUPT,
  73.109 +                "vlapic_update_ppr: vlapic %p ppr %x isr %x isrv %x",
  73.110 +                vlapic, ppr, isr, isrv);
  73.111 +
  73.112 +    return ppr;
  73.113 +}
  73.114 +
  73.115 +/* This only for fixed delivery mode */
  73.116 +int vlapic_match_dest(struct vlapic *target, struct vlapic *source,
  73.117 +                      int short_hand, int dest, int dest_mode,
  73.118 +                      int delivery_mode)
  73.119 +{
  73.120 +    int result = 0;
  73.121 +
  73.122 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_match_dest: "
  73.123 +                "target %p source %p dest %x dest_mode %x short_hand %x "
  73.124 +                "delivery_mode %x",
  73.125 +                target, source, dest, dest_mode, short_hand, delivery_mode);
  73.126 +
  73.127 +    switch (short_hand) {
  73.128 +    case VLAPIC_NO_SHORTHAND:
  73.129 +        if (!dest_mode) {   /* Physical */
  73.130 +            result = (target->id == dest);
  73.131 +        } else {            /* Logical */
  73.132 +            if (((target->dest_format >> 28) & 0xf) == 0xf) {   /* Flat mode */
  73.133 +                result = (target->logical_dest >> 24) & dest;
  73.134 +            } else {
  73.135 +                if ((delivery_mode == VLAPIC_DELIV_MODE_LPRI) &&
  73.136 +                   (dest == 0xff)) {
  73.137 +                    /* What shall we do now? */
  73.138 +                    printk("Broadcast IPI with lowest priority "
  73.139 +                           "delivery mode\n");
  73.140 +                    domain_crash_synchronous();
  73.141 +                }
  73.142 +                result = (target->logical_dest == (dest & 0xf)) ?
  73.143 +                  ((target->logical_dest >> 4) & (dest >> 4)) : 0;
  73.144 +            }
  73.145 +        }
  73.146 +        break;
  73.147 +
  73.148 +    case VLAPIC_SHORTHAND_SELF:
  73.149 +        if (target == source)
  73.150 +            result = 1;
  73.151 +        break;
  73.152 +
  73.153 +    case VLAPIC_SHORTHAND_INCLUDE_SELF:
  73.154 +        result = 1;
  73.155 +        break;
  73.156 +
  73.157 +    case VLAPIC_SHORTHAND_EXCLUDE_SELF:
  73.158 +        if (target != source)
  73.159 +            result = 1;
  73.160 +        break;
  73.161 +
  73.162 +    default:
  73.163 +        break;
  73.164 +    }
  73.165 +
  73.166 +    return result;
  73.167 +}
  73.168 +
  73.169 +/*
  73.170 + * Add a pending IRQ into lapic.
  73.171 + * Return 1 if successfully added and 0 if discarded.
  73.172 + */
  73.173 +int vlapic_accept_irq(struct vlapic *vlapic, int delivery_mode,
  73.174 +                      int vector, int level, int trig_mode)
  73.175 +{
  73.176 +    int	result = 1;
  73.177 +
  73.178 +    switch (delivery_mode) {
  73.179 +    case VLAPIC_DELIV_MODE_FIXED:
  73.180 +    case VLAPIC_DELIV_MODE_LPRI:
  73.181 +        /* FIXME add logic for vcpu on reset */
  73.182 +        if (!vlapic->vcpu || !vlapic_enabled(vlapic))
  73.183 +            return 0;
  73.184 +
  73.185 +        if (test_and_set_bit(vector, &vlapic->irr[0])) {
  73.186 +            printk("<vlapic_accept_irq>"
  73.187 +                    "level trig mode repeatedly for vector %d\n", vector);
  73.188 +            result = 0;
  73.189 +        } else {
  73.190 +            if (level) {
  73.191 +                printk("<vlapic_accept_irq> level trig mode for vector %d\n", vector);
  73.192 +                set_bit(vector, &vlapic->tmr[0]);
  73.193 +            }
  73.194 +        }
  73.195 +        evtchn_set_pending(vlapic->vcpu, iopacket_port(vlapic->domain));
  73.196 +        break;
  73.197 +
  73.198 +    case VLAPIC_DELIV_MODE_RESERVED:
  73.199 +        printk("Ignore deliver mode 3 in vlapic_accept_irq\n");
  73.200 +        break;
  73.201 +
  73.202 +    case VLAPIC_DELIV_MODE_SMI:
  73.203 +    case VLAPIC_DELIV_MODE_NMI:
  73.204 +        /* Fixme */
  73.205 +        printk("TODO: for guest SMI/NMI\n");
  73.206 +        break;
  73.207 +
  73.208 +    case VLAPIC_DELIV_MODE_INIT:
  73.209 +        if (!level && trig_mode == 1) {        //Deassert
  73.210 +            printk("This vmx_vlapic is for P4, no work for De-assert init\n");
  73.211 +        } else {
  73.212 +            /* FIXME How to check the situation after vcpu reset? */
  73.213 +            vlapic->init_sipi_sipi_state = VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI;
  73.214 +            if (vlapic->vcpu) {
  73.215 +                vcpu_pause(vlapic->vcpu);
  73.216 +            }
  73.217 +        }
  73.218 +        break;
  73.219 +
  73.220 +    case VLAPIC_DELIV_MODE_STARTUP:
  73.221 +        if (vlapic->init_sipi_sipi_state != VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI)
  73.222 +            break;
  73.223 +        vlapic->init_sipi_sipi_state = VLAPIC_INIT_SIPI_SIPI_STATE_NORM;
  73.224 +        if (!vlapic->vcpu) {
  73.225 +            /* XXX Call vmx_bringup_ap here */
  73.226 +             result = 0;
  73.227 +        }else{
  73.228 +            //vmx_vcpu_reset(vlapic->vcpu);
  73.229 +        }
  73.230 +        break;
  73.231 +
  73.232 +    default:
  73.233 +        printk("TODO: not support interrup type %x\n", delivery_mode);
  73.234 +        domain_crash_synchronous();
  73.235 +        break;
  73.236 +    }
  73.237 +
  73.238 +    return result;
  73.239 +}
  73.240 +/*
  73.241 +    This function is used by both ioapic and local APIC
  73.242 +    The bitmap is for vcpu_id
  73.243 + */
  73.244 +struct vlapic* apic_round_robin(struct domain *d,
  73.245 +                                uint8_t dest_mode,
  73.246 +                                uint8_t vector,
  73.247 +                                uint32_t bitmap)
  73.248 +{
  73.249 +    int next, old;
  73.250 +    struct vlapic* target = NULL;
  73.251 +
  73.252 +    if (dest_mode == 0) { //Physical mode
  73.253 +        printk("<apic_round_robin> lowest priority for physical mode\n");
  73.254 +        return NULL;
  73.255 +    }
  73.256 +
  73.257 +    if (!bitmap) {
  73.258 +        printk("<apic_round_robin> no bit on bitmap\n");
  73.259 +        return NULL;
  73.260 +    }
  73.261 +
  73.262 +    spin_lock(&d->arch.vmx_platform.round_robin_lock);
  73.263 +
  73.264 +    old = next = d->arch.vmx_platform.round_info[vector];
  73.265 +
  73.266 +    next++;
  73.267 +    if (next == MAX_VIRT_CPUS || !d->vcpu[next])
  73.268 +        next = 0;
  73.269 +
  73.270 +    do {
  73.271 +        /* the vcpu array is arranged according to vcpu_id */
  73.272 +        if (test_bit(next, &bitmap)) {
  73.273 +            target = d->vcpu[next]->arch.arch_vmx.vlapic;
  73.274 +            if (!vlapic_enabled(target)) {
  73.275 +                printk("warning: targe round robin local apic disabled\n");
  73.276 +                /* XXX should we domain crash?? Or should we return NULL */
  73.277 +            }
  73.278 +            break;
  73.279 +        }
  73.280 +
  73.281 +        next ++;
  73.282 +        if (next == MAX_VIRT_CPUS || !d->vcpu[next])
  73.283 +            next = 0;
  73.284 +    }while(next != old);
  73.285 +
  73.286 +    d->arch.vmx_platform.round_info[vector] = next;
  73.287 +    spin_unlock(&d->arch.vmx_platform.round_robin_lock);
  73.288 +    return target;
  73.289 +}
  73.290 +
  73.291 +void
  73.292 +vlapic_EOI_set(struct vlapic *vlapic)
  73.293 +{
  73.294 +    int vector = vlapic_find_highest_isr(vlapic);
  73.295 +
  73.296 +    /* Not every write EOI will has correpsoning ISR,
  73.297 +       one example is when Kernel check timer on setup_IO_APIC */
  73.298 +    if (vector == -1) {
  73.299 +        return ;
  73.300 +    }
  73.301 +
  73.302 +    vlapic_clear_isr(vlapic, vector);
  73.303 +    vlapic_update_ppr(vlapic);
  73.304 +}
  73.305 +
  73.306 +int vlapic_check_vector(struct vlapic *vlapic,
  73.307 +                        unsigned char dm, int vector)
  73.308 +{
  73.309 +    if ((dm == VLAPIC_DELIV_MODE_FIXED) && (vector < 16)) {
  73.310 +        vlapic->err_status |= 0x40;
  73.311 +        vlapic_accept_irq(vlapic, VLAPIC_DELIV_MODE_FIXED,
  73.312 +          vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), 0, 0);
  73.313 +        printk("<vlapic_check_vector>: check fail\n");
  73.314 +        return 0;
  73.315 +    }
  73.316 +    return 1;
  73.317 +}
  73.318 +
  73.319 +
  73.320 +void vlapic_ipi(struct vlapic *vlapic)
  73.321 +{
  73.322 +    unsigned int dest = (vlapic->icr_high >> 24) & 0xff;
  73.323 +    unsigned int short_hand = (vlapic->icr_low >> 18) & 3;
  73.324 +    unsigned int trig_mode = (vlapic->icr_low >> 15) & 1;
  73.325 +    unsigned int level = (vlapic->icr_low >> 14) & 1;
  73.326 +    unsigned int dest_mode = (vlapic->icr_low >> 11) & 1;
  73.327 +    unsigned int delivery_mode = (vlapic->icr_low >> 8) & 7;
  73.328 +    unsigned int vector = (vlapic->icr_low & 0xff);
  73.329 +
  73.330 +    struct vlapic *target;
  73.331 +    struct vcpu *v = NULL;
  73.332 +    int result = 0;
  73.333 +    uint32_t lpr_map;
  73.334 +
  73.335 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_ipi: "
  73.336 +                "icr_high %x icr_low %x "
  73.337 +                "short_hand %x dest %x trig_mode %x level %x "
  73.338 +                "dest_mode %x delivery_mode %x vector %x",
  73.339 +                vlapic->icr_high, vlapic->icr_low,
  73.340 +                short_hand, dest, trig_mode, level, dest_mode,
  73.341 +                delivery_mode, vector);
  73.342 +
  73.343 +    for_each_vcpu ( vlapic->domain, v ) {
  73.344 +        target = VLAPIC(v);
  73.345 +        if (vlapic_match_dest(target, vlapic, short_hand,
  73.346 +                              dest, dest_mode, delivery_mode)) {
  73.347 +            if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
  73.348 +                set_bit(v->vcpu_id, &lpr_map);
  73.349 +            }else
  73.350 +                result = vlapic_accept_irq(target, delivery_mode,
  73.351 +                  vector, level, trig_mode);
  73.352 +        }
  73.353 +    }
  73.354 +
  73.355 +    if (delivery_mode == VLAPIC_DELIV_MODE_LPRI) {
  73.356 +        extern struct vlapic*
  73.357 +          apic_round_robin(struct domain *d,
  73.358 +            uint8_t dest_mode, uint8_t vector, uint32_t bitmap);
  73.359 +
  73.360 +        v = vlapic->vcpu;
  73.361 +        target = apic_round_robin(v->domain, dest_mode, vector, lpr_map);
  73.362 +
  73.363 +        if (target)
  73.364 +            vlapic_accept_irq(target, delivery_mode,
  73.365 +              vector, level, trig_mode);
  73.366 +    }
  73.367 +}
  73.368 +
  73.369 +void vlapic_begin_timer(struct vlapic *vlapic)
  73.370 +{
  73.371 +    s_time_t cur = NOW(), offset;
  73.372 +
  73.373 +    offset = vlapic->timer_current *
  73.374 +      (262144 / get_apic_bus_scale()) * vlapic->timer_divide_counter;
  73.375 +    vlapic->vlapic_timer.expires = cur + offset;
  73.376 +
  73.377 +    set_ac_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires );
  73.378 +
  73.379 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_begin_timer: "
  73.380 +                "bus_scale %x now %08x%08x expire %08x%08x "
  73.381 +                "offset %08x%08x current %x",
  73.382 +                get_apic_bus_scale(), (uint32_t)(cur >> 32), (uint32_t)cur,
  73.383 +                (uint32_t)(vlapic->vlapic_timer.expires >> 32),
  73.384 +                (uint32_t) vlapic->vlapic_timer.expires,
  73.385 +                (uint32_t)(offset >> 32), (uint32_t)offset,
  73.386 +                vlapic->timer_current);
  73.387 +}
  73.388 +
  73.389 +void vlapic_read_aligned(struct vlapic *vlapic, unsigned int offset,
  73.390 +                         unsigned int len, unsigned int *result)
  73.391 +{
  73.392 +    if (len != 4) {
  73.393 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.394 +                    "local apic read with len=%d (should be 4)", len);
  73.395 +    }
  73.396 +
  73.397 +    *result = 0;
  73.398 +
  73.399 +    switch (offset) {
  73.400 +    case APIC_ID:
  73.401 +        *result = (vlapic->id) << 24;
  73.402 +        break;
  73.403 +
  73.404 +    case APIC_LVR:
  73.405 +        *result = vlapic->version;
  73.406 +        break;
  73.407 +
  73.408 +    case APIC_TASKPRI:
  73.409 +        *result = vlapic->task_priority;
  73.410 +        break;
  73.411 +
  73.412 +    case APIC_ARBPRI:
  73.413 +        printk("Access local APIC ARBPRI register which is for P6\n");
  73.414 +        break;
  73.415 +
  73.416 +    case APIC_PROCPRI:
  73.417 +        *result = vlapic->processor_priority;
  73.418 +        break;
  73.419 +
  73.420 +    case APIC_EOI:      /* EOI is write only */
  73.421 +        break;
  73.422 +
  73.423 +    case APIC_LDR:
  73.424 +        *result = vlapic->logical_dest;
  73.425 +        break;
  73.426 +
  73.427 +    case APIC_DFR:
  73.428 +        *result = vlapic->dest_format;
  73.429 +        break;
  73.430 +
  73.431 +    case APIC_SPIV:
  73.432 +        *result = vlapic->spurious_vec;
  73.433 +        break;
  73.434 +
  73.435 +    case APIC_ISR:
  73.436 +    case 0x110:
  73.437 +    case 0x120:
  73.438 +    case 0x130:
  73.439 +    case 0x140:
  73.440 +    case 0x150:
  73.441 +    case 0x160:
  73.442 +    case 0x170:
  73.443 +        *result = vlapic->isr[(offset - APIC_ISR) >> 4];
  73.444 +        break;
  73.445 +
  73.446 +    case APIC_TMR:
  73.447 +    case 0x190:
  73.448 +    case 0x1a0:
  73.449 +    case 0x1b0:
  73.450 +    case 0x1c0:
  73.451 +    case 0x1d0:
  73.452 +    case 0x1e0:
  73.453 +    case 0x1f0:
  73.454 +        *result = vlapic->tmr[(offset - APIC_TMR) >> 4];
  73.455 +        break;
  73.456 +
  73.457 +    case APIC_IRR:
  73.458 +    case 0x210:
  73.459 +    case 0x220:
  73.460 +    case 0x230:
  73.461 +    case 0x240:
  73.462 +    case 0x250:
  73.463 +    case 0x260:
  73.464 +    case 0x270:
  73.465 +        *result = vlapic->irr[(offset - APIC_IRR) >> 4];
  73.466 +        break;
  73.467 +
  73.468 +    case APIC_ESR:
  73.469 +        if (vlapic->err_write_count)
  73.470 +            *result = vlapic->err_status;
  73.471 +        break;
  73.472 +
  73.473 +    case APIC_ICR:
  73.474 +        *result = vlapic->icr_low;
  73.475 +        break;
  73.476 +
  73.477 +    case APIC_ICR2:
  73.478 +        *result = vlapic->icr_high;
  73.479 +        break;
  73.480 +
  73.481 +    case APIC_LVTT:     /* LVT Timer Reg */
  73.482 +    case APIC_LVTTHMR:     /* LVT Thermal Monitor */
  73.483 +    case APIC_LVTPC:     /* LVT Performance Counter */
  73.484 +    case APIC_LVT0:     /* LVT LINT0 Reg */
  73.485 +    case APIC_LVT1:     /* LVT Lint1 Reg */
  73.486 +    case APIC_LVTERR:     /* LVT Error Reg */
  73.487 +        *result = vlapic->lvt[(offset - APIC_LVTT) >> 4];
  73.488 +        break;
  73.489 +
  73.490 +    case APIC_TMICT:
  73.491 +        *result = vlapic->timer_initial;
  73.492 +        break;
  73.493 +
  73.494 +    case APIC_TMCCT:         //Timer CCR
  73.495 +        {
  73.496 +            uint32_t counter;
  73.497 +            s_time_t passed, cur = NOW();
  73.498 +
  73.499 +            if (cur <= vlapic->timer_current_update) {
  73.500 +                passed = ~0x0LL - vlapic->timer_current_update + cur;
  73.501 +                VMX_DBG_LOG(DBG_LEVEL_VLAPIC,"time elapsed");
  73.502 +            }else
  73.503 +                passed = cur - vlapic->timer_current_update;
  73.504 +
  73.505 +            counter = (passed * get_apic_bus_scale()) / (262144* vlapic->timer_divide_counter);
  73.506 +            if (vlapic->timer_current > counter)
  73.507 +                *result = vlapic->timer_current - counter;
  73.508 +            else {
  73.509 +                if (!vlapic_lvt_timer_period(vlapic))
  73.510 +                    *result = 0;
  73.511 +                //FIXME should we add interrupt here?
  73.512 +                else
  73.513 +                    //*result = counter % vlapic->timer_initial;
  73.514 +                    *result = vlapic->timer_initial - (counter - vlapic->timer_current);
  73.515 +            }
  73.516 +            vlapic->timer_current = *result;
  73.517 +            vlapic->timer_current_update = NOW();
  73.518 +
  73.519 +            VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  73.520 +                        "initial %x timer current %x "
  73.521 +                        "update %08x%08x cur %08x%08x offset %d",
  73.522 +                        vlapic->timer_initial, vlapic->timer_current,
  73.523 +                        (uint32_t)(vlapic->timer_current_update >> 32),
  73.524 +                        (uint32_t)vlapic->timer_current_update ,
  73.525 +                        (uint32_t)(cur >> 32), (uint32_t)cur, counter);
  73.526 +        }
  73.527 +        break;
  73.528 +
  73.529 +    case APIC_TDCR:
  73.530 +        *result = vlapic->timer_divconf;
  73.531 +        break;
  73.532 +
  73.533 +    default:
  73.534 +        printk("Read local APIC address %x not implemented\n",offset);
  73.535 +        *result = 0;
  73.536 +        break;
  73.537 +    }
  73.538 +}
  73.539 +
  73.540 +unsigned long vlapic_read(struct vcpu *v, unsigned long address,
  73.541 +            unsigned long len)
  73.542 +{
  73.543 +    unsigned int alignment;
  73.544 +    unsigned int tmp;
  73.545 +    unsigned long result;
  73.546 +    struct vlapic *vlapic = VLAPIC(v);
  73.547 +    unsigned int offset = address - vlapic->base_address;
  73.548 +
  73.549 +    if ( len != 4) {
  73.550 +        /* some bugs on kernel cause read this with byte*/
  73.551 +        printk("Local APIC read with len = %lx, should be 4 instead\n", len);
  73.552 +    }
  73.553 +
  73.554 +    alignment = offset & 0x3;
  73.555 +
  73.556 +    vlapic_read_aligned(vlapic, offset & ~0x3, 4, &tmp);
  73.557 +    switch (len) {
  73.558 +    case 1:
  73.559 +        result = *((unsigned char *)&tmp + alignment);
  73.560 +        break;
  73.561 +
  73.562 +    case 2:
  73.563 +        result = *(unsigned short *)((unsigned char *)&tmp + alignment);
  73.564 +        break;
  73.565 +
  73.566 +    case 4:
  73.567 +        result = *(unsigned int *)((unsigned char *)&tmp + alignment);
  73.568 +        break;
  73.569 +
  73.570 +    default:
  73.571 +        printk("Local APIC read with len = %lx, should be 4 instead\n", len);
  73.572 +        domain_crash_synchronous();
  73.573 +        break;
  73.574 +    }
  73.575 +
  73.576 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.577 +                "vlapic_read offset %x with length %lx and the result is %lx",
  73.578 +                offset, len, result);
  73.579 +    return result;
  73.580 +}
  73.581 +
  73.582 +unsigned long vlapic_write(struct vcpu *v, unsigned long address,
  73.583 +                  unsigned long len, unsigned long val)
  73.584 +{
  73.585 +    struct vlapic *vlapic = VLAPIC(v);
  73.586 +    unsigned int offset = address - vlapic->base_address;
  73.587 +
  73.588 +    if (offset != 0xb0)
  73.589 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.590 +          "vlapic_write offset %x with length %lx source %lx",
  73.591 +          offset, len, val);
  73.592 +
  73.593 +    /*
  73.594 +     * According to IA 32 Manual, all resgiters should be accessed with
  73.595 +     * 32 bits alignment.
  73.596 +     */
  73.597 +    if (len != 4) {
  73.598 +        unsigned int tmp;
  73.599 +        unsigned char alignment;
  73.600 +
  73.601 +        /* Some kernel do will access with byte/word alignment*/
  73.602 +        printk("Notice: Local APIC write with len = %lx\n",len);
  73.603 +        alignment = offset & 0x3;
  73.604 +        tmp = vlapic_read(v, offset & (~0x3), 4);
  73.605 +        switch (len) {
  73.606 +        case 1:
  73.607 +            /* XXX the saddr is a tmp variable from caller, so should be ok
  73.608 +               But we should still change the following ref to val to 
  73.609 +               local variable later */
  73.610 +            val  = (tmp & ~(0xff << alignment)) |
  73.611 +                        ((val & 0xff) << alignment);
  73.612 +            break;
  73.613 +
  73.614 +        case 2:
  73.615 +            if (alignment != 0x0 && alignment != 0x2) {
  73.616 +                printk("alignment error for vlapic with len == 2\n");
  73.617 +                    domain_crash_synchronous();
  73.618 +            }
  73.619 +
  73.620 +            val = (tmp & ~(0xffff << alignment)) |
  73.621 +                        ((val & 0xffff)  << alignment);
  73.622 +            break;
  73.623 +
  73.624 +        case 3:
  73.625 +            /* will it happen? */
  73.626 +            printk("vlapic_write with len = 3 !!!\n");
  73.627 +            domain_crash_synchronous();
  73.628 +            break;
  73.629 +
  73.630 +        default:
  73.631 +            printk("Local APIC write with len = %lx, should be 4 instead\n", len);
  73.632 +            domain_crash_synchronous();
  73.633 +            break;
  73.634 +        }
  73.635 +    }
  73.636 +
  73.637 +    offset &= 0xff0;
  73.638 +
  73.639 +    switch (offset) {
  73.640 +    case APIC_ID:   /* Local APIC ID */
  73.641 +        vlapic->id = ((val) >> 24) & VAPIC_ID_MASK;
  73.642 +        break;
  73.643 +
  73.644 +    case APIC_TASKPRI:
  73.645 +        vlapic->task_priority = val & 0xff;
  73.646 +        vlapic_update_ppr(vlapic);
  73.647 +        break;
  73.648 +
  73.649 +    case APIC_EOI:
  73.650 +        vlapic_EOI_set(vlapic);
  73.651 +        break;
  73.652 +
  73.653 +    case APIC_LDR:
  73.654 +        vlapic->logical_dest = val & VAPIC_LDR_MASK;
  73.655 +        break;
  73.656 +
  73.657 +    case APIC_DFR:
  73.658 +        vlapic->dest_format = val ;
  73.659 +        break;
  73.660 +
  73.661 +    case APIC_SPIV:
  73.662 +        vlapic->spurious_vec = val & 0x1ff;
  73.663 +        if (!(vlapic->spurious_vec & 0x100)) {
  73.664 +            int i = 0;
  73.665 +            for (i=0; i < VLAPIC_LVT_NUM; i++) 
  73.666 +                vlapic->lvt[i] |= 0x10000;
  73.667 +            vlapic->status |= VLAPIC_SOFTWARE_DISABLE_MASK;
  73.668 +        }
  73.669 +        else
  73.670 +            vlapic->status &= ~VLAPIC_SOFTWARE_DISABLE_MASK;
  73.671 +        break;
  73.672 +
  73.673 +    case APIC_ESR:
  73.674 +        vlapic->err_write_count = !vlapic->err_write_count;
  73.675 +        if (!vlapic->err_write_count)
  73.676 +            vlapic->err_status = 0;
  73.677 +        break;
  73.678 +
  73.679 +    case APIC_ICR:
  73.680 +        /* No delay here, so we always clear the pending bit*/
  73.681 +        vlapic->icr_low = val & ~(1 << 12);
  73.682 +        vlapic_ipi(vlapic);
  73.683 +        break;
  73.684 +
  73.685 +    case APIC_ICR2:
  73.686 +        vlapic->icr_high = val & 0xff000000;
  73.687 +        break;
  73.688 +
  73.689 +    case APIC_LVTT: // LVT Timer Reg
  73.690 +    case APIC_LVTTHMR: // LVT Thermal Monitor
  73.691 +    case APIC_LVTPC: // LVT Performance Counter
  73.692 +    case APIC_LVT0: // LVT LINT0 Reg
  73.693 +    case APIC_LVT1: // LVT Lint1 Reg
  73.694 +    case APIC_LVTERR: // LVT Error Reg
  73.695 +        {
  73.696 +            int vt = (offset - APIC_LVTT) >> 4;
  73.697 +
  73.698 +            vlapic->lvt[vt] = val & vlapic_lvt_mask[vt];
  73.699 +            if (vlapic->status & VLAPIC_SOFTWARE_DISABLE_MASK)
  73.700 +                vlapic->lvt[vt] |= VLAPIC_LVT_BIT_MASK;
  73.701 +
  73.702 +            /* On hardware, when write vector less than 0x20 will error */
  73.703 +            vlapic_check_vector(vlapic, vlapic_lvt_dm(vlapic->lvt[vt]),
  73.704 +              vlapic_lvt_vector(vlapic, vt));
  73.705 +
  73.706 +            if (!vlapic->vcpu_id && (offset == APIC_LVT0)) {
  73.707 +                if ((vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_DELIMOD)
  73.708 +                            == 0x700) {
  73.709 +                    if (!(vlapic->lvt[VLAPIC_LVT_LINT0] & VLAPIC_LVT_BIT_MASK)) {
  73.710 +                        set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  73.711 +                    }else
  73.712 +                        clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  73.713 +                }
  73.714 +                else
  73.715 +                    clear_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  73.716 +            }
  73.717 +
  73.718 +        }
  73.719 +        break;
  73.720 +
  73.721 +    case APIC_TMICT:
  73.722 +        if (vlapic_timer_active(vlapic))
  73.723 +            rem_ac_timer(&(vlapic->vlapic_timer));
  73.724 +
  73.725 +        vlapic->timer_initial = val;
  73.726 +        vlapic->timer_current = val;
  73.727 +        vlapic->timer_current_update = NOW();
  73.728 +
  73.729 +        VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.730 +          "timer_init %x timer_current %x timer_current_update %08x%08x",
  73.731 +          vlapic->timer_initial, vlapic->timer_current, (uint32_t)(vlapic->timer_current_update>>32), (uint32_t)vlapic->timer_current_update);
  73.732 +        vlapic_begin_timer(vlapic);
  73.733 +        break;
  73.734 +
  73.735 +    case APIC_TDCR:
  73.736 +        {
  73.737 +            //FIXME clean this code
  73.738 +            unsigned char tmp1,tmp2;
  73.739 +            tmp1 = (val & 0xf);
  73.740 +            tmp2 = ((tmp1 & 0x3 )|((tmp1 & 0x8) >>1)) + 1;
  73.741 +            vlapic->timer_divide_counter = 0x1<<tmp2;
  73.742 +
  73.743 +            VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  73.744 +                        "timer divider is 0x%x",
  73.745 +                        vlapic->timer_divide_counter);
  73.746 +        }
  73.747 +        break;
  73.748 +
  73.749 +    default:
  73.750 +        printk("Local APIC Write to read-only register\n");
  73.751 +        break;
  73.752 +    }
  73.753 +    return 1;
  73.754 +}
  73.755 +
  73.756 +int vlapic_range(struct vcpu *v, unsigned long addr)
  73.757 +{
  73.758 +    struct vlapic *vlapic = VLAPIC(v);
  73.759 +
  73.760 +    if (vlapic_global_enabled(vlapic) &&
  73.761 +        (addr >= vlapic->base_address) &&
  73.762 +        (addr <= (vlapic->base_address + VLOCAL_APIC_MEM_LENGTH)))
  73.763 +        return 1;
  73.764 +
  73.765 +    return 0;
  73.766 +}
  73.767 +
  73.768 +void vlapic_msr_set(struct vlapic *vlapic, uint64_t value)
  73.769 +{
  73.770 +    /* When apic disabled */
  73.771 +    if (!vlapic)
  73.772 +        return;
  73.773 +
  73.774 +    if (vlapic->vcpu_id)
  73.775 +        value &= ~MSR_IA32_APICBASE_BSP;
  73.776 +
  73.777 +    vlapic->apic_base_msr = value;
  73.778 +    vlapic->base_address = vlapic_get_base_address(vlapic);
  73.779 +
  73.780 +    if (!(value & 0x800))
  73.781 +        set_bit(_VLAPIC_GLOB_DISABLE, &vlapic->status );
  73.782 +
  73.783 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.784 +                "apic base msr = 0x%08x%08x,\nbase address = 0x%lx",
  73.785 +                (uint32_t)(vlapic->apic_base_msr >> 32),
  73.786 +                (uint32_t)vlapic->apic_base_msr,
  73.787 +                vlapic->base_address);
  73.788 +}
  73.789 +
  73.790 +static inline int vlapic_get_init_id(struct vcpu *v)
  73.791 +{
  73.792 +    return v->vcpu_id;
  73.793 +}
  73.794 +
  73.795 +void vlapic_timer_fn(void *data)
  73.796 +{
  73.797 +    struct vlapic *vlapic;
  73.798 +
  73.799 +    vlapic = data;
  73.800 +    if (!vlapic_enabled(vlapic)) return;
  73.801 +
  73.802 +    vlapic->timer_current_update = NOW();
  73.803 +
  73.804 +    if (vlapic_lvt_timer_enabled(vlapic)) {
  73.805 +        if (!vlapic_irr_status(vlapic,
  73.806 +              vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER))) {
  73.807 +            test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
  73.808 +              &vlapic->irr[0]);
  73.809 +        }
  73.810 +        else
  73.811 +            vlapic->intr_pending_count[vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)]++;
  73.812 +    }
  73.813 +
  73.814 +    vlapic->timer_current_update = NOW();
  73.815 +    if (vlapic_lvt_timer_period(vlapic)) {
  73.816 +        s_time_t offset;
  73.817 +
  73.818 +        vlapic->timer_current = vlapic->timer_initial;
  73.819 +        offset = vlapic->timer_current * (262144/get_apic_bus_scale()) * vlapic->timer_divide_counter;
  73.820 +        vlapic->vlapic_timer.expires = NOW() + offset;
  73.821 +        set_ac_timer(&(vlapic->vlapic_timer), vlapic->vlapic_timer.expires);
  73.822 +    }else {
  73.823 +        vlapic->timer_current = 0;
  73.824 +    }
  73.825 +
  73.826 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC_TIMER,
  73.827 +      "vlapic_timer_fn: now: %08x%08x expire %08x%08x init %x current %x",
  73.828 +      (uint32_t)(NOW() >> 32),(uint32_t)NOW(),
  73.829 +      (uint32_t)(vlapic->vlapic_timer.expires >> 32),
  73.830 +      (uint32_t)vlapic->vlapic_timer.expires,
  73.831 +      vlapic->timer_initial,vlapic->timer_current);
  73.832 +}
  73.833 +
  73.834 +#if 0
  73.835 +static int
  73.836 +vlapic_check_direct_intr(struct vcpu *v, int * mode)
  73.837 +{
  73.838 +    struct vlapic *vlapic = VLAPIC(v);
  73.839 +    int type;
  73.840 +
  73.841 +    type = __fls(vlapic->direct_intr.deliver_mode);
  73.842 +    if (type == -1)
  73.843 +        return -1;
  73.844 +
  73.845 +    *mode = type;
  73.846 +    return 0;
  73.847 +}
  73.848 +#endif
  73.849 +
  73.850 +int
  73.851 +vlapic_accept_pic_intr(struct vcpu *v)
  73.852 +{
  73.853 +    struct vlapic *vlapic = VLAPIC(v);
  73.854 +
  73.855 +    return vlapic ? test_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status) : 1;
  73.856 +}
  73.857 +
  73.858 +int cpu_get_apic_interrupt(struct vcpu* v, int *mode)
  73.859 +{
  73.860 +    struct vlapic *vlapic = VLAPIC(v);
  73.861 +
  73.862 +    if (vlapic && vlapic_enabled(vlapic)) {
  73.863 +        int highest_irr = vlapic_find_highest_irr(vlapic);
  73.864 +
  73.865 +        if (highest_irr != -1 && highest_irr >= vlapic->processor_priority) {
  73.866 +            if (highest_irr < 0x10) {
  73.867 +                vlapic->err_status |= 0x20;
  73.868 +                /* XXX What will happen if this vector illegal stil */
  73.869 +                VMX_DBG_LOG(DBG_LEVEL_VLAPIC,
  73.870 +                  "vmx_intr_assist: illegal vector number %x err_status %x",
  73.871 +                  highest_irr,  vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR));
  73.872 +
  73.873 +                set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR), &vlapic->irr[0]);
  73.874 +                highest_irr = vlapic_lvt_vector(vlapic, VLAPIC_LVT_ERROR);
  73.875 +            }
  73.876 +
  73.877 +            *mode = VLAPIC_DELIV_MODE_FIXED;
  73.878 +            return highest_irr;
  73.879 +        }
  73.880 +    }
  73.881 +    return -1;
  73.882 +}
  73.883 +
  73.884 +void vlapic_post_injection(struct vcpu *v, int vector, int deliver_mode) {
  73.885 +    struct vlapic  *vlapic = VLAPIC(v);
  73.886 +
  73.887 +    if (!vlapic)
  73.888 +        return;
  73.889 +
  73.890 +    switch (deliver_mode) {
  73.891 +    case VLAPIC_DELIV_MODE_FIXED:
  73.892 +    case VLAPIC_DELIV_MODE_LPRI:
  73.893 +        vlapic_set_isr(vlapic, vector);
  73.894 +        vlapic_clear_irr(vlapic, vector);
  73.895 +        vlapic_update_ppr(vlapic);
  73.896 +
  73.897 +        if (vector == vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER)) {
  73.898 +            vlapic->intr_pending_count[vector]--;
  73.899 +            if (vlapic->intr_pending_count[vector] > 0)
  73.900 +                test_and_set_bit(vlapic_lvt_vector(vlapic, VLAPIC_LVT_TIMER),
  73.901 +                  &vlapic->irr[0]);
  73.902 +        }
  73.903 +
  73.904 +        break;
  73.905 +        /*XXX deal with these later */
  73.906 +
  73.907 +    case VLAPIC_DELIV_MODE_RESERVED:
  73.908 +        printk("Ignore deliver mode 3 in vlapic_post_injection\n");
  73.909 +        break;
  73.910 +
  73.911 +    case VLAPIC_DELIV_MODE_SMI:
  73.912 +    case VLAPIC_DELIV_MODE_NMI:
  73.913 +    case VLAPIC_DELIV_MODE_INIT:
  73.914 +    case VLAPIC_DELIV_MODE_STARTUP:
  73.915 +        vlapic->direct_intr.deliver_mode &= ~(1 << deliver_mode);
  73.916 +        break;
  73.917 +
  73.918 +    default:
  73.919 +        printk("<vlapic_post_injection> error deliver mode\n");
  73.920 +        break;
  73.921 +    }
  73.922 +}
  73.923 +
  73.924 +static int vlapic_reset(struct vlapic *vlapic)
  73.925 +{
  73.926 +    struct vcpu *v = vlapic->vcpu;
  73.927 +    int apic_id = v->vcpu_id, i;
  73.928 +
  73.929 +    if (!v || !vlapic)
  73.930 +        return 0;
  73.931 +
  73.932 +    memset(vlapic, 0,sizeof(struct vlapic));
  73.933 +
  73.934 +    v->arch.arch_vmx.vlapic = vlapic;
  73.935 +
  73.936 +    vlapic->domain = v->domain;
  73.937 +
  73.938 +    vlapic->id = apic_id;
  73.939 +
  73.940 +    vlapic->version = VLAPIC_VERSION;
  73.941 +
  73.942 +    vlapic->apic_base_msr = VLAPIC_BASE_MSR_INIT_VALUE;
  73.943 +
  73.944 +    if (apic_id == 0)
  73.945 +        vlapic->apic_base_msr |= MSR_IA32_APICBASE_BSP;
  73.946 +    vlapic->base_address = vlapic_get_base_address(vlapic);
  73.947 +
  73.948 +    for (i = 0; i < VLAPIC_LVT_NUM; i++)
  73.949 +        vlapic->lvt[i] = VLAPIC_LVT_BIT_MASK;
  73.950 +
  73.951 +    vlapic->dest_format = 0xffffffffU;
  73.952 +
  73.953 +    vlapic->spurious_vec = 0xff;
  73.954 +
  73.955 +
  73.956 +    init_ac_timer(&vlapic->vlapic_timer,
  73.957 +      vlapic_timer_fn, vlapic, v->processor);
  73.958 +
  73.959 +#ifdef VLAPIC_NO_BIOS
  73.960 +    /*
  73.961 +     * XXX According to mp sepcific, BIOS will enable LVT0/1,
  73.962 +     * remove it after BIOS enabled
  73.963 +     */
  73.964 +    if (!v->vcpu_id) {
  73.965 +        vlapic->lvt[VLAPIC_LVT_LINT0] = 0x700;
  73.966 +        vlapic->lvt[VLAPIC_LVT_LINT1] = 0x500;
  73.967 +        set_bit(_VLAPIC_BSP_ACCEPT_PIC, &vlapic->status);
  73.968 +    }
  73.969 +#endif
  73.970 +
  73.971 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_reset: "
  73.972 +      "vcpu=%p id=%d vlapic_apic_base_msr=%08x%08x "
  73.973 +      "vlapic_base_address=%0lx",
  73.974 +      v, vlapic->id, (uint32_t)(vlapic->apic_base_msr >> 32),
  73.975 +      (uint32_t)vlapic->apic_base_msr, vlapic->base_address);
  73.976 +
  73.977 +    return 1;
  73.978 +}
  73.979 +
  73.980 +int vlapic_init(struct vcpu *v)
  73.981 +{
  73.982 +    struct vlapic *vlapic = NULL;
  73.983 +
  73.984 +    VMX_DBG_LOG(DBG_LEVEL_VLAPIC, "vlapic_init %d", v->vcpu_id);
  73.985 +
  73.986 +    vlapic = xmalloc_bytes(sizeof(struct vlapic));
  73.987 +
  73.988 +    if (!vlapic) {
  73.989 +        printk("malloc vlapic error for vcpu %x\n", v->vcpu_id);
  73.990 +        return -ENOMEM;
  73.991 +    }
  73.992 +
  73.993 +    vlapic->vcpu = v;
  73.994 +
  73.995 +    vlapic_reset(vlapic);
  73.996 +
  73.997 +    return 0;
  73.998 +}
  73.999 +
 73.1000 +#endif  /* CONFIG_VMX */
    74.1 --- a/xen/arch/x86/vmx_vmcs.c	Mon Oct 24 21:00:35 2005 -0600
    74.2 +++ b/xen/arch/x86/vmx_vmcs.c	Sat Oct 29 09:51:35 2005 +0100
    74.3 @@ -252,6 +252,10 @@ static void vmx_setup_platform(struct do
    74.4      pic_init(&platform->vmx_pic,  pic_irq_request, 
    74.5               &platform->interrupt_request);
    74.6      register_pic_io_hook();
    74.7 +
    74.8 +    if ( vmx_apic_support(d) ) {
    74.9 +        spin_lock_init(&d->arch.vmx_platform.round_robin_lock);
   74.10 +    }
   74.11  }
   74.12  
   74.13  static void vmx_set_host_env(struct vcpu *v)
   74.14 @@ -313,6 +317,9 @@ static void vmx_do_launch(struct vcpu *v
   74.15  
   74.16      vmx_stts();
   74.17  
   74.18 +    if(vmx_apic_support(v->domain))
   74.19 +        vlapic_init(v);
   74.20 +
   74.21      vmx_set_host_env(v);
   74.22  
   74.23      error |= __vmwrite(GUEST_LDTR_SELECTOR, 0);
    75.1 --- a/xen/common/acm_ops.c	Mon Oct 24 21:00:35 2005 -0600
    75.2 +++ b/xen/common/acm_ops.c	Sat Oct 29 09:51:35 2005 +0100
    75.3 @@ -133,7 +133,10 @@ long do_acm_op(struct acm_op * u_acm_op)
    75.4              struct domain *subj = find_domain_by_id(op->u.getssid.id.domainid);
    75.5              if (!subj)
    75.6                  return -ESRCH; /* domain not found */
    75.7 -
    75.8 +            if (subj->ssid == NULL) {
    75.9 +                put_domain(subj);
   75.10 +                return -ESRCH;
   75.11 +            }
   75.12              ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   75.13              put_domain(subj);
   75.14          } else
   75.15 @@ -167,6 +170,10 @@ long do_acm_op(struct acm_op * u_acm_op)
   75.16                  ret = -ESRCH; /* domain not found */
   75.17                  goto out;
   75.18              }
   75.19 +            if (subj->ssid == NULL) {
   75.20 +                put_domain(subj);
   75.21 +                ret = -ESRCH;
   75.22 +            }
   75.23              ssidref1 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   75.24              put_domain(subj);
   75.25          } else {
   75.26 @@ -182,6 +189,10 @@ long do_acm_op(struct acm_op * u_acm_op)
   75.27                  ret = -ESRCH; /* domain not found */
   75.28                  goto out;
   75.29              }
   75.30 +            if (subj->ssid == NULL) {
   75.31 +                put_domain(subj);
   75.32 +                return -ESRCH;
   75.33 +            }
   75.34              ssidref2 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
   75.35              put_domain(subj);
   75.36          } else {
    76.1 --- a/xen/common/schedule.c	Mon Oct 24 21:00:35 2005 -0600
    76.2 +++ b/xen/common/schedule.c	Sat Oct 29 09:51:35 2005 +0100
    76.3 @@ -514,7 +514,7 @@ static void dom_timer_fn(void *data)
    76.4  /* Initialise the data structures. */
    76.5  void __init scheduler_init(void)
    76.6  {
    76.7 -    int i;
    76.8 +    int i, rc;
    76.9  
   76.10      open_softirq(SCHEDULE_SOFTIRQ, __enter_scheduler);
   76.11  
   76.12 @@ -540,7 +540,9 @@ void __init scheduler_init(void)
   76.13  
   76.14      printk("Using scheduler: %s (%s)\n", ops.name, ops.opt_name);
   76.15  
   76.16 -    BUG_ON(SCHED_OP(alloc_task, idle_task[0]) < 0);
   76.17 +    rc = SCHED_OP(alloc_task, idle_task[0]);
   76.18 +    BUG_ON(rc < 0);
   76.19 +
   76.20      sched_add_domain(idle_task[0]);
   76.21  }
   76.22  
    77.1 --- a/xen/include/acm/acm_hooks.h	Mon Oct 24 21:00:35 2005 -0600
    77.2 +++ b/xen/include/acm/acm_hooks.h	Sat Oct 29 09:51:35 2005 +0100
    77.3 @@ -100,10 +100,10 @@ struct acm_operations {
    77.4      void (*fail_domain_create)         (void *subject_ssid, ssidref_t ssidref);
    77.5      void (*post_domain_destroy)        (void *object_ssid, domid_t id);
    77.6      /* event channel control hooks  (can be NULL) */
    77.7 -    int  (*pre_eventchannel_unbound)      (domid_t id);
    77.8 -    void (*fail_eventchannel_unbound)     (domid_t id);
    77.9 -    int  (*pre_eventchannel_interdomain)  (domid_t id1, domid_t id2);
   77.10 -    int  (*fail_eventchannel_interdomain) (domid_t id1, domid_t id2);
   77.11 +    int  (*pre_eventchannel_unbound)      (domid_t id1, domid_t id2);
   77.12 +    void (*fail_eventchannel_unbound)     (domid_t id1, domid_t id2);
   77.13 +    int  (*pre_eventchannel_interdomain)  (domid_t id);
   77.14 +    void (*fail_eventchannel_interdomain) (domid_t id);
   77.15      /* grant table control hooks (can be NULL)  */
   77.16      int  (*pre_grant_map_ref)          (domid_t id);
   77.17      void (*fail_grant_map_ref)         (domid_t id);
   77.18 @@ -193,31 +193,31 @@ static inline void acm_post_domain_destr
   77.19      return;
   77.20  }
   77.21  
   77.22 -static inline int acm_pre_eventchannel_unbound(domid_t id)
   77.23 +static inline int acm_pre_eventchannel_unbound(domid_t id1, domid_t id2)
   77.24  {
   77.25      if ((acm_primary_ops->pre_eventchannel_unbound != NULL) && 
   77.26 -        acm_primary_ops->pre_eventchannel_unbound(id))
   77.27 +        acm_primary_ops->pre_eventchannel_unbound(id1, id2))
   77.28          return ACM_ACCESS_DENIED;
   77.29      else if ((acm_secondary_ops->pre_eventchannel_unbound != NULL) && 
   77.30 -             acm_secondary_ops->pre_eventchannel_unbound(id)) {
   77.31 +             acm_secondary_ops->pre_eventchannel_unbound(id1, id2)) {
   77.32          /* roll-back primary */
   77.33          if (acm_primary_ops->fail_eventchannel_unbound != NULL)
   77.34 -            acm_primary_ops->fail_eventchannel_unbound(id);
   77.35 +            acm_primary_ops->fail_eventchannel_unbound(id1, id2);
   77.36          return ACM_ACCESS_DENIED;
   77.37      } else
   77.38          return ACM_ACCESS_PERMITTED;
   77.39  }
   77.40  
   77.41 -static inline int acm_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
   77.42 +static inline int acm_pre_eventchannel_interdomain(domid_t id)
   77.43  {
   77.44      if ((acm_primary_ops->pre_eventchannel_interdomain != NULL) &&
   77.45 -        acm_primary_ops->pre_eventchannel_interdomain(id1, id2))
   77.46 +        acm_primary_ops->pre_eventchannel_interdomain(id))
   77.47          return ACM_ACCESS_DENIED;
   77.48      else if ((acm_secondary_ops->pre_eventchannel_interdomain != NULL) &&
   77.49 -             acm_secondary_ops->pre_eventchannel_interdomain(id1, id2)) {
   77.50 +             acm_secondary_ops->pre_eventchannel_interdomain(id)) {
   77.51          /* roll-back primary */
   77.52          if (acm_primary_ops->fail_eventchannel_interdomain != NULL)
   77.53 -            acm_primary_ops->fail_eventchannel_interdomain(id1, id2);
   77.54 +            acm_primary_ops->fail_eventchannel_interdomain(id);
   77.55          return ACM_ACCESS_DENIED;
   77.56      } else
   77.57          return ACM_ACCESS_PERMITTED;
   77.58 @@ -234,10 +234,22 @@ static inline int acm_pre_dom0_op(dom0_o
   77.59              current->domain->ssid, op->u.createdomain.ssidref);
   77.60          break;
   77.61      case DOM0_DESTROYDOMAIN:
   77.62 +        if (*ssid != NULL) {
   77.63 +            printkd("%s: Warning. Overlapping destruction.\n", 
   77.64 +                    __func__);
   77.65 +            return -EACCES;
   77.66 +        }
   77.67          d = find_domain_by_id(op->u.destroydomain.domain);
   77.68          if (d != NULL) {
   77.69              *ssid = d->ssid; /* save for post destroy when d is gone */
   77.70 -            /* no policy-specific hook */
   77.71 +            if (*ssid == NULL) {
   77.72 +                printk("%s: Warning. Destroying domain without ssid pointer.\n", 
   77.73 +                       __func__);
   77.74 +                put_domain(d);
   77.75 +                return -EACCES;
   77.76 +            }
   77.77 +            d->ssid = NULL; /* make sure it's not used any more */
   77.78 +             /* no policy-specific hook */
   77.79              put_domain(d);
   77.80              ret = 0;
   77.81          }
   77.82 @@ -248,7 +260,7 @@ static inline int acm_pre_dom0_op(dom0_o
   77.83      return ret;
   77.84  }
   77.85  
   77.86 -static inline void acm_post_dom0_op(dom0_op_t *op, void *ssid) 
   77.87 +static inline void acm_post_dom0_op(dom0_op_t *op, void **ssid)
   77.88  {
   77.89      switch(op->cmd) {
   77.90      case DOM0_CREATEDOMAIN:
   77.91 @@ -261,7 +273,8 @@ static inline void acm_post_dom0_op(dom0
   77.92      case DOM0_DESTROYDOMAIN:
   77.93          acm_post_domain_destroy(ssid, op->u.destroydomain.domain);
   77.94          /* free security ssid for the destroyed domain (also if null policy */
   77.95 -        acm_free_domain_ssid((struct acm_ssid_domain *)ssid);
   77.96 +        acm_free_domain_ssid((struct acm_ssid_domain *)(*ssid));
   77.97 +        *ssid = NULL;
   77.98          break;
   77.99      }
  77.100  }
  77.101 @@ -282,12 +295,13 @@ static inline int acm_pre_event_channel(
  77.102  
  77.103      switch(op->cmd) {
  77.104      case EVTCHNOP_alloc_unbound:
  77.105 -        ret = acm_pre_eventchannel_unbound(op->u.alloc_unbound.dom);
  77.106 +        ret = acm_pre_eventchannel_unbound(
  77.107 +                  op->u.alloc_unbound.dom,
  77.108 +                  op->u.alloc_unbound.remote_dom);
  77.109          break;
  77.110      case EVTCHNOP_bind_interdomain:
  77.111          ret = acm_pre_eventchannel_interdomain(
  77.112 -            current->domain->domain_id,
  77.113 -            op->u.bind_interdomain.remote_dom);
  77.114 +                  op->u.bind_interdomain.remote_dom);
  77.115          break;
  77.116      default:
  77.117          ret = 0; /* ok */
    78.1 --- a/xen/include/asm-x86/vmx_intercept.h	Mon Oct 24 21:00:35 2005 -0600
    78.2 +++ b/xen/include/asm-x86/vmx_intercept.h	Sat Oct 29 09:51:35 2005 +0100
    78.3 @@ -14,6 +14,16 @@
    78.4  #define VMX_MMIO                    1
    78.5  
    78.6  typedef int (*intercept_action_t)(ioreq_t *);
    78.7 +typedef unsigned long (*vmx_mmio_read_t)(struct vcpu *v,
    78.8 +                                         unsigned long addr,
    78.9 +                                         unsigned long length);
   78.10 +
   78.11 +typedef unsigned long (*vmx_mmio_write_t)(struct vcpu *v,
   78.12 +                                         unsigned long addr,
   78.13 +                                         unsigned long length,
   78.14 +                                         unsigned long val);
   78.15 +
   78.16 +typedef int (*vmx_mmio_check_t)(struct vcpu *v, unsigned long addr);
   78.17  
   78.18  struct io_handler {
   78.19      int                 type;
   78.20 @@ -27,6 +37,16 @@ struct vmx_io_handler {
   78.21      struct  io_handler hdl_list[MAX_IO_HANDLER];
   78.22  };
   78.23  
   78.24 +struct vmx_mmio_handler {
   78.25 +    vmx_mmio_check_t check_handler;
   78.26 +    vmx_mmio_read_t read_handler;
   78.27 +    vmx_mmio_write_t write_handler;
   78.28 +};
   78.29 +
   78.30 +#define VMX_MMIO_HANDLER_NR 1
   78.31 +
   78.32 +extern struct vmx_mmio_handler vmx_mmio_handers[VMX_MMIO_HANDLER_NR];
   78.33 +
   78.34  /* global io interception point in HV */
   78.35  extern int vmx_io_intercept(ioreq_t *p, int type);
   78.36  extern int register_io_handler(unsigned long addr, unsigned long size,
   78.37 @@ -37,10 +57,7 @@ static inline int vmx_portio_intercept(i
   78.38      return vmx_io_intercept(p, VMX_PORTIO);
   78.39  }
   78.40  
   78.41 -static inline int vmx_mmio_intercept(ioreq_t *p)
   78.42 -{
   78.43 -    return vmx_io_intercept(p, VMX_MMIO);
   78.44 -}
   78.45 +int vmx_mmio_intercept(ioreq_t *p);
   78.46  
   78.47  static inline int register_portio_handler(unsigned long addr,
   78.48                                            unsigned long size,
   78.49 @@ -49,11 +66,4 @@ static inline int register_portio_handle
   78.50      return register_io_handler(addr, size, action, VMX_PORTIO);
   78.51  }
   78.52  
   78.53 -static inline int register_mmio_handler(unsigned long addr,
   78.54 -                                        unsigned long size,
   78.55 -                                        intercept_action_t action)
   78.56 -{
   78.57 -    return register_io_handler(addr, size, action, VMX_MMIO);
   78.58 -}
   78.59 -
   78.60  #endif /* _VMX_INTERCEPT_H */
    79.1 --- a/xen/include/asm-x86/vmx_platform.h	Mon Oct 24 21:00:35 2005 -0600
    79.2 +++ b/xen/include/asm-x86/vmx_platform.h	Sat Oct 29 09:51:35 2005 +0100
    79.3 @@ -80,10 +80,13 @@ struct instruction {
    79.4  struct vmx_platform {
    79.5      unsigned long          shared_page_va;
    79.6      unsigned int           nr_vcpu;
    79.7 +    unsigned int           lapic_enable;
    79.8  
    79.9      struct vmx_virpit      vmx_pit;
   79.10      struct vmx_io_handler  vmx_io_handler;
   79.11      struct vmx_virpic      vmx_pic;
   79.12 +    unsigned char          round_info[256];
   79.13 +    spinlock_t             round_robin_lock;
   79.14      int                    interrupt_request;
   79.15  };
   79.16  
    80.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    80.2 +++ b/xen/include/asm-x86/vmx_vlapic.h	Sat Oct 29 09:51:35 2005 +0100
    80.3 @@ -0,0 +1,245 @@
    80.4 +/*
    80.5 + * vmx_vlapic.h: virtualize LAPIC definitions.
    80.6 + * Copyright (c) 2004, Intel Corporation.
    80.7 + *
    80.8 + * This program is free software; you can redistribute it and/or modify it
    80.9 + * under the terms and conditions of the GNU General Public License,
   80.10 + * version 2, as published by the Free Software Foundation.
   80.11 + *
   80.12 + * This program is distributed in the hope it will be useful, but WITHOUT
   80.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   80.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   80.15 + * more details.
   80.16 + *
   80.17 + * You should have received a copy of the GNU General Public License along with
   80.18 + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
   80.19 + * Place - Suite 330, Boston, MA 02111-1307 USA.
   80.20 + *
   80.21 + */
   80.22 +
   80.23 +#ifndef VMX_VLAPIC_H
   80.24 +#define VMX_VLAPIC_H
   80.25 +
   80.26 +#include <asm/msr.h>
   80.27 +#include <public/io/ioreq.h>
   80.28 +
   80.29 +#if defined(__i386__) || defined(__x86_64__)
   80.30 +static inline int __fls(uint32_t word)
   80.31 +{
   80.32 +    int bit;
   80.33 +
   80.34 +    __asm__("bsrl %1,%0"
   80.35 +      :"=r" (bit)
   80.36 +      :"rm" (word));
   80.37 +    return word ? bit : -1;
   80.38 +}
   80.39 +#else
   80.40 +#define __fls(x)    generic_fls(x)
   80.41 +static __inline__ int generic_fls(uint32_t x)
   80.42 +{
   80.43 +    int r = 31;
   80.44 +
   80.45 +    if (!x)
   80.46 +        return -1;
   80.47 +    if (!(x & 0xffff0000u)) {
   80.48 +        x <<= 16;
   80.49 +        r -= 16;
   80.50 +    }
   80.51 +    if (!(x & 0xff000000u)) {
   80.52 +        x <<= 8;
   80.53 +        r -= 8;
   80.54 +    }
   80.55 +    if (!(x & 0xf0000000u)) {
   80.56 +        x <<= 4;
   80.57 +        r -= 4;
   80.58 +    }
   80.59 +    if (!(x & 0xc0000000u)) {
   80.60 +        x <<= 2;
   80.61 +        r -= 2;
   80.62 +    }
   80.63 +    if (!(x & 0x80000000u)) {
   80.64 +        x <<= 1;
   80.65 +        r -= 1;
   80.66 +    }
   80.67 +    return r;
   80.68 +}
   80.69 +#endif
   80.70 +
   80.71 +static __inline__ int find_highest_bit(uint32_t *data, int length)
   80.72 +{
   80.73 +    while(length && !data[--length]);
   80.74 +    return __fls(data[length]) +  32 * length;
   80.75 +}
   80.76 +
   80.77 +#define VLAPIC(v)                       (v->arch.arch_vmx.vlapic)
   80.78 +
   80.79 +#define VAPIC_ID_MASK                   0xff
   80.80 +#define VAPIC_LDR_MASK                  (VAPIC_ID_MASK << 24)
   80.81 +#define VLAPIC_VERSION                  0x00050014
   80.82 +
   80.83 +#define VLAPIC_BASE_MSR_MASK            0x00000000fffff900ULL
   80.84 +#define VLAPIC_BASE_MSR_INIT_BASE_ADDR  0xfee00000U
   80.85 +#define VLAPIC_BASE_MSR_BASE_ADDR_MASK  0xfffff000U
   80.86 +#define VLAPIC_BASE_MSR_INIT_VALUE      (VLAPIC_BASE_MSR_INIT_BASE_ADDR | \
   80.87 +                                         MSR_IA32_APICBASE_ENABLE)
   80.88 +#define VLOCAL_APIC_MEM_LENGTH          (1 << 12)
   80.89 +
   80.90 +#define VLAPIC_LVT_TIMER                0
   80.91 +#define VLAPIC_LVT_THERMAL              1
   80.92 +#define VLAPIC_LVT_PERFORM              2
   80.93 +#define VLAPIC_LVT_LINT0                3
   80.94 +#define VLAPIC_LVT_LINT1                4
   80.95 +#define VLAPIC_LVT_ERROR                5
   80.96 +#define VLAPIC_LVT_NUM                  6
   80.97 +
   80.98 +#define VLAPIC_LVT_BIT_MASK             (1 << 16)
   80.99 +#define VLAPIC_LVT_BIT_VECTOR           0xff
  80.100 +#define VLAPIC_LVT_BIT_DELIMOD          (0x7 << 8)
  80.101 +#define VLAPIC_LVT_BIT_DELISTATUS       (1 << 12)
  80.102 +#define VLAPIC_LVT_BIT_POLARITY         (1 << 13)
  80.103 +#define VLAPIC_LVT_BIT_IRR              (1 << 14)
  80.104 +#define VLAPIC_LVT_BIT_TRIG             (1 << 15)
  80.105 +#define VLAPIC_LVT_TIMERMODE            (1 << 17)
  80.106 +
  80.107 +#define VLAPIC_DELIV_MODE_FIXED          0x0
  80.108 +#define VLAPIC_DELIV_MODE_LPRI           0x1
  80.109 +#define VLAPIC_DELIV_MODE_SMI            0x2
  80.110 +#define VLAPIC_DELIV_MODE_RESERVED       0x3
  80.111 +#define VLAPIC_DELIV_MODE_NMI            0x4
  80.112 +#define VLAPIC_DELIV_MODE_INIT           0x5
  80.113 +#define VLAPIC_DELIV_MODE_STARTUP        0x6
  80.114 +#define VLAPIC_DELIV_MODE_EXT            0x7
  80.115 +
  80.116 +
  80.117 +
  80.118 +#define VLAPIC_NO_SHORTHAND             0x0
  80.119 +#define VLAPIC_SHORTHAND_SELF           0x1
  80.120 +#define VLAPIC_SHORTHAND_INCLUDE_SELF   0x2
  80.121 +#define VLAPIC_SHORTHAND_EXCLUDE_SELF   0x3
  80.122 +
  80.123 +#define vlapic_lvt_timer_enabled(vlapic)    \
  80.124 +  (!(vlapic->lvt[VLAPIC_LVT_TIMER] & VLAPIC_LVT_BIT_MASK))
  80.125 +
  80.126 +#define vlapic_lvt_vector(vlapic, type)   \
  80.127 +  (vlapic->lvt[type] & VLAPIC_LVT_BIT_VECTOR)
  80.128 +
  80.129 +#define vlapic_lvt_dm(value)        ((value >> 8) && 7)
  80.130 +#define vlapic_lvt_timer_period(vlapic) \
  80.131 +  (vlapic->lvt[VLAPIC_LVT_TIMER] & VLAPIC_LVT_TIMERMODE)
  80.132 +
  80.133 +#define vlapic_isr_status(vlapic,vector)    \
  80.134 +  test_bit(vector, &vlapic->isr[0])
  80.135 +
  80.136 +#define vlapic_irr_status(vlapic,vector)    \
  80.137 +  test_bit(vector, &vlapic->irr[0])
  80.138 +
  80.139 +#define vlapic_set_isr(vlapic,vector) \
  80.140 +  test_and_set_bit(vector, &vlapic->isr[0])
  80.141 +
  80.142 +#define vlapic_set_irr(vlapic,vector)      \
  80.143 +  test_and_set_bit(vector, &vlapic->irr[0])
  80.144 +
  80.145 +#define vlapic_clear_irr(vlapic,vector)      \
  80.146 +  clear_bit(vector, &vlapic->irr[0])
  80.147 +#define vlapic_clear_isr(vlapic,vector)     \
  80.148 +  clear_bit(vector, &vlapic->isr[0])
  80.149 +
  80.150 +#define vlapic_enabled(vlapic)               \
  80.151 +  (!(vlapic->status &                           \
  80.152 +     (VLAPIC_GLOB_DISABLE_MASK | VLAPIC_SOFTWARE_DISABLE_MASK)))
  80.153 +
  80.154 +#define vlapic_global_enabled(vlapic)               \
  80.155 +  !(test_bit(_VLAPIC_GLOB_DISABLE, &(vlapic)->status))
  80.156 +
  80.157 +typedef struct direct_intr_info {
  80.158 +    int deliver_mode;
  80.159 +    int source[6];
  80.160 +} direct_intr_info_t;
  80.161 +
  80.162 +#define VLAPIC_INIT_SIPI_SIPI_STATE_NORM          0
  80.163 +#define VLAPIC_INIT_SIPI_SIPI_STATE_WAIT_SIPI     1
  80.164 +
  80.165 +struct vlapic
  80.166 +{
  80.167 +    //FIXME check what would be 64 bit on EM64T
  80.168 +    uint32_t           version;
  80.169 +#define _VLAPIC_GLOB_DISABLE            0x0
  80.170 +#define VLAPIC_GLOB_DISABLE_MASK        0x1
  80.171 +#define VLAPIC_SOFTWARE_DISABLE_MASK    0x2
  80.172 +#define _VLAPIC_BSP_ACCEPT_PIC          0x3
  80.173 +    uint32_t           status;
  80.174 +    uint32_t           id;
  80.175 +    uint32_t           vcpu_id;
  80.176 +    unsigned long      base_address;
  80.177 +    uint32_t           isr[8];
  80.178 +    uint32_t           irr[INTR_LEN_32];
  80.179 +    uint32_t           tmr[INTR_LEN_32];
  80.180 +    uint32_t           task_priority;
  80.181 +    uint32_t           processor_priority;
  80.182 +    uint32_t           logical_dest;
  80.183 +    uint32_t           dest_format;
  80.184 +    uint32_t           spurious_vec;
  80.185 +    uint32_t           lvt[6];
  80.186 +    uint32_t           timer_initial;
  80.187 +    uint32_t           timer_current;
  80.188 +    uint32_t           timer_divconf;
  80.189 +    uint32_t           timer_divide_counter;
  80.190 +    struct ac_timer    vlapic_timer;
  80.191 +    int                intr_pending_count[MAX_VECTOR];
  80.192 +    s_time_t           timer_current_update;
  80.193 +    uint32_t           icr_high;
  80.194 +    uint32_t           icr_low;
  80.195 +    direct_intr_info_t direct_intr;
  80.196 +    uint32_t           err_status;
  80.197 +    unsigned long      init_ticks;
  80.198 +    uint32_t           err_write_count;
  80.199 +    uint64_t           apic_base_msr;
  80.200 +    uint32_t           init_sipi_sipi_state;
  80.201 +    struct vcpu        *vcpu;
  80.202 +    struct domain      *domain;
  80.203 +};
  80.204 +
  80.205 +static inline int  vlapic_timer_active(struct vlapic *vlapic)
  80.206 +{
  80.207 +    return  active_ac_timer(&(vlapic->vlapic_timer));
  80.208 +}
  80.209 +
  80.210 +int vlapic_find_highest_irr(struct vlapic *vlapic);
  80.211 +
  80.212 +int vlapic_find_highest_isr(struct vlapic *vlapic);
  80.213 +
  80.214 +static uint32_t inline vlapic_get_base_address(struct vlapic *vlapic)
  80.215 +{
  80.216 +    return (vlapic->apic_base_msr & VLAPIC_BASE_MSR_BASE_ADDR_MASK);
  80.217 +}
  80.218 +
  80.219 +void vlapic_post_injection(struct vcpu* v, int vector, int deliver_mode);
  80.220 +
  80.221 +int cpu_get_apic_interrupt(struct vcpu* v, int *mode);
  80.222 +
  80.223 +extern uint32_t vlapic_update_ppr(struct vlapic *vlapic);
  80.224 +
  80.225 +int vlapic_update(struct vcpu *v);
  80.226 +
  80.227 +extern int vlapic_init(struct vcpu *vc);
  80.228 +
  80.229 +extern void vlapic_msr_set(struct vlapic *vlapic, uint64_t value);
  80.230 +
  80.231 +int vlapic_range(struct vcpu *v, unsigned long addr);
  80.232 +
  80.233 +unsigned long vlapic_write(struct vcpu *v, unsigned long address,
  80.234 +                           unsigned long len, unsigned long val);
  80.235 +
  80.236 +unsigned long vlapic_read(struct vcpu *v, unsigned long address,
  80.237 +                          unsigned long len);
  80.238 +
  80.239 +int vlapic_accept_pic_intr(struct vcpu *v);
  80.240 +
  80.241 +struct vlapic* apic_round_robin(struct domain *d,
  80.242 +                                uint8_t dest_mode,
  80.243 +                                uint8_t vector,
  80.244 +                                uint32_t bitmap);
  80.245 +
  80.246 +int vmx_apic_support(struct domain *d);
  80.247 +
  80.248 +#endif /* VMX_VLAPIC_H */
    81.1 --- a/xen/include/asm-x86/vmx_vmcs.h	Mon Oct 24 21:00:35 2005 -0600
    81.2 +++ b/xen/include/asm-x86/vmx_vmcs.h	Sat Oct 29 09:51:35 2005 +0100
    81.3 @@ -22,6 +22,7 @@
    81.4  #include <asm/config.h>
    81.5  #include <asm/vmx_cpu.h>
    81.6  #include <asm/vmx_platform.h>
    81.7 +#include <asm/vmx_vlapic.h>
    81.8  #include <public/vmx_assist.h>
    81.9  
   81.10  extern int start_vmx(void);
   81.11 @@ -96,6 +97,7 @@ struct arch_vmx_struct {
   81.12      struct msr_state        msr_content;
   81.13      struct mmio_op          mmio_op;  /* MMIO */
   81.14      void                    *io_bitmap_a, *io_bitmap_b;
   81.15 +    struct vlapic           *vlapic;
   81.16      u64                     tsc_offset;
   81.17  };
   81.18  
   81.19 @@ -272,18 +274,21 @@ enum vmcs_field {
   81.20  
   81.21  #define VMX_DEBUG 1
   81.22  #if VMX_DEBUG
   81.23 -#define DBG_LEVEL_0     (1 << 0)
   81.24 -#define DBG_LEVEL_1     (1 << 1)
   81.25 -#define DBG_LEVEL_2     (1 << 2)
   81.26 -#define DBG_LEVEL_3     (1 << 3)
   81.27 -#define DBG_LEVEL_IO    (1 << 4)
   81.28 -#define DBG_LEVEL_VMMU  (1 << 5)
   81.29 +#define DBG_LEVEL_0                 (1 << 0)
   81.30 +#define DBG_LEVEL_1                 (1 << 1)
   81.31 +#define DBG_LEVEL_2                 (1 << 2)
   81.32 +#define DBG_LEVEL_3                 (1 << 3)
   81.33 +#define DBG_LEVEL_IO                (1 << 4)
   81.34 +#define DBG_LEVEL_VMMU              (1 << 5)
   81.35 +#define DBG_LEVEL_VLAPIC            (1 << 6)
   81.36 +#define DBG_LEVEL_VLAPIC_TIMER      (1 << 7)
   81.37 +#define DBG_LEVEL_VLAPIC_INTERRUPT  (1 << 7)
   81.38  
   81.39  extern unsigned int opt_vmx_debug_level;
   81.40  #define VMX_DBG_LOG(level, _f, _a...)           \
   81.41      if ((level) & opt_vmx_debug_level)          \
   81.42          printk("[VMX:%d.%d] " _f "\n",          \
   81.43 -                current->domain->domain_id, current->vcpu_id, ## _a)
   81.44 +               current->domain->domain_id, current->vcpu_id, ## _a)
   81.45  #else
   81.46  #define VMX_DBG_LOG(level, _f, _a...)
   81.47  #endif
    82.1 --- a/xen/include/public/io/ioreq.h	Mon Oct 24 21:00:35 2005 -0600
    82.2 +++ b/xen/include/public/io/ioreq.h	Sat Oct 29 09:51:35 2005 +0100
    82.3 @@ -29,11 +29,11 @@
    82.4  #define STATE_IORESP_READY      3
    82.5  #define STATE_IORESP_HOOK       4
    82.6  
    82.7 -#define IOREQ_TYPE_PIO  0 /* pio */
    82.8 -#define IOREQ_TYPE_COPY  1 /* mmio ops */
    82.9 -#define IOREQ_TYPE_AND  2
   82.10 -#define IOREQ_TYPE_OR  3
   82.11 -#define IOREQ_TYPE_XOR  4
   82.12 +#define IOREQ_TYPE_PIO          0 /* pio */
   82.13 +#define IOREQ_TYPE_COPY         1 /* mmio ops */
   82.14 +#define IOREQ_TYPE_AND          2
   82.15 +#define IOREQ_TYPE_OR           3
   82.16 +#define IOREQ_TYPE_XOR          4
   82.17  
   82.18  /*
   82.19   * VMExit dispatcher should cooperate with instruction decoder to
   82.20 @@ -55,9 +55,10 @@ typedef struct {
   82.21      uint8_t type;    /* I/O type                     */
   82.22  } ioreq_t;
   82.23  
   82.24 -#define MAX_VECTOR    256
   82.25 +#define MAX_VECTOR      256
   82.26  #define BITS_PER_BYTE   8
   82.27  #define INTR_LEN        (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint64_t)))
   82.28 +#define INTR_LEN_32     (MAX_VECTOR/(BITS_PER_BYTE * sizeof(uint32_t)))
   82.29  
   82.30  typedef struct {
   82.31      uint16_t  pic_elcr;
    83.1 --- a/xen/include/public/io/vmx_vpic.h	Mon Oct 24 21:00:35 2005 -0600
    83.2 +++ b/xen/include/public/io/vmx_vpic.h	Sat Oct 29 09:51:35 2005 +0100
    83.3 @@ -76,7 +76,7 @@ void pic_update_irq(struct vmx_virpic *s
    83.4  uint32_t pic_intack_read(struct vmx_virpic *s);
    83.5  void register_pic_io_hook (void);
    83.6  int cpu_get_pic_interrupt(struct vcpu *v, int *type);
    83.7 -int is_pit_irq(struct vcpu *v, int irq);
    83.8 +int is_pit_irq(struct vcpu *v, int irq, int type);
    83.9  void do_pic_irqs (struct vmx_virpic *s, uint16_t irqs);
   83.10  void do_pic_irqs_clear (struct vmx_virpic *s, uint16_t irqs);
   83.11  
    84.1 --- a/xen/include/public/xen.h	Mon Oct 24 21:00:35 2005 -0600
    84.2 +++ b/xen/include/public/xen.h	Sat Oct 29 09:51:35 2005 +0100
    84.3 @@ -410,6 +410,7 @@ typedef struct shared_info {
    84.4  #define MAX_GUEST_CMDLINE 1024
    84.5  typedef struct start_info {
    84.6      /* THE FOLLOWING ARE FILLED IN BOTH ON INITIAL BOOT AND ON RESUME.    */
    84.7 +    char magic[32];             /* "Xen-<version>.<subversion>". */
    84.8      unsigned long nr_pages;     /* Total pages allocated to this domain.  */
    84.9      unsigned long shared_info;  /* MACHINE address of shared info struct. */
   84.10      uint32_t flags;             /* SIF_xxx flags.                         */
    85.1 --- a/xen/include/xen/sched.h	Mon Oct 24 21:00:35 2005 -0600
    85.2 +++ b/xen/include/xen/sched.h	Sat Oct 29 09:51:35 2005 +0100
    85.3 @@ -101,7 +101,6 @@ struct domain
    85.4      struct list_head xenpage_list;    /* linked list, of size xenheap_pages */
    85.5      unsigned int     tot_pages;       /* number of pages currently possesed */
    85.6      unsigned int     max_pages;       /* maximum value for tot_pages        */
    85.7 -    unsigned int     next_io_page;    /* next io pfn to give to domain      */
    85.8      unsigned int     xenheap_pages;   /* # pages allocated from Xen heap    */
    85.9  
   85.10      /* Scheduling. */