linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback
@ 2023-08-30 11:13 Lecopzer Chen
  2023-09-05  9:09 ` Mel Gorman
  0 siblings, 1 reply; 9+ messages in thread
From: Lecopzer Chen @ 2023-08-30 11:13 UTC (permalink / raw)
  To: akpm, mgorman
  Cc: linux-kernel, linux-mm, vbabka, nsaenzju, yj.chiang,
	Lecopzer Chen, Mark-pk Tsai, Joe Liu

commit 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a
spinlock") fallback freeing page to free_one_page() if pcp trylock
failed. This make MIGRATE_CMA be able to fallback and be stolen
whole pageblock by MIGRATE_UNMOVABLE in the page allocation.

PCP free is fine because free_pcppages_bulk() will always get
migratetype again before freeing the page, thus this only happen when
someone tried to put CMA page in to other MIGRATE_TYPE's freelist.

Fixes: 4b23a68f9536 ("mm/page_alloc: protect PCP lists with a spinlock")
Reported-by: Joe Liu <joe.liu@mediatek.com>
Signed-off-by: Lecopzer Chen <lecopzer.chen@mediatek.com>
Cc: Mark-pk Tsai <mark-pk.tsai@mediatek.com>
Cc: Joe Liu <joe.liu@mediatek.com>
---
 mm/page_alloc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 452459836b71..0ea88c031838 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -2428,6 +2428,14 @@ void free_unref_page(struct page *page, unsigned int order)
 		free_unref_page_commit(zone, pcp, page, migratetype, order);
 		pcp_spin_unlock(pcp);
 	} else {
+#ifdef CONFIG_CMA
+		/*
+		 * CMA must be back to its freelist. Otherwise CMA pageblock may
+		 * be stolen by fallback flow while getting free page.
+		 */
+		if (get_pcppage_migratetype(page) == MIGRATE_CMA)
+			migratetype = MIGRATE_CMA;
+#endif
 		free_one_page(zone, page, pfn, order, migratetype, FPI_NONE);
 	}
 	pcp_trylock_finish(UP_flags);
-- 
2.18.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-09-11 19:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 11:13 [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback Lecopzer Chen
2023-09-05  9:09 ` Mel Gorman
2023-09-05  9:22   ` Lecopzer Chen
2023-09-05  9:37   ` Vlastimil Babka
2023-09-05 12:28     ` Mel Gorman
2023-09-11 15:57   ` Johannes Weiner
2023-09-11 16:13     ` Vlastimil Babka
2023-09-11 18:11       ` Johannes Weiner
2023-09-11 19:59         ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox