1 // SPDX-License-Identifier: GPL-2.0-only
3 * vcpu_width_config - Test KVM_ARM_VCPU_INIT() with KVM_ARM_VCPU_EL1_32BIT.
5 * Copyright (c) 2022 Google LLC.
7 * This is a test that ensures that non-mixed-width vCPUs (all 64bit vCPUs
8 * or all 32bit vcPUs) can be configured and mixed-width vCPUs cannot be
13 #include "processor.h"
14 #include "test_util.h"
18 * Add a vCPU, run KVM_ARM_VCPU_INIT with @init0, and then
19 * add another vCPU, and run KVM_ARM_VCPU_INIT with @init1.
21 static int add_init_2vcpus(struct kvm_vcpu_init
*init0
,
22 struct kvm_vcpu_init
*init1
)
24 struct kvm_vcpu
*vcpu0
, *vcpu1
;
28 vm
= vm_create_barebones();
30 vcpu0
= __vm_vcpu_add(vm
, 0);
31 ret
= __vcpu_ioctl(vcpu0
, KVM_ARM_VCPU_INIT
, init0
);
35 vcpu1
= __vm_vcpu_add(vm
, 1);
36 ret
= __vcpu_ioctl(vcpu1
, KVM_ARM_VCPU_INIT
, init1
);
44 * Add two vCPUs, then run KVM_ARM_VCPU_INIT for one vCPU with @init0,
45 * and run KVM_ARM_VCPU_INIT for another vCPU with @init1.
47 static int add_2vcpus_init_2vcpus(struct kvm_vcpu_init
*init0
,
48 struct kvm_vcpu_init
*init1
)
50 struct kvm_vcpu
*vcpu0
, *vcpu1
;
54 vm
= vm_create_barebones();
56 vcpu0
= __vm_vcpu_add(vm
, 0);
57 vcpu1
= __vm_vcpu_add(vm
, 1);
59 ret
= __vcpu_ioctl(vcpu0
, KVM_ARM_VCPU_INIT
, init0
);
63 ret
= __vcpu_ioctl(vcpu1
, KVM_ARM_VCPU_INIT
, init1
);
71 * Tests that two 64bit vCPUs can be configured, two 32bit vCPUs can be
72 * configured, and two mixed-width vCPUs cannot be configured.
73 * Each of those three cases, configure vCPUs in two different orders.
74 * The one is running KVM_CREATE_VCPU for 2 vCPUs, and then running
75 * KVM_ARM_VCPU_INIT for them.
76 * The other is running KVM_CREATE_VCPU and KVM_ARM_VCPU_INIT for a vCPU,
77 * and then run those commands for another vCPU.
81 struct kvm_vcpu_init init0
, init1
;
85 TEST_REQUIRE(kvm_has_cap(KVM_CAP_ARM_EL1_32BIT
));
87 /* Get the preferred target type and copy that to init1 for later use */
88 vm
= vm_create_barebones();
89 vm_ioctl(vm
, KVM_ARM_PREFERRED_TARGET
, &init0
);
93 /* Test with 64bit vCPUs */
94 ret
= add_init_2vcpus(&init0
, &init0
);
96 "Configuring 64bit EL1 vCPUs failed unexpectedly");
97 ret
= add_2vcpus_init_2vcpus(&init0
, &init0
);
99 "Configuring 64bit EL1 vCPUs failed unexpectedly");
101 /* Test with 32bit vCPUs */
102 init0
.features
[0] = (1 << KVM_ARM_VCPU_EL1_32BIT
);
103 ret
= add_init_2vcpus(&init0
, &init0
);
104 TEST_ASSERT(ret
== 0,
105 "Configuring 32bit EL1 vCPUs failed unexpectedly");
106 ret
= add_2vcpus_init_2vcpus(&init0
, &init0
);
107 TEST_ASSERT(ret
== 0,
108 "Configuring 32bit EL1 vCPUs failed unexpectedly");
110 /* Test with mixed-width vCPUs */
111 init0
.features
[0] = 0;
112 init1
.features
[0] = (1 << KVM_ARM_VCPU_EL1_32BIT
);
113 ret
= add_init_2vcpus(&init0
, &init1
);
114 TEST_ASSERT(ret
!= 0,
115 "Configuring mixed-width vCPUs worked unexpectedly");
116 ret
= add_2vcpus_init_2vcpus(&init0
, &init1
);
117 TEST_ASSERT(ret
!= 0,
118 "Configuring mixed-width vCPUs worked unexpectedly");