mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jason Wessel <jason.wessel@windriver.com>
To: gregkh@suse.de
Cc: linux-usb@vger.kernel.org, Alan Stern <stern@rowland.harvard.edu>,
	linux-kernel@vger.kernel.org,
	Jason Wessel <jason.wessel@windriver.com>,
	Alan Cox <alan@linux.intel.com>
Subject: [PATCH 6/6] usb-serialy,sysrq: Run the sysrq handler in a tasklet
Date: Tue,  9 Mar 2010 00:29:11 -0600	[thread overview]
Message-ID: <1268116151-1448-7-git-send-email-jason.wessel@windriver.com> (raw)
In-Reply-To: <1268116151-1448-6-git-send-email-jason.wessel@windriver.com>

If a sysrq is processed on the while holding the usb hcd lock, it is
impossible to drain the queue of urbs via the polling interface and
all the printk output is lost.

Using a tasklet to schedule the sysrq allows the hcd device lock to
free up, and you can issue a sysrq-t to get the task list.

CC: Greg Kroah-Hartman <gregkh@suse.de>
CC: Alan Cox <alan@linux.intel.com>
CC: Alan Stern <stern@rowland.harvard.edu>
CC: linux-usb@vger.kernel.org
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 drivers/char/sysrq.c       |   29 +++++++++++++++++++++++++++++
 include/linux/sysrq.h      |    4 ++++
 include/linux/usb/serial.h |    2 +-
 3 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index 1ae2de7..ad62e53 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -584,6 +584,35 @@ int unregister_sysrq_key(int key, struct sysrq_key_op *op_p)
 }
 EXPORT_SYMBOL(unregister_sysrq_key);
 
+/* The sysrq tasklet is used only in the rare case that an
+ * input/output character device processes a sysrq in its input
+ * routine while holding a lock required for the output routine for
+ * the console device.
+ */
+static struct sysrq_tasklet_data {
+	struct tty_struct *tty;
+	unsigned int key;
+	int pending;
+} priv_sysrq_data;
+
+static void sysrq_task(unsigned long args)
+{
+	handle_sysrq(priv_sysrq_data.key, priv_sysrq_data.tty);
+	priv_sysrq_data.pending = 0;
+}
+static DECLARE_TASKLET(sysrq_tasklet, sysrq_task, 0);
+
+void handle_sysrq_tasklet(int key, struct tty_struct *tty)
+{
+	if (priv_sysrq_data.pending)
+		return;
+	priv_sysrq_data.pending = 1;
+	priv_sysrq_data.key = key;
+	priv_sysrq_data.tty = tty;
+	tasklet_schedule(&sysrq_tasklet);
+}
+EXPORT_SYMBOL(handle_sysrq_tasklet);
+
 #ifdef CONFIG_PROC_FS
 /*
  * writing 'C' to /proc/sysrq-trigger is like sysrq-C
diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
index 99adcdc..0ff5fb4 100644
--- a/include/linux/sysrq.h
+++ b/include/linux/sysrq.h
@@ -52,6 +52,7 @@ extern int __sysrq_enabled;
  */
 
 void handle_sysrq(int key, struct tty_struct *tty);
+void handle_sysrq_tasklet(int key, struct tty_struct *tty);
 void __handle_sysrq(int key, struct tty_struct *tty, int check_mask);
 int register_sysrq_key(int key, struct sysrq_key_op *op);
 int unregister_sysrq_key(int key, struct sysrq_key_op *op);
@@ -70,6 +71,9 @@ static inline int __reterr(void)
 static inline void handle_sysrq(int key, struct tty_struct *tty)
 {
 }
+static inline void handle_sysrq_tasklet(int key, struct tty_struct *tty)
+{
+}
 
 #define register_sysrq_key(ig,nore) __reterr()
 #define unregister_sysrq_key(ig,nore) __reterr()
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 60f8422..ae8887e 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -333,7 +333,7 @@ static inline int usb_serial_handle_sysrq_char(struct tty_struct *tty,
 #ifdef CONFIG_MAGIC_SYSRQ
 	if (port->sysrq && port->port.console) {
 		if (ch && time_before(jiffies, port->sysrq)) {
-			handle_sysrq(ch, tty);
+			handle_sysrq_tasklet(ch, tty);
 			port->sysrq = 0;
 			return 1;
 		}
-- 
1.6.3.1.9.g95405b


  reply	other threads:[~2010-03-09  6:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-09  6:29 [PATCH 0/6] usb console improvements series Jason Wessel
2010-03-09  6:29 ` [PATCH 1/6] tty_port,usb-console: Fix usb serial console open/close regression Jason Wessel
2010-03-09  6:29   ` [PATCH 2/6] usb-serial: Use tty_port version of console instead of the usb_serial_port version Jason Wessel
2010-03-09  6:29     ` [PATCH 3/6] usb-console: pass baud from console to the initial tty open Jason Wessel
2010-03-09  6:29       ` [PATCH 4/6] usb-serial: optimize sysrq function calls Jason Wessel
2010-03-09  6:29         ` [PATCH 5/6] usb-hcd,usb-console: poll hcd device to force usb console writes Jason Wessel
2010-03-09  6:29           ` Jason Wessel [this message]
2010-03-09 15:08           ` Alan Stern
2010-03-10 22:27             ` Jason Wessel
2010-03-09 15:14         ` [PATCH 4/6] usb-serial: optimize sysrq function calls Alan Stern
2010-03-10 22:18           ` Jason Wessel
2010-03-16 20:30 ` [PATCH 0/6] usb console improvements series Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268116151-1448-7-git-send-email-jason.wessel@windriver.com \
    --to=jason.wessel@windriver.com \
    --cc=alan@linux.intel.com \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®