DAMON development mailing list
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 13/16] mm/damon/sysfs: implement probe/weight file
Date: Mon,  6 Jul 2026 17:08:39 -0700	[thread overview]
Message-ID: <20260707000841.97795-1-sj@kernel.org> (raw)
In-Reply-To: <20260706151939.847A71F000E9@smtp.kernel.org>

On Mon, 06 Jul 2026 15:19:38 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Unbounded `weight` from sysfs causes an integer overflow in `damon_probe_hits_wsum()`, which corrupts the core region scoring algorithm.
> - [High] Setting a large `weight` via sysfs trivially bypasses the `max_nr_regions` limit, leading to unbounded kernel memory usage and CPU starvation.
> --
> 
> commit 13d5322850c993787f439a6daf8065f8717e7f80
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/sysfs: implement probe/weight file
> 
> This commit implements a new sysfs file, weight, under the probe directory.
> Users can set the probe weight and enable monitoring using it.
> 
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index b65651498e0d1..a8ef7903bf94f 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> 
> [ ... ]
> 
> > @@ -1100,12 +1101,35 @@ static void damon_sysfs_probe_rm_dirs(struct damon_sysfs_probe *probe)
> 
> [ ... ]
> 
> > +static ssize_t weight_store(struct kobject *kobj,
> > +		struct kobj_attribute *attr, const char *buf, size_t count)
> > +{
> > +	struct damon_sysfs_probe *probe = container_of(kobj,
> > +			struct damon_sysfs_probe, kobj);
> > +	int err = kstrtouint(buf, 0, &probe->weight);
> 
> [Severity: High]
> Does this allow an unbounded unsigned int weight to be set, potentially
> causing an integer overflow during calculation?
> 
> In damon_probe_hits_wsum(), the score is calculated by multiplying the
> hits and the weight:
> 
> mm/damon/core.c:damon_probe_hits_wsum() {
>     ...
>     sum += r->last_probe_hits[i++] * probe->weight;
>     ...
> }
> 
> Because weight is allowed to be up to UINT_MAX, and probe_hits can be up to
> 255, could this calculation wrap around? If it wraps around, regions with a
> higher number of probe hits might erroneously compute a lower weighted sum
> than colder regions, which seems like it would break the ability to
> accurately track memory.

A minor issue for unlikely user setup.  But I agree this is better to be fixed,
and the core layer parameters validation makes this easy to fix.  I will work
on fixing this, in the next version of this series, or separately.

> 
> 
> [Severity: High]
> Could a large weight bypass the max_nr_regions limit and lead to unbounded
> region growth?
> 
> In kdamond_merge_regions(), the merge loop condition checks against max_thres:
> 
> mm/damon/core.c:kdamond_merge_regions() {
>     ...
>     } while (nr_regions > c->attrs.max_nr_regions &&
>              threshold / 2 < max_thres);
>     ...
> }
> 
> The initial threshold scales with the unbounded weight. If a user configures a
> large weight, does threshold / 2 immediately exceed max_thres on the first
> loop iteration?
> 
> This would cause the loop to terminate prematurely, failing to iteratively
> increase the threshold to merge regions. Could this allow the number of
> regions to grow without bound and lead to severe CPU starvation?

Yes, but only for one aggregation interval.  I don't think this is an issue.

> 
> > +
> > +	return err ? err : count;
> > +}
> > +
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260706141912.88445-1-sj@kernel.org?part=13


Thanks,
SJ

[...]

  reply	other threads:[~2026-07-07  0:08 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-06 14:18 [RFC PATCH v1.1 00/16] mm/damon: introduce data attributes only monitoring SJ Park
2026-07-06 14:18 ` [RFC PATCH v1.1 01/16] mm/damon/core: introduce damon_probe->weight SJ Park
2026-07-06 14:18 ` [RFC PATCH v1.1 02/16] mm/damon/core: ask apply_probes() ops callback to set sampling address SJ Park
2026-07-06 14:18 ` [RFC PATCH v1.1 03/16] mm/damon/paddr: set samples in apply_probes() if requested SJ Park
2026-07-06 14:18 ` [RFC PATCH v1.1 04/16] mm/damon/core: ask apply_probe() to return max probe hits weighted sum SJ Park
2026-07-06 14:39   ` sashiko-bot
2026-07-06 23:42     ` SJ Park
2026-07-06 14:18 ` [RFC PATCH v1.1 05/16] mm/damon/core: implement damon_probe_hits_wsum() SJ Park
2026-07-06 14:41   ` sashiko-bot
2026-07-06 23:46     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 06/16] mm/damon/paddr: respect return_max_wsum SJ Park
2026-07-06 14:44   ` sashiko-bot
2026-07-06 23:47     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 07/16] mm/damon/core: extend merge function to work with probe hits SJ Park
2026-07-06 14:55   ` sashiko-bot
2026-07-06 23:52     ` SJ Park
2026-07-07  3:30       ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 08/16] mm/damon/core: disable access monitoring when probe weights are set SJ Park
2026-07-06 15:03   ` sashiko-bot
2026-07-06 23:54     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 09/16] mm/damon/core: set samples in apply_probes() if " SJ Park
2026-07-06 15:02   ` sashiko-bot
2026-07-06 23:56     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 10/16] mm/damon/core: s/max_nr_accesses/max_merge_score/ in kdamond_fn() SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 11/16] mm/damon/core: get merge threshold from probe hits when weights are set SJ Park
2026-07-06 15:18   ` sashiko-bot
2026-07-07  0:03     ` SJ Park
2026-07-07  3:34       ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 12/16] mm/damon/core: implement damon_has_probe_weight() SJ Park
2026-07-06 15:16   ` sashiko-bot
2026-07-07  0:05     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 13/16] mm/damon/sysfs: implement probe/weight file SJ Park
2026-07-06 15:19   ` sashiko-bot
2026-07-07  0:08     ` SJ Park [this message]
2026-07-06 14:19 ` [RFC PATCH v1.1 14/16] Docs/mm/damon/design: document attrs-only monitoring SJ Park
2026-07-06 15:34   ` sashiko-bot
2026-07-07  0:11     ` SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 15/16] Docs/admin-guide/mm/damon/usage: document weight sysfs file SJ Park
2026-07-06 14:19 ` [RFC PATCH v1.1 16/16] Docs/ABI/damon: document probe weight file SJ Park
2026-07-07  0:13 ` [RFC PATCH v1.1 00/16] mm/damon: introduce data attributes only monitoring 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=20260707000841.97795-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox