DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH 5/9] mm/damon/core: document damon_call()/damon_start() race hang issue
Date: Sat, 12 Sep 2026 20:19:44 +0000	[thread overview]
Message-ID: <20260912201944.AA8D91F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260912200814.145612-6-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Brittle cancellation polling loop in damon_call() can cause indefinite hangs on rapid context restarts.
- [High] Missing initialization of `walk_control_obsolete` in `damon_new_ctx()` causes unrecoverable hangs in `damos_walk()`.
--

commit edbd3bc657324e35d324500107e2e30a1ffabc31
Author: SJ Park <sj@kernel.org>

mm/damon/core: document damon_call()/damon_start() race hang issue

This commit documents a potential race condition and indefinite hang between
damon_start() and damon_call() if they are executed in parallel for the same
DAMON context. It adds a cautionary comment to damon_call() to warn API
users about this behavior.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index 6e4b0144c3dd1..f304813a08460 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -2218,6 +2218,9 @@ int damon_kdamond_pid(struct damon_ctx *ctx)
>   *
>   * When this function is failed, the @ctx is guaranteed to be stopped.
>   *
> + * This function should not be called in parallel to damon_start() for the
> + * @ctx.  In the case, this function could indefinitely hang.
> + *

[Severity: High]
This is a pre-existing issue, but does the cancellation polling loop in
damon_call() cause indefinite hangs on rapid context restarts?

If Thread A is blocked in damon_call(), and Thread B stops the DAMON context
(e.g., via module parameters), the monitoring thread cancels the call and
exits.

If Thread A is preempted before evaluating the canceled polling loop,
and Thread C concurrently restarts the context, Thread A resumes, evaluates
damon_is_running(ctx) to true (due to the newly spawned thread), and hangs
forever waiting for the new thread to stop:

mm/damon/core.c:damon_call() {
    ...
canceled:
        while (damon_is_running(ctx))
                schedule_timeout_idle(msecs_to_jiffies(100));
        return -ECANCELED;
}

This race can be triggered by root via concurrent sysfs or module parameter
writes (e.g., in damon_reclaim).

[Severity: High]
This is a pre-existing issue, but does the missing initialization of
walk_control_obsolete in damon_new_ctx() cause unrecoverable hangs in
damos_walk()?

damon_new_ctx() explicitly initializes call_controls_obsolete = true to
protect damon_call() from hanging if invoked before the context is started.
However, it fails to initialize walk_control_obsolete:

mm/damon/core.c:damon_new_ctx() {
    ...
        ctx->call_controls_obsolete = true;
        prandom_seed_state(&ctx->rnd_state, get_random_u64());
    ...
}

If damos_walk() is called before damon_start(), it bypasses the safety check
and blocks forever on wait_for_completion(), because no thread exists to
signal it:

mm/damon/core.c:damos_walk() {
    ...
        mutex_lock(&ctx->walk_control_lock);
        if (ctx->walk_control_obsolete) {
                mutex_unlock(&ctx->walk_control_lock);
                return -ECANCELED;
        }
    ...
}

Even though it requires erroneous API usage, the API intends to gracefully
reject this via the obsolete flag. The missing initialization breaks this
boundary, leading to an unkillable hang.

>   * Return: 0 on success, negative error code otherwise.
>   */
>  int damon_call(struct damon_ctx *ctx, struct damon_call_control *control)

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912200814.145612-1-sj@kernel.org?part=5

  reply	other threads:[~2026-09-12 20:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12 20:08 [RFC PATCH 0/9] mm/damon: cleanup, clarify, and add/improve test SJ Park
2026-09-12 20:08 ` [RFC PATCH 1/9] mm/damon/api: remove NR_DAMOS_FILTER_TYPES SJ Park
2026-09-12 20:10   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 2/9] mm/damon/core: use abs_diff() in damon_feed_loop_next_input() SJ Park
2026-09-12 20:14   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 3/9] mm/damon/core: use mult_frac() " SJ Park
2026-09-12 20:12   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 4/9] mm/damon/core: use damos_quota_is_set() in damos_adjust_quota() SJ Park
2026-09-12 20:14   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 5/9] mm/damon/core: document damon_call()/damon_start() race hang issue SJ Park
2026-09-12 20:19   ` sashiko-bot [this message]
2026-09-12 20:08 ` [RFC PATCH 6/9] mm/damon/paddr: remove pa parameter from damon_pa_filter_pass() SJ Park
2026-09-12 20:13   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 7/9] selftests/damon/sysfs_memcg_path_leak: fail only for real DAMON leak SJ Park
2026-09-12 20:15   ` sashiko-bot
2026-09-12 20:20     ` SJ Park
2026-09-12 20:08 ` [RFC PATCH 8/9] mm/damon/tests/core-kunit: test eligible_mem_bp commitment SJ Park
2026-09-12 20:10   ` sashiko-bot
2026-09-12 20:08 ` [RFC PATCH 9/9] Docs/mm/damon/design: clarify bp is basis point SJ Park
2026-09-12 20:10   ` sashiko-bot
2026-09-12 20:26   ` Randy Dunlap

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260912201944.AA8D91F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox