diff mbox series

[RFC,12/37] mm: gup: Don't allow longterm pinning of MIGRATE_METADATA pages

Message ID 20230823131350.114942-13-alexandru.elisei@arm.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [RFC,01/37] mm: page_alloc: Rename gfp_to_alloc_flags_cma -> gfp_to_alloc_flags_fast | expand

Commit Message

Alexandru Elisei Aug. 23, 2023, 1:13 p.m. UTC
Treat MIGRATE_METADATA pages just like movable or CMA pages and don't allow
them to be pinned longterm.

No special handling needed for migrate_longterm_unpinnable_pages() because
the gfp mask for allocating the destination pages is GFP_USER.  GFP_USER
doesn't include __GFP_MOVABLE, which makes it impossible to accidently
allocate metadata pages for migrating the pinned pages.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 include/linux/mm.h | 10 +++++++---
 mm/Kconfig         |  2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 2dd73e4f3d8e..ce87d55ecf87 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1925,16 +1925,20 @@  static inline bool is_zero_folio(const struct folio *folio)
 	return is_zero_page(&folio->page);
 }
 
-/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin folios */
+/* MIGRATE_CMA, MIGRATE_METADATA and ZONE_MOVABLE do not allow pin folios */
 #ifdef CONFIG_MIGRATION
 static inline bool folio_is_longterm_pinnable(struct folio *folio)
 {
-#ifdef CONFIG_CMA
+#if defined(CONFIG_CMA) || defined(CONFIG_MEMORY_METADATA)
 	int mt = folio_migratetype(folio);
 
-	if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
+	if (mt == MIGRATE_ISOLATE)
+		return false;
+
+	if (is_migrate_cma(mt) || is_migrate_metadata(mt))
 		return false;
 #endif
+
 	/* The zero page can be "pinned" but gets special handling. */
 	if (is_zero_folio(folio))
 		return true;
diff --git a/mm/Kconfig b/mm/Kconfig
index 838193522e20..847e1669dba0 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -1238,6 +1238,8 @@  config LOCK_MM_AND_FIND_VMA
 
 config MEMORY_METADATA
 	bool
+	select MEMORY_ISOLATION
+	select MIGRATION
 
 source "mm/damon/Kconfig"