From: sashiko-bot@kernel.org
To: "David Woodhouse" <dwmw2@infradead.org>
Cc: media-ci@linuxtv.org, dri-devel@lists.freedesktop.org,
kvm@vger.kernel.org
Subject: Re: [RFC PATCH 09/11] selftests/kvm: gmem_provider KVM-only tests
Date: Thu, 16 Jul 2026 15:46:27 +0000 [thread overview]
Message-ID: <20260716154627.CC1151F000E9@smtp.kernel.org> (raw)
In-Reply-To: <7022c98bc66214bf02334d648ec0fd4d296c6c14.1784194290.git.dwmw@amazon.co.uk>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The test does not check for partial completion of KVM_SEV_SNP_LAUNCH_UPDATE, leading to potentially silent incomplete memory initialization.
- [Medium] The test fails to assert KVM_EXIT_MEMORY_FAULT on the revoke path because the validation is placed in an unreachable 'else' branch.
--
--- Patch [9]: [RFC PATCH 09/11] selftests/kvm: gmem_provider KVM-only tests ---
commit 93ae3986a0340a4d14084b20d7839ed583b0c01b
Author: David Woodhouse <dwmw@amazon.co.uk>
selftests/kvm: gmem_provider KVM-only tests
Three selftests that exercise the guest_memfd provider ABI purely from
the KVM side (no iommufd, no assigned devices). These tests verify the
live-update survivability, hugepage mappings, and memory revocation.
> diff --git a/tools/testing/selftests/kvm/x86/gmem_provider_revoke_test.c b/tools/testing/selftests/kvm/x86/gmem_provider_revoke_test.c
> index 0000000000000..7e711ea526748 100644
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/gmem_provider_revoke_test.c
[ ... ]
> + /* 2) Revoke: mark absent and zap the guest NPT (provider->KVM). */
> + req = (struct gmem_provider_present){ .offset = 0, .len = 4096, .present = 0 };
> + r = ioctl(gmem_fd, GMEM_PROVIDER_SET_PRESENT, &req);
> + TEST_ASSERT(!r, "revoke ioctl failed, errno %d", errno);
> +
> + /* 3) Guest re-reads -> re-fault into absent get_pfn -> must NOT see MAGIC. */
> + r = _vcpu_run(vcpu);
> + if (r) {
> + pr_info("revoked: vcpu_run failed (errno %d) -- guest faulted, as expected\n",
> + errno);
> + } else {
> + TEST_ASSERT(vcpu->run->exit_reason == KVM_EXIT_MEMORY_FAULT,
> + "revoked: expected fault or KVM_EXIT_MEMORY_FAULT, got %u (%s)",
> + vcpu->run->exit_reason,
> + exit_reason_str(vcpu->run->exit_reason));
> + pr_info("revoked: KVM_EXIT_MEMORY_FAULT as expected\n");
> + }
[Severity: Medium]
Since KVM_EXIT_MEMORY_FAULT always causes the KVM_RUN ioctl to return -1
with errno EFAULT, won't _vcpu_run(vcpu) return a non-zero value here?
If so, this execution path would take the if (r) branch, completely bypassing
the exit reason validation in the else block. Should this check be moved or
adjusted to properly assert that the exit reason is indeed
KVM_EXIT_MEMORY_FAULT?
> +
> + /* 4) Restore: mark present again. */
> + req.present = 1;
> + r = ioctl(gmem_fd, GMEM_PROVIDER_SET_PRESENT, &req);
> + TEST_ASSERT(!r, "restore ioctl failed, errno %d", errno);
> +
[ ... ]
> diff --git a/tools/testing/selftests/kvm/x86/gmem_provider_test.c b/tools/testing/selftests/kvm/x86/gmem_provider_test.c
> index 0000000000000..d7caa11616dfe 100644
> --- /dev/null
> +++ b/tools/testing/selftests/kvm/x86/gmem_provider_test.c
[ ... ]
> + struct kvm_sev_snp_launch_start start = { .policy = 0x30000 };
> + ret = sev_ioctl(vm_fd, sev_fd, KVM_SEV_SNP_LAUNCH_START, &start);
> + if (ret) { perror("SNP_LAUNCH_START"); goto out; }
> +
> + printf("[VM%d] SNP_LAUNCH_UPDATE (code + zero, %luMB)\n",
> + vm_num, GUEST_MEM_SIZE >> 20);
> + struct kvm_sev_snp_launch_update update = {
> + .gfn_start = 0,
> + .uaddr = (uint64_t)(unsigned long)src,
> + .len = PAGE_SIZE_4K,
> + .type = KVM_SEV_SNP_PAGE_TYPE_NORMAL,
> + };
> + ret = sev_ioctl(vm_fd, sev_fd, KVM_SEV_SNP_LAUNCH_UPDATE, &update);
> + if (ret) { perror("SNP_LAUNCH_UPDATE code"); goto out; }
[Severity: Medium]
If a signal interrupts the KVM_SEV_SNP_LAUNCH_UPDATE ioctl, KVM might
return 0 but leave update.len > 0 indicating a partial completion.
Does this code need a loop to check update.len and retry the remaining
length to prevent silent partial initialization?
> +
> + struct kvm_sev_snp_launch_update update_zero = {
> + .gfn_start = 1,
> + .uaddr = (uint64_t)(unsigned long)(src + PAGE_SIZE_4K),
> + .len = GUEST_MEM_SIZE - PAGE_SIZE_4K,
> + .type = KVM_SEV_SNP_PAGE_TYPE_ZERO,
> + };
> + ret = sev_ioctl(vm_fd, sev_fd, KVM_SEV_SNP_LAUNCH_UPDATE, &update_zero);
> + if (ret) { perror("SNP_LAUNCH_UPDATE zero"); goto out; }
[Severity: Medium]
Similarly, could a signal interrupting this update_zero ioctl cause a partial
completion here as well? If the return value is 0 but update_zero.len is
still greater than 0, the rest of the 16MB guest memory would be left
uninitialized, potentially causing flaky test failures later.
> +
> + struct kvm_sev_snp_launch_finish finish = { 0 };
> + ret = sev_ioctl(vm_fd, sev_fd, KVM_SEV_SNP_LAUNCH_FINISH, &finish);
--
Sashiko AI review · https://sashiko.dev/#/patchset/f09647f427565c1789a6979470045aab78661563.1784194290.git.dwmw@amazon.co.uk?part=9
next prev parent reply other threads:[~2026-07-16 15:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 9:31 [RFC PATCH 00/11] KVM: Allow alternative providers of guest_memfd backed by PFNMAP memory David Woodhouse
2026-07-16 9:31 ` [RFC PATCH 01/11] KVM: selftests: sev_smoke_test: Only run VM types the host offers David Woodhouse
2026-07-16 9:31 ` [RFC PATCH 02/11] KVM: selftests: sev_init2_tests: Derive SEV availability from KVM David Woodhouse
2026-07-16 9:31 ` [RFC PATCH 03/11] KVM: SEV: Remove struct page dependency from SNP gmem paths David Woodhouse
2026-07-16 15:30 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 04/11] KVM: guest_memfd: Introduce guest memory ops and route native gmem through them David Woodhouse
2026-07-16 15:30 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 05/11] iommufd: Look up private-interconnect phys via exporter symbols David Woodhouse
2026-07-16 15:33 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 06/11] iommufd: Plumb dma-buf memory-type (RAM vs MMIO) through the phys map David Woodhouse
2026-07-16 15:41 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 07/11] KVM: guest_memfd: Add ops-driven page revocation David Woodhouse
2026-07-16 15:42 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 08/11] samples/kvm: Add guest_memfd backing sample David Woodhouse
2026-07-16 15:53 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 09/11] selftests/kvm: gmem_provider KVM-only tests David Woodhouse
2026-07-16 15:46 ` sashiko-bot [this message]
2026-07-16 9:31 ` [RFC PATCH 10/11] selftests/kvm: gmem_provider iommufd tests David Woodhouse
2026-07-16 15:48 ` sashiko-bot
2026-07-16 9:31 ` [RFC PATCH 11/11] samples/kvm, selftests/kvm: Allow the gmem_provider NVMe DMA test on arm64 David Woodhouse
2026-07-16 15:54 ` sashiko-bot
2026-07-16 15:31 ` [RFC PATCH 01/11] KVM: selftests: sev_smoke_test: Only run VM types the host offers sashiko-bot
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=20260716154627.CC1151F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=dwmw2@infradead.org \
--cc=kvm@vger.kernel.org \
--cc=media-ci@linuxtv.org \
--cc=sashiko-reviews@lists.linux.dev \
/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