Skip to contentSkip to conversation

xen/arm: export device_tree_get_reg and device_tree_get_u32

PATCH Stefano Stabellini 2 participants 15 messages Sep 24, 2019 – Sep 25, 2019 11 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.21.1908201838370.20094@sstabellini-ThinkPad-T480s

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 14 lines · Julien Grall

Hi,

Quoted 10 lines · Stefano Stabellini

They'll be used in later patches.

---
Changes in v4:
- new patch

---
  xen/arch/arm/bootfdt.c        | 8 ++++----
  xen/include/xen/device_tree.h | 6 ++++++
Quoted 5 lines

device_tree.h is a common header that describe all the function implemented by common/device_tree.c.

Most likely you want to declare the prototype in asm-arm/setup.h as this is done for all the others function exported in bootfdt.c.

I'll do that

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [Xen-devel] [PATCH v4 5/8] xen/arm: assign devices to boot domains

Quoted 73 lines · Julien Grall

Hi,

Quoted 70 lines · Stefano Stabellini

Scan the user provided dtb fragment at boot. For each device node, map memory to guests, and route interrupts and setup the iommu.

The memory region to remap is specified by the "xen,reg" property.

The iommu is setup by passing the node of the device to assign on the host device tree. The path is specified in the device tree fragment as the "xen,path" string property.

The interrupts are remapped based on the information from the corresponding node on the host device tree. Call handle_device_interrupts to remap interrupts. Interrupts related device tree properties are copied from the device tree fragment, same as all the other properties.

---
Changes in v4:
- use unsigned
- improve commit message
- code style
- use dt_prop_cmp
- use device_tree_get_reg
- don't copy over xen,reg and xen,path
- don't create special interrupt properties for domU: copy them from the fragment
- in-code comment

Changes in v3:
- improve commit message
- remove superfluous cast
- merge code with the copy code
- add interrup-parent
- demove depth > 2 check
- reuse code from handle_device_interrupts
- copy interrupts from host dt

Changes in v2:
- rename "path" to "xen,path"
- grammar fix
- use gaddr_to_gfn and maddr_to_mfn
- remove depth <= 2 limitation in scanning the dtb fragment
- introduce and parse xen,reg
- code style
- support more than one interrupt per device
- specify only the GIC is supported

---
  xen/arch/arm/domain_build.c | 66 ++++++++++++++++++++++++++++++++++---
  1 file changed, 62 insertions(+), 4 deletions(-)
xen/arch/arm/domain_build.c +3 -2
index c71b9f2889..256c83462a 100644
@@ -1721,6 +1721,9 @@ static int __init handle_prop_pfdt(struct kernel_info
 *kinfo,
      void *fdt = kinfo->fdt;
      int propoff, nameoff, res;
      const struct fdt_property *prop;
+    struct dt_device_node *node;
+    const __be32 *cell;
+    unsigned int i, len;
        for ( propoff = fdt_first_property_offset(pfdt, nodeoff);
            propoff >= 0;
@@ -1730,10 +1733,65 @@ static int __init handle_prop_pfdt(struct
 kernel_info *kinfo,
              return -FDT_ERR_INTERNAL;
            nameoff = fdt32_to_cpu(prop->nameoff);
-        res = fdt_property(fdt, fdt_string(pfdt, nameoff),
-                           prop->data, fdt32_to_cpu(prop->len));
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init handle_prop_pfdt(struct · line 1738

Quoted 5 lines
xen/arch/arm/domain_build.c +3 -2
-        if ( res )
-            return res;
+
+        /* xen,reg specifies where to map the MMIO region */
+        if ( dt_prop_cmp("xen,reg", fdt_string(pfdt, nameoff)) == 0 )

The construct fdt_string(pfdt, nameoff) is used quite often within this function. I think it is warrant for a local variable.

OK

Quoted 13 lines
Quoted 13 lines
xen/arch/arm/domain_build.c +13 -0
+        {
+            paddr_t mstart, size, gstart;
+            cell = (const __be32 *)prop->data;
+            len = fdt32_to_cpu(prop->len) /
+                  ((address_cells * 2 + size_cells) * sizeof(uint32_t));
+
+            for ( i = 0; i < len; i++ )
+            {
+                device_tree_get_reg(&cell, address_cells, size_cells,
+                                    &mstart, &size);
+                gstart = dt_next_cell(address_cells, &cell);
+
+                res = guest_physmap_add_entry(kinfo->d,
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init handle_prop_pfdt(struct · line 1754

Quoted 3 lines
xen/arch/arm/domain_build.c +2 -0
 gaddr_to_gfn(gstart),
+                                              maddr_to_mfn(mstart),
+                                              get_order_from_bytes(size),

guest_physmap_add_entry is definitely not the correct function to call. It takes an order and means that if the user ask to map 12KB, it will effectively map 16KB. You want to use map_regions_p2mt as this is done everywhere else for mapping MMIO regions.

OK

Quoted 5 lines

It also raises the question what should we do if the size passed in not page-aligned? Shall we just blindly round up/down? Should we warn?

This was not important for dom0, but is potentially critical for domU as you may happen to inadvertently to export more than you hope to a guest.

A warning or even a panic would be OK because it is a static misconfiguration.

Quoted 39 lines
Quoted 39 lines
xen/arch/arm/domain_build.c +38 -0
+                                              p2m_mmio_direct_dev);
+                if ( res < 0 )
+                {
+                    dprintk(XENLOG_ERR,
+                            "Failed to map %"PRIpaddr" to the guest
 at%"PRIpaddr"\n",
+                            mstart, gstart);
+                    return -EFAULT;
+                }
+            }
+        }
+        /*
+         * xen,path specifies the corresponding node in the host DT.
+         * Both interrupt mappings and IOMMU settings are based on it,
+         * as they are done based on the corresponding host DT node.
+         */
+        else if ( dt_prop_cmp("xen,path", fdt_string(pfdt, nameoff)) == 0 )
+        {
+            node = dt_find_node_by_path(prop->data);
+            if ( node == NULL )
+            {
+                dprintk(XENLOG_ERR, "Couldn't find node %s in host_dt!\n",
+                        (char *)prop->data);
+                return -EINVAL;
+            }
+
+            res = iommu_assign_dt_device(kinfo->d, node);
+            if ( res < 0 )
+                return res;
+
+            res = handle_device_interrupts(kinfo->d, node, true);
+            if ( res < 0 )
+                return res;
+        }
+        /* copy all other properties */
+        else
+        {
+            res = fdt_property(fdt, fdt_string(pfdt, nameoff), prop->data,
+                               fdt32_to_cpu(prop->len));
Quoted 12 lines
Quoted 6 lines
xen/arch/arm/domain_build.c +3 -0
+            if ( res )
+                return res;
+        }
      }
        /* FDT_ERR_NOTFOUND => There is no more properties for this node */

Cheers,

Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [Xen-devel] [PATCH v4 5/8] xen/arm: assign devices to boot domains

Hi Stefano,

Quoted 8 lines · Stefano Stabellini
Quoted 5 lines · Julien Grall

It also raises the question what should we do if the size passed in not page-aligned? Shall we just blindly round up/down? Should we warn?

This was not important for dom0, but is potentially critical for domU as you may happen to inadvertently to export more than you hope to a guest.

A warning or even a panic would be OK because it is a static misconfiguration.

Yes and no, there are platforms where devices are sharing the same pages (see the UART on Sunxi SoC for instance). So this is a valid configuration, but we don't support it.

The problem does not arise for domU created by the toolstack because we request a frame. Note that I would not want to use a frame for Dom0less assignment as I think this is buggy.

Anyway, I would rather not add a panic in this code and let the upper layer deciding what to do.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#8 lore raw

Re: [Xen-devel] [PATCH v4 5/8] xen/arm: assign devices to boot domains

Quoted 11 lines · Julien Grall

Hi Stefano,

Quoted 8 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall

It also raises the question what should we do if the size passed in not page-aligned? Shall we just blindly round up/down? Should we warn?

This was not important for dom0, but is potentially critical for domU as you
may happen to inadvertently to export more than you hope to a guest.

Quoted 6 lines
Quoted 2 lines

A warning or even a panic would be OK because it is a static misconfiguration.

Yes and no, there are platforms where devices are sharing the same pages (see the UART on Sunxi SoC for instance). So this is a valid configuration, but we don't support it.

Hopefully the user should know that the minimum granularity is 4K.

Quoted 6 lines

The problem does not arise for domU created by the toolstack because we request a frame. Note that I would not want to use a frame for Dom0less assignment as I think this is buggy.

Anyway, I would rather not add a panic in this code and let the upper layer deciding what to do.

OK. I added a warning.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#11 lore raw

Re: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis

Quoted 22 lines · Julien Grall

Hi Stefano,

Quoted 11 lines · Stefano Stabellini

We don't have a clear way to know how many virtual SPIs we need for the dom0-less domains. Introduce a new option under xen,domain to specify the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis".

Remove the old setting of nr_spis based on the presence of the vpl011.

I am afraid this still does not explain the implications of this patch to current setup (with and without VPL011).

For instance, with your change, VPL011 may not work anymore. Imagine we decide to push the vpl011 interrupt towards the end of the Interrupt ID space (i.e. 1019).

Quoted 7 lines

I don't think we want the user to have to select nr_spis by himself for this case.

Regarding the change without vpl011, this is not explained why all the domains (even the one without SPIs routed) will have SPIs exposed. For instance, if you were to expose 256 interrupts for 4 domains, this will roughly use 80KB of memory. I don't think this is what you had in mind as "low footprint".

What do you think of the following:

The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI).

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#12 lore raw

Re: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis

Hi,

Quoted 38 lines · Stefano Stabellini
Quoted 22 lines · Julien Grall

Hi Stefano,

Quoted 11 lines · Stefano Stabellini

We don't have a clear way to know how many virtual SPIs we need for the dom0-less domains. Introduce a new option under xen,domain to specify the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis".

Remove the old setting of nr_spis based on the presence of the vpl011.

I am afraid this still does not explain the implications of this patch to current setup (with and without VPL011).

For instance, with your change, VPL011 may not work anymore. Imagine we decide to push the vpl011 interrupt towards the end of the Interrupt ID space (i.e. 1019).

Quoted 7 lines

I don't think we want the user to have to select nr_spis by himself for this case.

Regarding the change without vpl011, this is not explained why all the domains (even the one without SPIs routed) will have SPIs exposed. For instance, if you were to expose 256 interrupts for 4 domains, this will roughly use 80KB of memory. I don't think this is what you had in mind as "low footprint".

What do you think of the following:

The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI).

Quoted 4 lines

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work.

This is good to address my first remark. How about the others?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#13 lore raw

Re: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis

Quoted 46 lines · Julien Grall

Hi,

Quoted 43 lines · Stefano Stabellini
Quoted 28 lines · Julien Grall

Hi Stefano,

Quoted 11 lines · Stefano Stabellini

We don't have a clear way to know how many virtual SPIs we need for the dom0-less domains. Introduce a new option under xen,domain to specify the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis".

Remove the old setting of nr_spis based on the presence of the vpl011.

I am afraid this still does not explain the implications of this patch to current setup (with and without VPL011).

For instance, with your change, VPL011 may not work anymore. Imagine we decide
to push the vpl011 interrupt towards the end of the Interrupt ID space (i.e.
1019).

I don't think we want the user to have to select nr_spis by himself for this
case.

Quoted 7 lines

Regarding the change without vpl011, this is not explained why all the domains
(even the one without SPIs routed) will have SPIs exposed. For instance, if
you were to expose 256 interrupts for 4 domains, this will roughly use 80KB of
memory. I don't think this is what you had in mind as "low footprint".

What do you think of the following:

The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI).

Quoted 6 lines
Quoted 4 lines

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work.

This is good to address my first remark. How about the others?

For your point about "VPL011 may not work anymore", are you suggesting we print a warning or that we always allocate at least GUEST_VPL011_SPI+1 SPIs if vpl011 is requested?

For your point about "it is not explained why all the domains will have SPIs exposed" would you like me to add a sentence to the commit message to make it clearer or do you have something else in mind?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

Re: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis

Hi,

Quoted 52 lines · Stefano Stabellini
Quoted 51 lines · Julien Grall

Hi,

Quoted 47 lines · Stefano Stabellini
Quoted 28 lines · Julien Grall

Hi Stefano,

Quoted 11 lines · Stefano Stabellini

We don't have a clear way to know how many virtual SPIs we need for the dom0-less domains. Introduce a new option under xen,domain to specify the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis".

Remove the old setting of nr_spis based on the presence of the vpl011.

I am afraid this still does not explain the implications of this patch to current setup (with and without VPL011).

For instance, with your change, VPL011 may not work anymore. Imagine we decide
to push the vpl011 interrupt towards the end of the Interrupt ID space (i.e.
1019).

I don't think we want the user to have to select nr_spis by himself for this
case.

Quoted 7 lines

Regarding the change without vpl011, this is not explained why all the domains
(even the one without SPIs routed) will have SPIs exposed. For instance, if
you were to expose 256 interrupts for 4 domains, this will roughly use 80KB of
memory. I don't think this is what you had in mind as "low footprint".

What do you think of the following:

The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI).

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work.

