Re: [PATCH v3 2/2] mm/damon/reclaim: validate min_region_size to be power of 2

SeongJae Park
2026-04-03T16:20:52Z

On Fri, 3 Apr 2026 13:23:50 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:

> The damon_commit_ctx() checks if 'min_region_sz' is a power-of-2.
> However, if an invalid input is provided via the DAMON_RECLAIM interface,
> the validation failure occurs too late, causing kdamond to terminate
> unexpectedly.
>
> To reproduce:
> 1. Enable DAMON_RECLAIM.
> 2. Set an invalid 'addr_unit' (e.g., addr_unit=3) so that
> 'min_region_sz = DAMON_MIN_REGION_SZ / addr_unit' becomes
> non-power-of-2.
> 3. Commit parameters, and observe kdamond termination.
>
> This patch adds an early check in damon_reclaim_apply_parameters() to
> validate 'min_region_sz' and return -EINVAL immediately if it is not a
> power-of-2, preventing unexpected kdamond termination.
>
> Fixes: 7db551fcfb2a ("mm/damon/reclaim: support addr_unit for DAMON_RECLAIM")
> Cc: <stable@vger.kernel.org> # 6.18.x

I'm not very sure if this deserves Cc-ing stable@. I posted more details on my
reply to the first patch of this series. Let's discuss further on the thread.

I will skip reviewing this patch until the discussion on the thread is done.

Thanks,
SJ …