From: Andre Przywara Subject: [PATCH v4 04/10] AArch{32, 64}: dynamically configure the number of GIC interrupts Date: Fri, 26 Jun 2015 14:16:12 +0100 Message-ID: <1435324578-21832-5-git-send-email-andre.przywara@arm.com> References: <1435324578-21832-1-git-send-email-andre.przywara@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7EC345714A for ; Fri, 26 Jun 2015 09:05:36 -0400 (EDT) Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JShmhF8sEjdh for ; Fri, 26 Jun 2015 09:05:35 -0400 (EDT) Received: from foss.arm.com (foss.arm.com [217.140.101.70]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 22033570EF for ; Fri, 26 Jun 2015 09:05:35 -0400 (EDT) In-Reply-To: <1435324578-21832-1-git-send-email-andre.przywara@arm.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu To: will.deacon@arm.com, marc.zyngier@arm.com Cc: penberg@kernel.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org List-Id: kvmarm@lists.cs.columbia.edu From: Marc Zyngier In order to reduce the memory usage of large guests (as well as improve performance), tell KVM about the number of interrupts we require. To avoid synchronization with the various device creation, use a late_init callback to compute the GIC configuration. [Andre: rename to gic__init_gic() to ease future expansion] Signed-off-by: Marc Zyngier Signed-off-by: Andre Przywara --- arm/gic.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/arm/gic.c b/arm/gic.c index 1ff3663..8560c9b 100644 --- a/arm/gic.c +++ b/arm/gic.c @@ -1,10 +1,12 @@ #include "kvm/fdt.h" +#include "kvm/irq.h" #include "kvm/kvm.h" #include "kvm/virtio.h" #include "arm-common/gic.h" #include +#include #include static int gic_fd = -1; @@ -96,6 +98,29 @@ int gic__create(struct kvm *kvm) return err; } +static int gic__init_gic(struct kvm *kvm) +{ + int lines = irq__get_nr_allocated_lines(); + u32 nr_irqs = ALIGN(lines, 32) + GIC_SPI_IRQ_BASE; + struct kvm_device_attr nr_irqs_attr = { + .group = KVM_DEV_ARM_VGIC_GRP_NR_IRQS, + .addr = (u64)(unsigned long)&nr_irqs, + }; + + /* + * If we didn't use the KVM_CREATE_DEVICE method, KVM will + * give us some default number of interrupts. + */ + if (gic_fd < 0) + return 0; + + if (!ioctl(gic_fd, KVM_HAS_DEVICE_ATTR, &nr_irqs_attr)) + return ioctl(gic_fd, KVM_SET_DEVICE_ATTR, &nr_irqs_attr); + + return 0; +} +late_init(gic__init_gic) + void gic__generate_fdt_nodes(void *fdt, u32 phandle) { u64 reg_prop[] = { -- 2.3.5