Drivers: hv: vmbus: Fix ring buffer signaling
Subsystems (2)
PATCH 1/1 Drivers: hv: vmbus: Fix ring buffer signaling
From: Michael Kelley <[email protected]>
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.
--- drivers/hv/ring_buffer.c | 52 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 17 deletions(-)
drivers/hv/ring_buffer.c +35 -17
@@ -376,13 +376,24 @@ __hv_pkt_iter_next(struct vmbus_channel *channel, }EXPORT_SYMBOL_GPL (__hv_pkt_iter_next); +/* How many bytes were read in this iterator cycle */ +static u32 hv_pkt_iter_bytes_read (const struct hv_ring_buffer_info *rbi, +u32 start_read_index) +{ +if (rbi->priv_read_index >= start_read_index) +return rbi->priv_read_index - start_read_index; +else +return rbi->ring_datasize - start_read_index + + rbi->priv_read_index; +} +/* * Update host ring buffer after iterating over packets. */ void hv_pkt_iter_close (struct vmbus_channel *channel) {struct hv_ring_buffer_info *rbi = &channel->inbound; -u32 orig_write_sz =hv_get_bytes_to_write (rbi); +u32 curr_write_sz, pending_sz, bytes_read, start_read_index;/* * Make sure all reads are done before we update the read index since
@@ -390,8 +401,12 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)* is updated. */ virt_rmb (); + start_read_index = rbi->ring_buffer->read_index; rbi->ring_buffer->read_index = rbi->priv_read_index; +if (!rbi->ring_buffer->feature_bits.feat_pending_send_sz) +return ; +/* * Issue a full memory barrier before making the signaling decision. * Here is the reason for having this barrier:
@@ -405,26 +420,29 @@ void hv_pkt_iter_close(struct vmbus_channel *channel)*/ virt_mb (); -/* If host has disabled notifications then skip */ -if (rbi->ring_buffer->interrupt_mask) + pending_sz =READ_ONCE (rbi->ring_buffer->pending_send_sz); +if (!pending_sz)return ; -if (rbi->ring_buffer->feature_bits.feat_pending_send_sz) { -u32 pending_sz =READ_ONCE (rbi->ring_buffer->pending_send_sz); +/* +* 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); + bytes_read =hv_pkt_iter_bytes_read (rbi, start_read_index); -/* -* 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) -return ; +/* +* If there was space before we began iteration, +* then host was not blocked. +*/ -/* If pending write will not fit, don't give false hope. */ -if (hv_get_bytes_to_write (rbi) < pending_sz) -return ; - } +if (curr_write_sz - bytes_read > pending_sz) +return ; + +/* If pending write will not fit, don't give false hope. */ +if (curr_write_sz <= pending_sz) +return ;vmbus_setevent (channel); }
Signature · 6 lines
2.15.1 _______________________________________________ devel mailing list [email protected] http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
Quoted 14 lines · On Sun, 4 Mar 2018 22:24:08 -0700 [email protected] wrote:
From: Michael Kelley <[email protected]>
Fix bugs in signaling the Hyper-V host when freeing space in the
host->guestring buffer:1. The
interrupt_maskmust not be used to determine whether to signal on thehost->guestring buffer
2. The ring bufferwrite_indexmust be read (viahv_get_bytes_to_write) *after*pending_send_szis read in order to avoid a race condition
3. Comparisons withpending_send_szmust treat the "equals" case as not-enough-space
4. Don't signal if thepending_send_szfeature is not present. Older versions of Hyper-V that don't implement this feature will poll.
Quoted 5 lines
Fixes 03bad714a161 ("vmbus: more host signalling avoidance")Cc Stable <[email protected]> # 4.14 and aboveSigned-off-by Michael Kelley <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>
What ever happened to this patch? It doesn't seem to be in char-misc, upstream, or stable kernel tree yet.
Quoted 27 lines · Stephen Hemminger
Quoted 14 lines · On Sun, 4 Mar 2018 22:24:08 -0700 [email protected] wrote:
From: Michael Kelley <[email protected]>
Fix bugs in signaling the Hyper-V host when freeing space in the
host->guestring buffer:1. The
interrupt_maskmust not be used to determine whether to signal on thehost->guestring buffer
2. The ring bufferwrite_indexmust be read (viahv_get_bytes_to_write) *after*pending_send_szis read in order to avoid a race condition
3. Comparisons withpending_send_szmust treat the "equals" case as not-enough-space
4. Don't signal if thepending_send_szfeature is not present. Older versions of Hyper-V that don't implement this feature will poll.Quoted 5 lines
Fixes 03bad714a161 ("vmbus: more host signalling avoidance")Cc Stable <[email protected]> # 4.14 and aboveSigned-off-by Michael Kelley <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>What ever happened to this patch? It doesn't seem to be in char-misc, upstream, or stable kernel tree yet.
Thanks, I hadn't updated to rc7 yet
-----Original Message-----
From: Joshua R. Poulson <[email protected]>
Sent: Wednesday, March 28, 2018 12:18 PM
To: Stephen Hemminger <[email protected]>
Cc: K. Y. Srinivasan <[email protected]>; KY Srinivasan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; Andy Whitcroft <[email protected]>; Vitaly Kuznetsov <[email protected]>; [email protected]; Leann Ogasawara <[email protected]>; Marcelo Henrique Cerri <[email protected]>; Stephen Hemminger <[email protected]>; Michael Kelley <[email protected]>; Stable <[email protected]>
Subject: Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
Quoted 27 lines · Stephen Hemminger
Quoted 14 lines · On Sun, 4 Mar 2018 22:24:08 -0700 [email protected] wrote:
From: Michael Kelley <[email protected]>
Fix bugs in signaling the Hyper-V host when freeing space in the
host->guestring buffer:1. The
interrupt_maskmust not be used to determine whether to signal on thehost->guestring buffer
2. The ring bufferwrite_indexmust be read (viahv_get_bytes_to_write) *after*pending_send_szis read in order to avoid a race condition
3. Comparisons withpending_send_szmust treat the "equals" case as not-enough-space
4. Don't signal if thepending_send_szfeature is not present. Older versions of Hyper-V that don't implement this feature will poll.Quoted 5 lines
Fixes 03bad714a161 ("vmbus: more host signalling avoidance")Cc Stable <[email protected]> # 4.14 and aboveSigned-off-by Michael Kelley <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>What ever happened to this patch? It doesn't seem to be in char-misc, upstream, or stable kernel tree yet.
Greg KH
maintainerQuoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Sun, 4 Mar 2018 22:24:08 -0700 [email protected] wrote:
From: Michael Kelley <[email protected]>
Fix bugs in signaling the Hyper-V host when freeing space in the
host->guestring buffer:1. The
interrupt_maskmust not be used to determine whether to signal on thehost->guestring buffer
2. The ring bufferwrite_indexmust be read (viahv_get_bytes_to_write) *after*pending_send_szis read in order to avoid a race condition
3. Comparisons withpending_send_szmust treat the "equals" case as not-enough-space
4. Don't signal if thepending_send_szfeature is not present. Older versions of Hyper-V that don't implement this feature will poll.
Quoted 9 lines
Quoted 5 lines
Fixes 03bad714a161 ("vmbus: more host signalling avoidance")Cc Stable <[email protected]> # 4.14 and aboveSigned-off-by Michael Kelley <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>What ever happened to this patch? It doesn't seem to be in char-misc, upstream, or stable kernel tree yet.
It was in the 4.14.31 and 4.15.14 stable releases.
thanks,
greg k-h
_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel