From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0127.outbound.protection.outlook.com ([104.47.40.127]:11008 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032207AbeCAP3C (ORCPT ); Thu, 1 Mar 2018 10:29:02 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Jianyu Zhan , Thomas Gleixner , Sasha Levin Subject: [added to the 4.1 stable tree] futex: Replace barrier() in unqueue_me() with READ_ONCE() Date: Thu, 1 Mar 2018 15:23:57 +0000 Message-ID: <20180301152116.1486-142-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jianyu Zhan This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 29b75eb2d56a714190a93d7be4525e617591077a ] Commit e91467ecd1ef ("bug in futex unqueue_me") introduced a barrier() in unqueue_me() to prevent the compiler from rereading the lock pointer which might change after a check for NULL. Replace the barrier() with a READ_ONCE() for the following reasons: 1) READ_ONCE() is a weaker form of barrier() that affects only the specific load operation, while barrier() is a general compiler level memory barri= er. READ_ONCE() was not available at the time when the barrier was added. 2) Aside of that READ_ONCE() is descriptive and self explainatory while a barrier without comment is not clear to the casual reader. No functional change. [ tglx: Massaged changelog ] Signed-off-by: Jianyu Zhan Acked-by: Christian Borntraeger Acked-by: Darren Hart Cc: dave@stgolabs.net Cc: peterz@infradead.org Cc: linux@rasmusvillemoes.dk Cc: akpm@linux-foundation.org Cc: fengguang.wu@intel.com Cc: bigeasy@linutronix.de Link: http://lkml.kernel.org/r/1457314344-5685-1-git-send-email-nasa4836@gm= ail.com Signed-off-by: Thomas Gleixner Signed-off-by: Sasha Levin --- kernel/futex.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 585cf96dab32..959cc4fc6de5 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -1831,8 +1831,12 @@ static int unqueue_me(struct futex_q *q) =20 /* In the common case we don't take the spinlock, which is nice. */ retry: - lock_ptr =3D q->lock_ptr; - barrier(); + /* + * q->lock_ptr can change between this read and the following spin_lock. + * Use READ_ONCE to forbid the compiler from reloading q->lock_ptr and + * optimizing lock_ptr out of the logic below. + */ + lock_ptr =3D READ_ONCE(q->lock_ptr); if (lock_ptr !=3D NULL) { spin_lock(lock_ptr); /* --=20 2.14.1