Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp704549pxb; Tue, 5 Apr 2022 19:32:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+9/4Mp7ZroopK/QZxrBf7lahYPEn8ivCdi/VmfrxxEwP1TTO6gR9eDOEHgcrYsdSacCE6 X-Received: by 2002:a65:5083:0:b0:382:3b02:9799 with SMTP id r3-20020a655083000000b003823b029799mr5438605pgp.302.1649212373439; Tue, 05 Apr 2022 19:32:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649212373; cv=none; d=google.com; s=arc-20160816; b=dLxGhjKjMHjS2UyEZlQhgMYSp34HMWqQA99MMkhsknnUR+LiKuAi6tll/PVA7VIWCK esxW9pFhB9pC/3kbXr1fMZWbrn3KExRlqFjHtU3CEzGuX7W1kc/Dwb9HR6RD3+jCIun5 WVyhI9tY6+XNSJFRx4PKBGSyQdDjqmDkqApi4KZFaNMHCfw9zJVKxnsTzzQsSGOy2uP0 1aYPnDHHX7d8qmPPFdk4TfIU93kOFQyRIfZ56RWdhYYvIgX73SXjtyGWHmfO9myruqj6 N0kNi+BG2TH60PFy3YMxAsPWCsrE3JlUgzsmikHMz6JMkfVtBfRCQy86eNQ83ccvUp0y 1bwg== 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=6g71XmzOlZ62qW5fDS96WWuPJdVP9zhgt55HtCOm+NM=; b=TUruzOrzUjt0XBWYPbhj28luiiRnUj21qpCpcgujM3j/TPTnbDs8p1O4rKDAbQejaV xGoD1eZPFUN47KVkXzQc6ej5pPHW2hlj0jxk9fjdaHUC5iYMcfOaLIEBk1+WN1SuVlCz wThf95sKL9NcBBRVF+LA7Io0wcp/zH4YAiCcOLQNj2lCyfhggCgRw4mBobDBc9vXxJ8E fqv6yj0kpAkt8gmN00hKkqJC5IWo9/vv+oZQm7K0v4Rt7cHnA58L67K0DJTxDp5SBvUb XbQo9GpfD0PZqUTjBK1AQRYLg0QIt65hSCfCzglvDe26pklXv7o8bS+Za3P1x88/Xc88 hdFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JsnnVA7J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r11-20020a17090aa08b00b001bfb0db0879si3270941pjp.88.2022.04.05.19.32.38; Tue, 05 Apr 2022 19:32:53 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JsnnVA7J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244541AbiDEJl2 (ORCPT + 99 others); Tue, 5 Apr 2022 05:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239842AbiDEIVF (ORCPT ); Tue, 5 Apr 2022 04:21:05 -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 2910CE41; Tue, 5 Apr 2022 01:19:08 -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 D7595B81B92; Tue, 5 Apr 2022 08:19:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 393DEC385A1; Tue, 5 Apr 2022 08:19:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146745; bh=JLGEI5VU07W1DBK8iHJcfnKy6qqnAle1Lo81C0XR89o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JsnnVA7JOmc9+FI3LzFjOsqNuRGtrRPqIVil/tExG9qygKN6fWTIZ14Dd8+oc1nb9 +N0Il7I5w24DZ3fl4IzQKuYzCiKKKAWrct2wfNMR68jqsyz5M1KSZOpEEgJuUV0rSO SBT7MR1pyH/0bhOQpAa9Bypj8DKOreSGC1QdOeto= 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.17 0872/1126] ext4: correct cluster len and clusters changed accounting in ext4_mb_mark_bb Date: Tue, 5 Apr 2022 09:26:59 +0200 Message-Id: <20220405070433.132870927@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 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 f9be6ab482a5..eac21e2b1132 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