public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Tony Battersby <tonyb@cybernetics.com>,
	linux-scsi@vger.kernel.org,
	"James E.J. Bottomley" <JBottomley@parallels.com>,
	Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] [SCSI] sg: fix EWOULDBLOCK errors with scsi-mq
Date: Sun, 15 Feb 2015 17:11:51 -0500	[thread overview]
Message-ID: <54E119A7.1010704@interlog.com> (raw)
In-Reply-To: <54DE3022.7070803@cybernetics.com>

On 15-02-13 12:10 PM, Tony Battersby wrote:
> 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: Douglas Gilbert <dgilbert@interlog.com>
> 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>

> For inclusion in kernel 3.20.
>
> The difference in behavior is due to bt_get() in block/blk-mq-tag.c
> checking for __GFP_WAIT.
>
> The bsg driver already calls blk_get_request() with GFP_KERNEL, so there
> is no need for a change there.
>
> --- linux-3.19.0/drivers/scsi/sg.c.orig	2015-02-13 11:04:40.000000000 -0500
> +++ linux-3.19.0/drivers/scsi/sg.c	2015-02-13 11:05:14.000000000 -0500
> @@ -1695,7 +1695,22 @@ sg_start_req(Sg_request *srp, unsigned c
>   			return -ENOMEM;
>   	}
>
> +	/*
> +	 * 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);
> -	rq = blk_get_request(q, rw, GFP_ATOMIC);
>   	if (IS_ERR(rq)) {
>   		kfree(long_cmdp);
>   		return PTR_ERR(rq);
>
> --


      reply	other threads:[~2015-02-15 22:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-13 17:10 [PATCH v2 2/2] [SCSI] sg: fix EWOULDBLOCK errors with scsi-mq Tony Battersby
2015-02-15 22:11 ` Douglas Gilbert [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54E119A7.1010704@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=JBottomley@parallels.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=tonyb@cybernetics.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox