@@ -1360,6 +1360,10 @@ static struct sk_buff *receive_small_xdp(struct net_device *dev,
1360
1360
if (unlikely (hdr -> hdr .gso_type ))
1361
1361
goto err_xdp ;
1362
1362
1363
+ /* Partially checksummed packets must be dropped. */
1364
+ if (unlikely (hdr -> hdr .flags & VIRTIO_NET_HDR_F_NEEDS_CSUM ))
1365
+ goto err_xdp ;
1366
+
1363
1367
buflen = SKB_DATA_ALIGN (GOOD_PACKET_LEN + headroom ) +
1364
1368
SKB_DATA_ALIGN (sizeof (struct skb_shared_info ));
1365
1369
@@ -1677,6 +1681,10 @@ static void *mergeable_xdp_get_buf(struct virtnet_info *vi,
1677
1681
if (unlikely (hdr -> hdr .gso_type ))
1678
1682
return NULL ;
1679
1683
1684
+ /* Partially checksummed packets must be dropped. */
1685
+ if (unlikely (hdr -> hdr .flags & VIRTIO_NET_HDR_F_NEEDS_CSUM ))
1686
+ return NULL ;
1687
+
1680
1688
/* Now XDP core assumes frag size is PAGE_SIZE, but buffers
1681
1689
* with headroom may add hole in truesize, which
1682
1690
* make their length exceed PAGE_SIZE. So we disabled the
@@ -1943,6 +1951,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
1943
1951
struct net_device * dev = vi -> dev ;
1944
1952
struct sk_buff * skb ;
1945
1953
struct virtio_net_common_hdr * hdr ;
1954
+ u8 flags ;
1946
1955
1947
1956
if (unlikely (len < vi -> hdr_len + ETH_HLEN )) {
1948
1957
pr_debug ("%s: short packet %i\n" , dev -> name , len );
@@ -1951,6 +1960,15 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
1951
1960
return ;
1952
1961
}
1953
1962
1963
+ /* 1. Save the flags early, as the XDP program might overwrite them.
1964
+ * These flags ensure packets marked as VIRTIO_NET_HDR_F_DATA_VALID
1965
+ * stay valid after XDP processing.
1966
+ * 2. XDP doesn't work with partially checksummed packets (refer to
1967
+ * virtnet_xdp_set()), so packets marked as
1968
+ * VIRTIO_NET_HDR_F_NEEDS_CSUM get dropped during XDP processing.
1969
+ */
1970
+ flags = ((struct virtio_net_common_hdr * )buf )-> hdr .flags ;
1971
+
1954
1972
if (vi -> mergeable_rx_bufs )
1955
1973
skb = receive_mergeable (dev , vi , rq , buf , ctx , len , xdp_xmit ,
1956
1974
stats );
@@ -1966,7 +1984,7 @@ static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
1966
1984
if (dev -> features & NETIF_F_RXHASH && vi -> has_rss_hash_report )
1967
1985
virtio_skb_set_hash (& hdr -> hash_v1_hdr , skb );
1968
1986
1969
- if (hdr -> hdr . flags & VIRTIO_NET_HDR_F_DATA_VALID )
1987
+ if (flags & VIRTIO_NET_HDR_F_DATA_VALID )
1970
1988
skb -> ip_summed = CHECKSUM_UNNECESSARY ;
1971
1989
1972
1990
if (virtio_net_hdr_to_skb (skb , & hdr -> hdr ,
@@ -5666,8 +5684,16 @@ static int virtnet_probe(struct virtio_device *vdev)
5666
5684
dev -> features |= dev -> hw_features & NETIF_F_ALL_TSO ;
5667
5685
/* (!csum && gso) case will be fixed by register_netdev() */
5668
5686
}
5669
- if (virtio_has_feature (vdev , VIRTIO_NET_F_GUEST_CSUM ))
5670
- dev -> features |= NETIF_F_RXCSUM ;
5687
+
5688
+ /* 1. With VIRTIO_NET_F_GUEST_CSUM negotiation, the driver doesn't
5689
+ * need to calculate checksums for partially checksummed packets,
5690
+ * as they're considered valid by the upper layer.
5691
+ * 2. Without VIRTIO_NET_F_GUEST_CSUM negotiation, the driver only
5692
+ * receives fully checksummed packets. The device may assist in
5693
+ * validating these packets' checksums, so the driver won't have to.
5694
+ */
5695
+ dev -> features |= NETIF_F_RXCSUM ;
5696
+
5671
5697
if (virtio_has_feature (vdev , VIRTIO_NET_F_GUEST_TSO4 ) ||
5672
5698
virtio_has_feature (vdev , VIRTIO_NET_F_GUEST_TSO6 ))
5673
5699
dev -> features |= NETIF_F_GRO_HW ;
0 commit comments