Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1026500ybe; Wed, 4 Sep 2019 11:20:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwB8LwokrrRo18+THIlhVscqbgad5/QdvkALigW7lIgw/lDVbu6IcH389nOD2bK26v+0GpC X-Received: by 2002:a62:3145:: with SMTP id x66mr48388644pfx.186.1567621257542; Wed, 04 Sep 2019 11:20:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621257; cv=none; d=google.com; s=arc-20160816; b=ht1ox2lMFMaXJUad1u2SlfBgQY2eDgAe/MWCkt42dTKt+UVcPhTcRA8tO6F6quTqOY EPVGMN3Ujp7AulVQuRO++la6WHER/YeVAko6T7YPFeGErl2P1YUEBW0gqdu7dX0b53KP PdLmEihVcCHMprE5VltNLdKXrMb0ZZMC2WdZm51nlwszmfzKe546xxPSVb2qabCwEwpy lmMcDaCVBFkrmWiRHaQF4o9lrV84kyhU1QRjaeC+3b9HTJtuLuEbOl5LBYh3TNFxqcqy +psdvJY1E9ebvJ+hdecXmTmiPEXsU6R9UX4QJjxBBpHQg/3S9zrmJcSqVzivuYOrhGt5 zQlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bFTJ/ewpQjSAc9AJVJl4XsKPOMQSJoU3Z4odaYAb3gg=; b=CuzY8uiNKv4wAceE0RwqPabYrOdbY1E6QMW4z8vM8ZUekl3M1Hv2lvYv0zbj71e1d7 XdXgV2341WhTdj5n41+hBKB6x5OCHhwlsc2ZRdobrsiZ3YJKOmRpYjceQnnCfKgE7do3 RqlkeE5xsjzeRZF925BUS32adYSs5GcgivW4ubL2y4o+qleRBwt1EY9xTlpLTHN4rddx Pfl1Ho1tPbiMgc6Cnq+gdflNN8A/ybYCZJk1pkM5umjgf5ReZYAVebCu9sRNQwU5msHj rFHo6Yx5k+8V406XeVzeNxCE46e5riehNpL/fPfKGVXmPivKVlSDiJnMaJuKhyEIieP3 BLcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZGdHn8md; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r9si18374826pli.405.2019.09.04.11.20.41; Wed, 04 Sep 2019 11:20:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZGdHn8md; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389656AbfIDSK4 (ORCPT + 99 others); Wed, 4 Sep 2019 14:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:54720 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390170AbfIDSKz (ORCPT ); Wed, 4 Sep 2019 14:10:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0C2FC23400; Wed, 4 Sep 2019 18:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620654; bh=reqK3qDzV0OY1qcf3LHJVujmnjBe/yW+o7i+jB6muVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZGdHn8mdjIWAQY63T0A6/chrIbjfPnQ1yx0kqUFIJoXDD3vdr2EhFBdm85nTsNjbS FW/Ou9mTKslh2Mor0DIIH04N7pYHMpSNQiwGazHqN5Pt0rnagrO3Zv34fOLpHM1jND 6sSTAuW3AEimFrukyvia/i9w+XikFjdRtL6YgouI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Will Deacon , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Jan Stancek , Sasha Levin Subject: [PATCH 5.2 044/143] lcoking/rwsem: Add missing ACQUIRE to read_slowpath sleep loop Date: Wed, 4 Sep 2019 19:53:07 +0200 Message-Id: <20190904175315.793575310@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 99143f82a255e7f054bead8443462fae76dd829e ] While reviewing another read_slowpath patch, both Will and I noticed another missing ACQUIRE, namely: X = 0; CPU0 CPU1 rwsem_down_read() for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); X = 1; rwsem_up_write(); rwsem_mark_wake() atomic_long_add(adjustment, &sem->count); smp_store_release(&waiter->task, NULL); if (!waiter.task) break; ... } r = X; Allows 'r == 0'. Reported-by: Peter Zijlstra (Intel) Reported-by: Will Deacon Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Ingo Molnar Acked-by: Jan Stancek Signed-off-by: Sasha Levin --- kernel/locking/rwsem-xadd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c index 397dedc58432d..385ebcfc31a6d 100644 --- a/kernel/locking/rwsem-xadd.c +++ b/kernel/locking/rwsem-xadd.c @@ -485,8 +485,10 @@ __rwsem_down_read_failed_common(struct rw_semaphore *sem, int state) /* wait to be given the lock */ while (true) { set_current_state(state); - if (!waiter.task) + if (!smp_load_acquire(&waiter.task)) { + /* Orders against rwsem_mark_wake()'s smp_store_release() */ break; + } if (signal_pending_state(state, current)) { raw_spin_lock_irq(&sem->wait_lock); if (waiter.task) -- 2.20.1