Skip to contentSkip to conversation

mm: Fix assertion in folio_end_read()

PATCH In review Matthew Wilcox (Oracle) 4 participants 8 messages Jan 10, 2025 – Jan 14, 2025

Subsystems (4)
lore
Share & tools
lore

Matthew Wilcox (Oracle)

author maintainer
#0 lore raw

PATCH 1/2 mm: Fix assertion in folio_end_read()

We only need to assert that the uptodate flag is clear if we're going to set it. This hasn't been a problem before now because we have only used folio_end_read() when completing with an error, but it's convenient to use it in squashfs if we discover the folio is already uptodate.

---
 mm/filemap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
index 12ba297bb85e..3b1eefa9aab8 100644
@@ -1505,7 +1505,7 @@ void folio_end_read(struct folio *folio, bool success)
 	/* Must be in bottom byte for x86 to work */
 	BUILD_BUG_ON(PG_uptodate > 7);
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
-	VM_BUG_ON_FOLIO(folio_test_uptodate(folio), folio);
+	VM_BUG_ON_FOLIO(success && folio_test_uptodate(folio), folio);
 
 	if (likely(success))
 		mask |= 1 << PG_uptodate;
Signature · 1 line
2.45.2
author maintainer
#1 lore raw

PATCH 2/2 squashfs: Fix "convert squashfs_fill_page() to take a folio"

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

---
 fs/squashfs/file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/file.c +3 -3
index da25d6fa45ce..018f0053a4f5 100644
@@ -400,7 +400,7 @@ void squashfs_copy_cache(struct folio *folio,
 			bytes -= PAGE_SIZE, offset += PAGE_SIZE) {
 		struct folio *push_folio;
 		size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0;
-		bool uptodate = true;
+		bool updated = false;
 
 		TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail);
 
@@ -415,9 +415,9 @@ void squashfs_copy_cache(struct folio *folio,
 		if (folio_test_uptodate(push_folio))
 			goto skip_folio;
 
-		uptodate = squashfs_fill_page(push_folio, buffer, offset, avail);
+		updated = squashfs_fill_page(push_folio, buffer, offset, avail);
 skip_folio:
-		folio_end_read(push_folio, uptodate);
+		folio_end_read(push_folio, updated);
 		if (i != folio->index)
 			folio_put(push_folio);
 	}
Signature · 1 line
2.45.2
#2 lore raw

Re: [PATCH 2/2] squashfs: Fix "convert squashfs_fill_page() to take a folio"

Quoted 5 lines · Matthew Wilcox (Oracle)

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

This is missing the change to folio_end_read() and the change for IS_ERR() that was in the version of the patch I tested. Just checking that those were handled separately in a thread I'm not CCed on?

Quoted 31 lines
---
 fs/squashfs/file.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/file.c +3 -3
index da25d6fa45ce..018f0053a4f5 100644
@@ -400,7 +400,7 @@ void squashfs_copy_cache(struct folio *folio,
 			bytes -= PAGE_SIZE, offset += PAGE_SIZE) {
 		struct folio *push_folio;
 		size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0;
-		bool uptodate = true;
+		bool updated = false;
 
 		TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail);
 
@@ -415,9 +415,9 @@ void squashfs_copy_cache(struct folio *folio,
 		if (folio_test_uptodate(push_folio))
 			goto skip_folio;
 
-		uptodate = squashfs_fill_page(push_folio, buffer, offset, avail);
+		updated = squashfs_fill_page(push_folio, buffer, offset, avail);
 skip_folio:
-		folio_end_read(push_folio, uptodate);
+		folio_end_read(push_folio, updated);
 		if (i != folio->index)
 			folio_put(push_folio);
 	}
author maintainer
#3 lore raw

Re: [PATCH 2/2] squashfs: Fix "convert squashfs_fill_page() to take a folio"

Quoted 10 lines · Ryan Roberts
Quoted 5 lines · Matthew Wilcox (Oracle)

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

This is missing the change to folio_end_read() and the change for IS_ERR() that was in the version of the patch I tested. Just checking that those were handled separately in a thread I'm not CCed on?

https://lore.kernel.org/mm-commits/[email protected]/
https://lore.kernel.org/mm-commits/[email protected]/

Shouldn't be anything missing; I applied the first one to my tree, then wrote the second one and the third one you're replying to. Then I did a git diff HEAD~3 and sent the result to you to test.

Has anything gone wrong in this process?

maintainer
#4 lore raw

Re: [PATCH 2/2] squashfs: Fix "convert squashfs_fill_page() to take a folio"

