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

From: Alexandru Elisei
Date: Wed Aug 23 2023 - 09:16:30 EST


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@xxxxxxx>
---
include/linux/mm.h | 10 +++++++---
mm/Kconfig | 2 ++
2 files changed, 9 insertions(+), 3 deletions(-)

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"

--
2.41.0