Quoted 5 lines
Quoted 1 line

This is good to address my first remark. How about the others?

For your point about "VPL011 may not work anymore", are you suggesting we print a warning or that we always allocate at least GUEST_VPL011_SPI+1 SPIs if vpl011 is requested?

My preference is to do the later as this match the behavior when guest are created by libxl. This is also the current behavior.

But if you want to change this behavior, then you need to document it as this is a breakage between the previous interface.

Quoted 4 lines

For your point about "it is not explained why all the domains will have SPIs exposed" would you like me to add a sentence to the commit message to make it clearer or do you have something else in mind?

A sentence in the commit message is be good enough.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

Re: [Xen-devel] [PATCH v4 7/8] xen/arm: introduce nr_spis

Quoted 63 lines · Julien Grall

Hi,

Quoted 60 lines · Stefano Stabellini
Quoted 59 lines · Julien Grall

Hi,

Quoted 55 lines · Stefano Stabellini
Quoted 35 lines · Julien Grall

Hi Stefano,

Quoted 13 lines · Stefano Stabellini

We don't have a clear way to know how many virtual SPIs we need for the
dom0-less domains. Introduce a new option under xen,domain to specify
the number of SPIs to allocate for a domain.

The property is optional. When absent, we'll use the physical number of
GIC lines for dom0-less domains, just like for dom0. Given that dom0-less VMs are meant for static partitioning scenarios where the number of VMs is very low, increased memory overhead should not be a problem, and it is possible to minimize it using "nr_spis".

Quoted 2 lines

Remove the old setting of nr_spis based on the presence of the vpl011.

I am afraid this still does not explain the implications of this patch to
current setup (with and without VPL011).

For instance, with your change, VPL011 may not work anymore. Imagine we
decide
to push the vpl011 interrupt towards the end of the Interrupt ID space (i.e.
1019).

I don't think we want the user to have to select nr_spis by himself for
this
case.

Quoted 8 lines

Regarding the change without vpl011, this is not explained why all the domains
(even the one without SPIs routed) will have SPIs exposed. For instance,
if
you were to expose 256 interrupts for 4 domains, this will roughly use 80KB of
memory. I don't think this is what you had in mind as "low footprint".

What do you think of the following:

The implication of this change is that without nr_spis dom0less domains get the same amount of SPI allocated as dom0, regardless of how many physical devices they have assigned, and regardless of whether they have a virtual pl011 (which also needs an emulated SPI).

When nr_spis is present, the domain gets exactly nr_spis allocated SPIs. If the number is too low, it might not be enough for the devices assigned it to it. If the number is less than GUEST_VPL011_SPI, the virtual pl011 won't work.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This is good to address my first remark. How about the others?

For your point about "VPL011 may not work anymore", are you suggesting
we print a warning or that we always allocate at least GUEST_VPL011_SPI+1 SPIs if vpl011 is requested?

My preference is to do the later as this match the behavior when guest are created by libxl. This is also the current behavior.

OK, if nr_spis is not present, I'll make sure that the allocated SPIs are enough to account for GUEST_VPL011_SPI.

Quoted 9 lines

But if you want to change this behavior, then you need to document it as this is a breakage between the previous interface.

Quoted 4 lines

For your point about "it is not explained why all the domains will have SPIs exposed" would you like me to add a sentence to the commit message to make it clearer or do you have something else in mind?

A sentence in the commit message is be good enough.

OK

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#18 lore raw

Re: [Xen-devel] [PATCH v4 8/8] xen/arm: add dom0-less device assignment info to docs

Quoted 33 lines · Julien Grall

Hi Stefano,

Quoted 30 lines · Stefano Stabellini

Add info about the SPI used for the virtual pl011.

---
Changes in v4:
- fix spelling
- add "multiboot,module"
- improve commit message
- improve doc
- expand the nr_spis and vpl011 sections and include information about the vpl011 SPI
- move passthrough information to docs/misc/arm/passthrough.txt

Changes in v3:
- add nr_spis
- change description of interrupts and interrupt-parent

Changes in v2:
- device tree fragment loaded in cacheable memory
- rename multiboot,dtb to multiboot,device-tree
- rename "path" to "xen,path"
- add a note about device memory mapping
- introduce xen,reg
- specify only the GIC is supported

---
  docs/misc/arm/device-tree/booting.txt |  44 ++++++++++-
  docs/misc/arm/passthrough.txt         | 105 ++++++++++++++++++++++++++
  2 files changed, 148 insertions(+), 1 deletion(-)
Quoted 15 lines

docs/misc/arm/device-tree/booting.txt

Quoted 11 lines
docs/misc/arm/device-tree/booting.txt +0 -0
index 317a9e962a..0b850c0591 100644
@@ -146,7 +146,18 @@ with the following properties:
    - vpl011
  -    An empty property to enable/disable a virtual pl011 for the guest to

use.

docs/misc/arm/device-tree/booting.txt +2 -0
+    An empty property to enable/disable a virtual pl011 for the guest to
+    use. The virtual pl011 uses SPI number 32 (see GUEST_VPL011_SPI).

This is a bit confusing, if you say SPI number 32, then you are saying the interrupt identifier will be 64. However, the interrupt identifier is 32, so the SPI number is 0.

I'll clarify

Quoted 67 lines
Quoted 67 lines

+ Please note that the SPI used for the virtual pl011 could clash with
the

docs/misc/arm/device-tree/booting.txt +40 -0
+    physical SPI of a physical device assigned to the guest.
+
+- nr_spis
+
+    Optional. A 32-bit integer specifying the number of SPIs (Shared
+    Peripheral Interrupts) to allocate for the domain. If nr_spis is
+    missing, the max number of SPIs supported by the physical GIC is
+    used. If both vpl011 and nr_spis are set, nr_spis should be at least
+    1 to account for the SPI used by the virtual pl011.
    - #address-cells and #size-cells
  @@ -226,3 +237,34 @@ chosen {
          };
      };
  };
