Skip to contentSkip to conversation

mm-damon-core-cancel-damos_walk-before-damon_ctx-kdamond-reset.patch removed from -mm tree

merged mm-stable Andrew Morton 1 participant 1 message Jan 31

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled

     Subject: mm/damon/core: cancel damos_walk() before damon_ctx->kdamond reset

has been removed from the -mm tree. Its filename was
mm-damon-core-cancel-damos_walk-before-damon_ctx-kdamond-reset.patch

This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: SeongJae Park <[email protected]>
Subject: mm/damon/core: cancel damos_walk() before damon_ctx->kdamond reset
Date: Sat, 17 Jan 2026 09:52:50 -0800

damos_walk() request is canceled after damon_ctx->kdamond is reset. This can make weird situations where damon_is_running() returns false but the DAMON context has the damos_walk() request linked. There was a similar situation for damon_call() requests handling [1], which _was_ able to cause a racy use-after-free bug. Unlike the case of damon_call(), because damos_walk() is always synchronously handled and allows only single request at time, there is no such problematic race cases. But, keeping it as is could stem another subtle race condition bug in future.

Avoid that by cancelling the requests before the ->kdamond reset. Note that this change also makes all damon_ctx dependent resource cleanups consistently done before the damon_ctx->kdamond reset.

---

 mm/damon/core.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-cancel-damos_walk-before-damon_ctx-kdamond-reset +1 -2
@@ -2856,14 +2856,13 @@ done:
 
 	kfree(ctx->regions_score_histogram);
 	kdamond_call(ctx, true);
+	damos_walk_cancel(ctx);
 
 	pr_debug("kdamond (%d) finishes\n", current->pid);
 	mutex_lock(&ctx->kdamond_lock);
 	ctx->kdamond = NULL;
 	mutex_unlock(&ctx->kdamond_lock);
 
-	damos_walk_cancel(ctx);
-
 	mutex_lock(&damon_lock);
 	nr_running_ctxs--;
 	if (!nr_running_ctxs && running_exclusive_ctxs)

_

Patches currently in -mm which might be from [email protected] are