All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
@ 2016-09-16 10:59 Vitaly Kuznetsov
  2016-09-19  2:26 ` David Miller
  2016-09-19  2:26 ` David Miller
  0 siblings, 2 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-16 10:59 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, Patrick Talbert, Boris Ostrovsky, David Vrabel,
	Juergen Gross, xen-devel

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 <vkuznets@redhat.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
---
- This is just a RESEND with David's ACK added.
---
 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) ||
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-16 10:59 [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary Vitaly Kuznetsov
  2016-09-19  2:26 ` David Miller
@ 2016-09-19  2:26 ` David Miller
  2016-09-19 10:22   ` Vitaly Kuznetsov
  2016-09-19 10:22   ` Vitaly Kuznetsov
  1 sibling, 2 replies; 10+ messages in thread
From: David Miller @ 2016-09-19  2:26 UTC (permalink / raw)
  To: vkuznets
  Cc: netdev, linux-kernel, ptalbert, boris.ostrovsky, david.vrabel,
	jgross, xen-devel

From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Fri, 16 Sep 2016 12:59:14 +0200

> @@ -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);

I think you also have to recalculate 'len' in this case too, as
skb_headlen() will definitely be different for nskb.

In fact, I can't see how this code can work properly without that fix.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-16 10:59 [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary Vitaly Kuznetsov
@ 2016-09-19  2:26 ` David Miller
  2016-09-19  2:26 ` David Miller
  1 sibling, 0 replies; 10+ messages in thread
From: David Miller @ 2016-09-19  2:26 UTC (permalink / raw)
  To: vkuznets
  Cc: jgross, ptalbert, netdev, linux-kernel, david.vrabel, xen-devel,
	boris.ostrovsky

From: Vitaly Kuznetsov <vkuznets@redhat.com>
Date: Fri, 16 Sep 2016 12:59:14 +0200

> @@ -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);

I think you also have to recalculate 'len' in this case too, as
skb_headlen() will definitely be different for nskb.

In fact, I can't see how this code can work properly without that fix.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19  2:26 ` David Miller
@ 2016-09-19 10:22   ` Vitaly Kuznetsov
  2016-09-19 10:23     ` David Vrabel
  2016-09-19 10:23     ` David Vrabel
  2016-09-19 10:22   ` Vitaly Kuznetsov
  1 sibling, 2 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-19 10:22 UTC (permalink / raw)
  To: David Miller
  Cc: netdev, linux-kernel, ptalbert, boris.ostrovsky, david.vrabel,
	jgross, xen-devel

David Miller <davem@davemloft.net> writes:

> From: Vitaly Kuznetsov <vkuznets@redhat.com>
> Date: Fri, 16 Sep 2016 12:59:14 +0200
>
>> @@ -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);
>
> I think you also have to recalculate 'len' in this case too, as
> skb_headlen() will definitely be different for nskb.
>
> In fact, I can't see how this code can work properly without that fix.

Thank you for your feedback David,

