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$
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 15:23:26 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/Kconfig	Wed Sep 21 15:25:58 2005 +0100
     3.3 @@ -73,6 +73,8 @@ config XEN_NETDEV_BACKEND
     3.4  config XEN_TPMDEV_FRONTEND
     3.5          bool "TPM-device frontend driver"
     3.6          default n
     3.7 +	select TCG_TPM
     3.8 +	select TCG_XEN
     3.9          help
    3.10            The TPM-device frontend driver.
    3.11  
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 15:23:26 2005 +0100
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     5.3 @@ -1,4 +1,4 @@
     5.4 -/******************************************************************************
     5.5 + /******************************************************************************
     5.6   * drivers/xen/tpmback/interface.c
     5.7   *
     5.8   * Vritual TPM interface management.
     5.9 @@ -21,180 +21,175 @@
    5.10  
    5.11  static kmem_cache_t *tpmif_cachep;
    5.12  int num_frontends = 0;
    5.13 +
    5.14  LIST_HEAD(tpmif_list);
    5.15  
    5.16 -
    5.17 -tpmif_t *alloc_tpmif(domid_t domid, long int instance)
    5.18 +tpmif_t *
    5.19 +alloc_tpmif(domid_t domid, long int instance)
    5.20  {
    5.21 -    struct page *page;
    5.22 -    tpmif_t *tpmif;
    5.23 +	struct page *page;
    5.24 +	tpmif_t *tpmif;
    5.25  
    5.26 -    tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    5.27 -    if (!tpmif)
    5.28 -        return ERR_PTR(-ENOMEM);
    5.29 +	tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    5.30 +	if (!tpmif)
    5.31 +		return ERR_PTR(-ENOMEM);
    5.32  
    5.33 -    memset(tpmif, 0, sizeof(*tpmif));
    5.34 -    tpmif->domid        = domid;
    5.35 -    tpmif->status       = DISCONNECTED;
    5.36 -    tpmif->tpm_instance = instance;
    5.37 -    atomic_set(&tpmif->refcnt, 1);
    5.38 +	memset(tpmif, 0, sizeof (*tpmif));
    5.39 +	tpmif->domid = domid;
    5.40 +	tpmif->status = DISCONNECTED;
    5.41 +	tpmif->tpm_instance = instance;
    5.42 +	atomic_set(&tpmif->refcnt, 1);
    5.43  
    5.44 -    page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    5.45 -    BUG_ON(page == NULL);
    5.46 -    tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    5.47 +	page = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    5.48 +	BUG_ON(page == NULL);
    5.49 +	tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
    5.50  
    5.51 -    list_add(&tpmif->tpmif_list, &tpmif_list);
    5.52 -    num_frontends++;
    5.53 +	list_add(&tpmif->tpmif_list, &tpmif_list);
    5.54 +	num_frontends++;
    5.55  
    5.56 -    return tpmif;
    5.57 +	return tpmif;
    5.58  }
    5.59  
    5.60 -
    5.61 -void free_tpmif(tpmif_t *tpmif)
    5.62 +void
    5.63 +free_tpmif(tpmif_t * tpmif)
    5.64  {
    5.65 -    num_frontends--;
    5.66 -    list_del(&tpmif->tpmif_list);
    5.67 -    kmem_cache_free(tpmif_cachep, tpmif);
    5.68 +	num_frontends--;
    5.69 +	list_del(&tpmif->tpmif_list);
    5.70 +	kmem_cache_free(tpmif_cachep, tpmif);
    5.71  }
    5.72  
    5.73 -
    5.74 -tpmif_t *tpmif_find(domid_t domid, long int instance)
    5.75 +tpmif_t *
    5.76 +tpmif_find(domid_t domid, long int instance)
    5.77  {
    5.78 -    tpmif_t *tpmif;
    5.79 +	tpmif_t *tpmif;
    5.80  
    5.81 -    list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    5.82 -        if (tpmif->tpm_instance == instance) {
    5.83 -            if (tpmif->domid == domid) {
    5.84 -                tpmif_get(tpmif);
    5.85 -                return tpmif;
    5.86 -	    } else {
    5.87 -	        return NULL;
    5.88 -	    }
    5.89 -        }
    5.90 -    }
    5.91 +	list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    5.92 +		if (tpmif->tpm_instance == instance) {
    5.93 +			if (tpmif->domid == domid) {
    5.94 +				tpmif_get(tpmif);
    5.95 +				return tpmif;
    5.96 +			} else {
    5.97 +				return NULL;
    5.98 +			}
    5.99 +		}
   5.100 +	}
   5.101  
   5.102 -    return alloc_tpmif(domid, instance);
   5.103 +	return alloc_tpmif(domid, instance);
   5.104  }
   5.105  
   5.106 -
   5.107 -static int map_frontend_page(tpmif_t *tpmif, unsigned long localaddr,
   5.108 -			     unsigned long shared_page)
   5.109 +static int
   5.110 +map_frontend_page(tpmif_t * tpmif, unsigned long localaddr,
   5.111 +		  unsigned long shared_page)
   5.112  {
   5.113 -    struct gnttab_map_grant_ref op = {
   5.114 -        .host_addr = localaddr,
   5.115 -        .flags     = GNTMAP_host_map,
   5.116 -        .ref       = shared_page,
   5.117 -        .dom       = tpmif->domid,
   5.118 -    };
   5.119 +	struct gnttab_map_grant_ref op = {
   5.120 +		.host_addr = localaddr,
   5.121 +		.flags = GNTMAP_host_map,
   5.122 +		.ref = shared_page,
   5.123 +		.dom = tpmif->domid,
   5.124 +	};
   5.125  
   5.126 -    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   5.127 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1));
   5.128  
   5.129 -    if (op.handle < 0) {
   5.130 -	DPRINTK(" Grant table operation failure !\n");
   5.131 -	return op.handle;
   5.132 -    }
   5.133 +	if (op.handle < 0) {
   5.134 +		DPRINTK(" Grant table operation failure !\n");
   5.135 +		return op.handle;
   5.136 +	}
   5.137  
   5.138 -    tpmif->shmem_ref    = shared_page;
   5.139 -    tpmif->shmem_handle = op.handle;
   5.140 -    tpmif->shmem_vaddr  = localaddr;
   5.141 -    return 0;
   5.142 +	tpmif->shmem_ref = shared_page;
   5.143 +	tpmif->shmem_handle = op.handle;
   5.144 +	tpmif->shmem_vaddr = localaddr;
   5.145 +	return 0;
   5.146  }
   5.147  
   5.148 -
   5.149 -static void unmap_frontend_page(tpmif_t *tpmif)
   5.150 +static void
   5.151 +unmap_frontend_page(tpmif_t * tpmif)
   5.152  {
   5.153 -    struct gnttab_unmap_grant_ref op;
   5.154 +	struct gnttab_unmap_grant_ref op;
   5.155  
   5.156 -    op.host_addr = tpmif->shmem_vaddr;
   5.157 -    op.handle = tpmif->shmem_handle;
   5.158 -    op.dev_bus_addr = 0;
   5.159 +	op.host_addr = tpmif->shmem_vaddr;
   5.160 +	op.handle = tpmif->shmem_handle;
   5.161 +	op.dev_bus_addr = 0;
   5.162  
   5.163 -    BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   5.164 +	BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
   5.165  }
   5.166  
   5.167 -
   5.168 -int tpmif_map(tpmif_t *tpmif,
   5.169 -              unsigned long shared_page, unsigned int evtchn)
   5.170 +int
   5.171 +tpmif_map(tpmif_t * tpmif, unsigned long shared_page, unsigned int evtchn)
   5.172  {
   5.173 -    struct vm_struct *vma;
   5.174 -    evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
   5.175 -    int err;
   5.176 +	struct vm_struct *vma;
   5.177 +	evtchn_op_t op = {.cmd = EVTCHNOP_bind_interdomain };
   5.178 +	int err;
   5.179  
   5.180 -    BUG_ON(tpmif->remote_evtchn);
   5.181 +	BUG_ON(tpmif->remote_evtchn);
   5.182  
   5.183 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
   5.184 -	return -ENOMEM;
   5.185 +	if ((vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL)
   5.186 +		return -ENOMEM;
   5.187  
   5.188 -    err = map_frontend_page(tpmif,
   5.189 -                            VMALLOC_VMADDR(vma->addr),
   5.190 -                            shared_page);
   5.191 -    if (err) {
   5.192 -        vfree(vma->addr);
   5.193 -	return err;
   5.194 -    }
   5.195 +	err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
   5.196 +	if (err) {
   5.197 +		vfree(vma->addr);
   5.198 +		return err;
   5.199 +	}
   5.200  
   5.201 -    op.u.bind_interdomain.dom1 = DOMID_SELF;
   5.202 -    op.u.bind_interdomain.dom2 = tpmif->domid;
   5.203 -    op.u.bind_interdomain.port1 = 0;
   5.204 -    op.u.bind_interdomain.port2 = evtchn;
   5.205 -    err = HYPERVISOR_event_channel_op(&op);
   5.206 -    if (err) {
   5.207 -	unmap_frontend_page(tpmif);
   5.208 -	vfree(vma->addr);
   5.209 -	return err;
   5.210 -    }
   5.211 +	op.u.bind_interdomain.dom1 = DOMID_SELF;
   5.212 +	op.u.bind_interdomain.dom2 = tpmif->domid;
   5.213 +	op.u.bind_interdomain.port1 = 0;
   5.214 +	op.u.bind_interdomain.port2 = evtchn;
   5.215 +	err = HYPERVISOR_event_channel_op(&op);
   5.216 +	if (err) {
   5.217 +		unmap_frontend_page(tpmif);
   5.218 +		vfree(vma->addr);
   5.219 +		return err;
   5.220 +	}
   5.221  
   5.222 -    tpmif->evtchn = op.u.bind_interdomain.port1;
   5.223 -    tpmif->remote_evtchn = evtchn;
   5.224 +	tpmif->evtchn = op.u.bind_interdomain.port1;
   5.225 +	tpmif->remote_evtchn = evtchn;
   5.226  
   5.227 -    tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   5.228 +	tpmif->tx = (tpmif_tx_interface_t *) vma->addr;
   5.229  
   5.230 -    bind_evtchn_to_irqhandler(tpmif->evtchn,
   5.231 -                              tpmif_be_int,
   5.232 -                              0,
   5.233 -                              "tpmif-backend",
   5.234 -			      tpmif);
   5.235 -    tpmif->status        = CONNECTED;
   5.236 -    tpmif->shmem_ref     = shared_page;
   5.237 -    tpmif->active        = 1;
   5.238 +	bind_evtchn_to_irqhandler(tpmif->evtchn,
   5.239 +				  tpmif_be_int, 0, "tpmif-backend", tpmif);
   5.240 +	tpmif->status = CONNECTED;
   5.241 +	tpmif->shmem_ref = shared_page;
   5.242 +	tpmif->active = 1;
   5.243  
   5.244 -    return 0;
   5.245 +	return 0;
   5.246  }
   5.247  
   5.248 -
   5.249 -static void __tpmif_disconnect_complete(void *arg)
   5.250 +static void
   5.251 +__tpmif_disconnect_complete(void *arg)
   5.252  {
   5.253 -    evtchn_op_t op = { .cmd = EVTCHNOP_close };
   5.254 -    tpmif_t *tpmif = (tpmif_t *) arg;
   5.255 +	evtchn_op_t op = {.cmd = EVTCHNOP_close };
   5.256 +	tpmif_t *tpmif = (tpmif_t *) arg;
   5.257  
   5.258 -    op.u.close.port = tpmif->evtchn;
   5.259 -    op.u.close.dom  = DOMID_SELF;
   5.260 -    HYPERVISOR_event_channel_op(&op);
   5.261 -    op.u.close.port = tpmif->remote_evtchn;
   5.262 -    op.u.close.dom  = tpmif->domid;
   5.263 -    HYPERVISOR_event_channel_op(&op);
   5.264 +	op.u.close.port = tpmif->evtchn;
   5.265 +	op.u.close.dom = DOMID_SELF;
   5.266 +	HYPERVISOR_event_channel_op(&op);
   5.267 +	op.u.close.port = tpmif->remote_evtchn;
   5.268 +	op.u.close.dom = tpmif->domid;
   5.269 +	HYPERVISOR_event_channel_op(&op);
   5.270  
   5.271 -    if (tpmif->evtchn)
   5.272 -         unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   5.273 +	if (tpmif->evtchn)
   5.274 +		unbind_evtchn_from_irqhandler(tpmif->evtchn, tpmif);
   5.275  
   5.276 -    if (tpmif->tx) {
   5.277 -        unmap_frontend_page(tpmif);
   5.278 -        vfree(tpmif->tx);
   5.279 -    }
   5.280 +	if (tpmif->tx) {
   5.281 +		unmap_frontend_page(tpmif);
   5.282 +		vfree(tpmif->tx);
   5.283 +	}
   5.284  
   5.285 -    free_tpmif(tpmif);
   5.286 +	free_tpmif(tpmif);
   5.287  }
   5.288  
   5.289 -
   5.290 -void tpmif_disconnect_complete(tpmif_t * tpmif)
   5.291 +void
   5.292 +tpmif_disconnect_complete(tpmif_t * tpmif)
   5.293  {
   5.294 -    INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   5.295 -    schedule_work(&tpmif->work);
   5.296 +	INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif);
   5.297 +	schedule_work(&tpmif->work);
   5.298  }
   5.299  
   5.300 -
   5.301 -void __init tpmif_interface_init(void)
   5.302 +void __init
   5.303 +tpmif_interface_init(void)
   5.304  {
   5.305 -    tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof(tpmif_t),
   5.306 -                                     0, 0, NULL, NULL);
   5.307 +	tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t),
   5.308 +					 0, 0, NULL, NULL);
   5.309  }
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 15:23:26 2005 +0100
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c	Wed Sep 21 15:25:58 2005 +0100
     6.3 @@ -257,18 +257,24 @@ static int setup_tpmring(struct xenbus_d
     6.4  
     6.5  	tpm_allocate_buffers(tp);
     6.6  
     6.7 -	info->ring_ref = gnttab_claim_grant_reference(&gref_head);
     6.8 -	ASSERT(info->ring_ref != -ENOSPC);
     6.9 -	gnttab_grant_foreign_access_ref(info->ring_ref,
    6.10 -					backend_id,
    6.11 -					(virt_to_machine(tp->tx) >> PAGE_SHIFT),
    6.12 -					0);
    6.13 +	err = gnttab_grant_foreign_access(backend_id,
    6.14 +					  (virt_to_machine(tp->tx) >> PAGE_SHIFT),
    6.15 +					  0);
    6.16 +
    6.17 +	if (err == -ENOSPC) {
    6.18 +		free_page((unsigned long)sring);
    6.19 +		tp->tx = NULL;
    6.20 +		xenbus_dev_error(dev, err, "allocating grant reference");
    6.21 +		return err;
    6.22 +	}
    6.23 +	info->ring_ref = err;
    6.24  
    6.25  	op.u.alloc_unbound.dom = backend_id;
    6.26  	err = HYPERVISOR_event_channel_op(&op);
    6.27  	if (err) {
    6.28 +		gnttab_end_foreign_access(info->ring_ref, 0);
    6.29  		free_page((unsigned long)sring);
    6.30 -		tp->tx = 0;
    6.31 +		tp->tx = NULL;
    6.32  		xenbus_dev_error(dev, err, "allocating event channel");
    6.33  		return err;
    6.34  	}
    6.35 @@ -282,6 +288,7 @@ static void destroy_tpmring(struct tpmfr
    6.36  	tpmif_set_connected_state(tp,0);
    6.37  
    6.38  	if ( tp->tx != NULL ) {
    6.39 +		gnttab_end_foreign_access(info->ring_ref, 0);
    6.40  		free_page((unsigned long)tp->tx);
    6.41  		tp->tx = NULL;
    6.42  	}
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 15:23:26 2005 +0100
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.h	Wed Sep 21 15:25:58 2005 +0100
     7.3 @@ -2,7 +2,8 @@
     7.4  #define TPM_FRONT_H
     7.5  
     7.6  
     7.7 -struct tpm_private {
     7.8 +struct tpm_private
     7.9 +{
    7.10  	tpmif_tx_interface_t *tx;
    7.11  	unsigned int evtchn;
    7.12  	int connected;
    7.13 @@ -29,7 +30,8 @@ struct tpmfront_info
    7.14  };
    7.15  
    7.16  
    7.17 -struct tx_buffer {
    7.18 +struct tx_buffer
    7.19 +{
    7.20  	unsigned int size;	// available space in data
    7.21  	unsigned int len;	// used space in data
    7.22  	unsigned char *data;    // pointer to a page
     9.1 --- a/tools/examples/xmexample.vmx	Wed Sep 21 15:23:26 2005 +0100
     9.2 +++ b/tools/examples/xmexample.vmx	Wed Sep 21 15:25:58 2005 +0100
     9.3 @@ -26,6 +26,10 @@ memory = 128
     9.4  # A name for your domain. All domains must have different names.
     9.5  name = "ExampleVMXDomain"
     9.6  
     9.7 +#-----------------------------------------------------------------------------
     9.8 +# the number of cpus guest platform has, default=1
     9.9 +vcpus=1
    9.10 +
    9.11  # Which CPU to start domain on? 
    9.12  #cpu = -1   # leave to Xen to pick
    9.13  
    10.1 --- a/tools/ioemu/vl.c	Wed Sep 21 15:23:26 2005 +0100
    10.2 +++ b/tools/ioemu/vl.c	Wed Sep 21 15:25:58 2005 +0100
    10.3 @@ -126,6 +126,7 @@ QEMUTimer *polling_timer;
    10.4  int vm_running;
    10.5  int audio_enabled = 0;
    10.6  int nic_pcnet = 1;
    10.7 +int vcpus = 1;
    10.8  int sb16_enabled = 1;
    10.9  int adlib_enabled = 1;
   10.10  int gus_enabled = 1;
   10.11 @@ -2105,6 +2106,7 @@ void help(void)
   10.12  	   "-snapshot       write to temporary files instead of disk image files\n"
   10.13             "-m megs         set virtual RAM size to megs MB [default=%d]\n"
   10.14             "-nographic      disable graphical output and redirect serial I/Os to console\n"
   10.15 +           "-vcpus          set CPU number of guest platform\n"
   10.16  #ifdef CONFIG_VNC
   10.17  	   "-vnc port             use vnc instead of sdl\n"
   10.18  	   "-vncport port         use a different port\n"
   10.19 @@ -2235,6 +2237,7 @@ enum {
   10.20      QEMU_OPTION_hdachs,
   10.21      QEMU_OPTION_L,
   10.22      QEMU_OPTION_no_code_copy,
   10.23 +    QEMU_OPTION_vcpus,
   10.24      QEMU_OPTION_pci,
   10.25      QEMU_OPTION_nic_pcnet,
   10.26      QEMU_OPTION_isa,
   10.27 @@ -2307,6 +2310,7 @@ const QEMUOption qemu_options[] = {
   10.28      { "hdachs", HAS_ARG, QEMU_OPTION_hdachs },
   10.29      { "L", HAS_ARG, QEMU_OPTION_L },
   10.30      { "no-code-copy", 0, QEMU_OPTION_no_code_copy },
   10.31 +    { "vcpus", 1, QEMU_OPTION_vcpus },
   10.32  #ifdef TARGET_PPC
   10.33      { "prep", 0, QEMU_OPTION_prep },
   10.34      { "g", 1, QEMU_OPTION_g },
   10.35 @@ -2646,6 +2650,9 @@ int main(int argc, char **argv)
   10.36              case QEMU_OPTION_S:
   10.37                  start_emulation = 0;
   10.38                  break;
   10.39 +            case QEMU_OPTION_vcpus:
   10.40 +                vcpus = atoi(optarg);
   10.41 +                fprintf(logfile, "qemu: the number of cpus is %d\n", vcpus);
   10.42              case QEMU_OPTION_pci:
   10.43                  pci_enabled = 1;
   10.44                  break;
    11.1 --- a/tools/libxc/xc_vmx_build.c	Wed Sep 21 15:23:26 2005 +0100
    11.2 +++ b/tools/libxc/xc_vmx_build.c	Wed Sep 21 15:25:58 2005 +0100
    11.3 @@ -626,6 +626,10 @@ static int setup_guest(int xc_handle,
    11.4      /* Mask all upcalls... */
    11.5      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
    11.6          shared_info->vcpu_data[i].evtchn_upcall_mask = 1;
    11.7 +
    11.8 +    shared_info->n_vcpu = vcpus;
    11.9 +    printf(" VCPUS:         %d\n", shared_info->n_vcpu);
   11.10 +
   11.11      munmap(shared_info, PAGE_SIZE);
   11.12  
   11.13      /* Populate the event channel port in the shared page */
    13.1 --- a/tools/python/xen/util/process.py	Wed Sep 21 15:23:26 2005 +0100
    13.2 +++ b/tools/python/xen/util/process.py	Wed Sep 21 15:25:58 2005 +0100
    13.3 @@ -24,6 +24,8 @@ def runscript(cmd):
    13.4          r = p.poll()
    13.5          for (fd, event) in r:
    13.6              if event == select.POLLHUP:
    13.7 +                cout.close()
    13.8 +                cerr.close()
    13.9                  return stdout
   13.10              if fd == cout.fileno():
   13.11                  stdout = stdout + cout.readline()
    25.1 --- a/tools/python/xen/xend/image.py	Wed Sep 21 15:23:26 2005 +0100
    25.2 +++ b/tools/python/xen/xend/image.py	Wed Sep 21 15:25:58 2005 +0100
    25.3 @@ -324,7 +324,7 @@ class VmxImageHandler(ImageHandler):
    25.4      # xm config file
    25.5      def parseDeviceModelArgs(self, imageConfig, deviceConfig):
    25.6          dmargs = [ 'cdrom', 'boot', 'fda', 'fdb',
    25.7 -                   'localtime', 'serial', 'stdvga', 'isa' ] 
    25.8 +                   'localtime', 'serial', 'stdvga', 'isa', 'vcpus' ] 
    25.9          ret = []
   25.10          for a in dmargs:
   25.11              v = sxp.child_value(imageConfig, a)
    26.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Sep 21 15:23:26 2005 +0100
    26.2 +++ b/tools/python/xen/xend/server/blkif.py	Wed Sep 21 15:25:58 2005 +0100
    26.3 @@ -42,7 +42,7 @@ class BlkifController(DevController):
    26.4          
    26.5          typedev = sxp.child_value(config, 'dev')
    26.6          if re.match('^ioemu:', typedev):
    26.7 -            return
    26.8 +            return (0,{},{})
    26.9  
   26.10          devid = blkif.blkdev_name_to_number(sxp.child_value(config, 'dev'))
   26.11  
    27.1 --- a/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 15:23:26 2005 +0100
    27.2 +++ b/tools/python/xen/xend/server/tpmif.py	Wed Sep 21 15:25:58 2005 +0100
    27.3 @@ -39,7 +39,7 @@ class TPMifController(DevController):
    27.4          """@see DevController.getDeviceDetails"""
    27.5          
    27.6          devid = int(sxp.child_value(config, 'instance', '0'))
    27.7 -        log.error("The domain has a TPM with instance %d." % devid)
    27.8 +        log.debug("The domain has a TPM with instance %d." % devid)
    27.9  
   27.10          back  = { 'instance' : "%i" % devid }
   27.11          front = { 'handle' : "%i" % devid }
    30.1 --- a/tools/python/xen/xm/create.py	Wed Sep 21 15:23:26 2005 +0100
    30.2 +++ b/tools/python/xen/xm/create.py	Wed Sep 21 15:25:58 2005 +0100
    30.3 @@ -496,7 +496,7 @@ def configure_vfr(opts, config, vals):
    30.4  def configure_vmx(opts, config_image, vals):
    30.5      """Create the config for VMX devices.
    30.6      """
    30.7 -    args = [ 'memmap', 'device_model', 'cdrom',
    30.8 +    args = [ 'memmap', 'device_model', 'vcpus', 'cdrom',
    30.9               'boot', 'fda', 'fdb', 'localtime', 'serial', 'macaddr', 'stdvga', 
   30.10               'isa', 'nographic', 'vnc', 'vncviewer', 'sdl', 'display']
   30.11      for a in args:
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/tools/vtpm/tpm_emulator-0.2b-x86_64.patch	Wed Sep 21 15:25:58 2005 +0100
    31.3 @@ -0,0 +1,499 @@
    31.4 +diff -uprN tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c
    31.5 +--- tpm_emulator-0.2/crypto/gmp_kernel_wrapper.c	2005-08-15 00:58:57.000000000 -0700
    31.6 ++++ tpm_emulator-0.2-x86_64/crypto/gmp_kernel_wrapper.c	2005-09-19 14:10:29.000000000 -0700
    31.7 +@@ -79,7 +79,7 @@ void __attribute__ ((regparm(0))) *kerne
    31.8 + {
    31.9 +   void *ret  = (void*)kmalloc(size, GFP_KERNEL);
   31.10 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME 
   31.11 +-    "GMP: cannot allocate memory (size=%u)\n", size);
   31.12 ++    "GMP: cannot allocate memory (size=%Zu)\n", size);
   31.13 +   return ret;
   31.14 + }
   31.15 + 
   31.16 +@@ -88,7 +88,7 @@ void __attribute__ ((regparm(0))) *kerne
   31.17 + {
   31.18 +   void *ret = (void*)kmalloc(new_size, GFP_KERNEL);
   31.19 +   if (!ret) panic(KERN_CRIT TPM_MODULE_NAME "GMP: Cannot reallocate memory "
   31.20 +-    "(old_size=%u new_size=%u)\n", old_size, new_size);
   31.21 ++    "(old_size=%Zu new_size=%Zu)\n", old_size, new_size);
   31.22 +   memcpy(ret, oldptr, old_size);
   31.23 +   kfree(oldptr);
   31.24 +   return ret;
   31.25 +diff -uprN tpm_emulator-0.2/linux_module.c tpm_emulator-0.2-x86_64/linux_module.c
   31.26 +--- tpm_emulator-0.2/linux_module.c	2005-08-15 00:58:57.000000000 -0700
   31.27 ++++ tpm_emulator-0.2-x86_64/linux_module.c	2005-09-19 14:10:29.000000000 -0700
   31.28 +@@ -66,7 +66,7 @@ static int tpm_release(struct inode *ino
   31.29 + 
   31.30 + static ssize_t tpm_read(struct file *file, char *buf, size_t count, loff_t *ppos)
   31.31 + {
   31.32 +-  debug("%s(%d)", __FUNCTION__, count);
   31.33 ++  debug("%s(%Zu)", __FUNCTION__, count);
   31.34 +   down(&tpm_mutex);
   31.35 +   if (tpm_response.data != NULL) {
   31.36 +     count = min(count, (size_t)tpm_response.size - (size_t)*ppos);
   31.37 +@@ -81,7 +81,7 @@ static ssize_t tpm_read(struct file *fil
   31.38 + 
   31.39 + static ssize_t tpm_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
   31.40 + {
   31.41 +-  debug("%s(%d)", __FUNCTION__, count);
   31.42 ++  debug("%s(%Zu)", __FUNCTION__, count);
   31.43 +   down(&tpm_mutex);
   31.44 +   *ppos = 0;
   31.45 +   if (tpm_response.data != NULL) kfree(tpm_response.data);
   31.46 +diff -uprN tpm_emulator-0.2/linux_module.h tpm_emulator-0.2-x86_64/linux_module.h
   31.47 +--- tpm_emulator-0.2/linux_module.h	2005-08-15 00:58:57.000000000 -0700
   31.48 ++++ tpm_emulator-0.2-x86_64/linux_module.h	2005-09-19 14:10:29.000000000 -0700
   31.49 +@@ -28,8 +28,10 @@
   31.50 + 
   31.51 + /* module settings */
   31.52 + 
   31.53 ++#ifndef STR
   31.54 + #define STR(s) __STR__(s)
   31.55 + #define __STR__(s) #s
   31.56 ++#endif
   31.57 + #include "tpm_version.h"
   31.58 + 
   31.59 + #define TPM_DEVICE_MINOR	224
   31.60 +diff -uprN tpm_emulator-0.2/Makefile tpm_emulator-0.2-x86_64/Makefile
   31.61 +--- tpm_emulator-0.2/Makefile	2005-08-15 00:58:57.000000000 -0700
   31.62 ++++ tpm_emulator-0.2-x86_64/Makefile	2005-09-19 14:10:29.000000000 -0700
   31.63 +@@ -7,6 +7,7 @@
   31.64 + KERNEL_RELEASE := $(shell uname -r)
   31.65 + KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
   31.66 + MOD_SUBDIR     := misc
   31.67 ++COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
   31.68 + 
   31.69 + # module settings
   31.70 + MODULE_NAME    := tpm_emulator
   31.71 +@@ -17,8 +18,14 @@ VERSION_BUILD  := $(shell date +"%s")
   31.72 + # enable/disable DEBUG messages
   31.73 + EXTRA_CFLAGS   += -DDEBUG -g  
   31.74 + 
   31.75 ++ifeq ($(COMPILE_ARCH),x86_64)
   31.76 ++LIBDIR = lib64
   31.77 ++else
   31.78 ++LIBDIR = lib
   31.79 ++endif
   31.80 ++
   31.81 + # GNU MP configuration
   31.82 +-GMP_LIB        := /usr/lib/libgmp.a
   31.83 ++GMP_LIB        := /usr/$(LIBDIR)/libgmp.a
   31.84 + GMP_HEADER     := /usr/include/gmp.h
   31.85 + 
   31.86 + # sources and objects
   31.87 +diff -uprN tpm_emulator-0.2/README tpm_emulator-0.2-x86_64/README
   31.88 +--- tpm_emulator-0.2/README	2005-08-15 00:58:57.000000000 -0700
   31.89 ++++ tpm_emulator-0.2-x86_64/README	2005-09-19 14:21:43.000000000 -0700
   31.90 +@@ -45,6 +45,12 @@ Example:
   31.91 + GMP_LIB        := /usr/lib/libgmp.a
   31.92 + GMP_HEADER     := /usr/include/gmp.h
   31.93 + 
   31.94 ++GNU MP Library on 64 bit Systems
   31.95 ++--------------------------------------------------------------------------
   31.96 ++Some 64-bit kernels have problems with importing the user-space gmp 
   31.97 ++library (/usr/lib*/libgmp.a) into kernel space.  These kernels will require
   31.98 ++that the gmp library be recompiled for kernel space with -mcmodel=kernel.
   31.99 ++
  31.100 + Installation
  31.101 + --------------------------------------------------------------------------
  31.102 + The compilation and installation process uses the build environment for 
  31.103 +diff -uprN tpm_emulator-0.2/tpm/tpm_credentials.c tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c
  31.104 +--- tpm_emulator-0.2/tpm/tpm_credentials.c	2005-08-15 00:58:57.000000000 -0700
  31.105 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_credentials.c	2005-09-19 14:10:29.000000000 -0700
  31.106 +@@ -47,16 +47,16 @@ int tpm_compute_pubkey_checksum(TPM_NONC
  31.107 + 
  31.108 + TPM_RESULT tpm_get_pubek(TPM_PUBKEY *pubEndorsementKey)
  31.109 + {
  31.110 +-  UINT32 key_length;
  31.111 ++  size_t key_length;
  31.112 +   if (!tpmData.permanent.data.endorsementKey.size) return TPM_NO_ENDORSEMENT;
  31.113 +   /* setup TPM_PUBKEY structure */
  31.114 +-  key_length = tpmData.permanent.data.endorsementKey.size;
  31.115 +-  pubEndorsementKey->pubKey.keyLength = key_length >> 3;
  31.116 ++  pubEndorsementKey->pubKey.keyLength = tpmData.permanent.data.endorsementKey.size >> 3;
  31.117 +   pubEndorsementKey->pubKey.key = tpm_malloc(pubEndorsementKey->pubKey.keyLength);
  31.118 +   if (pubEndorsementKey->pubKey.key == NULL) return TPM_FAIL;
  31.119 +   rsa_export_modulus(&tpmData.permanent.data.endorsementKey,
  31.120 +-    pubEndorsementKey->pubKey.key,
  31.121 +-    &pubEndorsementKey->pubKey.keyLength);
  31.122 ++		     pubEndorsementKey->pubKey.key,
  31.123 ++		     &key_length);
  31.124 ++  pubEndorsementKey->pubKey.keyLength = key_length;
  31.125 +   pubEndorsementKey->algorithmParms.algorithmID = TPM_ALG_RSA;
  31.126 +   pubEndorsementKey->algorithmParms.encScheme = TPM_ES_RSAESOAEP_SHA1_MGF1;
  31.127 +   pubEndorsementKey->algorithmParms.sigScheme = TPM_SS_NONE;
  31.128 +@@ -169,6 +169,7 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  31.129 + {
  31.130 +   TPM_RESULT res;
  31.131 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  31.132 ++  size_t key_length;
  31.133 +   info("TPM_OwnerReadInternalPub()");
  31.134 +   /* verify authorization */
  31.135 +   res = tpm_verify_auth(auth1, tpmData.permanent.data.ownerAuth, TPM_KH_OWNER);
  31.136 +@@ -180,7 +181,8 @@ TPM_RESULT TPM_OwnerReadInternalPub(TPM_
  31.137 +     publicPortion->pubKey.key = tpm_malloc(publicPortion->pubKey.keyLength);
  31.138 +     if (publicPortion->pubKey.key == NULL) return TPM_FAIL;
  31.139 +     rsa_export_modulus(&srk->key, publicPortion->pubKey.key, 
  31.140 +-      &publicPortion->pubKey.keyLength);
  31.141 ++      &key_length);
  31.142 ++    publicPortion->pubKey.keyLength = key_length;
  31.143 +     publicPortion->algorithmParms.algorithmID = TPM_ALG_RSA;
  31.144 +     publicPortion->algorithmParms.encScheme = srk->encScheme;
  31.145 +     publicPortion->algorithmParms.sigScheme = srk->sigScheme;
  31.146 +diff -uprN tpm_emulator-0.2/tpm/tpm_crypto.c tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c
  31.147 +--- tpm_emulator-0.2/tpm/tpm_crypto.c	2005-08-15 00:58:57.000000000 -0700
  31.148 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_crypto.c	2005-09-19 14:10:29.000000000 -0700
  31.149 +@@ -182,7 +182,8 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  31.150 +   TPM_KEY_DATA *cert, *key;
  31.151 +   sha1_ctx_t sha1_ctx;
  31.152 +   BYTE *buf, *p;
  31.153 +-  UINT32 length;
  31.154 ++  UINT32 length32;
  31.155 ++  size_t length;
  31.156 +   info("TPM_CertifyKey()");
  31.157 +   /* get keys */
  31.158 +   cert = tpm_get_key(certHandle);
  31.159 +@@ -264,14 +265,15 @@ TPM_RESULT TPM_CertifyKey(TPM_KEY_HANDLE
  31.160 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  31.161 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  31.162 +   p = buf = tpm_malloc(length);
  31.163 ++  length32=(UINT32) length;
  31.164 +   if (buf == NULL
  31.165 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  31.166 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  31.167 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  31.168 +     return TPM_FAIL;
  31.169 +   }
  31.170 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  31.171 +   sha1_init(&sha1_ctx);
  31.172 +-  sha1_update(&sha1_ctx, buf, length);
  31.173 ++  sha1_update(&sha1_ctx, buf, (size_t) length);
  31.174 +   sha1_final(&sha1_ctx, buf);
  31.175 +   res = tpm_sign(cert, auth1, FALSE, buf, SHA1_DIGEST_LENGTH, outData, outDataSize);
  31.176 +   tpm_free(buf);
  31.177 +@@ -292,7 +294,8 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  31.178 +   TPM_KEY_DATA *cert, *key;
  31.179 +   sha1_ctx_t sha1_ctx;
  31.180 +   BYTE *buf, *p;
  31.181 +-  UINT32 length;
  31.182 ++  size_t length;
  31.183 ++  UINT32 length32;
  31.184 +   info("TPM_CertifyKey2()");
  31.185 +   /* get keys */
  31.186 +   cert = tpm_get_key(certHandle);
  31.187 +@@ -362,8 +365,9 @@ TPM_RESULT TPM_CertifyKey2(TPM_KEY_HANDL
  31.188 +   /* compute the digest of the CERTIFY_INFO[2] structure and sign it */
  31.189 +   length = sizeof_TPM_CERTIFY_INFO((*certifyInfo));
  31.190 +   p = buf = tpm_malloc(length);
  31.191 ++  length32 = (UINT32) length;
  31.192 +   if (buf == NULL
  31.193 +-      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length, certifyInfo)) {
  31.194 ++      || tpm_marshal_TPM_CERTIFY_INFO(&p, &length32, certifyInfo)) {
  31.195 +     free_TPM_KEY_PARMS(certifyInfo->algorithmParms);
  31.196 +     return TPM_FAIL;
  31.197 +   }
  31.198 +diff -uprN tpm_emulator-0.2/tpm/tpm_data.c tpm_emulator-0.2-x86_64/tpm/tpm_data.c
  31.199 +--- tpm_emulator-0.2/tpm/tpm_data.c	2005-08-15 00:58:57.000000000 -0700
  31.200 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_data.c	2005-09-19 14:10:29.000000000 -0700
  31.201 +@@ -179,7 +179,7 @@ static int read_from_file(uint8_t **data
  31.202 + int tpm_store_permanent_data(void)
  31.203 + {
  31.204 +   uint8_t *buf, *ptr;
  31.205 +-  size_t buf_length, len;
  31.206 ++  UINT32 buf_length, len;
  31.207 + 
  31.208 +   /* marshal data */
  31.209 +   buf_length = len = sizeof_TPM_STCLEAR_FLAGS(tpmData.stclear.flags)
  31.210 +@@ -207,13 +207,14 @@ int tpm_store_permanent_data(void)
  31.211 + int tpm_restore_permanent_data(void)
  31.212 + {
  31.213 +   uint8_t *buf, *ptr;
  31.214 +-  size_t buf_length, len;
  31.215 ++  size_t buf_length;
  31.216 ++  UINT32 len;
  31.217 +   TPM_VERSION ver;
  31.218 + 
  31.219 +   /* read data */
  31.220 +   if (read_from_file(&buf, &buf_length)) return -1;
  31.221 +   ptr = buf;
  31.222 +-  len = buf_length;
  31.223 ++  len = (uint32_t) buf_length;
  31.224 +   /* unmarshal data */
  31.225 +   if (tpm_unmarshal_TPM_VERSION(&ptr, &len, &ver)
  31.226 +       || memcmp(&ver, &tpmData.permanent.data.version, sizeof(TPM_VERSION))
  31.227 +diff -uprN tpm_emulator-0.2/tpm/tpm_marshalling.c tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c
  31.228 +--- tpm_emulator-0.2/tpm/tpm_marshalling.c	2005-08-15 00:58:57.000000000 -0700
  31.229 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_marshalling.c	2005-09-19 14:10:29.000000000 -0700
  31.230 +@@ -981,7 +981,7 @@ int tpm_unmarshal_TPM_STANY_FLAGS(BYTE *
  31.231 + 
  31.232 + int tpm_marshal_RSA(BYTE **ptr, UINT32 *length, rsa_private_key_t *v)
  31.233 + {
  31.234 +-  UINT32 m_len, e_len, q_len;
  31.235 ++  size_t m_len, e_len, q_len;
  31.236 +   if (*length < sizeof_RSA((*v))) return -1;
  31.237 +   if (v->size > 0) {
  31.238 +     rsa_export_modulus(v, &(*ptr)[6], &m_len);
  31.239 +diff -uprN tpm_emulator-0.2/tpm/tpm_owner.c tpm_emulator-0.2-x86_64/tpm/tpm_owner.c
  31.240 +--- tpm_emulator-0.2/tpm/tpm_owner.c	2005-08-15 00:58:57.000000000 -0700
  31.241 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_owner.c	2005-09-19 14:10:29.000000000 -0700
  31.242 +@@ -108,7 +108,7 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  31.243 +   TPM_RESULT res;
  31.244 +   rsa_private_key_t *ek = &tpmData.permanent.data.endorsementKey;
  31.245 +   TPM_KEY_DATA *srk = &tpmData.permanent.data.srk;
  31.246 +-  UINT32 buf_size = ek->size >> 3;
  31.247 ++  size_t buf_size = ek->size >> 3, key_length; 
  31.248 +   BYTE buf[buf_size];
  31.249 + 
  31.250 +   info("TPM_TakeOwnership()");
  31.251 +@@ -172,7 +172,8 @@ TPM_RESULT TPM_TakeOwnership(TPM_PROTOCO
  31.252 +     return TPM_FAIL;
  31.253 +   }
  31.254 +   rsa_export_modulus(&srk->key, srkPub->pubKey.key,
  31.255 +-    &srkPub->pubKey.keyLength);
  31.256 ++		     &key_length);
  31.257 ++  srkPub->pubKey.keyLength = (UINT32) key_length;
  31.258 +   /* setup tpmProof and set state to owned */
  31.259 +   tpm_get_random_bytes(tpmData.permanent.data.tpmProof.nonce, 
  31.260 +     sizeof(tpmData.permanent.data.tpmProof.nonce));
  31.261 +diff -uprN tpm_emulator-0.2/tpm/tpm_storage.c tpm_emulator-0.2-x86_64/tpm/tpm_storage.c
  31.262 +--- tpm_emulator-0.2/tpm/tpm_storage.c	2005-08-15 00:58:57.000000000 -0700
  31.263 ++++ tpm_emulator-0.2-x86_64/tpm/tpm_storage.c	2005-09-19 14:10:29.000000000 -0700
  31.264 +@@ -58,6 +58,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  31.265 +                         BYTE *enc, UINT32 *enc_size)
  31.266 + {
  31.267 +   UINT32 len;
  31.268 ++  size_t enc_size32 = *enc_size;
  31.269 +   BYTE *buf, *ptr;
  31.270 +   rsa_public_key_t pub_key;
  31.271 +   int scheme;
  31.272 +@@ -72,7 +73,7 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  31.273 +   if (buf == NULL
  31.274 +       || tpm_marshal_TPM_SEALED_DATA(&ptr, &len, seal)
  31.275 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_SEALED_DATA((*seal)),
  31.276 +-                     enc, enc_size)) {
  31.277 ++                     enc, &enc_size32)) {
  31.278 +     tpm_free(buf);
  31.279 +     rsa_release_public_key(&pub_key);
  31.280 +     return -1;
  31.281 +@@ -85,7 +86,8 @@ int encrypt_sealed_data(TPM_KEY_DATA *ke
  31.282 + int decrypt_sealed_data(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size,
  31.283 +                         TPM_SEALED_DATA *seal, BYTE **buf) 
  31.284 + {
  31.285 +-  UINT32 len;
  31.286 ++  size_t len;
  31.287 ++  UINT32 len32;
  31.288 +   BYTE *ptr;
  31.289 +   int scheme;
  31.290 +   switch (key->encScheme) {
  31.291 +@@ -96,8 +98,12 @@ int decrypt_sealed_data(TPM_KEY_DATA *ke
  31.292 +   len = enc_size;
  31.293 +   *buf = ptr = tpm_malloc(len);
  31.294 +   if (*buf == NULL
  31.295 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  31.296 +-      || tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len, seal)) {
  31.297 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ){
  31.298 ++    tpm_free(*buf);
  31.299 ++    return -1;
  31.300 ++  }
  31.301 ++  len32 = len;
  31.302 ++  if (tpm_unmarshal_TPM_SEALED_DATA(&ptr, &len32, seal)) {
  31.303 +     tpm_free(*buf);
  31.304 +     return -1;
  31.305 +   }
  31.306 +@@ -237,11 +243,12 @@ TPM_RESULT TPM_Unseal(TPM_KEY_HANDLE par
  31.307 + 
  31.308 + TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE keyHandle, UINT32 inDataSize,
  31.309 +                       BYTE *inData, TPM_AUTH *auth1, 
  31.310 +-                      UINT32 *outDataSize, BYTE **outData)
  31.311 ++                      UINT32 *outDataSize32, BYTE **outData)
  31.312 + {
  31.313 +   TPM_RESULT res;
  31.314 +   TPM_KEY_DATA *key;
  31.315 +   int scheme;
  31.316 ++  size_t outDataSize;
  31.317 +   info("TPM_UnBind()");
  31.318 +   /* get key */
  31.319 +   key = tpm_get_key(keyHandle);
  31.320 +@@ -258,8 +265,8 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  31.321 +   /* the size of the input data muss be greater than zero */
  31.322 +   if (inDataSize == 0) return TPM_BAD_PARAMETER;
  31.323 +   /* decrypt data */
  31.324 +-  *outDataSize = inDataSize;
  31.325 +-  *outData = tpm_malloc(*outDataSize);
  31.326 ++  outDataSize = inDataSize;
  31.327 ++  *outData = tpm_malloc(outDataSize);
  31.328 +   if (*outData == NULL) return TPM_FAIL;
  31.329 +   switch (key->encScheme) {
  31.330 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  31.331 +@@ -267,20 +274,21 @@ TPM_RESULT TPM_UnBind(TPM_KEY_HANDLE key
  31.332 +     default: tpm_free(*outData); return TPM_DECRYPT_ERROR;
  31.333 +   }
  31.334 +   if (rsa_decrypt(&key->key, scheme, inData, inDataSize, 
  31.335 +-      *outData, outDataSize)) {
  31.336 ++		  *outData, &outDataSize) ) { 
  31.337 +     tpm_free(*outData);
  31.338 +     return TPM_DECRYPT_ERROR;
  31.339 +   }
  31.340 +   /* verify data if it is of type TPM_BOUND_DATA */
  31.341 +   if (key->encScheme == TPM_ES_RSAESOAEP_SHA1_MGF1 
  31.342 +       || key->keyUsage != TPM_KEY_LEGACY) {
  31.343 +-    if (*outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  31.344 ++    if (outDataSize < 5 || memcmp(*outData, "\x01\x01\00\x00\x02", 5) != 0) {
  31.345 +       tpm_free(*outData);
  31.346 +       return TPM_DECRYPT_ERROR;
  31.347 +     }
  31.348 +-    *outDataSize -= 5;
  31.349 +-    memmove(*outData, &(*outData)[5], *outDataSize);   
  31.350 +-  } 
  31.351 ++    outDataSize -= 5;
  31.352 ++    memmove(*outData, &(*outData)[5], outDataSize);   
  31.353 ++  }
  31.354 ++  *outDataSize32 = (UINT32) outDataSize; 
  31.355 +   return TPM_SUCCESS;
  31.356 + }
  31.357 + 
  31.358 +@@ -311,12 +319,13 @@ static int verify_key_digest(TPM_KEY *ke
  31.359 + }
  31.360 + 
  31.361 + int encrypt_private_key(TPM_KEY_DATA *key, TPM_STORE_ASYMKEY *store,
  31.362 +-                        BYTE *enc, UINT32 *enc_size)
  31.363 ++                        BYTE *enc, UINT32 *enc_size32)
  31.364 + {
  31.365 +   UINT32 len;
  31.366 +   BYTE *buf, *ptr;
  31.367 +   rsa_public_key_t pub_key;
  31.368 +   int scheme;
  31.369 ++  size_t enc_size;
  31.370 +   switch (key->encScheme) {
  31.371 +     case TPM_ES_RSAESOAEP_SHA1_MGF1: scheme = RSA_ES_OAEP_SHA1; break;
  31.372 +     case TPM_ES_RSAESPKCSv15: scheme = RSA_ES_PKCSV15; break;
  31.373 +@@ -328,11 +337,12 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  31.374 +   if (buf == NULL
  31.375 +       || tpm_marshal_TPM_STORE_ASYMKEY(&ptr, &len, store)
  31.376 +       || rsa_encrypt(&pub_key, scheme, buf, sizeof_TPM_STORE_ASYMKEY((*store)),
  31.377 +-                     enc, enc_size)) {
  31.378 ++                     enc, &enc_size)) {
  31.379 +     tpm_free(buf);
  31.380 +     rsa_release_public_key(&pub_key);
  31.381 +     return -1;
  31.382 +   }
  31.383 ++  *enc_size32 = (UINT32) enc_size;
  31.384 +   tpm_free(buf);
  31.385 +   rsa_release_public_key(&pub_key);
  31.386 +   return 0;
  31.387 +@@ -341,7 +351,8 @@ int encrypt_private_key(TPM_KEY_DATA *ke
  31.388 + int decrypt_private_key(TPM_KEY_DATA *key, BYTE *enc, UINT32 enc_size, 
  31.389 +                         TPM_STORE_ASYMKEY *store, BYTE **buf) 
  31.390 + {
  31.391 +-  UINT32 len;
  31.392 ++  UINT32 len32;
  31.393 ++  size_t len;
  31.394 +   BYTE *ptr;
  31.395 +   int scheme;
  31.396 +   switch (key->encScheme) {
  31.397 +@@ -352,11 +363,16 @@ int decrypt_private_key(TPM_KEY_DATA *ke
  31.398 +   len = enc_size;
  31.399 +   *buf = ptr = tpm_malloc(len);
  31.400 +   if (*buf == NULL
  31.401 +-      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len)
  31.402 +-      || tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len, store)) {
  31.403 ++      || rsa_decrypt(&key->key, scheme, enc, enc_size, *buf, &len) ) {
  31.404 ++    tpm_free(*buf);
  31.405 ++    return -1;
  31.406 ++  }
  31.407 ++  len32 = (UINT32) len;
  31.408 ++  if (tpm_unmarshal_TPM_STORE_ASYMKEY(&ptr, &len32, store)) {  
  31.409 +     tpm_free(*buf);
  31.410 +     return -1;
  31.411 +   }
  31.412 ++
  31.413 +   return 0;
  31.414 + }
  31.415 + 
  31.416 +@@ -371,7 +387,7 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  31.417 +   TPM_SESSION_DATA *session;
  31.418 +   TPM_STORE_ASYMKEY store;
  31.419 +   rsa_private_key_t rsa;
  31.420 +-  UINT32 key_length;
  31.421 ++  size_t key_length;
  31.422 + 
  31.423 +   info("TPM_CreateWrapKey()");
  31.424 +   /* get parent key */
  31.425 +@@ -428,11 +444,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  31.426 +   }
  31.427 +   if (compute_key_digest(wrappedKey, &store.pubDataDigest)) return TPM_FAIL;
  31.428 +   /* generate key and store it */
  31.429 +-  key_length = keyInfo->algorithmParms.parms.rsa.keyLength;
  31.430 +-  if (rsa_generate_key(&rsa, key_length)) return TPM_FAIL;
  31.431 +-  wrappedKey->pubKey.keyLength = key_length >> 3;
  31.432 ++  if (rsa_generate_key(&rsa, keyInfo->algorithmParms.parms.rsa.keyLength)) 
  31.433 ++    return TPM_FAIL;
  31.434 ++  wrappedKey->pubKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 3;
  31.435 +   wrappedKey->pubKey.key = tpm_malloc(wrappedKey->pubKey.keyLength);
  31.436 +-  store.privKey.keyLength = key_length >> 4;
  31.437 ++  store.privKey.keyLength = keyInfo->algorithmParms.parms.rsa.keyLength >> 4;
  31.438 +   store.privKey.key = tpm_malloc(store.privKey.keyLength);
  31.439 +   wrappedKey->encDataSize = parent->key.size >> 3;
  31.440 +   wrappedKey->encData = tpm_malloc(wrappedKey->encDataSize);
  31.441 +@@ -444,9 +460,11 @@ TPM_RESULT TPM_CreateWrapKey(TPM_KEY_HAN
  31.442 +     tpm_free(wrappedKey->encData);
  31.443 +     return TPM_FAIL;
  31.444 +   }
  31.445 +-  rsa_export_modulus(&rsa, wrappedKey->pubKey.key, 
  31.446 +-    &wrappedKey->pubKey.keyLength);
  31.447 +-  rsa_export_prime1(&rsa, store.privKey.key, &store.privKey.keyLength);
  31.448 ++  rsa_export_modulus(&rsa, wrappedKey->pubKey.key,
  31.449 ++		     &key_length);
  31.450 ++  wrappedKey->pubKey.keyLength = (UINT32) key_length;
  31.451 ++  rsa_export_prime1(&rsa, store.privKey.key, &key_length);
  31.452 ++  store.privKey.keyLength = (UINT32) key_length;
  31.453 +   rsa_release_private_key(&rsa);
  31.454 +   /* encrypt private key data */
  31.455 +   if (encrypt_private_key(parent, &store, wrappedKey->encData, 
  31.456 +@@ -560,6 +578,7 @@ TPM_RESULT TPM_LoadKey(TPM_KEY_HANDLE pa
  31.457 + 
  31.458 + int tpm_setup_key_parms(TPM_KEY_DATA *key, TPM_KEY_PARMS *parms)
  31.459 + {
  31.460 ++  size_t key_length;
  31.461 +   parms->algorithmID = TPM_ALG_RSA;
  31.462 +   parms->encScheme = key->encScheme;
  31.463 +   parms->sigScheme = key->sigScheme;
  31.464 +@@ -569,7 +588,8 @@ int tpm_setup_key_parms(TPM_KEY_DATA *ke
  31.465 +   parms->parms.rsa.exponent = tpm_malloc(parms->parms.rsa.exponentSize);
  31.466 +   if (parms->parms.rsa.exponent == NULL) return -1;
  31.467 +   rsa_export_exponent(&key->key, parms->parms.rsa.exponent,
  31.468 +-    &parms->parms.rsa.exponentSize);
  31.469 ++                      &key_length);  
  31.470 ++  parms->parms.rsa.exponentSize = (UINT32) key_length;
  31.471 +   parms->parmSize = 12 + parms->parms.rsa.exponentSize;  
  31.472 +   return 0;
  31.473 + }
  31.474 +@@ -580,6 +600,7 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  31.475 +   TPM_RESULT res;
  31.476 +   TPM_KEY_DATA *key;
  31.477 +   TPM_DIGEST digest;
  31.478 ++  size_t key_length;
  31.479 +   info("TPM_GetPubKey()");
  31.480 +   /* get key */
  31.481 +   if (keyHandle == TPM_KH_SRK) return TPM_BAD_PARAMETER;
  31.482 +@@ -607,8 +628,8 @@ TPM_RESULT TPM_GetPubKey(TPM_KEY_HANDLE 
  31.483 +   pubKey->pubKey.keyLength = key->key.size >> 3;
  31.484 +   pubKey->pubKey.key = tpm_malloc(pubKey->pubKey.keyLength);
  31.485 +   if (pubKey->pubKey.key == NULL) return TPM_FAIL;
  31.486 +-  rsa_export_modulus(&key->key, pubKey->pubKey.key, 
  31.487 +-    &pubKey->pubKey.keyLength);
  31.488 ++  rsa_export_modulus(&key->key, pubKey->pubKey.key, &key_length); 
  31.489 ++  pubKey->pubKey.keyLength = (UINT32) key_length;
  31.490 +   if (tpm_setup_key_parms(key, &pubKey->algorithmParms) != 0) {
  31.491 +     tpm_free(pubKey->pubKey.key);
  31.492 +     return TPM_FAIL;  
  31.493 +diff -uprN tpm_emulator-0.2/tpm_version.h tpm_emulator-0.2-x86_64/tpm_version.h
  31.494 +--- tpm_emulator-0.2/tpm_version.h	2005-08-15 00:58:57.000000000 -0700
  31.495 ++++ tpm_emulator-0.2-x86_64/tpm_version.h	1969-12-31 16:00:00.000000000 -0800
  31.496 +@@ -1,6 +0,0 @@
  31.497 +-#ifndef _TPM_VERSION_H_
  31.498 +-#define _TPM_VERSION_H_
  31.499 +-#define VERSION_MAJOR 0
  31.500 +-#define VERSION_MINOR 2
  31.501 +-#define VERSION_BUILD 1123950310
  31.502 +-#endif /* _TPM_VERSION_H_ */
    32.1 --- a/xen/arch/x86/vmx.c	Wed Sep 21 15:23:26 2005 +0100
    32.2 +++ b/xen/arch/x86/vmx.c	Wed Sep 21 15:25:58 2005 +0100
    32.3 @@ -377,12 +377,13 @@ static void inline __update_guest_eip(un
    32.4  
    32.5  static int vmx_do_page_fault(unsigned long va, struct cpu_user_regs *regs) 
    32.6  {
    32.7 -    unsigned long eip;
    32.8      unsigned long gpa; /* FIXME: PAE */
    32.9      int result;
   32.10  
   32.11 -#if VMX_DEBUG
   32.12 +#if 0 /* keep for debugging */
   32.13      {
   32.14 +        unsigned long eip;
   32.15 +
   32.16          __vmread(GUEST_RIP, &eip);
   32.17          VMX_DBG_LOG(DBG_LEVEL_VMMU, 
   32.18                      "vmx_do_page_fault = 0x%lx, eip = %lx, error_code = %lx",
   32.19 @@ -429,9 +430,9 @@ static void vmx_do_no_device_fault(void)
   32.20          
   32.21      clts();
   32.22      setup_fpu(current);
   32.23 -    __vmread(CR0_READ_SHADOW, &cr0);
   32.24 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   32.25      if (!(cr0 & X86_CR0_TS)) {
   32.26 -        __vmread(GUEST_CR0, &cr0);
   32.27 +        __vmread_vcpu(GUEST_CR0, &cr0);
   32.28          cr0 &= ~X86_CR0_TS;
   32.29          __vmwrite(GUEST_CR0, cr0);
   32.30      }
   32.31 @@ -1129,9 +1130,7 @@ static int vmx_set_cr0(unsigned long val
   32.32                  __vmwrite(VM_ENTRY_CONTROLS, vm_entry_value);
   32.33              }
   32.34          }
   32.35 -        __vmread(GUEST_RIP, &eip);
   32.36 -        VMX_DBG_LOG(DBG_LEVEL_1,
   32.37 -                    "Disabling CR0.PE at %%eip 0x%lx\n", eip);
   32.38 +
   32.39          if (vmx_assist(d, VMX_ASSIST_INVOKE)) {
   32.40              set_bit(VMX_CPU_STATE_ASSIST_ENABLED, &d->arch.arch_vmx.cpu_state);
   32.41              __vmread(GUEST_RIP, &eip);
   32.42 @@ -1370,17 +1369,17 @@ static int vmx_cr_access(unsigned long e
   32.43          clts();
   32.44          setup_fpu(current);
   32.45  
   32.46 -        __vmread(GUEST_CR0, &value);
   32.47 +        __vmread_vcpu(GUEST_CR0, &value);
   32.48          value &= ~X86_CR0_TS; /* clear TS */
   32.49          __vmwrite(GUEST_CR0, value);
   32.50  
   32.51 -        __vmread(CR0_READ_SHADOW, &value);
   32.52 +        __vmread_vcpu(CR0_READ_SHADOW, &value);
   32.53          value &= ~X86_CR0_TS; /* clear TS */
   32.54          __vmwrite(CR0_READ_SHADOW, value);
   32.55          break;
   32.56      case TYPE_LMSW:
   32.57          TRACE_VMEXIT(1,TYPE_LMSW);
   32.58 -        __vmread(CR0_READ_SHADOW, &value);
   32.59 +        __vmread_vcpu(CR0_READ_SHADOW, &value);
   32.60          value = (value & ~0xF) |
   32.61              (((exit_qualification & LMSW_SOURCE_DATA) >> 16) & 0xF);
   32.62          return vmx_set_cr0(value);
   32.63 @@ -1456,16 +1455,12 @@ static inline void vmx_do_msr_write(stru
   32.64                  (unsigned long)regs->edx);
   32.65  }
   32.66  
   32.67 +volatile unsigned long do_hlt_count;
   32.68  /*
   32.69   * Need to use this exit to reschedule
   32.70   */
   32.71 -static inline void vmx_vmexit_do_hlt(void)
   32.72 +void vmx_vmexit_do_hlt(void)
   32.73  {
   32.74 -#if VMX_DEBUG
   32.75 -    unsigned long eip;
   32.76 -    __vmread(GUEST_RIP, &eip);
   32.77 -#endif
   32.78 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_vmexit_do_hlt:eip=%lx", eip);
   32.79      raise_softirq(SCHEDULE_SOFTIRQ);
   32.80  }
   32.81  
   32.82 @@ -1516,13 +1511,9 @@ static inline void vmx_vmexit_do_extint(
   32.83      }
   32.84  }
   32.85  
   32.86 +volatile unsigned long do_mwait_count;
   32.87  static inline void vmx_vmexit_do_mwait(void)
   32.88  {
   32.89 -#if VMX_DEBUG
   32.90 -    unsigned long eip;
   32.91 -    __vmread(GUEST_RIP, &eip);
   32.92 -#endif
   32.93 -    VMX_DBG_LOG(DBG_LEVEL_1, "vmx_vmexit_do_mwait:eip=%lx", eip);
   32.94      raise_softirq(SCHEDULE_SOFTIRQ);
   32.95  }
   32.96  
   32.97 @@ -1631,9 +1622,13 @@ asmlinkage void vmx_vmexit_handler(struc
   32.98          return;
   32.99      }
  32.100  
  32.101 -    __vmread(GUEST_RIP, &eip);
  32.102 -    TRACE_3D(TRC_VMX_VMEXIT, v->domain->domain_id, eip, exit_reason);
  32.103 -    TRACE_VMEXIT(0,exit_reason);
  32.104 +#ifdef TRACE_BUFFER
  32.105 +    {
  32.106 +        __vmread(GUEST_RIP, &eip);
  32.107 +        TRACE_3D(TRC_VMX_VMEXIT, v->domain->domain_id, eip, exit_reason);
  32.108 +        TRACE_VMEXIT(0,exit_reason);
  32.109 +    }
  32.110 +#endif
  32.111  
  32.112      switch (exit_reason) {
  32.113      case EXIT_REASON_EXCEPTION_NMI:
    33.1 --- a/xen/arch/x86/vmx_io.c	Wed Sep 21 15:23:26 2005 +0100
    33.2 +++ b/xen/arch/x86/vmx_io.c	Wed Sep 21 15:25:58 2005 +0100
    33.3 @@ -891,7 +891,7 @@ asmlinkage void vmx_intr_assist(void)
    33.4      struct vcpu *v = current;
    33.5  
    33.6      highest_vector = find_highest_pending_irq(v, &intr_type);
    33.7 -    __vmread(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
    33.8 +    __vmread_vcpu(CPU_BASED_VM_EXEC_CONTROL, &cpu_exec_control);
    33.9  
   33.10      if (highest_vector == -1) {
   33.11          disable_irq_window(cpu_exec_control);
   33.12 @@ -948,14 +948,6 @@ asmlinkage void vmx_intr_assist(void)
   33.13  void vmx_do_resume(struct vcpu *d) 
   33.14  {
   33.15      vmx_stts();
   33.16 -    if ( vmx_paging_enabled(d) )
   33.17 -        __vmwrite(GUEST_CR3, pagetable_get_paddr(d->arch.shadow_table));
   33.18 -    else
   33.19 -        // paging is not enabled in the guest
   33.20 -        __vmwrite(GUEST_CR3, pagetable_get_paddr(d->domain->arch.phys_table));
   33.21 -
   33.22 -    __vmwrite(HOST_CR3, pagetable_get_paddr(d->arch.monitor_table));
   33.23 -    __vmwrite(HOST_RSP, (unsigned long)get_stack_bottom());
   33.24  
   33.25      if (event_pending(d)) {
   33.26          vmx_check_events(d);
    34.1 --- a/xen/arch/x86/vmx_vmcs.c	Wed Sep 21 15:23:26 2005 +0100
    34.2 +++ b/xen/arch/x86/vmx_vmcs.c	Wed Sep 21 15:25:58 2005 +0100
    34.3 @@ -68,9 +68,6 @@ static inline int construct_vmcs_control
    34.4      error |= __vmwrite(PIN_BASED_VM_EXEC_CONTROL, 
    34.5                         MONITOR_PIN_BASED_EXEC_CONTROLS);
    34.6  
    34.7 -    error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
    34.8 -                       MONITOR_CPU_BASED_EXEC_CONTROLS);
    34.9 -
   34.10      error |= __vmwrite(VM_EXIT_CONTROLS, MONITOR_VM_EXIT_CONTROLS);
   34.11  
   34.12      error |= __vmwrite(VM_ENTRY_CONTROLS, MONITOR_VM_ENTRY_CONTROLS);
   34.13 @@ -117,12 +114,6 @@ struct host_execution_env {
   34.14      unsigned long fs_base; 
   34.15      unsigned long gs_base; 
   34.16  #endif 
   34.17 -
   34.18 -    /* control registers */
   34.19 -    unsigned long cr3;
   34.20 -    unsigned long cr0;
   34.21 -    unsigned long cr4;
   34.22 -    unsigned long dr7;
   34.23  };
   34.24  
   34.25  #define round_pgdown(_p) ((_p)&PAGE_MASK) /* coped from domain.c */
   34.26 @@ -217,9 +208,33 @@ void vmx_do_launch(struct vcpu *v)
   34.27  /* Update CR3, GDT, LDT, TR */
   34.28      unsigned int  error = 0;
   34.29      unsigned long pfn = 0;
   34.30 +    unsigned long cr0, cr4;
   34.31      struct pfn_info *page;
   34.32      struct cpu_user_regs *regs = guest_cpu_user_regs();
   34.33  
   34.34 +    __asm__ __volatile__ ("mov %%cr0,%0" : "=r" (cr0) : );
   34.35 +
   34.36 +    error |= __vmwrite(GUEST_CR0, cr0);
   34.37 +    cr0 &= ~X86_CR0_PG;
   34.38 +    error |= __vmwrite(CR0_READ_SHADOW, cr0);
   34.39 +    error |= __vmwrite(CPU_BASED_VM_EXEC_CONTROL, 
   34.40 +                       MONITOR_CPU_BASED_EXEC_CONTROLS);
   34.41 +
   34.42 +    __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (cr4) : );
   34.43 +
   34.44 +#ifdef __x86_64__
   34.45 +    error |= __vmwrite(GUEST_CR4, cr4 & ~X86_CR4_PSE);
   34.46 +#else
   34.47 +    error |= __vmwrite(GUEST_CR4, cr4);
   34.48 +#endif
   34.49 +
   34.50 +#ifdef __x86_64__
   34.51 +    cr4 &= ~(X86_CR4_PGE | X86_CR4_VMXE | X86_CR4_PAE);
   34.52 +#else
   34.53 +    cr4 &= ~(X86_CR4_PGE | X86_CR4_VMXE);
   34.54 +#endif
   34.55 +    error |= __vmwrite(CR4_READ_SHADOW, cr4);
   34.56 +
   34.57      vmx_stts();
   34.58  
   34.59      page = (struct pfn_info *) alloc_domheap_page(NULL);
   34.60 @@ -254,7 +269,7 @@ construct_init_vmcs_guest(struct cpu_use
   34.61      int error = 0;
   34.62      union vmcs_arbytes arbytes;
   34.63      unsigned long dr7;
   34.64 -    unsigned long eflags, shadow_cr;
   34.65 +    unsigned long eflags;
   34.66  
   34.67      /* MSR */
   34.68      error |= __vmwrite(VM_EXIT_MSR_LOAD_ADDR, 0);
   34.69 @@ -326,27 +341,7 @@ construct_init_vmcs_guest(struct cpu_use
   34.70  
   34.71      arbytes.fields.seg_type = 0xb;          /* 32-bit TSS (busy) */
   34.72      error |= __vmwrite(GUEST_TR_AR_BYTES, arbytes.bytes);
   34.73 -
   34.74 -    error |= __vmwrite(GUEST_CR0, host_env->cr0); /* same CR0 */
   34.75 -
   34.76 -    /* Initally PG, PE are not set*/
   34.77 -    shadow_cr = host_env->cr0;
   34.78 -    shadow_cr &= ~X86_CR0_PG;
   34.79 -    error |= __vmwrite(CR0_READ_SHADOW, shadow_cr);
   34.80      /* CR3 is set in vmx_final_setup_guest */
   34.81 -#ifdef __x86_64__
   34.82 -    error |= __vmwrite(GUEST_CR4, host_env->cr4 & ~X86_CR4_PSE);
   34.83 -#else
   34.84 -    error |= __vmwrite(GUEST_CR4, host_env->cr4);
   34.85 -#endif
   34.86 -    shadow_cr = host_env->cr4;
   34.87 -
   34.88 -#ifdef __x86_64__
   34.89 -    shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE | X86_CR4_PAE);
   34.90 -#else
   34.91 -    shadow_cr &= ~(X86_CR4_PGE | X86_CR4_VMXE);
   34.92 -#endif
   34.93 -    error |= __vmwrite(CR4_READ_SHADOW, shadow_cr);
   34.94  
   34.95      error |= __vmwrite(GUEST_ES_BASE, host_env->ds_base);
   34.96      error |= __vmwrite(GUEST_CS_BASE, host_env->cs_base);
   34.97 @@ -403,12 +398,10 @@ static inline int construct_vmcs_host(st
   34.98      host_env->cs_base = 0;
   34.99  
  34.100      __asm__ __volatile__ ("mov %%cr0,%0" : "=r" (crn) : );
  34.101 -    host_env->cr0 = crn;
  34.102      error |= __vmwrite(HOST_CR0, crn); /* same CR0 */
  34.103  
  34.104      /* CR3 is set in vmx_final_setup_hostos */
  34.105      __asm__ __volatile__ ("mov %%cr4,%0" : "=r" (crn) : ); 
  34.106 -    host_env->cr4 = crn;
  34.107      error |= __vmwrite(HOST_CR4, crn);
  34.108  
  34.109      error |= __vmwrite(HOST_RIP, (unsigned long) vmx_asm_vmexit_handler);
    35.1 --- a/xen/include/asm-x86/vmx.h	Wed Sep 21 15:23:26 2005 +0100
    35.2 +++ b/xen/include/asm-x86/vmx.h	Wed Sep 21 15:25:58 2005 +0100
    35.3 @@ -314,6 +314,57 @@ static always_inline int ___vmread (cons
    35.4      return 0;
    35.5  }
    35.6  
    35.7 +
    35.8 +static always_inline void __vmwrite_vcpu(unsigned long field, unsigned long value)
    35.9 +{
   35.10 +    struct vcpu *v = current;
   35.11 +
   35.12 +    switch(field) {
   35.13 +    case CR0_READ_SHADOW:
   35.14 +	v->arch.arch_vmx.cpu_shadow_cr0 = value;
   35.15 +	break;
   35.16 +    case GUEST_CR0:
   35.17 +	v->arch.arch_vmx.cpu_cr0 = value;
   35.18 +	break;
   35.19 +    case CPU_BASED_VM_EXEC_CONTROL:
   35.20 +	v->arch.arch_vmx.cpu_based_exec_control = value;
   35.21 +	break;
   35.22 +    default:
   35.23 +	printk("__vmwrite_cpu: invalid field %lx\n", field);
   35.24 +	break;
   35.25 +    }
   35.26 +}
   35.27 +
   35.28 +static always_inline void __vmread_vcpu(unsigned long field, unsigned long *value)
   35.29 +{
   35.30 +    struct vcpu *v = current;
   35.31 +
   35.32 +    switch(field) {
   35.33 +    case CR0_READ_SHADOW:
   35.34 +	*value = v->arch.arch_vmx.cpu_shadow_cr0;
   35.35 +	break;
   35.36 +    case GUEST_CR0:
   35.37 +	*value = v->arch.arch_vmx.cpu_cr0;
   35.38 +	break;
   35.39 +    case CPU_BASED_VM_EXEC_CONTROL:
   35.40 +	*value = v->arch.arch_vmx.cpu_based_exec_control;
   35.41 +	break;
   35.42 +    default:
   35.43 +	printk("__vmread_cpu: invalid field %lx\n", field);
   35.44 +	break;
   35.45 +    }
   35.46 +
   35.47 +   /* 
   35.48 +    * __vmwrite() can be used for non-current vcpu, and it's possible that
   35.49 +    * the vcpu field is not initialized at that case.
   35.50 +    * 
   35.51 +    */
   35.52 +    if (!*value) {
   35.53 +	__vmread(field, value);
   35.54 +	__vmwrite_vcpu(field, *value);
   35.55 +    }
   35.56 +}
   35.57 +
   35.58  static inline int __vmwrite (unsigned long field, unsigned long value)
   35.59  {
   35.60      unsigned long eflags;
   35.61 @@ -326,6 +377,15 @@ static inline int __vmwrite (unsigned lo
   35.62      __save_flags(eflags);
   35.63      if (eflags & X86_EFLAGS_ZF || eflags & X86_EFLAGS_CF)
   35.64          return -1;
   35.65 +
   35.66 +    switch(field) {
   35.67 +    case CR0_READ_SHADOW:
   35.68 +    case GUEST_CR0:
   35.69 +    case CPU_BASED_VM_EXEC_CONTROL:
   35.70 +	__vmwrite_vcpu(field, value);
   35.71 +	break;
   35.72 +    }
   35.73 +
   35.74      return 0;
   35.75  }
   35.76  
   35.77 @@ -379,11 +439,12 @@ static inline void vmx_stts(void)
   35.78  {
   35.79      unsigned long cr0;
   35.80  
   35.81 -    __vmread(GUEST_CR0, &cr0);
   35.82 -    if (!(cr0 & X86_CR0_TS))
   35.83 +    __vmread_vcpu(GUEST_CR0, &cr0);
   35.84 +    if (!(cr0 & X86_CR0_TS)) {
   35.85          __vmwrite(GUEST_CR0, cr0 | X86_CR0_TS);
   35.86 +    }
   35.87  
   35.88 -    __vmread(CR0_READ_SHADOW, &cr0);
   35.89 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   35.90      if (!(cr0 & X86_CR0_TS))
   35.91         __vm_set_bit(EXCEPTION_BITMAP, EXCEPTION_BITMAP_NM);
   35.92  }
   35.93 @@ -393,7 +454,7 @@ static inline int vmx_paging_enabled(str
   35.94  {
   35.95      unsigned long cr0;
   35.96  
   35.97 -    __vmread(CR0_READ_SHADOW, &cr0);
   35.98 +    __vmread_vcpu(CR0_READ_SHADOW, &cr0);
   35.99      return (cr0 & X86_CR0_PE) && (cr0 & X86_CR0_PG);
  35.100  }
  35.101  
    36.1 --- a/xen/include/asm-x86/vmx_vmcs.h	Wed Sep 21 15:23:26 2005 +0100
    36.2 +++ b/xen/include/asm-x86/vmx_vmcs.h	Wed Sep 21 15:25:58 2005 +0100
    36.3 @@ -74,9 +74,12 @@ struct msr_state{
    36.4  struct arch_vmx_struct {
    36.5      struct vmcs_struct      *vmcs;  /* VMCS pointer in virtual */
    36.6      unsigned long           flags;  /* VMCS flags */
    36.7 +    unsigned long           cpu_cr0; /* copy of guest CR0 */
    36.8 +    unsigned long           cpu_shadow_cr0; /* copy of guest read shadow CR0 */
    36.9      unsigned long           cpu_cr2; /* save CR2 */
   36.10      unsigned long           cpu_cr3;
   36.11      unsigned long           cpu_state;
   36.12 +    unsigned long           cpu_based_exec_control;
   36.13      struct msr_state        msr_content;
   36.14      void                   *io_bitmap_a, *io_bitmap_b;
   36.15  };
    37.1 --- a/xen/include/public/io/tpmif.h	Wed Sep 21 15:23:26 2005 +0100
    37.2 +++ b/xen/include/public/io/tpmif.h	Wed Sep 21 15:25:58 2005 +0100
    37.3 @@ -20,8 +20,7 @@ typedef struct {
    37.4      unsigned long addr;   /* Machine address of packet.   */
    37.5      int      ref;         /* grant table access reference */
    37.6      u16      id;          /* Echoed in response message.  */
    37.7 -    u16      size:15;     /* Packet size in bytes.        */
    37.8 -    u16      mapped:1;
    37.9 +    u16      size;        /* Packet size in bytes.        */
   37.10  } tpmif_tx_request_t;
   37.11  
   37.12  /*
   37.13 @@ -30,13 +29,16 @@ typedef struct {
   37.14   */
   37.15  typedef u32 TPMIF_RING_IDX;
   37.16  
   37.17 -#define TPMIF_TX_RING_SIZE 16
   37.18 +#define TPMIF_TX_RING_SIZE 10
   37.19  
   37.20  /* This structure must fit in a memory page. */
   37.21 +
   37.22  typedef struct {
   37.23 -    union {
   37.24 -        tpmif_tx_request_t  req;
   37.25 -    } ring[TPMIF_TX_RING_SIZE];
   37.26 +    tpmif_tx_request_t req;
   37.27 +} tpmif_ring_t;
   37.28 +
   37.29 +typedef struct {
   37.30 +    tpmif_ring_t ring[TPMIF_TX_RING_SIZE];
   37.31  } tpmif_tx_interface_t;
   37.32  
   37.33  #endif