Re: [PATCH 1/3] mm/hugetlb_cma: fix incorrect hugetlb_cma_size assignment on malformed input

From: Oscar Salvador (SUSE)

Date: Wed Oct 28 2026 - 10:46:58 EST


On Wed, Oct 28, 2026 at 07:33:17PM +0800, Kaitao Cheng wrote:
> From: Kaitao Cheng <chengkaitao@xxxxxxxxxx>
>
> When hugetlb_cma contains a global size after node-specific entries,
> cmdline_parse_hugetlb_cma() enters the global branch and reparses the
> original parameter string. For hugetlb_cma=1:2G,4G, this interprets the
> initial node ID as a one-byte global size and clears the 2 GiB reservation
> recorded for node 1.
>
> Global and node-specific formats cannot be mixed. Return -EINVAL when a
> global entry follows a node-specific entry, before updating any settings.
> This preserves the valid prefix, so the example retains node 1's 2 GiB
> reservation and reports the malformed option.
>
> Fixes: 38e719ab2673 ("hugetlb: support node specified when using cma for gigantic hugepages")
> Closes: https://sashiko.dev/#/bug/linux-10f40d3e-3feb-4622-9da8-1fedecb2d0e2
> Signed-off-by: Kaitao Cheng <chengkaitao@xxxxxxxxxx>

Reviewed-by: Oscar Salvador <osalvador@xxxxxxx>

> ---
> mm/hugetlb_cma.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/mm/hugetlb_cma.c b/mm/hugetlb_cma.c
> index 95fd2d190f0d..8e6b20341fc4 100644
> --- a/mm/hugetlb_cma.c
> +++ b/mm/hugetlb_cma.c
> @@ -167,6 +167,9 @@ static int __init cmdline_parse_hugetlb_cma(char *p)
> } else {
> char *next;
>
> + if (s != p)
> + return -EINVAL;
> +
> tmp = memparse(p, &next);
> if (*next == '%') {
> if (tmp > 100) {
> --
> 2.53.0
>

--
Oscar Salvador
SUSE Labs