1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * maximum APIC ID capability tests
4 *
5 * Copyright (C) 2022, Intel, Inc.
6 *
7 * Tests for getting/setting maximum APIC ID capability
8 */
9
10 #include "kvm_util.h"
11
12 #define MAX_VCPU_ID 2
13
main(int argc,char * argv[])14 int main(int argc, char *argv[])
15 {
16 struct kvm_vm *vm;
17 int ret;
18
19 vm = vm_create_barebones();
20
21 /* Get KVM_CAP_MAX_VCPU_ID cap supported in KVM */
22 ret = vm_check_cap(vm, KVM_CAP_MAX_VCPU_ID);
23
24 /* Try to set KVM_CAP_MAX_VCPU_ID beyond KVM cap */
25 ret = __vm_enable_cap(vm, KVM_CAP_MAX_VCPU_ID, ret + 1);
26 TEST_ASSERT(ret < 0,
27 "Setting KVM_CAP_MAX_VCPU_ID beyond KVM cap should fail");
28
29 /* Set KVM_CAP_MAX_VCPU_ID */
30 vm_enable_cap(vm, KVM_CAP_MAX_VCPU_ID, MAX_VCPU_ID);
31
32
33 /* Try to set KVM_CAP_MAX_VCPU_ID again */
34 ret = __vm_enable_cap(vm, KVM_CAP_MAX_VCPU_ID, MAX_VCPU_ID + 1);
35 TEST_ASSERT(ret < 0,
36 "Setting KVM_CAP_MAX_VCPU_ID multiple times should fail");
37
38 /* Create vCPU with id beyond KVM_CAP_MAX_VCPU_ID cap*/
39 ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)MAX_VCPU_ID);
40 TEST_ASSERT(ret < 0, "Creating vCPU with ID > MAX_VCPU_ID should fail");
41
42 kvm_vm_free(vm);
43 return 0;
44 }
45