From patchwork Thu Jun 19 12:44:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 4383041 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F6389F390 for ; Thu, 19 Jun 2014 12:45:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0CF3A20340 for ; Thu, 19 Jun 2014 12:44:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3E3B1202EB for ; Thu, 19 Jun 2014 12:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752668AbaFSMot (ORCPT ); Thu, 19 Jun 2014 08:44:49 -0400 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:62807 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbaFSMon (ORCPT ); Thu, 19 Jun 2014 08:44:43 -0400 Received: from e106785-lin.cambridge.arm.com (e106785-lin.cambridge.arm.com [10.1.209.161]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s5JCidws005003; Thu, 19 Jun 2014 13:44:40 +0100 (BST) From: Andre Przywara To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: will.deacon@arm.com, marc.zyngier@arm.com Subject: [PATCH 4/4] kvmtool: add command line parameter to instantiate a vGICv3 Date: Thu, 19 Jun 2014 13:44:39 +0100 Message-Id: <1403181879-29908-5-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403181879-29908-1-git-send-email-andre.przywara@arm.com> References: <1403181879-29908-1-git-send-email-andre.przywara@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 Add the command line parameter "--gicv3" to request GICv3 emulation in the kernel. Connect that to the already existing GICv3 code. Signed-off-by: Andre Przywara --- tools/kvm/arm/aarch64/arm-cpu.c | 5 ++++- .../kvm/arm/aarch64/include/kvm/kvm-config-arch.h | 4 +++- tools/kvm/arm/gic.c | 17 +++++++++++++++++ tools/kvm/arm/include/arm-common/kvm-config-arch.h | 1 + tools/kvm/arm/kvm.c | 4 +++- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/kvm/arm/aarch64/arm-cpu.c b/tools/kvm/arm/aarch64/arm-cpu.c index 35771e0..e3514ea 100644 --- a/tools/kvm/arm/aarch64/arm-cpu.c +++ b/tools/kvm/arm/aarch64/arm-cpu.c @@ -12,7 +12,10 @@ static void generate_fdt_nodes(void *fdt, struct kvm *kvm, u32 gic_phandle) { int timer_interrupts[4] = {13, 14, 11, 10}; - gic__generate_fdt_nodes(fdt, gic_phandle, KVM_DEV_TYPE_ARM_VGIC_V2); + gic__generate_fdt_nodes(fdt, gic_phandle, + kvm->cfg.arch.gicv3 ? + KVM_DEV_TYPE_ARM_VGIC_V3 : + KVM_DEV_TYPE_ARM_VGIC_V2); timer__generate_fdt_nodes(fdt, kvm, timer_interrupts); } diff --git a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h index 89860ae..780a6d1 100644 --- a/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h +++ b/tools/kvm/arm/aarch64/include/kvm/kvm-config-arch.h @@ -3,7 +3,9 @@ #define ARM_OPT_ARCH_RUN(cfg) \ OPT_BOOLEAN('\0', "aarch32", &(cfg)->aarch32_guest, \ - "Run AArch32 guest"), + "Run AArch32 guest"), \ + OPT_BOOLEAN('\0', "gicv3", &(cfg)->gicv3, \ + "use a GICv3 interrupt controller in the guest"), #include "arm-common/kvm-config-arch.h" diff --git a/tools/kvm/arm/gic.c b/tools/kvm/arm/gic.c index 5141868..15dc99d 100644 --- a/tools/kvm/arm/gic.c +++ b/tools/kvm/arm/gic.c @@ -76,6 +76,7 @@ static int gic__create_device(struct kvm *kvm, u32 type) case KVM_DEV_TYPE_ARM_VGIC_V3: dist_attr.attr = KVM_VGIC_V3_ADDR_TYPE_DIST; redist_addr = dist_addr - nr_redists * ARM_GIC_REDIST_SIZE; + pr_info("creating GICv3 KVM device"); break; default: return -ENODEV; @@ -119,6 +120,17 @@ static int gic__create_irqchip(struct kvm *kvm) return err; } +static int gicv3__init_irqchip(struct kvm *kvm) +{ + if (kvm->nrcpus > 255) { + pr_warning("%d CPUS greater than maximum of %d -- truncating\n", + kvm->nrcpus, 255); + kvm->nrcpus = 255; + } + + return gic__create_device(kvm, KVM_DEV_TYPE_ARM_VGIC_V3); +} + static int gicv2__init_irqchip(struct kvm *kvm) { int err; @@ -150,6 +162,9 @@ int gic__init_irqchip(struct kvm *kvm, u32 type) switch (type) { case KVM_DEV_TYPE_ARM_VGIC_V2: return gicv2__init_irqchip(kvm); + case KVM_DEV_TYPE_ARM_VGIC_V3: + nr_redists = kvm->cfg.nrcpus; + return gicv3__init_irqchip(kvm); } return -ENODEV; } @@ -196,6 +211,8 @@ void gic__generate_fdt_nodes(void *fdt, u32 phandle, u32 type) compatible = "arm,gic-v3"; reg_prop[2] = ARM_GIC_DIST_BASE - nr_redists * ARM_GIC_REDIST_SIZE; reg_prop[3] = ARM_GIC_REDIST_SIZE * nr_redists; + pr_info("creating FDT for a GICv3 with %d redistributors", + nr_redists); break; default: return; diff --git a/tools/kvm/arm/include/arm-common/kvm-config-arch.h b/tools/kvm/arm/include/arm-common/kvm-config-arch.h index f3baf39..088b012 100644 --- a/tools/kvm/arm/include/arm-common/kvm-config-arch.h +++ b/tools/kvm/arm/include/arm-common/kvm-config-arch.h @@ -7,6 +7,7 @@ struct kvm_config_arch { const char *dump_dtb_filename; unsigned int force_cntfrq; bool aarch32_guest; + bool gicv3; }; #define OPT_ARCH_RUN(pfx, cfg) \ diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c index faf4702..3858170 100644 --- a/tools/kvm/arm/kvm.c +++ b/tools/kvm/arm/kvm.c @@ -80,6 +80,8 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) MADV_MERGEABLE); /* Initialise the virtual GIC. */ - if (gic__init_irqchip(kvm, KVM_DEV_TYPE_ARM_VGIC_V2)) + if (gic__init_irqchip(kvm, kvm->cfg.arch.gicv3 ? + KVM_DEV_TYPE_ARM_VGIC_V3 : + KVM_DEV_TYPE_ARM_VGIC_V2)) die("Failed to initialise virtual GIC"); }