From: Liew Rui Yan <aethernet65535@gmail.com>
To: aethernet65535@gmail.com
Cc: damon@lists.linux.dev, linux-mm@kvack.org, sj@kernel.org
Subject: Re: (sashiko review) [RFC PATCH] mm/damon: reset thread status parameters upon kdamond termination
Date: Tue, 31 Mar 2026 02:53:47 +0800 [thread overview]
Message-ID: <20260330185347.45872-1-aethernet65535@gmail.com> (raw)
In-Reply-To: <20260330164347.12772-1-aethernet65535@gmail.com>
Forwarding Sashiko review for doing discussions via mails.
# review url: https://sashiko.dev/#/patchset/20260330164347.12772-1-aethernet65535@gmail.com
# start of sashiko.dev inline review
commit 636b179cc5df5a638d7988bd9de56ce4d8602f4a
Author: Liew Rui Yan <aethernet65535@gmail.com>
mm/damon: reset thread status parameters upon kdamond termination
This commit introduces a thread status structure in the DAMON context to
link the kdamond state with module parameters. It updates these parameters
when the kdamond thread finishes to reflect its actual state.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index db6c67e52d2b..6c71203beec5 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
[ ... ]
> @@ -2941,6 +2944,14 @@ static void kdamond_init_ctx(struct damon_ctx *ctx)
> }
> }
>
> +static void damon_update_thread_status(struct damon_ctx *ctx)
> +{
> + if (ctx->thread_status.kdamond_pid)
> + *ctx->thread_status.kdamond_pid = -1;
> + if (ctx->thread_status.enabled)
> + *ctx->thread_status.enabled = false;
Can this write race with the user enabling the module? If a user writes 'Y'
to 'enabled', the store function spawns kdamond and prepares to set 'enabled'
to true. If kdamond exits immediately (e.g., due to invalid targets), could
this line asynchronously set 'enabled' to false before the store function
overwrites it with true?
If so, the system would be left in a state where the thread is dead but
'enabled' is true. Subsequent attempts to write 'N' to 'enabled' would fail
on damon_stop(), leaving the module permanently locked.
> +}
> +
> /*
> * The monitoring daemon that runs as a kernel thread
> */
[ ... ]
> @@ -3065,17 +3076,23 @@ static int kdamond_fn(void *data)
> kdamond_call(ctx, true);
> damos_walk_cancel(ctx);
>
> - pr_debug("kdamond (%d) finishes\n", current->pid);
> mutex_lock(&ctx->kdamond_lock);
> ctx->kdamond = NULL;
> mutex_unlock(&ctx->kdamond_lock);
>
> + if (ctx->thread_status.enabled && *ctx->thread_status.enabled)
Can this access freed memory? If the kdamond_lock is dropped and
ctx->kdamond is NULL, damon_is_running(ctx) becomes false. If a concurrent
sysfs operation removes the context, could ctx be freed by damon_destroy_ctx()
before these lines execute, causing a use-after-free and memory corruption in
damon_update_thread_status(ctx)?
> + pr_debug("kdamond (%d) crashed\n", current->pid);
Does this log normal user-requested shutdowns as crashes? When a user stops
the module by writing 'N' to 'enabled', the parameter store blocks on
damon_stop(). Since the global 'enabled' variable is still true at this
point, won't this incorrectly print a crash message instead of finishing
normally?
> + else
> + pr_debug("kdamond (%d) finishes\n", current->pid);
> +
> mutex_lock(&damon_lock);
> nr_running_ctxs--;
> if (!nr_running_ctxs && running_exclusive_ctxs)
> running_exclusive_ctxs = false;
> mutex_unlock(&damon_lock);
>
> + damon_update_thread_status(ctx);
> +
> return 0;
> }
# end of sashiko.dev inline review
# review url: https://sashiko.dev/#/patchset/20260330164347.12772-1-aethernet65535@gmail.com
#
# hkml [1] generated a draft of this mail. It can be regenerated
# using below command:
#
# hkml patch sashiko_dev --for_forwarding \
# 20260330164347.12772-1-aethernet65535@gmail.com
#
# [1] https://github.com/sjp38/hackermail
next prev parent reply other threads:[~2026-03-30 18:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 16:43 [RFC PATCH] mm/damon: reset thread status parameters upon kdamond termination Liew Rui Yan
2026-03-30 18:53 ` Liew Rui Yan [this message]
2026-03-30 19:51 ` (sashiko review) " Liew Rui Yan
2026-03-30 22:42 ` Liew Rui Yan
2026-03-31 5:02 ` SeongJae Park
2026-03-31 6:58 ` Liew Rui Yan
2026-03-31 16:09 ` Liew Rui Yan
2026-04-01 0:44 ` SeongJae Park
2026-04-01 8:24 ` Liew Rui Yan
2026-04-01 15:41 ` SeongJae Park
2026-04-02 5:34 ` Liew Rui Yan
2026-04-02 13:54 ` SeongJae Park
2026-04-03 4:34 ` Liew Rui Yan
2026-04-03 14:06 ` SeongJae Park
2026-04-01 0:29 ` SeongJae Park
2026-04-01 8:23 ` Liew Rui Yan
2026-04-02 0:40 ` SeongJae Park
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=20260330185347.45872-1-aethernet65535@gmail.com \
--to=aethernet65535@gmail.com \
--cc=damon@lists.linux.dev \
--cc=linux-mm@kvack.org \
--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