Skip to contentSkip to conversation

xen/arm: gic: Make sure the number of interrupt lines is valid before using it

PATCH In review Julien Grall 3 participants 4 messages Nov 30, 2018 – Jan 23, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: gic: Make sure the number of interrupt lines is valid before using it

GICv2 and GICv3 supports up to 1020 interrupts. However, the value computed from GICD_TYPER.ITLinesNumber can be up to 1024. On GICv3, we will end up to write in reserved registers that are right after the IROUTERs one as the value is not capped early enough.

Cap the number of interrupts as soon as we compute it so we know we can safely using it afterwards.

---
This patch should be backport up to Xen 4.9.

---
 xen/arch/arm/gic-v2.c | 7 ++++---
 xen/arch/arm/gic-v3.c | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
xen/arch/arm/gic-v2.c +4 -3
index 1a744c576f..e9fb8a01ab 100644
@@ -353,6 +353,10 @@ static void __init gicv2_dist_init(void)
 
     type = readl_gicd(GICD_TYPER);
     nr_lines = 32 * ((type & GICD_TYPE_LINES) + 1);
+    /* Only 1020 interrupts are supported */
+    nr_lines = min(1020U, nr_lines);
+    gicv2_info.nr_lines = nr_lines;
+
     gic_cpus = 1 + ((type & GICD_TYPE_CPUS) >> 5);
     printk("GICv2: %d lines, %d cpu%s%s (IID %8.8x).\n",
            nr_lines, gic_cpus, (gic_cpus == 1) ? "" : "s",
@@ -377,9 +381,6 @@ static void __init gicv2_dist_init(void)
     for ( i = 32; i < nr_lines; i += 32 )
         writel_gicd(~0x0, GICD_ICENABLER + (i / 32) * 4);
 
-    /* Only 1020 interrupts are supported */
-    gicv2_info.nr_lines = min(1020U, nr_lines);
-
     /* Turn on the distributor */
     writel_gicd(GICD_CTL_ENABLE, GICD_CTLR);
 }
xen/arch/arm/gic-v3.c +4 -3
index 6fbc106757..c9200d24e1 100644
@@ -607,6 +607,10 @@ static void __init gicv3_dist_init(void)
     if ( type & GICD_TYPE_LPIS )
         gicv3_lpi_init_host_lpis(GICD_TYPE_ID_BITS(type));
 
+    /* Only 1020 interrupts are supported */
+    nr_lines = min(1020U, nr_lines);
+    gicv3_info.nr_lines = nr_lines;
+
     printk("GICv3: %d lines, (IID %8.8x).\n",
            nr_lines, readl_relaxed(GICD + GICD_IIDR));
 
@@ -646,9 +650,6 @@ static void __init gicv3_dist_init(void)
 
     for ( i = NR_GIC_LOCAL_IRQS; i < nr_lines; i++ )
         writeq_relaxed(affinity, GICD + GICD_IROUTER + i * 8);
-
-    /* Only 1020 interrupts are supported */
-    gicv3_info.nr_lines = min(1020U, nr_lines);
 }
 
 static int gicv3_enable_redist(void)
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Julien Grall

GICv2 and GICv3 supports up to 1020 interrupts. However, the value computed from GICD_TYPER.ITLinesNumber can be up to 1024. On GICv3, we will end up to write in reserved registers that are right after the IROUTERs one as the value is not capped early enough.

Cap the number of interrupts as soon as we compute it so we know we can safely using it afterwards.

Quoted 2 lines

---
This patch should be backport up to Xen 4.9.

Agreed

Quoted 58 lines
---
 xen/arch/arm/gic-v2.c | 7 ++++---
 xen/arch/arm/gic-v3.c | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)
xen/arch/arm/gic-v2.c +4 -3
index 1a744c576f..e9fb8a01ab 100644
@@ -353,6 +353,10 @@ static void __init gicv2_dist_init(void)
 
     type = readl_gicd(GICD_TYPER);
     nr_lines = 32 * ((type & GICD_TYPE_LINES) + 1);
+    /* Only 1020 interrupts are supported */
+    nr_lines = min(1020U, nr_lines);
+    gicv2_info.nr_lines = nr_lines;
+
     gic_cpus = 1 + ((type & GICD_TYPE_CPUS) >> 5);
     printk("GICv2: %d lines, %d cpu%s%s (IID %8.8x).\n",
            nr_lines, gic_cpus, (gic_cpus == 1) ? "" : "s",
@@ -377,9 +381,6 @@ static void __init gicv2_dist_init(void)
     for ( i = 32; i < nr_lines; i += 32 )
         writel_gicd(~0x0, GICD_ICENABLER + (i / 32) * 4);
 
-    /* Only 1020 interrupts are supported */
-    gicv2_info.nr_lines = min(1020U, nr_lines);
-
     /* Turn on the distributor */
     writel_gicd(GICD_CTL_ENABLE, GICD_CTLR);
 }
xen/arch/arm/gic-v3.c +4 -3
index 6fbc106757..c9200d24e1 100644
@@ -607,6 +607,10 @@ static void __init gicv3_dist_init(void)
     if ( type & GICD_TYPE_LPIS )
         gicv3_lpi_init_host_lpis(GICD_TYPE_ID_BITS(type));
 
+    /* Only 1020 interrupts are supported */
+    nr_lines = min(1020U, nr_lines);
+    gicv3_info.nr_lines = nr_lines;
+
     printk("GICv3: %d lines, (IID %8.8x).\n",
            nr_lines, readl_relaxed(GICD + GICD_IIDR));
 
@@ -646,9 +650,6 @@ static void __init gicv3_dist_init(void)
 
     for ( i = NR_GIC_LOCAL_IRQS; i < nr_lines; i++ )
         writeq_relaxed(affinity, GICD + GICD_IROUTER + i * 8);
-
-    /* Only 1020 interrupts are supported */
-    gicv3_info.nr_lines = min(1020U, nr_lines);
 }
 
 static int gicv3_enable_redist(void)
Signature · 1 line
2.11.0

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

#2 lore raw

(+ Juergen)

Hi Juergen,

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

GICv2 and GICv3 supports up to 1020 interrupts. However, the value computed from GICD_TYPER.ITLinesNumber can be up to 1024. On GICv3, we will end up to write in reserved registers that are right after the IROUTERs one as the value is not capped early enough.

Quoted 7 lines
Quoted 5 lines

Cap the number of interrupts as soon as we compute it so we know we can safely using it afterwards.

Would it be possible to give an RAB for this patch?

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw
Quoted 16 lines · Julien Grall

(+ Juergen)

Hi Juergen,

Quoted 11 lines · Stefano Stabellini
Quoted 10 lines · Julien Grall

GICv2 and GICv3 supports up to 1020 interrupts. However, the value computed
from GICD_TYPER.ITLinesNumber can be up to 1024. On GICv3, we will end up to
write in reserved registers that are right after the IROUTERs one as the value is not capped early enough.

Cap the number of interrupts as soon as we compute it so we know we can safely using it afterwards.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Would it be possible to give an RAB for this patch?

Juergen

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