+
+
+Device Assignment
+=================
+
+Device Assignment (Passthrough) is supported by adding another module,
+alongside the kernel and ramdisk, with the device tree fragment
+corresponding to the device node to assign to the guest.
+
+The dtb sub-node should have the following properties:
+
+- compatible
+
+    "multiboot,device-tree" and "multiboot,module"
+
+- reg
+
+    Specifies the physical address of the device tree binary fragment
+    RAM and its length.
+
+As an example:
+
+        module@0xc000000 {
+            compatible = "multiboot,device-tree", "multiboot,module";
+            reg = <0x0 0xc000000 0xffffff>;
+        };
+
+The DTB fragment is loaded at 0xc000000 in the example above. It should
+follow the convention explained in docs/misc/arm/passthrough.txt. The
+DTB fragment will be added to the guest device tree, so that the guest
+kernel will be able to discover the device.
docs/misc/arm/passthrough.txt +0 -0
index 0efbd122de..8084f2e31b 100644
@@ -80,6 +80,111 @@ SPI numbers start from 32, in this example 80 + 32 =

112.
See man [xl.cfg] for the iomem format. The reg property is just a pair of address, then size numbers, each of them can occupy 1 or 2 cells. +

docs/misc/arm/passthrough.txt +11 -0
+Dom0-less Device Passthrough
+============================
+
+The partial device tree for dom0-less guests should have the following
+properties for each node corresponding to a physical device to assign to
+the guest:
+
+- xen,reg
+
+  The xen,reg property is an array of:
+
Quoted 8 lines

docs/misc/arm/passthrough.txt

Quoted 6 lines
docs/misc/arm/passthrough.txt +6 -0
+    <phys_addr size guest_addr>
+
+  They specify the physical address and size of the device memory
+  ranges together with the corresponding guest address to map them to.
+  The size of `phys_addr' and `guest_addr' is determined by
+  #address_cells; the size of `size' is determined by #size_cells.

#address_cells and #size_cells of which device-tree? Partial or Host?

here too

Quoted 6 lines

docs/misc/arm/passthrough.txt

Quoted 2 lines
docs/misc/arm/passthrough.txt +2 -0
+  The memory will be mapped as device memory in the guest
+  (p2m_mmio_direct_dev).

The p2m type means nothing for most of the user. What matters is the stage-2 will be configured with Device-nGnRE (strongly ordered for Armv7) for those mappings.

I'll say Device-nGnRE

Quoted 7 lines
Quoted 7 lines
docs/misc/arm/passthrough.txt +7 -0
+
+- xen,path
+
+  A string property representing the path in the host device tree to the
+  corresponding device node.
+
+In addition, a special /gic node is expected as a placeholder for the
Quoted 8 lines

docs/misc/arm/passthrough.txt

Quoted 5 lines
docs/misc/arm/passthrough.txt +5 -0
+full GIC node that will be added by Xen for the guest. /gic can be
+referenced by other properties in the device tree fragment. For
+instance, it can be referenced by interrupt-parent under a device node.
+Xen will take care of substituting the "gic" placeholder node for a
+complete GIC node while retaining all the references correctly.

This seems to imply that /gic will be retained in the guest DT. But we are going to create a new one in the form interrupt-controller@<unit>.

I'll clarify

Quoted 17 lines
Quoted 17 lines
docs/misc/arm/passthrough.txt +17 -0
+
+    gic: gic {
+        #interrupt-cells = <0x3>;
+        interrupt-controller;
+    };
+
+Note that the #interrupt-cells and interrupt-controller properties are
+not actually required, however, DTC expects them to be present if gic is
+referenced by interrupt-parent or similar.
+
+
+Example
+=======
+
+The following is a real-world example of a device tree fragment to
+assign a network card to a dom0-less guest on Xilinx Ultrascale+ MPSoC:
+
Quoted 8 lines

docs/misc/arm/passthrough.txt

Quoted 5 lines
docs/misc/arm/passthrough.txt +5 -0
+/dts-v1/;
+
+/ {
+    #address-cells = <0x2>;
+    #size-cells = <0x1>;

AFAICT, you basically dumped the DT with dtc. Can we provide something more human readable? For instance, 0xX, can be replace by X.

I am so used to reading it this way I can't tell anymore whan is more "humanly readable" :-)
I can replace 0xX by X for #address-cells and #size-cells everywhere in the example. I don't think it makes sense to do it for reg and interrupts properties?

Quoted 13 lines
Quoted 13 lines
docs/misc/arm/passthrough.txt +13 -0
+
+    gic: gic {
+        #interrupt-cells = <0x3>;
+        interrupt-controller;
+    };
+
+    passthrough {
+        compatible = "simple-bus";
+        ranges;
+        #address-cells = <0x2>;
+        #size-cells = <0x1>;
+
+        misc_clk {
Quoted 8 lines

docs/misc/arm/passthrough.txt

Quoted 5 lines
docs/misc/arm/passthrough.txt +5 -0
+            #clock-cells = <0x0>;
+            clock-frequency = <0x7735940>;
+            compatible = "fixed-clock";
+            linux,phandle = <0x1>;
+            phandle = <0x1>;

We should let the device-tree compiler to generate those property. Otherwise, it defeats the purpose of what you explained about /gic above.

yes, that's a good point, I'll fix it

Quoted 28 lines

The two comments applies for the full example.

Quoted 26 lines
docs/misc/arm/passthrough.txt +26 -0
+        };
+
+        ethernet@ff0e0000 {
+            compatible = "cdns,zynqmp-gem";
+            status = "okay";
+            reg = <0x0 0xff0e0000 0x1000>;
+            clock-names = "pclk", "hclk", "tx_clk", "rx_clk";
+            #address-cells = <0x1>;
+            #size-cells = <0x0>;
+            clocks = <0x1 0x1 0x1 0x1>;
+            phy-mode = "rgmii-id";
+            xlnx,ptp-enet-clock = <0x0>;
+            local-mac-address = [00 0a 35 00 22 01];
+            phy-handle = <0x2>;
+            interrupt-parent = <&gic>;
+            interrupts = <0x0 0x3f 0x4 0x0 0x3f 0x4>;
+            xen,path = "/amba/ethernet@ff0e0000";
+            xen,reg = <0x0 0xff0e0000 0x1000 0x0 0xff0e0000>;
+
+            phy@c {
+                reg = <0xc>;
+                ti,rx-internal-delay = <0x8>;
+                ti,tx-internal-delay = <0xa>;
+                ti,fifo-depth = <0x1>;
+                ti,rxctrl-strap-worka;
+                linux,phandle = <0x2>;
Quoted 12 lines

docs/misc/arm/passthrough.txt

Quoted 7 lines
docs/misc/arm/passthrough.txt +7 -0
+                phandle = <0x2>;
+            };
+        };
+    };
+};
+
+

