From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40C4FC43334 for ; Tue, 26 Jul 2022 02:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237329AbiGZCz7 (ORCPT ); Mon, 25 Jul 2022 22:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229853AbiGZCz6 (ORCPT ); Mon, 25 Jul 2022 22:55:58 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FEDEBF43; Mon, 25 Jul 2022 19:55:57 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4LsM2l41YdzlC3d; Tue, 26 Jul 2022 10:54:55 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP3 (Coremail) with SMTP id _Ch0CgAHamm5V99isC_KBA--.27636S3; Tue, 26 Jul 2022 10:55:55 +0800 (CST) Subject: Re: [PATCH] blk-mq: fix io hung due to missing commit_rqs while scheduler is none To: Ming Lei , Yu Kuai Cc: axboe@kernel.dk, osandov@fb.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yi.zhang@huawei.com References: <20220726023852.3413784-1-yukuai1@huaweicloud.com> From: Yu Kuai Message-ID: Date: Tue, 26 Jul 2022 10:55:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: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ZFpf9x0JUdHU DUUUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Ming ÔÚ 2022/07/26 10:48, Ming Lei дµÀ: > On Tue, Jul 26, 2022 at 10:38:52AM +0800, Yu Kuai wrote: >> From: Yu Kuai >> >> Currently, in virtio_scsi, if 'bd->last' is not set to true while >> dispatching request, such io will stay in driver's queue, and driver >> will wait for block layer to dispatch more rqs. However, if block >> layer failed to dispatch more rq, it should trigger commit_rqs to >> inform driver. >> >> There is a problem in blk_mq_try_issue_list_directly() that commit_rqs >> won't be called: >> >> // assume that queue_depth is set to 1, list contains two rq >> blk_mq_try_issue_list_directly >> blk_mq_request_issue_directly >> // dispatch first rq >> // last is false >> __blk_mq_try_issue_directly >> blk_mq_get_dispatch_budget >> // succeed to get first budget >> __blk_mq_issue_directly >> scsi_queue_rq >> cmd->flags |= SCMD_LAST >> virtscsi_queuecommand >> kick = (sc->flags & SCMD_LAST) != 0 >> // kick is false, first rq won't issue to disk >> queued++ >> >> blk_mq_request_issue_directly >> // dispatch second rq >> __blk_mq_try_issue_directly >> blk_mq_get_dispatch_budget >> // failed to get second budget >> ret == BLK_STS_RESOURCE >> blk_mq_request_bypass_insert >> // errors is still 0 >> >> if (!list_empty(list) || errors && ...) >> // won't pass, commit_rqs won't be called >> >> In this situation, first rq relied on second rq to dispatch, while >> second rq relied on first rq to complete, thus they will both hung. >> >> Fix the problem by also treat 'BLK_STS_RESOURCE' and >> 'BLK_STS_DEV_RESOURCE' as 'errors' in blk_mq_try_issue_list_directly(), >> so that 'commit_rqs' will be called when dispatch of last rq failed. >> >> Fixes: d666ba98f849 ("blk-mq: add mq_ops->commit_rqs()") >> Signed-off-by: Yu Kuai >> --- >> block/blk-mq.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/block/blk-mq.c b/block/blk-mq.c >> index 70177ee74295..752b0fe4c128 100644 >> --- a/block/blk-mq.c >> +++ b/block/blk-mq.c >> @@ -2680,6 +2680,7 @@ void blk_mq_try_issue_list_directly(struct blk_mq_hw_ctx *hctx, >> list_del_init(&rq->queuelist); >> ret = blk_mq_request_issue_directly(rq, list_empty(list)); >> if (ret != BLK_STS_OK) { >> + errors++; > > OK, it is because that list becomes empty, but .queue_rq(last_rq_in_list) > returns BLK_STS_*RESOURCE, but scsi can't call ->queuecommand() for this > real last rq. Then blk_mq_try_issue_list_directly() doesn't call > ->commit_rqs() too. > > Here errors means that request not queued successfully, so this patch > looks fine. > > Also I think blk_mq_dispatch_rq_list() needs similar handling too, > right? Yes, you're right, I'll handle blk_mq_dispatch_rq_list() in v2, and also change the title. Thanks, Kuai