From patchwork Tue Jan 13 14:25:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 43002 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1161420DE8 for ; Tue, 13 Jan 2015 14:28:09 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id a1sf1854143wgh.3 for ; Tue, 13 Jan 2015 06:28:08 -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=di/um48weqzzqngUwlL7qja/u6z96k7YeWNPkQu4AzA=; b=Z+NpxljAERoh3/4VsNAoKL7CBTW6vhkLMkBH4iycpwWb9wHGaVW1MKmtkjySmS1Ixv 042lSZjsVtjk/EdvI+wy+/YfBXyTCQxCWmxNPq9mke7Cp+l3iWgZev7kZ3HfnRTphjcZ mkg3o3S0tKXxq00SXk7qHADyZBry2wNN2YoP/a5vfnr7Bk+QNAlPUE+PKsbM1QyNb0IY Sm1sNx/jDZER3j7Jaq+qUz1EAyBQJ7LH81AtE3GqLEcghdmNTqGjHcFJOJs+AupbtDLS AQ2KxicXTra5b4TC+Cwyhle78bKaT54C9dDsZnAFf+rCmbW46V6R/0rTlb20wJD+uuuw QwGQ== X-Gm-Message-State: ALoCoQmHxVF6klxILF+ISiTEue3lUPUG+Z4dC94LBpHArOn4CH25rmU6dECiw4KtrMgnIRVGQ1iS X-Received: by 10.112.137.136 with SMTP id qi8mr365392lbb.13.1421159288320; Tue, 13 Jan 2015 06:28:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.202.198 with SMTP id kk6ls714126lac.103.gmail; Tue, 13 Jan 2015 06:28:08 -0800 (PST) X-Received: by 10.152.120.97 with SMTP id lb1mr42708666lab.76.1421159288117; Tue, 13 Jan 2015 06:28:08 -0800 (PST) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id xu5si3120061lab.9.2015.01.13.06.28.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:28:08 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id s18so2890373lam.2 for ; Tue, 13 Jan 2015 06:28:08 -0800 (PST) X-Received: by 10.112.180.135 with SMTP id do7mr41923000lbc.23.1421159288019; Tue, 13 Jan 2015 06:28:08 -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 c8csp1398821lbb; Tue, 13 Jan 2015 06:28:07 -0800 (PST) X-Received: by 10.220.127.79 with SMTP id f15mr21280983vcs.22.1421159278069; Tue, 13 Jan 2015 06:27:58 -0800 (PST) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id bd7si1082820vdd.96.2015.01.13.06.27.57 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 13 Jan 2015 06:27:58 -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 1YB2Qi-0001QE-RC; Tue, 13 Jan 2015 14:26:48 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YB2Qg-0001KQ-3G for xen-devel@lists.xenproject.org; Tue, 13 Jan 2015 14:26:46 +0000 Received: from [85.158.143.35] by server-3.bemta-4.messagelabs.com id FB/7D-15461-52B25B45; Tue, 13 Jan 2015 14:26:45 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-2.tower-21.messagelabs.com!1421159204!13114110!1 X-Originating-IP: [209.85.212.173] 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 23184 invoked from network); 13 Jan 2015 14:26:44 -0000 Received: from mail-wi0-f173.google.com (HELO mail-wi0-f173.google.com) (209.85.212.173) by server-2.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 13 Jan 2015 14:26:44 -0000 Received: by mail-wi0-f173.google.com with SMTP id em10so5838321wid.0 for ; Tue, 13 Jan 2015 06:26:44 -0800 (PST) X-Received: by 10.180.19.138 with SMTP id f10mr39321077wie.56.1421159203086; Tue, 13 Jan 2015 06:26:43 -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.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Jan 2015 06:26:41 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 13 Jan 2015 14:25:22 +0000 Message-Id: <1421159133-31526-14-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: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com, Jan Beulich Subject: [Xen-devel] [PATCH v3 13/24] xen/arm: Implement hypercall PHYSDEVOP_{, un}map_pirq 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.215.43 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: The physdev sub-hypercalls PHYSDEVOP_{,map}_pirq allow the toolstack to assign/deassign a physical IRQ to the guest (via the config options "irqs" for xl). The x86 version is using them with PIRQ (IRQ bound to an event channel). As ARM doesn't have a such concept, we could reuse it to bound a physical IRQ to a virtual IRQ. For now, we allow only SPIs to be mapped to the guest. The type MAP_PIRQ_TYPE_GSI is used for this purpose. Signed-off-by: Julien Grall Cc: Jan Beulich --- I'm not sure it's the best solution to reuse hypercalls for a different purpose. If x86 plan to have a such concept (i.e binding a physical IRQ to a virtual IRQ), we could introduce new hypercalls. Any thoughs? TODO: This patch is lacking of support of vIRQ != IRQ. I plan to handle it correctly on the next version. Changes in v3: - Functions to allocate/release/reserved a VIRQ has been moved in a separate patch - Make clear that only MAP_PIRQ_GSI is only supported for now Changes in v2: - Add PHYSDEVOP_unmap_pirq - Rework commit message - Add functions to allocate/release a VIRQ - is_routable_irq has been renamed into is_assignable_irq --- xen/arch/arm/physdev.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index 61b4a18..0cf9bbd 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -8,13 +8,145 @@ #include #include #include +#include +#include +#include +#include #include +#include +static int physdev_map_pirq(domid_t domid, int type, int index, int *pirq_p) +{ + struct domain *d; + int ret; + int irq = index; + int virq; + + d = rcu_lock_domain_by_any_id(domid); + if ( d == NULL ) + return -ESRCH; + + ret = xsm_map_domain_pirq(XSM_TARGET, d); + if ( ret ) + goto free_domain; + + /* For now we only suport GSI */ + if ( type != MAP_PIRQ_TYPE_GSI ) + { + ret = -EINVAL; + dprintk(XENLOG_G_ERR, + "dom%u: wrong map_pirq type 0x%x, only MAP_PIRQ_TYPE_GSI is supported.\n", + d->domain_id, type); + goto free_domain; + } + + if ( !is_assignable_irq(irq) ) + { + ret = -EINVAL; + dprintk(XENLOG_G_ERR, "IRQ%u is not routable to a guest\n", irq); + goto free_domain; + } + + ret = -EPERM; + if ( !irq_access_permitted(current->domain, irq) ) + goto free_domain; + + if ( *pirq_p < 0 ) + { + BUG_ON(irq < 16); /* is_assignable_irq already denies SGIs */ + virq = vgic_allocate_virq(d, (irq >= 32)); + + ret = -ENOSPC; + if ( virq < 0 ) + goto free_domain; + } + else + { + ret = -EBUSY; + virq = *pirq_p; + + if ( !vgic_reserve_virq(d, virq) ) + goto free_domain; + } + + gdprintk(XENLOG_DEBUG, "irq = %u virq = %u\n", irq, virq); + + ret = route_irq_to_guest(d, virq, irq, "routed IRQ"); + + if ( !ret ) + *pirq_p = virq; + else + vgic_free_virq(d, virq); + +free_domain: + rcu_unlock_domain(d); + + return ret; +} + +int physdev_unmap_pirq(domid_t domid, int pirq) +{ + struct domain *d; + int ret; + + d = rcu_lock_domain_by_any_id(domid); + if ( d == NULL ) + return -ESRCH; + + ret = xsm_unmap_domain_pirq(XSM_TARGET, d); + if ( ret ) + goto free_domain; + + ret = release_guest_irq(d, pirq); + if ( ret ) + goto free_domain; + + vgic_free_virq(d, pirq); + +free_domain: + rcu_unlock_domain(d); + + return ret; +} int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { - printk("%s %d cmd=%d: not implemented yet\n", __func__, __LINE__, cmd); - return -ENOSYS; + int ret; + + switch ( cmd ) + { + case PHYSDEVOP_map_pirq: + { + physdev_map_pirq_t map; + + ret = -EFAULT; + if ( copy_from_guest(&map, arg, 1) != 0 ) + break; + + ret = physdev_map_pirq(map.domid, map.type, map.index, &map.pirq); + + if ( __copy_to_guest(arg, &map, 1) ) + ret = -EFAULT; + } + break; + + case PHYSDEVOP_unmap_pirq: + { + physdev_unmap_pirq_t unmap; + + ret = -EFAULT; + if ( copy_from_guest(&unmap, arg, 1) != 0 ) + break; + + ret = physdev_unmap_pirq(unmap.domid, unmap.pirq); + } + + default: + ret = -ENOSYS; + break; + } + + return ret; } /*