LKML Archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/khugepaged: fix iteration in collapse_file
@ 2023-06-07  5:31 David Stevens
  2023-06-07 19:13 ` Peter Xu
  2023-06-09 20:02 ` Hugh Dickins
  0 siblings, 2 replies; 9+ messages in thread
From: David Stevens @ 2023-06-07  5:31 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: Peter Xu, Matthew Wilcox, Kirill A . Shutemov, Yang Shi,
	David Hildenbrand, Hugh Dickins, Jiaqi Yan, linux-kernel,
	David Stevens

From: David Stevens <stevensd@chromium.org>

Remove an unnecessary call to xas_set(index) when iterating over the
target range in collapse_file. The extra call to xas_set reset the xas
cursor to the top of the tree, causing the xas_next call on the next
iteration to walk the tree to index instead of advancing to index+1.
This returned the same page again, which would cause collapse_file to
fail because the page is already locked.

This bug was hidden when CONFIG_DEBUG_VM was set. When that config was
used, the xas_load in a subsequent VM_BUG_ON assert would walk xas from
the top of the tree to index, causing the xas_next call on the next loop
iteration to advance the cursor as expected.

Fixes: a2e17cc2efc7 ("mm/khugepaged: maintain page cache uptodate flag")
Signed-off-by: David Stevens <stevensd@chromium.org>
---
 mm/khugepaged.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index 6b9d39d65b73..2d0d58fb4e7f 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -2070,7 +2070,6 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr,
 					TTU_IGNORE_MLOCK | TTU_BATCH_FLUSH);
 
 		xas_lock_irq(&xas);
-		xas_set(&xas, index);
 
 		VM_BUG_ON_PAGE(page != xas_load(&xas), page);
 
-- 
2.41.0.rc2.161.g9c6817b8e7-goog


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

end of thread, other threads:[~2023-06-29 16:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07  5:31 [PATCH] mm/khugepaged: fix iteration in collapse_file David Stevens
2023-06-07 19:13 ` Peter Xu
2023-06-09 20:02 ` Hugh Dickins
2023-06-10  1:45   ` David Stevens
2023-06-11 18:26     ` Hugh Dickins
2023-06-25 19:06       ` [PATCH] mm/khugepaged: fix regression in collapse_file() Hugh Dickins
2023-06-25 19:42         ` Linus Torvalds
2023-06-29  4:31           ` [PATCH hotfix] " Hugh Dickins
2023-06-29 16:42             ` Linus Torvalds

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 read-only IMAP folder(s) and NNTP newsgroup(s).