Skip to contentSkip to conversation

xen: arm: Handle cpus nodes with #address-cells > 1

PATCH Superseded Ian Campbell 3 participants 4 messages Nov 22, 2013

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 9/15 xen: arm: Handle cpus nodes with #address-cells > 1

The APM X-Gene Mustang board DTS has #address-cells = 2.

---
v2: Use dt_read_number, check the property length

---
 xen/arch/arm/smpboot.c |   34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
xen/arch/arm/smpboot.c +29 -5
index 6c90fa6..b6a1307 100644
@@ -125,18 +125,42 @@ void __init smp_init_cpus(void)
 
     dt_for_each_child_node( cpus, cpu )
     {
-        u32 hwid;
+        const __be32 *prop;
+        u64 addr;
+        u32 reg_len, hwid;
 
         if ( !dt_device_type_is_equal(cpu, "cpu") )
             continue;
 
-        if ( !dt_property_read_u32(cpu, "reg", &hwid) )
+        if ( dt_n_size_cells(cpu) != 0 )
+            printk(XENLOG_WARNING "cpu node `%s`: #size-cells %d\n",
+                   dt_node_full_name(cpu), dt_n_size_cells(cpu));
+
+        prop = dt_get_property(cpu, "reg", &reg_len);
+        if ( !prop )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: has no reg property\n",
+                   dt_node_full_name(cpu));
+            continue;
+        }
+
+        if ( reg_len < dt_n_addr_cells(cpu) )
         {
-            printk(XENLOG_WARNING "cpu node `%s`: missing reg property\n",
+            printk(XENLOG_WARNING "cpu node `%s`: reg property too short\n",
                    dt_node_full_name(cpu));
             continue;
         }
 
+        addr = dt_read_number(prop, dt_n_addr_cells(cpu));
+
+        hwid = addr;
+        if ( hwid != addr )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: hwid overflow %"PRIx64"\n",
+                   dt_node_full_name(cpu), addr);
+            continue;
+        }
+
         /*
          * 8 MSBs must be set to 0 in the DT since the reg property
          * defines the MPIDR[23:0]
@@ -159,8 +183,8 @@ void __init smp_init_cpus(void)
             if ( tmp_map[j] == hwid )
             {
                 printk(XENLOG_WARNING
-                       "cpu node `%s`: duplicate /cpu reg properties in the DT\n",
-                       dt_node_full_name(cpu));
+                       "cpu node `%s`: duplicate /cpu reg properties %"PRIx32" in the DT\n",
+                       dt_node_full_name(cpu), hwid);
                 break;
             }
         }
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 3 lines · Ian Campbell

The APM X-Gene Mustang board DTS has #address-cells = 2.

Quoted 75 lines

---
v2: Use dt_read_number, check the property length

---
 xen/arch/arm/smpboot.c |   34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
xen/arch/arm/smpboot.c +29 -6
index 6c90fa6..b6a1307 100644
@@ -125,18 +125,42 @@ void __init smp_init_cpus(void)
 
     dt_for_each_child_node( cpus, cpu )
     {
-        u32 hwid;
+        const __be32 *prop;
+        u64 addr;
+        u32 reg_len, hwid;
 
         if ( !dt_device_type_is_equal(cpu, "cpu") )
             continue;
 
-        if ( !dt_property_read_u32(cpu, "reg", &hwid) )
+        if ( dt_n_size_cells(cpu) != 0 )
+            printk(XENLOG_WARNING "cpu node `%s`: #size-cells %d\n",
+                   dt_node_full_name(cpu), dt_n_size_cells(cpu));
+
+        prop = dt_get_property(cpu, "reg", &reg_len);
+        if ( !prop )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: has no reg property\n",
+                   dt_node_full_name(cpu));
+            continue;
+        }
+
+        if ( reg_len < dt_n_addr_cells(cpu) )
         {
-            printk(XENLOG_WARNING "cpu node `%s`: missing reg property\n",
+            printk(XENLOG_WARNING "cpu node `%s`: reg property too short\n",
                    dt_node_full_name(cpu));
             continue;
         }
 
+        addr = dt_read_number(prop, dt_n_addr_cells(cpu));
+
+        hwid = addr;
+        if ( hwid != addr )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: hwid overflow %"PRIx64"\n",
+                   dt_node_full_name(cpu), addr);
+            continue;
+        }
+
         /*
          * 8 MSBs must be set to 0 in the DT since the reg property
          * defines the MPIDR[23:0]
@@ -159,8 +183,8 @@ void __init smp_init_cpus(void)
             if ( tmp_map[j] == hwid )
             {
                 printk(XENLOG_WARNING
-                       "cpu node `%s`: duplicate /cpu reg properties in the DT\n",
-                       dt_node_full_name(cpu));
+                       "cpu node `%s`: duplicate /cpu reg properties %"PRIx32" in the DT\n",
+                       dt_node_full_name(cpu), hwid);
                 break;
             }
         }
--

1.7.10.4

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to Ian Campbell
Quoted 29 lines · Ian Campbell

The APM X-Gene Mustang board DTS has #address-cells = 2.

---
v2: Use dt_read_number, check the property length

---
  xen/arch/arm/smpboot.c |   34 +++++++++++++++++++++++++++++-----
  1 file changed, 29 insertions(+), 5 deletions(-)
xen/arch/arm/smpboot.c +6 -2
index 6c90fa6..b6a1307 100644
@@ -125,18 +125,42 @@ void __init smp_init_cpus(void)
 
      dt_for_each_child_node( cpus, cpu )
      {
-        u32 hwid;
+        const __be32 *prop;
+        u64 addr;
+        u32 reg_len, hwid;
 
          if ( !dt_device_type_is_equal(cpu, "cpu") )
              continue;
 
-        if ( !dt_property_read_u32(cpu, "reg", &hwid) )
+        if ( dt_n_size_cells(cpu) != 0 )
+            printk(XENLOG_WARNING "cpu node `%s`: #size-cells %d\n",
+                   dt_node_full_name(cpu), dt_n_size_cells(cpu));

xen/arch/arm/smpboot.c void __init smp_init_cpus(void) · line 147

Quoted 10 lines
xen/arch/arm/smpboot.c +10 -0
+
+        prop = dt_get_property(cpu, "reg", &reg_len);
+        if ( !prop )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: has no reg property\n",
+                   dt_node_full_name(cpu));
+            continue;
+        }
+
+        if ( reg_len < dt_n_addr_cells(cpu) )

dt_n_addr_cells is the number of cells not in bytes.

You must use dt_cells_to_size(dt_nr_addr_cells(cpu)), perhaps an helper would be useful here.

Signature · 1 line
Julien Grall
#3 lore raw
Quoted 3 lines · Julien Grall
Quoted 1 line

+ if ( reg_len < dt_n_addr_cells(cpu) )

dt_n_addr_cells is the number of cells not in bytes.

Gah.

Quoted 2 lines

You must use dt_cells_to_size(dt_nr_addr_cells(cpu)), perhaps an helper would be useful here.

While investigating I noticed that almost nowhere else seems to care about this and it doesn't seem that needing to is all that common. So I just went with the plain dt_cells_to_size:

Quoted 1 line

From 5a96dd424e484bc5d6c00022c4861873c06928fd Mon Sep 17 00:00:00 2001

From: Ian Campbell <[email protected]>
Date: Thu, 10 Oct 2013 13:11:46 +0100
Subject: [PATCH] xen: arm: Handle cpus nodes with #address-cells > 1

The APM X-Gene Mustang board DTS has #address-cells = 2.

---
v3: Correct check for property length (bytes not cells)
v2: Use dt_read_number, check the property length

---
 xen/arch/arm/smpboot.c |   34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
xen/arch/arm/smpboot.c +29 -5
index 6c90fa6..7636ab8 100644
@@ -125,18 +125,42 @@ void __init smp_init_cpus(void)
 
     dt_for_each_child_node( cpus, cpu )
     {
-        u32 hwid;
+        const __be32 *prop;
+        u64 addr;
+        u32 reg_len, hwid;
 
         if ( !dt_device_type_is_equal(cpu, "cpu") )
             continue;
 
-        if ( !dt_property_read_u32(cpu, "reg", &hwid) )
+        if ( dt_n_size_cells(cpu) != 0 )
+            printk(XENLOG_WARNING "cpu node `%s`: #size-cells %d\n",
+                   dt_node_full_name(cpu), dt_n_size_cells(cpu));
+
+        prop = dt_get_property(cpu, "reg", &reg_len);
+        if ( !prop )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: has no reg property\n",
+                   dt_node_full_name(cpu));
+            continue;
+        }
+
+        if ( reg_len < dt_cells_to_size(dt_n_addr_cells(cpu)) )
         {
-            printk(XENLOG_WARNING "cpu node `%s`: missing reg property\n",
+            printk(XENLOG_WARNING "cpu node `%s`: reg property too short\n",
                    dt_node_full_name(cpu));
             continue;
         }
 
+        addr = dt_read_number(prop, dt_n_addr_cells(cpu));
+
+        hwid = addr;
+        if ( hwid != addr )
+        {
+            printk(XENLOG_WARNING "cpu node `%s`: hwid overflow %"PRIx64"\n",
+                   dt_node_full_name(cpu), addr);
+            continue;
+        }
+
         /*
          * 8 MSBs must be set to 0 in the DT since the reg property
          * defines the MPIDR[23:0]
@@ -159,8 +183,8 @@ void __init smp_init_cpus(void)
             if ( tmp_map[j] == hwid )
             {
                 printk(XENLOG_WARNING
-                       "cpu node `%s`: duplicate /cpu reg properties in the DT\n",
-                       dt_node_full_name(cpu));
+                       "cpu node `%s`: duplicate /cpu reg properties %"PRIx32" in the DT\n",
+                       dt_node_full_name(cpu), hwid);
                 break;
             }
         }
Signature · 1 line
1.7.10.4