Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/damon/core: introduce damon_call_control->dealloc_on_cancel

Patch series "mm/damon/sysfs: fix refresh_ms control overwriting on
multi-kdamonds usages".

Automatic esssential DAMON/DAMOS status update feature of DAMON sysfs
interface (refresh_ms) is broken [1] for multiple DAMON contexts
(kdamonds) use case, since it uses a global single damon_call_control
object for all created DAMON contexts. The fields of the object,
particularly the list field is over-written for the contexts and it makes
unexpected results including user-space hangup and kernel crashes [2].
Fix it by extending damon_call_control for the use case and updating the
usage on DAMON sysfs interface to use per-context dynamically allocated
damon_call_control object.


This patch (of 2):

When damon_call_control->repeat is set, damon_call() is executed
asynchronously, and is eventually canceled when kdamond finishes. If the
damon_call_control object is dynamically allocated, finding the place to
deallocate the object is difficult. Introduce a new damon_call_control
field, namely dealloc_on_cancel, to ask the kdamond deallocates those
dynamically allocated objects when those are canceled.

Link: https://lkml.kernel.org/r/20250908201513.60802-3-sj@kernel.org
Link: https://lkml.kernel.org/r/20250908201513.60802-2-sj@kernel.org
Fixes: d809a7c64ba8 ("mm/damon/sysfs: implement refresh_ms file internal work")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: Yunjeong Mun <yunjeong.mun@sk.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

SeongJae Park and committed by
Andrew Morton
e6a0deb6 2da6de30

+8 -2
+2
include/linux/damon.h
··· 636 636 * @data: Data that will be passed to @fn. 637 637 * @repeat: Repeat invocations. 638 638 * @return_code: Return code from @fn invocation. 639 + * @dealloc_on_cancel: De-allocate when canceled. 639 640 * 640 641 * Control damon_call(), which requests specific kdamond to invoke a given 641 642 * function. Refer to damon_call() for more details. ··· 646 645 void *data; 647 646 bool repeat; 648 647 int return_code; 648 + bool dealloc_on_cancel; 649 649 /* private: internal use only */ 650 650 /* informs if the kdamond finished handling of the request */ 651 651 struct completion completion;
+6 -2
mm/damon/core.c
··· 2479 2479 mutex_lock(&ctx->call_controls_lock); 2480 2480 list_del(&control->list); 2481 2481 mutex_unlock(&ctx->call_controls_lock); 2482 - if (!control->repeat) 2482 + if (!control->repeat) { 2483 2483 complete(&control->completion); 2484 - else 2484 + } else if (control->canceled && control->dealloc_on_cancel) { 2485 + kfree(control); 2486 + continue; 2487 + } else { 2485 2488 list_add(&control->list, &repeat_controls); 2489 + } 2486 2490 } 2487 2491 control = list_first_entry_or_null(&repeat_controls, 2488 2492 struct damon_call_control, list);