Skip to contentSkip to conversation

arm: gic: enable GIC MMIO tests for GICv3 as well

PATCH In review Andre Przywara 2 participants 3 messages Sep 5, 2019 – Sep 6, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: gic: enable GIC MMIO tests for GICv3 as well

So far the GIC MMIO tests were only enabled for a GICv2 guest. Modern machines tend to have a GICv3-only GIC, so can't run those guests. It turns out that most GIC distributor registers we test in the unit tests are actually the same in GICv3, so we can just enable those tests for GICv3 guests as well.
The only exception is the CPU number in the TYPER register, which we just protect against running on a GICv3 guest.

---
 arm/gic.c         | 13 +++++++++++--
 arm/unittests.cfg | 16 +++++++++++-----
 lib/arm/asm/gic.h |  2 ++
 3 files changed, 24 insertions(+), 7 deletions(-)
arm/gic.c +11 -2
index ed5642e..bd3c027 100644
@@ -6,6 +6,7 @@
  *   + MMIO access tests
  * GICv3
  *   + test sending/receiving IPIs
+ *   + MMIO access tests
  *
  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
  *
@@ -483,7 +484,14 @@ static void gic_test_mmio(void)
 		idreg = gic_dist_base + GICD_ICPIDR2;
 		break;
 	case 0x3:
-		report_abort("GICv3 MMIO tests NYI");
+		/*
+		 * We only test generic registers or those affecting
+		 * SPIs, so don't need to consider the SGI base in
+		 * the redistributor here.
+		 */
+		gic_dist_base = gicv3_dist_base();
+		idreg = gic_dist_base + GICD_PIDR2;
+		break;
 	default:
 		report_abort("GIC version %d not supported", gic_version());
 	}
@@ -492,7 +500,8 @@ static void gic_test_mmio(void)
 	nr_irqs = GICD_TYPER_IRQS(reg);
 	report_info("number of implemented SPIs: %d", nr_irqs - GIC_FIRST_SPI);
 
-	test_typer_v2(reg);
+	if (gic_version() == 0x2)
+		test_typer_v2(reg);
 
 	report_info("IIDR: 0x%08x", readl(gic_dist_base + GICD_IIDR));
 
arm/unittests.cfg +11 -5
index 6d3df92..3fd5b04 100644
@@ -86,22 +86,28 @@ smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'ipi'
 groups = gic
 
-[gicv2-mmio]
+[gicv2-max-mmio]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
-[gicv2-mmio-up]
+[gicv3-max-mmio]
+file = gic.flat
+smp = $MAX_SMP
+extra_params = -machine gic-version=3 -append 'mmio'
+groups = gic
+
+[gic-mmio-up]
 file = gic.flat
 smp = 1
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
-[gicv2-mmio-3p]
+[gic-mmio-3p]
 file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
 [gicv3-ipi]
lib/arm/asm/gic.h +2 -0
index f6dfb90..ffed025 100644
@@ -23,6 +23,8 @@
 #define GICD_ITARGETSR			0x0800
 #define GICD_SGIR			0x0f00
 #define GICD_ICPIDR2			0x0fe8
+/* only in GICv3 */
+#define GICD_PIDR2			0xffe8
 
 #define GICD_TYPER_IRQS(typer)		((((typer) & 0x1f) + 1) * 32)
 #define GICD_INT_EN_SET_SGI		0x0000ffff
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 96 lines · Andre Przywara

So far the GIC MMIO tests were only enabled for a GICv2 guest. Modern machines tend to have a GICv3-only GIC, so can't run those guests. It turns out that most GIC distributor registers we test in the unit tests are actually the same in GICv3, so we can just enable those tests for GICv3 guests as well.
The only exception is the CPU number in the TYPER register, which we just protect against running on a GICv3 guest.

---
 arm/gic.c         | 13 +++++++++++--
 arm/unittests.cfg | 16 +++++++++++-----
 lib/arm/asm/gic.h |  2 ++
 3 files changed, 24 insertions(+), 7 deletions(-)
arm/gic.c +11 -2
index ed5642e..bd3c027 100644
@@ -6,6 +6,7 @@
  *   + MMIO access tests
  * GICv3
  *   + test sending/receiving IPIs
+ *   + MMIO access tests
  *
  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
  *
@@ -483,7 +484,14 @@ static void gic_test_mmio(void)
 		idreg = gic_dist_base + GICD_ICPIDR2;
 		break;
 	case 0x3:
-		report_abort("GICv3 MMIO tests NYI");
+		/*
+		 * We only test generic registers or those affecting
+		 * SPIs, so don't need to consider the SGI base in
+		 * the redistributor here.
+		 */
+		gic_dist_base = gicv3_dist_base();
+		idreg = gic_dist_base + GICD_PIDR2;
+		break;
 	default:
 		report_abort("GIC version %d not supported", gic_version());
 	}
@@ -492,7 +500,8 @@ static void gic_test_mmio(void)
 	nr_irqs = GICD_TYPER_IRQS(reg);
 	report_info("number of implemented SPIs: %d", nr_irqs - GIC_FIRST_SPI);
 
-	test_typer_v2(reg);
+	if (gic_version() == 0x2)
+		test_typer_v2(reg);
 
 	report_info("IIDR: 0x%08x", readl(gic_dist_base + GICD_IIDR));
 
arm/unittests.cfg +11 -5
index 6d3df92..3fd5b04 100644
@@ -86,22 +86,28 @@ smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'ipi'
 groups = gic
 
