History

KVM: Allow KVM_CHECK_EXTENSION on the vm fd

The KVM_CHECK_EXTENSION is only available on the kvm fd today. Unfortunately on PPC some of the capabilities change depending on the way a VM was created. So instead we need a way to expose capabilities as VM ioctl, so that we can see which VM type we're using (HV or PR). To enable this, add the KVM_CHECK_EXTENSION ioctl to our vm ioctl portfolio.

Alexander Graf committed 12 years ago

Commit 92b591a1 parent 784aa3d3 files · +37 −29Browse files

Unified · Split

3 files
  1. Documentation/virtual/kvm/api.txt +5 −2
  2. include/uapi/linux/kvm.h +1 −0
  3. virt/kvm/kvm_main.c +31 −27
Documentation/virtual/kvm/api.txt+5−2
@@ -148,9 +148,9 @@ of banks, as set via the KVM_X86_SETUP_MCE ioctl. · 147 unmodified lines
148 148
1494.4 KVM_CHECK_EXTENSION1494.4 KVM_CHECK_EXTENSION
150 150
151Capability: basic151Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
152Architectures: all152Architectures: all
153Type: system ioctl153Type: system ioctl, vm ioctl
154Parameters: extension identifier (KVM_CAP_*)154Parameters: extension identifier (KVM_CAP_*)
155Returns: 0 if unsupported; 1 (or some other positive integer) if supported155Returns: 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. · 3 unmodified lines
160Generally 0 means no and 1 means yes, but some extensions may report160Generally 0 means no and 1 means yes, but some extensions may report
161additional information in the integer return value.161additional information in the integer return value.
162 162
163Based on their initialization different VMs may have different capabilities.
164It is thus encouraged to use the vm ioctl to query for capabilities (available
165with KVM_CAP_CHECK_EXTENSION_VM on the vm fd)
163 166
1644.5 KVM_GET_VCPU_MMAP_SIZE1674.5 KVM_GET_VCPU_MMAP_SIZE
165 168
include/uapi/linux/kvm.h+1−0
@@ -759,6 +759,7 @@ struct kvm_ppc_smmu_info { · 758 unmodified lines
759#define KVM_CAP_ARM_PSCI_0_2 102759#define KVM_CAP_ARM_PSCI_0_2 102
760#define KVM_CAP_PPC_FIXUP_HCALL 103760#define KVM_CAP_PPC_FIXUP_HCALL 103
761#define KVM_CAP_PPC_ENABLE_HCALL 104761#define KVM_CAP_PPC_ENABLE_HCALL 104
762#define KVM_CAP_CHECK_EXTENSION_VM 105
762 763
763#ifdef KVM_CAP_IRQ_ROUTING764#ifdef KVM_CAP_IRQ_ROUTING
764 765
virt/kvm/kvm_main.c+31−27
@@ -2324,6 +2324,34 @@ static int kvm_ioctl_create_device(struct kvm *kvm, · 2323 unmodified lines
2324 return 0;2324 return 0;
2325}2325}
2326 2326
2327static 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
2327static long kvm_vm_ioctl(struct file *filp,2355static 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, · 157 unmodified lines
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) · 78 unmodified lines
2571 return r;2602 return r;
2572}2603}
2573 2604
2574static 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
2601static long kvm_dev_ioctl(struct file *filp,2605static long kvm_dev_ioctl(struct file *filp,
2602 unsigned int ioctl, unsigned long arg)2606 unsigned int ioctl, unsigned long arg)
2603{2607{