Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1064582ybl; Wed, 14 Aug 2019 10:08:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9yUPY74d9SBkViTVUUbfCzWwrvWiBzqncS2zhIyNFAARdqZ/x58HIz5goemI0oJVLyv9x X-Received: by 2002:a17:902:bf07:: with SMTP id bi7mr396322plb.167.1565802500928; Wed, 14 Aug 2019 10:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565802500; cv=none; d=google.com; s=arc-20160816; b=QtUqIQg5RQ0M2BLIZXjILOb3funcDl6Oxw2KTXkJZsO6pIS8t7Y8tlYRXy41J40vum mQpfFobm17k+kt5vrXj13F0M9l4RL2yuYWtXiilKI3STJ7EEvUYbIdZ1MHkYAKZXR91w DZ28u9EKQHQ1Bb4LdxbqkMOjClsgogif/HCEkc4XSLqquad0T1AId7+Y3N2uTwTfQcty E5Wuno9AMrqvJ/28sN4ONfSniV4Z5QPQxtcphi4NM8UdNTyFW6/QnPkcN0tPXC4W28Y1 IE5ZjK44GFuXO3LIw0yirihBk7h5ehZZCHUEVOye/DINmMQxO0CKjMOObeZIOjIJEvB4 WSAw== 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=hwgByrdYoUmU8jBZq/V3U8nPDlk+/2wrVY25r4c4Qc0=; b=a3TA0KKbH340XBOkf+34HQ4EIps4+cxMW7UXoVgxeN7vSle112rX/3VuQhWxn25opC SI5XbNzJY6MZ6PHAfADkL9ADG6aONV7VjIsfxpKDQALoTLeLAxIahODMC0fDGmthlejH RLi8fybqOKwz+YAGeyG8uOgxjgzaAtXMMO1Ida7RLEvRZ/aHedELXshtQN3wYQ5iIHty apM1zE2PmiC0ojJLywtmcqlkZeqYlZt0o+JfxOWWoyWgQpIjw+jjxq9y1BsrT2ay1lQq BzOjwWZQuDtFkXV/Alsiy4wH7Z7Tv/zAjevxs1XrYGdaDKTnWocPkYUAheJAQU4mZ/bI O6Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ffaOjDja; 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 k192si173796pge.222.2019.08.14.10.08.04; Wed, 14 Aug 2019 10:08:20 -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=ffaOjDja; 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 S1729736AbfHNRGq (ORCPT + 99 others); Wed, 14 Aug 2019 13:06:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:55904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729717AbfHNRGm (ORCPT ); Wed, 14 Aug 2019 13:06:42 -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 F3AF2208C2; Wed, 14 Aug 2019 17:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802401; bh=sI1rR7Q0OoFFmyKoxb+1VVO9/zhq4ryum9OVSMrKso4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ffaOjDjaIRxzsjVv8eyzeJPfokwvsa8gUo3aCLWhuWA66Jk9CitsvvH5/cUur6UoH N5LesV0aOXalxjxdqunjUk+b8EA+B/C1cWQg+8A4VH2MKIRngxP0Zw5WV1+kqb13Tp nBha9uLsqIkl4xDFYB6AO6ySu2nMu7FFRGm2VPkg= 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 5.2 111/144] tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop Date: Wed, 14 Aug 2019 19:01:07 +0200 Message-Id: <20190814165804.554716394@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@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 717292c1c0dfc..60ff236a3d63d 100644 --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c @@ -93,8 +93,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); } @@ -194,7 +193,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