Skip to content

Commit 63e5c5a

Browse files
committed
KVM: selftests: Create GUEST_MEMFD for relevant invalid flags testcases
Actually create a GUEST_MEMFD instance and pass it to KVM when doing negative tests for KVM_SET_USER_MEMORY_REGION2 + KVM_MEM_GUEST_MEMFD. Without a valid GUEST_MEMFD file descriptor, KVM_SET_USER_MEMORY_REGION2 will always fail with -EINVAL, resulting in false passes for any and all tests of illegal combinations of KVM_MEM_GUEST_MEMFD and other flags. Fixes: 5d74316 ("KVM: selftests: Add a memory region subtest to validate invalid flags") Link: https://lore.kernel.org/r/20240222190612.2942589-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a1176ef commit 63e5c5a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ static void test_invalid_memory_region_flags(void)
367367
}
368368

369369
if (supported_flags & KVM_MEM_GUEST_MEMFD) {
370+
int guest_memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);
371+
370372
r = __vm_set_user_memory_region2(vm, 0,
371373
KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_GUEST_MEMFD,
372-
0, MEM_REGION_SIZE, NULL, 0, 0);
374+
0, MEM_REGION_SIZE, NULL, guest_memfd, 0);
373375
TEST_ASSERT(r && errno == EINVAL,
374376
"KVM_SET_USER_MEMORY_REGION2 should have failed, dirty logging private memory is unsupported");
377+
378+
close(guest_memfd);
375379
}
376380
}
377381

0 commit comments

Comments
 (0)