Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758614AbcCDBNN (ORCPT ); Thu, 3 Mar 2016 20:13:13 -0500 Received: from mail-ob0-f182.google.com ([209.85.214.182]:34174 "EHLO mail-ob0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753967AbcCDBNM (ORCPT ); Thu, 3 Mar 2016 20:13:12 -0500 MIME-Version: 1.0 In-Reply-To: <20160303170532.GC1092@dvhart-mobl5.amr.corp.intel.com> References: <1457019485-26441-1-git-send-email-nasa4836@gmail.com> <20160303170532.GC1092@dvhart-mobl5.amr.corp.intel.com> From: Jianyu Zhan Date: Fri, 4 Mar 2016 09:12:31 +0800 Message-ID: Subject: Re: [PATCH] futex: replace bare barrier() with more lightweight READ_ONCE() To: Darren Hart Cc: LKML , Peter Zijlstra , Thomas Gleixner , dave@stgolabs.net, Andrew Morton , Ingo Molnar , Rasmus Villemoes , dvhart@linux.intel.com, Christian Borntraeger , Fengguang Wu , bigeasy@linutronix.de Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 37 On Fri, Mar 4, 2016 at 1:05 AM, Darren Hart wrote: > I thought I provided a corrected comment block.... maybe I didn't. We have been > working on improving the futex documentation, so we're paying close attention to > terminology as well as grammar. This one needs a couple minor tweaks. I suggest: > > /* > * Use READ_ONCE to forbid the compiler from reloading q->lock_ptr and > * optimizing lock_ptr out of the logic below. > */ > > The bit about q->lock_ptr possibly changing is already covered by the large > comment block below the spin_lock(lock_ptr) call. The large comment block is explaining the why the retry logic is required. To achieve this semantic requirement, the READ_ONCE is needed to prevent compiler optimizing it by doing double loads. So I think the comment above should explain this tricky part. > /* Use READ_ONCE to forbid the compiler from reloading q->lock_ptr in spin_lock() */ And as for preventing from optimizing the lock_ptr out of the retry code block, I have consult Paul Mckenney, he suggests one more READ_ONCE should be added here: if (unlikely(lock_ptr != READ_ONCE(q->lock_ptr))) { <------------------------------ spin_unlock(lock_ptr); goto retry; } And I think this are two problem, and should be separated into two patches? Regards, Jianyu Zhan