ia64/xen-unstable

changeset 6593:d47439c8c0ed

Fix save/restore when using grant tables in network, robust-ify netback
against bogus front-end drivers, plus various small cleanups. Note that
there is now only /one/ config option controlling the use of grant tables
with networking (not separate ones for rx and tx).

An outstanding issue is that console reconnect after a restore causes badness.

Signed-off-by: Steven Hand <steven@xensource.com>
author shand@ubuntu.eng.hq.xensource.com
date Thu Sep 01 20:19:34 2005 -0800 (2005-09-01)
parents 9de43bdef6ca
children 2c41ae58d6b2
files linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/kernel/gnttab.c linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c tools/console/daemon/utils.c xen/Rules.mk xen/common/domain.c xen/common/grant_table.c xen/include/public/io/netif.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/Kconfig	Thu Sep 01 11:09:16 2005 -0800
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/Kconfig	Thu Sep 01 20:19:34 2005 -0800
     1.3 @@ -109,15 +109,8 @@ config XEN_NETDEV_FRONTEND
     1.4  	  dedicated device-driver domain, or your master control domain
     1.5  	  (domain 0), then you almost certainly want to say Y here.
     1.6  
     1.7 -config XEN_NETDEV_GRANT_TX
     1.8 -        bool "Grant table substrate for net drivers tx path (DANGEROUS)"
     1.9 -        default n
    1.10 -        help
    1.11 -          This introduces the use of grant tables as a data exhange mechanism
    1.12 -          between the frontend and backend network drivers.
    1.13 -
    1.14 -config XEN_NETDEV_GRANT_RX
    1.15 -        bool "Grant table substrate for net drivers rx path (DANGEROUS)"
    1.16 +config XEN_NETDEV_GRANT
    1.17 +        bool "Grant table substrate for network drivers (DANGEROUS)"
    1.18          default n
    1.19          help
    1.20            This introduces the use of grant tables as a data exhange mechanism
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Thu Sep 01 11:09:16 2005 -0800
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32	Thu Sep 01 20:19:34 2005 -0800
     2.3 @@ -19,8 +19,7 @@ CONFIG_XEN_NETDEV_BACKEND=y
     2.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     2.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     2.6  CONFIG_XEN_NETDEV_FRONTEND=y
     2.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     2.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     2.9 +CONFIG_XEN_NETDEV_GRANT=y
    2.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    2.11  # CONFIG_XEN_BLKDEV_TAP is not set
    2.12  # CONFIG_XEN_SHADOW_MODE is not set
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Thu Sep 01 11:09:16 2005 -0800
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64	Thu Sep 01 20:19:34 2005 -0800
     3.3 @@ -19,8 +19,7 @@ CONFIG_XEN_NETDEV_BACKEND=y
     3.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     3.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     3.6  CONFIG_XEN_NETDEV_FRONTEND=y
     3.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     3.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     3.9 +CONFIG_XEN_NETDEV_GRANT=y
    3.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    3.11  # CONFIG_XEN_BLKDEV_TAP is not set
    3.12  # CONFIG_XEN_SHADOW_MODE is not set
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Thu Sep 01 11:09:16 2005 -0800
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32	Thu Sep 01 20:19:34 2005 -0800
     4.3 @@ -16,8 +16,7 @@ CONFIG_NO_IDLE_HZ=y
     4.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     4.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     4.6  CONFIG_XEN_NETDEV_FRONTEND=y
     4.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     4.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     4.9 +CONFIG_XEN_NETDEV_GRANT=y
    4.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    4.11  # CONFIG_XEN_BLKDEV_TAP is not set
    4.12  # CONFIG_XEN_SHADOW_MODE is not set
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Thu Sep 01 11:09:16 2005 -0800
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64	Thu Sep 01 20:19:34 2005 -0800
     5.3 @@ -16,8 +16,7 @@ CONFIG_NO_IDLE_HZ=y
     5.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     5.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     5.6  CONFIG_XEN_NETDEV_FRONTEND=y
     5.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     5.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     5.9 +CONFIG_XEN_NETDEV_GRANT=y
    5.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    5.11  # CONFIG_XEN_BLKDEV_TAP is not set
    5.12  # CONFIG_XEN_SHADOW_MODE is not set
     6.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Thu Sep 01 11:09:16 2005 -0800
     6.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32	Thu Sep 01 20:19:34 2005 -0800
     6.3 @@ -19,8 +19,7 @@ CONFIG_XEN_NETDEV_BACKEND=y
     6.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     6.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     6.6  CONFIG_XEN_NETDEV_FRONTEND=y
     6.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     6.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     6.9 +CONFIG_XEN_NETDEV_GRANT=y
    6.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    6.11  # CONFIG_XEN_BLKDEV_TAP is not set
    6.12  # CONFIG_XEN_SHADOW_MODE is not set
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64	Thu Sep 01 11:09:16 2005 -0800
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64	Thu Sep 01 20:19:34 2005 -0800
     7.3 @@ -19,8 +19,7 @@ CONFIG_XEN_NETDEV_BACKEND=y
     7.4  # CONFIG_XEN_TPMDEV_BACKEND is not set
     7.5  CONFIG_XEN_BLKDEV_FRONTEND=y
     7.6  CONFIG_XEN_NETDEV_FRONTEND=y
     7.7 -CONFIG_XEN_NETDEV_GRANT_TX=y
     7.8 -CONFIG_XEN_NETDEV_GRANT_RX=y
     7.9 +CONFIG_XEN_NETDEV_GRANT=y
    7.10  # CONFIG_XEN_NETDEV_FRONTEND_PIPELINED_TRANSMITTER is not set
    7.11  # CONFIG_XEN_BLKDEV_TAP is not set
    7.12  # CONFIG_XEN_SHADOW_MODE is not set
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Thu Sep 01 11:09:16 2005 -0800
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Thu Sep 01 20:19:34 2005 -0800
     9.3 @@ -105,7 +105,7 @@ int xencons_ring_init(void)
     9.4  		xen_start_info.console_evtchn, handle_input,
     9.5  		0, "xencons", inring());
     9.6  	if (err) {
     9.7 -		xprintk(KERN_ERR "XEN console request irq failed %i\n", err);
     9.8 +		xprintk("XEN console request irq failed %i\n", err);
     9.9  		unbind_evtchn_from_irq(xen_start_info.console_evtchn);
    9.10  		return err;
    9.11  	}
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 01 11:09:16 2005 -0800
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 01 20:19:34 2005 -0800
    10.3 @@ -20,9 +20,12 @@
    10.4  #include <asm/io.h>
    10.5  #include <asm/pgalloc.h>
    10.6  
    10.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    10.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
    10.9  #include <asm-xen/xen-public/grant_table.h>
   10.10  #include <asm-xen/gnttab.h>
   10.11 +
   10.12 +#define GRANT_INVALID_REF (0xFFFF)
   10.13 +
   10.14  #endif
   10.15  
   10.16  
   10.17 @@ -37,6 +40,11 @@
   10.18  #define ASSERT(_p) ((void)0)
   10.19  #define DPRINTK(_f, _a...) ((void)0)
   10.20  #endif
   10.21 +#define IPRINTK(fmt, args...) \
   10.22 +    printk(KERN_INFO "xen_net: " fmt, ##args)
   10.23 +#define WPRINTK(fmt, args...) \
   10.24 +    printk(KERN_WARNING "xen_net: " fmt, ##args)
   10.25 +
   10.26  
   10.27  typedef struct netif_st {
   10.28      /* Unique identifier for this interface. */
   10.29 @@ -47,13 +55,13 @@ typedef struct netif_st {
   10.30  
   10.31      /* Physical parameters of the comms window. */
   10.32      unsigned long    tx_shmem_frame;
   10.33 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   10.34 +#ifdef CONFIG_XEN_NETDEV_GRANT
   10.35      u16              tx_shmem_handle;
   10.36      unsigned long    tx_shmem_vaddr; 
   10.37      grant_ref_t      tx_shmem_ref; 
   10.38  #endif
   10.39      unsigned long    rx_shmem_frame;
   10.40 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   10.41 +#ifdef CONFIG_XEN_NETDEV_GRANT
   10.42      u16              rx_shmem_handle;
   10.43      unsigned long    rx_shmem_vaddr; 
   10.44      grant_ref_t      rx_shmem_ref; 
   10.45 @@ -68,7 +76,7 @@ typedef struct netif_st {
   10.46      /* Private indexes into shared ring. */
   10.47      NETIF_RING_IDX rx_req_cons;
   10.48      NETIF_RING_IDX rx_resp_prod; /* private version of shared variable */
   10.49 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   10.50 +#ifdef CONFIG_XEN_NETDEV_GRANT
   10.51      NETIF_RING_IDX rx_resp_prod_copy; /* private version of shared variable */
   10.52  #endif
   10.53      NETIF_RING_IDX tx_req_cons;
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 01 11:09:16 2005 -0800
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 01 20:19:34 2005 -0800
    11.3 @@ -111,65 +111,57 @@ netif_t *alloc_netif(domid_t domid, unsi
    11.4      return netif;
    11.5  }
    11.6  
    11.7 -static int map_frontend_page(netif_t *netif, unsigned long localaddr,
    11.8 -			     unsigned long tx_ring_ref, unsigned long rx_ring_ref)
    11.9 +static int map_frontend_pages(netif_t *netif, unsigned long localaddr,
   11.10 +                              unsigned long tx_ring_ref, 
   11.11 +                              unsigned long rx_ring_ref)
   11.12  {
   11.13 -#if !defined(CONFIG_XEN_NETDEV_GRANT_TX)||!defined(CONFIG_XEN_NETDEV_GRANT_RX)
   11.14 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.15 +    struct gnttab_map_grant_ref op;
   11.16 +
   11.17 +    /* Map: Use the Grant table reference */
   11.18 +    op.host_addr = localaddr;
   11.19 +    op.flags     = GNTMAP_host_map;
   11.20 +    op.ref       = tx_ring_ref;
   11.21 +    op.dom       = netif->domid;
   11.22 +    
   11.23 +    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   11.24 +    if (op.handle < 0) { 
   11.25 +        DPRINTK(" Grant table operation failure mapping tx_ring_ref!\n");
   11.26 +        return op.handle;
   11.27 +    }
   11.28 +
   11.29 +    netif->tx_shmem_ref    = tx_ring_ref;
   11.30 +    netif->tx_shmem_handle = op.handle;
   11.31 +    netif->tx_shmem_vaddr  = localaddr;
   11.32 +
   11.33 +    /* Map: Use the Grant table reference */
   11.34 +    op.host_addr = localaddr + PAGE_SIZE;
   11.35 +    op.flags     = GNTMAP_host_map;
   11.36 +    op.ref       = rx_ring_ref;
   11.37 +    op.dom       = netif->domid;
   11.38 +
   11.39 +    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   11.40 +    if (op.handle < 0) { 
   11.41 +        DPRINTK(" Grant table operation failure mapping rx_ring_ref!\n");
   11.42 +        return op.handle;
   11.43 +    }
   11.44 +
   11.45 +    netif->rx_shmem_ref    = rx_ring_ref;
   11.46 +    netif->rx_shmem_handle = op.handle;
   11.47 +    netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
   11.48 +
   11.49 +#else
   11.50      pgprot_t      prot = __pgprot(_KERNPG_TABLE);
   11.51      int           err;
   11.52 -#endif
   11.53 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX)
   11.54 -    {
   11.55 -        struct gnttab_map_grant_ref op;
   11.56  
   11.57 -        /* Map: Use the Grant table reference */
   11.58 -        op.host_addr = localaddr;
   11.59 -        op.flags     = GNTMAP_host_map;
   11.60 -        op.ref       = tx_ring_ref;
   11.61 -        op.dom       = netif->domid;
   11.62 -       
   11.63 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   11.64 -        if (op.handle < 0) { 
   11.65 -            DPRINTK(" Grant table operation failure !\n");
   11.66 -            return op.handle;
   11.67 -        }
   11.68 -
   11.69 -        netif->tx_shmem_ref    = tx_ring_ref;
   11.70 -        netif->tx_shmem_handle = op.handle;
   11.71 -        netif->tx_shmem_vaddr  = localaddr;
   11.72 -    }
   11.73 -#else 
   11.74      err = direct_remap_area_pages(&init_mm, localaddr,
   11.75  				  tx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
   11.76  				  prot, netif->domid); 
   11.77 -    if (err)
   11.78 -	return err;
   11.79 -#endif
   11.80 -
   11.81 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX)
   11.82 -    {
   11.83 -        struct gnttab_map_grant_ref op;
   11.84 -
   11.85 -        /* Map: Use the Grant table reference */
   11.86 -        op.host_addr = localaddr + PAGE_SIZE;
   11.87 -        op.flags     = GNTMAP_host_map;
   11.88 -        op.ref       = rx_ring_ref;
   11.89 -        op.dom       = netif->domid;
   11.90 -
   11.91 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   11.92 -        if (op.handle < 0) { 
   11.93 -            DPRINTK(" Grant table operation failure !\n");
   11.94 -            return op.handle;
   11.95 -        }
   11.96 -
   11.97 -        netif->rx_shmem_ref    = rx_ring_ref;
   11.98 -        netif->rx_shmem_handle = op.handle;
   11.99 -        netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
  11.100 -    }
  11.101 -#else 
  11.102 -    err = direct_remap_area_pages(&init_mm, localaddr + PAGE_SIZE,
  11.103 +    
  11.104 +    err |= direct_remap_area_pages(&init_mm, localaddr + PAGE_SIZE,
  11.105  				  rx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
  11.106  				  prot, netif->domid);
  11.107 +
  11.108      if (err)
  11.109  	return err;
  11.110  #endif
  11.111 @@ -177,25 +169,23 @@ static int map_frontend_page(netif_t *ne
  11.112      return 0;
  11.113  }
  11.114  
  11.115 -static void unmap_frontend_page(netif_t *netif)
  11.116 +static void unmap_frontend_pages(netif_t *netif)
  11.117  {
  11.118 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX) || defined(CONFIG_XEN_NETDEV_GRANT_TX)
  11.119 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.120      struct gnttab_unmap_grant_ref op;
  11.121 -#endif
  11.122  
  11.123 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.124      op.host_addr    = netif->tx_shmem_vaddr;
  11.125      op.handle       = netif->tx_shmem_handle;
  11.126      op.dev_bus_addr = 0;
  11.127      BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  11.128 -#endif
  11.129  
  11.130 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.131      op.host_addr    = netif->rx_shmem_vaddr;
  11.132      op.handle       = netif->rx_shmem_handle;
  11.133      op.dev_bus_addr = 0;
  11.134      BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  11.135  #endif
  11.136 +
  11.137 +    return; 
  11.138  }
  11.139  
  11.140  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
  11.141 @@ -209,8 +199,8 @@ int netif_map(netif_t *netif, unsigned l
  11.142      if (vma == NULL)
  11.143          return -ENOMEM;
  11.144  
  11.145 -    err = map_frontend_page(netif, (unsigned long)vma->addr, tx_ring_ref,
  11.146 -			    rx_ring_ref);
  11.147 +    err = map_frontend_pages(netif, (unsigned long)vma->addr, tx_ring_ref,
  11.148 +                             rx_ring_ref);
  11.149      if (err) {
  11.150          vfree(vma->addr);
  11.151  	return err;
  11.152 @@ -222,7 +212,7 @@ int netif_map(netif_t *netif, unsigned l
  11.153      op.u.bind_interdomain.port2 = evtchn;
  11.154      err = HYPERVISOR_event_channel_op(&op);
  11.155      if (err) {
  11.156 -	unmap_frontend_page(netif);
  11.157 +	unmap_frontend_pages(netif);
  11.158  	vfree(vma->addr);
  11.159  	return err;
  11.160      }
  11.161 @@ -267,7 +257,7 @@ static void free_netif(void *arg)
  11.162      unregister_netdev(netif->dev);
  11.163  
  11.164      if (netif->tx) {
  11.165 -	unmap_frontend_page(netif);
  11.166 +	unmap_frontend_pages(netif);
  11.167  	vfree(netif->tx); /* Frees netif->rx as well. */
  11.168      }
  11.169  
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Sep 01 11:09:16 2005 -0800
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Sep 01 20:19:34 2005 -0800
    12.3 @@ -14,23 +14,6 @@
    12.4  #include <asm-xen/balloon.h>
    12.5  #include <asm-xen/xen-public/memory.h>
    12.6  
    12.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    12.8 -#include <asm-xen/xen-public/grant_table.h>
    12.9 -#include <asm-xen/gnttab.h>
   12.10 -#ifdef GRANT_DEBUG
   12.11 -static void
   12.12 -dump_packet(int tag, u32 addr, unsigned char *p)
   12.13 -{
   12.14 -	int i;
   12.15 -
   12.16 -	printk(KERN_ALERT "#### rx_action %c %08x ", tag & 0xff, addr);
   12.17 -	for (i = 0; i < 20; i++) {
   12.18 -		printk("%02x", p[i]);
   12.19 -	}
   12.20 -	printk("\n");
   12.21 -}
   12.22 -#endif
   12.23 -#endif
   12.24  
   12.25  static void netif_idx_release(u16 pending_idx);
   12.26  static void netif_page_release(struct page *page);
   12.27 @@ -57,7 +40,8 @@ static struct timer_list net_timer;
   12.28  static struct sk_buff_head rx_queue;
   12.29  static multicall_entry_t rx_mcl[NETIF_RX_RING_SIZE*2+1];
   12.30  static mmu_update_t rx_mmu[NETIF_RX_RING_SIZE];
   12.31 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.32 +
   12.33 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.34  static gnttab_donate_t grant_rx_op[MAX_PENDING_REQS];
   12.35  #else
   12.36  static struct mmuext_op rx_mmuext[NETIF_RX_RING_SIZE];
   12.37 @@ -88,18 +72,15 @@ static PEND_RING_IDX dealloc_prod, deall
   12.38  
   12.39  static struct sk_buff_head tx_queue;
   12.40  
   12.41 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   12.42 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.43  static u16 grant_tx_ref[MAX_PENDING_REQS];
   12.44  static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
   12.45  static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
   12.46 +
   12.47  #else
   12.48  static multicall_entry_t tx_mcl[MAX_PENDING_REQS];
   12.49  #endif
   12.50  
   12.51 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   12.52 -#define GRANT_INVALID_REF (0xFFFF)
   12.53 -#endif
   12.54 -
   12.55  static struct list_head net_schedule_list;
   12.56  static spinlock_t net_schedule_list_lock;
   12.57  
   12.58 @@ -127,7 +108,7 @@ static unsigned long alloc_mfn(void)
   12.59      return mfn;
   12.60  }
   12.61  
   12.62 -#ifndef CONFIG_XEN_NETDEV_GRANT_RX
   12.63 +#ifndef CONFIG_XEN_NETDEV_GRANT
   12.64  static void free_mfn(unsigned long mfn)
   12.65  {
   12.66      unsigned long flags;
   12.67 @@ -200,7 +181,7 @@ int netif_be_start_xmit(struct sk_buff *
   12.68          dev_kfree_skb(skb);
   12.69          skb = nskb;
   12.70      }
   12.71 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.72 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.73  #ifdef DEBUG_GRANT
   12.74      printk(KERN_ALERT "#### be_xmit: req_prod=%d req_cons=%d id=%04x gr=%04x\n",
   12.75             netif->rx->req_prod,
   12.76 @@ -246,12 +227,12 @@ int xen_network_done(void)
   12.77  
   12.78  static void net_rx_action(unsigned long unused)
   12.79  {
   12.80 -    netif_t *netif;
   12.81 +    netif_t *netif = NULL; 
   12.82      s8 status;
   12.83      u16 size, id, evtchn;
   12.84      multicall_entry_t *mcl;
   12.85      mmu_update_t *mmu;
   12.86 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.87 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.88      gnttab_donate_t *gop;
   12.89  #else
   12.90      struct mmuext_op *mmuext;
   12.91 @@ -266,7 +247,7 @@ static void net_rx_action(unsigned long 
   12.92  
   12.93      mcl = rx_mcl;
   12.94      mmu = rx_mmu;
   12.95 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.96 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.97      gop = grant_rx_op;
   12.98  #else
   12.99      mmuext = rx_mmuext;
  12.100 @@ -282,7 +263,7 @@ static void net_rx_action(unsigned long 
  12.101          if ( (new_mfn = alloc_mfn()) == 0 )
  12.102          {
  12.103              if ( net_ratelimit() )
  12.104 -                printk(KERN_WARNING "Memory squeeze in netback driver.\n");
  12.105 +                WPRINTK("Memory squeeze in netback driver.\n");
  12.106              mod_timer(&net_timer, jiffies + HZ);
  12.107              skb_queue_head(&rx_queue, skb);
  12.108              break;
  12.109 @@ -297,7 +278,7 @@ static void net_rx_action(unsigned long 
  12.110  				pfn_pte_ma(new_mfn, PAGE_KERNEL), 0);
  12.111          mcl++;
  12.112  
  12.113 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.114 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.115          gop->mfn = old_mfn;
  12.116          gop->domid = netif->domid;
  12.117          gop->handle = netif->rx->ring[
  12.118 @@ -340,7 +321,7 @@ static void net_rx_action(unsigned long 
  12.119      mcl->args[3] = DOMID_SELF;
  12.120      mcl++;
  12.121  
  12.122 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.123 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.124      mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
  12.125  #else
  12.126      mcl[-3].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
  12.127 @@ -349,9 +330,17 @@ static void net_rx_action(unsigned long 
  12.128          BUG();
  12.129  
  12.130      mcl = rx_mcl;
  12.131 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.132 -    BUG_ON(HYPERVISOR_grant_table_op(
  12.133 -        GNTTABOP_donate, grant_rx_op, gop - grant_rx_op));
  12.134 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.135 +    if(HYPERVISOR_grant_table_op(GNTTABOP_donate, grant_rx_op, 
  12.136 +                                 gop - grant_rx_op)) { 
  12.137 +        /* 
  12.138 +        ** The other side has given us a bad grant ref, or has no headroom, 
  12.139 +        ** or has gone away. Unfortunately the current grant table code 
  12.140 +        ** doesn't inform us which is the case, so not much we can do. 
  12.141 +        */
  12.142 +        DPRINTK("net_rx: donate to DOM%u failed; dropping (up to) %d "
  12.143 +                "packets.\n", grant_rx_op[0].domid, gop - grant_rx_op); 
  12.144 +    }
  12.145      gop = grant_rx_op;
  12.146  #else
  12.147      mmuext = rx_mmuext;
  12.148 @@ -363,7 +352,7 @@ static void net_rx_action(unsigned long 
  12.149  
  12.150          /* Rederive the machine addresses. */
  12.151          new_mfn = mcl[0].args[1] >> PAGE_SHIFT;
  12.152 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.153 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.154          old_mfn = 0; /* XXX Fix this so we can free_mfn() on error! */
  12.155  #else
  12.156          old_mfn = mmuext[0].mfn;
  12.157 @@ -380,8 +369,13 @@ static void net_rx_action(unsigned long 
  12.158  
  12.159          /* Check the reassignment error code. */
  12.160          status = NETIF_RSP_OKAY;
  12.161 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.162 -        BUG_ON(gop->status != 0); /* XXX */
  12.163 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.164 +        if(gop->status != 0) { 
  12.165 +            DPRINTK("Bad status %d from grant donate to DOM%u\n", 
  12.166 +                    gop->status, netif->domid);
  12.167 +            /* XXX SMH: should free 'old_mfn' here */
  12.168 +            status = NETIF_RSP_ERROR; 
  12.169 +        } 
  12.170  #else
  12.171          if ( unlikely(mcl[1].result != 0) )
  12.172          {
  12.173 @@ -404,7 +398,7 @@ static void net_rx_action(unsigned long 
  12.174  
  12.175          netif_put(netif);
  12.176          dev_kfree_skb(skb);
  12.177 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.178 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.179          mcl++;
  12.180          gop++;
  12.181  #else
  12.182 @@ -420,6 +414,7 @@ static void net_rx_action(unsigned long 
  12.183          notify_via_evtchn(evtchn);
  12.184      }
  12.185  
  12.186 +  out: 
  12.187      /* More work to do? */
  12.188      if ( !skb_queue_empty(&rx_queue) && !timer_pending(&net_timer) )
  12.189          tasklet_schedule(&net_rx_tasklet);
  12.190 @@ -496,7 +491,7 @@ static void tx_credit_callback(unsigned 
  12.191  
  12.192  inline static void net_tx_action_dealloc(void)
  12.193  {
  12.194 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.195 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.196      gnttab_unmap_grant_ref_t *gop;
  12.197  #else
  12.198      multicall_entry_t *mcl;
  12.199 @@ -508,7 +503,7 @@ inline static void net_tx_action_dealloc
  12.200      dc = dealloc_cons;
  12.201      dp = dealloc_prod;
  12.202  
  12.203 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.204 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.205      /*
  12.206       * Free up any grants we have finished using
  12.207       */
  12.208 @@ -542,7 +537,7 @@ inline static void net_tx_action_dealloc
  12.209  #endif
  12.210      while ( dealloc_cons != dp )
  12.211      {
  12.212 -#ifndef CONFIG_XEN_NETDEV_GRANT_TX
  12.213 +#ifndef CONFIG_XEN_NETDEV_GRANT
  12.214          /* The update_va_mapping() must not fail. */
  12.215          BUG_ON(mcl[0].result != 0);
  12.216  #endif
  12.217 @@ -569,7 +564,7 @@ inline static void net_tx_action_dealloc
  12.218          
  12.219          netif_put(netif);
  12.220  
  12.221 -#ifndef CONFIG_XEN_NETDEV_GRANT_TX
  12.222 +#ifndef CONFIG_XEN_NETDEV_GRANT
  12.223          mcl++;
  12.224  #endif
  12.225      }
  12.226 @@ -585,7 +580,7 @@ static void net_tx_action(unsigned long 
  12.227      netif_tx_request_t txreq;
  12.228      u16 pending_idx;
  12.229      NETIF_RING_IDX i;
  12.230 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.231 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.232      gnttab_map_grant_ref_t *mop;
  12.233  #else
  12.234      multicall_entry_t *mcl;
  12.235 @@ -595,7 +590,7 @@ static void net_tx_action(unsigned long 
  12.236      if ( dealloc_cons != dealloc_prod )
  12.237          net_tx_action_dealloc();
  12.238  
  12.239 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.240 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.241      mop = tx_map_ops;
  12.242  #else
  12.243      mcl = tx_mcl;
  12.244 @@ -696,7 +691,7 @@ static void net_tx_action(unsigned long 
  12.245  
  12.246          /* Packets passed to netif_rx() must have some headroom. */
  12.247          skb_reserve(skb, 16);
  12.248 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.249 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.250          mop->host_addr = MMAP_VADDR(pending_idx);
  12.251          mop->dom       = netif->domid;
  12.252          mop->ref       = txreq.addr >> PAGE_SHIFT;
  12.253 @@ -719,7 +714,7 @@ static void net_tx_action(unsigned long 
  12.254  
  12.255          pending_cons++;
  12.256  
  12.257 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.258 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.259          if ( (mop - tx_map_ops) >= ARRAY_SIZE(tx_map_ops) )
  12.260              break;
  12.261  #else
  12.262 @@ -729,7 +724,7 @@ static void net_tx_action(unsigned long 
  12.263  #endif
  12.264      }
  12.265  
  12.266 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.267 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.268      if ( mop == tx_map_ops )
  12.269          return;
  12.270  
  12.271 @@ -752,7 +747,7 @@ static void net_tx_action(unsigned long 
  12.272          memcpy(&txreq, &pending_tx_info[pending_idx].req, sizeof(txreq));
  12.273  
  12.274          /* Check the remap error code. */
  12.275 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.276 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.277          /* 
  12.278             XXX SMH: error returns from grant operations are pretty poorly
  12.279             specified/thought out, but the below at least conforms with 
  12.280 @@ -826,7 +821,7 @@ static void net_tx_action(unsigned long 
  12.281          netif_rx(skb);
  12.282          netif->dev->last_rx = jiffies;
  12.283  
  12.284 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.285 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.286          mop++;
  12.287  #else
  12.288          mcl++;
  12.289 @@ -949,12 +944,9 @@ static int __init netback_init(void)
  12.290           !(xen_start_info.flags & SIF_INITDOMAIN) )
  12.291          return 0;
  12.292  
  12.293 -    printk("Initialising Xen netif backend\n");
  12.294 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.295 -    printk("#### netback tx using grant tables\n");
  12.296 -#endif
  12.297 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.298 -    printk("#### netback rx using grant tables\n");
  12.299 +    IPRINTK("Initialising Xen netif backend.\n");
  12.300 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.301 +    IPRINTK("Using grant tables.\n");
  12.302  #endif
  12.303  
  12.304      /* We can increase reservation by this much in net_rx_action(). */
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Sep 01 11:09:16 2005 -0800
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Sep 01 20:19:34 2005 -0800
    13.3 @@ -55,9 +55,18 @@
    13.4  #include <asm/page.h>
    13.5  #include <asm/uaccess.h>
    13.6  
    13.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    13.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
    13.9  #include <asm-xen/xen-public/grant_table.h>
   13.10  #include <asm-xen/gnttab.h>
   13.11 +
   13.12 +static grant_ref_t gref_tx_head;
   13.13 +static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1]; 
   13.14 +
   13.15 +static grant_ref_t gref_rx_head;
   13.16 +static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1];
   13.17 +
   13.18 +#define GRANT_INVALID_REF	(0xFFFF)
   13.19 +
   13.20  #ifdef GRANT_DEBUG
   13.21  static void
   13.22  dump_packet(int tag, void *addr, u32 ap)
   13.23 @@ -71,9 +80,18 @@ dump_packet(int tag, void *addr, u32 ap)
   13.24      }
   13.25      printk("\n");
   13.26  }
   13.27 +
   13.28 +#define GDPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
   13.29 +                           __FILE__ , __LINE__ , ## _a )
   13.30 +#else 
   13.31 +#define dump_packet(x,y,z)  ((void)0)  
   13.32 +#define GDPRINTK(_f, _a...) ((void)0)
   13.33  #endif
   13.34 +
   13.35  #endif
   13.36  
   13.37 +
   13.38 +
   13.39  #ifndef __GFP_NOWARN
   13.40  #define __GFP_NOWARN 0
   13.41  #endif
   13.42 @@ -102,23 +120,11 @@ dump_packet(int tag, void *addr, u32 ap)
   13.43  #define TX_TEST_IDX req_cons  /* conservative: not seen all our requests? */
   13.44  #endif
   13.45  
   13.46 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   13.47 -static grant_ref_t gref_tx_head;
   13.48 -static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1];
   13.49 -#endif
   13.50 -
   13.51 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   13.52 -static grant_ref_t gref_rx_head;
   13.53 -static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1];
   13.54 -#endif
   13.55 -
   13.56 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   13.57 -#define GRANT_INVALID_REF	(0xFFFF)
   13.58 -#endif
   13.59  
   13.60  #define NETIF_STATE_DISCONNECTED 0
   13.61  #define NETIF_STATE_CONNECTED    1
   13.62  
   13.63 +
   13.64  static unsigned int netif_state = NETIF_STATE_DISCONNECTED;
   13.65  
   13.66  static void network_tx_buf_gc(struct net_device *dev);
   13.67 @@ -279,7 +285,7 @@ static void network_tx_buf_gc(struct net
   13.68          for (i = np->tx_resp_cons; i != prod; i++) {
   13.69              id  = np->tx->ring[MASK_NETIF_TX_IDX(i)].resp.id;
   13.70              skb = np->tx_skbs[id];
   13.71 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   13.72 +#ifdef CONFIG_XEN_NETDEV_GRANT
   13.73              if (unlikely(gnttab_query_foreign_access(grant_tx_ref[id]) != 0)) {
   13.74                  /* other domain is still using this grant - shouldn't happen
   13.75                     but if it does, we'll try to reclaim the grant later */
   13.76 @@ -310,7 +316,7 @@ static void network_tx_buf_gc(struct net
   13.77          mb();
   13.78      } while (prod != np->tx->resp_prod);
   13.79  
   13.80 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   13.81 +#ifdef CONFIG_XEN_NETDEV_GRANT
   13.82    out: 
   13.83  #endif
   13.84  
   13.85 @@ -330,8 +336,8 @@ static void network_alloc_rx_buffers(str
   13.86      int i, batch_target;
   13.87      NETIF_RING_IDX req_prod = np->rx->req_prod;
   13.88      struct xen_memory_reservation reservation;
   13.89 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   13.90 -    int ref;
   13.91 +#ifdef CONFIG_XEN_NETDEV_GRANT
   13.92 +    grant_ref_t ref;
   13.93  #endif
   13.94  
   13.95      if (unlikely(np->backend_state != BEST_CONNECTED))
   13.96 @@ -365,9 +371,9 @@ static void network_alloc_rx_buffers(str
   13.97          np->rx_skbs[id] = skb;
   13.98          
   13.99          np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.id = id;
  13.100 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.101 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.102  	ref = gnttab_claim_grant_reference(&gref_rx_head);
  13.103 -        if (unlikely(ref < 0)) {
  13.104 +        if (unlikely((signed short)ref < 0)) {
  13.105              printk(KERN_ALERT "#### netfront can't claim rx reference\n");
  13.106              BUG();
  13.107          }
  13.108 @@ -426,8 +432,8 @@ static int network_start_xmit(struct sk_
  13.109      struct net_private *np = netdev_priv(dev);
  13.110      netif_tx_request_t *tx;
  13.111      NETIF_RING_IDX i;
  13.112 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.113 -    unsigned int ref;
  13.114 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.115 +    grant_ref_t ref;
  13.116      unsigned long mfn;
  13.117  #endif
  13.118  
  13.119 @@ -464,9 +470,9 @@ static int network_start_xmit(struct sk_
  13.120      tx = &np->tx->ring[MASK_NETIF_TX_IDX(i)].req;
  13.121  
  13.122      tx->id   = id;
  13.123 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.124 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.125      ref = gnttab_claim_grant_reference(&gref_tx_head);
  13.126 -    if (unlikely(ref < 0)) {
  13.127 +    if (unlikely((signed short)ref < 0)) {
  13.128          printk(KERN_ALERT "#### netfront can't claim tx grant reference\n");
  13.129          BUG();
  13.130      }
  13.131 @@ -519,7 +525,7 @@ static irqreturn_t netif_int(int irq, vo
  13.132      network_tx_buf_gc(dev);
  13.133      spin_unlock_irqrestore(&np->tx_lock, flags);
  13.134  
  13.135 -    if ((np->rx_resp_cons != np->rx->resp_prod) && (np->user_state == UST_OPEN))
  13.136 +    if((np->rx_resp_cons != np->rx->resp_prod) && (np->user_state == UST_OPEN))
  13.137          netif_rx_schedule(dev);
  13.138  
  13.139      return IRQ_HANDLED;
  13.140 @@ -537,7 +543,7 @@ static int netif_poll(struct net_device 
  13.141      int work_done, budget, more_to_do = 1;
  13.142      struct sk_buff_head rxq;
  13.143      unsigned long flags;
  13.144 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.145 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.146      unsigned long mfn;
  13.147      grant_ref_t ref;
  13.148  #endif
  13.149 @@ -574,8 +580,19 @@ static int netif_poll(struct net_device 
  13.150              continue;
  13.151          }
  13.152  
  13.153 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.154 -        ref = grant_rx_ref[rx->id];
  13.155 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.156 +        ref = grant_rx_ref[rx->id]; 
  13.157 +
  13.158 +        if(ref == GRANT_INVALID_REF) { 
  13.159 +            printk(KERN_WARNING "Bad rx grant reference %d from dom %d.\n",
  13.160 +                   ref, np->backend_id);
  13.161 +            np->rx->ring[MASK_NETIF_RX_IDX(np->rx->req_prod)].req.id = rx->id;
  13.162 +            wmb();
  13.163 +            np->rx->req_prod++;
  13.164 +            work_done--;
  13.165 +            continue;
  13.166 +        }
  13.167 +
  13.168          grant_rx_ref[rx->id] = GRANT_INVALID_REF;
  13.169          mfn = gnttab_end_foreign_transfer_ref(ref);
  13.170          gnttab_release_grant_reference(&gref_rx_head, ref);
  13.171 @@ -585,7 +602,7 @@ static int netif_poll(struct net_device 
  13.172          ADD_ID_TO_FREELIST(np->rx_skbs, rx->id);
  13.173  
  13.174          /* NB. We handle skb overflow later. */
  13.175 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.176 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.177          skb->data = skb->head + rx->addr;
  13.178  #else
  13.179          skb->data = skb->head + (rx->addr & ~PAGE_MASK);
  13.180 @@ -600,14 +617,14 @@ static int netif_poll(struct net_device 
  13.181          np->stats.rx_bytes += rx->status;
  13.182  
  13.183          /* Remap the page. */
  13.184 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.185 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.186          mmu->ptr = mfn << PAGE_SHIFT | MMU_MACHPHYS_UPDATE;
  13.187  #else
  13.188          mmu->ptr  = (rx->addr & PAGE_MASK) | MMU_MACHPHYS_UPDATE;
  13.189  #endif
  13.190          mmu->val  = __pa(skb->head) >> PAGE_SHIFT;
  13.191          mmu++;
  13.192 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.193 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.194  	MULTI_update_va_mapping(mcl, (unsigned long)skb->head,
  13.195  				pfn_pte_ma(mfn, PAGE_KERNEL), 0);
  13.196  #else
  13.197 @@ -617,20 +634,20 @@ static int netif_poll(struct net_device 
  13.198  #endif
  13.199          mcl++;
  13.200  
  13.201 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.202 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.203          phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] = mfn;
  13.204 +        GDPRINTK("#### rx_poll     enqueue vdata=%p mfn=%lu ref=%x\n",
  13.205 +                skb->data, mfn, ref);
  13.206  #else
  13.207          phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] = 
  13.208              rx->addr >> PAGE_SHIFT;
  13.209 -#endif
  13.210 +#endif 
  13.211  
  13.212 -#ifdef GRANT_DEBUG
  13.213 -        printk(KERN_ALERT "#### rx_poll     enqueue vdata=%p mfn=%lu ref=%x\n",
  13.214 -               skb->data, mfn, ref);
  13.215 -#endif
  13.216 +
  13.217          __skb_queue_tail(&rxq, skb);
  13.218      }
  13.219  
  13.220 +
  13.221      /* Some pages are no longer absent... */
  13.222      balloon_update_driver_allowance(-work_done);
  13.223  
  13.224 @@ -646,9 +663,9 @@ static int netif_poll(struct net_device 
  13.225      }
  13.226  
  13.227      while ((skb = __skb_dequeue(&rxq)) != NULL) {
  13.228 -#ifdef GRANT_DEBUG
  13.229 -        printk(KERN_ALERT "#### rx_poll     dequeue vdata=%p mfn=%lu\n",
  13.230 -               skb->data, virt_to_mfn(skb->data));
  13.231 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.232 +        GDPRINTK("#### rx_poll     dequeue vdata=%p mfn=%lu\n",
  13.233 +                skb->data, virt_to_mfn(skb->data));
  13.234          dump_packet('d', skb->data, (unsigned long)skb->data);
  13.235  #endif
  13.236          /*
  13.237 @@ -747,7 +764,6 @@ static struct net_device_stats *network_
  13.238      return &np->stats;
  13.239  }
  13.240  
  13.241 -
  13.242  static void network_connect(struct net_device *dev)
  13.243  {
  13.244      struct net_private *np;
  13.245 @@ -787,8 +803,11 @@ static void network_connect(struct net_d
  13.246              tx = &np->tx->ring[requeue_idx++].req;
  13.247  
  13.248              tx->id   = i;
  13.249 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.250 -            tx->addr = 0; /*(ref << PAGE_SHIFT) |*/
  13.251 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.252 +            gnttab_grant_foreign_access_ref(grant_tx_ref[i], np->backend_id, 
  13.253 +                                            virt_to_mfn(np->tx_skbs[i]->data),
  13.254 +                                            GNTMAP_readonly); 
  13.255 +            tx->addr = grant_tx_ref[i] << PAGE_SHIFT; 
  13.256  #else
  13.257              tx->addr = virt_to_mfn(skb->data) << PAGE_SHIFT;
  13.258  #endif
  13.259 @@ -803,9 +822,20 @@ static void network_connect(struct net_d
  13.260      np->tx->req_prod = requeue_idx;
  13.261  
  13.262      /* Rebuild the RX buffer freelist and the RX ring itself. */
  13.263 -    for (requeue_idx = 0, i = 1; i <= NETIF_RX_RING_SIZE; i++)
  13.264 -        if ((unsigned long)np->rx_skbs[i] >= __PAGE_OFFSET)
  13.265 -            np->rx->ring[requeue_idx++].req.id = i;
  13.266 +    for (requeue_idx = 0, i = 1; i <= NETIF_RX_RING_SIZE; i++) { 
  13.267 +        if ((unsigned long)np->rx_skbs[i] >= __PAGE_OFFSET) {
  13.268 +#ifdef CONFIG_XEN_NETDEV_GRANT 
  13.269 +            /* Reinstate the grant ref so backend can 'donate' mfn to us. */
  13.270 +            gnttab_grant_foreign_transfer_ref(grant_rx_ref[i], np->backend_id,
  13.271 +                                              virt_to_mfn(np->rx_skbs[i]->head)
  13.272 +                );
  13.273 +            np->rx->ring[requeue_idx].req.gref = grant_rx_ref[i];
  13.274 +#endif
  13.275 +            np->rx->ring[requeue_idx].req.id   = i;
  13.276 +            requeue_idx++; 
  13.277 +        }
  13.278 +    }
  13.279 +
  13.280      wmb();                
  13.281      np->rx->req_prod = requeue_idx;
  13.282  
  13.283 @@ -901,13 +931,14 @@ static int create_netdev(int handle, str
  13.284      /* Initialise {tx,rx}_skbs to be a free chain containing every entry. */
  13.285      for (i = 0; i <= NETIF_TX_RING_SIZE; i++) {
  13.286          np->tx_skbs[i] = (void *)((unsigned long) i+1);
  13.287 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.288 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.289          grant_tx_ref[i] = GRANT_INVALID_REF;
  13.290  #endif
  13.291      }
  13.292 +
  13.293      for (i = 0; i <= NETIF_RX_RING_SIZE; i++) {
  13.294          np->rx_skbs[i] = (void *)((unsigned long) i+1);
  13.295 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.296 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.297          grant_rx_ref[i] = GRANT_INVALID_REF;
  13.298  #endif
  13.299      }
  13.300 @@ -991,10 +1022,8 @@ static int setup_device(struct xenbus_de
  13.301  	evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound };
  13.302  	int err;
  13.303  
  13.304 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.305 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.306  	info->tx_ring_ref = GRANT_INVALID_REF;
  13.307 -#endif
  13.308 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.309  	info->rx_ring_ref = GRANT_INVALID_REF;
  13.310  #endif
  13.311  
  13.312 @@ -1014,7 +1043,7 @@ static int setup_device(struct xenbus_de
  13.313  	memset(info->rx, 0, PAGE_SIZE);
  13.314  	info->backend_state = BEST_DISCONNECTED;
  13.315  
  13.316 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.317 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.318  	err = gnttab_grant_foreign_access(info->backend_id,
  13.319  					  virt_to_mfn(info->tx), 0);
  13.320  	if (err < 0) {
  13.321 @@ -1022,11 +1051,7 @@ static int setup_device(struct xenbus_de
  13.322  		goto out;
  13.323  	}
  13.324  	info->tx_ring_ref = err;
  13.325 -#else
  13.326 -	info->tx_ring_ref = virt_to_mfn(info->tx);
  13.327 -#endif
  13.328  
  13.329 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.330  	err = gnttab_grant_foreign_access(info->backend_id,
  13.331  					  virt_to_mfn(info->rx), 0);
  13.332  	if (err < 0) {
  13.333 @@ -1034,7 +1059,9 @@ static int setup_device(struct xenbus_de
  13.334  		goto out;
  13.335  	}
  13.336  	info->rx_ring_ref = err;
  13.337 +
  13.338  #else
  13.339 +	info->tx_ring_ref = virt_to_mfn(info->tx);
  13.340  	info->rx_ring_ref = virt_to_mfn(info->rx);
  13.341  #endif
  13.342  
  13.343 @@ -1054,16 +1081,17 @@ static int setup_device(struct xenbus_de
  13.344  	if (info->rx)
  13.345  		free_page((unsigned long)info->rx);
  13.346  	info->rx = 0;
  13.347 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.348 +
  13.349 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.350  	if (info->tx_ring_ref != GRANT_INVALID_REF)
  13.351  		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  13.352  	info->tx_ring_ref = GRANT_INVALID_REF;
  13.353 -#endif
  13.354 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.355 +
  13.356  	if (info->rx_ring_ref != GRANT_INVALID_REF)
  13.357  		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  13.358  	info->rx_ring_ref = GRANT_INVALID_REF;
  13.359  #endif
  13.360 +
  13.361  	return err;
  13.362  }
  13.363  
  13.364 @@ -1075,16 +1103,17 @@ static void netif_free(struct netfront_i
  13.365  	if (info->rx)
  13.366  		free_page((unsigned long)info->rx);
  13.367  	info->rx = 0;
  13.368 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.369 +
  13.370 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.371  	if (info->tx_ring_ref != GRANT_INVALID_REF)
  13.372  		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  13.373  	info->tx_ring_ref = GRANT_INVALID_REF;
  13.374 -#endif
  13.375 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.376 +
  13.377  	if (info->rx_ring_ref != GRANT_INVALID_REF)
  13.378  		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  13.379  	info->rx_ring_ref = GRANT_INVALID_REF;
  13.380  #endif
  13.381 +
  13.382  	unbind_evtchn_from_irqhandler(info->evtchn, info->netdev);
  13.383  	info->evtchn = 0;
  13.384  }
  13.385 @@ -1294,6 +1323,7 @@ static int netfront_resume(struct xenbus
  13.386  	int err;
  13.387  
  13.388  	err = talk_to_backend(dev, np);
  13.389 +
  13.390  	return err;
  13.391  }
  13.392  
  13.393 @@ -1342,29 +1372,28 @@ static int __init netif_init(void)
  13.394      if (xen_start_info.flags & SIF_INITDOMAIN)
  13.395          return 0;
  13.396  
  13.397 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.398 -    /* A grant for every ring slot */
  13.399 +    if ((err = xennet_proc_init()) != 0)
  13.400 +        return err;
  13.401 +
  13.402 +    IPRINTK("Initialising virtual ethernet driver.\n");
  13.403 +
  13.404 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.405 +    IPRINTK("Using grant tables.\n"); 
  13.406 +
  13.407 +    /* A grant for every tx ring slot */
  13.408      if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE,
  13.409                                        &gref_tx_head) < 0) {
  13.410          printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
  13.411          return 1;
  13.412      }
  13.413 -    printk(KERN_ALERT "Netdev frontend (TX) is using grant tables.\n"); 
  13.414 -#endif
  13.415 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.416 -    /* A grant for every ring slot */
  13.417 +    /* A grant for every rx ring slot */
  13.418      if (gnttab_alloc_grant_references(NETIF_RX_RING_SIZE,
  13.419                                        &gref_rx_head) < 0) {
  13.420          printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
  13.421          return 1;
  13.422      }
  13.423 -    printk(KERN_ALERT "Netdev frontend (RX) is using grant tables.\n"); 
  13.424  #endif
  13.425  
  13.426 -    if ((err = xennet_proc_init()) != 0)
  13.427 -        return err;
  13.428 -
  13.429 -    IPRINTK("Initialising virtual ethernet driver.\n");
  13.430  
  13.431      (void)register_inetaddr_notifier(&notifier_inetdev);
  13.432  
  13.433 @@ -1377,10 +1406,8 @@ static int __init netif_init(void)
  13.434  
  13.435  static void netif_exit(void)
  13.436  {
  13.437 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  13.438 +#ifdef CONFIG_XEN_NETDEV_GRANT
  13.439      gnttab_free_grant_references(gref_tx_head);
  13.440 -#endif
  13.441 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  13.442      gnttab_free_grant_references(gref_rx_head);
  13.443  #endif
  13.444  }
    14.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Thu Sep 01 11:09:16 2005 -0800
    14.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Thu Sep 01 20:19:34 2005 -0800
    14.3 @@ -212,7 +212,7 @@ int xb_init_comms(void)
    14.4  		xen_start_info.store_evtchn, wake_waiting,
    14.5  		0, "xenbus", &xb_waitq);
    14.6  	if (err) {
    14.7 -		printk(KERN_ERR "XENBUS request irq failed %i\n", err);
    14.8 +		xprintk("XENBUS request irq failed %i\n", err);
    14.9  		unbind_evtchn_from_irq(xen_start_info.store_evtchn);
   14.10  		return err;
   14.11  	}
    15.1 --- a/tools/console/daemon/utils.c	Thu Sep 01 11:09:16 2005 -0800
    15.2 +++ b/tools/console/daemon/utils.c	Thu Sep 01 20:19:34 2005 -0800
    15.3 @@ -234,7 +234,7 @@ bool xen_setup(void)
    15.4  	}
    15.5  
    15.6  	if (!xs_watch(xs, "/console", "console")) {
    15.7 -		dolog(LOG_ERR, "xenstore watch on /console failes.");
    15.8 +		dolog(LOG_ERR, "xenstore watch on /console fails.");
    15.9  		goto out_close_data;
   15.10  	}
   15.11  
    17.1 --- a/xen/common/domain.c	Thu Sep 01 11:09:16 2005 -0800
    17.2 +++ b/xen/common/domain.c	Thu Sep 01 20:19:34 2005 -0800
    17.3 @@ -178,6 +178,9 @@ void domain_shutdown(u8 reason)
    17.4      struct domain *d = current->domain;
    17.5      struct vcpu *v;
    17.6  
    17.7 +    if(reason == SHUTDOWN_crash) 
    17.8 +        printk("Domain %d crash detected.\n", d->domain_id); 
    17.9 +
   17.10      if ( d->domain_id == 0 )
   17.11      {
   17.12          extern void machine_restart(char *);
    18.1 --- a/xen/common/grant_table.c	Thu Sep 01 11:09:16 2005 -0800
    18.2 +++ b/xen/common/grant_table.c	Thu Sep 01 20:19:34 2005 -0800
    18.3 @@ -887,21 +887,21 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    18.4                     e->tot_pages, e->max_pages);
    18.5              spin_unlock(&e->page_alloc_lock);
    18.6              put_domain(e);
    18.7 -            result = GNTST_general_error;
    18.8 +            gop->status = result = GNTST_general_error;
    18.9              break;
   18.10          }
   18.11          if (unlikely(test_bit(DOMFLAGS_DYING, &e->domain_flags))) {
   18.12              printk("gnttab_donate: target domain is dying\n");
   18.13              spin_unlock(&e->page_alloc_lock);
   18.14              put_domain(e);
   18.15 -            result = GNTST_general_error;
   18.16 +            gop->status = result = GNTST_general_error;
   18.17              break;
   18.18          }
   18.19          if (unlikely(!gnttab_prepare_for_transfer(e, d, gop->handle))) {
   18.20 -            printk("gnttab_donate: gnttab_prepare_for_transfer fails\n");
   18.21 +            printk("gnttab_donate: gnttab_prepare_for_transfer fails.\n");
   18.22              spin_unlock(&e->page_alloc_lock);
   18.23              put_domain(e);
   18.24 -            result = GNTST_general_error;
   18.25 +            gop->status = result = GNTST_general_error;
   18.26              break;
   18.27          }
   18.28  #else
   18.29 @@ -914,7 +914,8 @@ gnttab_donate(gnttab_donate_t *uop, unsi
   18.30                     e->tot_pages, e->max_pages, gop->handle, e->d_flags);
   18.31              spin_unlock(&e->page_alloc_lock);
   18.32              put_domain(e);
   18.33 -            result = GNTST_general_error;
   18.34 +            /* XXX SMH: better error return here would be useful */
   18.35 +            gop->status = result = GNTST_general_error;
   18.36              break;
   18.37          }
   18.38  #endif
   18.39 @@ -1020,7 +1021,7 @@ gnttab_check_unmap(
   18.40      lgt = ld->grant_table;
   18.41      
   18.42  #if GRANT_DEBUG_VERBOSE
   18.43 -    if ( ld->domain_ id != 0 ) {
   18.44 +    if ( ld->domain_id != 0 ) {
   18.45              DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   18.46                      rd->domain_id, ld->domain_id, frame, readonly);
   18.47        }
    19.1 --- a/xen/include/public/io/netif.h	Thu Sep 01 11:09:16 2005 -0800
    19.2 +++ b/xen/include/public/io/netif.h	Thu Sep 01 20:19:34 2005 -0800
    19.3 @@ -23,13 +23,13 @@ typedef struct netif_tx_response {
    19.4  
    19.5  typedef struct {
    19.6      u16       id;    /* Echoed in response message.        */
    19.7 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
    19.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
    19.9      grant_ref_t gref;	/* 2: Reference to incoming granted frame */
   19.10  #endif
   19.11  } netif_rx_request_t;
   19.12  
   19.13  typedef struct {
   19.14 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   19.15 +#ifdef CONFIG_XEN_NETDEV_GRANT
   19.16      u32      addr;   /*  0: Offset in page of start of received packet  */
   19.17  #else
   19.18      unsigned long addr; /* Machine address of packet.              */