[RFC PATCH 08/10] mm: hugetlb: disable CMA if liveupdate is enabled

Pratyush Yadav posted 10 patches 2 months ago
Only 9 patches received!
[RFC PATCH 08/10] mm: hugetlb: disable CMA if liveupdate is enabled
Posted by Pratyush Yadav 2 months ago
Hugetlb live update support does not yet work with CMA. Print a warning
and disable CMA if the config for live updating hugetlb is enabled, and
liveupdate is enabled at runtime.

Signed-off-by: Pratyush Yadav <pratyush@kernel.org>
---
 kernel/liveupdate/Kconfig | 3 +++
 mm/hugetlb_cma.c          | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/kernel/liveupdate/Kconfig b/kernel/liveupdate/Kconfig
index 86e76aed8a93..4676fea6d8a6 100644
--- a/kernel/liveupdate/Kconfig
+++ b/kernel/liveupdate/Kconfig
@@ -82,6 +82,9 @@ config LIVEUPDATE_HUGETLB
 	  use hugetlb memfd to back VM memory, or for other user workloads needing
 	  to live update huge pages.
 
+	  Enabling this config disables CMA for hugetlb pages. It is not yet
+	  supported with live update.
+
 	  If unsure, say N.
 
 endmenu
diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c
index e8e4dc7182d5..fa3bb776c0d2 100644
--- a/mm/hugetlb_cma.c
+++ b/mm/hugetlb_cma.c
@@ -4,6 +4,7 @@
 #include <linux/cma.h>
 #include <linux/compiler.h>
 #include <linux/mm_inline.h>
+#include <linux/liveupdate.h>
 
 #include <asm/page.h>
 #include <asm/setup.h>
@@ -152,6 +153,12 @@ void __init hugetlb_cma_reserve(int order)
 	if (!hugetlb_cma_size)
 		return;
 
+	if (IS_ENABLED(CONFIG_LIVEUPDATE_HUGETLB) && liveupdate_enabled()) {
+		pr_warn("HugeTLB: CMA not supported with live update. Falling back to pre-allocating pages.\n");
+		hugetlb_cma_size = 0;
+		return;
+	}
+
 	hugetlb_bootmem_set_nodes();
 
 	for (nid = 0; nid < MAX_NUMNODES; nid++) {
-- 
2.43.0
Re: [RFC PATCH 08/10] mm: hugetlb: disable CMA if liveupdate is enabled
Posted by Pasha Tatashin 1 month, 2 weeks ago
On Sat, Dec 6, 2025 at 6:03 PM Pratyush Yadav <pratyush@kernel.org> wrote:
>
> Hugetlb live update support does not yet work with CMA. Print a warning
> and disable CMA if the config for live updating hugetlb is enabled, and
> liveupdate is enabled at runtime.

Could you please elaborate this commit to explain why it is not
supported, and what it would take to support CMA.

Thanks,
Pasha
Re: [RFC PATCH 08/10] mm: hugetlb: disable CMA if liveupdate is enabled
Posted by Pratyush Yadav 1 month, 1 week ago
On Tue, Dec 23 2025, Pasha Tatashin wrote:

> On Sat, Dec 6, 2025 at 6:03 PM Pratyush Yadav <pratyush@kernel.org> wrote:
>>
>> Hugetlb live update support does not yet work with CMA. Print a warning
>> and disable CMA if the config for live updating hugetlb is enabled, and
>> liveupdate is enabled at runtime.
>
> Could you please elaborate this commit to explain why it is not
> supported, and what it would take to support CMA.

The main reason is that when HugeTLB CMA is enabled, the huge pages come
from CMA. If we have preserved pages, we would need to "insert" those
pages into the CMA when they are restored.

CMA does support multiple ranges, so I suppose it can be done, but it
needs some plumbing to work properly.

Will add this in the next revision.

-- 
Regards,
Pratyush Yadav