public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] 2.4.X Avoid excessive recursion when setting device offline
@ 2004-03-29 17:07 Justin T. Gibbs
  2004-03-29 17:26 ` Arjan van de Ven
  0 siblings, 1 reply; 6+ messages in thread
From: Justin T. Gibbs @ 2004-03-29 17:07 UTC (permalink / raw)
  To: linux-scsi

How to reproduce: Queue up lots of I/O to a device.  Set that device
		  offline.

Result: The SCSI mid-layer blows out the kernel stack due to the inherent
	recursion in its request function.  The repeating stack trace goes
	something like:

	scsi_request_fn
	__scsi_end_request
	scsi_release_command
	scsi_queue_next_request
	scsi_request_fn
	...

This patch prevents recursive calls through the scsi_request_fn
for the same queue:

===== scsi.h 1.9 vs edited =====
--- 1.9/drivers/scsi/scsi.h	Wed Jun 25 17:34:08 2003
+++ edited/scsi.h	Sun Mar 28 13:50:35 2004
@@ -609,6 +609,7 @@
 	unsigned starved:1;	/* unable to process commands because
 				   host busy */
 	unsigned no_start_on_add:1;	/* do not issue start on add */
+	unsigned running_request_fn:1;
 
 	// Flag to allow revalidate to succeed in sd_open
 	int allow_revalidate;
===== scsi_lib.c 1.17 vs edited =====
--- 1.17/drivers/scsi/scsi_lib.c	Fri Jul  4 11:12:45 2003
+++ edited/scsi_lib.c	Sun Mar 28 14:07:48 2004
@@ -850,12 +850,20 @@
 	if (!SDpnt) {
 		panic("Missing device");
 	}
+
 	SHpnt = SDpnt->host;
 
 	/*
 	 * To start with, we keep looping until the queue is empty, or until
-	 * the host is no longer able to accept any more requests.
+	 * the host is no longer able to accept any more requests.  We avoid
+	 * excessive recursion through the SCSI layer by recording that we
+	 * are running this queue and rejecting requests to run it again. This
+	 * avoids blowing out the stack when multiple commands are failed
+	 * during our loop.
 	 */
+	if (SDpnt->running_request_fn)
+		return;
+	SDpnt->running_request_fn = 1;
 	while (1 == 1) {
 		/*
 		 * Check this again - each time we loop through we will have
@@ -863,7 +871,7 @@
 		 * we need to check to see if the queue is plugged or not.
 		 */
 		if (SHpnt->in_recovery || q->plugged)
-			return;
+			break;
 
 		/*
 		 * If the device cannot accept another request, then quit.
@@ -1099,6 +1107,7 @@
 		 */
 		spin_lock_irq(&io_request_lock);
 	}
+	SDpnt->running_request_fn = 0;
 }
 
 /*


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-03-30  7:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-29 17:07 [PATCH] 2.4.X Avoid excessive recursion when setting device offline Justin T. Gibbs
2004-03-29 17:26 ` Arjan van de Ven
2004-03-29 17:42   ` Justin T. Gibbs
2004-03-29 17:47   ` James Bottomley
2004-03-29 17:52     ` Justin T. Gibbs
2004-03-30  7:03   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox