public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: fix apply_to_existing_page_range()
@ 2025-04-09  9:40 Kirill A. Shutemov
  2025-04-09  9:52 ` David Hildenbrand
  0 siblings, 1 reply; 5+ messages in thread
From: Kirill A. Shutemov @ 2025-04-09  9:40 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Hildenbrand, Vlastimil Babka, linux-mm, linux-kernel,
	Kirill A. Shutemov, Daniel Axtens

In the case of apply_to_existing_page_range(), apply_to_pte_range() is
reached with 'create' set to false. When !create, the loop over the PTE
page table is broken.

apply_to_pte_range() will only move to the next PTE entry if 'create' is
true or if the current entry is not pte_none().

This means that the user of apply_to_existing_page_range() will not have
'fn' called for any entries after the first pte_none() in the PTE page
table.

Fix the loop logic in apply_to_pte_range().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fixes: be1db4753ee6 ("mm/memory.c: add apply_to_existing_page_range() helper")
Cc: Daniel Axtens <dja@axtens.net>
---
 mm/memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index fb7b8dc75167..2094564f4dfb 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -2907,11 +2907,11 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
 	if (fn) {
 		do {
 			if (create || !pte_none(ptep_get(pte))) {
-				err = fn(pte++, addr, data);
+				err = fn(pte, addr, data);
 				if (err)
 					break;
 			}
-		} while (addr += PAGE_SIZE, addr != end);
+		} while (pte++, addr += PAGE_SIZE, addr != end);
 	}
 	*mask |= PGTBL_PTE_MODIFIED;
 
-- 
2.47.2


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

end of thread, other threads:[~2025-04-09 10:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-09  9:40 [PATCH] mm: fix apply_to_existing_page_range() Kirill A. Shutemov
2025-04-09  9:52 ` David Hildenbrand
2025-04-09 10:23   ` Kirill A. Shutemov
2025-04-09 10:26     ` David Hildenbrand
2025-04-09 10:41       ` Kirill A. Shutemov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox