From: Bart Van Assche <bvanassche@acm.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Stanley Chu <stanley.chu@mediatek.com>,
Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Ming Lei <ming.lei@redhat.com>, stable <stable@vger.kernel.org>,
Can Guo <cang@codeaurora.org>,
"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: Re: [PATCH] block: Fix a race in the runtime power management code
Date: Thu, 27 Aug 2020 20:27:49 -0700 [thread overview]
Message-ID: <5da883fe-b5ec-b98d-ae0c-bc053b6e22cb@acm.org> (raw)
In-Reply-To: <20200827203321.GB449067@rowland.harvard.edu>
On 2020-08-27 13:33, Alan Stern wrote:
> It may not need to be that complicated. what about something like this?
>
> Index: usb-devel/block/blk-core.c
> ===================================================================
> --- usb-devel.orig/block/blk-core.c
> +++ usb-devel/block/blk-core.c
> @@ -420,11 +420,11 @@ EXPORT_SYMBOL(blk_cleanup_queue);
> /**
> * blk_queue_enter() - try to increase q->q_usage_counter
> * @q: request queue pointer
> - * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PREEMPT
> + * @flags: BLK_MQ_REQ_NOWAIT and/or BLK_MQ_REQ_PM
> */
> int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)
> {
> - const bool pm = flags & BLK_MQ_REQ_PREEMPT;
> + const bool pm = flags & BLK_MQ_REQ_PM;
>
> while (true) {
> bool success = false;
> @@ -626,7 +626,8 @@ struct request *blk_get_request(struct r
> struct request *req;
>
> WARN_ON_ONCE(op & REQ_NOWAIT);
> - WARN_ON_ONCE(flags & ~(BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_PREEMPT));
> + WARN_ON_ONCE(flags & ~(BLK_MQ_REQ_NOWAIT | BLK_MQ_REQ_PREEMPT |
> + BLK_MQ_REQ_PM));
>
> req = blk_mq_alloc_request(q, op, flags);
> if (!IS_ERR(req) && q->mq_ops->initialize_rq_fn)
> Index: usb-devel/drivers/scsi/scsi_lib.c
> ===================================================================
> --- usb-devel.orig/drivers/scsi/scsi_lib.c
> +++ usb-devel/drivers/scsi/scsi_lib.c
> @@ -245,11 +245,15 @@ int __scsi_execute(struct scsi_device *s
> {
> struct request *req;
> struct scsi_request *rq;
> + blk_mq_req_flags_t mq_req_flags;
> int ret = DRIVER_ERROR << 24;
>
> + mq_req_flags = BLK_MQ_REQ_PREEMPT;
> + if (rq_flags & RQF_PM)
> + mq_req_flags |= BLK_MQ_REQ_PM;
> req = blk_get_request(sdev->request_queue,
> data_direction == DMA_TO_DEVICE ?
> - REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, BLK_MQ_REQ_PREEMPT);
> + REQ_OP_SCSI_OUT : REQ_OP_SCSI_IN, mq_req_flags);
> if (IS_ERR(req))
> return ret;
> rq = scsi_req(req);
> Index: usb-devel/include/linux/blk-mq.h
> ===================================================================
> --- usb-devel.orig/include/linux/blk-mq.h
> +++ usb-devel/include/linux/blk-mq.h
> @@ -435,6 +435,8 @@ enum {
> BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 << 1),
> /* set RQF_PREEMPT */
> BLK_MQ_REQ_PREEMPT = (__force blk_mq_req_flags_t)(1 << 3),
> + /* used for power management */
> + BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 4),
> };
>
> struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
I think this patch will break SCSI domain validation. The SCSI domain
validation code calls scsi_device_quiesce() and that function in turn calls
blk_set_pm_only(). The SCSI domain validation code submits SCSI commands with
the BLK_MQ_REQ_PREEMPT flag. Since the above code postpones such requests
while blk_set_pm_only() is in effect, I think the above patch will cause the
SCSI domain validation code to deadlock.
Bart.
next prev parent reply other threads:[~2020-08-28 3:27 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-24 3:06 [PATCH] block: Fix a race in the runtime power management code Bart Van Assche
2020-08-24 14:47 ` Alan Stern
2020-08-25 9:01 ` Stanley Chu
2020-08-25 9:11 ` Stanley Chu
2020-08-25 18:24 ` Alan Stern
2020-08-25 22:22 ` Bart Van Assche
2020-08-26 1:51 ` Alan Stern
2020-08-27 3:35 ` Bart Van Assche
2020-08-27 20:33 ` Alan Stern
2020-08-28 3:27 ` Bart Van Assche [this message]
2020-08-28 15:37 ` Alan Stern
2020-08-29 0:51 ` Bart Van Assche
2020-08-29 1:12 ` Alan Stern
2020-08-29 2:57 ` Bart Van Assche
2020-08-26 2:58 ` Bart Van Assche
2020-08-26 4:00 ` Stanley Chu
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=5da883fe-b5ec-b98d-ae0c-bc053b6e22cb@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=cang@codeaurora.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
--cc=stable@vger.kernel.org \
--cc=stanley.chu@mediatek.com \
--cc=stern@rowland.harvard.edu \
/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