[PATCH] vmbus: fix lockup if ring fills up

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Stephen Hemminger <sthemmin@xxxxxxxxxxxxx

This fixes a day one bug in circular ring buffer.  The ring buffer
will get stuck if the number of bytes written exactly fills the
ring buffer size.  The root cause is an off by one bug.

Ring empty state is when read_index == write_loc.
The very last slot in the circular buffer must never be filled
otherwise there is no way to tell the difference between completely
full and empty!

Signed-off-by: Stephen Hemminger <stephen@xxxxxxxxxxxxxxxxxx>
---
Please queue for stable as well

 include/linux/hyperv.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h
index cd184bd..28f88de 100644
--- a/include/linux/hyperv.h
+++ b/include/linux/hyperv.h
@@ -150,6 +150,7 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi,
 
 	*write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
 		read_loc - write_loc;
+	*write -= 1;
 	*read = dsize - *write;
 }
 
@@ -177,7 +178,8 @@ static inline u32 hv_get_bytes_to_write(struct hv_ring_buffer_info *rbi)
 
 	write = write_loc >= read_loc ? dsize - (write_loc - read_loc) :
 		read_loc - write_loc;
-	return write;
+	/* make sure ring never gets completely full */
+	return write - 1;
 }
 
 /*
-- 
2.7.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux