From patchwork Thu Mar 19 19:29:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46104 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 969D821515 for ; Thu, 19 Mar 2015 19:32:40 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf14227298lab.1 for ; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=nsto23W2uPiO5YvjX1bBKyupu0b6jzMYWvN3AwsJ7Iw=; b=BALTjKk2bIKp+rUu/tu0t3nmi2h+O+PPtj3VE90BYOKgsTI0RUPHmhYnKFI06gsvMH 3q8DZuqr3hMPE/1qzJn1JzDXQPRu2mJf9qKrjhDEgabxq1HvdVFauOW7u3L2RGgT7Rxz eYmVGEjS6AtK4pr++W8V1DaSMiUnw+owRYmCBhrDijg0wjhtUEEqMzrtNu/P39RQidOS kqpq/FXfFvmjWlIN6fkz/X8C7A9LcX4Au7ukC4R+Y5HkInFfYpOwZOqRNs9r7mRKvv94 RDEQdxQJKTxhzz6J6P2x7puFOVHegRkGRc0cqVR+eTBirWm+MYxhReJjYzvNHosx9+Y8 kOKw== X-Gm-Message-State: ALoCoQm+myZAvpv0bJzLjvOls0YoH5L59srrvJxxfweMp1raiqA8jqocCHEVSOxKAn45j0I0rgE7 X-Received: by 10.194.236.196 with SMTP id uw4mr9277679wjc.5.1426793559550; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.5 with SMTP id lg5ls281133lab.106.gmail; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) X-Received: by 10.112.73.65 with SMTP id j1mr69323336lbv.87.1426793559261; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id w6si1627782lae.131.2015.03.19.12.32.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:32:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbblx11 with SMTP id lx11so38291652lbb.3 for ; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) X-Received: by 10.112.130.195 with SMTP id og3mr68945509lbb.112.1426793559037; Thu, 19 Mar 2015 12:32:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp597688lbj; Thu, 19 Mar 2015 12:32:38 -0700 (PDT) X-Received: by 10.52.64.204 with SMTP id q12mr37152114vds.40.1426793550605; Thu, 19 Mar 2015 12:32:30 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id ys17si2021152vdb.11.2015.03.19.12.32.29 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:30 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9p-0004eX-4p; Thu, 19 Mar 2015 19:31:05 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYg9o-0004br-1Q for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:04 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id 24/21-24808-7F32B055; Thu, 19 Mar 2015 19:31:03 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-11.tower-31.messagelabs.com!1426793462!13832741!1 X-Originating-IP: [74.125.82.178] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26138 invoked from network); 19 Mar 2015 19:31:02 -0000 Received: from mail-we0-f178.google.com (HELO mail-we0-f178.google.com) (74.125.82.178) by server-11.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:02 -0000 Received: by wetk59 with SMTP id k59so65623308wet.3 for ; Thu, 19 Mar 2015 12:31:02 -0700 (PDT) X-Received: by 10.194.157.68 with SMTP id wk4mr36033393wjb.130.1426793462309; Thu, 19 Mar 2015 12:31:02 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:01 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:42 +0000 Message-Id: <1426793399-6283-17-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> Cc: Wei Liu , ian.campbell@citrix.com, tim@xen.org, Julien Grall , Ian Jackson , stefano.stabellini@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v4 16/33] xen/arm: Let the toolstack configure the number of SPIs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: Each domain may have a different number of IRQs depending on the devices assigned to it. Rather re-using the number of IRQs used by the hardwared GIC, let the toolstack specify the number of SPIs when the domain is created. This will avoid to waste memory. To calculate the number of SPIs, we take advantage of the fact that the libxl interface can only expose 1:1 mapping and look for the largest SPI in the list. Signed-off-by: Julien Grall Cc: Ian Jackson Cc: Jan Beulich Cc: Wei Liu --- Changes in v4: - Check the number of SPIs supported by the virtual GIC against the number supported by the hardware GIC. - Use uint32_t rather than int in the toolstack code. - Initialize spi after the check in the toolstack code - Typoes Changes in v3: - Fix typoes - A separate has been created to extend the DOMCTL create domain Changes in v2: - Patch added --- tools/libxc/xc_domain.c | 1 + tools/libxl/libxl_arm.c | 21 +++++++++++++++++++++ xen/arch/arm/domain.c | 2 +- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 11 ++++++----- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/setup.h | 1 + xen/include/asm-arm/vgic.h | 2 +- xen/include/public/arch-arm.h | 2 ++ 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index 448e958..579d266 100644 --- a/tools/libxc/xc_domain.c +++ b/tools/libxc/xc_domain.c @@ -67,6 +67,7 @@ int xc_domain_create(xc_interface *xch, /* No arch-specific configuration for now */ #elif defined (__arm__) || defined(__aarch64__) config.gic_version = XEN_DOMCTL_CONFIG_GIC_DEFAULT; + config.nr_spis = 0; #else errno = ENOSYS; return -1; diff --git a/tools/libxl/libxl_arm.c b/tools/libxl/libxl_arm.c index dc0919a..2407c2e 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -39,6 +39,27 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc, libxl_domain_config *d_config, xc_domain_configuration_t *xc_config) { + uint32_t nr_spis = 0; + unsigned int i; + + for (i = 0; i < d_config->b_info.num_irqs; i++) { + uint32_t irq = d_config->b_info.irqs[i]; + uint32_t spi; + + if (irq < 32) + continue; + + spi = irq - 32; + + if (nr_spis <= spi) + nr_spis = spi + 1; + } + + LOG(DEBUG, "Configure the domain"); + + xc_config->nr_spis = nr_spis; + LOG(DEBUG, " - Allocate %u SPIs", nr_spis); + xc_config->gic_version = XEN_DOMCTL_CONFIG_GIC_DEFAULT; return 0; diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index ce9f349..7c5bf9f 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -562,7 +562,7 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, if ( (rc = gicv_setup(d)) != 0 ) goto fail; - if ( (rc = domain_vgic_init(d)) != 0 ) + if ( (rc = domain_vgic_init(d, config->nr_spis)) != 0 ) goto fail; if ( (rc = domain_vtimer_init(d)) != 0 ) diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index defe39e..c935266 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -830,6 +830,7 @@ void __init start_xen(unsigned long boot_phys_offset, /* Create initial domain 0. */ /* The vGIC for DOM0 is exactly emulated the hardware GIC */ config.gic_version = XEN_DOMCTL_CONFIG_GIC_DEFAULT; + config.nr_spis = gic_number_lines() - 32; dom0 = domain_create(0, 0, 0, &config); if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) == NULL) ) diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index c07822f..74751e0 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -68,16 +68,17 @@ static void vgic_init_pending_irq(struct pending_irq *p, unsigned int virq) p->irq = virq; } -int domain_vgic_init(struct domain *d) +int domain_vgic_init(struct domain *d, unsigned int nr_spis) { int i; d->arch.vgic.ctlr = 0; - if ( is_hardware_domain(d) ) - d->arch.vgic.nr_spis = gic_number_lines() - 32; - else - d->arch.vgic.nr_spis = 0; /* We don't need SPIs for the guest */ + /* Limit the number of SPIs supported base on the hardware */ + if ( nr_spis > (gic_number_lines() - NR_LOCAL_IRQS) ) + return -EINVAL; + + d->arch.vgic.nr_spis = nr_spis; switch ( gic_hw_version() ) { diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 9e0419e..6dacfef 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -125,6 +125,8 @@ struct arch_domain unsigned int evtchn_irq; } __cacheline_aligned; +#define domain_is_configured(d) ((d)->arch.is_configured) + struct arch_vcpu { struct { diff --git a/xen/include/asm-arm/setup.h b/xen/include/asm-arm/setup.h index ba5a67d..254cc17 100644 --- a/xen/include/asm-arm/setup.h +++ b/xen/include/asm-arm/setup.h @@ -54,6 +54,7 @@ void copy_from_paddr(void *dst, paddr_t paddr, unsigned long len); void arch_get_xen_caps(xen_capabilities_info_t *info); int construct_dom0(struct domain *d); +int configure_dom0(struct domain *d); void discard_initial_modules(void); diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index aba0d80..647f2fe 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -177,7 +177,7 @@ enum gic_sgi_mode; #define vgic_num_irqs(d) ((d)->arch.vgic.nr_spis + 32) -extern int domain_vgic_init(struct domain *d); +extern int domain_vgic_init(struct domain *d, unsigned int nr_spis); extern void domain_vgic_free(struct domain *d); extern int vcpu_vgic_init(struct vcpu *v); extern struct vcpu *vgic_get_target_vcpu(struct vcpu *v, unsigned int irq); diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index ed7e98f..c029e0f 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -315,6 +315,8 @@ typedef uint64_t xen_callback_t; struct xen_arch_domainconfig { /* IN/OUT */ uint8_t gic_version; + /* IN */ + uint32_t nr_spis; }; #endif