From: SeongJae Park <sj@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: SeongJae Park <sj@kernel.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [PATCH 3/3] mm/damon/core: use time_after_eq() in kdamond_fn()
Date: Sat, 7 Mar 2026 11:49:14 -0800 [thread overview]
Message-ID: <20260307194915.203169-4-sj@kernel.org> (raw)
In-Reply-To: <20260307194915.203169-1-sj@kernel.org>
damon_ctx->passed_sample_intervals and damon_ctx->next_*_sis are
unsigned long. Those are compared in kdamond_fn() using normal
comparison operators. It is unsafe from overflow. Use time_after_eq(),
which is safe from overflows when correctly used, instead.
Signed-off-by: SeongJae Park <sj@kernel.org>
---
mm/damon/core.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 4ede733a94cc0..cd2d7a8e3fe92 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2915,7 +2915,8 @@ static int kdamond_fn(void *data)
if (ctx->ops.check_accesses)
max_nr_accesses = ctx->ops.check_accesses(ctx);
- if (ctx->passed_sample_intervals >= next_aggregation_sis) {
+ if (time_after_eq(ctx->passed_sample_intervals,
+ next_aggregation_sis)) {
kdamond_merge_regions(ctx,
max_nr_accesses / 10,
sz_limit);
@@ -2935,10 +2936,12 @@ static int kdamond_fn(void *data)
sample_interval = ctx->attrs.sample_interval ?
ctx->attrs.sample_interval : 1;
- if (ctx->passed_sample_intervals >= next_aggregation_sis) {
+ if (time_after_eq(ctx->passed_sample_intervals,
+ next_aggregation_sis)) {
if (ctx->attrs.intervals_goal.aggrs &&
- ctx->passed_sample_intervals >=
- ctx->next_intervals_tune_sis) {
+ time_after_eq(
+ ctx->passed_sample_intervals,
+ ctx->next_intervals_tune_sis)) {
/*
* ctx->next_aggregation_sis might be updated
* from kdamond_call(). In the case,
@@ -2972,7 +2975,8 @@ static int kdamond_fn(void *data)
kdamond_split_regions(ctx);
}
- if (ctx->passed_sample_intervals >= next_ops_update_sis) {
+ if (time_after_eq(ctx->passed_sample_intervals,
+ next_ops_update_sis)) {
ctx->next_ops_update_sis = next_ops_update_sis +
ctx->attrs.ops_update_interval /
sample_interval;
--
2.47.3
prev parent reply other threads:[~2026-03-07 19:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-07 19:49 [PATCH 0/3] mm/damon/core: make passed_sample_intervals comparisons overflow-safe SeongJae Park
2026-03-07 19:49 ` [PATCH 1/3] mm/damon/core: remove damos_set_next_apply_sis() duplicates SeongJae Park
2026-03-07 19:49 ` [PATCH 2/3] mm/damon/core: use time_before() for next_apply_sis SeongJae Park
2026-03-07 19:49 ` SeongJae 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=20260307194915.203169-4-sj@kernel.org \
--to=sj@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.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