From patchwork Mon May 22 07:25:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 97140 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1272835vqo; Mon, 22 May 2023 00:46:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4KDvzR+oI8GNcjiLomG10/uk8zGV2ZMBriE0P7BzHkd8PWp4owJe1K+oqgQXwc9akw1Cah X-Received: by 2002:a17:90a:d384:b0:255:54ce:c3a9 with SMTP id q4-20020a17090ad38400b0025554cec3a9mr3778021pju.24.1684741566582; Mon, 22 May 2023 00:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684741566; cv=none; d=google.com; s=arc-20160816; b=QxUC2pBP8iSEqoA5pAnWVkhdIcp/feDA0mHijMkmHtIdzYhgEB0+o4hinI13d1HZAn 6iUtu5xByih5e19NBlA9f9fB1xCjTxRHctV79lPm0DX0JsKki4TDtfIJnXSAbO+p2oKo JurGIcPKf94l+UbCrcDsVRreVXKG0E+Lan0uzpWOrpHSmQRdaL3zbiWjR8ThB7xxmeL1 jxuO44uMn4a9B74QnpLlSQfqCCRRJHs3b3q5QR8mUxwQUI8COYVR5HVZxxupfhp3mYvH 9ipm70I8FjkAsNuruuHU2onjvYL40F3u4mSpJnCuJ1+YeWOF59F+CGPOq59k0dfZxF16 rdCg== 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=OOveZIlyUiCLSxoPzTkwef61yMmMfmouzkXTlwwECYw=; b=D9TwLBhon2cMZbkTZfwFHF2QPpOfa0ha1/ecqh/ov2S78Q2sP+fFiN9/dM8XlAW3Qb RE4UFxIMmtkv8MfUojUkGl+64DFnXWCAZRVHBy10XWPoQuzw1C5o1Jh5tUZB+PEsxOuN uQuE28XnuGVqSHsIuUYpG0Iyp8ze9XARosPBrcmYytGn0ogdPuBTEX6wImb4XaeP7FBN l3VB1MRPi7ij9CS18OPykC6lqME+XhIOnJbZpyB3jnPlltH11ECgn6VsM+EFiMgswJLV MgfkO4ALtCftRK1xai9pvuWYDm13uRBdEBwULaSwtJ1NFva9gQ/3FO6XqAWGNMoBtfLE KVnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u26-20020a63b55a000000b004fc39adf481si4651960pgo.381.2023.05.22.00.45.54; Mon, 22 May 2023 00:46:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232448AbjEVH1V (ORCPT + 99 others); Mon, 22 May 2023 03:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232318AbjEVH1N (ORCPT ); Mon, 22 May 2023 03:27:13 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3478AB7; Mon, 22 May 2023 00:27:10 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QPptL1g8Sz4f3jq4; Mon, 22 May 2023 15:27:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgBH7epJGWtkztVuJw--.34097S5; Mon, 22 May 2023 15:27:07 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v4 1/3] md/raid10: fix overflow of md/safe_mode_delay Date: Mon, 22 May 2023 15:25:33 +0800 Message-Id: <20230522072535.1523740-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230522072535.1523740-1-linan666@huaweicloud.com> References: <20230522072535.1523740-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgBH7epJGWtkztVuJw--.34097S5 X-Coremail-Antispam: 1UD129KBjvJXoW7uF1rXr4rZr1ftr17CF48Zwb_yoW8Xr1kp3 yfJ343Gw4rKFy0gFnFqr4kWFy5G3Z2qrW2y3yIy34ftF9rXF1Yqas5GanYgr98W3yrAFy7 Jw1DAF15ZFykCaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmjb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUGw A2048vs2IY020Ec7CjxVAFwI0_JFI_Gr1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU858n5UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1766579573054547509?= X-GMAIL-MSGID: =?utf-8?q?1766579573054547509?= From: Li Nan There is no input check when echo md/safe_mode_delay in safe_delay_store(). And msec might also overflow when HZ < 1000 in safe_delay_show(), Fix it by checking overflow in safe_delay_store() and use unsigned long conversion in safe_delay_show(). Fixes: 72e02075a33f ("md: factor out parsing of fixed-point numbers") Signed-off-by: Li Nan --- drivers/md/md.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 8e344b4b3444..b2d69260b5b1 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -3794,8 +3794,9 @@ int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale) static ssize_t safe_delay_show(struct mddev *mddev, char *page) { - int msec = (mddev->safemode_delay*1000)/HZ; - return sprintf(page, "%d.%03d\n", msec/1000, msec%1000); + unsigned int msec = ((unsigned long)mddev->safemode_delay*1000)/HZ; + + return sprintf(page, "%u.%03u\n", msec/1000, msec%1000); } static ssize_t safe_delay_store(struct mddev *mddev, const char *cbuf, size_t len) @@ -3807,7 +3808,7 @@ safe_delay_store(struct mddev *mddev, const char *cbuf, size_t len) return -EINVAL; } - if (strict_strtoul_scaled(cbuf, &msec, 3) < 0) + if (strict_strtoul_scaled(cbuf, &msec, 3) < 0 || msec > UINT_MAX / HZ) return -EINVAL; if (msec == 0) mddev->safemode_delay = 0; From patchwork Mon May 22 07:25:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 97146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1272983vqo; Mon, 22 May 2023 00:46:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7eWRY9wDLDlqUZMKwyLflmeVKx4+hLaaSaPwH60Zmvz8xH4COtvI+NkpCOL/Lui8JIG1yq X-Received: by 2002:aa7:88c4:0:b0:64c:c65f:7322 with SMTP id k4-20020aa788c4000000b0064cc65f7322mr12673320pff.30.1684741585883; Mon, 22 May 2023 00:46:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684741585; cv=none; d=google.com; s=arc-20160816; b=t6CdBu7urawop9nBIv+TPc9A3SDqpkKgFalfcChBM0JeEtxnoZRWfYDUdSpDxSiZEx T0wQT8/U4qei04pSMi/32dg+UerUHuaTp2LMPa5EE4o4eJ34qFiGK+pRgrcYhTHJhK+v LLjCPINrvXT6osJD0TwdmQ2oruXiAlFrJ2KfosL9rWqIVuAPiNGO7OHN25Hww2MDopIR Qv+C2COqS/fiHBfCzQLm/WlPRNMaMrjUYuQAGGWvmzzxEv7K4GVvP7OnD3/kvT3aNhuH SRVI5p0NEidb5YGZtO+mLQ4WGRO4B1TZhhCVQHgMsAqqm8M+Z1pxUtQ1YIY5UElgRuxO pOyA== 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=JHq+i2pEaogviQJ4omG2nlrzDfT94IMHySUa+rXc+LI=; b=FUT39u/03gIM8o68XhAoSVZ/rb3Vdqi3ftr8CMdb+fmKdy2RqOdaUc+c1QF6OsV97f 79zVwm+17cxnNcMul/uB5HQ4iFdHo34f+FQfCaUCZShLGo75X/P+sZCReJzHGmbd2nGt YErWnAPs7bURglzXi4mJ6yyNjeJiT57yg3Rsep4/t4l3h+20vUSHgVIpNEqnSljk2UGZ OSeMs3yt8NGtSWeyHLzCplg5kljI7vcGQw+6/B5WuYm6z/1emM2HeV7WExja17SLTx92 5Q3s1jVkwFTwyQ11xsue6THms5CncbcOgW/cYHyCxfMnMDYvwm0Ieo79LgSJu3yfkNn5 Fj+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020aa79529000000b0064678cefdd5si4442632pfp.223.2023.05.22.00.46.13; Mon, 22 May 2023 00:46:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232592AbjEVH1Y (ORCPT + 99 others); Mon, 22 May 2023 03:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232439AbjEVH1R (ORCPT ); Mon, 22 May 2023 03:27:17 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FA0ABF; Mon, 22 May 2023 00:27:10 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QPptL5nDLz4f3p17; Mon, 22 May 2023 15:27:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgBH7epJGWtkztVuJw--.34097S6; Mon, 22 May 2023 15:27:07 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v4 2/3] md/raid10: fix wrong setting of max_corr_read_errors Date: Mon, 22 May 2023 15:25:34 +0800 Message-Id: <20230522072535.1523740-3-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230522072535.1523740-1-linan666@huaweicloud.com> References: <20230522072535.1523740-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgBH7epJGWtkztVuJw--.34097S6 X-Coremail-Antispam: 1UD129KBjvdXoWrur4kXF4fGw18JF4fZrWxtFb_yoW3ZFg_Ca 1Fqay3Xr9Iyr12ywn8Zr4SvrW2y3yv9ryDWF1Ika45A3WrZ34Iqa4ru3s8Xr1rJrWkua45 Xr1kK3yIvr4DKjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbk8YFVCjjxCrM7AC8VAFwI0_Wr0E3s1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r15M2 8IrcIa0xkI8VCY1x0267AKxVW8JVW5JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64 xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j 6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73 UjIFyTuYvjxUc-txDUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1766579592916816666?= X-GMAIL-MSGID: =?utf-8?q?1766579592916816666?= From: Li Nan There is no input check when echo md/max_read_errors and overflow might occur. Add check of input number. Fixes: 1e50915fe0bb ("raid: improve MD/raid10 handling of correctable read errors.") Signed-off-by: Li Nan Reviewed-by: Yu Kuai --- drivers/md/md.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/md.c b/drivers/md/md.c index b2d69260b5b1..350094f1cb09 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -4478,6 +4478,8 @@ max_corrected_read_errors_store(struct mddev *mddev, const char *buf, size_t len rv = kstrtouint(buf, 10, &n); if (rv < 0) return rv; + if (n > INT_MAX) + return -EINVAL; atomic_set(&mddev->max_corr_read_errors, n); return len; } From patchwork Mon May 22 07:25:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Nan X-Patchwork-Id: 97135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1272716vqo; Mon, 22 May 2023 00:45:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5N3mW8MzfEXDMBtyTAnlBb2xg/fJmDSiWG7sxOfXCW5ZMh2Wzebpq/HTwQnG6tuit61kJb X-Received: by 2002:a17:902:7287:b0:1a9:8ba4:d0d3 with SMTP id d7-20020a170902728700b001a98ba4d0d3mr9639252pll.8.1684741550328; Mon, 22 May 2023 00:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684741550; cv=none; d=google.com; s=arc-20160816; b=exUjTrGQ03DdaH/ELN6W+Ds3oViAd2hQ0oJ16jpYc/iHAF8i7ypFkkQYQOK3MbkTaH z2njCnTJ0oJh9oT6Cjs6iCEmu4ADuOkuT1C4S17dpFFlTCu0MMblO0s5ayleIgVSObSY wGkWPmLQHvQ7je9pO0SJX7SynLjt4Vcdjxp+Nqk/ORadvqsC3GL9zjjSG39q19Owf+Sb +UtV6mQnqHgVI7PnMbQha3Sh3GHG39nXlo+SASBugF4kcc34WFDvapxLuTkbB7W4RFV8 aQD97x4fqhRb/TfUSkVsHmUcNvCczMrNrrlkmLcDZLPnSYFRoo/bN0reue0xyw6TuHda 5Xbg== 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=9NmEVNntJFi5oTwtCBZmfE4LSoflCyDRVFKE33HthZg=; b=lt55aVjqOeVvNqyWB3EkoUy0T32gvnTL28tqeBSzUfyuuunidT3CxetUSenwvJHAxF T+m4wwEZ/QiHc0h8vKsGEDzfmARP91htQsoqj3Ml/lEewc20CNcKENGyXQDclezgc6MN hBRg4tL0kZ+r3OMCKU0dNu3Oic359P6UiPSjPp9Nbm/pphVU8LslRgnPbCP5qMeuuJ9N 8gD3tK706CjFnDh78lAMI028CCL5hm3siRr0MBi0uXLLmW1WjJcwzhLJTmWRCkSBljQ4 guGUCoDGLpygW9Ih6GZ+9dUGVz1P2w38nauIFjM02zh4G8lVLzb+jtu5MM8vS41uSMLe jsqQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v6-20020a17090a898600b002478d1e81c7si4129379pjn.174.2023.05.22.00.45.38; Mon, 22 May 2023 00:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232602AbjEVH10 (ORCPT + 99 others); Mon, 22 May 2023 03:27:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232460AbjEVH1S (ORCPT ); Mon, 22 May 2023 03:27:18 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3A60CA; Mon, 22 May 2023 00:27:11 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QPptL3Mf1z4f3jHg; Mon, 22 May 2023 15:27:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP2 (Coremail) with SMTP id Syh0CgBH7epJGWtkztVuJw--.34097S7; Mon, 22 May 2023 15:27:08 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v4 3/3] md/raid10: optimize check_decay_read_errors() Date: Mon, 22 May 2023 15:25:35 +0800 Message-Id: <20230522072535.1523740-4-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230522072535.1523740-1-linan666@huaweicloud.com> References: <20230522072535.1523740-1-linan666@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: Syh0CgBH7epJGWtkztVuJw--.34097S7 X-Coremail-Antispam: 1UD129KBjvJXoWxCFWxAF4UZFWfKrWDKry3Jwb_yoWrXryDpa 15Aas8Jr4UJryUAw1DJryqya4FyryfCayjyrWxJa1Iqwn5Jrn8ta45GFy2g348GF9xJw15 XrZ8Gr4DCr4DKFUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmjb4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUWw A2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxS w2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxV W8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v2 6rxl6s0DM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrV ACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWU JVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lFIxGxcIEc7CjxVA2Y2 ka0xkIwI1lw4CEc2x0rVAKj4xxMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7 AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE 2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7IU1BOJ7UUUUU== X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1766579556137622145?= X-GMAIL-MSGID: =?utf-8?q?1766579556137622145?= From: Li Nan check_decay_read_errors() is used to handle rdev->read_errors. But read_errors is inc and read after check_decay_read_errors() is invoked in fix_read_error(). Put all operations of read_errors into check_decay_read_errors() and clean up unnecessary atomic_read of read_errors. Suggested-by: Yu Kuai Signed-off-by: Li Nan --- drivers/md/raid10.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 4fcfcb350d2b..d31eed17f186 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -2655,23 +2655,24 @@ static void recovery_request_write(struct mddev *mddev, struct r10bio *r10_bio) } /* - * Used by fix_read_error() to decay the per rdev read_errors. + * Used by fix_read_error() to decay the per rdev read_errors and check if + * read_error > max_read_errors. * We halve the read error count for every hour that has elapsed * since the last recorded read error. * */ -static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev) +static bool check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev) { - long cur_time_mon; + time64_t cur_time_mon = ktime_get_seconds(); unsigned long hours_since_last; - unsigned int read_errors = atomic_read(&rdev->read_errors); - - cur_time_mon = ktime_get_seconds(); + unsigned int read_errors; + unsigned int max_read_errors = + atomic_read(&mddev->max_corr_read_errors); if (rdev->last_read_error == 0) { /* first time we've seen a read error */ rdev->last_read_error = cur_time_mon; - return; + goto increase; } hours_since_last = (long)(cur_time_mon - @@ -2684,10 +2685,25 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev) * just set read errors to 0. We do this to avoid * overflowing the shift of read_errors by hours_since_last. */ + read_errors = atomic_read(&rdev->read_errors); if (hours_since_last >= 8 * sizeof(read_errors)) atomic_set(&rdev->read_errors, 0); else atomic_set(&rdev->read_errors, read_errors >> hours_since_last); + +increase: + read_errors = atomic_inc_return(&rdev->read_errors); + if (read_errors > max_read_errors) { + pr_notice("md/raid10:%s: %pg: Raid device exceeded read_error threshold [cur %d:max %d]\n", + mdname(mddev), rdev->bdev, + read_errors, max_read_errors); + pr_notice("md/raid10:%s: %pg: Failing raid device\n", + mdname(mddev), rdev->bdev); + md_error(mddev, rdev); + return false; + } + + return true; } static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector, @@ -2727,7 +2743,6 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 int sect = 0; /* Offset from r10_bio->sector */ int sectors = r10_bio->sectors; struct md_rdev *rdev; - int max_read_errors = atomic_read(&mddev->max_corr_read_errors); int d = r10_bio->devs[r10_bio->read_slot].devnum; /* still own a reference to this rdev, so it cannot @@ -2740,15 +2755,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10 more fix_read_error() attempts */ return; - check_decay_read_errors(mddev, rdev); - atomic_inc(&rdev->read_errors); - if (atomic_read(&rdev->read_errors) > max_read_errors) { - pr_notice("md/raid10:%s: %pg: Raid device exceeded read_error threshold [cur %d:max %d]\n", - mdname(mddev), rdev->bdev, - atomic_read(&rdev->read_errors), max_read_errors); - pr_notice("md/raid10:%s: %pg: Failing raid device\n", - mdname(mddev), rdev->bdev); - md_error(mddev, rdev); + if (!check_decay_read_errors(mddev, rdev)) { r10_bio->devs[r10_bio->read_slot].bio = IO_BLOCKED; return; }