Re: [PATCH v2 1/2] KVM: selftests: SEV: Verify unsupported VM types are rejected at creation

From: Sean Christopherson

Date: Thu Jul 09 2026 - 16:21:20 EST


On Thu, Jul 09, 2026, Hemanth Selam wrote:
> @@ -73,19 +74,34 @@ static void test_init2_invalid(unsigned long vm_type, struct kvm_sev_init *init,
> kvm_vm_free(vm);
> }
>
> +static void test_create_invalid_type(unsigned long vm_type, const char *msg)
> +{
> + int fd = __kvm_ioctl(kvm_fd, KVM_CREATE_VM, (void *)vm_type);
> + int err = errno;
> +
> + /* Clean up before asserting; TEST_ASSERT() aborts on failure. */

Literally every test relies on the kernel to clean up fds on an early exit. I
see no reason for this to behave differently.

Also, Sashiko was wrong. If KVM_CREATE_VM fails with something other than EINVAL,
the assert will NOT fire, but fd will be < 0.

> + if (fd >= 0)
> + close(fd);
> +
> + TEST_ASSERT(fd < 0 && err == EINVAL,
> + "KVM_CREATE_VM should reject unsupported type (%s), got fd=%d errno=%d",
> + msg, fd, err);

test_assert logs the errno, no need to spit it out here as well.

> +}
> +
> void test_vm_types(void)
> {
> test_init2(KVM_X86_SEV_VM, &(struct kvm_sev_init){});
>
> - /*
> - * TODO: check that unsupported types cannot be created. Probably
> - * a separate selftest.

Heh, I agree with the comment: put this in a separate selftest. This doesn't
have anything to do with KVM_SEV_INIT2, and in fact doesn't even have anyting to
do with SEV+ or even x86. E.g. add a kvm_vm_types_test that attempts to create
all possible VM types, and asserts success/failure based on the output from
kvm_check_cap(KVM_CAP_VM_TYPES).