Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 7772855

Browse files
abattersbyJames Bottomley
authored andcommitted
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: <[email protected]> # 3.17+ Signed-off-by: Tony Battersby <[email protected]> Acked-by: Douglas Gilbert <[email protected]> Tested-by: Douglas Gilbert <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 7568615 commit 7772855

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

drivers/scsi/sg.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,22 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
16801680
return -ENOMEM;
16811681
}
16821682

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);
16841699
if (IS_ERR(rq)) {
16851700
kfree(long_cmdp);
16861701
return PTR_ERR(rq);

0 commit comments

Comments
 (0)