From nobody Sun Feb 8 13:32:45 2026 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 980091AAE13 for ; Fri, 19 Dec 2025 12:40:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766148055; cv=none; b=cD2LY2u/2PbYDnkCPBVPMGYwy9g1tlGmIMPogfBOaVUWEfftoBWDAcTfENZrJv/Snue8SyF8qPKxspRk/basrmEVoreZmWZkq+QxOTS8oh+bbwnd95ibE9ZsymzlLoIf0/1r5BZEwvBApWypP3nelGhWrQCqlPewTMiR4v7Bkgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766148055; c=relaxed/simple; bh=9Lbjg60mV6ELzUjAeBc1k0iW0FLYQFX11lyiNpWJAv0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type: References; b=OgYYkpetncpHm+HZ1a7q/+W+6Vs+ddunPaMps1T4r3nRvxULz2sN1fKcDixYzgYq1W3qrYPYa9Wsi06F7zH0ghHsnhpvlENXwaM5PSZ3XU8BLqNiLrePjClt6P7hzxY68v6SRKyHlOQytTgjU+0o1CB/KGFxNQBpPA91VjNIgkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=uP1LZs4W; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="uP1LZs4W" Received: from epcas1p3.samsung.com (unknown [182.195.41.47]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20251219124045epoutp03632446383cabfad634aa694a1a3d54df~Cnko2Kyg31569615696epoutp03v for ; Fri, 19 Dec 2025 12:40:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20251219124045epoutp03632446383cabfad634aa694a1a3d54df~Cnko2Kyg31569615696epoutp03v DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1766148045; bh=jMDcKQ9i6N+1e+bXvO2dHhPmBoF8oPQlpRZ6OtKYHpE=; h=From:To:Cc:Subject:Date:References:From; b=uP1LZs4WnnbhlA8C+a3q3yqbvuNDWe3HBAxjgxZsLCatucoI8EkJLVQy8pVf3Y0ww 9LfIiGnqk7WjPuKmA3akBWiLbCgbd065UR3s1g7uVxO/bx6MuVv/e6G5ctwWhR42eV mS1o9hpyuoVtCY1FhxY2B/njbDyo02Ism3v3Ch44= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPS id 20251219124044epcas1p476be6abc6c9af383dbc8890a9d13b57e~CnkoYAh-I0384603846epcas1p4q; Fri, 19 Dec 2025 12:40:44 +0000 (GMT) Received: from epcas1p2.samsung.com (unknown [182.195.38.115]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dXnFS5DRVz3hhT7; Fri, 19 Dec 2025 12:40:44 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20251219124044epcas1p3df48558b10b0540c2ea1ec65779c261d~Cnknu9BCT2398323983epcas1p3R; Fri, 19 Dec 2025 12:40:44 +0000 (GMT) Received: from junbeom.yeom (unknown [10.253.99.78]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251219124044epsmtip13b608729c8bb9b8f4cdab1cef393a8b7~CnknsFj5O2626826268epsmtip14; Fri, 19 Dec 2025 12:40:44 +0000 (GMT) From: Junbeom Yeom To: xiang@kernel.org, chao@kernel.org Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Junbeom Yeom , stable@vger.kernel.org, Jaewook Kim , Sungjong Seo Subject: [PATCH v2] erofs: fix unexpected EIO under memory pressure Date: Fri, 19 Dec 2025 21:40:31 +0900 Message-Id: <20251219124031.2731710-1-junbeom.yeom@samsung.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CMS-MailID: 20251219124044epcas1p3df48558b10b0540c2ea1ec65779c261d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 101P cpgsPolicy: CPGSC10-711,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20251219124044epcas1p3df48558b10b0540c2ea1ec65779c261d References: erofs readahead could fail with ENOMEM under the memory pressure because it tries to alloc_page with GFP_NOWAIT | GFP_NORETRY, while GFP_KERNEL for a regular read. And if readahead fails (with non-uptodate folios), the original request will then fall back to synchronous read, and `.read_folio()` should return appropriate errnos. However, in scenarios where readahead and read operations compete, read operation could return an unintended EIO because of an incorrect error propagation. To resolve this, this patch modifies the behavior so that, when the PCL is for read(which means pcl.besteffort is true), it attempts actual decompression instead of propagating the privios error except initial EIO. - Page size: 4K - The original size of FileA: 16K - Compress-ratio per PCL: 50% (Uncompressed 8K -> Compressed 4K) [page0, page1] [page2, page3] [PCL0]---------[PCL1] - functions declaration: . pread(fd, buf, count, offset) . readahead(fd, offset, count) - Thread A tries to read the last 4K - Thread B tries to do readahead 8K from 4K - RA, besteffort =3D=3D false - R, besteffort =3D=3D true pread(FileA, buf, 4K, 12K) do readahead(page3) // failed with ENOMEM wait_lock(page3) if (!uptodate(page3)) goto do_read readahead(FileA, 4K, 8K) // Here create PCL-chain like below: // [null, page1] [page2, null] // [PCL0:RA]-----[PCL1:RA] ... do read(page3) // found [PCL1:RA] and add page3 into it, // and then, change PCL1 from RA to R ... // Now, PCL-chain is as below: // [null, page1] [page2, page3] // [PCL0:RA]-----[PCL1:R] // try to decompress PCL-chain... z_erofs_decompress_queue err =3D 0; // failed with ENOMEM, so page 1 // only for RA will not be uptodated. // it's okay. err =3D decompress([PCL0:RA], err) // However, ENOMEM propagated to next // PCL, even though PCL is not only // for RA but also for R. As a result, // it just failed with ENOMEM without // trying any decompression, so page2 // and page3 will not be uptodated. ** BUG HERE ** --> err =3D decompress([PCL1:R], err) return err as ENOMEM ... wait_lock(page3) if (!uptodate(page3)) return EIO <-- Return an unexpected EIO! ... Fixes: 2349d2fa02db ("erofs: sunset unneeded NOFAILs") Cc: stable@vger.kernel.org Reviewed-by: Jaewook Kim Reviewed-by: Sungjong Seo Signed-off-by: Junbeom Yeom Reviewed-by: Gao Xiang --- v2: - If disk I/Os are successful, handle to decompress each pcluster. fs/erofs/zdata.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 27b1f44d10ce..70e1597dec8a 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1262,7 +1262,7 @@ static int z_erofs_parse_in_bvecs(struct z_erofs_back= end *be, bool *overlapped) return err; } =20 -static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, int err) +static int z_erofs_decompress_pcluster(struct z_erofs_backend *be, bool ei= o) { struct erofs_sb_info *const sbi =3D EROFS_SB(be->sb); struct z_erofs_pcluster *pcl =3D be->pcl; @@ -1270,7 +1270,7 @@ static int z_erofs_decompress_pcluster(struct z_erofs= _backend *be, int err) const struct z_erofs_decompressor *alg =3D z_erofs_decomp[pcl->algorithmformat]; bool try_free =3D true; - int i, j, jtop, err2; + int i, j, jtop, err2, err =3D eio ? -EIO : 0; struct page *page; bool overlapped; const char *reason; @@ -1413,12 +1413,12 @@ static int z_erofs_decompress_queue(const struct z_= erofs_decompressqueue *io, .pcl =3D io->head, }; struct z_erofs_pcluster *next; - int err =3D io->eio ? -EIO : 0; + int err =3D 0; =20 for (; be.pcl !=3D Z_EROFS_PCLUSTER_TAIL; be.pcl =3D next) { DBG_BUGON(!be.pcl); next =3D READ_ONCE(be.pcl->next); - err =3D z_erofs_decompress_pcluster(&be, err) ?: err; + err =3D z_erofs_decompress_pcluster(&be, io->eio) ?: err; } return err; } --=20 2.34.1