Skip to contentSkip to conversation

Char: tty_io, fix closecount counting

PATCH In review Jiri Slaby 2 participants 6 messages May 26, 2008 – Jun 3, 2008 Char and misc drivers

lore
Share & tools
lore

Jiri Slaby

author
#0 lore raw

PATCH 1/1 Char: tty_io, fix closecount counting

Alan, please N/ACK this.

--

filp->f_op->write never equals to tty_write for the console device, so closecount++ is never reached and we don't close console device so many times we open it before. (The closecount is used only for /dev/console.)

This is probably a fix for an issue first reported in 2.6.18.1:
http://lkml.org/lkml/2006/10/20/301
and
http://marc.info/?l=linux-mips&m=118797256328587

---
 drivers/char/tty_io.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/tty_io.c +1 -1
index c9e6e24..8c7b6ed 100644
@@ -1434,9 +1434,9 @@ static void do_tty_hangup(struct work_struct *work)
 	list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
 		if (filp->f_op->write == redirected_tty_write)
 			cons_filp = filp;
+		closecount++;
 		if (filp->f_op->write != tty_write)
 			continue;
-		closecount++;
 		tty_fasync(-1, filp, 0);	/* can't block */
 		filp->f_op = &hung_up_tty_fops;
 	}
Signature · 1 line
1.5.4.5
author
#1 lore raw

Jiri Slaby napsal(a):

Quoted 3 lines

filp->f_op->write never equals to tty_write for the console device, so closecount++ is never reached and we don't close console device so many times we open it before. (The closecount is used only for /dev/console.)

[...]

Quoted 8 lines
 drivers/char/tty_io.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/tty_io.c +0 -0
index c9e6e24..8c7b6ed 100644

drivers/char/tty_io.c static void do_tty_hangup(struct work_struct *work) · line 1439

Quoted 7 lines
drivers/char/tty_io.c +1 -1
@@ -1434,9 +1434,9 @@ static void do_tty_hangup(struct work_struct *work)
 	list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
 		if (filp->f_op->write == redirected_tty_write)
 			cons_filp = filp;
+		closecount++;
 		if (filp->f_op->write != tty_write)
 			continue;
-		closecount++;

Hm, no, this is wrong.

author
#2 lore raw
In reply to Jiri Slaby

Jiri Slaby napsal(a):

Quoted 4 lines

This is probably a fix for an issue first reported in 2.6.18.1:
http://lkml.org/lkml/2006/10/20/301
and
http://marc.info/?l=linux-mips&m=118797256328587

Alan, I know, you already stated some time ago, that you don't have a clue what could have caused this. Haven't you found anything since that time as I think the hangup path is the only possible cause of this problem?

I've found an other one from 2.6.17-rc4:
http://readlist.com/lists/vger.kernel.org/linux-kernel/44/220050.html
and from 2.6.22+suse_stuff:
http://lists.opensuse.org/opensuse-bugs/2008-04/msg05628.html

It is ever vcs1, which is /dev/console and it is the only treated separately (otherwise I think we would have more (and distinct) reports like this). When the console is HUPped? And what should happen with openers? The 2.6.22+suse happened when sulogin /dev/console was invoked. Any ideas how to track this down?

Quoted 13 lines
drivers/char/tty_io.c +1 -1
@@ -1434,9 +1434,9 @@ static void do_tty_hangup(struct work_struct *work)
 	list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
 		if (filp->f_op->write == redirected_tty_write)
 			cons_filp = filp;
+		closecount++;
 		if (filp->f_op->write != tty_write)
 			continue;
-		closecount++;
 		tty_fasync(-1, filp, 0);	/* can't block */
 		filp->f_op = &hung_up_tty_fops;
 	}
author
#3 lore raw

Jiri Slaby napsal(a):

Quoted 15 lines

Jiri Slaby napsal(a):

Quoted 4 lines

This is probably a fix for an issue first reported in 2.6.18.1:
http://lkml.org/lkml/2006/10/20/301
and
http://marc.info/?l=linux-mips&m=118797256328587

Alan, I know, you already stated some time ago, that you don't have a clue what could have caused this. Haven't you found anything since that time as I think the hangup path is the only possible cause of this problem?

I've found an other one from 2.6.17-rc4:
http://readlist.com/lists/vger.kernel.org/linux-kernel/44/220050.html
and from 2.6.22+suse_stuff:
http://lists.opensuse.org/opensuse-bugs/2008-04/msg05628.html

It is ever vcs1, which is /dev/console and it is the only treated separately (otherwise I think we would have more (and distinct) reports like this). When the console is HUPped? And what should happen with openers? The 2.6.22+suse happened when sulogin /dev/console was invoked. Any ideas how to track this down?

Quoted 13 lines

drivers/char/tty_io.c static void do_tty_hangup(struct work_struct *work) · line 1442

Quoted 13 lines
drivers/char/tty_io.c +1 -1
@@ -1434,9 +1434,9 @@ static void do_tty_hangup(struct work_struct *work)
     list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) {
         if (filp->f_op->write == redirected_tty_write)
             cons_filp = filp;
+        closecount++;
         if (filp->f_op->write != tty_write)
             continue;
-        closecount++;
         tty_fasync(-1, filp, 0);    /* can't block */
         filp->f_op = &hung_up_tty_fops;
     }

(Ah, btw, I've uttered this change as wrong.)

#4 lore raw
In reply to Jiri Slaby
Quoted 5 lines

It is ever vcs1, which is /dev/console and it is the only treated separately (otherwise I think we would have more (and distinct) reports like this). When the console is HUPped? And what should happen with openers? The 2.6.22+suse happened when sulogin /dev/console was invoked. Any ideas how to track this down?

Its a complete and total mess is the obvious answer. In fact its far worse than it first looks and I don't believe it can be fixed without reworking the whole printk/console stuff.

I spent several days this week mapping out how the tty open/close/hangup logic works and to be honest what I've learned is

- It doesn't
- It can't be easily fixed to
- There are numerous races
- The whole "tty/console" abstraction for printk type stuff is totally broken by design and replicated in several places for good measure.

At this point I have to say I can't even see a way to get from the existing tty open/close/hangup logic to a working one which does not involve changes to every driver with a 'flag day' type switch between the two implementations.

For the existing codebase I think the best we can do in this area is label it "condemned" and not touch it, because any change will be unpredictable in its effect and not a real fix.

I'd love to be proved wrong. Doing a grand reimplementation of large chunks of the tty layer isn't what I want to do, I just see no alternative at this point.

Alan

author
#5 lore raw
Quoted 5 lines · Alan Cox
Quoted 1 line

It is ever vcs1, which is /dev/console and it is the only treated separately (otherwise I think we would have more (and distinct) reports like this). When the console is HUPped? And what should happen with openers? The 2.6.22+suse happened when sulogin /dev/console was invoked. Any ideas how to track this down?

Its a complete and total mess is the obvious answer. In fact its far worse than it first looks and I don't believe it can be fixed without reworking the whole printk/console stuff.

Thanks a heap for the answer.