All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Peter Zijlstra <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: gregkh@linuxfoundation.org, peterz@infradead.org, jslaby@suse.cz,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	tglx@linutronix.de, hpa@zytor.com, mingo@kernel.org
Subject: [tip:sched/core] sched, tty: Deal with nested sleeps
Date: Tue, 28 Oct 2014 04:10:52 -0700	[thread overview]
Message-ID: <tip-97d9e28d1a27b84a6a0b155f2390289afa279341@git.kernel.org> (raw)
In-Reply-To: <20140924082242.323011233@infradead.org>

Commit-ID:  97d9e28d1a27b84a6a0b155f2390289afa279341
Gitweb:     http://git.kernel.org/tip/97d9e28d1a27b84a6a0b155f2390289afa279341
Author:     Peter Zijlstra <peterz@infradead.org>
AuthorDate: Wed, 24 Sep 2014 10:18:51 +0200
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 28 Oct 2014 10:56:10 +0100

sched, tty: Deal with nested sleeps

n_tty_{read,write} are wait loops with sleeps in. Wait loops rely on
task_struct::state and sleeps do too, since that's the only means of
actually sleeping. Therefore the nested sleeps destroy the wait loop
state.

Fix this by using the new woken_wake_function and wait_woken() stuff,
which registers wakeups in wait and thereby allows shrinking the
task_state::state changes to the actual sleep part.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiri Slaby <jslaby@suse.cz>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: tglx@linutronix.de
Cc: ilya.dryomov@inktank.com
Cc: umgwanakikbuti@gmail.com
Cc: oleg@redhat.com
Link: http://lkml.kernel.org/r/20140924082242.323011233@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 drivers/tty/n_tty.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 89c4cee..fb3f519 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2123,7 +2123,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	unsigned char __user *b = buf;
-	DECLARE_WAITQUEUE(wait, current);
+	DEFINE_WAIT_FUNC(wait, woken_wake_function);
 	int c;
 	int minimum, time;
 	ssize_t retval = 0;
@@ -2186,10 +2186,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 			nr--;
 			break;
 		}
-		/* This statement must be first before checking for input
-		   so that any interrupt will set the state back to
-		   TASK_RUNNING. */
-		set_current_state(TASK_INTERRUPTIBLE);
 
 		if (((minimum - (b - buf)) < ldata->minimum_to_wake) &&
 		    ((minimum - (b - buf)) >= 1))
@@ -2220,13 +2216,13 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 				n_tty_set_room(tty);
 				up_read(&tty->termios_rwsem);
 
-				timeout = schedule_timeout(timeout);
+				timeout = wait_woken(&wait, TASK_INTERRUPTIBLE,
+						     timeout);
 
 				down_read(&tty->termios_rwsem);
 				continue;
 			}
 		}
