Commit 5f5651c6 authored by Oliver Upton's avatar Oliver Upton Committed by Paolo Bonzini

KVM: selftests: Require DISABLE_NX_HUGE_PAGES cap for NX hugepage test

Require KVM_CAP_VM_DISABLE_NX_HUGE_PAGES for the entire NX hugepage test
instead of skipping the "disable" subtest if the capability isn't
supported by the host kernel.  While the "enable" subtest does provide
value when the capability isn't supported, silently providing only half
the promised coveraged is undesirable, i.e. it's better to skip the test
so that the user knows something.

Alternatively, the test could print something to alert the user instead
of silently skipping the subtest, but that would encourage other tests
to follow suit, and it's not clear that it's desirable to take selftests
in that direction.  And if selftests do head down the path of skipping
subtests, such behavior needs first-class support in the framework.

Opportunistically convert other test preconditions to TEST_REQUIRE().
Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
Reviewed-by: default avatarDavid Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20220812175301.3915004-1-oliver.upton@linux.dev
[sean: rewrote changelog to capture discussion about skipping the test]
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 57abfa11
...@@ -118,13 +118,6 @@ void run_test(int reclaim_period_ms, bool disable_nx_huge_pages, ...@@ -118,13 +118,6 @@ void run_test(int reclaim_period_ms, bool disable_nx_huge_pages,
vm = vm_create(1); vm = vm_create(1);
if (disable_nx_huge_pages) { if (disable_nx_huge_pages) {
/*
* Cannot run the test without NX huge pages if the kernel
* does not support it.
*/
if (!kvm_check_cap(KVM_CAP_VM_DISABLE_NX_HUGE_PAGES))
return;
r = __vm_disable_nx_huge_pages(vm); r = __vm_disable_nx_huge_pages(vm);
if (reboot_permissions) { if (reboot_permissions) {
TEST_ASSERT(!r, "Disabling NX huge pages should succeed if process has reboot permissions"); TEST_ASSERT(!r, "Disabling NX huge pages should succeed if process has reboot permissions");
...@@ -248,18 +241,13 @@ int main(int argc, char **argv) ...@@ -248,18 +241,13 @@ int main(int argc, char **argv)
} }
} }
if (token != MAGIC_TOKEN) { TEST_REQUIRE(kvm_has_cap(KVM_CAP_VM_DISABLE_NX_HUGE_PAGES));
print_skip("This test must be run with the magic token %d.\n" TEST_REQUIRE(reclaim_period_ms > 0);
"This is done by nx_huge_pages_test.sh, which\n"
"also handles environment setup for the test.",
MAGIC_TOKEN);
exit(KSFT_SKIP);
}
if (!reclaim_period_ms) { __TEST_REQUIRE(token == MAGIC_TOKEN,
print_skip("The NX reclaim period must be specified and non-zero"); "This test must be run with the magic token %d.\n"
exit(KSFT_SKIP); "This is done by nx_huge_pages_test.sh, which\n"
} "also handles environment setup for the test.");
run_test(reclaim_period_ms, false, reboot_permissions); run_test(reclaim_period_ms, false, reboot_permissions);
run_test(reclaim_period_ms, true, reboot_permissions); run_test(reclaim_period_ms, true, reboot_permissions);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment