linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: Honggyu Kim <honggyu.kim@sk.com>
Cc: SeongJae Park <sj@kernel.org>,
	damon@lists.linux.dev, Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, kernel_team@skhynix.com,
	Yunjeong Mun <yunjeong.mun@sk.com>
Subject: Re: [PATCH v2 4/4] mm/damon: fix divide by zero in damon_get_intervals_score()
Date: Tue,  1 Jul 2025 10:00:06 -0700	[thread overview]
Message-ID: <20250701170006.53864-1-sj@kernel.org> (raw)
In-Reply-To: <20250701081927.1873-5-honggyu.kim@sk.com>

Hi Honggyu,

On Tue,  1 Jul 2025 17:19:26 +0900 Honggyu Kim <honggyu.kim@sk.com> wrote:

> The current implementation allows having zero size regions with no
> special reasons, but damon_get_intervals_score() gets crashed by divide
> by zero when the region size is zero.
> 
>   [   29.403950] Oops: divide error: 0000 [#1] SMP NOPTI
> 
> This patch fixes the bug, but does not disallow zero size regions to
> keep the backward compatibility since disallowing zero size regions
> might be a breaking change for some users.
> 
> Fixes: f04b0fedbe71 ("mm/damon/core: implement intervals auto-tuning")
> Signed-off-by: Honggyu Kim <honggyu.kim@sk.com>
> Cc: Yunjeong Mun <yunjeong.mun@sk.com>
> ---
>  mm/damon/core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/damon/core.c b/mm/damon/core.c
> index b217e0120e09..e274a4d958d6 100644
> --- a/mm/damon/core.c
> +++ b/mm/damon/core.c
> @@ -1448,7 +1448,10 @@ static unsigned long damon_get_intervals_score(struct damon_ctx *c)
>  			access_events += sz_region * r->nr_accesses;
>  		}
>  	}
> -	target_access_events = max_access_events * goal_bp / 10000;
> +	if (likely(max_access_events) > 0)

This makes checkpatch.pl complaints as below:

WARNING: Using likely should generally have parentheses around the comparison
#39: FILE: mm/damon/core.c:1451:
+       if (likely(max_access_events) > 0)

This is not performance critical part, so I think we can simply drop likely().

> +		target_access_events = max_access_events * goal_bp / 10000;
> +	else
> +		target_access_events = 1;

But, target_access_events could still be zero if goal_bp is zero or
max_access_events * goal_bp is less thatn 10000?

I'd like to simply do the target_access_events calculation as is, and set
target_access_events as 1, if it is zero.  Since this is not a performance
critical path, I think that's ok.

Also, in the previous version, we discussed the reproduction step requires
sample modules.  But seems we can also reproduce this with the official DAMON
sysfs ABI by setting the intervals goal zero, and I just confirmed that.  Let's
Cc stable@.

>  	return access_events * 10000 / target_access_events;
>  }
>  
> -- 
> 2.34.1


Thanks,
SJ


  reply	other threads:[~2025-07-01 17:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-01  8:19 [PATCH v2 0/4] mm/damon: fix divide by zero and its samples Honggyu Kim
2025-07-01  8:19 ` [PATCH v2 1/4] samples/damon: fix damon sample prcl for start failure Honggyu Kim
2025-07-01  8:19 ` [PATCH v2 2/4] samples/damon: fix damon sample wsse " Honggyu Kim
2025-07-01  8:19 ` [PATCH v2 3/4] samples/damon: fix damon sample mtier " Honggyu Kim
2025-07-01  8:19 ` [PATCH v2 4/4] mm/damon: fix divide by zero in damon_get_intervals_score() Honggyu Kim
2025-07-01 17:00   ` SeongJae Park [this message]
2025-07-02  0:08     ` Honggyu Kim

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=20250701170006.53864-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=damon@lists.linux.dev \
    --cc=honggyu.kim@sk.com \
    --cc=kernel_team@skhynix.com \
    --cc=linux-mm@kvack.org \
    --cc=yunjeong.mun@sk.com \
    /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;
as well as URLs for NNTP newsgroup(s).