Re: [PATCH] tty: add the option to have a tty reject a new ldisc
From: Jiri Slaby
Date: Wed Apr 24 2024 - 02:25:22 EST
On 23. 04. 24, 18:33, Linus Torvalds wrote:
... and use it to limit the virtual terminals to just N_TTY. They are
kind of special, and in particular, the "con_write()" routine violates
the "writes cannot sleep" rule that some ldiscs rely on.
This avoids the
BUG: sleeping function called from invalid context at kernel/printk/printk.c:2659
when N_GSM has been attached to a virtual console, and gsmld_write()
calls con_write() while holding a spinlock, and con_write() then tries
to get the console lock.
..> --- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -545,6 +545,12 @@ int tty_set_ldisc(struct tty_struct *tty, int disc)
goto out;
}
+ if (tty->ops->ldisc_ok) {
+ retval = tty->ops->ldisc_ok(tty, disc);
+ if (retval)
+ goto out;
This caught my eye as it looks like:
if (ldisc_ok)
die;
Perhaps dub it ldisc_check()? Alternatively, make it return a bool and
invert the logic here? That would make the ugly ternary in
con_ldisc_ok() go away too.
But whatever, it finally evades that group of bugs.
Now, I am not sure what the problem with attaching some weird ldisc to a
pty was. I will take a look next week (I am unavailable ATM).
thanks,
--
js
suse labs