Skip to content

Commit

Permalink
KVM: selftests: Add a testcase to verify GUEST_MEMFD and READONLY are…
Browse files Browse the repository at this point in the history
… exclusive

Extend set_memory_region_test's invalid flags subtest to verify that
GUEST_MEMFD is incompatible with READONLY.  GUEST_MEMFD doesn't currently
support writes from userspace and KVM doesn't support emulated MMIO on
private accesses, and so KVM is supposed to reject the GUEST_MEMFD+READONLY
in order to avoid configuration that KVM can't support.

Link: https://lore.kernel.org/r/20240222190612.2942589-6-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Feb 23, 2024
1 parent 63e5c5a commit 2dfd238
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/testing/selftests/kvm/set_memory_region_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ static void test_invalid_memory_region_flags(void)
TEST_ASSERT(r && errno == EINVAL,
"KVM_SET_USER_MEMORY_REGION2 should have failed, dirty logging private memory is unsupported");

r = __vm_set_user_memory_region2(vm, 0,
KVM_MEM_READONLY | KVM_MEM_GUEST_MEMFD,
0, MEM_REGION_SIZE, NULL, guest_memfd, 0);
TEST_ASSERT(r && errno == EINVAL,
"KVM_SET_USER_MEMORY_REGION2 should have failed, read-only GUEST_MEMFD memslots are unsupported");

close(guest_memfd);
}
}
Expand Down

0 comments on commit 2dfd238

Please sign in to comment.