Skip to contentSkip to conversation

arm: add few checks to gic_init

PATCH In review Stefano Stabellini 2 participants 2 messages Nov 30, 2012 – Dec 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 arm: add few checks to gic_init

Check for:
- uninitialized GIC interface addresses;
- non-page aligned GIC interface addresses.

Panic in both cases.
Also remove the code from GICH and GICC to handle non-page aligned interfaces.

xen/arch/arm/gic.c +19 -4
index 8efbeb3..2b29e7e 100644
@@ -34,10 +34,8 @@
 
 /* Access to the GIC Distributor registers through the fixmap */
 #define GICD ((volatile uint32_t *) FIXMAP_ADDR(FIXMAP_GICD))
-#define GICC ((volatile uint32_t *) (FIXMAP_ADDR(FIXMAP_GICC1)  \
-                                     + ((uint32_t) gic.cbase & 0xfff)))
-#define GICH ((volatile uint32_t *) (FIXMAP_ADDR(FIXMAP_GICH)  \
-                                     + ((uint32_t) gic.hbase & 0xfff)))
+#define GICC ((volatile uint32_t *) FIXMAP_ADDR(FIXMAP_GICC1)) 
+#define GICH ((volatile uint32_t *) FIXMAP_ADDR(FIXMAP_GICH))
 static void gic_restore_pending_irqs(struct vcpu *v);
 
 /* Global state */
@@ -308,6 +306,23 @@ static void __cpuinit gic_hyp_disable(void)
 /* Set up the GIC */
 void __init gic_init(void)
 {
+    if ( !early_info.gic.gic_dist_addr ||
+         !early_info.gic.gic_cpu_addr ||
+         !early_info.gic.gic_hyp_addr ||
+         !early_info.gic.gic_vcpu_addr )
+        panic("the physical address of one of the GIC interfaces is missing:\n"
+              "        gic_dist_addr=%"PRIpaddr"\n"
+              "        gic_cpu_addr=%"PRIpaddr"\n"
+              "        gic_hyp_addr=%"PRIpaddr"\n"
+              "        gic_vcpu_addr=%"PRIpaddr"\n",
+              early_info.gic.gic_dist_addr, early_info.gic.gic_cpu_addr,
+              early_info.gic.gic_hyp_addr, early_info.gic.gic_vcpu_addr);
+    if ( (early_info.gic.gic_dist_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_cpu_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_hyp_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_vcpu_addr & ~PAGE_MASK) )
+        panic("error: GIC interfaces not page aligned.\n");
+
     gic.dbase = early_info.gic.gic_dist_addr;
     gic.cbase = early_info.gic.gic_cpu_addr;
     gic.hbase = early_info.gic.gic_hyp_addr;
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · Stefano Stabellini

Check for:
- uninitialized GIC interface addresses;
- non-page aligned GIC interface addresses.

Panic in both cases.
Also remove the code from GICH and GICC to handle non-page aligned interfaces.

I tried to apply but I got rejects. I thought this came before "xen: get GIC addresses from DT", have I got it backwards?

Quoted 6 lines

/

xen/arch/arm/gic.c +1 -0
@@ -308,6 +306,23 @@ static void __cpuinit gic_hyp_disable(void)
 /* Set up the GIC */
 void __init gic_init(void)
 {
+    if ( !early_info.gic.gic_dist_addr ||

xen/arch/arm/gic.c static void __cpuinit gic_hyp_disable(void) · line 319

Quoted 10 lines
xen/arch/arm/gic.c +10 -0
+         !early_info.gic.gic_cpu_addr ||
+         !early_info.gic.gic_hyp_addr ||
+         !early_info.gic.gic_vcpu_addr )
+        panic("the physical address of one of the GIC interfaces is missing:\n"
+              "        gic_dist_addr=%"PRIpaddr"\n"
+              "        gic_cpu_addr=%"PRIpaddr"\n"
+              "        gic_hyp_addr=%"PRIpaddr"\n"
+              "        gic_vcpu_addr=%"PRIpaddr"\n",
+              early_info.gic.gic_dist_addr, early_info.gic.gic_cpu_addr,
+              early_info.gic.gic_hyp_addr, early_info.gic.gic_vcpu_addr);

Might be worth printing these out unconditionally as part of a message about initialising the GIC (which could include version, number of interrupts etc too).

Useful in its own right but better than duplicating them in the next panic message too.

xen/arch/arm/gic.c static void __cpuinit gic_hyp_disable(void) · line 324

Quoted 5 lines
xen/arch/arm/gic.c +5 -0
+    if ( (early_info.gic.gic_dist_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_cpu_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_hyp_addr & ~PAGE_MASK) ||
+         (early_info.gic.gic_vcpu_addr & ~PAGE_MASK) )
+        panic("error: GIC interfaces not page aligned.\n");

"error: " seems a bit redundant in a panic message ;-)

Quoted 4 lines
xen/arch/arm/gic.c +1 -0
+
     gic.dbase = early_info.gic.gic_dist_addr;
     gic.cbase = early_info.gic.gic_cpu_addr;
     gic.hbase = early_info.gic.gic_hyp_addr;