diff mbox series

[v3,6/6] xen/arm: add reserved-memory regions to the dom0 memory node

Message ID 20190621235608.2153-6-sstabellini@kernel.org (mailing list archive)
State Superseded
Headers show
Series [v3,1/6] xen/arm: extend device_tree_for_each_node | expand

Commit Message

Stefano Stabellini June 21, 2019, 11:56 p.m. UTC
Reserved memory regions are automatically remapped to dom0. Their device
tree nodes are also added to dom0 device tree. However, the dom0 memory
node is not currently extended to cover the reserved memory regions
ranges as required by the spec.  This commit fixes it.

Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
---
 xen/arch/arm/domain_build.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

Comments

Julien Grall July 10, 2019, 5:03 p.m. UTC | #1
Hi Stefano,

On 6/22/19 12:56 AM, Stefano Stabellini wrote:
> Reserved memory regions are automatically remapped to dom0. Their device
> tree nodes are also added to dom0 device tree. However, the dom0 memory
> node is not currently extended to cover the reserved memory regions
> ranges as required by the spec.  This commit fixes it.
> 
> Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> ---
>   xen/arch/arm/domain_build.c | 17 ++++++++++++++++-
>   1 file changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> index 76dd4bf6f9..5047eb4c28 100644
> --- a/xen/arch/arm/domain_build.c
> +++ b/xen/arch/arm/domain_build.c
> @@ -643,7 +643,8 @@ static int __init make_memory_node(const struct domain *d,
>   {
>       int res, i;
>       int reg_size = addrcells + sizecells;
> -    int nr_cells = reg_size*kinfo->mem.nr_banks;
> +    int nr_cells = reg_size * (kinfo->mem.nr_banks + (is_hardware_domain(d) ?
> +                               bootinfo.reserved_mem.nr_banks : 0));

A device-tree is allowed to have multiple memory node. So I would 
actually prefer if we create a new node for the reserved-memory regions.

You could replace the last parameter with struct meminfo *. Note that 
you would need to specify a unit in the node-name.

>       __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */];

Note that you will overrun reg here if the two arrays (reserved_mem and 
mem) are full.

>       __be32 *cells;
>   
> @@ -673,6 +674,20 @@ static int __init make_memory_node(const struct domain *d,
>           dt_child_set_range(&cells, addrcells, sizecells, start, size);
>       }
>   
> +    if ( is_hardware_domain(d) )
> +    {
> +        for ( i = 0; i < bootinfo.reserved_mem.nr_banks; i++ )
> +        {
> +            u64 start = bootinfo.reserved_mem.bank[i].start;
> +            u64 size = bootinfo.reserved_mem.bank[i].size;
> +
> +            dt_dprintk("  Bank %d: %#"PRIx64"->%#"PRIx64"\n",
> +                    i, start, start + size);
> +
> +            dt_child_set_range(&cells, addrcells, sizecells, start, size);
> +        }
> +    }
> +
>       res = fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg));
>       if ( res )
>           return res;
> 

Cheers,
Stefano Stabellini Aug. 6, 2019, 9:27 p.m. UTC | #2
On Wed, 10 Jul 2019, Julien Grall wrote:
> Hi Stefano,
> 
> On 6/22/19 12:56 AM, Stefano Stabellini wrote:
> > Reserved memory regions are automatically remapped to dom0. Their device
> > tree nodes are also added to dom0 device tree. However, the dom0 memory
> > node is not currently extended to cover the reserved memory regions
> > ranges as required by the spec.  This commit fixes it.
> > 
> > Signed-off-by: Stefano Stabellini <stefanos@xilinx.com>
> > ---
> >   xen/arch/arm/domain_build.c | 17 ++++++++++++++++-
> >   1 file changed, 16 insertions(+), 1 deletion(-)
> > 
> > diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
> > index 76dd4bf6f9..5047eb4c28 100644
> > --- a/xen/arch/arm/domain_build.c
> > +++ b/xen/arch/arm/domain_build.c
> > @@ -643,7 +643,8 @@ static int __init make_memory_node(const struct domain
> > *d,
> >   {
> >       int res, i;
> >       int reg_size = addrcells + sizecells;
> > -    int nr_cells = reg_size*kinfo->mem.nr_banks;
> > +    int nr_cells = reg_size * (kinfo->mem.nr_banks + (is_hardware_domain(d)
> > ?
> > +                               bootinfo.reserved_mem.nr_banks : 0));
> 
> A device-tree is allowed to have multiple memory node. So I would actually
> prefer if we create a new node for the reserved-memory regions.
> 
> You could replace the last parameter with struct meminfo *. Note that you
> would need to specify a unit in the node-name.

Yes, makes sense, good suggestion.


> >       __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */];
> >
> Note that you will overrun reg here if the two arrays (reserved_mem and mem)
> are full.

Won't be a problem anymore after making the suggested changes.


> >       __be32 *cells;
> >   @@ -673,6 +674,20 @@ static int __init make_memory_node(const struct
> > domain *d,
> >           dt_child_set_range(&cells, addrcells, sizecells, start, size);
> >       }
> >   +    if ( is_hardware_domain(d) )
> > +    {
> > +        for ( i = 0; i < bootinfo.reserved_mem.nr_banks; i++ )
> > +        {
> > +            u64 start = bootinfo.reserved_mem.bank[i].start;
> > +            u64 size = bootinfo.reserved_mem.bank[i].size;
> > +
> > +            dt_dprintk("  Bank %d: %#"PRIx64"->%#"PRIx64"\n",
> > +                    i, start, start + size);
> > +
> > +            dt_child_set_range(&cells, addrcells, sizecells, start, size);
> > +        }
> > +    }
> > +
> >       res = fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg));
> >       if ( res )
> >           return res;
> > 
> 
> Cheers,
> 
> -- 
> Julien Grall
>
diff mbox series

Patch

diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c
index 76dd4bf6f9..5047eb4c28 100644
--- a/xen/arch/arm/domain_build.c
+++ b/xen/arch/arm/domain_build.c
@@ -643,7 +643,8 @@  static int __init make_memory_node(const struct domain *d,
 {
     int res, i;
     int reg_size = addrcells + sizecells;
-    int nr_cells = reg_size*kinfo->mem.nr_banks;
+    int nr_cells = reg_size * (kinfo->mem.nr_banks + (is_hardware_domain(d) ?
+                               bootinfo.reserved_mem.nr_banks : 0));
     __be32 reg[NR_MEM_BANKS * 4 /* Worst case addrcells + sizecells */];
     __be32 *cells;
 
@@ -673,6 +674,20 @@  static int __init make_memory_node(const struct domain *d,
         dt_child_set_range(&cells, addrcells, sizecells, start, size);
     }
 
+    if ( is_hardware_domain(d) )
+    {
+        for ( i = 0; i < bootinfo.reserved_mem.nr_banks; i++ )
+        {
+            u64 start = bootinfo.reserved_mem.bank[i].start;
+            u64 size = bootinfo.reserved_mem.bank[i].size;
+
+            dt_dprintk("  Bank %d: %#"PRIx64"->%#"PRIx64"\n",
+                    i, start, start + size);
+
+            dt_child_set_range(&cells, addrcells, sizecells, start, size);
+        }
+    }
+
     res = fdt_property(fdt, "reg", reg, nr_cells * sizeof(*reg));
     if ( res )
         return res;