From patchwork Fri Oct 31 17:26:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 5205991 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 62781C11AC for ; Fri, 31 Oct 2014 17:39:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 79E2C20212 for ; Fri, 31 Oct 2014 17:39:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D2FF201C7 for ; Fri, 31 Oct 2014 17:39:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XkG7i-0005dd-4p; Fri, 31 Oct 2014 17:36:30 +0000 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XkG7N-0005WE-N6 for linux-arm-kernel@lists.infradead.org; Fri, 31 Oct 2014 17:36:10 +0000 Received: from e106785-lin.cambridge.arm.com ([10.1.203.149]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s9VHQswx025574; Fri, 31 Oct 2014 17:26:56 GMT From: Andre Przywara To: christoffer.dall@linaro.org, marc.zyngier@arm.com Subject: [PATCH v3 09/19] arm/arm64: KVM: make the maximum number of vCPUs a per-VM value Date: Fri, 31 Oct 2014 17:26:44 +0000 Message-Id: <1414776414-13426-10-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414776414-13426-1-git-send-email-andre.przywara@arm.com> References: <1414776414-13426-1-git-send-email-andre.przywara@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141031_103610_120438_142803EC X-CRM114-Status: GOOD ( 15.78 ) X-Spam-Score: -5.6 (-----) Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- arch/arm/include/asm/kvm_host.h | 1 + arch/arm/kvm/arm.c | 6 ++++++ arch/arm64/include/asm/kvm_host.h | 3 +++ virt/kvm/arm/vgic-v2.c | 7 +++++++ virt/kvm/arm/vgic-v3.c | 8 ++++++++ 5 files changed, 25 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index b443dfe..7969e6e 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -68,6 +68,7 @@ struct kvm_arch { /* Interrupt controller */ struct vgic_dist vgic; + int max_vcpus; }; #define KVM_NR_MEM_OBJS 40 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 60c7997..ac0aa7f 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -131,6 +131,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) /* Mark the initial VMID generation invalid */ kvm->arch.vmid_gen = 0; + kvm->arch.max_vcpus = CONFIG_KVM_ARM_MAX_VCPUS; return ret; out_free_stage2_pgd: @@ -213,6 +214,11 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, unsigned int id) int err; struct kvm_vcpu *vcpu; + if (id >= kvm->arch.max_vcpus) { + err = -EINVAL; + goto out; + } + vcpu = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL); if (!vcpu) { err = -ENOMEM; diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 286bb61..f9e130d 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -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; diff --git a/virt/kvm/arm/vgic-v2.c b/virt/kvm/arm/vgic-v2.c index 417ecaa..c92ac33 100644 --- a/virt/kvm/arm/vgic-v2.c +++ b/virt/kvm/arm/vgic-v2.c @@ -159,11 +159,18 @@ static struct vgic_params vgic_v2_params; static bool vgic_v2_init_emul(struct kvm *kvm, int type) { struct vgic_vm_ops *vm_ops = &kvm->arch.vgic.vm_ops; + int nr_vcpus; switch (type) { case KVM_DEV_TYPE_ARM_VGIC_V2: + nr_vcpus = atomic_read(&kvm->online_vcpus); + if (nr_vcpus > 8) { + pr_warn_ratelimited("VGICv2 only supports up to 8 vCPUs\n"); + return false; + } vm_ops->get_lr = vgic_v2_get_lr; vm_ops->set_lr = vgic_v2_set_lr; + kvm->arch.max_vcpus = 8; return true; } diff --git a/virt/kvm/arm/vgic-v3.c b/virt/kvm/arm/vgic-v3.c index 6825c71..fc4d628 100644 --- a/virt/kvm/arm/vgic-v3.c +++ b/virt/kvm/arm/vgic-v3.c @@ -171,11 +171,19 @@ static const struct vgic_ops vgic_v3_ops = { static bool vgic_v3_init_emul_compat(struct kvm *kvm, int type) { struct vgic_vm_ops *vm_ops = &kvm->arch.vgic.vm_ops; + int nr_vcpus; switch (type) { case KVM_DEV_TYPE_ARM_VGIC_V2: + nr_vcpus = atomic_read(&kvm->online_vcpus); + if (nr_vcpus > 8) { + pr_warn_ratelimited("VGICv2 supports only up to 8 vCPUs\n"); + return false; + } + vm_ops->get_lr = vgic_v3_get_lr; vm_ops->set_lr = vgic_v3_set_lr; + kvm->arch.max_vcpus = 8; return true; } return false;