linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()
@ 2024-01-22 17:17 David Hildenbrand
  2024-01-22 17:22 ` Ryan Roberts
  2024-01-23  8:49 ` Yuezhang.Mo
  0 siblings, 2 replies; 4+ messages in thread
From: David Hildenbrand @ 2024-01-22 17:17 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Ryan Roberts, Matthew Wilcox,
	Andrew Morton

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.

Reported-by: Ryan Roberts <ryan.roberts@arm.com>
Closes: https://lkml.kernel.org/r/2445cedb-61fb-422c-8bfb-caf0a2beed62@arm.com
Fixes: c46265030b0f ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()")
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 mm/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/memory.c b/mm/memory.c
index 7e1f4849463aa..89bcae0b224d6 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -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;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()
  2024-01-22 17:17 [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range() David Hildenbrand
@ 2024-01-22 17:22 ` Ryan Roberts
  2024-01-23  8:49 ` Yuezhang.Mo
  1 sibling, 0 replies; 4+ messages in thread
From: Ryan Roberts @ 2024-01-22 17:22 UTC (permalink / raw)
  To: David Hildenbrand, linux-kernel; +Cc: linux-mm, Matthew Wilcox, Andrew Morton

On 22/01/2024 17:17, David Hildenbrand wrote:
> 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.

> 
> 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.
> 
> Reported-by: Ryan Roberts <ryan.roberts@arm.com>
> Closes: https://lkml.kernel.org/r/2445cedb-61fb-422c-8bfb-caf0a2beed62@arm.com
> Fixes: c46265030b0f ("mm/memory: page_remove_rmap() -> folio_remove_rmap_pte()")
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>

> ---
>  mm/memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 7e1f4849463aa..89bcae0b224d6 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -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;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()
  2024-01-22 17:17 [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range() David Hildenbrand
  2024-01-22 17:22 ` Ryan Roberts
@ 2024-01-23  8:49 ` Yuezhang.Mo
  2024-01-23  8:57   ` David Hildenbrand
  1 sibling, 1 reply; 4+ messages in thread
From: Yuezhang.Mo @ 2024-01-23  8:49 UTC (permalink / raw)
  To: David Hildenbrand, linux-kernel@vger.kernel.org
  Cc: linux-mm@kvack.org, Ryan Roberts, Matthew Wilcox, Andrew Morton

Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>

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

> -----Original Message-----
> From: owner-linux-mm@kvack.org <owner-linux-mm@kvack.org> On Behalf
> Of David Hildenbrand
> Sent: Tuesday, January 23, 2024 1:18 AM
> To: linux-kernel@vger.kernel.org
> Cc: linux-mm@kvack.org; David Hildenbrand <david@redhat.com>; Ryan
> Roberts <ryan.roberts@arm.com>; Matthew Wilcox <willy@infradead.org>;
> Andrew Morton <akpm@linux-foundation.org>
> 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.
> 
> Reported-by: Ryan Roberts <ryan.roberts@arm.com>
> Closes:
> https://lkml.kernel.org/r/2445cedb-61fb-422c-8bfb-caf0a2beed62@arm.com
> Fixes: c46265030b0f ("mm/memory: page_remove_rmap() ->
> folio_remove_rmap_pte()")
> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
> ---
>  mm/memory.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index 7e1f4849463aa..89bcae0b224d6 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -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;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range()
  2024-01-23  8:49 ` Yuezhang.Mo
@ 2024-01-23  8:57   ` David Hildenbrand
  0 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2024-01-23  8:57 UTC (permalink / raw)
  To: Yuezhang.Mo@sony.com, linux-kernel@vger.kernel.org
  Cc: linux-mm@kvack.org, Ryan Roberts, Matthew Wilcox, Andrew Morton

On 23.01.24 09:49, Yuezhang.Mo@sony.com wrote:
> Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
> 
> 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!

-- 
Cheers,

David / dhildenb



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-23  8:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 17:17 [PATCH v1] mm/memory: fix folio_set_dirty() vs. folio_mark_dirty() in zap_pte_range() David Hildenbrand
2024-01-22 17:22 ` Ryan Roberts
2024-01-23  8:49 ` Yuezhang.Mo
2024-01-23  8:57   ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).