Skip to contentSkip to conversation

fuse: fix premature writetrhough request for large folio

PATCH Superseded Jingbo Xu 2 participants 4 messages Jan 14 – Jan 15

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jingbo Xu

author
#0 lore raw

PATCH v2 1/1 fuse: fix premature writetrhough request for large folio

When large folio is enabled and the initial folio offset exceeds PAGE_SIZE, e.g. the position resides in the second page of a large folio, after the folio copying the offset (in the page) won't be updated to 0 even though the expected range is successfully copied until the end of the folio. In this case fuse_fill_write_pages() exits prematurelly before the request has reached the max_write/max_pages limit.

Fix this by eliminating page offset entirely and use folio offset instead.

Fixes d60a6015e1a2 ("fuse: support large folios for writethrough writes")

---
changes since v1:
- add Reviewed-by tag (Horst)

v1: https://yhbt.net/lore/all/[email protected]/

---
 fs/fuse/file.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/fuse/file.c +4 -6
index 625d236b881b..6aafb32338b6 100644
@@ -1272,7 +1272,6 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 {
 	struct fuse_args_pages *ap = &ia->ap;
 	struct fuse_conn *fc = get_fuse_conn(mapping->host);
-	unsigned offset = pos & (PAGE_SIZE - 1);
 	size_t count = 0;
 	unsigned int num;
 	int err = 0;
@@ -1299,7 +1298,7 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 		if (mapping_writably_mapped(mapping))
 			flush_dcache_folio(folio);
 
-		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
+		folio_offset = offset_in_folio(folio, pos);
 		bytes = min(folio_size(folio) - folio_offset, num);
 
 		tmp = copy_folio_from_iter_atomic(folio, folio_offset, bytes, ii);
@@ -1329,9 +1328,6 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 		count += tmp;
 		pos += tmp;
 		num -= tmp;
-		offset += tmp;
-		if (offset == folio_size(folio))
-			offset = 0;
 
 		/* If we copied full folio, mark it uptodate */
 		if (tmp == folio_size(folio))
@@ -1343,7 +1339,9 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 			ia->write.folio_locked = true;
 			break;
 		}
-		if (!fc->big_writes || offset != 0)
+		if (!fc->big_writes)
+			break;
+		if (folio_offset + tmp != folio_size(folio))
 			break;
 	}
 
Signature · 1 line
2.19.1.6.gb485710b
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Jingbo Xu

When large folio is enabled and the initial folio offset exceeds PAGE_SIZE, e.g. the position resides in the second page of a large folio, after the folio copying the offset (in the page) won't be updated to 0 even though the expected range is successfully copied until the end of the folio. In this case fuse_fill_write_pages() exits prematurelly before the request has reached the max_write/max_pages limit.

Quoted 5 lines

Fix this by eliminating page offset entirely and use folio offset instead.

Fixes d60a6015e1a2 ("fuse: support large folios for writethrough writes")

This should not need the stable tag or any backports. The bug cannot trigger until the future patch for turning on large folios lands.

Quoted 2 lines

This LGTM, thanks for spotting this.

Btw, are your prod systems running fuse with large folios enabled? If so, are your servers using writeback caching too?

Thanks,
Joanne

Quoted 54 lines

---
changes since v1:
- add Reviewed-by tag (Horst)

v1: https://yhbt.net/lore/all/[email protected]/

---
 fs/fuse/file.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
fs/fuse/file.c +4 -7
index 625d236b881b..6aafb32338b6 100644
@@ -1272,7 +1272,6 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
 {
        struct fuse_args_pages *ap = &ia->ap;
        struct fuse_conn *fc = get_fuse_conn(mapping->host);
-       unsigned offset = pos & (PAGE_SIZE - 1);
        size_t count = 0;
        unsigned int num;
        int err = 0;
@@ -1299,7 +1298,7 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
                if (mapping_writably_mapped(mapping))
                        flush_dcache_folio(folio);
 
-               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
+               folio_offset = offset_in_folio(folio, pos);
                bytes = min(folio_size(folio) - folio_offset, num);
 
                tmp = copy_folio_from_iter_atomic(folio, folio_offset, bytes, ii);
@@ -1329,9 +1328,6 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
                count += tmp;
                pos += tmp;
                num -= tmp;
-               offset += tmp;
-               if (offset == folio_size(folio))
-                       offset = 0;
 
                /* If we copied full folio, mark it uptodate */
                if (tmp == folio_size(folio))
@@ -1343,7 +1339,9 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
                        ia->write.folio_locked = true;
                        break;
                }
-               if (!fc->big_writes || offset != 0)
+               if (!fc->big_writes)
+                       break;
+               if (folio_offset + tmp != folio_size(folio))
                        break;
        }
 
--

2.19.1.6.gb485710b

author
#2 lore raw
Quoted 9 lines · Joanne Koong
Quoted 8 lines · Jingbo Xu

When large folio is enabled and the initial folio offset exceeds PAGE_SIZE, e.g. the position resides in the second page of a large folio, after the folio copying the offset (in the page) won't be updated to 0 even though the expected range is successfully copied until the end of the folio. In this case fuse_fill_write_pages() exits prematurelly before the request has reached the max_write/max_pages limit.

Quoted 8 lines
Quoted 5 lines

Fix this by eliminating page offset entirely and use folio offset instead.

Fixes d60a6015e1a2 ("fuse: support large folios for writethrough writes")

This should not need the stable tag or any backports. The bug cannot trigger until the future patch for turning on large folios lands.

I think 6.18 stable also needs this fix?

Signature · 2 lines
Thanks,
Jingbo
author
#3 lore raw

Hi Joanne,

Quoted 15 lines · Jingbo Xu
Quoted 12 lines · Joanne Koong
Quoted 11 lines · Jingbo Xu

When large folio is enabled and the initial folio offset exceeds PAGE_SIZE, e.g. the position resides in the second page of a large folio, after the folio copying the offset (in the page) won't be updated to 0 even though the expected range is successfully copied until the end of the folio. In this case fuse_fill_write_pages() exits prematurelly before the request has reached the max_write/max_pages limit.

Fix this by eliminating page offset entirely and use folio offset instead.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Fixes d60a6015e1a2 ("fuse: support large folios for writethrough writes")

This should not need the stable tag or any backports. The bug cannot trigger until the future patch for turning on large folios lands.

I think 6.18 stable also needs this fix?

Sorry I got it mixed up. I remembered that the patch enabling large folio is along with the whole patch series supporting large folio, but I missed the fact that it was not merged to mainline.

So the stable tree indeed doesn't need the fix. Sorry for the noise. I will drop the stable CC tag later.

Signature · 2 lines
Thanks,
Jingbo