ia64/xen-unstable

changeset 7008:f71bb61e0500

Fix mapping of shared ring pages into backend drivers.
This should fix observed problems when creating a domain,
causing Xen to print "Could not find PTE entry for
address ...".

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed Sep 21 16:36:46 2005 +0000 (2005-09-21)
parents 55fc0ecc19c3
children 76f4c7ea7602
files linux-2.6-xen-sparse/drivers/xen/Makefile linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blktap/interface.c linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c linux-2.6-xen-sparse/drivers/xen/usbback/interface.c linux-2.6-xen-sparse/drivers/xen/util.c linux-2.6-xen-sparse/include/asm-xen/driver_util.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/Makefile	Wed Sep 21 15:25:58 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/Makefile	Wed Sep 21 16:36:46 2005 +0000
     1.3 @@ -1,4 +1,5 @@
     1.4  
     1.5 +obj-y	+= util.o
     1.6  
     1.7  obj-y	+= console/
     1.8  obj-y	+= evtchn/
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c	Wed Sep 21 16:36:46 2005 +0000
     2.3 @@ -8,6 +8,7 @@
     2.4  
     2.5  #include "common.h"
     2.6  #include <asm-xen/evtchn.h>
     2.7 +#include <asm-xen/driver_util.h>
     2.8  
     2.9  static kmem_cache_t *blkif_cachep;
    2.10  
    2.11 @@ -69,12 +70,12 @@ int blkif_map(blkif_t *blkif, unsigned l
    2.12  
    2.13      BUG_ON(blkif->remote_evtchn);
    2.14  
    2.15 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
    2.16 +    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
    2.17  	return -ENOMEM;
    2.18  
    2.19      err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page);
    2.20      if (err) {
    2.21 -        vfree(vma->addr);
    2.22 +        vunmap(vma->addr);
    2.23  	return err;
    2.24      }
    2.25  
    2.26 @@ -85,7 +86,7 @@ int blkif_map(blkif_t *blkif, unsigned l
    2.27      err = HYPERVISOR_event_channel_op(&op);
    2.28      if (err) {
    2.29  	unmap_frontend_page(blkif);
    2.30 -	vfree(vma->addr);
    2.31 +	vunmap(vma->addr);
    2.32  	return err;
    2.33      }
    2.34  
    2.35 @@ -123,7 +124,7 @@ static void free_blkif(void *arg)
    2.36  
    2.37      if (blkif->blk_ring.sring) {
    2.38  	unmap_frontend_page(blkif);
    2.39 -	vfree(blkif->blk_ring.sring);
    2.40 +	vunmap(blkif->blk_ring.sring);
    2.41  	blkif->blk_ring.sring = NULL;
    2.42      }
    2.43  
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Wed Sep 21 15:25:58 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/interface.c	Wed Sep 21 16:36:46 2005 +0000
     3.3 @@ -8,6 +8,7 @@
     3.4  
     3.5  #include "common.h"
     3.6  #include <asm-xen/evtchn.h>
     3.7 +#include <asm-xen/driver_util.h>
     3.8  
     3.9  static kmem_cache_t *blkif_cachep;
    3.10  
    3.11 @@ -69,12 +70,12 @@ int blkif_map(blkif_t *blkif, unsigned l
    3.12  
    3.13      BUG_ON(blkif->remote_evtchn);
    3.14  
    3.15 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
    3.16 +    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
    3.17  	return -ENOMEM;
    3.18  
    3.19      err = map_frontend_page(blkif, (unsigned long)vma->addr, shared_page);
    3.20      if (err) {
    3.21 -        vfree(vma->addr);
    3.22 +        vunmap(vma->addr);
    3.23  	return err;
    3.24      }
    3.25  
    3.26 @@ -85,7 +86,7 @@ int blkif_map(blkif_t *blkif, unsigned l
    3.27      err = HYPERVISOR_event_channel_op(&op);
    3.28      if (err) {
    3.29  	unmap_frontend_page(blkif);
    3.30 -	vfree(vma->addr);
    3.31 +	vunmap(vma->addr);
    3.32  	return err;
    3.33      }
    3.34  
    3.35 @@ -121,7 +122,7 @@ static void free_blkif(void *arg)
    3.36  
    3.37      if (blkif->blk_ring.sring) {
    3.38  	unmap_frontend_page(blkif);
    3.39 -	vfree(blkif->blk_ring.sring);
    3.40 +	vunmap(blkif->blk_ring.sring);
    3.41  	blkif->blk_ring.sring = NULL;
    3.42      }
    3.43  
     4.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Wed Sep 21 16:36:46 2005 +0000
     4.3 @@ -8,6 +8,7 @@
     4.4  
     4.5  #include "common.h"
     4.6  #include <linux/rtnetlink.h>
     4.7 +#include <asm-xen/driver_util.h>
     4.8  
     4.9  static void __netif_up(netif_t *netif)
    4.10  {
    4.11 @@ -198,14 +199,14 @@ int netif_map(netif_t *netif, unsigned l
    4.12  	evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain };
    4.13  	int err;
    4.14  
    4.15 -	vma = get_vm_area(2*PAGE_SIZE, VM_IOREMAP);
    4.16 +	vma = prepare_vm_area(2*PAGE_SIZE);
    4.17  	if (vma == NULL)
    4.18  		return -ENOMEM;
    4.19  
    4.20  	err = map_frontend_pages(
    4.21  		netif, (unsigned long)vma->addr, tx_ring_ref, rx_ring_ref);
    4.22  	if (err) {
    4.23 -		vfree(vma->addr);
    4.24 +		vunmap(vma->addr);
    4.25  		return err;
    4.26  	}
    4.27  
    4.28 @@ -216,7 +217,7 @@ int netif_map(netif_t *netif, unsigned l
    4.29  	err = HYPERVISOR_event_channel_op(&op);
    4.30  	if (err) {
    4.31  		unmap_frontend_pages(netif);
    4.32 -		vfree(vma->addr);
    4.33 +		vunmap(vma->addr);
    4.34  		return err;
    4.35  	}
    4.36  
    4.37 @@ -261,7 +262,7 @@ static void free_netif_callback(void *ar
    4.38  
    4.39  	if (netif->tx) {
    4.40  		unmap_frontend_pages(netif);
    4.41 -		vfree(netif->tx); /* Frees netif->rx as well. */
    4.42 +		vunmap(netif->tx); /* Frees netif->rx as well. */
    4.43  	}
    4.44  
    4.45  	free_netdev(netif->dev);
     5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c	Wed Sep 21 16:36:46 2005 +0000
     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 @@ -13,6 +13,7 @@
    5.10  
    5.11  #include "common.h"
    5.12  #include <asm-xen/balloon.h>
    5.13 +#include <asm-xen/driver_util.h>
    5.14  
    5.15  #define VMALLOC_VMADDR(x) ((unsigned long)(x))
    5.16  
    5.17 @@ -122,12 +123,12 @@ tpmif_map(tpmif_t * tpmif, unsigned long
    5.18  
    5.19  	BUG_ON(tpmif->remote_evtchn);
    5.20  
    5.21 -	if ((vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL)
    5.22 +	if ((vma = prepare_vm_area(PAGE_SIZE)) == NULL)
    5.23  		return -ENOMEM;
    5.24  
    5.25  	err = map_frontend_page(tpmif, VMALLOC_VMADDR(vma->addr), shared_page);
    5.26  	if (err) {
    5.27 -		vfree(vma->addr);
    5.28 +		vunmap(vma->addr);
    5.29  		return err;
    5.30  	}
    5.31  
    5.32 @@ -138,7 +139,7 @@ tpmif_map(tpmif_t * tpmif, unsigned long
    5.33  	err = HYPERVISOR_event_channel_op(&op);
    5.34  	if (err) {
    5.35  		unmap_frontend_page(tpmif);
    5.36 -		vfree(vma->addr);
    5.37 +		vunmap(vma->addr);
    5.38  		return err;
    5.39  	}
    5.40  
    5.41 @@ -174,7 +175,7 @@ static void
    5.42  
    5.43  	if (tpmif->tx) {
    5.44  		unmap_frontend_page(tpmif);
    5.45 -		vfree(tpmif->tx);
    5.46 +		vunmap(tpmif->tx);
    5.47  	}
    5.48  
    5.49  	free_tpmif(tpmif);
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/usbback/interface.c	Wed Sep 21 15:25:58 2005 +0100
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/usbback/interface.c	Wed Sep 21 16:36:46 2005 +0000
     6.3 @@ -7,6 +7,7 @@
     6.4   */
     6.5  
     6.6  #include "common.h"
     6.7 +#include <asm-xen/driver_util.h>
     6.8  
     6.9  #define USBIF_HASHSZ 1024
    6.10  #define USBIF_HASH(_d) (((int)(_d))&(USBIF_HASHSZ-1))
    6.11 @@ -33,7 +34,7 @@ static void __usbif_disconnect_complete(
    6.12       * may be outstanding requests at the device whose asynchronous responses
    6.13       * must still be notified to the remote driver.
    6.14       */
    6.15 -    vfree(usbif->usb_ring.sring);
    6.16 +    vunmap(usbif->usb_ring.sring);
    6.17  
    6.18      /* Construct the deferred response message. */
    6.19      cmsg.type         = CMSG_USBIF_BE;
    6.20 @@ -154,7 +155,7 @@ void usbif_connect(usbif_be_connect_t *c
    6.21          return;
    6.22      }
    6.23  
    6.24 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
    6.25 +    if ( (vma = prepare_vm_area(PAGE_SIZE)) == NULL )
    6.26      {
    6.27          connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
    6.28          return;
    6.29 @@ -172,14 +173,14 @@ void usbif_connect(usbif_be_connect_t *c
    6.30              connect->status = USBIF_BE_STATUS_MAPPING_ERROR;
    6.31          else
    6.32              connect->status = USBIF_BE_STATUS_ERROR;
    6.33 -        vfree(vma->addr);
    6.34 +        vunmap(vma->addr);
    6.35          return;
    6.36      }
    6.37  
    6.38      if ( up->status != DISCONNECTED )
    6.39      {
    6.40          connect->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
    6.41 -        vfree(vma->addr);
    6.42 +        vunmap(vma->addr);
    6.43          return;
    6.44      }
    6.45  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/util.c	Wed Sep 21 16:36:46 2005 +0000
     7.3 @@ -0,0 +1,46 @@
     7.4 +#include <linux/config.h>
     7.5 +#include <linux/mm.h>
     7.6 +#include <linux/slab.h>
     7.7 +#include <linux/vmalloc.h>
     7.8 +#include <asm/uaccess.h>
     7.9 +
    7.10 +static int touch_fn(
    7.11 +	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
    7.12 +{
    7.13 +	char c;
    7.14 +	BUG_ON(!__get_user(c, (char *)addr));
    7.15 +	return 0;
    7.16 +}
    7.17 +
    7.18 +struct vm_struct *prepare_vm_area(unsigned long size)
    7.19 +{
    7.20 +	struct vm_struct *area;
    7.21 +
    7.22 +	area = get_vm_area(size, VM_IOREMAP);
    7.23 +	if (area == NULL)
    7.24 +		return NULL;
    7.25 +
    7.26 +	/*
    7.27 +         * This ensures that page tables are constructed for this region
    7.28 +         * of kernel virtual address space. Furthermore, by touching each
    7.29 +         * memory page (in touch_fn()) we ensure that the page tables are
    7.30 +         * mapped into the current mm as well as init_mm.
    7.31 +         */
    7.32 +	if (generic_page_range(&init_mm, (unsigned long)area->addr,
    7.33 +			       area->size, touch_fn, NULL)) {
    7.34 +		vunmap(area->addr);
    7.35 +		return NULL;
    7.36 +	}
    7.37 +
    7.38 +	return area;
    7.39 +}
    7.40 +
    7.41 +/*
    7.42 + * Local variables:
    7.43 + *  c-file-style: "linux"
    7.44 + *  indent-tabs-mode: t
    7.45 + *  c-indent-level: 8
    7.46 + *  c-basic-offset: 8
    7.47 + *  tab-width: 8
    7.48 + * End:
    7.49 + */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/driver_util.h	Wed Sep 21 16:36:46 2005 +0000
     8.3 @@ -0,0 +1,10 @@
     8.4 +
     8.5 +#ifndef __ASM_XEN_DRIVER_UTIL_H__
     8.6 +#define __ASM_XEN_DRIVER_UTIL_H__
     8.7 +
     8.8 +#include <linux/config.h>
     8.9 +#include <linux/vmalloc.h>
    8.10 +
    8.11 +extern struct vm_struct *prepare_vm_area(unsigned long size);
    8.12 +
    8.13 +#endif /* __ASM_XEN_DRIVER_UTIL_H__ */