Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15109276rwb; Mon, 28 Nov 2022 08:05:21 -0800 (PST) X-Google-Smtp-Source: AA0mqf4hyjFGVFoPuTtQUZkbSQ2lfp+fRGLcJjTNgOZYlVsicGERpzAn0HAYPu+7me6JuPkb+z9I X-Received: by 2002:a17:906:19d7:b0:7b2:b782:e1df with SMTP id h23-20020a17090619d700b007b2b782e1dfmr39608482ejd.308.1669651520244; Mon, 28 Nov 2022 08:05:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669651520; cv=none; d=google.com; s=arc-20160816; b=kUdSLY3Iryx7KTBmI7OGIK13YQfUZn3tmgWnPIdPWHODxLqGeGxOYyTb5zwKf9XbsB KX+NfqmJVLVe9q3Gg/XkyR42X5KWCWIoHDV9+0f51tUx8VwxrXbS3jDBQt/xtkr9rJIs h7PhjNnGT3Q55m30ztoueHaLP7uvwJsKWsgO+8ZwJk4/mrdo6KhyzEs0WIlv9jR9qbsL 53kBdtyAlHOqvTmNzOFGGEvEeEdChWAkKGHpZ+qdl94VUwv/UqgER8IsmTFUc8HEWN42 Rx+mRt7EP0mc3r4hgpDztSfg802OAzrMFE82U/BfWst+LMBzJ2cuGrs1b+43TohVA45q ThlA== 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=rKWtQPmqkoY/qkWVcqIndEq8FfU71DE9FG8AJqb9uaA=; b=COA3Kz9cFG8Zi5eIXI0QjhnpPe1+3nyqKRCi9L6qInlUFexz0Z3wqQOfSNnk16uzYU bv9G9fJLOoNoayyc+QIQkb5LmRPmqe5SJZJniSUEnb+4zKKkZqOHYT7viwU/EeUlDZKu 612ezsVM276CBlGaNe1SfLlyjlC4gvO1AxzDyzSFad1dnGriKsy6ahP1m+BhFvcTE7LN 3wDeF8KkE9vUPBMYfjWmHUmRklBK+D0B7gGvhCElvXHDKffjz2KKAtkydsa91uKsYLCy LUQHCh8eQ17Xk+gcR/QS3v6AiGZWhNaP+yGcQz8y30iKMMFz4Ug7boAoLTT+OJ6Ja2er aS2Q== 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:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a170906340d00b007ac9a51342asi7732038ejb.188.2022.11.28.08.04.55; Mon, 28 Nov 2022 08:05:20 -0800 (PST) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231734AbiK1PXu (ORCPT + 84 others); Mon, 28 Nov 2022 10:23:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbiK1PXc (ORCPT ); Mon, 28 Nov 2022 10:23:32 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B341E59; Mon, 28 Nov 2022 07:23:31 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NLTk31BpDzRpG4; Mon, 28 Nov 2022 23:22:51 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500024.china.huawei.com (7.185.36.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 23:23:28 +0800 Received: from huawei.com (10.175.127.227) by dggpeml500003.china.huawei.com (7.185.36.200) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 28 Nov 2022 23:23:28 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 4/8] blk-iocost: read params inside lock in sysfs apis Date: Mon, 28 Nov 2022 23:44:30 +0800 Message-ID: <20221128154434.4177442-5-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221128154434.4177442-1-linan122@huawei.com> References: <20221128154434.4177442-1-linan122@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: dggems701-chm.china.huawei.com (10.3.19.178) To dggpeml500003.china.huawei.com (7.185.36.200) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, 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 Otherwise, user might get abnormal values if params is updated concurrently. Signed-off-by: Yu Kuai Signed-off-by: Li Nan --- block/blk-iocost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 2bfecc511dd9..a645184aba4a 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3125,6 +3125,7 @@ static u64 ioc_qos_prfill(struct seq_file *sf, struct blkg_policy_data *pd, if (!dname) return 0; + spin_lock_irq(&ioc->lock); seq_printf(sf, "%s enable=%d ctrl=%s rpct=%u.%02u rlat=%u wpct=%u.%02u wlat=%u min=%u.%02u max=%u.%02u\n", dname, ioc->enabled, ioc->user_qos_params ? "user" : "auto", ioc->params.qos[QOS_RPPM] / 10000, @@ -3137,6 +3138,7 @@ static u64 ioc_qos_prfill(struct seq_file *sf, struct blkg_policy_data *pd, ioc->params.qos[QOS_MIN] % 10000 / 100, ioc->params.qos[QOS_MAX] / 10000, ioc->params.qos[QOS_MAX] % 10000 / 100); + spin_unlock_irq(&ioc->lock); return 0; } @@ -3319,12 +3321,14 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf, if (!dname) return 0; + spin_lock_irq(&ioc->lock); seq_printf(sf, "%s ctrl=%s model=linear " "rbps=%llu rseqiops=%llu rrandiops=%llu " "wbps=%llu wseqiops=%llu wrandiops=%llu\n", dname, ioc->user_cost_model ? "user" : "auto", u[I_LCOEF_RBPS], u[I_LCOEF_RSEQIOPS], u[I_LCOEF_RRANDIOPS], u[I_LCOEF_WBPS], u[I_LCOEF_WSEQIOPS], u[I_LCOEF_WRANDIOPS]); + spin_unlock_irq(&ioc->lock); return 0; } -- 2.31.1