Skip to content

Commit

Permalink
selftests/kvm: fix compilation on non-x86_64 platforms
Browse files Browse the repository at this point in the history
MEM_REGION_SLOT and MEM_REGION_GPA are not really needed in
test_invalid_memory_region_flags; the VM never runs and there are no
other slots, so it is okay to use slot 0 and place it at address
zero.  This fixes compilation on architectures that do not
define them.

Fixes: 5d74316 ("KVM: selftests: Add a memory region subtest to validate invalid flags")
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini committed Nov 21, 2023
1 parent 6c370dc commit e9e60c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions tools/testing/selftests/kvm/guest_memfd_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ static void test_create_guest_memfd_invalid(struct kvm_vm *vm)
}

for (flag = 0; flag; flag <<= 1) {
uint64_t bit;

fd = __vm_create_guest_memfd(vm, page_size, flag);
TEST_ASSERT(fd == -1 && errno == EINVAL,
"guest_memfd() with flag '0x%lx' should fail with EINVAL",
Expand Down
12 changes: 6 additions & 6 deletions tools/testing/selftests/kvm/set_memory_region_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,25 @@ static void test_invalid_memory_region_flags(void)
if ((supported_flags & BIT(i)) && !(v2_only_flags & BIT(i)))
continue;

r = __vm_set_user_memory_region(vm, MEM_REGION_SLOT, BIT(i),
MEM_REGION_GPA, MEM_REGION_SIZE, NULL);
r = __vm_set_user_memory_region(vm, 0, BIT(i),
0, MEM_REGION_SIZE, NULL);

TEST_ASSERT(r && errno == EINVAL,
"KVM_SET_USER_MEMORY_REGION should have failed on v2 only flag 0x%lx", BIT(i));

if (supported_flags & BIT(i))
continue;

r = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT, BIT(i),
MEM_REGION_GPA, MEM_REGION_SIZE, NULL, 0, 0);
r = __vm_set_user_memory_region2(vm, 0, BIT(i),
0, MEM_REGION_SIZE, NULL, 0, 0);
TEST_ASSERT(r && errno == EINVAL,
"KVM_SET_USER_MEMORY_REGION2 should have failed on unsupported flag 0x%lx", BIT(i));
}

if (supported_flags & KVM_MEM_GUEST_MEMFD) {
r = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT,
r = __vm_set_user_memory_region2(vm, 0,
KVM_MEM_LOG_DIRTY_PAGES | KVM_MEM_GUEST_MEMFD,
MEM_REGION_GPA, MEM_REGION_SIZE, NULL, 0, 0);
0, MEM_REGION_SIZE, NULL, 0, 0);
TEST_ASSERT(r && errno == EINVAL,
"KVM_SET_USER_MEMORY_REGION2 should have failed, dirty logging private memory is unsupported");
}
Expand Down

0 comments on commit e9e60c8

Please sign in to comment.