If MTE is disabled (for example, from the kernel command line with the arm64.nomte option), the tag storage pages behave just like normal pages, because they will never be used to store tags. If that's the case, expose them to the page allocator as MIGRATE_MOVABLE pages. MIGRATE_MOVABLE has been chosen because the bulk of memory allocations comes from userspace, and the migratetype for those allocations is MIGRATE_MOVABLE. MIGRATE_RECLAIMABLE and MIGRATE_UNMOVABLE requests can still use the pages as a fallback. Signed-off-by: Alexandru Elisei <alexandru.elisei@xxxxxxx> --- arch/arm64/kernel/mte_tag_storage.c | 18 ++++++++++++++++++ include/linux/gfp.h | 2 ++ mm/mm_init.c | 3 +-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/mte_tag_storage.c b/arch/arm64/kernel/mte_tag_storage.c index 87160f53960f..4a6bfdf88458 100644 --- a/arch/arm64/kernel/mte_tag_storage.c +++ b/arch/arm64/kernel/mte_tag_storage.c @@ -296,6 +296,24 @@ static int __init mte_tag_storage_activate_regions(void) } } + /* + * MTE disabled, tag storage pages can be used like any other pages. The + * only restriction is that the pages cannot be used by kexec because + * the memory is marked as reserved in the memblock allocator. + */ + if (!system_supports_mte()) { + for (i = 0; i< num_tag_regions; i++) { + tag_range = &tag_regions[i].tag_range; + for (pfn = tag_range->start; + pfn <= tag_range->end; + pfn += pageblock_nr_pages) { + init_reserved_pageblock(pfn_to_page(pfn), MIGRATE_MOVABLE); + } + } + + return 0; + } + for (i = 0; i < num_tag_regions; i++) { tag_range = &tag_regions[i].tag_range; for (pfn = tag_range->start; pfn <= tag_range->end; pfn += pageblock_nr_pages) { diff --git a/include/linux/gfp.h b/include/linux/gfp.h index fb344baa9a9b..622bb9406cae 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -354,6 +354,8 @@ extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, #endif void free_contig_range(unsigned long pfn, unsigned long nr_pages); +extern void init_reserved_pageblock(struct page *page, enum migratetype migratetype); + #ifdef CONFIG_MEMORY_METADATA extern void init_metadata_reserved_pageblock(struct page *page); #else diff --git a/mm/mm_init.c b/mm/mm_init.c index 467c80e9dacc..eedaacdf153d 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -2330,8 +2330,7 @@ bool __init deferred_grow_zone(struct zone *zone, unsigned int order) #endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ #if defined(CONFIG_CMA) || defined(CONFIG_MEMORY_METADATA) -static void __init init_reserved_pageblock(struct page *page, - enum migratetype migratetype) +void __init init_reserved_pageblock(struct page *page, enum migratetype migratetype) { unsigned i = pageblock_nr_pages; struct page *p = page; -- 2.41.0