in my testing (even when I tried doing skb_copy() for all skbs
unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
impression that both 'skb->len' and 'skb->data_len' remain the same when
we do skb_copy(). However, in case you think there are cases when
headlen changes, I see no problem with re-calculating 'len' as it won't
bring any significant performace penalty compared to the already added
skb_copy().

I'll send 'v2'.

-- 
  Vitaly

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19  2:26 ` David Miller
  2016-09-19 10:22   ` Vitaly Kuznetsov
@ 2016-09-19 10:22   ` Vitaly Kuznetsov
  1 sibling, 0 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-19 10:22 UTC (permalink / raw)
  To: David Miller
  Cc: jgross, ptalbert, netdev, linux-kernel, david.vrabel, xen-devel,
	boris.ostrovsky

David Miller <davem@davemloft.net> writes:

> From: Vitaly Kuznetsov <vkuznets@redhat.com>
> Date: Fri, 16 Sep 2016 12:59:14 +0200
>
>> @@ -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);
>
> I think you also have to recalculate 'len' in this case too, as
> skb_headlen() will definitely be different for nskb.
>
> In fact, I can't see how this code can work properly without that fix.

Thank you for your feedback David,

in my testing (even when I tried doing skb_copy() for all skbs
unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
impression that both 'skb->len' and 'skb->data_len' remain the same when
we do skb_copy(). However, in case you think there are cases when
headlen changes, I see no problem with re-calculating 'len' as it won't
bring any significant performace penalty compared to the already added
skb_copy().

I'll send 'v2'.

-- 
  Vitaly

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19 10:22   ` Vitaly Kuznetsov
@ 2016-09-19 10:23     ` David Vrabel
  2016-09-19 10:36       ` Vitaly Kuznetsov
  2016-09-19 10:36       ` Vitaly Kuznetsov
  2016-09-19 10:23     ` David Vrabel
  1 sibling, 2 replies; 10+ messages in thread
From: David Vrabel @ 2016-09-19 10:23 UTC (permalink / raw)
  To: Vitaly Kuznetsov, David Miller
  Cc: netdev, linux-kernel, ptalbert, boris.ostrovsky, jgross, xen-devel

On 19/09/16 11:22, Vitaly Kuznetsov wrote:
> David Miller <davem@davemloft.net> writes:
> 
>> From: Vitaly Kuznetsov <vkuznets@redhat.com>
>> Date: Fri, 16 Sep 2016 12:59:14 +0200
>>
>>> @@ -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);
>>
>> I think you also have to recalculate 'len' in this case too, as
>> skb_headlen() will definitely be different for nskb.
>>
>> In fact, I can't see how this code can work properly without that fix.
> 
> Thank you for your feedback David,
> 
> in my testing (even when I tried doing skb_copy() for all skbs
> unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
> impression that both 'skb->len' and 'skb->data_len' remain the same when
> we do skb_copy(). However, in case you think there are cases when
> headlen changes, I see no problem with re-calculating 'len' as it won't
> bring any significant performace penalty compared to the already added
> skb_copy().

I think you can move the len = skb_headlen(skb) after the if, no need to
recalculate it.

David

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19 10:22   ` Vitaly Kuznetsov
  2016-09-19 10:23     ` David Vrabel
@ 2016-09-19 10:23     ` David Vrabel
  1 sibling, 0 replies; 10+ messages in thread
From: David Vrabel @ 2016-09-19 10:23 UTC (permalink / raw)
  To: Vitaly Kuznetsov, David Miller
  Cc: jgross, ptalbert, netdev, linux-kernel, xen-devel, boris.ostrovsky

On 19/09/16 11:22, Vitaly Kuznetsov wrote:
> David Miller <davem@davemloft.net> writes:
> 
>> From: Vitaly Kuznetsov <vkuznets@redhat.com>
>> Date: Fri, 16 Sep 2016 12:59:14 +0200
>>
>>> @@ -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);
>>
>> I think you also have to recalculate 'len' in this case too, as
>> skb_headlen() will definitely be different for nskb.
>>
>> In fact, I can't see how this code can work properly without that fix.
> 
> Thank you for your feedback David,
> 
> in my testing (even when I tried doing skb_copy() for all skbs
> unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
> impression that both 'skb->len' and 'skb->data_len' remain the same when
> we do skb_copy(). However, in case you think there are cases when
> headlen changes, I see no problem with re-calculating 'len' as it won't
> bring any significant performace penalty compared to the already added
> skb_copy().

I think you can move the len = skb_headlen(skb) after the if, no need to
recalculate it.

David

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19 10:23     ` David Vrabel
  2016-09-19 10:36       ` Vitaly Kuznetsov
@ 2016-09-19 10:36       ` Vitaly Kuznetsov
  1 sibling, 0 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-19 10:36 UTC (permalink / raw)
  To: David Vrabel
  Cc: David Miller, netdev, linux-kernel, ptalbert, boris.ostrovsky,
	jgross, xen-devel

David Vrabel <david.vrabel@citrix.com> writes:

> On 19/09/16 11:22, Vitaly Kuznetsov wrote:
>> David Miller <davem@davemloft.net> writes:
>> 
>>> From: Vitaly Kuznetsov <vkuznets@redhat.com>
>>> Date: Fri, 16 Sep 2016 12:59:14 +0200
>>>
>>>> @@ -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);
>>>
>>> I think you also have to recalculate 'len' in this case too, as
>>> skb_headlen() will definitely be different for nskb.
>>>
>>> In fact, I can't see how this code can work properly without that fix.
>> 
>> Thank you for your feedback David,
>> 
>> in my testing (even when I tried doing skb_copy() for all skbs
>> unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
>> impression that both 'skb->len' and 'skb->data_len' remain the same when
>> we do skb_copy(). However, in case you think there are cases when
>> headlen changes, I see no problem with re-calculating 'len' as it won't
>> bring any significant performace penalty compared to the already added
>> skb_copy().
>
> I think you can move the len = skb_headlen(skb) after the if, no need to
> recalculate it.

Sorry, I was too fast with sending 'v2' and did the other way
around. I'll do v3.

-- 
  Vitaly

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
  2016-09-19 10:23     ` David Vrabel
@ 2016-09-19 10:36       ` Vitaly Kuznetsov
  2016-09-19 10:36       ` Vitaly Kuznetsov
  1 sibling, 0 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-19 10:36 UTC (permalink / raw)
  To: David Vrabel
  Cc: jgross, ptalbert, netdev, linux-kernel, xen-devel,
	boris.ostrovsky, David Miller

David Vrabel <david.vrabel@citrix.com> writes:

> On 19/09/16 11:22, Vitaly Kuznetsov wrote:
>> David Miller <davem@davemloft.net> writes:
>> 
>>> From: Vitaly Kuznetsov <vkuznets@redhat.com>
>>> Date: Fri, 16 Sep 2016 12:59:14 +0200
>>>
>>>> @@ -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);
>>>
>>> I think you also have to recalculate 'len' in this case too, as
>>> skb_headlen() will definitely be different for nskb.
>>>
>>> In fact, I can't see how this code can work properly without that fix.
>> 
>> Thank you for your feedback David,
>> 
>> in my testing (even when I tried doing skb_copy() for all skbs
>> unconditionally) skb_headlen(nskb) always equals 'len' so I was under an
>> impression that both 'skb->len' and 'skb->data_len' remain the same when
>> we do skb_copy(). However, in case you think there are cases when
>> headlen changes, I see no problem with re-calculating 'len' as it won't
>> bring any significant performace penalty compared to the already added
>> skb_copy().
>
> I think you can move the len = skb_headlen(skb) after the if, no need to
> recalculate it.

Sorry, I was too fast with sending 'v2' and did the other way
around. I'll do v3.

-- 
  Vitaly

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary
@ 2016-09-16 10:59 Vitaly Kuznetsov
  0 siblings, 0 replies; 10+ messages in thread
From: Vitaly Kuznetsov @ 2016-09-16 10:59 UTC (permalink / raw)
  To: netdev
  Cc: Juergen Gross, Patrick Talbert, linux-kernel, David Vrabel,
	xen-devel, Boris Ostrovsky

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 <vkuznets@redhat.com>
Acked-by: David Vrabel <david.vrabel@citrix.com>
---
- This is just a RESEND with David's ACK added.
---
 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) ||
-- 
2.7.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-09-19 10:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-16 10:59 [PATCH net-next RESEND] xen-netfront: avoid packet loss when ethernet header crosses page boundary Vitaly Kuznetsov
2016-09-19  2:26 ` David Miller
2016-09-19  2:26 ` David Miller
2016-09-19 10:22   ` Vitaly Kuznetsov
2016-09-19 10:23     ` David Vrabel
2016-09-19 10:36       ` Vitaly Kuznetsov
2016-09-19 10:36       ` Vitaly Kuznetsov
2016-09-19 10:23     ` David Vrabel
2016-09-19 10:22   ` Vitaly Kuznetsov
  -- strict thread matches above, loose matches on Subject: below --
2016-09-16 10:59 Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.