ia64/xen-unstable

changeset 7007:55fc0ecc19c3

Merge.
author emellor@ewan
date Wed Sep 21 15:25:58 2005 +0100 (2005-09-21)
parents 9647be59212d 7a45b8ccef01
children f71bb61e0500
files .hgignore extras/mini-os/xenbus/xenbus_xs.c linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h tools/examples/network-bridge tools/examples/xmexample.vmx tools/ioemu/vl.c tools/libxc/xc_vmx_build.c tools/python/xen/lowlevel/xc/xc.c tools/python/xen/util/process.py tools/python/xen/xend/PrettyPrint.py tools/python/xen/xend/XendBootloader.py tools/python/xen/xend/XendCheckpoint.py tools/python/xen/xend/XendClient.py tools/python/xen/xend/XendDmesg.py tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendLogging.py tools/python/xen/xend/XendNode.py tools/python/xen/xend/XendProtocol.py tools/python/xen/xend/encode.py tools/python/xen/xend/image.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/tpmif.py tools/python/xen/xend/xenstore/xsnode.py tools/python/xen/xend/xenstore/xstransact.py tools/python/xen/xm/create.py tools/vtpm/tpm_emulator-0.2b-x86_64.patch xen/arch/x86/vmx.c xen/arch/x86/vmx_io.c xen/arch/x86/vmx_vmcs.c xen/include/asm-x86/vmx.h xen/include/asm-x86/vmx_vmcs.h xen/include/public/io/tpmif.h
line diff
     1.1 --- a/.hgignore	Wed Sep 21 15:23:26 2005 +0100
     1.2 +++ b/.hgignore	Wed Sep 21 15:25:58 2005 +0100
     1.3 @@ -139,9 +139,10 @@
     1.4  ^tools/vnet/vnet-module/\..*\.cmd$
     1.5  ^tools/vnet/vnet-module/\.tmp_versions/.*$
     1.6  ^tools/vnet/vnet-module/vnet_module\.mod\..*$
     1.7 -^tools/vtpm/vtpm*
     1.8 -^tools/vtpm/tpm_emulator-*
     1.9 -^tools/vtpm_manager/manager/vtpm_managerd
    1.10 +^tools/vtpm/tpm_emulator/.*$
    1.11 +^tools/vtpm/tpm_emulator-.*\.tar\.gz$
    1.12 +^tools/vtpm/vtpm/.*$
    1.13 +^tools/vtpm_manager/manager/vtpm_managerd$
    1.14  ^tools/xcutils/xc_restore$
    1.15  ^tools/xcutils/xc_save$
    1.16  ^tools/xenstat/xentop/xentop$
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 15:23:26 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 15:25:58 2005 +0100
     2.3 @@ -73,6 +73,8 @@ config XEN_NETDEV_BACKEND
     2.4  config XEN_TPMDEV_FRONTEND
     2.5          bool "TPM-device frontend driver"
     2.6          default n
     2.7 +	select TCG_TPM
     2.8 +	select TCG_XEN
     2.9          help
    2.10            The TPM-device frontend driver.
    2.11  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 15:23:26 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     3.3 @@ -1,4 +1,4 @@
     3.4 -/******************************************************************************
     3.5 + /******************************************************************************
     3.6   * drivers/xen/tpmback/interface.c
     3.7   *
     3.8   * Vritual TPM interface management.
     3.9 @@ -21,180 +21,175 @@
    3.10  
    3.11  static kmem_cache_t *tpmif_cachep;
    3.12  int num_frontends = 0;
    3.13 +
    3.14  LIST_HEAD(tpmif_list);
    3.15  
    3.16 -
    3.17 -tpmif_t *alloc_tpmif(domid_t domid, long int instance)
    3.18 -{
    3.19 -    struct page *page;
    3.20 -    tpmif_t *tpmif;
    3.21 -
    3.22 -    tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    3.23 -    if (!tpmif)
    3.24 -        return ERR_PTR(-ENOMEM);
    3.25 -
    3.26 -    memset(tpmif, 0, sizeof(*tpmif));
    3.27 -    tpmif->domid        = domid;
    3.28 -    tpmif->status       = DISCONNECTED;
    3.29 -    tpmif->tpm_instance = instance;
    3.30 -    atomic_set(&tpmif->refcnt, 1);
    3.31 -
    3.32 -    page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    3.33 -    BUG_ON(page == NULL);
    3.34 -    tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    3.35 -
    3.36 -    list_add(&tpmif->tpmif_list, &tpmif_list);
    3.37 -    num_frontends++;
    3.38 -
    3.39 -    return tpmif;
    3.40 -}
    3.41 -
    3.42 -
    3.43 -void free_tpmif(tpmif_t *tpmif)
    3.44 -{
    3.45 -    num_frontends--;
    3.46 -    list_del(&tpmif->tpmif_list);
    3.47 -    kmem_cache_free(tpmif_cachep, tpmif);
    3.48 -}
    3.49 -
    3.50 -
    3.51 -tpmif_t *tpmif_find(domid_t domid, long int instance)
    3.52 +tpmif_t *
    3.53 +alloc_tpmif(domid_t domid, long int instance)
    3.54  {
    3.55 -    tpmif_t *tpmif;
    3.56 -
    3.57 -    list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    3.58 -        if (tpmif->tpm_instance == instance) {
    3.59 -            if (tpmif->domid == domid) {
    3.60 -                tpmif_get(tpmif);
    3.61 -                return tpmif;
    3.62 -	    } else {
    3.63 -	        return NULL;
    3.64 -	    }
    3.65 -        }
    3.66 -    }
    3.67 -
    3.68 -    return alloc_tpmif(domid, instance);
    3.69 -}
    3.70 -
    3.71 +	struct page *page;
    3.72 +	tpmif_t *tpmif;
    3.73  
    3.74 -static int map_frontend_page(tpmif_t *tpmif, unsigned long localaddr,
    3.75 -			     unsigned long shared_page)
    3.76 -{
    3.77 -    struct gnttab_map_grant_ref op = {
    3.78 -        .host_addr = localaddr,
    3.79 -        .flags     = GNTMAP_host_map,
    3.80 -        .ref       = shared_page,
    3.81 -        .dom       = tpmif->domid,
    3.82 -    };
    3.83 +	tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    3.84 +	if (!tpmif)
    3.85 +		return ERR_PTR(-ENOMEM);
    3.86  
    3.87 -    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
    3.88 +	memset(tpmif, 0, sizeof (*tpmif));
    3.89 +	tpmif->domid = domid;
    3.90 +	tpmif->status = DISCONNECTED;
    3.91 +	tpmif->tpm_instance = instance;
    3.92 +	atomic_set(&tpmif->refcnt, 1);
    3.93  
    3.94 -    if (op.handle < 0) {
    3.95 -	DPRINTK(" Grant table operation failure !\n");
    3.96 -	return op.handle;
    3.97 -    }
    3.98 +	page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    3.99 +	BUG_ON(page == NULL);
   3.100 +	tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
   3.101  
   3.102 -    tpmif->shmem_ref    = shared_page;
   3.103 -    tpmif->shmem_handle = op.handle;
   3.104 -    tpmif->shmem_vaddr  = localaddr;
   3.105 -    return 0;
   3.106 +	list_add(&tpmif->tpmif_list, &tpmif_list);
   3.107 +	num_frontends++;
   3.108 +
   3.109 +	return tpmif;
   3.110  }
   3.111  
   3.112 -
   3.113 -static void unmap_frontend_page(tpmif_t *tpmif)
   3.114 +void
   3.115 +free_tpmif(tpmif_t * tpmif)
   3.116  {
   3.117 -    struct gnttab_unmap_grant_ref op;
   3.118 -
   3.119 -    op.host_addr = tpmif->shmem_vaddr;
   3.120 -    op.handle = tpmif->shmem_handle;
   3.121 -    op.dev_bus_addr = 0;
   3.122 -
   3.123 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   3.124 +	num_frontends--;
   3.125 +	list_del(&tpmif->tpmif_list);
   3.126 +	kmem_cache_free(tpmif_cachep, tpmif);
   3.127  }
   3.128  
   3.129 -
   3.130 -int tpmif_map(tpmif_t *tpmif,
   3.131 -              unsigned long shared_page, unsigned int evtchn)
   3.132 +tpmif_t *
   3.133 +tpmif_find(domid_t domid, long int instance)
   3.134  {
   3.135 -    struct vm_struct *vma;
   3.136 -    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   3.137 -    int err;
   3.138 -
   3.139 -    BUG_ON(tpmif->remote_evtchn);
   3.140 -
   3.141 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
   3.142 -	return -ENOMEM;
   3.143 -
   3.144 -    err = map_frontend_page(tpmif,
   3.145 -                            VMALLOC_VMADDR(vma->addr),
   3.146 -                            shared_page);
   3.147 -    if (err) {
   3.148 -        vfree(vma->addr);
   3.149 -	return err;
   3.150 -    }
   3.151 +	tpmif_t *tpmif;
   3.152  
   3.153 -    op.u.bind_interdomain.dom1 = DOMID_SELF;
   3.154 -    op.u.bind_interdomain.dom2 = tpmif->domid;
   3.155 -    op.u.bind_interdomain.port1 = 0;
   3.156 -    op.u.bind_interdomain.port2 = evtchn;
   3.157 -    err = HYPERVISOR_event_channel_op(&op);
   3.158 -    if (err) {
   3.159 -	unmap_frontend_page(tpmif);
   3.160 -	vfree(vma->addr);
   3.161 -	return err;
   3.162 -    }
   3.163 +	list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
   3.164 +		if (tpmif->tpm_instance == instance) {
   3.165 +			if (tpmif->domid == domid) {
   3.166 +				tpmif_get(tpmif);
   3.167 +				return tpmif;
   3.168 +			} else {
   3.169 +				return NULL;
   3.170 +			}
   3.171 +		}
   3.172 +	}
   3.173  
   3.174 -    tpmif->evtchn = op.u.bind_interdomain.port1;
   3.175 -    tpmif->remote_evtchn = evtchn;
   3.176 -
   3.177 -    tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   3.178 -
   3.179 -    bind_evtchn_to_irqhandler(tpmif->evtchn,
   3.180 -                              tpmif_be_int,
   3.181 -                              0,
   3.182 -                              "tpmif-backend",
   3.183 -			      tpmif);
   3.184 -    tpmif->status        = CONNECTED;
   3.185 -    tpmif->shmem_ref     = shared_page;
   3.186 -    tpmif->active        = 1;
   3.187 -
   3.188 -    return 0;
   3.189 +	return alloc_tpmif(domid, instance);
   3.190  }
   3.191  
   3.192 -
   3.193 -static void __tpmif_disconnect_complete(void *arg)
   3.194 +static int
   3.195 +map_frontend_page(tpmif_t * tpmif, unsigned long localaddr,
   3.196 +		  unsigned long shared_page)
   3.197  {
   3.198 -    evtchn_op_t op = { .cmd = EVTCHNOP_close };
   3.199 -    tpmif_t *tpmif = (tpmif_t *) arg;
   3.200 +	struct gnttab_map_grant_ref op = {
   3.201 +		.host_addr = localaddr,
   3.202 +		.flags = GNTMAP_host_map,
   3.203 +		.ref = shared_page,
   3.204 +		.dom = tpmif->domid,
   3.205 +	};
   3.206  
   3.207 -    op.u.close.port = tpmif->evtchn;
   3.208 -    op.u.close.dom  = DOMID_SELF;
   3.209 -    HYPERVISOR_event_channel_op(&op);
   3.210 -    op.u.close.port = tpmif->remote_evtchn;
   3.211 -    op.u.close.dom  = tpmif->domid;
   3.212 -    HYPERVISOR_event_channel_op(&op);
   3.213 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   3.214  
   3.215 -    if (tpmif->evtchn)
   3.216 -         unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   3.217 +	if (op.handle < 0) {
   3.218 +		DPRINTK(" Grant table operation failure !\n");
   3.219 +		return op.handle;
   3.220 +	}
   3.221  
   3.222 -    if (tpmif->tx) {
   3.223 -        unmap_frontend_page(tpmif);
   3.224 -        vfree(tpmif->tx);
   3.225 -    }
   3.226 -
   3.227 -    free_tpmif(tpmif);
   3.228 +	tpmif->shmem_ref = shared_page;
   3.229 +	tpmif->shmem_handle = op.handle;
   3.230 +	tpmif->shmem_vaddr = localaddr;
   3.231 +	return 0;
   3.232  }
   3.233  
   3.234 +static void
   3.235 +unmap_frontend_page(tpmif_t * tpmif)
   3.236 +{
   3.237 +	struct gnttab_unmap_grant_ref op;
   3.238  
   3.239 -void tpmif_disconnect_complete(tpmif_t * tpmif)
   3.240 -{
   3.241 -    INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   3.242 -    schedule_work(&tpmif->work);
   3.243 +	op.host_addr = tpmif->shmem_vaddr;
   3.244 +	op.handle = tpmif->shmem_handle;
   3.245 +	op.dev_bus_addr = 0;
   3.246 +
   3.247 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   3.248  }
   3.249  
   3.250 -
   3.251 -void __init tpmif_interface_init(void)
   3.252 +int
   3.253 +tpmif_map(tpmif_t * tpmif, unsigned long shared_page, unsigned int evtchn)
   3.254  {
   3.255 -    tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof(tpmif_t),
   3.256 -                                     0, 0, NULL, NULL);
   3.257 +	struct vm_struct *vma;
   3.258 +	evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
   3.259 +	int err;
   3.260 +
   3.261 +	BUG_ON(tpmif->remote_evtchn);
   3.262 +
   3.263 +	if ((vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL)
   3.264 +		return -ENOMEM;
   3.265 +
   3.266 +	err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
   3.267 +	if (err) {
   3.268 +		vfree(vma->addr);
   3.269 +		return err;
   3.270 +	}
   3.271 +
   3.272 +	op.u.bind_interdomain.dom1 = DOMID_SELF;
   3.273 +	op.u.bind_interdomain.dom2 = tpmif->domid;
   3.274 +	op.u.bind_interdomain.port1 = 0;
   3.275 +	op.u.bind_interdomain.port2 = evtchn;
   3.276 +	err = HYPERVISOR_event_channel_op(&op);
   3.277 +	if (err) {
   3.278 +		unmap_frontend_page(tpmif);
   3.279 +		vfree(vma->addr);
   3.280 +		return err;
   3.281 +	}
   3.282 +
   3.283 +	tpmif->evtchn = op.u.bind_interdomain.port1;
   3.284 +	tpmif->remote_evtchn = evtchn;
   3.285 +
   3.286 +	tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   3.287 +
   3.288 +	bind_evtchn_to_irqhandler(tpmif->evtchn,
   3.289 +				  tpmif_be_int, 0, "tpmif-backend", tpmif);
   3.290 +	tpmif->status = CONNECTED;
   3.291 +	tpmif->shmem_ref = shared_page;
   3.292 +	tpmif->active = 1;
   3.293 +
   3.294 +	return 0;
   3.295  }
   3.296 +
   3.297 +static void
   3.298 +__tpmif_disconnect_complete(void *arg)
   3.299 +{
   3.300 +	evtchn_op_t op = {.cmd = EVTCHNOP_close };
   3.301 +	tpmif_t *tpmif = (tpmif_t *) arg;
   3.302 +
   3.303 +	op.u.close.port = tpmif->evtchn;
   3.304 +	op.u.close.dom = DOMID_SELF;
   3.305 +	HYPERVISOR_event_channel_op(&op);
   3.306 +	op.u.close.port = tpmif->remote_evtchn;
   3.307 +	op.u.close.dom = tpmif->domid;
   3.308 +	HYPERVISOR_event_channel_op(&op);
   3.309 +
   3.310 +	if (tpmif->evtchn)
   3.311 +		unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   3.312 +
   3.313 +	if (tpmif->tx) {
   3.314 +		unmap_frontend_page(tpmif);
   3.315 +		vfree(tpmif->tx);
   3.316 +	}
   3.317 +
   3.318 +	free_tpmif(tpmif);
   3.319 +}
   3.320 +
   3.321 +void
   3.322 +tpmif_disconnect_complete(tpmif_t * tpmif)
   3.323 +{
   3.324 +	INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   3.325 +	schedule_work(&tpmif->work);
   3.326 +}
   3.327 +
   3.328 +void __init
   3.329 +tpmif_interface_init(void)
   3.330 +{
   3.331 +	tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
   3.332 +					 0, 0, NULL, NULL);
   3.333 +}
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 15:23:26 2005 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 15:25:58 2005 +0100
     4.3 @@ -257,18 +257,24 @@ static int setup_tpmring(struct xenbus_d
     4.4  
     4.5  	tpm_allocate_buffers(tp);
     4.6  
     4.7 -	info->ring_ref = gnttab_claim_grant_reference(&gref_head);
     4.8 -	ASSERT(info->ring_ref != -ENOSPC);
     4.9 -	gnttab_grant_foreign_access_ref(info->ring_ref,
    4.10 -					backend_id,
    4.11 -					(virt_to_machine(tp->tx) >> PAGE_SHIFT),
    4.12 -					0);
    4.13 +	err = gnttab_grant_foreign_access(backend_id,
    4.14 +					  (virt_to_machine(tp->tx) >> PAGE_SHIFT),
    4.15 +					  0);
    4.16 +
    4.17 +	if (err == -ENOSPC) {
    4.18 +		free_page((unsigned long)sring);
    4.19 +		tp->tx = NULL;
    4.20 +		xenbus_dev_error(dev, err, "allocating grant reference");
    4.21 +		return err;
    4.22 +	}
    4.23 +	info->ring_ref = err;
    4.24  
    4.25  	op.u.alloc_unbound.dom = backend_id;
    4.26  	err = HYPERVISOR_event_channel_op(&op);
    4.27  	if (err) {
    4.28 +		gnttab_end_foreign_access(info->ring_ref, 0);
    4.29  		free_page((unsigned long)sring);
    4.30 -		tp->tx = 0;
    4.31 +		tp->tx = NULL;
    4.32  		xenbus_dev_error(dev, err, "allocating event channel");
    4.33  		return err;
    4.34  	}
    4.35 @@ -282,6 +288,7 @@ static void destroy_tpmring(struct tpmfr
    4.36  	tpmif_set_connected_state(tp,0);
    4.37  
    4.38  	if ( tp->tx != NULL ) {
    4.39 +		gnttab_end_foreign_access(info->ring_ref, 0);
    4.40  		free_page((unsigned long)tp->tx);
    4.41  		tp->tx = NULL;
    4.42  	}
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 15:23:26 2005 +0100
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 15:25:58 2005 +0100
     5.3 @@ -2,7 +2,8 @@
     5.4  #define TPM_FRONT_H
     5.5  
     5.6  
     5.7 -struct tpm_private {
     5.8 +struct tpm_private
     5.9 +{
    5.10  	tpmif_tx_interface_t *tx;
    5.11  	unsigned int evtchn;
    5.12  	int connected;
    5.13 @@ -29,7 +30,8 @@ struct tpmfront_info
    5.14  };
    5.15  
    5.16  
    5.17 -struct tx_buffer {
    5.18 +struct tx_buffer
    5.19 +{
    5.20  	unsigned int size;	// available space in data
    5.21  	unsigned int len;	// used space in data
    5.22  	unsigned char *data;    // pointer to a page
     6.1 --- a/tools/examples/xmexample.vmx	Wed Sep 21 15:23:26 2005 +0100
     6.2 +++ b/tools/examples/xmexample.vmx	Wed Sep 21 15:25:58 2005 +0100
     6.3 @@ -26,6 +26,10 @@ memory = 128
     6.4  # A name for your domain. All domains must have different names.
     6.5  name = "ExampleVMXDomain"
     6.6  
     6.7 +#-----------------------------------------------------------------------------
     6.8 +# the number of cpus guest platform has, default=1
     6.9 +vcpus=1
    6.10 +
    6.11  # Which CPU to start domain on? 
    6.12  #cpu = -1   # leave to Xen to pick
    6.13  
     7.1 --- a/tools/ioemu/vl.c	Wed Sep 21 15:23:26 2005 +0100
     7.2 +++ b/tools/ioemu/vl.c	Wed Sep 21 15:25:58 2005 +0100
     7.3 @@ -126,6 +126,7 @@ QEMUTimer *polling_timer;
     7.4  int vm_running;
     7.5  int audio_enabled = 0;
     7.6  int nic_pcnet = 1;
     7.7 +int vcpus = 1;
     7.8  int sb16_enabled = 1;
     7.9  int adlib_enabled = 1;
    7.10  int gus_enabled = 1;
    7.11 @@ -2105,6 +2106,7 @@ void help(void)
    7.12  	   "-snapshot       write to temporary files instead of disk image files\n"
    7.13             "-m megs         set virtual RAM size to megs MB [default=%d]\n"
    7.14             "-nographic      disable graphical output and redirect serial I/Os to console\n"
    7.15 +           "-vcpus          set CPU number of guest platform\n"
    7.16  #ifdef CONFIG_VNC
    7.17  	   "-vnc port             use vnc instead of sdl\n"
    7.18  	   "-vncport port         use a different port\n"
    7.19 @@ -2235,6 +2237,7 @@ enum {
    7.20      QEMU_OPTION_hdachs,
    7.21      QEMU_OPTION_L,
    7.22      QEMU_OPTION_no_code_copy,
    7.23 +    QEMU_OPTION_vcpus,
    7.24      QEMU_OPTION_pci,
    7.25      QEMU_OPTION_nic_pcnet,
    7.26      QEMU_OPTION_isa,
    7.27 @@ -2307,6 +2310,7 @@ const QEMUOption qemu_options[] = {
    7.28      { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
    7.29      { "L", HAS_ARG, QEMU_OPTION_L },
    7.30      { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
    7.31 +    { "vcpus", 1, QEMU_OPTION_vcpus },
    7.32  #ifdef TARGET_PPC
    7.33      { "prep", 0, QEMU_OPTION_prep },
    7.34      { "g", 1, QEMU_OPTION_g },
    7.35 @@ -2646,6 +2650,9 @@ int main(int argc, char **argv)
    7.36              case QEMU_OPTION_S:
    7.37                  start_emulation = 0;
    7.38                  break;
    7.39 +            case QEMU_OPTION_vcpus:
    7.40 +                vcpus = atoi(optarg);
    7.41 +                fprintf(logfile, "qemu: the number of cpus is %d\n", vcpus);
    7.42              case QEMU_OPTION_pci:
    7.43                  pci_enabled = 1;
    7.44                  break;
     8.1 --- a/tools/libxc/xc_vmx_build.c	Wed Sep 21 15:23:26 2005 +0100
     8.2 +++ b/tools/libxc/xc_vmx_build.c	Wed Sep 21 15:25:58 2005 +0100
     8.3 @@ -626,6 +626,10 @@ static int setup_guest(int xc_handle,
     8.4      /* Mask all upcalls... */
     8.5      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
     8.6          shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
     8.7 +
     8.8 +    shared_info->n_vcpu = vcpus;
     8.9 +    printf(" VCPUS:         %d\n", shared_info->n_vcpu);
    8.10 +
    8.11      munmap(shared_info, PAGE_SIZE);
    8.12  
    8.13      /* Populate the event channel port in the shared page */
     9.1 --- a/tools/python/xen/util/process.py	Wed Sep 21 15:23:26 2005 +0100
     9.2 +++ b/tools/python/xen/util/process.py	Wed Sep 21 15:25:58 2005 +0100
     9.3 @@ -24,6 +24,8 @@ def runscript(cmd):
     9.4          r = p.poll()
     9.5          for (fd, event) in r:
     9.6              if event == select.POLLHUP:
     9.7 +                cout.close()
     9.8 +                cerr.close()
     9.9                  return stdout
    9.10              if fd == cout.fileno():
    9.11                  stdout = stdout + cout.readline()
    10.1 --- a/tools/python/xen/xend/image.py	Wed Sep 21 15:23:26 2005 +0100
    10.2 +++ b/tools/python/xen/xend/image.py	Wed Sep 21 15:25:58 2005 +0100
    10.3 @@ -324,7 +324,7 @@ class VmxImageHandler(ImageHandler):
    10.4      # xm config file
    10.5      def parseDeviceModelArgs(self, imageConfig, deviceConfig):
    10.6          dmargs = [ 'cdrom', 'boot', 'fda', 'fdb',
    10.7 -                   'localtime', 'serial', 'stdvga', 'isa' ] 
    10.8 +                   'localtime', 'serial', 'stdvga', 'isa', 'vcpus' ] 
    10.9          ret = []
   10.10          for a in dmargs:
   10.11              v = sxp.child_value(imageConfig, a)
    11.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Sep 21 15:23:26 2005 +0100
    11.2 +++ b/tools/python/xen/xend/server/blkif.py	Wed Sep 21 15:25:58 2005 +0100
    11.3 @@ -42,7 +42,7 @@ class BlkifController(DevController):
    11.4          
    11.5          typedev = sxp.child_value(config, 'dev')
    11.6          if re.match('^ioemu:', typedev):
    11.7 -            return
    11.8 +            return (0,{},{})
    11.9  
   11.10          devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev'))
   11.11  
    12.1 --- a/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 15:23:26 2005 +0100
    12.2 +++ b/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 15:25:58 2005 +0100
    12.3 @@ -39,7 +39,7 @@ class TPMifController(DevController):
    12.4          """@see DevController.getDeviceDetails"""
    12.5          
    12.6          devid = int(sxp.child_value(config, 'instance', '0'))
    12.7 -        log.error("The domain has a TPM with instance %d." % devid)
    12.8 +        log.debug("The domain has a TPM with instance %d." % devid)
    12.9  
   12.10          back  = { 'instance' : "%i" % devid }
   12.11          front = { 'handle' : "%i" % devid }
    13.1 --- a/tools/python/xen/xm/create.py	Wed Sep 21 15:23:26 2005 +0100
    13.2 +++ b/tools/python/xen/xm/create.py	Wed Sep 21 15:25:58 2005 +0100
    13.3 @@ -496,7 +496,7 @@ def configure_vfr(opts, config, vals):
    13.4  def configure_vmx(opts, config_image, vals):
    13.5      """Create the config for VMX devices.
    13.6      """
    13.7 -    args = [ 'memmap', 'device_model', 'cdrom',
    13.8 +    args = [ 'memmap', 'device_model', 'vcpus', 'cdrom',
    13.9               'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', 
   13.10               'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display']
   13.11      for a in args:
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/vtpm/tpm_emulator-0.2b-x86_64.patch	Wed Sep 21 15:25:58 2005 +0100
    14.3 @@ -0,0 +1,499 @@
    14.4 +diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
    14.5 +--- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c	2005-08-15 00:58:57.000000000 -0700
    14.6 ++++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-19 14:10:29.000000000 -0700
    14.7 +@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
    14.8 + {
    14.9 +   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
   14.10 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
   14.11 +-    "GMP: cannot allocate memory (size=%u)\n", size);
   14.12 ++    "GMP: cannot allocate memory (size=%Zu)\n", size);
   14.13 +   return ret;
   14.14 + }
   14.15 + 
   14.16 +@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
   14.17 + {
   14.18 +   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   14.19 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
   14.20 +-    "(old_size=%u new_size=%u)\n", old_size, new_size);
   14.21 ++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   14.22 +   memcpy(ret, oldptr, old_size);
   14.23 +   kfree(oldptr);
   14.24 +   return ret;
   14.25 +diff -uprN tpm_emulator-0.2/linux_module.c tpm_emulator-0.2-x86_64/linux_module.c
   14.26 +--- tpm_emulator-0.2/linux_module.c	2005-08-15 00:58:57.000000000 -0700
   14.27 ++++ tpm_emulator-0.2-x86_64/linux_module.c	2005-09-19 14:10:29.000000000 -0700
   14.28 +@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
   14.29 + 
   14.30 + static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
   14.31 + {
   14.32 +-  debug("%s(%d)", __FUNCTION__, count);
   14.33 ++  debug("%s(%Zu)", __FUNCTION__, count);
   14.34 +   down(&tpm_mutex);
   14.35 +   if (tpm_response.data != NULL) {
   14.36 +     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
   14.37 +@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
   14.38 + 
   14.39 + static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
   14.40 + {
   14.41 +-  debug("%s(%d)", __FUNCTION__, count);
   14.42 ++  debug("%s(%Zu)", __FUNCTION__, count);
   14.43 +   down(&tpm_mutex);
   14.44 +   *ppos = 0;
   14.45 +   if (tpm_response.data != NULL) kfree(tpm_response.data);
   14.46 +diff -uprN tpm_emulator-0.2/linux_module.h tpm_emulator-0.2-x86_64/linux_module.h
   14.47 +--- tpm_emulator-0.2/linux_module.h	2005-08-15 00:58:57.000000000 -0700
   14.48 ++++ tpm_emulator-0.2-x86_64/linux_module.h	2005-09-19 14:10:29.000000000 -0700
   14.49 +@@ -28,8 +28,10 @@
   14.50 + 
   14.51 + /* module settings */
   14.52 + 
   14.53 ++#ifndef STR
   14.54 + #define STR(s) __STR__(s)
   14.55 + #define __STR__(s) #s
   14.56 ++#endif
   14.57 + #include "tpm_version.h"
   14.58 + 
   14.59 + #define TPM_DEVICE_MINOR	224
   14.60 +diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
   14.61 +--- tpm_emulator-0.2/Makefile	2005-08-15 00:58:57.000000000 -0700
   14.62 ++++ tpm_emulator-0.2-x86_64/Makefile	2005-09-19 14:10:29.000000000 -0700
   14.63 +@@ -7,6 +7,7 @@
   14.64 + KERNEL_RELEASE := $(shell uname -r)
   14.65 + KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   14.66 + MOD_SUBDIR     := misc
   14.67 ++COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   14.68 + 
   14.69 + # module settings
   14.70 + MODULE_NAME    := tpm_emulator
   14.71 +@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
   14.72 + # enable/disable DEBUG messages
   14.73 + EXTRA_CFLAGS   += -DDEBUG -g  
   14.74 + 
   14.75 ++ifeq ($(COMPILE_ARCH),x86_64)
   14.76 ++LIBDIR = lib64
   14.77 ++else
   14.78 ++LIBDIR = lib
   14.79 ++endif
   14.80 ++
   14.81 + # GNU MP configuration
   14.82 +-GMP_LIB        := /usr/lib/libgmp.a
   14.83 ++GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
   14.84 + GMP_HEADER     := /usr/include/gmp.h
   14.85 + 
   14.86 + # sources and objects
   14.87 +diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
   14.88 +--- tpm_emulator-0.2/README	2005-08-15 00:58:57.000000000 -0700
   14.89 ++++ tpm_emulator-0.2-x86_64/README	2005-09-19 14:21:43.000000000 -0700
   14.90 +@@ -45,6 +45,12 @@ Example:
   14.91 + GMP_LIB        := /usr/lib/libgmp.a
   14.92 + GMP_HEADER     := /usr/include/gmp.h
   14.93 + 
   14.94 ++GNU MP Library on 64 bit Systems
   14.95 ++--------------------------------------------------------------------------
   14.96 ++Some 64-bit kernels have problems with importing the user-space gmp 
   14.97 ++library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
   14.98 ++that the gmp library be recompiled for kernel space with -mcmodel=kernel.
   14.99 ++
  14.100 + Installation
  14.101 + --------------------------------------------------------------------------
  14.102 + The compilation and installation process uses the build environment for 
  14.103 +diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
  14.104 +--- tpm_emulator-0.2/tpm/tpm_credentials.c	2005-08-15 00:58:57.000000000 -0700
  14.105 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c	2005-09-19 14:10:29.000000000 -0700
  14.106 +@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
  14.107 + 
  14.108 + TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
  14.109 + {
  14.110 +-  UINT32 key_length;
  14.111 ++  size_t key_length;
  14.112 +   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
  14.113 +   /* setup TPM_PUBKEY structure */
  14.114 +-  key_length = tpmData.permanent.data.endorsementKey.size;
  14.115 +-  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
  14.116 ++  pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
  14.117 +   pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
  14.118 +   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
  14.119 +   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
  14.120 +-    pubEndorsementKey->pubKey.key,
  14.121 +-    &pubEndorsementKey->pubKey.keyLength);
  14.122 ++		     pubEndorsementKey->pubKey.key,
  14.123 ++		     &key_length);
  14.124 ++  pubEndorsementKey->pubKey.keyLength = key_length;
  14.125 +   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
  14.126 +   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  14.127 +   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
  14.128 +@@ -169,6 +169,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  14.129 + {
  14.130 +   TPM_RESULT res;
  14.131 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  14.132 ++  size_t key_length;
  14.133 +   info("TPM_OwnerReadInternalPub()");
  14.134 +   /* verify authorization */
  14.135 +   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
  14.136 +@@ -180,7 +181,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  14.137 +     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
  14.138 +     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
  14.139 +     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
  14.140 +-      &publicPortion->pubKey.keyLength);
  14.141 ++      &key_length);
  14.142 ++    publicPortion->pubKey.keyLength = key_length;
  14.143 +     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
  14.144 +     publicPortion->algorithmParms.encScheme = srk->encScheme;
  14.145 +     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
  14.146 +diff -uprN tpm_emulator-0.2/tpm/tpm_crypto.c tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
  14.147 +--- tpm_emulator-0.2/tpm/tpm_crypto.c	2005-08-15 00:58:57.000000000 -0700
  14.148 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-19 14:10:29.000000000 -0700
  14.149 +@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  14.150 +   TPM_KEY_DATA *cert, *key;
  14.151 +   sha1_ctx_t sha1_ctx;
  14.152 +   BYTE *buf, *p;
  14.153 +-  UINT32 length;
  14.154 ++  UINT32 length32;
  14.155 ++  size_t length;
  14.156 +   info("TPM_CertifyKey()");
  14.157 +   /* get keys */
  14.158 +   cert = tpm_get_key(certHandle);
  14.159 +@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  14.160 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  14.161 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  14.162 +   p = buf = tpm_malloc(length);
  14.163 ++  length32=(UINT32) length;
  14.164 +   if (buf == NULL
  14.165 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  14.166 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  14.167 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  14.168 +     return TPM_FAIL;
  14.169 +   }
  14.170 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  14.171 +   sha1_init(&sha1_ctx);
  14.172 +-  sha1_update(&sha1_ctx, buf, length);
  14.173 ++  sha1_update(&sha1_ctx, buf, (size_t) length);
  14.174 +   sha1_final(&sha1_ctx, buf);
  14.175 +   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
  14.176 +   tpm_free(buf);
  14.177 +@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  14.178 +   TPM_KEY_DATA *cert, *key;
  14.179 +   sha1_ctx_t sha1_ctx;
  14.180 +   BYTE *buf, *p;
  14.181 +-  UINT32 length;
  14.182 ++  size_t length;
  14.183 ++  UINT32 length32;
  14.184 +   info("TPM_CertifyKey2()");
  14.185 +   /* get keys */
  14.186 +   cert = tpm_get_key(certHandle);
  14.187 +@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  14.188 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  14.189 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  14.190 +   p = buf = tpm_malloc(length);
  14.191 ++  length32 = (UINT32) length;
  14.192 +   if (buf == NULL
  14.193 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  14.194 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  14.195 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  14.196 +     return TPM_FAIL;
  14.197 +   }
  14.198 +diff -uprN tpm_emulator-0.2/tpm/tpm_data.c tpm_emulator-0.2-x86_64/tpm/tpm_data.c
  14.199 +--- tpm_emulator-0.2/tpm/tpm_data.c	2005-08-15 00:58:57.000000000 -0700
  14.200 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-19 14:10:29.000000000 -0700
  14.201 +@@ -179,7 +179,7 @@ static int read_from_file(uint8_t **data
  14.202 + int tpm_store_permanent_data(void)
  14.203 + {
  14.204 +   uint8_t *buf, *ptr;
  14.205 +-  size_t buf_length, len;
  14.206 ++  UINT32 buf_length, len;
  14.207 + 
  14.208 +   /* marshal data */
  14.209 +   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
  14.210 +@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
  14.211 + int tpm_restore_permanent_data(void)
  14.212 + {
  14.213 +   uint8_t *buf, *ptr;
  14.214 +-  size_t buf_length, len;
  14.215 ++  size_t buf_length;
  14.216 ++  UINT32 len;
  14.217 +   TPM_VERSION ver;
  14.218 + 
  14.219 +   /* read data */
  14.220 +   if (read_from_file(&buf, &buf_length)) return -1;
  14.221 +   ptr = buf;
  14.222 +-  len = buf_length;
  14.223 ++  len = (uint32_t) buf_length;
  14.224 +   /* unmarshal data */
  14.225 +   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
  14.226 +       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
  14.227 +diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
  14.228 +--- tpm_emulator-0.2/tpm/tpm_marshalling.c	2005-08-15 00:58:57.000000000 -0700
  14.229 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c	2005-09-19 14:10:29.000000000 -0700
  14.230 +@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
  14.231 + 
  14.232 + int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
  14.233 + {
  14.234 +-  UINT32 m_len, e_len, q_len;
  14.235 ++  size_t m_len, e_len, q_len;
  14.236 +   if (*length < sizeof_RSA((*v))) return -1;
  14.237 +   if (v->size > 0) {
  14.238 +     rsa_export_modulus(v, &(*ptr)[6], &m_len);
  14.239 +diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
  14.240 +--- tpm_emulator-0.2/tpm/tpm_owner.c	2005-08-15 00:58:57.000000000 -0700
  14.241 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c	2005-09-19 14:10:29.000000000 -0700
  14.242 +@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  14.243 +   TPM_RESULT res;
  14.244 +   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
  14.245 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  14.246 +-  UINT32 buf_size = ek->size >> 3;
  14.247 ++  size_t buf_size = ek->size >> 3, key_length; 
  14.248 +   BYTE buf[buf_size];
  14.249 + 
  14.250 +   info("TPM_TakeOwnership()");
  14.251 +@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  14.252 +     return TPM_FAIL;
  14.253 +   }
  14.254 +   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
  14.255 +-    &srkPub->pubKey.keyLength);
  14.256 ++		     &key_length);
  14.257 ++  srkPub->pubKey.keyLength = (UINT32) key_length;
  14.258 +   /* setup tpmProof and set state to owned */
  14.259 +   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
  14.260 +     sizeof(tpmData.permanent.data.tpmProof.nonce));
  14.261 +diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
  14.262 +--- tpm_emulator-0.2/tpm/tpm_storage.c	2005-08-15 00:58:57.000000000 -0700
  14.263 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c	2005-09-19 14:10:29.000000000 -0700
  14.264 +@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  14.265 +                         BYTE *enc, UINT32 *enc_size)
  14.266 + {
  14.267 +   UINT32 len;
  14.268 ++  size_t enc_size32 = *enc_size;
  14.269 +   BYTE *buf, *ptr;
  14.270 +   rsa_public_key_t pub_key;
  14.271 +   int scheme;
  14.272 +@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  14.273 +   if (buf == NULL
  14.274 +       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
  14.275 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
  14.276 +-                     enc, enc_size)) {
  14.277 ++                     enc, &enc_size32)) {
  14.278 +     tpm_free(buf);
  14.279 +     rsa_release_public_key(&pub_key);
  14.280 +     return -1;
  14.281 +@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  14.282 + int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
  14.283 +                         TPM_SEALED_DATA *seal, BYTE **buf) 
  14.284 + {
  14.285 +-  UINT32 len;
  14.286 ++  size_t len;
  14.287 ++  UINT32 len32;
  14.288 +   BYTE *ptr;
  14.289 +   int scheme;
  14.290 +   switch (key->encScheme) {
  14.291 +@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
  14.292 +   len = enc_size;
  14.293 +   *buf = ptr = tpm_malloc(len);
  14.294 +   if (*buf == NULL
  14.295 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  14.296 +-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
  14.297 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
  14.298 ++    tpm_free(*buf);
  14.299 ++    return -1;
  14.300 ++  }
  14.301 ++  len32 = len;
  14.302 ++  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
  14.303 +     tpm_free(*buf);
  14.304 +     return -1;
  14.305 +   }
  14.306 +@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
  14.307 + 
  14.308 + TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
  14.309 +                       BYTE *inData, TPM_AUTH *auth1, 
  14.310 +-                      UINT32 *outDataSize, BYTE **outData)
  14.311 ++                      UINT32 *outDataSize32, BYTE **outData)
  14.312 + {
  14.313 +   TPM_RESULT res;
  14.314 +   TPM_KEY_DATA *key;
  14.315 +   int scheme;
  14.316 ++  size_t outDataSize;
  14.317 +   info("TPM_UnBind()");
  14.318 +   /* get key */
  14.319 +   key = tpm_get_key(keyHandle);
  14.320 +@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  14.321 +   /* the size of the input data muss be greater than zero */
  14.322 +   if (inDataSize == 0) return TPM_BAD_PARAMETER;
  14.323 +   /* decrypt data */
  14.324 +-  *outDataSize = inDataSize;
  14.325 +-  *outData = tpm_malloc(*outDataSize);
  14.326 ++  outDataSize = inDataSize;
  14.327 ++  *outData = tpm_malloc(outDataSize);
  14.328 +   if (*outData == NULL) return TPM_FAIL;
  14.329 +   switch (key->encScheme) {
  14.330 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  14.331 +@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  14.332 +     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
  14.333 +   }
  14.334 +   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
  14.335 +-      *outData, outDataSize)) {
  14.336 ++		  *outData, &outDataSize) ) { 
  14.337 +     tpm_free(*outData);
  14.338 +     return TPM_DECRYPT_ERROR;
  14.339 +   }
  14.340 +   /* verify data if it is of type TPM_BOUND_DATA */
  14.341 +   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
  14.342 +       || key->keyUsage != TPM_KEY_LEGACY) {
  14.343 +-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  14.344 ++    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  14.345 +       tpm_free(*outData);
  14.346 +       return TPM_DECRYPT_ERROR;
  14.347 +     }
  14.348 +-    *outDataSize -= 5;
  14.349 +-    memmove(*outData, &(*outData)[5], *outDataSize);   
  14.350 +-  } 
  14.351 ++    outDataSize -= 5;
  14.352 ++    memmove(*outData, &(*outData)[5], outDataSize);   
  14.353 ++  }
  14.354 ++  *outDataSize32 = (UINT32) outDataSize; 
  14.355 +   return TPM_SUCCESS;
  14.356 + }
  14.357 + 
  14.358 +@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
  14.359 + }
  14.360 + 
  14.361 + int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
  14.362 +-                        BYTE *enc, UINT32 *enc_size)
  14.363 ++                        BYTE *enc, UINT32 *enc_size32)
  14.364 + {
  14.365 +   UINT32 len;
  14.366 +   BYTE *buf, *ptr;
  14.367 +   rsa_public_key_t pub_key;
  14.368 +   int scheme;
  14.369 ++  size_t enc_size;
  14.370 +   switch (key->encScheme) {
  14.371 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  14.372 +     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
  14.373 +@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  14.374 +   if (buf == NULL
  14.375 +       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
  14.376 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
  14.377 +-                     enc, enc_size)) {
  14.378 ++                     enc, &enc_size)) {
  14.379 +     tpm_free(buf);
  14.380 +     rsa_release_public_key(&pub_key);
  14.381 +     return -1;
  14.382 +   }
  14.383 ++  *enc_size32 = (UINT32) enc_size;
  14.384 +   tpm_free(buf);
  14.385 +   rsa_release_public_key(&pub_key);
  14.386 +   return 0;
  14.387 +@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  14.388 + int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
  14.389 +                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
  14.390 + {
  14.391 +-  UINT32 len;
  14.392 ++  UINT32 len32;
  14.393 ++  size_t len;
  14.394 +   BYTE *ptr;
  14.395 +   int scheme;
  14.396 +   switch (key->encScheme) {
  14.397 +@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
  14.398 +   len = enc_size;
  14.399 +   *buf = ptr = tpm_malloc(len);
  14.400 +   if (*buf == NULL
  14.401 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  14.402 +-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
  14.403 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
  14.404 ++    tpm_free(*buf);
  14.405 ++    return -1;
  14.406 ++  }
  14.407 ++  len32 = (UINT32) len;
  14.408 ++  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
  14.409 +     tpm_free(*buf);
  14.410 +     return -1;
  14.411 +   }
  14.412 ++
  14.413 +   return 0;
  14.414 + }
  14.415 + 
  14.416 +@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  14.417 +   TPM_SESSION_DATA *session;
  14.418 +   TPM_STORE_ASYMKEY store;
  14.419 +   rsa_private_key_t rsa;
  14.420 +-  UINT32 key_length;
  14.421 ++  size_t key_length;
  14.422 + 
  14.423 +   info("TPM_CreateWrapKey()");
  14.424 +   /* get parent key */
  14.425 +@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  14.426 +   }
  14.427 +   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
  14.428 +   /* generate key and store it */
  14.429 +-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
  14.430 +-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
  14.431 +-  wrappedKey->pubKey.keyLength = key_length >> 3;
  14.432 ++  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
  14.433 ++    return TPM_FAIL;
  14.434 ++  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
  14.435 +   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
  14.436 +-  store.privKey.keyLength = key_length >> 4;
  14.437 ++  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
  14.438 +   store.privKey.key = tpm_malloc(store.privKey.keyLength);
  14.439 +   wrappedKey->encDataSize = parent->key.size >> 3;
  14.440 +   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
  14.441 +@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  14.442 +     tpm_free(wrappedKey->encData);
  14.443 +     return TPM_FAIL;
  14.444 +   }
  14.445 +-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
  14.446 +-    &wrappedKey->pubKey.keyLength);
  14.447 +-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
  14.448 ++  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
  14.449 ++		     &key_length);
  14.450 ++  wrappedKey->pubKey.keyLength = (UINT32) key_length;
  14.451 ++  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
  14.452 ++  store.privKey.keyLength = (UINT32) key_length;
  14.453 +   rsa_release_private_key(&rsa);
  14.454 +   /* encrypt private key data */
  14.455 +   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
  14.456 +@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
  14.457 + 
  14.458 + int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
  14.459 + {
  14.460 ++  size_t key_length;
  14.461 +   parms->algorithmID = TPM_ALG_RSA;
  14.462 +   parms->encScheme = key->encScheme;
  14.463 +   parms->sigScheme = key->sigScheme;
  14.464 +@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
  14.465 +   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
  14.466 +   if (parms->parms.rsa.exponent == NULL) return -1;
  14.467 +   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
  14.468 +-    &parms->parms.rsa.exponentSize);
  14.469 ++                      &key_length);  
  14.470 ++  parms->parms.rsa.exponentSize = (UINT32) key_length;
  14.471 +   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
  14.472 +   return 0;
  14.473 + }
  14.474 +@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  14.475 +   TPM_RESULT res;
  14.476 +   TPM_KEY_DATA *key;
  14.477 +   TPM_DIGEST digest;
  14.478 ++  size_t key_length;
  14.479 +   info("TPM_GetPubKey()");
  14.480 +   /* get key */
  14.481 +   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
  14.482 +@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  14.483 +   pubKey->pubKey.keyLength = key->key.size >> 3;
  14.484 +   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
  14.485 +   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
  14.486 +-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
  14.487 +-    &pubKey->pubKey.keyLength);
  14.488 ++  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
  14.489 ++  pubKey->pubKey.keyLength = (UINT32) key_length;
  14.490 +   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
  14.491 +     tpm_free(pubKey->pubKey.key);
  14.492 +     return TPM_FAIL;  
  14.493 +diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
  14.494 +--- tpm_emulator-0.2/tpm_version.h	2005-08-15 00:58:57.000000000 -0700
  14.495 ++++ tpm_emulator-0.2-x86_64/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
  14.496 +@@ -1,6 +0,0 @@
  14.497 +-#ifndef _TPM_VERSION_H_
  14.498 +-#define _TPM_VERSION_H_
  14.499 +-#define VERSION_MAJOR 0
  14.500 +-#define VERSION_MINOR 2
  14.501 +-#define VERSION_BUILD 1123950310
  14.502 +-#endif /* _TPM_VERSION_H_ */
    15.1 --- a/xen/arch/x86/vmx.c	Wed Sep 21 15:23:26 2005 +0100
    15.2 +++ b/xen/arch/x86/vmx.c	Wed Sep 21 15:25:58 2005 +0100
    15.3 @@ -377,12 +377,13 @@ static void inline __update_guest_eip(un
    15.4  
    15.5  static int vmx_do_page_fault(unsigned long va, struct cpu_user_regs *regs) 
    15.6  {
    15.7 -    unsigned long eip;
    15.8      unsigned long gpa; /* FIXME: PAE */
    15.9      int result;
   15.10  
   15.11 -#if VMX_DEBUG
   15.12 +#if 0 /* keep for debugging */
   15.13      {
   15.14 +        unsigned long eip;
   15.15 +
   15.16          __vmread(GUEST_RIP, &eip);
   15.17          VMX_DBG_LOG(DBG_LEVEL_VMMU, 
   15.18                      "vmx_do_page_fault = 0x%lx, eip = %lx, error_code = %lx",
   15.19 @@ -429,9 +430,9 @@ static void vmx_do_no_device_fault(void)
   15.20          
   15.21      clts();
   15.22      setup_fpu(current);
   15.23 -    __vmread(CR0_READ_SHADOW, &cr0);
   15.24 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   15.25      if (!(cr0 & X86_CR0_TS)) {
   15.26 -        __vmread(GUEST_CR0, &cr0);
   15.27 +        __vmread_vcpu(GUEST_CR0, &cr0);
   15.28          cr0 &= ~X86_CR0_TS;
   15.29          __vmwrite(GUEST_CR0, cr0);
   15.30      }
   15.31 @@ -1129,9 +1130,7 @@ static int vmx_set_cr0(unsigned long val
   15.32                  __vmwrite(VM_ENTRY_CONTROLS, vm_entry_value);
   15.33              }
   15.34          }
   15.35 -        __vmread(GUEST_RIP, &eip);
   15.36 -        VMX_DBG_LOG(DBG_LEVEL_1,
   15.37 -                    "Disabling CR0.PE at %%eip 0x%lx\n", eip);
   15.38 +
   15.39          if (vmx_assist(d, VMX_ASSIST_INVOKE)) {
   15.40              set_bit(VMX_CPU_STATE_ASSIST_ENABLED, &d->arch.arch_vmx.cpu_state);
   15.41              __vmread(GUEST_RIP, &eip);
   15.42 @@ -1370,17 +1369,17 @@ static int vmx_cr_access(unsigned long e
   15.43          clts();
   15.44          setup_fpu(current);
   15.45  
   15.46 -        __vmread(GUEST_CR0, &value);
   15.47 +        __vmread_vcpu(GUEST_CR0, &value);
   15.48          value &= ~X86_CR0_TS; /* clear TS */
   15.49          __vmwrite(GUEST_CR0, value);
   15.50  
   15.51 -        __vmread(CR0_READ_SHADOW, &value);
   15.52 +        __vmread_vcpu(CR0_READ_SHADOW, &value);
   15.53          value &= ~X86_CR0_TS; /* clear TS */
   15.54          __vmwrite(CR0_READ_SHADOW, value);
   15.55          break;
   15.56      case TYPE_LMSW:
   15.57          TRACE_VMEXIT(1,TYPE_LMSW);
   15.58 -        __vmread(CR0_READ_SHADOW, &value);
   15.59 +        __vmread_vcpu(CR0_READ_SHADOW, &value);
   15.60          value = (value & ~0xF) |
   15.61              (((exit_qualification & LMSW_SOURCE_DATA) >> 16) & 0xF);
   15.62          return vmx_set_cr0(value);
   15.63 @@ -1456,16 +1455,12 @@ static inline void vmx_do_msr_write(stru
   15.64                  (unsigned long)regs->edx);
   15.65  }
   15.66  
   15.67 +volatile unsigned long do_hlt_count;
   15.68  /*
   15.69   * Need to use this exit to reschedule
   15.70   */
   15.71 -static inline void vmx_vmexit_do_hlt(void)
   15.72 +void vmx_vmexit_do_hlt(void)
   15.73  {
   15.74 -#if VMX_DEBUG
   15.75 -    unsigned long eip;
   15.76 -    __vmread(GUEST_RIP, &eip);
   15.77 -#endif
   15.78 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_vmexit_do_hlt:eip=%lx", eip);
   15.79      raise_softirq(SCHEDULE_SOFTIRQ);
   15.80  }
   15.81  
   15.82 @@ -1516,13 +1511,9 @@ static inline void vmx_vmexit_do_extint(
   15.83      }
   15.84  }
   15.85  
   15.86 +volatile unsigned long do_mwait_count;
   15.87  static inline void vmx_vmexit_do_mwait(void)
   15.88  {
   15.89 -#if VMX_DEBUG
   15.90 -    unsigned long eip;
   15.91 -    __vmread(GUEST_RIP, &eip);
   15.92 -#endif
   15.93 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_vmexit_do_mwait:eip=%lx", eip);
   15.94      raise_softirq(SCHEDULE_SOFTIRQ);
   15.95  }
   15.96  
   15.97 @@ -1631,9 +1622,13 @@ asmlinkage void vmx_vmexit_handler(struc
   15.98          return;
   15.99      }
  15.100  
  15.101 -    __vmread(GUEST_RIP, &eip);
  15.102 -    TRACE_3D(TRC_VMX_VMEXIT, v->domain->domain_id, eip, exit_reason);
  15.103 -    TRACE_VMEXIT(0,exit_reason);
  15.104 +#ifdef TRACE_BUFFER
  15.105 +    {
  15.106 +        __vmread(GUEST_RIP, &eip);
  15.107 +        TRACE_3D(TRC_VMX_VMEXIT, v->domain->domain_id, eip, exit_reason);
  15.108 +        TRACE_VMEXIT(0,exit_reason);
  15.109 +    }
  15.110 +#endif
  15.111  
  15.112      switch (exit_reason) {
  15.113      case EXIT_REASON_EXCEPTION_NMI:
    16.1 --- a/xen/arch/x86/vmx_io.c	Wed Sep 21 15:23:26 2005 +0100
    16.2 +++ b/xen/arch/x86/vmx_io.c	Wed Sep 21 15:25:58 2005 +0100
    16.3 @@ -891,7 +891,7 @@ asmlinkage void vmx_intr_assist(void)
    16.4      struct vcpu *v = current;
    16.5  
    16.6      highest_vector = find_highest_pending_irq(v, &intr_type);
    16.7 -    __vmread(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
    16.8 +    __vmread_vcpu(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
    16.9  
   16.10      if (highest_vector == -1) {
   16.11          disable_irq_window(cpu_exec_control);
   16.12 @@ -948,14 +948,6 @@ asmlinkage void vmx_intr_assist(void)
   16.13  void vmx_do_resume(struct vcpu *d) 
   16.14  {
   16.15      vmx_stts();
   16.16 -    if ( vmx_paging_enabled(d) )
   16.17 -        __vmwrite(GUEST_CR3, pagetable_get_paddr(d->arch.shadow_table));
   16.18 -    else
   16.19 -        // paging is not enabled in the guest
   16.20 -        __vmwrite(GUEST_CR3, pagetable_get_paddr(d->domain->arch.phys_table));
   16.21 -
   16.22 -    __vmwrite(HOST_CR3, pagetable_get_paddr(d->arch.monitor_table));
   16.23 -    __vmwrite(HOST_RSP, (unsigned long)get_stack_bottom());
   16.24  
   16.25      if (event_pending(d)) {
   16.26          vmx_check_events(d);
    17.1 --- a/xen/arch/x86/vmx_vmcs.c	Wed Sep 21 15:23:26 2005 +0100
    17.2 +++ b/xen/arch/x86/vmx_vmcs.c	Wed Sep 21 15:25:58 2005 +0100
    17.3 @@ -68,9 +68,6 @@ static inline int construct_vmcs_control
    17.4      error |= __vmwrite(PIN_BASED_VM_EXEC_CONTROL, 
    17.5                         MONITOR_PIN_BASED_EXEC_CONTROLS);
    17.6  
    17.7 -    error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
    17.8 -                       MONITOR_CPU_BASED_EXEC_CONTROLS);
    17.9 -
   17.10      error |= __vmwrite(VM_EXIT_CONTROLS, MONITOR_VM_EXIT_CONTROLS);
   17.11  
   17.12      error |= __vmwrite(VM_ENTRY_CONTROLS, MONITOR_VM_ENTRY_CONTROLS);
   17.13 @@ -117,12 +114,6 @@ struct host_execution_env {
   17.14      unsigned long fs_base; 
   17.15      unsigned long gs_base; 
   17.16  #endif 
   17.17 -
   17.18 -    /* control registers */
   17.19 -    unsigned long cr3;
   17.20 -    unsigned long cr0;
   17.21 -    unsigned long cr4;
   17.22 -    unsigned long dr7;
   17.23  };
   17.24  
   17.25  #define round_pgdown(_p) ((_p)&PAGE_MASK) /* coped from domain.c */
   17.26 @@ -217,9 +208,33 @@ void vmx_do_launch(struct vcpu *v)
   17.27  /* Update CR3, GDT, LDT, TR */
   17.28      unsigned int  error = 0;
   17.29      unsigned long pfn = 0;
   17.30 +    unsigned long cr0, cr4;
   17.31      struct pfn_info *page;
   17.32      struct cpu_user_regs *regs = guest_cpu_user_regs();
   17.33  
   17.34 +    __asm__ __volatile__ ("mov %%cr0,%0" : "=r" (cr0) : );
   17.35 +
   17.36 +    error |= __vmwrite(GUEST_CR0, cr0);
   17.37 +    cr0 &= ~X86_CR0_PG;
   17.38 +    error |= __vmwrite(CR0_READ_SHADOW, cr0);
   17.39 +    error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
   17.40 +                       MONITOR_CPU_BASED_EXEC_CONTROLS);
   17.41 +
   17.42 +    __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (cr4) : );
   17.43 +
   17.44 +#ifdef __x86_64__
   17.45 +    error |= __vmwrite(GUEST_CR4, cr4 & ~X86_CR4_PSE);
   17.46 +#else
   17.47 +    error |= __vmwrite(GUEST_CR4, cr4);
   17.48 +#endif
   17.49 +
   17.50 +#ifdef __x86_64__
   17.51 +    cr4 &= ~(X86_CR4_PGE | X86_CR4_VMXE | X86_CR4_PAE);
   17.52 +#else
   17.53 +    cr4 &= ~(X86_CR4_PGE | X86_CR4_VMXE);
   17.54 +#endif
   17.55 +    error |= __vmwrite(CR4_READ_SHADOW, cr4);
   17.56 +
   17.57      vmx_stts();
   17.58  
   17.59      page = (struct pfn_info *) alloc_domheap_page(NULL);
   17.60 @@ -254,7 +269,7 @@ construct_init_vmcs_guest(struct cpu_use
   17.61      int error = 0;
   17.62      union vmcs_arbytes arbytes;
   17.63      unsigned long dr7;
   17.64 -    unsigned long eflags, shadow_cr;
   17.65 +    unsigned long eflags;
   17.66  
   17.67      /* MSR */
   17.68      error |= __vmwrite(VM_EXIT_MSR_LOAD_ADDR, 0);
   17.69 @@ -326,27 +341,7 @@ construct_init_vmcs_guest(struct cpu_use
   17.70  
   17.71      arbytes.fields.seg_type = 0xb;          /* 32-bit TSS (busy) */
   17.72      error |= __vmwrite(GUEST_TR_AR_BYTES, arbytes.bytes);
   17.73 -
   17.74 -    error |= __vmwrite(GUEST_CR0, host_env->cr0); /* same CR0 */
   17.75 -
   17.76 -    /* Initally PG, PE are not set*/
   17.77 -    shadow_cr = host_env->cr0;
   17.78 -    shadow_cr &= ~X86_CR0_PG;
   17.79 -    error |= __vmwrite(CR0_READ_SHADOW, shadow_cr);
   17.80      /* CR3 is set in vmx_final_setup_guest */
   17.81 -#ifdef __x86_64__
   17.82 -    error |= __vmwrite(GUEST_CR4, host_env->cr4 & ~X86_CR4_PSE);
   17.83 -#else
   17.84 -    error |= __vmwrite(GUEST_CR4, host_env->cr4);
   17.85 -#endif
   17.86 -    shadow_cr = host_env->cr4;
   17.87 -
   17.88 -#ifdef __x86_64__
   17.89 -    shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE | X86_CR4_PAE);
   17.90 -#else
   17.91 -    shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE);
   17.92 -#endif
   17.93 -    error |= __vmwrite(CR4_READ_SHADOW, shadow_cr);
   17.94  
   17.95      error |= __vmwrite(GUEST_ES_BASE, host_env->ds_base);
   17.96      error |= __vmwrite(GUEST_CS_BASE, host_env->cs_base);
   17.97 @@ -403,12 +398,10 @@ static inline int construct_vmcs_host(st
   17.98      host_env->cs_base = 0;
   17.99  
  17.100      __asm__ __volatile__ ("mov %%cr0,%0" : "=r" (crn) : );
  17.101 -    host_env->cr0 = crn;
  17.102      error |= __vmwrite(HOST_CR0, crn); /* same CR0 */
  17.103  
  17.104      /* CR3 is set in vmx_final_setup_hostos */
  17.105      __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (crn) : ); 
  17.106 -    host_env->cr4 = crn;
  17.107      error |= __vmwrite(HOST_CR4, crn);
  17.108  
  17.109      error |= __vmwrite(HOST_RIP, (unsigned long) vmx_asm_vmexit_handler);
    18.1 --- a/xen/include/asm-x86/vmx.h	Wed Sep 21 15:23:26 2005 +0100
    18.2 +++ b/xen/include/asm-x86/vmx.h	Wed Sep 21 15:25:58 2005 +0100
    18.3 @@ -314,6 +314,57 @@ static always_inline int ___vmread (cons
    18.4      return 0;
    18.5  }
    18.6  
    18.7 +
    18.8 +static always_inline void __vmwrite_vcpu(unsigned long field, unsigned long value)
    18.9 +{
   18.10 +    struct vcpu *v = current;
   18.11 +
   18.12 +    switch(field) {
   18.13 +    case CR0_READ_SHADOW:
   18.14 +	v->arch.arch_vmx.cpu_shadow_cr0 = value;
   18.15 +	break;
   18.16 +    case GUEST_CR0:
   18.17 +	v->arch.arch_vmx.cpu_cr0 = value;
   18.18 +	break;
   18.19 +    case CPU_BASED_VM_EXEC_CONTROL:
   18.20 +	v->arch.arch_vmx.cpu_based_exec_control = value;
   18.21 +	break;
   18.22 +    default:
   18.23 +	printk("__vmwrite_cpu: invalid field %lx\n", field);
   18.24 +	break;
   18.25 +    }
   18.26 +}
   18.27 +
   18.28 +static always_inline void __vmread_vcpu(unsigned long field, unsigned long *value)
   18.29 +{
   18.30 +    struct vcpu *v = current;
   18.31 +
   18.32 +    switch(field) {
   18.33 +    case CR0_READ_SHADOW:
   18.34 +	*value = v->arch.arch_vmx.cpu_shadow_cr0;
   18.35 +	break;
   18.36 +    case GUEST_CR0:
   18.37 +	*value = v->arch.arch_vmx.cpu_cr0;
   18.38 +	break;
   18.39 +    case CPU_BASED_VM_EXEC_CONTROL:
   18.40 +	*value = v->arch.arch_vmx.cpu_based_exec_control;
   18.41 +	break;
   18.42 +    default:
   18.43 +	printk("__vmread_cpu: invalid field %lx\n", field);
   18.44 +	break;
   18.45 +    }
   18.46 +
   18.47 +   /* 
   18.48 +    * __vmwrite() can be used for non-current vcpu, and it's possible that
   18.49 +    * the vcpu field is not initialized at that case.
   18.50 +    * 
   18.51 +    */
   18.52 +    if (!*value) {
   18.53 +	__vmread(field, value);
   18.54 +	__vmwrite_vcpu(field, *value);
   18.55 +    }
   18.56 +}
   18.57 +
   18.58  static inline int __vmwrite (unsigned long field, unsigned long value)
   18.59  {
   18.60      unsigned long eflags;
   18.61 @@ -326,6 +377,15 @@ static inline int __vmwrite (unsigned lo
   18.62      __save_flags(eflags);
   18.63      if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
   18.64          return -1;
   18.65 +
   18.66 +    switch(field) {
   18.67 +    case CR0_READ_SHADOW:
   18.68 +    case GUEST_CR0:
   18.69 +    case CPU_BASED_VM_EXEC_CONTROL:
   18.70 +	__vmwrite_vcpu(field, value);
   18.71 +	break;
   18.72 +    }
   18.73 +
   18.74      return 0;
   18.75  }
   18.76  
   18.77 @@ -379,11 +439,12 @@ static inline void vmx_stts(void)
   18.78  {
   18.79      unsigned long cr0;
   18.80  
   18.81 -    __vmread(GUEST_CR0, &cr0);
   18.82 -    if (!(cr0 & X86_CR0_TS))
   18.83 +    __vmread_vcpu(GUEST_CR0, &cr0);
   18.84 +    if (!(cr0 & X86_CR0_TS)) {
   18.85          __vmwrite(GUEST_CR0, cr0 | X86_CR0_TS);
   18.86 +    }
   18.87  
   18.88 -    __vmread(CR0_READ_SHADOW, &cr0);
   18.89 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   18.90      if (!(cr0 & X86_CR0_TS))
   18.91         __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_NM);
   18.92  }
   18.93 @@ -393,7 +454,7 @@ static inline int vmx_paging_enabled(str
   18.94  {
   18.95      unsigned long cr0;
   18.96  
   18.97 -    __vmread(CR0_READ_SHADOW, &cr0);
   18.98 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   18.99      return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG);
  18.100  }
  18.101  
    19.1 --- a/xen/include/asm-x86/vmx_vmcs.h	Wed Sep 21 15:23:26 2005 +0100
    19.2 +++ b/xen/include/asm-x86/vmx_vmcs.h	Wed Sep 21 15:25:58 2005 +0100
    19.3 @@ -74,9 +74,12 @@ struct msr_state{
    19.4  struct arch_vmx_struct {
    19.5      struct vmcs_struct      *vmcs;  /* VMCS pointer in virtual */
    19.6      unsigned long           flags;  /* VMCS flags */
    19.7 +    unsigned long           cpu_cr0; /* copy of guest CR0 */
    19.8 +    unsigned long           cpu_shadow_cr0; /* copy of guest read shadow CR0 */
    19.9      unsigned long           cpu_cr2; /* save CR2 */
   19.10      unsigned long           cpu_cr3;
   19.11      unsigned long           cpu_state;
   19.12 +    unsigned long           cpu_based_exec_control;
   19.13      struct msr_state        msr_content;
   19.14      void                   *io_bitmap_a, *io_bitmap_b;
   19.15  };
    20.1 --- a/xen/include/public/io/tpmif.h	Wed Sep 21 15:23:26 2005 +0100
    20.2 +++ b/xen/include/public/io/tpmif.h	Wed Sep 21 15:25:58 2005 +0100
    20.3 @@ -20,8 +20,7 @@ typedef struct {
    20.4      unsigned long addr;   /* Machine address of packet.   */
    20.5      int      ref;         /* grant table access reference */
    20.6      u16      id;          /* Echoed in response message.  */
    20.7 -    u16      size:15;     /* Packet size in bytes.        */
    20.8 -    u16      mapped:1;
    20.9 +    u16      size;        /* Packet size in bytes.        */
   20.10  } tpmif_tx_request_t;
   20.11  
   20.12  /*
   20.13 @@ -30,13 +29,16 @@ typedef struct {
   20.14   */
   20.15  typedef u32 TPMIF_RING_IDX;
   20.16  
   20.17 -#define TPMIF_TX_RING_SIZE 16
   20.18 +#define TPMIF_TX_RING_SIZE 10
   20.19  
   20.20  /* This structure must fit in a memory page. */
   20.21 +
   20.22  typedef struct {
   20.23 -    union {
   20.24 -        tpmif_tx_request_t  req;
   20.25 -    } ring[TPMIF_TX_RING_SIZE];
   20.26 +    tpmif_tx_request_t req;
   20.27 +} tpmif_ring_t;
   20.28 +
   20.29 +typedef struct {
   20.30 +    tpmif_ring_t ring[TPMIF_TX_RING_SIZE];
   20.31  } tpmif_tx_interface_t;
   20.32  
   20.33  #endif