Skip to contentSkip to conversation

mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()

PATCH Applied David Hildenbrand 3 participants 4 messages Jan 22, 2024 – Jan 23, 2024

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

PATCH 1/1 mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()

The correct folio replacement for "set_page_dirty()" is "folio_mark_dirty()", not "folio_set_dirty()". Using the latter won't properly inform the FS using the dirty_folio() callback.

This has been found by code inspection, but likely this can result in some real trouble when zapping dirty PTEs that point at clean pagecache folios.

Fixes c46265030b0f ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()")
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Andrew Morton <[email protected]>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
index 7e1f4849463aa..89bcae0b224d6 100644
@@ -1464,7 +1464,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
 			delay_rmap = 0;
 			if (!folio_test_anon(folio)) {
 				if (pte_dirty(ptent)) {
-					folio_set_dirty(folio);
+					folio_mark_dirty(folio);
 					if (tlb_delay_rmap(tlb)) {
 						delay_rmap = 1;
 						force_flush = 1;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · David Hildenbrand

The correct folio replacement for "set_page_dirty()" is "folio_mark_dirty()", not "folio_set_dirty()". Using the latter won't properly inform the FS using the dirty_folio() callback.

That set_page_dirty() naming is pretty nasty, hey.

Quoted 11 lines

This has been found by code inspection, but likely this can result in some real trouble when zapping dirty PTEs that point at clean pagecache folios.

Fixes c46265030b0f ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()")
Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Andrew Morton <[email protected]>
Quoted 17 lines
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
index 7e1f4849463aa..89bcae0b224d6 100644
@@ -1464,7 +1464,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
 			delay_rmap = 0;
 			if (!folio_test_anon(folio)) {
 				if (pte_dirty(ptent)) {
-					folio_set_dirty(folio);
+					folio_mark_dirty(folio);
 					if (tlb_delay_rmap(tlb)) {
 						delay_rmap = 1;
 						force_flush = 1;
Reviewed-by on v1 1/1
#2 lore raw
In reply to David Hildenbrand

Without this fix, testing the latest exfat with xfstests, test cases generic/029 and generic/030 will fail.

Quoted 46 lines

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of David Hildenbrand
Sent: Tuesday, January 23, 2024 1:18 AM
To: [email protected]
Cc: [email protected]; David Hildenbrand <[email protected]>; Ryan Roberts <[email protected]>; Matthew Wilcox <[email protected]>; Andrew Morton <[email protected]>
Subject: [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()

The correct folio replacement for "set_page_dirty()" is "folio_mark_dirty()", not "folio_set_dirty()". Using the latter won't properly inform the FS using the dirty_folio() callback.

This has been found by code inspection, but likely this can result in some real trouble when zapping dirty PTEs that point at clean pagecache folios.

Closes:
https://lkml.kernel.org/r/[email protected]

Fixes c46265030b0f ("mm/memory: page_remove_rmap() ->

folio_remove_rmap_pte()")

Cc Matthew Wilcox (Oracle) <[email protected]>
Cc Andrew Morton <[email protected]>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory.c +1 -1
index 7e1f4849463aa..89bcae0b224d6 100644
@@ -1464,7 +1464,7 @@ static unsigned long zap_pte_range(struct
 mmu_gather *tlb,
 			delay_rmap = 0;
 			if (!folio_test_anon(folio)) {
 				if (pte_dirty(ptent)) {
-					folio_set_dirty(folio);
+					folio_mark_dirty(folio);
 					if (tlb_delay_rmap(tlb)) {
 						delay_rmap = 1;

force_flush = 1;

#3 lore raw
Quoted 4 lines · On 23.01.24 09:49, [email protected] wrote:

Without this fix, testing the latest exfat with xfstests, test cases generic/029 and generic/030 will fail.

Great, thanks for testing and for providing actual reproducers!

Signature · 3 lines
Cheers,

David / dhildenb