summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorTony Battersby <tonyb@cybernetics.com>2015-02-13 12:10:58 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-03-06 14:57:31 -0800
commite1ed769da5d4910885850a104d910d0495738d71 (patch)
tree9a0a901986ce492c52848e7a50ed40e83734cd42 /drivers
parent09c2814bd63d096180729ade91238b12f975e32f (diff)
downloadlinux-stable-e1ed769da5d4910885850a104d910d0495738d71.tar.gz
linux-stable-e1ed769da5d4910885850a104d910d0495738d71.tar.bz2
linux-stable-e1ed769da5d4910885850a104d910d0495738d71.zip
sg: fix EWOULDBLOCK errors with scsi-mq
commit 7772855a996ec6e16944b120ab5ce21050279821 upstream. 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". 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-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 57178eda815d..763bffe23517 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1695,7 +1695,22 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
return -ENOMEM;
}
- rq = blk_get_request(q, rw, GFP_ATOMIC);
+ /*
+ * NOTE
+ *
+ * With scsi-mq enabled, there are a fixed number of preallocated
+ * requests equal in number to shost->can_queue. If all of the
+ * preallocated requests are already in use, then using GFP_ATOMIC with
+ * blk_get_request() will return -EWOULDBLOCK, whereas using GFP_KERNEL
+ * will cause blk_get_request() to sleep until an active command
+ * completes, freeing up a request. Neither option is ideal, but
+ * GFP_KERNEL is the better choice to prevent userspace from getting an
+ * unexpected EWOULDBLOCK.
+ *
+ * With scsi-mq disabled, blk_get_request() with GFP_KERNEL usually
+ * does not sleep except under memory pressure.
+ */
+ rq = blk_get_request(q, rw, GFP_KERNEL);
if (IS_ERR(rq)) {
kfree(long_cmdp);
return PTR_ERR(rq);