Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1073711ybl; Wed, 14 Aug 2019 10:16:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqypx4b8sID8JaQqgd0eNBcW2QjbZ4DFabavWWC61JY2RHuMAOP26YjOu7wKvyMJmxawfUKY X-Received: by 2002:a17:902:bb8d:: with SMTP id m13mr412682pls.307.1565802966190; Wed, 14 Aug 2019 10:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802966; cv=none; d=google.com; s=arc-20160816; b=O6lYLx9au5dGUhY9vI4O/whxBIn2u3SzCNvY9c30Oo/AJIgATb7VB34ucho4WFIs8x NIvu9HSyzlOGnvOp14aP5kWBEZ/+FO7QzeEDPP/kKFmVKY67ifXZQlZxQZaDUwR0MURF bSohqFsvGg/1/ZFkuUmJqHIK6FJxBeVW4Sy2+0cSyS5V/flFh4vDZIYMKIoAaQZMyAjp u+Zp3Q+D9b2dfAEp/z4eiui+bHdHw9rbh/0Bz4SlTw2N+tK35sE37Z96NWl1+1WMCsbA 3aIDV+Uo2bwUpi9/MfI3srGBdWKRvrMGrlaFxwVVIl/TYGitVox7bLWLLajuCEwv8Mfj 2Gkw== 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=FpZrmUMNqiz/Ou4r/fNnEAalxsGM/uZS61PFAD8niag=; b=YHMRRLDVW8dJt306r7K/G99o9HHXIbJkA5Zafj2WN7iiubI6lAw78hgpluLQ+uAFhg 7sSNUPoL4cMnxI9vXb8YDUyWZRbASHG2VVesDyScWIqloo3Wpl7tDo0cLDOJX4RWpWNt HrK2XnDLB4KpoCEmtKpp+oc8wSVNYXJPgNbDUX2SIRCpvydMa1k6UMiyzaQ9aBlchhF8 zHsjXqGdmeURbKCprXljUvARUXzg1wrKEJvSAQRw3eivLiLMj456tvWZemGbBRTgpuC2 AFxCPgO4NilBaYRjsg4Ch/TBM3VXT8cxFu5rgv7mSVPGJLbxbQWrmltJgdFaNzN/CeJH AP+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IbqtHoJB; 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 h194si77867pfe.144.2019.08.14.10.15.50; Wed, 14 Aug 2019 10:16:06 -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=IbqtHoJB; 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 S1730990AbfHNRPT (ORCPT + 99 others); Wed, 14 Aug 2019 13:15:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:39848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731206AbfHNRPQ (ORCPT ); Wed, 14 Aug 2019 13:15:16 -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 538E0214DA; Wed, 14 Aug 2019 17:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802915; bh=dE3D+F4skbFjy5hvykzWYLmOKidb7j7vPCxSnfZi97k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IbqtHoJBTLoCZgI4y5Gn9XJ/7zYeqzeaYfXaSqwP9Dgw97b5EUNClvxW5zNURSTcJ f85pBK/TTGIH1K7cuU8C0NFjm9uGElzHt/epu8yqtH9K1L0vv6FmuAHCNyplevvqj4 uWisg9g7wm9YNf7PI+aiDPoCcBbYp8o0Xt91TpSs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will Deacon , "Peter Zijlstra (Intel)" , Linus Torvalds , Peter Hurley , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.14 49/69] tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop Date: Wed, 14 Aug 2019 19:01:47 +0200 Message-Id: <20190814165748.892413705@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165744.822314328@linuxfoundation.org> References: <20190814165744.822314328@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 952041a8639a7a3a73a2b6573cb8aa8518bc39f8 ] While reviewing rwsem down_slowpath, Will noticed ldsem had a copy of a bug we just found for rwsem. 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: Will Deacon Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon Cc: Linus Torvalds Cc: Peter Hurley Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: 4898e640caf0 ("tty: Add timed, writer-prioritized rw semaphore") Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- drivers/tty/tty_ldsem.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/tty_ldsem.c b/drivers/tty/tty_ldsem.c index 5c2cec298816b..c6ce34161281a 100644 --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c @@ -139,8 +139,7 @@ static void __ldsem_wake_readers(struct ld_semaphore *sem) list_for_each_entry_safe(waiter, next, &sem->read_wait, list) { tsk = waiter->task; - smp_mb(); - waiter->task = NULL; + smp_store_release(&waiter->task, NULL); wake_up_process(tsk); put_task_struct(tsk); } @@ -235,7 +234,7 @@ down_read_failed(struct ld_semaphore *sem, long count, long timeout) for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); - if (!waiter.task) + if (!smp_load_acquire(&waiter.task)) break; if (!timeout) break; -- 2.20.1