DAMON development mailing list
 help / color / mirror / Atom feed
* [RFC PATCH mm-hotfixes-unstable] mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel()
@ 2026-11-22 22:40 SJ Park
  2026-11-22 22:46 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: SJ Park @ 2026-11-22 22:40 UTC (permalink / raw)
  Cc: SJ Park, stable, Andrew Morton, damon, linux-mm

DAMOS walk could be unexpectedly only partially performed.  It can
happen when there are multiple schemes and the walk is requested after
the previous walk is canceled.

The expectation of DAMOS walk for a setup that has multiple schemes is
that it will walk for one snapshot for all schemes.  To know if the walk
for the one snapshot of a given scheme is done, each damos struct has
the walk_completed field.  It is set when the walk for the given scheme
is completed.  The walk skips schemes having the field set.  It is reset
for all schemes when all the schemes get it set.

damos_walk_cancel() cancels all existing walks.  But it does not reset
the walk_completed field.  damos_walk_cancel() can be called at any
kdamond loop iteration.  For example, due to DAMON context pause or
DAMOS watermarks-caused deactivation.  It means that the function can be
called while only some of the schemes completed their walks.  And users
could request another walk after the canceled walk.  In the case,
because some of the schemes still have walk_completed fields set, the
walk for them is skipped.  As a result, DAMOS walk based user operations
such as update_schemes_tried_bytes kdamond command could show incomplete
output.

Fix by unsetting the fields of all schemes in damos_walk_cancel().

The user impact is not critical.  No crash or leak happens.  Only DAMOS
based monitoring results retrieval could work unexpectedly, under the
certain setup and the race.  Given the best effort nature of DAMON, such
occasional monitoring quality degradation would be not critical.

The issue has found from the Sashiko bug database.

Closes: https://sashiko.dev/#/bug/linux-228a4c52-0545-4c1f-90ce-41114d8272e9
Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
Cc: <stable@vger.kernel.org> # 6.14.x
Signed-off-by: SJ Park <sj@kernel.org>
---
 mm/damon/core.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/mm/damon/core.c b/mm/damon/core.c
index b8678a53b0a98..ec7f20b7856de 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -2699,6 +2699,7 @@ static void damos_walk_complete(struct damon_ctx *ctx, struct damos *s)
 static void damos_walk_cancel(struct damon_ctx *ctx)
 {
 	struct damos_walk_control *control;
+	struct damos *s;
 
 	mutex_lock(&ctx->walk_control_lock);
 	control = ctx->walk_control;
@@ -2706,6 +2707,9 @@ static void damos_walk_cancel(struct damon_ctx *ctx)
 
 	if (!control)
 		return;
+
+	damon_for_each_scheme(s, ctx)
+		s->walk_completed = false;
 	control->canceled = true;
 	complete(&control->completion);
 	mutex_lock(&ctx->walk_control_lock);

base-commit: bcafbab5174a89c3f689e458b5114641a0f68032
-- 
2.47.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RFC PATCH mm-hotfixes-unstable] mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel()
  2026-11-22 22:40 [RFC PATCH mm-hotfixes-unstable] mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel() SJ Park
@ 2026-11-22 22:46 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-22 22:46 UTC (permalink / raw)
  To: SJ Park; +Cc: damon

> DAMOS walk could be unexpectedly only partially performed.  It can
> happen when there are multiple schemes and the walk is requested after
> the previous walk is canceled.
> 
> The expectation of DAMOS walk for a setup that has multiple schemes is
> that it will walk for one snapshot for all schemes.  To know if the walk
> for the one snapshot of a given scheme is done, each damos struct has
> the walk_completed field.  It is set when the walk for the given scheme
> is completed.  The walk skips schemes having the field set.  It is reset
> for all schemes when all the schemes get it set.
> 
> damos_walk_cancel() cancels all existing walks.  But it does not reset
> the walk_completed field.  damos_walk_cancel() can be called at any
> kdamond loop iteration.  For example, due to DAMON context pause or
> DAMOS watermarks-caused deactivation.  It means that the function can be
> [ ... ]
> 
> Closes: https://sashiko.dev/#/bug/linux-228a4c52-0545-4c1f-90ce-41114d8272e9
> Fixes: bf0eaba0ff9c ("mm/damon/core: implement damos_walk()")
> Cc: <stable@vger.kernel.org> # 6.14.x
> Signed-off-by: SJ Park <sj@kernel.org>

Sashiko has reviewed this patch and found no issues.

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-22 22:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 22:40 [RFC PATCH mm-hotfixes-unstable] mm/damon/core: cleanup damos->walk_completed in damos_walk_cancel() SJ Park
2026-11-22 22:46 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox