Skip to content

Commit 2949282

Browse files
sjp38akpm00
authored andcommitted
mm/damon/reclaim: schedule 'damon_reclaim_timer' only after 'system_wq' is initialized
Commit 059342d ("mm/damon/reclaim: fix the timer always stays active") made DAMON_RECLAIM's 'enabled' parameter store callback, 'enabled_store()', to schedule 'damon_reclaim_timer'. The scheduling uses 'system_wq', which is initialized in 'workqueue_init_early()'. As kernel parameters parsing function ('parse_args()') is called before 'workqueue_init_early()', 'enabled_store()' can be executed before 'workqueue_init_early()' and end up accessing the uninitialized 'system_wq'. As a result, the booting hang[1]. This commit fixes the issue by checking if the initialization is done before scheduling the timer. [1] https://lkml.kernel.org/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: 059342d ("mm/damon/reclaim: fix the timer always stays active") Signed-off-by: SeongJae Park <[email protected]> Reported-by: Greg White <[email protected]> Cc: Hailong Tu <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d25c83c commit 2949282

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

mm/damon/reclaim.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ static void damon_reclaim_timer_fn(struct work_struct *work)
374374
}
375375
static DECLARE_DELAYED_WORK(damon_reclaim_timer, damon_reclaim_timer_fn);
376376

377+
static bool damon_reclaim_initialized;
378+
377379
static int enabled_store(const char *val,
378380
const struct kernel_param *kp)
379381
{
@@ -382,6 +384,10 @@ static int enabled_store(const char *val,
382384
if (rc < 0)
383385
return rc;
384386

387+
/* system_wq might not initialized yet */
388+
if (!damon_reclaim_initialized)
389+
return rc;
390+
385391
if (enabled)
386392
schedule_delayed_work(&damon_reclaim_timer, 0);
387393

@@ -449,6 +455,8 @@ static int __init damon_reclaim_init(void)
449455
damon_add_target(ctx, target);
450456

451457
schedule_delayed_work(&damon_reclaim_timer, 0);
458+
459+
damon_reclaim_initialized = true;
452460
return 0;
453461
}
454462

0 commit comments

Comments
 (0)