Cheers,

Signature · 1 line
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

Re: [Xen-devel] [PATCH v4 8/8] xen/arm: add dom0-less device assignment info to docs

Quoted 5 lines · Stefano Stabellini
Quoted 1 line · Julien Grall

On 8/21/19 4:53 AM, Stefano Stabellini wrote:

I can replace 0xX by X for #address-cells and #size-cells everywhere in the example. I don't think it makes sense to do it for reg and interrupts properties?

I agree it does not make sense for the property reg. However, for "interrupts" property it would as it makes easier to find out the interrupt number. Looking at example in the bindings they actually use decimal number for the first two cells and then an hexadecimal:

      interrupts = <1 8 0xf04>;

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#20 lore raw

Re: [Xen-devel] [PATCH v4 8/8] xen/arm: add dom0-less device assignment info to docs

Quoted 7 lines · Julien Grall
Quoted 5 lines · Stefano Stabellini
Quoted 1 line · Julien Grall

On 8/21/19 4:53 AM, Stefano Stabellini wrote:

I can replace 0xX by X for #address-cells and #size-cells everywhere in the example. I don't think it makes sense to do it for reg and interrupts properties?

Quoted 6 lines

I agree it does not make sense for the property reg. However, for "interrupts" property it would as it makes easier to find out the interrupt number. Looking at example in the bindings they actually use decimal number for the first two cells and then an hexadecimal:

      interrupts = <1 8 0xf04>;

I can do that

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#23 lore raw

Re: [Xen-devel] [PATCH v4 4/8] xen/arm: copy dtb fragment to guest dtb

Quoted 21 lines · Julien Grall

Hi Stefano,

Quoted 18 lines · Stefano Stabellini

Read the dtb fragment corresponding to a passthrough device from memory at the location referred to by the "multiboot,device-tree" compatible node.

Add a new field named dtb_bootmodule to struct kernel_info to keep track of the dtb fragment location.

Copy the fragment to the guest dtb (only /aliases and /passthrough).

Set kinfo->guest_phandle_gic based on the phandle of the special "/gic" node in the device tree fragment. "/gic" is a dummy node in the dtb fragment that represents the gic interrupt controller. Other properties in the dtb fragment might refer to it (for instance interrupt-parent of a device node). We reuse the phandle of "/gic" from the dtb fragment as the phandle of the full GIC node that will be created for the guest device tree. That way, when we copy properties from the device tree fragment to the domU device tree the links remain unbroken.

Quoted 7 lines
Quoted 3 lines

Some of the code below is taken from tools/libxl/libxl_arm.c. Note that it is OK to take LGPL 2.1 code and including it into a GPLv2 code base. The result is GPLv2 code.

I would be much in favor to keep the code as close a possible to the libxl code rather than re-inventing the wheel copying the partial DT. In other words, if there are reason to diverge, then I would like to understand why.

We started from something similar to libxl (see v1) but through several rounds of review we came to this version. The main reason is that the libxl code has only to copy the partial device tree. This patch has to copy and also to scan the partial device tree, taking action when appropriate.

If you look at this patch in isolation, it looks like it is different for no particular reason, but if you take the patch series as a whole, this approach is better suited I think.

But you do have a point that in a couple of places this is diverging for no reason. Specifically, we should have a check_partial_fdt function here too. I'll add it.

Quoted 43 lines
Quoted 43 lines

----
Changes in v4:
- use recursion in the implementation
- rename handle_properties to handle_prop_pfdt
- rename scan_pt_node to scan_pfdt_node
- pass kinfo to handle_properties
- use uint32_t instead of u32
- rename r to res
- add "passthrough" and "aliases" check
- add a name == NULL check
- code style
- move DTB fragment scanning earlier, before DomU GIC node creation
- set guest_phandle_gic based on "/gic"
- in-code comment

Changes in v3:
- switch to using device_tree_for_each_node for the copy

Changes in v2:
- add a note about the code coming from libxl in the commit message
- copy /aliases
- code style

---
  xen/arch/arm/domain_build.c  | 112 +++++++++++++++++++++++++++++++++++
  xen/include/asm-arm/kernel.h |   2 +-
  2 files changed, 113 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +1 -0
index cd585f05ca..c71b9f2889 100644
@@ -14,6 +14,7 @@
  #include <xen/guest_access.h>
  #include <xen/iocap.h>
  #include <xen/acpi.h>
+#include <xen/vmap.h>
  #include <xen/warning.h>
  #include <acpi/actables.h>
  #include <asm/device.h>
@@ -1713,6 +1714,111 @@ static int __init make_vpl011_uart_node(struct
 kernel_info *kinfo)
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_vpl011_uart_node(struct · line 1720

Quoted 6 lines
xen/arch/arm/domain_build.c +2 -0
  }
  #endif
  +static int __init handle_prop_pfdt(struct kernel_info *kinfo,
+                                   const void *pfdt, int nodeoff,
+                                   uint32_t address_cells, uint32_t
 size_cells)

Why do you need address_cells and size_cells in parameter?

Yes, it will be necessary for later patches.

Quoted 40 lines
Quoted 40 lines
xen/arch/arm/domain_build.c +26 -0
+{
+    void *fdt = kinfo->fdt;
+    int propoff, nameoff, res;
+    const struct fdt_property *prop;
+
+    for ( propoff = fdt_first_property_offset(pfdt, nodeoff);
+          propoff >= 0;
+          propoff = fdt_next_property_offset(pfdt, propoff) )
+    {
+        if ( !(prop = fdt_get_property_by_offset(pfdt, propoff, NULL)) )
+            return -FDT_ERR_INTERNAL;
+
+        nameoff = fdt32_to_cpu(prop->nameoff);
+        res = fdt_property(fdt, fdt_string(pfdt, nameoff),
+                           prop->data, fdt32_to_cpu(prop->len));
+        if ( res )
+            return res;
+    }
+
+    /* FDT_ERR_NOTFOUND => There is no more properties for this node */
+    return ( propoff != -FDT_ERR_NOTFOUND ) ? propoff : 0;
+}
+
+static int __init scan_pfdt_node(struct kernel_info *kinfo, const void
 *pfdt,
+                                 int nodeoff, int depth,
+                                 uint32_t address_cells, uint32_t

size_cells)

