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 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp()
Date: Sun, 2 Aug 2026 10:51:49 -0700 [thread overview]
Message-ID: <20260802175150.2143-1-sj@kernel.org> (raw)
In-Reply-To: <20260802165105.947281F000E9@smtp.kernel.org>
On Sun, 02 Aug 2026 16:51:05 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] 32-bit integer overflows and truncations in DAMON memory metric calculations cause wildly incorrect quota logic on 32-bit architectures.
> --
>
> --- Patch [9]: [RFC PATCH v1.1 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() ---
> commit e72445b8d3c8d0866c458b7707c7433d7912c2e6
> Author: SJ Park <sj@kernel.org>
>
> mm/damon/core: handle extreme memory state in get_in_active_mem_bp()
>
> This commit addresses a divide-by-zero issue in damos_get_in_active_mem_bp().
> It ensures the denominator is at least 1 when calculating the ratio of
> active or inactive memory, preventing a crash if both are zero.
>
> Link: https://lore.kernel.org/20260721034756.147011-1-sj@kernel.org
>
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 67ad1f07c29a4..c79b854e1a971 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -3014,7 +3014,7 @@ static unsigned int damos_get_in_active_mem_bp(bool active_ratio)
> > global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE);
> > inactive = global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_ANON) +
> > global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE);
> > - total = active + inactive;
> > + total = max(active + inactive, 1);
> > if (active_ratio)
>
> [Severity: High]
> This is a pre-existing issue, but does this code overflow 32-bit unsigned
> math on 32-bit architectures?
>
> The mult_frac(x, n, d) macro computes (x / d) * n + (x % d) * n / d. Since
> n is 10000, the multiplication x * 10000 is performed using 32-bit unsigned
> arithmetic on 32-bit systems (where unsigned long is 32 bits). If active
> memory exceeds 429,496 pages (~1.76 GB), the multiplication overflows
> ULONG_MAX, resulting in an incorrect ratio.
>
> Does this same overflow also affect other DAMON memory metric calculations?
> For example, in damos_get_node_eligible_mem_bp():
>
> return mult_frac((unsigned long)node_eligible, 10000,
> (unsigned long)total_eligible);
>
> This explicitly casts a 64-bit phys_addr_t to unsigned long, truncating
> capacities over 4GB on 32-bit systems. It also overflows mult_frac() if the
> eligible memory exceeds just ~419 KB.
>
> Similarly, in damon_get_intervals_score():
>
> max_access_events += sz_region * c->attrs.aggr_samples;
> access_events += sz_region * r->nr_accesses;
>
> Because sz_region is in bytes, accumulating these into an unsigned long
> seems to overflow for regions larger than a few tens of megabytes.
Known low priority issue.
>
> > return mult_frac(active, 10000, total);
> > return mult_frac(inactive, 10000, total);
> > }
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260802162631.90304-1-sj@kernel.org?part=9
>
Thanks,
SJ
prev parent reply other threads:[~2026-08-02 17:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-02 16:26 [RFC PATCH v1.1 0/9] mm/damon: fix DAMOS bugs in core, paddr and vaddr SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 1/9] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 2/9] mm/damon/core: initialize damos_quota_goal->last_psi_total SJ Park
2026-08-02 16:43 ` sashiko-bot
2026-08-02 17:41 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 3/9] mm/damon/paddr: respect folio end for DAMOS_STAT SJ Park
2026-08-02 16:34 ` sashiko-bot
2026-08-02 17:43 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 4/9] mm/damon/paddr: respect folio end for DAMOS actions except STAT SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 5/9] mm/damon/vaddr: respect folio end for DAMOS_STAT SJ Park
2026-08-02 16:36 ` sashiko-bot
2026-08-02 17:45 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 6/9] mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD} SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 7/9] mm/damon/core: handle extreme memory state in damon_get_node_mem_bp() SJ Park
2026-08-02 16:35 ` sashiko-bot
2026-08-02 17:49 ` SJ Park
2026-08-02 17:59 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 8/9] mm/damon/core: handle extreme memory state in get_node_memcg_used_bp() SJ Park
2026-08-02 16:38 ` sashiko-bot
2026-08-02 17:51 ` SJ Park
2026-08-02 16:26 ` [RFC PATCH v1.1 9/9] mm/damon/core: handle extreme memory state in get_in_active_mem_bp() SJ Park
2026-08-02 16:51 ` sashiko-bot
2026-08-02 17:51 ` SJ Park [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=20260802175150.2143-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