From patchwork Sat Oct 22 07:20:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1104790wrr; Sat, 22 Oct 2022 01:33:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fgr00ald3UeMuOGESGq5vTGwi7suS64EGPdWS67kp8G5UqYr9LwiKoLb6THBXot/yPaRZ X-Received: by 2002:a17:90b:3c88:b0:20d:9724:95dc with SMTP id pv8-20020a17090b3c8800b0020d972495dcmr26721091pjb.56.1666427604072; Sat, 22 Oct 2022 01:33:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427604; cv=none; d=google.com; s=arc-20160816; b=MjKkPaKb9gNfRbch608DqYZutZv8d6jwD8LkkGg9RKllD9QCDL2jRoVxKrdHp7TXe5 6IeDIGvIV2cjIqi3h5kZ/x0Wiy+sEXEMpcB5wo/isiVX6YBx1RHagTKxABETtSyeB1Ng jT23jmquVocejRMdmE0mSAlkpomvn+Cm41DnejTfHiiOXY95t5z9CcKHz+GhO6HM2InG CtjuWEMV8aoLvnQgfj/ZaAHpyMesAl1qfhO7ha3L65gunziFhOmzzZ0PjC0NPN/05zbv 2fqUtzqesWPu/k5s5HNsXPfUxtHRA7IWfWfmPJUWvRTm/uVV75H3CD9PfxbFVGofg2vk d3yg== 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=TIfJNZGQBLnfMFOQY80t4LIwutfA4bvGJOnU3XFk4fs=; b=GK0rVtx4yS5dzKP+IzBdD+t9l6L9qyUL9lvpbyZlNZPy4g7fUAcMPdn45PCbMPqEzJ y6Hy50YdERXfHf9nDDqu+gbsMl6qyVp/kFp/uRulobc2QrLnsC+ZwX5z8kyrAJyxHy1I rB6ysTMj7vOk2jcUST7EHuWvhLeROagWO0HWB2hocsRqoSW8S0aPYKp3xoJbnuQ//cxP eu7elBfYkkxZCysWl0vS4ieb5wZOwJ3sYwkwl4QVaYqQVwRLF3bB8XL2Aa5W1Zm4lYHg FeameVWoMCSIUs3cRHRAgVVekJ6ol/TA8mGP6ptEk2FTtym91PpUMY6ociJnXdzToH2Y MA/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ts5QmW25; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a630408000000b0043090081d69si5172713pge.82.2022.10.22.01.33.07; Sat, 22 Oct 2022 01:33:24 -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=Ts5QmW25; 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 S233507AbiJVIRG (ORCPT + 99 others); Sat, 22 Oct 2022 04:17:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233843AbiJVIPW (ORCPT ); Sat, 22 Oct 2022 04:15:22 -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 1263C2C6EA3; Sat, 22 Oct 2022 00:56:17 -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 5C89EB82E08; Sat, 22 Oct 2022 07:41:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C66B6C433C1; Sat, 22 Oct 2022 07:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424477; bh=cNt7T6RmL3y/9iiO0cyR9PT7nxKXSZDGJ+iSkvgxvIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ts5QmW25qpVUWv5PL6jYpACpazI3FQXg2Vz6uOJq9g6gxRMSBPJQoOrESeLEIhSX1 6qiYP+jJoKJ20yg826/D8qTmU6L7xSBDimFVoTDjVpoEWPdsm1W681fuYZF27PpP2K HoeIsZTfkx/0Sho/z4GAd73r3dC6ejoMpFdU8mFM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Jens Axboe Subject: [PATCH 5.19 159/717] blk-wbt: call rq_qos_add() after wb_normal is initialized Date: Sat, 22 Oct 2022 09:20:38 +0200 Message-Id: <20221022072443.637691100@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747375991317051702?= X-GMAIL-MSGID: =?utf-8?q?1747375991317051702?= From: Yu Kuai commit 8c5035dfbb9475b67c82b3fdb7351236525bf52b upstream. Our test found a problem that wbt inflight counter is negative, which will cause io hang(noted that this problem doesn't exist in mainline): t1: device create t2: issue io add_disk blk_register_queue wbt_enable_default wbt_init rq_qos_add // wb_normal is still 0 /* * in mainline, disk can't be opened before * bdev_add(), however, in old kernels, disk * can be opened before blk_register_queue(). */ blkdev_issue_flush // disk size is 0, however, it's not checked submit_bio_wait submit_bio blk_mq_submit_bio rq_qos_throttle wbt_wait bio_to_wbt_flags rwb_enabled // wb_normal is 0, inflight is not increased wbt_queue_depth_changed(&rwb->rqos); wbt_update_limits // wb_normal is initialized rq_qos_track wbt_track rq->wbt_flags |= bio_to_wbt_flags(rwb, bio); // wb_normal is not 0,wbt_flags will be set t3: io completion blk_mq_free_request rq_qos_done wbt_done wbt_is_tracked // return true __wbt_done wbt_rqw_done atomic_dec_return(&rqw->inflight); // inflight is decreased commit 8235b5c1e8c1 ("block: call bdev_add later in device_add_disk") can avoid this problem, however it's better to fix this problem in wbt: 1) Lower kernel can't backport this patch due to lots of refactor. 2) Root cause is that wbt call rq_qos_add() before wb_normal is initialized. Fixes: e34cbd307477 ("blk-wbt: add general throttling mechanism") Cc: Signed-off-by: Yu Kuai Link: https://lore.kernel.org/r/20220913105749.3086243-1-yukuai1@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-wbt.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -843,6 +843,10 @@ int wbt_init(struct request_queue *q) rwb->enable_state = WBT_STATE_ON_DEFAULT; rwb->wc = 1; rwb->rq_depth.default_depth = RWB_DEF_DEPTH; + rwb->min_lat_nsec = wbt_default_latency_nsec(q); + + wbt_queue_depth_changed(&rwb->rqos); + wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags)); /* * Assign rwb and add the stats callback. @@ -853,11 +857,6 @@ int wbt_init(struct request_queue *q) blk_stat_add_callback(q, rwb->cb); - rwb->min_lat_nsec = wbt_default_latency_nsec(q); - - wbt_queue_depth_changed(&rwb->rqos); - wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags)); - return 0; err_free: