Re: [PATCH v5 02/17] kexec: Record allocated CMA pages to fix release size mismatch

From: sashiko-bot

Date: Fri Sep 18 2026 - 07:00:09 EST


> The CMA pages allocated for a kexec segment are released using the
> segment's memsz to calculate the number of pages. However, some
> architecture loaders modify the segment's memsz after allocation
> (e.g. arm64 subtracts text_offset), causing the release function to
> free fewer pages than were originally allocated, leaking the remaining
> CMA pages.
>
> Add a per-segment `segment_cma_pages` array to store the number of
> pages actually allocated from CMA. Populate it during
> kexec_add_buffer() using the aligned memsz, and use it in
> kimage_free_cma() to accurately release all allocated pages.
>
> This avoids relying on the potentially modified segment->memsz and
> prevents silent CMA memory leaks.
>
> Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Baoquan He <baoquan.he@xxxxxxxxx>
> Cc: Mike Rapoport <rppt@xxxxxxxxxx>
> Cc: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>
> Cc: Pratyush Yadav <pratyush@xxxxxxxxxx>
> Cc: Brian Mak <makb@xxxxxxxxxxx>
> Cc: Pingfan Liu <piliu@xxxxxxxxxx>
> Cc: Sourabh Jain <sourabhjain@xxxxxxxxxxxxx>
> Cc: Justinien Bouron <jbouron@xxxxxxxxxx>
> Cc: Li Chen <me@linux.beauty>
> Cc: stable@xxxxxxxxxxxxxxx
> Link: https://sashiko.dev/#/patchset/20260729031235.2840255-1-ruanjinjie%40huawei.com
> Fixes: 07d24902977e ("kexec: enable CMA based contiguous allocation")
> Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>

Sashiko has reviewed this patch and found no issues. It looks great!

--
Sashiko AI review · https://sashiko.dev/#/patchset/20260918100442.3841135-1-ruanjinjie@xxxxxxxxxx?part=2