Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp983565rwi; Wed, 19 Oct 2022 05:29:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5N9uUPbTTGgfXquydpforBx8But6+MZVFaGBLx1TNXBUOyd9Ujtkdg1mAtveEN4hATDetN X-Received: by 2002:a17:90b:1b07:b0:20d:571c:1d3d with SMTP id nu7-20020a17090b1b0700b0020d571c1d3dmr9660168pjb.192.1666182543524; Wed, 19 Oct 2022 05:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666182543; cv=none; d=google.com; s=arc-20160816; b=jbAwdFqSB9HKEeyLEAPvK8VC5rjpAPFrdCaPQpAj+GVgBpanrl1nHZ99Jj7+LLCg11 9hFXVebfpkr2c4S2teFYkJov+Ey+ao4JhtsHPVk6a5nrb153/qC8Xs1qtsxNPiXNNjTC nzi2GF2K2OfzV8B3btxJO8ugmuUs3AHhBB09gCKhVJXZbnaTmjgGWaaoIUGgdVcRLJW7 Yu+Cwz/VkAZFBVqqATjfvkTeKChSRPXSp1rxFo97gQYv9bUxcAY/NTeuLRWLfiZZJJ0O tWr9DuGAfsPjvdjkQq8cIWD/19wx5nTxlTYwDlJseVAPLyBtxi6HYCGYvNVzx++1TFWQ mOwg== 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=Q+KwH+u66Mr4VBJ6suqLpOIZghFV7rGFROyDlHXdMCusUWM3JaiLwxXUaCcOS4HLs7 5AugXJ/DQAAU/jvROS7jrZa+eGM8tEnJ/QuOk8GTZoWjAJmI8j61m0RGQanblTqPW+PD nr6DAHnBpZ0nqq7p3iqiZZyQPcDakwzjGF80df+ouhMQYF0o9R16crP+bLNi+wa1okxM oG3lN+cfMGnxqDa7y/72azyzYBAcdlT4M+c7v5b0bbqLQL6UqmGx1Xt42mJJqwrOTb2U ftkCA1/VCZ2uq42ufMFsU6ucMkkSRfyQhTfFGsZYW0+AB0GA3GBP1eHD/vSsyje3muR6 o8rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qTzh2qs5; 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 p2-20020a170902b08200b00180556e1b6bsi17294520plr.609.2022.10.19.05.28.43; Wed, 19 Oct 2022 05:29:03 -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=qTzh2qs5; 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 S232976AbiJSMSO (ORCPT + 99 others); Wed, 19 Oct 2022 08:18:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232957AbiJSMRm (ORCPT ); Wed, 19 Oct 2022 08:17:42 -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 CD179FF235; Wed, 19 Oct 2022 04:53:25 -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 C2432B822F6; Wed, 19 Oct 2022 08:45:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3680FC433D6; Wed, 19 Oct 2022 08:45:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169145; bh=cNt7T6RmL3y/9iiO0cyR9PT7nxKXSZDGJ+iSkvgxvIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTzh2qs5jq7cpuGiQ6MH8/M+ErxjaGR6i5k4LHR3Ksey7GkcFyGgZsXST9L9fFAfB 9O8yXlMg98j5Grw+IqWLBisbxSwBRJqM3BFayfbG73H2AvuPh50riMl9YsUTxT8mb8 GJ1G1jp24n7A5dJnBLD60NxPZTo6NZrqoO1GNobY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Jens Axboe Subject: [PATCH 6.0 173/862] blk-wbt: call rq_qos_add() after wb_normal is initialized Date: Wed, 19 Oct 2022 10:24:20 +0200 Message-Id: <20221019083257.596074416@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@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.4 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 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: