diff options
-rw-r--r-- | Documentation/virtual/kvm/api.txt | 7 | ||||
-rw-r--r-- | include/uapi/linux/kvm.h | 1 | ||||
-rw-r--r-- | virt/kvm/kvm_main.c | 58 |
3 files changed, 37 insertions, 29 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 884f819e1908..8898caf8c090 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt | |||
@@ -148,9 +148,9 @@ of banks, as set via the KVM_X86_SETUP_MCE ioctl. | |||
148 | 148 | ||
149 | 4.4 KVM_CHECK_EXTENSION | 149 | 4.4 KVM_CHECK_EXTENSION |
150 | 150 | ||
151 | Capability: basic | 151 | Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl |
152 | Architectures: all | 152 | Architectures: all |
153 | Type: system ioctl | 153 | Type: system ioctl, vm ioctl |
154 | Parameters: extension identifier (KVM_CAP_*) | 154 | Parameters: extension identifier (KVM_CAP_*) |
155 | Returns: 0 if unsupported; 1 (or some other positive integer) if supported | 155 | Returns: 0 if unsupported; 1 (or some other positive integer) if supported |
156 | 156 | ||
@@ -160,6 +160,9 @@ receives an integer that describes the extension availability. | |||
160 | Generally 0 means no and 1 means yes, but some extensions may report | 160 | Generally 0 means no and 1 means yes, but some extensions may report |
161 | additional information in the integer return value. | 161 | additional information in the integer return value. |
162 | 162 | ||
163 | Based on their initialization different VMs may have different capabilities. | ||
164 | It is thus encouraged to use the vm ioctl to query for capabilities (available | ||
165 | with KVM_CAP_CHECK_EXTENSION_VM on the vm fd) | ||
163 | 166 | ||
164 | 4.5 KVM_GET_VCPU_MMAP_SIZE | 167 | 4.5 KVM_GET_VCPU_MMAP_SIZE |
165 | 168 | ||
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 0418b746cb68..51776cac6a9b 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h | |||
@@ -759,6 +759,7 @@ struct kvm_ppc_smmu_info { | |||
759 | #define KVM_CAP_ARM_PSCI_0_2 102 | 759 | #define KVM_CAP_ARM_PSCI_0_2 102 |
760 | #define KVM_CAP_PPC_FIXUP_HCALL 103 | 760 | #define KVM_CAP_PPC_FIXUP_HCALL 103 |
761 | #define KVM_CAP_PPC_ENABLE_HCALL 104 | 761 | #define KVM_CAP_PPC_ENABLE_HCALL 104 |
762 | #define KVM_CAP_CHECK_EXTENSION_VM 105 | ||
762 | 763 | ||
763 | #ifdef KVM_CAP_IRQ_ROUTING | 764 | #ifdef KVM_CAP_IRQ_ROUTING |
764 | 765 | ||
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e28f3caa539d..1b95cc926cfc 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -2324,6 +2324,34 @@ static int kvm_ioctl_create_device(struct kvm *kvm, | |||
2324 | return 0; | 2324 | return 0; |
2325 | } | 2325 | } |
2326 | 2326 | ||
2327 | static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) | ||
2328 | { | ||
2329 | switch (arg) { | ||
2330 | case KVM_CAP_USER_MEMORY: | ||
2331 | case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: | ||
2332 | case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS: | ||
2333 | #ifdef CONFIG_KVM_APIC_ARCHITECTURE | ||
2334 | case KVM_CAP_SET_BOOT_CPU_ID: | ||
2335 | #endif | ||
2336 | case KVM_CAP_INTERNAL_ERROR_DATA: | ||
2337 | #ifdef CONFIG_HAVE_KVM_MSI | ||
2338 | case KVM_CAP_SIGNAL_MSI: | ||
2339 | #endif | ||
2340 | #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING | ||
2341 | case KVM_CAP_IRQFD_RESAMPLE: | ||
2342 | #endif | ||
2343 | case KVM_CAP_CHECK_EXTENSION_VM: | ||
2344 | return 1; | ||
2345 | #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING | ||
2346 | case KVM_CAP_IRQ_ROUTING: | ||
2347 | return KVM_MAX_IRQ_ROUTES; | ||
2348 | #endif | ||
2349 | default: | ||
2350 | break; | ||
2351 | } | ||
2352 | return kvm_vm_ioctl_check_extension(kvm, arg); | ||
2353 | } | ||
2354 | |||
2327 | static long kvm_vm_ioctl(struct file *filp, | 2355 | static long kvm_vm_ioctl(struct file *filp, |
2328 | unsigned int ioctl, unsigned long arg) | 2356 | unsigned int ioctl, unsigned long arg) |
2329 | { | 2357 | { |
@@ -2487,6 +2515,9 @@ static long kvm_vm_ioctl(struct file *filp, | |||
2487 | r = 0; | 2515 | r = 0; |
2488 | break; | 2516 | break; |
2489 | } | 2517 | } |
2518 | case KVM_CHECK_EXTENSION: | ||
2519 | r = kvm_vm_ioctl_check_extension_generic(kvm, arg); | ||
2520 | break; | ||
2490 | default: | 2521 | default: |
2491 | r = kvm_arch_vm_ioctl(filp, ioctl, arg); | 2522 | r = kvm_arch_vm_ioctl(filp, ioctl, arg); |
2492 | if (r == -ENOTTY) | 2523 | if (r == -ENOTTY) |
@@ -2571,33 +2602,6 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) | |||
2571 | return r; | 2602 | return r; |
2572 | } | 2603 | } |
2573 | 2604 | ||
2574 | static long kvm_vm_ioctl_check_extension_generic(struct kvm *kvm, long arg) | ||
2575 | { | ||
2576 | switch (arg) { | ||
2577 | case KVM_CAP_USER_MEMORY: | ||
2578 | case KVM_CAP_DESTROY_MEMORY_REGION_WORKS: | ||
2579 | case KVM_CAP_JOIN_MEMORY_REGIONS_WORKS: | ||
2580 | #ifdef CONFIG_KVM_APIC_ARCHITECTURE | ||
2581 | case KVM_CAP_SET_BOOT_CPU_ID: | ||
2582 | #endif | ||
2583 | case KVM_CAP_INTERNAL_ERROR_DATA: | ||
2584 | #ifdef CONFIG_HAVE_KVM_MSI | ||
2585 | case KVM_CAP_SIGNAL_MSI: | ||
2586 | #endif | ||
2587 | #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING | ||
2588 | case KVM_CAP_IRQFD_RESAMPLE: | ||
2589 | #endif | ||
2590 | return 1; | ||
2591 | #ifdef CONFIG_HAVE_KVM_IRQ_ROUTING | ||
2592 | case KVM_CAP_IRQ_ROUTING: | ||
2593 | return KVM_MAX_IRQ_ROUTES; | ||
2594 | #endif | ||
2595 | default: | ||
2596 | break; | ||
2597 | } | ||
2598 | return kvm_vm_ioctl_check_extension(kvm, arg); | ||
2599 | } | ||
2600 | |||
2601 | static long kvm_dev_ioctl(struct file *filp, | 2605 | static long kvm_dev_ioctl(struct file *filp, |
2602 | unsigned int ioctl, unsigned long arg) | 2606 | unsigned int ioctl, unsigned long arg) |
2603 | { | 2607 | { |