All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
@ 2018-03-05  5:24 ` kys
  0 siblings, 0 replies; 7+ messages in thread
From: kys @ 2018-03-05  5:24 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, vkuznets, jasowang,
	leann.ogasawara, marcelo.cerri, sthemmin
  Cc: Michael Kelley, Stable

From: Michael Kelley <mhkelley@outlook.com>

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")

Cc: Stable <stable@vger.kernel.org> # 4.14 and above
Signed-off-by: Michael Kelley <mhkelley@outlook.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
 drivers/hv/ring_buffer.c | 52 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 1aa17795727b..3cd7f29906ae 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -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);
 }
-- 
2.15.1

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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
@ 2018-03-05  5:24 ` kys
  0 siblings, 0 replies; 7+ messages in thread
From: kys @ 2018-03-05  5:24 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, olaf, apw, vkuznets, jasowang,
	leann.ogasawara, marcelo.cerri, sthemmin
  Cc: Michael Kelley, Stable, K . Y . Srinivasan

From: Michael Kelley <mhkelley@outlook.com>

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")

Cc: Stable <stable@vger.kernel.org> # 4.14 and above
Signed-off-by: Michael Kelley <mhkelley@outlook.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
 drivers/hv/ring_buffer.c | 52 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 1aa17795727b..3cd7f29906ae 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -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);
 }
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
  2018-03-05  5:24 ` kys
  (?)
@ 2018-03-28 19:01 ` Stephen Hemminger
  2018-03-28 19:18   ` Joshua R. Poulson
  2018-03-29  7:24     ` Greg KH
  -1 siblings, 2 replies; 7+ messages in thread
From: Stephen Hemminger @ 2018-03-28 19:01 UTC (permalink / raw)
  To: kys
  Cc: kys, gregkh, linux-kernel, devel, olaf, apw, vkuznets, jasowang,
	leann.ogasawara, marcelo.cerri, sthemmin, Michael Kelley, Stable

On Sun,  4 Mar 2018 22:24:08 -0700
kys@exchange.microsoft.com wrote:

> From: Michael Kelley <mhkelley@outlook.com>
> 
> 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")
> 
> Cc: Stable <stable@vger.kernel.org> # 4.14 and above
> Signed-off-by: Michael Kelley <mhkelley@outlook.com>
> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>

What ever happened to this patch? It doesn't seem to be in char-misc, upstream,
or stable kernel tree yet.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
  2018-03-28 19:01 ` Stephen Hemminger
@ 2018-03-28 19:18   ` Joshua R. Poulson
  2018-03-28 23:25     ` Stephen Hemminger
  2018-03-29  7:24     ` Greg KH
  1 sibling, 1 reply; 7+ messages in thread
From: Joshua R. Poulson @ 2018-03-28 19:18 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: K. Y. Srinivasan, KY Srinivasan, gregkh, linux-kernel, devel,
	olaf, Andy Whitcroft, Vitaly Kuznetsov, jasowang,
	Leann Ogasawara, Marcelo Henrique Cerri, Stephen Hemminger,
	Michael Kelley, Stable

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v4.16-rc7&id=655296c8bbeffcf020558c4455305d597a73bde1

On Wed, Mar 28, 2018 at 12:01 PM, Stephen Hemminger
<stephen@networkplumber.org> wrote:
> On Sun,  4 Mar 2018 22:24:08 -0700
> kys@exchange.microsoft.com wrote:
>
>> From: Michael Kelley <mhkelley@outlook.com>
>>
>> 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")
>>
>> Cc: Stable <stable@vger.kernel.org> # 4.14 and above
>> Signed-off-by: Michael Kelley <mhkelley@outlook.com>
>> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
>
> What ever happened to this patch? It doesn't seem to be in char-misc, upstream,
> or stable kernel tree yet.
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
  2018-03-28 19:18   ` Joshua R. Poulson
@ 2018-03-28 23:25     ` Stephen Hemminger
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2018-03-28 23:25 UTC (permalink / raw)
  To: 'Joshua R. Poulson'
  Cc: 'K. Y. Srinivasan', 'KY Srinivasan',
	gregkh, linux-kernel, devel, olaf, 'Andy Whitcroft',
	'Vitaly Kuznetsov', jasowang, 'Leann Ogasawara',
	'Marcelo Henrique Cerri', 'Stephen Hemminger',
	'Michael Kelley', 'Stable'

Thanks, I hadn't updated to rc7 yet


-----Original Message-----
From: Joshua R. Poulson <jrp@pun.org> 
Sent: Wednesday, March 28, 2018 12:18 PM
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: K. Y. Srinivasan <kys@exchange.microsoft.com>; KY Srinivasan <kys@microsoft.com>; gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org; devel@linuxdriverproject.org; olaf@aepfle.de; Andy Whitcroft <apw@canonical.com>; Vitaly Kuznetsov <vkuznets@redhat.com>; jasowang@redhat.com; Leann Ogasawara <leann.ogasawara@canonical.com>; Marcelo Henrique Cerri <marcelo.cerri@canonical.com>; Stephen Hemminger <sthemmin@microsoft.com>; Michael Kelley <mhkelley@outlook.com>; Stable <stable@vger.kernel.org>
Subject: Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v4.16-rc7&id=655296c8bbeffcf020558c4455305d597a73bde1

On Wed, Mar 28, 2018 at 12:01 PM, Stephen Hemminger
<stephen@networkplumber.org> wrote:
> On Sun,  4 Mar 2018 22:24:08 -0700
> kys@exchange.microsoft.com wrote:
>
>> From: Michael Kelley <mhkelley@outlook.com>
>>
>> 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")
>>
>> Cc: Stable <stable@vger.kernel.org> # 4.14 and above
>> Signed-off-by: Michael Kelley <mhkelley@outlook.com>
>> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
>
> What ever happened to this patch? It doesn't seem to be in char-misc, upstream,
> or stable kernel tree yet.
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
  2018-03-28 19:01 ` Stephen Hemminger
@ 2018-03-29  7:24     ` Greg KH
  2018-03-29  7:24     ` Greg KH
  1 sibling, 0 replies; 7+ messages in thread
From: Greg KH @ 2018-03-29  7:24 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: olaf, kys, sthemmin, jasowang, linux-kernel, Stable,
	Michael Kelley, marcelo.cerri, apw, devel, vkuznets,
	leann.ogasawara

On Wed, Mar 28, 2018 at 12:01:42PM -0700, Stephen Hemminger wrote:
> On Sun,  4 Mar 2018 22:24:08 -0700
> kys@exchange.microsoft.com wrote:
> 
> > From: Michael Kelley <mhkelley@outlook.com>
> > 
> > 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")
> > 
> > Cc: Stable <stable@vger.kernel.org> # 4.14 and above
> > Signed-off-by: Michael Kelley <mhkelley@outlook.com>
> > Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
> 
> 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
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling
@ 2018-03-29  7:24     ` Greg KH
  0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2018-03-29  7:24 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: kys, kys, linux-kernel, devel, olaf, apw, vkuznets, jasowang,
	leann.ogasawara, marcelo.cerri, sthemmin, Michael Kelley, Stable

On Wed, Mar 28, 2018 at 12:01:42PM -0700, Stephen Hemminger wrote:
> On Sun,  4 Mar 2018 22:24:08 -0700
> kys@exchange.microsoft.com wrote:
> 
> > From: Michael Kelley <mhkelley@outlook.com>
> > 
> > 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")
> > 
> > Cc: Stable <stable@vger.kernel.org> # 4.14 and above
> > Signed-off-by: Michael Kelley <mhkelley@outlook.com>
> > Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
> 
> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-03-29  7:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-05  5:24 [PATCH 1/1] Drivers: hv: vmbus: Fix ring buffer signaling kys
2018-03-05  5:24 ` kys
2018-03-28 19:01 ` Stephen Hemminger
2018-03-28 19:18   ` Joshua R. Poulson
2018-03-28 23:25     ` Stephen Hemminger
2018-03-29  7:24   ` Greg KH
2018-03-29  7:24     ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.