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
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Thu Sep 01 11:09:16 2005 -0800
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/console/xencons_ring.c	Thu Sep 01 20:19:34 2005 -0800
     8.3 @@ -105,7 +105,7 @@ int xencons_ring_init(void)
     8.4  		xen_start_info.console_evtchn, handle_input,
     8.5  		0, "xencons", inring());
     8.6  	if (err) {
     8.7 -		xprintk(KERN_ERR "XEN console request irq failed %i\n", err);
     8.8 +		xprintk("XEN console request irq failed %i\n", err);
     8.9  		unbind_evtchn_from_irq(xen_start_info.console_evtchn);
    8.10  		return err;
    8.11  	}
     9.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 01 11:09:16 2005 -0800
     9.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Thu Sep 01 20:19:34 2005 -0800
     9.3 @@ -20,9 +20,12 @@
     9.4  #include <asm/io.h>
     9.5  #include <asm/pgalloc.h>
     9.6  
     9.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
     9.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
     9.9  #include <asm-xen/xen-public/grant_table.h>
    9.10  #include <asm-xen/gnttab.h>
    9.11 +
    9.12 +#define GRANT_INVALID_REF (0xFFFF)
    9.13 +
    9.14  #endif
    9.15  
    9.16  
    9.17 @@ -37,6 +40,11 @@
    9.18  #define ASSERT(_p) ((void)0)
    9.19  #define DPRINTK(_f, _a...) ((void)0)
    9.20  #endif
    9.21 +#define IPRINTK(fmt, args...) \
    9.22 +    printk(KERN_INFO "xen_net: " fmt, ##args)
    9.23 +#define WPRINTK(fmt, args...) \
    9.24 +    printk(KERN_WARNING "xen_net: " fmt, ##args)
    9.25 +
    9.26  
    9.27  typedef struct netif_st {
    9.28      /* Unique identifier for this interface. */
    9.29 @@ -47,13 +55,13 @@ typedef struct netif_st {
    9.30  
    9.31      /* Physical parameters of the comms window. */
    9.32      unsigned long    tx_shmem_frame;
    9.33 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
    9.34 +#ifdef CONFIG_XEN_NETDEV_GRANT
    9.35      u16              tx_shmem_handle;
    9.36      unsigned long    tx_shmem_vaddr; 
    9.37      grant_ref_t      tx_shmem_ref; 
    9.38  #endif
    9.39      unsigned long    rx_shmem_frame;
    9.40 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
    9.41 +#ifdef CONFIG_XEN_NETDEV_GRANT
    9.42      u16              rx_shmem_handle;
    9.43      unsigned long    rx_shmem_vaddr; 
    9.44      grant_ref_t      rx_shmem_ref; 
    9.45 @@ -68,7 +76,7 @@ typedef struct netif_st {
    9.46      /* Private indexes into shared ring. */
    9.47      NETIF_RING_IDX rx_req_cons;
    9.48      NETIF_RING_IDX rx_resp_prod; /* private version of shared variable */
    9.49 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
    9.50 +#ifdef CONFIG_XEN_NETDEV_GRANT
    9.51      NETIF_RING_IDX rx_resp_prod_copy; /* private version of shared variable */
    9.52  #endif
    9.53      NETIF_RING_IDX tx_req_cons;
    10.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 01 11:09:16 2005 -0800
    10.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Thu Sep 01 20:19:34 2005 -0800
    10.3 @@ -111,65 +111,57 @@ netif_t *alloc_netif(domid_t domid, unsi
    10.4      return netif;
    10.5  }
    10.6  
    10.7 -static int map_frontend_page(netif_t *netif, unsigned long localaddr,
    10.8 -			     unsigned long tx_ring_ref, unsigned long rx_ring_ref)
    10.9 +static int map_frontend_pages(netif_t *netif, unsigned long localaddr,
   10.10 +                              unsigned long tx_ring_ref, 
   10.11 +                              unsigned long rx_ring_ref)
   10.12  {
   10.13 -#if !defined(CONFIG_XEN_NETDEV_GRANT_TX)||!defined(CONFIG_XEN_NETDEV_GRANT_RX)
   10.14 +#ifdef CONFIG_XEN_NETDEV_GRANT
   10.15 +    struct gnttab_map_grant_ref op;
   10.16 +
   10.17 +    /* Map: Use the Grant table reference */
   10.18 +    op.host_addr = localaddr;
   10.19 +    op.flags     = GNTMAP_host_map;
   10.20 +    op.ref       = tx_ring_ref;
   10.21 +    op.dom       = netif->domid;
   10.22 +    
   10.23 +    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   10.24 +    if (op.handle < 0) { 
   10.25 +        DPRINTK(" Grant table operation failure mapping tx_ring_ref!\n");
   10.26 +        return op.handle;
   10.27 +    }
   10.28 +
   10.29 +    netif->tx_shmem_ref    = tx_ring_ref;
   10.30 +    netif->tx_shmem_handle = op.handle;
   10.31 +    netif->tx_shmem_vaddr  = localaddr;
   10.32 +
   10.33 +    /* Map: Use the Grant table reference */
   10.34 +    op.host_addr = localaddr + PAGE_SIZE;
   10.35 +    op.flags     = GNTMAP_host_map;
   10.36 +    op.ref       = rx_ring_ref;
   10.37 +    op.dom       = netif->domid;
   10.38 +
   10.39 +    BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   10.40 +    if (op.handle < 0) { 
   10.41 +        DPRINTK(" Grant table operation failure mapping rx_ring_ref!\n");
   10.42 +        return op.handle;
   10.43 +    }
   10.44 +
   10.45 +    netif->rx_shmem_ref    = rx_ring_ref;
   10.46 +    netif->rx_shmem_handle = op.handle;
   10.47 +    netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
   10.48 +
   10.49 +#else
   10.50      pgprot_t      prot = __pgprot(_KERNPG_TABLE);
   10.51      int           err;
   10.52 -#endif
   10.53 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX)
   10.54 -    {
   10.55 -        struct gnttab_map_grant_ref op;
   10.56  
   10.57 -        /* Map: Use the Grant table reference */
   10.58 -        op.host_addr = localaddr;
   10.59 -        op.flags     = GNTMAP_host_map;
   10.60 -        op.ref       = tx_ring_ref;
   10.61 -        op.dom       = netif->domid;
   10.62 -       
   10.63 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   10.64 -        if (op.handle < 0) { 
   10.65 -            DPRINTK(" Grant table operation failure !\n");
   10.66 -            return op.handle;
   10.67 -        }
   10.68 -
   10.69 -        netif->tx_shmem_ref    = tx_ring_ref;
   10.70 -        netif->tx_shmem_handle = op.handle;
   10.71 -        netif->tx_shmem_vaddr  = localaddr;
   10.72 -    }
   10.73 -#else 
   10.74      err = direct_remap_area_pages(&init_mm, localaddr,
   10.75  				  tx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
   10.76  				  prot, netif->domid); 
   10.77 -    if (err)
   10.78 -	return err;
   10.79 -#endif
   10.80 -
   10.81 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX)
   10.82 -    {
   10.83 -        struct gnttab_map_grant_ref op;
   10.84 -
   10.85 -        /* Map: Use the Grant table reference */
   10.86 -        op.host_addr = localaddr + PAGE_SIZE;
   10.87 -        op.flags     = GNTMAP_host_map;
   10.88 -        op.ref       = rx_ring_ref;
   10.89 -        op.dom       = netif->domid;
   10.90 -
   10.91 -	BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) );
   10.92 -        if (op.handle < 0) { 
   10.93 -            DPRINTK(" Grant table operation failure !\n");
   10.94 -            return op.handle;
   10.95 -        }
   10.96 -
   10.97 -        netif->rx_shmem_ref    = rx_ring_ref;
   10.98 -        netif->rx_shmem_handle = op.handle;
   10.99 -        netif->rx_shmem_vaddr  = localaddr + PAGE_SIZE;
  10.100 -    }
  10.101 -#else 
  10.102 -    err = direct_remap_area_pages(&init_mm, localaddr + PAGE_SIZE,
  10.103 +    
  10.104 +    err |= direct_remap_area_pages(&init_mm, localaddr + PAGE_SIZE,
  10.105  				  rx_ring_ref<<PAGE_SHIFT, PAGE_SIZE,
  10.106  				  prot, netif->domid);
  10.107 +
  10.108      if (err)
  10.109  	return err;
  10.110  #endif
  10.111 @@ -177,25 +169,23 @@ static int map_frontend_page(netif_t *ne
  10.112      return 0;
  10.113  }
  10.114  
  10.115 -static void unmap_frontend_page(netif_t *netif)
  10.116 +static void unmap_frontend_pages(netif_t *netif)
  10.117  {
  10.118 -#if defined(CONFIG_XEN_NETDEV_GRANT_RX) || defined(CONFIG_XEN_NETDEV_GRANT_TX)
  10.119 +#ifdef CONFIG_XEN_NETDEV_GRANT
  10.120      struct gnttab_unmap_grant_ref op;
  10.121 -#endif
  10.122  
  10.123 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  10.124      op.host_addr    = netif->tx_shmem_vaddr;
  10.125      op.handle       = netif->tx_shmem_handle;
  10.126      op.dev_bus_addr = 0;
  10.127      BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  10.128 -#endif
  10.129  
  10.130 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  10.131      op.host_addr    = netif->rx_shmem_vaddr;
  10.132      op.handle       = netif->rx_shmem_handle;
  10.133      op.dev_bus_addr = 0;
  10.134      BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1));
  10.135  #endif
  10.136 +
  10.137 +    return; 
  10.138  }
  10.139  
  10.140  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
  10.141 @@ -209,8 +199,8 @@ int netif_map(netif_t *netif, unsigned l
  10.142      if (vma == NULL)
  10.143          return -ENOMEM;
  10.144  
  10.145 -    err = map_frontend_page(netif, (unsigned long)vma->addr, tx_ring_ref,
  10.146 -			    rx_ring_ref);
  10.147 +    err = map_frontend_pages(netif, (unsigned long)vma->addr, tx_ring_ref,
  10.148 +                             rx_ring_ref);
  10.149      if (err) {
  10.150          vfree(vma->addr);
  10.151  	return err;
  10.152 @@ -222,7 +212,7 @@ int netif_map(netif_t *netif, unsigned l
  10.153      op.u.bind_interdomain.port2 = evtchn;
  10.154      err = HYPERVISOR_event_channel_op(&op);
  10.155      if (err) {
  10.156 -	unmap_frontend_page(netif);
  10.157 +	unmap_frontend_pages(netif);
  10.158  	vfree(vma->addr);
  10.159  	return err;
  10.160      }
  10.161 @@ -267,7 +257,7 @@ static void free_netif(void *arg)
  10.162      unregister_netdev(netif->dev);
  10.163  
  10.164      if (netif->tx) {
  10.165 -	unmap_frontend_page(netif);
  10.166 +	unmap_frontend_pages(netif);
  10.167  	vfree(netif->tx); /* Frees netif->rx as well. */
  10.168      }
  10.169  
    11.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Sep 01 11:09:16 2005 -0800
    11.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Sep 01 20:19:34 2005 -0800
    11.3 @@ -14,23 +14,6 @@
    11.4  #include <asm-xen/balloon.h>
    11.5  #include <asm-xen/xen-public/memory.h>
    11.6  
    11.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    11.8 -#include <asm-xen/xen-public/grant_table.h>
    11.9 -#include <asm-xen/gnttab.h>
   11.10 -#ifdef GRANT_DEBUG
   11.11 -static void
   11.12 -dump_packet(int tag, u32 addr, unsigned char *p)
   11.13 -{
   11.14 -	int i;
   11.15 -
   11.16 -	printk(KERN_ALERT "#### rx_action %c %08x ", tag & 0xff, addr);
   11.17 -	for (i = 0; i < 20; i++) {
   11.18 -		printk("%02x", p[i]);
   11.19 -	}
   11.20 -	printk("\n");
   11.21 -}
   11.22 -#endif
   11.23 -#endif
   11.24  
   11.25  static void netif_idx_release(u16 pending_idx);
   11.26  static void netif_page_release(struct page *page);
   11.27 @@ -57,7 +40,8 @@ static struct timer_list net_timer;
   11.28  static struct sk_buff_head rx_queue;
   11.29  static multicall_entry_t rx_mcl[NETIF_RX_RING_SIZE*2+1];
   11.30  static mmu_update_t rx_mmu[NETIF_RX_RING_SIZE];
   11.31 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   11.32 +
   11.33 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.34  static gnttab_donate_t grant_rx_op[MAX_PENDING_REQS];
   11.35  #else
   11.36  static struct mmuext_op rx_mmuext[NETIF_RX_RING_SIZE];
   11.37 @@ -88,18 +72,15 @@ static PEND_RING_IDX dealloc_prod, deall
   11.38  
   11.39  static struct sk_buff_head tx_queue;
   11.40  
   11.41 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   11.42 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.43  static u16 grant_tx_ref[MAX_PENDING_REQS];
   11.44  static gnttab_unmap_grant_ref_t tx_unmap_ops[MAX_PENDING_REQS];
   11.45  static gnttab_map_grant_ref_t tx_map_ops[MAX_PENDING_REQS];
   11.46 +
   11.47  #else
   11.48  static multicall_entry_t tx_mcl[MAX_PENDING_REQS];
   11.49  #endif
   11.50  
   11.51 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   11.52 -#define GRANT_INVALID_REF (0xFFFF)
   11.53 -#endif
   11.54 -
   11.55  static struct list_head net_schedule_list;
   11.56  static spinlock_t net_schedule_list_lock;
   11.57  
   11.58 @@ -127,7 +108,7 @@ static unsigned long alloc_mfn(void)
   11.59      return mfn;
   11.60  }
   11.61  
   11.62 -#ifndef CONFIG_XEN_NETDEV_GRANT_RX
   11.63 +#ifndef CONFIG_XEN_NETDEV_GRANT
   11.64  static void free_mfn(unsigned long mfn)
   11.65  {
   11.66      unsigned long flags;
   11.67 @@ -200,7 +181,7 @@ int netif_be_start_xmit(struct sk_buff *
   11.68          dev_kfree_skb(skb);
   11.69          skb = nskb;
   11.70      }
   11.71 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   11.72 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.73  #ifdef DEBUG_GRANT
   11.74      printk(KERN_ALERT "#### be_xmit: req_prod=%d req_cons=%d id=%04x gr=%04x\n",
   11.75             netif->rx->req_prod,
   11.76 @@ -246,12 +227,12 @@ int xen_network_done(void)
   11.77  
   11.78  static void net_rx_action(unsigned long unused)
   11.79  {
   11.80 -    netif_t *netif;
   11.81 +    netif_t *netif = NULL; 
   11.82      s8 status;
   11.83      u16 size, id, evtchn;
   11.84      multicall_entry_t *mcl;
   11.85      mmu_update_t *mmu;
   11.86 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   11.87 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.88      gnttab_donate_t *gop;
   11.89  #else
   11.90      struct mmuext_op *mmuext;
   11.91 @@ -266,7 +247,7 @@ static void net_rx_action(unsigned long 
   11.92  
   11.93      mcl = rx_mcl;
   11.94      mmu = rx_mmu;
   11.95 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   11.96 +#ifdef CONFIG_XEN_NETDEV_GRANT
   11.97      gop = grant_rx_op;
   11.98  #else
   11.99      mmuext = rx_mmuext;
  11.100 @@ -282,7 +263,7 @@ static void net_rx_action(unsigned long 
  11.101          if ( (new_mfn = alloc_mfn()) == 0 )
  11.102          {
  11.103              if ( net_ratelimit() )
  11.104 -                printk(KERN_WARNING "Memory squeeze in netback driver.\n");
  11.105 +                WPRINTK("Memory squeeze in netback driver.\n");
  11.106              mod_timer(&net_timer, jiffies + HZ);
  11.107              skb_queue_head(&rx_queue, skb);
  11.108              break;
  11.109 @@ -297,7 +278,7 @@ static void net_rx_action(unsigned long 
  11.110  				pfn_pte_ma(new_mfn, PAGE_KERNEL), 0);
  11.111          mcl++;
  11.112  
  11.113 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.114 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.115          gop->mfn = old_mfn;
  11.116          gop->domid = netif->domid;
  11.117          gop->handle = netif->rx->ring[
  11.118 @@ -340,7 +321,7 @@ static void net_rx_action(unsigned long 
  11.119      mcl->args[3] = DOMID_SELF;
  11.120      mcl++;
  11.121  
  11.122 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.123 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.124      mcl[-2].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
  11.125  #else
  11.126      mcl[-3].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
  11.127 @@ -349,9 +330,17 @@ static void net_rx_action(unsigned long 
  11.128          BUG();
  11.129  
  11.130      mcl = rx_mcl;
  11.131 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.132 -    BUG_ON(HYPERVISOR_grant_table_op(
  11.133 -        GNTTABOP_donate, grant_rx_op, gop - grant_rx_op));
  11.134 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.135 +    if(HYPERVISOR_grant_table_op(GNTTABOP_donate, grant_rx_op, 
  11.136 +                                 gop - grant_rx_op)) { 
  11.137 +        /* 
  11.138 +        ** The other side has given us a bad grant ref, or has no headroom, 
  11.139 +        ** or has gone away. Unfortunately the current grant table code 
  11.140 +        ** doesn't inform us which is the case, so not much we can do. 
  11.141 +        */
  11.142 +        DPRINTK("net_rx: donate to DOM%u failed; dropping (up to) %d "
  11.143 +                "packets.\n", grant_rx_op[0].domid, gop - grant_rx_op); 
  11.144 +    }
  11.145      gop = grant_rx_op;
  11.146  #else
  11.147      mmuext = rx_mmuext;
  11.148 @@ -363,7 +352,7 @@ static void net_rx_action(unsigned long 
  11.149  
  11.150          /* Rederive the machine addresses. */
  11.151          new_mfn = mcl[0].args[1] >> PAGE_SHIFT;
  11.152 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.153 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.154          old_mfn = 0; /* XXX Fix this so we can free_mfn() on error! */
  11.155  #else
  11.156          old_mfn = mmuext[0].mfn;
  11.157 @@ -380,8 +369,13 @@ static void net_rx_action(unsigned long 
  11.158  
  11.159          /* Check the reassignment error code. */
  11.160          status = NETIF_RSP_OKAY;
  11.161 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.162 -        BUG_ON(gop->status != 0); /* XXX */
  11.163 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.164 +        if(gop->status != 0) { 
  11.165 +            DPRINTK("Bad status %d from grant donate to DOM%u\n", 
  11.166 +                    gop->status, netif->domid);
  11.167 +            /* XXX SMH: should free 'old_mfn' here */
  11.168 +            status = NETIF_RSP_ERROR; 
  11.169 +        } 
  11.170  #else
  11.171          if ( unlikely(mcl[1].result != 0) )
  11.172          {
  11.173 @@ -404,7 +398,7 @@ static void net_rx_action(unsigned long 
  11.174  
  11.175          netif_put(netif);
  11.176          dev_kfree_skb(skb);
  11.177 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.178 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.179          mcl++;
  11.180          gop++;
  11.181  #else
  11.182 @@ -420,6 +414,7 @@ static void net_rx_action(unsigned long 
  11.183          notify_via_evtchn(evtchn);
  11.184      }
  11.185  
  11.186 +  out: 
  11.187      /* More work to do? */
  11.188      if ( !skb_queue_empty(&rx_queue) && !timer_pending(&net_timer) )
  11.189          tasklet_schedule(&net_rx_tasklet);
  11.190 @@ -496,7 +491,7 @@ static void tx_credit_callback(unsigned 
  11.191  
  11.192  inline static void net_tx_action_dealloc(void)
  11.193  {
  11.194 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.195 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.196      gnttab_unmap_grant_ref_t *gop;
  11.197  #else
  11.198      multicall_entry_t *mcl;
  11.199 @@ -508,7 +503,7 @@ inline static void net_tx_action_dealloc
  11.200      dc = dealloc_cons;
  11.201      dp = dealloc_prod;
  11.202  
  11.203 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.204 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.205      /*
  11.206       * Free up any grants we have finished using
  11.207       */
  11.208 @@ -542,7 +537,7 @@ inline static void net_tx_action_dealloc
  11.209  #endif
  11.210      while ( dealloc_cons != dp )
  11.211      {
  11.212 -#ifndef CONFIG_XEN_NETDEV_GRANT_TX
  11.213 +#ifndef CONFIG_XEN_NETDEV_GRANT
  11.214          /* The update_va_mapping() must not fail. */
  11.215          BUG_ON(mcl[0].result != 0);
  11.216  #endif
  11.217 @@ -569,7 +564,7 @@ inline static void net_tx_action_dealloc
  11.218          
  11.219          netif_put(netif);
  11.220  
  11.221 -#ifndef CONFIG_XEN_NETDEV_GRANT_TX
  11.222 +#ifndef CONFIG_XEN_NETDEV_GRANT
  11.223          mcl++;
  11.224  #endif
  11.225      }
  11.226 @@ -585,7 +580,7 @@ static void net_tx_action(unsigned long 
  11.227      netif_tx_request_t txreq;
  11.228      u16 pending_idx;
  11.229      NETIF_RING_IDX i;
  11.230 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.231 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.232      gnttab_map_grant_ref_t *mop;
  11.233  #else
  11.234      multicall_entry_t *mcl;
  11.235 @@ -595,7 +590,7 @@ static void net_tx_action(unsigned long 
  11.236      if ( dealloc_cons != dealloc_prod )
  11.237          net_tx_action_dealloc();
  11.238  
  11.239 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.240 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.241      mop = tx_map_ops;
  11.242  #else
  11.243      mcl = tx_mcl;
  11.244 @@ -696,7 +691,7 @@ static void net_tx_action(unsigned long 
  11.245  
  11.246          /* Packets passed to netif_rx() must have some headroom. */
  11.247          skb_reserve(skb, 16);
  11.248 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.249 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.250          mop->host_addr = MMAP_VADDR(pending_idx);
  11.251          mop->dom       = netif->domid;
  11.252          mop->ref       = txreq.addr >> PAGE_SHIFT;
  11.253 @@ -719,7 +714,7 @@ static void net_tx_action(unsigned long 
  11.254  
  11.255          pending_cons++;
  11.256  
  11.257 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.258 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.259          if ( (mop - tx_map_ops) >= ARRAY_SIZE(tx_map_ops) )
  11.260              break;
  11.261  #else
  11.262 @@ -729,7 +724,7 @@ static void net_tx_action(unsigned long 
  11.263  #endif
  11.264      }
  11.265  
  11.266 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.267 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.268      if ( mop == tx_map_ops )
  11.269          return;
  11.270  
  11.271 @@ -752,7 +747,7 @@ static void net_tx_action(unsigned long 
  11.272          memcpy(&txreq, &pending_tx_info[pending_idx].req, sizeof(txreq));
  11.273  
  11.274          /* Check the remap error code. */
  11.275 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.276 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.277          /* 
  11.278             XXX SMH: error returns from grant operations are pretty poorly
  11.279             specified/thought out, but the below at least conforms with 
  11.280 @@ -826,7 +821,7 @@ static void net_tx_action(unsigned long 
  11.281          netif_rx(skb);
  11.282          netif->dev->last_rx = jiffies;
  11.283  
  11.284 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.285 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.286          mop++;
  11.287  #else
  11.288          mcl++;
  11.289 @@ -949,12 +944,9 @@ static int __init netback_init(void)
  11.290           !(xen_start_info.flags & SIF_INITDOMAIN) )
  11.291          return 0;
  11.292  
  11.293 -    printk("Initialising Xen netif backend\n");
  11.294 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  11.295 -    printk("#### netback tx using grant tables\n");
  11.296 -#endif
  11.297 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  11.298 -    printk("#### netback rx using grant tables\n");
  11.299 +    IPRINTK("Initialising Xen netif backend.\n");
  11.300 +#ifdef CONFIG_XEN_NETDEV_GRANT
  11.301 +    IPRINTK("Using grant tables.\n");
  11.302  #endif
  11.303  
  11.304      /* We can increase reservation by this much in net_rx_action(). */
    12.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Sep 01 11:09:16 2005 -0800
    12.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Sep 01 20:19:34 2005 -0800
    12.3 @@ -55,9 +55,18 @@
    12.4  #include <asm/page.h>
    12.5  #include <asm/uaccess.h>
    12.6  
    12.7 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    12.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
    12.9  #include <asm-xen/xen-public/grant_table.h>
   12.10  #include <asm-xen/gnttab.h>
   12.11 +
   12.12 +static grant_ref_t gref_tx_head;
   12.13 +static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1]; 
   12.14 +
   12.15 +static grant_ref_t gref_rx_head;
   12.16 +static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1];
   12.17 +
   12.18 +#define GRANT_INVALID_REF	(0xFFFF)
   12.19 +
   12.20  #ifdef GRANT_DEBUG
   12.21  static void
   12.22  dump_packet(int tag, void *addr, u32 ap)
   12.23 @@ -71,9 +80,18 @@ dump_packet(int tag, void *addr, u32 ap)
   12.24      }
   12.25      printk("\n");
   12.26  }
   12.27 +
   12.28 +#define GDPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
   12.29 +                           __FILE__ , __LINE__ , ## _a )
   12.30 +#else 
   12.31 +#define dump_packet(x,y,z)  ((void)0)  
   12.32 +#define GDPRINTK(_f, _a...) ((void)0)
   12.33  #endif
   12.34 +
   12.35  #endif
   12.36  
   12.37 +
   12.38 +
   12.39  #ifndef __GFP_NOWARN
   12.40  #define __GFP_NOWARN 0
   12.41  #endif
   12.42 @@ -102,23 +120,11 @@ dump_packet(int tag, void *addr, u32 ap)
   12.43  #define TX_TEST_IDX req_cons  /* conservative: not seen all our requests? */
   12.44  #endif
   12.45  
   12.46 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   12.47 -static grant_ref_t gref_tx_head;
   12.48 -static grant_ref_t grant_tx_ref[NETIF_TX_RING_SIZE + 1];
   12.49 -#endif
   12.50 -
   12.51 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.52 -static grant_ref_t gref_rx_head;
   12.53 -static grant_ref_t grant_rx_ref[NETIF_RX_RING_SIZE + 1];
   12.54 -#endif
   12.55 -
   12.56 -#if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
   12.57 -#define GRANT_INVALID_REF	(0xFFFF)
   12.58 -#endif
   12.59  
   12.60  #define NETIF_STATE_DISCONNECTED 0
   12.61  #define NETIF_STATE_CONNECTED    1
   12.62  
   12.63 +
   12.64  static unsigned int netif_state = NETIF_STATE_DISCONNECTED;
   12.65  
   12.66  static void network_tx_buf_gc(struct net_device *dev);
   12.67 @@ -279,7 +285,7 @@ static void network_tx_buf_gc(struct net
   12.68          for (i = np->tx_resp_cons; i != prod; i++) {
   12.69              id  = np->tx->ring[MASK_NETIF_TX_IDX(i)].resp.id;
   12.70              skb = np->tx_skbs[id];
   12.71 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   12.72 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.73              if (unlikely(gnttab_query_foreign_access(grant_tx_ref[id]) != 0)) {
   12.74                  /* other domain is still using this grant - shouldn't happen
   12.75                     but if it does, we'll try to reclaim the grant later */
   12.76 @@ -310,7 +316,7 @@ static void network_tx_buf_gc(struct net
   12.77          mb();
   12.78      } while (prod != np->tx->resp_prod);
   12.79  
   12.80 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   12.81 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.82    out: 
   12.83  #endif
   12.84  
   12.85 @@ -330,8 +336,8 @@ static void network_alloc_rx_buffers(str
   12.86      int i, batch_target;
   12.87      NETIF_RING_IDX req_prod = np->rx->req_prod;
   12.88      struct xen_memory_reservation reservation;
   12.89 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
   12.90 -    int ref;
   12.91 +#ifdef CONFIG_XEN_NETDEV_GRANT
   12.92 +    grant_ref_t ref;
   12.93  #endif
   12.94  
   12.95      if (unlikely(np->backend_state != BEST_CONNECTED))
   12.96 @@ -365,9 +371,9 @@ static void network_alloc_rx_buffers(str
   12.97          np->rx_skbs[id] = skb;
   12.98          
   12.99          np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.id = id;
  12.100 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.101 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.102  	ref = gnttab_claim_grant_reference(&gref_rx_head);
  12.103 -        if (unlikely(ref < 0)) {
  12.104 +        if (unlikely((signed short)ref < 0)) {
  12.105              printk(KERN_ALERT "#### netfront can't claim rx reference\n");
  12.106              BUG();
  12.107          }
  12.108 @@ -426,8 +432,8 @@ static int network_start_xmit(struct sk_
  12.109      struct net_private *np = netdev_priv(dev);
  12.110      netif_tx_request_t *tx;
  12.111      NETIF_RING_IDX i;
  12.112 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.113 -    unsigned int ref;
  12.114 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.115 +    grant_ref_t ref;
  12.116      unsigned long mfn;
  12.117  #endif
  12.118  
  12.119 @@ -464,9 +470,9 @@ static int network_start_xmit(struct sk_
  12.120      tx = &np->tx->ring[MASK_NETIF_TX_IDX(i)].req;
  12.121  
  12.122      tx->id   = id;
  12.123 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.124 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.125      ref = gnttab_claim_grant_reference(&gref_tx_head);
  12.126 -    if (unlikely(ref < 0)) {
  12.127 +    if (unlikely((signed short)ref < 0)) {
  12.128          printk(KERN_ALERT "#### netfront can't claim tx grant reference\n");
  12.129          BUG();
  12.130      }
  12.131 @@ -519,7 +525,7 @@ static irqreturn_t netif_int(int irq, vo
  12.132      network_tx_buf_gc(dev);
  12.133      spin_unlock_irqrestore(&np->tx_lock, flags);
  12.134  
  12.135 -    if ((np->rx_resp_cons != np->rx->resp_prod) && (np->user_state == UST_OPEN))
  12.136 +    if((np->rx_resp_cons != np->rx->resp_prod) && (np->user_state == UST_OPEN))
  12.137          netif_rx_schedule(dev);
  12.138  
  12.139      return IRQ_HANDLED;
  12.140 @@ -537,7 +543,7 @@ static int netif_poll(struct net_device 
  12.141      int work_done, budget, more_to_do = 1;
  12.142      struct sk_buff_head rxq;
  12.143      unsigned long flags;
  12.144 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.145 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.146      unsigned long mfn;
  12.147      grant_ref_t ref;
  12.148  #endif
  12.149 @@ -574,8 +580,19 @@ static int netif_poll(struct net_device 
  12.150              continue;
  12.151          }
  12.152  
  12.153 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.154 -        ref = grant_rx_ref[rx->id];
  12.155 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.156 +        ref = grant_rx_ref[rx->id]; 
  12.157 +
  12.158 +        if(ref == GRANT_INVALID_REF) { 
  12.159 +            printk(KERN_WARNING "Bad rx grant reference %d from dom %d.\n",
  12.160 +                   ref, np->backend_id);
  12.161 +            np->rx->ring[MASK_NETIF_RX_IDX(np->rx->req_prod)].req.id = rx->id;
  12.162 +            wmb();
  12.163 +            np->rx->req_prod++;
  12.164 +            work_done--;
  12.165 +            continue;
  12.166 +        }
  12.167 +
  12.168          grant_rx_ref[rx->id] = GRANT_INVALID_REF;
  12.169          mfn = gnttab_end_foreign_transfer_ref(ref);
  12.170          gnttab_release_grant_reference(&gref_rx_head, ref);
  12.171 @@ -585,7 +602,7 @@ static int netif_poll(struct net_device 
  12.172          ADD_ID_TO_FREELIST(np->rx_skbs, rx->id);
  12.173  
  12.174          /* NB. We handle skb overflow later. */
  12.175 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.176 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.177          skb->data = skb->head + rx->addr;
  12.178  #else
  12.179          skb->data = skb->head + (rx->addr & ~PAGE_MASK);
  12.180 @@ -600,14 +617,14 @@ static int netif_poll(struct net_device 
  12.181          np->stats.rx_bytes += rx->status;
  12.182  
  12.183          /* Remap the page. */
  12.184 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.185 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.186          mmu->ptr = mfn << PAGE_SHIFT | MMU_MACHPHYS_UPDATE;
  12.187  #else
  12.188          mmu->ptr  = (rx->addr & PAGE_MASK) | MMU_MACHPHYS_UPDATE;
  12.189  #endif
  12.190          mmu->val  = __pa(skb->head) >> PAGE_SHIFT;
  12.191          mmu++;
  12.192 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.193 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.194  	MULTI_update_va_mapping(mcl, (unsigned long)skb->head,
  12.195  				pfn_pte_ma(mfn, PAGE_KERNEL), 0);
  12.196  #else
  12.197 @@ -617,20 +634,20 @@ static int netif_poll(struct net_device 
  12.198  #endif
  12.199          mcl++;
  12.200  
  12.201 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.202 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.203          phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] = mfn;
  12.204 +        GDPRINTK("#### rx_poll     enqueue vdata=%p mfn=%lu ref=%x\n",
  12.205 +                skb->data, mfn, ref);
  12.206  #else
  12.207          phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] = 
  12.208              rx->addr >> PAGE_SHIFT;
  12.209 -#endif
  12.210 +#endif 
  12.211  
  12.212 -#ifdef GRANT_DEBUG
  12.213 -        printk(KERN_ALERT "#### rx_poll     enqueue vdata=%p mfn=%lu ref=%x\n",
  12.214 -               skb->data, mfn, ref);
  12.215 -#endif
  12.216 +
  12.217          __skb_queue_tail(&rxq, skb);
  12.218      }
  12.219  
  12.220 +
  12.221      /* Some pages are no longer absent... */
  12.222      balloon_update_driver_allowance(-work_done);
  12.223  
  12.224 @@ -646,9 +663,9 @@ static int netif_poll(struct net_device 
  12.225      }
  12.226  
  12.227      while ((skb = __skb_dequeue(&rxq)) != NULL) {
  12.228 -#ifdef GRANT_DEBUG
  12.229 -        printk(KERN_ALERT "#### rx_poll     dequeue vdata=%p mfn=%lu\n",
  12.230 -               skb->data, virt_to_mfn(skb->data));
  12.231 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.232 +        GDPRINTK("#### rx_poll     dequeue vdata=%p mfn=%lu\n",
  12.233 +                skb->data, virt_to_mfn(skb->data));
  12.234          dump_packet('d', skb->data, (unsigned long)skb->data);
  12.235  #endif
  12.236          /*
  12.237 @@ -747,7 +764,6 @@ static struct net_device_stats *network_
  12.238      return &np->stats;
  12.239  }
  12.240  
  12.241 -
  12.242  static void network_connect(struct net_device *dev)
  12.243  {
  12.244      struct net_private *np;
  12.245 @@ -787,8 +803,11 @@ static void network_connect(struct net_d
  12.246              tx = &np->tx->ring[requeue_idx++].req;
  12.247  
  12.248              tx->id   = i;
  12.249 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.250 -            tx->addr = 0; /*(ref << PAGE_SHIFT) |*/
  12.251 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.252 +            gnttab_grant_foreign_access_ref(grant_tx_ref[i], np->backend_id, 
  12.253 +                                            virt_to_mfn(np->tx_skbs[i]->data),
  12.254 +                                            GNTMAP_readonly); 
  12.255 +            tx->addr = grant_tx_ref[i] << PAGE_SHIFT; 
  12.256  #else
  12.257              tx->addr = virt_to_mfn(skb->data) << PAGE_SHIFT;
  12.258  #endif
  12.259 @@ -803,9 +822,20 @@ static void network_connect(struct net_d
  12.260      np->tx->req_prod = requeue_idx;
  12.261  
  12.262      /* Rebuild the RX buffer freelist and the RX ring itself. */
  12.263 -    for (requeue_idx = 0, i = 1; i <= NETIF_RX_RING_SIZE; i++)
  12.264 -        if ((unsigned long)np->rx_skbs[i] >= __PAGE_OFFSET)
  12.265 -            np->rx->ring[requeue_idx++].req.id = i;
  12.266 +    for (requeue_idx = 0, i = 1; i <= NETIF_RX_RING_SIZE; i++) { 
  12.267 +        if ((unsigned long)np->rx_skbs[i] >= __PAGE_OFFSET) {
  12.268 +#ifdef CONFIG_XEN_NETDEV_GRANT 
  12.269 +            /* Reinstate the grant ref so backend can 'donate' mfn to us. */
  12.270 +            gnttab_grant_foreign_transfer_ref(grant_rx_ref[i], np->backend_id,
  12.271 +                                              virt_to_mfn(np->rx_skbs[i]->head)
  12.272 +                );
  12.273 +            np->rx->ring[requeue_idx].req.gref = grant_rx_ref[i];
  12.274 +#endif
  12.275 +            np->rx->ring[requeue_idx].req.id   = i;
  12.276 +            requeue_idx++; 
  12.277 +        }
  12.278 +    }
  12.279 +
  12.280      wmb();                
  12.281      np->rx->req_prod = requeue_idx;
  12.282  
  12.283 @@ -901,13 +931,14 @@ static int create_netdev(int handle, str
  12.284      /* Initialise {tx,rx}_skbs to be a free chain containing every entry. */
  12.285      for (i = 0; i <= NETIF_TX_RING_SIZE; i++) {
  12.286          np->tx_skbs[i] = (void *)((unsigned long) i+1);
  12.287 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.288 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.289          grant_tx_ref[i] = GRANT_INVALID_REF;
  12.290  #endif
  12.291      }
  12.292 +
  12.293      for (i = 0; i <= NETIF_RX_RING_SIZE; i++) {
  12.294          np->rx_skbs[i] = (void *)((unsigned long) i+1);
  12.295 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.296 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.297          grant_rx_ref[i] = GRANT_INVALID_REF;
  12.298  #endif
  12.299      }
  12.300 @@ -991,10 +1022,8 @@ static int setup_device(struct xenbus_de
  12.301  	evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound };
  12.302  	int err;
  12.303  
  12.304 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.305 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.306  	info->tx_ring_ref = GRANT_INVALID_REF;
  12.307 -#endif
  12.308 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.309  	info->rx_ring_ref = GRANT_INVALID_REF;
  12.310  #endif
  12.311  
  12.312 @@ -1014,7 +1043,7 @@ static int setup_device(struct xenbus_de
  12.313  	memset(info->rx, 0, PAGE_SIZE);
  12.314  	info->backend_state = BEST_DISCONNECTED;
  12.315  
  12.316 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.317 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.318  	err = gnttab_grant_foreign_access(info->backend_id,
  12.319  					  virt_to_mfn(info->tx), 0);
  12.320  	if (err < 0) {
  12.321 @@ -1022,11 +1051,7 @@ static int setup_device(struct xenbus_de
  12.322  		goto out;
  12.323  	}
  12.324  	info->tx_ring_ref = err;
  12.325 -#else
  12.326 -	info->tx_ring_ref = virt_to_mfn(info->tx);
  12.327 -#endif
  12.328  
  12.329 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.330  	err = gnttab_grant_foreign_access(info->backend_id,
  12.331  					  virt_to_mfn(info->rx), 0);
  12.332  	if (err < 0) {
  12.333 @@ -1034,7 +1059,9 @@ static int setup_device(struct xenbus_de
  12.334  		goto out;
  12.335  	}
  12.336  	info->rx_ring_ref = err;
  12.337 +
  12.338  #else
  12.339 +	info->tx_ring_ref = virt_to_mfn(info->tx);
  12.340  	info->rx_ring_ref = virt_to_mfn(info->rx);
  12.341  #endif
  12.342  
  12.343 @@ -1054,16 +1081,17 @@ static int setup_device(struct xenbus_de
  12.344  	if (info->rx)
  12.345  		free_page((unsigned long)info->rx);
  12.346  	info->rx = 0;
  12.347 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.348 +
  12.349 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.350  	if (info->tx_ring_ref != GRANT_INVALID_REF)
  12.351  		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  12.352  	info->tx_ring_ref = GRANT_INVALID_REF;
  12.353 -#endif
  12.354 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.355 +
  12.356  	if (info->rx_ring_ref != GRANT_INVALID_REF)
  12.357  		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  12.358  	info->rx_ring_ref = GRANT_INVALID_REF;
  12.359  #endif
  12.360 +
  12.361  	return err;
  12.362  }
  12.363  
  12.364 @@ -1075,16 +1103,17 @@ static void netif_free(struct netfront_i
  12.365  	if (info->rx)
  12.366  		free_page((unsigned long)info->rx);
  12.367  	info->rx = 0;
  12.368 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.369 +
  12.370 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.371  	if (info->tx_ring_ref != GRANT_INVALID_REF)
  12.372  		gnttab_end_foreign_access(info->tx_ring_ref, 0);
  12.373  	info->tx_ring_ref = GRANT_INVALID_REF;
  12.374 -#endif
  12.375 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.376 +
  12.377  	if (info->rx_ring_ref != GRANT_INVALID_REF)
  12.378  		gnttab_end_foreign_access(info->rx_ring_ref, 0);
  12.379  	info->rx_ring_ref = GRANT_INVALID_REF;
  12.380  #endif
  12.381 +
  12.382  	unbind_evtchn_from_irqhandler(info->evtchn, info->netdev);
  12.383  	info->evtchn = 0;
  12.384  }
  12.385 @@ -1294,6 +1323,7 @@ static int netfront_resume(struct xenbus
  12.386  	int err;
  12.387  
  12.388  	err = talk_to_backend(dev, np);
  12.389 +
  12.390  	return err;
  12.391  }
  12.392  
  12.393 @@ -1342,29 +1372,28 @@ static int __init netif_init(void)
  12.394      if (xen_start_info.flags & SIF_INITDOMAIN)
  12.395          return 0;
  12.396  
  12.397 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.398 -    /* A grant for every ring slot */
  12.399 +    if ((err = xennet_proc_init()) != 0)
  12.400 +        return err;
  12.401 +
  12.402 +    IPRINTK("Initialising virtual ethernet driver.\n");
  12.403 +
  12.404 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.405 +    IPRINTK("Using grant tables.\n"); 
  12.406 +
  12.407 +    /* A grant for every tx ring slot */
  12.408      if (gnttab_alloc_grant_references(NETIF_TX_RING_SIZE,
  12.409                                        &gref_tx_head) < 0) {
  12.410          printk(KERN_ALERT "#### netfront can't alloc tx grant refs\n");
  12.411          return 1;
  12.412      }
  12.413 -    printk(KERN_ALERT "Netdev frontend (TX) is using grant tables.\n"); 
  12.414 -#endif
  12.415 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.416 -    /* A grant for every ring slot */
  12.417 +    /* A grant for every rx ring slot */
  12.418      if (gnttab_alloc_grant_references(NETIF_RX_RING_SIZE,
  12.419                                        &gref_rx_head) < 0) {
  12.420          printk(KERN_ALERT "#### netfront can't alloc rx grant refs\n");
  12.421          return 1;
  12.422      }
  12.423 -    printk(KERN_ALERT "Netdev frontend (RX) is using grant tables.\n"); 
  12.424  #endif
  12.425  
  12.426 -    if ((err = xennet_proc_init()) != 0)
  12.427 -        return err;
  12.428 -
  12.429 -    IPRINTK("Initialising virtual ethernet driver.\n");
  12.430  
  12.431      (void)register_inetaddr_notifier(&notifier_inetdev);
  12.432  
  12.433 @@ -1377,10 +1406,8 @@ static int __init netif_init(void)
  12.434  
  12.435  static void netif_exit(void)
  12.436  {
  12.437 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
  12.438 +#ifdef CONFIG_XEN_NETDEV_GRANT
  12.439      gnttab_free_grant_references(gref_tx_head);
  12.440 -#endif
  12.441 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
  12.442      gnttab_free_grant_references(gref_rx_head);
  12.443  #endif
  12.444  }
    13.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Thu Sep 01 11:09:16 2005 -0800
    13.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c	Thu Sep 01 20:19:34 2005 -0800
    13.3 @@ -212,7 +212,7 @@ int xb_init_comms(void)
    13.4  		xen_start_info.store_evtchn, wake_waiting,
    13.5  		0, "xenbus", &xb_waitq);
    13.6  	if (err) {
    13.7 -		printk(KERN_ERR "XENBUS request irq failed %i\n", err);
    13.8 +		xprintk("XENBUS request irq failed %i\n", err);
    13.9  		unbind_evtchn_from_irq(xen_start_info.store_evtchn);
   13.10  		return err;
   13.11  	}
    14.1 --- a/tools/console/daemon/utils.c	Thu Sep 01 11:09:16 2005 -0800
    14.2 +++ b/tools/console/daemon/utils.c	Thu Sep 01 20:19:34 2005 -0800
    14.3 @@ -234,7 +234,7 @@ bool xen_setup(void)
    14.4  	}
    14.5  
    14.6  	if (!xs_watch(xs, "/console", "console")) {
    14.7 -		dolog(LOG_ERR, "xenstore watch on /console failes.");
    14.8 +		dolog(LOG_ERR, "xenstore watch on /console fails.");
    14.9  		goto out_close_data;
   14.10  	}
   14.11  
    15.1 --- a/xen/common/domain.c	Thu Sep 01 11:09:16 2005 -0800
    15.2 +++ b/xen/common/domain.c	Thu Sep 01 20:19:34 2005 -0800
    15.3 @@ -178,6 +178,9 @@ void domain_shutdown(u8 reason)
    15.4      struct domain *d = current->domain;
    15.5      struct vcpu *v;
    15.6  
    15.7 +    if(reason == SHUTDOWN_crash) 
    15.8 +        printk("Domain %d crash detected.\n", d->domain_id); 
    15.9 +
   15.10      if ( d->domain_id == 0 )
   15.11      {
   15.12          extern void machine_restart(char *);
    16.1 --- a/xen/common/grant_table.c	Thu Sep 01 11:09:16 2005 -0800
    16.2 +++ b/xen/common/grant_table.c	Thu Sep 01 20:19:34 2005 -0800
    16.3 @@ -887,21 +887,21 @@ gnttab_donate(gnttab_donate_t *uop, unsi
    16.4                     e->tot_pages, e->max_pages);
    16.5              spin_unlock(&e->page_alloc_lock);
    16.6              put_domain(e);
    16.7 -            result = GNTST_general_error;
    16.8 +            gop->status = result = GNTST_general_error;
    16.9              break;
   16.10          }
   16.11          if (unlikely(test_bit(DOMFLAGS_DYING, &e->domain_flags))) {
   16.12              printk("gnttab_donate: target domain is dying\n");
   16.13              spin_unlock(&e->page_alloc_lock);
   16.14              put_domain(e);
   16.15 -            result = GNTST_general_error;
   16.16 +            gop->status = result = GNTST_general_error;
   16.17              break;
   16.18          }
   16.19          if (unlikely(!gnttab_prepare_for_transfer(e, d, gop->handle))) {
   16.20 -            printk("gnttab_donate: gnttab_prepare_for_transfer fails\n");
   16.21 +            printk("gnttab_donate: gnttab_prepare_for_transfer fails.\n");
   16.22              spin_unlock(&e->page_alloc_lock);
   16.23              put_domain(e);
   16.24 -            result = GNTST_general_error;
   16.25 +            gop->status = result = GNTST_general_error;
   16.26              break;
   16.27          }
   16.28  #else
   16.29 @@ -914,7 +914,8 @@ gnttab_donate(gnttab_donate_t *uop, unsi
   16.30                     e->tot_pages, e->max_pages, gop->handle, e->d_flags);
   16.31              spin_unlock(&e->page_alloc_lock);
   16.32              put_domain(e);
   16.33 -            result = GNTST_general_error;
   16.34 +            /* XXX SMH: better error return here would be useful */
   16.35 +            gop->status = result = GNTST_general_error;
   16.36              break;
   16.37          }
   16.38  #endif
   16.39 @@ -1020,7 +1021,7 @@ gnttab_check_unmap(
   16.40      lgt = ld->grant_table;
   16.41      
   16.42  #if GRANT_DEBUG_VERBOSE
   16.43 -    if ( ld->domain_ id != 0 ) {
   16.44 +    if ( ld->domain_id != 0 ) {
   16.45              DPRINTK("Foreign unref rd(%d) ld(%d) frm(%lx) flgs(%x).\n",
   16.46                      rd->domain_id, ld->domain_id, frame, readonly);
   16.47        }
    17.1 --- a/xen/include/public/io/netif.h	Thu Sep 01 11:09:16 2005 -0800
    17.2 +++ b/xen/include/public/io/netif.h	Thu Sep 01 20:19:34 2005 -0800
    17.3 @@ -23,13 +23,13 @@ typedef struct netif_tx_response {
    17.4  
    17.5  typedef struct {
    17.6      u16       id;    /* Echoed in response message.        */
    17.7 -#ifdef CONFIG_XEN_NETDEV_GRANT_RX
    17.8 +#ifdef CONFIG_XEN_NETDEV_GRANT
    17.9      grant_ref_t gref;	/* 2: Reference to incoming granted frame */
   17.10  #endif
   17.11  } netif_rx_request_t;
   17.12  
   17.13  typedef struct {
   17.14 -#ifdef CONFIG_XEN_NETDEV_GRANT_TX
   17.15 +#ifdef CONFIG_XEN_NETDEV_GRANT
   17.16      u32      addr;   /*  0: Offset in page of start of received packet  */
   17.17  #else
   17.18      unsigned long addr; /* Machine address of packet.              */