From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Qi Zheng <qi.zheng@linux.dev>,
muchun.song@linux.dev, osalvador@suse.de,
akpm@linux-foundation.org, azpijr@gmail.com,
lance.yang@linux.dev, fvdl@google.com
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Qi Zheng <zhengqi.arch@bytedance.com>,
stable@vger.kernel.org
Subject: Re: [PATCH v5 2/3] mm: gup: allow long-term pins of CMA-allocated HugeTLB folios
Date: Tue, 17 Nov 2026 10:43:45 +0100 [thread overview]
Message-ID: <558f6c84-84d6-4029-8199-46d4e07c8c0a@kernel.org> (raw)
In-Reply-To: <295af6601ce79f2c2b3dc4352a3279f0e6ac513e.1794907279.git.zhengqi.arch@bytedance.com>
On 11/17/26 10:33, Qi Zheng wrote:
> From: Qi Zheng <zhengqi.arch@bytedance.com>
>
> Long-term pinning rejects HugeTLB folios explicitly allocated from CMA,
> causing unnecessary migration or pinning failures. These folios already
> own their CMA memory and do not need to be migrated out for future CMA
> allocations.
>
> Add cma_folio_is_longterm_pinnable() to recognize these allocations
> through HPG_cma. Allow them to be pinned even in ZONE_MOVABLE, since
> memory blocks overlapping boot-time CMA areas cannot be offlined. Ordinary
> movable allocations that borrow CMA memory remain unpinnable.
>
> Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma")
> Cc: stable@vger.kernel.org
> Suggested-by: Muchun Song <muchun.song@linux.dev>
> Suggested-by: David Hildenbrand (Arm) <david@kernel.org>
> Signed-off-by: Qi Zheng <zhengqi.arch@bytedance.com>
> Acked-by: Muchun Song <muchun.song@linux.dev>
> Reviewed-by: Oscar Salvador <osalvador@suse.de>
> Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
> Reviewed-by: Frank van der Linden <fvdl@google.com>
> ---
> include/linux/cma.h | 3 +++
> include/linux/mm.h | 9 ++++++---
> mm/cma.c | 11 +++++++++++
> 3 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/include/linux/cma.h b/include/linux/cma.h
> index 8555d38a97b1a..d829fd0355bae 100644
> --- a/include/linux/cma.h
> +++ b/include/linux/cma.h
> @@ -21,6 +21,9 @@
> #define CMA_MIN_ALIGNMENT_BYTES (PAGE_SIZE * CMA_MIN_ALIGNMENT_PAGES)
>
> struct cma;
> +struct folio;
> +
> +bool cma_folio_is_longterm_pinnable(struct folio *folio);
>
> extern unsigned long totalcma_pages;
> extern phys_addr_t cma_get_base(const struct cma *cma);
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index daf5c5b567ebc..e71aae8001831 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -38,6 +38,7 @@
> #include <linux/bitops.h>
> #include <linux/iommu-debug-pagealloc.h>
> #include <linux/kcsan-checks.h>
> +#include <linux/cma.h>
>
> struct mempolicy;
> struct anon_vma;
> @@ -3015,15 +3016,18 @@ static inline bool is_zero_folio(const struct folio *folio)
> return is_zero_page(&folio->page);
> }
>
> -/* MIGRATE_CMA and ZONE_MOVABLE do not allow pin folios */
> #ifdef CONFIG_MIGRATION
> +/*
> + * MIGRATE_CMA and ZONE_MOVABLE folios cannot normally be long-term pinned.
> + * CMA may allow pinning folios explicitly allocated from its areas.
> + */
> static inline bool folio_is_longterm_pinnable(struct folio *folio)
> {
> #ifdef CONFIG_CMA
> int mt = folio_migratetype(folio);
>
> if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE)
> - return false;
> + return cma_folio_is_longterm_pinnable(folio);
> #endif
> /* The zero page can be "pinned" but gets special handling. */
> if (is_zero_folio(folio))
> @@ -3042,7 +3046,6 @@ static inline bool folio_is_longterm_pinnable(struct folio *folio)
>
> /* Otherwise, non-movable zone folios can be pinned. */
> return !folio_is_zone_movable(folio);
> -
> }
> #else
> static inline bool folio_is_longterm_pinnable(struct folio *folio)
> diff --git a/mm/cma.c b/mm/cma.c
> index 9ec1d1fd5dff5..fea5d1015319d 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -29,6 +29,7 @@
> #include <linux/highmem.h>
> #include <linux/io.h>
> #include <linux/kmemleak.h>
> +#include <linux/hugetlb.h>
> #include <trace/events/cma.h>
>
> #include "internal.h"
> @@ -38,6 +39,16 @@
> struct cma cma_areas[MAX_CMA_AREAS];
> unsigned int cma_area_count;
>
> +bool cma_folio_is_longterm_pinnable(struct folio *folio)
> +{
> + /*
> + * 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);
> +}
> +
> phys_addr_t cma_get_base(const struct cma *cma)
> {
> WARN_ON_ONCE(cma->nranges != 1);
Thanks.
Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
This can go through Andrew's tree with the other hugetlb stuff.
--
Cheers,
David
next prev parent reply other threads:[~2026-11-17 9:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1794907279.git.zhengqi.arch@bytedance.com>
2026-11-17 9:33 ` [PATCH v5 1/3] x86: hugetlb: disable default CMA reservations on 32-bit kernel Qi Zheng
2026-11-17 9:33 ` [PATCH v5 2/3] mm: gup: allow long-term pins of CMA-allocated HugeTLB folios Qi Zheng
2026-11-17 9:43 ` David Hildenbrand (Arm) [this message]
2026-11-17 9:33 ` [PATCH v5 3/3] mm: hugetlb: fix GFP mask propagation to CMA Qi Zheng
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=558f6c84-84d6-4029-8199-46d4e07c8c0a@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=azpijr@gmail.com \
--cc=fvdl@google.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=osalvador@suse.de \
--cc=qi.zheng@linux.dev \
--cc=stable@vger.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