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 @init1, and then
19 * add another vCPU, and run KVM_ARM_VCPU_INIT with @init2.
21 static int add_init_2vcpus(struct kvm_vcpu_init *init1,
22 struct kvm_vcpu_init *init2)
27 vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
30 ret = _vcpu_ioctl(vm, 0, KVM_ARM_VCPU_INIT, init1);
35 ret = _vcpu_ioctl(vm, 1, KVM_ARM_VCPU_INIT, init2);
43 * Add two vCPUs, then run KVM_ARM_VCPU_INIT for one vCPU with @init1,
44 * and run KVM_ARM_VCPU_INIT for another vCPU with @init2.
46 static int add_2vcpus_init_2vcpus(struct kvm_vcpu_init *init1,
47 struct kvm_vcpu_init *init2)
52 vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
57 ret = _vcpu_ioctl(vm, 0, KVM_ARM_VCPU_INIT, init1);
61 ret = _vcpu_ioctl(vm, 1, KVM_ARM_VCPU_INIT, init2);
69 * Tests that two 64bit vCPUs can be configured, two 32bit vCPUs can be
70 * configured, and two mixed-width vCPUs cannot be configured.
71 * Each of those three cases, configure vCPUs in two different orders.
72 * The one is running KVM_CREATE_VCPU for 2 vCPUs, and then running
73 * KVM_ARM_VCPU_INIT for them.
74 * The other is running KVM_CREATE_VCPU and KVM_ARM_VCPU_INIT for a vCPU,
75 * and then run those commands for another vCPU.
79 struct kvm_vcpu_init init1, init2;
83 if (!kvm_check_cap(KVM_CAP_ARM_EL1_32BIT)) {
84 print_skip("KVM_CAP_ARM_EL1_32BIT is not supported");
88 /* Get the preferred target type and copy that to init2 for later use */
89 vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
90 vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init1);
94 /* Test with 64bit vCPUs */
95 ret = add_init_2vcpus(&init1, &init1);
97 "Configuring 64bit EL1 vCPUs failed unexpectedly");
98 ret = add_2vcpus_init_2vcpus(&init1, &init1);
100 "Configuring 64bit EL1 vCPUs failed unexpectedly");
102 /* Test with 32bit vCPUs */
103 init1.features[0] = (1 << KVM_ARM_VCPU_EL1_32BIT);
104 ret = add_init_2vcpus(&init1, &init1);
105 TEST_ASSERT(ret == 0,
106 "Configuring 32bit EL1 vCPUs failed unexpectedly");
107 ret = add_2vcpus_init_2vcpus(&init1, &init1);
108 TEST_ASSERT(ret == 0,
109 "Configuring 32bit EL1 vCPUs failed unexpectedly");
111 /* Test with mixed-width vCPUs */
112 init1.features[0] = 0;
113 init2.features[0] = (1 << KVM_ARM_VCPU_EL1_32BIT);
114 ret = add_init_2vcpus(&init1, &init2);
115 TEST_ASSERT(ret != 0,
116 "Configuring mixed-width vCPUs worked unexpectedly");
117 ret = add_2vcpus_init_2vcpus(&init1, &init2);
118 TEST_ASSERT(ret != 0,
119 "Configuring mixed-width vCPUs worked unexpectedly");