From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 1/7] mm/damon/core: initialize damos->last_applied
Date: Fri, 17 Jul 2026 17:53:15 -0700 [thread overview]
Message-ID: <20260718005316.89585-1-sj@kernel.org> (raw)
In-Reply-To: <20260718003220.DEDC31F000E9@smtp.kernel.org>
On Sat, 18 Jul 2026 00:32:20 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Uninitialized memory use in DAMOS quota goals allocation (last_psi_total and nid).
> - [High] damos_quota_init() modifies the passed quota struct, unintentionally resetting runtime quota statistics of actively running schemes.
> --
>
> --- Patch [1]: [PATCH 1/7] mm/damon/core: initialize damos->last_applied ---
> commit 316d27ac2ea17607b5c9df656020658fa1b425df
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: initialize damos->last_applied
>
> This commit initializes the last_applied field of the damos scheme struct to
> NULL in damon_new_scheme(). This prevents an uninitialized value from causing
> a DAMON scheme to unexpectedly skip applying an action to a folio the very
> first time.
>
> Link: https://lore.kernel.org/20260714055436.120034-1-sj@kernel.org
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 603b102ff80f9..20d267c615faf 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -705,6 +705,7 @@ struct damos *damon_new_scheme(struct damos_access_pattern *pattern,
> > INIT_LIST_HEAD(&scheme->ops_filters);
> > scheme->stat = (struct damos_stat){};
> > scheme->max_nr_snapshots = 0;
> > + scheme->last_applied = NULL;
> > INIT_LIST_HEAD(&scheme->list);
> >
> > scheme->quota = *(damos_quota_init(quota));
>
> [Severity: High]
> This is a pre-existing issue, but does damos_quota_init() unintentionally reset
> the runtime statistics of actively running schemes?
>
> When updating a DAMON context via sysfs, damon_commit_ctx() calls
> damon_new_test_ctx() which iterates over running schemes and calls
> damon_new_scheme(), passing the active &src_scheme->quota pointer.
>
> Inside damon_new_scheme(), it executes:
> scheme->quota = *(damos_quota_init(quota));
>
> If damos_quota_init() directly modifies the passed pointer:
>
> mm/damon/core.c:damos_quota_init() {
> quota->esz = 0;
> quota->total_charged_sz = 0;
> quota->total_charged_ns = 0;
> quota->charged_sz = 0;
> ...
> }
>
> It appears this silently clears the tracking variables of the actively running
> scheme, potentially breaking the ability to track memory usage limits.
No. The damon_new_scheme() is for a case the commit is adding new scheme to
the destination context. There is no data to erase.
>
> [Severity: High]
> This isn't a bug introduced by this patch, but while reviewing initialization,
> I noticed a potential issue with quota goals. Are the metric-specific fields in
> damos_new_quota_goal() left uninitialized?
>
> When allocating a new goal via sysfs or damon_commit_ctx():
>
> mm/damon/core.c:damos_new_quota_goal() {
> ...
> goal = kmalloc_obj(*goal);
> ...
> }
>
> It seems fields like last_psi_total and nid are not zero-initialized.
>
> Later, damos_commit_quota_goal_union() misses the switch case for
> DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP, leaving dst->nid uninitialized.
>
> This can result in using garbage values when calculating current_value:
>
> mm/damon/core.c:damos_set_quota_goal_current_value() {
> ...
> goal->current_value = damos_get_node_eligible_mem_bp(c, s, goal->nid);
> ...
> }
This is no issue. The caller should set the nid. And core functions using the
nid validates it before really using it.
>
> And for PSI goals:
>
> mm/damon/core.c:damos_set_quota_goal_current_value() {
> ...
> goal->current_value = now_psi_total - goal->last_psi_total;
> goal->last_psi_total = now_psi_total;
> ...
> }
>
> Could subtracting an uninitialized last_psi_total underflow and cause the
> quota tuner to aggressively zero out the quota?
Good finding. I will separately fix this.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260718001442.87129-1-sj@kernel.org?part=1
Thanks,
SJ
next prev parent reply other threads:[~2026-07-18 0:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-18 0:14 [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
2026-07-18 0:14 ` [PATCH 1/7] mm/damon/core: initialize damos->last_applied SJ Park
2026-07-18 0:32 ` sashiko-bot
2026-07-18 0:53 ` SJ Park [this message]
2026-07-18 0:14 ` [PATCH 2/7] mm/damon/core-kunit: check region count before testing in split_at() SJ Park
2026-07-18 0:30 ` sashiko-bot
2026-07-18 0:55 ` SJ Park
2026-07-18 0:14 ` [PATCH 3/7] mm/damon/vaddr-kunit: check region count in three_regions test SJ Park
2026-07-18 0:14 ` [PATCH 4/7] mm/damon/core-kunit: handle region split failure in filter_out() SJ Park
2026-07-18 0:29 ` sashiko-bot
2026-07-18 1:00 ` SJ Park
2026-07-18 0:14 ` [PATCH 5/7] mm/damon/core-kunit: skip wrong dest walk in commit_dests_for() SJ Park
2026-07-18 0:25 ` sashiko-bot
2026-07-18 1:01 ` SJ Park
2026-07-18 0:14 ` [PATCH 6/7] mm/damon/core-kunit: skip wrong quota goal walk in commit_quota_goals() SJ Park
2026-07-18 0:22 ` sashiko-bot
2026-07-18 1:02 ` SJ Park
2026-07-18 0:14 ` [PATCH 7/7] mm/damon/core-kunit: skip wrong region walk in commit_target_regions() SJ Park
2026-07-18 1:13 ` [PATCH 0/7] mm/damon: fix uninitialized DAMOS field and kunit exec expectation bugs SJ Park
-- strict thread matches above, loose matches on Subject: below --
2026-07-17 0:30 SJ Park
2026-07-17 0:30 ` [PATCH 1/7] mm/damon/core: initialize damos->last_applied SJ Park
2026-07-17 0:52 ` sashiko-bot
2026-07-17 1:12 ` SJ 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=20260718005316.89585-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.