From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753975AbcFGHKg (ORCPT ); Tue, 7 Jun 2016 03:10:36 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:55921 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753908AbcFGHKd (ORCPT ); Tue, 7 Jun 2016 03:10:33 -0400 Date: Tue, 7 Jun 2016 09:10:27 +0200 From: Peter Zijlstra To: Mateusz Guzik Cc: linux-tip-commits@vger.kernel.org, paulmck@linux.vnet.ibm.com, akpm@linux-foundation.org, torvalds@linux-foundation.org, adobriyan@gmail.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, hpa@zytor.com Subject: Re: [tip:locking/core] locking/barriers: Validate lockless_dereference() is used on a pointer type Message-ID: <20160607071027.GJ30909@twins.programming.kicks-ass.net> References: <20160522104827.GP3193@twins.programming.kicks-ass.net> <20160606213138.rizmdnhgdqyavnub@mguzik> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160606213138.rizmdnhgdqyavnub@mguzik> 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 Mon, Jun 06, 2016 at 11:31:39PM +0200, Mateusz Guzik wrote: > The reason is that leaf_walk_rcu does get_child_rcu(pn, cindex++), which > ends up in lockless_dereference as pn[cindex++], which is now evaluated > twice. Indeed, bad that; yes I think the below will work, will you send a proper patch so I can apply? > The simplest fix I see does the assignment later, that is: > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index e9c6417..06f27fd 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -551,8 +551,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > */ > #define lockless_dereference(p) \ > ({ \ > - __maybe_unused const void * const _________p2 = p; \ > typeof(p) _________p1 = READ_ONCE(p); \ > + __maybe_unused const void * const _________p2 = _________p1; \ > smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ > (_________p1); \ > }) > > -- > Mateusz Guzik