xen/arm: Add support for non-PCI passthrough
v9 cover xen/arm: Add support for non-PCI passthrough
Hi all,
This is a resend of the last part of the non-PCI passthrough after another error found by Ian C. during build compilation on Debian Wheezy.
Debian wheezy is using an old version of libfdt which doesn't export correcly fdt_first_property_offset, fdt_get_property_by_offset and fdt_next_property_offset.
Thoses functions are used in order to copy the partial device tree into the guest supports.
Adding compatibility for thoses functions (as we did for fdt_{first,next}_subnode) is not easy because it requires to pull some libfdt internal functions.
After discussion [1], it has been decided to disable support of partial device tree on any OS using libfdt < 1.4.0 (release in september 2014). Realistically only Debian Wheezy is impacted which has been superseed by Jessie recently.
Any user who want to use passthrough on OS which don't have a recent libfdt will have to build a new version of libfdt of append the device tree to the guest kernel.
Sincerely yours,
[1] http://lists.xen.org/archives/html/xen-devel/2015-05/msg01682.html
Julien Grall (6):
tools/libxl: Check if fdt_{first,next}_subnode are present in libfdt tools/(lib)xl: Add partial device tree support for ARM tools/libxl: arm: Use an higher value for the GIC phandle
libxl: Add support for Device Tree passthrough
xl: Add new option dtdev
docs/misc: arm: Add documentation about Device Tree passthrough
docs/man/xl.cfg.pod.5 | 18 ++++ docs/misc/arm/passthrough.txt | 63 +++++++++++++ tools/configure.ac | 18 ++++ tools/libxl/Makefile | 2 +- tools/libxl/libxl.h | 7 ++ tools/libxl/libxl_arm.c | 182 +++++++++++++++++++++++++++++++++++++- tools/libxl/libxl_create.c | 32 +++++++ tools/libxl/libxl_internal.h | 5 ++ tools/libxl/libxl_libfdt_compat.c | 94 ++++++++++++++++++++ tools/libxl/libxl_libfdt_compat.h | 80 +++++++++++++++++ tools/libxl/libxl_types.idl | 11 +++ tools/libxl/xl_cmdimpl.c | 23 ++++- 12 files changed, 529 insertions(+), 6 deletions(-) create mode 100644 docs/misc/arm/passthrough.txt create mode 100644 tools/libxl/libxl_libfdt_compat.c create mode 100644 tools/libxl/libxl_libfdt_compat.h
Signature · 1 line
2.1.4
PATCH v9 1/6 tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
From: Julien Grall <[email protected]>
The functions fdt_{first,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...
The later has been fixed recently in the dtc repo [1]
When the functions are not available, implement our own in order to use them in a following patch.
[1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git
commit a4b093f7366fdb429ca1781144d3985fa50d0fbb
---
tools/configure needs to be regenerate as this patch is modifying tools/configure.ac
Changes in v9:
- Remove spurious change in libxl_internal.h
- Add _hidden on the imported fdt_* functions
- Typo in the commit message
Changes in v8:
- Forgot to add the new header file libxl_libfdt_compat.h on the previous version
Changes in v7:
- Drop Ian's ack as he request some changes due to build issue
- Check if the declaration are present if not add declaration
- Remove changes config.h.in as it will be regenerate before committed
Changes in v6:
- Add Ian's Ack
Changes in v5:
- Add Ian's Signed-off-by for the license part and update the license
- Rename libxl_fdt to libxl_libfdt_compat.c
Changes in v4:
- Patch added
--- tools/configure.ac | 6 +++ tools/libxl/Makefile | 2 +- tools/libxl/libxl_libfdt_compat.c | 94 +++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_libfdt_compat.h | 80 +++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_libfdt_compat.c create mode 100644 tools/libxl/libxl_libfdt_compat.h
tools/configure.ac +6 -0
@@ -355,6 +355,12 @@ AC_SUBST(libiconv) case "$host_cpu" in arm*|aarch64) AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])]) + +# The functions fdt_{first,next}_subnode may not be available because: +# * It has been introduced in 2013 => Doesn't work on Wheezy +# * The prototype exists but the functions are not exposed. Don't ask why... +AC_CHECK_FUNCS([fdt_first_subnode fdt_next_subnode]) +AC_CHECK_DECLS([fdt_first_subnode, fdt_next_subnode],,,[#include <libfdt.h>]) esac # Checks for header files.
tools/libxl/Makefile +1 -1
@@ -59,7 +59,7 @@ endif LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o -LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o +LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o ifeq ($(CONFIG_NetBSD),y) LIBXL_OBJS-y += libxl_netbsd.o
tools/libxl/libxl_libfdt_compat.c new file +94 -0
94 lines not on this page · raw message
tools/libxl/libxl_libfdt_compat.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Hi,
tools/libxl/libxl_libfdt_compat.h line 71
Quoted 12 lines · Julien Grall
tools/libxl/libxl_libfdt_compat.h new file +12
-0+#ifndef LIBXL_LIBFDT_COMPAT_H +#define LIBXL_LIBFDT_COMPAT_H + +#if !HAVE_DECL_FDT_FIRST_SUBNODE +int fdt_first_subnode (const void *fdt,int offset); +#endif + +#if !HAVE_DECL_FDT_NEXT_SUBNODE +int fdt_next_subnode (const void *fdt,int offset); +#endif + +#endif
I've just noticed that I forgot to hide the 2 new functions as suggested by Ian.
I can resend this series or send a follow-up.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 19 lines · Julien Grall
Hi,
tools/libxl/libxl_libfdt_compat.h line 71
Quoted 12 lines · Julien Grall
tools/libxl/libxl_libfdt_compat.h new file +12
-0+#ifndef LIBXL_LIBFDT_COMPAT_H +#define LIBXL_LIBFDT_COMPAT_H + +#if !HAVE_DECL_FDT_FIRST_SUBNODE +int fdt_first_subnode (const void *fdt,int offset); +#endif + +#if !HAVE_DECL_FDT_NEXT_SUBNODE +int fdt_next_subnode (const void *fdt,int offset); +#endif + +#endif I've just noticed that I forgot to hide the 2 new functions as suggested by Ian.
Quoted 1 line
I can resend this series or send a follow-up.
Perhaps just send an update of this one patch?
Quoted 3 lines
Regards,
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 20 lines · Ian Campbell
Quoted 19 lines · Julien Grall
Hi,
tools/libxl/libxl_libfdt_compat.h line 71
Quoted 12 lines · Julien Grall
tools/libxl/libxl_libfdt_compat.h new file +12
-0+#ifndef LIBXL_LIBFDT_COMPAT_H +#define LIBXL_LIBFDT_COMPAT_H + +#if !HAVE_DECL_FDT_FIRST_SUBNODE +int fdt_first_subnode (const void *fdt,int offset); +#endif + +#if !HAVE_DECL_FDT_NEXT_SUBNODE +int fdt_next_subnode (const void *fdt,int offset); +#endif + +#endif I've just noticed that I forgot to hide the 2 new functions as suggested by Ian.
Quoted 3 lines
Quoted 1 line
I can resend this series or send a follow-up.
Perhaps just send an update of this one patch?
I will resend this patch by tomorrow.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
In reply to Julien GrallHi,
new version of this patch below.
I have also pushed a new branch will all the series:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch passthrough-v9.1
Regards,
Quoted 1 line
From
d4f0ea84f26649b61bc6afb550348069b71d41c5Mon Sep 17 00:00:00 2001
From: Julien Grall <[email protected]>
Date: Tue, 17 Mar 2015 17:58:14 +0000
Subject: [PATCH] tools/libxl: Check if fdt_{first,next}_subnode are present in
libfdt
The functions fdt_{first,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...
The later has been fixed recently in the dtc repo [1]
When the functions are not available, implement our own in order to use them in a following patch.
Note that the _hidden attribute is placed in both the prototype and the declaration because some version of libfdt expose the prototype but not the declaration.
[1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git
commit a4b093f7366fdb429ca1781144d3985fa50d0fbb
---
tools/configure needs to be regenerate as this patch is modifying tools/configure.ac
Changes in v9.1:
- Mark hidden the new function.
Changes in v9:
- Remove spurious change in libxl_internal.h
- Add _hidden on the imported fdt_* functions
- Typo in the commit message
Changes in v8:
- Forgot to add the new header file libxl_libfdt_compat.h on the previous version
Changes in v7:
- Drop Ian's ack as he request some changes due to build issue
- Check if the declaration are present if not add declaration
- Remove changes config.h.in as it will be regenerate before committed
Changes in v6:
- Add Ian's Ack
Changes in v5:
- Add Ian's Signed-off-by for the license part and update the license
- Rename libxl_fdt to libxl_libfdt_compat.c
Changes in v4:
- Patch added
--- tools/configure.ac | 6 +++ tools/libxl/Makefile | 2 +- tools/libxl/libxl_libfdt_compat.c | 94 +++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_libfdt_compat.h | 82 ++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_libfdt_compat.c create mode 100644 tools/libxl/libxl_libfdt_compat.h
tools/configure.ac +6 -0
@@ -355,6 +355,12 @@ AC_SUBST(libiconv) case "$host_cpu" in arm*|aarch64) AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])]) + +# The functions fdt_{first,next}_subnode may not be available because: +# * It has been introduced in 2013 => Doesn't work on Wheezy +# * The prototype exists but the functions are not exposed. Don't ask why... +AC_CHECK_FUNCS([fdt_first_subnode fdt_next_subnode]) +AC_CHECK_DECLS([fdt_first_subnode, fdt_next_subnode],,,[#include <libfdt.h>]) esac # Checks for header files.
tools/libxl/Makefile +1 -1
@@ -59,7 +59,7 @@ endif LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o -LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o +LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o ifeq ($(CONFIG_NetBSD),y) LIBXL_OBJS-y += libxl_netbsd.o
tools/libxl/libxl_libfdt_compat.c new file +94 -0
94 lines not on this page · raw message
tools/libxl/libxl_libfdt_compat.h new file +82 -0
82 lines not on this page · raw message
Signature · 7 lines
2.1.4 -- Julien Grall
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 7 lines · Julien Grall
[...]
Fromd4f0ea84f26649b61bc6afb550348069b71d41c5Mon Sep 17 00:00:00 2001
From: Julien Grall <[email protected]>
Date: Tue, 17 Mar 2015 17:58:14 +0000
Subject: [PATCH]tools/libxl: Check if fdt_{first,next}_subnode are present in
libfdt
Quoted 6 lines
The functions fdt_{first,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...The later has been fixed recently in the dtc repo [1]
But the bug is still present in 1.4.0, right? Hence this patch is not obsolete even given the next one.
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 13 lines · Ian Campbell
Quoted 12 lines · Julien Grall
[...]
Fromd4f0ea84f26649b61bc6afb550348069b71d41c5Mon Sep 17 00:00:00 2001
From: Julien Grall <[email protected]>
Date: Tue, 17 Mar 2015 17:58:14 +0000
Subject: [PATCH]tools/libxl: Check if fdt_{first,next}_subnode are present in
libfdtThe functions fdt_{first,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...
Quoted 4 lines
Quoted 1 line
The later has been fixed recently in the dtc repo [1]
But the bug is still present in 1.4.0, right? Hence this patch is not obsolete even given the next one.
It is present until 1.4.1. The changes will be on the next released of libfdt.
The commit may be useful for people building there own libfdt.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v9 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt
Quoted 16 lines · Julien Grall
Quoted 15 lines · Ian Campbell
Quoted 13 lines · Julien Grall
[...]
Fromd4f0ea84f26649b61bc6afb550348069b71d41c5Mon Sep 17 00:00:00 2001
From: Julien Grall <[email protected]>
Date: Tue, 17 Mar 2015 17:58:14 +0000
Subject: [PATCH]tools/libxl: Check if fdt_{first,next}_subnode are present in
libfdtThe functions fdt_{first,next}_subnode may not be available because:
* It has been introduced in 2013 => Doesn't work on Wheezy
* The prototype exists but the functions are not exposed. Don't ask why...The later has been fixed recently in the dtc repo [1]
Quoted 7 lines
Quoted 2 lines
But the bug is still present in 1.4.0, right? Hence this patch is not obsolete even given the next one.
It is present until 1.4.1. The changes will be on the next released of libfdt.
The commit may be useful for people building there own libfdt.
Right, I shall carry on with committing both then, thanks.
PATCH v9 2/6 tools/(lib)xl: Add partial device tree support for ARM
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Allow the user to pass additional nodes to the guest device tree. For this purpose, everything in the node /passthrough from the partial device tree will be copied into the guest device tree.
The node /aliases will be also copied to allow the user to define aliases which can be used by the guest kernel.
A simple partial device tree will look like:
/dts-v1/;
/ {
#address-cells = <2>;
#size-cells = <2>;
passthrough {
compatible = "simple-bus";
ranges;
#address-cells = <2>;
#size-cells = <2>;
/* List of your nodes */
}
};Note that:
* The interrupt-parent property will be added by the toolstack in the root node
* The properties compatible, ranges, #address-cells and #size-cells in /passthrough are mandatory.
The helpers provided by the libfdt don't perform all the necessary security check on a given device tree. Therefore, only trusted device tree should be used.
Note: The partial device tree code requires the presence of libfdt functions which have been only correctly exported in libfdt 1.4.0 and higher. All the major distributions but Debian Wheezy are using v1.4.0 or higher. It has been decided to disable partial device tree support on OSes where libfdt doesn't meet the requirement.
---
An example of the partial device tree, as long as how to passthrough a non-pci device will be added to the tree in a follow-up patch.
A new LIBXL_HAVE_* will be added in the patch which add support for non-PCI passthrough as both are tight.
Changes in v9:
- Drop ack from the 2 Ian's due to build changes
- Only enable partial device tree when libfdt > 1.4.0 is present
Changes in v7:
- Drop declaration of fdt_{first,next}_subnode. They are correctly define in libxl_libfdt_compat.h if necessary
Changes in v6:
- Fix grammar in the commit message
- Spelling mistake the IDL
- Add Ian J. and Ian C.'s ack
Changes in v5:
- Add a warning in the IDL
- Remove the requirement to use only the version 17 of the FDT format.
Changes in v4:
- Mark the option as unsafe
- The _fdt_* helpers has been moved in a separate patch/file. Only the prototype is declared
- The partial DT is considered valid. Remove some security check which make the code cleaner
- Typoes
Changes in v3:
- Patch added
--- docs/man/xl.cfg.pod.5 | 10 +++ tools/configure.ac | 12 +++ tools/libxl/libxl_arm.c | 173 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_types.idl | 4 + tools/libxl/xl_cmdimpl.c | 1 + 5 files changed, 200 insertions(+)
docs/man/xl.cfg.pod.5 +10 -0
@@ -460,6 +460,16 @@ not emulated. Specify that this domain is a driver domain. This enables certain features needed in order to run a driver domain. +=item B<device_tree=PATH> + +Specify a partial device tree (compiled via the Device Tree Compiler). +Everything under the node "/passthrough" will be copied into the guest +device tree. For convenience, the node "/aliases" is also copied to allow +the user to defined aliases which can be used by the guest kernel. + +Given the complexity of verifying the validity of a device tree, this +option should only be used with trusted device tree. + =back =head2 Devices
tools/configure.ac +12 -0
@@ -356,6 +356,18 @@ case "$host_cpu" in arm*|aarch64) AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])]) +# Check for libfdt >= 1.4.0. If present enable passthrough +# Note that libfdt doesn't provide versionning. So we need to rely on +# function present in new version. +# Use fdt_first_property_offset which has been correctly exported since v1.4.0 +AC_CHECK_FUNC(fdt_first_property_offset, [partial_dt="y"], [partial_dt="n"]) + +AS_IF([test "x$partial_dt" = "xy" ], + [AC_DEFINE([ENABLE_PARTIAL_DEVICE_TREE], [1], + [Enabling support partial device tree in libxl])], + [AC_MSG_WARN([Disabling support for partial device tree in libxl. + Please install libfdt library - version 1.4.0 or higher])]) + # The functions fdt_{first,next}_subnode may not be available because: # * It has been introduced in 2013 => Doesn't work on Wheezy # * The prototype exists but the functions are not exposed. Don't ask why...
tools/libxl/libxl_arm.c +173 -0
204 lines not on this page · raw message
tools/libxl/libxl_types.idl +4 -0
@@ -413,6 +413,10 @@ libxl_domain_build_info = Struct("domain_build_info",[ ("kernel", string), ("cmdline", string), ("ramdisk", string), + # Given the complexity of verifying the validity of a device tree, + # libxl doesn't do any security check on it. It's the responsibility + # of the caller to provide only trusted device tree. + ("device_tree", string), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string), ("bios", libxl_bios_type),
tools/libxl/xl_cmdimpl.c +1 -0
@@ -1379,6 +1379,7 @@ static void parse_config_data(const char *config_source,xlu_cfg_replace_string (config,"kernel" , &b_info->kernel,0 );xlu_cfg_replace_string (config,"ramdisk" , &b_info->ramdisk,0 ); +xlu_cfg_replace_string (config,"device_tree" , &b_info->device_tree,0 ); b_info->cmdline =parse_cmdline (config);xlu_cfg_get_defbool (config,"driver_domain" , &c_info->driver_domain,0 );
Signature · 1 line
2.1.4
PATCH v9 3/6 tools/libxl: arm: Use an higher value for the GIC phandle
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The partial device tree may contains phandle. The Device Tree Compiler tends to allocate the phandle from 1.
Reserve the ID 65000 for the GIC phandle. I think we can safely assume that the partial device tree will never contain a such ID.
---
To allocate dynamically the phandle, we would need to fill in post-hoc (like we do with e.g the initramfs location) the #interrupt-parent in "/". That would also require some refactoring in the code to pass the phandle every time.
Defer this solution to a follow-up in order as having 65000 would be very unlikely.
Changes in v6:
- Add a note in the doc about the reserved phandle
Changes in v5:
- Add Ian C.'s Ack.
Changes in v3:
- Patch added
--- docs/man/xl.cfg.pod.5 | 3 +++ tools/libxl/libxl_arm.c | 9 +++++---- tools/libxl/libxl_types.idl | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5 +3 -0
@@ -470,6 +470,9 @@ the user to defined aliases which can be used by the guest kernel. Given the complexity of verifying the validity of a device tree, this option should only be used with trusted device tree. +Note that the partial device tree should avoid to use the phandle 65000 +which is reserved by the toolstack. + =back =head2 Devices
tools/libxl/libxl_arm.c +5 -4
@@ -81,10 +81,11 @@ static struct arch_info { {"xen-3.0-aarch64", "arm,armv8-timer", "arm,armv8" }, }; -enum { -PHANDLE_NONE =0 , -PHANDLE_GIC , -}; +/* +* The device tree compiler (DTC) is allocating the phandle from 1 to +* onwards. Reserve a high value for the GIC phandle. +*/ +#define PHANDLE_GIC (65000)typedef uint32_t be32 ;typedef be32 gic_interrupt [3 ];
tools/libxl/libxl_types.idl +2 -0
@@ -416,6 +416,8 @@ libxl_domain_build_info = Struct("domain_build_info",[ # Given the complexity of verifying the validity of a device tree, # libxl doesn't do any security check on it. It's the responsibility # of the caller to provide only trusted device tree. + # Note that the partial device tree should avoid to use the phandle + # 65000 which is reserved by the toolstack. ("device_tree", string), ("u", KeyedUnion(None, libxl_domain_type, "type", [("hvm", Struct(None, [("firmware", string),
Signature · 1 line
2.1.4
PATCH v9 4/6 libxl: Add support for Device Tree passthrough
In reply to Julien GrallFrom: Julien Grall <[email protected]>
On ARM, every non-PCI device are described in the device tree. Each of them can be found via a path.
This patch introduces a very basic support, only the IOMMU will be set up correctly. The user will have to:
- Describe the device in the partial device tree
- Map manually MMIO/IRQ
This is a first approach, that will allow to have a basic Device Tree passthrough support in Xen. This could be improved later.
Furthermore add LIBXL_HAVE_DEVICETREE_PASSTHROUGH to indicate we support Device Tree passthrough and partial device tree (introduced by a previous patch).
---
Changes in v6:
- Add Ian C. and Ian J.'s ack
Changes in v5:
- Replace some "non-PCI" to "Device Tree"
Changes in v4:
- Add LIBXL_HAVE_DEVICTREE_PASSTHROUGH to indicate we support non-PCI passthrough. This is also used in order to indicate partial device tree is supported
- Remove libxl_dtdev.c as it contains only a 2 lines functions and call directly xc_* from libxl_create.c
- Introduce domcreate_attach_dtdev
Changes in v3:
- Dynamic allocation has been dropped
- Rework the commit message in accordance with the previous item
Changes in v2:
- Get DT infos earlier
- Allocate/map IRQ in libxl__arch_domain_create rather than in libxl__device_dt_add
- Use VIRQ rather than the PIRQ to construct the interrupts properties of the device tree
- Correct cpumask in make_dtdev_node. We allow the interrupt to be used on the 8 CPUs
- Fix LOGE when we map the MMIO region in the guest in libxl__device_dt_add. The domain and the IRQ were inverted
- Calculate the number of SPIs to configure the VGIC
- xc_physdev_dtdev_* helpers has been renamed to xc_dtdev_*
- Rename libxl_device_dt to libxl_device_dtdev
--- tools/libxl/libxl.h | 7 +++++++ tools/libxl/libxl_create.c | 32 ++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 5 +++++ tools/libxl/libxl_types.idl | 5 +++++ 4 files changed, 49 insertions(+)
tools/libxl/libxl.h +7 -0
@@ -192,6 +192,13 @@* is not present, instead of ERROR_INVAL. */ #define LIBXL_HAVE_ERROR_DOMAIN_NOTFOUND 1 + +/* +* libxl_domain_build_info has device_tree and libxl_device_dtdev +* exists. This mean Device Tree passthrough is supported for ARM +*/ +#define LIBXL_HAVE_DEVICETREE_PASSTHROUGH 1 +/* * libxl ABI compatibility *
tools/libxl/libxl_create.c +32 -0
@@ -764,6 +764,8 @@ static void domcreate_attach_vtpms(libxl__egc *egc, libxl__multidev *multidev, int ret);static void domcreate_attach_pci (libxl__egc *egc,libxl__multidev *aodevs,int ret); +static void domcreate_attach_dtdev (libxl__egc *egc, +libxl__domain_create_state *dcs);static void domcreate_console_available (libxl__egc *egc,libxl__domain_create_state *dcs);
@@ -1457,6 +1459,36 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev, } } +domcreate_attach_dtdev (egc, dcs); +return ; + +error_out: +assert (ret); +domcreate_complete (egc, dcs, ret); +} + +static void domcreate_attach_dtdev (libxl__egc *egc, +libxl__domain_create_state *dcs) +{ +STATE_AO_GC (dcs->ao); +int i; +int ret; +int domid = dcs->guest_domid; + +/* convenience aliases */ +libxl_domain_config *const d_config = dcs->guest_config; + +for (i =0 ; i < d_config->num_dtdevs; i++) { +const libxl_device_dtdev *dtdev = &d_config->dtdevs[i]; + +LOG (DEBUG ,"Assign device \"%s\" to dom%u" , dtdev->path, domid); + ret =xc_assign_dt_device (CTX ->xch, domid, dtdev->path); +if (ret <0 ) { +LOG (ERROR ,"xc_assign_dtdevice failed: %d\n" , ret); + goto error_out; + } + } +domcreate_console_available (egc, dcs);domcreate_complete (egc, dcs,0 );
tools/libxl/libxl_internal.h +5 -0
@@ -1208,6 +1208,11 @@ _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num); _hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); +/* from libxl_dtdev */ + +_hidden int libxl__device_dt_add(libxl__gc *gc, uint32_t domid, +const libxl_device_dtdev *dtdev); +/*----- xswait: wait for a xenstore node to be suitable -----*/ typedef struct libxl__xswait_state libxl__xswait_state ;
tools/libxl/libxl_types.idl +5 -0
@@ -541,6 +541,10 @@ libxl_device_pci = Struct("device_pci", [ ("seize", bool), ]) +libxl_device_dtdev = Struct("device_dtdev", [ + ("path", string), + ]) + libxl_device_vtpm = Struct("device_vtpm", [ ("backend_domid", libxl_domid), ("backend_domname", string),
@@ -567,6 +571,7 @@ libxl_domain_config = Struct("domain_config", [ ("disks", Array(libxl_device_disk, "num_disks")), ("nics", Array(libxl_device_nic, "num_nics")), ("pcidevs", Array(libxl_device_pci, "num_pcidevs")), + ("dtdevs", Array(libxl_device_dtdev, "num_dtdevs")), ("vfbs", Array(libxl_device_vfb, "num_vfbs")), ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")),
Signature · 1 line
2.1.4
PATCH v9 5/6 xl: Add new option dtdev
In reply to Julien GrallFrom: Julien Grall <[email protected]>
The option "dtdev" will be used to passthrough a device described in the device tree to a guest.
---
Changes in v5:
- Drop "non-PCI" in the commit message
- Add Ian's ack
Changes in v4:
- Typoes in the documentation
- Wrap the line in xl_cmdimpl.c
Changes in v2:
- libxl_device_dt has been rename to libxl_device_dtdev
- use xrealloc instead of realloc
--- docs/man/xl.cfg.pod.5 | 5 +++++ tools/libxl/xl_cmdimpl.c | 22 +++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
docs/man/xl.cfg.pod.5 +5 -0
@@ -789,6 +789,11 @@ More information about Xen gfx_passthru feature is available on the XenVGAPassthrough L<http://wiki.xen.org/wiki/XenVGAPassthrough> wiki page. +=item B<dtdev=[ "DTDEV_PATH", "DTDEV_PATH", ... ]> + +Specifies the host device tree nodes to passthrough to this guest. Each +DTDEV_PATH is the absolute path in the device tree. + =item B<ioports=[ "IOPORT_RANGE", "IOPORT_RANGE", ... ]> Allow guest to access specific legacy I/O ports. Each B<IOPORT_RANGE>
tools/libxl/xl_cmdimpl.c +21 -1
@@ -1169,7 +1169,7 @@ static void parse_config_data(const char *config_source,long l, vcpus =0 ;XLU_Config *config;XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; -XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian; +XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs;int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian;int pci_power_mgmt =0 ;int pci_msitranslate =0 ;
@@ -1941,6 +1941,26 @@ skip_vfb:libxl_defbool_set (&b_info->u.pv.e820_host, true); } +if (!xlu_cfg_get_list (config,"dtdev" , &dtdevs,0 ,0 )) { + d_config->num_dtdevs =0 ; + d_config->dtdevs =NULL ; +for (i =0 ; (buf =xlu_cfg_get_listitem (dtdevs, i)) !=NULL ; i++) { +libxl_device_dtdev *dtdev; + + d_config->dtdevs =xrealloc (d_config->dtdevs, +sizeof (libxl_device_dtdev) * (i +1 )); + dtdev = d_config->dtdevs + d_config->num_dtdevs; +libxl_device_dtdev_init (dtdev); + + dtdev->path =strdup (buf); +if (dtdev->path ==NULL ) { +fprintf (stderr,"unable to duplicate string for dtdevs\n" ); +exit (-1 ); + } + d_config->num_dtdevs++; + } + } +switch (xlu_cfg_get_list (config,"cpuid" , &cpuids,0 ,1 )) {case 0 : {
Signature · 1 line
2.1.4
PATCH v9 6/6 docs/misc: arm: Add documentation about Device Tree passthrough
In reply to Julien GrallFrom: Julien Grall <[email protected]>
Note that the example is done on Midway whose SMMU driver is not supported on Xen upstream.
Currently, I don't have other platform where I can test Device Tree passthrough.
---
Changes in v6:
- Typo in the doc
- Add a link to http://www.devicetree.org/Device_Tree_Usage
- Add Ian's ack
Changes in v5:
- Drop references to "non-PCI" in favor of "Device Tree"
- Typoes and update the docs
Changes in v4:
- Patch added
--- docs/misc/arm/passthrough.txt | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 docs/misc/arm/passthrough.txt
docs/misc/arm/passthrough.txt new file +63 -0
@@ -0,0 +1,63 @@ +Passthrough a device described in the Device Tree to a guest +============================================================ + +The example will use the secondary network card for the midway server. + +1) Mark the device to let Xen know the device will be used for passthrough. +This is done in the device tree node describing the device by adding the +property "xen,passthrough". The command to do it in U-Boot is: + + fdt set /soc/ethernet@fff51000 xen,passthrough + +2) Create a partial device tree describing the device. The IRQ are mapped +1:1 to the guest (i.e VIRQ == IRQ). For MMIO, you will have to find a hole +in the guest memory layout (see xen/include/public/arch-arm.h, note that +the layout is not stable and can change between versions of Xen). + +/dts-v1/; + +/ { + /* #*cells are here to keep DTC happy */ + #address-cells = <2>; + #size-cells = <2>; + + aliases { + net = &mac0; + }; + + passthrough { + compatible = "simple-bus"; + ranges; + #address-cells = <2>; + #size-cells = <2>; + mac0: ethernet@10000000 { + compatible = "calxeda,hb-xgmac"; + reg = <0 0x10000000 0 0x1000>; + interrupts = <0 80 4 0 81 4 0 82 4>; + }; + }; +}; + +Note: + * The interrupt-parent property will be added by the toolstack in the + root node; + * The following properties are mandatory with the /passthrough node: + - compatible: It should always contain "simple-bus" + - ranges + - #address-cells + - #size-cells + * See http://www.devicetree.org/Device_Tree_Usage for more + information about device tree. + +3) Compile the partial guest device with dtc (Device Tree Compiler). +For our purpose, the compiled file will be called guest-midway.dtb and +placed in /root in DOM0. + +3) Add the following options in the guest configuration file: + +device_tree = "/root/guest-midway.dtb" +dtdev = [ "/soc/ethernet@fff51000" ] +irqs = [ 112, 113, 114 ] +iomem = [ "0xfff51,1@0x10000" ] + +
Signature · 1 line
2.1.4
Ian Campbell
AppliedQuoted 4 lines · Julien Grall
Hi all,
This is a resend of the last part of the non-PCI passthrough after another error found by Ian C. during build compilation on Debian Wheezy.
Applied, with the replacement patch #1. Thanks.
Ian.