From: Peter Zijlstra <peterz@infradead.org>
To: Mateusz Guzik <mguzik@redhat.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de,
mingo@kernel.org, hpa@zytor.com, torvalds@linux-foundation.org
Subject: Re: [PATCH] locking/barriers: evaluate the argument to lockless_dereference only once
Date: Tue, 14 Jun 2016 12:50:38 +0200 [thread overview]
Message-ID: <20160614105038.GC30921@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1465305295-16336-1-git-send-email-mguzik@redhat.com>
On Tue, Jun 07, 2016 at 03:14:55PM +0200, Mateusz Guzik wrote:
> The commit 25841ee0e9d2a ("Validate lockless_dereference() is used on a
> pointer type") added a second use of the parameter to the macro.
>
> This leads to trouble with consumers which use arguments with side
> effects.
Current tip/locking/core doesn't have that patch anymore IIRC, Ingo
folded your thing and we now have:
commit 331b6d8c7afc2e5b900b9dcd850c265e1ba8d8e7
Author: Peter Zijlstra <peterz@infradead.org>
Date: Sun May 22 12:48:27 2016 +0200
locking/barriers: Validate lockless_dereference() is used on a pointer type
Use the type to validate the argument @p is indeed a pointer type.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Paul McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20160522104827.GP3193@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index 793c0829e3a3..06f27fd9d760 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -545,10 +545,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
* Similar to rcu_dereference(), but for situations where the pointed-to
* object's lifetime is managed by something other than RCU. That
* "something other" might be reference counting or simple immortality.
+ *
+ * The seemingly unused void * variable is to validate @p is indeed a pointer
+ * type. All pointer types silently cast to void *.
*/
#define lockless_dereference(p) \
({ \
typeof(p) _________p1 = READ_ONCE(p); \
+ __maybe_unused const void * const _________p2 = _________p1; \
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
(_________p1); \
})
prev parent reply other threads:[~2016-06-14 10:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 13:14 Mateusz Guzik
2016-06-14 10:50 ` Peter Zijlstra [this message]
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=20160614105038.GC30921@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mguzik@redhat.com \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.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
all inboxes | Powered by JetHome®