aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorTony Battersby <tonyb@cybernetics.com>2015-02-13 12:09:44 -0500
committerJames Bottomley <JBottomley@Parallels.com>2015-02-17 09:55:32 -0500
commit7568615c1054907ea8c7701ab86dad51aa099888 (patch)
tree9a8fbf348961fd4970423b51a41ce7ae7b3e0421 /drivers/scsi
parent3b524a683af8991b4eab4182b947c65f0ce1421b (diff)
sg: fix unkillable I/O wait deadlock with scsi-mq
When using the write()/read() interface for submitting commands, the SCSI generic driver does not call blk_put_request() on a completed SCSI command until userspace calls read() to get the command completion. Since scsi-mq uses a fixed number of preallocated requests, this makes it possible for userspace to exhaust the entire preallocated supply of requests. For places in the kernel that call blk_get_request() with GFP_KERNEL, this can cause the calling process to deadlock in a permanent unkillable I/O wait in blk_get_request() -> ... -> bt_get(). For places in the kernel that call blk_get_request() with GFP_ATOMIC, this can cause blk_get_request() always to return -EWOULDBLOCK. Note that these problems happen only if scsi-mq is enabled. Prevent the problems by calling blk_put_request() as soon as the SCSI command completes instead of waiting for userspace to call read(). Cc: <stable@vger.kernel.org> # 3.17+ Signed-off-by: Tony Battersby <tonyb@cybernetics.com> Acked-by: Douglas Gilbert <dgilbert@interlog.com> Tested-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/sg.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 6ad1480e87b7..208bf3c8a16c 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1335,6 +1335,17 @@ sg_rq_end_io(struct request *rq, int uptodate)
1335 } 1335 }
1336 /* Rely on write phase to clean out srp status values, so no "else" */ 1336 /* Rely on write phase to clean out srp status values, so no "else" */
1337 1337
1338 /*
1339 * Free the request as soon as it is complete so that its resources
1340 * can be reused without waiting for userspace to read() the
1341 * result. But keep the associated bio (if any) around until
1342 * blk_rq_unmap_user() can be called from user context.
1343 */
1344 srp->rq = NULL;
1345 if (rq->cmd != rq->__cmd)
1346 kfree(rq->cmd);
1347 __blk_put_request(rq->q, rq);
1348
1338 write_lock_irqsave(&sfp->rq_list_lock, iflags); 1349 write_lock_irqsave(&sfp->rq_list_lock, iflags);
1339 if (unlikely(srp->orphan)) { 1350 if (unlikely(srp->orphan)) {
1340 if (sfp->keep_orphan) 1351 if (sfp->keep_orphan)
@@ -1762,10 +1773,10 @@ sg_finish_rem_req(Sg_request *srp)
1762 SCSI_LOG_TIMEOUT(4, sg_printk(KERN_INFO, sfp->parentdp, 1773 SCSI_LOG_TIMEOUT(4, sg_printk(KERN_INFO, sfp->parentdp,
1763 "sg_finish_rem_req: res_used=%d\n", 1774 "sg_finish_rem_req: res_used=%d\n",
1764 (int) srp->res_used)); 1775 (int) srp->res_used));
1765 if (srp->rq) { 1776 if (srp->bio)
1766 if (srp->bio) 1777 ret = blk_rq_unmap_user(srp->bio);
1767 ret = blk_rq_unmap_user(srp->bio);
1768 1778
1779 if (srp->rq) {
1769 if (srp->rq->cmd != srp->rq->__cmd) 1780 if (srp->rq->cmd != srp->rq->__cmd)
1770 kfree(srp->rq->cmd); 1781 kfree(srp->rq->cmd);
1771 blk_put_request(srp->rq); 1782 blk_put_request(srp->rq);