[lkml]   [2009]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[patch 44/88] SCSI: sg: avoid blk_put_request/blk_rq_unmap_user in interrupt
2.6.28-stable review patch.  If anyone has any objections, please let us know.


From: FUJITA Tomonori <>

upstream commit: c96952ed7031e7c576ecf90cf95b8ec099d5295a

This fixes the following oops:

You can reproduce this bug by interrupting a program before a sg
response completes. This leads to the special sg state (the orphan
state), then sg calls blk_put_request in interrupt (rq->end_io).

The above bug report shows the recursive lock problem because sg calls
blk_put_request in interrupt. We could call __blk_put_request here
instead however we also need to handle blk_rq_unmap_user here, which
can't be called in interrupt too.

In the orphan state, we don't need to care about the data transfer
(the program revoked the command) so adding 'just free the resource'
mode to blk_rq_unmap_user is a possible option.

I prefer to avoid complicating the blk mapping API when possible. I
change the orphan state to call sg_finish_rem_req via
execute_in_process_context. We hold sg_fd->kref so sg_fd doesn't go
away until keventd_wq finishes our work. copy_from_user/to_user fails
so blk_rq_unmap_user just frees the resource without the data

Signed-off-by: FUJITA Tomonori <>
Acked-by: Douglas Gilbert <>
Signed-off-by: James Bottomley <>
Signed-off-by: Chris Wright <>
Signed-off-by: Greg Kroah-Hartman <>
drivers/scsi/sg.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -138,6 +138,7 @@ typedef struct sg_request { /* SG_MAX_QU
volatile char done; /* 0->before bh, 1->before read, 2->read */
struct request *rq;
struct bio *bio;
+ struct execute_work ew;
} Sg_request;

typedef struct sg_fd { /* holds the state of a file descriptor */
@@ -1234,6 +1235,15 @@ sg_mmap(struct file *filp, struct vm_are
return 0;

+static void sg_rq_end_io_usercontext(struct work_struct *work)
+ struct sg_request *srp = container_of(work, struct sg_request,;
+ struct sg_fd *sfp = srp->parentfp;
+ sg_finish_rem_req(srp);
+ kref_put(&sfp->f_ref, sg_remove_sfp);
* This function is a "bottom half" handler that is called by the mid
* level when a command is completed (or has failed).
@@ -1312,10 +1322,9 @@ static void sg_rq_end_io(struct request
kill_fasync(&sfp->async_qp, SIGPOLL, POLL_IN);
+ kref_put(&sfp->f_ref, sg_remove_sfp);
} else
- sg_finish_rem_req(srp); /* call with srp->done == 0 */
- kref_put(&sfp->f_ref, sg_remove_sfp);
+ execute_in_process_context(sg_rq_end_io_usercontext, &srp->ew);

static struct file_operations sg_fops = {

 \ /
  Last update: 2009-04-30 19:29    [W:0.229 / U:0.840 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site