xen/arch/arm/domain_build.c +12 -0
+{
+    int rc = 0;
+    void *fdt = kinfo->fdt;
+    int node_next;
+    const char *name = fdt_get_name(pfdt, nodeoff, NULL);
+
+    /*
+     * Take the GIC phandle value from the special /gic node in the DTB
+     * fragment.
+     */
+    if ( depth == 1 && dt_node_cmp(name, "gic") == 0 )
+    {
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 3 lines
xen/arch/arm/domain_build.c +3 -0
+        kinfo->guest_phandle_gic = fdt_get_phandle(pfdt, nodeoff);
+        return 0;
+    }

I don't like this solution. You are bypassing most of the function just for the benefits of have the name in hand. Can this be done separately? This would also avoid to have an extra parameter (depth) for the only benefits of this check.

All right, I'll change it and remove depth.

Quoted 9 lines
Quoted 9 lines
xen/arch/arm/domain_build.c +9 -0
+
+    rc = fdt_begin_node(fdt, fdt_get_name(pfdt, nodeoff, NULL));
+    if ( rc )
+        return rc;
+
+    rc = handle_prop_pfdt(kinfo, pfdt, nodeoff, address_cells, size_cells);
+    if ( rc )
+        return rc;
+
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+    address_cells = device_tree_get_u32(pfdt, nodeoff, "#address-cells",
+                                        address_cells);
+    size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells",
+                                     size_cells);

I am pretty sure I mention it before (though not on this patch...), this is not matching the DT spec. address_cells and size_cells are not propagated to the next level. So these should be DT_ROOT_NODE_{ADDR, SIZE}_CELLS_DEFAULT.

They are only propagated from parent to children, not from parent to grandchildren. This function is recursive. In this case we are reading #address-cells and #size-cells just to pass it on by 1 level as by the spec. Am I misunderstanding something?

Quoted 17 lines
Quoted 17 lines
xen/arch/arm/domain_build.c +5 -0
+
+    node_next = fdt_first_subnode(pfdt, nodeoff);
+    while ( node_next > 0 )
+    {
+        scan_pfdt_node(kinfo, pfdt, node_next, depth + 1, address_cells,

size_cells);

xen/arch/arm/domain_build.c +11 -0
+        node_next = fdt_next_subnode(pfdt, node_next);
+    }
+
+    return fdt_end_node(fdt);
+}
+
+static int __init domain_handle_dtb_bootmodule(struct domain *d,
+                                               struct kernel_info *kinfo)
+{
+    void *pfdt;
+    int res, node_next;
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 5 lines
xen/arch/arm/domain_build.c +5 -0
+
+    pfdt = ioremap_cache(kinfo->dtb_bootmodule->start,
+                         kinfo->dtb_bootmodule->size);
+    if ( pfdt == NULL )
+        return -EFAULT;

Shouldn't you check you actually have a device-tree in hand and that it fits in the size specified by the user? See check_partial_fdt() in libxl_arm.c.

Yes, you are right about that. I'll add a check_partial_fdt function call here.

Quoted 7 lines

xen/arch/arm/domain_build.c

Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+
+    node_next = fdt_first_subnode(pfdt, 0);
+    while ( node_next > 0 )
+    {

Why do we have to go through the all the nodes of the first level? Can't we just lookup for the path and copy the node as libxl does?

Yes, we could do that, but fdt_path_offset is implemented as a loop anyway and we would still have the same "gic", "aliases" and "passthrough" checks. I tried the change but the code doesn't look much nicer and we would end up increasing runtime complexity.

Quoted 34 lines
Quoted 27 lines
xen/arch/arm/domain_build.c +23 -0
+        const char *name = fdt_get_name(pfdt, node_next, NULL);
+
+        /* only scan /gic /aliases /passthrough, ignore the rest */
+        if ( name != NULL &&
+             (dt_node_cmp(name, "passthrough") == 0 ||
+              dt_node_cmp(name, "aliases") == 0 ||
+              dt_node_cmp(name, "gic") == 0) )
+        {
+            res = scan_pfdt_node(kinfo, pfdt, node_next, 1,
+                    DT_ROOT_NODE_ADDR_CELLS_DEFAULT,
+                    DT_ROOT_NODE_SIZE_CELLS_DEFAULT);
+            if ( res )
+                return res;
+        }
+
+        node_next = fdt_next_subnode(pfdt, node_next);
+    }
+
+    iounmap(pfdt);
+
+    return res;
+}
+
  /*
   * The max size for DT is 2MB. However, the generated DT is small, 4KB
   * are enough for now, but we might have to increase it in the future.

xen/arch/arm/domain_build.c static int __init prepare_dtb_domU(struct domain *d, · line 1877

Quoted 4 lines
xen/arch/arm/domain_build.c +0 -0
@@ -1768,6 +1874,12 @@ static int __init prepare_dtb_domU(struct domain *d,
 struct kernel_info *kinfo)
      if ( ret )
          goto err;
  +    if ( kinfo->dtb_bootmodule ) {

Coding style:

Quoted 2 lines

if ( ... )
{

I'll fix

Quoted 13 lines
Quoted 13 lines
xen/arch/arm/domain_build.c +5 -0
+        ret = domain_handle_dtb_bootmodule(d, kinfo);
+        if ( ret )
+            return ret;
+    }
+
      ret = make_gic_domU_node(kinfo);
      if ( ret )
          goto err;
xen/include/asm-arm/kernel.h +0 -0
index 760434369b..7f5e659561 100644
@@ -28,7 +28,7 @@ struct kernel_info {
Quoted 8 lines

xen/include/asm-arm/kernel.h struct kernel_info { · line 34

Quoted 8 lines
xen/include/asm-arm/kernel.h +1 -1
      paddr_t gnttab_size;
        /* boot blob load addresses */
-    const struct bootmodule *kernel_bootmodule, *initrd_bootmodule;
+    const struct bootmodule *kernel_bootmodule, *initrd_bootmodule,
 *dtb_bootmodule;
      const char* cmdline;
      paddr_t dtb_paddr;
      paddr_t initrd_paddr;

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#24 lore raw

