hyperv: Fix the error processing in netvsc_send()
Subsystems (3)
Haiyang Zhang
maintainerPATCH 1/1 hyperv: Fix the error processing in netvsc_send()
The existing code frees the skb in EAGAIN case, in which the skb will be retried from upper layer and used again.
Also, the existing code doesn't free send buffer slot in error case, because there is no completion message for unsent packets.
This patch fixes these problems.
(Please also include this patch for stable trees. Thanks!)
--- drivers/net/hyperv/netvsc.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/hyperv/netvsc.c +8 -3
@@ -716,7 +716,7 @@ int netvsc_send(struct hv_device *device,u64 req_id;unsigned int section_index =NETVSC_INVALID_INDEX ;u32 msg_size =0 ; -struct sk_buff *skb; +struct sk_buff *skb =NULL ;u16 q_idx = packet->q_idx;
@@ -743,8 +743,6 @@ int netvsc_send(struct hv_device *device, packet); skb = (struct sk_buff *) (unsigned long )packet->send_completion_tid; -if (skb) -dev_kfree_skb_any (skb); packet->page_buf_cnt =0 ; } }
@@ -810,6 +808,13 @@ int netvsc_send(struct hv_device *device, packet, ret); } +if (ret !=0 ) { +if (section_index !=NETVSC_INVALID_INDEX ) +netvsc_free_send_slot (net_device, section_index); + }else if (skb) { +dev_kfree_skb_any (skb); + } +return ret; }
Signature · 1 line
1.7.4.1
Quoted 37 lines · Haiyang Zhang
The existing code frees the skb in EAGAIN case, in which the skb will be retried from upper layer and used again.
Also, the existing code doesn't free send buffer slot in error case, because there is no completion message for unsent packets.
This patch fixes these problems.(Please also include this patch for stable trees. Thanks!)
Signed-off-by Haiyang Zhang <[email protected]>Reviewed-by K. Y. Srinivasan <[email protected]>--- drivers/net/hyperv/netvsc.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)drivers/net/hyperv/netvsc.c +1
-3@@ -716,7 +716,7 @@ int netvsc_send(struct hv_device *device,u64 req_id;unsigned int section_index =NETVSC_INVALID_INDEX ;u32 msg_size =0 ; -struct sk_buff *skb; +struct sk_buff *skb =NULL ;u16 q_idx = packet->q_idx;@@ -743,8 +743,6 @@ int netvsc_send(struct hv_device *device, packet); skb = (struct sk_buff *) (unsigned long )packet->send_completion_tid; -if (skb) -dev_kfree_skb_any (skb); packet->page_buf_cnt =0 ; } }
drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 813
Quoted 6 lines
drivers/net/hyperv/netvsc.c +3
-0@@ -810,6 +808,13 @@ int netvsc_send(struct hv_device *device, packet, ret); } +if (ret !=0 ) { +if (section_index !=NETVSC_INVALID_INDEX ) +netvsc_free_send_slot (net_device, section_index);
What if ret is -EINVAL or -ENOSPC? Looks like we need free the skb in this case also.
drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 815
Quoted 3 lines
drivers/net/hyperv/netvsc.c +2
-0+ }else if (skb) { +dev_kfree_skb_any (skb);
The caller - netvsc_start_xmit() do this also, may be handle this in caller is better since netvsc_start_xmit() is the only user that tries to send a skb?
btw, I find during netvsc_start_xmit(), ret was change to -ENOSPC when queue_sends[q_idx] < 1. But non of the caller check -ENOSPC in fact?
Thanks
Quoted 13 lines
drivers/net/hyperv/netvsc.c +2
-0+ } +return ret; }Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Haiyang Zhang
maintainerQuoted 11 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Friday, January 30, 2015 5:25 AMdrivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 813
Quoted 3 lines
drivers/net/hyperv/netvsc.c +3
-0+if (ret !=0 ) { +if (section_index !=NETVSC_INVALID_INDEX ) +netvsc_free_send_slot (net_device, section_index);What if ret is
-EINVALor-ENOSPC? Looks like we need free the skb in this case also.
In these cases, skb is freed in netvsc_start_xmit().
Quoted 7 lines
drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 815
Quoted 3 lines
drivers/net/hyperv/netvsc.c +2
-0+ }else if (skb) { +dev_kfree_skb_any (skb);The caller -
netvsc_start_xmit()do this also, may be handle this in caller is better sincenetvsc_start_xmit()is the only user that tries to send a skb?
When the packet is sent out normally, we frees it in netvsc_send() if it's copied to send-buffer. The free is done in netvsc_send(), because the copy is also in this function. If it's not copied, it will be freed in another function -- netvsc_xmit_completion().
netvsc_start_xmit() only does free skb in error case.
Quoted 2 lines
btw, I find during
netvsc_start_xmit(), ret was change to-ENOSPCwhen queue_sends[q_idx] < 1. But non of the caller check-ENOSPCin fact?
In this case, we don't request re-send, so set ret to a value other than -EAGAIN. It's handled in the same way as errors != -EAGAIN, so we don't need to check this value specifically.
Thanks,
- Haiyang
David Miller
maintainerFrom: Haiyang Zhang <[email protected]>
Date: Thu, 29 Jan 2015 12:34:49 -0800
Quoted 10 lines
The existing code frees the skb in EAGAIN case, in which the skb will be retried from upper layer and used again.
Also, the existing code doesn't free send buffer slot in error case, because there is no completion message for unsent packets.
This patch fixes these problems.(Please also include this patch for stable trees. Thanks!)
Signed-off-by Haiyang Zhang <[email protected]>Reviewed-by K. Y. Srinivasan <[email protected]>
Applied and queued up for -stable, thanks.
Quoted 25 lines · Haiyang Zhang
Quoted 5 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Friday, January 30, 2015 5:25 AMQuoted 7 lines
drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 813
Quoted 3 lines
drivers/net/hyperv/netvsc.c +3
-0+if (ret !=0 ) { +if (section_index !=NETVSC_INVALID_INDEX ) +netvsc_free_send_slot (net_device, section_index);What if ret is
-EINVALor-ENOSPC? Looks like we need free the skb
in
this case also.In these cases, skb is freed in
netvsc_start_xmit().Quoted 8 lines
drivers/net/hyperv/netvsc.c int netvsc_send(struct hv_device *device, · line 815
Quoted 3 lines
drivers/net/hyperv/netvsc.c +2
-0+ }else if (skb) { +dev_kfree_skb_any (skb);The caller -
netvsc_start_xmit()do this also, may be handle this in caller is better sincenetvsc_start_xmit()is the only user that
tries
to send a skb?
Quoted 6 lines
When the packet is sent out normally, we frees it in
netvsc_send()if it's copied to send-buffer. The free is done innetvsc_send(), because the copy is also in this function. If it's not copied, it will be freed in another function --netvsc_xmit_completion().
netvsc_start_xmit()only does free skb in error case.
Ok.
Quoted 8 lines
Quoted 5 lines
btw, I find during
netvsc_start_xmit(), ret was change to-ENOSPC
when
queue_sends[q_idx] < 1. But non of the caller check-ENOSPCin fact?In this case, we don't request re-send, so set ret to a value other than
-EAGAIN.
Why not? We have available slots for it to be sent now. Dropping the packet in this case may cause out of order sending.
Quoted 2 lines
It's handled in the same way as errors !=
-EAGAIN, so we don't need to check this value specifically.
Thanks
Haiyang Zhang
maintainerQuoted 9 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Monday, February 2, 2015 1:49 AMQuoted 4 lines
Quoted 3 lines
btw, I find during
netvsc_start_xmit(), ret was change to-ENOSPC
when
queue_sends[q_idx] < 1. But non of the caller check-ENOSPCin fact?
Quoted 6 lines
Quoted 3 lines
In this case, we don't request re-send, so set ret to a value other than
-EAGAIN.Why not? We have available slots for it to be sent now. Dropping the packet in this case may cause out of order sending.
The EAGAIN error doesn't normally happen, because we set the hi water mark to stop send queue. If in really rare case, the ring buffer is full and there is no outstanding sends, we can't stop queue here because there will be no send-completion msg to wake it up. And, the ring buffer is likely to be occupied by other special msg, e.g. receive-completion msg (not a normal case), so we can't assume there are available slots. We don't request retry from the upper layer in this case to avoid possible busy retry.
Thanks,
- Haiyang
Quoted 16 lines · Haiyang Zhang
Quoted 16 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Monday, February 2, 2015 1:49 AMQuoted 1 line
Quoted 1 line
btw, I find during
netvsc_start_xmit(), ret was change to
-ENOSPCQuoted 2 lines
Quoted 2 lines
when
queue_sends[q_idx] < 1. But non of the caller check-ENOSPCinfact?
Quoted 2 lines
In this case, we don't request re-send, so set ret to a value
other
Quoted 2 lines
than
-EAGAIN.
Quoted 5 lines
Quoted 2 lines
Why not? We have available slots for it to be sent now. Dropping the packet in this case may cause out of order sending.
The EAGAIN error doesn't normally happen, because we set the hi water mark to stop send queue.
This is not true since only txq was stopped which means only network stack stop sending packets but not for control path e.g rndis_filter_send_request() or other callers who call vmbus_sendpacket() directly (e.g recv completion).
For control path, user may meet several errors when they want to change mac address under heavy load.
What's more serious is netvsc_send_recv_completion(), it can not even recover from more than 3 times of EAGAIN.
I must say mixing data packets with control packets with the same channel sounds really scary. Since control packets could be blocked or even dropped because of data packets already queued during heavy load, and you need to synchronize two paths carefully (e.g I didn't see any tx lock were held if rndis_filter_send_request() call netsc_send() which may stop or start a queue).
Quoted 3 lines
If in really rare case, the ring buffer is full and there
is no outstanding sends, we can't stop queue here because there will be no send-completion msg to wake it up.
Confused, I believe only txq is stopped but we may still get completion interrupt in this case.
Quoted 2 lines
And, the ring buffer is likely to be occupied by other special msg, e.g. receive-completion msg (not a normal case), so we can't assume there are available slots.
Then why not checking hv_ringbuf_avail_percent() instead? And there's no need to check queue_sends since it does not count recv completion.
Quoted 2 lines
We don't request retry from
the upper layer in this case to avoid possible busy retry.
Can't we just do this by stopping txq and depending on tx interrupt to wake it?
Thanks
Haiyang Zhang
maintainerQuoted 20 lines
-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Wednesday, February 4, 2015 2:29 AMQuoted 3 lines
The EAGAIN error doesn't normally happen, because we set the hi water mark
to stop send queue.This is not true since only txq was stopped which means only network stack stop sending packets but not for control path e.g
rndis_filter_send_request()or other callers who callvmbus_sendpacket()directly (e.g recv completion).For control path, user may meet several errors when they want to change mac address under heavy load.
What's more serious is
netvsc_send_recv_completion(), it can not even recover from more than 3 times of EAGAIN.
Quoted 6 lines
I must say mixing data packets with control packets with the same channel sounds really scary. Since control packets could be blocked or even dropped because of data packets already queued during heavy load, and you need to synchronize two paths carefully (e.g I didn't see any tx lock were held if
rndis_filter_send_request()callnetsc_send()which may stop or start a queue).
The RING_AVAIL_PERCENT_HIWATER is defined to be 20, so the data traffic can only occupy 20% of the ring buffer before stopping the txq. So, this mechanism ensures the control messages are not blocked by data traffic.
Quoted 7 lines
Quoted 4 lines
If in really rare case, the ring buffer is full and there
is no outstanding sends, we can't stop queue here because there will be no
send-completion msg to wake it up.Confused, I believe only txq is stopped but we may still get completion interrupt in this case.
If there is no outstanding sends in this queue (queue_sends[q_idx]), we won't receive any more send-completion msg.
Quoted 8 lines
Quoted 5 lines
And, the ring buffer is likely to be
occupied by other special msg, e.g. receive-completion msg (not a normal case),
so we can't assume there are available slots.Then why not checking
hv_ringbuf_avail_percent()instead? And there's no need to checkqueue_sendssince it does not count recv completion.
When ret == -EAGAIN, which means the ring is full, we don't need to check hv_ringbuf_avail_percent().
Quoted 5 lines
Quoted 2 lines
We don't request retry from
the upper layer in this case to avoid possible busy retry.Can't we just do this by stopping txq and depending on tx interrupt to wake it?
There is no tx interrupt. Do you mean rx interrupt for the send-completion?
In usual cases, when we hit the high water mark, the stopped queue depends on the send-completion msg to wake up. But, not in some special cases. As said above, we won't receive any more send-completion msg when there is no outstanding sends in this queue.
Thanks,
- Haiyang