From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=113.46.200.217 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796002895; b=TcR5DHgYHVbLjHCnh07TuWXWLGBNA2s0GEfdEBQ/lqPp9WipOw/3t5EtqKDbMto/Ozkb KDQ3muReKzFAsOtGRoyJ3+NvP7HCof3UzQJ6n10brSdcnbQXQ2PYaGF5HbDlPX6YUBB+M 7JjU7Gh/nTg9VEkKCCatO95KL7/rZCHgtfwxKhRmV51oD2yQ0JmUD9PhLWgyHOpYkCGEd +v7gpcxD2fsu6fkJVDolBfxhi/+PBxrlxHV84mMehZBoYrYD4y6JPziO4ce8tgLklNA1f Kv0qwES2QsTL8DVOgTl/EshnSVHMf+jnNHu4cC85XSCl8F4N8Q88iQ6LmiA27PyWZ9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002895; h=DMARC-Filter:dkim-signature:Received:Received:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:CC:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding:X-Originating-IP: X-ClientProxiedBy; bh=ZcW9XphLJ9R6xc0VOW8Oe7e4hfE7EQaDfiymZnUowDY=; b=El85TpkS6WmwiCLs0Gcqe3Z3zNC0bv4lA7/+1cMkxDi2t6AWg+BODfjfw6SI3a9GhHfW 9G9RORA6nW3EGf1attOV+RB2TdKiB5NVnlePUz4WEbPx5ZNDKavQgdejyb8wWk5994dzX 9xCIX1oKDq8haZYg8nS++Rn+AjCEOfBvnO8kDa0O/unAVhHmHhV+Ng6c9SBKVGi396bFo DTUfgjs6d/olGVqTeffWio3gdKaJpo6vTJRlaPdoOr8Oef0LBAwjfkbF3kGV5uKUVjnog H9lDqPr/YzWnwLagu2D8MWHgP0GOsxomyp+9ByKYliRjAayd1+ox+KGUTMRn6Xan5rA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=wpqxcw47; arc=none smtp.remote-ip=113.46.200.217 Received: from canpmsgout02.his.huawei.com (canpmsgout02.his.huawei.com [113.46.200.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC85F606A31C for ; Mon, 30 Nov 2026 01:41:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CC85F606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.a=rsa-sha256 header.s=dkim header.b=wpqxcw47 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=ZcW9XphLJ9R6xc0VOW8Oe7e4hfE7EQaDfiymZnUowDY=; b=wpqxcw47lkwiWBwofuCzro4YCn/HqYvZXhSzuWCQ/VA4AIn4KxoIF7Ynh3XkbfT1ncRZU+L+j Xf/ieA9WWHoAui2K6X7x22yuS4naUyOxxaSh28PhSzguVBpdJY4ZG+NquQQpTZ1ZgGzZJxkwHsh QyPrff9ax90AP7EoPrUD70I= Received: from mail.maildlp.com (unknown [172.19.163.104]) by canpmsgout02.his.huawei.com (SkyGuard) with ESMTPS id 4jd6CY69tZzcZxm; Mon, 30 Nov 2026 09:40:09 +0800 (CST) Received: from whupemo200011.china.huawei.com (unknown [7.152.185.179]) by mail.maildlp.com (Postfix) with ESMTPS id E7C2A4056E; Mon, 30 Nov 2026 09:41:23 +0800 (CST) Received: from [10.174.177.171] (10.174.177.171) by whupemo200011.china.huawei.com (7.152.185.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.56; Mon, 30 Nov 2026 09:41:22 +0800 Message-ID: Date: Mon, 30 Nov 2026 09:41:21 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ubifs: Bound lpt_gc() retries when LPT GC makes no progress To: , Richard Weinberger CC: , , References: <20261124-lpt-gc-send-v1-1-eb975487c6d5@tantalus.com> From: Zhihao Cheng In-Reply-To: <20261124-lpt-gc-send-v1-1-eb975487c6d5@tantalus.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To whupemo200011.china.huawei.com (7.152.185.179) 在 2026/11/25 4:39, Devin Armstrong via B4 Relay 写道: > From: Devin Armstrong > > ubifs_lpt_start_commit() and ubifs_lpt_post_commit() call lpt_gc() in a > "while (need_write_all(c))" loop. If lpt_gc_lnum() cannot dirty every > node of the LEB it was given, that LEB's free + dirty space never > reaches leb_size, need_write_all() keeps returning 1, lpt_gc() keeps > selecting the same LEB, and the loop never ends. > > One way to get there is the LPT scanning problem reported in the link > below: the 0xff padding at the end of an LPT commit followed by the > first bytes of the next commit's lsave node can form a valid-looking > node (the 16-bit CRC matches by chance). When this happens, a read-write > mount or remount spins in the kernel at 100% CPU and can't be killed. > Read-only mounts never commit, so they are not affected. > > Track the LEB and its dirty space selected by lpt_gc() in the caller's > loop. If the same LEB is selected UBIFS_LPT_GC_MAX_RETRIES times in a > row with unchanged dirty space, return -EUCLEAN. Any pass that makes > progress changes the dirty space and restarts the count, so the normal > GC retry cycle is unaffected. > > The error makes the commit fail, which puts UBIFS in read-only mode, so > the mount or remount fails with an error instead of hanging. This does > not repair the LPT, it only turns an endless loop into a failure. > > Link: https://lore.kernel.org/linux-mtd/97ca7fe4-4ad4-edd1-e97a-1d540aeabe2d@huawei.com/ > > Signed-off-by: Devin Armstrong > --- > Tested on a v7.0 based kernel (out-of-tree ubifs.ko built with this patch). > Remounting a volume with the linked issue as read-write now fails > immediately with -EUCLEAN and UBIFS goes read-only, instead of spinning > in the kernel. > > Also tested on a 4.19 based kernel on SPI NOR hardware with the same result. > > On a healthy volume, 2 million commits of mixed xattr/utime workload > showed no change in behavior and no "LPT GC" errors. > --- > fs/ubifs/lpt_commit.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 47 insertions(+), 4 deletions(-) Looks good to me. Reviewed-by: Zhihao Cheng And please add the fix tag which is suggested by sashiko. > > diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c > index f2cb214581..1e583f070c 100644 > --- a/fs/ubifs/lpt_commit.c > +++ b/fs/ubifs/lpt_commit.c > @@ -1140,14 +1140,39 @@ static int lpt_gc_lnum(struct ubifs_info *c, int lnum) > return 0; > } > > +/* > + * Maximum number of times in a row 'lpt_gc()' may select the same LPT LEB > + * without its dirty space changing, before LPT GC is considered stuck. > + */ > +#define UBIFS_LPT_GC_MAX_RETRIES 10 > + > +/** > + * struct lpt_gc_leb_retry - state for detecting LPT GC that makes no progress. > + * @lnum: LEB selected by the previous 'lpt_gc()' call (-1 if none) > + * @dirty: dirty space of @lnum when it was selected > + * @count: number of consecutive times @lnum was selected with @dirty unchanged > + * > + * The caller keeps this on its stack for the duration of its GC loop. > + */ > +struct lpt_gc_leb_retry { > + int lnum; > + int dirty; > + int count; > +}; > + > /** > * lpt_gc - LPT garbage collection. > * @c: UBIFS file-system description object > + * @retry: LPT GC progress tracking, see 'struct lpt_gc_leb_retry' > * > * Select a LPT LEB for LPT garbage collection and call 'lpt_gc_lnum()'. > + * If the same LEB keeps being selected and its dirty space does not change, > + * the LPT is damaged and collecting it again cannot help, so give up instead > + * of looping forever. > + * > * Returns %0 on success and a negative error code on failure. > */ > -static int lpt_gc(struct ubifs_info *c) > +static int lpt_gc(struct ubifs_info *c, struct lpt_gc_leb_retry *retry) > { > int i, lnum = -1, dirty = 0; > > @@ -1165,6 +1190,19 @@ static int lpt_gc(struct ubifs_info *c) > mutex_unlock(&c->lp_mutex); > if (lnum == -1) > return -ENOSPC; > + > + if (lnum == retry->lnum && dirty == retry->dirty) { > + if (++retry->count >= UBIFS_LPT_GC_MAX_RETRIES) { > + ubifs_err(c, "LPT GC of LEB %d made no progress after %d attempts", > + lnum, retry->count); > + return -EUCLEAN; > + } > + } else { > + retry->count = 0; > + } > + retry->lnum = lnum; > + retry->dirty = dirty; > + > return lpt_gc_lnum(c, lnum); > } > > @@ -1193,6 +1231,8 @@ int ubifs_lpt_start_commit(struct ubifs_info *c) > goto out; > > if (c->check_lpt_free) { > + struct lpt_gc_leb_retry retry = { .lnum = -1 }; > + > /* > * We ensure there is enough free space in > * ubifs_lpt_post_commit() by marking nodes dirty. That > @@ -1202,7 +1242,7 @@ int ubifs_lpt_start_commit(struct ubifs_info *c) > c->check_lpt_free = 0; > while (need_write_all(c)) { > mutex_unlock(&c->lp_mutex); > - err = lpt_gc(c); > + err = lpt_gc(c, &retry); > if (err) > return err; > mutex_lock(&c->lp_mutex); > @@ -1315,14 +1355,17 @@ int ubifs_lpt_post_commit(struct ubifs_info *c) > err = lpt_tgc_end(c); > if (err) > goto out; > - if (c->big_lpt) > + if (c->big_lpt) { > + struct lpt_gc_leb_retry retry = { .lnum = -1 }; > + > while (need_write_all(c)) { > mutex_unlock(&c->lp_mutex); > - err = lpt_gc(c); > + err = lpt_gc(c, &retry); > if (err) > return err; > mutex_lock(&c->lp_mutex); > } > + } > out: > mutex_unlock(&c->lp_mutex); > return err; > > --- > base-commit: a5e0055eac837a1168c781653943d4a0d9920af3 > change-id: 20261124-lpt-gc-send-3ea0fe326e70 > > Best regards,