Hello SeongJae,
Noted on inline replies - I'll follow that format from the next response.
Following up on this thread with progress.
As discussed, I dropped the userspace selftest approach since it
cannot reliably trigger the microsecond-wide race window.
I wrote a KUnit test instead, added to mm/damon/tests/core-kunit.h:
- Creates a damon_ctx
- Sets ctx->walk_control_obsolete = true under walk_control_lock,
simulating the state just before kdamond_fn() exits
- Calls damos_walk() and verifies it returns -ECANCELED immediately
I built and ran this on a kernel with commit 33c3f6c2b48c
("mm/damon/core: fix damos_walk() vs kdamond_fn() exit race") present,
and the test passes along with all other 28 existing damon KUnit
tests:
ok 29 damon_test_walk_control_obsolete
# damon: pass:29 fail:0 skip:0 total:29
Since walk_control_obsolete is a field introduced by this fix, a
kernel with the fix reverted would not compile this test (the field
would not exist). So the usual "fails before fix, passes after fix"
verification does not apply the same way here - the test directly
validates the new field/behavior introduced by the fix.
If this approach looks reasonable, I plan to send v3 with this KUnit
test (replacing the userspace selftest from v1/v2), along with the
commit message format and other minor fixes from your earlier review.
Please let me know if you'd like any changes before I send v3.
Thanks,
Sailesh Nandanavanam
On Fri, 12 Jun, 2026, 01:50 Sailesh Nandanavanam,
<[email protected]> wrote:
>
> Hello SeongJae,
>
> Noted on inline replies - I'll follow that format from the next response.
>
> Following up on this thread with progress.
>
> As discussed, I dropped the userspace selftest approach since it cannot
> reliably trigger the microsecond-wide race window.
>
> I wrote a KUnit test instead, added to mm/damon/tests/core-kunit.h:
>
> - Creates a damon_ctx
> - Sets ctx->walk_control_obsolete = true under walk_control_lock, simulating
> the state just before kdamond_fn() exits
> - Calls damos_walk() and verifies it returns -ECANCELED immediately
>
> I built and ran this on a kernel with commit 33c3f6c2b48c ("mm/damon/core:
> fix damos_walk() vs kdamond_fn() exit race") present, and the test passes
> along with all other 28 existing damon KUnit tests:
>
> ok 29 damon_test_walk_control_obsolete
> # damon: pass:29 fail:0 skip:0 total:29
>
> Since walk_control_obsolete is a field introduced by this fix, a kernel with
> the fix reverted would not compile this test (the field would not exist). So
> the usual "fails before fix, passes after fix" verification does not apply
> the same way here - the test directly validates the new field/behavior
> introduced by the fix.
>
> If this approach looks reasonable, I plan to send v3 with this KUnit test
> (replacing the userspace selftest from v1/v2), along with the commit message
> format and other minor fixes from your earlier review.
>
> Please let me know if you'd like any changes before I send v3.
>
> Thanks,
> Sailesh
>
> On Sat, Jun 6, 2026 at 6:06 AM SeongJae Park <[email protected]> wrote:
>>
>> On Fri, 5 Jun 2026 12:44:50 +0530 Sailesh Nandanavanam
>> <[email protected]> wrote:
>>
>> > Hi SeongJae,
>> >
>> > Apologies for the delayed response.
>>
>> No worry!
>>
>> [...]
>> > I agree that a KUnit test is the right approach since it runs inside the
>> > kernel and can directly set walk_control_obsolete to simulate the race
>> > condition reliably without timing dependencies.
>> >
>> > I will drop the userspace selftest approach and write a KUnit test for
>> > damos_walk() functionality including walk_control_obsolete. I will verify
>> > it fails on a kernel with commit 33c3f6c2b48c ("mm/damon/core: fix
>> > damos_walk() vs kdamond_fn() exit race") reverted and passes with the fix
>> > present before sending v3.
>> >
>> > Regarding other feedback:
>> > - Will use correct commit description format with subject in brackets
>> > - Will remove the Fixes: tag
>> > - Will add blank line before _damon_sysfs import
>> > - Will add changelog and link previous versions
>> > - Will share revision plan and wait at least one day
>> > before sending new version
>>
>> Sounds good. Please consider using in-line reply [1] from the next time,
>> though!
>>
>> >
>> > Please give me some time to study mm/damon/tests/core-kunit.h and implement
>> > this properly.
>>
>> No rush, take your time.
>>
>> [1] https://subspace.kernel.org/etiquette.html#do-not-top-post-when-replying
>>
>>
>> Thanks,
>> SJ
>>
>> [...]