Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2410489imu; Thu, 24 Jan 2019 12:16:42 -0800 (PST) X-Google-Smtp-Source: ALg8bN5RhkuiW01XkZPe7jHvCG9wUjUY0g8KvX5CwGQ/t+XPRj/Zp2NyB6J1ABYS7h8yEmsPPVsk X-Received: by 2002:a63:30c8:: with SMTP id w191mr7474541pgw.120.1548361002169; Thu, 24 Jan 2019 12:16:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548361002; cv=none; d=google.com; s=arc-20160816; b=S1+mwf9Dt3kJ6TBp5Z8uSxBre4unkRsEnFh0jPG1IGvbRrK8jJ9MZeaxcGBm3Nalg5 1PjK2jNxMqySPDCaD0/O07VWoZdaYwbendn1HqymZAhcvIffoEBMBLnESlmjuziXTbwb m4rcz8GuckEc7uTwYYeOXit6f9wT+CHrnwrnxUFw4mW/UhWy41Aaow4pLeRsg+wKTk36 LqAc4RvdBFkGk2FhBu76Rxz3d8MSGb6RUOT7zRfD66BwLZwnoBn2JwzNtRq2qZhtJNB2 J1AHFsHnlccqzBwPKejYiulDDAHH1PVut7NdWFXc8U4kkge54q8VSyGVaL6avO8dhx9C h4Zg== 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=PkD9UCUQBHrVhkqfmn0vFvYF637gqxpThUDLG1YQQhs=; b=Tu3SBIPoYy/sbrZEti4ZUXafJOnWd6EofFUHbVGAfkm4FfBDxuFNzNrI4lf0HntfgA 1GzohRYbKRRih5Rb7REuNV/xJA7chBJL7Ks/t4lvITflDY2U743OTLEryGRkX9KWy1EV NkLHcKysQFeA5bG2zaQibVchbZ4ytfOyXg7XaPTYVz8Vnbf0yLVgckdlDU6zDok4MqaZ sMnkT9kUYi/83oQh/SLw4/4/JOmJyLlP+MvPEdU4M5z11JgkkxRIEmEcUrOoLDQO3NS1 bEscuCGvkfi+OW8wwZjDNqbHCgjlhunI46oUapf43m9Y5IbjUB4uj8FHDfAbpTW3rlzD OSXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="f/mmZt4C"; 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 y10si22831657plt.406.2019.01.24.12.16.26; Thu, 24 Jan 2019 12:16:42 -0800 (PST) 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="f/mmZt4C"; 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 S1730019AbfAXTYI (ORCPT + 99 others); Thu, 24 Jan 2019 14:24:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:49226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730004AbfAXTYG (ORCPT ); Thu, 24 Jan 2019 14:24:06 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 69D4F217D7; Thu, 24 Jan 2019 19:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548357845; bh=3BaXdNCT1fVIMiYhxm7S6M0xfl8C9LDgBruj+ADoWTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f/mmZt4CDoOt9LhIbsEMgZhVWOhSKfLJKY25+Wa8EJJoZ93g3VStHd37sP6jwDYqh RL/G1/xaaxDIDoflKrZ9VqUqobsX8raqrHP8uKfhaPQCGQhEvHnhx48e2NwKvqs00C iUOKrUKEfYDeC1EWnl0p2hnCX9IEdZ4+MDChMLOo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , Peter Zijlstra , kernel test robot , Dmitry Safonov Subject: [PATCH 4.4 001/104] tty/ldsem: Wake up readers after timed out down_write() Date: Thu, 24 Jan 2019 20:18:50 +0100 Message-Id: <20190124190155.074369771@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190124190154.968308875@linuxfoundation.org> References: <20190124190154.968308875@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Safonov commit 231f8fd0cca078bd4396dd7e380db813ac5736e2 upstream. ldsem_down_read() will sleep if there is pending writer in the queue. If the writer times out, readers in the queue should be woken up, otherwise they may miss a chance to acquire the semaphore until the last active reader will do ldsem_up_read(). There was a couple of reports where there was one active reader and other readers soft locked up: Showing all locks held in the system: 2 locks held by khungtaskd/17: #0: (rcu_read_lock){......}, at: watchdog+0x124/0x6d1 #1: (tasklist_lock){.+.+..}, at: debug_show_all_locks+0x72/0x2d3 2 locks held by askfirst/123: #0: (&tty->ldisc_sem){.+.+.+}, at: ldsem_down_read+0x46/0x58 #1: (&ldata->atomic_read_lock){+.+...}, at: n_tty_read+0x115/0xbe4 Prevent readers wait for active readers to release ldisc semaphore. Link: lkml.kernel.org/r/20171121132855.ajdv4k6swzhvktl6@wfg-t540p.sh.intel.com Link: lkml.kernel.org/r/20180907045041.GF1110@shao2-debian Cc: Jiri Slaby Cc: Peter Zijlstra Cc: stable@vger.kernel.org Reported-by: kernel test robot Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman --- drivers/tty/tty_ldsem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c @@ -307,6 +307,16 @@ down_write_failed(struct ld_semaphore *s if (!locked) ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem); list_del(&waiter.list); + + /* + * In case of timeout, wake up every reader who gave the right of way + * to writer. Prevent separation readers into two groups: + * one that helds semaphore and another that sleeps. + * (in case of no contention with a writer) + */ + if (!locked && list_empty(&sem->write_wait)) + __ldsem_wake_readers(sem); + raw_spin_unlock_irq(&sem->wait_lock); __set_task_state(tsk, TASK_RUNNING);