From patchwork Tue Apr 29 13:44:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 29355 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f69.google.com (mail-qa0-f69.google.com [209.85.216.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 38C97202FE for ; Tue, 29 Apr 2014 13:46:40 +0000 (UTC) Received: by mail-qa0-f69.google.com with SMTP id s7sf584837qap.0 for ; Tue, 29 Apr 2014 06:46: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:message-id:date:from:user-agent :mime-version:to:references:in-reply-to:cc:subject:precedence :list-id:list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-type:content-transfer-encoding; bh=ReIfLhD++dq6QzTxyQQdl/nREUk7vumlzn3sBZKSU+M=; b=asC0p9LLw4hpxFwp7rvmZ66VSXTH2d+elymGYAwcSrlT9FbPflL8FclcFekli0TEyw EhJcbKfoyUUacHCTkolX94WHazfLoi4jLrPT6KV9pTgey0pzim+LhoTMDJv4YlCRR8NM cWzce1Hfppgr5lFhDLnGlz3gt0mI86QbQkycUVZy2k5Y2kZ/iaBkZn21OoGFmIXaGCZ9 TSxi47UWFG6RrM0CLfhGEMTpeHSLeIk0mucYXi2eteZqe9wn/y304cugR1QjNQvATZyI 5kObmI6BcfMpNg3VU1g7jKrVEHcuGsW33sKzKM9N6t1wG8U/w0qG8Y55dyJSQaPzLGK3 DjNA== X-Gm-Message-State: ALoCoQmW4tnqxnRYIJ6d5jmbxD2Jg2IQkY1YVqLdj6eOYYWmTtctC8s5VN1voU6Nq9EotN/lPLI+ X-Received: by 10.236.209.97 with SMTP id r61mr13205263yho.33.1398779199917; Tue, 29 Apr 2014 06:46:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.209 with SMTP id x75ls95643qgx.46.gmail; Tue, 29 Apr 2014 06:46:39 -0700 (PDT) X-Received: by 10.58.171.229 with SMTP id ax5mr13485182vec.24.1398779199754; Tue, 29 Apr 2014 06:46:39 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id sc12si4520467veb.133.2014.04.29.06.46.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 06:46:39 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id lf12so292919vcb.27 for ; Tue, 29 Apr 2014 06:46:39 -0700 (PDT) X-Received: by 10.221.26.10 with SMTP id rk10mr29713243vcb.0.1398779199635; Tue, 29 Apr 2014 06:46: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.220.221.72 with SMTP id ib8csp198852vcb; Tue, 29 Apr 2014 06:46:38 -0700 (PDT) X-Received: by 10.58.66.195 with SMTP id h3mr333180vet.57.1398779198538; Tue, 29 Apr 2014 06:46:38 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id oo7si4518076vcb.130.2014.04.29.06.46.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 29 Apr 2014 06:46:38 -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 1Wf8KN-0002uN-Cw; Tue, 29 Apr 2014 13:44:07 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Wf8KL-0002uI-Fy for xen-devel@lists.xen.org; Tue, 29 Apr 2014 13:44:05 +0000 Received: from [85.158.139.211:22896] by server-9.bemta-5.messagelabs.com id CF/06-04350-4ACAF535; Tue, 29 Apr 2014 13:44:04 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-8.tower-206.messagelabs.com!1398779043!1279071!1 X-Originating-IP: [74.125.83.44] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6196 invoked from network); 29 Apr 2014 13:44:04 -0000 Received: from mail-ee0-f44.google.com (HELO mail-ee0-f44.google.com) (74.125.83.44) by server-8.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 29 Apr 2014 13:44:04 -0000 Received: by mail-ee0-f44.google.com with SMTP id c41so324859eek.31 for ; Tue, 29 Apr 2014 06:44:03 -0700 (PDT) X-Received: by 10.14.9.195 with SMTP id 43mr2587525eet.89.1398779043784; Tue, 29 Apr 2014 06:44:03 -0700 (PDT) Received: from [10.80.2.139] ([185.25.64.249]) by mx.google.com with ESMTPSA id l42sm59353389eew.19.2014.04.29.06.44.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 29 Apr 2014 06:44:03 -0700 (PDT) Message-ID: <535FACA1.5030702@linaro.org> Date: Tue, 29 Apr 2014 14:44:01 +0100 From: Julien Grall User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20131104 Icedove/17.0.10 MIME-Version: 1.0 To: Arianna Avanzini , Ian.Campbell@eu.citrix.com References: <1398087904-16594-1-git-send-email-avanzini.arianna@gmail.com> <1398087904-16594-2-git-send-email-avanzini.arianna@gmail.com> <535F9D01.6000907@linaro.org> In-Reply-To: <535F9D01.6000907@linaro.org> Cc: paolo.valente@unimore.it, keir@xen.org, stefano.stabellini@eu.citrix.com, tim@xen.org, dario.faggioli@citrix.com, Ian.Jackson@eu.citrix.com, xen-devel@lists.xen.org, julien.grall@citrix.com, etrudeau@broadcom.com, JBeulich@suse.com, viktor.kleinik@globallogic.com Subject: Re: [Xen-devel] [PATCH v6 01/11] arch, arm: domain build: let dom0 access I/O memory of mapped devices 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: , 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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: On 04/29/2014 01:37 PM, Julien Grall wrote: > Hi Arianna, > > On 04/21/2014 02:44 PM, Arianna Avanzini wrote: >> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c >> index 187e071..1802b6e 100644 >> --- a/xen/arch/arm/domain_build.c >> +++ b/xen/arch/arm/domain_build.c >> @@ -11,6 +11,7 @@ >> #include >> #include >> #include >> +#include >> #include >> #include >> #include >> @@ -740,6 +741,16 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) >> DPRINT("addr %u = 0x%"PRIx64" - 0x%"PRIx64"\n", >> i, addr, addr + size - 1); >> >> + res = iomem_permit_access(d, paddr_to_pfn(addr & PAGE_MASK), >> + paddr_to_pfn(PAGE_ALIGN(addr + size - 1))); >> + if ( res ) >> + { >> + printk(XENLOG_ERR "Unable to permit to dom%d access to" >> + " 0x%"PRIx64" - 0x%"PRIx64"\n", >> + d->domain_id, >> + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); >> + return res; >> + } >> res = map_mmio_regions(d, addr & PAGE_MASK, >> PAGE_ALIGN(addr + size) - 1, >> addr & PAGE_MASK); >> > > I though a bit more about this patch. If the device is disabled (i.e > status="disabled"), Xen doesn't call map_device. > Futhermore, in your use case (e.g with iomem=) you might want to map > memory that is not describe to the device tree. > > I would either: > 1) give a full access to the I/O range > 2) give a full access to the I/O range except on the RAM region > > IHMO, the second solution might be better but I don't know if it's easy > to implement it. I quickly wrote a follow-up of the series (see below). We can either merge in this patch or I can carry it with the device passthrough patch series. diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 2f6ffe9..3498549 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -717,9 +717,14 @@ static int make_timer_node(const struct domain *d, void *fdt, return res; } -/* Map the device in the domain */ -static int map_device(struct domain *d, struct kernel_info *kinfo, - struct dt_device_node *dev) +/* For a specific device node : + * - Give access permission to the guest + * When the device is available: + * - Assign the device to the guest if it's protected by an IOMMU + * - Map the IRQs and iomem regions to DOM0 + */ +static int handle_device(struct domain *d, struct kernel_info *kinfo, + struct dt_device_node *dev, bool_t map) { unsigned int nirq; unsigned int naddr; @@ -734,7 +739,7 @@ static int map_device(struct domain *d, struct kernel_info *kinfo, DPRINT("%s nirq = %d naddr = %u\n", dt_node_full_name(dev), nirq, naddr); - if ( dt_device_is_protected(dev) ) + if ( dt_device_is_protected(dev) && map ) { DPRINT("%s setup iommu\n", dt_node_full_name(dev)); res = iommu_assign_dt_device(d, dev); @@ -778,12 +783,15 @@ static int map_device(struct domain *d, struct kernel_info *kinfo, } DPRINT("irq %u = %u type = 0x%x\n", i, irq.irq, irq.type); - res = route_dt_irq_to_guest(d, &irq, dt_node_name(dev)); - if ( res ) + if ( map ) { - printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n", - irq.irq, d->domain_id); - return res; + res = route_dt_irq_to_guest(d, &irq, dt_node_name(dev)); + if ( res ) + { + printk(XENLOG_ERR "Unable to route IRQ %u to domain %u\n", + irq.irq, d->domain_id); + return res; + } } } @@ -811,17 +819,21 @@ static int map_device(struct domain *d, struct kernel_info *kinfo, addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1); return res; } - res = map_mmio_regions(d, - paddr_to_pfn(addr & PAGE_MASK), - paddr_to_pfn_aligned(addr + size) - 1, - paddr_to_pfn(addr & PAGE_MASK)); - if ( res ) + + if ( map ) { - printk(XENLOG_ERR "Unable to map 0x%"PRIx64 - " - 0x%"PRIx64" in domain %d\n", - addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1, - d->domain_id); - return res; + res = map_mmio_regions(d, + paddr_to_pfn(addr & PAGE_MASK), + paddr_to_pfn_aligned(addr + size) - 1, + paddr_to_pfn(addr & PAGE_MASK)); + if ( res ) + { + printk(XENLOG_ERR "Unable to map 0x%"PRIx64 + " - 0x%"PRIx64" in domain %d\n", + addr & PAGE_MASK, PAGE_ALIGN(addr + size) - 1, + d->domain_id); + return res; + } } } @@ -902,10 +914,9 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, * property. Therefore these device doesn't need to be mapped. This * solution can be use later for pass through. */ - if ( !dt_device_type_is_equal(node, "memory") && - dt_device_is_available(node) ) + if ( !dt_device_type_is_equal(node, "memory") ) { - res = map_device(d, kinfo, node); + res = handle_device(d, kinfo, node, dt_device_is_available(node)); if ( res ) return res;