Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6258746imu; Mon, 21 Jan 2019 06:00:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN6E6dAz09Bz923VVMwlArxmQ9MzaVGL1ZYEeSE2jOUq1vcuR/OehjN2lKIIm7o685rGwGnu X-Received: by 2002:a17:902:32c3:: with SMTP id z61mr30241015plb.114.1548079239045; Mon, 21 Jan 2019 06:00:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079239; cv=none; d=google.com; s=arc-20160816; b=YRw0fxPMLcLfVgaM7FiAQKeS4x5a7e9mzYASG6dAtEpjIGqBFoexpUcbYpGRCtYOYf Nh0yy2zJ8R20PpSHv0HKGR66FKZ4wYDA46PuiT3Z8hX7TmSm/vow3v9ERWynr8cDe6XS LMpBfP0hZQZgGu9bNzSn9N2lNX14cgOwvpbfOiXyAxOS7zDVP6DY0ymTmXaR9/iQXe9Z pNFLrMb1N54x9eZ1x7SMJpkd8dOeplPH2GxPtQ4wU3gGb1nC6T6Zi91sBKj3jPqKH747 8DxGiq6qWZ0VrMVzA9KOLT7BAK+gSrrn3/0b1EnwAYseAPc4fPZtH34Ad2ZkufBeciWs EXFw== 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=6OPHjytGdPrvQHdvcEbXDL0PYaEtIe5fmv+UJpzNbfU=; b=IZxy88wLXd3BFOJL8pDWcr3VHDXmsnbnoUm2eu7rQrYydIH37d4XVJ6YmbcnV3RCQm rzxLwMZNBVCIQbk+feND0/chtqg/fg0XT5XU8ATC7fvl+RdV7rSkMZZF4C6mFN3RT/n7 7u09xVDvC7dL4A8CUYwyifXg15us2dNFpMnQZD6jpb5yHtix+govve3QdsmJeoofdu1r x4Wuvr4MSGeLhzhjushFjTheY7idcLjOSqir74yiQ3cneBYHEVu8HP6myegvIYFjVSQ0 8c8fVvsjnGCbbQCyNixpkjLTAF7Rwz6SwR+JJtuCYy+Fsg1346xFo61qNk0n5ZeF31oU 3OlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2rVK6u6n; 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 j26si12074875pgl.537.2019.01.21.06.00.23; Mon, 21 Jan 2019 06:00:39 -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=2rVK6u6n; 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 S1731806AbfAUN6Y (ORCPT + 99 others); Mon, 21 Jan 2019 08:58:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:43784 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731539AbfAUN6W (ORCPT ); Mon, 21 Jan 2019 08:58:22 -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 451EB2084C; Mon, 21 Jan 2019 13:58:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079101; bh=cEp8cXZio3msQyxgWdwkZSAuek0u9kWNfQats0FOjE0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2rVK6u6nVELk5JPrlCOzHXPPN6JqFFh60nAlnweJ90BvgF+QxE18nbuZs4Q03RSKZ 7P6LZ65yNBlGhh9jLqeQ6rO9crXS1aHvt3JbUPGLDLqpFWerzBdMLDCL52L3CcQ+F2 Zm8AbSQB5BeugG1jVkUnwYhWt0Kt28d/iHDWNRAQ= 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.19 01/99] tty/ldsem: Wake up readers after timed out down_write() Date: Mon, 21 Jan 2019 14:47:53 +0100 Message-Id: <20190121134913.976633904@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@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.19-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 @@ -293,6 +293,16 @@ down_write_failed(struct ld_semaphore *s if (!locked) atomic_long_add_return(-LDSEM_WAIT_BIAS, &sem->count); 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_current_state(TASK_RUNNING);