Console preparatory work
Subsystems (3)
cover Console preparatory work
Preparatory locking clean up and tty_port work for the console.
---
Alan Cox (3):
tty: Move the vt_tty field from the vc_data into the standard tty_port
tty: Make vt's have a tty_port
vc: Locking clean up
drivers/char/keyboard.c | 10 +++++----- drivers/char/selection.c | 4 ++++ drivers/char/vt.c | 19 +++++++++++-------- drivers/char/vt_ioctl.c | 2 +- include/linux/console_struct.h | 3 ++- 5 files changed, 23 insertions(+), 15 deletions(-)
Signature · 1 line
Signature|No Signature
PATCH 1/3 vc: Locking clean up
The virtual console layer uses the BKL for various things that don't really need it. Clean them out. Someone really needs to relock selection.c in its entirity. Have fun...
---
drivers/char/selection.c | 4 ++++ drivers/char/vt.c | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/char/selection.c +4 -0
@@ -26,6 +26,7 @@#include <linux/selection.h> #include <linux/tiocl.h> #include <linux/console.h> +#include <linux/smp_lock.h> /* Don't take this from <ctype.h>: 011-015 on the screen aren't spaces */ #define isspace (c) ((c) == ' ')
@@ -312,6 +313,8 @@ int paste_selection(struct tty_struct *tty)struct tty_ldisc *ld;DECLARE_WAITQUEUE (wait, current); +lock_kernel (); +acquire_console_sem ();poke_blanked_console ();release_console_sem ();
@@ -335,5 +338,6 @@ int paste_selection(struct tty_struct *tty)__set_current_state (TASK_RUNNING );tty_ldisc_deref (ld); +unlock_kernel ();return 0 ; }
drivers/char/vt.c +4 -3
@@ -280,8 +280,12 @@ static inline unsigned short *screenpos(struct vc_data *vc, int offset, int viewreturn p; } +/* Called from the keyboard irq path.. */ static inline void scrolldelta (int lines) { +/* FIXME */ +/* scrolldelta needs some kind of consistency lock, but the BKL was +and still is not protecting versus the scheduled back end */ scrollback_delta += lines;schedule_console_callback (); }
@@ -2604,8 +2608,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)return -EFAULT ; ret =0 ; -lock_kernel (); -switch (type) {case TIOCL_SETSEL :
@@ -2680,7 +2682,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg) ret = -EINVAL ;break ; } -unlock_kernel ();return ret; }
PATCH 2/3 tty: Make vt's have a tty_port
In reply to Alan CoxThe vt layer isn't safely handling reference counts to tty object on the input side. Add a tty port structure to the vt layer in order to implement this using the standard helpers.
---
drivers/char/vt.c | 2 ++ include/linux/console_struct.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
drivers/char/vt.c +2 -0
@@ -772,6 +772,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */if (!vc)return -ENOMEM ; vc_cons[currcons].d = vc; +tty_port_init (&vc->port);INIT_WORK (&vc_cons[currcons].SAK_work, vc_SAK);visual_init (vc, currcons,1 );if (!*vc->vc_uni_pagedir_loc)
@@ -2909,6 +2910,7 @@ static int __init con_init(void)for (currcons =0 ; currcons <MIN_NR_CONSOLES ; currcons++) { vc_cons[currcons].d = vc =kzalloc (sizeof (struct vc_data ),GFP_NOWAIT );INIT_WORK (&vc_cons[currcons].SAK_work, vc_SAK); +tty_port_init (&vc->port);visual_init (vc, currcons,1 ); vc->vc_screenbuf =kzalloc (vc->vc_screenbuf_size,GFP_NOWAIT ); vc_init(vc, vc->vc_rows, vc->vc_cols,
include/linux/console_struct.h +2 -0
@@ -21,6 +21,8 @@ struct vt_struct;#define NPAR 16struct vc_data { +struct tty_port port;/* Upper level data */ +unsigned short vc_num;/* Console number */ unsigned int vc_cols;/* [#] Console size */ unsigned int vc_rows;
PATCH 3/3 tty: Move the vt_tty field from the vc_data into the standard tty_port
In reply to Alan CoxThis takes all the tty references through the expected interface points so we can refcount them.
---
drivers/char/keyboard.c | 10 +++++----- drivers/char/vt.c | 10 +++++----- drivers/char/vt_ioctl.c | 2 +- include/linux/console_struct.h | 1 - 4 files changed, 11 insertions(+), 12 deletions(-)
drivers/char/keyboard.c +5 -5
@@ -299,7 +299,7 @@ int kbd_rate(struct kbd_repeat *rep)*/ static void put_queue (struct vc_data *vc,int ch) { -struct tty_struct *tty = vc->vc_tty; +struct tty_struct *tty = vc->port.tty;if (tty) {tty_insert_flip_char (tty, ch,0 );
@@ -309,7 +309,7 @@ static void put_queue(struct vc_data *vc, int ch)static void puts_queue (struct vc_data *vc,char *cp) { -struct tty_struct *tty = vc->vc_tty; +struct tty_struct *tty = vc->port.tty;if (!tty)return ;
@@ -485,7 +485,7 @@ static void fn_show_ptregs(struct vc_data *vc)static void fn_hold (struct vc_data *vc) { -struct tty_struct *tty = vc->vc_tty; +struct tty_struct *tty = vc->port.tty;if (rep || !tty)return ;
@@ -563,7 +563,7 @@ static void fn_inc_console(struct vc_data *vc)static void fn_send_intr (struct vc_data *vc) { -struct tty_struct *tty = vc->vc_tty; +struct tty_struct *tty = vc->port.tty;if (!tty)return ;
@@ -1162,7 +1162,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)struct keyboard_notifier_param param = { .vc = vc, .value = keycode, .down = down };int rc; - tty = vc->vc_tty; + tty = vc->port.tty;if (tty && (!tty->driver_data)) {/* No driver data? Strange. Okay we fix it then. */
drivers/char/vt.c +5 -5
@@ -961,12 +961,12 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,* Resize a virtual console as seen from the console end of things. We * use the common vc_do_resize methods to update the structures. The * caller must hold the console sem to protect console internals and -* vc->vc_tty +* vc->port.tty */ int vc_resize (struct vc_data *vc,unsigned int cols,unsigned int rows) { -return vc_do_resize (vc->vc_tty, vc, cols, rows); +return vc_do_resize (vc->port.tty, vc, cols, rows); }/**
@@ -2795,12 +2795,12 @@ static int con_open(struct tty_struct *tty, struct file *filp)struct vc_data *vc = vc_cons[currcons].d;/* Still being freed */ -if (vc->vc_tty) { +if (vc->port.tty) {release_console_sem ();return -ERESTARTSYS ; } tty->driver_data = vc; - vc->vc_tty = tty; + vc->port.tty = tty;if (!tty->winsize.ws_row && !tty->winsize.ws_col) { tty->winsize.ws_row = vc_cons[currcons].d->vc_rows;
@@ -2828,7 +2828,7 @@ static void con_shutdown(struct tty_struct *tty)struct vc_data *vc = tty->driver_data;BUG_ON (vc ==NULL );acquire_console_sem (); - vc->vc_tty =NULL ; + vc->port.tty =NULL ;release_console_sem ();tty_shutdown (tty); }
drivers/char/vt_ioctl.c +1 -1
@@ -1367,7 +1367,7 @@ void vc_SAK(struct work_struct *work)acquire_console_sem (); vc = vc_con->d;if (vc) { - tty = vc->vc_tty; + tty = vc->port.tty;/* * SAK should also work in all raw modes and reset * them properly.
include/linux/console_struct.h +0 -1
@@ -58,7 +58,6 @@ struct vc_data {/* VT terminal data */ unsigned int vc_state;/* Escape sequence parser state */ unsigned int vc_npar,vc_par[NPAR ];/* Parameters of current escape sequence */ -struct tty_struct *vc_tty;/* TTY we are attached to */ /* data for manual vt switching */ struct vt_mode vt_mode;struct pid *vt_pid;