Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mm/cma: accept memory of CMA areas reserved with memblock_reserve()
@ 2026-10-29 10:18 Mike Rapoport (Microsoft)
  2026-10-29 10:18 ` [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas Mike Rapoport (Microsoft)
  2026-10-29 10:18 ` [PATCH 2/2] mm/cma: accept memory of CMA areas reserved at a fixed address Mike Rapoport (Microsoft)
  0 siblings, 2 replies; 4+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-10-29 10:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Kiryl Shutsemau, Liam R. Howlett, Lorenzo Stoakes, Michal Hocko,
	Mike Rapoport, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-mm, stable

Pages of allocated CMA areas are released to the buddy allocator with
__free_pages(), which does not check for unaccepted memory.

This usually works because memblock accepts the memory it allocates.

However, multi-range CMA areas, used by hugetlb_cma, and fixed CMA areas
requested with cma=<size>@<base> are reserved with memblock_reserve() and
their memory is never accepted.

On TDX and SEV-SNP guests the first access to such a page is fatal.

To ease the backporting, each case is addressed by a separate patch:
- patch 1 accepts the memory of multi-range CMA areas
- patch 2 does the same for the fixed CMA areas

The second patch won't apply cleanly to 6.6 and 6.12, but I believe the
stable team LLMs will take care of that :)

---
Mike Rapoport (Microsoft) (2):
      mm/cma: accept memory of multi-range CMA areas
      mm/cma: accept memory of CMA areas reserved at a fixed address

 mm/cma.c | 4 ++++
 1 file changed, 4 insertions(+)
---
base-commit: 5b0764a53235d3c77e1ed674e836e1b3fe1a4b1f
change-id: 20261029-cma-multi-97fd4e58aa08

--
Sincerely yours,
Mike.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas
  2026-10-29 10:18 [PATCH 0/2] mm/cma: accept memory of CMA areas reserved with memblock_reserve() Mike Rapoport (Microsoft)
@ 2026-10-29 10:18 ` Mike Rapoport (Microsoft)
  2026-10-29 10:52   ` Gupta, Pankaj
  2026-10-29 10:18 ` [PATCH 2/2] mm/cma: accept memory of CMA areas reserved at a fixed address Mike Rapoport (Microsoft)
  1 sibling, 1 reply; 4+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-10-29 10:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Kiryl Shutsemau, Liam R. Howlett, Lorenzo Stoakes, Michal Hocko,
	Mike Rapoport, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-mm, stable

On systems with unaccepted memory, memblock allocations accept the
allocated range, but when cma_declare_contiguous_multi() uses open coded
allocation of multiple ranges, it reserves them with memblock_reserve()
and they are never accepted.

These pages are released to the buddy allocator by cma_activate_area()
with __free_pages() that does not check for unaccepted memory, so the
first access to such a page in a TDX or SEV-SNP guest is fatal.

Accept the memory of each range when it is reserved.

Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested")
Cc: stable@vger.kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 mm/cma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index a10ea37a261da..0035efb1130a5 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -678,6 +678,8 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
 			break;
 		}
 
+		accept_memory(mlp->base, size);
+
 		pr_debug("created region %d: %016llx - %016llx\n",
 		    nr, (u64)mlp->base, (u64)mlp->base + size);
 		cmrp = &cma->ranges[nr++];

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] mm/cma: accept memory of CMA areas reserved at a fixed address
  2026-10-29 10:18 [PATCH 0/2] mm/cma: accept memory of CMA areas reserved with memblock_reserve() Mike Rapoport (Microsoft)
  2026-10-29 10:18 ` [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas Mike Rapoport (Microsoft)
@ 2026-10-29 10:18 ` Mike Rapoport (Microsoft)
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Rapoport (Microsoft) @ 2026-10-29 10:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Kiryl Shutsemau, Liam R. Howlett, Lorenzo Stoakes, Michal Hocko,
	Mike Rapoport, Suren Baghdasaryan, Vlastimil Babka, linux-kernel,
	linux-mm, stable

CMA areas allocated from memblock have their memory accepted by
memblock_alloc_range_nid(), but areas reserved at a fixed address with
memblock_reserve() are not.

If a fixed CMA area is requested by the cma=<size>@<base> command line
parameter, it may be in regular RAM and on TDX and SEV-SNP guests it
must be accepted.

Accept the memory of fixed CMA areas as well, so that all CMA areas are
accepted regardless of how they were reserved.

Fixes: 75d090fd167a ("x86/tdx: Add unaccepted memory support")
Cc: stable@vger.kernel.org
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---
 mm/cma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/cma.c b/mm/cma.c
index 0035efb1130a5..f61d52796f4ef 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -381,6 +381,8 @@ static int __init cma_fixed_reserve(phys_addr_t base, phys_addr_t size)
 		return -EBUSY;
 	}
 
+	accept_memory(base, size);
+
 	return 0;
 }
 

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas
  2026-10-29 10:18 ` [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas Mike Rapoport (Microsoft)
@ 2026-10-29 10:52   ` Gupta, Pankaj
  0 siblings, 0 replies; 4+ messages in thread
From: Gupta, Pankaj @ 2026-10-29 10:52 UTC (permalink / raw)
  To: Mike Rapoport (Microsoft), Andrew Morton, David Hildenbrand
  Cc: Kiryl Shutsemau, Liam R. Howlett, Lorenzo Stoakes, Michal Hocko,
	Suren Baghdasaryan, Vlastimil Babka, linux-kernel, linux-mm,
	stable


> On systems with unaccepted memory, memblock allocations accept the
> allocated range, but when cma_declare_contiguous_multi() uses open coded
> allocation of multiple ranges, it reserves them with memblock_reserve()
> and they are never accepted.
>
> These pages are released to the buddy allocator by cma_activate_area()
> with __free_pages() that does not check for unaccepted memory, so the
> first access to such a page in a TDX or SEV-SNP guest is fatal.
>
> Accept the memory of each range when it is reserved.

Fix looks correct to me.

Any easy way to reproduce and test on SEV SNP?

Thanks,

Pankaj

>
> Fixes: c009da4258f9 ("mm, cma: support multiple contiguous ranges, if requested")
> Cc: stable@vger.kernel.org
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>   mm/cma.c | 2 ++
>   1 file changed, 2 insertions(+)
>
> diff --git a/mm/cma.c b/mm/cma.c
> index a10ea37a261da..0035efb1130a5 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -678,6 +678,8 @@ int __init cma_declare_contiguous_multi(phys_addr_t total_size,
>   			break;
>   		}
>   
> +		accept_memory(mlp->base, size);
> +
>   		pr_debug("created region %d: %016llx - %016llx\n",
>   		    nr, (u64)mlp->base, (u64)mlp->base + size);
>   		cmrp = &cma->ranges[nr++];
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-29 10:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-29 10:18 [PATCH 0/2] mm/cma: accept memory of CMA areas reserved with memblock_reserve() Mike Rapoport (Microsoft)
2026-10-29 10:18 ` [PATCH 1/2] mm/cma: accept memory of multi-range CMA areas Mike Rapoport (Microsoft)
2026-10-29 10:52   ` Gupta, Pankaj
2026-10-29 10:18 ` [PATCH 2/2] mm/cma: accept memory of CMA areas reserved at a fixed address Mike Rapoport (Microsoft)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox