From patchwork Fri Nov 4 02:39:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 15285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp119025wru; Thu, 3 Nov 2022 19:21:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6BABBAkvYt+mJ/P6UmLrI01ri6bQD+NVuck70LqlvnrDMZ6sbnUpjk186qibBSI6q098qd X-Received: by 2002:a17:907:72c7:b0:791:9ba2:4978 with SMTP id du7-20020a17090772c700b007919ba24978mr30909089ejc.217.1667528475283; Thu, 03 Nov 2022 19:21:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667528475; cv=none; d=google.com; s=arc-20160816; b=YCUV2qgbtMiKzekg5aqDKMl8KpKZqhr2xRPjCwTYsaEgIxlPdjE3CBaMBeTBjHJ7dS U8Acr7QR8GjT7d26znuAHg+VCNegYDK+e54WUL+OEOqJRmUfQfB40bcBYagKMI0WkFKr 7jebKAEtdU3HO/JiVu3cVCMbmcH0imI3IhlkcgQuO5Z7l5MDm1FskXX8avosldQ9Q7SS 0sZ5Qa7jsoOVWpywU8hPKMj1WwJKM4AWyCFlZfq3AaP/PJpzwgExlTtsNeQkk59IsIv4 5grMXdei3wEg2Ag2dD0UTtO/bDdJ8HWwUXJkCFLE1SiRfYDm2tzdsCUS7/3Apw6muBI8 RUVQ== 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=8HCx048Ed3tBIT13ClsyrTH8BynZxx8SfErQ2NzX4mQ=; b=ED2QE3SvjOEl0YGMW3wJ4eqMvo69l/10d3ZcZkTHR4R8XPC6eOyDrgJaZk38JJtJOJ ImQQighG89J2pvkklZAzmPj7lFyE06DwpOGIRe4Xr4uJEbqMkdCPI0JKnMIZI3Nfrvy4 bSnxYHXjv7OrD6uZDSufq+AvG0zpHFe+7d8lLc+WRv8n4XbCxp7ZNKZWuWzvWvRAQFyE rGJ8/VyPGh/AkJQBXYRhQxDalzaQgRQVl1QNVLaSh3lUD9u5wC0YLVkf2ccDwfO0iJdV f2z8ar/GRa+qFuqzIjCMtRj8csftZ+YYLaholK0nGuTIjIYE698qfizPF804mUCSOw2q Ol/w== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd12-20020a170907628c00b007ae127c6c80si3483595ejc.672.2022.11.03.19.20.52; Thu, 03 Nov 2022 19:21:15 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbiKDCSD (ORCPT + 99 others); Thu, 3 Nov 2022 22:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230301AbiKDCSB (ORCPT ); Thu, 3 Nov 2022 22:18:01 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4BBF20F; Thu, 3 Nov 2022 19:17:59 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4N3PNX0yHpz6Pspv; Fri, 4 Nov 2022 10:15:24 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgB3D9RTdmRjDShNBQ--.16192S5; Fri, 04 Nov 2022 10:17:58 +0800 (CST) From: Yu Kuai To: hch@lst.de, tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2 1/5] blk-iocost: cleanup ioc_qos_write() and ioc_cost_model_write() Date: Fri, 4 Nov 2022 10:39:34 +0800 Message-Id: <20221104023938.2346986-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221104023938.2346986-1-yukuai1@huaweicloud.com> References: <20221104023938.2346986-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgB3D9RTdmRjDShNBQ--.16192S5 X-Coremail-Antispam: 1UD129KBjvJXoWxur1UJF4rJFy5uFy5ZF18Krg_yoWrZr48pF WF93yaq3y8Ars7Wr42yF42ga4rCwsFgry7CFWkGr1fZrnFyrnFgF109FyUurW8JFZ3JFs8 JFZFqrWDCayDA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUqAp5UUUUU = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1748530338386320856?= X-GMAIL-MSGID: =?utf-8?q?1748530338386320856?= From: Yu Kuai There are no functional changes, just to make the code a litter cleaner and follow up patches easier. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig --- block/blk-iocost.c | 62 +++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index f01359906c83..fd495e823db2 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3185,7 +3185,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, if (!ioc) { ret = blk_iocost_init(disk); if (ret) - goto err; + goto out; ioc = q_to_ioc(disk->queue); } @@ -3197,6 +3197,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, enable = ioc->enabled; user = ioc->user_qos_params; + ret = -EINVAL; while ((p = strsep(&input, " \t\n"))) { substring_t args[MAX_OPT_ARGS]; char buf[32]; @@ -3218,7 +3219,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, else if (!strcmp(buf, "user")) user = true; else - goto einval; + goto out_unlock; continue; } @@ -3228,39 +3229,39 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, case QOS_WPPM: if (match_strlcpy(buf, &args[0], sizeof(buf)) >= sizeof(buf)) - goto einval; + goto out_unlock; if (cgroup_parse_float(buf, 2, &v)) - goto einval; + goto out_unlock; if (v < 0 || v > 10000) - goto einval; + goto out_unlock; qos[tok] = v * 100; break; case QOS_RLAT: case QOS_WLAT: if (match_u64(&args[0], &v)) - goto einval; + goto out_unlock; qos[tok] = v; break; case QOS_MIN: case QOS_MAX: if (match_strlcpy(buf, &args[0], sizeof(buf)) >= sizeof(buf)) - goto einval; + goto out_unlock; if (cgroup_parse_float(buf, 2, &v)) - goto einval; + goto out_unlock; if (v < 0) - goto einval; + goto out_unlock; qos[tok] = clamp_t(s64, v * 100, VRATE_MIN_PPM, VRATE_MAX_PPM); break; default: - goto einval; + goto out_unlock; } user = true; } if (qos[QOS_MIN] > qos[QOS_MAX]) - goto einval; + goto out_unlock; if (enable) { blk_stat_enable_accounting(disk->queue); @@ -3281,21 +3282,14 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, } ioc_refresh_params(ioc, true); - spin_unlock_irq(&ioc->lock); + ret = nbytes; - blk_mq_unquiesce_queue(disk->queue); - blk_mq_unfreeze_queue(disk->queue); - - blkdev_put_no_open(bdev); - return nbytes; -einval: +out_unlock: spin_unlock_irq(&ioc->lock); - blk_mq_unquiesce_queue(disk->queue); blk_mq_unfreeze_queue(disk->queue); - ret = -EINVAL; -err: +out: blkdev_put_no_open(bdev); return ret; } @@ -3364,7 +3358,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, if (!ioc) { ret = blk_iocost_init(bdev->bd_disk); if (ret) - goto err; + goto out; ioc = q_to_ioc(q); } @@ -3375,6 +3369,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, memcpy(u, ioc->params.i_lcoefs, sizeof(u)); user = ioc->user_cost_model; + ret = -EINVAL; while ((p = strsep(&input, " \t\n"))) { substring_t args[MAX_OPT_ARGS]; char buf[32]; @@ -3392,20 +3387,20 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, else if (!strcmp(buf, "user")) user = true; else - goto einval; + goto out_unlock; continue; case COST_MODEL: match_strlcpy(buf, &args[0], sizeof(buf)); if (strcmp(buf, "linear")) - goto einval; + goto out_unlock; continue; } tok = match_token(p, i_lcoef_tokens, args); if (tok == NR_I_LCOEFS) - goto einval; + goto out_unlock; if (match_u64(&args[0], &v)) - goto einval; + goto out_unlock; u[tok] = v; user = true; } @@ -3416,23 +3411,16 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, } else { ioc->user_cost_model = false; } - ioc_refresh_params(ioc, true); - spin_unlock_irq(&ioc->lock); - blk_mq_unquiesce_queue(q); - blk_mq_unfreeze_queue(q); - - blkdev_put_no_open(bdev); - return nbytes; + ioc_refresh_params(ioc, true); + ret = nbytes; -einval: +out_unlock: spin_unlock_irq(&ioc->lock); - blk_mq_unquiesce_queue(q); blk_mq_unfreeze_queue(q); - ret = -EINVAL; -err: +out: blkdev_put_no_open(bdev); return ret; } From patchwork Fri Nov 4 02:39:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 15289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp120588wru; Thu, 3 Nov 2022 19:25:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tf7IZLGm+t+uYtsmMV4WChGDf7ng/RX5ge7j3U+VJVqnuaBUxTaHsVfBwyjPrfB4lkCh8 X-Received: by 2002:a17:906:4e18:b0:7ab:777:a7d7 with SMTP id z24-20020a1709064e1800b007ab0777a7d7mr229256eju.757.1667528742068; Thu, 03 Nov 2022 19:25:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667528742; cv=none; d=google.com; s=arc-20160816; b=oJU0rYTt7S53WszfroE2bEAgSeYNU2otsmf4pxhR4inVWXY5MhgHInJCR6N/qPDR4m qyYcr1hQZo+/ERka+n9h8GfjzzykGZk//Ejq0aJfrvjcV+2Xd6GjAfpZGbibcpW275Cq oS21UEa4Vlnr3/WwnMxeRmvTQHqoyaw0fBJhJfg47LjeLI/gzIt3o9CcLoHY9C2vH9s4 Djo16aqCxrRuAg2dwRjNfRB8c2O+HSn/qSNqK1IC7Q4joRhQPXV+OYzzbBDq42+6/0O6 8Rqb/GjizUEamQK6JBbIIiG4DTvWcFKA8bHgBtXtg0cd+dg6ItyZmJDVzm9HQCWpIvvv g2SQ== 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=1LYe1O4OT6op2MgdqxZhxR3LSo1StE5Af8FKCx2rnzI=; b=KgGuq8Uvr6X4B12KmLLy7OOC9xa+3fm6iZy2pXIfeM3RqORK5hJyztGZg80qmmKpM7 mLVNpVFRTl22j3fK7ChJXFc6QL0Al++j8OhXpxO3hkdH2sP1xSLikxi00uzkxdFKwV8w 74eoj3/ltmsNmbdeGs3wZePKWnyWP7xq1jVJ3nPpITFgxHfbyggyYs0CGu842mKNhPJx qCBo7Of0O+4+uYdc1AGgL2IsCMGTfDQY4GQNOs/iT4cP5om5D6SHmNP1eqpWAkJwEPSZ j5hl8VaY1YjZxzz5GePM0IKzoDPgN6GywLVY+sVx3FoUuucRSPZ/QeG1S4aLN6F/NUZv lmfw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a056402440700b00461f1c61f1esi3850846eda.386.2022.11.03.19.25.18; Thu, 03 Nov 2022 19:25:42 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231420AbiKDCSQ (ORCPT + 99 others); Thu, 3 Nov 2022 22:18:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230388AbiKDCSB (ORCPT ); Thu, 3 Nov 2022 22:18:01 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A122DF4; Thu, 3 Nov 2022 19:17:59 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4N3PNV3VVwzKKPM; Fri, 4 Nov 2022 10:15:22 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgB3D9RTdmRjDShNBQ--.16192S6; Fri, 04 Nov 2022 10:17:58 +0800 (CST) From: Yu Kuai To: hch@lst.de, tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2 2/5] blk-iocost: improve hanlder of match_u64() Date: Fri, 4 Nov 2022 10:39:35 +0800 Message-Id: <20221104023938.2346986-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221104023938.2346986-1-yukuai1@huaweicloud.com> References: <20221104023938.2346986-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgB3D9RTdmRjDShNBQ--.16192S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Zry8Cw1xWF4kuF1DAw15CFg_yoW8CFy3pF Wa9rZIqFy5Jrs2gFnrCFnF9a43C397tryfGayDGa4fJr17Jr9F9Fn5JryDJFy8JrWfGws0 gFnay3y8G3ZrCrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUc6pPUUUUU = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1748530618549716696?= X-GMAIL-MSGID: =?utf-8?q?1748530618549716696?= From: Yu Kuai 1) There are one place that return value of match_u64() is not checked. 2) If match_u64() failed, return value is set to -EINVAL despite that there are other possible errnos. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig --- block/blk-iocost.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index fd495e823db2..c532129a1456 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3202,6 +3202,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, substring_t args[MAX_OPT_ARGS]; char buf[32]; int tok; + int err; s64 v; if (!*p) @@ -3209,7 +3210,12 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, switch (match_token(p, qos_ctrl_tokens, args)) { case QOS_ENABLE: - match_u64(&args[0], &v); + err = match_u64(&args[0], &v); + if (err) { + ret = err; + goto out_unlock; + } + enable = v; continue; case QOS_CTRL: @@ -3238,8 +3244,12 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, break; case QOS_RLAT: case QOS_WLAT: - if (match_u64(&args[0], &v)) + err = match_u64(&args[0], &v); + if (err) { + ret = err; goto out_unlock; + } + qos[tok] = v; break; case QOS_MIN: @@ -3374,6 +3384,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, substring_t args[MAX_OPT_ARGS]; char buf[32]; int tok; + int err; u64 v; if (!*p) @@ -3399,8 +3410,13 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, tok = match_token(p, i_lcoef_tokens, args); if (tok == NR_I_LCOEFS) goto out_unlock; - if (match_u64(&args[0], &v)) + + err = match_u64(&args[0], &v); + if (err) { + ret = err; goto out_unlock; + } + u[tok] = v; user = true; } From patchwork Fri Nov 4 02:39:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 15286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp119787wru; Thu, 3 Nov 2022 19:23:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4jpUgWLhMv4dZ486s6EsjZvgymuqEGbINJC7V4YyNaAegaw8g+73nk/Biq3N8HWde+W/8E X-Received: by 2002:a17:906:285a:b0:7ae:127a:cc2e with SMTP id s26-20020a170906285a00b007ae127acc2emr7331756ejc.229.1667528604060; Thu, 03 Nov 2022 19:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667528604; cv=none; d=google.com; s=arc-20160816; b=Tm5bY1qfi68JQJV+ZPkkpXqyZ9QJPyLq/V++wRcWh04ycHKq+OuPBGZXVPiP4N8usM mrujjeOxChWJo82ZBhIqs6vVxxeeh3ynFPF197mLblgV0fqerCycql8NF6XFUfS4jWRk y/nPOUPt9Pa8o4p8K9q/pHGj3fUE4zP8fyljVFQFoqVGMoIHyffUIqX1xw91EUGt6BxF UNQOxtlpDKBScjwaFAe2CqWirwMKevmnM8/Timn/ljQlmwUZ8+ygJosqYeHn07bsjDTe LMUiULZ9yGelOJiBBv8JttHpKFf/7qPvCrpn6h8nA8LTI6XdLzPd7P4tnMxU0OUiA0xG o8WA== 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=6Slk+Pkdg32wEAbwd1WHNkPgxOYKthT4xIRt4ZngIbY=; b=L6WHAhq1Nreukp6an0P5mjTu4DLM38GG6nGZ+r2U/102z1WD9qQIE8kqDU3GlIZMWs Tpa/iOXtPCP26usHIJpZxufhcJA8MqSJwayvbUGN8WL70wZvBPCU6Q8Di6VFEx/LFuV1 wtDRWRfUox/MmqmYHMS+9vB9jNgyYiXGXIke55R7Vm7QDSL5OP+abd+U2Rq7iZFeOtcy 62q24+r5O8ZNYRL4QKkJdvhhrStDiES6pTJkNOOzFHitI5VK1BmAVAirMTvyiUi3jE0v HjMiyODx79jzfUZVYdMcDWU7i46NoVKPbVAt0xS3ijrHu+PLrZ0Oi96NfyhZ/ab1X87A LuhA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id em6-20020a056402364600b00461e322ec5dsi3371122edb.294.2022.11.03.19.23.00; Thu, 03 Nov 2022 19:23: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231387AbiKDCSN (ORCPT + 99 others); Thu, 3 Nov 2022 22:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbiKDCSB (ORCPT ); Thu, 3 Nov 2022 22:18:01 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5880C38BB; Thu, 3 Nov 2022 19:18:00 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4N3PNy1GD9zlBh0; Fri, 4 Nov 2022 10:15:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgB3D9RTdmRjDShNBQ--.16192S7; Fri, 04 Nov 2022 10:17:58 +0800 (CST) From: Yu Kuai To: hch@lst.de, tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2 3/5] blk-iocost: don't allow to configure bio based device Date: Fri, 4 Nov 2022 10:39:36 +0800 Message-Id: <20221104023938.2346986-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221104023938.2346986-1-yukuai1@huaweicloud.com> References: <20221104023938.2346986-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgB3D9RTdmRjDShNBQ--.16192S7 X-Coremail-Antispam: 1UD129KBjvdXoWrKryxur13Zr1rCr4rJFWxXrb_yoWkJFg_Aa 4fW34qgFn5Gay8WF1jyF90qrZ3Gw4rXFWjvrW7JasxJF1DXas8tan3Xr18JF45uayj9a45 Ca97Cwn8Ars7WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb6AFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04 v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbJ73DUUUUU= = X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1748530473352795621?= X-GMAIL-MSGID: =?utf-8?q?1748530473352795621?= From: Yu Kuai iocost is based on rq_qos, which can only work for request based device, thus it doesn't make sense to configure iocost for bio based device. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig --- block/blk-iocost.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index c532129a1456..2bfecc511dd9 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3181,6 +3181,11 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, return PTR_ERR(bdev); disk = bdev->bd_disk; + if (!queue_is_mq(disk->queue)) { + ret = -EPERM; + goto out; + } + ioc = q_to_ioc(disk->queue); if (!ioc) { ret = blk_iocost_init(disk); @@ -3364,6 +3369,11 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, return PTR_ERR(bdev); q = bdev_get_queue(bdev); + if (!queue_is_mq(q)) { + ret = -EPERM; + goto out; + } + ioc = q_to_ioc(q); if (!ioc) { ret = blk_iocost_init(bdev->bd_disk); From patchwork Fri Nov 4 02:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 15288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp120287wru; Thu, 3 Nov 2022 19:25:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM42eXiCzYBiQzliAP9eFRx09210I/QBmKqr+VOGSMRpC0H0PQKYnSd+ql/Gbl788I3L6xdP X-Received: by 2002:a17:906:9746:b0:798:baec:3a80 with SMTP id o6-20020a170906974600b00798baec3a80mr31612202ejy.610.1667528703149; Thu, 03 Nov 2022 19:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667528703; cv=none; d=google.com; s=arc-20160816; b=oxBPO2c9iTwDIGG/NE6HAW7qmot4i/7aTSlg0EogolSmKxoDtKoXgMun4ic7I/mTXy ycSOuhox/gZtoZgj5Ozp4bE/Ve5dPPThGTQPcZ0GzM5Xbl670vD25HsJsLhh8kCM6o1i OAgW2+NDuUpnY1QUyQGlDEAbLZ8Hy7ezTsojnKpB8ugSv0NfWwz4HIEca3jBFuICN+Uv m4msvly3Karc5+N4WfL/NKbjqjliMl2mmcnI+IdJytyqE8idRPS7dQNS+hQYV9VTQbNV vuNk+ytyld1qkz+ElK4lj08izILV+OWOqDlEh+erTPqWokr2mRQR8xc7Vt08c0oZq0Wd +O6g== 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=VUwxWgMIn9Y/ODdH8Wpo16K/fMETsGpP8YPMPmK+wrw=; b=Uz1j/dEsST2v9Tj8EF2pps8WfLEJZZihFtchLTAkAlnmcRK6QPCzm06BFu9JSRI5CA yiIa487tMts0rfp4VU5BGHvQxSjG8k7+s+HpwtS6yj7PMaLwP/ocEyOc8KmTcpiHdI1d qkv/u149GbhCZDYwNWbL434hqXT8+Ly0JfT1JfWKorPFPgCmaHol4r/LgEOfRvh2EFDJ D837bOF6pve9sLfkrFNgjhxy4q+QPCLKr83VZ3OJpLcNuR01kl0az/fWssHSDg30nPpf 00B8GsRuCQ6rIbYZta8S2BZY+NDMMClZOT5xqmYfPPiJlRWPzdo87dmGU4S30B78gb+w 4IDA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr14-20020a170907720e00b007a2d966eeccsi3658473ejc.686.2022.11.03.19.24.40; Thu, 03 Nov 2022 19:25: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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbiKDCSJ (ORCPT + 99 others); Thu, 3 Nov 2022 22:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbiKDCSB (ORCPT ); Thu, 3 Nov 2022 22:18:01 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEC912B; Thu, 3 Nov 2022 19:18:00 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4N3PNy4WVRzlBwJ; Fri, 4 Nov 2022 10:15:46 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgB3D9RTdmRjDShNBQ--.16192S8; Fri, 04 Nov 2022 10:17:59 +0800 (CST) From: Yu Kuai To: hch@lst.de, tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2 4/5] blk-iocost: fix sleeping in atomic context warnning Date: Fri, 4 Nov 2022 10:39:37 +0800 Message-Id: <20221104023938.2346986-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221104023938.2346986-1-yukuai1@huaweicloud.com> References: <20221104023938.2346986-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgB3D9RTdmRjDShNBQ--.16192S8 X-Coremail-Antispam: 1UD129KBjvJXoWxCF4fWw15XFy5Gw45uF17KFg_yoW7Jr4kpF WYg39xt3y8trsrXw1DWrsFvr4rC34kKrWxJ3s3JFn3AF9rKrn2qF1kCryj9F48tFZ3ZrZx tr4Fq395AF4UArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkU UUUU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1748530577297749562?= X-GMAIL-MSGID: =?utf-8?q?1748530577297749562?= From: Yu Kuai match_u64() is called inside ioc->lock, which causes smatch static checker warnings: block/blk-iocost.c:3211 ioc_qos_write() warn: sleeping in atomic context block/blk-iocost.c:3240 ioc_qos_write() warn: sleeping in atomic context block/blk-iocost.c:3407 ioc_cost_model_write() warn: sleeping in atomic context Fix the problem by introducing a mutex and using it while prasing input params. Fixes: 2c0647988433 ("blk-iocost: don't release 'ioc->lock' while updating params") Reported-by: Dan Carpenter Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- block/blk-iocost.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 2bfecc511dd9..192ad4e0cfc6 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -404,6 +404,7 @@ struct ioc { bool enabled; + struct mutex params_mutex; struct ioc_params params; struct ioc_margins margins; u32 period_us; @@ -2212,6 +2213,8 @@ static void ioc_timer_fn(struct timer_list *timer) /* how were the latencies during the period? */ ioc_lat_stat(ioc, missed_ppm, &rq_wait_pct); + mutex_lock(&ioc->params_mutex); + /* take care of active iocgs */ spin_lock_irq(&ioc->lock); @@ -2222,6 +2225,7 @@ static void ioc_timer_fn(struct timer_list *timer) period_vtime = now.vnow - ioc->period_at_vtime; if (WARN_ON_ONCE(!period_vtime)) { spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); return; } @@ -2419,6 +2423,7 @@ static void ioc_timer_fn(struct timer_list *timer) } spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); } static u64 adjust_inuse_and_calc_cost(struct ioc_gq *iocg, u64 vtime, @@ -2801,9 +2806,11 @@ static void ioc_rqos_queue_depth_changed(struct rq_qos *rqos) { struct ioc *ioc = rqos_to_ioc(rqos); + mutex_lock(&ioc->params_mutex); spin_lock_irq(&ioc->lock); ioc_refresh_params(ioc, false); spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); } static void ioc_rqos_exit(struct rq_qos *rqos) @@ -2862,6 +2869,7 @@ static int blk_iocost_init(struct gendisk *disk) rqos->ops = &ioc_rqos_ops; rqos->q = q; + mutex_init(&ioc->params_mutex); spin_lock_init(&ioc->lock); timer_setup(&ioc->timer, ioc_timer_fn, 0); INIT_LIST_HEAD(&ioc->active_iocgs); @@ -2874,10 +2882,12 @@ static int blk_iocost_init(struct gendisk *disk) atomic64_set(&ioc->cur_period, 0); atomic_set(&ioc->hweight_gen, 0); + mutex_lock(&ioc->params_mutex); spin_lock_irq(&ioc->lock); ioc->autop_idx = AUTOP_INVALID; ioc_refresh_params(ioc, true); spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); /* * rqos must be added before activation to allow iocg_pd_init() to @@ -3197,7 +3207,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, blk_mq_freeze_queue(disk->queue); blk_mq_quiesce_queue(disk->queue); - spin_lock_irq(&ioc->lock); + mutex_lock(&ioc->params_mutex); memcpy(qos, ioc->params.qos, sizeof(qos)); enable = ioc->enabled; user = ioc->user_qos_params; @@ -3278,6 +3288,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, if (qos[QOS_MIN] > qos[QOS_MAX]) goto out_unlock; + spin_lock_irq(&ioc->lock); if (enable) { blk_stat_enable_accounting(disk->queue); blk_queue_flag_set(QUEUE_FLAG_RQ_ALLOC_TIME, disk->queue); @@ -3298,9 +3309,10 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, ioc_refresh_params(ioc, true); ret = nbytes; + spin_unlock_irq(&ioc->lock); out_unlock: - spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); blk_mq_unquiesce_queue(disk->queue); blk_mq_unfreeze_queue(disk->queue); @@ -3385,7 +3397,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, blk_mq_freeze_queue(q); blk_mq_quiesce_queue(q); - spin_lock_irq(&ioc->lock); + mutex_lock(&ioc->params_mutex); memcpy(u, ioc->params.i_lcoefs, sizeof(u)); user = ioc->user_cost_model; @@ -3431,6 +3443,7 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, user = true; } + spin_lock_irq(&ioc->lock); if (user) { memcpy(ioc->params.i_lcoefs, u, sizeof(u)); ioc->user_cost_model = true; @@ -3440,9 +3453,10 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, ioc_refresh_params(ioc, true); ret = nbytes; + spin_unlock_irq(&ioc->lock); out_unlock: - spin_unlock_irq(&ioc->lock); + mutex_unlock(&ioc->params_mutex); blk_mq_unquiesce_queue(q); blk_mq_unfreeze_queue(q); From patchwork Fri Nov 4 02:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 15287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp119882wru; Thu, 3 Nov 2022 19:23:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4JozL0vZissRElKK4DCq3oIYrqpsJREW80PAchCqHWbhOI+q14OlGUnL3e2qNcIvyWPNwY X-Received: by 2002:a05:6402:34c6:b0:462:a46a:a3b6 with SMTP id w6-20020a05640234c600b00462a46aa3b6mr33193938edc.164.1667528620461; Thu, 03 Nov 2022 19:23:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667528620; cv=none; d=google.com; s=arc-20160816; b=r+EqMQZ88EGg2dA48DRYow5oNIKS0tEfm8ji1n5O/t7oklAjduCsx+xTcMx921fFIF qdX7Dby4WFGG3+Bpj0SSMtNlJiDKxuNHOU5WBkX2+wiTNPHlZWmBR5HahYW9vSkFrtsY 4/CKvc97hvjmiA8AIU0l6THMvI5ncfvpjC4Uhze7LB7xQFjRpHIKvou9fMotoQLSeIZE WWJ0cOBrqGYUbY3P8lfsjy0eryLPPIJCyHhqGQz8PtUFl9SFgeUcr2irHLGDh5Uadrd4 xXzodz7qBeLuteXFMKOIX+fAXgvrg8nJtn4P5xbb9xNMVjS0c0OPaF030Em8JWfiiuWD 3ScQ== 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=4az2XGlcw+U7GtdL54MHn/sQv+/6M18dIvR3Xx4ufgU=; b=B0lOU0+9f6SLzcnCMUoI+YbLzo1ot+oyECboMCb0pzMdxN9/rLEZQptTizjv8g9n2Q CdNrAgCrcqcsiXhAl+F824hbF88zPtjbBgV9pb1NtldWl+S453r6bdBiH+FG4McXLv3t E8hHM3+FrzcykDvbebo1FpQa+ohuweZ449ken4W+j0kcoHXGEK9eVxzyspUaDygXyvot vm/n/RfCMeQP9rhB6xzcdufqq7nvbo4jxX7l4Yp45yAVCh5T39a3FrzyAyzFOM9m6kEs aislIUKdQsRQEoMGFl83gVS5hr0oNrDtgntMjjgLTbEmUAXgnkXrp+y0jHXZ9aqJSjPX 5xkQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz13-20020a170906cd0d00b0078db71898f2si2622513ejb.851.2022.11.03.19.23.17; Thu, 03 Nov 2022 19:23:40 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbiKDCSV (ORCPT + 99 others); Thu, 3 Nov 2022 22:18:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbiKDCSC (ORCPT ); Thu, 3 Nov 2022 22:18:02 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5455A5588; Thu, 3 Nov 2022 19:18:01 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4N3PNY5tBpz6T2Y5; Fri, 4 Nov 2022 10:15:25 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgB3D9RTdmRjDShNBQ--.16192S9; Fri, 04 Nov 2022 10:17:59 +0800 (CST) From: Yu Kuai To: hch@lst.de, tj@kernel.org, josef@toxicpanda.com, axboe@kernel.dk, yukuai3@huawei.com Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH v2 5/5] blk-iocost: read params inside lock in sysfs apis Date: Fri, 4 Nov 2022 10:39:38 +0800 Message-Id: <20221104023938.2346986-6-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221104023938.2346986-1-yukuai1@huaweicloud.com> References: <20221104023938.2346986-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgB3D9RTdmRjDShNBQ--.16192S9 X-Coremail-Antispam: 1UD129KBjvJXoW7Zr1kXFWktr13tF4kZFyDAwb_yoW8Wr4xpF Z0939rK3yFqr1xJF13tF4xXwn8C3yqgr4fXrsxuFyfAr9rZr1IqFsFkrW0kw48ZFWfC390 gFWagr4UCr45G37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOBTY UUUUU X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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?1748530490558183012?= X-GMAIL-MSGID: =?utf-8?q?1748530490558183012?= From: Yu Kuai Otherwise, user might get abnormal values if params is updated concurrently. Signed-off-by: Yu Kuai Reviewed-by: Christoph Hellwig Reviewed-by: Christoph Hellwig --- block/blk-iocost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 192ad4e0cfc6..7d682ce0bee6 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3135,6 +3135,7 @@ static u64 ioc_qos_prfill(struct seq_file *sf, struct blkg_policy_data *pd, if (!dname) return 0; + mutex_lock(&ioc->params_mutex); 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, @@ -3147,6 +3148,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); + mutex_unlock(&ioc->params_mutex); return 0; } @@ -3331,12 +3333,14 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf, if (!dname) return 0; + mutex_lock(&ioc->params_mutex); 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]); + mutex_unlock(&ioc->params_mutex); return 0; }