From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>, "Andrew Morton" <akpm@linux-foundation.org>
Cc: damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH 2/2] mm/damon/ops-common: use probe hits weighted sum in damon_hot_score()
Date: Thu, 03 Dec 2026 15:37:44 +0000 [thread overview]
Message-ID: <sashiko-outbox-248130@kernel.org> (raw)
In-Reply-To: <20261203151352.731319-3-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/damon: 32-bit overflow in mult_frac() inside
damon_freq_subscore()
--
commit 3b171ba030ec37fe884a6ae50ff0018c6075df31
Author: SJ Park <sj@kernel.org>
mm/damon/ops-common: use probe hits weighted sum in damon_hot_score()
This commit adds damon_freq_subscore() so damon_hot_score() uses the
weighted sum of probe hits instead of nr_accesses when probe weights are
configured.
> diff --git a/mm/damon/ops-common.c b/mm/damon/ops-common.c
> index 38720794c9fcf..adbdba6dc6da0 100644
> --- a/mm/damon/ops-common.c
> +++ b/mm/damon/ops-common.c
> @@ -165,6 +165,25 @@ void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
> #define DAMON_MAX_SUBSCORE (100)
> #define DAMON_MAX_AGE_IN_LOG (32)
>
> +static int damon_freq_subscore(struct damon_ctx *c,
> + struct damon_region *r)
> +{
> + unsigned int num, denom, samples_per_aggr;
> + struct damon_probe *p;
> +
> + samples_per_aggr = damon_nr_samples_per_aggr(&c->attrs);
> + if (damon_has_probe_weights(c)) {
> + num = damon_probe_hits_wsum(r, false, true, c);
> + denom = 0;
> + damon_for_each_probe(p, c)
> + denom += samples_per_aggr * p->weight;
> + } else {
> + num = damon_nr_accesses_mvsum(r, c);
> + denom = samples_per_aggr;
> + }
> + return mult_frac(num, DAMON_MAX_SUBSCORE, denom);
> +}
[Severity: Medium]
As reported by Aveline Noir on RFC v3 [1], can mult_frac() overflow 32-bit
arithmetic here?
Because num is an unsigned int, mult_frac() computes (num % denom) * 100
in 32 bits and wraps whenever num % denom exceeds UINT_MAX / 100.
damon_valid_probe_params() allows denom up to UINT_MAX, so with
samples_per_aggr = 100 and weight = 1,000,000, 43 hits wraps to 0.
When freq_subscore wraps to 0, damon_hot_score() negates age_in_log and
scores hot long-lived regions as coldest, inverting DAMOS quota
prioritization. Using div_u64((u64)num * DAMON_MAX_SUBSCORE, denom)
avoids the overflow.
[1] https://lore.kernel.org/r/179623279152.18.12629425945716322074.b4-reply@b4
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203151352.731319-1-sj@kernel.org?part=2
prev parent reply other threads:[~2026-12-03 15:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 15:13 [PATCH 0/2] mm/damon: aware attr-only mode in DAMOS quota region selection SJ Park
2026-12-03 15:13 ` [PATCH 1/2] mm/damon/core: expose damon_has_probe_weights() SJ Park
2026-12-03 15:13 ` [PATCH 2/2] mm/damon/ops-common: use probe hits weighted sum in damon_hot_score() SJ Park
2026-12-03 15:37 ` sashiko-bot [this message]
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=sashiko-outbox-248130@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-mm@kvack.org \
--cc=sashiko-reviews@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