* [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy @ 2026-03-22 6:03 Ajay Rajera 2026-03-22 7:26 ` Nithurshen 0 siblings, 1 reply; 5+ messages in thread From: Ajay Rajera @ 2026-03-22 6:03 UTC (permalink / raw) To: linux-erofs, xiang; +Cc: Ajay Rajera erofs_io_xcopy() has a fallback loop for when the kernel fast-paths (copy_file_range/sendfile) do not handle all the data. When erofs_io_read() returned 0 (source exhausted before all bytes were copied), the old logic checked `ret < 0` and `ret > 0`, ignoring `0`. Since `len -= 0` is a no-op, the loop would spin forever at 100% CPU with no progress. v2 fixed the loop but unconditionally trapped a 0-byte read by returning -EIO. However, if copy_file_range completely exhausts the bytes, `len` becomes 0. The do-while loop was then forced to execute once, making a 0-byte read, which returned 0. v2 falsely trapped this success as an -EIO error, causing mkfs.erofs to fail in CI. Fix this regression by replacing `do-while(len)` with a standard `while(len)` loop. This safely bypasses the block if `len` is 0 (avoiding fake -EIO errors), while correctly catching premature EOFs with -EIO. Also fix the 'pading' -> 'padding' typo in erofs_dev_read(). Signed-off-by: Ajay Rajera <newajay.11r@gmail.com> --- v3: Replace do-while loop to avoid 0-byte read -EIO regression. v2: Return -EIO instead of -ENODATA, use cleaner if/else. --- lib/io.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/io.c b/lib/io.c index 583f52d..ae6a600 100644 --- a/lib/io.c +++ b/lib/io.c @@ -660,22 +660,22 @@ int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos, #endif } - do { + while (len) { char buf[32768]; int ret = min_t(unsigned int, len, sizeof(buf)); ret = erofs_io_read(vin, buf, ret); - if (ret <= 0) { - if (!ret) - return -ENODATA; + if (ret < 0) return ret; - } + if (ret == 0) + return -EIO; + ret = erofs_io_pwrite(vout, buf, pos, ret); if (ret < 0) return ret; pos += ret; len -= ret; - } while (len); + } return 0; } -- 2.51.0.windows.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy 2026-03-22 6:03 [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy Ajay Rajera @ 2026-03-22 7:26 ` Nithurshen 2026-03-22 7:52 ` Ajay Rajera 0 siblings, 1 reply; 5+ messages in thread From: Nithurshen @ 2026-03-22 7:26 UTC (permalink / raw) To: newajay.11r; +Cc: linux-erofs, xiang Hi Ajay, As a fellow contributor and reviewer, one small request. Kindly send the next versions of patches (i.e. v2, v3, etc.) in the same thread to keep the mailing list list clean and easy for reviewers to follow up. Thanks and Regards, Nithurshen ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy 2026-03-22 7:26 ` Nithurshen @ 2026-03-22 7:52 ` Ajay Rajera 2026-03-22 12:09 ` Gao Xiang 0 siblings, 1 reply; 5+ messages in thread From: Ajay Rajera @ 2026-03-22 7:52 UTC (permalink / raw) To: Nithurshen; +Cc: linux-erofs, xiang yeah, sure. I didn't know that, so I apologize for it. I will keep this in mind from now on. Thanks, Ajay On Sun, 22 Mar 2026 at 12:56, Nithurshen <nithurshen.dev@gmail.com> wrote: > > Hi Ajay, > > As a fellow contributor and reviewer, one small request. > Kindly send the next versions of patches (i.e. v2, v3, etc.) in the > same thread to keep the mailing list list clean and easy for > reviewers to follow up. > > Thanks and Regards, > Nithurshen ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy 2026-03-22 7:52 ` Ajay Rajera @ 2026-03-22 12:09 ` Gao Xiang 2026-03-28 0:39 ` Ajay Rajera 0 siblings, 1 reply; 5+ messages in thread From: Gao Xiang @ 2026-03-22 12:09 UTC (permalink / raw) To: Ajay Rajera; +Cc: Nithurshen, linux-erofs, xiang On Sun, Mar 22, 2026 at 01:22:00PM +0530, Ajay Rajera wrote: > yeah, sure. > I didn't know that, so I apologize for it. > I will keep this in mind from now on. > Thanks, > Ajay The patch is broken, please apply locally before sending out. Thanks, Gao Xiang > > On Sun, 22 Mar 2026 at 12:56, Nithurshen <nithurshen.dev@gmail.com> wrote: > > > > Hi Ajay, > > > > As a fellow contributor and reviewer, one small request. > > Kindly send the next versions of patches (i.e. v2, v3, etc.) in the > > same thread to keep the mailing list list clean and easy for > > reviewers to follow up. > > > > Thanks and Regards, > > Nithurshen > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy 2026-03-22 12:09 ` Gao Xiang @ 2026-03-28 0:39 ` Ajay Rajera 0 siblings, 0 replies; 5+ messages in thread From: Ajay Rajera @ 2026-03-28 0:39 UTC (permalink / raw) To: linux-erofs; +Cc: xiang, Ajay Rajera erofs_io_xcopy() has a fallback loop for when the kernel fast paths (copy_file_range/sendfile) do not handle all the data. When erofs_io_read() returned 0 (source exhausted before all bytes were copied), the old logic checked `ret < 0` and `ret > 0`, ignoring `0`. Since `len -= 0` is a no-op, the loop would spin forever at 100% CPU with no progress. v2 fixed the loop but unconditionally trapped a 0-byte read by returning -EIO. However, if copy_file_range completely exhausts the bytes, `len` becomes 0. The do-while loop was then forced to execute once, making a 0-byte read, which returned 0. v2 falsely trapped this success as an -EIO error, causing mkfs.erofs to fail in CI. Fix this regression by replacing `do-while(len)` with a standard `while(len)` loop. This safely bypasses the block if `len` is 0 (avoiding fake -EIO errors), while correctly catching premature EOFs with -EIO. Also fix the 'pading' -> 'padding' typo in erofs_dev_read(). Signed-off-by: Ajay Rajera <newajay.11r@gmail.com> --- v3: Replace do-while loop to avoid 0-byte read -EIO regression. v2: Return -EIO instead of -ENODATA, use cleaner if/else. --- lib/io.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/io.c b/lib/io.c index 0c5eb2c..ae6a600 100644 --- a/lib/io.c +++ b/lib/io.c @@ -430,7 +430,7 @@ ssize_t erofs_dev_read(struct erofs_sb_info *sbi, int device_id, if (read < 0) return read; if (read < len) { - erofs_info("reach EOF of device @ %llu, pading with zeroes", + erofs_info("reach EOF of device @ %llu, padding with zeroes", offset | 0ULL); memset(buf + read, 0, len - read); } @@ -660,21 +660,22 @@ int erofs_io_xcopy(struct erofs_vfile *vout, off_t pos, #endif } - do { + while (len) { char buf[32768]; int ret = min_t(unsigned int, len, sizeof(buf)); ret = erofs_io_read(vin, buf, ret); if (ret < 0) return ret; - if (ret > 0) { - ret = erofs_io_pwrite(vout, buf, pos, ret); - if (ret < 0) - return ret; - pos += ret; - } + if (ret == 0) + return -EIO; + + ret = erofs_io_pwrite(vout, buf, pos, ret); + if (ret < 0) + return ret; + pos += ret; len -= ret; - } while (len); + } return 0; } -- 2.51.0.windows.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-28 0:39 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-03-22 6:03 [PATCH v3] erofs-utils: lib: fix infinite loop on EOF in erofs_io_xcopy Ajay Rajera 2026-03-22 7:26 ` Nithurshen 2026-03-22 7:52 ` Ajay Rajera 2026-03-22 12:09 ` Gao Xiang 2026-03-28 0:39 ` Ajay Rajera
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox