From patchwork Wed Nov 30 13:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp908742wrr; Wed, 30 Nov 2022 05:01:25 -0800 (PST) X-Google-Smtp-Source: AA0mqf6k+Yp+FkLD+kcyrzOuwVQnEBe2oAMTNnhfVH8KLS0FuyZuetP7CIyoHeMSv6MIQrGLERPp X-Received: by 2002:a65:694e:0:b0:474:6749:407d with SMTP id w14-20020a65694e000000b004746749407dmr34942994pgq.425.1669813279628; Wed, 30 Nov 2022 05:01:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813279; cv=none; d=google.com; s=arc-20160816; b=w+CYFECRTQLMAPlTM5ruKEgj1pfq6ow5fi2xygpeZHz5wE3iN4oh4DZuGMHGw9MLnH nA19p0iNaYYJrANjOt78e6TY+taftjaEvgcGWN3hEsTrpctMag89HEhk0ygb1l+dECFS QrWhOsFJtwfctgD1NiwOW66/YOtK0NgUxXqGB605nhnSy90TZUQVrgiEM/7Y11quoN8u 8ftbaEDmc4/qs0lZwh4Dari0uTOk6MrEB/Kz7O8ucJ5hUtJTLi25X51zc7G5PMu8usX2 PYxZDNlKp7vAqUfRBEfds0bh/qehBGLR3QUnceJo1EQEPBAvD7OT5a9wtyzKfQnkTooj 3QWQ== 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=RWPnTWSBTZQDU1blhEXa90glvApFrXiuIYe6Ep1Hb0UgWJVPQ8anAJd7lS7JNgJVtk eTFCzxIOLAAyVpo298O+ZbAJDzTckErRDUzQgxG28hesk/tWEoPuPLg5VCBYUmFBvisj hD6ZeIV/PqHNPnpnvNRNgWIxiq6UhDHE9A4luAAyS2GZALtqEHJQm6trHL8U1h0WHQ3P kPO/wygUbySgzd2IfVw8ObTpTxJZj3K30N0x0fW8kT/KWOU4dQKDM53T3+hvCfuzBTV/ 1v7Ygo+a2Zgb4coK4WItTUh4cbFZAe/aq543uXm9IRbQSaossggMtLzDxpzeFCxhSaP3 0eUA== 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 nn12-20020a17090b38cc00b00213b01e42adsi1602599pjb.42.2022.11.30.05.01.05; Wed, 30 Nov 2022 05:01:19 -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 S234424AbiK3NA7 (ORCPT + 99 others); Wed, 30 Nov 2022 08:00:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229760AbiK3NAz (ORCPT ); Wed, 30 Nov 2022 08:00:55 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F423B4B99D; Wed, 30 Nov 2022 05:00:53 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfSV6SB7zRpZH; Wed, 30 Nov 2022 21:00:10 +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; Wed, 30 Nov 2022 21:00:51 +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; Wed, 30 Nov 2022 21:00:50 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 1/9] blk-iocost: cleanup ioc_qos_write() and ioc_cost_model_write() Date: Wed, 30 Nov 2022 21:21:48 +0800 Message-ID: <20221130132156.2836184-2-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926129255358176?= X-GMAIL-MSGID: =?utf-8?q?1750926129255358176?= 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 Wed Nov 30 13:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp908816wrr; Wed, 30 Nov 2022 05:01:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4wMtxbxotVEoR5BPyJLR3USbKQqRNVkVntrwg+Wbf3SR+oF6DeUqHdMHzjomMq3I/Tr7Rj X-Received: by 2002:a17:903:3302:b0:189:9590:4f98 with SMTP id jk2-20020a170903330200b0018995904f98mr10937747plb.148.1669813292218; Wed, 30 Nov 2022 05:01:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813292; cv=none; d=google.com; s=arc-20160816; b=qlustpzatjBqlFKjGIocx/z+KoR/Ok7XjsTtKS7ZtL0m70R9y/L9e3k96ZOH/xYnsr XuhTI+EILES4PEmu4GcTvq4iApXfiqO8NxwhNjtDpmr7hCBp4UKeiqK7SmTr4BbEDVWp 6Qu1BQ0tGzPMK3WweJlJCThZCzkJEf1wQh4DzsdbcRVWrEgYxFHTW+LKlwuXv+KND0du 65m0K3rUFfPWOtwAS9785nHvOsrGggF+wKOU0nOdpzTaStabEynlTA1tgGOqhCi9/Cn9 PWMp4hzCT/16zHzEz+YyWkbelhlVn7NhZcDhhavUIJgAjet0IRtvrMgCZMNbX3JlMzmc bKEg== 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=c7rGZ4APFzB+cgHnBPRWoJMtj5nvD1dQb2Q2zIAsuWio8yXVIQdSDs1hL4/E6XuCJw ggV3X1kDEp/9vomzgeZ2sqZQBzhWiaDuuBjqL+wHY6Nd2anR5uq75doMkBEukAOBc4Bz RN1jaTEn5ZBEOsE2rPojWy92v4ZFprGVOzwWtVDV0H4jDn/HF892qHz5un4jJsTSL5Ro /fE6vXh78sbXFTTyOgoDh8UUIXfR8JQqBqBdcVh1JCywdKQYavcSAk2uXDmVo3Ls+P3q RX02+lPEQ4EC9f8evSo8hqPZqmGq9obC9LYwi0xc8H+7CjAsYlIfkWtvvndpzI9ig8NO GVCw== 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 d14-20020a655ace000000b004775cf62c5dsi1253937pgt.297.2022.11.30.05.01.18; Wed, 30 Nov 2022 05:01:32 -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 S235367AbiK3NBC (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232924AbiK3NA4 (ORCPT ); Wed, 30 Nov 2022 08:00:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF594AF34; Wed, 30 Nov 2022 05:00:54 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfST1lmDzHwFM; Wed, 30 Nov 2022 21:00:09 +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; Wed, 30 Nov 2022 21:00:51 +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; Wed, 30 Nov 2022 21:00:51 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 2/9] blk-iocost: improve hanlder of match_u64() Date: Wed, 30 Nov 2022 21:21:49 +0800 Message-ID: <20221130132156.2836184-3-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926142602633428?= X-GMAIL-MSGID: =?utf-8?q?1750926142602633428?= 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 Wed Nov 30 13:21:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp909194wrr; Wed, 30 Nov 2022 05:02:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf5AtXOmfrWC+X/6pnk9jfwwJwxYhQyIZyr946JNmSSwB771sjhILMIrQm64V/O99F7Z7l2H X-Received: by 2002:a17:902:d592:b0:186:8930:20e6 with SMTP id k18-20020a170902d59200b00186893020e6mr42773604plh.64.1669813323265; Wed, 30 Nov 2022 05:02:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813323; cv=none; d=google.com; s=arc-20160816; b=HS5xFnZ904i5Y/qm6df3/LXBYJeuH5VuaV3fllVDefTX9G2ab9uDWKWlVWNF3AHdfV 7h9jYTBhzyVJPbmu8v7mivFTpa8Ze8KNMFIJC6I0qpl/w3qluDyU2lze2uopK/F0HGrM u2NPc6TMfSuugv9cQx3esU+EU6PLaMhPnjLT8M2x6h4Ipn07/UcXMCwCOKNr5zmwFw95 FfHZn4OFfkmDeF5FILsBV0Hn7sNyqZy/PI3IX08SswiO+w6qf89XnSrKiovmBxY1rp1A 36zVCGRcYPndfO6eYQV2ioPcv7hg7bEPcK91ME4axBpdR6X11UU7aWzkkYROhS+j9kt6 Dg5A== 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=qSGPpAeMHdhGdSPUdAuwqISEZzXZdbV1SbxrmU5JVeM=; b=SvDx8vC8EYJV4Sx/8j+ZgeMS63MVGNOzogES7frHUHFhM1IygxKIjbBgfglrgvEaZf MzvZImhAbahH1qygsgbzzQvXSDfYno3YHvyzu2PyhvBlpwkjrnCv6ak3JaEmo79pDdvR BloASdFsSv+CuFphTC31ZdarRhtyu2F2UZfahW0OBxNrLAUzRPjIYJFeflU8WZgbvCi/ Uzn2VD/tMi81QRdtwU5GAj+iNJMfmWzdnzOsU9/Nm4mrfjRiNOrxu+e0sqiWcE1m5gsD K7AKo+88eh6Wvidjtnug3y52zIIFdqeQNuMNTZ+VezD0l95wW1xBGDxWhCRWbwib2kSS 0pXQ== 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 s14-20020a056a0008ce00b0055706edd79csi1637338pfu.240.2022.11.30.05.01.49; Wed, 30 Nov 2022 05:02:03 -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 S235628AbiK3NBR (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbiK3NA5 (ORCPT ); Wed, 30 Nov 2022 08:00:57 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C60874B99D; Wed, 30 Nov 2022 05:00:54 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NMfSX2fc4z15Mxy; Wed, 30 Nov 2022 21:00:12 +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; Wed, 30 Nov 2022 21:00:52 +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; Wed, 30 Nov 2022 21:00:51 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 3/9] blk-iocost: don't allow to configure bio based device Date: Wed, 30 Nov 2022 21:21:50 +0800 Message-ID: <20221130132156.2836184-4-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926175119622108?= X-GMAIL-MSGID: =?utf-8?q?1750926175119622108?= 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 Acked-by: Tejun Heo --- block/blk-iocost.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index c532129a1456..bc6522bb314d 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 = -EOPNOTSUPP; + 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 = -EOPNOTSUPP; + goto out; + } + ioc = q_to_ioc(q); if (!ioc) { ret = blk_iocost_init(bdev->bd_disk); From patchwork Wed Nov 30 13:21:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27782 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp908962wrr; Wed, 30 Nov 2022 05:01:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4WqmgktBdxdZheKQHysYFn6Qt/o6SfBrQidh8jrPUhTQM5v0MQGViK+Q0eJlF3EjDvTynk X-Received: by 2002:a17:90a:d34d:b0:218:a0ce:9d5e with SMTP id i13-20020a17090ad34d00b00218a0ce9d5emr54757347pjx.96.1669813304603; Wed, 30 Nov 2022 05:01:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813304; cv=none; d=google.com; s=arc-20160816; b=WaH9ZcEGWfKa72V2cwiGTeETq07MtyGQd3+VD1TW4cAtk2VrJTqhkrcID8PUwjfyXz dn0IDZojuPXylQf2ryQbxZO93wk4tsRmJF0L3Prfs4f/WKlrJc2cZ0arpNNb/G+bWUAN Oev13XpIs+KqiwWcdb4dvgVkyZJGJX0uONg9PvnPcns0edjvpdNzlGy9XB2zsDjvebPu jLNRuakRNJtaAmmhTMEY7iKMYNcocI4zhcCcYkgdDQKm/POf06bMsLetUbtODM4HjBZy XSQ+Xn02LLAiQoxy6OmqJGcbojGxiiB5vdQ5BB4eyHke1U8OjF9iPUrimJp1p0WwE4Es gwSg== 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=zO4jYYKRQsPemUQc8y7lZXqTFrEF9fekid4csQmKyfk=; b=Bu/0+jPafuF7UwVdGO4RxuI8M4e5jARc32q6f6xJSovfuQe5Iw+m7T4uClB99ll8/a 4q9MD85bfDhRjU0Cuv54hHPbH1MXWNQMXzeNTUH9O24XgAKroSi4u034LmxTKVUwA4al VwadAmmq50jtF3qgK1D3tEiKBv/ck20+rihd3tBvS+smnFNT8dIJ6fN5w/swIoH11u+Q 7/tqA4jJUq3BlQHzBjencgvq06rQLFRzu26PDa+5jjXRLYKieWVCb/XBAz8s9QKjzYYg zuuF1KCPtPuOcWTgVAhiE6rTbzrZLwxZURXS57fs1MhDGVdDdPni0vkwr4tTLk/JXMEk 6+GA== 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 il11-20020a17090b164b00b0020d4f9a4b4dsi1654797pjb.49.2022.11.30.05.01.31; Wed, 30 Nov 2022 05:01:44 -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 S235577AbiK3NBG (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbiK3NA4 (ORCPT ); Wed, 30 Nov 2022 08:00:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62E8C429B1; Wed, 30 Nov 2022 05:00:54 -0800 (PST) Received: from dggpeml500026.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfSX2sz3zRpdX; Wed, 30 Nov 2022 21:00:12 +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; Wed, 30 Nov 2022 21:00:52 +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; Wed, 30 Nov 2022 21:00:52 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 4/9] blk-iocost: read params inside lock in sysfs apis Date: Wed, 30 Nov 2022 21:21:51 +0800 Message-ID: <20221130132156.2836184-5-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926155394162347?= X-GMAIL-MSGID: =?utf-8?q?1750926155394162347?= From: Yu Kuai Otherwise, user might get abnormal values if params is updated concurrently. Signed-off-by: Yu Kuai Signed-off-by: Li Nan Acked-by: Tejun Heo --- block/blk-iocost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index bc6522bb314d..3a96cd557c47 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 Wed Nov 30 13:21:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp909437wrr; Wed, 30 Nov 2022 05:02:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf4me+NaEM7t89W3e2+lxNLlkkwzZmJ0c+CfIj7OMghkcD+2euwGPPvGPhf0VceQ96TeYVNm X-Received: by 2002:a17:90b:350:b0:219:58c4:ccc9 with SMTP id fh16-20020a17090b035000b0021958c4ccc9mr6057316pjb.181.1669813343823; Wed, 30 Nov 2022 05:02:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813343; cv=none; d=google.com; s=arc-20160816; b=jPmA3Gc28PBuwDPh0OcRMbrxO0+cuGfYz0mYRLO68csAo8jkqR4iLgfAa76yxBjA9y gszVrbd+t+/gRZm802zgwieU3Kt7kRBgHm3pdVCrRl2c7DhLLXb11FIwzMnF9+npRevJ YkoXUm3VugnG091SY53wnGpqjVKJJ8DXvFxtnt9PoL2JBXnt9hoyWsqbdAFaA/bUkIM/ kVW5NAT+Sdfwhj9xCAjEmkP2oa8dDCxhg7cpxnTeNExcK+Z1/13fhFY/ty4ZWbodt4po n2Q09rVYbE6bObWW8BiU60Kfia0QUku6JHY/I8/HG5OXQc2JBfcb+Y5UP8TLRA/Q0ZnN oZgQ== 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=Gpmgj9GinjtbELh55WCgT2HTG/KLFvxWoYTFVUTNFaA=; b=BtPL6DdKJ5j8p4uolLiXWUAkA2nxfRZBKuTXdGj8fetURM93bC8F7GvL4lGre/Gh5W XAKDx9bEm1hA/ILrDbPQtXNQ9sTcxrEQ1WmuQNiO5cFDqAFMfbbtf+3TnlRNfjieblC9 yucHXWyzwUuunKSEZJGl832BYC4ib9pb+m11+zZmjvzcMLtu9qTlda1KfAxX5MPet/Gx NeLjQVmGbpQlZLwvo3rP0bf6AFryMxp7B1aXfPPWviFLjc/wif678IPDzIZeK1U402IJ mjh3lFLb7rMF1khUxD8VnXB9obeDtgQBC9f+B/pZtGXEliuyXiEAxSn19godm6Ec0DhA M1Cw== 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 u22-20020a056a00099600b00575deb1844asi1480853pfg.381.2022.11.30.05.02.08; Wed, 30 Nov 2022 05:02: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 S235584AbiK3NBW (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229929AbiK3NA5 (ORCPT ); Wed, 30 Nov 2022 08:00:57 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 665EF4AF34; Wed, 30 Nov 2022 05:00:56 -0800 (PST) Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NMfSY2Z9Gz15N01; Wed, 30 Nov 2022 21:00:13 +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; Wed, 30 Nov 2022 21:00:53 +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; Wed, 30 Nov 2022 21:00:52 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 5/9] blk-iocost: fix divide by 0 error in calc_lcoefs() Date: Wed, 30 Nov 2022 21:21:52 +0800 Message-ID: <20221130132156.2836184-6-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926196952948002?= X-GMAIL-MSGID: =?utf-8?q?1750926196952948002?= 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 3a96cd557c47..f4a754b9d10f 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 Wed Nov 30 13:21:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27783 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp909152wrr; Wed, 30 Nov 2022 05:02:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf4lxAwvsKlNRvGAB/l4Bm0WCQjUFloOxJmD42KzGoTruXZf0OX1raZaIUxAbEk3oT1zllnw X-Received: by 2002:a62:a515:0:b0:56e:28b1:56a3 with SMTP id v21-20020a62a515000000b0056e28b156a3mr42211121pfm.43.1669813320466; Wed, 30 Nov 2022 05:02:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813320; cv=none; d=google.com; s=arc-20160816; b=x0tIBOz4oYm/ieqAEJ5mMyJlEpPFPtIXK8k/VB7QyFrYZ9Av8/YsQ4BNbJPCiCwXDF Lf5K+f3H/heXrNcbVZBApC5VPgoFSNuiNYVQKgfvaObbjBvJ3OlzjORRY12x3xSs0cNQ BD04rKBTcxHujKzGBmxaMcRuENYF5zC31r5kSN64mO3KbIpD7pHT5IkGurq9vsWlkfCf 88GevwaMgO7l0xRNUjC5sjqT9siNTHWppg8kMVXazjYqfEZ2yVp7pbFAUpZ5rNhZ6M0H yUQah3nmzhE8z7gTTKolVdJ4rc9nj5axPLSx54BIrnDHCCKMa72jNYS3dIBHF06rTD7d +XgA== 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=JZ02pBcNw3ivTfDwGgBkNytotimScpxpEc793DzsV5c=; b=aIiVzEzm8mdzekJ+J/LfrgxF6bCosqL4QWLTBu+oREBE+zjLm29eSUUbcT0xv3MGh9 sono2Vxz8uQwnzvV8XcRZZw5DHxW33xdmTCxXu2dO0qFAlWir6H1iFVUxy9LzgMVgWnu bDf0kHnsvs3MjY+owHTXduAYDYnYK151YFV4vC2vZOtmWqx+h5Z2jEqc7qnYe62cgP/j ERZNUgAZebY11qKN5RlWNsVN97kskAfZHF4z9J+F8d8fml0xliDfmeOlKbzuVY8AhK33 0pbSXgsHiwR+JHwytVTHQUa4/VG9MYF0+JST24PTFMgxzRHIuZpKF+83VGhHRPsfaXmu XJxg== 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 r16-20020a63fc50000000b00477a32da0a9si1253479pgk.455.2022.11.30.05.01.45; Wed, 30 Nov 2022 05:02:00 -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 S235505AbiK3NBM (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233835AbiK3NA4 (ORCPT ); Wed, 30 Nov 2022 08:00:56 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C62FD4EC19; Wed, 30 Nov 2022 05:00:55 -0800 (PST) Received: from dggpeml500020.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfSW1hWRzHwK2; Wed, 30 Nov 2022 21:00:11 +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; Wed, 30 Nov 2022 21:00:53 +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; Wed, 30 Nov 2022 21:00:53 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 6/9] blk-iocost: change div64_u64 to DIV64_U64_ROUND_UP in ioc_refresh_params() Date: Wed, 30 Nov 2022 21:21:53 +0800 Message-ID: <20221130132156.2836184-7-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926172051001168?= X-GMAIL-MSGID: =?utf-8?q?1750926172051001168?= 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 Acked-by: Tejun Heo --- 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 f4a754b9d10f..2316ba93e7d6 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 Wed Nov 30 13:21:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27787 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp909620wrr; Wed, 30 Nov 2022 05:02:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7unij4qKLKPGEoT9Uu8PExrevNTANOpXZHbNdDshM5u8YmNi7/Z6V6UWMqz7AXgpkTpb40 X-Received: by 2002:a17:90a:c795:b0:218:9893:9aa7 with SMTP id gn21-20020a17090ac79500b0021898939aa7mr52775991pjb.223.1669813362331; Wed, 30 Nov 2022 05:02:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813362; cv=none; d=google.com; s=arc-20160816; b=GLU52sPq9H+8lNAklxW4gv6L4514ZZ97Jm5pEA3x3JTCaIbQlLq0cXMAvZ3nxDmbq1 PFpGTGAZeSmkNyMkOO5y72Y38EFaPaoSffBT875hk8PNCh9P64KCNhKVcyNvocZnxeB/ P0tfFLghC7XuBr2KrCus0FCHuerFcUSgoJhwO9QpF9xxTV8JamNMFKbeOYKxhw35ZIWl bLjrkvAf4KAcg9sGm55IgCnDdip07OS0dQYR54iAI9VuWeXdS1gXLt/d3/PR7t/+0uUw OlTxRpkEtqTKuMTvdrJJRd+IftU4+qCJsa5LLShS0b2uiTEOWLyLM0JSz4fkMfitwv60 yuYQ== 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=ux/u74cTCHbFFg1rxGvp+JsiH9rX2KPf2tvkKgm4PjY=; b=sc1yVAsfJA8jd20lfs0usU6LzSRJIMaTyhkdiwbgcuWJbGaAIbtvV8jdJt0qtM6cfZ 3yK8mZoWJKyDEo8/yqaTnISI2uhL6igw8eHksOXy/TZWia5+/mcI8xeJ8rO/XEbB/XQU Co29/8QGar7AxtntbCnngD2W1xwV1pSYUlmy6v/ZPA97t7eUUk6o4J3Ef5QTgcPHq3re I4DmxdSs0rFRcwZmSU6ZbEz6556OMQJbwQbvR3WIMG9I6VnSufnU8YxuDnQyA1hDiUAp pc07Bxdve0BEG6qsrENCEZQEB/pnWxsyMiHSH7afOLhD5CTOuYfmWL3g0QcslDgj+m1j +lLQ== 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 205-20020a6305d6000000b0046fc9e82c99si1225072pgf.206.2022.11.30.05.02.26; Wed, 30 Nov 2022 05:02:42 -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 S235773AbiK3NBb (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234023AbiK3NA6 (ORCPT ); Wed, 30 Nov 2022 08:00:58 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F24ED52170; Wed, 30 Nov 2022 05:00:55 -0800 (PST) Received: from dggpeml500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfSY6G8xzRpYq; Wed, 30 Nov 2022 21:00:13 +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; Wed, 30 Nov 2022 21:00:54 +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; Wed, 30 Nov 2022 21:00:53 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 7/9] blk-iocost: fix UAF in ioc_pd_free Date: Wed, 30 Nov 2022 21:21:54 +0800 Message-ID: <20221130132156.2836184-8-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926216579854290?= X-GMAIL-MSGID: =?utf-8?q?1750926216579854290?= 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 //delete device del_gendisk bdi_unregister bdi_remove_from_list synchronize_rcu_expedited //rmdir cgroup blkcg_destroy_blkgs blkg_destroy percpu_ref_kill blkg_release call_rcu 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 Acked-by: Tejun Heo --- 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 2316ba93e7d6..710cf63a1643 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 Wed Nov 30 13:21:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp909440wrr; Wed, 30 Nov 2022 05:02:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6KLBTJFFPVLM4c00C9d1Fi/o3SEg5XR7PZQ0JgABf8cIUU8J7QCj3mJqabEjKdVBWz+OHA X-Received: by 2002:a63:5308:0:b0:46f:cec6:8805 with SMTP id h8-20020a635308000000b0046fcec68805mr37979933pgb.612.1669813344211; Wed, 30 Nov 2022 05:02:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669813344; cv=none; d=google.com; s=arc-20160816; b=RbjrU3RvKGEz3WH0Cz8U5hi/xdQB9KhFthLGixxxEZO//KHPpnSxbWL71gkXbNiCcu Wa+9eC65onLWoczgbjEaJITjBhJFZ+fJL8+3mVtOoA+vrt9yxmqBuB/s/ovuxKzv0GQW uuaj+UwWIDQ5JcAZHI6OipbPpwnUdhL97/sWa8O+zKTfeEXHiojxH2f+K+vWMjdgVQeZ HeRIo7mH2xTnNbzwX7Kl5n285CDl3AxOGRrnh6ofT6w6bin2XPrK9OHA/SCCDOpkMXZx NkJc+lgEvgG4eWpmd0hJmM/pb+aadvBDt0p7jv3lAlTYg3zX9xSUtGASCjFM52oA718q 0Oag== 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=MMUIHipO+ixyCCOtLxkU84axM/dUNdIPeQzLp6D81hs=; b=Rxi/z7fzhkh+mFl8dRsFGjGe38fAzI7BaU6ousAOCp2kIQwovQMPRSKqjCILDzKWel 38cAH8lJQwZxuA4/G73HtyI51RXCeBDd+ih3ENmJgEHR2HpOI7G9Mp5qXMBfUqAnJcaK zHmIHbr4QJjgo/mBZFShM99T17IlLCB4EGJK8mHpFbJxSIqAjxyGkHb38pjJKr5L6Zfe hmgftG29usPnhOdprwCp/ztL4f292wt+IG56SqEXvNFoCgF2E3TzvWwsKoq1StPCCYg/ C9nQFU7inFiJ9BxG+TySOwO6hZ62sfy0p5O6WmmOgGyvefoUVsqdUxAss7doZFbtW6cj vThA== 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 k9-20020a170902760900b001869fd74e0csi1160072pll.311.2022.11.30.05.02.09; Wed, 30 Nov 2022 05:02: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 S235757AbiK3NB0 (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234500AbiK3NA6 (ORCPT ); Wed, 30 Nov 2022 08:00:58 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EDFF4E421; Wed, 30 Nov 2022 05:00:56 -0800 (PST) Received: from dggpeml500021.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4NMfPR28XyzJp39; Wed, 30 Nov 2022 20:57:31 +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; Wed, 30 Nov 2022 21:00:54 +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; Wed, 30 Nov 2022 21:00:54 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 8/9] block: fix null-pointer dereference in ioc_pd_init Date: Wed, 30 Nov 2022 21:21:55 +0800 Message-ID: <20221130132156.2836184-9-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750926197194870938?= X-GMAIL-MSGID: =?utf-8?q?1750926197194870938?= 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..0db440bbfefb 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(disk->queue); blkcg_exit_disk(disk); bioset_exit(&disk->bio_split); From patchwork Wed Nov 30 13:21:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 27789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp920410wrr; Wed, 30 Nov 2022 05:21:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5//I6HsmpLWbPYhjBOLKMx9lYcIlS3dBGGrR+gs3Y1QMLO3+UrzvuAT+aXrnxsFFhzNZ0L X-Received: by 2002:a17:902:e313:b0:189:97e9:c8e with SMTP id q19-20020a170902e31300b0018997e90c8emr9988404plc.63.1669814496580; Wed, 30 Nov 2022 05:21:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669814496; cv=none; d=google.com; s=arc-20160816; b=wDO3D0RJbaC0i5jPVHcadzopO9K5mPOXZBgRnB6Rdk1BycmKTTQP6ZP87aUOJgY+5Y Bd0Ct7aLzGGsClc0EEHuJ1jvunqYj2mPwN6fpAmSPmdbxLh6h37XEUZMasXU7XGzHKRQ dMSxjArn12fxufSgAqXI/xZTxkcS9Qa02cm7UFVoyFBTZwJaZHnI30FpvGp4rgqTyrDl YFJNhwLMSxfXQE1bvGaZoDRZ9k1tp8UBM7yqk8jYFs3m9J9XNTUi3DRwuNsqBnr20JU4 c5Wu6nhxOmifAF0e2uUBNkcdkTHZ77q/YNgKhU9O5cSnhkvvVZcxQwOEHG52in+3gxE2 U17A== 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=qYYu8MaQosUsSgpRafqL3nDsZVgA3iEEguStEtj1YfU=; b=aaehX5f0266shfoKNuC3Lq9+lE6jbguCKZgg/WN75yng8TCwryBEXsBVQcxfGk+0HC 2JMon9ucji54CUbze09PDQMCFefwk25+fGZj04o0AlPw+OUeQ56B+buF6fk4q8Hl8MJm ctvcztIhJDXjtfC5L34X8ctD9yroRWH22Z4TauEka2FlFZ4hr5b63JlA4UTUfbWeebi2 U6JPxOrehMBsTpFWJDR20fzWkRLqYCn2JdE+jdosYJizeFMqZo612oroOEGUXWK/DlJU QcLgaQGIRodc4z9eRtuZCli2hLMkT5ZANr7fkybj9dCSGNCujSPRp/cGGYLeL9TKJmfr C7Cw== 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 u13-20020a63140d000000b00476e9888164si1252403pgl.88.2022.11.30.05.21.23; Wed, 30 Nov 2022 05:21:36 -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 S235801AbiK3NBp (ORCPT + 99 others); Wed, 30 Nov 2022 08:01:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234936AbiK3NA6 (ORCPT ); Wed, 30 Nov 2022 08:00:58 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40B154EC2A; Wed, 30 Nov 2022 05:00:58 -0800 (PST) Received: from dggpeml500024.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NMfSZ67kyzRpfP; Wed, 30 Nov 2022 21:00:14 +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; Wed, 30 Nov 2022 21:00:55 +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; Wed, 30 Nov 2022 21:00:54 +0800 From: Li Nan To: , , CC: , , , , , Subject: [PATCH -next v2 9/9] blk-iocost: fix walk_list corruption Date: Wed, 30 Nov 2022 21:21:56 +0800 Message-ID: <20221130132156.2836184-10-linan122@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221130132156.2836184-1-linan122@huawei.com> References: <20221130132156.2836184-1-linan122@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) 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?1750927405729975786?= X-GMAIL-MSGID: =?utf-8?q?1750927405729975786?= From: Yu Kuai Our test report a problem: ------------[ cut here ]------------ list_del corruption. next->prev should be ffff888127e0c4b0, but was ffff888127e090b0 WARNING: CPU: 2 PID: 3117789 at lib/list_debug.c:62 __list_del_entry_valid+0x119/0x130 RIP: 0010:__list_del_entry_valid+0x119/0x130 RIP: 0010:__list_del_entry_valid+0x119/0x130 Call Trace: iocg_flush_stat.isra.0+0x11e/0x230 ? ioc_rqos_done+0x230/0x230 ? ioc_now+0x14f/0x180 ioc_timer_fn+0x569/0x1640 We haven't reporduced it yet, but we think this is due to parent iocg is freed before child iocg, and then in ioc_timer_fn, walk_list is corrupted. 1) Remove child cgroup can concurrent with remove parent cgroup, and ioc_pd_free for parent iocg can be called before child iocg. This can be fixed by moving the handle of walk_list to ioc_pd_offline, since that offline from child is ensured to be called before parent. 2) ioc_pd_free can be triggered from both removing device and removing cgroup, this patch fix the problem by deleting timer before deactivating policy, so that free parent iocg first in this case won't matter. Signed-off-by: Yu Kuai Signed-off-by: Li Nan --- block/blk-iocost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/blk-iocost.c b/block/blk-iocost.c index 710cf63a1643..d2b873908f88 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -2813,13 +2813,14 @@ static void ioc_rqos_exit(struct rq_qos *rqos) { struct ioc *ioc = rqos_to_ioc(rqos); + del_timer_sync(&ioc->timer); + blkcg_deactivate_policy(rqos->q, &blkcg_policy_iocost); spin_lock_irq(&ioc->lock); ioc->running = IOC_STOP; spin_unlock_irq(&ioc->lock); - del_timer_sync(&ioc->timer); free_percpu(ioc->pcpu_stat); kfree(ioc); }