linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christian Borntraeger <borntraeger@de.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	x86@kernel.org, kvm-ppc@vger.kernel.org, linux-mm@kvack.org,
	xen-devel@lists.xenproject.org, linuxppc-dev@lists.ozlabs.org
Subject: [PATCH 6/8] kernel: tighten rules for ACCESS ONCE
Date: Thu, 15 Jan 2015 09:58:32 +0100	[thread overview]
Message-ID: <1421312314-72330-7-git-send-email-borntraeger@de.ibm.com> (raw)
In-Reply-To: <1421312314-72330-1-git-send-email-borntraeger@de.ibm.com>

Now that all non-scalar users of ACCESS_ONCE have been converted
to READ_ONCE or ASSIGN once, lets tighten ACCESS_ONCE to only
work on scalar types.
This variant was proposed by Alexei Starovoitov.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 include/linux/compiler.h | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index a1c81f8..5e186bf 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -447,12 +447,23 @@ static __always_inline void __assign_once_size(volatile void *p, void *res, int
  * to make the compiler aware of ordering is to put the two invocations of
  * ACCESS_ONCE() in different C statements.
  *
- * This macro does absolutely -nothing- to prevent the CPU from reordering,
- * merging, or refetching absolutely anything at any time.  Its main intended
- * use is to mediate communication between process-level code and irq/NMI
- * handlers, all running on the same CPU.
+ * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
+ * on a union member will work as long as the size of the member matches the
+ * size of the union and the size is smaller than word size.
+ *
+ * The major use cases of ACCESS_ONCE used to be (1) Mediating communication
+ * between process-level code and irq/NMI handlers, all running on the same CPU,
+ * and (2) Ensuring that the compiler does not  fold, spindle, or otherwise
+ * mutilate accesses that either do not require ordering or that interact
+ * with an explicit memory barrier or atomic instruction that provides the
+ * required ordering.
+ *
+ * If possible use READ_ONCE/ASSIGN_ONCE instead.
  */
-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
+#define __ACCESS_ONCE(x) ({ \
+	 __maybe_unused typeof(x) __var = 0; \
+	(volatile typeof(x) *)&(x); })
+#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
 
 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
 #ifdef CONFIG_KPROBES
-- 
1.9.3

  parent reply	other threads:[~2015-01-15  8:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-15  8:58 [PATCH 0/8] current ACCESS_ONCE patch queue Christian Borntraeger
2015-01-15  8:58 ` [PATCH 1/8] ppc/kvm: Replace ACCESS_ONCE with READ_ONCE Christian Borntraeger
2015-01-15 23:09   ` Michael Ellerman
2015-01-16  9:43     ` Christian Borntraeger
2015-01-15  8:58 ` [PATCH 2/8] ppc/hugetlbfs: " Christian Borntraeger
2015-01-15  8:58 ` [PATCH 3/8] x86/xen/p2m: " Christian Borntraeger
2015-01-15  9:26   ` Jürgen Groß
2015-01-15 10:43   ` [Xen-devel] " David Vrabel
2015-01-15 11:07     ` Christian Borntraeger
2015-01-15  8:58 ` [PATCH 4/8] x86/spinlock: Leftover conversion ACCESS_ONCE->READ_ONCE Christian Borntraeger
2015-01-15 19:38   ` Oleg Nesterov
2015-01-15 19:51     ` Christian Borntraeger
2015-01-15 20:01       ` Oleg Nesterov
2015-01-15 21:00         ` Christian Borntraeger
2015-01-15  8:58 ` [PATCH 5/8] mm/gup: Replace ACCESS_ONCE with READ_ONCE Christian Borntraeger
2015-01-15  8:58 ` Christian Borntraeger [this message]
2015-01-15  8:58 ` [PATCH 7/8] next: sh: Fix compile error Christian Borntraeger
2015-01-15  8:58 ` [PATCH 8/8] kernel: Fix sparse warning for ACCESS_ONCE Christian Borntraeger
2015-01-16 12:12 ` [PATCH 0/8] current ACCESS_ONCE patch queue Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421312314-72330-7-git-send-email-borntraeger@de.ibm.com \
    --to=borntraeger@de.ibm.com \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).