Skip to contentSkip to conversation

: Add scatter and gather support

RFC In review Herbert Xu 2 participants 6 messages May 31, 2006 – Jun 2, 2006

lore
Share & tools
lore

Herbert Xu

author
#0 lore raw

cover : Add scatter and gather support

Hi:

The following patches add scatter-and-gather support in the domU => dom0 direction. This is a precursor to adding TSO in the same direction. If everyone's happy with this approach then it's trivial to do the same thing for the opposite direction.

SG support is required to support skb's larger than one page. This in turn is needed for either jumbo MTU or TSO. One of these is required to bring local networking performance up to a level that is acceptable.

Testing SG support without TSO is a bit tricky because the xen bridge won't pass any packets larger than the MTU of all its constituents. The easiest way to test it is to add an address to the xenbr0 interface and a route with a specific advmss.

On the frontend:

# ifconfig eth0 x.y.z.u netmask 255.255.255.0 mtu 16436

On the backend:

# ip a a dev xenbr0 x.y.z.v/32
# ip r a x.y.z.u dev xenbr0 advmss 16396

This should get you going. Now for some numbers:

netperf -t TCP_STREAM -H x.y.z.u -- -s 65536,65536 -S 65536,65536

baseline: 778.96Mb/s
mtu=16436: 2815.60Mb/s
mtu=60040: 4410.02Mb/s

lo(16436): 5508.34Mb/s
lo(60040): 8508.91Mb/s

Don't pay too much attention to the absolute numbers, it's a fairly modest laptop. However, the rate of increase is self-evident.

I'll post a set of TSO patches soon.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#1 lore raw

RFC 1/2 back: Add SG support

Hi:

[NET] back: Add SG support

This patch adds scatter-and-gather support to the backend. It also advertises this fact through xenbus so that the frontend can detect this and send through SG requests only if it is supported.

SG support is required to support skb's larger than one page. This in turn is needed for either jumbo MTU or TSO. One of these is required to bring local networking performance up to a level that is acceptable.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
linux-2.6-xen-sparse/drivers/xen/netback/netback.c +227 -54
diff -r afabaa39be52 -r f9466d959b1b linux-2.6-xen-sparse/drivers/xen/netback/netback.c
@@ -487,6 +487,178 @@ inline static void net_tx_action_dealloc
 	}
 }
 
+static void netbk_tx_err(netif_t *netif, RING_IDX end)
+{
+	RING_IDX cons = netif->tx.req_cons;
+
+	do {
+		netif_tx_request_t *txp = RING_GET_REQUEST(&netif->tx, cons);
+		make_tx_response(netif, txp->id, NETIF_RSP_ERROR);
+	} while (++cons < end);
+	netif->tx.req_cons = cons;
+	netif_schedule_work(netif);
+	netif_put(netif);
+}
+
+static int netbk_count_requests(netif_t *netif, netif_tx_request_t *txp,
+				int work_to_do)
+{
+	netif_tx_request_t *first = txp;
+	RING_IDX cons = netif->tx.req_cons;
+	int frags = 1;
+
+	while (txp->flags & NETTXF_more_data) {
+		if (frags >= work_to_do) {
+			DPRINTK("Need more frags\n");
+			return -frags;
+		}
+
+		txp = RING_GET_REQUEST(&netif->tx, cons + frags);
+		if (txp->size > first->size) {
+			DPRINTK("Frags galore\n");
+			return -frags;
+		}
+
+		first->size -= txp->size;
+		frags++;
+
+		if (unlikely((txp->offset + txp->size) > PAGE_SIZE)) {
+			DPRINTK("txp->offset: %x, size: %u\n",
+				txp->offset, txp->size);
+			return -frags;
+		}
+	}
+
+	return frags;
+}
+
+static gnttab_map_grant_ref_t *netbk_get_requests(netif_t *netif,
+						  struct sk_buff *skb,
+						  gnttab_map_grant_ref_t *mop)
+{
+	struct skb_shared_info *shinfo = skb_shinfo(skb);
+	skb_frag_t *frags = shinfo->frags;
+	netif_tx_request_t *txp;
+	unsigned long pending_idx = *((u16 *)skb->data);
+	int nr_frags = shinfo->nr_frags;
+	RING_IDX cons = netif->tx.req_cons + 1;
+	int i;
+
+	if ((unsigned long)shinfo->frags[0].page == pending_idx) {
+		frags++;
+		nr_frags--;
+	}
+
+	for (i = 0; i < nr_frags; i++) {
+		txp = RING_GET_REQUEST(&netif->tx, cons + i);
+		pending_idx = pending_ring[MASK_PEND_IDX(pending_cons++)];
+
+		gnttab_set_map_op(mop++, MMAP_VADDR(pending_idx),
+				  GNTMAP_host_map | GNTMAP_readonly,
+				  txp->gref, netif->domid);
+
+		memcpy(&pending_tx_info[pending_idx].req, txp, sizeof(*txp));
+		netif_get(netif);
+		pending_tx_info[pending_idx].netif = netif;
+		frags[i].page = (void *)pending_idx;
+	}
+
+	return mop;
+}
+
+static int netbk_tx_check_mop(struct sk_buff *skb,
+			       gnttab_map_grant_ref_t **mopp)
+{
+	gnttab_map_grant_ref_t *mop = *mopp;
+	int pending_idx = *((u16 *)skb->data);
+	netif_t *netif = pending_tx_info[pending_idx].netif;
+	netif_tx_request_t *txp;
+	struct skb_shared_info *shinfo = skb_shinfo(skb);
+	int nr_frags = shinfo->nr_frags;
+	int start;
+	int err;
+	int i;
+
+	err = mop->status;
+	if (unlikely(err)) {
+		txp = &pending_tx_info[pending_idx].req;
+		make_tx_response(netif, txp->id, NETIF_RSP_ERROR);
+		pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
+		netif_put(netif);
+	} else {
+		set_phys_to_machine(
+			__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
+			FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
+		grant_tx_handle[pending_idx] = mop->handle;
+	}
+
+	start = 0;
+	if ((unsigned long)shinfo->frags[0].page == pending_idx)
+		start++;
+
+	for (i = start; i < nr_frags; i++) {
+		int newerr;
+		int j;
+
+		pending_idx = (unsigned long)shinfo->frags[i].page;
+
+		newerr = (++mop)->status;
+		if (likely(!newerr)) {
+			set_phys_to_machine(
+				__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
+				FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
+			grant_tx_handle[pending_idx] = mop->handle;
+
+			if (unlikely(err))
+				netif_idx_release(pending_idx);
+			continue;
+		}
+
+		txp = &pending_tx_info[pending_idx].req;
+		make_tx_response(netif, txp->id, NETIF_RSP_ERROR);
+		pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
+		netif_put(netif);
+
+		if (err)
+			continue;
+
+		pending_idx = *((u16 *)skb->data);
+		netif_idx_release(pending_idx);
+
+		for (j = start; j < i; j++) {
+			pending_idx = (unsigned long)shinfo->frags[i].page;
+			netif_idx_release(pending_idx);
+		}
+		err |= newerr;
+	}
+
+	*mopp = mop + 1;
+	return err;
+}
+
+static void netbk_fill_frags(struct sk_buff *skb)
+{
+	struct skb_shared_info *shinfo = skb_shinfo(skb);
+	int nr_frags = shinfo->nr_frags;
+	int i;
+
+	for (i = 0; i < nr_frags; i++) {
+		skb_frag_t *frag = shinfo->frags + i;
+		netif_tx_request_t *txp;
+		unsigned long pending_idx;
+
+		pending_idx = (unsigned long)frag->page;
+		txp = &pending_tx_info[pending_idx].req;
+		frag->page = virt_to_page(MMAP_VADDR(pending_idx));
+		frag->size = txp->size;
+		frag->page_offset = txp->offset;
+
+		skb->len += txp->size;
+		skb->data_len += txp->size;
+		skb->truesize += txp->size;
+	}
+}
+
 /* Called after netfront has transmitted */
 static void net_tx_action(unsigned long unused)
 {
@@ -504,7 +676,7 @@ static void net_tx_action(unsigned long 
 		net_tx_action_dealloc();
 
 	mop = tx_map_ops;
-	while ((NR_PENDING_REQS < MAX_PENDING_REQS) &&
+	while (((NR_PENDING_REQS + MAX_SKB_FRAGS) < MAX_PENDING_REQS) &&
 		!list_empty(&net_schedule_list)) {
 		/* Get a netif from the list with work to do. */
 		ent = net_schedule_list.next;
@@ -552,38 +724,44 @@ static void net_tx_action(unsigned long 
 		}
 		netif->remaining_credit -= txreq.size;
 
-		netif->tx.req_cons++;
-
-		netif_schedule_work(netif);
-
-		if (unlikely(txreq.size < ETH_HLEN) || 
-		    unlikely(txreq.size > ETH_FRAME_LEN)) {
+		ret = netbk_count_requests(netif, &txreq, work_to_do);
+		if (unlikely(ret < 0)) {
+			netbk_tx_err(netif, i - ret);
+			continue;
+		}
+		i += ret;
+
+		if (unlikely(ret > MAX_SKB_FRAGS + 1)) {
+			DPRINTK("Too many frags\n");
+			netbk_tx_err(netif, i);
+			continue;
+		}
+
+		if (unlikely(txreq.size < ETH_HLEN)) {
 			DPRINTK("Bad packet size: %d\n", txreq.size);
-			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
-			netif_put(netif);
+			netbk_tx_err(netif, i);
 			continue; 
 		}
 
 		/* No crossing a page as the payload mustn't fragment. */
-		if (unlikely((txreq.offset + txreq.size) >= PAGE_SIZE)) {
+		if (unlikely((txreq.offset + txreq.size) > PAGE_SIZE)) {
 			DPRINTK("txreq.offset: %x, size: %u, end: %lu\n", 
 				txreq.offset, txreq.size, 
 				(txreq.offset &~PAGE_MASK) + txreq.size);
-			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
-			netif_put(netif);
+			netbk_tx_err(netif, i);
 			continue;
 		}
 
 		pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
 
-		data_len = (txreq.size > PKT_PROT_LEN) ?
+		data_len = (txreq.size > PKT_PROT_LEN &&
+			    ret < MAX_SKB_FRAGS + 1) ?
 			PKT_PROT_LEN : txreq.size;
 
 		skb = alloc_skb(data_len+16, GFP_ATOMIC);
 		if (unlikely(skb == NULL)) {
 			DPRINTK("Can't allocate a skb in start_xmit.\n");
-			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
-			netif_put(netif);
+			netbk_tx_err(netif, i);
 			break;
 		}
 
@@ -600,9 +778,23 @@ static void net_tx_action(unsigned long 
 		pending_tx_info[pending_idx].netif = netif;
 		*((u16 *)skb->data) = pending_idx;
 
+		__skb_put(skb, data_len);
+
+		skb_shinfo(skb)->nr_frags = ret - 1;
+		if (data_len < txreq.size) {
+			skb_shinfo(skb)->nr_frags++;
+			skb_shinfo(skb)->frags[0].page =
+				(void *)(unsigned long)pending_idx;
+		}
+
 		__skb_queue_tail(&tx_queue, skb);
 
 		pending_cons++;
+
+		mop = netbk_get_requests(netif, skb, mop);
+
+		netif->tx.req_cons = i;
+		netif_schedule_work(netif);
 
 		if ((mop - tx_map_ops) >= ARRAY_SIZE(tx_map_ops))
 			break;
@@ -617,75 +809,56 @@ static void net_tx_action(unsigned long 
 
 	mop = tx_map_ops;
 	while ((skb = __skb_dequeue(&tx_queue)) != NULL) {
+		netif_tx_request_t *txp;
+
 		pending_idx = *((u16 *)skb->data);
 		netif       = pending_tx_info[pending_idx].netif;
-		memcpy(&txreq, &pending_tx_info[pending_idx].req,
-		       sizeof(txreq));
+		txp         = &pending_tx_info[pending_idx].req;
 
 		/* Check the remap error code. */
-		if (unlikely(mop->status)) {
+		if (unlikely(netbk_tx_check_mop(skb, &mop))) {
 			printk(KERN_ALERT "#### netback grant fails\n");
-			make_tx_response(netif, txreq.id, NETIF_RSP_ERROR);
-			netif_put(netif);
+			skb_shinfo(skb)->nr_frags = 0;
 			kfree_skb(skb);
-			mop++;
-			pending_ring[MASK_PEND_IDX(pending_prod++)] =
-				pending_idx;
 			continue;
 		}
-		set_phys_to_machine(
-			__pa(MMAP_VADDR(pending_idx)) >> PAGE_SHIFT,
-			FOREIGN_FRAME(mop->dev_bus_addr >> PAGE_SHIFT));
-		grant_tx_handle[pending_idx] = mop->handle;
-
-		data_len = (txreq.size > PKT_PROT_LEN) ?
-			PKT_PROT_LEN : txreq.size;
-
-		__skb_put(skb, data_len);
+
+		data_len = skb->len;
 		memcpy(skb->data, 
-		       (void *)(MMAP_VADDR(pending_idx)|txreq.offset),
+		       (void *)(MMAP_VADDR(pending_idx)|txp->offset),
 		       data_len);
-		if (data_len < txreq.size) {
+		if (data_len < txp->size) {
 			/* Append the packet payload as a fragment. */
-			skb_shinfo(skb)->frags[0].page        = 
-				virt_to_page(MMAP_VADDR(pending_idx));
-			skb_shinfo(skb)->frags[0].size        =
-				txreq.size - data_len;
-			skb_shinfo(skb)->frags[0].page_offset = 
-				txreq.offset + data_len;
-			skb_shinfo(skb)->nr_frags = 1;
+			txp->offset += data_len;
+			txp->size -= data_len;
 		} else {
 			/* Schedule a response immediately. */
 			netif_idx_release(pending_idx);
 		}
-
-		skb->data_len  = txreq.size - data_len;
-		skb->len      += skb->data_len;
-		skb->truesize += skb->data_len;
-
-		skb->dev      = netif->dev;
-		skb->protocol = eth_type_trans(skb, skb->dev);
 
 		/*
 		 * Old frontends do not assert data_validated but we
 		 * can infer it from csum_blank so test both flags.
 		 */
-		if (txreq.flags & (NETTXF_data_validated|NETTXF_csum_blank)) {
+		if (txp->flags & (NETTXF_data_validated|NETTXF_csum_blank)) {
 			skb->ip_summed = CHECKSUM_UNNECESSARY;
 			skb->proto_data_valid = 1;
 		} else {
 			skb->ip_summed = CHECKSUM_NONE;
 			skb->proto_data_valid = 0;
 		}
-		skb->proto_csum_blank = !!(txreq.flags & NETTXF_csum_blank);
-
-		netif->stats.rx_bytes += txreq.size;
+		skb->proto_csum_blank = !!(txp->flags & NETTXF_csum_blank);
+
+		netbk_fill_frags(skb);
+
+		skb->dev      = netif->dev;
+		skb->protocol = eth_type_trans(skb, skb->dev);
+
+		netif->stats.rx_bytes += skb->len;
 		netif->stats.rx_packets++;
 
 		netif_rx(skb);
 		netif->dev->last_rx = jiffies;
-
-		mop++;
 	}
 }
 
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c +26 -0
diff -r afabaa39be52 -r f9466d959b1b linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
@@ -69,6 +69,8 @@ static int netback_probe(struct xenbus_d
 static int netback_probe(struct xenbus_device *dev,
 			 const struct xenbus_device_id *id)
 {
+	const char *message;
+	xenbus_transaction_t xbt;
 	int err;
 	struct backend_info *be = kzalloc(sizeof(struct backend_info),
 					  GFP_KERNEL);
@@ -86,6 +88,27 @@ static int netback_probe(struct xenbus_d
 	if (err)
 		goto fail;
 
+	do {
+		err = xenbus_transaction_start(&xbt);
+		if (err) {
+			xenbus_dev_fatal(dev, err, "starting transaction");
+			goto fail;
+		}
+
+		err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1);
+		if (err) {
+			message = "writing feature-sg";
+			goto abort_transaction;
+		}
+
+		err = xenbus_transaction_end(xbt, 0);
+	} while (err == -EAGAIN);
+
+	if (err) {
+		xenbus_dev_fatal(dev, err, "completing transaction");
+		goto fail;
+	}
+
 	err = xenbus_switch_state(dev, XenbusStateInitWait);
 	if (err) {
 		goto fail;
@@ -93,6 +116,9 @@ static int netback_probe(struct xenbus_d
 
 	return 0;
 
+abort_transaction:
+	xenbus_transaction_end(xbt, 1);
+	xenbus_dev_fatal(dev, err, "%s", message);
 fail:
 	DPRINTK("failed");
 	netback_remove(dev);
xen/include/public/io/netif.h +4 -0
diff -r afabaa39be52 -r f9466d959b1b xen/include/public/io/netif.h
@@ -26,6 +26,10 @@
 /* Packet data has been validated against protocol checksum. */
 #define _NETTXF_data_validated (1)
 #define  NETTXF_data_validated (1U<<_NETTXF_data_validated)
+
+/* Packet continues in the request. */
+#define _NETTXF_more_data      (2)
+#define  NETTXF_more_data      (1U<<_NETTXF_more_data)
 
 struct netif_tx_request {
     grant_ref_t gref;      /* Reference to buffer page */
xen/include/public/io/ring.h +7 -3
diff -r afabaa39be52 -r f9466d959b1b xen/include/public/io/ring.h
@@ -159,11 +159,15 @@ typedef struct __name##_back_ring __name
 
 /* Test if there are outstanding messages to be processed on a ring. */
 #define RING_HAS_UNCONSUMED_RESPONSES(_r)                               \
-    ((_r)->rsp_cons != (_r)->sring->rsp_prod)
+    ((_r)->sring->rsp_prod - (_r)->rsp_cons)
 
 #define RING_HAS_UNCONSUMED_REQUESTS(_r)                                \
-    (((_r)->req_cons != (_r)->sring->req_prod) &&                       \
-     (((_r)->req_cons - (_r)->rsp_prod_pvt) != RING_SIZE(_r)))
+    ({									\
+	unsigned int req = (_r)->sring->req_prod - (_r)->req_cons;	\
+	unsigned int rsp = RING_SIZE(_r) -				\
+			   ((_r)->req_cons - (_r)->rsp_prod_pvt);	\
+	req < rsp ? req : rsp;						\
+    })
 
 /* Direct access to individual ring elements, by index. */
 #define RING_GET_REQUEST(_r, _idx)                                      \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

author
#2 lore raw

RFC 2/2 front: Transmit SG packets if supported

In reply to Herbert Xu

Hi:

[NET] front: Transmit SG packets if supported

This patch adds scatter-and-gather transmission support to the frontend. This allows the MTU to be raised right now and the potential for TSO in future.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c +142 -29
diff -r f9466d959b1b linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
@@ -45,6 +45,7 @@
 #include <linux/bitops.h>
 #include <linux/ethtool.h>
 #include <linux/in.h>
+#include <linux/if_ether.h>
 #include <net/sock.h>
 #include <net/pkt_sched.h>
 #include <net/arp.h>
@@ -173,6 +174,11 @@ static void xennet_sysfs_delif(struct ne
 #define xennet_sysfs_delif(dev) do { } while(0)
 #endif
 
+static inline int xennet_can_sg(struct net_device *dev)
+{
+	return dev->features & NETIF_F_SG;
+}
+
 /**
  * Entry point to this code when a new device is created.  Allocate the basic
  * structures and the ring buffers for communication with the backend, and
@@ -307,8 +313,6 @@ again:
 		goto destroy_ring;
 	}
 
-	xenbus_switch_state(dev, XenbusStateConnected);
-
 	return 0;
 
  abort_transaction:
@@ -370,12 +374,9 @@ static int setup_device(struct xenbus_de
 		goto fail;
 
 	memcpy(netdev->dev_addr, info->mac, ETH_ALEN);
-	network_connect(netdev);
 	info->irq = bind_evtchn_to_irqhandler(
 		info->evtchn, netif_int, SA_SAMPLE_RANDOM, netdev->name,
 		netdev);
-	(void)send_fake_arp(netdev);
-	show_device(info);
 
 	return 0;
 
@@ -391,15 +392,24 @@ static void backend_changed(struct xenbu
 static void backend_changed(struct xenbus_device *dev,
 			    enum xenbus_state backend_state)
 {
+	struct netfront_info *np = dev->data;
+	struct net_device *netdev = np->netdev;
+
 	DPRINTK("\n");
 
 	switch (backend_state) {
 	case XenbusStateInitialising:
-	case XenbusStateInitWait:
 	case XenbusStateInitialised:
 	case XenbusStateConnected:
 	case XenbusStateUnknown:
 	case XenbusStateClosed:
+		break;
+
+	case XenbusStateInitWait:
+		network_connect(netdev);
+		xenbus_switch_state(dev, XenbusStateConnected);
+		(void)send_fake_arp(netdev);
+		show_device(np);
 		break;
 
 	case XenbusStateClosing:
@@ -452,13 +462,17 @@ static int network_open(struct net_devic
 	return 0;
 }
 
+static inline int netfront_tx_slot_available(struct netfront_info *np)
+{
+	return RING_FREE_REQUESTS(&np->tx) >= MAX_SKB_FRAGS + 1;
+}
+
 static inline void network_maybe_wake_tx(struct net_device *dev)
 {
 	struct netfront_info *np = netdev_priv(dev);
 
 	if (unlikely(netif_queue_stopped(dev)) &&
-	    !RING_FULL(&np->tx) &&
-	    !gnttab_empty_grant_references(&np->gref_tx_head) &&
+	    netfront_tx_slot_available(np) &&
 	    likely(netif_running(dev)))
 		netif_wake_queue(dev);
 }
@@ -638,36 +652,95 @@ static void network_alloc_rx_buffers(str
 	RING_PUSH_REQUESTS(&np->rx);
 }
 
+static void xennet_make_frags(struct sk_buff *skb, struct net_device *dev,
+			      struct netif_tx_request *tx)
+{
+	struct netfront_info *np = netdev_priv(dev);
+	char *data = skb->data;
+	unsigned long mfn;
+	RING_IDX prod = np->tx.req_prod_pvt;
+	int frags = skb_shinfo(skb)->nr_frags;
+	unsigned int offset = offset_in_page(data);
+	unsigned int len = skb_headlen(skb);
+	unsigned int id;
+	grant_ref_t ref;
+	int i;
+
+	while (len > PAGE_SIZE - offset) {
+		tx->size = PAGE_SIZE - offset;
+		tx->flags |= NETTXF_more_data;
+		len -= tx->size;
+		data += tx->size;
+		offset = 0;
+
+		id = get_id_from_freelist(np->tx_skbs);
+		np->tx_skbs[id] = skb_get(skb);
+		tx = RING_GET_REQUEST(&np->tx, prod++);
+		tx->id = id;
+		ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+		BUG_ON((signed short)ref < 0);
+
+		mfn = virt_to_mfn(data);
+		gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
+						mfn, GNTMAP_readonly);
+
+		tx->gref = np->grant_tx_ref[id] = ref;
+		tx->offset = offset;
+		tx->size = len;
+		tx->flags = 0;
+	}
+
+	for (i = 0; i < frags; i++) {
+		skb_frag_t *frag = skb_shinfo(skb)->frags + i;
+
+		tx->flags |= NETTXF_more_data;
+
+		id = get_id_from_freelist(np->tx_skbs);
+		np->tx_skbs[id] = skb_get(skb);
+		tx = RING_GET_REQUEST(&np->tx, prod++);
+		tx->id = id;
+		ref = gnttab_claim_grant_reference(&np->gref_tx_head);
+		BUG_ON((signed short)ref < 0);
+
+		mfn = pfn_to_mfn(page_to_pfn(frag->page));
+		gnttab_grant_foreign_access_ref(ref, np->xbdev->otherend_id,
+						mfn, GNTMAP_readonly);
+
+		tx->gref = np->grant_tx_ref[id] = ref;
+		tx->offset = frag->page_offset;
+		tx->size = frag->size;
+		tx->flags = 0;
+	}
+
+	np->tx.req_prod_pvt = prod;
+}
 
 static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	unsigned short id;
 	struct netfront_info *np = netdev_priv(dev);
 	struct netif_tx_request *tx;
+	char *data = skb->data;
 	RING_IDX i;
 	grant_ref_t ref;
 	unsigned long mfn;
 	int notify;
-
-	if (unlikely((((unsigned long)skb->data & ~PAGE_MASK) + skb->len) >=
-		     PAGE_SIZE)) {
-		struct sk_buff *nskb;
-		nskb = __dev_alloc_skb(skb->len, GFP_ATOMIC|__GFP_NOWARN);
-		if (unlikely(nskb == NULL))
-			goto drop;
-		skb_put(nskb, skb->len);
-		memcpy(nskb->data, skb->data, skb->len);
-		/* Copy only the header fields we use in this driver. */
-		nskb->dev = skb->dev;
-		nskb->ip_summed = skb->ip_summed;
-		nskb->proto_data_valid = skb->proto_data_valid;
-		dev_kfree_skb(skb);
-		skb = nskb;
+	int frags = skb_shinfo(skb)->nr_frags;
+	unsigned int offset = offset_in_page(data);
+	unsigned int len = skb_headlen(skb);
+
+	frags += (offset + len + PAGE_SIZE - 1) / PAGE_SIZE;
+	if (unlikely(frags > MAX_SKB_FRAGS + 1)) {
+		printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n",
+		       frags);
+		dump_stack();
+		goto drop;
 	}
 
 	spin_lock_irq(&np->tx_lock);
 
-	if (unlikely(!netif_carrier_ok(dev))) {
+	if (unlikely(!netif_carrier_ok(dev) ||
+		     (frags > 1 && !xennet_can_sg(dev)))) {
 		spin_unlock_irq(&np->tx_lock);
 		goto drop;
 	}
@@ -682,12 +755,12 @@ static int network_start_xmit(struct sk_
 	tx->id   = id;
 	ref = gnttab_claim_grant_reference(&np->gref_tx_head);
 	BUG_ON((signed short)ref < 0);
-	mfn = virt_to_mfn(skb->data);
+	mfn = virt_to_mfn(data);
 	gnttab_grant_foreign_access_ref(
 		ref, np->xbdev->otherend_id, mfn, GNTMAP_readonly);
 	tx->gref = np->grant_tx_ref[id] = ref;
-	tx->offset = (unsigned long)skb->data & ~PAGE_MASK;
-	tx->size = skb->len;
+	tx->offset = offset;
+	tx->size = len;
 
 	tx->flags = 0;
 	if (skb->ip_summed == CHECKSUM_HW) /* local packet? */
@@ -696,14 +769,17 @@ static int network_start_xmit(struct sk_
 		tx->flags |= NETTXF_data_validated;
 
 	np->tx.req_prod_pvt = i + 1;
+
+	xennet_make_frags(skb, dev, tx);
+	tx->size = skb->len;
+
 	RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&np->tx, notify);
 	if (notify)
 		notify_remote_via_irq(np->irq);
 
 	network_tx_buf_gc(dev);
 
-	if (RING_FULL(&np->tx) ||
-	    gnttab_empty_grant_references(&np->gref_tx_head))
+	if (!netfront_tx_slot_available(np))
 		netif_stop_queue(dev);
 
 	spin_unlock_irq(&np->tx_lock);
@@ -963,12 +1039,46 @@ static struct net_device_stats *network_
 	return &np->stats;
 }
 
+static int xennet_change_mtu(struct net_device *dev, int mtu)
+{
+	int max = xennet_can_sg(dev) ? 65535 - ETH_HLEN : ETH_DATA_LEN;
+
+	if (mtu > max)
+		return -EINVAL;
+	dev->mtu = mtu;
+	return 0;
+}
+
+static int xennet_set_sg(struct net_device *dev, u32 data)
+{
+	if (data) {
+		struct netfront_info *np = netdev_priv(dev);
+		int val;
+
+		if (xenbus_scanf(XBT_NULL, np->xbdev->otherend, "feature-sg",
+				 "%d", &val) < 0)
+			val = 0;
+		if (!val)
+			return -ENOSYS;
+	} else if (dev->mtu > ETH_DATA_LEN)
+		dev->mtu = ETH_DATA_LEN;
+
+	return ethtool_op_set_sg(dev, data);
+}
+
+static void xennet_set_features(struct net_device *dev)
+{
+	xennet_set_sg(dev, 1);
+}
+
 static void network_connect(struct net_device *dev)
 {
 	struct netfront_info *np;
 	int i, requeue_idx;
 	struct netif_tx_request *tx;
 	struct sk_buff *skb;
+
+	xennet_set_features(dev);
 
 	np = netdev_priv(dev);
 	spin_lock_irq(&np->tx_lock);
@@ -1081,6 +1191,8 @@ static struct ethtool_ops network_ethtoo
 {
 	.get_tx_csum = ethtool_op_get_tx_csum,
 	.set_tx_csum = ethtool_op_set_tx_csum,
+	.get_sg = ethtool_op_get_sg,
+	.set_sg = xennet_set_sg,
 };
 
 #ifdef CONFIG_SYSFS
@@ -1297,6 +1409,7 @@ static struct net_device * __devinit cre
 	netdev->poll            = netif_poll;
 	netdev->set_multicast_list = network_set_multicast_list;
 	netdev->uninit          = netif_uninit;
+	netdev->change_mtu	= xennet_change_mtu;
 	netdev->weight          = 64;
 	netdev->features        = NETIF_F_IP_CSUM;
 
xen/include/public/io/ring.h +5 -1
diff -r f9466d959b1b xen/include/public/io/ring.h
@@ -151,11 +151,15 @@ typedef struct __name##_back_ring __name
 #define RING_SIZE(_r)                                                   \
     ((_r)->nr_ents)
 
+/* Number of free requests (for use on front side only). */
+#define RING_FREE_REQUESTS(_r)						\
+    (RING_SIZE(_r) - ((_r)->req_prod_pvt - (_r)->rsp_cons))
+
 /* Test if there is an empty slot available on the front ring.
  * (This is only meaningful from the front. )
  */
 #define RING_FULL(_r)                                                   \
-    (((_r)->req_prod_pvt - (_r)->rsp_cons) == RING_SIZE(_r))
+    (RING_FREE_REQUESTS(_r) == 0)
 
 /* Test if there are outstanding messages to be processed on a ring. */
 #define RING_HAS_UNCONSUMED_RESPONSES(_r)                               \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
In reply to Herbert Xu
Quoted 4 lines · Herbert Xu

The following patches add scatter-and-gather support in the domU => dom0 direction. This is a precursor to adding TSO in the same direction. If everyone's happy with this approach then it's trivial to do the same thing for the opposite direction.

Thanks! I'll need a bit of time to read through these patches but my first impression is they look very good.

Just one question so far: you modify some of the macros in ring.h but don't actually use those macros in your patch. Is there a reason for the changes?

-- Keir

author
#4 lore raw
Quoted 4 lines · Keir Fraser

Just one question so far: you modify some of the macros in ring.h but don't actually use those macros in your patch. Is there a reason for the changes?

Some of the modified macros are used in this patch. The rest are there for consistency and will be used when I do the opposite direction for dom0 => domU.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
author
#5 lore raw

[NET] loopback: Added support for SG

In reply to Herbert Xu

Hi:

This patch allows us to use jumbo frames through the looped eth0 device rather than only on xenbr0.

[NET] loopback: Added support for SG

Just like the standard loopback device, SG support here is innate. So all we need to do is mark it as such and zero the change_mtu method so that the MTU can be changed at will.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
linux-2.6-xen-sparse/drivers/xen/netback/loopback.c +2 -0
diff -r a4e3b3286aac linux-2.6-xen-sparse/drivers/xen/netback/loopback.c
@@ -146,11 +146,13 @@ static void loopback_construct(struct ne
 	dev->hard_start_xmit = loopback_start_xmit;
 	dev->get_stats       = loopback_get_stats;
 	dev->set_multicast_list = loopback_set_multicast_list;
+	dev->change_mtu	     = NULL;
 
 	dev->tx_queue_len    = 0;
 
 	dev->features        = (NETIF_F_HIGHDMA |
 				NETIF_F_LLTX |
+				NETIF_F_SG |
 				NETIF_F_IP_CSUM);
 
 	SET_ETHTOOL_OPS(dev, &network_ethtool_ops);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel