ia64/xen-unstable

changeset 10537:23136423a765

[TPM] Fix an occasional problem when doing local migration due to the xenstore's
'instance' variable not being initialized at the time when it's driver
counterpart is accessed. That variable's content was used to initialize the
tpmif structure. Instead, now a pointer to the structure is passed whose
'instance' variable will be initialized before the domain is resumed.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Jun 27 11:29:29 2006 +0100 (2006-06-27)
parents 60d7d64eaff2
children ab63f44d948e
files linux-2.6-xen-sparse/drivers/xen/tpmback/common.h linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Tue Jun 27 11:27:25 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Tue Jun 27 11:29:29 2006 +0100
     1.3 @@ -21,6 +21,8 @@
     1.4  	pr_debug("(file=%s, line=%d) " _f,	\
     1.5  		 __FILE__ , __LINE__ , ## _a )
     1.6  
     1.7 +struct backend_info;
     1.8 +
     1.9  typedef struct tpmif_st {
    1.10  	struct list_head tpmif_list;
    1.11  	/* Unique identifier for this interface. */
    1.12 @@ -43,7 +45,7 @@ typedef struct tpmif_st {
    1.13  	struct list_head list;	/* scheduling list */
    1.14  	atomic_t refcnt;
    1.15  
    1.16 -	long int tpm_instance;
    1.17 +	struct backend_info *bi;
    1.18  	unsigned long mmap_vstart;
    1.19  
    1.20  	grant_handle_t shmem_handle;
    1.21 @@ -54,7 +56,7 @@ typedef struct tpmif_st {
    1.22  } tpmif_t;
    1.23  
    1.24  void tpmif_disconnect_complete(tpmif_t * tpmif);
    1.25 -tpmif_t *tpmif_find(domid_t domid, long int instance);
    1.26 +tpmif_t *tpmif_find(domid_t domid, struct backend_info *bi);
    1.27  void tpmif_interface_init(void);
    1.28  void tpmif_interface_exit(void);
    1.29  void tpmif_schedule_work(tpmif_t * tpmif);
    1.30 @@ -64,8 +66,11 @@ void tpmif_xenbus_exit(void);
    1.31  int tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn);
    1.32  irqreturn_t tpmif_be_int(int irq, void *dev_id, struct pt_regs *regs);
    1.33  
    1.34 +long int tpmback_get_instance(struct backend_info *bi);
    1.35 +
    1.36  int vtpm_release_packets(tpmif_t * tpmif, int send_msgs);
    1.37  
    1.38 +
    1.39  #define tpmif_get(_b) (atomic_inc(&(_b)->refcnt))
    1.40  #define tpmif_put(_b)					\
    1.41  	do {						\
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Tue Jun 27 11:27:25 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Tue Jun 27 11:29:29 2006 +0100
     2.3 @@ -20,7 +20,7 @@ int num_frontends = 0;
     2.4  
     2.5  LIST_HEAD(tpmif_list);
     2.6  
     2.7 -static tpmif_t *alloc_tpmif(domid_t domid, long int instance)
     2.8 +static tpmif_t *alloc_tpmif(domid_t domid, struct backend_info *bi)
     2.9  {
    2.10  	tpmif_t *tpmif;
    2.11  
    2.12 @@ -31,7 +31,7 @@ static tpmif_t *alloc_tpmif(domid_t domi
    2.13  	memset(tpmif, 0, sizeof (*tpmif));
    2.14  	tpmif->domid = domid;
    2.15  	tpmif->status = DISCONNECTED;
    2.16 -	tpmif->tpm_instance = instance;
    2.17 +	tpmif->bi = bi;
    2.18  	snprintf(tpmif->devname, sizeof(tpmif->devname), "tpmif%d", domid);
    2.19  	atomic_set(&tpmif->refcnt, 1);
    2.20  
    2.21 @@ -54,12 +54,12 @@ static void free_tpmif(tpmif_t * tpmif)
    2.22  	kmem_cache_free(tpmif_cachep, tpmif);
    2.23  }
    2.24  
    2.25 -tpmif_t *tpmif_find(domid_t domid, long int instance)
    2.26 +tpmif_t *tpmif_find(domid_t domid, struct backend_info *bi)
    2.27  {
    2.28  	tpmif_t *tpmif;
    2.29  
    2.30  	list_for_each_entry(tpmif, &tpmif_list, tpmif_list) {
    2.31 -		if (tpmif->tpm_instance == instance) {
    2.32 +		if (tpmif->bi == bi) {
    2.33  			if (tpmif->domid == domid) {
    2.34  				tpmif_get(tpmif);
    2.35  				return tpmif;
    2.36 @@ -69,7 +69,7 @@ tpmif_t *tpmif_find(domid_t domid, long 
    2.37  		}
    2.38  	}
    2.39  
    2.40 -	return alloc_tpmif(domid, instance);
    2.41 +	return alloc_tpmif(domid, bi);
    2.42  }
    2.43  
    2.44  static int map_frontend_page(tpmif_t *tpmif, unsigned long shared_page)
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Tue Jun 27 11:27:25 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Tue Jun 27 11:29:29 2006 +0100
     3.3 @@ -161,7 +161,7 @@ static struct packet *packet_alloc(tpmif
     3.4  	if (NULL != pak) {
     3.5  		if (tpmif) {
     3.6  			pak->tpmif = tpmif;
     3.7 -			pak->tpm_instance = tpmif->tpm_instance;
     3.8 +			pak->tpm_instance = tpmback_get_instance(tpmif->bi);
     3.9  			tpmif_get(tpmif);
    3.10  		}
    3.11  		pak->data_len = size;
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Tue Jun 27 11:27:25 2006 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/xenbus.c	Tue Jun 27 11:29:29 2006 +0100
     4.3 @@ -45,6 +45,14 @@ static void backend_changed(struct xenbu
     4.4  static void frontend_changed(struct xenbus_device *dev,
     4.5  			     enum xenbus_state frontend_state);
     4.6  
     4.7 +long int tpmback_get_instance(struct backend_info *bi)
     4.8 +{
     4.9 +	long int res = -1;
    4.10 +	if (bi && bi->is_instance_set)
    4.11 +		res = bi->instance;
    4.12 +	return res;
    4.13 +}
    4.14 +
    4.15  static int tpmback_remove(struct xenbus_device *dev)
    4.16  {
    4.17  	struct backend_info *be = dev->dev.driver_data;
    4.18 @@ -57,6 +65,7 @@ static int tpmback_remove(struct xenbus_
    4.19  		be->backend_watch.node = NULL;
    4.20  	}
    4.21  	if (be->tpmif) {
    4.22 +		be->tpmif->bi = NULL;
    4.23  		vtpm_release_packets(be->tpmif, 0);
    4.24  		tpmif_put(be->tpmif);
    4.25  		be->tpmif = NULL;
    4.26 @@ -150,7 +159,7 @@ static void frontend_changed(struct xenb
    4.27  		break;
    4.28  
    4.29  	case XenbusStateClosing:
    4.30 -		be->tpmif->tpm_instance = -1;
    4.31 +		be->instance = -1;
    4.32  		break;
    4.33  
    4.34  	case XenbusStateClosed:
    4.35 @@ -233,8 +242,7 @@ static int connect_ring(struct backend_i
    4.36  	}
    4.37  
    4.38  	if (!be->tpmif) {
    4.39 -		be->tpmif = tpmif_find(dev->otherend_id,
    4.40 -				       be->instance);
    4.41 +		be->tpmif = tpmif_find(dev->otherend_id, be);
    4.42  		if (IS_ERR(be->tpmif)) {
    4.43  			err = PTR_ERR(be->tpmif);
    4.44  			be->tpmif = NULL;