Re: [PATCH] kunit: Fix race condition in try-catch completion

From: Miguel Ojeda
Date: Sat Apr 13 2024 - 17:05:29 EST


On Thu, Apr 11, 2024 at 10:59 PM David Gow <davidgow@xxxxxxxxxx> wrote:
>
> KUnit's try-catch infrastructure now uses vfork_done, which is always
> set to a valid completion when a kthread is created, but which is set to
> NULL once the thread terminates. This creates a race condition, where
> the kthread exits before we can wait on it.
>
> Keep a copy of vfork_done, which is taken before we wake_up_process()
> and so valid, and wait on that instead.
>
> Fixes: 4de2a8e4cca4 ("kunit: Handle test faults")
> Reported-by: Linux Kernel Functional Testing <lkft@xxxxxxxxxx>
> Closes: https://lore.kernel.org/lkml/20240410102710.35911-1-naresh.kamboju@xxxxxxxxxx/
> Tested-by: Linux Kernel Functional Testing <lkft@xxxxxxxxxx>
> Acked-by: Mickaël Salaün <mic@xxxxxxxxxxx>
> Signed-off-by: David Gow <davidgow@xxxxxxxxxx>

I noticed it with the Rust tests too, and indeed this fixed it:

Tested-by: Miguel Ojeda <ojeda@xxxxxxxxxx>

Thanks!

Cheers,
Miguel