From: sashiko-bot@kernel.org
To: gutierrez.asier@huawei-partners.com
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1 3/4] mm/damon: introduce DAMON_HUGEPAGE for hot region hugepage collapsing
Date: Thu, 30 Apr 2026 15:43:38 +0000 [thread overview]
Message-ID: <20260430154338.E22E6C2BCB3@smtp.kernel.org> (raw)
In-Reply-To: <20260430134139.2446417-4-gutierrez.asier@huawei-partners.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Silent failure and invalid state when target PID is not found.
- [High] TOCTOU race condition on `aggr_interval` leading to divide-by-zero kernel panic.
- [Medium] Memory leak of DAMON context upon module initialization failure.
--
commit 982630eef231c8c59229da1208ed3240bf24f081
Author: Asier Gutierrez <gutierrez.asier@huawei-partners.com>
mm/damon: introduce DAMON_HUGEPAGE for hot region hugepage collapsing
This patch introduces a new DAMON module (DAMON_HUGEPAGE)
which collapses hot regions into huge pages.
> diff --git a/mm/damon/hugepage.c b/mm/damon/hugepage.c
> new file mode 100644
> index 0000000000000..02729736dc560
> --- /dev/null
> +++ b/mm/damon/hugepage.c
[ ... ]
> +static struct damos *damon_hugepage_new_scheme(void)
> +{
> + struct damos_access_pattern pattern = {
> + /* Find regions having PMD_SIZE or larger size */
> + .min_sz_region = PMD_SIZE,
> + .max_sz_region = ULONG_MAX,
> + .min_nr_accesses = 0,
> + .max_nr_accesses = UINT_MAX,
> + .min_age_region = min_age /
> + damon_hugepage_mon_attrs.aggr_interval,
Is there a race condition here? Since damon_hugepage_mon_attrs is exposed
as a module parameter, aggr_interval could be modified locklessly. If it is
set to 0 concurrently between the check in damon_hugepage_apply_parameters()
and this division, could it trigger a divide-by-zero kernel panic?
> + .max_age_region = UINT_MAX,
> + };
> +
> + return damon_new_scheme(
> + &pattern,
> + /* synchrounous partial collapse as soon as found */
> + DAMOS_HUGEPAGE, 0,
> + /* under the quota. */
> + &damon_hugepage_quota,
> + &(struct damos_watermarks){}, NUMA_NO_NODE);
> +}
> +
> +static int damon_hugepage_apply_parameters(void)
> +{
> + struct damon_ctx *param_ctx;
> + struct damon_target *param_target;
> + struct damos *scheme;
> + struct damos_quota_goal *goal;
> + struct pid *spid;
> + int err;
> +
> + err = damon_modules_new_vaddr_ctx_target(¶m_ctx, ¶m_target);
> + if (err)
> + return err;
> +
> + param_ctx->addr_unit = addr_unit;
> + param_ctx->min_region_sz = max(DAMON_MIN_REGION_SZ / addr_unit, 1);
> +
> + spid = find_get_pid(monitored_pid);
> + if (!spid)
> + goto out;
Does this silently return success when the monitored PID is not found?
Because err is 0 from the successful context creation above, jumping
to the out label returns 0.
This would cause DAMON to start with an empty context without informing
the user that their configuration failed.
> +
> + param_target->pid = spid;
> +
> + if (!damon_hugepage_mon_attrs.aggr_interval) {
> + err = -EINVAL;
> + goto out;
> + }
[ ... ]
> +static int __init damon_hugepage_init(void)
> +{
> + int err;
> +
> + if (!damon_initialized()) {
> + err = -ENOMEM;
> + goto out;
> + }
> + err = damon_modules_new_vaddr_ctx_target(&ctx, &target);
> + if (err)
> + goto out;
> +
> + call_control.data = ctx;
> +
> + /* 'enabled' has set before this function, probably via command line */
> + if (enabled)
> + err = damon_hugepage_turn(true);
> +
> +out:
> + if (err && enabled)
> + enabled = false;
> + return err;
> +}
Does this code leak the allocated ctx and target if damon_hugepage_turn()
fails?
Because module initialization failure prevents the module exit routine
from running, it seems damon_destroy_ctx() should be called in the error
path to avoid a memory leak.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260430134139.2446417-1-gutierrez.asier@huawei-partners.com?part=3
next prev parent reply other threads:[~2026-04-30 15:43 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 13:41 [RFC PATCH v1 0/4] mm/damon: Introduce a huge page collapsing mechanism using auto tuning gutierrez.asier
2026-04-30 13:41 ` [RFC PATCH v1 1/4] mm/damon: Generalize ctx_target creation for damon_ops_id and add vaddr support gutierrez.asier
2026-04-30 13:41 ` [RFC PATCH v1 2/4] mm/damon: Introduce DAMOS_QUOTA_HUGEPAGE auto tuning gutierrez.asier
2026-04-30 14:31 ` sashiko-bot
2026-04-30 20:06 ` Gutierrez Asier
2026-05-01 0:48 ` SeongJae Park
2026-04-30 13:41 ` [RFC PATCH v1 3/4] mm/damon: introduce DAMON_HUGEPAGE for hot region hugepage collapsing gutierrez.asier
2026-04-30 15:43 ` sashiko-bot [this message]
2026-05-04 14:29 ` Gutierrez Asier
2026-05-01 0:54 ` SeongJae Park
2026-04-30 13:41 ` [RFC PATCH v1 4/4] Documentation/admin-guide/mm/damon: add DAMON-based Hugepage Management documentation gutierrez.asier
2026-04-30 15:46 ` sashiko-bot
2026-05-01 0:57 ` SeongJae Park
2026-05-01 0:41 ` [RFC PATCH v1 0/4] mm/damon: Introduce a huge page collapsing mechanism using auto tuning SeongJae Park
2026-05-04 13:52 ` Gutierrez Asier
2026-05-06 16:41 ` 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=20260430154338.E22E6C2BCB3@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--cc=gutierrez.asier@huawei-partners.com \
--cc=sashiko@lists.linux.dev \
/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