All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix altsysrq deadlock
@ 2004-10-26 17:27 Jason Baron
  2004-10-26 17:43 ` John Richard Moser
  0 siblings, 1 reply; 6+ messages in thread
From: Jason Baron @ 2004-10-26 17:27 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel


hi,

This patch fixes a deadlock in the handle_sysrq function. The handle_sysrq
function is called in both process as well as interrupt context.  The
__sysrq_lock_table() function does not disable interrupts when taking the
sysrq_key_table_lock. Thus, it is fairly easy to to do a keyboard
sys-altrq-foo, while a 'echo foo > /proc/sysrq-trigger' is running and
cause a deadlock. It can be annoying to have the machine lockup exactly
when you are trying to debug something else.

Usually a spin_lock_irqsave would be used. However, I don't think that is
appropriate here because some of the altsysrq functions can take a while 
to run.

Thus, the patch below simply uses a spin_trylock and on failure does not
spin if we are in interrupt context. A trylock in all cases would be ok
too, but this patch preserves existing behavior as much as possible.  An
altsyrq that produces no output might seem troublesome, but it is
primarily used as a debugging tool, so trying it again seems reasonable.

Please apply.

-Jason 

--- linux/drivers/char/sysrq.c.orig	Tue Oct 26 12:49:59 2004
+++ linux/drivers/char/sysrq.c	Tue Oct 26 12:54:51 2004
@@ -291,6 +291,8 @@ void __sysrq_lock_table (void) { spin_lo
 
 void __sysrq_unlock_table (void) { spin_unlock(&sysrq_key_table_lock); }
 
+#define __sysrq_trylock_table() spin_trylock(&sysrq_key_table_lock)
+
 /*
  * get and put functions for the table, exposed to modules.
  */
@@ -324,7 +326,13 @@ void __handle_sysrq(int key, struct pt_r
 	int orig_log_level;
 	int i, j;
 
-	__sysrq_lock_table();
+	if(!__sysrq_trylock_table()) {
+		if(in_interrupt())
+			return;
+		else
+			__sysrq_lock_table();
+	}
+
 	orig_log_level = console_loglevel;
 	console_loglevel = 7;
 	printk(KERN_INFO "SysRq : ");



^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <Pine.LNX.4.44.0410261311590.12088-100000@dhcp83-105.boston.redhat.com>]

end of thread, other threads:[~2004-10-27 19:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-26 17:27 [PATCH] fix altsysrq deadlock Jason Baron
2004-10-26 17:43 ` John Richard Moser
2004-10-26 18:22   ` Jason Baron
2004-10-26 18:33     ` John Richard Moser
     [not found] <Pine.LNX.4.44.0410261311590.12088-100000@dhcp83-105.boston.redhat.com>
2004-10-27  2:40 ` Andrew Morton
2004-10-27 19:05   ` Jason Baron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.