mm/damon/core: set ctx->call_controls_obsolete in damon_new_ctx()

damon_ctx->call_controls_obsolete is used to disallow damon_call()
requests when the request cannot be served.  The field is unset and set
when the context execution is started and terminated, respectively.  The
intention is to allow damon_call() requests only while the context is
actively being executed.

damon_ctx constructor, damon_new_ctx() unsets the field, though.  As a
result, passing the damon_ctx parameter that never successfully
damon_start()-ed to damon_call() can indefinitely hang.  The callers
should ensure to avoid the case.  Such parameter validation is not always
simple.  Actually such bugs in DAMON_RECLAIM and DAMON_LRU_SORT have been
found and fixed [1].

Set the field in damon_new_ctx(), so that DAMON API callers can pass the
context parameter to damon_call() without the additional check.

Link: https://lore.kernel.org/20260903010334.93622-3-sj@kernel.org
Link: https://lore.kernel.org/20260803134646.16640-1-sj@kernel.org [1]
Signed-off-by: SJ Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
SJ Park 2026-09-02 18:03:31 -07:00 committed by Andrew Morton
parent 616e096d43
commit 1fecdf1d56

View File

@ -933,6 +933,7 @@ struct damon_ctx *damon_new_ctx(void)
INIT_LIST_HEAD(&ctx->adaptive_targets);
INIT_LIST_HEAD(&ctx->schemes);
ctx->call_controls_obsolete = true;
prandom_seed_state(&ctx->rnd_state, get_random_u64());
return ctx;
@ -2206,10 +2207,6 @@ int damon_kdamond_pid(struct damon_ctx *ctx)
* synchronization. The return value of the function will be saved in
* &damon_call_control->return_code.
*
* Note that this function should be called only after damon_start() with the
* @ctx has succeeded. Otherwise, this function could fall into an indefinite
* wait.
*
* When this function is failed, the @ctx is guaranteed to be stopped.
*
* Return: 0 on success, negative error code otherwise.