All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [RFC PATCH 1/4] mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS
Date: Wed, 04 Nov 2026 15:44:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-197530@kernel.org> (raw)
In-Reply-To: <20261104153645.82945-2-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] mm/damon/core: 32-bit overflow calculating age_ms in damos_filter_match()
--

commit 8785e74923668744015c21ff7266b94722501bbc
Author: SJ Park <sj@kernel.org>

mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS

This commit adds a new DAMOS core filter type, DAMOS_FILTER_TYPE_AGE_MS,
allowing schemes to filter target regions by age in milliseconds using
damos_filter->range_min and damos_filter->range_max.

> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index d36823f4d0928..d631863b034db 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c

[ ... ]

> @@ -2552,7 +2554,7 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,
>  	bool matched = false;
>  	struct damon_target *ti;
>  	int target_idx = 0;
> -	unsigned long start, end, wsum;
> +	unsigned long start, end, wsum, age_ms;
>  
>  	*err = 0;
>  	switch (filter->type) {
> @@ -2594,6 +2596,11 @@ static bool damos_filter_match(struct damon_ctx *ctx, struct damon_target *t,
>  		matched = filter->range_min <= wsum &&
>  			wsum <= filter->range_max;
>  		break;
> +	case DAMOS_FILTER_TYPE_AGE_MS:
> +		age_ms = r->age * ctx->attrs.aggr_interval / USEC_PER_MSEC;
> +		matched = filter->range_min <= age_ms &&
> +			age_ms <= filter->range_max;
> +		break;

[Severity: Medium]
Can the multiplication r->age * ctx->attrs.aggr_interval in
damos_filter_match() overflow on 32-bit architectures?

Since r->age is unsigned int and ctx->attrs.aggr_interval is unsigned long
(in microseconds), the multiplication is evaluated in 32-bit unsigned long
on 32-bit platforms before dividing by USEC_PER_MSEC. Once a region's age
exceeds ULONG_MAX microseconds (about 4,295 seconds, or r->age >= 42,950 at
the default 100,000 us aggr_interval), the intermediate product wraps around
and misclassifies old regions with a small age_ms value.

By comparison, damon_hot_score() in mm/damon/ops-common.c casts r->age to
u64 and uses div_u64() to avoid this 32-bit overflow:

	age_in_sec = div_u64((u64)r->age * c->attrs.aggr_interval,
			     USEC_PER_SEC);

Should damos_filter_match() similarly use div_u64((u64)r->age *
ctx->attrs.aggr_interval, USEC_PER_MSEC)?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261104153645.82945-1-sj@kernel.org?part=1


  reply	other threads:[~2026-11-04 15:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 15:36 [RFC PATCH 0/4] DAMOS access pattern supports selecting regions to apply a given SJ Park
2026-11-04 15:36 ` [RFC PATCH 1/4] mm/damon/core: add DAMOS_FILTER_TYPE_AGE_MS SJ Park
2026-11-04 15:44   ` sashiko-bot [this message]
2026-11-04 15:47     ` SJ Park
2026-11-04 15:36 ` [RFC PATCH 2/4] mm/damon/sysfs-schemes: support DAMOS_FILTER_TYPE_AGE_MS SJ Park
2026-11-04 15:50   ` sashiko-bot
2026-11-04 15:51     ` SJ Park
2026-11-04 15:36 ` [RFC PATCH 3/4] Docs/mm/damon/design: update for age_ms damos core filter type SJ Park
2026-11-04 15:53   ` sashiko-bot
2026-11-04 15:36 ` [RFC PATCH 4/4] Docs/admin-guide/mm/damon/usage: update for age_ms damos core filter SJ Park
2026-11-04 15:56   ` sashiko-bot
2026-11-05  1:15 ` [RFC PATCH 0/4] DAMOS access pattern supports selecting regions to apply a given 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=sashiko-outbox-197530@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.