From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v2 3/3] mm/damon/stat: detect and use fresh enabled value
Date: Sat, 18 Apr 2026 05:54:16 +0000 [thread overview]
Message-ID: <20260418055417.1399AC19424@smtp.kernel.org> (raw)
In-Reply-To: <20260418014439.6353-4-sj@kernel.org>
Sashiko AI review found 1 potential issue(s):
- [Medium] Leaking damon_stat_context when explicitly disabling DAMON_STAT after an unexpected kdamond termination.
--
commit 4bf999258ec2f00a1ac02dbd77ac9f923e38bd2f
Author: SeongJae Park <sj@kernel.org>
mm/damon/stat: detect and use fresh enabled value
This commit modifies DAMON_STAT to dynamically check the kdamond status
when the enabled parameter is requested, rather than relying on a cached
parameter value. This ensures users do not see stale values if kdamond
stops unexpectedly.
> diff --git a/mm/damon/stat.c b/mm/damon/stat.c
> index 99ba346f9e325..3951b762cbddf 100644
> --- a/mm/damon/stat.c
> +++ b/mm/damon/stat.c
[ ... ]
> @@ -273,17 +276,23 @@ static void damon_stat_stop(void)
> damon_stat_context = NULL;
> }
>
> +static bool damon_stat_enabled(void)
> +{
> + if (!damon_stat_context)
> + return false;
> + return damon_is_running(damon_stat_context);
> +}
> +
> static int damon_stat_enabled_store(
> const char *val, const struct kernel_param *kp)
> {
> - bool is_enabled = enabled;
> int err;
>
> err = kstrtobool(val, &enabled);
> if (err)
> return err;
>
> - if (is_enabled == enabled)
> + if (damon_stat_enabled() == enabled)
> return 0;
Could this leak damon_stat_context if the kdamond thread stops unexpectedly?
If kdamond terminates due to an internal failure,
damon_is_running(damon_stat_context) returns false, making
damon_stat_enabled() also return false.
If a user then explicitly disables DAMON_STAT by writing 'N' to the enabled
parameter, both damon_stat_enabled() and enabled would be false. This causes
the function to return 0 early, bypassing the call to damon_stat_stop().
Since damon_stat_stop() is the function responsible for invoking
damon_destroy_ctx() and setting damon_stat_context to NULL, does this bypass
leave the context structure allocated?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260418014439.6353-1-sj@kernel.org?part=3
next prev parent reply other threads:[~2026-04-18 5:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-18 1:44 [RFC PATCH v2 0/3] mm/damon/modules: detect and use fresh status SeongJae Park
2026-04-18 1:44 ` [RFC PATCH v2 1/3] mm/damon/reclaim: detect and use fresh enabled and kdamond_pid values SeongJae Park
2026-04-18 4:57 ` sashiko-bot
2026-04-18 15:14 ` SeongJae Park
2026-04-18 1:44 ` [RFC PATCH v2 2/3] mm/damon/lru_sort: " SeongJae Park
2026-04-18 5:30 ` sashiko-bot
2026-04-18 15:36 ` SeongJae Park
2026-04-18 1:44 ` [RFC PATCH v2 3/3] mm/damon/stat: detect and use fresh enabled value SeongJae Park
2026-04-18 5:54 ` sashiko-bot [this message]
2026-04-18 15: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=20260418055417.1399AC19424@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko@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