Skip to contentSkip to conversation

hyperv: Fix the error processing in netvsc_send()

PATCH In review Haiyang Zhang 3 participants 8 messages Jan 29, 2015 – Feb 4, 2015 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

PATCH 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
index 9f49c01..7cd4eb3 100644
@@ -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
#1 lore raw
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!)

---
 drivers/net/hyperv/netvsc.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/hyperv/netvsc.c +1 -3
index 9f49c01..7cd4eb3 100644
@@ -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
author maintainer
#2 lore raw
Quoted 11 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Friday, January 30, 2015 5:25 AM

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 -EINVAL or -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 since netvsc_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 -ENOSPC when queue_sends[q_idx] < 1. But non of the caller check -ENOSPC in 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

A message that is not in the archive (sent off-list or not yet received): BN1PR0301MB0770FCDA58F3BC9E25382D95CA310@BN1PR0301MB0770.namprd03.prod.out look.com

#4 lore raw
Quoted 25 lines · Haiyang Zhang
Quoted 5 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Friday, January 30, 2015 5:25 AM

Quoted 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 -EINVAL or -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 since netvsc_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 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.

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 -ENOSPC in 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

author maintainer
#5 lore raw
Quoted 9 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Monday, February 2, 2015 1:49 AM

Quoted 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 -ENOSPC in 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

A message that is not in the archive (sent off-list or not yet received): BN1PR0301MB077018D4A512E3AA9B8583E0CA3D0@BN1PR0301MB0770.namprd03.prod.out look.com

#7 lore raw
Quoted 16 lines · Haiyang Zhang
Quoted 16 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Monday, February 2, 2015 1:49 AM

Quoted 1 line
Quoted 1 line

btw, I find during netvsc_start_xmit(), ret was change to

-ENOSPC

Quoted 2 lines
Quoted 2 lines

when
queue_sends[q_idx] < 1. But non of the caller check -ENOSPC in

fact?

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

author maintainer
#8 lore raw
Quoted 20 lines

-----Original Message-----
From: Jason Wang [mailto:[email protected]]
Sent: Wednesday, February 4, 2015 2:29 AM

Quoted 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 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.

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() call netsc_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 check queue_sends since 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

maintainer
#9 lore raw
In reply to Haiyang Zhang

From: 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!)

Applied and queued up for -stable, thanks.