Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1062951pxb; Wed, 6 Apr 2022 07:53:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+fRWDnCZi/le/N4wbgByPGXXgdUwwx9qFeZN3Q3J8J9y0GkUfRWlGXZUIr6NUeeMk2aZX X-Received: by 2002:a17:902:9345:b0:153:4d7a:53d9 with SMTP id g5-20020a170902934500b001534d7a53d9mr9217183plp.116.1649256808315; Wed, 06 Apr 2022 07:53:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649256808; cv=none; d=google.com; s=arc-20160816; b=OAfDs616QsWBXtzX+T96JjOodMlDGNGlVcRsVHttLiQhT8yhRUvcxIJAIf923Vl4RU 51gKFW2qkUQXYDB6oGmXpG78s6g1hIgWHYZaCSUGTRl7uDDzoMRSVK/n2U0ISCqrA7Ni LszjdYjjtjiaOmSTNZlFcwKytnQesK2U+lmKWeYGSOlMZwp+lnstKSOYDinHMq887lwA hJMR+5Bhz3dJifd66K2kZe5RvO29ddH43LseMCb/zZw2gTjrztSssQYR6GD+nZVFEVVt e21odE/V0VRy0QdSDSAr+K5Fc4srkegDqr1NXB7J1C8VzzPfpqhDoDbCwJYvtMFl6ccg q7iA== 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=gIVDR/J+zm+08qV6ROqjaoKgq3EyMif8A1yzpOg4O1U=; b=D672MlrAY8phAutfPskZI+C2x3w0nBqvGLW5USwOS9GXbYeP6os7mGSi+72s08AJwX T1E+hhByGleuTbYn64JwFVkkc0UGKu3pfo9Ksz/sxpBev3M/1JuwuSpWBcNDULOxy/6M 1fWcu4uuXZ7uQPljv5b8OyO+jeOz/fInfv/T7k9HQeN+cOOtTrwXS0aVCkEc3prVcGDw JmpI6odAD8CMj8/DwzA+qhEWUeEfylCYoQKNFtMA2g3p5p4awHU6elkZ3t0IxonfMaOM elQASx4UcDMvQ6+2bzq52wE6mfXzejfZKSep9XRfBZ5m3qmnsQ73Wslk2NUZsBoCky3a sIHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fI3cURfx; 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 w10-20020a170902d70a00b001568ce587edsi11703836ply.549.2022.04.06.07.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 07:53:28 -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=fI3cURfx; 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 4E3565933D9; Wed, 6 Apr 2022 05:45:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1451705AbiDEWag (ORCPT + 99 others); Tue, 5 Apr 2022 18:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238653AbiDEJwx (ORCPT ); Tue, 5 Apr 2022 05:52:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F1744991A; Tue, 5 Apr 2022 02:50:55 -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 AFDB3B817D3; Tue, 5 Apr 2022 09:50:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16133C385A1; Tue, 5 Apr 2022 09:50:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152252; bh=cxIlbeMDmUc/aVrFTc+t0g8Jo+ZFlW+CNDEk4hZ16Io=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fI3cURfxOKzPq+kR3EwB5eYqs1pOK4dhU3c9MMjJCtQqwMTetRGX4jZFedYgK0euY o92rcf1HnBg5R/mbXKCjQANZ8kRJgQgCS5TgATcNpwY1HlhFu4m6L/EBuikTyjMeCV U0JlfHOjZYuf3G7n6fg7a6nrFyEqaCz0jfkvqNSg= 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.15 711/913] ext4: correct cluster len and clusters changed accounting in ext4_mb_mark_bb Date: Tue, 5 Apr 2022 09:29:33 +0200 Message-Id: <20220405070401.147664169@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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 74e3286d0e26..9a749327336f 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