Skip to contentSkip to conversation

xen/arm: Consolidate make_timer_node and make_timer_domU_node

PATCH Superseded Viktor Mitin 4 participants 16 messages Aug 1, 2019 – Aug 2, 2019

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover xen/arm: Consolidate make_timer_node and make_timer_domU_node

Functions make_timer_node and make_timer_domU_node are quite similar, so it is better to consolidate them to avoid discrepancy.

This patch series achives this goal in two steps:
- Extend fdt_property_interrupts to deal with other domain than the hwdom.
- Consolidate make_timer_node and make_timer_domU_node into one function:
make_timer_node(const struct kernel_info *kinfo)

Viktor Mitin (2):
xen/arm: extend fdt_property_interrupts to support DomU xen/arm: consolidate make_timer_node and make_timer_domU_node

 xen/arch/arm/domain_build.c | 128 +++++++++++++++---------------------
 1 file changed, 52 insertions(+), 76 deletions(-)
Signature · 7 lines
2.17.1


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

PATCH v5 1/2 xen/arm: extend fdt_property_interrupts to support DomU

Extend fdt_property_interrupts to deal with other domain than the hwdom.

The prototype of fdt_property_interrupts() has been modified to support both hwdom and domU in one function.

The new prototype of make_timer_node function is required since make_timer_node calls fdt_property_interrupts which uses kinfo:

make_timer_node(const struct kernel_info *kinfo)

This is a preparatory for the next patch which consolidates make_timer_node and make_timer_domU_node". Original goal is to consolidate make_timer functions.

---
 xen/arch/arm/domain_build.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
