SysRq: do not pass tty argument around
Subsystems (17)
cover SysRq: do not pass tty argument around
Hi,
The following 3 patches get rid of 'tty' argument in SysRq handlers as nobody is using it. If noone objects I'd like to get it merged through my tree.
Thanks!
--
Dmitry
PATCH 1/3 Input: sysrq - drop tty argument from sysrq ops handlers
Noone is using tty argument so let's get rid of it.
---
arch/arm/kernel/etm.c | 2 +- arch/powerpc/xmon/xmon.c | 5 ++--- arch/sparc/kernel/process_64.c | 2 +- drivers/char/sysrq.c | 42 ++++++++++++++++++++------------------- drivers/gpu/drm/drm_fb_helper.c | 2 +- drivers/net/ibm_newemac/debug.c | 2 +- include/linux/sysrq.h | 6 +++++- kernel/power/poweroff.c | 2 +- 8 files changed, 33 insertions(+), 30 deletions(-)
arch/arm/kernel/etm.c +1 -1
@@ -230,7 +230,7 @@ static void etm_dump(void)etb_lock (t); } -static void sysrq_etm_dump (int key,struct tty_struct *tty) +static void sysrq_etm_dump (int key) {dev_dbg (tracer.dev,"Dumping ETB buffer\n" );etm_dump ();
arch/powerpc/xmon/xmon.c +2 -3
@@ -2728,15 +2728,14 @@ static void xmon_init(int enable) }#ifdef CONFIG_MAGIC_SYSRQ -static void sysrq_handle_xmon (int key,struct tty_struct *tty) +static void sysrq_handle_xmon (int key) {/* ensure xmon is enabled */ xmon_init (1 );debugger (get_irq_regs ()); } -static struct sysrq_key_op sysrq_xmon_op = -{ +static struct sysrq_key_op sysrq_xmon_op = { .handler = sysrq_handle_xmon, .help_msg ="Xmon" , .action_msg = "Entering xmon",
arch/sparc/kernel/process_64.c +1 -1
@@ -303,7 +303,7 @@ void arch_trigger_all_cpu_backtrace(void)#ifdef CONFIG_MAGIC_SYSRQ -static void sysrq_handle_globreg (int key,struct tty_struct *tty) +static void sysrq_handle_globreg (int key) {arch_trigger_all_cpu_backtrace (); }
drivers/char/sysrq.c +21 -21
168 lines not on this page · raw message
drivers/gpu/drm/drm_fb_helper.c +1 -1
@@ -295,7 +295,7 @@ static void drm_fb_helper_restore_work_fn(struct work_struct *ignored) } static DECLARE_WORK(drm_fb_helper_restore_work, drm_fb_helper_restore_work_fn); -static void drm_fb_helper_sysrq (int dummy1,struct tty_struct *dummy3) +static void drm_fb_helper_sysrq (int dummy1) {schedule_work (&drm_fb_helper_restore_work); }
drivers/net/ibm_newemac/debug.c +1 -1
@@ -238,7 +238,7 @@ void emac_dbg_dump_all(void) }#if defined(CONFIG_MAGIC_SYSRQ ) -static void emac_sysrq_handler (int key,struct tty_struct *tty) +static void emac_sysrq_handler (int key) {emac_dbg_dump_all (); }
include/linux/sysrq.h +5 -1
@@ -31,7 +31,7 @@ struct tty_struct;#define SYSRQ_ENABLE_RTNICE 0x0100struct sysrq_key_op { -void (*handler)(int ,struct tty_struct *); +void (*handler)(int );char *help_msg;char *action_msg;int enable_mask;
@@ -58,6 +58,10 @@ static inline void handle_sysrq(int key, struct tty_struct *tty) { } +static inline void __handle_sysrq (int key,struct tty_struct *tty,int check_mask); +{ +} +static inline int register_sysrq_key (int key,struct sysrq_key_op *op) {return -EINVAL ;
kernel/power/poweroff.c +1 -1
@@ -24,7 +24,7 @@ static void do_poweroff(struct work_struct *dummy) static DECLARE_WORK(poweroff_work, do_poweroff); -static void handle_poweroff (int key,struct tty_struct *tty) +static void handle_poweroff (int key) {/* run sysrq poweroff on boot cpu */ schedule_work_on (cpumask_first (cpu_online_mask), &poweroff_work);
Re: [PATCH 1/3] Input: sysrq - drop tty argument from sysrq ops handlers
Quoted 1 line · Dmitry Torokhov
Noone is using tty argument so let's get rid of it.
While talking about sysrq...
I noticed that serial drivers call sysrq with the uart lock held.
I've seen deadlocks caused by that, for example, when entering the debugger, it waits forever for a CPU which is itself waiting on the UART lock.
I have a patch to drop the lock in serial_core.h, I'll post that tomorrow hopefully, just checking if there's any objection there ? The serial drivers might need to be audited a bit to make sure they cope with the lock being dropped and re-acquired around the sysrq call.
Cheers,
Ben.
Re: [PATCH 1/3] Input: sysrq - drop tty argument from sysrq ops handlers
Quoted 2 lines
I have a patch to drop the lock in
serial_core.h, I'll post that tomorrow hopefully, just checking if there's any objection there ? The
Fundamentally - no. However the impact it has on a lot of the drivers will be significant and you'll be submitting a huge patch pile to fix up all the locking assumptions (for one it means port->tty might change across any call that ends up in sysrq)
Quoted 2 lines
serial drivers might need to be audited a bit to make sure they cope with the lock being dropped and re-acquired around the sysrq call.
Architecturally I think it would make more sense to add a new sysrq helper which merely sets a flag, and check that flag at the end of the IRQ when dropping the lock anyway.
Otherwise it'll be a huge amount of work to even build test all those consoles.
Alan
Re: [PATCH 1/3] Input: sysrq - drop tty argument from sysrq ops handlers
Quoted 5 lines · Alan Cox
Fundamentally - no. However the impact it has on a lot of the drivers will be significant and you'll be submitting a huge patch pile to fix up all the locking assumptions (for one it means
port->ttymight change across any call that ends up in sysrq)
Right. That's nasty. I think we need somewhat to break the loop when that happens as if we were getting a new interrupt to some extent.
And that's a lot of drivers to fix.
Quoted 6 lines
Quoted 2 lines
serial drivers might need to be audited a bit to make sure they cope with the lock being dropped and re-acquired around the sysrq call.
Architecturally I think it would make more sense to add a new sysrq helper which merely sets a flag, and check that flag at the end of the IRQ when dropping the lock anyway.
Interesting idea. That does mean that multiple sysrq in one interrupt will be coalesced but I don't see that as an issue.
Quoted 2 lines
Otherwise it'll be a huge amount of work to even build test all those consoles.
Right. Better to have a way where we can fix them one at a time. I'll look into it. Thanks.
Cheers,
Ben.
Jason Wessel
maintainerRe: [PATCH 1/3] Input: sysrq - drop tty argument from sysrq ops handlers
In reply to Benjamin HerrenschmidtQuoted 10 lines · Benjamin Herrenschmidt
Quoted 2 lines · Dmitry Torokhov
Noone is using tty argument so let's get rid of it.
While talking about sysrq...
I noticed that serial drivers call sysrq with the uart lock held.
The usb serial has the same kind of problem with all sorts of locks. I had resorted to using a tasklet or workqueue to get the sysrq to execute just outside the usb serial driver context. This work never made it upstream because it was part of another series, but the reference is:
http://lkml.org/lkml/2010/3/9/17
For the standard serial you might be able to get away with dropping the lock for the sysrq.
Did you have a particular way to trigger the problem or was it just completely random, because I don't know that I have observed this behavior with the typical 8250 driver.
Jason.
Quoted 14 lines
I've seen deadlocks caused by that, for example, when entering the debugger, it waits forever for a CPU which is itself waiting on the UART lock.
I have a patch to drop the lock in
serial_core.h, I'll post that tomorrow hopefully, just checking if there's any objection there ? The serial drivers might need to be audited a bit to make sure they cope with the lock being dropped and re-acquired around the sysrq call.Cheers,
Ben.
Re: [PATCH 1/3] Input: sysrq - drop tty argument from sysrq ops handlers
Quoted 8 lines · Jason Wessel
The usb serial has the same kind of problem with all sorts of locks. I
had resorted to using a tasklet or workqueue to get the sysrq to execute
just outside the usb serial driver context. This work never made it upstream because it was part of another series, but the reference is:
http://lkml.org/lkml/2010/3/9/17
Quoted 7 lines
For the standard serial you might be able to get away with dropping the
lock for the sysrq.Did you have a particular way to trigger the problem or was it just completely random, because I don't know that I have observed this behavior with the typical 8250 driver.
Yes, I do actually :-) A 64-way machine and a bunch of processes flooding the console will do it just fine :-)
Cheers,
Ben.
PATCH 2/3 Input: sysrq - drop tty argument form handle_sysrq()
In reply to Dmitry TorokhovSysrq operations do not accept tty argument anymore so no need to pass it to us.
---
arch/ia64/hp/sim/simserial.c | 2 +- arch/um/drivers/mconsole_kern.c | 2 +- drivers/char/hangcheck-timer.c | 2 +- drivers/char/hvc_console.c | 2 +- drivers/char/hvsi.c | 2 +- drivers/char/sysrq.c | 11 +++++------ drivers/s390/char/ctrlchar.c | 4 +--- drivers/serial/sn_console.c | 2 +- drivers/usb/serial/generic.c | 2 +- drivers/xen/manage.c | 2 +- include/linux/serial_core.h | 2 +- include/linux/sysrq.h | 11 ++++------- kernel/debug/kdb/kdb_main.c | 2 +- 13 files changed, 20 insertions(+), 26 deletions(-)
arch/ia64/hp/sim/simserial.c +1 -1
@@ -149,7 +149,7 @@ static void receive_chars(struct tty_struct *tty) ch =ia64_ssc (0 ,0 ,0 ,0 ,SSC_GETCHAR );while (!ch); - handle_sysrq(ch, NULL); + handle_sysrq(ch); }#endif seen_esc =0 ;
arch/um/drivers/mconsole_kern.c +1 -1
@@ -690,7 +690,7 @@ static void with_console(struct mc_request *req, void (*proc)(void *),static void sysrq_proc (void *arg) {char *op = arg; -handle_sysrq (*op,NULL ); +handle_sysrq (*op); }void mconsole_sysrq (struct mc_request *req)
drivers/char/hangcheck-timer.c +1 -1
@@ -159,7 +159,7 @@ static void hangcheck_fire(unsigned long data)if (hangcheck_dump_tasks) {printk (KERN_CRIT "Hangcheck: Task state:\n" );#ifdef CONFIG_MAGIC_SYSRQ -handle_sysrq ('t' ,NULL ); +handle_sysrq ('t' );#endif /* CONFIG_MAGIC_SYSRQ */ }if (hangcheck_reboot) {
drivers/char/hvc_console.c +1 -1
@@ -651,7 +651,7 @@ int hvc_poll(struct hvc_struct *hp)if (sysrq_pressed)continue ; }else if (sysrq_pressed) { -handle_sysrq (buf[i], tty); +handle_sysrq (buf[i]); sysrq_pressed =0 ;continue ; }
drivers/char/hvsi.c +1 -1
@@ -403,7 +403,7 @@ static void hvsi_insert_chars(struct hvsi_struct *hp, const char *buf, int len) hp->sysrq =1 ;continue ; }else if (hp->sysrq) { -handle_sysrq (c, hp->tty); +handle_sysrq (c); hp->sysrq =0 ;continue ; }
drivers/char/sysrq.c +5 -6
@@ -18,7 +18,6 @@#include <linux/interrupt.h> #include <linux/mm.h> #include <linux/fs.h> -#include <linux/tty.h> #include <linux/mount.h> #include <linux/kdev_t.h> #include <linux/major.h>
@@ -493,7 +492,7 @@ static void __sysrq_put_key_op(int key, struct sysrq_key_op *op_p) sysrq_key_table[i] = op_p; } -void __handle_sysrq (int key,struct tty_struct *tty,int check_mask) +void __handle_sysrq (int key,bool check_mask) {struct sysrq_key_op *op_p;int orig_log_level;
@@ -545,10 +544,10 @@ void __handle_sysrq(int key, struct tty_struct *tty, int check_mask)spin_unlock_irqrestore (&sysrq_key_table_lock, flags); } -void handle_sysrq (int key,struct tty_struct *tty) +void handle_sysrq (int key) {if (sysrq_on ()) -__handle_sysrq (key, tty,1 ); +__handle_sysrq (key, true); }EXPORT_SYMBOL (handle_sysrq);
@@ -597,7 +596,7 @@ static bool sysrq_filter(struct input_handle *handle, unsigned int type,default :if (sysrq_down && value && value !=2 ) -__handle_sysrq (sysrq_xlate[code],NULL ,1 ); +__handle_sysrq (sysrq_xlate[code], true);break ; }
@@ -765,7 +764,7 @@ static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,if (get_user (c, buf))return -EFAULT ; -__handle_sysrq (c,NULL ,0 ); +__handle_sysrq (c, false); }return count;
drivers/s390/char/ctrlchar.c +1 -3
@@ -16,12 +16,11 @@#ifdef CONFIG_MAGIC_SYSRQ static int ctrlchar_sysrq_key; -static struct tty_struct *sysrq_tty;static void ctrlchar_handle_sysrq (struct work_struct *work) { -handle_sysrq (ctrlchar_sysrq_key, sysrq_tty); +handle_sysrq (ctrlchar_sysrq_key); } static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
@@ -54,7 +53,6 @@ ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)/* racy */ if (len ==3 && buf[1 ] =='-' ) { ctrlchar_sysrq_key = buf[2 ]; - sysrq_tty = tty;schedule_work (&ctrlchar_work);return CTRLCHAR_SYSRQ ; }
drivers/serial/sn_console.c +1 -1
@@ -492,7 +492,7 @@ sn_receive_chars(struct sn_cons_port *port, unsigned long flags) sysrq_requested =0 ;if (ch &&time_before (jiffies, sysrq_timeout)) {spin_unlock_irqrestore (&port->sc_port.lock, flags); -handle_sysrq (ch,NULL ); +handle_sysrq (ch);spin_lock_irqsave (&port->sc_port.lock, flags);/* ignore actual sysrq command char */ continue ;
drivers/usb/serial/generic.c +1 -1
@@ -448,7 +448,7 @@ int usb_serial_handle_sysrq_char(struct tty_struct *tty, {if (port->sysrq && port->port.console) {if (ch &&time_before (jiffies, port->sysrq)) { -handle_sysrq (ch, tty); +handle_sysrq (ch); port->sysrq =0 ;return 1 ; }
drivers/xen/manage.c +1 -1
@@ -212,7 +212,7 @@ static void sysrq_handler(struct xenbus_watch *watch, const char **vec, goto again;if (sysrq_key !='\0' ) -handle_sysrq (sysrq_key,NULL ); +handle_sysrq (sysrq_key); }static struct xenbus_watch sysrq_watch = {
include/linux/serial_core.h +1 -1
@@ -453,7 +453,7 @@ uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)#ifdef SUPPORT_SYSRQ if (port->sysrq) {if (ch &&time_before (jiffies, port->sysrq)) { -handle_sysrq (ch, port->state->port.tty); +handle_sysrq (ch); port->sysrq =0 ;return 1 ; }
include/linux/sysrq.h +4 -7
@@ -16,9 +16,6 @@#include <linux/errno.h> -struct pt_regs ; -struct tty_struct ; -/* Possible values of bitmask for enabling sysrq functions */ /* 0x0001 is reserved for enable everything */ #define SYSRQ_ENABLE_LOG 0x0002
@@ -44,8 +41,8 @@ struct sysrq_key_op {* are available -- else NULL's). */ -void handle_sysrq (int key,struct tty_struct *tty); -void __handle_sysrq (int key,struct tty_struct *tty,int check_mask); +void handle_sysrq (int key); +void __handle_sysrq (int key,bool check_mask);int register_sysrq_key (int key,struct sysrq_key_op *op);int unregister_sysrq_key (int key,struct sysrq_key_op *op);struct sysrq_key_op *__sysrq_get_key_op (int key);
@@ -54,11 +51,11 @@ int sysrq_toggle_support(int enable_mask);#else -static inline void handle_sysrq (int key,struct tty_struct *tty) +static inline void handle_sysrq (int key) { } -static inline void __handle_sysrq (int key,struct tty_struct *tty,int check_mask); +static inline void __handle_sysrq (int key,bool check_mask) { }
kernel/debug/kdb/kdb_main.c +1 -1
@@ -1821,7 +1821,7 @@ static int kdb_sr(int argc, const char **argv)if (argc !=1 )return KDB_ARGCOUNT ; kdb_trap_printk++; -__handle_sysrq (*argv[1 ],NULL ,0 ); +__handle_sysrq (*argv[1 ], false); kdb_trap_printk--;return 0 ;
Re: [PATCH 2/3] Input: sysrq - drop tty argument form handle_sysrq()
Quoted 5 lines · Dmitry Torokhov
Sysrq operations do not accept tty argument anymore so no need to pass it to us.
Signed-off-by Dmitry Torokhov <[email protected]>
Looks fine to me. The kernel debugger was passing NULL anyway because
A) it was not going to be easy to figure out the tty at the time, and B) the sysrq was not using the tty at the lowest level.
PATCH 3/3 USB: drop tty argument from usb_serial_handle_sysrq_char()
In reply to Dmitry TorokhovSince handle_sysrq() does not take tty as argument anymore we can drop it from usb_serial_handle_sysrq_char() as well.
---
drivers/usb/serial/ftdi_sio.c | 2 +- drivers/usb/serial/generic.c | 5 ++--- drivers/usb/serial/pl2303.c | 2 +- include/linux/usb/serial.h | 3 +-- 4 files changed, 5 insertions(+), 7 deletions(-)
drivers/usb/serial/ftdi_sio.c +1 -1
@@ -1827,7 +1827,7 @@ static int ftdi_process_packet(struct tty_struct *tty,if (port->port.console && port->sysrq) {for (i =0 ; i < len; i++, ch++) { -if (!usb_serial_handle_sysrq_char (tty, port, *ch)) +if (!usb_serial_handle_sysrq_char (port, *ch))tty_insert_flip_char (tty, *ch, flag); } }else {
drivers/usb/serial/generic.c +2 -3
@@ -338,7 +338,7 @@ void usb_serial_generic_process_read_urb(struct urb *urb)tty_insert_flip_string (tty, ch, urb->actual_length); else {for (i =0 ; i < urb->actual_length; i++, ch++) { -if (!usb_serial_handle_sysrq_char (tty, port, *ch)) +if (!usb_serial_handle_sysrq_char (port, *ch))tty_insert_flip_char (tty, *ch,TTY_NORMAL ); } }
@@ -443,8 +443,7 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty)EXPORT_SYMBOL_GPL (usb_serial_generic_unthrottle);#ifdef CONFIG_MAGIC_SYSRQ -int usb_serial_handle_sysrq_char (struct tty_struct *tty, -struct usb_serial_port *port,unsigned int ch) +int usb_serial_handle_sysrq_char (struct usb_serial_port *port,unsigned int ch) {if (port->sysrq && port->port.console) {if (ch &&time_before (jiffies, port->sysrq)) {
drivers/usb/serial/pl2303.c +1 -1
@@ -788,7 +788,7 @@ static void pl2303_process_read_urb(struct urb *urb)if (port->port.console && port->sysrq) {for (i =0 ; i < urb->actual_length; ++i) -if (!usb_serial_handle_sysrq_char (tty, port, data[i])) +if (!usb_serial_handle_sysrq_char (port, data[i]))tty_insert_flip_char (tty, data[i], tty_flag); }else { tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
include/linux/usb/serial.h +1 -2
@@ -342,8 +342,7 @@ extern int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,extern void usb_serial_generic_process_read_urb (struct urb *urb);extern int usb_serial_generic_prepare_write_buffer (struct usb_serial_port *port,void *dest,size_t size); -extern int usb_serial_handle_sysrq_char (struct tty_struct *tty, -struct usb_serial_port *port, +extern int usb_serial_handle_sysrq_char (struct usb_serial_port *port,unsigned int ch);extern int usb_serial_handle_break (struct usb_serial_port *port);
Re: [PATCH 3/3] USB: drop tty argument from usb_serial_handle_sysrq_char()
Quoted 4 lines · Dmitry Torokhov
Since
handle_sysrq()does not take tty as argument anymore we can drop it fromusb_serial_handle_sysrq_char()as well.
Quoted 5 lines · On Wed, 04 Aug 2010 00:58:55 -0700 Dmitry Torokhov <[email protected]>…
Hi,
The following 3 patches get rid of 'tty' argument in SysRq handlers as nobody is using it. If noone objects I'd like to get it merged through my tree.
Looks good to me.
Quoted 5 lines · Dmitry Torokhov
Hi,
The following 3 patches get rid of 'tty' argument in SysRq handlers as nobody is using it. If noone objects I'd like to get it merged through my tree.
Nice job.
No objection from me for you to take this through your tree:
thanks,
greg k-h