From 8497f46a873656ba8c6f79895d70107e2d6ac9d0 Mon Sep 17 00:00:00 2001 From: sunshijie Date: Mon, 21 Aug 2023 21:00:15 +0800 Subject: [PATCH] UPSTREAM: erofs: avoid useless loops in z_erofs_pcluster_readmore() when reading beyond EOF z_erofs_pcluster_readmore() may take a long time to loop when the page offset is large enough, which is unnecessary should be prevented. For example, when the following case is encountered, it will loop 4691368 times, taking about 27 seconds: - offset = 19217289215 - inode_size = 1442672 Signed-off-by: Chunhai Guo Fixes: 386292919c25 ("erofs: introduce readmore decompression strategy") Reviewed-by: Gao Xiang Reviewed-by: Yue Hu Reviewed-by: Chao Yu Link: https://lore.kernel.org/r/20230710042531.28761-1-guochunhai@vivo.com Signed-off-by: Gao Xiang (cherry picked from commit 936aa701d82d397c2d1afcd18ce2c739471d978d https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev) Bug: 296824280 Change-Id: I279b0fadcfa8c0ff0d638a86c7bb2c6b4d07f194 Signed-off-by: sunshijie Signed-off-by: sunshijie --- fs/erofs/zdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index e9a07ac7bb26..01c1ab655277 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1691,7 +1691,7 @@ static void z_erofs_pcluster_readmore(struct z_erofs_decompress_frontend *f, } cur = map->m_la + map->m_llen - 1; - while (cur >= end) { + while ((cur >= end) && (cur < i_size_read(inode))) { pgoff_t index = cur >> PAGE_SHIFT; struct page *page;