[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240209183743.22030-12-pbonzini@redhat.com>
Date: Fri, 9 Feb 2024 13:37:43 -0500
From: Paolo Bonzini <pbonzini@...hat.com>
To: linux-kernel@...r.kernel.org,
kvm@...r.kernel.org
Cc: seanjc@...gle.com,
michael.roth@....com,
aik@....com,
isaku.yamahata@...el.com
Subject: [PATCH 11/10] selftests: kvm: switch sev_migrate_tests to KVM_SEV_INIT2
Signed-off-by: Paolo Bonzini <pbonzini@...hat.com>
---
.../selftests/kvm/x86_64/sev_migrate_tests.c | 45 ++++++++++---------
1 file changed, 23 insertions(+), 22 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
index c7ef97561038..301f7083cad0 100644
--- a/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
+++ b/tools/testing/selftests/kvm/x86_64/sev_migrate_tests.c
@@ -50,11 +50,12 @@ static void sev_ioctl(int vm_fd, int cmd_id, void *data)
static struct kvm_vm *sev_vm_create(bool es)
{
struct kvm_vm *vm;
+ struct kvm_sev_init init = { 0 };
struct kvm_sev_launch_start start = { 0 };
int i;
- vm = vm_create_barebones();
- sev_ioctl(vm->fd, es ? KVM_SEV_ES_INIT : KVM_SEV_INIT, NULL);
+ vm = vm_create_barebones_type(es ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM);
+ sev_ioctl(vm->fd, KVM_SEV_INIT2, &init);
for (i = 0; i < NR_MIGRATE_TEST_VCPUS; ++i)
__vm_vcpu_add(vm, i);
if (es)
@@ -65,12 +66,12 @@ static struct kvm_vm *sev_vm_create(bool es)
return vm;
}
-static struct kvm_vm *aux_vm_create(bool with_vcpus)
+static struct kvm_vm *aux_vm_create(bool es, bool with_vcpus)
{
struct kvm_vm *vm;
int i;
- vm = vm_create_barebones();
+ vm = vm_create_barebones_type(es ? KVM_X86_SEV_ES_VM : KVM_X86_SEV_VM);
if (!with_vcpus)
return vm;
@@ -102,7 +103,7 @@ static void test_sev_migrate_from(bool es)
src_vm = sev_vm_create(es);
for (i = 0; i < NR_MIGRATE_TEST_VMS; ++i)
- dst_vms[i] = aux_vm_create(true);
+ dst_vms[i] = aux_vm_create(es, true);
/* Initial migration from the src to the first dst. */
sev_migrate_from(dst_vms[0], src_vm);
@@ -164,16 +165,17 @@ static void test_sev_migrate_locking(void)
static void test_sev_migrate_parameters(void)
{
- struct kvm_vm *sev_vm, *sev_es_vm, *vm_no_vcpu, *vm_no_sev,
+ struct kvm_vm *sev_vm, *sev_es_vm, *vm_no_vcpu,
*sev_es_vm_no_vmsa;
int ret;
vm_no_vcpu = vm_create_barebones();
- vm_no_sev = aux_vm_create(true);
- ret = __sev_migrate_from(vm_no_vcpu, vm_no_sev);
+ sev_vm = aux_vm_create(false, true);
+ ret = __sev_migrate_from(vm_no_vcpu, sev_vm);
TEST_ASSERT(ret == -1 && errno == EINVAL,
"Migrations require SEV enabled. ret %d, errno: %d\n", ret,
errno);
+ kvm_vm_free(sev_vm);
if (!have_sev_es)
goto out;
@@ -213,7 +215,6 @@ static void test_sev_migrate_parameters(void)
kvm_vm_free(sev_es_vm_no_vmsa);
out:
kvm_vm_free(vm_no_vcpu);
- kvm_vm_free(vm_no_sev);
}
static int __sev_mirror_create(struct kvm_vm *dst, struct kvm_vm *src)
@@ -272,7 +273,7 @@ static void test_sev_mirror(bool es)
int i;
src_vm = sev_vm_create(es);
- dst_vm = aux_vm_create(false);
+ dst_vm = aux_vm_create(es, false);
sev_mirror_create(dst_vm, src_vm);
@@ -295,8 +296,8 @@ static void test_sev_mirror_parameters(void)
int ret;
sev_vm = sev_vm_create(/* es= */ false);
- vm_with_vcpu = aux_vm_create(true);
- vm_no_vcpu = aux_vm_create(false);
+ vm_with_vcpu = aux_vm_create(false, true);
+ vm_no_vcpu = aux_vm_create(false, false);
ret = __sev_mirror_create(sev_vm, sev_vm);
TEST_ASSERT(
@@ -345,13 +346,13 @@ static void test_sev_move_copy(void)
*dst_mirror_vm, *dst2_mirror_vm, *dst3_mirror_vm;
sev_vm = sev_vm_create(/* es= */ false);
- dst_vm = aux_vm_create(true);
- dst2_vm = aux_vm_create(true);
- dst3_vm = aux_vm_create(true);
- mirror_vm = aux_vm_create(false);
- dst_mirror_vm = aux_vm_create(false);
- dst2_mirror_vm = aux_vm_create(false);
- dst3_mirror_vm = aux_vm_create(false);
+ dst_vm = aux_vm_create(false, true);
+ dst2_vm = aux_vm_create(false, true);
+ dst3_vm = aux_vm_create(false, true);
+ mirror_vm = aux_vm_create(false, false);
+ dst_mirror_vm = aux_vm_create(false, false);
+ dst2_mirror_vm = aux_vm_create(false, false);
+ dst3_mirror_vm = aux_vm_create(false, false);
sev_mirror_create(mirror_vm, sev_vm);
@@ -378,9 +379,9 @@ static void test_sev_move_copy(void)
* destruction is done safely.
*/
sev_vm = sev_vm_create(/* es= */ false);
- dst_vm = aux_vm_create(true);
- mirror_vm = aux_vm_create(false);
- dst_mirror_vm = aux_vm_create(false);
+ dst_vm = aux_vm_create(false, true);
+ mirror_vm = aux_vm_create(false, false);
+ dst_mirror_vm = aux_vm_create(false, false);
sev_mirror_create(mirror_vm, sev_vm);
--
2.39.0
Powered by blists - more mailing lists