Commit 71fbfd5f38f73515f1516a68fbe04dba198b70f0

Authored by Alexander Graf
Committed by Avi Kivity
1 parent ca7f4203b9

KVM: Add support for enabling capabilities per-vcpu

Some times we don't want all capabilities to be available to all
our vcpus. One example for that is the OSI interface, implemented
in the next patch.

In order to have a generic mechanism in how to enable capabilities
individually, this patch introduces a new ioctl that can be used
for this purpose. That way features we don't want in all guests or
userspace configurations can just not be enabled and we're good.

Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: Avi Kivity <avi@redhat.com>

Showing 3 changed files with 73 additions and 0 deletions Side-by-side Diff

Documentation/kvm/api.txt
... ... @@ -813,6 +813,41 @@
813 813 because of a quirk in the virtualization implementation (see the internals
814 814 documentation when it pops into existence).
815 815  
  816 +4.36 KVM_ENABLE_CAP
  817 +
  818 +Capability: KVM_CAP_ENABLE_CAP
  819 +Architectures: ppc
  820 +Type: vcpu ioctl
  821 +Parameters: struct kvm_enable_cap (in)
  822 +Returns: 0 on success; -1 on error
  823 +
  824 ++Not all extensions are enabled by default. Using this ioctl the application
  825 +can enable an extension, making it available to the guest.
  826 +
  827 +On systems that do not support this ioctl, it always fails. On systems that
  828 +do support it, it only works for extensions that are supported for enablement.
  829 +
  830 +To check if a capability can be enabled, the KVM_CHECK_EXTENSION ioctl should
  831 +be used.
  832 +
  833 +struct kvm_enable_cap {
  834 + /* in */
  835 + __u32 cap;
  836 +
  837 +The capability that is supposed to get enabled.
  838 +
  839 + __u32 flags;
  840 +
  841 +A bitfield indicating future enhancements. Has to be 0 for now.
  842 +
  843 + __u64 args[4];
  844 +
  845 +Arguments for enabling a feature. If a feature needs initial values to
  846 +function properly, this is the place to put them.
  847 +
  848 + __u8 pad[64];
  849 +};
  850 +
816 851 5. The kvm_run structure
817 852  
818 853 Application code obtains a pointer to the kvm_run structure by
arch/powerpc/kvm/powerpc.c
... ... @@ -150,6 +150,7 @@
150 150 case KVM_CAP_PPC_SEGSTATE:
151 151 case KVM_CAP_PPC_PAIRED_SINGLES:
152 152 case KVM_CAP_PPC_UNSET_IRQ:
  153 + case KVM_CAP_ENABLE_CAP:
153 154 r = 1;
154 155 break;
155 156 case KVM_CAP_COALESCED_MMIO:
... ... @@ -465,6 +466,23 @@
465 466 return 0;
466 467 }
467 468  
  469 +static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
  470 + struct kvm_enable_cap *cap)
  471 +{
  472 + int r;
  473 +
  474 + if (cap->flags)
  475 + return -EINVAL;
  476 +
  477 + switch (cap->cap) {
  478 + default:
  479 + r = -EINVAL;
  480 + break;
  481 + }
  482 +
  483 + return r;
  484 +}
  485 +
468 486 int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu,
469 487 struct kvm_mp_state *mp_state)
470 488 {
... ... @@ -491,6 +509,15 @@
491 509 if (copy_from_user(&irq, argp, sizeof(irq)))
492 510 goto out;
493 511 r = kvm_vcpu_ioctl_interrupt(vcpu, &irq);
  512 + break;
  513 + }
  514 + case KVM_ENABLE_CAP:
  515 + {
  516 + struct kvm_enable_cap cap;
  517 + r = -EFAULT;
  518 + if (copy_from_user(&cap, argp, sizeof(cap)))
  519 + goto out;
  520 + r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
494 521 break;
495 522 }
496 523 default:
... ... @@ -400,6 +400,15 @@
400 400 __u8 pad[36];
401 401 };
402 402  
  403 +/* for KVM_ENABLE_CAP */
  404 +struct kvm_enable_cap {
  405 + /* in */
  406 + __u32 cap;
  407 + __u32 flags;
  408 + __u64 args[4];
  409 + __u8 pad[64];
  410 +};
  411 +
403 412 #define KVMIO 0xAE
404 413  
405 414 /*
... ... @@ -508,6 +517,7 @@
508 517 #endif
509 518 #define KVM_CAP_X86_ROBUST_SINGLESTEP 51
510 519 #define KVM_CAP_PPC_UNSET_IRQ 53
  520 +#define KVM_CAP_ENABLE_CAP 54
511 521  
512 522 #ifdef KVM_CAP_IRQ_ROUTING
513 523  
... ... @@ -697,6 +707,7 @@
697 707 /* Available with KVM_CAP_DEBUGREGS */
698 708 #define KVM_GET_DEBUGREGS _IOR(KVMIO, 0xa1, struct kvm_debugregs)
699 709 #define KVM_SET_DEBUGREGS _IOW(KVMIO, 0xa2, struct kvm_debugregs)
  710 +#define KVM_ENABLE_CAP _IOW(KVMIO, 0xa3, struct kvm_enable_cap)
700 711  
701 712 #define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
702 713