From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC19E277026; Sat, 17 Oct 2026 16:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256051; cv=none; b=MW1WSRlrq9E+O4rhysMW70D2yyyGokYloTozy4tDGWaU6CXbYLeexMoihf7FlR6OVMpbmW1gY2I+Rdyddr1gXcJ6hrPJipQAbUnley/O8eUfvWrgT1gD/Jdgv5NtOSo0c7F3NTmYp/tKlEhJVvMcl10ZID4KFtxTw4Jofg/zZXw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256051; c=relaxed/simple; bh=ODply0LUWcFngzJozGdCz1CYNsyKGwjpBVHZPJ6s24c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UOwbZ+J556N/giSGFGN2tEzQZEQwEMGq3c9hNBMDwR6sdG/+cFO15hplXWv7zfqm1NVaxcQ+/bdLFC1aOMe+t+HRETvcVS5NzC/1Lcul8YbskcLWddOn1/5Xim3sKfOeIjdm6M1gwrJsZqfxEpNZxPjnbLf9Z1MN36DHywxBbHY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=zgq3Fxna; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="zgq3Fxna" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B3DA31F000C4; Sat, 17 Oct 2026 16:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256050; bh=s+Rz0bDtK70LhPdj0/VCL6L2DP7qeKcz8BNg4gsuNdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zgq3FxnaaBjVoofZl1PYpz/7JdSuJ+Lab6ruvnC9VHo8Tb5dMa6IRzuAbFxZapt3Z 90XYDY+t1I40Onoueed3SyC5p4uNkq6uZAk59cx+gUI3XoHBKE+j5jb0jBS5bwEjIY 1vu8qnQ3tfXBgHJrnCpXaSKm0+XzENm/8VzM5fmY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nikhil Gurudasani , Gao Xiang , Sasha Levin Subject: [PATCH 6.6 0107/1674] erofs: preserve LZMA decoders on resize failure Date: Sat, 17 Oct 2026 17:39:39 +0200 Message-ID: <20261017160433.895197156@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikhil Gurudasani [ Upstream commit 617d0d8d199ba1790c94310fd75a22d01c97a8d6 ] The pool-resize path frees each stream's old decoder before allocating its replacement. If an allocation fails after some streams have already been replaced, the failed stream is put back on the list with state == NULL. z_erofs_lzma_max_dictsize is still advanced as if the whole pool had been resized. An existing LZMA mount can select the broken stream and pass NULL to xz_dec_microlzma_reset(). A retry at the same size also skip another resize attempt. Since the global maximum was advanced, thus, the invalid state is left unrepaired. Allocate each replacement before freeing the old decoder, temporarily retaining one old decoder during allocation. Stop at the first failure and advance z_erofs_lzma_max_dictsize only after all streams satisfy the request. Record each stream's dictionary capacity so retries can skip streams already enlarged before a partial failure. Fixes: 622ceaddb764 ("erofs: lzma compression support") Cc: stable@vger.kernel.org Signed-off-by: Nikhil Gurudasani Reviewed-by: Gao Xiang Signed-off-by: Gao Xiang [ Retained the existing `struct xz_buf buf` member alongside the new `dict_size` field. ] Signed-off-by: Sasha Levin --- fs/erofs/decompressor_lzma.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/erofs/decompressor_lzma.c b/fs/erofs/decompressor_lzma.c index 613fe99cf629f..0ea93a7b7a4ea 100644 --- a/fs/erofs/decompressor_lzma.c +++ b/fs/erofs/decompressor_lzma.c @@ -6,6 +6,7 @@ struct z_erofs_lzma { struct z_erofs_lzma *next; struct xz_dec_microlzma *state; + unsigned int dict_size; struct xz_buf buf; u8 bounce[PAGE_SIZE]; }; @@ -132,11 +133,19 @@ int z_erofs_load_lzma_config(struct super_block *sb, err = 0; /* 2. walk each isolated stream and grow max dict_size if needed */ for (strm = head; strm; strm = strm->next) { + struct xz_dec_microlzma *state; + + if (strm->dict_size >= dict_size) + continue; + state = xz_dec_microlzma_alloc(XZ_PREALLOC, dict_size); + if (!state) { + err = -ENOMEM; + break; + } if (strm->state) xz_dec_microlzma_end(strm->state); - strm->state = xz_dec_microlzma_alloc(XZ_PREALLOC, dict_size); - if (!strm->state) - err = -ENOMEM; + strm->state = state; + strm->dict_size = dict_size; } /* 3. push back all to the global list and update max dict_size */ @@ -146,7 +155,8 @@ int z_erofs_load_lzma_config(struct super_block *sb, spin_unlock(&z_erofs_lzma_lock); wake_up_all(&z_erofs_lzma_wq); - z_erofs_lzma_max_dictsize = dict_size; + if (!err) + z_erofs_lzma_max_dictsize = dict_size; mutex_unlock(&lzma_resize_mutex); return err; } -- 2.53.0