]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
arm/arm64: KVM: make the maximum number of vCPUs a per-VM value
authorAndre Przywara <andre.przywara@arm.com>
Mon, 2 Jun 2014 14:26:01 +0000 (16:26 +0200)
committerChristoffer Dall <christoffer.dall@linaro.org>
Tue, 20 Jan 2015 17:25:28 +0000 (18:25 +0100)
Currently the maximum number of vCPUs supported is a global value
limited by the used GIC model. GICv3 will lift this limit, but we
still need to observe it for guests using GICv2.
So the maximum number of vCPUs is per-VM value, depending on the
GIC model the guest uses.
Store and check the value in struct kvm_arch, but keep it down to
8 for now.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
arch/arm/include/asm/kvm_host.h
arch/arm/kvm/arm.c
arch/arm64/include/asm/kvm_host.h
include/kvm/arm_vgic.h
virt/kvm/arm/vgic-v2.c
virt/kvm/arm/vgic-v3.c
virt/kvm/arm/vgic.c

index 2fa51740edc2fbe863d82e69010df4e18eda0e36..bde494654bccb6a7434ed81f355fbdd426a43b97 100644 (file)
@@ -68,6 +68,7 @@ struct kvm_arch {
 
        /* Interrupt controller */
        struct vgic_dist        vgic;
+       int max_vcpus;
 };
 
 #define KVM_NR_MEM_OBJS     40
index 3a51ffca75e38ef803e2ff07ad196eae933705e2..6fbfa5fff05dcc2bd7140d3993170b9dc457fa8e 100644 (file)
@@ -132,6 +132,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
        /* Mark the initial VMID generation invalid */
        kvm->arch.vmid_gen = 0;
 
+       /* The maximum number of VCPUs is limited by the host's GIC model */
+       kvm->arch.max_vcpus = kvm_vgic_get_max_vcpus();
+
        return ret;
 out_free_stage2_pgd:
        kvm_free_stage2_pgd(kvm);
@@ -218,6 +221,11 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id)
                goto out;
        }
 
+       if (id >= kvm->arch.max_vcpus) {
+               err = -EINVAL;
+               goto out;
+       }
+
        vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
        if (!vcpu) {
                err = -ENOMEM;
index ff8ee3ec32f4c3fbbf4b7ebd2403325ae05f6f10..2c49aa4ac818596540c97694667fb076cbe7c363 100644 (file)
@@ -59,6 +59,9 @@ struct kvm_arch {
        /* VTTBR value associated with above pgd and vmid */
        u64    vttbr;
 
+       /* The maximum number of vCPUs depends on the used GIC model */
+       int max_vcpus;
+
        /* Interrupt controller */
        struct vgic_dist        vgic;
 
index dd243969bfc3f2b12a520f64963d1dc9be079eb1..1c0e9dbabe6d2b0cd37a2e4bea8d76dcb0730e29 100644 (file)
@@ -33,6 +33,7 @@
 #define VGIC_V2_MAX_LRS                (1 << 6)
 #define VGIC_V3_MAX_LRS                16
 #define VGIC_MAX_IRQS          1024
+#define VGIC_V2_MAX_CPUS       8
 
 /* Sanity checks... */
 #if (KVM_MAX_VCPUS > 8)
@@ -132,6 +133,7 @@ struct vgic_params {
        unsigned int    maint_irq;
        /* Virtual control interface base address */
        void __iomem    *vctrl_base;
+       int             max_gic_vcpus;
 };
 
 struct vgic_vm_ops {
@@ -289,6 +291,7 @@ struct kvm_exit_mmio;
 int kvm_vgic_addr(struct kvm *kvm, unsigned long type, u64 *addr, bool write);
 int kvm_vgic_hyp_init(void);
 int kvm_vgic_map_resources(struct kvm *kvm);
+int kvm_vgic_get_max_vcpus(void);
 int kvm_vgic_create(struct kvm *kvm, u32 type);
 void kvm_vgic_destroy(struct kvm *kvm);
 void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu);
@@ -393,6 +396,11 @@ static inline bool vgic_ready(struct kvm *kvm)
 {
        return true;
 }
+
+static inline int kvm_vgic_get_max_vcpus(void)
+{
+       return KVM_MAX_VCPUS;
+}
 #endif
 
 #endif
index e1cd3cb95903d9c237a1cec353efd41cf45c5d80..e8b82b289844c3d56c70553ab9bb315a3d7bfc16 100644 (file)
@@ -237,6 +237,7 @@ int vgic_v2_probe(struct device_node *vgic_node,
                 vctrl_res.start, vgic->maint_irq);
 
        vgic->type = VGIC_V2;
+       vgic->max_gic_vcpus = VGIC_V2_MAX_CPUS;
        *ops = &vgic_v2_ops;
        *params = vgic;
        goto out;
index d14c75f4a33bb1f8a03e10fe24b6dbf168c1053d..ea39bad4b004b99012dff561a029e280eb95fb2c 100644 (file)
@@ -235,6 +235,7 @@ int vgic_v3_probe(struct device_node *vgic_node,
        vgic->vcpu_base = vcpu_res.start;
        vgic->vctrl_base = NULL;
        vgic->type = VGIC_V3;
+       vgic->max_gic_vcpus = KVM_MAX_VCPUS;
 
        kvm_info("%s@%llx IRQ%d\n", vgic_node->name,
                 vcpu_res.start, vgic->maint_irq);
index 1c3b75eb28f0b629530500149808bb8620a49752..2126bf5b00355d0f4380a99c724e1efacc805036 100644 (file)
@@ -1878,6 +1878,17 @@ static int vgic_vcpu_init_maps(struct kvm_vcpu *vcpu, int nr_irqs)
        return 0;
 }
 
+/**
+ * kvm_vgic_get_max_vcpus - Get the maximum number of VCPUs allowed by HW
+ *
+ * The host's GIC naturally limits the maximum amount of VCPUs a guest
+ * can use.
+ */
+int kvm_vgic_get_max_vcpus(void)
+{
+       return vgic->max_gic_vcpus;
+}
+
 void kvm_vgic_destroy(struct kvm *kvm)
 {
        struct vgic_dist *dist = &kvm->arch.vgic;
@@ -2072,6 +2083,8 @@ static void vgic_v2_init_emulation(struct kvm *kvm)
        dist->vm_ops.add_sgi_source = vgic_v2_add_sgi_source;
        dist->vm_ops.init_model = vgic_v2_init_model;
        dist->vm_ops.map_resources = vgic_v2_map_resources;
+
+       kvm->arch.max_vcpus = VGIC_V2_MAX_CPUS;
 }
 
 static int init_vgic_model(struct kvm *kvm, int type)
@@ -2084,6 +2097,9 @@ static int init_vgic_model(struct kvm *kvm, int type)
                return -ENODEV;
        }
 
+       if (atomic_read(&kvm->online_vcpus) > kvm->arch.max_vcpus)
+               return -E2BIG;
+
        return 0;
 }