KVM: selftests: Fix hang in hardware_disable_test
authorDavid Matlack <dmatlack@google.com>
Fri, 14 May 2021 23:05:21 +0000 (23:05 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 27 May 2021 11:45:55 +0000 (07:45 -0400)
commita10453c038a7e97169185405242d20d21de0bb91
treeb7b20b56f97bc95c9199992a07314da02e335b7e
parent50bc913d526beb9937f1eb0159ec63c43234f961
KVM: selftests: Fix hang in hardware_disable_test

If /dev/kvm is not available then hardware_disable_test will hang
indefinitely because the child process exits before posting to the
semaphore for which the parent is waiting.

Fix this by making the parent periodically check if the child has
exited. We have to be careful to forward the child's exit status to
preserve a KSFT_SKIP status.

I considered just checking for /dev/kvm before creating the child
process, but there are so many other reasons why the child could exit
early that it seemed better to handle that as general case.

Tested:

$ ./hardware_disable_test
/dev/kvm not available, skipping test
$ echo $?
4
$ modprobe kvm_intel
$ ./hardware_disable_test
$ echo $?
0

Signed-off-by: David Matlack <dmatlack@google.com>
Message-Id: <20210514230521.2608768-1-dmatlack@google.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/hardware_disable_test.c