From: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
To: sj@kernel.org
Cc: shuah@kernel.org, damon@lists.linux.dev, linux-mm@kvack.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
Subject: [PATCH] selftests/damon: add regression test for damos_walk() vs kdamond exit race
Date: Sun, 24 May 2026 14:48:12 +0530 [thread overview]
Message-ID: <20260524091812.35283-1-saileshnandanavanam@gmail.com> (raw)
Add a regression test that verifies damos_walk() does not deadlock
when racing with kdamond_fn() exit.
When kdamond_fn() finishes its main loop, it cancels remaining
damos_walk() requests and unsets damon_ctx->kdamond. Without the fix
in commit 33c3f6c2b48c, damos_walk() could be called right after
cancellation but before kdamond pointer unset, causing it to wait
forever for handling that never comes.
The test starts kdamond monitoring a short-lived process, waits for
the process to exit naturally triggering kdamond termination, then
rapidly calls update_schemes_tried_regions to hit the race window.
Without the fix this would hang indefinitely.
Fixes: 33c3f6c2b48c ("mm/damon/core: fix damos_walk() vs kdamond_fn() exit race")
Signed-off-by: Sailesh Nandanavanam <saileshnandanavanam@gmail.com>
---
tools/testing/selftests/damon/Makefile | 1 +
.../sysfs_damos_walk_kdamond_exit_race.py | 47 +++++++++++++++++++
2 files changed, 48 insertions(+)
create mode 100644 tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py
diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftests/damon/Makefile
index 2180c328a825..60c83d6c318e 100644
--- a/tools/testing/selftests/damon/Makefile
+++ b/tools/testing/selftests/damon/Makefile
@@ -20,6 +20,7 @@ TEST_PROGS += sysfs_update_removed_scheme_dir.sh
TEST_PROGS += sysfs_update_schemes_tried_regions_hang.py
TEST_PROGS += sysfs_memcg_path_leak.sh
TEST_PROGS += sysfs_no_op_commit_break.py
+TEST_PROGS += sysfs_damos_walk_kdamond_exit_race.py
EXTRA_CLEAN = __pycache__
diff --git a/tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py b/tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py
new file mode 100644
index 000000000000..9b9d66a23f51
--- /dev/null
+++ b/tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0
+#
+# Regression test for damos_walk() vs kdamond_fn() exit race.
+import subprocess
+import time
+import _damon_sysfs
+def main():
+ proc = subprocess.Popen(['sleep', '0.3'])
+ kdamonds = _damon_sysfs.Kdamonds([_damon_sysfs.Kdamond(
+ contexts=[_damon_sysfs.DamonCtx(
+ ops='vaddr',
+ targets=[_damon_sysfs.DamonTarget(pid=proc.pid)],
+ schemes=[_damon_sysfs.Damos(
+ action='stat',
+ access_pattern=_damon_sysfs.DamosAccessPattern(
+ nr_accesses=[0, 200]))]
+ )]
+ )])
+ err = kdamonds.start()
+ if err is not None:
+ print('kdamond start failed: %s' % err)
+ exit(1)
+ proc.wait()
+ completed = False
+ timeout = time.time() + 5
+ while time.time() < timeout:
+ err = kdamonds.kdamonds[0].update_schemes_tried_regions()
+ if err is not None:
+ completed = True
+ break
+ try:
+ with open('/sys/kernel/mm/damon/admin/kdamonds/0/state') as f:
+ state = f.read().strip()
+ if state == 'off':
+ completed = True
+ break
+ except:
+ completed = True
+ break
+ if not completed:
+ print('FAIL: test timed out - possible damos_walk/kdamond exit race deadlock')
+ kdamonds.stop()
+ exit(1)
+ print('PASS: damos_walk() vs kdamond exit race not triggered')
+if __name__ == '__main__':
+ main()
--
2.34.1
reply other threads:[~2026-05-24 9:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260524091812.35283-1-saileshnandanavanam@gmail.com \
--to=saileshnandanavanam@gmail.com \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
--cc=sj@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®