Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3061174rwe; Mon, 29 Aug 2022 05:18:48 -0700 (PDT) X-Google-Smtp-Source: AA6agR5WHeyro/m86RvNWG270W0ctAUc/QbNAIxS3aLrz40Giqd8uW0fpaMaCuPrT73vIYyn/UEk X-Received: by 2002:a17:90b:1a90:b0:1fd:f662:1657 with SMTP id ng16-20020a17090b1a9000b001fdf6621657mr507682pjb.140.1661775528115; Mon, 29 Aug 2022 05:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661775528; cv=none; d=google.com; s=arc-20160816; b=QRP/gmTYSutAablFZRNfjzhyLSBFA+GUrEfrKctFq/F8sE1cbXH0oNTSM+w9RYUWhv TgwSFzxCRi1cgtZcMI5UVY8c3fVwng4sb87V5TjyLJgCWu+EO2mVPmQwA1/DXOF2Zdms DTEGy9YJ8uIf41p8vuoV849zR9rCBjnkvwW8ah8tqs9CSLuAJK6NSyMOAAWLySNWgi/D Oe2xqMDWl8phWmPQSLFW9DppOyIh45+3Q3WFGG3LW4KexubkabRRFRBo8OJ1HRU7dp6P NYj7xzLX9jSO+Z/pGMFhk+kPvIofg3YrNCEvpB/A2Sf0Hprwefig9EdYNH0qTnJiw71l dnzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1SJtn/YEyxNqPRWU4OtRWvWxE6hzgr0xEFa85nBO2a4=; b=jHB+MHNdkYKvF7HFWtCR20cR5f96AA12MQYUGS5h5xomOx9C5R3oqtvbpVA1w7UY3r j1Yos5axxb/eptkoExgTgCquDvqk8u2XWBP9MOgdwGvfVR6RAJOEYBy4coaw2ItX0fLt qsFSy/uwPeNGbnmOeRqVtDA2y87YTOBnUkQhONhnU6C5aNMhjgGEMWyoFHDrQ9gcGz7+ X05mOA5/CruY51vvbGNUtuHHnqpfkkSlIpxwKcJx1JtaWgl89A5oe3JJHpv5pMPWSDJZ Por9AWrwbjTKvGTCRg7GV2FzMJK54V8HK3HLLZDDngtTP9pJLWVZSvp6fXvpew0SFW4M T6ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ydkK0+kb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c15-20020a170902b68f00b00174d26d18fbsi2048826pls.67.2022.08.29.05.18.36; Mon, 29 Aug 2022 05:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ydkK0+kb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbiH2MLm (ORCPT + 99 others); Mon, 29 Aug 2022 08:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiH2MLG (ORCPT ); Mon, 29 Aug 2022 08:11:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26A609410B; Mon, 29 Aug 2022 04:56:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D05CCB80FA7; Mon, 29 Aug 2022 11:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28D5EC433D6; Mon, 29 Aug 2022 11:18:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771924; bh=0OQtm6rkpc4cY5rw8LYv1/UD5ttx5nhgrijG2qWkUBQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ydkK0+kbRBryEgHMllYavm+KuaGgv7Xjg11JxyeMbiP54Ck0AdvF+8XUQDBjQE2Tl M9aib6I34x0Lam1bQj9aYxx54Csj5Rs7H6jXj049pqbUS9FOEMA8+IcpmiPiXuVl/z eb97pO87LONaYmojFGg0bKwGzUGJcLCCOe1yWPSo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Ming Lei , Jens Axboe Subject: [PATCH 5.19 142/158] blk-mq: fix io hung due to missing commit_rqs Date: Mon, 29 Aug 2022 12:59:52 +0200 Message-Id: <20220829105815.052283659@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu Kuai commit 65fac0d54f374625b43a9d6ad1f2c212bd41f518 upstream. 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' as 'errors' since it means that request is not queued successfully. Same problem exists in blk_mq_dispatch_rq_list(), 'BLK_STS_*RESOURCE' can't be treated as 'errors' here, fix the problem by calling commit_rqs if queue_rq return 'BLK_STS_*RESOURCE'. Fixes: d666ba98f849 ("blk-mq: add mq_ops->commit_rqs()") Signed-off-by: Yu Kuai Reviewed-by: Ming Lei Link: https://lore.kernel.org/r/20220726122224.1790882-1-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-mq.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1925,7 +1925,8 @@ out: /* If we didn't flush the entire list, we could have told the driver * there was more coming, but that turned out to be a lie. */ - if ((!list_empty(list) || errors) && q->mq_ops->commit_rqs && queued) + if ((!list_empty(list) || errors || needs_resource || + ret == BLK_STS_DEV_RESOURCE) && q->mq_ops->commit_rqs && queued) q->mq_ops->commit_rqs(hctx); /* * Any items that need requeuing? Stuff them into hctx->dispatch, @@ -2678,6 +2679,7 @@ void blk_mq_try_issue_list_directly(stru list_del_init(&rq->queuelist); ret = blk_mq_request_issue_directly(rq, list_empty(list)); if (ret != BLK_STS_OK) { + errors++; if (ret == BLK_STS_RESOURCE || ret == BLK_STS_DEV_RESOURCE) { blk_mq_request_bypass_insert(rq, false, @@ -2685,7 +2687,6 @@ void blk_mq_try_issue_list_directly(stru break; } blk_mq_end_request(rq, ret); - errors++; } else queued++; }