Skip to contentSkip to conversation

Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

PATCH In review K. Y. Srinivasan 1 participant 2 messages Mar 11, 2016 – Apr 2, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

On the consumer side, we have interrupt driven flow management of the producer. It is sufficient to base the signalling decision on the amount of space that is available to write after the read is complete. The current code samples the previous available space and uses this in making the signalling decision. This state can be stale and is unnecessary. Since the state can be stale, we end up not signalling the host (when we should) and this can result in a hang. Fix this problem by removing the unnecessary check.

I would like to thank Arseney Romanenko <[email protected]> for pointing out this bug.

---
 drivers/hv/ring_buffer.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/hv/ring_buffer.c +3 -4
index 5613e2b..085003a 100644
@@ -103,8 +103,7 @@ static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
  *    there is room for the producer to send the pending packet.
  */
 
-static bool hv_need_to_signal_on_read(u32 prev_write_sz,
-				      struct hv_ring_buffer_info *rbi)
+static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
 {
 	u32 cur_write_sz;
 	u32 r_size;
@@ -120,7 +119,7 @@ static bool hv_need_to_signal_on_read(u32 prev_write_sz,
 	cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc) :
 			read_loc - write_loc;
 
-	if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
+	if (cur_write_sz >= pending_sz)
 		return true;
 
 	return false;
@@ -455,7 +454,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,
 	/* Update the read index */
 	hv_set_next_read_location(inring_info, next_read_location);
 
-	*signal = hv_need_to_signal_on_read(bytes_avail_towrite, inring_info);
+	*signal = hv_need_to_signal_on_read(inring_info);
 
 	return ret;
 }
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 21 lines

-----Original Message-----
From: K. Y. Srinivasan [mailto:[email protected]]
Sent: Friday, March 11, 2016 12:39 PM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: KY Srinivasan <[email protected]>; [email protected]
Subject: [PATCH 1/1] Drivers: hv: vmbus: Fix a bug in hv_need_to_signal_on_read()

On the consumer side, we have interrupt driven flow management of the producer. It is sufficient to base the signalling decision on the amount of space that is available to write after the read is complete. The current code samples the previous available space and uses this in making the signalling decision. This state can be stale and is unnecessary. Since the state can be stale, we end up not signalling the host (when we should) and this can result in a hang. Fix this problem by removing the unnecessary check.

Quoted 2 lines

I would like to thank Arseney Romanenko <[email protected]> for pointing out this bug.

Greg,

Please drop this patch. I am going to update and send the patch.

K. Y

Quoted 47 lines
---
 drivers/hv/ring_buffer.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
drivers/hv/ring_buffer.c +1 -2
index 5613e2b..085003a 100644
@@ -103,8 +103,7 @@ static bool hv_need_to_signal(u32 old_write, struct
 hv_ring_buffer_info *rbi)
  *    there is room for the producer to send the pending packet.
  */
 
-static bool hv_need_to_signal_on_read(u32 prev_write_sz,
-				      struct hv_ring_buffer_info *rbi)
+static bool hv_need_to_signal_on_read(struct hv_ring_buffer_info *rbi)
 {
 	u32 cur_write_sz;
drivers/hv/ring_buffer.c +0 -0
 	u32 r_size;
@@ -120,7 +119,7 @@ static bool hv_need_to_signal_on_read(u32
 prev_write_sz,
 	cur_write_sz = write_loc >= read_loc ? r_size - (write_loc - read_loc)

:

drivers/hv/ring_buffer.c +2 -2
 			read_loc - write_loc;
 
-	if ((prev_write_sz < pending_sz) && (cur_write_sz >= pending_sz))
+	if (cur_write_sz >= pending_sz)
 		return true;
 
 	return false;
@@ -455,7 +454,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info
 *inring_info,
 	/* Update the read index */
 	hv_set_next_read_location(inring_info, next_read_location);
 
-	*signal = hv_need_to_signal_on_read(bytes_avail_towrite,
 inring_info);
+	*signal = hv_need_to_signal_on_read(inring_info);
 

return ret;
}
--
1.7.4.1