From patchwork Tue Apr 22 13:14:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 28811 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A5B5F203AC for ; Tue, 22 Apr 2014 13:16:41 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id md12sf24092640pbc.0 for ; Tue, 22 Apr 2014 06:16:40 -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:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=3RBwHpUfA6nCqhfiq8sPiHMPGsoGJ0kENckwMzejIpk=; b=jyTdmnNiGvbCynX7UUpSnzdVybIeWToXbSqPdje0HWz0a2kOshEnNqwO3MKs7szAw2 r/IMVfPjBC7OT9/E6iQo7aKtb3wmAujuiW9KeA+nMBG1lJkwy4gWXYEigwAXFkCD2bu2 8/XHh/uKjPFYHWnCwYljwrqWQl6D677RdVkjtRmht5a49qFIMglXftODCnPX8jKo5bfm /y/kwNoVDFOTz0rTu0pQktUVt5xWwGG6iy13XPlU/WKFh/TjGpXdKr2z+w3ch646OL0H kEUWDndpws9LDW6ipcmf/1sco5nB8X+ZDkwVTEfbG3LXgN/oavbnm+C0MTssMRRtqwvC XLeQ== X-Gm-Message-State: ALoCoQlnKEdX/AUAnFFTRvz4eTKQ0J2+O0Gfp0p1vNKCAIQZqhf5LUi50mRnJw2P9OqHG37kOsQY X-Received: by 10.67.5.165 with SMTP id cn5mr24818053pad.9.1398172600679; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.145 with SMTP id c17ls99234qgd.60.gmail; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) X-Received: by 10.58.77.238 with SMTP id v14mr1606772vew.27.1398172600459; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id tq2si6872171vdc.201.2014.04.22.06.16.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:16:40 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.178; Received: by mail-ve0-f178.google.com with SMTP id jw12so9308843veb.23 for ; Tue, 22 Apr 2014 06:16:40 -0700 (PDT) X-Received: by 10.52.230.161 with SMTP id sz1mr37346vdc.64.1398172600368; Tue, 22 Apr 2014 06:16:40 -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 ib8csp23884vcb; Tue, 22 Apr 2014 06:16:39 -0700 (PDT) X-Received: by 10.140.33.181 with SMTP id j50mr16432597qgj.81.1398172598653; Tue, 22 Apr 2014 06:16:38 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id t4si14049842qat.173.2014.04.22.06.16.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 22 Apr 2014 06:16:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) 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 1WcaY1-0006bf-Np; Tue, 22 Apr 2014 13:15:41 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WcaXn-0006Jw-My for xen-devel@lists.xenproject.org; Tue, 22 Apr 2014 13:15:29 +0000 Received: from [193.109.254.147:26713] by server-9.bemta-14.messagelabs.com id E1/D9-03644-F6B66535; Tue, 22 Apr 2014 13:15:27 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-15.tower-27.messagelabs.com!1398172526!123817!1 X-Originating-IP: [74.125.83.47] 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 1200 invoked from network); 22 Apr 2014 13:15:26 -0000 Received: from mail-ee0-f47.google.com (HELO mail-ee0-f47.google.com) (74.125.83.47) by server-15.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 22 Apr 2014 13:15:26 -0000 Received: by mail-ee0-f47.google.com with SMTP id b15so4618681eek.20 for ; Tue, 22 Apr 2014 06:15:26 -0700 (PDT) X-Received: by 10.14.220.130 with SMTP id o2mr55567359eep.42.1398172525990; Tue, 22 Apr 2014 06:15:25 -0700 (PDT) Received: from belegaer.uk.xensource.com ([185.25.64.249]) by mx.google.com with ESMTPSA id 45sm112969867eeh.9.2014.04.22.06.15.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Apr 2014 06:15:25 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 22 Apr 2014 14:14:35 +0100 Message-Id: <1398172475-27873-22-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1398172475-27873-1-git-send-email-julien.grall@linaro.org> References: <1398172475-27873-1-git-send-email-julien.grall@linaro.org> Cc: stefano.stabellini@citrix.com, Julien Grall , tim@xen.org, ian.campbell@citrix.com Subject: [Xen-devel] [PATCH v4 21/21] xen/arm: Add the property "protected-devices" in the hypervisor node 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=neutral (google.com: 209.85.128.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: DOM0 is using the swiotlb to bounce DMA. When the device is protected by an IOMMU, we can safely bypass the swiotlb. We can't disable the swiotlb for all devices because some of them may not be protected. Only Xen is able to know if an IOMMU protects the device The new property "protected-devices" is a list of device phandles protected by an IOMMU. Signed-off-by: Julien Grall --- This patch *MUST NOT* be applied until we agreed on a device binding the device tree folks. Changes in v4: - Explained why dt_devlocks is not needed - Renamed _cells into cells_iter - next_assigned was renamed into domain_list - Update commit message to reflect the usage of this property Changes in v2: - Patch added --- xen/arch/arm/domain_build.c | 52 ++++++++++++++++++++++++++++++++++++++----- xen/arch/arm/kernel.h | 3 +++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index b9b2fa0..76801f3 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -320,19 +320,22 @@ static int make_memory_node(const struct domain *d, return res; } -static int make_hypervisor_node(struct domain *d, - void *fdt, const struct dt_device_node *parent) +static int make_hypervisor_node(struct domain *d, struct kernel_info *kinfo, + const struct dt_device_node *parent) { const char compat[] = "xen,xen-"__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)"\0" "xen,xen"; __be32 reg[4]; gic_interrupt_t intr; - __be32 *cells; + __be32 *cells, *cells_iter; int res; int addrcells = dt_n_addr_cells(parent); int sizecells = dt_n_size_cells(parent); paddr_t gnttab_start, gnttab_size; + const struct dt_device_node *dev; + struct hvm_iommu *hd = domain_hvm_iommu(d); + void *fdt = kinfo->fdt; DPRINT("Create hypervisor node\n"); @@ -380,6 +383,40 @@ static int make_hypervisor_node(struct domain *d, if ( res ) return res; + if ( kinfo->num_dev_protected ) + { + /* Don't need to take dtdevs_lock here, because DOM0 building is + * done with only 1 CPU online */ + cells = xmalloc_array(__be32, kinfo->num_dev_protected * + dt_size_to_cells(sizeof(dt_phandle))); + if ( !cells ) + return -FDT_ERR_XEN(ENOMEM); + + cells_iter = cells; + + DPRINT(" List of protected devices\n"); + list_for_each_entry( dev, &hd->dt_devices, domain_list ) + { + DPRINT(" - %s\n", dt_node_full_name(dev)); + if ( !dev->phandle ) + { + printk(XENLOG_ERR "Unable to handle protected device (%s)" + "with no phandle", dt_node_full_name(dev)); + xfree(cells); + return -FDT_ERR_XEN(EINVAL); + } + dt_set_cell(&cells_iter, dt_size_to_cells(sizeof(dt_phandle)), + dev->phandle); + } + + res = fdt_property(fdt, "protected-devices", cells, + sizeof (dt_phandle) * kinfo->num_dev_protected); + + xfree(cells); + if ( res ) + return res; + } + res = fdt_end_node(fdt); return res; @@ -680,7 +717,8 @@ static int make_timer_node(const struct domain *d, void *fdt, } /* Map the device in the domain */ -static int map_device(struct domain *d, struct dt_device_node *dev) +static int map_device(struct domain *d, struct kernel_info *kinfo, + struct dt_device_node *dev) { unsigned int nirq; unsigned int naddr; @@ -705,6 +743,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) dt_node_full_name(dev)); return res; } + kinfo->num_dev_protected++; } /* Map IRQs */ @@ -854,7 +893,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, if ( !dt_device_type_is_equal(node, "memory") && dt_device_is_available(node) ) { - res = map_device(d, node); + res = map_device(d, kinfo, node); if ( res ) return res; @@ -885,7 +924,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, if ( node == dt_host ) { - res = make_hypervisor_node(d, kinfo->fdt, node); + res = make_hypervisor_node(d, kinfo, node); if ( res ) return res; @@ -1040,6 +1079,7 @@ int construct_dom0(struct domain *d) d->max_pages = ~0U; + kinfo.num_dev_protected = 0; kinfo.unassigned_mem = dom0_mem; rc = kernel_probe(&kinfo); diff --git a/xen/arch/arm/kernel.h b/xen/arch/arm/kernel.h index fd2f61d..7acfe3c 100644 --- a/xen/arch/arm/kernel.h +++ b/xen/arch/arm/kernel.h @@ -18,6 +18,9 @@ struct kernel_info { paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */ struct dt_mem_info mem; + /* Number of devices protected by an IOMMU */ + unsigned int num_dev_protected; + /* kernel entry point */ paddr_t entry;