Skip to content

Commit 10a8d94

Browse files
Jason Wangdavem330
authored andcommitted
virtio_net: introduce VIRTIO_NET_HDR_F_DATA_VALID
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>
1 parent 40d15cd commit 10a8d94

5 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎drivers/net/macvtap.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ static int macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
508508
vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
509509
vnet_hdr->csum_start = skb_checksum_start_offset(skb);
510510
vnet_hdr->csum_offset = skb->csum_offset;
511+
} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
512+
vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
511513
} /* else everything is zero */
512514

513515
return 0;

‎drivers/net/tun.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
788788
gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
789789
gso.csum_start = skb_checksum_start_offset(skb);
790790
gso.csum_offset = skb->csum_offset;
791+
} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
792+
gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
791793
} /* else everything is zero */
792794

793795
if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total,

‎drivers/net/virtio_net.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ static void receive_buf(struct net_device *dev, void *buf, unsigned int len)
274274
hdr->hdr.csum_start,
275275
hdr->hdr.csum_offset))
276276
goto frame_err;
277+
} else if (hdr->hdr.flags & VIRTIO_NET_HDR_F_DATA_VALID) {
278+
skb->ip_summed = CHECKSUM_UNNECESSARY;
277279
}
278280

279281
skb->protocol = eth_type_trans(skb, dev);

‎include/linux/virtio_net.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct virtio_net_config {
6363
* specify GSO or CSUM features, you can simply ignore the header. */
6464
struct virtio_net_hdr {
6565
#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 // Use csum_start, csum_offset
66+
#define VIRTIO_NET_HDR_F_DATA_VALID 2 // Csum is valid
6667
__u8 flags;
6768
#define VIRTIO_NET_HDR_GSO_NONE 0 // Not a GSO frame
6869
#define VIRTIO_NET_HDR_GSO_TCPV4 1 // GSO frame, IPv4 TCP (TSO)

‎net/packet/af_packet.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,6 +1685,8 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
16851685
vnet_hdr.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
16861686
vnet_hdr.csum_start = skb_checksum_start_offset(skb);
16871687
vnet_hdr.csum_offset = skb->csum_offset;
1688+
} else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
1689+
vnet_hdr.flags = VIRTIO_NET_HDR_F_DATA_VALID;
16881690
} /* else everything is zero */
16891691

16901692
err = memcpy_toiovec(msg->msg_iov, (void *)&vnet_hdr,

0 commit comments

Comments
 (0)