From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Andi Kleen <ak@suse.de>
Cc: Chris Wright <chrisw@sous-sol.org>,
virtualization@lists.osdl.org,
Andrew Morton <akpm@linux-foundation.org>,
lkml <linux-kernel@vger.kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>
Subject: [patch 26/29] xen: fix netfront checksums
Date: Fri, 04 May 2007 16:21:17 -0700 [thread overview]
Message-ID: <20070504232121.554055808@goop.org> (raw)
In-Reply-To: 20070504232051.411946839@goop.org
[-- Attachment #1: xen-netfront-csum-fixes.patch --]
[-- Type: text/plain, Size: 4161 bytes --]
If we receive a partially checksummed packed, we need to work out how
much of it was checksummed based on its protocol. The ideal would be
that Xen could tell us how much is checksummed, but in the meantime
we'll make do with this.
[ This is a separate patch for review; will be folded into
xen-netfront later. ]
From: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
drivers/net/xen-netfront.c | 76 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 68 insertions(+), 8 deletions(-)
===================================================================
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -35,10 +35,12 @@
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#include <linux/ethtool.h>
-#include <linux/in.h>
#include <linux/if_ether.h>
+#include <linux/tcp.h>
+#include <linux/udp.h>
#include <linux/moduleparam.h>
#include <linux/mm.h>
+#include <net/ip.h>
#include <xen/xenbus.h>
#include <xen/events.h>
@@ -564,8 +566,12 @@ static int xennet_start_xmit(struct sk_b
extra = NULL;
tx->flags = 0;
- if (skb->ip_summed == CHECKSUM_PARTIAL) /* local packet? */
+ if (skb->ip_summed == CHECKSUM_PARTIAL)
+ /* local packet? */
tx->flags |= NETTXF_csum_blank | NETTXF_data_validated;
+ else if (skb->ip_summed == CHECKSUM_UNNECESSARY)
+ /* remote but checksummed. */
+ tx->flags |= NETTXF_data_validated;
if (skb_shinfo(skb)->gso_size) {
struct xen_netif_extra_info *gso;
@@ -867,9 +873,50 @@ static RING_IDX xennet_fill_frags(struct
return cons;
}
-static void handle_incoming_queue(struct net_device *dev,
+static int skb_checksum_setup(struct sk_buff *skb)
+{
+ struct iphdr *iph;
+ unsigned char *th;
+ int err = -EPROTO;
+
+ if (skb->protocol != htons(ETH_P_IP))
+ goto out;
+
+ iph = (void *)skb->data;
+ th = skb->data + 4 * iph->ihl;
+ if (th >= skb_tail_pointer(skb))
+ goto out;
+
+ skb->csum_start = th - skb->head;
+ switch (iph->protocol) {
+ case IPPROTO_TCP:
+ skb->csum_offset = offsetof(struct tcphdr, check);
+ break;
+ case IPPROTO_UDP:
+ skb->csum_offset = offsetof(struct udphdr, check);
+ break;
+ default:
+ if (net_ratelimit())
+ printk(KERN_ERR "Attempting to checksum a non-"
+ "TCP/UDP packet, dropping a protocol"
+ " %d packet", iph->protocol);
+ goto out;
+ }
+
+ if ((th + skb->csum_offset + 2) > skb_tail_pointer(skb))
+ goto out;
+
+ err = 0;
+
+out:
+ return err;
+}
+
+static int handle_incoming_queue(struct net_device *dev,
struct sk_buff_head *rxq)
{
+ struct netfront_info *np = netdev_priv(dev);
+ int packets_dropped = 0;
struct sk_buff *skb;
while ((skb = __skb_dequeue(rxq)) != NULL) {
@@ -886,10 +933,24 @@ static void handle_incoming_queue(struct
/* Ethernet work: Delayed to here as it peeks the header. */
skb->protocol = eth_type_trans(skb, dev);
+ if (skb->ip_summed == CHECKSUM_PARTIAL) {
+ if (skb_checksum_setup(skb)) {
+ kfree_skb(skb);
+ packets_dropped++;
+ np->stats.rx_errors++;
+ continue;
+ }
+ }
+
+ np->stats.rx_packets++;
+ np->stats.rx_bytes += skb->len;
+
/* Pass it up. */
netif_receive_skb(skb);
dev->last_rx = jiffies;
}
+
+ return packets_dropped;
}
static int xennet_poll(struct net_device *dev, int *pbudget)
@@ -1003,11 +1064,10 @@ err:
skb->truesize += skb->data_len - (RX_COPY_THRESHOLD - len);
skb->len += skb->data_len;
- if (rx->flags & NETRXF_data_validated)
+ if (rx->flags & NETRXF_csum_blank)
+ skb->ip_summed = CHECKSUM_PARTIAL;
+ else if (rx->flags & NETRXF_data_validated)
skb->ip_summed = CHECKSUM_UNNECESSARY;
-
- np->stats.rx_packets++;
- np->stats.rx_bytes += skb->len;
__skb_queue_tail(&rxq, skb);
@@ -1029,7 +1089,7 @@ err:
while ((skb = __skb_dequeue(&errq)))
kfree_skb(skb);
- handle_incoming_queue(dev, &rxq);
+ work_done -= handle_incoming_queue(dev, &rxq);
/* If we get a callback with very few responses, reduce fill target. */
/* NB. Note exponential increase, linear decrease. */
--
next prev parent reply other threads:[~2007-05-04 23:21 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-04 23:20 [patch 00/29] xen: Xen implementation for paravirt_ops Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 01/29] xen: Add apply_to_page_range() which applies a function to a pte range Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 02/29] xen: Allocate and free vmalloc areas Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 03/29] xen: Add nosegneg capability to the vsyscall page notes Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 04/29] xen: Add Xen interface header files Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 05/29] xen: Core Xen implementation Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 06/29] xen: Xen virtual mmu Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 07/29] xen: xen event channels Jeremy Fitzhardinge
2007-05-04 23:20 ` [patch 08/29] xen: xen time implementation Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 09/29] xen: xen configuration Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 10/29] xen: Complete pagetable pinning for Xen Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 11/29] xen: ignore RW mapping of RO pages in pagetable_init Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 12/29] xen: fix multicall batching Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 13/29] xen: Account for time stolen by Xen Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 14/29] xen: Implement xen_sched_clock Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 15/29] xen: Xen SMP guest support Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 16/29] xen: Add support for preemption Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 17/29] xen: lazy-mmu operations Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 18/29] xen: deal with negative stolen time Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 19/29] xen: Use the hvc console infrastructure for Xen console Jeremy Fitzhardinge
2007-05-06 16:31 ` Olof Johansson
2007-05-04 23:21 ` [patch 20/29] xen: Add early printk support via hvc console Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 21/29] xen: Add Xen grant table support Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 22/29] xen: Add the Xenbus sysfs and virtual device hotplug driver Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 23/29] xen: Add Xen virtual block device driver Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 24/29] xen: rename xen netif_ structures to xen_netif_ Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 25/29] xen: Add the Xen virtual network device driver Jeremy Fitzhardinge
2007-05-05 9:16 ` Christoph Hellwig
2007-05-05 10:05 ` Jeremy Fitzhardinge
2007-05-05 10:23 ` Herbert Xu
2007-05-07 21:10 ` Jeremy Fitzhardinge
2007-05-08 12:13 ` [1/2] [NET] link_watch: Move link watch list into net_device Herbert Xu
2007-05-08 12:16 ` [2/2] [NET] link_watch: Remove delay for up even when we're down Herbert Xu
2007-05-09 1:36 ` David Miller
2007-05-08 20:19 ` [1/2] [NET] link_watch: Move link watch list into net_device Jeremy Fitzhardinge
2007-05-09 1:49 ` Herbert Xu
2007-05-09 1:35 ` David Miller
2007-05-10 22:00 ` Jeremy Fitzhardinge
2007-05-10 22:07 ` David Miller
2007-05-10 22:12 ` Jeremy Fitzhardinge
2007-05-10 22:14 ` Andrew Morton
2007-05-10 22:22 ` Jeremy Fitzhardinge
2007-05-10 22:25 ` David Miller
2007-05-10 22:45 ` Jeremy Fitzhardinge
2007-05-10 22:53 ` Chris Wright
2007-05-10 22:53 ` David Miller
2007-05-05 10:16 ` [patch 25/29] xen: Add the Xen virtual network device driver Rusty Russell
2007-05-07 21:11 ` Jeremy Fitzhardinge
2007-05-07 22:35 ` Rusty Russell
2007-05-08 6:30 ` Jeremy Fitzhardinge
2007-05-08 6:42 ` Rusty Russell
2007-05-04 23:21 ` Jeremy Fitzhardinge [this message]
2007-05-04 23:21 ` [patch 27/29] xen: Xen machine operations Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 28/29] xen: Place vcpu_info structure into per-cpu memory, if possible Jeremy Fitzhardinge
2007-05-04 23:21 ` [patch 29/29] xen: Attempt to patch inline versions of common operations Jeremy Fitzhardinge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070504232121.554055808@goop.org \
--to=jeremy@goop.org \
--cc=ak@suse.de \
--cc=akpm@linux-foundation.org \
--cc=chrisw@sous-sol.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=virtualization@lists.osdl.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).