From patchwork Mon Nov 28 15:44:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5748775wrr; Mon, 28 Nov 2022 07:26:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4P9EvvPZQv/vdW1q42FosW55/VNOoi0ODrXHGSr12IxlZ5Q74E1rjd641GKehRQ/6mfAo8 X-Received: by 2002:a17:906:3e41:b0:78d:bc9f:33da with SMTP id t1-20020a1709063e4100b0078dbc9f33damr42955958eji.80.1669649171056; Mon, 28 Nov 2022 07:26:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649171; cv=none; d=google.com; s=arc-20160816; b=mRNFKe6xCUZV0Q3WGmxX3N6v+12LCA7bl/IIuEE61Y+8D3UJgQppiXYltknrAyQ91J h+LqNwSyFSGAIWEybFhPPA8RyaLgETUjQKlkD954nN/Z26IXsSzLqYnOLnOjHB1kNO+7 iB+sMSjed4Y8pwZZeThy6usfuTePmvT01TtrXCLv4afaVenIWbKCm7MBp2kl83Q5+smg FoncIK+CwSYnSFe2qnvtC8ioJFPR+iueqwbL1M4Yy3iElt6ZMFRh2735+EFmAp7XISH3 UvurfOIOi/pJrQxuJwHARdwb5Gmnz8IGpaVaoaTvMNl+0i8Am7AjS/ZI/CpSOiBFkk8A AqCw== 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=DlYnLMfRxKwxQBif0aUUXa3+0UXsR2omfMrCm8bB51I=; b=sWbYFgmiNj1+o8vN78mQsSfzrylTUjygqwJZtsXGIfoxl9mwaqj+gV6YGY2e/pNkY5 74doc9nr1MtlVsyLtDMGK10Ondk/zPl5wItb4Tgc//wJScyRrmPsC8ftQ4PmEjdltlMu 5Lns12agpKDUpD2c4F6jJ1HfU4gbQMe7ZGxCZqF3Su27+dnkK5VlDLkA4Bl2v75NYbvW 1e6iItynVAYjgCccC0AgNPBQ2Cn2mXXThLEs8uszLOiWHdpj37bQSHQbg0cRHjx0V3Hc Tb3tIU9dTCL3MbskrU7Nts4GqKBwjVeoVULFxcKvPorkm50vOSefTD7oFvLWf/xvMyRa IL8A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz44-20020a1709077dac00b007becf776d7esi3855489ejc.462.2022.11.28.07.25.45; Mon, 28 Nov 2022 07:26:11 -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 S231708AbiK1PXg (ORCPT + 99 others); Mon, 28 Nov 2022 10:23:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbiK1PXa (ORCPT ); Mon, 28 Nov 2022 10:23:30 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C590E59; Mon, 28 Nov 2022 07:23:29 -0800 (PST) Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLTk10FWLzmW6v; Mon, 28 Nov 2022 23:22:49 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500020.china.huawei.com (7.185.36.88) 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:27 +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:26 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 1/8] blk-iocost: cleanup ioc_qos_write() and ioc_cost_model_write() Date: Mon, 28 Nov 2022 23:44:27 +0800 Message-ID: <20221128154434.4177442-2-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754049368024173?= X-GMAIL-MSGID: =?utf-8?q?1750754049368024173?= 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 Signed-off-by: Li Nan --- 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 Mon Nov 28 15:44:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5749951wrr; Mon, 28 Nov 2022 07:27:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5s/2wfdciK5kMTDJwGFDY2LjbVj+xx7RJHq5KEiKGy6cpAapXcxxSNgcEa9cx0V5WTvELW X-Received: by 2002:a17:906:c283:b0:7ae:2277:9fec with SMTP id r3-20020a170906c28300b007ae22779fecmr42676303ejz.623.1669649269671; Mon, 28 Nov 2022 07:27:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649269; cv=none; d=google.com; s=arc-20160816; b=pIH5bAGfiNZQJNatDkOLwxGlJoDHZ9p1v56it4VyDdldBj54XdTVy/nAt6ELX0ir1v l/+FrnuOP3aSLuvGdla3VpqheNJ2FiwlDOQ9OMzdwtEl2mlss8QcnxW3GjU+vRniOMtu 9r+Jjx0IVTnwXD/dFnFWQO0ANqKtPS5NXXuLr4Vdyn/byfnEKx1srwFOGFGEjIt9R2EX ezQ2rEEY2cTIlhuvntXHdnyT5escFrOWHQhoEyfN60SOjmbbJWtWv3s+BbOwrShDPfyP DZ26Ndm1ftY/LP3RQgOFdH4IwWLZSVW8nNz+PuAuDc2BN7K0iyf1B+SkVjRNbkd4Vgbt S3Xw== 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=Q8yLqyqzOfGtkIz83RYljVFXFg81+m8W3dZLdJayQB0=; b=E8XTF6Tsf+Qvyx/fCROwx7Wnh6UtI1T2wLI0hX3ugsmqtz8wZU3qY6U1EtPGI3LzxO 9Dh5ICubmcwdBcNXXUAHd3Z3gtRPQH+UPloD3ob8pBCHpIcyYq+L6923gVsrbfrdQWef h0Ov3qY+jdHikx2AAVAbznDOKurF5/81bnSEV17h3pfL/TwOPeGIUjGVqvX5I4apGJVn dQJq5Ur1pJnsX5znHyPXzQGOXXZiNRN3F/jepV2S6/kb2GkgT8ERUQsll9K6K9emASYZ xJpelKG8xYP5T5PLwh5l2uc1rLX3n75L3MgRu9uJjY1LtEneZySpBCsiXn30049BtyYH f4sw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv11-20020a17090760cb00b0073dda1430b9si10280973ejc.403.2022.11.28.07.27.16; Mon, 28 Nov 2022 07:27:49 -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 S231246AbiK1PXl (ORCPT + 99 others); Mon, 28 Nov 2022 10:23:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231216AbiK1PXa (ORCPT ); Mon, 28 Nov 2022 10:23:30 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5E8525EA; Mon, 28 Nov 2022 07:23:29 -0800 (PST) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NLTk223r5z15MtB; Mon, 28 Nov 2022 23:22:50 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500022.china.huawei.com (7.185.36.66) 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:27 +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:27 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 2/8] blk-iocost: improve hanlder of match_u64() Date: Mon, 28 Nov 2022 23:44:28 +0800 Message-ID: <20221128154434.4177442-3-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754152236274328?= X-GMAIL-MSGID: =?utf-8?q?1750754152236274328?= 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 Signed-off-by: Li Nan --- 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 Mon Nov 28 15:44:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26825 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5750220wrr; Mon, 28 Nov 2022 07:28:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf44PsjrzFmma1221lHqlLcGyn8yc8OgP/ZnKpinMdkJIWIjZB7N8/NIONk6U963DoysiQLq X-Received: by 2002:a17:906:2c51:b0:7b2:8c66:9bda with SMTP id f17-20020a1709062c5100b007b28c669bdamr2636933ejh.732.1669649291246; Mon, 28 Nov 2022 07:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649291; cv=none; d=google.com; s=arc-20160816; b=VMQ2rE4h57yHy+HI2pfvHehuVFdTbYYp6Z4NvG3zTxY04L5kWyU9z/kwr6FWGK58pI L58B6ybQnHCHzu+BTZNFjHoVmlwoZ7EqOsSkYD4YcKZ0wf6nDzjdRow6SjnXpwy9PBb5 wfgTWZU45OGvDeQRloROBmbE70KfnKRq6tzNYu4rJdr0o7+CRds8ZrM5hHxJT33Z7BNt bYh5DhNEmtIetdrvesJC89CHOBvF9kFSzKZhGafn0+junED1uv3Yoc/rBy/6mzhWwyg2 81NU3w0pTzkkEQoAKF/+i+S8AFsWGjztdQN0GzxrwqWoZg+JsmMNl/nWjxNsxvFHWmDT 0DxA== 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=Npf3kO5j+EBCYK1BXyvBfU//cZc97bL1ktTKSm5ysKg=; b=MRCzNE45t1lHOthEajaa8u3Fyk6jeLAbR2gQjPfqF4MJUj0sRNOs8vL0BPGnpZvBTa nXWG87LCrsSuvqFXhiNYvm01XUI2YoXSOr1pLeR4bJDOuF+zrSeGFIKSElgmPbT+VPjn W2Ael633mU3pTUNwybvSMFX1ihNfSyhZ0TbK1e8jC2MsKEfBB7EHjhzCyuECKbYwPzDm Zt5Qo7gaVZpUyXWIwknNOTgHRaTreHprXFnKUFgUZcjS60hUtzvMW1svYjBVnhSH7zeO EFJu491Dn8GoA3CzJHMvTmaTNtaxkTdpF1csCuiL7TZgyQdTEkZtDjVVE0AvD9KwZbHl l7WQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ib20-20020a1709072c7400b0079330b37fb6si7953920ejc.880.2022.11.28.07.27.44; Mon, 28 Nov 2022 07:28:11 -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 S231756AbiK1PXq (ORCPT + 99 others); Mon, 28 Nov 2022 10:23:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231468AbiK1PXc (ORCPT ); Mon, 28 Nov 2022 10:23:32 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 996A025EA; Mon, 28 Nov 2022 07:23:31 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NLTft5ZFgzJnwS; Mon, 28 Nov 2022 23:20:06 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500021.china.huawei.com (7.185.36.21) 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:27 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 3/8] blk-iocost: don't allow to configure bio based device Date: Mon, 28 Nov 2022 23:44:29 +0800 Message-ID: <20221128154434.4177442-4-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754175061193606?= X-GMAIL-MSGID: =?utf-8?q?1750754175061193606?= 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 Signed-off-by: Li Nan --- 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 Mon Nov 28 15:44:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5750224wrr; Mon, 28 Nov 2022 07:28:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf4YhuXNr89w4TI6VdteepuX4SmolDdKUiY0cHDIQ8HkgNeHtA06Ug75zglokJgZgtAcTgH7 X-Received: by 2002:a17:906:f189:b0:7ae:3fa3:d7c6 with SMTP id gs9-20020a170906f18900b007ae3fa3d7c6mr41717438ejb.494.1669649291426; Mon, 28 Nov 2022 07:28:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649291; cv=none; d=google.com; s=arc-20160816; b=An3oqIgKAA5EcipIqbs2FuXuzedoNl3tkn+DdZ9erJnym2TaNbr8bqD7E3y6tF7YRp WlJKg51oEGqn2mIfEpDy5INDb8VG4r0gxLQ97Rc/hhP6EO/sQ5bZS5WNNAGcXEurVwYW u92wlrg9abgmjIDQXwm0/iVtuHo0m9xEv5RRdTBJ+Cn65JbWhwWMj7X/0+YdFvscg1Q2 oYVv+9pUomZoxQ4gZqHYjqMhWOtMjODx69NhfLVpR3S90ZoQaySezPguZT90JAwXLoq8 hLDRrEjsv/hlOfqCBYL4cjEwuV2NDbu8zriyV3nIa2fK4Ao/JiLGcXPLYF2NII35l6Qk OuPA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i17-20020a1709064fd100b007ae814af6aasi11824858ejw.87.2022.11.28.07.27.42; Mon, 28 Nov 2022 07:28:11 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754175356008043?= X-GMAIL-MSGID: =?utf-8?q?1750754175356008043?= 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; } From patchwork Mon Nov 28 15:44:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26828 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5750396wrr; Mon, 28 Nov 2022 07:28:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf51i2tHcA1D54od8+S77fJqEVKmcXC0aemutUR70v+dklOz+/oKxhuUvr3dkP13Iy+gQpt0 X-Received: by 2002:a17:906:d297:b0:7b8:4c22:2d6c with SMTP id ay23-20020a170906d29700b007b84c222d6cmr28093568ejb.144.1669649304394; Mon, 28 Nov 2022 07:28:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649304; cv=none; d=google.com; s=arc-20160816; b=bWJH17foKm9NKk61DDUlFsCcirAtY7rMsqzyw325c2BWJqbIgR2+UBw27gs3aiepd2 K/ZeiJvFCVt5aDb6qlVwcV2oJa8OYQlyDPMgCzkj7UzRLsm1A6DX8ScrrXNsBO4fScYo U7zv+HSnlasQ25Hriit9fOJ8l1B6aQYCrPOdCl70L6fG4tchj/q6+Yaq4pZm3mpH91HP vdhHhqGmDELakjfi4Q+FCkoDIaeNuy7AxzPvGfjRD/ZB3c6OvLVUoNdjA+NUWOLYLUF4 cSF5cmpXRxCG8pCpJvAtC6JHLpC+DagunQeDrp2Gyg5ZNdDIyP3Xe3Jmp7YgRL8klwED Goqg== 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=f0UE8ya8e8ehbY2S1WePqiFvpP2bx/jiYReJUs8S0d4=; b=cfVBuiUjpfQCBJTXuCJrk7gGaWcP/rKGNINWfrVXVTDC1qR35ETb166IEZ9eP/5org YBeJ8bCL4AUYdhHTOnkjyyepME8VtyP7uhbq40skPkmFyKU5W6UdbCTeGLZM5AHmuyA8 QPL1eZs6LBryuwJ1iENxJpbnssJzwCUI77C2+iTAXfOgCBu2Y73yKRYTtVC1MLwxJx2E GMBgoyizPED4xUdAoV41Wk08Z55DbowOGensbcfdOIFw0cQTiNOQ401o2xxbVUaIShgD eHEIElDCQpJh8syxltRRL+7cdDkHLIjl75HaLlG7htolvHdOYutpkSR8xilYQrZLoVXa MzqA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z5-20020a05640240c500b00468310367c5si11812031edb.214.2022.11.28.07.27.57; Mon, 28 Nov 2022 07:28:24 -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 S231941AbiK1PX5 (ORCPT + 99 others); Mon, 28 Nov 2022 10:23:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231461AbiK1PXc (ORCPT ); Mon, 28 Nov 2022 10:23:32 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C24DF5; Mon, 28 Nov 2022 07:23:31 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLTk27433zmW82; Mon, 28 Nov 2022 23:22:50 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500023.china.huawei.com (7.185.36.114) 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:29 +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 5/8] blk-iocost: fix divide by 0 error in calc_lcoefs() Date: Mon, 28 Nov 2022 23:44:31 +0800 Message-ID: <20221128154434.4177442-6-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754188998744837?= X-GMAIL-MSGID: =?utf-8?q?1750754188998744837?= echo max of u64 to cost.model can cause divide by 0 error. # echo 8:0 rbps=18446744073709551615 > /sys/fs/cgroup/io.cost.model divide error: 0000 [#1] PREEMPT SMP RIP: 0010:calc_lcoefs+0x4c/0xc0 Call Trace: ioc_refresh_params+0x2b3/0x4f0 ioc_cost_model_write+0x3cb/0x4c0 ? _copy_from_iter+0x6d/0x6c0 ? kernfs_fop_write_iter+0xfc/0x270 cgroup_file_write+0xa0/0x200 kernfs_fop_write_iter+0x17d/0x270 vfs_write+0x414/0x620 ksys_write+0x73/0x160 __x64_sys_write+0x1e/0x30 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd calc_lcoefs() uses the input value of cost.model in DIV_ROUND_UP_ULL, overflow would happen if bps plus IOC_PAGE_SIZE is greater than ULLONG_MAX, it can cause divide by 0 error.I_LCOEF_MAX is introduced to prevent it. Signed-off-by: Li Nan --- block/blk-iocost.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index a645184aba4a..a4fa17ebb2fa 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -306,6 +306,9 @@ enum { IOC_PAGE_SIZE = 1 << IOC_PAGE_SHIFT, IOC_SECT_TO_PAGE_SHIFT = IOC_PAGE_SHIFT - SECTOR_SHIFT, + /* avoid overflow */ + I_LCOEF_MAX = ULLONG_MAX - IOC_PAGE_SIZE, + /* if apart further than 16M, consider randio for linear model */ LCOEF_RANDIO_PAGES = 4096, }; @@ -3431,6 +3434,8 @@ static ssize_t ioc_cost_model_write(struct kernfs_open_file *of, char *input, goto out_unlock; } + if (v > I_LCOEF_MAX) + goto out_unlock; u[tok] = v; user = true; } From patchwork Mon Nov 28 15:44:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5748873wrr; Mon, 28 Nov 2022 07:26:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7iUbc1lUkd3q7bAUGBCcxMUkEWCrt11lRERMtcthPdF+rra41ma5p+E1KLf3wf5g7VY2Gl X-Received: by 2002:a17:906:99cb:b0:7bb:7dda:7d3c with SMTP id s11-20020a17090699cb00b007bb7dda7d3cmr18594049ejn.182.1669649178915; Mon, 28 Nov 2022 07:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649178; cv=none; d=google.com; s=arc-20160816; b=KVsFYAb7fdhHY44qsVIAlXTqdeutgRnwoHkevXDncyj8/EynYrvinX+NZqt3ItfLbg /CMXo2w6hbeu+o3E+ErU4Ohqt+ZQumRvxJfaq8vX9PW3ycwQqjoZToY/hbUbR+eigshp SnnIPdlLCl/jDEpMuNL4grDaIMP0xF0jFxpxD7fWdAAoqQE49CKAqCSFWL1qjruLp8kj 4aauaKy3eAi80bF0+3SnVGlGlKirhMDb2K0bPBQf0czSjkuUcr5P9J9C1AyljMmXQ9ZJ wO03lqVWqBqYJnBPOlWaSzgQHKWsdBoZLDCYp1bo0zca+nJcz/OW0LjWiga6WQfA81e6 DbqQ== 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=WN1SHVCvMATqQJTDI3M8RzmIRukUZ6cM6N64GeMM1zo=; b=yhEEUSFcNdOHX2ekYA5gQERH/wuWm+jVffSAtn5+LJUH4ekXO/PKNery3zHIW/QJR4 UkFKcqC5v+1QPoukQhZ2XSqVTslQQEW2kUEoCi5DGK0RYaOz31cRekJ35p8bz/kDJdi0 ACWP8F1+O6/IK4RX+Zyy8zTYVTTLsiU/XRLj0IAwgsOorY7q0EKQeB3BkA9P2X4zA5+Z t01wc0XzYlud3J4LOI8FXSXsjduVE4h3RI1QW1WyHDAJdqxqbSwbUAD4ETCeKq6ej2hj V84GZgoA8fUtpgTeHYnDkaQgDFjY9PjnWhZldtaVK4TSjs+3hPEaKRqePjSPENwgdDXq ACig== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a1709065d0300b007878c9d73a2si11281171ejt.426.2022.11.28.07.25.55; Mon, 28 Nov 2022 07:26:18 -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 S231984AbiK1PYH (ORCPT + 99 others); Mon, 28 Nov 2022 10:24:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbiK1PXe (ORCPT ); Mon, 28 Nov 2022 10:23:34 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C38B325EA; Mon, 28 Nov 2022 07:23:33 -0800 (PST) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLTf902d3zqSkM; Mon, 28 Nov 2022 23:19:29 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500026.china.huawei.com (7.185.36.106) 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:29 +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:29 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 6/8] blk-iocost: change div64_u64 to DIV64_U64_ROUND_UP in ioc_refresh_params() Date: Mon, 28 Nov 2022 23:44:32 +0800 Message-ID: <20221128154434.4177442-7-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754057381427773?= X-GMAIL-MSGID: =?utf-8?q?1750754057381427773?= vrate_min is calculated by DIV64_U64_ROUND_UP, but vrate_max is calculated by div64_u64. Vrate_min may be 1 greater than vrate_max if the input values min and max of cost.qos are equal. Signed-off-by: Li Nan --- block/blk-iocost.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index a4fa17ebb2fa..03977385449f 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -926,7 +926,7 @@ static bool ioc_refresh_params(struct ioc *ioc, bool force) ioc->vrate_min = DIV64_U64_ROUND_UP((u64)ioc->params.qos[QOS_MIN] * VTIME_PER_USEC, MILLION); - ioc->vrate_max = div64_u64((u64)ioc->params.qos[QOS_MAX] * + ioc->vrate_max = DIV64_U64_ROUND_UP((u64)ioc->params.qos[QOS_MAX] * VTIME_PER_USEC, MILLION); return true; From patchwork Mon Nov 28 15:44:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5748719wrr; Mon, 28 Nov 2022 07:26:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf7wDMK0TcU1NtBjwD7fl7XwtpdAvw6A/HL11vffb8YFJa/fL4dIW6RkI2lUtlzgjCDO8Jpe X-Received: by 2002:a17:907:9856:b0:780:8144:a41f with SMTP id jj22-20020a170907985600b007808144a41fmr45296473ejc.189.1669649165191; Mon, 28 Nov 2022 07:26:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649165; cv=none; d=google.com; s=arc-20160816; b=fIPb3N3soeLw/zy0jH062S0aHSGhtHtaqRhv94gv3WJkRmkqD6dIENo7vfbm0/CV3t 44a0TB4HNKUu7Ief/SWJLVIns68W/PmkTmLpzTMhWy0unPemn1pwnTgfeNhhdaz7NZBn vBXzHbY9k93FTqggExsQAISNXKGrvYkCm+LyLcoTu/9uCjzgFbnqbZyGcohe2FJxuqY5 qOXd44vllUIm67QrkxivaM6/OnvGm+uIAFRlgPSNET+HeQZ60cQcvt5VIvgH9hzx7rb7 p+l41VAoYzFmLadPwuAhJ2oymKzPqti1puk/DBKvDTIA7wRyBB0jNt+XIkduud7B9UBF LmnQ== 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=HBdA8eceY3nohEu8BZzQ9VqGmhsl4GBpJP2MMpaNeps=; b=tTq4vPOVnoAj5H1kh+20hEn+Q4+ms8NpnMmXvCytZXxfZkZE6qoC/7rW97OMweBMEo J2fnlnVzP5NdSI801GEuatzmddAeoQNsM9jkZhoMUL8nxMHNQFiFMSlZmsXIFo6qrMdF m9+CwVcQfDQaQPNo4lcKe39DbCmj2nBP9rVO23ScOUdSs0N+zlYTp41cfq6zC6fEfsh1 EhLvQnjr/dsBn+ao0ISoiY5sTV8xTxL8bilwoGo5wBfDZhCnak5WIe2JWxUE0Aamro+a EkLTlMN2rbMbU1MwZ9BVUiTyMLDB+T/jUKdtxHjpbiwuKsMnLY7tYe0rsTCIXCCRZZnk vDgA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l16-20020a056402255000b0045d46f28533si11098599edb.377.2022.11.28.07.25.39; Mon, 28 Nov 2022 07:26:05 -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 S231779AbiK1PXy (ORCPT + 99 others); Mon, 28 Nov 2022 10:23:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231516AbiK1PXc (ORCPT ); Mon, 28 Nov 2022 10:23:32 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E34032AEE; Mon, 28 Nov 2022 07:23:31 -0800 (PST) Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NLTk36zDZzmW9G; Mon, 28 Nov 2022 23:22:51 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500025.china.huawei.com (7.185.36.35) 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:30 +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:29 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 7/8] blk-iocost: fix possible UAF in ioc_pd_free Date: Mon, 28 Nov 2022 23:44:33 +0800 Message-ID: <20221128154434.4177442-8-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754043120344286?= X-GMAIL-MSGID: =?utf-8?q?1750754043120344286?= Our test found the following problem in kernel 5.10, and the same problem should exist in mainline: BUG: KASAN: use-after-free in _raw_spin_lock_irqsave+0x71/0xe0 Write of size 4 at addr ffff8881432000e0 by task swapper/4/0 ... Call Trace: dump_stack+0x9c/0xd3 print_address_description.constprop.0+0x19/0x170 __kasan_report.cold+0x6c/0x84 kasan_report+0x3a/0x50 check_memory_region+0xfd/0x1f0 _raw_spin_lock_irqsave+0x71/0xe0 ioc_pd_free+0x9d/0x250 blkg_free.part.0+0x80/0x100 __blkg_release+0xf3/0x1c0 rcu_do_batch+0x292/0x700 rcu_core+0x270/0x2d0 __do_softirq+0xfd/0x402 asm_call_irq_on_stack+0x12/0x20 do_softirq_own_stack+0x37/0x50 irq_exit_rcu+0x134/0x1a0 sysvec_apic_timer_interrupt+0x36/0x80 asm_sysvec_apic_timer_interrupt+0x12/0x20 Freed by task 57: kfree+0xba/0x680 rq_qos_exit+0x5a/0x80 blk_cleanup_queue+0xce/0x1a0 virtblk_remove+0x77/0x130 [virtio_blk] virtio_dev_remove+0x56/0xe0 __device_release_driver+0x2ba/0x450 device_release_driver+0x29/0x40 bus_remove_device+0x1d8/0x2c0 device_del+0x333/0x7e0 device_unregister+0x27/0x90 unregister_virtio_device+0x22/0x40 virtio_pci_remove+0x53/0xb0 pci_device_remove+0x7a/0x130 __device_release_driver+0x2ba/0x450 device_release_driver+0x29/0x40 pci_stop_bus_device+0xcf/0x100 pci_stop_and_remove_bus_device+0x16/0x20 disable_slot+0xa1/0x110 acpiphp_disable_and_eject_slot+0x35/0xe0 hotplug_event+0x1b8/0x3c0 acpiphp_hotplug_notify+0x37/0x70 acpi_device_hotplug+0xee/0x320 acpi_hotplug_work_fn+0x69/0x80 process_one_work+0x3c5/0x730 worker_thread+0x93/0x650 kthread+0x1ba/0x210 ret_from_fork+0x22/0x30 It happened as follow: T1 T2 T3 //rmdir cgroup blkcg_destroy_blkgs blkg_destroy percpu_ref_kill blkg_release call_rcu //delete device del_gendisk rq_qos_exit ioc_rqos_exit kfree(ioc) __blkg_release blkg_free blkg_free_workfn pd_free_fn ioc_pd_free spin_lock_irqsave ->ioc is freed Fix the problem by moving the operation on ioc in ioc_pd_free() to ioc_pd_offline(), and just free resource in ioc_pd_free() like iolatency and throttle. Signed-off-by: Li Nan --- block/blk-iocost.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 03977385449f..1b855babfc35 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -2978,7 +2978,7 @@ static void ioc_pd_init(struct blkg_policy_data *pd) spin_unlock_irqrestore(&ioc->lock, flags); } -static void ioc_pd_free(struct blkg_policy_data *pd) +static void ioc_pd_offline(struct blkg_policy_data *pd) { struct ioc_gq *iocg = pd_to_iocg(pd); struct ioc *ioc = iocg->ioc; @@ -3002,6 +3002,12 @@ static void ioc_pd_free(struct blkg_policy_data *pd) hrtimer_cancel(&iocg->waitq_timer); } +} + +static void ioc_pd_free(struct blkg_policy_data *pd) +{ + struct ioc_gq *iocg = pd_to_iocg(pd); + free_percpu(iocg->pcpu_stat); kfree(iocg); } @@ -3488,6 +3494,7 @@ static struct blkcg_policy blkcg_policy_iocost = { .cpd_free_fn = ioc_cpd_free, .pd_alloc_fn = ioc_pd_alloc, .pd_init_fn = ioc_pd_init, + .pd_offline_fn = ioc_pd_offline, .pd_free_fn = ioc_pd_free, .pd_stat_fn = ioc_pd_stat, }; From patchwork Mon Nov 28 15:44:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 26827 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5750388wrr; Mon, 28 Nov 2022 07:28:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf6my/HQw0Sxa42jySsia6tQGNmc8xY1CHk+O4hQcaSMBkZKKEvVtpHi9Q30g/H+61BJnc7a X-Received: by 2002:a50:f602:0:b0:469:4e4f:4827 with SMTP id c2-20020a50f602000000b004694e4f4827mr40311396edn.214.1669649303787; Mon, 28 Nov 2022 07:28:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649303; cv=none; d=google.com; s=arc-20160816; b=o6iAcm8MY5Sp/k8RT69zo0n2rb0dSFv05OFH0oAIJbfZfUl5iKghEAyBeIHcQlnn3e pXHDqTc5WoO8VVQFKNBi85Lpc+cMjVxnfCpWURdJHWQJX8v7AWxTpXxN6gC5nf0X04Qa pTz/+BiYHt0onmQjCuW8ceFKoecwEYLjtLQZYTx3P2UYVc3yZm7wezLhrJGmdG7L6Aov kflamcqb5bgDqXRHel8Ps+/YoMGF6i6gYWjQs085SMEUeTncCJfnge/zE5eD2L/C2VPL DMS4lVdslxh4KZP5OP0lvvJpdbgOzK2SUuxoM1xTSpNvFEq8C6ysxRPg07pQiKrucAfa x1QQ== 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=DFv0pknN1CNLR3dxTrIaXMFbPHMpYDqm9AJmGvSasDE=; b=P3xDeBXYWz3MZkp5HszbDI3w1xO1T7hYVzNDjH0mfR1zFoXbJ2NcesCZk1XRfc54am V5L8fyxb+HdBlqt9pnignKFk11NYy8wcEt+RJIyV390VEvViajEpUnIFDsYe278d+cWC rzM3MfVnSzvBaJSKazeDa5MLdO7N87wVfNenrnLhQXgQqzkhOG2ePmadw82bbxN5rK2s N9zas6ppzlNcrbAFVPjk+Twbw9slciu9PigQgKxIlR6WtBKID576ZRcpe49phD1QFPFD oZdEkVkt6KHeLVmAXaDjx1PmXlK4NFi//BjYFH2+IOQERxBWtEo+re0uNBI9XqReFCoC pCgg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g5-20020a1709065d0500b007ada2efa6b7si11520092ejt.567.2022.11.28.07.27.58; Mon, 28 Nov 2022 07:28:23 -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 S231964AbiK1PYB (ORCPT + 99 others); Mon, 28 Nov 2022 10:24:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbiK1PXc (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 617072DFC; Mon, 28 Nov 2022 07:23:32 -0800 (PST) Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NLTk15F8fzHw8m; Mon, 28 Nov 2022 23:22:49 +0800 (CST) Received: from dggpeml500003.china.huawei.com (7.185.36.200) by dggpeml500020.china.huawei.com (7.185.36.88) 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:30 +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:30 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next 8/8] block: fix null-pointer dereference in ioc_pd_init Date: Mon, 28 Nov 2022 23:44:34 +0800 Message-ID: <20221128154434.4177442-9-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750754188451215720?= X-GMAIL-MSGID: =?utf-8?q?1750754188451215720?= Remove block device when iocost is initializing may cause null-pointer dereference: CPU1 CPU2 ioc_qos_write blkcg_conf_open_bdev blkdev_get_no_open kobject_get_unless_zero blk_iocost_init rq_qos_add del_gendisk rq_qos_exit q->rq_qos = rqos->next //iocost is removed from q->roqs blkcg_activate_policy pd_init_fn ioc_pd_init ioc = q_to_ioc(blkg->q) //cant find iocost and return null Fix problem by moving rq_qos_exit() to disk_release(). ioc_qos_write() get bd_device.kobj in blkcg_conf_open_bdev(), so disk_release will not be actived until iocost initialization is complited. Signed-off-by: Li Nan --- block/genhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/genhd.c b/block/genhd.c index dcf200bcbd3e..c264da49eaaa 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -656,7 +656,6 @@ void del_gendisk(struct gendisk *disk) elevator_exit(q); mutex_unlock(&q->sysfs_lock); } - rq_qos_exit(q); blk_mq_unquiesce_queue(q); /* @@ -1168,6 +1167,7 @@ static void disk_release(struct device *dev) !test_bit(GD_ADDED, &disk->state)) blk_mq_exit_queue(disk->queue); + rq_qos_exit(q); blkcg_exit_disk(disk); bioset_exit(&disk->bio_split);