Add GIC SGI boot/self tests in Xen
PATCH v4 1/1 Add GIC SGI boot/self tests in Xen
Boot self-tests (also referred to as boot-time tests or power-on self-tests) are intended to check that Xen has configured the hardware correctly before bringing up any domains.
Introduce tests to confirm that, using a dedicated SGI (GIC_SGI_TEST):
1. A cpu can send the SGI to itself
2. A cpu can send the SGI to another specific CPU (CPU0)
3. A cpu can send the SGI to all the other CPUs
Each CPU counts the test SGIs it takes. A sender samples those counters before sending and then waits for the count of every CPU it targeted to change, which is how it tells that the SGI was really delivered. The counters are never reset, so comparing against a sample rather than an absolute value keeps concurrent senders from disturbing each other.
A test reports a failure by panic(), so Xen never continues on a platform where SGI delivery is broken. When the tests pass, Xen carries on booting normally.
Also introduce a config CONFIG_BOOT_SELFTEST which enables these tests. It depends on DEBUG and is off unless explicitly enabled.
Also introduce a boolean command line parameter "gic-test", so that a build with CONFIG_BOOT_SELFTEST enabled can be shipped but the tests selected at boot. It is documented in docs/misc/xen-command-line.pandoc.
In order to keep all the boot self-tests together in the binary, a separate section "initcallboottest" is introduced. Tests are registered using __initcallboottest() and run once on every CPU by do_init_boottests(), bracketed by begin/end messages. They run before any domain is created on the primary core, and before the idle loop is entered on a secondary core.
---
Link to v3:
https://www.mail-archive.com/[email protected]/msg215355.html
Upstream CI run:
https://gitlab.com/xen-project/people/ayankuma/xen/-/pipelines/2853709475
Changes in v4:
- gic-test.c is SPDX GPL-2.0-only; COPYING states v2-only is the only valid version. v3 had changed this to GPL-2.0-or-later to match the neighbouring GIC files, which was wrong (Julien).
- The SGI handler uses ACCESS_ONCE() for the increment as well as the read, since the counter is published to another CPU. Not an atomic:
only the receiving CPU writes its own counter (Julien).
- Dropped the file name from the gic_sgi_test_interrupt() comment in asm/gic.h (Julien).
- asm/setup.h is included after asm/tee/tee.h in smpboot.c (Julien).
- Sent as a new thread rather than in-reply-to v3 (Julien).
- Rebased onto current staging (adbbbd47a1); applied unchanged.
automation/gitlab-ci/build.yaml | 8 ++ automation/gitlab-ci/test.yaml | 8 ++ .../scripts/qemu-boot-selftest-arm64.sh | 72 +++++++++++++ docs/misc/xen-command-line.pandoc | 10 ++ xen/arch/arm/Kconfig | 13 +++ xen/arch/arm/Makefile | 1 + xen/arch/arm/gic-test.c | 102 ++++++++++++++++++ xen/arch/arm/gic.c | 5 + xen/arch/arm/include/asm/gic.h | 8 ++ xen/arch/arm/include/asm/setup.h | 9 ++ xen/arch/arm/setup.c | 20 ++++ xen/arch/arm/smpboot.c | 3 + xen/arch/arm/xen.lds.S | 4 + 13 files changed, 263 insertions(+) create mode 100755 automation/scripts/qemu-boot-selftest-arm64.sh create mode 100644 xen/arch/arm/gic-test.c
automation/gitlab-ci/build.yaml +8 -0
@@ -420,6 +420,14 @@ alpine-3.24-arm64-gcc-debug: CONFIG_UBSAN=y CONFIG_UBSAN_FATAL=y +alpine-3.24-arm64-gcc-debug-boot-selftest: + extends: .gcc-arm64-build-debug + <<: *build-test + variables: + CONTAINER: alpine:3.24-arm64v8 + EXTRA_XEN_CONFIG: | + CONFIG_BOOT_SELFTEST=y + alpine-3.24-arm64-gcc-randconfig: extends: .gcc-arm64-build variables:
automation/gitlab-ci/test.yaml +8 -0
@@ -605,6 +605,14 @@ qemu-smoke-dom0less-arm64-gcc-debug-gicv3: - *arm64-test-needs - alpine-3.24-arm64-gcc-debug +qemu-smoke-boot-selftest-arm64-gcc-debug: + extends: .qemu-arm64 + script: + - ./automation/scripts/qemu-boot-selftest-arm64.sh 2>&1 | tee ${LOGFILE} + needs: + - *arm64-test-needs + - alpine-3.24-arm64-gcc-debug-boot-selftest + qemu-smoke-dom0less-arm64-gcc-debug-staticmem: extends: .qemu-arm64 script:
automation/scripts/qemu-boot-selftest-arm64.sh new file +72 -0
72 lines not on this page · raw message
docs/misc/xen-command-line.pandoc +10 -0
@@ -1282,6 +1282,16 @@ available on Intel Panther Lake and Diamond Rapids CPUs, and AMD Zen6 CPUs. FRED is fully supported on AMD hardware. On Intel hardware it is still tech preview, and in particular not security supported. +### gic-test (arm) +> `= <boolean>` + +> Default: `false` + +Only available when `CONFIG_BOOT_SELFTEST` is enabled. + +Run the GIC SGI boot self-tests while each CPU is brought up. Xen panics if +an SGI is not delivered; otherwise it carries on booting normally. + ### gnttab > `= List of [ max-ver:<integer>, transitive=<bool>, transfer=<bool> ]`
xen/arch/arm/Kconfig +13 -0
@@ -498,6 +498,19 @@ config ARM64_HARDEN_BRANCH_PREDICTOR config ARM32_HARDEN_BRANCH_PREDICTOR def_bool y if ARM_32 && HARDEN_BRANCH_PREDICTOR +config BOOT_SELFTEST + bool "Enable boot self-tests" + depends on DEBUG + help + This option enables boot self-tests. They are intended to check that + Xen has configured the hardware correctly before bringing up any + domains. A failure is reported by panic(); when the tests pass, Xen + boots normally. + + Selected at boot with the "gic-test" command line option. + + If unsure, say N. + source "arch/arm/platforms/Kconfig" source "common/Kconfig"
xen/arch/arm/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-y += domctl.o obj-$(CONFIG_EARLY_PRINTK) += early_printk.o obj-y += efi/ obj-y += gic.o +obj-$(CONFIG_BOOT_SELFTEST) += gic-test.o obj-$(CONFIG_GICV2) += gic-v2.o obj-$(CONFIG_GICV3) += gic-v3.o obj-$(CONFIG_HAS_ITS) += gic-v3-its.o
xen/arch/arm/gic-test.c new file +102 -0
102 lines not on this page · raw message
xen/arch/arm/gic.c +5 -0
@@ -330,6 +330,11 @@ static void do_static_sgi(struct cpu_user_regs *regs, enum gic_sgi sgi)case GIC_SGI_CALL_FUNCTION :smp_call_function_interrupt ();break ; +#ifdef CONFIG_BOOT_SELFTEST +case GIC_SGI_TEST : +gic_sgi_test_interrupt (); +break ; +#endif default :panic ("Unhandled SGI %d on CPU%d\n" , sgi,smp_processor_id ());break ;
xen/arch/arm/include/asm/gic.h +8 -0
@@ -306,6 +306,9 @@ enum gic_sgi {GIC_SGI_EVENT_CHECK ,GIC_SGI_DUMP_STATE ,GIC_SGI_CALL_FUNCTION , +#ifdef CONFIG_BOOT_SELFTEST +GIC_SGI_TEST , +#endif GIC_SGI_STATIC_MAX, };
@@ -321,6 +324,11 @@ extern void send_SGI_one(unsigned int cpu, enum gic_sgi sgi);extern void send_SGI_self (enum gic_sgi sgi);extern void send_SGI_allbutself (enum gic_sgi sgi); +#ifdef CONFIG_BOOT_SELFTEST +/* Record a GIC_SGI_TEST delivered to this CPU. */ +void gic_sgi_test_interrupt (void ); +#endif +/* print useful debug info */ extern void gic_dump_info (struct vcpu *v);extern void gic_dump_vgic_info (struct vcpu *v);
xen/arch/arm/include/asm/setup.h +9 -0
@@ -48,6 +48,15 @@ void setup_mm(void);extern uint32_t hyp_traps_vector[];void init_traps (void ); +#ifdef CONFIG_BOOT_SELFTEST +#define __initcallboottest (fn) \ + static const initcall_t __initcall_##fn __init_call("boottest") = (fn) + +void do_init_boottests (void ); +#else +static inline void do_init_boottests (void ) {} +#endif +int handle_device (struct domain *d,struct dt_device_node *dev,p2m_type_t p2mt,struct rangeset *iomem_ranges,struct rangeset *irq_ranges);
xen/arch/arm/setup.c +20 -0
@@ -81,6 +81,24 @@ static void __init init_idle_domain(void)/* TODO: setup_idle_pagetable(); */ } +#ifdef CONFIG_BOOT_SELFTEST +extern const initcall_t __initcall_boot_test_start[], + __initcall_boot_test_end[]; + +void do_init_boottests (void ) +{ +const initcall_t *call; + +printk ("CPU%u: boot self-tests start\n" ,smp_processor_id ()); + +for ( call = __initcall_boot_test_start; call < __initcall_boot_test_end; + call++ ) + (*call)(); + +printk ("CPU%u: boot self-tests done\n" ,smp_processor_id ()); +} +#endif /* CONFIG_BOOT_SELFTEST */ +static const char *__initdata processor_implementers[] = { ['A' ] ="ARM Limited" , ['B' ] ="Broadcom Corporation" ,
@@ -471,6 +489,8 @@ void asmlinkage __init noreturn start_xen(unsigned long fdt_paddr)enable_errata_workarounds ();enable_cpu_features (); +do_init_boottests (); +/* Create initial domain 0. */ if ( !is_dom0less_mode () )create_dom0 ();
xen/arch/arm/smpboot.c +3 -0
@@ -30,6 +30,7 @@#include <asm/psci.h> #include <asm/acpi.h> #include <asm/tee/tee.h> +#include <asm/setup.h> /* Override macros from asm/page.h to make them work with mfn_t */ #undef virt_to_mfn
@@ -413,6 +414,8 @@ void asmlinkage noreturn start_secondary(void)printk (XENLOG_DEBUG "CPU %u booted.\n" ,smp_processor_id ()); +do_init_boottests (); +startup_cpu_idle_loop (); }
xen/arch/arm/xen.lds.S +4 -0
@@ -146,6 +146,10 @@ SECTIONS *(.initcall1.init) __initcall_end = .; + __initcall_boot_test_start = .; + *(.initcallboottest.init) + __initcall_boot_test_end = .; + . = ALIGN(4); __alt_instructions = .; *(.altinstructions)
Signature · 1 line
2.25.1
Hi Ayan,
Quoted 18 lines · Ayan Kumar Halder
xen/arch/arm/gic-test.c new file +18
-0+static void __init expect_sgi (const cpumask_t *mask, +const unsigned int *before,const char *what) +{ +s_time_t deadline =NOW () +MILLISECS (100 ); +unsigned int cpu; + + for_each_cpu ( cpu, mask ) + { +while (sgi_count (cpu) == before[cpu] ) + { +if (NOW () > deadline ) +panic ("GIC selftest: %s: CPU%u did not receive GIC_SGI_TEST\n" , + what, cpu); +cpu_relax (); + } + } + +printk ("GIC selftest: CPU%u: %s: OK\n" ,smp_processor_id (), what);
xen/arch/arm/gic-test.c line 69
Quoted 10 lines
xen/arch/arm/gic-test.c new file +10
-0+} + +/* +* "All but self" is only meaningful once every CPU can take an SGI, so it is +* run by whichever CPU observes that it is the last one to get here. +*/ +static int __init gic_sgi_selftest (void ) +{ +static atomic_t __initdata seen =ATOMIC_INIT (0 ); +unsigned int before[NR_CPUS ] = { };
Sorry I didn't spot this earlier. NR_CPUS can be quite large (up to 16K). So this will blow up the stack.
There are two options:
1) Use static
2) Temporarily allocate "before"
I don't have a strong opinion on which way to go with.
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien
Hi Ayan,
Hi Julien,
Quoted 27 lines · Ayan Kumar Halder
Quoted 25 lines
+static void
__initexpect_sgi(constcpumask_t*mask,
+ const unsigned int *before, const char *what)xen/arch/arm/gic-test.c new file +10
-0+{ + s_time_t deadline = NOW() + MILLISECS(100); + unsigned int cpu; + + for_each_cpu ( cpu, mask ) + { + while ( sgi_count(cpu) == before[cpu] ) + { + if ( NOW() > deadline ) + panic("GIC selftest: %s: CPU%u did not receiveGIC_SGI_TEST\n",
+ what, cpu);
+cpu_relax();
+ }
+ }xen/arch/arm/gic-test.c new file +6
-0+ + printk("GIC selftest: CPU%u: %s: OK\n", smp_processor_id(), what); +} + +/* +* "All but self" is only meaningful once every CPU can take an SGI, so it is
Quoted 8 lines
xen/arch/arm/gic-test.c line 69
Quoted 6 lines
+ * run by whichever CPU observes that it is the last one to get here.
+ */xen/arch/arm/gic-test.c new file +4
-0+static int __init gic_sgi_selftest (void ) +{ + static atomic_t __initdata seen = ATOMIC_INIT(0); + unsigned int before[NR_CPUS] = { };Sorry I didn't spot this earlier.
NR_CPUScan be quite large (up to 16K). So this will blow up the stack.
As this is a test, we have hardcoded NR_CPUS = 4 in automation/scripts/qemu-boot-selftest-arm64.sh.
If there are 16K CPUs, our test only checks for 4 cpus only.
However if there is still a concern ....
Quoted 6 lines
There are two options:
1) Use static
2) Temporarily allocate "before"I don't have a strong opinion on which way to go with.
I can use static.
- Ayan
Quoted 3 lines
Cheers,
Grall, Julien
Reviewed-byHi Ayan,
Quoted 27 lines · Ayan Kumar
Quoted 26 lines · Julien
Quoted 25 lines · Ayan Kumar Halder
+static void
__initexpect_sgi(constcpumask_t*mask,
+ const unsigned int *before, const char *what)xen/arch/arm/gic-test.c new file +10
-0+{ + s_time_t deadline = NOW() + MILLISECS(100); + unsigned int cpu; + + for_each_cpu ( cpu, mask ) + { + while ( sgi_count(cpu) == before[cpu] ) + { + if ( NOW() > deadline ) + panic("GIC selftest: %s: CPU%u did not receiveGIC_SGI_TEST\n",
+ what, cpu);
+cpu_relax();
+ }
+ }xen/arch/arm/gic-test.c new file +6
-0+ + printk("GIC selftest: CPU%u: %s: OK\n", smp_processor_id(), what); +} + +/* +* "All but self" is only meaningful once every CPU can take an SGI, so it is
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/gic-test.c line 69
Quoted 6 lines
+ * run by whichever CPU observes that it is the last one to get here.
+ */xen/arch/arm/gic-test.c new file +4
-0+static int __init gic_sgi_selftest (void ) +{ + static atomic_t __initdata seen = ATOMIC_INIT(0); + unsigned int before[NR_CPUS] = { };Sorry I didn't spot this earlier.
NR_CPUScan be quite large (up to 16K). So this will blow up the stack.
We discussed this offline at Xen Summit. But I will answer here as well.
Quoted 2 lines
As this is a test, we have hardcoded
NR_CPUS= 4 in automation/scripts/qemu-boot-selftest-arm64.sh.
I agree with your current test harness we only test 4 CPUs. However, this is not enforced by the Kconfig in Xen. So anyone could modify the script (or write their own) with a much higher number of NR_CPUS (possibly to match the number of pCPUs on their hardware).
Depending on the value, they could face a stack overflow.
Quoted 4 lines
If there are 16K CPUs, our test only checks for 4 cpus only.
However if there is still a concern ....
I would preferred if this is solved. Assuming this is fixed:
Cheers,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien
Hi Ayan,
Hi Julien,
Quoted 46 lines · Ayan Kumar
Quoted 28 lines · Julien
Quoted 27 lines · Ayan Kumar Halder
Quoted 26 lines
+static void
__initexpect_sgi(constcpumask_t*mask, + const unsigned int *before, const char *what)xen/arch/arm/gic-test.c new file +10
-0+{ + s_time_t deadline = NOW() + MILLISECS(100); + unsigned int cpu; + + for_each_cpu ( cpu, mask ) + { + while ( sgi_count(cpu) == before[cpu] ) + { + if ( NOW() > deadline ) + panic("GIC selftest: %s: CPU%u did not receiveGIC_SGI_TEST\n",
+ what, cpu);
+cpu_relax();
+ }
+ }
+
+printk("GIC selftest: CPU%u: %s: OK\n", smp_processor_id(), what);xen/arch/arm/gic-test.c new file +4
-0+} + +/* +* "All but self" is only meaningful once every CPU can take an SGI, so it is
Quoted 8 lines
Quoted 8 lines
xen/arch/arm/gic-test.c line 69
Quoted 6 lines
+ * run by whichever CPU observes that it is the last one to get here.
+ */xen/arch/arm/gic-test.c new file +4
-0+static int __init gic_sgi_selftest (void ) +{ + static atomic_t __initdata seen = ATOMIC_INIT(0); + unsigned int before[NR_CPUS] = { };Sorry I didn't spot this earlier.
NR_CPUScan be quite large (up to 16K). So this will blow up the stack.We discussed this offline at Xen Summit. But I will answer here as well.
Quoted 2 lines
As this is a test, we have hardcoded
NR_CPUS= 4 in automation/scripts/qemu-boot-selftest-arm64.sh.I agree with your current test harness we only test 4 CPUs. However, this is not enforced by the
Kconfigin Xen. So anyone could modify the script (or write their own) with a much higher number ofNR_CPUS(possibly to match the number of pCPUs on their hardware).
Quoted 8 lines
Depending on the value, they could face a stack overflow.
Quoted 4 lines
If there are 16K CPUs, our test only checks for 4 cpus only.
However if there is still a concern ....
I would preferred if this is solved. Assuming this is fixed:
I have fixed this. Please see
[PATCH v5] xen/arm: gic: Add GIC SGI boot/self tests in Xen
Quoted 2 lines
Reviewed-by Julien Grall <[email protected]>
I have kept your R-b. :)
- Ayan