ia64/xen-unstable

changeset 11764:9d0b22eb1758

[TPM] back: Allocate pages for foreign mappings individually rather than contiguously.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Oct 05 23:16:21 2006 +0100 (2006-10-05)
parents 0fe7624dde63
children 34b2348dfe4b
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
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Thu Oct 05 22:49:26 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/common.h	Thu Oct 05 23:16:21 2006 +0100
     1.3 @@ -46,11 +46,10 @@ typedef struct tpmif_st {
     1.4  	atomic_t refcnt;
     1.5  
     1.6  	struct backend_info *bi;
     1.7 -	unsigned long mmap_vstart;
     1.8  
     1.9  	grant_handle_t shmem_handle;
    1.10  	grant_ref_t shmem_ref;
    1.11 -	struct page *pagerange;
    1.12 +	struct page **mmap_pages;
    1.13  
    1.14  	char devname[20];
    1.15  } tpmif_t;
    1.16 @@ -80,6 +79,9 @@ int vtpm_release_packets(tpmif_t * tpmif
    1.17  
    1.18  extern int num_frontends;
    1.19  
    1.20 -#define MMAP_VADDR(t,_req) ((t)->mmap_vstart + ((_req) * PAGE_SIZE))
    1.21 +static inline unsigned long idx_to_kaddr(tpmif_t *t, unsigned int idx)
    1.22 +{
    1.23 +	return (unsigned long)pfn_to_kaddr(page_to_pfn(t->mmap_pages[idx]));
    1.24 +}
    1.25  
    1.26  #endif /* __TPMIF__BACKEND__COMMON_H__ */
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Oct 05 22:49:26 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Thu Oct 05 23:16:21 2006 +0100
     2.3 @@ -23,10 +23,11 @@ LIST_HEAD(tpmif_list);
     2.4  static tpmif_t *alloc_tpmif(domid_t domid, struct backend_info *bi)
     2.5  {
     2.6  	tpmif_t *tpmif;
     2.7 +	int i;
     2.8  
     2.9  	tpmif = kmem_cache_alloc(tpmif_cachep, GFP_KERNEL);
    2.10  	if (!tpmif)
    2.11 -		return ERR_PTR(-ENOMEM);
    2.12 +		goto out_of_memory;
    2.13  
    2.14  	memset(tpmif, 0, sizeof (*tpmif));
    2.15  	tpmif->domid = domid;
    2.16 @@ -35,22 +36,46 @@ static tpmif_t *alloc_tpmif(domid_t domi
    2.17  	snprintf(tpmif->devname, sizeof(tpmif->devname), "tpmif%d", domid);
    2.18  	atomic_set(&tpmif->refcnt, 1);
    2.19  
    2.20 -	tpmif->pagerange = balloon_alloc_empty_page_range(TPMIF_TX_RING_SIZE);
    2.21 -	BUG_ON(tpmif->pagerange == NULL);
    2.22 -	tpmif->mmap_vstart = (unsigned long)pfn_to_kaddr(
    2.23 -	                                    page_to_pfn(tpmif->pagerange));
    2.24 +	tpmif->mmap_pages = kmalloc(sizeof(tpmif->mmap_pages[0])
    2.25 +				    * TPMIF_TX_RING_SIZE, GFP_KERNEL);
    2.26 +	if (tpmif->mmap_pages == NULL)
    2.27 +		goto out_of_memory;
    2.28 +
    2.29 +	for (i = 0; i < TPMIF_TX_RING_SIZE; i++) {
    2.30 +		tpmif->mmap_pages[i] = balloon_alloc_empty_page();
    2.31 +		if (tpmif->mmap_pages[i] == NULL) {
    2.32 +			while (--i >= 0)
    2.33 +				balloon_free_empty_page(tpmif->mmap_pages[i]);
    2.34 +			goto out_of_memory;
    2.35 +		}
    2.36 +	}
    2.37  
    2.38  	list_add(&tpmif->tpmif_list, &tpmif_list);
    2.39  	num_frontends++;
    2.40  
    2.41  	return tpmif;
    2.42 +
    2.43 + out_of_memory:
    2.44 +	if (tpmif != NULL) {
    2.45 +		kfree(tpmif->mmap_pages);
    2.46 +		kmem_cache_free(tpmif_cachep, tpmif);
    2.47 +	}
    2.48 +	printk("%s: out of memory\n", __FUNCTION__);
    2.49 +	return ERR_PTR(-ENOMEM);
    2.50  }
    2.51  
    2.52  static void free_tpmif(tpmif_t * tpmif)
    2.53  {
    2.54 +	int i;
    2.55 +
    2.56  	num_frontends--;
    2.57 +
    2.58  	list_del(&tpmif->tpmif_list);
    2.59 -	balloon_dealloc_empty_page_range(tpmif->pagerange, TPMIF_TX_RING_SIZE);
    2.60 +
    2.61 +	for (i = 0; i < TPMIF_TX_RING_SIZE; i++)
    2.62 +		balloon_free_empty_page(tpmif->mmap_pages[i]);
    2.63 +	kfree(tpmif->mmap_pages);
    2.64 +
    2.65  	kmem_cache_free(tpmif_cachep, tpmif);
    2.66  }
    2.67  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Thu Oct 05 22:49:26 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c	Thu Oct 05 23:16:21 2006 +0100
     3.3 @@ -253,7 +253,7 @@ int _packet_write(struct packet *pak,
     3.4  			return 0;
     3.5  		}
     3.6  
     3.7 -		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
     3.8 +		gnttab_set_map_op(&map_op, idx_to_kaddr(tpmif, i),
     3.9  				  GNTMAP_host_map, tx->ref, tpmif->domid);
    3.10  
    3.11  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
    3.12 @@ -270,7 +270,7 @@ int _packet_write(struct packet *pak,
    3.13  
    3.14  		tocopy = min_t(size_t, size - offset, PAGE_SIZE);
    3.15  
    3.16 -		if (copy_from_buffer((void *)(MMAP_VADDR(tpmif, i) |
    3.17 +		if (copy_from_buffer((void *)(idx_to_kaddr(tpmif, i) |
    3.18  					      (tx->addr & ~PAGE_MASK)),
    3.19  				     &data[offset], tocopy, isuserbuffer)) {
    3.20  			tpmif_put(tpmif);
    3.21 @@ -278,7 +278,7 @@ int _packet_write(struct packet *pak,
    3.22  		}
    3.23  		tx->size = tocopy;
    3.24  
    3.25 -		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
    3.26 +		gnttab_set_unmap_op(&unmap_op, idx_to_kaddr(tpmif, i),
    3.27  				    GNTMAP_host_map, handle);
    3.28  
    3.29  		if (unlikely
    3.30 @@ -391,7 +391,7 @@ static int packet_read_shmem(struct pack
    3.31  
    3.32  		tx = &tpmif->tx->ring[i].req;
    3.33  
    3.34 -		gnttab_set_map_op(&map_op, MMAP_VADDR(tpmif, i),
    3.35 +		gnttab_set_map_op(&map_op, idx_to_kaddr(tpmif, i),
    3.36  				  GNTMAP_host_map, tx->ref, tpmif->domid);
    3.37  
    3.38  		if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref,
    3.39 @@ -414,10 +414,10 @@ static int packet_read_shmem(struct pack
    3.40  		}
    3.41  
    3.42  		DPRINTK("Copying from mapped memory at %08lx\n",
    3.43 -			(unsigned long)(MMAP_VADDR(tpmif, i) |
    3.44 +			(unsigned long)(idx_to_kaddr(tpmif, i) |
    3.45  					(tx->addr & ~PAGE_MASK)));
    3.46  
    3.47 -		src = (void *)(MMAP_VADDR(tpmif, i) |
    3.48 +		src = (void *)(idx_to_kaddr(tpmif, i) |
    3.49  			       ((tx->addr & ~PAGE_MASK) + pg_offset));
    3.50  		if (copy_to_buffer(&buffer[offset],
    3.51  				   src, to_copy, isuserbuffer)) {
    3.52 @@ -428,7 +428,7 @@ static int packet_read_shmem(struct pack
    3.53  			tpmif->domid, buffer[offset], buffer[offset + 1],
    3.54  			buffer[offset + 2], buffer[offset + 3]);
    3.55  
    3.56 -		gnttab_set_unmap_op(&unmap_op, MMAP_VADDR(tpmif, i),
    3.57 +		gnttab_set_unmap_op(&unmap_op, idx_to_kaddr(tpmif, i),
    3.58  				    GNTMAP_host_map, handle);
    3.59  
    3.60  		if (unlikely