[PATCH 32/34] KVM: selftests: Add basic selftest for guest_memfd()
Ackerley Tng
ackerleytng at google.com
Thu Nov 16 13:00:22 PST 2023
Paolo Bonzini <pbonzini at redhat.com> writes:
> <snip>
>
> +static void test_create_guest_memfd_invalid(struct kvm_vm *vm)
> +{
> + size_t page_size = getpagesize();
> + uint64_t flag;
> + size_t size;
> + int fd;
> +
> + for (size = 1; size < page_size; size++) {
> + fd = __vm_create_guest_memfd(vm, size, 0);
> + TEST_ASSERT(fd == -1 && errno == EINVAL,
> + "guest_memfd() with non-page-aligned page size '0x%lx' should fail with EINVAL",
> + size);
> + }
> +
> + for (flag = 1; flag; flag <<= 1) {
Since transparent hugepage support is no longer officially part of this
series,
> + uint64_t bit;
this declaration of bit can be removed.
> +
> + 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",
> + flag);
> +
This loop can also be removed,
> + for_each_set_bit(bit, &valid_flags, 64) {
> + fd = __vm_create_guest_memfd(vm, page_size, flag | BIT_ULL(bit));
> + TEST_ASSERT(fd == -1 && errno == EINVAL,
> + "guest_memfd() with flags '0x%llx' should fail with EINVAL",
> + flag | BIT_ULL(bit));
> + }
otherwise this won't compile because valid_flags is not declared.
These lines will have to be added back when adding transparent hugepage
support.
> + }
> +}
Tested-by: Ackerley Tng <ackerleytng at google.com>
More information about the kvm-riscv
mailing list