Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1372239yba; Tue, 2 Apr 2019 07:42:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqx6rhrwuwkXBxU4VdNZ8Kbl5lqoN1ATbGZYxZFLHoavSXktQ+4TGXMpZfLXFWqtFpilPJXu X-Received: by 2002:a17:902:59c5:: with SMTP id d5mr37529298plj.104.1554216178977; Tue, 02 Apr 2019 07:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554216178; cv=none; d=google.com; s=arc-20160816; b=Y2GBxBkKso8aJGfnS31MqGL84OfMV49cuGpBdza1z0SaPF7chNxr/UHdUv7tCQAFih zbF5wqdljnG5EwQD7w0uhPXALfuunLVvFEnsSfndPi1MUpTMqIwWzADAMxUGlDssBDNh lW7ngasOKl7UNh6jm3VFRf+DrMMfWmxAFTezpE5dzt4JMUA1OQ0QPwQVdff5e9JcGBAm SfrT34V6CX+/Tf0joCysUwR8BqXK+WPN8rvmLfemxny5lfLy2ew/8r7yrvXD/VgkXgcc eCTBY3R8ddnbTZiIwV8iaEmGyYz45walEGmU4xMmJayYIssLWFEn4BXDs/rJDo0qfA6g xKxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=BHQAsPvJq6VcKzmx/kc5RorwleDElqrbBgwfRhW2POI=; b=vgsPhmJ+V7h+dI523SPJjJVYYSSt+DsRzgU7RSQYiC4q80wx9IDYdm05Bj41X6GGYA UOyw27kLb2YvngYSDUghMARcYGYiA+4TwlfNeT+VYpdUN2WW+IyIRf4rx1Bi0RiRRwXn wfRF3wdd30I/oAw7ZPqj3EOHcdLjeee9FDBcPmIMc1rPqBQTBQndItaO0xDbJ7sftZ1l lTc2s69jsBi+1RWCWFMAGZ3db9vCJCjQj69OEyDNNDOorNr12wWLJuyMFzV98v/902Ci 9x/vOoOXsXU/SoyOhQj4tolyDrClWTasis44Cp2wav2i8PzC4iCQkZhK5uAAhp7v0Z3P ybiw== ARC-Authentication-Results: i=1; mx.google.com; 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 e9si9044114pgn.236.2019.04.02.07.42.43; Tue, 02 Apr 2019 07:42:58 -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; 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 S1731848AbfDBNmg (ORCPT + 99 others); Tue, 2 Apr 2019 09:42:36 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:43704 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731535AbfDBNkM (ORCPT ); Tue, 2 Apr 2019 09:40:12 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJdv-0002nE-Nl; Tue, 02 Apr 2019 14:39:59 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdu-0004sH-AN; Tue, 02 Apr 2019 14:39:58 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "Jiri Slaby" , "kernel test robot" , "Dmitry Safonov" , "Peter Zijlstra" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 23/99] tty/ldsem: Wake up readers after timed out down_write() In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.65-rc1 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 Reported-by: kernel test robot Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/tty/tty_ldsem.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/drivers/tty/tty_ldsem.c +++ b/drivers/tty/tty_ldsem.c @@ -306,6 +306,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);