linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Lecopzer Chen <lecopzer.chen@mediatek.com>
To: <akpm@linux-foundation.org>, <mgorman@techsingularity.net>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	<vbabka@suse.cz>, <nsaenzju@redhat.com>, <yj.chiang@mediatek.com>,
	Lecopzer Chen <lecopzer.chen@mediatek.com>,
	Mark-pk Tsai <mark-pk.tsai@mediatek.com>,
	Joe Liu <joe.liu@mediatek.com>
Subject: [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback
Date: Wed, 30 Aug 2023 19:13:33 +0800	[thread overview]
Message-ID: <20230830111332.7599-1-lecopzer.chen@mediatek.com> (raw)

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



             reply	other threads:[~2023-08-30 11:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 11:13 Lecopzer Chen [this message]
2023-09-05  9:09 ` [PATCH] mm: page_alloc: fix cma pageblock was stolen in rmqueue fallback 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230830111332.7599-1-lecopzer.chen@mediatek.com \
    --to=lecopzer.chen@mediatek.com \
    --cc=akpm@linux-foundation.org \
    --cc=joe.liu@mediatek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mark-pk.tsai@mediatek.com \
    --cc=mgorman@techsingularity.net \
    --cc=nsaenzju@redhat.com \
    --cc=vbabka@suse.cz \
    --cc=yj.chiang@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).