xen/arch/arm/domain_build.c +12 -8
index 4c8404155a..bc7d17dd2c 100644
@@ -621,17 +621,20 @@ static void __init set_interrupt(gic_interrupt_t interrupt,
  *  "interrupts": contains the list of interrupts
  *  "interrupt-parent": link to the GIC
  */
-static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr,
+static int __init fdt_property_interrupts(const struct kernel_info *kinfo,
+                                          gic_interrupt_t *intr,
                                           unsigned num_irq)
 {
     int res;
+    uint32_t phandle = is_hardware_domain(kinfo->d) ?
+                       dt_interrupt_controller->phandle : GUEST_PHANDLE_GIC;
 
-    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    res = fdt_property(kinfo->fdt, "interrupts",
+                       intr, sizeof (intr[0]) * num_irq);
     if ( res )
         return res;
 
-    res = fdt_property_cell(fdt, "interrupt-parent",
-                            dt_interrupt_controller->phandle);
+    res = fdt_property_cell(kinfo->fdt, "interrupt-parent", phandle);
 
     return res;
 }
@@ -733,7 +736,7 @@ static int __init make_hypervisor_node(struct domain *d,
      *  TODO: Handle properly the cpumask;
      */
     set_interrupt(intr, d->arch.evtchn_irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    res = fdt_property_interrupts(fdt, &intr, 1);
+    res = fdt_property_interrupts(kinfo, &intr, 1);
     if ( res )
         return res;
 
@@ -960,8 +963,9 @@ static int __init make_gic_node(const struct domain *d, void *fdt,
     return res;
 }
 
-static int __init make_timer_node(const struct domain *d, void *fdt)
+static int __init make_timer_node(const struct kernel_info *kinfo)
 {
+    void *fdt = kinfo->fdt;
     static const struct dt_device_match timer_ids[] __initconst =
     {
         DT_MATCH_COMPATIBLE("arm,armv7-timer"),
@@ -1016,7 +1020,7 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
     dt_dprintk("  Virt interrupt %u\n", irq);
     set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property_interrupts(kinfo, intrs, 3);
     if ( res )
         return res;
 
@@ -1377,7 +1381,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
     if ( device_get_class(node) == DEVICE_GIC )
         return make_gic_node(d, kinfo->fdt, node);
     if ( dt_match_node(timer_matches, node) )
-        return make_timer_node(d, kinfo->fdt);
+        return make_timer_node(kinfo);
 
     /* Skip nodes used by Xen */
     if ( dt_device_used_by(node) == DOMID_XEN )

--
2.17.1

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

Reviewed-by on v5 1/2
#2 lore raw

Re: [Xen-devel] [PATCH v5 1/2] xen/arm: extend fdt_property_interrupts to support DomU

Hi Viktor,

Quoted 8 lines · Viktor Mitin

Extend fdt_property_interrupts to deal with other domain than the hwdom.

The prototype of fdt_property_interrupts() has been modified to support both hwdom and domU in one function.

The new prototype of make_timer_node function is required since make_timer_node calls fdt_property_interrupts which uses kinfo:

Quoted 8 lines

make_timer_node(const struct kernel_info *kinfo)

This is a preparatory for the next patch which consolidates make_timer_node and make_timer_domU_node". Original goal is to consolidate make_timer functions.

Quoted 71 lines
---
 xen/arch/arm/domain_build.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
xen/arch/arm/domain_build.c +12 -8
index 4c8404155a..bc7d17dd2c 100644
@@ -621,17 +621,20 @@ static void __init set_interrupt(gic_interrupt_t interrupt,
  *  "interrupts": contains the list of interrupts
  *  "interrupt-parent": link to the GIC
  */
-static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr,
+static int __init fdt_property_interrupts(const struct kernel_info *kinfo,
+                                          gic_interrupt_t *intr,
                                           unsigned num_irq)
 {
     int res;
+    uint32_t phandle = is_hardware_domain(kinfo->d) ?
+                       dt_interrupt_controller->phandle : GUEST_PHANDLE_GIC;
 
-    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    res = fdt_property(kinfo->fdt, "interrupts",
+                       intr, sizeof (intr[0]) * num_irq);
     if ( res )
         return res;
 
-    res = fdt_property_cell(fdt, "interrupt-parent",
-                            dt_interrupt_controller->phandle);
+    res = fdt_property_cell(kinfo->fdt, "interrupt-parent", phandle);
 
     return res;
 }
@@ -733,7 +736,7 @@ static int __init make_hypervisor_node(struct domain *d,
      *  TODO: Handle properly the cpumask;
      */
     set_interrupt(intr, d->arch.evtchn_irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    res = fdt_property_interrupts(fdt, &intr, 1);
+    res = fdt_property_interrupts(kinfo, &intr, 1);
     if ( res )
         return res;
 
@@ -960,8 +963,9 @@ static int __init make_gic_node(const struct domain *d, void *fdt,
     return res;
 }
 
-static int __init make_timer_node(const struct domain *d, void *fdt)
+static int __init make_timer_node(const struct kernel_info *kinfo)
 {
+    void *fdt = kinfo->fdt;
     static const struct dt_device_match timer_ids[] __initconst =
     {
         DT_MATCH_COMPATIBLE("arm,armv7-timer"),
@@ -1016,7 +1020,7 @@ static int __init make_timer_node(const struct domain *d, void *fdt)
     dt_dprintk("  Virt interrupt %u\n", irq);
     set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
-    res = fdt_property_interrupts(fdt, intrs, 3);
+    res = fdt_property_interrupts(kinfo, intrs, 3);
     if ( res )
         return res;
 
@@ -1377,7 +1381,7 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
     if ( device_get_class(node) == DEVICE_GIC )
         return make_gic_node(d, kinfo->fdt, node);
     if ( dt_match_node(timer_matches, node) )
-        return make_timer_node(d, kinfo->fdt);
+        return make_timer_node(kinfo);
 
     /* Skip nodes used by Xen */
     if ( dt_device_used_by(node) == DOMID_XEN )
Signature · 5 lines
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

Re: [Xen-devel] [PATCH v5 1/2] xen/arm: extend fdt_property_interrupts to support DomU

Quoted 17 lines · Volodymyr Babchuk
Quoted 17 lines
xen/arch/arm/domain_build.c +4 -1
index 4c8404155a..bc7d17dd2c 100644
@@ -621,17 +621,20 @@ static void __init set_interrupt(gic_interrupt_t interrupt,
  *  "interrupts": contains the list of interrupts
  *  "interrupt-parent": link to the GIC
  */
-static int __init fdt_property_interrupts(void *fdt, gic_interrupt_t *intr,
+static int __init fdt_property_interrupts(const struct kernel_info *kinfo,
+                                          gic_interrupt_t *intr,
                                           unsigned num_irq)
 {
     int res;
+    uint32_t phandle = is_hardware_domain(kinfo->d) ?
+                       dt_interrupt_controller->phandle : GUEST_PHANDLE_GIC;
 
Quoted 3 lines

xen/arch/arm/domain_build.c static void __init set_interrupt(gic_interrupt_t interrupt, · line 633

Quoted 3 lines
xen/arch/arm/domain_build.c +2 -1
-    res = fdt_property(fdt, "interrupts", intr, sizeof (intr[0]) * num_irq);
+    res = fdt_property(kinfo->fdt, "interrupts",
+                       intr, sizeof (intr[0]) * num_irq);

Just as a minor style point seeing as these are in discussion at the moment.  sizeof() is written without a space, as if it was a function not an operator.

This can easily be fixed on commit.

Everything else I can spot looks fine.

~Andrew

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

#4 lore raw

PATCH v5 2/2 xen/arm: consolidate make_timer_node and make_timer_domU_node

In reply to Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
 xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
 1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +39 -67
index bc7d17dd2c..58542130ca 100644
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
         { /* sentinel */ },
     };
     struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
     int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];
     gic_interrupt_t intrs[3];
     u32 clock_frequency;
     bool clock_valid;
@@ -990,35 +988,49 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
         return -FDT_ERR_XEN(ENOENT);
     }
 
-    compatible = dt_get_property(dev, "compatible", &len);
-    if ( !compatible )
-    {
-        dprintk(XENLOG_ERR, "Can't find compatible property for timer node\n");
-        return -FDT_ERR_XEN(ENOENT);
-    }
-
     res = fdt_begin_node(fdt, "timer");
     if ( res )
         return res;
 
-    res = fdt_property(fdt, "compatible", compatible, len);
-    if ( res )
-        return res;
-
-    /* The timer IRQ is emulated by Xen. It always exposes an active-low
-     * level-sensitive interrupt */
-
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
-    dt_dprintk("  Secure interrupt %u\n", irq);
-    set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    if ( !is_64bit_domain(kinfo->d) )
+    {
+        res = fdt_property_string(fdt, "compatible", "arm,armv7-timer");
+        if ( res )
+            return res;
+    }
+    else
+    {
+        res = fdt_property_string(fdt, "compatible", "arm,armv8-timer");
+        if ( res )
+            return res;
+    }
 
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
-    dt_dprintk("  Non secure interrupt %u\n", irq);
-    set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    /*
+     * The timer IRQ is emulated by Xen.
+     * It always exposes an active-low level-sensitive interrupt
+     */
 
-    irq = timer_get_irq(TIMER_VIRT_PPI);
-    dt_dprintk("  Virt interrupt %u\n", irq);
-    set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    if ( is_hardware_domain(kinfo->d) )
+    {
+        irq[TIMER_PHYS_SECURE_PPI] = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+        irq[TIMER_PHYS_NONSECURE_PPI] =
+                                    timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+        irq[TIMER_VIRT_PPI] = timer_get_irq(TIMER_VIRT_PPI);
+    }
+    else
+    {
+        irq[TIMER_PHYS_SECURE_PPI] = GUEST_TIMER_PHYS_S_PPI;
+        irq[TIMER_PHYS_NONSECURE_PPI] = GUEST_TIMER_PHYS_NS_PPI;
+        irq[TIMER_VIRT_PPI] = GUEST_TIMER_VIRT_PPI;
+    }
+    dt_dprintk("  Secure interrupt %u\n", irq[TIMER_PHYS_SECURE_PPI]);
+    set_interrupt(intrs[0], irq[TIMER_PHYS_SECURE_PPI],
+                  0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    dt_dprintk("  Non secure interrupt %u\n", irq[TIMER_PHYS_NONSECURE_PPI]);
+    set_interrupt(intrs[1], irq[TIMER_PHYS_NONSECURE_PPI],
+                  0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    dt_dprintk("  Virt interrupt %u\n", irq[TIMER_VIRT_PPI]);
+    set_interrupt(intrs[2], irq[TIMER_VIRT_PPI], 0xf, DT_IRQ_TYPE_LEVEL_LOW);
 
     res = fdt_property_interrupts(kinfo, intrs, 3);
     if ( res )
@@ -1603,46 +1615,6 @@ static int __init make_gic_domU_node(const struct domain *d, void *fdt)
     }
 }
 
-static int __init make_timer_domU_node(const struct domain *d, void *fdt)
-{
-    int res;
-    gic_interrupt_t intrs[3];
-
-    res = fdt_begin_node(fdt, "timer");
-    if ( res )
-        return res;
-
-    if ( !is_64bit_domain(d) )
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv7-timer");
-        if ( res )
-            return res;
-    }
-    else
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv8-timer");
-        if ( res )
-            return res;
-    }
-
-    set_interrupt(intrs[0], GUEST_TIMER_PHYS_S_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[1], GUEST_TIMER_PHYS_NS_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[2], GUEST_TIMER_VIRT_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-
-    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
-    if ( res )
-        return res;
-
-    res = fdt_property_cell(fdt, "interrupt-parent",
-                            GUEST_PHANDLE_GIC);
-    if (res)
-        return res;
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 #ifdef CONFIG_SBSA_VUART_CONSOLE
 static int __init make_vpl011_uart_node(const struct domain *d, void *fdt)
 {
@@ -1748,7 +1720,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
     if ( ret )
         goto err;
 
-    ret = make_timer_domU_node(d, kinfo->fdt);
+    ret = make_timer_node(kinfo);
     if ( ret )
         goto err;
 
Signature · 7 lines
2.17.1


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

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 26 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
 xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
 1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index bc7d17dd2c..58542130ca 100644

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 8 lines
xen/arch/arm/domain_build.c +1 -3
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
         { /* sentinel */ },
     };
     struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
     int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 30 lines
xen/arch/arm/domain_build.c +2 -17
     gic_interrupt_t intrs[3];
     u32 clock_frequency;
     bool clock_valid;
@@ -990,35 +988,49 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
         return -FDT_ERR_XEN(ENOENT);
     }
 
-    compatible = dt_get_property(dev, "compatible", &len);
-    if ( !compatible )
-    {
-        dprintk(XENLOG_ERR, "Can't find compatible property for timer node\n");
-        return -FDT_ERR_XEN(ENOENT);
-    }
-
     res = fdt_begin_node(fdt, "timer");
     if ( res )
         return res;
 
-    res = fdt_property(fdt, "compatible", compatible, len);
-    if ( res )
-        return res;
-
-    /* The timer IRQ is emulated by Xen. It always exposes an active-low
-     * level-sensitive interrupt */
-
-    irq = timer_get_irq(TIMER_PHYS_SECURE_PPI);
-    dt_dprintk("  Secure interrupt %u\n", irq);
-    set_interrupt(intrs[0], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    if ( !is_64bit_domain(kinfo->d) )
+    {

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 1006

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+        res = fdt_property_string(fdt, "compatible", "arm,armv7-timer");
+        if ( res )
+            return res;
+    }
+    else
+    {
+        res = fdt_property_string(fdt, "compatible", "arm,armv8-timer");
+        if ( res )
+            return res;
+    }

Both cases bear the same piece of code:
if ( res )
return res;

You can move it out of outer "if". This will make code shorter and simpler.

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 1011

Quoted 8 lines
xen/arch/arm/domain_build.c +4 -3
-    irq = timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
-    dt_dprintk("  Non secure interrupt %u\n", irq);
-    set_interrupt(intrs[1], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    /*
+     * The timer IRQ is emulated by Xen.
+     * It always exposes an active-low level-sensitive interrupt
+     */

Missing full stop at the end of the last sentence.

Quoted 15 lines
xen/arch/arm/domain_build.c +11 -3
-    irq = timer_get_irq(TIMER_VIRT_PPI);
-    dt_dprintk("  Virt interrupt %u\n", irq);
-    set_interrupt(intrs[2], irq, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    if ( is_hardware_domain(kinfo->d) )
+    {
+        irq[TIMER_PHYS_SECURE_PPI] = timer_get_irq(TIMER_PHYS_SECURE_PPI);
+        irq[TIMER_PHYS_NONSECURE_PPI] =
+                                    timer_get_irq(TIMER_PHYS_NONSECURE_PPI);
+        irq[TIMER_VIRT_PPI] = timer_get_irq(TIMER_VIRT_PPI);
+    }
+    else
+    {
+        irq[TIMER_PHYS_SECURE_PPI] = GUEST_TIMER_PHYS_S_PPI;
+        irq[TIMER_PHYS_NONSECURE_PPI] = GUEST_TIMER_PHYS_NS_PPI;

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 1033

Quoted 10 lines
xen/arch/arm/domain_build.c +10 -0
+        irq[TIMER_VIRT_PPI] = GUEST_TIMER_VIRT_PPI;
+    }
+    dt_dprintk("  Secure interrupt %u\n", irq[TIMER_PHYS_SECURE_PPI]);
+    set_interrupt(intrs[0], irq[TIMER_PHYS_SECURE_PPI],
+                  0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    dt_dprintk("  Non secure interrupt %u\n", irq[TIMER_PHYS_NONSECURE_PPI]);
+    set_interrupt(intrs[1], irq[TIMER_PHYS_NONSECURE_PPI],
+                  0xf, DT_IRQ_TYPE_LEVEL_LOW);
+    dt_dprintk("  Virt interrupt %u\n", irq[TIMER_VIRT_PPI]);
+    set_interrupt(intrs[2], irq[TIMER_VIRT_PPI], 0xf, DT_IRQ_TYPE_LEVEL_LOW);

Why are you using plain indexes for intrs[] and enums for irq[]?

Quoted 51 lines
xen/arch/arm/domain_build.c +0 -40
     res = fdt_property_interrupts(kinfo, intrs, 3);
     if ( res )
@@ -1603,46 +1615,6 @@ static int __init make_gic_domU_node(const struct domain *d, void *fdt)
     }
 }
 
-static int __init make_timer_domU_node(const struct domain *d, void *fdt)
-{
-    int res;
-    gic_interrupt_t intrs[3];
-
-    res = fdt_begin_node(fdt, "timer");
-    if ( res )
-        return res;
-
-    if ( !is_64bit_domain(d) )
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv7-timer");
-        if ( res )
-            return res;
-    }
-    else
-    {
-        res = fdt_property_string(fdt, "compatible", "arm,armv8-timer");
-        if ( res )
-            return res;
-    }
-
-    set_interrupt(intrs[0], GUEST_TIMER_PHYS_S_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[1], GUEST_TIMER_PHYS_NS_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-    set_interrupt(intrs[2], GUEST_TIMER_VIRT_PPI, 0xf, DT_IRQ_TYPE_LEVEL_LOW);
-
-    res = fdt_property(fdt, "interrupts", intrs, sizeof (intrs[0]) * 3);
-    if ( res )
-        return res;
-
-    res = fdt_property_cell(fdt, "interrupt-parent",
-                            GUEST_PHANDLE_GIC);
-    if (res)
-        return res;
-
-    res = fdt_end_node(fdt);
-
-    return res;
-}
-
 #ifdef CONFIG_SBSA_VUART_CONSOLE
 static int __init make_vpl011_uart_node(const struct domain *d, void *fdt)
 {

xen/arch/arm/domain_build.c static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo) · line 1725

Quoted 7 lines
xen/arch/arm/domain_build.c +1 -1
@@ -1748,7 +1720,7 @@ static int __init prepare_dtb_domU(struct domain *d, struct kernel_info *kinfo)
     if ( ret )
         goto err;
 
-    ret = make_timer_domU_node(d, kinfo->fdt);
+    ret = make_timer_node(kinfo);
     if ( ret )
         goto err;

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

#6 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Hi,

Quoted 48 lines · Volodymyr Babchuk
Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 31 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
  xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
  1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -2
index bc7d17dd2c..58542130ca 100644
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
          { /* sentinel */ },
      };
      struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -1
      int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 61 lines · Julien Grall

Hi,

Quoted 49 lines · Volodymyr Babchuk
Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 32 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
    updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
     - changed 'kept' to 'keep', etc.
     - removed empty line
     - updated indentation of parameters in functions calls
     - fixed NITs
     - updated commit message
---
  xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------

  1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -2
index bc7d17dd2c..58542130ca 100644
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct 
 kernel_info *kinfo)
           { /* sentinel */ },
       };
       struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -1
       int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 1 line

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

I forgot to mention. @Viktor, it is good to try to reply to each comment at least those you don't plan to address. So the reviewer doesn't have the feeling comments are ignored...

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 v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 18 lines · Julien Grall
Quoted 7 lines · Julien Grall
Quoted 6 lines
Quoted 1 line

+ unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 5 lines

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Quoted 3 lines

I forgot to mention. @Viktor, it is good to try to reply to each comment at least those you don't plan to address. So the reviewer doesn't have the feeling comments are ignored...

Well, I address each of the comments or write about it explicitly in other cases.
In this particular case, I'd added '-1', but later did not merge it due to mistake.
So it supposed to be the next:
+ unsigned int irq[MAX_TIMER_PPI-1]

There are no comments ignored from my side, at least not intentionally. In this case, there were myriads of the small things, like add space here or remove empty line there.
I did not agree with all of them, however, in the next version (in v5), all of them have been addressed.

Thanks

Quoted 4 lines

Cheers,

--
Julien Grall

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

#9 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Hi Viktor,

Quoted 23 lines · Viktor Mitin
Quoted 18 lines · Julien Grall
Quoted 7 lines · Julien Grall
Quoted 6 lines
Quoted 1 line

+ unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 5 lines

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Quoted 3 lines

I forgot to mention. @Viktor, it is good to try to reply to each comment at least those you don't plan to address. So the reviewer doesn't have the feeling comments are ignored...

Quoted 6 lines

Well, I address each of the comments or write about it explicitly in other cases.
In this particular case, I'd added '-1', but later did not merge it due to mistake.
So it supposed to be the next:
+ unsigned int irq[MAX_TIMER_PPI-1]

Please no '-1', it is worst than hardcoding value. In the code you are using an element of an enum to access the array. There are no guarantee the last element is actually the one you want to drop and therefore you risk to overflow it if mistakenly used.

The risk is not worth compare to saving just 4-byte on the stack.

Cheers,

Signature · 6 lines
Julien Grall

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

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 8 lines · Julien Grall
Quoted 7 lines

Well, I address each of the comments or write about it explicitly in other cases.
In this particular case, I'd added '-1', but later did not merge it due to mistake.
So it supposed to be the next:
+ unsigned int irq[MAX_TIMER_PPI-1]

Quoted 5 lines

Please no '-1', it is worst than hardcoding value. In the code you are using an element of an enum to access the array. There are no guarantee the last element is actually the one you want to drop and therefore you risk to overflow it if mistakenly used.

I agree that using -1 is not the best idea. It would be better to introduce a new enum for that. However, since we already have the enum with 4 items for that, it is better to use it as is.

Quoted 1 line

The risk is not worth compare to saving just 4-byte on the stack.

Completely agree about it, so I will use MAX_TIMER_PPI(as it is done now) in the next patch series version,

Thanks

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

#11 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

In reply to Julien Grall

Hi Julien,

Quoted 60 lines · Julien Grall

Hi,

Quoted 48 lines · Volodymyr Babchuk
Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 31 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
  xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
  1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -2
index bc7d17dd2c..58542130ca 100644
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
          { /* sentinel */ },
      };
      struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -1
      int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 5 lines

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Yes, but then it should be documented at least. Comment above will be fine. In this case we also can declare and use intrs[] in the same way.

Signature · 5 lines
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#12 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Hi Volodymyr,

Quoted 65 lines · Volodymyr Babchuk

Hi Julien,

Quoted 60 lines · Julien Grall

Hi,

Quoted 56 lines · Volodymyr Babchuk
Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 26 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
   xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
   1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -0
index bc7d17dd2c..58542130ca 100644

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 8 lines
xen/arch/arm/domain_build.c +1 -3
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
           { /* sentinel */ },
       };
       struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
       int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

Quoted 7 lines
Quoted 5 lines

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Yes, but then it should be documented at least. Comment above will be fine.

I don't really see the problem with the current code... This is similar to when we use a structure but not all the field in certain circumstance (see dt_device_match for instance). So I would not force the contributor to do it.

Quoted 1 line

In this case we also can declare and use intrs[] in the same way.

There is no guarantee the index in irq will match intrs[...]. So you need to keep them hardcoded in the latter case.

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 v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 73 lines · Julien Grall

Hi Volodymyr,

Quoted 70 lines · Volodymyr Babchuk

Hi Julien,

Quoted 65 lines · Julien Grall

Hi,

Quoted 48 lines · Volodymyr Babchuk
Quoted 8 lines · Viktor Mitin

Functions make_timer_node and make_timer_domU_node are quite similar. So it is better to consolidate them to avoid discrepancy. The main difference between the functions is the timer interrupts used.

Keep the domU version for the compatible as it is simpler. Mean do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type.

It is hard to parse the last sentence. What about "Keep the domU version for the compatible as it is simpler: do not copy platform's 'compatible' property into hwdom device tree, instead set either arm,armv7-timer or arm,armv8-timer, depending on the platform type." ?

Quoted 31 lines

Keep the hw version for the clock as it is relevant for the both cases.

The new function has changed prototype due to fdt_property_interrupts
make_timer_node(const struct kernel_info *kinfo)

---
v4 updates:
updated "Keep the domU version for the compatible as it is simpler"

v5 updates:
- changed 'kept' to 'keep', etc.
- removed empty line
- updated indentation of parameters in functions calls
- fixed NITs
- updated commit message

---
   xen/arch/arm/domain_build.c | 106 +++++++++++++-----------------------
   1 file changed, 39 insertions(+), 67 deletions(-)
xen/arch/arm/domain_build.c +0 -2
index bc7d17dd2c..58542130ca 100644
@@ -973,10 +973,8 @@ static int __init make_timer_node(const struct kernel_info *kinfo)
           { /* sentinel */ },
       };
       struct dt_device_node *dev;
-    u32 len;
-    const void *compatible;
Quoted 8 lines

xen/arch/arm/domain_build.c static int __init make_timer_node(const struct kernel_info *kinfo) · line 977

Quoted 3 lines
xen/arch/arm/domain_build.c +1 -1
       int res;
-    unsigned int irq;
+    unsigned int irq[MAX_TIMER_PPI];

As I said in the previous version, you are wasting stack space there. Also, this is misleading. When I see array of 4 items, I expect that all 4 items will be used. But you are using only 3, so it leads to two conclusions: either you made a mistake, or I don't understand what it happening. Either option is bad.

4 byte on a stack of 16KB... that's not really a waste worth an argument. The more the stack is pretty empty as this is boot. So yes, you will not use the last index because you don't expose hypervisor timer to guest yet! (Imagine nested virt). But at least it avoids hardcoding a number of index and match the enum.

Quoted 7 lines
Quoted 2 lines

Yes, but then it should be documented at least. Comment above will be fine.

I don't really see the problem with the current code... This is similar to when we use a structure but not all the field in certain circumstance (see dt_device_match for instance). So I would not force the contributor to do it.

Okay, then.

Quoted 4 lines
Quoted 1 line

In this case we also can declare and use intrs[] in the same way.

There is no guarantee the index in irq will match intrs[...]. So you need to keep them hardcoded in the latter case.

Oh, right.

Signature · 5 lines
Volodymyr Babchuk at EPAM
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#14 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Quoted 5 lines · Volodymyr Babchuk
Quoted 4 lines
Quoted 1 line

In this case we also can declare and use intrs[] in the same way.

There is no guarantee the index in irq will match intrs[...]. So you need to keep them hardcoded in the latter case.

Oh, right.

I don't like the idea of using hardcoded numbers in the code. BTW, Misra rule says it should not be used as well. However, in this case, I did not change it, because it should be done in another patch. Anyway, hardcoded numbers should be avoided in the code, it seems this is a good candidate for a new Xen coding style rule if we want to achieve Misra compliance someday.

Thanks

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

#15 lore raw

Re: [Xen-devel] [PATCH v5 2/2] xen/arm: consolidate make_timer_node and make_timer_domU_node

Hi,

Quoted 11 lines · Viktor Mitin
Quoted 5 lines · Volodymyr Babchuk
Quoted 4 lines
Quoted 1 line

In this case we also can declare and use intrs[] in the same way.

There is no guarantee the index in irq will match intrs[...]. So you need to keep them hardcoded in the latter case.

Oh, right.

I don't like the idea of using hardcoded numbers in the code. BTW, Misra rule says it should not be used as well.

When mentioning a spec, it is common to also specify the exact section so others don't have to spend time look for it.

I skimmed quickly through the MISRA and can't find the rule you suggest here. Furthermore, they have a lot of examples in the spec with harcoded size. So I am perplexed they actively discourage it...

Cheers,

Signature · 6 lines
Julien Grall

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