Quoted 6 lines · On Sat, 11 Jan 2025 17:58:32 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 5 lines · Ryan Roberts
Quoted 4 lines · Matthew Wilcox (Oracle)

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

This is missing the change to folio_end_read() and the change for IS_ERR() that was in the version of the patch I tested. Just checking that those were handled separately in a thread I'm not CCed on?

https://lore.kernel.org/mm-commits/[email protected]/

I have this as a fix against a different patch: "squashfs: convert squashfs_copy_cache() to take a folio"

Quoted 1 line

https://lore.kernel.org/mm-commits/[email protected]/

I queued this separately as a hotfix, without cc:stable. I guess it didn't really need that urgency, but wrong code is wrong.

Quoted 5 lines

Shouldn't be anything missing; I applied the first one to my tree, then wrote the second one and the third one you're replying to. Then I did a git diff HEAD~3 and sent the result to you to test.

Has anything gone wrong in this process?

I don't think so.

#5 lore raw

Re: [PATCH 2/2] squashfs: Fix "convert squashfs_fill_page() to take a folio"

Quoted 24 lines · Andrew Morton
Quoted 6 lines · On Sat, 11 Jan 2025 17:58:32 +0000 Matthew Wilcox <[email protected]> wrote:
Quoted 5 lines · Ryan Roberts
Quoted 4 lines · Matthew Wilcox (Oracle)

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

This is missing the change to folio_end_read() and the change for IS_ERR() that was in the version of the patch I tested. Just checking that those were handled separately in a thread I'm not CCed on?

https://lore.kernel.org/mm-commits/[email protected]/

I have this as a fix against a different patch: "squashfs: convert squashfs_copy_cache() to take a folio"

Quoted 1 line

https://lore.kernel.org/mm-commits/[email protected]/

I queued this separately as a hotfix, without cc:stable. I guess it didn't really need that urgency, but wrong code is wrong.

Quoted 7 lines
Quoted 5 lines

Shouldn't be anything missing; I applied the first one to my tree, then wrote the second one and the third one you're replying to. Then I did a git diff HEAD~3 and sent the result to you to test.

Has anything gone wrong in this process?

I don't think so.

Agreed - thanks!

maintainer Reviewed-by Tested-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] squashfs: Fix "convert squashfs_fill_page() to take a folio"

In reply to Matthew Wilcox (Oracle)
Quoted 7 lines · Matthew Wilcox (Oracle)

I got the polarity of "uptodate" wrong. Rename it. Thanks to Ryan for testing; please fold into above named patch, and he'd like you to add

Quoted 29 lines
---
  fs/squashfs/file.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/file.c +3 -3
index da25d6fa45ce..018f0053a4f5 100644
@@ -400,7 +400,7 @@ void squashfs_copy_cache(struct folio *folio,
  			bytes -= PAGE_SIZE, offset += PAGE_SIZE) {
  		struct folio *push_folio;
  		size_t avail = buffer ? min(bytes, PAGE_SIZE) : 0;
-		bool uptodate = true;
+		bool updated = false;
 
  		TRACE("bytes %zu, i %d, available_bytes %zu\n", bytes, i, avail);
 
@@ -415,9 +415,9 @@ void squashfs_copy_cache(struct folio *folio,
  		if (folio_test_uptodate(push_folio))
  			goto skip_folio;
 
-		uptodate = squashfs_fill_page(push_folio, buffer, offset, avail);
+		updated = squashfs_fill_page(push_folio, buffer, offset, avail);
  skip_folio:
-		folio_end_read(push_folio, uptodate);
+		folio_end_read(push_folio, updated);
  		if (i != folio->index)
  			folio_put(push_folio);
  	}
maintainer Reviewed-by Tested-by on v1 1/2
#7 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 6 lines · Matthew Wilcox (Oracle)

We only need to assert that the uptodate flag is clear if we're going to set it. This hasn't been a problem before now because we have only used folio_end_read() when completing with an error, but it's convenient to use it in squashfs if we discover the folio is already uptodate.

Quoted 17 lines
---
  mm/filemap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
index 12ba297bb85e..3b1eefa9aab8 100644
@@ -1505,7 +1505,7 @@ void folio_end_read(struct folio *folio, bool success)
  	/* Must be in bottom byte for x86 to work */
  	BUILD_BUG_ON(PG_uptodate > 7);
  	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
-	VM_BUG_ON_FOLIO(folio_test_uptodate(folio), folio);
+	VM_BUG_ON_FOLIO(success && folio_test_uptodate(folio), folio);
 
  	if (likely(success))
  		mask |= 1 << PG_uptodate;