Re: [Xen-devel] [PATCH v4 06/33] xen/arm: Introduce xen, passthrough property

2015-03-31 Thread Ian Campbell
On Thu, 2015-03-19 at 19:29 +, Julien Grall wrote:
 When a device is marked for passthrough (via the new property
 xen,passthrough), dom0 must not access to the device (i.e not
 loading a driver), but should be able to manage the MMIO/interrupt
 of the passthrough device.
 
 The latter part will allow the toolstack to map MMIO/IRQ when a device
 is pass through to a guest.
 
 The property xen,passthrough will be translated as 'status=disabled'
 in the device tree to avoid DOM0 using the device. We assume that DOM0 is
 able to cope with this property (already the case for Linux, and
 required by ePAPR).
 
 Rework the function map_device (renamed into handle_device) to:
 
 * For a given device node:
 - Give permission to manage IRQ/MMIO for this device
 - Retrieve the IRQ configuration (i.e edge/level) from the device
 tree
 * When the device is not marked for guest passthrough:
 - Assign the device to the guest if it's protected by an IOMMU
 - Map the IRQs and MMIOs regions to the guest
 
 Signed-off-by: Julien Grall julien.gr...@linaro.org
 Acked-by: Stefano Stabellini stefano.stabell...@eu.citrix.com

Acked-by: Ian Campbell ian.campb...@citrix.com



___
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 06/33] xen/arm: Introduce xen, passthrough property

2015-03-19 Thread Julien Grall
When a device is marked for passthrough (via the new property
xen,passthrough), dom0 must not access to the device (i.e not
loading a driver), but should be able to manage the MMIO/interrupt
of the passthrough device.

The latter part will allow the toolstack to map MMIO/IRQ when a device
is pass through to a guest.

The property xen,passthrough will be translated as 'status=disabled'
in the device tree to avoid DOM0 using the device. We assume that DOM0 is
able to cope with this property (already the case for Linux, and
required by ePAPR).

Rework the function map_device (renamed into handle_device) to:

* For a given device node:
- Give permission to manage IRQ/MMIO for this device
- Retrieve the IRQ configuration (i.e edge/level) from the device
tree
* When the device is not marked for guest passthrough:
- Assign the device to the guest if it's protected by an IOMMU
- Map the IRQs and MMIOs regions to the guest

Signed-off-by: Julien Grall julien.gr...@linaro.org
Acked-by: Stefano Stabellini stefano.stabell...@eu.citrix.com

---
Changes in v4:
- Add Stefano's ack
- Rebase on the latest staging (no function changes)
- Rework the device passthrough documentation to be weaker
- Coding style and typoes

Changes in v3:
- This patch was formely xen/arm: Follow-up to allow DOM0
manage IRQ and MMIO. It has been split in 2 parts [1].
- Update commit title and improve message
- Remove spurious change

[1] https://patches.linaro.org/34669/
---
 docs/misc/arm/device-tree/passthrough.txt |  9 +++
 xen/arch/arm/device.c |  2 +-
 xen/arch/arm/domain_build.c   | 97 ---
 xen/common/device_tree.c  |  6 ++
 xen/include/xen/device_tree.h | 11 
 5 files changed, 103 insertions(+), 22 deletions(-)
 create mode 100644 docs/misc/arm/device-tree/passthrough.txt

diff --git a/docs/misc/arm/device-tree/passthrough.txt 
b/docs/misc/arm/device-tree/passthrough.txt
new file mode 100644
index 000..6715646
--- /dev/null
+++ b/docs/misc/arm/device-tree/passthrough.txt
@@ -0,0 +1,9 @@
+Device passthrough
+===
+
+Any device with the property xen,passthrough set will not be exposed to
+DOM0 and therefore no driver will be loaded.
+
+It is highly recommended to set this property on devices which are passed
+through since many devices will not cope with being accessed by dom0 and
+then handed over to another domain.
diff --git a/xen/arch/arm/device.c b/xen/arch/arm/device.c
index 675784c..0b53f6a 100644
--- a/xen/arch/arm/device.c
+++ b/xen/arch/arm/device.c
@@ -30,7 +30,7 @@ int __init device_init(struct dt_device_node *dev, enum 
device_class class,
 
 ASSERT(dev != NULL);
 
-if ( !dt_device_is_available(dev) )
+if ( !dt_device_is_available(dev) || dt_device_for_passthrough(dev) )
 return  -ENODEV;
 
 for ( desc = _sdevice; desc != _edevice; desc++ )
diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 31b32df..2eb31ad 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -402,7 +402,7 @@ static int write_properties(struct domain *d, struct 
kernel_info *kinfo,
 const struct dt_device_node *node)
 {
 const char *bootargs = NULL;
-const struct dt_property *prop;
+const struct dt_property *prop, *status = NULL;
 int res = 0;
 int had_dom0_bootargs = 0;
 
@@ -457,6 +457,17 @@ static int write_properties(struct domain *d, struct 
kernel_info *kinfo,
 }
 }
 
+/* Don't expose the property xen,passthrough to the guest */
+if ( dt_property_name_is_equal(prop, xen,passthrough) )
+continue;
+
+/* Remember and skip the status property as Xen may modify it later */
+if ( dt_property_name_is_equal(prop, status) )
+{
+status = prop;
+continue;
+}
+
 res = fdt_property(kinfo-fdt, prop-name, prop_data, prop_len);
 
 xfree(new_data);
@@ -465,6 +476,19 @@ static int write_properties(struct domain *d, struct 
kernel_info *kinfo,
 return res;
 }
 
+/*
+ * Override the property status to disable the device when it's
+ * marked for passthrough.
+ */
+if ( dt_device_for_passthrough(node) )
+res = fdt_property_string(kinfo-fdt, status, disabled);
+else if ( status )
+res = fdt_property(kinfo-fdt, status, status-value,
+   status-length);
+
+if ( res )
+return res;
+
 if ( dt_node_path_is_equal(node, /chosen) )
 {
 const struct bootmodule *mod = kinfo-initrd_bootmodule;
@@ -903,8 +927,15 @@ 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 dt_device_node *dev)
+/*
+ * For a given device node:
+ *  - Give