~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/kvm/x86_64/max_vcpuid_cap_test.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 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         /* Test BOOT_CPU_ID interaction (MAX_VCPU_ID cannot be lower) */
 30         if (kvm_has_cap(KVM_CAP_SET_BOOT_CPU_ID)) {
 31                 vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)MAX_VCPU_ID);
 32 
 33                 /* Try setting KVM_CAP_MAX_VCPU_ID below BOOT_CPU_ID */
 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 below BOOT_CPU_ID should fail");
 37         }
 38 
 39         /* Set KVM_CAP_MAX_VCPU_ID */
 40         vm_enable_cap(vm, KVM_CAP_MAX_VCPU_ID, MAX_VCPU_ID);
 41 
 42         /* Try to set KVM_CAP_MAX_VCPU_ID again */
 43         ret = __vm_enable_cap(vm, KVM_CAP_MAX_VCPU_ID, MAX_VCPU_ID + 1);
 44         TEST_ASSERT(ret < 0,
 45                     "Setting KVM_CAP_MAX_VCPU_ID multiple times should fail");
 46 
 47         /* Create vCPU with id beyond KVM_CAP_MAX_VCPU_ID cap */
 48         ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)MAX_VCPU_ID);
 49         TEST_ASSERT(ret < 0, "Creating vCPU with ID > MAX_VCPU_ID should fail");
 50 
 51         /* Create vCPU with bits 63:32 != 0, but an otherwise valid id */
 52         ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)(1L << 32));
 53         TEST_ASSERT(ret < 0, "Creating vCPU with ID[63:32] != 0 should fail");
 54 
 55         /* Create vCPU with id within bounds */
 56         ret = __vm_ioctl(vm, KVM_CREATE_VCPU, (void *)0);
 57         TEST_ASSERT(ret >= 0, "Creating vCPU with ID 0 should succeed");
 58 
 59         close(ret);
 60         kvm_vm_free(vm);
 61         return 0;
 62 }
 63 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php