From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
Date: Tue, 1 Sep 2026 18:13:12 -0700 [thread overview]
Message-ID: <20260902011314.110041-1-sj@kernel.org> (raw)
In-Reply-To: <20260902003951.11EED1F000E9@smtp.kernel.org>
On Wed, 02 Sep 2026 00:39:50 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Inconsistent state handling in damon_commit_ctx() on memory allocation failure.
> --
>
> commit c0fdc35d2fb6726e726ba0e857811cbaefc34918
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit
>
> damos_commit_quota_goal_union() is not updating the ->nid union field
> when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP. Hence, if a
> DAMOS quota goal of the type is online committed in a way that it will
> reuse other quota goal's memory space, the new goal will work with a
> garbage nid value. As a result, the DAMOS scheme can show unexpected
> aggressiveness.
>
> > damos_commit_quota_goal_union() is not updating the ->nid union field
> > when the goal metric is DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP.
>
> This isn't a bug, but there's a typo (DAMOS_QUITA_NODE_ELIGIBLE_MEM_BP) in
> the commit message.
Good catch. I will ask Andrew if he could fix this while picking this.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 647ac77f573bb..a499d7866c507 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -1143,6 +1143,9 @@ static void damos_commit_quota_goal_union(
> > dst->nid = src->nid;
> > dst->memcg_id = src->memcg_id;
> > break;
> > + case DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP:
> > + dst->nid = src->nid;
> > + break;
> > default:
> > break;
> > }
>
> [Severity: High]
> This isn't a bug introduced by this patch, but is a pre-existing logic
> flaw in the core DAMON commit mechanism on memory allocation failure.
>
> In mm/damon/core.c:damon_commit_ctx():
>
> err = __damon_commit_ctx(test_ctx, src);
> if (err)
> goto out;
> err = __damon_commit_ctx(dst, src);
>
> If the second call to __damon_commit_ctx() fails with -ENOMEM, won't it
> leave the active dst context corrupted?
>
> For example, an OOM condition can occur here in
> mm/damon/core.c:damon_commit_schemes():
>
> new_scheme = damon_new_scheme(&src_scheme->pattern,
> src_scheme->action,
> src_scheme->apply_interval_us,
> &src_scheme->quota, &src_scheme->wmarks,
> NUMA_NO_NODE);
> if (!new_scheme)
> return -ENOMEM;
>
> A failure here exits the commit process without rolling back prior scheme
> updates, leaving the active dst context partially updated.
>
> The kernel handles this by setting dst->maybe_corrupted = true, which
> forces the kdamond monitoring thread to terminate gracefully but permanently.
>
> Could this be triggered by a user-initiated online parameter update
> encountering an OOM condition during the second __damon_commit_ctx()
> invocation?
>
> Does this violate the atomic nature of damon_commit_ctx() (which uses
> test_ctx precisely to avoid partial updates on the active context) and
> cause an unintended loss of the running context?
Such user would need to have sysfs write permission first. With the
permission, the user could do whatever, even worse than stopping DAMON.
So no issue in my opinion.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260902002725.108635-1-sj@kernel.org?part=3
Thanks,
SJ
next prev parent reply other threads:[~2026-09-02 1:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 0:27 [PATCH 0/4] mm/damon: fix misc bugs in kunit, quota goals and sysfs refresh_ms SJ Park
2026-09-02 0:27 ` [PATCH 1/4] mm/damon/tests/core-kunit: test committing psi goal to psi goal SJ Park
2026-09-02 0:34 ` sashiko-bot
2026-09-03 8:33 ` Kunwu Chan
2026-09-02 0:27 ` [PATCH 2/4] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total SJ Park
2026-09-02 0:34 ` sashiko-bot
2026-09-03 9:23 ` Kunwu Chan
2026-09-02 0:27 ` [PATCH 3/4] mm/damon/core: copy nid for eligible_mem_bp damos quota goal commit SJ Park
2026-09-02 0:39 ` sashiko-bot
2026-09-02 1:13 ` SJ Park [this message]
2026-09-02 1:14 ` SJ Park
2026-09-03 8:45 ` Kunwu Chan
2026-09-03 13:49 ` SJ Park
2026-09-02 0:27 ` [PATCH 4/4] mm/damon/sysfs: set next refresh jiffies per sysfs context SJ Park
2026-09-02 0:39 ` sashiko-bot
2026-09-03 10:01 ` Kunwu Chan
2026-09-02 1:16 ` [PATCH 0/4] mm/damon: fix misc bugs in kunit, quota goals and sysfs refresh_ms SJ Park
2026-09-03 3:13 ` Lian Wang
2026-09-03 13:51 ` 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=20260902011314.110041-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.