[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <diqzr0oe30iq.fsf@ackerleytng-ctop.c.googlers.com>
Date: Mon, 07 Aug 2023 23:17:49 +0000
From: Ackerley Tng <ackerleytng@...gle.com>
To: Sean Christopherson <seanjc@...gle.com>
Cc: pbonzini@...hat.com, maz@...nel.org, oliver.upton@...ux.dev,
chenhuacai@...nel.org, mpe@...erman.id.au, anup@...infault.org,
paul.walmsley@...ive.com, palmer@...belt.com,
aou@...s.berkeley.edu, seanjc@...gle.com, willy@...radead.org,
akpm@...ux-foundation.org, paul@...l-moore.com, jmorris@...ei.org,
serge@...lyn.com, kvm@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.linux.dev,
linux-mips@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
kvm-riscv@...ts.infradead.org, linux-riscv@...ts.infradead.org,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org,
linux-security-module@...r.kernel.org,
linux-kernel@...r.kernel.org, chao.p.peng@...ux.intel.com,
tabba@...gle.com, jarkko@...nel.org, yu.c.zhang@...ux.intel.com,
vannapurve@...gle.com, mail@...iej.szmigiero.name, vbabka@...e.cz,
david@...hat.com, qperret@...gle.com, michael.roth@....com,
wei.w.wang@...el.com, liam.merwick@...cle.com,
isaku.yamahata@...il.com, kirill.shutemov@...ux.intel.com
Subject: Re: [RFC PATCH v11 27/29] KVM: selftests: Expand set_memory_region_test
to validate guest_memfd()
Sean Christopherson <seanjc@...gle.com> writes:
> From: Chao Peng <chao.p.peng@...ux.intel.com>
>
> Expand set_memory_region_test to exercise various positive and negative
> testcases for private memory.
>
> - Non-guest_memfd() file descriptor for private memory
> - guest_memfd() from different VM
> - Overlapping bindings
> - Unaligned bindings
>
> Signed-off-by: Chao Peng <chao.p.peng@...ux.intel.com>
> Co-developed-by: Ackerley Tng <ackerleytng@...gle.com>
> Signed-off-by: Ackerley Tng <ackerleytng@...gle.com>
> [sean: trim the testcases to remove duplicate coverage]
> Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> ---
> .../selftests/kvm/include/kvm_util_base.h | 10 ++
> .../selftests/kvm/set_memory_region_test.c | 99 +++++++++++++++++++
> 2 files changed, 109 insertions(+)
>
> diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
> index 334df27a6f43..39b38c75b99c 100644
> --- a/tools/testing/selftests/kvm/include/kvm_util_base.h
> +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
> @@ -789,6 +789,16 @@ static inline struct kvm_vm *vm_create_barebones(void)
> return ____vm_create(VM_SHAPE_DEFAULT);
> }
>
> <snip>
> +
> +static void test_add_private_memory_region(void)
> +{
> + struct kvm_vm *vm, *vm2;
> + int memfd, i;
> +
> + pr_info("Testing ADD of KVM_MEM_PRIVATE memory regions\n");
> +
> + vm = vm_create_barebones_protected_vm();
> +
> + test_invalid_guest_memfd(vm, vm->kvm_fd, 0, "KVM fd should fail");
> + test_invalid_guest_memfd(vm, vm->fd, 0, "VM's fd should fail");
> +
> + memfd = kvm_memfd_alloc(MEM_REGION_SIZE, false);
> + test_invalid_guest_memfd(vm, vm->fd, 0, "Regular memfd() should fail");
This should be
test_invalid_guest_memfd(vm, memfd, 0, "Regular memfd() should fail");
> + close(memfd);
> +
> + vm2 = vm_create_barebones_protected_vm();
> + memfd = vm_create_guest_memfd(vm2, MEM_REGION_SIZE, 0);
> + test_invalid_guest_memfd(vm, memfd, 0, "Other VM's guest_memfd() should fail");
> +
> + vm_set_user_memory_region2(vm2, MEM_REGION_SLOT, KVM_MEM_PRIVATE,
> + MEM_REGION_GPA, MEM_REGION_SIZE, 0, memfd, 0);
> + close(memfd);
> + kvm_vm_free(vm2);
> +
> + memfd = vm_create_guest_memfd(vm, MEM_REGION_SIZE, 0);
> + for (i = 1; i < PAGE_SIZE; i++)
> + test_invalid_guest_memfd(vm, memfd, i, "Unaligned offset should fail");
> +
> + vm_set_user_memory_region2(vm, MEM_REGION_SLOT, KVM_MEM_PRIVATE,
> + MEM_REGION_GPA, MEM_REGION_SIZE, 0, memfd, 0);
> + close(memfd);
> +
> + kvm_vm_free(vm);
> +}
> +
> <snip>
Powered by blists - more mailing lists