[PATCH v4 02/18] hugetlb_vmemmap: Always flush TLB if needed upon PTE remapping

James Houghton jthoughton at google.com
Tue Dec 1 07:07:44 PST 2026


vmemmap_remap_range() can potentially leave the vmemmap in a partially
optimized state. In this case, a TLB flush should be done if the walk
caller asked for it, even if the optimization was not fully applied.

A follow-up patch will more completely deal with partially-optimized
folios.

Signed-off-by: James Houghton <jthoughton at google.com>
---
 mm/hugetlb_vmemmap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c
index 09b9fd83c198..a4727558cc57 100644
--- a/mm/hugetlb_vmemmap.c
+++ b/mm/hugetlb_vmemmap.c
@@ -163,13 +163,13 @@ static int vmemmap_remap_range(unsigned long start, unsigned long end,
 
 	ret = walk_kernel_page_table_range_lockless(start, end, &vmemmap_remap_ops,
 						    NULL, walk);
-	if (ret)
-		return ret;
 
-	if (walk->remap_pte && !(walk->flags & VMEMMAP_DEFER_TLB_FLUSH))
-		flush_tlb_kernel_range(start, end);
+	if (walk->remap_pte && walk->nr_walked &&
+	    !(walk->flags & VMEMMAP_DEFER_TLB_FLUSH))
+		flush_tlb_kernel_range(start,
+				       start + walk->nr_walked * PAGE_SIZE);
 
-	return 0;
+	return ret;
 }
 
 /*
-- 
2.56.1.839.g22a8290db9-goog




More information about the linux-arm-kernel mailing list