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

Commit fe34c4e

Browse files
abattersbygregkh
authored andcommitted
sg: fix EWOULDBLOCK errors with scsi-mq
commit 7772855 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 <[email protected]> Acked-by: Douglas Gilbert <[email protected]> Tested-by: Douglas Gilbert <[email protected]> Signed-off-by: James Bottomley <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ba48f24 commit fe34c4e

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
@@ -1721,7 +1721,22 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
17211721
return -ENOMEM;
17221722
}
17231723

1724-
rq = blk_get_request(q, rw, GFP_ATOMIC);
1724+
/*
1725+
* NOTE
1726+
*
1727+
* With scsi-mq enabled, there are a fixed number of preallocated
1728+
* requests equal in number to shost->can_queue. If all of the
1729+
* preallocated requests are already in use, then using GFP_ATOMIC with
1730+
* blk_get_request() will return -EWOULDBLOCK, whereas using GFP_KERNEL
1731+
* will cause blk_get_request() to sleep until an active command
1732+
* completes, freeing up a request. Neither option is ideal, but
1733+
* GFP_KERNEL is the better choice to prevent userspace from getting an
1734+
* unexpected EWOULDBLOCK.
1735+
*
1736+
* With scsi-mq disabled, blk_get_request() with GFP_KERNEL usually
1737+
* does not sleep except under memory pressure.
1738+
*/
1739+
rq = blk_get_request(q, rw, GFP_KERNEL);
17251740
if (IS_ERR(rq)) {
17261741
kfree(long_cmdp);
17271742
return PTR_ERR(rq);

0 commit comments

Comments
 (0)