]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
virtio_net: introduce VIRTIO_NET_HDR_F_DATA_VALID
authorJason Wang <jasowang@redhat.com>
Fri, 10 Jun 2011 00:56:17 +0000 (00:56 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 11 Jun 2011 22:57:47 +0000 (15:57 -0700)
There's no need for the guest to validate the checksum if it have been
validated by host nics. So this patch introduces a new flag -
VIRTIO_NET_HDR_F_DATA_VALID which is used to bypass the checksum
examing in guest. The backend (tap/macvtap) may set this flag when
met skbs with CHECKSUM_UNNECESSARY to save cpu utilization.

No feature negotiation is needed as old driver just ignore this flag.

Iperf shows 12%-30% performance improvement for UDP traffic. For TCP,
when gro is on no difference as it produces skb with partial
checksum. But when gro is disabled, 20% or even higher improvement
could be measured by netperf.

Signed-off-by: Jason Wang <jasowang@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/macvtap.c
drivers/net/tun.c
drivers/net/virtio_net.c
include/linux/virtio_net.h
net/packet/af_packet.c

index 6696e56e63206024c7f529331f7088c72406982d..ecee0fe65a9776584762f96ed364df8325e904ee 100644 (file)
@@ -508,6 +508,8 @@ static int macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
                vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
                vnet_hdr->csum_start = skb_checksum_start_offset(skb);
                vnet_hdr->csum_offset = skb->csum_offset;
+       } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
+               vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
        } /* else everything is zero */
 
        return 0;
index ef68e13c042debe5f7f1c4606f8fc83ab03f0389..4dab85eecb601e2807f1d4675be261e280d844fe 100644 (file)
@@ -788,6 +788,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
                        gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
                        gso.csum_start = skb_checksum_start_offset(skb);
                        gso.csum_offset = skb->csum_offset;
+               } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
+                       gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
                } /* else everything is zero */
 
                if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total,
index f6853247a620046a12e9dab53c9e4f3adcf4d2b2..be3686a298dab7cc71d75d04b7c7346e84848356 100644 (file)
@@ -274,6 +274,8 @@ static void receive_buf(struct net_device *dev, void *buf, unsigned int len)
                                          hdr->hdr.csum_start,
                                          hdr->hdr.csum_offset))
                        goto frame_err;
+       } else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {
+               skb->ip_summed = CHECKSUM_UNNECESSARY;
        }
 
        skb->protocol = eth_type_trans(skb, dev);
index 136040bba3e36068364c276e38f3ab975b0cabef..970d5a2a90475350608d8e00095d41fa869741ce 100644 (file)
@@ -63,6 +63,7 @@ struct virtio_net_config {
  * specify GSO or CSUM features, you can simply ignore the header. */
 struct virtio_net_hdr {
 #define VIRTIO_NET_HDR_F_NEEDS_CSUM    1       // Use csum_start, csum_offset
+#define VIRTIO_NET_HDR_F_DATA_VALID    2       // Csum is valid
        __u8 flags;
 #define VIRTIO_NET_HDR_GSO_NONE                0       // Not a GSO frame
 #define VIRTIO_NET_HDR_GSO_TCPV4       1       // GSO frame, IPv4 TCP (TSO)
index 67f6749a0a456b11edb93f39a4d3b439e06e9896..b54ec41adea9274aac168cf85f9a450d6e96644b 100644 (file)
@@ -1685,6 +1685,8 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
                        vnet_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
                        vnet_hdr.csum_start = skb_checksum_start_offset(skb);
                        vnet_hdr.csum_offset = skb->csum_offset;
+               } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
+                       vnet_hdr.flags = VIRTIO_NET_HDR_F_DATA_VALID;
                } /* else everything is zero */
 
                err = memcpy_toiovec(msg->msg_iov, (void *)&vnet_hdr,