From: SeongJae Park <sj@kernel.org>
Cc: SeongJae Park <sj@kernel.org>,
"# 6 . 17 . x" <stable@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
damon@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: [RFC PATCH v4 5/6] samples/damon/wsse: stop and free damon ctx when damon_call() fails
Date: Wed, 10 Jun 2026 06:55:43 -0700 [thread overview]
Message-ID: <20260610135546.64943-6-sj@kernel.org> (raw)
In-Reply-To: <20260610135546.64943-1-sj@kernel.org>
damon_sample_wsse_start() calls damon_call() right after damon_start()
is succeeded. The kdamond that has started by the damon_start() could
be terminated by itself before or in the middle of the damon_call()
execution. There could be multiple reasons for such a stop including
monitoring target process termination and kdamond_fn() internal memory
allocation failures. In the case, damon_call() will fail and return an
error without cleaning up the DAMON context object. The
damon_sample_wsse_start() caller assumes it would clean up the object,
though. When the user requests to start DAMON again,
damon_sample_wsse_start() is called again, allocates a new DAMON context
object and overwrites the pointer for the previous object. As a result,
the previous context object is leaked.
Safely stop the kdamond and deallocate the context object when the
failure is returned. Note that the kdamond should be stopped first,
because damon_call() failure means not complete termination of the
kdamond but only the fact that the termination process has started.
The user impact shouldn't be that significant because the race is not
easy to happen, and only up to one DAMON context object can be leaked
per race.
The issue was discovered [1] by Sashiko.
[1] https://lore.kernel.org/20260610034828.4632-1-sj@kernel.org
Fixes: cc9c1b8c205b ("samples/damon/wsse: use damon_call() repeat mode instead of damon_callback")
Cc: <stable@vger.kernel.org> # 6.17.x
Signed-off-by: SeongJae Park <sj@kernel.org>
---
samples/damon/wsse.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/samples/damon/wsse.c b/samples/damon/wsse.c
index bbd9392ab5b36..ff5e8a890f448 100644
--- a/samples/damon/wsse.c
+++ b/samples/damon/wsse.c
@@ -92,7 +92,12 @@ static int damon_sample_wsse_start(void)
return err;
}
repeat_call_control.data = ctx;
- return damon_call(ctx, &repeat_call_control);
+ err = damon_call(ctx, &repeat_call_control);
+ if (err) {
+ damon_stop(&ctx, 1);
+ damon_destroy_ctx(ctx);
+ }
+ return err;
}
static void damon_sample_wsse_stop(void)
--
2.47.3
next prev parent reply other threads:[~2026-06-10 13:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-10 13:55 [RFC PATCH v4 0/6] samples/damon: handle damon_{start,stop}() failures SeongJae Park
2026-06-10 13:55 ` [RFC PATCH v4 1/6] samples/damon/wsse: handle damon_start() failure SeongJae Park
2026-06-10 13:55 ` [RFC PATCH v4 2/6] samples/damon/prcl: " SeongJae Park
2026-06-10 13:55 ` [RFC PATCH v4 3/6] samples/damon/mtier: " SeongJae Park
2026-06-10 13:55 ` [RFC PATCH v4 4/6] samples/damon/mtier: handle damon_stop() failure SeongJae Park
2026-06-10 13:55 ` SeongJae Park [this message]
2026-06-10 13:55 ` [RFC PATCH v4 6/6] samples/damon/prcl: stop and free damon ctx when damon_call() fails SeongJae 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=20260610135546.64943-6-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 \
--cc=stable@vger.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.