Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iomap: Fix inline extent handling in iomap_readpage

Before commit 740499c78408 ("iomap: fix the iomap_readpage_actor return
value for inline data"), when hitting an IOMAP_INLINE extent,
iomap_readpage_actor would report having read the entire page. Since
then, it only reports having read the inline data (iomap->length).

This will force iomap_readpage into another iteration, and the
filesystem will report an unaligned hole after the IOMAP_INLINE extent.
But iomap_readpage_actor (now iomap_readpage_iter) isn't prepared to
deal with unaligned extents, it will get things wrong on filesystems
with a block size smaller than the page size, and we'll eventually run
into the following warning in iomap_iter_advance:

WARN_ON_ONCE(iter->processed > iomap_length(iter));

Fix that by changing iomap_readpage_iter to return 0 when hitting an
inline extent; this will cause iomap_iter to stop immediately.

To fix readahead as well, change iomap_readahead_iter to pass on
iomap_readpage_iter return values less than or equal to zero.

Fixes: 740499c78408 ("iomap: fix the iomap_readpage_actor return value for inline data")
Cc: stable@vger.kernel.org # v5.15+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>

authored by

Andreas Gruenbacher and committed by
Darrick J. Wong
d8af404f 13605725

+9 -2
+9 -2
fs/iomap/buffered-io.c
··· 256 256 unsigned poff, plen; 257 257 sector_t sector; 258 258 259 - if (iomap->type == IOMAP_INLINE) 260 - return min(iomap_read_inline_data(iter, page), length); 259 + if (iomap->type == IOMAP_INLINE) { 260 + loff_t ret = iomap_read_inline_data(iter, page); 261 + 262 + if (ret < 0) 263 + return ret; 264 + return 0; 265 + } 261 266 262 267 /* zero post-eof blocks as the page may be mapped */ 263 268 iop = iomap_page_create(iter->inode, page); ··· 375 370 ctx->cur_page_in_bio = false; 376 371 } 377 372 ret = iomap_readpage_iter(iter, ctx, done); 373 + if (ret <= 0) 374 + return ret; 378 375 } 379 376 380 377 return done;