Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4309798ybl; Mon, 26 Aug 2019 08:33:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaUKoO4vtKgdm/4Ei1PnnF0NflM9c86w0GwOTZfKdbY9LdL+huW9XbOPp3fT9N07KWafNt X-Received: by 2002:a17:902:8a4:: with SMTP id 33mr7608245pll.322.1566833591045; Mon, 26 Aug 2019 08:33:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566833591; cv=none; d=google.com; s=arc-20160816; b=PDYQkt+udrJWsLzz8ffhNCpYYAuhfxK3GYvttAsOZwkEY4fgPiTZBcWbb8Hk2fOpL7 h2dPYmmqDhtYEjiH4Ap1Oia9nULcKmbAc6GXDZt52//+Ra6IDtGhcUTj6ggzei82PB/d KSiCZVhX01T4vuSts8dgCyT0j98NSl5NpHW97NApSvDzYVDb1bY3LakVltEdbDQcK6P9 cQolanKJB3GtwocEyteZvF73XAvxqQVKEa5qW78M2i870XvJ7xsqRnNo1a7KdT1Q1o42 L597VPCwGunGAZQMiiMcrZ18bR4Gl/rfc2Tpt7HDc2wkj2/pdwfBWfVJQ0LiFgsItlgN 5XKg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ms3xQ7YEXMDvIC4Sl67KrtOOUUlioRkrOuQtoQmg6aU=; b=CwuyOy7CcB8o9eJNbZe+I8TjVr++qajt6II8tifdRAjg+92Cy2uoVJPFs1zUBCN8NT HSYkhp7HPe+05/mJJBAM/n6YHoaL4wORNqApBv7TfmiiH1SWe2fBl/2sFdEPEf+iQA9+ rx0bwrWvZPMqDIyBmUHTOZdl9ugWskgfk62uv6GeTXym9/919ITcDtS/Xk+EsRowJh8P Xnp2hGs+b7ALfF3YkJLkqHOvVgN/olFm8E3bg1MU6Ri9g9LAOogToo/KvAp4yI5UA+qp Zri/9QxOlXcs4sek7D8uGlwCxzmZ4LqUkUMX+TSxHeifUoSg417/LMP1Jyi0Q/DJnwfY ebjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nAPge+57; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t16si10759844pfq.88.2019.08.26.08.32.55; Mon, 26 Aug 2019 08:33:11 -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=nAPge+57; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732494AbfHZOb3 (ORCPT + 99 others); Mon, 26 Aug 2019 10:31:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:41358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbfHZOb1 (ORCPT ); Mon, 26 Aug 2019 10:31:27 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E75B021872; Mon, 26 Aug 2019 14:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566829886; bh=DCula5wz850U7JxrQ1gzlc8ZfKRh7hzVzTC/fMTmSCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nAPge+57McI/g7uojKda2avW2UEoz4Oymjut9Ca/jxzLVEmqEIVdFu/3hDsoSZdRR Eqj1QJIYCLwE8qliXqL1wFvQHyOFO8WK8pGQGdORLh1p3kKWa09ANWprw6D3BbWd0b q+G+ZwQzEJ0B0Kl4moof4Epp0yTEKkYW88BW5poA= From: Sasha Levin To: peterz@infradead.org, will@kernel.org, jstancek@redhat.com, stable@vger.kernel.org Cc: torvalds@linux-foundation.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Ingo Molnar , Sasha Levin Subject: [PATCH v5.2 2/2] lcoking/rwsem: Add missing ACQUIRE to read_slowpath sleep loop Date: Mon, 26 Aug 2019 10:31:14 -0400 Message-Id: <20190826143114.23471-2-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190826143114.23471-1-sashal@kernel.org> References: <20190826143114.23471-1-sashal@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ 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 Signed-off-by: Sasha Levin --- This is a backport for the v5.2 stable tree. There were multiple reports of this issue being hit. Given that there were a few changes to the code around this, I'd appreciate an ack before pulling it in. 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