From patchwork Fri Oct 28 10:10:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12195 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp727473wru; Fri, 28 Oct 2022 02:51:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lwIWLMMkVRJXFBup/7zuSRA2jI9SuWZiilPqh5sOk7LK/wVEf8N1RHaiRsIs6TIDqykB5 X-Received: by 2002:a05:6402:2893:b0:461:59fd:9b4 with SMTP id eg19-20020a056402289300b0046159fd09b4mr33347032edb.389.1666950670709; Fri, 28 Oct 2022 02:51:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666950670; cv=none; d=google.com; s=arc-20160816; b=NuQrUW0ROzU/kAfUihK73c/j9+slpvTEfH12xoe2wQ1zj/AXLLUCLbi93Ay6ZAgrFC tuh8ExMaXikxjfHDZweb2e82awC0WTH+5b0iq5szHgol5PpVzgHpCi/gHEyGw4+2sw2t Wx6zkHP+EShCZtUzFNOnshuF4KBNpWxW296tnbM6fkhyveVBthiil7ypzTJTmCvTVyf0 huTOK15Rt0/77NjCPcu9GeTxR8UpaHJ6E1FmciaTs81krXpHILLBLw0VaNeoSU0kXexK j55unfQCAspkmObmKONcN6x6AtJOEkv7lFkBtbrYnrcNLRJft9czZWYsKWJkzQNZEUsL HM9w== 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=X1hpJ/LxUMIkiwGyWBHE9M+eXD0u0a+a4ayZsxZFy2Y=; b=JsDMNZSv8zq2kXu9QKxGRH5Ctaz0VMqz//g7tfe4IfGoCREdoZWf34Q1HWlvHgQqQm ddubWYXinR6IoynXX60O/1nF3ty5NLJTSZjJH9TxoLtd5cd4QrfvEwT0AmNaPbkH5gil jnA1LdbgSY2mWeB/KuR94o0G73zdPxeGiUXBjVULRDsH6ja5jZFLDKEneB2DTK9c2rBM livAVblqM7g+nkTsQ4evf4FOoIywpvinio4It6BW/nTbPukaESQ1HXf3O49BYH93XvnL h2DwSMMjflwKYtkgemwcevgJlQ2vn+BiF/IYX91bQEiRGLyMTq7CPtSaqY6KLjZmukX6 CoGw== 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 hv17-20020a17090760d100b0073d8e26e78bsi4077126ejc.960.2022.10.28.02.50.47; Fri, 28 Oct 2022 02:51:10 -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 S229950AbiJ1JtZ (ORCPT + 99 others); Fri, 28 Oct 2022 05:49:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiJ1JtJ (ORCPT ); Fri, 28 Oct 2022 05:49:09 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47A731C4ECC; Fri, 28 Oct 2022 02:49:08 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MzHkQ0kfwz6T8tN; Fri, 28 Oct 2022 17:46:38 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgCntOaQpVtjHAtNAQ--.59885S5; Fri, 28 Oct 2022 17:49:06 +0800 (CST) From: Yu Kuai To: 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 -next 1/5] blk-iocost: cleanup ioc_qos_write() and ioc_cost_model_write() Date: Fri, 28 Oct 2022 18:10:52 +0800 Message-Id: <20221028101056.1971715-2-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028101056.1971715-1-yukuai1@huaweicloud.com> References: <20221028101056.1971715-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCntOaQpVtjHAtNAQ--.59885S5 X-Coremail-Antispam: 1UD129KBjvJXoWxur1UJF4rJFy5uFy5ZF18Krg_yoWrCFW8pF WF93yaq3y8Ars7Wr42yF42ga4rCwsrWry7CFWkGr1fZrnFyrnFgF109FyUurW8JFZ3Jrs8 JFZFqrWDCayDA3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_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?1747924466306137166?= X-GMAIL-MSGID: =?utf-8?q?1747924466306137166?= 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 Oct 28 10:10:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12200 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp728211wru; Fri, 28 Oct 2022 02:53:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/byPzuD8os7JcAQWZu7ULhCmZmPqI3w0jvvGxgwP4piPT1caKWzdfubpSBamqcgdZEl+S X-Received: by 2002:a17:907:628a:b0:781:bbff:1d42 with SMTP id nd10-20020a170907628a00b00781bbff1d42mr45391570ejc.375.1666950822996; Fri, 28 Oct 2022 02:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666950822; cv=none; d=google.com; s=arc-20160816; b=kN/nzDKBLPro0jQVNxw/OcsfN0zMKi1gR/xqEAkZym/pxnzI/9SOEscto5wrBURSI7 sMJDF/0JzfOXLddySf3EiYmTPpAJVj4jTIVILq6rt7xe8jXmQ9NIEGkOT+ry/Cni4YQ4 nXDNSLHX+rbnSHpTIhV5YASnLsDcYvscWjvLdBiwKzuWllA7IRj4/G8uYFXKolLZOBNn eqHvQvjVWtsjWBy2B3EE2nVB5J9clFAKbsV3C4i0ffY2fK1vSaQyRlTxE5tiJmNpNakg R+DyYmNXKpPoBhluFt5Eod14pYQaPKKXEnwN/XWFEDrSMPLw4E3ZnRzLJocpDTAOqdgF JR5w== 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=ihdJ/llUiB3bzHetohKQ/nQefWXnFquQyyNmN08brdo=; b=tD8WkP7uPIWfOgvbxRbERHE1YcxN9iyFUDOyEWuDoXgwjoTFfdoYebGiq/VMegg2DP PLEaPqsbuhSuPoa0a7+l9a+AMw5jXXSLZ5/IWgpK66JSq8UgHm65KVmAkcHEbHr9FYnx cza4DJXsdyQ+dR/svPKfpgLtcBodfpQtx+XXIqPbIaVGTAmNYHNi5UJte0RjjDWCg0Ek uJ9+eqe1IiXhOt6GvpQIFrag6Ok9xjKOAQNVI0AIAqu802/7dTloOl7dRgIFTqOj4oo+ 8Ag0agiSUe+k5v1zbJUIZ1JKopfRu4+1QJLnQYeL29RCv2jjme1SDDMIk7HSpQzT+Iq2 PuoA== 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 he18-20020a1709073d9200b0078d93245e34si4437677ejc.793.2022.10.28.02.53.19; Fri, 28 Oct 2022 02:53: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 S230016AbiJ1Jtf (ORCPT + 99 others); Fri, 28 Oct 2022 05:49:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229842AbiJ1JtL (ORCPT ); Fri, 28 Oct 2022 05:49:11 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95861C4ED2; Fri, 28 Oct 2022 02:49:09 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MzHkq0khRzlFZG; Fri, 28 Oct 2022 17:46:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgCntOaQpVtjHAtNAQ--.59885S6; Fri, 28 Oct 2022 17:49:07 +0800 (CST) From: Yu Kuai To: 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 -next 2/5] blk-iocost: improve hanlder of match_u64() Date: Fri, 28 Oct 2022 18:10:53 +0800 Message-Id: <20221028101056.1971715-3-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028101056.1971715-1-yukuai1@huaweicloud.com> References: <20221028101056.1971715-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCntOaQpVtjHAtNAQ--.59885S6 X-Coremail-Antispam: 1UD129KBjvJXoW7Zry8Cw1rGw4kZrW5CF45KFg_yoW8Cry3pF Wa9rZIqFy5Jrs2gFnrCFnF9a43C392qryxGayDGa4fJr17Jr9FgFn5JryDJFy8JrWfGws0 gFnay3y8G3ZrCrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9m14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_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?1747924626536741938?= X-GMAIL-MSGID: =?utf-8?q?1747924626536741938?= 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 Oct 28 10:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12197 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp728003wru; Fri, 28 Oct 2022 02:52:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6E8t5u3exrXVyrZKthgz53GIQv0GHwM9zH39OcWEcYNEt5L4lUkUeKqs6jtD7x8fAwC533 X-Received: by 2002:a05:6402:5485:b0:459:147a:d902 with SMTP id fg5-20020a056402548500b00459147ad902mr51850938edb.263.1666950778081; Fri, 28 Oct 2022 02:52:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666950778; cv=none; d=google.com; s=arc-20160816; b=uTXwW9AH0hY+yjTvvYIZj7YWT+GbLPe0MbIp6YbZM4+Ttbu+PKj0r2KonAKwz0HZrW 95Sis1T2BDu89xPzE9e+k7qj4/9fFVTEnLXiexsHE/ja94FzIhc4stwWe/PrT9rqcbyR NHRz+yQodOpfx6hgU3W0GZB0nlXfG4i6gTcYkgReETVLDUkUi8lYWoq4SZLKDukZCriC 6a0kE72+xnN4JAcsuIFQnRNz+DMQtzMQn1h47CxrpjmuV8DiRZIEWU2Pd2SBW76uOrxg eBibP+Av9H361SS3Vu+RZwm750dblOVttfI0NBSc6Sxgrzx1iDJ2jjYw78o6XJcyIwFD MPSg== 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=TfKOV2wgkb9eIOZp8HhkDWDG+dxEABIs36jkn/lIIaM=; b=d4UZYNaWJ9q7sohEsjTCNXjzjR4ZF7lMmRWflBEJHh9EzPs+ku68m27gzKdqyxisF9 fLaXjX8hVCAwoRl/yssuNKcRYavhJ+0M2ZXvO+5v8FuJ7rgazj8aRxBkGEb7EtHBnJiS gIMEc9ta5+Z+cmuLsrOOQHtDmL2DBvT5YIYSa9CzX8bewRfWPlBiUVjvNjkREOa0kPqp pYb1FCbvOtjk+5xxP/pBy3+bFpODTRt/5PtyKF4vzn20wlOKLKQb0jporv6w24Uxmmp5 2Frl0nKNhIHRhM/Apiy7ma5Sr8T3jyjkvLLSrOGJx425hVIRrGE2OxPVburaojGznJgE S5PQ== 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 o15-20020a170906974f00b0078a9cbab78asi4799219ejy.738.2022.10.28.02.52.34; Fri, 28 Oct 2022 02:52:58 -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 S230118AbiJ1Jtm (ORCPT + 99 others); Fri, 28 Oct 2022 05:49:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229887AbiJ1JtM (ORCPT ); Fri, 28 Oct 2022 05:49:12 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A95DA1C4EFB; Fri, 28 Oct 2022 02:49:09 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4MzHkq3fxszlFZK; Fri, 28 Oct 2022 17:46:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgCntOaQpVtjHAtNAQ--.59885S7; Fri, 28 Oct 2022 17:49:07 +0800 (CST) From: Yu Kuai To: 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 -next 3/5] blk-iocost: don't allow to configure bio based device Date: Fri, 28 Oct 2022 18:10:54 +0800 Message-Id: <20221028101056.1971715-4-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028101056.1971715-1-yukuai1@huaweicloud.com> References: <20221028101056.1971715-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCntOaQpVtjHAtNAQ--.59885S7 X-Coremail-Antispam: 1UD129KBjvdXoWrKryxur13Zr1rAF1fWFWxWFg_yoWDZFg_Ca 4fW34qgFn5Gay8WF1jyF90qFWfGw4FqFWjvFW7tasxAFnIqas0yan3Zry8GF45uayj9a45 Ca93uwn5Zrs7WjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb-kFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWwA2048vs2IY02 0Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7MxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbJ73DUUUUU== 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?1747924579375919647?= X-GMAIL-MSGID: =?utf-8?q?1747924579375919647?= 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 Oct 28 10:10:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12196 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp727565wru; Fri, 28 Oct 2022 02:51:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/6VgBzrgGGPzQhakT+G/4lQWBDr9ldI75Vln3RiCxHwEfnE8EYJ0g5Xo+A8JKpDIvCBJc X-Received: by 2002:a05:6402:5419:b0:457:c955:a40f with SMTP id ev25-20020a056402541900b00457c955a40fmr48610710edb.391.1666950688305; Fri, 28 Oct 2022 02:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666950688; cv=none; d=google.com; s=arc-20160816; b=tYXYUqTey8pJUor49NrH/2O39rqIrQ6Bll45zk2O2WUPmOywpdwc4z+SefSdO2VRc+ mQNLONSiXBluBdrQVB9Uzn2UEqe3IDsVmE5LsCKC/C2imhVdUxKcXJeP74f9em7zHTTo jIOP+e9mrAd+a9KSRcq9NLD3AhbG3F+SDKiWTMYvlmxqaSZuIB/bDXF2lSpY4+jjzZtL f2KCOFy/zKztjYDX3z6NpPB003Eyuds6/P/mZ1Q9Uzdllc3BMW60DozgKfUgempRb2Un Eo8EHNIuSf4IMAMExytRG7owFeCJ/1G+GgTBWn/n7IUKJr5i7ngHZv/2K6r0x4Q2mGSu Embg== 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=MvroMvFjNQT8+ybNHDKAAeg786h8hDYO8jKjj7KLGMM=; b=iQrlhroOpQW/Sjf443E7xyueU0e9+oY82SGWwyCSle2lpki6ICCM5ldcG1sxUNMjgW ESNKYT+bUqz34NPqMWWVAOo53/NedLb8IInDLahR3+BQUk5upfWYJUIpyida3ZEENO+A IRFn3n5vUzUtYjKRWms1DemaU/yxfWP41qTqD2IKzm42LOlmBjXZVRe/oQ2RHNeQlWtr QlFtD0SUWeEvIbc74ENluAC5h+E9v792g3cvDOS9zdsnf3MpSVrlp40Ov9GMwnf7PD27 fR/yaiU3YRH6myniCsVy+LZQu3+KwGCpKCdJfgTHxbK7I9p2qTlplFyi1JV9UaoHel6X FCBQ== 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 h14-20020a50cdce000000b00461c7ad026csi3323531edj.61.2022.10.28.02.51.05; Fri, 28 Oct 2022 02:51:28 -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 S230055AbiJ1Jt3 (ORCPT + 99 others); Fri, 28 Oct 2022 05:49:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbiJ1JtL (ORCPT ); Fri, 28 Oct 2022 05:49:11 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62D041C4ED0; Fri, 28 Oct 2022 02:49:09 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MzHkR2BBHz6T8ty; Fri, 28 Oct 2022 17:46:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgCntOaQpVtjHAtNAQ--.59885S8; Fri, 28 Oct 2022 17:49:07 +0800 (CST) From: Yu Kuai To: 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 -next 4/5] blk-iocost: fix sleeping in atomic context warnning in ioc_qos_write() Date: Fri, 28 Oct 2022 18:10:55 +0800 Message-Id: <20221028101056.1971715-5-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028101056.1971715-1-yukuai1@huaweicloud.com> References: <20221028101056.1971715-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCntOaQpVtjHAtNAQ--.59885S8 X-Coremail-Antispam: 1UD129KBjvJXoW3Jry5Zw4xurWUuw1fAr17trb_yoWxXw4rpF 1F93sxt348Xrs3urWIqw4IvF13Cws7Wr1xCFWfGrySqr17trnYg3W8CryUCF48J393JFZx JFWDKF4DGrZ7CrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9C14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxK x2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI 0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUQSdkUUUUU= 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?1747924485272582935?= X-GMAIL-MSGID: =?utf-8?q?1747924485272582935?= 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 Fix the problem by prase params before holding the lock. Fixes: 2c0647988433 ("blk-iocost: don't release 'ioc->lock' while updating params") Reported-by: Dan Carpenter Signed-off-by: Yu Kuai --- block/blk-iocost.c | 172 +++++++++++++++++++++++++++++---------------- 1 file changed, 111 insertions(+), 61 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 2bfecc511dd9..27b41f3f1b07 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3165,44 +3165,25 @@ static const match_table_t qos_tokens = { { NR_QOS_PARAMS, NULL }, }; -static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, - size_t nbytes, loff_t off) -{ - struct block_device *bdev; - struct gendisk *disk; - struct ioc *ioc; +struct ioc_qos_params { u32 qos[NR_QOS_PARAMS]; - bool enable, user; - char *p; - int ret; - - bdev = blkcg_conf_open_bdev(&input); - if (IS_ERR(bdev)) - 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); - if (ret) - goto out; - ioc = q_to_ioc(disk->queue); - } + bool enable; + bool user; + bool set_qos[NR_QOS_PARAMS]; + bool set_enable; + bool set_user; +}; - blk_mq_freeze_queue(disk->queue); - blk_mq_quiesce_queue(disk->queue); +static struct ioc_qos_params *ioc_qos_parse_params(char *input) +{ + struct ioc_qos_params *params; + char *p; + int ret = -EINVAL; - spin_lock_irq(&ioc->lock); - memcpy(qos, ioc->params.qos, sizeof(qos)); - enable = ioc->enabled; - user = ioc->user_qos_params; + params = kzalloc(sizeof(*params), GFP_KERNEL); + if (!params) + return ERR_PTR(-ENOMEM); - ret = -EINVAL; while ((p = strsep(&input, " \t\n"))) { substring_t args[MAX_OPT_ARGS]; char buf[32]; @@ -3218,19 +3199,21 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, err = match_u64(&args[0], &v); if (err) { ret = err; - goto out_unlock; + goto out_err; } - enable = v; + params->enable = v; + params->set_enable = true; continue; case QOS_CTRL: match_strlcpy(buf, &args[0], sizeof(buf)); if (!strcmp(buf, "auto")) - user = false; + params->user = false; else if (!strcmp(buf, "user")) - user = true; + params->user = true; else - goto out_unlock; + goto out_err; + params->set_user = true; continue; } @@ -3240,62 +3223,128 @@ 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 out_unlock; + goto out_err; if (cgroup_parse_float(buf, 2, &v)) - goto out_unlock; + goto out_err; if (v < 0 || v > 10000) - goto out_unlock; - qos[tok] = v * 100; + goto out_err; + params->qos[tok] = v * 100; break; case QOS_RLAT: case QOS_WLAT: err = match_u64(&args[0], &v); if (err) { ret = err; - goto out_unlock; + goto out_err; } - qos[tok] = v; + params->qos[tok] = v; break; case QOS_MIN: case QOS_MAX: if (match_strlcpy(buf, &args[0], sizeof(buf)) >= sizeof(buf)) - goto out_unlock; + goto out_err; if (cgroup_parse_float(buf, 2, &v)) - goto out_unlock; + goto out_err; if (v < 0) - goto out_unlock; - qos[tok] = clamp_t(s64, v * 100, + goto out_err; + params->qos[tok] = clamp_t(s64, v * 100, VRATE_MIN_PPM, VRATE_MAX_PPM); break; default: - goto out_unlock; + goto out_err; } - user = true; + params->user = true; + params->set_user = true; + params->set_qos[tok] = true; } - if (qos[QOS_MIN] > qos[QOS_MAX]) - goto out_unlock; + return params; + +out_err: + kfree(params); + return ERR_PTR(ret); +} + +static int ioc_qos_update_params(struct request_queue *q, struct ioc *ioc, + struct ioc_qos_params *params) +{ + int i; - if (enable) { - blk_stat_enable_accounting(disk->queue); - blk_queue_flag_set(QUEUE_FLAG_RQ_ALLOC_TIME, disk->queue); + for (i = 0; i < NR_QOS_PARAMS; ++i) + if (!params->set_qos[i]) + params->qos[i] = ioc->params.qos[i]; + if (params->qos[QOS_MIN] > params->qos[QOS_MAX]) + return -EINVAL; + + if (!params->set_enable) + params->enable = ioc->enabled; + if (params->enable) { + blk_stat_enable_accounting(q); + blk_queue_flag_set(QUEUE_FLAG_RQ_ALLOC_TIME, q); ioc->enabled = true; - wbt_disable_default(disk->queue); + wbt_disable_default(q); } else { - blk_queue_flag_clear(QUEUE_FLAG_RQ_ALLOC_TIME, disk->queue); + blk_queue_flag_clear(QUEUE_FLAG_RQ_ALLOC_TIME, q); ioc->enabled = false; - wbt_enable_default(disk->queue); + wbt_enable_default(q); } - if (user) { - memcpy(ioc->params.qos, qos, sizeof(qos)); + if (!params->set_user) + params->user = ioc->user_qos_params; + if (params->user) { + memcpy(ioc->params.qos, params->qos, sizeof(params->qos)); ioc->user_qos_params = true; } else { ioc->user_qos_params = false; } + return 0; +} + +static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, + size_t nbytes, loff_t off) +{ + struct block_device *bdev; + struct gendisk *disk; + struct ioc *ioc; + struct ioc_qos_params *params; + int ret; + + bdev = blkcg_conf_open_bdev(&input); + if (IS_ERR(bdev)) + 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); + if (ret) + goto out; + ioc = q_to_ioc(disk->queue); + } + + params = ioc_qos_parse_params(input); + if (IS_ERR(params)) { + ret = PTR_ERR(params); + goto out; + } + + blk_mq_freeze_queue(disk->queue); + blk_mq_quiesce_queue(disk->queue); + + spin_lock_irq(&ioc->lock); + + ret = ioc_qos_update_params(disk->queue, ioc, params); + if (ret) + goto out_unlock; + ioc_refresh_params(ioc, true); ret = nbytes; @@ -3303,6 +3352,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input, spin_unlock_irq(&ioc->lock); blk_mq_unquiesce_queue(disk->queue); blk_mq_unfreeze_queue(disk->queue); + kfree(params); out: blkdev_put_no_open(bdev); From patchwork Fri Oct 28 10:10:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai X-Patchwork-Id: 12198 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp728093wru; Fri, 28 Oct 2022 02:53:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM71vepvT5Zy7tTIL3izbJycFLxDXLDGbslrURR7KUiUlovbJodb62/yvqwg4GgZ+3NXbAQR X-Received: by 2002:a17:906:8a63:b0:7ad:95cf:726a with SMTP id hy3-20020a1709068a6300b007ad95cf726amr4893400ejc.82.1666950796674; Fri, 28 Oct 2022 02:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666950796; cv=none; d=google.com; s=arc-20160816; b=E6w5ASdR9p+5132jW5t7jzP4B9O84lJ4Kmvw028C3gpN/sWOfPEpbB/WOOhOm4Olfp S5vtCBaUQsG2Hu6oA2IkTM3AbypmT5U3u9TkWHAy/qAcMCEpvLVUEndMZLyxI7TYmYVJ yamRq6lf91C5Q7EQW0R8vMkpMcd5/Fjalx6ttVSjs+rA1epQ7j9tE7U9vs1pOeVgZ1+8 u0oVkhSXiJ9Lfm1dhHw0vBwiPxeEJwOHLoX+yMoUe+QwRR5wysy1Bo+rGzcMM6cXtnbX 1VfGTxME5UBJR2eSkiNDQorZl8oCFvpgkTjqT4p1D6/YNxreDhGSyZw5r/jbOYkJWIKz nieQ== 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=TbrGEiu+ggC75n/IDa8HnLWTtk9G2pjXV8Li9UjaESU=; b=nOkcARjCPBWExzfsX1khoKVLCa55Oq+179jrAkQlrVFDwU2nBJsBja8q+W7skbYa3w hY+sw3SLdKKadVMEGbxr2G1MY2E1r+woQIFQr42ZXGOvFlUb1HipBeC6KyBucMkEibOb xm3XagryL7Kg6FWtp0L+XPwKe4Ik05pfmRleqbY0KGOtOuoOYeAnoddEFcY0DGOtjS6n RqD8A+U0BykxHjIo6YckCDSiPxxwp7rwxlsSbp7eBth9bK/Q+HwWfka91qaqwRVf9+VV kUTEp7rvkZTAgt3TEvBPUfs3jyWdkWcOQmvPFw2KuOGeBKy/8PueVfrFGxkoO4ElNYw4 i7+g== 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 dm4-20020a05640222c400b00459b0141076si170968edb.465.2022.10.28.02.52.53; Fri, 28 Oct 2022 02:53:16 -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 S230048AbiJ1Jtr (ORCPT + 99 others); Fri, 28 Oct 2022 05:49:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229868AbiJ1JtM (ORCPT ); Fri, 28 Oct 2022 05:49:12 -0400 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D2B1C6BD7; Fri, 28 Oct 2022 02:49:09 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4MzHkR5J8Yz6T8sr; Fri, 28 Oct 2022 17:46:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgCntOaQpVtjHAtNAQ--.59885S9; Fri, 28 Oct 2022 17:49:08 +0800 (CST) From: Yu Kuai To: 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 -next 5/5] blk-iocost: fix sleeping in atomic context warnning in ioc_cost_model_write() Date: Fri, 28 Oct 2022 18:10:56 +0800 Message-Id: <20221028101056.1971715-6-yukuai1@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221028101056.1971715-1-yukuai1@huaweicloud.com> References: <20221028101056.1971715-1-yukuai1@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: gCh0CgCntOaQpVtjHAtNAQ--.59885S9 X-Coremail-Antispam: 1UD129KBjvJXoWxCF4fWw18Zr4fCFWDZF1kZrb_yoWrZrW7pF Wfu3sxt3y0qrs3CFWIq3yIqF1fuwn7Ww47Gay3Grn3tr17Kr109F18uryjkFW8J3yrJFWY qF98tr4UWrW7CFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCF04k20xvY0x0EwIxGrw CFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE 14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2 IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UMIIF0xvE42xK8VAv wI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUOBTYUUUUU 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?1747924598598454238?= X-GMAIL-MSGID: =?utf-8?q?1747924598598454238?= From: Yu Kuai match_u64() is called inside ioc->lock, which causes smatch static checker warnings: block/blk-iocost.c:3407 ioc_cost_model_write() warn: sleeping in atomic context Fix the problem by prase params before holding the lock. Fixes: 2c0647988433 ("blk-iocost: don't release 'ioc->lock' while updating params") Reported-by: Dan Carpenter Signed-off-by: Yu Kuai --- block/blk-iocost.c | 128 +++++++++++++++++++++++++++++---------------- 1 file changed, 84 insertions(+), 44 deletions(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 27b41f3f1b07..62e18c2719cb 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -3403,43 +3403,23 @@ static const match_table_t i_lcoef_tokens = { { NR_I_LCOEFS, NULL }, }; -static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, - size_t nbytes, loff_t off) -{ - struct block_device *bdev; - struct request_queue *q; - struct ioc *ioc; +struct ioc_model_params { u64 u[NR_I_LCOEFS]; bool user; - char *p; - int ret; - - bdev = blkcg_conf_open_bdev(&input); - if (IS_ERR(bdev)) - 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); - if (ret) - goto out; - ioc = q_to_ioc(q); - } + bool set_u[NR_I_LCOEFS]; + bool set_user; +}; - blk_mq_freeze_queue(q); - blk_mq_quiesce_queue(q); +static struct ioc_model_params *ioc_model_parse_params(char *input) +{ + struct ioc_model_params *params; + char *p; + int ret = -EINVAL; - spin_lock_irq(&ioc->lock); - memcpy(u, ioc->params.i_lcoefs, sizeof(u)); - user = ioc->user_cost_model; + params = kzalloc(sizeof(*params), GFP_KERNEL); + if (!params) + return ERR_PTR(-ENOMEM); - ret = -EINVAL; while ((p = strsep(&input, " \t\n"))) { substring_t args[MAX_OPT_ARGS]; char buf[32]; @@ -3454,48 +3434,108 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, case COST_CTRL: match_strlcpy(buf, &args[0], sizeof(buf)); if (!strcmp(buf, "auto")) - user = false; + params->user = false; else if (!strcmp(buf, "user")) - user = true; + params->user = true; else - goto out_unlock; + goto err; + params->set_user = true; continue; case COST_MODEL: match_strlcpy(buf, &args[0], sizeof(buf)); if (strcmp(buf, "linear")) - goto out_unlock; + goto err; continue; } tok = match_token(p, i_lcoef_tokens, args); if (tok == NR_I_LCOEFS) - goto out_unlock; + goto err; err = match_u64(&args[0], &v); if (err) { ret = err; - goto out_unlock; + goto err; } - u[tok] = v; - user = true; + params->u[tok] = v; + params->set_u[tok] = true; + params->user = true; + params->set_user = true; } - if (user) { - memcpy(ioc->params.i_lcoefs, u, sizeof(u)); + return params; + +err: + kfree(params); + return ERR_PTR(ret); +} + +static void ioc_model_update_params(struct ioc *ioc, + struct ioc_model_params *params) +{ + int i; + + if (!params->set_user) + params->user = ioc->user_cost_model; + if (params->user) { + for (i = 0; i < NR_I_LCOEFS; ++i) + if (params->set_u[i]) + ioc->params.i_lcoefs[i] = params->u[i]; ioc->user_cost_model = true; } else { ioc->user_cost_model = false; } +} + +static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, + size_t nbytes, loff_t off) +{ + struct block_device *bdev; + struct request_queue *q; + struct ioc *ioc; + struct ioc_model_params *params; + int ret; + + bdev = blkcg_conf_open_bdev(&input); + if (IS_ERR(bdev)) + 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); + if (ret) + goto out; + ioc = q_to_ioc(q); + } + + params = ioc_model_parse_params(input); + if (IS_ERR(params)) { + ret = PTR_ERR(params); + goto out; + } + + blk_mq_freeze_queue(q); + blk_mq_quiesce_queue(q); + + spin_lock_irq(&ioc->lock); + + ioc_model_update_params(ioc, params); ioc_refresh_params(ioc, true); - ret = nbytes; -out_unlock: spin_unlock_irq(&ioc->lock); + blk_mq_unquiesce_queue(q); blk_mq_unfreeze_queue(q); + kfree(params); + ret = nbytes; out: blkdev_put_no_open(bdev); return ret;