selftests/damon: add regression test for damos_walk() vs kdamond exit race
Subsystems (3)
PATCH 1/1 selftests/damon: add regression test for damos_walk() vs kdamond exit race
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.
--- 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
tools/testing/selftests/damon/Makefile +1 -0
@@ -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__
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] The script hardcodes the sysfs state path and suppresses exceptions with a bare `except` block…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] The script hardcodes the sysfs state path and suppresses exceptions with a bare except block, yielding a false pass if path resolution fails.
- [Medium] The script's custom timeout logic is incapable of detecting the kernel deadlock because it blocks synchronously on the system call.
- [Low] The new test script sysfs_damos_walk_kdamond_exit_race.py lacks execute permissions.
--
commit c1a389c100306b9715b021c992e2707ecc7ffc39
Author: Sailesh Nandanavanam <[email protected]>
selftests/damon: add regression test for damos_walk() vs kdamond exit race
This commit adds a regression test to verify that damos_walk() does not deadlock when racing with the kdamond_fn() exit path. It starts kdamond monitoring a short-lived process, waits for termination, and then rapidly calls update_schemes_tried_regions to hit the race window.
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py
Quoted 5 lines
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py new file +0
-0
[Severity: Low]
Should this file be created with executable permissions (100755)? Since the script is added to TEST_PROGS in the Makefile, the kselftest framework expects it to be directly executable. Without the execute bit, it can cause warnings during test execution.
Quoted 3 lines
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py new file +2
-0@@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0
[ ... ]
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py line 28
Quoted 5 lines
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py new file +5
-0+ proc.wait() + completed = False + timeout = time.time() + 5 + while time.time() < timeout: + err = kdamonds.kdamonds[0].update_schemes_tried_regions()
[Severity: Medium]
If the kernel deadlock bug occurs, update_schemes_tried_regions() will trigger an uninterruptible wait in the kernel. Doesn't this mean the Python script will block indefinitely on the system call in the D state?
Since the script is single-threaded, the while loop condition would never be re-evaluated, making the internal timeout and failure message unreachable. Instead, the test would just hang until the global kselftest timeout kills it.
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py line 40
Quoted 12 lines
tools/testing/selftests/damon/sysfs_damos_walk_kdamond_exit_race.py new file +12
-0+ 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
[Severity: Medium]
Is it safe to hardcode the sysfs state path and use a bare except block here?
If sysfs is mounted at a non-standard location or another file error occurs, open() will raise an exception. The bare except block will catch this, incorrectly set completed to True, and exit the loop immediately. This results in a false pass on the very first iteration, completely missing the race window it is intended to test.
Could the script dynamically resolve the path using the kdamonds object instead of suppressing all exceptions?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1