From patchwork Mon Aug 22 15:42:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 9293785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 59BAD608A7 for ; Mon, 22 Aug 2016 15:45:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4C911289D3 for ; Mon, 22 Aug 2016 15:45:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 413EC28A30; Mon, 22 Aug 2016 15:45:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D048128A12 for ; Mon, 22 Aug 2016 15:45:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bbrNe-0007NP-FF; Mon, 22 Aug 2016 15:43:18 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bbrNc-0007NJ-Ol for xen-devel@lists.xenproject.org; Mon, 22 Aug 2016 15:43:16 +0000 Received: from [85.158.139.211] by server-12.bemta-5.messagelabs.com id 59/6F-01026-49D1BB75; Mon, 22 Aug 2016 15:43:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDLMWRWlGSWpSXmKPExsVysWW7jO5k2d3 hBv/6RS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxpbw8zFvwUrZh1ZR1rA+M1wS5GTg4hgd1M ElfuqXQxcgHZZxgldr34zQ6SYBPQkfj+9BQziC0iICXxccd2dpAiZoFvjBLLj95mAkkIC6RIP LnWyQJiswioSuw7cp0NxOYVcJa4f/QtWFxCQFuiYdZkFpBmCYE+Ron5H48wT2DkWsDIsIpRoz i1qCy1SNfITC+pKDM9oyQ3MTNH19DAVC83tbg4MT01JzGpWC85P3cTI9CX9QwMjDsYb0/2O8Q oycGkJMpr1rozXIgvKT+lMiOxOCO+qDQntfgQowwHh5IEr47M7nAhwaLU9NSKtMwcYFDBpCU4 eJREeKVB0rzFBYm5xZnpEKlTjIpS4rxWIAkBkERGaR5cGyyQLzHKSgnzMjIwMAjxFKQW5WaWo Mq/YhTnYFQS5lUCmcKTmVcCN/0V0GImoMXX/28HWVySiJCSamC074qSLN2uM5f3+xGObUwiRX KO23YXHH2/q/te6HH5PVemVJTJXN+3Y4Nu9fLvgeUsq9K3/1hYIP/2a7lxwDw1/n+P58eURK5 Xb/1g7358+fmyB8oH3khsWj6J5fCUc7yxpw+sCW99WWzaEcPOH/via8Z/PYcbXf0H3xm0TNbY uulGr+Pl3J4MJZbijERDLeai4kQASTeIol8CAAA= X-Env-Sender: vkuznets@redhat.com X-Msg-Ref: server-16.tower-206.messagelabs.com!1471880593!39768275!1 X-Originating-IP: [209.132.183.28] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA5LjEzMi4xODMuMjggPT4gNTQwNjQ=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61077 invoked from network); 22 Aug 2016 15:43:15 -0000 Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by server-16.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Aug 2016 15:43:15 -0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C9093B71F; Mon, 22 Aug 2016 15:43:13 +0000 (UTC) Received: from vitty.brq.redhat.com (ovpn-112-78.phx2.redhat.com [10.3.112.78]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u7MFh5BD022015; Mon, 22 Aug 2016 11:43:07 -0400 From: Vitaly Kuznetsov To: netdev@vger.kernel.org Date: Mon, 22 Aug 2016 17:42:57 +0200 Message-Id: <1471880577-21380-1-git-send-email-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 22 Aug 2016 15:43:13 +0000 (UTC) Cc: Juergen Gross , Patrick Talbert , linux-kernel@vger.kernel.org, David Vrabel , xen-devel@lists.xenproject.org, Boris Ostrovsky Subject: [Xen-devel] [PATCH net-next] xen-netfront: avoid packet loss when ethernet header crosses page boundary X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Small packet loss is reported on complex multi host network configurations including tunnels, NAT, ... My investigation led me to the following check in netback which drops packets: if (unlikely(txreq.size < ETH_HLEN)) { netdev_err(queue->vif->dev, "Bad packet size: %d\n", txreq.size); xenvif_tx_err(queue, &txreq, extra_count, idx); break; } But this check itself is legitimate. SKBs consist of a linear part (which has to have the ethernet header) and (optionally) a number of frags. Netfront transmits the head of the linear part up to the page boundary as the first request and all the rest becomes frags so when we're reconstructing the SKB in netback we can't distinguish between original frags and the 'tail' of the linear part. The first SKB needs to be at least ETH_HLEN size. So in case we have an SKB with its linear part starting too close to the page boundary the packet is lost. I see two ways to fix the issue: - Change the 'wire' protocol between netfront and netback to start keeping the original SKB structure. We'll have to add a flag indicating the fact that the particular request is a part of the original linear part and not a frag. We'll need to know the length of the linear part to pre-allocate memory. - Avoid transmitting SKBs with linear parts starting too close to the page boundary. That seems preferable short-term and shouldn't bring significant performance degradation as such packets are rare. That's what this patch is trying to achieve with skb_copy(). Signed-off-by: Vitaly Kuznetsov Acked-by: David Vrabel --- drivers/net/xen-netfront.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 96ccd4e..28c4a66 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -565,6 +565,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) struct netfront_queue *queue = NULL; unsigned int num_queues = dev->real_num_tx_queues; u16 queue_index; + struct sk_buff *nskb; /* Drop the packet if no queues are set up */ if (num_queues < 1) @@ -595,6 +596,19 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev) offset = offset_in_page(skb->data); len = skb_headlen(skb); + /* The first req should be at least ETH_HLEN size or the packet will be + * dropped by netback. + */ + if (unlikely(PAGE_SIZE - offset < ETH_HLEN)) { + nskb = skb_copy(skb, GFP_ATOMIC); + if (!nskb) + goto drop; + dev_kfree_skb_any(skb); + skb = nskb; + page = virt_to_page(skb->data); + offset = offset_in_page(skb->data); + } + spin_lock_irqsave(&queue->tx_lock, flags); if (unlikely(!netif_carrier_ok(dev) ||