* [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
@ 2026-11-25 15:51 Sang-Heon Jeon
2026-11-25 21:49 ` Usama Arif
2026-11-25 22:43 ` David Hildenbrand (Arm)
0 siblings, 2 replies; 3+ messages in thread
From: Sang-Heon Jeon @ 2026-11-25 15:51 UTC (permalink / raw)
To: Andrew Morton, David Hildenbrand
Cc: Liam R. Howlett, linux-kernel, linux-mm, Michal Hocko,
Mike Rapoport, Vlastimil Babka, Qi Zheng, Usama Arif,
Muchun Song, Oscar Salvador, Frank van der Linden,
Kiryl Shutsemau, Baoquan He, Pasha Tatashin, Pratyush Yadav,
Jiri Bohac, kexec
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
2026-11-25 15:51 [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA Sang-Heon Jeon
@ 2026-11-25 21:49 ` Usama Arif
2026-11-25 22:43 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 3+ messages in thread
From: Usama Arif @ 2026-11-25 21:49 UTC (permalink / raw)
To: Sang-Heon Jeon, Andrew Morton, David Hildenbrand
Cc: Liam R. Howlett, linux-kernel, linux-mm, Michal Hocko,
Mike Rapoport, Vlastimil Babka, Qi Zheng, Muchun Song,
Oscar Salvador, Frank van der Linden, Kiryl Shutsemau,
Baoquan He, Pasha Tatashin, Pratyush Yadav, Jiri Bohac, kexec
On 25/11/2026 07:51, Sang-Heon Jeon wrote:
> 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[].
>
Is spending the workload to protect the dump the right way round for this
option? kdump.rst describes it as
This reservation method is intended for systems that can't afford to
sacrifice enough memory for standard crashkernel reservation and where
less reliable and possibly incomplete kdump is preferable to no kdump at
all.
so the dump is the part the admin has already agreed to give up.
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
2026-11-25 15:51 [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA Sang-Heon Jeon
2026-11-25 21:49 ` Usama Arif
@ 2026-11-25 22:43 ` David Hildenbrand (Arm)
1 sibling, 0 replies; 3+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-25 22:43 UTC (permalink / raw)
To: Sang-Heon Jeon, Andrew Morton
Cc: Liam R. Howlett, linux-kernel, linux-mm, Michal Hocko,
Mike Rapoport, Vlastimil Babka, Qi Zheng, Usama Arif,
Muchun Song, Oscar Salvador, Frank van der Linden,
Kiryl Shutsemau, Baoquan He, Pasha Tatashin, Pratyush Yadav,
Jiri Bohac, kexec
On 11/25/26 16:51, Sang-Heon Jeon wrote:
> 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)
I think that's a real problem with this thing.
The solution is not to disallow long-term pinning. :/
--
Cheers,
David
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 22:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 15:51 [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA Sang-Heon Jeon
2026-11-25 21:49 ` Usama Arif
2026-11-25 22:43 ` David Hildenbrand (Arm)
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®