mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sang-Heon Jeon <ekffu200098@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>
Cc: "Liam R. Howlett" <liam@infradead.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Michal Hocko <mhocko@suse.com>, Mike Rapoport <rppt@kernel.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Qi Zheng <zhengqi.arch@bytedance.com>,
	Usama Arif <usama.arif@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Frank van der Linden <fvdl@google.com>,
	Kiryl Shutsemau <kas@kernel.org>,
	Baoquan He <baoquan.he@linux.dev>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Pratyush Yadav <pratyush@kernel.org>, Jiri Bohac <jbohac@suse.cz>,
	kexec@lists.infradead.org
Subject: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
Date: Thu, 26 Nov 2026 00:51:06 +0900	[thread overview]
Message-ID: <20261125155108.24098-1-ekffu200098@gmail.com> (raw)

crashkernel=size,cma uses existing hugetlb_cma memory, so
crashk_cma_ranges[] may contain HugeTLB folios. HugeTLB folios allocated
from hugetlb_cma can be long-term pinned without being migrated.

After a crash, the crash kernel uses the memory in crashk_cma_ranges[],
but a device can still write to a long-term pinned folio.

So reject long-term pins of HugeTLB folios overlapping
crashk_cma_ranges[].

Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
The above scenario is only possible with the two patches below applied.
Currently only linux-next, which is targeting v7.5, has both of them.

  "mm/hugetlb: allow crashkernel to reuse hugetlb CMA memory" (kexec-next)
  "mm: gup: allow long-term pins of CMA-allocated HugeTLB folios" (mm-unstable)
---
 mm/cma.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/mm/cma.c b/mm/cma.c
index 0c97aadcfea4..cb4a92e2b9f5 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -32,6 +32,8 @@
 #include <linux/hugetlb.h>
 #include <trace/events/cma.h>
 #include <linux/page-isolation.h>
+#include <linux/crash_reserve.h>
+#include <linux/range.h>
 
 #include "internal.h"
 #include "cma.h"
@@ -42,12 +44,33 @@ unsigned int cma_area_count;
 
 bool cma_folio_is_longterm_pinnable(struct folio *folio)
 {
+	struct range r;
+	int i;
+
 	/*
 	 * Explicitly allocated CMA folios own their CMA memory and can be
 	 * pinned even in ZONE_MOVABLE, as CMA memory cannot be offlined.
 	 * For now, only HugeTLB tracks these allocations with a folio flag.
 	 */
-	return folio_test_hugetlb(folio) && folio_test_hugetlb_cma(folio);
+	if (!folio_test_hugetlb(folio) || !folio_test_hugetlb_cma(folio))
+		return false;
+
+	/*
+	 * The crash kernel uses the memory in crashk_cma_ranges[], but a
+	 * device can still write to a long-term pinned folio after a crash.
+	 */
+	if (!crashk_cma_cnt)
+		return true;
+
+	r.start = PFN_PHYS(folio_pfn(folio));
+	r.end = r.start + folio_size(folio) - 1;
+
+	for (i = 0; i < crashk_cma_cnt; i++) {
+		if (range_overlaps(&crashk_cma_ranges[i], &r))
+			return false;
+	}
+
+	return true;
 }
 
 phys_addr_t cma_get_base(const struct cma *cma)

base-commit: a036649714c3446abfdc36d0ae483046432b16c5
-- 
2.53.0


                 reply	other threads:[~2026-11-25 15:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261125155108.24098-1-ekffu200098@gmail.com \
    --to=ekffu200098@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baoquan.he@linux.dev \
    --cc=david@kernel.org \
    --cc=fvdl@google.com \
    --cc=jbohac@suse.cz \
    --cc=kas@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=osalvador@suse.de \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rppt@kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=zhengqi.arch@bytedance.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

all inboxes | Powered by JetHome®