From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: Re: [PATCH v6 01/11] arch, arm: domain build: let dom0 access I/O memory of mapped devices Date: Tue, 29 Apr 2014 14:44:01 +0100 Message-ID: <535FACA1.5030702@linaro.org> 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> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <535F9D01.6000907@linaro.org> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Arianna Avanzini , Ian.Campbell@eu.citrix.com 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 List-Id: xen-devel@lists.xenproject.org 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; -- Julien Grall