Re: [Xen-devel] [PATCH v4 4/8] xen/arm: copy dtb fragment to guest dtb

Quoted 54 lines · Stefano Stabellini
Quoted 44 lines · Julien Grall
Quoted 43 lines · Stefano Stabellini

----
Changes in v4:
- use recursion in the implementation
- rename handle_properties to handle_prop_pfdt
- rename scan_pt_node to scan_pfdt_node
- pass kinfo to handle_properties
- use uint32_t instead of u32
- rename r to res
- add "passthrough" and "aliases" check
- add a name == NULL check
- code style
- move DTB fragment scanning earlier, before DomU GIC node creation
- set guest_phandle_gic based on "/gic"
- in-code comment

Changes in v3:
- switch to using device_tree_for_each_node for the copy

Changes in v2:
- add a note about the code coming from libxl in the commit message
- copy /aliases
- code style

---
   xen/arch/arm/domain_build.c  | 112 +++++++++++++++++++++++++++++++++++
   xen/include/asm-arm/kernel.h |   2 +-
   2 files changed, 113 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +1 -0
index cd585f05ca..c71b9f2889 100644
@@ -14,6 +14,7 @@
   #include <xen/guest_access.h>
   #include <xen/iocap.h>
   #include <xen/acpi.h>
+#include <xen/vmap.h>
   #include <xen/warning.h>
   #include <acpi/actables.h>
   #include <asm/device.h>
@@ -1713,6 +1714,111 @@ static int __init make_vpl011_uart_node(struct
 kernel_info *kinfo)
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_vpl011_uart_node(struct · line 1720

Quoted 6 lines
xen/arch/arm/domain_build.c +2 -0
   }
   #endif
   +static int __init handle_prop_pfdt(struct kernel_info *kinfo,
+                                   const void *pfdt, int nodeoff,
+                                   uint32_t address_cells, uint32_t
 size_cells)

Why do you need address_cells and size_cells in parameter?

Quoted 1 line

Yes, it will be necessary for later patches.

ok.

Quoted 51 lines
Quoted 42 lines
Quoted 42 lines
xen/arch/arm/domain_build.c +26 -0
+{
+    void *fdt = kinfo->fdt;
+    int propoff, nameoff, res;
+    const struct fdt_property *prop;
+
+    for ( propoff = fdt_first_property_offset(pfdt, nodeoff);
+          propoff >= 0;
+          propoff = fdt_next_property_offset(pfdt, propoff) )
+    {
+        if ( !(prop = fdt_get_property_by_offset(pfdt, propoff, NULL)) )
+            return -FDT_ERR_INTERNAL;
+
+        nameoff = fdt32_to_cpu(prop->nameoff);
+        res = fdt_property(fdt, fdt_string(pfdt, nameoff),
+                           prop->data, fdt32_to_cpu(prop->len));
+        if ( res )
+            return res;
+    }
+
+    /* FDT_ERR_NOTFOUND => There is no more properties for this node */
+    return ( propoff != -FDT_ERR_NOTFOUND ) ? propoff : 0;
+}
+
+static int __init scan_pfdt_node(struct kernel_info *kinfo, const void
 *pfdt,
+                                 int nodeoff, int depth,
+                                 uint32_t address_cells, uint32_t

size_cells)

xen/arch/arm/domain_build.c +12 -0
+{
+    int rc = 0;
+    void *fdt = kinfo->fdt;
+    int node_next;
+    const char *name = fdt_get_name(pfdt, nodeoff, NULL);
+
+    /*
+     * Take the GIC phandle value from the special /gic node in the DTB
+     * fragment.
+     */
+    if ( depth == 1 && dt_node_cmp(name, "gic") == 0 )
+    {
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 3 lines
xen/arch/arm/domain_build.c +3 -0
+        kinfo->guest_phandle_gic = fdt_get_phandle(pfdt, nodeoff);
+        return 0;
+    }

I don't like this solution. You are bypassing most of the function just for the benefits of have the name in hand. Can this be done separately? This would also avoid to have an extra parameter (depth) for the only benefits of this check.

Quoted 1 line

All right, I'll change it and remove depth.

Thinking again about this function, you will allow a users to describe a device in the node /aliases. So there are more to do in this function.

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/domain_build.c +9 -0
+
+    rc = fdt_begin_node(fdt, fdt_get_name(pfdt, nodeoff, NULL));
+    if ( rc )
+        return rc;
+
+    rc = handle_prop_pfdt(kinfo, pfdt, nodeoff, address_cells, size_cells);
+    if ( rc )
+        return rc;
+
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+    address_cells = device_tree_get_u32(pfdt, nodeoff, "#address-cells",
+                                        address_cells);
+    size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells",
+                                     size_cells);

I am pretty sure I mention it before (though not on this patch...), this is not matching the DT spec. address_cells and size_cells are not propagated to the next level. So these should be DT_ROOT_NODE_{ADDR, SIZE}_CELLS_DEFAULT.

Quoted 4 lines

They are only propagated from parent to children, not from parent to grandchildren. This function is recursive. In this case we are reading #address-cells and #size-cells just to pass it on by 1 level as by the spec. Am I misunderstanding something?

I am afraid this is not correct. device_tree_get_u32 take the default number of cells as 3rd parameter. This is used if the property does not exist.

