From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.23 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794474280; b=vJBU0naGS+Ss1h5l9KEMZ0qtLpw819DJV543PuitT4yvXJINlVbOSZ/WpY36u5npxXJ5 FNxmuGwAN7TRfDp41Zbu9JWlMHLqjLWAPUQRlU/NAURP70ON/esPMwwfL3YU0PFxLrNRz xoic59Du9OFaxRjySf1BiejQTL0aTVimHOGlrVRZvT3ixQvCJdkF+ocKO2qe+vuR+QDsC ciS3RXGII2GlD32yhZsW/q+BgKhAKfzGadjQvJ71c7yRgu41SFjXVyCRtFVbwPa4KI0HW 7wDtIeYXnARGI9gkR0iTNinyqLuB/5w1q49EXIZj/Y0N/6y7PnD688rpucMK+RidOdw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794474280; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=3QXd43+9YkcDdqXRXfijDPFLngipxJU07bnf2rvgj7k=; b=3KFUSmultb/c1ft6+cUbe7+Hq/PzA6IPgm01fuSxjM167Z0+aLbD2dWRkGPzSYXddqcP d4VI+7iRsPrxgszKYPJF9K6KellvywdYiiK8z/FhdAnu3zahPEh8t4F9wjSn2LrUbWwml X7Vy0R28uelCN0x6l7HQaEqjIBD3BSihixdp9bV60eP1Hn20SnuUC7HhfIpRdECqa6bZo lsjanW+sdsmigfEIynclJapuDL1BYi027iJSJrao7uc+XonzfgO976Mw+s2iO6wvraUjo hLj2dKeAA7mPoqkl6V0mV5d9w0DHHN76+hwobJKSXyfSblT9Wso44WMvpApHUAvCYeg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jQBBi8sk; arc=none smtp.remote-ip=95.215.58.23 Received: from mta1.migadu.com (out-23.mta1.migadu.com [95.215.58.23]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7109E606A327 for ; Thu, 12 Nov 2026 09:04:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7109E606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=jQBBi8sk X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=8Qf+LHzFQU7sWVDR2P/LLaDSEFd56f41ktqAEc9o61g=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1794474277; v=1; x=1795079077; b=jQBBi8skxsUmEGg7hgwl5JSxXg48EUwvnKFRaYkIg+/x+bn6PT2Qf94ueriElqvJRdjbGXL+ wAX1gW4SAtXCwlINFhQQPaa269TqOTKCTLqthogsTDg00QhNrVzKBeJpwWIfrwVQksUNfQGsuSt AHo7FxKOYP5lSWWFzv9ZK1Xw= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 8b0e325b35ab9706; Thu, 12 Nov 2026 09:04:37 +0000 X-Mizu-Trace-ID: 8b0e325b35ab9706 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Thu, 12 Nov 2026 17:04:28 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/3] mm: gup: allow long-term pins of CMA-allocated HugeTLB folios To: "David Hildenbrand (Arm)" , Muchun Song Cc: osalvador@suse.de, akpm@linux-foundation.org, azpijr@gmail.com, Lance Yang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Qi Zheng References: <503c9f6d869e3206c6fd591de962c3d619b73825.1794379433.git.zhengqi.arch@bytedance.com> <80FED512-77D2-4D49-BAE5-745CE1F711CA@linux.dev> <1116fd15-a927-4f6e-a0ab-084bc36a90aa@linux.dev> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/12/26 4:49 PM, David Hildenbrand (Arm) wrote: > On 11/12/26 07:13, Qi Zheng wrote: >> >> >> On 11/11/26 3:42 PM, Muchun Song wrote: >>> >>> >>>> >>>> From: Qi Zheng >>>> >>>> Long-term pinning treats explicitly CMA-allocated HugeTLB folios as >>>> unpinnable, causing unnecessary migration or pinning failures. >>>> >>>> These folios already own their CMA bitmap ranges, and memory blocks >>> >>> Commit message needs updating to bitmap as well. >> >> Will do. >> >>> >>>> overlapping CMA areas cannot be offlined. Allow HugeTLB folios with >>>> HPG_cma to be pinned directly, including in ZONE_MOVABLE. >>>> >>>> Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages >>>> using cma") >>>> Cc: stable@vger.kernel.org >>>> Suggested-by: Muchun Song >>>> Signed-off-by: Qi Zheng >>>> Acked-by: Muchun Song >>>> Reviewed-by: Oscar Salvador >>>> Reviewed-by: Jose A. Perez de Azpillaga >>>> --- >>>> include/linux/mm.h | 29 +---------------------------- >>>> mm/gup.c           | 31 +++++++++++++++++++++++++++++++ >>>> 2 files changed, 32 insertions(+), 28 deletions(-) >>>> >>>> diff --git a/include/linux/mm.h b/include/linux/mm.h >>>> index b0da9be413098..47d1d96bfc7fd 100644 >>>> --- a/include/linux/mm.h >>>> +++ b/include/linux/mm.h >>>> @@ -2954,35 +2954,8 @@ 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 >>>> -static inline bool folio_is_longterm_pinnable(struct folio *folio) >>> >>> I think David prefer to move this function first, then fix it in a separate >>> patch, >>> right? >> >> Hi David, is this what you mean? If so, I will split it into two patches >> for the v5. > > Let's try something that is more future-directed: cma should deal with > cma details. In the future we might implement something reasonable there. Aha, that does make more sense. Will do. Thanks, Qi > > 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 6af3b7008f1ad..5392e225cab9b 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -3,6 +3,7 @@ > #define _LINUX_MM_H > > #include > +#include > #include > #include > #include > @@ -2975,7 +2976,10 @@ 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 */ > +/* > + * MIGRATE_CMA and ZONE_MOVABLE folios cannot normally be long-term pinned. > + * CMA may allow pinning folios explicitly allocated from its areas. > + */ > #ifdef CONFIG_MIGRATION > static inline bool folio_is_longterm_pinnable(struct folio *folio) > { > @@ -2983,7 +2987,7 @@ static inline bool folio_is_longterm_pinnable(struct folio *folio) > 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)) > diff --git a/mm/cma.c b/mm/cma.c > index 9ec1d1fd5dff5..b3bf0014a90f5 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -27,6 +27,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -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 bitmap ranges 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);