From: Brendan Jackman <jackmanb@google.com> Date: Thu, 27 Feb 2025 16:15:47 +0000 (+0000) Subject: mm/page_alloc: add lockdep assertion for pageblock type change X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b4cfcc26f507ecef2861ccfb883698933083fce6;p=users%2Fjedix%2Flinux-maple.git mm/page_alloc: add lockdep assertion for pageblock type change Since the migratetype hygiene patches [0], the locking here is a bit more formalised, so write it down with an assert. [0] https://lore.kernel.org/lkml/20240320180429.678181-3-hannes@cmpxchg.org/T/ Link: https://lkml.kernel.org/r/20250227-pageblock-lockdep-v1-1-3701efb331bb@google.com Signed-off-by: Brendan Jackman <jackmanb@google.com> Cc: David Hildenbrand <david@redhat.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Oscar Salvador <osalvador@suse.de> Cc: Vlastimil Babka <vbabka@suse.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> --- diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index eaac5ae8c05c..ff9511d9b9e6 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -175,6 +175,7 @@ void put_online_mems(void); void mem_hotplug_begin(void); void mem_hotplug_done(void); +bool in_mem_hotplug(void); /* See kswapd_is_running() */ static inline void pgdat_kswapd_lock(pg_data_t *pgdat) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 16cf9e17077e..2b9d1a6267c0 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -267,6 +267,11 @@ void mem_hotplug_done(void) cpus_read_unlock(); } +bool in_mem_hotplug(void) +{ + return percpu_is_write_locked(&mem_hotplug_lock); +} + u64 max_mem_size = U64_MAX; /* add this memory to iomem resource */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c3402009cb88..dd7e280a61c6 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -417,6 +417,10 @@ void set_pfnblock_flags_mask(struct page *page, unsigned long flags, void set_pageblock_migratetype(struct page *page, int migratetype) { + lockdep_assert_once(system_state == SYSTEM_BOOTING || + in_mem_hotplug() || + lockdep_is_held(&page_zone(page)->lock)); + if (unlikely(page_group_by_mobility_disabled && migratetype < MIGRATE_PCPTYPES)) migratetype = MIGRATE_UNMOVABLE;