Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp633788pxb; Tue, 5 Apr 2022 16:42:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt29FjdwmvGydSEP7xMy1U2dD37oTNiiEosdDXSnXnVsjaZz5JnJjiYOJk6neN2vK05A2z X-Received: by 2002:a05:6a00:801:b0:4fd:f66a:b36c with SMTP id m1-20020a056a00080100b004fdf66ab36cmr5902213pfk.68.1649202126196; Tue, 05 Apr 2022 16:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202126; cv=none; d=google.com; s=arc-20160816; b=IexRSr+Bo53XvMUBv5EGD0hWdG4e2vipXMznLTfB+kVMrrCKSi5iJYWXnpNuBEPLwG KDKol7otyrrTiCZW6BqbCkks59iq84JM+ewt9uC2jih8PbE9xRP+JVLtbF7zqaz32pYA TDmr4zNzkBQLXTdDJ73ls5chyypUZ/bECCVXOTWkHj6zIE7+M1wuEfrOTuemDzoSz5on SULBD3pGHH7Vj+4JwPp7L01jPk0Vwdp4V6MiY89cglzwfGpWZXONdLHvxwGfF5Y53JYT Rv27XjsD1QpCjgaEhGur5m3jHGEmZDnb5lz1nSX0lwt2YxaR/lLa9mHiWRk1RyjmOL5P Gmxw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M0PxjRJkj8tmsilF0a9YJFct1MIQlCow3qwEsWD+b5s=; b=McqsFEGbZgz/GlVYRfml85jesAq60Wb8hzAG0g7uIOk4JjeJcVVUZE6AHht+hZ5fQL SqY7WehyyNeQZAIVDKjzeTgdsj0JcXuuV36DpQnfldfGWXVXmRnnehgxyHQ/ZjNkOk+J 8Y9agKFtMoGQCyfcd0Mtfn5hj8QOxYavy5wzqnYZi9giimxDuSb/g7EQ0aIow6sHW2B0 tcMZzsV9xI2DiqRIgGNzbgO1jKiX3SuSdF/kpeza1UhRIPyhM0eqbdjPBcFLXwndusnU iebtdJfG787tQQL1/+cgLhz8uQMzudgAOjK5gMqSuXEesYsY4khZRvn8NzJVSqOH0n0K +4zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fRZqc0Er; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ip5-20020a17090b314500b001caa4c5d4b6si3305560pjb.68.2022.04.05.16.42.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:42:06 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fRZqc0Er; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 661161E8CE3; Tue, 5 Apr 2022 16:26:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387846AbiDENTe (ORCPT + 99 others); Tue, 5 Apr 2022 09:19:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344286AbiDEJTE (ORCPT ); Tue, 5 Apr 2022 05:19:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C278237DE; Tue, 5 Apr 2022 02:07:21 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C5900B80DA1; Tue, 5 Apr 2022 09:07:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 34078C385A0; Tue, 5 Apr 2022 09:07:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149638; bh=xorRcJWLyDePlbEryOuirjB9N5M1QbwwaFb0JW6nk/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fRZqc0EruEqYXXB5NTC5Yd1/wx7Zrkrszgj27h4HLiGPxfUhzjFtKJ3h1NR9jMnB5 dPFDjJ7AGgwpg4ar4pNEeQLdeLBa0qHF7WvfVk1h5WXXVhQxhrPt3wuxRKZ8np9639 hLe8wUs0N9FJdAN+E8qenM8l+RCBZQcleBZplpwI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ritesh Harjani , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.16 0786/1017] ext4: correct cluster len and clusters changed accounting in ext4_mb_mark_bb Date: Tue, 5 Apr 2022 09:28:19 +0200 Message-Id: <20220405070417.585711425@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Ritesh Harjani [ Upstream commit a5c0e2fdf7cea535ba03259894dc184e5a4c2800 ] ext4_mb_mark_bb() currently wrongly calculates cluster len (clen) and flex_group->free_clusters. This patch fixes that. Identified based on code review of ext4_mb_mark_bb() function. Signed-off-by: Ritesh Harjani Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/a0b035d536bafa88110b74456853774b64c8ac40.1644992609.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index e872ea582555..c0868b82a62f 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3899,10 +3899,11 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, struct ext4_sb_info *sbi = EXT4_SB(sb); ext4_group_t group; ext4_grpblk_t blkoff; - int i, clen, err; + int i, err; int already; + unsigned int clen, clen_changed; - clen = EXT4_B2C(sbi, len); + clen = EXT4_NUM_B2C(sbi, len); ext4_get_group_no_and_offset(sb, block, &group, &blkoff); bitmap_bh = ext4_read_block_bitmap(sb, group); @@ -3923,6 +3924,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, if (!mb_test_bit(blkoff + i, bitmap_bh->b_data) == !state) already++; + clen_changed = clen - already; if (state) ext4_set_bits(bitmap_bh->b_data, blkoff, clen); else @@ -3935,9 +3937,9 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, group, gdp)); } if (state) - clen = ext4_free_group_clusters(sb, gdp) - clen + already; + clen = ext4_free_group_clusters(sb, gdp) - clen_changed; else - clen = ext4_free_group_clusters(sb, gdp) + clen - already; + clen = ext4_free_group_clusters(sb, gdp) + clen_changed; ext4_free_group_clusters_set(sb, gdp, clen); ext4_block_bitmap_csum_set(sb, group, gdp, bitmap_bh); @@ -3947,10 +3949,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, if (sbi->s_log_groups_per_flex) { ext4_group_t flex_group = ext4_flex_group(sbi, group); + struct flex_groups *fg = sbi_array_rcu_deref(sbi, + s_flex_groups, flex_group); - atomic64_sub(len, - &sbi_array_rcu_deref(sbi, s_flex_groups, - flex_group)->free_clusters); + if (state) + atomic64_sub(clen_changed, &fg->free_clusters); + else + atomic64_add(clen_changed, &fg->free_clusters); } err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh); -- 2.34.1