From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751699AbcFNKut (ORCPT ); Tue, 14 Jun 2016 06:50:49 -0400 Received: from merlin.infradead.org ([205.233.59.134]:36101 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750760AbcFNKus (ORCPT ); Tue, 14 Jun 2016 06:50:48 -0400 Date: Tue, 14 Jun 2016 12:50:38 +0200 From: Peter Zijlstra To: Mateusz Guzik 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 Message-ID: <20160614105038.GC30921@twins.programming.kicks-ass.net> References: <1465305295-16336-1-git-send-email-mguzik@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1465305295-16336-1-git-send-email-mguzik@redhat.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 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) Cc: Alexey Dobriyan Cc: Andrew Morton Cc: Linus Torvalds Cc: Paul E. McKenney Cc: Paul McKenney Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20160522104827.GP3193@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar 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); \ })