* [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; 6+ 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 related [flat|nested] 6+ 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-26 13:07 ` David Hildenbrand (Arm)
2026-11-25 22:43 ` David Hildenbrand (Arm)
1 sibling, 1 reply; 6+ 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] 6+ 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)
2026-11-26 8:21 ` Michal Hocko
1 sibling, 1 reply; 6+ 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] 6+ messages in thread
* Re: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
2026-11-25 22:43 ` David Hildenbrand (Arm)
@ 2026-11-26 8:21 ` Michal Hocko
0 siblings, 0 replies; 6+ messages in thread
From: Michal Hocko @ 2026-11-26 8:21 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Sang-Heon Jeon, Andrew Morton, Liam R. Howlett, linux-kernel,
linux-mm, 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 Wed 25-11-26 23:43:40, David Hildenbrand wrote:
> 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. :/
Yes, I would tend to agree. While there is a risk of stale writes from
RDMA on long term pinned pages on the crash kernel I would simply advise
admins to not use cma backing for crash kernel on those setups unless
they are willing to live with unreliable dumping.
I can see how reusing hugetlb cmas might be really helpful for
crashkernel as this can consume a lot of memory and you rarely care
about the content in the crash kernel - same as any other userspace
memory.
--
Michal Hocko
SUSE Labs
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
2026-11-25 21:49 ` Usama Arif
@ 2026-11-26 13:07 ` David Hildenbrand (Arm)
2026-11-26 15:16 ` Sang-Heon Jeon
0 siblings, 1 reply; 6+ messages in thread
From: David Hildenbrand (Arm) @ 2026-11-26 13:07 UTC (permalink / raw)
To: Usama Arif, Sang-Heon Jeon, Andrew Morton
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 11/25/26 22:49, Usama Arif wrote:
>
>
> 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.
We have in there:
"This option increases the risk of a kdump failure: DMA transfers configured by
the first kernel may end up corrupting the second kernel's memory."
... but I recall some discussions about short-term vs. long-term vs. cma
discussions.
Ah: https://lore.kernel.org/all/ZWJllXCN0SDIELrX@dwarf.suse.cz/
"User pages for RDMA, should be pinned with FOLL_LONGTERM and that
would migrate them away from the CMA area.
But you're right that DMA to user pages pinned without
FOLL_LONGTERM would still be possible. Would this be a problem in
practice? Do you see any way around it?
"
And later (me):
https://lore.kernel.org/all/04904e86-5b5f-4aa1-a120-428dac119189@redhat.com/
"What does "short" mean? At least in theory, long-term pinning is
forbidden for MIGRATE_CMA, so we should not have such pages mapped into
an iommu where DMA can happily keep going on for quite a while.
But that assumes that our old kernel is not buggy, and doesn't end up
mapping these pages into an IOMMU where DMA will just continue. I recall
that DRM might currently be a problem, described here [1]."
And in the end, we settled for the 10s wait, crossing our fingers that it will
be alright :)
--
Cheers,
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] mm/cma: reject long-term pins of HugeTLB folios overlapping crashkernel CMA
2026-11-26 13:07 ` David Hildenbrand (Arm)
@ 2026-11-26 15:16 ` Sang-Heon Jeon
0 siblings, 0 replies; 6+ messages in thread
From: Sang-Heon Jeon @ 2026-11-26 15:16 UTC (permalink / raw)
To: David Hildenbrand (Arm)
Cc: Usama Arif, Andrew Morton, 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
Hi, Usama, David, Michal
2026년 11월 26일 (목) 오후 10:07, David Hildenbrand (Arm) <david@kernel.org>님이 작성:
>
> On 11/25/26 22:49, Usama Arif wrote:
> >
> >
> > 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.
>
> We have in there:
>
> "This option increases the risk of a kdump failure: DMA transfers configured by
> the first kernel may end up corrupting the second kernel's memory."
>
> ... but I recall some discussions about short-term vs. long-term vs. cma
> discussions.
>
> Ah: https://lore.kernel.org/all/ZWJllXCN0SDIELrX@dwarf.suse.cz/
>
> "User pages for RDMA, should be pinned with FOLL_LONGTERM and that
> would migrate them away from the CMA area.
>
> But you're right that DMA to user pages pinned without
> FOLL_LONGTERM would still be possible. Would this be a problem in
> practice? Do you see any way around it?
> "
>
> And later (me):
>
> https://lore.kernel.org/all/04904e86-5b5f-4aa1-a120-428dac119189@redhat.com/
>
> "What does "short" mean? At least in theory, long-term pinning is
> forbidden for MIGRATE_CMA, so we should not have such pages mapped into
> an iommu where DMA can happily keep going on for quite a while.
>
> But that assumes that our old kernel is not buggy, and doesn't end up
> mapping these pages into an IOMMU where DMA will just continue. I recall
> that DRM might currently be a problem, described here [1]."
>
>
> And in the end, we settled for the 10s wait, crossing our fingers that it will
> be alright :)
Thanks for the explanation. So, the possibility of corruption of
CMA-based crashkernel is already well known, and should be taken care
of by administrators. I also agree that saving memory by reusing
hugetlb cma could be very helpful, and it's not a good idea to block
that.
Feel free to drop this patch. Sorry for the noise.
Best regards,
Sang-Heon Jeon
> --
> Cheers,
>
> David
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-26 15:17 UTC | newest]
Thread overview: 6+ 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-26 13:07 ` David Hildenbrand (Arm)
2026-11-26 15:16 ` Sang-Heon Jeon
2026-11-25 22:43 ` David Hildenbrand (Arm)
2026-11-26 8:21 ` Michal Hocko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox