Skip to content

Commit 604141c

Browse files
Heng Qidavem330
authored andcommitted
virtio_net: checksum offloading handling fix
In virtio spec 0.95, VIRTIO_NET_F_GUEST_CSUM was designed to handle partially checksummed packets, and the validation of fully checksummed packets by the device is independent of VIRTIO_NET_F_GUEST_CSUM negotiation. However, the specification erroneously stated: "If VIRTIO_NET_F_GUEST_CSUM is not negotiated, the device MUST set flags to zero and SHOULD supply a fully checksummed packet to the driver." This statement is inaccurate because even without VIRTIO_NET_F_GUEST_CSUM negotiation, the device can still set the VIRTIO_NET_HDR_F_DATA_VALID flag. Essentially, the device can facilitate the validation of these packets' checksums - a process known as RX checksum offloading - removing the need for the driver to do so. This scenario is currently not implemented in the driver and requires correction. The necessary specification correction[1] has been made and approved in the virtio TC vote. [1] https://lists.oasis-open.org/archives/virtio-comment/202401/msg00011.html Fixes: 4f49129 ("virtio-net: Set RXCSUM feature if GUEST_CSUM is available") Signed-off-by: Heng Qi <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7be4cb7 commit 604141c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

drivers/net/virtio_net.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5666,8 +5666,16 @@ static int virtnet_probe(struct virtio_device *vdev)
56665666
dev->features |= dev->hw_features & NETIF_F_ALL_TSO;
56675667
/* (!csum && gso) case will be fixed by register_netdev() */
56685668
}
5669-
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_CSUM))
5670-
dev->features |= NETIF_F_RXCSUM;
5669+
5670+
/* 1. With VIRTIO_NET_F_GUEST_CSUM negotiation, the driver doesn't
5671+
* need to calculate checksums for partially checksummed packets,
5672+
* as they're considered valid by the upper layer.
5673+
* 2. Without VIRTIO_NET_F_GUEST_CSUM negotiation, the driver only
5674+
* receives fully checksummed packets. The device may assist in
5675+
* validating these packets' checksums, so the driver won't have to.
5676+
*/
5677+
dev->features |= NETIF_F_RXCSUM;
5678+
56715679
if (virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO4) ||
56725680
virtio_has_feature(vdev, VIRTIO_NET_F_GUEST_TSO6))
56735681
dev->features |= NETIF_F_GRO_HW;

0 commit comments

Comments
 (0)