-[gicv2-mmio]
+[gicv2-max-mmio]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
-[gicv2-mmio-up]
+[gicv3-max-mmio]
+file = gic.flat
+smp = $MAX_SMP
+extra_params = -machine gic-version=3 -append 'mmio'
+groups = gic
+
+[gic-mmio-up]
 file = gic.flat
 smp = 1
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
-[gicv2-mmio-3p]
+[gic-mmio-3p]
 file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
 [gicv3-ipi]
lib/arm/asm/gic.h +0 -0
index f6dfb90..ffed025 100644

lib/arm/asm/gic.h line 27

Quoted 5 lines
lib/arm/asm/gic.h +2 -0
@@ -23,6 +23,8 @@
 #define GICD_ITARGETSR			0x0800
 #define GICD_SGIR			0x0f00
 #define GICD_ICPIDR2			0x0fe8
+/* only in GICv3 */
+#define GICD_PIDR2			0xffe8

If this is gicv3-only, then shouldn't it go to lib/arm/asm/gic-v3.h ?

Quoted 6 lines
lib/arm/asm/gic.h +0 -0
 #define GICD_TYPER_IRQS(typer)		((((typer) & 0x1f) + 1) * 32)
 #define GICD_INT_EN_SET_SGI		0x0000ffff
Signature · 1 line
2.17.1

Otherwise

#2 lore raw

On Fri, 6 Sep 2019 08:48:37 +0200
Andrew Jones <[email protected]> wrote:

Hi,

Quoted 91 lines · Andre Przywara
Quoted 90 lines

So far the GIC MMIO tests were only enabled for a GICv2 guest. Modern machines tend to have a GICv3-only GIC, so can't run those guests. It turns out that most GIC distributor registers we test in the unit tests are actually the same in GICv3, so we can just enable those tests for GICv3 guests as well.
The only exception is the CPU number in the TYPER register, which we just protect against running on a GICv3 guest.

---
 arm/gic.c         | 13 +++++++++++--
 arm/unittests.cfg | 16 +++++++++++-----
 lib/arm/asm/gic.h |  2 ++
 3 files changed, 24 insertions(+), 7 deletions(-)
arm/gic.c +11 -2
index ed5642e..bd3c027 100644
@@ -6,6 +6,7 @@
  *   + MMIO access tests
  * GICv3
  *   + test sending/receiving IPIs
+ *   + MMIO access tests
  *
  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <[email protected]>
  *
@@ -483,7 +484,14 @@ static void gic_test_mmio(void)
 		idreg = gic_dist_base + GICD_ICPIDR2;
 		break;
 	case 0x3:
-		report_abort("GICv3 MMIO tests NYI");
+		/*
+		 * We only test generic registers or those affecting
+		 * SPIs, so don't need to consider the SGI base in
+		 * the redistributor here.
+		 */
+		gic_dist_base = gicv3_dist_base();
+		idreg = gic_dist_base + GICD_PIDR2;
+		break;
 	default:
 		report_abort("GIC version %d not supported", gic_version());
 	}
@@ -492,7 +500,8 @@ static void gic_test_mmio(void)
 	nr_irqs = GICD_TYPER_IRQS(reg);
 	report_info("number of implemented SPIs: %d", nr_irqs - GIC_FIRST_SPI);
 
-	test_typer_v2(reg);
+	if (gic_version() == 0x2)
+		test_typer_v2(reg);
 
 	report_info("IIDR: 0x%08x", readl(gic_dist_base + GICD_IIDR));
 
arm/unittests.cfg +11 -5
index 6d3df92..3fd5b04 100644
@@ -86,22 +86,28 @@ smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'ipi'
 groups = gic
 
-[gicv2-mmio]
+[gicv2-max-mmio]
 file = gic.flat
 smp = $((($MAX_SMP < 8)?$MAX_SMP:8))
 extra_params = -machine gic-version=2 -append 'mmio'
 groups = gic
 
-[gicv2-mmio-up]
+[gicv3-max-mmio]
+file = gic.flat
+smp = $MAX_SMP
+extra_params = -machine gic-version=3 -append 'mmio'
+groups = gic
+
+[gic-mmio-up]
 file = gic.flat
 smp = 1
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
-[gicv2-mmio-3p]
+[gic-mmio-3p]
 file = gic.flat
 smp = $((($MAX_SMP < 3)?$MAX_SMP:3))
-extra_params = -machine gic-version=2 -append 'mmio'
+extra_params = -append 'mmio'
 groups = gic
 
Quoted 13 lines

lib/arm/asm/gic.h line 27

Quoted 11 lines
arm/unittests.cfg +0 -0
 [gicv3-ipi]
lib/arm/asm/gic.h +2 -0
index f6dfb90..ffed025 100644
@@ -23,6 +23,8 @@
 #define GICD_ITARGETSR			0x0800
 #define GICD_SGIR			0x0f00
 #define GICD_ICPIDR2			0x0fe8
+/* only in GICv3 */
+#define GICD_PIDR2			0xffe8  

If this is gicv3-only, then shouldn't it go to lib/arm/asm/gic-v3.h ?

Ah, true, I missed that file.

Added it there, I will send a reworked version as part of now some bigger series to test GICD_IROUTER and SPIs as well.

Quoted 11 lines
Quoted 7 lines
lib/arm/asm/gic.h +0 -0
 #define GICD_TYPER_IRQS(typer)		((((typer) & 0x1f) + 1) * 32)
 #define GICD_INT_EN_SET_SGI		0x0000ffff
Signature · 1 line
2.17.1

Otherwise

Thanks!

Cheers,
Andre.