From 61b68ccc4db016a38ac82116625f80125d93d198 Mon Sep 17 00:00:00 2001 From: Kyle McMartin Date: Mon, 22 Nov 2010 14:03:11 -0500 Subject: [PATCH] TTY: restore tty_ldisc_wait_idle --- kernel.spec | 10 ++- tty-restore-tty_ldisc_wait_idle.patch | 117 ++++++++++++++++++++++++++ 2 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 tty-restore-tty_ldisc_wait_idle.patch diff --git a/kernel.spec b/kernel.spec index ebe9ea95d..319981471 100644 --- a/kernel.spec +++ b/kernel.spec @@ -51,7 +51,7 @@ Summary: The Linux kernel # For non-released -rc kernels, this will be prepended with "0.", so # for example a 3 here will become 0.3 # -%global baserelease 7 +%global baserelease 8 %global fedora_build %{baserelease} # base_sublevel is the kernel version we're starting with and patching @@ -726,6 +726,8 @@ Patch12305: xhci_hcd-suspend-resume.patch Patch12306: secmark-do-not-return-early-if-there-was-no-error.patch +Patch12307: tty-restore-tty_ldisc_wait_idle.patch + %endif BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root @@ -1346,6 +1348,8 @@ ApplyPatch xhci_hcd-suspend-resume.patch #ApplyPatch secmark-do-not-return-early-if-there-was-no-error.patch +ApplyPatch tty-restore-tty_ldisc_wait_idle.patch + # END OF PATCH APPLICATIONS %endif @@ -1959,6 +1963,10 @@ fi # || || %changelog +* Mon Nov 22 2010 Kyle McMartin 2.6.36.1-8.rc1 +- Merge 100eeae2 (TTY: restore tty_ldisc_wait_idle) which should fix the WARN + in tty_open in rawhide. + * Mon Nov 22 2010 Kyle McMartin 2.6.36.1-7.rc1 - Make vmlinuz world readable again. diff --git a/tty-restore-tty_ldisc_wait_idle.patch b/tty-restore-tty_ldisc_wait_idle.patch new file mode 100644 index 000000000..3e784dd57 --- /dev/null +++ b/tty-restore-tty_ldisc_wait_idle.patch @@ -0,0 +1,117 @@ +From 4d458f558d5b904f14080b073b549d18c9503f93 Mon Sep 17 00:00:00 2001 +From: Jiri Slaby +Date: Sun, 31 Oct 2010 23:17:51 +0100 +Subject: TTY: restore tty_ldisc_wait_idle + +It was removed in 65b770468e98 (tty-ldisc: turn ldisc user count into +a proper refcount), but we need to wait for last user to quit the +ldisc before we close it in tty_set_ldisc. + +Otherwise weird things start to happen. There might be processes +waiting in tty_read->n_tty_read on tty->read_wait for input to appear +and at that moment, a change of ldisc is fatal. n_tty_close is called, +it frees read_buf and the waiting process is still in the middle of +reading and goes nuts after it is woken. + +Previously we prevented close to happen when others are in ldisc ops +by tty_ldisc_wait_idle in tty_set_ldisc. But the commit above removed +that. So revoke the change and test whether there is 1 user (=we), and +allow the close then. + +We can do that without ldisc/tty locks, because nobody else can open +the device due to TTY_LDISC_CHANGING bit set, so we in fact wait for +everybody to leave. + +I don't understand why tty_ldisc_lock would be needed either when the +counter is an atomic variable, so this is a lockless +tty_ldisc_wait_idle. + +On the other hand, if we fail to wait (timeout or signal), we have to +reenable the halted ldiscs, so we take ldisc lock and reuse the setup +path at the end of tty_set_ldisc. + +Signed-off-by: Jiri Slaby +Acked-by: Linus Torvalds +Tested-by: Sebastian Andrzej Siewior +LKML-Reference: <20101031104136.GA511@Chamillionaire.breakpoint.cc> +LKML-Reference: <1287669539-22644-1-git-send-email-jslaby@suse.cz> +Cc: Alan Cox +Cc: stable@kernel.org [32, 33, 36] +Signed-off-by: Greg Kroah-Hartman +--- + drivers/char/tty_ldisc.c | 29 +++++++++++++++++++++++++++++ + 1 files changed, 29 insertions(+), 0 deletions(-) + +diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c +index 412f977..5bbf33a 100644 +--- a/drivers/char/tty_ldisc.c ++++ b/drivers/char/tty_ldisc.c +@@ -47,6 +47,7 @@ + + static DEFINE_SPINLOCK(tty_ldisc_lock); + static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); ++static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_idle); + /* Line disc dispatch table */ + static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS]; + +@@ -83,6 +84,7 @@ static void put_ldisc(struct tty_ldisc *ld) + return; + } + local_irq_restore(flags); ++ wake_up(&tty_ldisc_idle); + } + + /** +@@ -531,6 +533,23 @@ static int tty_ldisc_halt(struct tty_struct *tty) + } + + /** ++ * tty_ldisc_wait_idle - wait for the ldisc to become idle ++ * @tty: tty to wait for ++ * ++ * Wait for the line discipline to become idle. The discipline must ++ * have been halted for this to guarantee it remains idle. ++ */ ++static int tty_ldisc_wait_idle(struct tty_struct *tty) ++{ ++ int ret; ++ ret = wait_event_interruptible_timeout(tty_ldisc_idle, ++ atomic_read(&tty->ldisc->users) == 1, 5 * HZ); ++ if (ret < 0) ++ return ret; ++ return ret > 0 ? 0 : -EBUSY; ++} ++ ++/** + * tty_set_ldisc - set line discipline + * @tty: the terminal to set + * @ldisc: the line discipline +@@ -634,8 +653,17 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) + + flush_scheduled_work(); + ++ retval = tty_ldisc_wait_idle(tty); ++ + tty_lock(); + mutex_lock(&tty->ldisc_mutex); ++ ++ /* handle wait idle failure locked */ ++ if (retval) { ++ tty_ldisc_put(new_ldisc); ++ goto enable; ++ } ++ + if (test_bit(TTY_HUPPED, &tty->flags)) { + /* We were raced by the hangup method. It will have stomped + the ldisc data and closed the ldisc down */ +@@ -669,6 +697,7 @@ int tty_set_ldisc(struct tty_struct *tty, int ldisc) + + tty_ldisc_put(o_ldisc); + ++enable: + /* + * Allow ldisc referencing to occur again + */ +-- +1.7.3.2 +