From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.3 03/18] mm/damon/core: always update ->last_nr_accesses for intervals change
Date: Mon, 22 Jun 2026 14:37:13 +0000 [thread overview]
Message-ID: <20260622143713.7ED1C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260622142139.30269-4-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] 32-bit integer overflow in `damon_accesses_bp_to_nr_accesses()` and `damon_nr_accesses_to_accesses_bp()` when interval ratios are large.
--
commit d0875d13ff723f48c4ed975ef9fd7e92fde65c11
Author: SeongJae Park <sj@kernel.org>
mm/damon/core: always update ->last_nr_accesses for intervals change
This commit ensures the last_nr_accesses value in a damon_region is always
updated when intervals change to prevent stale values from causing incorrect
calculations. It updates damon_update_monitoring_result() to unconditionally
scale last_nr_accesses using damon_nr_accesses_for_new_attrs().
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index addd14e4e70bf..bc40a6d10f277 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -873,6 +873,8 @@ static void damon_update_monitoring_result(struct damon_region *r,
> struct damon_attrs *old_attrs, struct damon_attrs *new_attrs,
> bool aggregating)
> {
> + r->last_nr_accesses = damon_nr_accesses_for_new_attrs(
> + r->last_nr_accesses, old_attrs, new_attrs);
[Severity: High]
This is a pre-existing issue, but does this calculation in the underlying
functions risk a 32-bit integer overflow?
The new call to damon_nr_accesses_for_new_attrs() relies on
damon_accesses_bp_to_nr_accesses() and damon_nr_accesses_to_accesses_bp().
Looking at damon_accesses_bp_to_nr_accesses():
mm/damon/core.c:damon_accesses_bp_to_nr_accesses() {
...
return accesses_bp * damon_max_nr_accesses(attrs) / 10000;
}
If a user configures a small sample_interval (e.g., 5ms) and a large
aggr_interval (e.g., 3600s), the ratio calculated by damon_max_nr_accesses()
is 720,000. For an accesses_bp of 10000 (100%), the multiplication yields
7,200,000,000, which exceeds the 32-bit unsigned int maximum and silently
truncates.
Similarly, in damon_nr_accesses_to_accesses_bp():
mm/damon/core.c:damon_nr_accesses_to_accesses_bp() {
...
return mult_frac(nr_accesses, 10000, damon_max_nr_accesses(attrs));
}
The mult_frac macro uses the type of nr_accesses (unsigned int) for its
internal calculations. Can this cause a similar 32-bit overflow when
multiplying the remainder by 10000 if the remainder exceeds 429,496?
> if (!aggregating) {
> r->nr_accesses = damon_nr_accesses_for_new_attrs(
> r->nr_accesses, old_attrs, new_attrs);
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260622142139.30269-1-sj@kernel.org?part=3
next prev parent reply other threads:[~2026-06-22 14:37 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 14:21 [RFC PATCH v1.3 00/18] mm/damon: optimize out nr_accesses_bp SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 01/18] mm/damon: introduce damon_nr_accesses_mvsum() SeongJae Park
2026-06-22 14:36 ` sashiko-bot
2026-06-23 0:19 ` SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 02/18] mm/damon/tests/core-kunit: test damon_mvsum() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 03/18] mm/damon/core: always update ->last_nr_accesses for intervals change SeongJae Park
2026-06-22 14:37 ` sashiko-bot [this message]
2026-06-23 0:20 ` SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 04/18] mm/damon/core: handle unreset nr_accesses in damon_nr_accesses_mvsum() SeongJae Park
2026-06-22 14:42 ` sashiko-bot
2026-06-23 0:23 ` SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 05/18] mm/damon/core: use damon_nr_accesses_mvsum() in __damos_valid_target() SeongJae Park
2026-06-22 14:37 ` sashiko-bot
2026-06-23 0:24 ` SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 06/18] mm/damon/core: use damon_nr_accesses_mvsum() for damos region tracing SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 07/18] mm/damon/sysfs-schemes: use damon_nr_accesses_mvsum() for damo regions SeongJae Park
2026-06-22 14:36 ` sashiko-bot
2026-06-23 0:25 ` SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 08/18] mm/damon/core: remove damon_warn_fix_nr_accesses_corruption() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 09/18] mm/damon/core: remove damon_verify_reset_aggregated() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 10/18] mm/damon/core: remove damon_verify_merge_regions_of() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 11/18] mm/damon/tests/core-kunit: remove nr_accesses_bp setup and tests SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 12/18] selftests/damon/drgn_dump_damon_status: do not dump nr_accesses_bp SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 13/18] mm/damon/core: remove nr_accesses_bp setups and updates SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 14/18] mm/damon/core: remove attrs param from damon_update_region_access_rate() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 15/18] mm/damonn/paddr: remove attrs param from __damon_pa_check_access() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 16/18] mm/damon/vaddr: remove attrs param from __damon_va_check_access() SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 17/18] mm/damon/core: remove damon_moving_sum() and its unit test SeongJae Park
2026-06-22 14:21 ` [RFC PATCH v1.3 18/18] mm/damon: remove damon_region->nr_accesses_bp SeongJae 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=20260622143713.7ED1C1F000E9@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