xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@linaro.org>
To: xen-devel@lists.xenproject.org
Cc: stefano.stabellini@citrix.com,
	Julien Grall <julien.grall@linaro.org>,
	tim@xen.org, ian.campbell@citrix.com
Subject: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Date: Tue, 11 Mar 2014 15:49:58 +0000	[thread overview]
Message-ID: <1394552999-14171-13-git-send-email-julien.grall@linaro.org> (raw)
In-Reply-To: <1394552999-14171-1-git-send-email-julien.grall@linaro.org>

DOM0 is using the swiotlb to bounce DMA. With the IOMMU support in Xen,
protected devices should not use it.

Only Xen is abled 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 <julien.grall@linaro.org>

---
    This patch *MUST NOT* be applied until we agreed on a device binding
    the device tree folks. DOM0 can run safely with swiotlb on protected
    devices while LVM is not used for guest disk.

    Changes in v2:
        - Patch added
---
 xen/arch/arm/domain_build.c |   51 ++++++++++++++++++++++++++++++++++++++-----
 xen/arch/arm/kernel.h       |    3 +++
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 2438aa0..565784a 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -324,19 +324,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;
     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");
 
@@ -384,6 +387,39 @@ 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 */
+        cells = xmalloc_array(__be32, kinfo->num_dev_protected *
+                              dt_size_to_cells(sizeof(dt_phandle)));
+        if ( !cells )
+            return -FDT_ERR_XEN(ENOMEM);
+
+        _cells = cells;
+
+        DPRINT("  List of protected devices\n");
+        list_for_each_entry( dev, &hd->dt_devices, next_assigned )
+        {
+            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, 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;
@@ -670,7 +706,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;
@@ -695,6 +732,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 */
@@ -843,7 +881,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;
@@ -874,7 +912,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;
 
@@ -1027,6 +1065,7 @@ int construct_dom0(struct domain *d)
 
     d->max_pages = ~0U;
 
+    kinfo.num_dev_protected = 0;
     kinfo.unassigned_mem = dom0_mem;
 
     allocate_memory(d, &kinfo);
diff --git a/xen/arch/arm/kernel.h b/xen/arch/arm/kernel.h
index b48c2c9..3af5c50 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;
+
     paddr_t dtb_paddr;
     paddr_t entry;
 
-- 
1.7.10.4

  parent reply	other threads:[~2014-03-11 15:50 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-11 15:49 [PATCH v3 00/13] IOMMU support for ARM Julien Grall
2014-03-11 15:49 ` [PATCH v3 01/13] xen/common: grant-table: only call IOMMU if paging mode translate is disabled Julien Grall
2014-03-11 15:49 ` [PATCH v3 02/13] xen/passthrough: amd: Remove domain_id from hvm_iommu Julien Grall
2014-03-18 16:19   ` Ian Campbell
2014-03-18 16:32     ` Jan Beulich
2014-03-11 15:49 ` [PATCH v3 03/13] xen/dts: Add dt_property_read_bool Julien Grall
2014-03-11 15:49 ` [PATCH v3 04/13] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle Julien Grall
2014-03-18 16:20   ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM Julien Grall
2014-03-18 16:22   ` Ian Campbell
2014-03-18 17:28     ` Julien Grall
2014-03-18 17:50       ` Ian Campbell
2014-03-18 18:19         ` Julien Grall
2014-03-19 10:01           ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code Julien Grall
2014-03-11 16:50   ` Jan Beulich
2014-03-11 17:09     ` Julien Grall
2014-03-12  7:15       ` Jan Beulich
2014-03-18 16:24   ` Ian Campbell
2014-03-18 17:36     ` Julien Grall
2014-03-18 17:50       ` Ian Campbell
2014-03-18 18:21         ` Julien Grall
2014-03-19 10:02           ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 07/13] xen/passthrough: iommu: Introduce arch specific code Julien Grall
2014-03-11 16:15   ` Julien Grall
2014-03-11 16:53   ` Jan Beulich
2014-03-18 16:27   ` Ian Campbell
2014-03-18 19:40     ` Julien Grall
2014-03-11 15:49 ` [PATCH v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment Julien Grall
2014-03-11 16:55   ` Jan Beulich
2014-03-18 16:33   ` Ian Campbell
2014-03-18 19:46     ` Julien Grall
2014-03-19 10:12       ` Ian Campbell
2014-03-19 10:42         ` Julien Grall
2014-03-19 10:54           ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 09/13] xen/passthrough: Introduce IOMMU ARM architecture Julien Grall
2014-03-18 16:40   ` Ian Campbell
2014-03-18 19:58     ` Julien Grall
2014-03-19 10:29       ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 10/13] MAINTAINERS: Add drivers/passthrough/arm Julien Grall
2014-03-11 15:49 ` [PATCH v3 11/13] xen/arm: Don't give IOMMU devices to dom0 when iommu is disabled Julien Grall
2014-03-18 16:41   ` Ian Campbell
2014-03-11 15:49 ` Julien Grall [this message]
2014-03-18 16:48   ` [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node Ian Campbell
2014-03-18 20:09     ` Julien Grall
2014-03-19 10:33       ` Ian Campbell
2014-04-03 21:51         ` Julien Grall
2014-04-04  9:40           ` Ian Campbell
2014-04-04 10:25             ` Julien Grall
2014-04-04 10:28               ` Ian Campbell
2014-04-04 10:39                 ` Julien Grall
2014-04-04 10:48                   ` Ian Campbell
2014-04-04 11:01                     ` Julien Grall
2014-04-04 11:13                       ` Ian Campbell
2014-04-04 11:23                         ` Julien Grall
2014-04-04 12:45                           ` Ian Campbell
2014-04-04 13:10                             ` Julien Grall
2014-04-04 13:18                               ` Ian Campbell
2014-03-11 15:49 ` [PATCH v3 13/13] drivers/passthrough: arm: Add support for SMMU drivers Julien Grall
2014-03-18 16:54   ` Ian Campbell
2014-03-18 20:25     ` Julien Grall
2014-03-19 10:35       ` Ian Campbell
2014-03-19 10:44         ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394552999-14171-13-git-send-email-julien.grall@linaro.org \
    --to=julien.grall@linaro.org \
    --cc=ian.campbell@citrix.com \
    --cc=stefano.stabellini@citrix.com \
    --cc=tim@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).