From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.2 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/
Date: Wed, 08 Jul 2026 01:42:40 +0000 [thread overview]
Message-ID: <20260708014241.346731F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708013252.95888-4-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The calculation of sample counts and ratios in `damon_sample_bp_to_count()` and `damon_nr_accesses_to_accesses_bp()` can suffer from a 32-bit integer overflow under extreme interval configurations, leading to corrupted DAMON metrics.
--
--- Patch [3]: [RFC PATCH v1.2 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ ---
commit e8ec17a3e305676513352140eeb31c1b75063618
Author: SJ Park <sj@kernel.org>
mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/
This commit renames accesses_bp_to_nr_accesses() to sample_bp_to_count()
to better describe its actual behavior. The function converts a positive
samples ratio into a count.
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -876,11 +876,11 @@ static unsigned int damon_age_for_new_attrs(unsigned int age,
> return age * old_attrs->aggr_interval / new_attrs->aggr_interval;
> }
>
> -/* convert access ratio in bp (per 10,000) to nr_accesses */
> -static unsigned int damon_accesses_bp_to_nr_accesses(
> - unsigned int accesses_bp, struct damon_attrs *attrs)
> +/* convert sample ratio in bp (per 10,000) to count */
> +static unsigned int damon_sample_bp_to_count(
> + unsigned int bp, struct damon_attrs *attrs)
> {
> - return accesses_bp * damon_nr_samples_per_aggr(attrs) / 10000;
> + return bp * damon_nr_samples_per_aggr(attrs) / 10000;
[Severity: High]
This is a pre-existing issue, but can the 32-bit unsigned arithmetic here
silently overflow under extreme configurations?
If an automated tool configures DAMON via sysfs (for example, with
sample_us = 1 and aggr_us = 1000000) such that the ratio
aggr_interval / sample_interval exceeds 429,496, the multiplication
bp * damon_nr_samples_per_aggr(attrs) would exceed 32 bits.
This could return a heavily truncated count, potentially corrupting access
metrics and causing flawed memory management decisions.
A similar overflow appears to happen in the calculation of the ratio in
damon_nr_accesses_to_accesses_bp(). When it calls mult_frac, the parameter
nr_accesses is an unsigned int, causing nr_accesses * 10000 to overflow
and wrap around when evaluating the remainder multiplication.
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260708013252.95888-1-sj@kernel.org?part=3
next prev parent reply other threads:[~2026-07-08 1:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 1:32 [RFC PATCH v1.2 0/7] mm/damon: update probe hits for runtime parameter commits SJ Park
2026-07-08 1:32 ` [RFC PATCH v1.2 1/7] mm/damon/core: remove comment and test for nr_to_bp() divide-by-zero SJ Park
2026-07-08 1:43 ` sashiko-bot
2026-07-08 1:32 ` [RFC PATCH v1.2 2/7] mm/damon/core: s/damon_max_nr_accesses()/damon_nr_samples_per_aggr()/ SJ Park
2026-07-08 1:45 ` sashiko-bot
2026-07-08 1:32 ` [RFC PATCH v1.2 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ SJ Park
2026-07-08 1:42 ` sashiko-bot [this message]
2026-07-08 1:32 ` [RFC PATCH v1.2 4/7] mm/damon/core: s/nr_accesses_to_accesses_bp/sample_count_to_bp/ SJ Park
2026-07-08 1:48 ` sashiko-bot
2026-07-08 1:32 ` [RFC PATCH v1.2 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ SJ Park
2026-07-08 1:45 ` sashiko-bot
2026-07-08 1:32 ` [RFC PATCH v1.2 6/7] mm/damon/core: update probe hits for new parameter commit SJ Park
2026-07-08 1:47 ` sashiko-bot
2026-07-08 1:32 ` [RFC PATCH v1.2 7/7] mm/damon/core: handle unreset probe_hits in probe_hits_mvsum() SJ Park
2026-07-08 2:32 ` [RFC PATCH v1.2 0/7] mm/damon: update probe hits for runtime parameter commits 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=20260708014241.346731F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=damon@lists.linux.dev \
--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