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
148148
149149 4.4 KVM_CHECK_EXTENSION
150150
151−Capability: basic
151+Capability: basic, KVM_CAP_CHECK_EXTENSION_VM for vm ioctl
152152 Architectures: all
153−Type: system ioctl
153+Type: system ioctl, vm ioctl
154154 Parameters: extension identifier (KVM_CAP_*)
155155 Returns: 0 if unsupported; 1 (or some other positive integer) if supported
156156
@@ -160,6 +160,9 @@ receives an integer that describes the extension availability. · 3 unmodified lines
160160 Generally 0 means no and 1 means yes, but some extensions may report
161161 additional information in the integer return value.
162162
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)
163166
164167 4.5 KVM_GET_VCPU_MMAP_SIZE
165168
include/uapi/linux/kvm.h+1−0
@@ -759,6 +759,7 @@ struct kvm_ppc_smmu_info { · 758 unmodified lines
759759 #define KVM_CAP_ARM_PSCI_0_2 102
760760 #define KVM_CAP_PPC_FIXUP_HCALL 103
761761 #define KVM_CAP_PPC_ENABLE_HCALL 104
762+#define KVM_CAP_CHECK_EXTENSION_VM 105
762763
763764 #ifdef KVM_CAP_IRQ_ROUTING
764765
virt/kvm/kvm_main.c+31−27
@@ -2324,6 +2324,34 @@ static int kvm_ioctl_create_device(struct kvm *kvm, · 2323 unmodified lines
23242324 return 0;
23252325 }
23262326
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+
23272355 static long kvm_vm_ioctl(struct file *filp,
23282356 unsigned int ioctl, unsigned long arg)
23292357 {
@@ -2487,6 +2515,9 @@ static long kvm_vm_ioctl(struct file *filp, · 157 unmodified lines
24872515 r = 0;
24882516 break;
24892517 }
2518+ case KVM_CHECK_EXTENSION:
2519+ r = kvm_vm_ioctl_check_extension_generic(kvm, arg);
2520+ break;
24902521 default:
24912522 r = kvm_arch_vm_ioctl(filp, ioctl, arg);
24922523 if (r == -ENOTTY)
@@ -2571,33 +2602,6 @@ static int kvm_dev_ioctl_create_vm(unsigned long type) · 78 unmodified lines
25712602 return r;
25722603 }
25732604
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−
26012605 static long kvm_dev_ioctl(struct file *filp,
26022606 unsigned int ioctl, unsigned long arg)
26032607 {