From patchwork Tue Jan 13 14:25:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 42999 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f198.google.com (mail-we0-f198.google.com [74.125.82.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8E16A20DE8 for ; Tue, 13 Jan 2015 14:28:00 +0000 (UTC) Received: by mail-we0-f198.google.com with SMTP id q59sf1867601wes.1 for ; Tue, 13 Jan 2015 06:27:59 -0800 (PST) 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=Bz2/mAAJ6F/Wmvb9OUD+NQR7Sn5eKQfYZV/xhkrpChY=; b=R78HRRIVhFWtlwKQZWejBOdhdRtJ2GdgFvUEKndXqZOuq30ieTO0MQONfnSLcaCgn+ 4uFdH69kPNBSBp0XjYQvCcFAsLE29vtaMTlEG3kNk/1kv2EXkKcYyZcRvEcJEPcpy9Za lOqqOi6mjRBGAa+JAPe0yhVnwH3No+vfIWuhmdUJRQ9oGjb94xMHZJXmGxYluD6aazih biEUPt3yl+HfyndIKlEcNprKvurPs+taMFQit/T0Zh0ngc9JSumj8vFFJONfcwKRyzAd vLvpM6aHFscJsaMQGn8bhUHxYyiL2kN4iLV+HgFjVrIiXnU5Yk+HyMXILqcLVbpxvnMe J1KA== X-Gm-Message-State: ALoCoQlZblWjDJBqZyyy3cNfBBS8HFSvFvQrIe4P5kjUMvw1LhMO57JuhGr96atkI/8LZ+QlNX3f X-Received: by 10.194.78.42 with SMTP id y10mr380976wjw.4.1421159279822; Tue, 13 Jan 2015 06:27:59 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.234.228 with SMTP id uh4ls822008lac.108.gmail; Tue, 13 Jan 2015 06:27:59 -0800 (PST) X-Received: by 10.153.11.170 with SMTP id ej10mr42502924lad.24.1421159279595; Tue, 13 Jan 2015 06:27:59 -0800 (PST) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id eq7si10787732lbb.18.2015.01.13.06.27.59 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:27:59 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by mail-lb0-f177.google.com with SMTP id b6so2805460lbj.8 for ; Tue, 13 Jan 2015 06:27:59 -0800 (PST) X-Received: by 10.152.234.35 with SMTP id ub3mr42714326lac.70.1421159279453; Tue, 13 Jan 2015 06:27:59 -0800 (PST) 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.9.200 with SMTP id c8csp1398788lbb; Tue, 13 Jan 2015 06:27:58 -0800 (PST) X-Received: by 10.229.219.74 with SMTP id ht10mr666496qcb.25.1421159271411; Tue, 13 Jan 2015 06:27:51 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id v8si27004757qat.30.2015.01.13.06.27.50 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:27:51 -0800 (PST) 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 1YB2Qd-0001HE-5H; Tue, 13 Jan 2015 14:26:43 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YB2Qb-0001Ej-Je for xen-devel@lists.xenproject.org; Tue, 13 Jan 2015 14:26:41 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 1D/24-25276-02B25B45; Tue, 13 Jan 2015 14:26:40 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-12.tower-21.messagelabs.com!1421159200!21155286!1 X-Originating-IP: [209.85.212.175] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.12.5; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14452 invoked from network); 13 Jan 2015 14:26:40 -0000 Received: from mail-wi0-f175.google.com (HELO mail-wi0-f175.google.com) (209.85.212.175) by server-12.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 13 Jan 2015 14:26:40 -0000 Received: by mail-wi0-f175.google.com with SMTP id l15so21663607wiw.2 for ; Tue, 13 Jan 2015 06:26:39 -0800 (PST) X-Received: by 10.194.191.164 with SMTP id gz4mr70781174wjc.70.1421159199904; Tue, 13 Jan 2015 06:26:39 -0800 (PST) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id ni15sm14513482wic.18.2015.01.13.06.26.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 06:26:39 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 Jan 2015 14:25:20 +0000 Message-Id: <1421159133-31526-12-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421159133-31526-1-git-send-email-julien.grall@linaro.org> References: <1421159133-31526-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 v3 11/24] 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.177 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 assume that any IRQ given via the option "irqs=" in xl is mapped 1:1 to the guest. Signed-off-by: Julien Grall Cc: Ian Jackson Cc: Jan Beulich Cc: Wei Liu --- 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 | 19 +++++++++++++++++++ xen/arch/arm/domain.c | 7 ++++++- xen/arch/arm/setup.c | 1 + xen/arch/arm/vgic.c | 10 +++++----- 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, 38 insertions(+), 7 deletions(-) diff --git a/tools/libxc/xc_domain.c b/tools/libxc/xc_domain.c index eebc121..eb066cf 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 cddce6e..53177eb 100644 --- a/tools/libxl/libxl_arm.c +++ b/tools/libxl/libxl_arm.c @@ -39,6 +39,25 @@ 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++) { + int irq = d_config->b_info.irqs[i]; + int spi = irq - 32; + + if (irq < 32) + continue; + + 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 2473b10..6e56665 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -560,10 +560,15 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags, } config->gic_version = gic_version; + /* Sanity check on the number of SPIs */ + rc = -EINVAL; + if ( config->nr_spis > (gic_number_lines() - 32) ) + goto fail; + 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 18227f6..b28a708 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -815,6 +815,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 c915670..fc8a270 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -67,16 +67,16 @@ 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 */ + /* The number of SPIs has to be aligned to 32 see + * GICD_TYPER.ITLinesNumber definition + */ + d->arch.vgic.nr_spis = ROUNDUP(nr_spis, 32); switch ( gic_hw_version() ) { diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index d302fc9..101b4e9 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -121,6 +121,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 1cd7808..e97a5eb 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 4c1b9f9..45d3b1f 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -320,6 +320,8 @@ typedef uint64_t xen_callback_t; struct xen_arch_domainconfig { /* IN/OUT */ uint8_t gic_version; + /* IN */ + uint32_t nr_spis; }; #endif