mbox series

[v4,00/10] Fix Kselftest's vfork() side effects

Message ID 20240502210926.145539-1-mic@digikod.net
Headers show
Series Fix Kselftest's vfork() side effects | expand

Message

Mickaël Salaün May 2, 2024, 9:09 p.m. UTC
Hi,

As reported by Kernel Test Robot [1], some pidfd tests fail.  This is
due to the use of vfork() which introduced some side effects.
Similarly, while making it more generic, a previous commit made some
Landlock file system tests flaky, and subject to the host's file system
mount configuration.

This series fixes all these side effects by replacing vfork() with
clone3() and CLONE_VFORK, which is cleaner (no arbitrary shared memory)
and makes the Kselftest framework more robust.

I tried different approaches and I found this one to be the cleaner and
less invasive for current test cases.

This fourth series add a patch from Sean Christopherson that fixes KVM
tests.

I successfully ran the following tests (using TEST_F and
fork/clone/clone3) with this series:
- landlock:fs_test
- landlock:net_test
- landlock:ptrace_test
- move_mount_set_group:move_mount_set_group_test
- net/af_unix:scm_pidfd
- perf_events:remove_on_exec
- pidfd:pidfd_getfd_test
- pidfd:pidfd_setns_test
- seccomp:seccomp_bpf
- user_events:abi_test

[1] https://lore.kernel.org/oe-lkp/202403291015.1fcfa957-oliver.sang@intel.com

Previous versions:
v1: https://lore.kernel.org/r/20240426172252.1862930-1-mic@digikod.net
v2: https://lore.kernel.org/r/20240429130931.2394118-1-mic@digikod.net
v3: https://lore.kernel.org/r/20240429191911.2552580-1-mic@digikod.net

Regards,

Mickaël Salaün (10):
  selftests/pidfd: Fix config for pidfd_setns_test
  selftests/landlock: Fix FS tests when run on a private mount point
  selftests/harness: Fix fixture teardown
  selftests/harness: Fix interleaved scheduling leading to race
    conditions
  selftests/landlock: Do not allocate memory in fixture data
  selftests/harness: Constify fixture variants
  selftests/pidfd: Fix wrong expectation
  selftests/harness: Share _metadata between forked processes
  selftests/harness: Fix vfork() side effects
  selftests/harness: Fix TEST_F()'s exit codes

 tools/testing/selftests/kselftest_harness.h   | 123 +++++++++++++-----
 tools/testing/selftests/landlock/fs_test.c    |  83 +++++++-----
 tools/testing/selftests/pidfd/config          |   2 +
 .../selftests/pidfd/pidfd_setns_test.c        |   2 +-
 4 files changed, 141 insertions(+), 69 deletions(-)


base-commit: e67572cd2204894179d89bd7b984072f19313b03

Comments

Mickaël Salaün May 3, 2024, 7:51 a.m. UTC | #1
On Thu, May 02, 2024 at 03:45:22PM GMT, Sean Christopherson wrote:
> On Thu, May 02, 2024, Mickaël Salaün wrote:
> > @@ -462,8 +462,10 @@ static inline pid_t clone3_vfork(void)
> >  		munmap(teardown, sizeof(*teardown)); \
> >  		if (self && fixture_name##_teardown_parent) \
> >  			munmap(self, sizeof(*self)); \
> > -		if (!WIFEXITED(status) && WIFSIGNALED(status)) \
> > -			/* Forward signal to __wait_for_test(). */ \
> > +		/* Forward exit codes and signals to __wait_for_test(). */ \
> > +		if (WIFEXITED(status)) \
> > +			_exit(_metadata->exit_code); \
> 
> This needs to be:
> 
> 		if (WIFEXITED(status)) \
> 			_exit(WEXITSTATUS(status)); \
> 
> otherwise existing tests that communicate FAIL/SKIP via exit() continue to yield
> exit(0) and thus false passes.

Yes of course.

> 
> If that conflicts with tests that want to communicate via _metadata->exit_code,
> then maybe this?
> 
> 		if (WIFEXITED(status)) \
> 			_exit(WEXITSTATUS(status) ?: _metadata->exit_code); \

I prefer this approach handling failed expectations in the fixture
teardown too.

However, the direct call to _exit() doesn't handle failed asserts.  I'll
fix that.


> 
> Or I suppose _metadata->exit_code could have priority, but that seems weird to
> me, e.g. if a test sets exit_code and then explodes, it seems like the explosion
> should be reported.
> 
> > +		if (WIFSIGNALED(status)) \
> >  			kill(getpid(), WTERMSIG(status)); \
> >  		__test_check_assert(_metadata); \
> >  	} \
> > -- 
> > 2.45.0
> > 
>