From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933173AbbCYPBc (ORCPT ); Wed, 25 Mar 2015 11:01:32 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:36522 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932427AbbCYPB3 (ORCPT ); Wed, 25 Mar 2015 11:01:29 -0400 Message-ID: <5512CDC4.10203@gmail.com> Date: Wed, 25 Mar 2015 16:01:24 +0100 From: Patrick Marlier User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: paulmck@linux.vnet.ibm.com CC: linux-kernel@vger.kernel.org, Josh Triplett Subject: Re: [PATCH 1/3] rculist: Fix list_entry_rcu to read ptr with rcu_dereference_raw References: <55113D0A.2030302@gmail.com> <20150325143018.GZ5718@linux.vnet.ibm.com> In-Reply-To: <20150325143018.GZ5718@linux.vnet.ibm.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/25/2015 03:30 PM, Paul E. McKenney wrote: > On Tue, Mar 24, 2015 at 11:31:38AM +0100, Patrick Marlier wrote: >> Change to read effectively ptr with rcu_dereference_raw and not the >> __ptr variable on the stack. >> >> Signed-off-by: Patrick Marlier > Avoiding an extra load could be worthwhile in a number of situations, > agreed. Not only a load. It adds a store and a load on the stack and I think this creates a dependency in the processor pipeline. > However, won't this change cause sparse to complain if invoked on a > non-RCU-protected pointer? The ability to use list-RCU API > members on both RCU and non-RCU pointers was one of the points > of the previous commit, right? Probably we can put back the cast but I am not familiar enough with the RCU API. Also, the problem here is that you probably want ACCESS_ONCE to happen on the content of 'ptr' and not on the stack variable '__ptr'. (you have to follow this chain: rcu_dereference_raw -> rcu_dereference_check -> __rcu_dereference_check -> lockless_dereference -> ACCESS_ONCE) #define lockless_dereference(p) \ ({ \ typeof(p) _________p1 = ACCESS_ONCE(p); \ smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ (_________p1); \ }) #define __ACCESS_ONCE(x) ({ \ __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \ (volatile typeof(x) *)&(x); }) #define ACCESS_ONCE(x) (*__ACCESS_ONCE(x)) Note that ACCESS_ONCE is doing "&" on x. IMHO, I would prefer saving some useless instructions for better performance rather than giving too much flexibility on the API (also pretty sure the cast can be still done). -- Patrick Marlier