-		__set_current_state(TASK_RUNNING);
 
 		/* Deal with packet mode. */
 		if (packet && b == buf) {
@@ -2273,7 +2269,6 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 
 	mutex_unlock(&ldata->atomic_read_lock);
 
-	__set_current_state(TASK_RUNNING);
 	if (b - buf)
 		retval = b - buf;
 
@@ -2306,7 +2301,7 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 			   const unsigned char *buf, size_t nr)
 {
 	const unsigned char *b = buf;
-	DECLARE_WAITQUEUE(wait, current);
+	DEFINE_WAIT_FUNC(wait, woken_wake_function);
 	int c;
 	ssize_t retval = 0;
 
@@ -2324,7 +2319,6 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 
 	add_wait_queue(&tty->write_wait, &wait);
 	while (1) {
-		set_current_state(TASK_INTERRUPTIBLE);
 		if (signal_pending(current)) {
 			retval = -ERESTARTSYS;
 			break;
@@ -2378,12 +2372,11 @@ static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
 		}
 		up_read(&tty->termios_rwsem);
 
-		schedule();
+		wait_woken(&wait, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
 
 		down_read(&tty->termios_rwsem);
 	}
 break_out:
-	__set_current_state(TASK_RUNNING);
 	remove_wait_queue(&tty->write_wait, &wait);
 	if (b - buf != nr && tty->fasync)
 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);

  reply	other threads:[~2014-10-28 11:11 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24  8:18 [PATCH 00/11] nested sleeps, fixes and debug infrastructure Peter Zijlstra
2014-09-24  8:18 ` [PATCH 01/11] locking/mutex: Dont assume TASK_RUNNING Peter Zijlstra
2014-10-28 11:09   ` [tip:sched/core] locking/mutex: Don't " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 02/11] wait: Provide infrastructure to deal with nested blocking Peter Zijlstra
2014-09-29 21:02   ` Oleg Nesterov
2014-10-02  7:37     ` Peter Zijlstra
2014-10-02 21:21       ` Oleg Nesterov
2014-10-28 11:09   ` [tip:sched/core] sched/wait: " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 03/11] wait: Add might_sleep() Peter Zijlstra
2014-10-28 11:09   ` [tip:sched/core] sched/wait: Add might_sleep() checks tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 04/11] exit: Deal with nested sleeps Peter Zijlstra
2014-10-28 11:10   ` [tip:sched/core] sched, " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 05/11] inotify: " Peter Zijlstra
2014-10-28 11:10   ` [tip:sched/core] sched, " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 06/11] tty: " Peter Zijlstra
2014-10-28 11:10   ` tip-bot for Peter Zijlstra [this message]
2014-09-24  8:18 ` [PATCH 07/11] smp: Correctly deal " Peter Zijlstra
2014-10-28 11:11   ` [tip:sched/core] sched, " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 08/11] module: Fix nested sleep Peter Zijlstra
2014-09-29 22:18   ` Oleg Nesterov
2014-09-30 13:43     ` Peter Zijlstra
2014-10-28 11:11   ` [tip:sched/core] sched, modules: Fix nested sleep in add_unformed_module() tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 09/11] net: Clean up sk_wait_event() vs might_sleep() Peter Zijlstra
2014-09-24  8:36   ` Peter Zijlstra
2014-10-28 11:11   ` [tip:sched/core] sched, net: Clean up sk_wait_event() vs. might_sleep() tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 10/11] sched: Debug nested sleeps Peter Zijlstra
2014-09-29 22:13   ` Oleg Nesterov
2014-09-30 13:49     ` Peter Zijlstra
2014-09-30 21:47       ` Oleg Nesterov
2014-10-01 16:10         ` Peter Zijlstra
2014-10-01 18:35           ` Oleg Nesterov
2014-10-02  9:07             ` Peter Zijlstra
2014-10-02 21:34               ` Oleg Nesterov
2014-10-28 11:11   ` [tip:sched/core] " tip-bot for Peter Zijlstra
2014-09-24  8:18 ` [PATCH 11/11] sched: Exclude cond_resched() from nested sleep test Peter Zijlstra
2014-10-28 11:12   ` [tip:sched/core] " tip-bot for Peter Zijlstra
2014-09-25  8:30 ` [PATCH 00/11] nested sleeps, fixes and debug infrastructure Mike Galbraith
2014-09-25  9:06   ` Peter Zijlstra
2014-09-25  9:10     ` Mike Galbraith
2014-09-25  9:15     ` Peter Zijlstra
2014-09-25  9:56       ` Mike Galbraith
2014-09-25 13:59         ` BUG: sleeping function called from invalid context at drivers/cpufreq/cpufreq.c:370 Mike Galbraith
2014-09-26  6:24           ` Mike Galbraith
2014-09-26  7:54             ` Mike Galbraith
2014-09-26 14:10               ` Rafael J. Wysocki
2014-09-26 22:44               ` Rafael J. Wysocki
2014-09-27  6:14                 ` Mike Galbraith
2014-09-27 19:57                   ` Rafael J. Wysocki
2014-10-02 10:22       ` [PATCH 00/11] nested sleeps, fixes and debug infrastructure Peter Zijlstra
2014-10-02 12:15         ` Peter Zijlstra
2014-10-27 13:41           ` Peter Zijlstra
2014-10-28  0:07             ` Oleg Nesterov
2014-10-28  8:23               ` Peter Zijlstra
2014-10-29  0:00                 ` Oleg Nesterov
2014-10-29  9:35                   ` Peter Zijlstra
2014-10-29 11:31                     ` Peter Zijlstra
2014-10-29 11:36                       ` Peter Zijlstra
2014-10-29 14:26                   ` Peter Zijlstra
2014-11-04 16:08         ` [tip:sched/core] audit, sched/wait: Fixup kauditd_thread() wait loop tip-bot for Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-97d9e28d1a27b84a6a0b155f2390289afa279341@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hpa@zytor.com \
    --cc=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.