From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/
Date: Wed, 8 Jul 2026 07:27:42 -0700 [thread overview]
Message-ID: <20260708142743.124162-1-sj@kernel.org> (raw)
In-Reply-To: <20260708140944.F26821F000E9@smtp.kernel.org>
On Wed, 08 Jul 2026 14:09:44 +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] 32-bit arithmetic overflow in sample count and basis points conversions leads to incorrect scaling for large interval ratios.
> - [High] 32-bit integer overflow in `damon_age_for_new_attrs` when calculating region age during attribute updates on 32-bit architectures.
> --
>
> --- Patch [5]: [PATCH 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ ---
> commit 7659397725f64a348908ab982da60d557f63b8c0
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/
>
> This commit renames damon_nr_accesses_for_new_attrs() to
> damon_nr_samples_for_new_attrs() to reflect its general use for any positive
> sample count.
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 718268df27fa7..800ff6b6d2473 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -890,22 +890,21 @@ static unsigned int damon_sample_count_to_bp(
> > return mult_frac(count, 10000, damon_nr_samples_per_aggr(attrs));
> > }
>
> [Severity: High]
> This is a pre-existing issue, but does this code overflow 32-bit arithmetic
> when the sample count is large?
>
> In mm/damon/core.c:damon_sample_count_to_bp(), the mult_frac macro multiplies
> the remainder by 10000, which can overflow 32-bit arithmetic.
>
> Similarly, in damon_sample_bp_to_count(), the 32-bit multiplication overflows
> since both operands are 32-bit unsigned integers:
>
> mm/damon/core.c:damon_sample_bp_to_count() {
> return bp * damon_nr_samples_per_aggr(attrs) / 10000;
> }
>
> This occurs when the number of samples per aggregation interval exceeds
> roughly 429,496 (e.g., sample_interval=1us and aggr_interval=1s, yielding
> 1,000,000 samples).
>
> This could cause the region access tracking variables to be corrupted and
> truncated during dynamic attribute updates (damon_set_attrs), rendering DAMOS
> memory management schemes dysfunctional.
>
> Both intervals are fully configurable by privileged users via DAMON
> sysfs/debugfs interfaces, or dynamically updated by DAMON's auto-tuning
> feature, making the overflow reachable in real-world scenarios.
Known low priority issue.
>
> [Severity: High]
> This is also a pre-existing issue, but can the region age calculation
> overflow on 32-bit architectures during attribute updates?
>
> Looking at damon_age_for_new_attrs(), the multiplication is limited to the
> architecture's native unsigned long size:
>
> mm/damon/core.c:damon_age_for_new_attrs() {
> return age * old_attrs->aggr_interval / new_attrs->aggr_interval;
> }
>
> On 32-bit architectures, aggr_interval (unsigned long) and age (unsigned int)
> are both 32-bit. The product exceeds ULONG_MAX (4,294,967,295) once the
> stable time exceeds ~4,294 seconds.
>
> This causes an integer overflow before the division, meaning any memory
> region that remains stable for more than ~71.5 minutes will have its age
> wrapped around and reset to an incorrectly small value when DAMON
> attributes are dynamically updated.
>
> This could break DAMOS schemes that target old pages for reclamation.
>
> The bug is automatically triggered by DAMON's auto-tuning thread
> (kdamond_tune_intervals), which periodically calls damon_set_attrs, or via
> user-initiated sysfs attribute updates.
Known low priority issue.
>
> > -static unsigned int damon_nr_accesses_for_new_attrs(unsigned int nr_accesses,
> > +static unsigned int damon_nr_samples_for_new_attrs(unsigned int nr,
> > struct damon_attrs *old_attrs, struct damon_attrs *new_attrs)
> > {
> > return damon_sample_bp_to_count(
> > - damon_sample_count_to_bp(nr_accesses, old_attrs),
> > - new_attrs);
> > + damon_sample_count_to_bp(nr, old_attrs), new_attrs);
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260708135359.122587-1-sj@kernel.org?part=5
Thanks,
SJ
next prev parent reply other threads:[~2026-07-08 14:27 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 13:53 [PATCH 0/7] mm/damon: update probe hits for runtime parameter commits SJ Park
2026-07-08 13:53 ` [PATCH 1/7] mm/damon/core: remove comment and test for nr_to_bp() divide-by-zero SJ Park
2026-07-08 14:13 ` sashiko-bot
2026-07-08 14:25 ` SJ Park
2026-07-08 14:31 ` SJ Park
2026-07-08 13:53 ` [PATCH 2/7] mm/damon/core: s/damon_max_nr_accesses()/damon_nr_samples_per_aggr()/ SJ Park
2026-07-08 13:53 ` [PATCH 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ SJ Park
2026-07-08 13:53 ` [PATCH 4/7] mm/damon/core: s/nr_accesses_to_accesses_bp/sample_count_to_bp/ SJ Park
2026-07-08 14:03 ` sashiko-bot
2026-07-08 14:26 ` SJ Park
2026-07-08 13:53 ` [PATCH 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ SJ Park
2026-07-08 14:09 ` sashiko-bot
2026-07-08 14:27 ` SJ Park [this message]
2026-07-08 13:53 ` [PATCH 6/7] mm/damon/core: update probe hits for new parameter commit SJ Park
2026-07-08 14:08 ` sashiko-bot
2026-07-08 14:28 ` SJ Park
2026-07-08 13:53 ` [PATCH 7/7] mm/damon/core: handle unreset probe_hits in probe_hits_mvsum() SJ Park
2026-07-08 14:34 ` [PATCH 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=20260708142743.124162-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