Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3245965lfo; Sun, 22 May 2022 23:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCCSjiWccchxFx/YOKxVzBd27vXL/Is6LsDwP0sbqkOw+r5NmXqeuEV7lBab0pZKX0pMdg X-Received: by 2002:a63:de01:0:b0:3fa:1a35:36e0 with SMTP id f1-20020a63de01000000b003fa1a3536e0mr6500447pgg.92.1653288403999; Sun, 22 May 2022 23:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653288403; cv=none; d=google.com; s=arc-20160816; b=HyyGYVvtBkEJA1qSRK43rxf7DzhRKMN27YBIYDLyVlN0W6o1GQ5guatfmHYjAZUlM+ wF40Y/S30mRQPv6xLuwewaj9z4yfMQGtIwQX7hxLQ+Ul2cgBKGQaeDks93fKbJ0VtQ7Q 2hGGgQfMDBoTuDUFmTyf1/7aM/zNbZFEls+PH3WZ4HtdBUXeHmeMaDm7UVIoy+rgqt1s v36L9x689oQbjf0NhZOyQ4D4n9V4g5heZKUadHFBwgHq4NAa4C++z+njwKHHLSc9UQGY 0EoY4L5KrXvWiSviJ959Echkwy7B55te+UCRnS+FWroaDYt1yOBqusnLmosrLaxbakaG lzWg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=fHxREhC6f7WUI7uhXIKOs3GJMzoHqEwBSBTnb5JQLPk=; b=EY+Y7m4rhVhdvtyHrApguE00ikQGWXN1CkQGIc3ZQjdIOLXBYe+twjWUptjBZ7wimP JALUaVA1+fPk+5cwEK6YZqBqWuk8rXHzr1elhbLcFN6DFlDxIMZVhCs8+S6gsmZ9bejE K5EEelOYT4A+PzAscekFUXH0vhBZTl9HlubJFdBujy2W0RSJlyhrFVYyrYlDIVDdYtQw mak5ag0qjsVqanHkIbA4gABnwdiToQRDjTqWrLkmjakZyRbjdNFiffwxZnWWWuVbFP5A SLG3avojSutSQQCwnapsTTdwupSMyIGVpXBOR5JN2QauuGjtQMGwAEpfK2OCA2qBJSDq LOIA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s7-20020a63f047000000b003d82053da65si9115656pgj.501.2022.05.22.23.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 May 2022 23:46:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3E7043D4AB; Sun, 22 May 2022 23:16:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352065AbiEUHY3 (ORCPT + 99 others); Sat, 21 May 2022 03:24:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354726AbiEUHYP (ORCPT ); Sat, 21 May 2022 03:24:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C325166475; Sat, 21 May 2022 00:24:14 -0700 (PDT) Received: from kwepemi100015.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L4w6t5tfwzjWwt; Sat, 21 May 2022 15:23:18 +0800 (CST) Received: from kwepemm600009.china.huawei.com (7.193.23.164) by kwepemi100015.china.huawei.com (7.221.188.125) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 21 May 2022 15:24:12 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 21 May 2022 15:24:11 +0800 From: Yu Kuai To: , , , CC: , , , Subject: [PATCH -next v3 3/6] nbd: don't clear 'NBD_CMD_INFLIGHT' flag if request is not completed Date: Sat, 21 May 2022 15:37:46 +0800 Message-ID: <20220521073749.3146892-4-yukuai3@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220521073749.3146892-1-yukuai3@huawei.com> References: <20220521073749.3146892-1-yukuai3@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600009.china.huawei.com (7.193.23.164) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Otherwise io will hung because request will only be completed if the cmd has the flag 'NBD_CMD_INFLIGHT'. Fixes: 07175cb1baf4 ("nbd: make sure request completion won't concurrent") Signed-off-by: Yu Kuai --- drivers/block/nbd.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 2ee1e376d5c4..a0d0910dae2a 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -403,13 +403,14 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, if (!mutex_trylock(&cmd->lock)) return BLK_EH_RESET_TIMER; - if (!__test_and_clear_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { + if (!test_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { mutex_unlock(&cmd->lock); return BLK_EH_DONE; } if (!refcount_inc_not_zero(&nbd->config_refs)) { cmd->status = BLK_STS_TIMEOUT; + __clear_bit(NBD_CMD_INFLIGHT, &cmd->flags); mutex_unlock(&cmd->lock); goto done; } @@ -478,6 +479,7 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req, dev_err_ratelimited(nbd_to_dev(nbd), "Connection timed out\n"); set_bit(NBD_RT_TIMEDOUT, &config->runtime_flags); cmd->status = BLK_STS_IOERR; + __clear_bit(NBD_CMD_INFLIGHT, &cmd->flags); mutex_unlock(&cmd->lock); sock_shutdown(nbd); nbd_config_put(nbd); @@ -745,7 +747,7 @@ static struct nbd_cmd *nbd_handle_reply(struct nbd_device *nbd, int index, cmd = blk_mq_rq_to_pdu(req); mutex_lock(&cmd->lock); - if (!__test_and_clear_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { + if (!test_bit(NBD_CMD_INFLIGHT, &cmd->flags)) { dev_err(disk_to_dev(nbd->disk), "Suspicious reply %d (status %u flags %lu)", tag, cmd->status, cmd->flags); ret = -ENOENT; @@ -854,8 +856,16 @@ static void recv_work(struct work_struct *work) } rq = blk_mq_rq_from_pdu(cmd); - if (likely(!blk_should_fake_timeout(rq->q))) - blk_mq_complete_request(rq); + if (likely(!blk_should_fake_timeout(rq->q))) { + bool complete; + + mutex_lock(&cmd->lock); + complete = __test_and_clear_bit(NBD_CMD_INFLIGHT, + &cmd->flags); + mutex_unlock(&cmd->lock); + if (complete) + blk_mq_complete_request(rq); + } percpu_ref_put(&q->q_usage_counter); } -- 2.31.1