Skip to contentSkip to conversation

xen/arm: Add support for non-PCI passthrough

PATCH Superseded Julien Grall 2 participants 11 messages May 12, 2015 – May 13, 2015

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v8 cover xen/arm: Add support for non-PCI passthrough

Hello all,

This a resend of the last part of non-PCI passthrough after Andrii spotted that I forgot to include the new header libxl_libfdt_compat.h.

I hope this will be the last build error found.

Regards,

Cc Andrii Anisov <[email protected]>

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                |   6 ++
 tools/libxl/Makefile              |   2 +-
 tools/libxl/libxl.h               |   7 ++
 tools/libxl/libxl_arm.c           | 160 +++++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_create.c        |  32 ++++++++
 tools/libxl/libxl_internal.h      |   6 ++
 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, 496 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
#1 lore raw

PATCH v8 1/6 tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt

From: Julien Grall <[email protected]>

The functions fdt_{fisrt,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 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_internal.h      |  1 +
 tools/libxl/libxl_libfdt_compat.c | 94 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_libfdt_compat.h | 80 +++++++++++++++++++++++++++++++++
 5 files changed, 182 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
index d31c2f3..5b48ab2 100644
@@ -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
index 1b16598..2afb146 100644
@@ -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_internal.h +1 -0
index 8eb38aa..857abd4 100644
@@ -3692,6 +3692,7 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
  */
 void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
                                     const libxl_bitmap *sptr);
+
 #endif
 
 /*
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
#2 lore raw

Re: [PATCH v8 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt

Quoted 3 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions fdt_{fisrt,next}_subnode may not be available because:

"first"

Quoted 9 lines

* 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.

Quoted 6 lines

[1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git

    commit a4b093f7366fdb429ca1781144d3985fa50d0fbb

I'm afraid this failed to build again this time with:

tools/libxl/libxenlight.so: undefined reference to fdt_first_property_offset' tools/libxl/libxenlight.so: undefined reference to fdt_get_property_by_offset' tools/libxl/libxenlight.so: undefined reference to `fdt_next_property_offset'

That's with arm32 == Debian Wheezy and arm64 == Ubuntu Saucy.

The arm32 machine is marilith-n13 here in Cambridge which you should have access to.

arm64 is a chroot on my workstation, I could give you access if that would be helpful, but I expect solving this for arm32 would solve it for arm64 too.

Quoted 1 line
 tools/libxl/libxl_internal.h      |  1 +

Spurious change, please drop.

Quoted 234 lines
 tools/libxl/libxl_libfdt_compat.c | 94 +++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_libfdt_compat.h | 80 +++++++++++++++++++++++++++++++++
 5 files changed, 182 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
index d31c2f3..5b48ab2 100644
@@ -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
index 1b16598..2afb146 100644
@@ -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_internal.h +1 -0
index 8eb38aa..857abd4 100644
@@ -3692,6 +3692,7 @@ static inline void libxl__update_config_vtpm(libxl__gc *gc,
  */
 void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
                                     const libxl_bitmap *sptr);
+
 #endif
 
 /*
tools/libxl/libxl_libfdt_compat.c new file +94 -0
new file mode 100644
index 0000000..a1823b2
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ *
+ * This file is part of libxl, and was originally taken from libfdt.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * Additionally, this particular file is dual licensed.  That is,
+ * alternatively, at your option:
+ *
+ *      Redistribution and use in source and binary forms, with or
+ *      without modification, are permitted provided that the following
+ *      conditions are met:
+ *
+ *      1. Redistributions of source code must retain the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer.
+ *      2. Redistributions in binary form must reproduce the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer in the documentation and/or other materials
+ *         provided with the distribution.
+ *
+ *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *      CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *      INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *      MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *      DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *      CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *      NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *      LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *      CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *      OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *      EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Note that this applies only to this file, and other files with a
+ * similar notice.  Also, note that when the same code is distributed
+ * along with the rest of libxl, you must comply with the terms of the
+ * LGPLv2.1 for the whole of libxl including this file.
+ *
+ * The intent is to permit, in particular, upstream libfdt to
+ * incorporate improvements to this file within upstream libfdt.  At
+ * the time of writing, upstream libfdt is dual licensed: 2-clause BSD
+ * (as above) and GPLv2-or-later.  The 2-clause BSD licence is
+ * compatible with both GPLv2-or-later and LGPLv2.1-only; this permits
+ * copying in both directions, and the optional licence upgrade to a
+ * copyleft licence by libdft upstream or the Xen Project,
+ * respectively.
+ */
+
+#include <libfdt.h>
+
+#include "libxl_libfdt_compat.h"
+
+#ifndef HAVE_FDT_FIRST_SUBNODE
+int fdt_first_subnode(const void *fdt, int offset)
+{
+	int depth = 0;
+
+	offset = fdt_next_node(fdt, offset, &depth);
+	if (offset < 0 || depth != 1)
+		return -FDT_ERR_NOTFOUND;
+
+	return offset;
+}
+#endif
+
+#ifndef HAVE_FDT_NEXT_SUBNODE
+int fdt_next_subnode(const void *fdt, int offset)
+{
+	int depth = 1;
+
+	/*
+	 * With respect to the parent, the depth of the next subnode will be
+	 * the same as the last.
+	 */
+	do {
+		offset = fdt_next_node(fdt, offset, &depth);
+		if (offset < 0 || depth < 1)
+			return -FDT_ERR_NOTFOUND;
+	} while (depth > 1);
+
+	return offset;
+}
+#endif
tools/libxl/libxl_libfdt_compat.h new file +80 -0
new file mode 100644
index 0000000..cf414f5
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2006 David Gibson, IBM Corporation.
+ *
+ * This file is part of libxl, and was originally taken from libfdt.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; version 2.1 only. with the special
+ * exception on linking described in file LICENSE.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * Additionally, this particular file is dual licensed.  That is,
+ * alternatively, at your option:
+ *
+ *      Redistribution and use in source and binary forms, with or
+ *      without modification, are permitted provided that the following
+ *      conditions are met:
+ *
+ *      1. Redistributions of source code must retain the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer.
+ *      2. Redistributions in binary form must reproduce the above
+ *         copyright notice, this list of conditions and the following
+ *         disclaimer in the documentation and/or other materials
+ *         provided with the distribution.
+ *
+ *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ *      CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ *      INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ *      MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *      DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *      CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ *      NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ *      LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *      CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ *      OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ *      EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Note that this applies only to this file, and other files with a
+ * similar notice.  Also, note that when the same code is distributed
+ * along with the rest of libxl, you must comply with the terms of the
+ * LGPLv2.1 for the whole of libxl including this file.
+ *
+ * The intent is to permit, in particular, upstream libfdt to
+ * incorporate improvements to this file within upstream libfdt.  At
+ * the time of writing, upstream libfdt is dual licensed: 2-clause BSD
+ * (as above) and GPLv2-or-later.  The 2-clause BSD licence is
+ * compatible with both GPLv2-or-later and LGPLv2.1-only; this permits
+ * copying in both directions, and the optional licence upgrade to a
+ * copyleft licence by libdft upstream or the Xen Project,
+ * respectively.
+ */
+
+#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
+
+/*
+ * Local variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+
#3 lore raw

Re: [PATCH v8 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt

Hi Ian,

Quoted 23 lines · Ian Campbell
Quoted 3 lines · Julien Grall

From: Julien Grall <[email protected]>

The functions fdt_{fisrt,next}_subnode may not be available because:

"first"

Quoted 9 lines

* 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.

Quoted 6 lines

[1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git

    commit a4b093f7366fdb429ca1781144d3985fa50d0fbb
Quoted 7 lines

I'm afraid this failed to build again this time with:

tools/libxl/libxenlight.so: undefined reference to fdt_first_property_offset' tools/libxl/libxenlight.so: undefined reference to fdt_get_property_by_offset' tools/libxl/libxenlight.so: undefined reference to `fdt_next_property_offset'

That's with arm32 == Debian Wheezy and arm64 == Ubuntu Saucy.

:(. Both the distribution are using an old version of libfdt where the 3 prototypes are defined but the implementation is not exposed in the library (this is because they use a whitelist for building it)

I gave look to see if we can import them from libfdt. It will require to import few others in order to make them work:
- _fdt_check_node_offset
- _fdt_offset_ptr
- _nextprop

I think we can skip the first one because it's only a validity check. FWIW, we declared the the partial device tree should be trusted so valid.

Nonetheless we would add 5 more functions (+ the actual 2) in libxl which represents ~50 lines of codes.

The 3 offending function have been correctly exposed since the version v1.4.0 released in June 2013.

I gave a look to major distribution to see which version is using an old version of libfdt (i.e < 1.4.0:
- Centos: < Centos 6
- Debian: < Jessie => Wheezy using an old version
- Fedora: < Fedora 20
- openSuse: < opensuse 13.1
- ubuntu: < Ubuntu 14.04 => The LTS (14.04) is using a new version
- RedHat: < Redhat 6

AFAICT, all major distributions except debian (for wheezy) are using a libfdt > v1.4. So I would suggest to disable the partial device tree support on distribution using older version.

If the user want to use platform device passthrough it would have either to build a newer version of libfdt or append a device tree to the guest kernel.

Note: IIRC osstest is using wheezy. If so, we won't be able to test platform device passthrough until the distribution version is upgraded.

Although, we don't currently have a platform supporting non-PCI passthrough in osstest.

Regards,

Signature · 1 line
Julien Grall
#4 lore raw

Re: [PATCH v8 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt

Quoted 28 lines · Julien Grall

:(. Both the distribution are using an old version of libfdt where the 3 prototypes are defined but the implementation is not exposed in the library (this is because they use a whitelist for building it)

I gave look to see if we can import them from libfdt. It will require to import few others in order to make them work:
- _fdt_check_node_offset
- _fdt_offset_ptr
- _nextprop

I think we can skip the first one because it's only a validity check. FWIW, we declared the the partial device tree should be trusted so valid.

Nonetheless we would add 5 more functions (+ the actual 2) in libxl which represents ~50 lines of codes.

The 3 offending function have been correctly exposed since the version v1.4.0 released in June 2013.

I gave a look to major distribution to see which version is using an old version of libfdt (i.e < 1.4.0:
- Centos: < Centos 6
- Debian: < Jessie => Wheezy using an old version
- Fedora: < Fedora 20
- openSuse: < opensuse 13.1
- ubuntu: < Ubuntu 14.04 => The LTS (14.04) is using a new version
- RedHat: < Redhat 6

Quoted 3 lines

AFAICT, all major distributions except debian (for wheezy) are using a libfdt > v1.4. So I would suggest to disable the partial device tree support on distribution using older version.

OK, I think we can live with this.

Quoted 9 lines

If the user want to use platform device passthrough it would have either to build a newer version of libfdt or append a device tree to the guest kernel.

Note: IIRC osstest is using wheezy. If so, we won't be able to test platform device passthrough until the distribution version is upgraded.

Although, we don't currently have a platform supporting non-PCI passthrough in osstest.

Right, I'd expect us to have upgraded to Jessie before we got hold of such production hardware anyway.

Ian.

#5 lore raw

Re: [PATCH v8 1/6] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt

Hi Ian,

Quoted 30 lines · Ian Campbell
Quoted 28 lines · Julien Grall

:(. Both the distribution are using an old version of libfdt where the 3 prototypes are defined but the implementation is not exposed in the library (this is because they use a whitelist for building it)

I gave look to see if we can import them from libfdt. It will require to import few others in order to make them work:
- _fdt_check_node_offset
- _fdt_offset_ptr
- _nextprop

I think we can skip the first one because it's only a validity check. FWIW, we declared the the partial device tree should be trusted so valid.

Nonetheless we would add 5 more functions (+ the actual 2) in libxl which represents ~50 lines of codes.

The 3 offending function have been correctly exposed since the version v1.4.0 released in June 2013.

I gave a look to major distribution to see which version is using an old version of libfdt (i.e < 1.4.0:
- Centos: < Centos 6
- Debian: < Jessie => Wheezy using an old version
- Fedora: < Fedora 20
- openSuse: < opensuse 13.1
- ubuntu: < Ubuntu 14.04 => The LTS (14.04) is using a new version
- RedHat: < Redhat 6

Quoted 5 lines
Quoted 3 lines

AFAICT, all major distributions except debian (for wheezy) are using a libfdt > v1.4. So I would suggest to disable the partial device tree support on distribution using older version.

OK, I think we can live with this.

I will resend the series later today or tomorrow.

Quoted 4 lines
Quoted 4 lines

If the user want to use platform device passthrough it would have either to build a newer version of libfdt or append a device tree to the guest kernel.

Quoted 8 lines
Quoted 5 lines

Note: IIRC osstest is using wheezy. If so, we won't be able to test platform device passthrough until the distribution version is upgraded.

Although, we don't currently have a platform supporting non-PCI passthrough in osstest.

Right, I'd expect us to have upgraded to Jessie before we got hold of such production hardware anyway.

Good!

Regards,

Signature · 1 line
Julien Grall
#6 lore raw

PATCH v8 2/6 tools/(lib)xl: Add partial device tree support for ARM

In reply to Julien Grall

From: 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.

---
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 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/libxl/libxl_arm.c     | 151 ++++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_types.idl |   4 ++
 tools/libxl/xl_cmdimpl.c    |   1 +
 4 files changed, 166 insertions(+)
docs/man/xl.cfg.pod.5 +10 -0
index 8e4154f..ead8a5c 100644
@@ -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/libxl/libxl_arm.c +151 -0

182 lines not on this page · raw message

tools/libxl/libxl_types.idl +4 -0
index 023b21e..2b57785 100644
@@ -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
index 526a1f6..19bf103 100644
@@ -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
#7 lore raw

PATCH v8 3/6 tools/libxl: arm: Use an higher value for the GIC phandle

In reply to Julien Grall

From: 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
index ead8a5c..fb8721f 100644
@@ -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
index 6ad8b21..e144535 100644
@@ -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
index 2b57785..3254617 100644
@@ -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
#8 lore raw

PATCH v8 4/6 libxl: Add support for Device Tree passthrough

In reply to Julien Grall

From: 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
index efc0617..4aab751 100644
@@ -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
index f0da7dc..0a2359e 100644
@@ -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
index 857abd4..dcb3f5c 100644
@@ -1203,6 +1203,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
index 3254617..8158691 100644
@@ -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
#9 lore raw

PATCH v8 5/6 xl: Add new option dtdev

In reply to Julien Grall

From: 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
index fb8721f..a189091 100644
@@ -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
index 19bf103..51ab85a 100644
@@ -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
#10 lore raw

PATCH v8 6/6 docs/misc: arm: Add documentation about Device Tree passthrough

In reply to Julien Grall

From: 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
new file mode 100644
index 0000000..4a39649
@@ -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