[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 09/10] KVM: selftests: Add tests around sharing a restrictedm
From: |
Ackerley Tng |
Subject: |
[RFC PATCH 09/10] KVM: selftests: Add tests around sharing a restrictedmem fd |
Date: |
Thu, 16 Mar 2023 00:31:02 +0000 |
Tests that
+ Different memslots in the same VM should be able to share a
restrictedmem_fd
+ A second VM cannot share the same offsets in a restrictedmem_fd
+ Different VMs should be able to share the same restrictedmem_fd, as
long as the offsets in the restrictedmem_fd are different
Signed-off-by: Ackerley Tng <ackerleytng@google.com>
---
.../selftests/kvm/set_memory_region_test.c | 29 +++++++++++++++++--
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/kvm/set_memory_region_test.c
b/tools/testing/selftests/kvm/set_memory_region_test.c
index cc727d11569e..789c413e2a67 100644
--- a/tools/testing/selftests/kvm/set_memory_region_test.c
+++ b/tools/testing/selftests/kvm/set_memory_region_test.c
@@ -401,7 +401,7 @@ static bool set_private_region_failed(struct kvm_vm *vm,
void *hva,
static void test_private_regions(void)
{
int ret;
- struct kvm_vm *vm;
+ struct kvm_vm *vm, *vm2;
void *mem;
int fd;
@@ -416,7 +416,7 @@ static void test_private_regions(void)
vm = __vm_create(shape, 1, 0);
- mem = mmap(NULL, MEM_REGION_SIZE * 2, PROT_READ | PROT_WRITE,
+ mem = mmap(NULL, MEM_REGION_SIZE * 3, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
TEST_ASSERT(mem != MAP_FAILED, "Failed to mmap() host");
@@ -448,8 +448,31 @@ static void test_private_regions(void)
TEST_ASSERT(ret == -1 && errno == EINVAL,
"Set overlapping restrictedmem_offset should fail");
- munmap(mem, MEM_REGION_SIZE * 2);
+ ret = __vm_set_user_memory_region2(vm, MEM_REGION_SLOT + 1,
+ KVM_MEM_PRIVATE,
+ MEM_REGION_GPA + MEM_REGION_SIZE,
+ MEM_REGION_SIZE,
+ mem + MEM_REGION_SIZE,
+ fd, MEM_REGION_SIZE);
+ TEST_ASSERT(!ret,
+ "Different memslots should be able to share a
restrictedmem_fd");
+
+ vm2 = __vm_create(shape, 1, 0);
+ TEST_ASSERT(set_private_region_failed(vm2, mem + 2 * MEM_REGION_SIZE,
fd, 0),
+ "Pages (offsets) of a restrictedmem_fd should be exclusive
to a VM");
+
+ ret = __vm_set_user_memory_region2(vm2, MEM_REGION_SLOT,
+ KVM_MEM_PRIVATE,
+ MEM_REGION_GPA + 2 * MEM_REGION_SIZE,
+ MEM_REGION_SIZE,
+ mem + 2 * MEM_REGION_SIZE,
+ fd, 2 * MEM_REGION_SIZE);
+ TEST_ASSERT(!ret,
+ "Different VMs should be able to share a restrictedmem_fd");
+
+ munmap(mem, MEM_REGION_SIZE * 3);
kvm_vm_free(vm);
+ kvm_vm_free(vm2);
}
int main(int argc, char *argv[])
--
2.40.0.rc2.332.ga46443480c-goog
- [RFC PATCH 00/10] Additional selftests for restrictedmem, Ackerley Tng, 2023/03/15
- [RFC PATCH 01/10] KVM: selftests: Test error message fixes for memfd_restricted selftests, Ackerley Tng, 2023/03/15
- [RFC PATCH 02/10] KVM: selftests: Test that ftruncate to non-page-aligned size on a restrictedmem fd should fail, Ackerley Tng, 2023/03/15
- [RFC PATCH 03/10] KVM: selftests: Test that VM private memory should not be readable from host, Ackerley Tng, 2023/03/15
- [RFC PATCH 04/10] KVM: selftests: Exercise restrictedmem allocation and truncation code after KVM invalidation code has been unbound, Ackerley Tng, 2023/03/15
- [RFC PATCH 05/10] KVM: selftests: Generalize private_mem_conversions_test for parallel execution, Ackerley Tng, 2023/03/15
- [RFC PATCH 06/10] KVM: selftests: Default private_mem_conversions_test to use 1 memslot for test data, Ackerley Tng, 2023/03/15
- [RFC PATCH 07/10] KVM: selftests: Add vm_userspace_mem_region_add_with_restrictedmem, Ackerley Tng, 2023/03/15
- [RFC PATCH 08/10] KVM: selftests: Default private_mem_conversions_test to use 1 restrictedmem file for test data, Ackerley Tng, 2023/03/15
- [RFC PATCH 09/10] KVM: selftests: Add tests around sharing a restrictedmem fd,
Ackerley Tng <=
- [RFC PATCH 10/10] KVM: selftests: Test KVM exit behavior for private memory/access, Ackerley Tng, 2023/03/15