aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/sg.c
diff options
context:
space:
mode:
authorTony Battersby <tonyb@cybernetics.com>2015-02-13 12:10:58 -0500
committerJames Bottomley <JBottomley@Parallels.com>2015-02-17 09:57:54 -0500
commit7772855a996ec6e16944b120ab5ce21050279821 (patch)
treeee736c6d1316437299d0c6c4948cfbc02f1dff56 /drivers/scsi/sg.c
parent7568615c1054907ea8c7701ab86dad51aa099888 (diff)
sg: fix EWOULDBLOCK errors with scsi-mq
With scsi-mq enabled, userspace programs can get unexpected EWOULDBLOCK (a.k.a. EAGAIN) errors when submitting commands to the SCSI generic driver. Fix by calling blk_get_request() with GFP_KERNEL instead of GFP_ATOMIC. Note: to avoid introducing a potential deadlock, this patch should be applied after the patch titled "sg: fix unkillable I/O wait deadlock with scsi-mq". 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/sg.c')
-rw-r--r--drivers/scsi/sg.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 208bf3c8a16c..5cb2a5e80b2b 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1680,7 +1680,22 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
1680 return -ENOMEM; 1680 return -ENOMEM;
1681 } 1681 }
1682 1682
1683 rq = blk_get_request(q, rw, GFP_ATOMIC); 1683 /*
1684 * NOTE
1685 *
1686 * With scsi-mq enabled, there are a fixed number of preallocated
1687 * requests equal in number to shost->can_queue. If all of the
1688 * preallocated requests are already in use, then using GFP_ATOMIC with
1689 * blk_get_request() will return -EWOULDBLOCK, whereas using GFP_KERNEL
1690 * will cause blk_get_request() to sleep until an active command
1691 * completes, freeing up a request. Neither option is ideal, but
1692 * GFP_KERNEL is the better choice to prevent userspace from getting an
1693 * unexpected EWOULDBLOCK.
1694 *
1695 * With scsi-mq disabled, blk_get_request() with GFP_KERNEL usually
1696 * does not sleep except under memory pressure.
1697 */
1698 rq = blk_get_request(q, rw, GFP_KERNEL);
1684 if (IS_ERR(rq)) { 1699 if (IS_ERR(rq)) {
1685 kfree(long_cmdp); 1700 kfree(long_cmdp);
1686 return PTR_ERR(rq); 1701 return PTR_ERR(rq);