From: sashiko-bot@kernel.org
To: "Tarun Sahu" <tarunsahu@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [RFC PATCH v2 10/10] selftests: kvm: Add guest_memfd_preservation_test
Date: Fri, 05 Jun 2026 17:22:49 +0000 [thread overview]
Message-ID: <20260605172249.B9A691F00893@smtp.kernel.org> (raw)
In-Reply-To: <deb20fbe3584a8c6bfda276447fe464c6553737d.1780676742.git.tarunsahu@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Phase 2 blindly recreates a vCPU on the preserved VM, failing with -EEXIST.
- [Medium] Phase 2 attempts to recreate preserved memslots without explicit deletion, causing KVM_SET_USER_MEMORY_REGION ioctls to fail with -EINVAL.
--
commit fe4115b3a7bf4dcb06bece577462cff5bac12723
Author: Tarun Sahu <tarunsahu@google.com>
selftests: kvm: Add guest_memfd_preservation_test
Add a new KVM selftest guest_memfd_preservation_test to verify that
guest memory backed by guest_memfd is preserved properly. The test leverages
the Live Update Orchestrator (LUO) infrastructure to save and restore memory
folios and configuration layouts during live updates.
> diff --git a/tools/testing/selftests/kvm/guest_memfd_preservation_test.c b/tools/testing/selftests/kvm/guest_memfd_preservation_test.c
> new file mode 100644
> index 0000000000000..74f90c5c4bf5b
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/guest_memfd_preservation_test.c
[ ... ]
> +static void do_phase1(void)
> +{
[ ... ]
> + session_fd = luo_create_session(dev_luo_fd, SESSION_NAME);
> + TEST_ASSERT(session_fd >= 0, "Failed to create LUO session");
> +
> + ret = luo_session_preserve_fd(session_fd, vm->fd, VM_TOKEN);
> + TEST_ASSERT(ret == 0, "Failed to preserve VM file descriptor");
[Severity: Medium]
Since this test creates a VM with vCPU 0 and preserves the VM file descriptor,
but doesn't preserve the vCPU file descriptor, will vCPU 0 still be retained
in KVM's state for phase 2 without a way to access it?
> +
> + ret = luo_session_preserve_fd(session_fd, gmem_fd, GMEM_TOKEN);
> + TEST_ASSERT(ret == 0, "Failed to preserve guest_memfd file descriptor");
[ ... ]
> +static void do_phase2(void)
> +{
[ ... ]
> + vm = vm_create_from_fd(retrieved_vm_fd, shape);
> +
> + u64 nr_pages = 2048; /* 8MB is plenty for slot0 pages */
> +
> + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, 0, 0, nr_pages, 0);
[Severity: Medium]
Does this code attempt to overwrite existing memslot 0 with a new userspace
address without deleting it first?
Since the VM's internal memslots are retained in KVM kernel state when
preserved, redefining slot 0 with a new userspace_addr violates KVM's memslot
mutability rules and will likely cause KVM_SET_USER_MEMORY_REGION to fail with
-EINVAL.
> + kvm_vm_elf_load(vm, program_invocation_name);
> +
> + for (int i = 0; i < NR_MEM_REGIONS; i++)
> + vm->memslots[i] = 0;
> +
> + struct userspace_mem_region *slot0 = memslot2region(vm, 0);
> +
> + ucall_init(vm, slot0->region.guest_phys_addr + slot0->region.memory_size);
> +
> + vm_set_user_memory_region2(vm, slot, KVM_MEM_GUEST_MEMFD, gpa, GMEM_SIZE, NULL,
> + retrieved_gmem_fd, 0);
[Severity: Medium]
Will this also trigger an -EINVAL error from KVM?
Similar to slot 0, redefining the guest_memfd memslot (slot 1) without explicit
deletion first also violates KVM's memslot mutability rules.
> +
> + for (size_t i = 0; i < GMEM_SIZE; i += page_size)
> + virt_pg_map(vm, gpa + i, gpa + i);
> +
> + vcpu = vm_vcpu_add(vm, 0, guest_code_phase2);
[Severity: Medium]
Will this blindly recreate a vCPU on the preserved VM, resulting in an
immediate -EEXIST failure?
Because the entire VM state was preserved in phase 1, vCPU 0 already exists in
KVM's state. Calling vm_vcpu_add() for vCPU 0 again causes KVM to reject the
duplicate KVM_CREATE_VCPU request.
> + kvm_arch_vm_finalize_vcpus(vm);
> +
> + vcpu_args_set(vcpu, 3, gpa, GMEM_SIZE, DATA_SIZE);
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1780676742.git.tarunsahu@google.com?part=10
next prev parent reply other threads:[~2026-06-05 17:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1780676742.git.tarunsahu@google.com>
2026-06-05 17:08 ` [RFC PATCH v2 01/10] liveupdate: luo_file: Add internal APIs for file preservation Tarun Sahu
2026-06-05 17:24 ` sashiko-bot
2026-06-07 0:41 ` tarunsahu
2026-06-07 0:35 ` tarunsahu
2026-06-05 17:08 ` [RFC PATCH v2 02/10] liveupdate: Add LIVEUPDATE_GUEST_MEMFD config option Tarun Sahu
2026-06-05 17:08 ` [RFC PATCH v2 03/10] kvm: Prepare core VM structs and helpers for LUO support Tarun Sahu
2026-06-05 17:21 ` sashiko-bot
2026-06-22 23:59 ` Ackerley Tng
2026-06-05 17:08 ` [RFC PATCH v2 04/10] kvm: kvm_luo: Allow kvm preservation with LUO Tarun Sahu
2026-06-05 17:26 ` sashiko-bot
2026-06-08 16:13 ` tarunsahu
2026-06-05 17:08 ` [RFC PATCH v2 05/10] kvm: guest_memfd: Move internal definitions and helper to new header Tarun Sahu
2026-06-05 17:08 ` [RFC PATCH v2 06/10] kvm: guest_memfd: Add support for freezing and unfreezing mappings Tarun Sahu
2026-06-05 17:21 ` sashiko-bot
2026-06-08 18:20 ` tarunsahu
2026-06-22 23:54 ` Ackerley Tng
2026-06-23 0:09 ` Sean Christopherson
2026-06-05 17:08 ` [RFC PATCH v2 07/10] kvm: guest_memfd_luo: add support for guest_memfd preservation Tarun Sahu
2026-06-05 17:25 ` sashiko-bot
2026-06-08 18:22 ` tarunsahu
2026-06-22 23:27 ` Ackerley Tng
2026-06-05 17:08 ` [RFC PATCH v2 08/10] docs: add documentation for guest_memfd preservation via LUO Tarun Sahu
2026-06-05 17:08 ` [RFC PATCH v2 09/10] selftests: kvm: Split ____vm_create() to expose init helpers Tarun Sahu
2026-06-05 17:08 ` [RFC PATCH v2 10/10] selftests: kvm: Add guest_memfd_preservation_test Tarun Sahu
2026-06-05 17:22 ` sashiko-bot [this message]
2026-06-08 18:26 ` tarunsahu
2026-06-22 23:01 ` Ackerley Tng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260605172249.B9A691F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tarunsahu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox