Subject: Re: [PATCH 1/2] mactap: Fix checksum errors for non-gso packets in bridge mode

From: "Michael S. Tsirkin" <[email-masked]>
Date: Wed, 23 Apr 2014 22:20:22 +0300

On Wed, Apr 23, 2014 at 12:51:40PM -0400, Vlad Yasevich wrote:
> The following is a problematic configuration:
> 
>  VM1: virtio-net device connected to macvtap0@eth0
>  VM2: e1000 device connect to macvtap1@eth0
> 
> The problem is is that virtio-net supports checksum offloading
> and thus sends the packets to the host with CHECKSUM_PARTIAL set.
> On the other hand, e1000 does not support any acceleration.
> 
> For small TCP packets (and this includes the 3-way handshake),
> e1000 ends up receiving packets that only have a partial checksum
> set.  This causes TCP to fail checksum validation and to drop
> packets.  As a result tcp connections can not be established.
> 
> Commit 3e4f8b787370978733ca6cae452720a4f0c296b8
> 	macvtap: Perform GSO on forwarding path.
> fixes this issue for large packets wthat will end up undergoing GSO.
> This commit adds a check for the non-GSO case and attempts to
> compute the checksum for partially checksummed packets in the
> non-GSO case.
> 
> CC: Daniel Lezcano <[email-masked]>
> CC: Patrick McHardy <[email-masked]>
> CC: Andrian Nord <[email-masked]>
> CC: Eric Dumazet <[email-masked]>
> CC: Michael S. Tsirkin <[email-masked]>
> CC: Jason Wang <[email-masked]>
> Signed-off-by: Vlad Yasevich <[email-masked]>
> ---
>  drivers/net/macvtap.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
> index ff111a8..ba91084 100644
> --- a/drivers/net/macvtap.c
> +++ b/drivers/net/macvtap.c
> @@ -322,6 +322,13 @@ static rx_handler_result_t macvtap_handle_frame(struct sk_buff **pskb)
>  			segs = nskb;
>  		}
>  	} else {
> +		/* If we receive a partial checksum and the tap side
> +		 * doesn't support checksum offload, compute the checksum.
> +		 */
> +		if (skb->ip_summed == CHECKSUM_PARTIAL &&
> +		    !(features & NETIF_F_ALL_CSUM) &&
> +		    skb_checksum_help(skb))
> +			goto drop;

Hmm confused by NETIF_F_ALL_CSUM here.

features come from here:
                feature_mask = NETIF_F_HW_CSUM;

                if (arg & (TUN_F_TSO4 | TUN_F_TSO6)) {
                        if (arg & TUN_F_TSO_ECN)
                                feature_mask |= NETIF_F_TSO_ECN;
                        if (arg & TUN_F_TSO4)
                                feature_mask |= NETIF_F_TSO;
                        if (arg & TUN_F_TSO6)
                                feature_mask |= NETIF_F_TSO6;
                }

                if (arg & TUN_F_UFO)
                        feature_mask |= NETIF_F_UFO;

okay so why not just check that NETIF_F_HW_CSUM is set?

Also does it matter whether specific offloads are enabled?

>  		skb_queue_tail(&q->sk.sk_receive_queue, skb);
>  	}
>  
> -- 
> 1.9.0