Received: by 2002:a05:7412:a9a3:b0:f9:327e:43ab with SMTP id o35csp164179rdh; Mon, 18 Dec 2023 07:16:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IF403cbS+b6OJu32sOC+cn+2nPLmX4m3F3Vb/XymlaPo0zWT9BYebU4fXF8g2447XOjO9Jr X-Received: by 2002:ac8:4e4f:0:b0:423:f6b7:fd82 with SMTP id e15-20020ac84e4f000000b00423f6b7fd82mr27263533qtw.34.1702912571325; Mon, 18 Dec 2023 07:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702912571; cv=none; d=google.com; s=arc-20160816; b=Y9fh8Xq6vGLxJ5UJ5WBlZvW19fz8Zy2rZkwqAKqVExRNmePt9BmK1mkHhi7pTcRHvR UDjzh7eNil/VD9q4bMAGTXhvdUDYah++3DllTqrYSTYbKhXpHOK0lI0kgOXwxq5Usr/7 BMV+aYvDC2m+rJySulJwHB3UM3MLzvw95wumgc01ea3Cs9AHrZd3SFEnAB6Hu+an2Rgt CvraHnY/nblyolTh0mcvGWKVS+jquOhIszE0vT9C8sim1UKG5fh08dI5JqEYHBMsLfhY 9AsJdg1NhThqc/nl2jIK6T7bKZJRo9vJrlWj8vLgObk5O6hpXPh//vPLmUxlC2M7Utbo DX/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=+cm4PMMqFmVathp7mybQaRO8gVagPOtZ+MpnGlv1cXU=; fh=TFc7OJl2g/oa1GtWT2xRhZwnEOCA6XcX46Kq3QR5Nto=; b=vqzx9xVHY0/RFtBpEr0JP0FAscOvFhIEfu4fK4xacBaqqWm67nKATuYSM90FQGtNmL weFjqzXxN+5gkdfIPeRSCHOfXoiO5ewZ0oB+moW6moC0Z47A1zZp2UONJRBy/glhT4gh 2N0QL5f9fBvjHfZNIHp0xQ3rBYEKVTBZqvRauO0RMK4uIxhPRKwgAXDmPD1zJMkQvCEb /J9sLkdVIyUdf1ZImoGbjYhyMW+/jn/Z1Lq0+/zcB6oj4+yNPdM47wLveScO8BBCnrzV 3XE00jFehoVzkc1eJ0+S4ChwTgG3CZ1BjSKX3atf/AuW2E4awlGPj5F8CAquq0HGDoaS mpEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=l5Ca33k+; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=xsNnaOhy; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vjwRspq7; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4+bounces-497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-497-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id e15-20020a05622a110f00b00425f146bdb7si13044001qty.613.2023.12.18.07.16.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:16:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=l5Ca33k+; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=xsNnaOhy; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vjwRspq7; dkim=neutral (no key) header.i=@suse.cz; spf=pass (google.com: domain of linux-ext4+bounces-497-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-497-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5630E1C23575 for ; Mon, 18 Dec 2023 15:16:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5831C498B6; Mon, 18 Dec 2023 15:15:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="l5Ca33k+"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="xsNnaOhy"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="vjwRspq7"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="a0gdTFNl" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3E56F49890; Mon, 18 Dec 2023 15:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0482421E0D; Mon, 18 Dec 2023 15:14:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702912497; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+cm4PMMqFmVathp7mybQaRO8gVagPOtZ+MpnGlv1cXU=; b=l5Ca33k+JhYUsjq1pc4mJyNHCOiPfevvqobkUCWIrNfy0oCW6WA1OVnBijQP5v9kc5QeAW N/ZF1IxYlnWV/EkZR/k9xfw+j6WeoHJU7hTt5LtZmnYulNliHccHFIV0CW4/Z/y4p4yeXu y1wedumAsRe9AiH0Ufo1II5aIFieORc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702912497; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+cm4PMMqFmVathp7mybQaRO8gVagPOtZ+MpnGlv1cXU=; b=xsNnaOhydrtNCt0dRF1Mv+sJ5G0Wkj6Cl6jfUkWB1s7bf7gkCP8YQYrtoNBAWKB87CtK1y IgnYC/HmJx53/OAg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702912496; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+cm4PMMqFmVathp7mybQaRO8gVagPOtZ+MpnGlv1cXU=; b=vjwRspq7HpGM/ahbEvab+2ey5t7yWRduEh8THIkXUo9jisr6NH321IjTl1KHWyi7rCrK3A 5RpKkBMnjAjL/xAvUbaFiUdnVYCuDkpa4uFFpMqpnFSJf/3DyKqv1Jm9BO27d9OHY0Z8yP nVy+TRHCv7hjsOcT0ZBz4/+w/WupLHE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702912496; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+cm4PMMqFmVathp7mybQaRO8gVagPOtZ+MpnGlv1cXU=; b=a0gdTFNlGs7CNz+hZtRVZBDbdmUUpuSR2bFG7dhpVzxVQ88zmanXide4VZ0fub9k+OGoZV a9UHVp9ArJS9bhDA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id D6D7013927; Mon, 18 Dec 2023 15:14:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id yypvNO9hgGX7eAAAn2gu4w (envelope-from ); Mon, 18 Dec 2023 15:14:55 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 36F40A07E0; Mon, 18 Dec 2023 16:14:55 +0100 (CET) Date: Mon, 18 Dec 2023 16:14:55 +0100 From: Jan Kara To: Baokun Li Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, yukuai3@huawei.com, stable@vger.kernel.org Subject: Re: [PATCH 3/4] ext4: avoid bb_free and bb_fragments inconsistency in mb_free_blocks() Message-ID: <20231218151455.yqph44iz4ihsujz5@quack3> References: <20231218141814.1477338-1-libaokun1@huawei.com> <20231218141814.1477338-4-libaokun1@huawei.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231218141814.1477338-4-libaokun1@huawei.com> X-Spam-Level: Authentication-Results: smtp-out1.suse.de; none X-Spam-Level: X-Spam-Score: 0.70 X-Spamd-Result: default: False [0.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCPT_COUNT_SEVEN(0.00)[11]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,huawei.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; FREEMAIL_CC(0.00)[vger.kernel.org,mit.edu,dilger.ca,suse.cz,gmail.com,huawei.com]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Flag: NO On Mon 18-12-23 22:18:13, Baokun Li wrote: > After updating bb_free in mb_free_blocks, it is possible to return without > updating bb_fragments because the block being freed is found to have > already been freed, which leads to inconsistency between bb_free and > bb_fragments. > > Since the group may be unlocked in ext4_grp_locked_error(), this can lead > to problems such as dividing by zero when calculating the average fragment > length. Therefore, to ensure consistency, move the update of bb_free to > after the block double-free check. > > Fixes: eabe0444df90 ("ext4: speed-up releasing blocks on commit") > CC: stable@vger.kernel.org # 3.10 > Signed-off-by: Baokun Li I agree there's no point in updating the allocation info if the bitmap is corrupted. We will not try to allocate (or free) blocks in that group anymore. I'm just a bit unsure about the EXT4_FC_REPLAY state where we don't mark the bitmap as corrupted although some blocks were already marked as freed. So in this case the free space statistics tracking will go permanently wrong. I'm kind of wondering in which case does fast-commit free already freed blocks. Ted, any idea? Honza > --- > fs/ext4/mballoc.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index a95fa6e2b0f9..2fbee0f0f5c3 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -1892,11 +1892,6 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, > mb_check_buddy(e4b); > mb_free_blocks_double(inode, e4b, first, count); > > - this_cpu_inc(discard_pa_seq); > - e4b->bd_info->bb_free += count; > - if (first < e4b->bd_info->bb_first_free) > - e4b->bd_info->bb_first_free = first; > - > /* access memory sequentially: check left neighbour, > * clear range and then check right neighbour > */ > @@ -1922,9 +1917,14 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, > sb, e4b->bd_group, > EXT4_GROUP_INFO_BBITMAP_CORRUPT); > } > - goto done; > + return; > } > > + this_cpu_inc(discard_pa_seq); > + e4b->bd_info->bb_free += count; > + if (first < e4b->bd_info->bb_first_free) > + e4b->bd_info->bb_first_free = first; > + > /* let's maintain fragments counter */ > if (left_is_free && right_is_free) > e4b->bd_info->bb_fragments--; > @@ -1949,7 +1949,6 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, > if (first <= last) > mb_buddy_mark_free(e4b, first >> 1, last >> 1); > > -done: > mb_set_largest_free_order(sb, e4b->bd_info); > mb_update_avg_fragment_size(sb, e4b->bd_info); > mb_check_buddy(e4b); > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR