[linux-azure:xenial][PATCH 2/2] UBUNTU: SAUCE: hv: vmbus: Fix ring buffer signaling
Marcelo Henrique Cerri
marcelo.cerri at canonical.com
Wed Feb 14 14:06:49 UTC 2018
From: Michael Kelley <mikelley at microsoft.com>
BugLink: http://bugs.launchpad.net/bugs/1748662
Fix bugs in signaling the Hyper-V host when freeing space in the
host->guest ring buffer:
1. The interrupt_mask must not be used to determine whether to signal
on the host->guest ring buffer
2. The ring buffer write_index must be read (via hv_get_bytes_to_write)
*after* pending_send_sz is read in order to avoid a race condition
3. Comparisons with pending_send_sz must treat the "equals" case as
not-enough-space
4. Don't signal if the pending_send_sz feature is not present. Older
versions of Hyper-V that don't implement this feature will poll.
Fixes: 03bad714a161 ("vmbus: more host signalling avoidance")
Signed-off-by: Michael Kelley <mikelley at microsoft.com>
[marcelo.cerri at canonical.com: backported to linux-azure]
Signed-off-by: Marcelo Henrique Cerri <marcelo.cerri at canonical.com>
---
drivers/hv/ring_buffer.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 8214042757cb..469d0eaa269e 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -407,10 +407,11 @@ EXPORT_SYMBOL_GPL(__hv_pkt_iter_next);
void hv_pkt_iter_close(struct vmbus_channel *channel)
{
struct hv_ring_buffer_info *rbi = &channel->inbound;
- u32 orig_write_sz;
-
- /* Available space before read_index update */
- orig_write_sz = hv_get_bytes_to_write(rbi);
+ u32 curr_write_sz;
+ u32 delta = rbi->ring_buffer->read_index < rbi->priv_read_index ?
+ (rbi->priv_read_index - rbi->ring_buffer->read_index) :
+ (rbi->ring_datasize - rbi->ring_buffer->read_index +
+ rbi->priv_read_index);
/*
* Make sure all reads are done before we update the read index since
@@ -438,18 +439,27 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)
u32 pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
/*
- * If there was space before we began iteration, then
- * host was not blocked. Also handles the case where
- * pending_sz is zero because host has nothing pending.
+ * Ensure the read of write_index in hv_get_bytes_to_write()
+ * happens after the read of pending_send_sz.
+ */
+ virt_rmb();
+ curr_write_sz = hv_get_bytes_to_write(rbi);
+
+ /*
+ * If there was space before we began iteration,
+ * then host was not blocked. Also handles case where
+ * pending_sz is zero then host has nothing pending
+ * and does not need to be signaled.
*/
- if (orig_write_sz > pending_sz)
+ if (curr_write_sz - delta > pending_sz)
return;
/* If pending write will not fit, don't give false hope. */
- if (hv_get_bytes_to_write(rbi) < pending_sz)
+ if (curr_write_sz <= pending_sz)
return;
+
+ vmbus_setevent(channel);
}
- vmbus_setevent(channel);
}
EXPORT_SYMBOL_GPL(hv_pkt_iter_close);
--
2.7.4
More information about the kernel-team
mailing list