Skip to contentSkip to conversation

iomap: iomap_write_failed fix

PATCH In review Andreas Gruenbacher 4 participants 4 messages May 3, 2022 – May 4, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: iomap_write_failed fix

The @lend parameter of truncate_pagecache_range() should be the offset of the last byte of the hole, not the first byte beyond it.

Fixes ae259a9c8593 ("fs: introduce iomap infrastructure")
---
 fs/iomap/buffered-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +2 -1
index 8ce8720093b9..358ee1fb6f0d 100644
@@ -531,7 +531,8 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
 	 * write started inside the existing inode size.
 	 */
 	if (pos + len > i_size)
-		truncate_pagecache_range(inode, max(pos, i_size), pos + len);
+		truncate_pagecache_range(inode, max(pos, i_size),
+					 pos + len - 1);
 }
 
 static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Andreas Gruenbacher

The @lend parameter of truncate_pagecache_range() should be the offset of the last byte of the hole, not the first byte beyond it.

Fixes ae259a9c8593 ("fs: introduce iomap infrastructure")

Hm, yes, this is _true_, but it's a fix without importance (except maybe for an overflow case?) Look at the condition this is called in. We aren't punching out an extra byte in the page cache because we're punching beyond the end of the file.

It should be fixed because people copy-and-paste code. But it's not urgent, and doesn't need to be backported.

Quoted 22 lines
---
 fs/iomap/buffered-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +2 -1
index 8ce8720093b9..358ee1fb6f0d 100644
@@ -531,7 +531,8 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
 	 * write started inside the existing inode size.
 	 */
 	if (pos + len > i_size)
-		truncate_pagecache_range(inode, max(pos, i_size), pos + len);
+		truncate_pagecache_range(inode, max(pos, i_size),
+					 pos + len - 1);
 }
 
 static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Andreas Gruenbacher
Quoted 5 lines · Andreas Gruenbacher

The @lend parameter of truncate_pagecache_range() should be the offset of the last byte of the hole, not the first byte beyond it.

Fixes ae259a9c8593 ("fs: introduce iomap infrastructure")

I'll queue this up for ... 5.19? Testing infrastructure still sorta tied up until I get at least two clean runs on 5.18-rcX, which <cough> still hasn't happened yet.

--D

Quoted 21 lines
---
 fs/iomap/buffered-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/iomap/buffered-io.c +2 -1
index 8ce8720093b9..358ee1fb6f0d 100644
@@ -531,7 +531,8 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len)
 	 * write started inside the existing inode size.
 	 */
 	if (pos + len > i_size)
-		truncate_pagecache_range(inode, max(pos, i_size), pos + len);
+		truncate_pagecache_range(inode, max(pos, i_size),
+					 pos + len - 1);
 }
 
 static int iomap_read_folio_sync(loff_t block_start, struct folio *folio,
Signature · 1 line
2.35.1