Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1363778 > unrolled thread

[PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile

Started by"K. Y. Srinivasan" <kys@microsoft.com>
First post2016-03-24 00:20 +0100
Last post2016-04-02 00:10 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile "K. Y. Srinivasan" <kys@microsoft.com> - 2016-03-24 00:20 +0100
    Re: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read  variables that are volatile Greg KH <gregkh@linuxfoundation.org> - 2016-04-01 02:10 +0200
      RE: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables  that are volatile KY Srinivasan <kys@microsoft.com> - 2016-04-02 00:10 +0200

#1363778 — [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile

From"K. Y. Srinivasan" <kys@microsoft.com>
Date2016-03-24 00:20 +0100
Subject[PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile
Message-ID<rg0ee-2bF-7@gated-at.bofh.it>
Use the READ_ONCE macro to access variabes that can change asynchronously.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
 drivers/hv/ring_buffer.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/ring_buffer.c b/drivers/hv/ring_buffer.c
index 902375b..2919395 100644
--- a/drivers/hv/ring_buffer.c
+++ b/drivers/hv/ring_buffer.c
@@ -69,7 +69,7 @@ u32 hv_end_read(struct hv_ring_buffer_info *rbi)
 static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
 {
 	mb();
-	if (rbi->ring_buffer->interrupt_mask)
+	if (READ_ONCE(rbi->ring_buffer->interrupt_mask))
 		return false;
 
 	/* check interrupt_mask before read_index */
@@ -78,7 +78,7 @@ static bool hv_need_to_signal(u32 old_write, struct hv_ring_buffer_info *rbi)
 	 * This is the only case we need to signal when the
 	 * ring transitions from being empty to non-empty.
 	 */
-	if (old_write == rbi->ring_buffer->read_index)
+	if (old_write == READ_ONCE(rbi->ring_buffer->read_index))
 		return true;
 
 	return false;
@@ -102,8 +102,9 @@ static bool hv_need_to_signal(u32 old_write, 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 pending_sz = rbi->ring_buffer->pending_send_sz;
+	u32 pending_sz;
 
+	pending_sz = READ_ONCE(rbi->ring_buffer->pending_send_sz);
 	/* If the other end is not blocked on write don't bother. */
 	if (pending_sz == 0)
 		return false;
-- 
1.7.4.1

[toc] | [next] | [standalone]


#1368893 — Re: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile

FromGreg KH <gregkh@linuxfoundation.org>
Date2016-04-01 02:10 +0200
SubjectRe: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile
Message-ID<riUP0-4r5-5@gated-at.bofh.it>
In reply to#1363778
On Wed, Mar 23, 2016 at 05:53:52PM -0700, K. Y. Srinivasan wrote:
> Use the READ_ONCE macro to access variabes that can change asynchronously.

Why?  What is this "fixing"?

thanks,

greg k-h

[toc] | [prev] | [next] | [standalone]


#1369629 — RE: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile

FromKY Srinivasan <kys@microsoft.com>
Date2016-04-02 00:10 +0200
SubjectRE: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read variables that are volatile
Message-ID<rjfqq-2i4-9@gated-at.bofh.it>
In reply to#1368893

> -----Original Message-----
> From: Greg KH [mailto:gregkh@linuxfoundation.org]
> Sent: Thursday, March 31, 2016 5:01 PM
> To: KY Srinivasan <kys@microsoft.com>
> Cc: linux-kernel@vger.kernel.org; devel@linuxdriverproject.org;
> olaf@aepfle.de; apw@canonical.com; vkuznets@redhat.com;
> jasowang@redhat.com
> Subject: Re: [PATCH 2/7] Drivers: hv: vmbus: Use READ_ONCE() to read
> variables that are volatile
> 
> On Wed, Mar 23, 2016 at 05:53:52PM -0700, K. Y. Srinivasan wrote:
> > Use the READ_ONCE macro to access variabes that can change
> asynchronously.
> 
> Why?  What is this "fixing"?

This is to prevent the compiler optimizations and moving the code. This is the
recommended mechanism for reading volatile variables. 

Regards,

K. Y
> 
> thanks,
> 
> greg k-h

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web