Re: [RFC v2] mm/damon: add synchronous validation for commit_inputs

SeongJae Park
2026-03-21T17:32:42Z

Hello Liew,

On Sat, 21 Mar 2026 22:09:26 +0800 Liew Rui Yan <aethernet65535@gmail.com> wrote:

> Problem
> =======
> Writing invalid parameters to sysfs followed by 'commit_inputs=Y' fails
> silently (no error returned to shell), because the validation happens
> aynchronously in the kdamond.
>
> Solution
> ========
> To fix this, I proposed adding synchronous validation in
> damon_lru_sort_commit_inputs_store() and
> damon_reclaim_commit_inputs_store() before setting the 'commit_inputs'
> flag. This allow users to receive immediate feedback (e.g., -EINVAL) if
> the parameters are invalid.
>
> Changes
> =======
> 1. Added damon_lru_sort_commit_inputs_store() and
> damon_reclaim_commit_inputs_store() to handle parameter validation
> before setting 'commit_inputs'.

Nice idea. I think we could do even applying parameters in the callback. It
could be something similar to what DAMON_SYSFS is doing. The code path for
doing that in DAMON_SYSFS is, state_store() -> damon_sysfs_handle_cmd() ->
damon_sysfs_damon_call() -> damon_call() -> damon_sysfs_commit_input(). In the
damon_sysfs_commit_input(), you can show how DAMON_SYSFS validates input. You
can also refer to commit 4c9ea539ad59 ("mm/damon/sysfs: validate user inputs
from damon_sysfs_commit_input()") for more details.

> 2. Added damon_validate_attrs() to centralize validation logic.

I think damon_commit_ctx() is a better way for validation.

>
> This change is motivated from another discussion [1].
>
> [1] https://lore.kernel.org/20260318153731.97470-1-aethernet65535@gmail.com
>
> Signed-off-by: Liew Rui Yan <aethernet65535@gmail.com>

Because this is an RFC and I have a high level comment above, I'm skipping
detailed review of the code.

Thanks,
SJ …