So if the children does not have the two properties, then you will end up to use the parent's value as default when parsing grandchildren "reg" properties.

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+
+    node_next = fdt_first_subnode(pfdt, 0);
+    while ( node_next > 0 )
+    {
Quoted 7 lines
Quoted 2 lines

Why do we have to go through the all the nodes of the first level? Can't we just lookup for the path and copy the node as libxl does?

Yes, we could do that, but fdt_path_offset is implemented as a loop anyway and we would still have the same "gic", "aliases" and "passthrough" checks. I tried the change but the code doesn't look much nicer and we would end up increasing runtime complexity.

This is ok as long as they don't depend on each other. This is not very clear from the code that "/gic" does not need to be parsed first, so you may want to explain in a comment.

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#25 lore raw

Re: [Xen-devel] [PATCH v4 4/8] xen/arm: copy dtb fragment to guest dtb

Quoted 115 lines · Julien Grall
Quoted 55 lines · Stefano Stabellini
Quoted 45 lines · Julien Grall
Quoted 44 lines · Stefano Stabellini

----
Changes in v4:
- use recursion in the implementation
- rename handle_properties to handle_prop_pfdt
- rename scan_pt_node to scan_pfdt_node
- pass kinfo to handle_properties
- use uint32_t instead of u32
- rename r to res
- add "passthrough" and "aliases" check
- add a name == NULL check
- code style
- move DTB fragment scanning earlier, before DomU GIC node creation
- set guest_phandle_gic based on "/gic"
- in-code comment

Changes in v3:
- switch to using device_tree_for_each_node for the copy

Changes in v2:
- add a note about the code coming from libxl in the commit message
- copy /aliases
- code style

---
   xen/arch/arm/domain_build.c  | 112
+++++++++++++++++++++++++++++++++++
   xen/include/asm-arm/kernel.h |   2 +-
   2 files changed, 113 insertions(+), 1 deletion(-)
xen/arch/arm/domain_build.c +1 -0
index cd585f05ca..c71b9f2889 100644
@@ -14,6 +14,7 @@
   #include <xen/guest_access.h>
   #include <xen/iocap.h>
   #include <xen/acpi.h>
+#include <xen/vmap.h>
   #include <xen/warning.h>
   #include <acpi/actables.h>
   #include <asm/device.h>
@@ -1713,6 +1714,111 @@ static int __init make_vpl011_uart_node(struct
 kernel_info *kinfo)
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_vpl011_uart_node(struct · line 1720

Quoted 6 lines
xen/arch/arm/domain_build.c +2 -0
   }
   #endif
   +static int __init handle_prop_pfdt(struct kernel_info *kinfo,
+                                   const void *pfdt, int nodeoff,
+                                   uint32_t address_cells, uint32_t
 size_cells)

Why do you need address_cells and size_cells in parameter?

Quoted 1 line

Yes, it will be necessary for later patches.

ok.

Quoted 55 lines
Quoted 54 lines
Quoted 36 lines
xen/arch/arm/domain_build.c +24 -0
+{
+    void *fdt = kinfo->fdt;
+    int propoff, nameoff, res;
+    const struct fdt_property *prop;
+
+    for ( propoff = fdt_first_property_offset(pfdt, nodeoff);
+          propoff >= 0;
+          propoff = fdt_next_property_offset(pfdt, propoff) )
+    {
+        if ( !(prop = fdt_get_property_by_offset(pfdt, propoff, NULL))
 )
+            return -FDT_ERR_INTERNAL;
+
+        nameoff = fdt32_to_cpu(prop->nameoff);
+        res = fdt_property(fdt, fdt_string(pfdt, nameoff),
+                           prop->data, fdt32_to_cpu(prop->len));
+        if ( res )
+            return res;
+    }
+
+    /* FDT_ERR_NOTFOUND => There is no more properties for this node */
+    return ( propoff != -FDT_ERR_NOTFOUND ) ? propoff : 0;
+}
+
+static int __init scan_pfdt_node(struct kernel_info *kinfo, const void

*pfdt,

xen/arch/arm/domain_build.c +2 -0
+                                 int nodeoff, int depth,
+                                 uint32_t address_cells, uint32_t

size_cells)

xen/arch/arm/domain_build.c +5 -0
+{
+    int rc = 0;
+    void *fdt = kinfo->fdt;
+    int node_next;
+    const char *name = fdt_get_name(pfdt, nodeoff, NULL);

xen/arch/arm/domain_build.c

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+
+    /*
+     * Take the GIC phandle value from the special /gic node in the DTB
+     * fragment.
+     */
+    if ( depth == 1 && dt_node_cmp(name, "gic") == 0 )
+    {
+        kinfo->guest_phandle_gic = fdt_get_phandle(pfdt, nodeoff);
+        return 0;
+    }

I don't like this solution. You are bypassing most of the function just for
the benefits of have the name in hand. Can this be done separately? This would
also avoid to have an extra parameter (depth) for the only benefits of this
check.

Quoted 4 lines
Quoted 1 line

All right, I'll change it and remove depth.

Thinking again about this function, you will allow a users to describe a device in the node /aliases. So there are more to do in this function.

Yes, that's true. I can pass a parameter to make sure the proper behavior is applied to /aliases (only copy) and /passthrough (copy and look for device assignment properties).

Quoted 28 lines
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
xen/arch/arm/domain_build.c +6 -0
+
+    rc = fdt_begin_node(fdt, fdt_get_name(pfdt, nodeoff, NULL));
+    if ( rc )
+        return rc;
+
+    rc = handle_prop_pfdt(kinfo, pfdt, nodeoff, address_cells,

size_cells);

xen/arch/arm/domain_build.c +4 -0
+    if ( rc )
+        return rc;
+
+    address_cells = device_tree_get_u32(pfdt, nodeoff,

"#address-cells",

xen/arch/arm/domain_build.c +2 -0
+                                        address_cells);
+    size_cells = device_tree_get_u32(pfdt, nodeoff, "#size-cells",
Quoted 8 lines
Quoted 1 line

+ size_cells);

I am pretty sure I mention it before (though not on this patch...), this is
not matching the DT spec. address_cells and size_cells are not propagated to
the next level. So these should be DT_ROOT_NODE_{ADDR, SIZE}_CELLS_DEFAULT.

Quoted 4 lines

They are only propagated from parent to children, not from parent to grandchildren. This function is recursive. In this case we are reading #address-cells and #size-cells just to pass it on by 1 level as by the spec. Am I misunderstanding something?

Quoted 5 lines

I am afraid this is not correct. device_tree_get_u32 take the default number of cells as 3rd parameter. This is used if the property does not exist.

So if the children does not have the two properties, then you will end up to use the parent's value as default when parsing grandchildren "reg" properties.

I understand your point now. I'll fix it.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines

xen/arch/arm/domain_build.c

Quoted 4 lines
xen/arch/arm/domain_build.c +4 -0
+
+    node_next = fdt_first_subnode(pfdt, 0);
+    while ( node_next > 0 )
+    {

Why do we have to go through the all the nodes of the first level? Can't we
just lookup for the path and copy the node as libxl does?

Quoted 8 lines
Quoted 4 lines

Yes, we could do that, but fdt_path_offset is implemented as a loop anyway and we would still have the same "gic", "aliases" and "passthrough" checks. I tried the change but the code doesn't look much nicer and we would end up increasing runtime complexity.

This is ok as long as they don't depend on each other. This is not very clear from the code that "/gic" does not need to be parsed first, so you may want to explain in a comment.

OK, I'll clarify

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel